<template>
  <div class="demo-collapse">
    <div class="container">
      <div class="left">
        <div class="mr-4">协议版本</div>
        <el-select>
          <el-option :value="option"></el-option>
        </el-select>
      </div>
      <div class="right">
        <el-button @click="addCmd = true">新增指令</el-button>
        <el-button>导出协议</el-button>
      </div>
    </div>

    <div class="mb-4 mt-4">协议指令</div>

    <el-collapse class="mt-4">
      <el-collapse-item title="HY_ACU7M5_PositionSet&nbsp;&nbsp;&nbsp;XY置位指令&nbsp;&nbsp;&nbsp;Tx" name="1">
        <protpcol-table></protpcol-table>
      </el-collapse-item>
      <el-collapse-item title="HY_ACU7M5_MoveStop&nbsp;&nbsp;&nbsp;停止运动指令&nbsp;&nbsp;&nbsp;Tx" name="2">
        <protpcol-table></protpcol-table>
      </el-collapse-item>
    </el-collapse>

    <el-dialog v-model="addCmd" title="新增指令">
      <el-form >
        <el-form-item label="协议名称" :label-width="formLabelWidth">
          <el-input  autocomplete="off" />
        </el-form-item>
        <el-form-item label="指令名称" :label-width="formLabelWidth">
          <el-input  autocomplete="off" />
        </el-form-item>
        <el-form-item label="指令类型" :label-width="formLabelWidth">
          <el-select>
            <el-option label="TX"></el-option>
            <el-option label="RX"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="协议类型" :label-width="formLabelWidth">
          <el-select>
            <el-option label="ASCII"></el-option>
            <el-option label="HEX"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="定时发送" :label-width="formLabelWidth">
          <el-input  autocomplete="off" />
        </el-form-item>
        <el-form-item label="说明" :label-width="formLabelWidth">
          <el-input  autocomplete="off" />
        </el-form-item>
      </el-form>
      <template #footer>
      <span class="dialog-footer">
        <el-button @click="addCmd = false">取消</el-button>
        <el-button type="primary" @click="open">
          确定
        </el-button>
      </span>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
import {ref} from 'vue'
import {ElMessage, ElMessageBox} from "element-plus";
import ProtpcolTable from "./protpcol-table.vue";

const addCmd = ref(false)
const option = ref('option')
const formLabelWidth = '140px'

const open = () => {
  ElMessageBox.confirm(
      '是否确认增加？',
      'Warning',
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }
  )
      .then(() => {
        ElMessage({
          type: 'success',
          message: '增加成功',
        })
        addCmd.value = false
      })
      .catch(() => {
        ElMessage({
          type: 'info',
          message: '已取消',
        })
      })
}
</script>

<style>
.container {
  /*width: 100%;*/
  /*border: 1px solid;*/

  display: flex;
  justify-content: space-between; /* 使内部元素平均分布 */
  align-items: center; /* 垂直居中 */
  margin: auto;
}

.left {
  align-items: center;
  display: flex;

}

.right {
  display: flex;
  align-items: center; /* 垂直居中 */
}

</style>
