import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';

import { getSimpleUserList } from '#/api/system/user';

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'bizName',
      label: '业务类型',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入业务类型名称',
      },
    },
    {
      fieldName: 'approvalEnabled',
      label: '是否启用',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: [
          { label: '已启用', value: true },
          { label: '未启用', value: false },
        ],
        placeholder: '请选择是否启用',
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions['columns'] {
  return [
    { field: 'bizName', title: '业务类型', minWidth: 160 },
    { field: 'bizType', title: '业务编码', minWidth: 200 },
    {
      field: 'approvalEnabled',
      title: '是否启用审批',
      width: 120,
      align: 'center',
      slots: { default: 'approvalEnabled' },
    },
    {
      field: 'userNames',
      title: '审批人',
      minWidth: 200,
      slots: { default: 'userNames' },
    },
    { field: 'remark', title: '备注', minWidth: 200 },
    { title: '操作', width: 140, fixed: 'right', slots: { default: 'actions' } },
  ];
}

/** 配置表单：业务类型 + 启用开关 + 审批人 */
export function useConfigFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'bizName',
      label: '业务类型',
      component: 'Input',
      componentProps: {
        disabled: true,
      },
    },
    {
      fieldName: 'bizType',
      label: '业务编码',
      component: 'Input',
      componentProps: {
        disabled: true,
      },
    },
    {
      fieldName: 'approvalEnabled',
      label: '启用审批',
      component: 'Switch',
      defaultValue: false,
      componentProps: {
        checkedChildren: '启用',
        unCheckedChildren: '停用',
      },
      help: '停用后该业务类型将无法提交审核',
    },
    {
      fieldName: 'userIds',
      label: '审批人',
      component: 'ApiSelect',
      componentProps: {
        api: getSimpleUserList,
        labelField: 'nickname',
        valueField: 'id',
        mode: 'multiple',
        allowClear: true,
        placeholder: '请选择审批人',
      },
      help: '可配置多个审批人，多个审批人之间为「或签」，即任意一人审核通过即为通过',
    },
    {
      fieldName: 'remark',
      label: '备注',
      component: 'Textarea',
      componentProps: {
        rows: 3,
        placeholder: '请输入备注',
      },
    },
  ];
}
