<template>
  <el-dialog v-model="visible" title="批量授权下发" width="600px">
    <el-form :model="authForm" label-width="100px">
      <el-form-item label="目标设备">
        <el-input :value="currentDevice?.label || '所有设备'" disabled />
      </el-form-item>
      <el-form-item label="选择人员">
         <el-transfer
          v-model="authForm.targetUsers"
          :data="userListMock"
          :titles="['未授权', '已选择']"
          filter-placeholder="搜索人员"
          filterable
        />
      </el-form-item>
      <el-form-item label="有效期限">
        <el-date-picker
          v-model="authForm.period"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          style="width: 100%"
        />
      </el-form-item>
      <el-form-item label="认证方式">
        <el-checkbox-group v-model="authForm.authTypes">
          <el-checkbox label="face">人脸识别</el-checkbox>
          <el-checkbox label="card">校园卡</el-checkbox>
        </el-checkbox-group>
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="confirmAuth">确认下发</el-button>
    </template>
  </el-dialog>
</template>

<script setup>
import { ref, reactive } from 'vue'
import { ElMessage } from 'element-plus'

const visible = ref(false)
const currentDevice = ref(null)

const authForm = reactive({
  targetUsers: [],
  period: [],
  authTypes: ['face', 'card']
})

// Mock Transfer Data
const userListMock = Array.from({ length: 20 }).map((_, i) => ({
  key: i,
  label: `学生${i + 1}`,
  disabled: i % 4 === 0
}))

const open = (device) => {
  currentDevice.value = device
  visible.value = true
}

const confirmAuth = () => {
  visible.value = false
  ElMessage.success('权限下发指令已推送至设备')
}

defineExpose({
  open
})
</script>
