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

import { DictEnum } from '@vben/constants';

import { z } from '#/adapter/form';
import { queryGasStationList } from '#/api/schedule/index';
import { queryrclassesApilist } from '#/api/schedule/work/classes';
import { selectAllSysStationAreaList } from '#/api/system/infoEntry/stationInfo/stationInfo';
import { getPostList } from '#/api/system/post/post';
import { getDictOptions } from '#/utils/dict';
import { renderDictTag } from '#/utils/render';

export const querySchema: FormSchemaGetter = () => [
  {
    component: 'ApiSelect',
    componentProps: {
      api: selectAllSysStationAreaList,
      labelField: 'stationName',
      valueField: 'id',
      placeholder: '请选择油站',
      clearable: true,
    },
    fieldName: 'stationId',
    label: '油站',
  },
  {
    component: 'ApiSelect',
    componentProps: {
      api: queryrclassesApilist,
      labelField: 'shiftName',
      valueField: 'shiftName',
      placeholder: '请选择班次名称',
      clearable: true,
      resultField: 'rows',
    },
    fieldName: 'shiftName',
    label: '班次名称',
  },
  {
    component: 'ApiSelect',
    componentProps: {
      api: getPostList,
      labelField: 'postName',
      valueField: 'postId',
      placeholder: '请选择岗位',
      resultField: 'rows',
      clearable: true,
    },
    fieldName: 'position',
    label: '岗位',
  },
  {
    component: 'DatePicker',
    componentProps: {
      type: 'datetime',
      format: 'YYYY-MM-DD HH:mm:ss',
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
      placeholder: '选择时间',
    },
    fieldName: 'startTime',
    label: '上班时间',
  },
  // {
  //   component: 'Input',
  //   fieldName: 'employeeName',
  //   label: '姓名',
  // },
  {
    component: 'Select',
    componentProps: { options: getDictOptions(DictEnum.WORK_CONTENT) },
    fieldName: 'workContent',
    label: '上班内容',
  },
];
export const columns: VxeGridProps['columns'] = [
  // {
  //   title: '姓名',
  //   field: 'employeeName',
  //   minWidth: 130,
  // },
  {
    title: '工号',
    field: 'employeeNo',
    minWidth: 130,
  },
  {
    title: '岗位',
    field: 'positionName',
    // slots: { default: ({ row }) => row.position },
    minWidth: 130,
  },
  {
    title: '上班日期',
    field: 'workDate',
    minWidth: 130,
  },
  {
    title: '班次名称',
    field: 'shiftName',
    minWidth: 130,
  },
  {
    title: '上班时间',
    field: 'startTime',
    minWidth: 130,
  },
  {
    title: '下班时间',
    field: 'endTime',
    minWidth: 130,
  },
  {
    title: '上班时长',
    field: 'duration',
    minWidth: 130,
  },
  {
    title: '上班内容',
    field: 'workContentName',
    minWidth: 130,
  },
  {
    title: '油站',
    field: 'stationName',
    minWidth: 130,
  },
  {
    title: '状态',
    field: 'status',
    minWidth: 130,
    slots: {
      default: ({ row }) => {
        return renderDictTag(row.status.toString(), [
          { dictLabel: '未确认', dictValue: 0 },
          { dictLabel: '已确认', dictValue: 1 },
        ]);
      },
    },
  },
];
export const drawerFormSchema: FormSchemaGetter = () => [
  {
    component: 'ApiSelect',
    componentProps: {
      api: queryGasStationList,
      labelField: 'stationName',
      valueField: 'stationId',
      placeholder: '请选择油站',
    },
    fieldName: 'stationId',
    label: '油站',
    rules: 'required',
  },
  {
    component: 'ApiSelect',
    componentProps: {
      api: queryGasStationList,
      labelField: 'nickName',
      valueField: 'userId',
      placeholder: '请输入员工ID',
    },
    fieldName: 'employeeId',
    label: '员工ID',
    rules: 'required',
  },
  {
    component: 'ApiSelect',
    componentProps: {
      api: queryrclassesApilist,
      labelField: 'shiftName',
      valueField: 'shiftName',
      placeholder: '请选择班次名称',
      resultField: 'rows',
    },
    fieldName: 'shiftName',
    label: '班次名称',
    rules: 'required',
  },
  {
    component: 'ApiSelect',
    componentProps: {
      api: getPostList,
      labelField: 'postName',
      valueField: 'postId',
      placeholder: '请选择岗位',
      resultField: 'rows',
    },
    fieldName: 'position',
    label: '岗位',
    rules: 'required',
  },
  {
    component: 'DatePicker',
    componentProps: {
      type: 'date',
      format: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
      placeholder: '选择日期',
    },
    fieldName: 'workDate',
    label: '上班日期',
    rules: 'required',
  },
  {
    component: 'DatePicker',
    componentProps: {
      type: 'datetime',
      format: 'YYYY-MM-DD HH:mm:ss',
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
      placeholder: '选择上班时间',
    },
    fieldName: 'startTime',
    label: '上班时间',
    rules: 'required',
  },
  {
    component: 'DatePicker',
    componentProps: {
      type: 'datetime',
      format: 'YYYY-MM-DD HH:mm:ss',
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
      placeholder: '选择下班时间',
    },
    fieldName: 'endTime',
    label: '下班时间',
    rules: 'required',
  },
  {
    component: 'InputNumber',
    componentProps: {
      placeholder: '请输入上班时长(小时)',
      min: 0,
      step: 0.5,
      precision: 1,
    },
    fieldName: 'duration',
    label: '上班时长',
    rules: z
      .number()
      .min(0.5, '上班时长不能少于0.5小时')
      .max(24, '上班时长不能超过24小时'),
  },
  // {
  //   component: 'Input',
  //   componentProps: {
  //     placeholder: '请输入员工ID',
  //     required: true,
  //     type: 'number',
  //   },
  //   fieldName: 'employeeId',
  //   label: '员工ID',
  // },
  // {
  //   component: 'Input',
  //   componentProps: {
  //     placeholder: '请输入姓名',
  //   },
  //   fieldName: 'employeeName',
  //   label: '姓名',
  //   rules: z
  //     .string()
  //     .trim()
  //     .min(1, '请输入姓名')
  //     .max(20, '姓名长度不能超过20个字符'),
  // },
  {
    component: 'Input',
    componentProps: {
      placeholder: '请输入工号',
    },
    fieldName: 'employeeNo',
    label: '工号',
    rules: z
      .string()
      .trim()
      .min(1, '请输入工号')
      .max(20, '工号长度不能超过20个字符'),
  },
  {
    component: 'RadioGroup',
    componentProps: {
      options: [
        { label: '未确认', value: 0 },
        { label: '已确认', value: 1 },
      ],
    },
    fieldName: 'status',
    label: '状态',
    defaultValue: 0,
    rules: 'required',
  },
  {
    component: 'Select',
    componentProps: {
      options: getDictOptions(DictEnum.WORK_CONTENT),
      placeholder: '请选择上班内容',
    },
    fieldName: 'workContent',
    label: '上班内容',
    rules: 'required',
  },
];
