import type {
  ProColumns,
  ProFormColumnsType,
} from '@ant-design/pro-components';
import dayjs from 'dayjs';
import type { TenantPackageVO } from '@/services/system/tenant/package';

export const baseTenantColumns: ProColumns<TenantPackageVO>[] = [
  {
    title: '套餐编号',
    dataIndex: 'id',
    width: 100,
    hideInSearch: true, // 在搜索表单中隐藏
  },
  {
    title: '套餐名',
    dataIndex: 'name',
  },
  {
    title: '状态',
    dataIndex: 'status',
    valueType: 'select',
    valueEnum: {
      all: { text: '全部', status: 'Default' },
      open: { text: '未解决', status: 'Error' },
      closed: { text: '已解决', status: 'Success' },
    },
  },
  {
    title: '备注',
    dataIndex: 'remark',
    hideInSearch: true, // 在搜索表单中隐藏
  },
  {
    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: TenantPackageVO) =>
      dayjs(record.createTime).format('YYYY-MM-DD HH:mm:ss'),
  },
];

export const formColumns = (_type: string): ProFormColumnsType[] => [
  {
    title: '套餐名',
    dataIndex: 'name',
    formItemProps: {
      rules: [
        {
          required: true,
          message: '请输入用户名',
        },
      ],
    },
  },
  {
    title: '套餐权限',
    dataIndex: 'menuIds',
    valueType: 'treeSelect',
    fieldProps: {
      multiple: true,
      placeholder: '请选择租户权限',
      options: [{ lable: '11', value: 5016 }],
    },
  },
  {
    title: '租户状态',
    dataIndex: 'status',
    valueType: 'radio',
    formItemProps: {
      rules: [
        {
          required: true,
          message: '请选择租户状态',
        },
      ],
    },
    fieldProps: {
      placeholder: '请选择套餐类型',
      options: [
        {
          label: '开启',
          value: 1,
        },
        {
          label: '关闭',
          value: 0,
        },
      ],
    },
  },
  {
    title: '备注',
    dataIndex: 'remark',
    valueType: 'textarea',
  },
];
