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

// 油枪自检损益表数据类型定义
export interface OilGunTementData {
  id: number;
  taskName: string; // 任务名称
  station: string; // 油站
  executor: string; // 执行人
  position: string; // 岗位
  comment: string; // 评论
  deadline: string; // 截止时间
  processTime: string; // 处理时间
  status: string; // 完成状态
  creator: string; // 创建人
  area: string; // 片区
}

// 油枪自检损益表表格配置
export const tableColumns: VxeGridProps['columns'] = [
  { title: '任务名称', field: 'taskName', minWidth: 180, align: 'center' },
  { 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: 160, align: 'center' },
  { title: '处理时间', field: 'processTime', minWidth: 160, align: 'center' },
  { title: '完成状态', field: 'status', minWidth: 120, align: 'center' },
  { title: '创建人', field: 'creator', minWidth: 120, align: 'center' },
  { 
    title: '操作', 
    minWidth: 200, 
    align: 'center', 
    slots: { default: 'action' },
    fixed: 'right'
  },
];

// 搜索表单选项配置
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: '赵六' },
];

// 生成随机日期
const generateRandomDate = (startDate: Date, endDate: Date): string => {
  const randomTime = startDate.getTime() + Math.random() * (endDate.getTime() - startDate.getTime());
  const date = new Date(randomTime);
  return date.toISOString().slice(0, 19).replace('T', ' ');
};

// 油枪自检损益表模拟数据
export const OIL_GUN_TEMENT_MOCK_DATA: OilGunTementData[] = Array.from({ length: 20 }, (_, index) => {
  const id = index + 1;
  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 processDate = new Date();
  processDate.setDate(processDate.getDate() - Math.floor(Math.random() * 30));
  const deadlineDate = new Date(processDate);
  deadlineDate.setDate(deadlineDate.getDate() - Math.floor(Math.random() * 7));
  
  return {
    id,
    taskName: `油枪自检任务${id}`,
    station: randomStation,
    executor: randomExecutor,
    position: randomPosition,
    comment: randomComment,
    deadline: generateRandomDate(deadlineDate, processDate),
    processTime: generateRandomDate(processDate, new Date()),
    status: randomStatus,
    creator: randomCreator,
    area: randomArea
  };
});

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