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: 'amount',
    width: 130,
    sorter: true,
  },
  {
    title: '创建日期',
    dataIndex: 'createtime',
    width: 160,
    customRender({ record }) {
      return moment(record.createtime * 1000).format('YYYY-MM-DD HH:mm:ss');
    },
    sorter: true,
  },
  {
    title: '备注',
    dataIndex: 'remark',
    width: 200,
    sorter: true,
  },
];
export const info_columns: BasicColumn[] = [
  // {
  //   title: 'ID',
  //   dataIndex: 'id',
  //   width: 160,
  // },
  {
    title: '交易名称',
    dataIndex: 'typename',
    width: 160,
  },
  {
    title: '资金增减',
    dataIndex: 'type',
    width: 120,
    customRender({ record }) {
      const options = ['支出', '收入'];
      return options[record.type];
    },
  },
  {
    title: '金额',
    dataIndex: 'money',
    width: 120,
  },
  {
    title: '相关会员',
    dataIndex: 'member',
    width: 140,
  },
  {
    title: '交易日期',
    dataIndex: 'tradetime',
    width: 200,
    customRender({ record }) {
      return moment(record.tradetime).format('YYYY-MM-DD');
    },
  },
  {
    title: '备注',
    dataIndex: 'remark',
    width: 160,
  },
];

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: `amount`,
        label: `余额`,
        component: 'Input',
        componentProps: {
          placeholder: '余额',
        },
        colProps: {
          xl: 12,
          xxl: 8,
        },
      },
      {
        field: `createdate`,
        label: `创建日期`,
        component: 'DatePicker',
        componentProps: {
          placeholder: '创建日期',
        },
        colProps: {
          xl: 12,
          xxl: 8,
        },
      },
      {
        field: `remark`,
        label: `备注`,
        component: 'Input',
        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: 'amount',
    component: 'Input',
    label: '余额',
    labelWidth: adaptWidth.labelWidth,
    colProps: {
      span: adaptWidth.elContainer,
    },
    componentProps: {
      placeholder: '余额',
      type: 'number',
    },
  },
  {
    field: 'remark',
    component: 'Input',
    label: '备注',
    labelWidth: adaptWidth.labelWidth,
    colProps: {
      span: adaptWidth.elContainer,
    },
    componentProps: {
      placeholder: '备注',
    },
  },
];
