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: 'inOut',
    width: 130,
    customRender({ record }) {
      const options = ['错误', '收入', '支出', '内部转账'];
      return options[record.inOut];
    },
    sorter: true,
  },
  {
    title: '备注',
    dataIndex: 'remark',
    width: 160,
    sorter: true,
  },
  {
    title: '创建日期',
    dataIndex: 'createdate',
    width: 200,
    customRender({ record }) {
      return moment(record.createdate).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: `inOut`,
        label: `收支类型`,
        component: 'Select',
        componentProps: {
          options: [
            {
              label: '收入',
              value: 1,
            },
            {
              label: '支出',
              value: 2,
            },
            {
              label: '内部转账',
              value: 3,
            },
          ],
        },
        colProps: {
          xl: 12,
          xxl: 8,
        },
      },
      {
        field: `remark`,
        label: `备注`,
        component: 'InputTextArea',
        componentProps: {
          placeholder: '备注',
        },
        colProps: {
          xl: 12,
          xxl: 8,
        },
      },
      {
        field: `createdate`,
        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: 'inOut',
    component: 'Select',
    label: '收支类型',
    labelWidth: adaptWidth.labelWidth,
    colProps: {
      span: adaptWidth.elContainer,
    },
    componentProps: {
      placeholder: '收支类型',
      options: [
        {
          label: '收入',
          value: 1,
        },
        {
          label: '支出',
          value: 2,
        },
        {
          label: '内部转账',
          value: 3,
        },
      ],
    },
    required: true,
  },
  {
    field: 'remark',
    component: 'InputTextArea',
    label: '备注',
    labelWidth: adaptWidth.labelWidth,
    colProps: {
      span: adaptWidth.elContainer,
    },
    componentProps: {
      placeholder: '备注',
    },
  },
];
