import type { VxeGridProps } from '#/adapter/vxe-table';
import type { FormSchemaGetter } from '#/adapter/form';

// 量缸试水记录类型定义
export interface WaterTestRecordData {
  id: number;
  area: string; // 片区
  station: string; // 油站
  status: string; // 完成状态
  processingTime: string; // 处理时间
  position: string; // 岗位
  comment: string; // 评论
  creator: string; // 创建人
  executor: string; // 执行人
  deadline: string; // 截止时间
  waterHeightAbove30mm: number; // 水高高于30mm（数量）
}

// 量缸试水记录表格配置
export const tableColumns: VxeGridProps['columns'] = [
  { title: '油站', field: 'station', minWidth: 150, align: 'center' },
  { title: '执行人', field: 'executor', minWidth: 120, align: 'center' },
  { title: '岗位', field: 'position', minWidth: 120, align: 'center' },
  { title: '评论', field: 'comment', minWidth: 150, align: 'center' },
  { title: '截止时间', field: 'deadline', minWidth: 150, align: 'center' },
  { title: '处理时间', field: 'processingTime', minWidth: 150, align: 'center' },
  { title: '完成状态', field: 'status', minWidth: 120, align: 'center' },
  { title: '水高高于30mm（数量）', field: 'waterHeightAbove30mm', minWidth: 150, align: 'center' },
  { title: '创建人', field: 'creator', minWidth: 120, align: 'center' },
  { 
    title: '操作', 
    field: 'action', 
    minWidth: 180, 
    align: 'center', 
    slots: { default: 'action' }
  },
];

// 下拉选项数据
const areaOptions = [
  { label: '默认片区', value: '默认片区' },
  { label: '片区1', value: '片区1' },
  { label: '片区2', value: '片区2' },
  { label: '片区3', value: '片区3' },
];

const stationOptions = [
  { label: '机场油站', value: '机场油站' },
  { label: '北京东加油站', value: '北京东加油站' },
  { label: '北京西加油站', value: '北京西加油站' },
  { label: '北京南加油站', value: '北京南加油站' },
  { label: '北京北加油站', value: '北京北加油站' },
  { label: '河北油站', value: '河北油站' },
  { label: '龙飞虎加油站', value: '龙飞虎加油站' },
  { label: '法站加油站', value: '法站加油站' },
];

const statusOptions = [
  { label: '已完成', value: '已完成' },
  { label: '未完成', value: '未完成' },
  { label: '进行中', value: '进行中' },
];

const positionOptions = [
  { label: '站长', value: '站长' },
  { label: '安全员', value: '安全员' },
  { label: '加油员', value: '加油员' },
  { label: '维修员', value: '维修员' },
];

const commentOptions = [
  { label: '正常', value: '正常' },
  { label: '需关注', value: '需关注' },
  { label: '异常', value: '异常' },
];

const creatorOptions = [
  { label: '张三', value: '张三' },
  { label: '李四', value: '李四' },
  { label: '王五', value: '王五' },
  { label: '赵六', value: '赵六' },
  { label: '孙七', value: '孙七' },
];

// 量缸试水记录模拟数据
export const WATER_TEST_RECORD_MOCK_DATA: WaterTestRecordData[] = [
  { 
    id: 1, 
    area: '默认片区', 
    station: '北京东加油站', 
    status: '已完成', 
    processingTime: '2025-12-10 10:30:00', 
    position: '安全员', 
    comment: '正常', 
    creator: '张三', 
    executor: '李四', 
    deadline: '2025-12-15 17:00:00', 
    waterHeightAbove30mm: 2
  },
  { 
    id: 2, 
    area: '片区1', 
    station: '机场油站', 
    status: '未完成', 
    processingTime: '2025-12-09 14:20:00', 
    position: '站长', 
    comment: '需关注', 
    creator: '王五', 
    executor: '赵六', 
    deadline: '2025-12-12 17:00:00', 
    waterHeightAbove30mm: 5
  },
  { 
    id: 3, 
    area: '片区2', 
    station: '北京南加油站', 
    status: '进行中', 
    processingTime: '2025-12-08 09:15:00', 
    position: '加油员', 
    comment: '异常', 
    creator: '孙七', 
    executor: '张三', 
    deadline: '2025-12-16 17:00:00', 
    waterHeightAbove30mm: 8
  },
  { 
    id: 4, 
    area: '片区3', 
    station: '北京北加油站', 
    status: '已完成', 
    processingTime: '2025-12-07 16:45:00', 
    position: '维修员', 
    comment: '正常', 
    creator: '李四', 
    executor: '王五', 
    deadline: '2025-12-10 17:00:00', 
    waterHeightAbove30mm: 1
  },
  { 
    id: 5, 
    area: '默认片区', 
    station: '北京西加油站', 
    status: '已完成', 
    processingTime: '2025-12-06 11:20:00', 
    position: '安全员', 
    comment: '需关注', 
    creator: '赵六', 
    executor: '孙七', 
    deadline: '2025-12-09 17:00:00', 
    waterHeightAbove30mm: 3
  },
];

