import type { VxeGridProps } from '#/adapter/vxe-table';
import type { FormSchemaGetter } from '#/adapter/form';
import { selectAllSysStation } from '#/api/system/infoEntry/stationInfo/stationInfo';

// 获取过滤后的岗位列表
import { getFilteredPositions } from '../../utils/positionFilter';

// 排水记录类型定义
export interface DrainageRecord {
  id: number;
  stationName: string; // 油站
  submitTime: string; // 提交时间
  executorName: string; // 执行人
  positionName: string; // 岗位
  comment: string; // 评论
  commenterName: string; // 评论人
}

// 排水记录表格配置
export const tableColumns: VxeGridProps['columns'] = [
  {
    type: 'checkbox',
    width: 80,
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    width: 150,
  },
  {
    field: 'stationName',
    title: '油站',
    minWidth: 120,
  },
  {
    field: 'submitTime',
    title: '提交时间',
    minWidth: 180,
  },
  {
    field: 'executorName',
    title: '执行人',
    minWidth: 120,
  },
  {
    field: 'positionName',
    title: '岗位',
    minWidth: 120,
  },
  {
    field: 'comment',
    title: '评论',
    minWidth: 200,
  },
];

// 排水记录虚拟数据
export const DRAINAGE_RECORD_MOCK_DATA: DrainageRecord[] = [
  {
    id: 1,
    stationName: '北京东加油站',
    submitTime: '2026-02-01 10:30:00',
    executorName: '张三',
    positionName: '站长',
    comment: '排水工作完成良好，无异常情况',
    commenterName: '李四'
  },
  {
    id: 2,
    stationName: '北京西加油站',
    submitTime: '2026-02-01 14:20:00',
    executorName: '王五',
    positionName: '值班员',
    comment: '排水系统运行正常',
    commenterName: '赵六'
  },
  {
    id: 3,
    stationName: '机场油站',
    submitTime: '2026-02-02 09:15:00',
    executorName: '孙七',
    positionName: '设备管理员',
    comment: '发现排水管道有轻微堵塞，已处理',
    commenterName: '周八'
  },
  {
    id: 4,
    stationName: '北京南加油站',
    submitTime: '2026-02-02 16:45:00',
    executorName: '吴九',
    positionName: '值班员',
    comment: '排水工作按时完成',
    commenterName: '郑十'
  },
  {
    id: 5,
    stationName: '北京北加油站',
    submitTime: '2026-02-03 11:00:00',
    executorName: '王十一',
    positionName: '站长',
    comment: '排水系统状态良好',
    commenterName: '李十二'
  },
];

export const queryFormSchema: FormSchemaGetter = () => [
  {
    component: 'ApiSelect',
    fieldName: 'stationId',
    label: '油站',
    componentProps: {
      placeholder: '请选择油站',
      clearable: true,
      api: async () => {
        const resp = await selectAllSysStation();
        const data = resp || [];
        return Array.isArray(data)
          ? data.map((item: any) => ({
              label: item.stationName,
              value: item.id.toString(),
            }))
          : [];
      },
      labelField: 'label',
      valueField: 'value',
    },
  },
  {
    component: 'DatePicker',
    fieldName: 'submitTime',
    label: '提交时间',
    componentProps: {
      placeholder: '请选择提交时间',
      type: 'daterange',
      format: 'YYYY-MM-DD HH:mm:ss',
      valueFormat: 'YYYY-MM-DD HH:mm:ss'
    },
  },
  {
    component: 'ApiSelect',
    fieldName: 'position',
    label: '岗位',
    componentProps: {
      placeholder: '请选择岗位',
      clearable: true,
      api: getFilteredPositions,
      labelField: 'label',
      valueField: 'value',
    },
  },
  {
    component: 'Input',
    componentProps: {
      placeholder: '请输入评论人',
    },
    fieldName: 'commenterName',
    label: '评论人',
  },
];

// 排水记录列表数据获取
export const getDrainageRecordList = async (params: any) => {
  // 模拟数据
  return {
    rows: DRAINAGE_RECORD_MOCK_DATA,
    total: DRAINAGE_RECORD_MOCK_DATA.length
  };
};
