import { FormProps, BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Form/index';
import { adapt } from '/@/utils/adapt';
import moment from 'moment';

const adaptWidth = adapt();

export const columns: BasicColumn[] = [
  {
    title: 'ID',
    dataIndex: 'id',
    editComponentProps: {
      prefix: '$',
    },
    width: 100,
    sorter: true,
  },
  {
    title: '交易名称',
    dataIndex: 'name',
    width: 130,
    sorter: true,
  },
  {
    title: '收支类型',
    dataIndex: 'type',
    width: 130,
    customRender({ record }) {
      const options = ['支出', '收入', '内部转账'];
      return options[record.type];
    },
    sorter: true,
  },
  {
    title: '操作人',
    dataIndex: 'people',
    width: 150,
    sorter: true,
  },
  {
    title: '备注',
    dataIndex: 'remark',
    width: 200,
    sorter: true,
  },
  {
    title: '创建日期',
    dataIndex: 'createTime',
    width: 200,
    customRender({ record }) {
      return moment(record.createTime).format('YYYY-MM-DD');
    },
    sorter: true,
  },
];

export function getFormConfig(): Partial<FormProps> {
  return {
    labelWidth: 100,
    schemas: [
      {
        field: `id`,
        label: `ID`,
        component: 'Input',
        componentProps: {
          placeholder: 'ID',
        },
        colProps: {
          xl: 12,
          xxl: 8,
        },
      },
      {
        field: `name`,
        label: `交易名称`,
        component: 'Input',
        componentProps: {
          placeholder: '交易名称',
        },
        colProps: {
          xl: 12,
          xxl: 8,
        },
      },
      {
        field: `type`,
        label: `收支类型`,
        component: 'Select',
        componentProps: {
          placeholder: '收支类型',
          options: [
            {
              label: '支出',
              value: 0,
            },
            {
              label: '收入',
              value: 1,
            },
            {
              label: '内部转账',
              value: 2,
            },
          ],
        },
        colProps: {
          xl: 12,
          xxl: 8,
        },
      },
      {
        field: `people`,
        label: `操作人`,
        component: 'Input',
        componentProps: {
          placeholder: '操作人',
        },
        colProps: {
          xl: 12,
          xxl: 8,
        },
      },
      {
        field: `remark`,
        label: `备注`,
        component: 'Input',
        componentProps: {
          placeholder: '备注',
        },
        colProps: {
          xl: 12,
          xxl: 8,
        },
      },
      {
        field: `createTime`,
        label: `创建时间`,
        component: 'DatePicker',
        componentProps: {
          placeholder: '创建时间',
        },
        colProps: {
          xl: 12,
          xxl: 8,
        },
      },
    ],
  };
}

// =================popup================================
export const schemas: FormSchema[] = [
  {
    field: 'name',
    component: 'Input',
    label: '交易名称',
    labelWidth: adaptWidth.labelWidth,
    colProps: {
      span: adaptWidth.elContainer,
    },
    componentProps: {
      placeholder: '交易名称',
    },
    required: true,
  },
  {
    field: 'type',
    component: 'Select',
    label: '收支类型',
    labelWidth: adaptWidth.labelWidth,
    colProps: {
      span: adaptWidth.elContainer,
    },
    componentProps: {
      placeholder: '收支类型',
      options: [
        {
          label: '支出',
          value: 0,
        },
        {
          label: '收入',
          value: 1,
        },
        {
          label: '内部转账',
          value: 2,
        },
      ],
    },
    required: true,
  },
  {
    field: 'remark',
    component: 'Input',
    label: '备注',
    labelWidth: adaptWidth.labelWidth,
    defaultValue: '',
    colProps: {
      span: adaptWidth.elContainer,
    },
    componentProps: {
      placeholder: '备注',
    },
  },
];
