<template>
  <el-form :model="form" label-width="auto" style="max-width: 600px">
    <!--    <el-form-item label="发布终点     ：">-->
    <!--      <el-button type="primary" @click="onSubmit">默认终点</el-button>-->
    <!--      <el-button type="primary" @click="onSubmit">自定义终点</el-button>-->
    <!--    </el-form-item>-->
    <el-form-item label="随机起终点     ：">
      <el-switch
          v-model="form.isRandom"
          inline-prompt
          active-text="是"
          inactive-text="否"
      />
      <div v-if="form.isRandom">
        <el-input-number  class="mx-4" v-model="form.randomCount" :min="1" :max="10" style="margin-left: 15px; width: 100px;"/>
        <span style="margin-left: 10px;">次</span>
      </div>
    </el-form-item>
    <el-form-item label="起点设置     ：" v-if="!form.isRandom">
      <el-radio-group v-model="form.origin" @change="originChange">
        <el-radio value="0">默认起点</el-radio>
        <el-radio value="1">自定义起点</el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="终点设置     ：" v-if="!form.isRandom">
      <el-radio-group v-model="form.destination" @change="destinationChange">
        <el-radio value="0">默认终点</el-radio>
        <el-radio value="1">自定义终点</el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="加载默认障碍物：">
      <el-radio-group v-model="form.resource">
        <el-radio :value="true">是</el-radio>
        <el-radio :value="false">否</el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="            ">
      <!--      <el-button type="primary" @click="goToMain">开始执行</el-button>-->
      <el-button type="primary" @click="dialogVisible = true">开始执行</el-button>

      <el-dialog
          v-model="dialogVisible"
          title="请输入自定义配置参数"
          width="300"
          :before-close="handleClose"
          draggable
      >
        <template #footer>
          <div class="dialog-footer">
            <el-form :model="form" label-width="auto">
              <el-form-item style="margin-bottom: 10px" label="位置 X ：">
                <el-input v-model="form.name" />
              </el-form-item>
              <el-form-item style="margin-bottom: 10px" label="位置 Y ：">
                <el-input v-model="form.name" />
              </el-form-item>
              <el-form-item style="margin-bottom: 10px" label="位置 Z ：">
                <el-input v-model="form.name" />
              </el-form-item>
              <el-form-item style="margin-bottom: 10px" label="姿态 X ：">
                <el-input v-model="form.name" />
              </el-form-item>
              <el-form-item style="margin-bottom: 10px" label="姿态 Y ：">
                <el-input v-model="form.name" />
              </el-form-item>
              <el-form-item style="margin-bottom: 10px" label="姿态 Z ：">
                <el-input v-model="form.name" />
              </el-form-item>
              <el-form-item style="margin-bottom: 10px" label="姿态 W ：">
                <el-input v-model="form.name" />
              </el-form-item>
            </el-form>
<!--            -->
<!--            <el-button @click="dialogVisible = false">取消</el-button>-->
            <el-button type="primary" @click="dialogVisible = false">确认</el-button>
          </div>
        </template>
      </el-dialog>
      <el-button style="margin-left: 10px;" type="primary" @click="goToMain">更换设置并执行</el-button>
    </el-form-item>
    <el-form-item label="            ">
      <el-button type="primary" @click="goToAlgorithmEval">算法评价</el-button>
    </el-form-item>
    <el-form-item label="            ">
      <el-button type="primary" @click="goToMain">返回</el-button>
    </el-form-item>

  </el-form>
</template>

<script lang="ts" setup>
import {useRouter} from 'vue-router'; // 导入 Vue Router 的 useRouter 钩子
import {reactive} from 'vue'
import {ref} from 'vue'
import {ElMessageBox} from 'element-plus'


const dialogVisible = ref(false)

const handleClose = (done: () => void) => {
  done()
}

// do not use same name with ref
const form = reactive({
  name: '',
  region: '',
  date1: '',
  date2: '',
  delivery: false,
  type: [],
  resource: true,
  desc: '',
  isRandom: false,
  origin: '0',
  destination: '0',
  randomCount: ref(1),
})

const originChange = (value: string) => {
  if (value == "1") {
    dialogVisible.value = true
  }
}

const destinationChange = (value: string) => {
  if (value == "1") {
    dialogVisible.value = true
  }
}

const onSubmit = () => {
  console.log('submit!')
}
const router = useRouter();

const goToMain = () => {
  router.push('/')
}

const goToAlgorithmEval = () => {
  router.push('/algorithm_eval')
}

</script>