import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { HrmLeaveTypeConfigApi } from '#/api/hrm/leave-type-config';

/** 表单类型 */
export type FormType = 'update';

/** 新增/修改请假扣款配置的表单 */
export function useFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'name',
      label: '请假类型',
      component: 'Input',
      componentProps: {
        disabled: true,
        placeholder: '',
      },
      formItemClass: 'col-span-2',
    },
    {
      fieldName: 'deductionRatio',
      label: '扣款比例',
      component: 'InputNumber',
      componentProps: {
        placeholder: '请输入扣款比例',
        min: 0,
        max: 100,
        step: 10,
        precision: 0,
        formatter: (value: number) => `${value}%`,
        parser: (value: string) => parseFloat(value.replace('%', '')),
        style: { width: '100%' },
      },
      rules: 'required',
      help: '扣款比例，如50%表示按一半扣款',
    },
    {
      fieldName: 'status',
      label: '状态',
      component: 'RadioGroup',
      componentProps: {
        options: [
          { label: '启用', value: 0 },
          { label: '禁用', value: 1 },
        ],
      },
      rules: 'required',
    },
    {
      fieldName: 'remark',
      label: '备注',
      component: 'Textarea',
      componentProps: {
        placeholder: '请输入备注',
        rows: 2,
      },
      formItemClass: 'col-span-2',
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions<HrmLeaveTypeConfigApi.LeaveTypeConfig>['columns'] {
  return [
    { field: 'name', title: '请假类型', minWidth: 120 },
    {
      field: 'deductionRatio',
      title: '扣款比例',
      width: 120,
      slots: { default: 'deductionRatio' },
    },
    { field: 'remark', title: '备注', minWidth: 200 },
    {
      field: 'status',
      title: '状态',
      width: 80,
      slots: { default: 'status' },
    },
    {
      field: 'createTime',
      title: '创建时间',
      width: 180,
      formatter: 'formatDateTime',
    },
    {
      title: '操作',
      width: 100,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}