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

import { selectAllSysAreaList, selectAllSysStation } from '#/api/system/infoEntry/stationInfo/stationInfo';

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


export const drawerFormSchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    fieldName: 'title',
    label: '标题',
    componentProps: {
      placeholder: '请输入标题',
    },
  },
  {
    component: 'Input',
    fieldName: 'content',
    label: '内容',
    componentProps: {
      placeholder: '请输入内容',
    },
  },
];

export const queryFormSchema: FormSchemaGetter = () => [
  {
    component: 'ApiSelect',
    fieldName: 'areaId',
    label: '片区',
    componentProps: {
      placeholder: '请选择片区',
      clearable: true,
      api: async () => {
        const resp = await selectAllSysAreaList();
        const data = resp || [];
        return Array.isArray(data)
          ? data.map((item: any) => ({
              label: item.areaName,
              value: item.id,
            }))
          : [];
      },
      labelField: 'label',
      valueField: 'value',
    },
  },
  {
    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: 'Select',
    fieldName: 'completionStatus',
    label: '完成状态',
    componentProps: {
      placeholder: '请选择完成状态',
      options: [
        { label: '按时完成', value: 2 },
        { label: '逾期完成', value: 1 },
      ],
    },
  },
  {
    component: 'DatePicker',
    fieldName: 'processStartTime',
    label: '处理时间',
    componentProps: {
      placeholder: '请选择处理开始日期',
      type: 'date',
      format: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
      style: {
        width: '100%',
      },
    },
  },
  {
    component: 'DatePicker',
    fieldName: 'processEndTime',
    label: '处理时间',
    componentProps: {
      placeholder: '请选择处理结束日期',
      type: 'date',
      format: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
      style: {
        width: '100%',
      },
    },
  },
  {
    component: 'ApiSelect',
    fieldName: 'position',
    label: '岗位',
    componentProps: {
      placeholder: '请选择岗位',
      clearable: true,
      api: getFilteredPositions,
      labelField: 'label',
      valueField: 'value',
    },
  },
  {
    component: 'Select',
    fieldName: 'isComment',
    label: '评论',
    componentProps: {
      placeholder: '请选择评论状态',
      options: [
        { label: '未评', value: 0 },
        { label: '已评', value: 1 },
      ],
    },
  },
  {
    component: 'Select',
    fieldName: 'createType',
    label: '创建',
    componentProps: {
      placeholder: '请选择创建方式',
      options: [
        { label: '系统', value: 0 },
        { label: '新增', value: 1 },
      ],
    },
  },
  {
    component: 'Input',
    fieldName: 'executorName',
    label: '执行人',
    componentProps: {
      placeholder: '请输入执行人',
    },
  },
  {
    component: 'Input',
    fieldName: 'taskName',
    label: '任务名称',
    componentProps: {
      placeholder: '请输入任务名称',
    },
  },
];


export const tableColumns: VxeGridProps['columns'] = [
  {
    type: 'checkbox',
    width: 80,
  },
  {
    field: 'taskName',
    title: '任务名称',
    minWidth: 150,
  },
  {
    field: 'stationName',
    title: '油站',
    minWidth: 120,
  },
  {
    field: 'attachmentName',
    title: '附件名称',
    minWidth: 150,
  },
  {
    field: 'executorName',
    title: '执行人',
    minWidth: 120,
  },
  {
    field: 'position',
    title: '岗位',
    minWidth: 120,
  },
  {
    field: 'isComment',
    title: '评论',
    minWidth: 100,
    align: 'center',
    formatter: (cellValue: number) => {
      return cellValue === 1 ? '已评' : '未评';
    },
  },
  {
    field: 'deadline',
    title: '截止时间',
    minWidth: 180,
  },
  {
    field: 'processTime',
    title: '处理时间',
    minWidth: 180,
  },
  {
    field: 'completionStatus',
    title: '完成状态',
    minWidth: 120,
    align: 'center',
    formatter: ({ row }) => {
      return row.completionStatus === 2 ? '按时完成' : '逾期完成';
    },
  },
  {
    field: 'createType',
    title: '创建',
    minWidth: 100,
    align: 'center',
    formatter: (cellValue: number) => {
      return cellValue === 0 ? '系统' : '新增';
    },
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    width: 150,
  },
];

