<script lang="ts" setup>
import { ElMessage } from 'element-plus'
import { TUNNEL_TYPES } from '@/config/dict'

const state = ref(false)
const type = ref<any>(null)
const params = reactive({})

const formRef = ref(null)

const rules = reactive<any>({
  // facilityEncode: [{ required: true }]
})

const popName = computed(() => {
  return {
    check: '查看',
    edit: '编辑',
    new: '新增'
  }[type.value]
})

const diaOpen = (xtype, e?) => {
  if (e) {
  }
  type.value = xtype
  state.value = true
}

const goClose = () => {
  state.value = false
}

const onClosed = () => {
  // 数据清除
}

// 提交
const onSubmit = async () => {
  // const base = await formRef.value?.pmsFirm()
  const base = await new Promise((resolve) => {
    formRef.value?.validate((e) => {
      resolve(e)
    })
  })
  if (!base) {
    return ElMessage.error('请完成数据填写！')
  }
  console.log(type.value, 'kkk')

  if (type.value === 'new') {
    // await tunnelCreate(params)
  } else {
    // await tunnelUpdate(params)
  }

  ElMessage.success(type.value === 'edit' ? '修改成功！' : '创建成功！')

  // state.value = false

  // emits('update')

  // ----
  // ElMessage.success(type.value === 'edit' ? '修改成功！' : '创建成功！')
  // state.value = false
  // emits('update')
}

defineExpose({
  diaOpen
})
</script>

<template>
  <el-dialog
    class="org-model"
    v-model="state"
    width="500"
    :destroy-on-close="true"
    :align-center="true"
    @closed="onClosed"
  >
    <div class="title">
      <div class="text">{{ popName }}菜单配置</div>
      <Icon @click="goClose" class="close" icon="ep:close" />
    </div>

    <div :class="['content', { disabled: type === 'check' }]">
      <el-form ref="formRef" :model="params" :rules :show-message="false">
        <div class="block-container road-setting">
          <el-form-item label=" ">
            <div class="w70 p-l-4 c-#ffffff"> 功能清单</div>
            <div class="c-#ffffff"> 是否可见</div>
          </el-form-item>

          <el-form-item prop="tunnelType1" label=" " class="radio_form_items">
            <div class="w70 p-l-4"> 全息车流模式</div>
            <el-switch
              class="x-switch"
              v-model="params.useEnable"
              inline-prompt
              active-text="可见"
              inactive-text="隐藏"
            />
          </el-form-item>

          <el-form-item prop="tunnelType1" label=" " class="radio_form_items">
            <div class="w70 p-l-4"> 首页</div>
            <el-switch
              class="x-switch"
              v-model="params.useEnable"
              inline-prompt
              active-text="可见"
              inactive-text="隐藏"
            />
          </el-form-item>
          <el-form-item prop="tunnelType1" label=" " class="radio_form_items">
            <div class="w70 p-l-4"> 留存车辆</div>
            <el-switch
              class="x-switch"
              v-model="params.useEnable"
              inline-prompt
              active-text="可见"
              inactive-text="隐藏"
            />
          </el-form-item>
          <el-form-item prop="tunnelType1" label=" " class="radio_form_items">
            <div class="w70 p-l-4"> 事件检测</div>
            <el-switch
              class="x-switch"
              v-model="params.useEnable"
              inline-prompt
              active-text="可见"
              inactive-text="隐藏"
            />
          </el-form-item>
          <el-form-item prop="tunnelType1" label=" " class="radio_form_items">
            <div class="w70 p-l-4"> 历史记录</div>
            <el-switch
              class="x-switch"
              v-model="params.useEnable"
              inline-prompt
              active-text="可见"
              inactive-text="隐藏"
            />
          </el-form-item>
          <el-form-item prop="tunnelType1" label=" " class="radio_form_items">
            <div class="w70 p-l-4"> 系统设置</div>
            <el-switch
              class="x-switch"
              v-model="params.useEnable"
              inline-prompt
              active-text="可见"
              inactive-text="隐藏"
            />
          </el-form-item>
          <el-form-item prop="tunnelType1" label=" " class="radio_form_items">
            <div class="w70 p-l-4"> 隧道管控模式</div>
            <el-switch
              class="x-switch"
              v-model="params.useEnable"
              inline-prompt
              active-text="可见"
              inactive-text="隐藏"
            />
          </el-form-item>
        </div>
      </el-form>
    </div>

    <template #footer>
      <div class="footer">
        <el-button v-if="type === 'check'" type="primary" @click="goClose">关闭</el-button>
        <template v-else>
          <el-button @click="goClose">取消</el-button>
          <el-button @click="onSubmit" type="primary">确定</el-button>
        </template>
      </div>
    </template>
  </el-dialog>
</template>

<style lang="scss" scoped>
$base_url: '@/assets/images/home/';

.title {
  height: 48px;
  display: flex;
  align-content: center;
  align-items: center;
  color: white;
  padding: 0 20px;
  font-size: 18px;
  font-weight: 600;
  justify-content: space-between;
  .close {
    cursor: pointer;
  }
}

.content {
  padding: 0 16px;
  // height: 600px;

  .block-container {
    padding-right: 24px;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    margin-top: 20px;
  }

  &.disabled {
    :deep(.base-block) {
      pointer-events: none;
    }
    :deep(.road-setting) {
      pointer-events: none;
    }
    :deep(.el-input) {
      background: rgba($color: #ffffff, $alpha: 0.2);
    }
  }
  .radio_form_items {
    color: #ffffff;
    :deep(.el-form-item__content) {
      height: 44px;
      background: rgba(69, 116, 182, 0.2);
      border-radius: 2px;
    }
    .x-switch {
      :deep(.el-switch__core) {
        height: 26px;
        width: 52px;
        border-radius: 26px;
      }
    }
  }
}

.footer {
  // background: rgba(69, 116, 182, 0.36);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 20px 24px;
  color: white;
}
</style>

<style lang="scss">
.org-model {
  padding: 0;
  box-sizing: border-box;
  // border: 1px solid rgba(255, 255, 255, 0.5);
  background: #0d3561;
  border-radius: 4px;

  .el-dialog__header {
    display: none;
  }
  .el-dialog__footer {
    padding-top: 0;
  }
  .def-btn {
    background: #1270ff;
    border: 1px solid rgba(155, 193, 255, 0.74);
    height: 28px;
    padding: 8px 10px;
    color: white;
    &:hover {
      border: 1px solid rgba(255, 255, 255, 0.8);
    }
  }
}
</style>
