import type {
  ProColumns,
  ProFormColumnsType,
} from '@ant-design/pro-components';
import { Tag } from 'antd';
import dayjs from 'dayjs';
import { tenantStatus } from '@/constants';
import type { DeptVO } from '@/services/system/dept';
import { getStatusLabel } from '@/utils/constant';

export const baseDeptColumns: ProColumns<DeptVO>[] = [
  {
    title: '部门名称',
    dataIndex: 'name',
    ellipsis: true,
    hideInSearch: true,
  },
  // { prop: "leaderUserId", label: "负责人", width: 100 },
  {
    title: '负责人',
    dataIndex: 'leaderUserId',
    hideInSearch: true,
  },
  // { prop: "sort", label: "排序", width: 100 },
  {
    title: '排序',
    dataIndex: 'sort',
    hideInSearch: true,
  },
  // {
  //     prop: "status",
  //     label: "状态",
  //     width: 100,
  //     render: (record) => (
  //       <ElTag type={record.status == 1 ? "info" : "primary"}>
  //         {getStatusLabel(tenantStatus, record.status)}
  //       </ElTag>
  //     )
  //   },
  {
    title: '状态',
    dataIndex: 'status',
    hideInSearch: true,
    render: (_, record: DeptVO) => [
      <Tag
        key={record.status}
        color={record.status === 1 ? 'default' : 'processing'}
      >
        {getStatusLabel(tenantStatus, record.status)}
      </Tag>,
    ],
  },
  //   {
  //     prop: "createTime",
  //     label: "创建时间",
  //     width: 160,
  //     render: (row) => dateFormatter(row.createTime)
  //   },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    valueType: 'dateRange',
    search: {
      transform: (value) => {
        return {
          'createTime[0]': dayjs(value[0])
            .startOf('day')
            .format('YYYY-MM-DD HH:mm:ss'),
          'createTime[1]': dayjs(value[1])
            .endOf('day')
            .format('YYYY-MM-DD HH:mm:ss'),
        };
      },
    },
    render: (_, record: DeptVO) =>
      dayjs(record.createTime).format('YYYY-MM-DD HH:mm:ss'),
  },
];

export const formColumns = (_type: string): ProFormColumnsType[] => [
  {
    title: '上级部门',
    dataIndex: 'parentId',
    valueType: 'treeSelect',
    fieldProps: () => {
      return {
        multiple: true,
        placeholder: '请选择上级部门',
        options: [{ label: '11', value: 5016 }],
      };
    },
  },
  {
    title: '部门名称',
    dataIndex: 'name',
    valueType: 'text',
    formItemProps: {
      rules: [
        {
          required: true,
          message: '请输入部门名称',
        },
      ],
    },
  },
  {
    title: '显示顺序',
    dataIndex: 'sort',
    valueType: 'digit',
    fieldProps: {
      min: 0,
    },
    formItemProps: {
      rules: [
        {
          required: true,
          message: '请输入显示顺序',
        },
      ],
    },
  },
  {
    title: '负责人',
    dataIndex: 'leaderUserId',
    formItemProps: {
      rules: [
        {
          required: true,
          message: '请选择负责人',
        },
      ],
    },
  },
  {
    title: '邮箱',
    dataIndex: 'email',
    formItemProps: {
      rules: [
        {
          required: true,
          message: '请输入邮箱',
        },
      ],
    },
  },
  {
    title: '状态',
    dataIndex: 'status',
    valueType: 'select',
    fieldProps: {
      options: [
        {
          label: '正常',
          value: 1,
        },
        {
          label: '禁用',
          value: 2,
        },
      ],
    },
    formItemProps: {
      rules: [
        {
          required: true,
        },
      ],
    },
  },
];