// 生成更多模拟数据
for (let i = 6; i <= 20; i++) {
  const randomArea = areaOptions[Math.floor(Math.random() * areaOptions.length)].value;
  const randomStation = stationOptions[Math.floor(Math.random() * stationOptions.length)].value;
  const randomStatus = statusOptions[Math.floor(Math.random() * statusOptions.length)].value;
  const randomPosition = positionOptions[Math.floor(Math.random() * positionOptions.length)].value;
  const randomComment = commentOptions[Math.floor(Math.random() * commentOptions.length)].value;
  const randomCreator = creatorOptions[Math.floor(Math.random() * creatorOptions.length)].value;
  const randomExecutor = creatorOptions[Math.floor(Math.random() * creatorOptions.length)].value;
  const randomDate = new Date(2025, 11, Math.floor(Math.random() * 15) + 1);
  const randomProcessingTime = new Date(2025, 11, Math.floor(Math.random() * 15) + 1, Math.floor(Math.random() * 24), Math.floor(Math.random() * 60), Math.floor(Math.random() * 60));
  const randomWaterHeight = Math.floor(Math.random() * 10) + 1;

  WATER_TEST_RECORD_MOCK_DATA.push({
    id: i,
    area: randomArea,
    station: randomStation,
    status: randomStatus,
    processingTime: randomProcessingTime.toISOString().replace('T', ' ').substring(0, 19),
    position: randomPosition,
    comment: randomComment,
    creator: randomCreator,
    executor: randomExecutor,
    deadline: new Date(randomDate.getTime() + 7 * 24 * 60 * 60 * 1000).toISOString().substring(0, 10) + ' 17:00:00',
    waterHeightAbove30mm: randomWaterHeight
  });
}

export const queryFormSchema: FormSchemaGetter = () => [
  {
    component: 'Select',
    fieldName: 'area',
    label: '片区',
    componentProps: {
      placeholder: '请选择片区',
      options: areaOptions,
      allowClear: true
    },
  },
  {
    component: 'Select',
    fieldName: 'station',
    label: '油站',
    componentProps: {
      placeholder: '请选择油站',
      options: stationOptions,
      allowClear: true
    },
  },
  {
    component: 'Select',
    fieldName: 'status',
    label: '完成状态',
    componentProps: {
      placeholder: '请选择完成状态',
      options: statusOptions,
      allowClear: true
    },
  },
  {
    component: 'DatePicker',
    fieldName: 'processingTime',
    label: '处理时间',
    componentProps: {
      placeholder: '请选择处理时间',
      type: 'daterange',
      format: 'YYYY-MM-DD HH:mm:ss',
      valueFormat: 'YYYY-MM-DD HH:mm:ss'
    },
  },
  {
    component: 'Select',
    fieldName: 'position',
    label: '岗位',
    componentProps: {
      placeholder: '请选择岗位',
      options: positionOptions,
      allowClear: true
    },
  },
  {
    component: 'Select',
    fieldName: 'comment',
    label: '评论',
    componentProps: {
      placeholder: '请选择评论',
      options: commentOptions,
      allowClear: true
    },
  },
  {
    component: 'Select',
    fieldName: 'creator',
    label: '创建人',
    componentProps: {
      placeholder: '请选择创建人',
      options: creatorOptions,
      allowClear: true
    },
  },
  {
    component: 'Input',
    fieldName: 'executor',
    label: '执行人',
    componentProps: {
      placeholder: '请输入执行人',
      allowClear: true
    },
  },
];

