/**
 * 项目：-
 * 模型分组：系统管理
 * 模型名称：配置表
 * @Author: xiongwei
 * @Date: 2022-06-28 11:50:00
 */

import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import get from 'lodash.get';


const colProps = { xs: { span: 24 }, sm: { span: 24 }, lg: { span: 8 } };
const colPropsInDrawer = { span: 24 };

export const schema = {
  model: 'Setting',
  viewInPage: false,
  properties: [
    {
      field: 'id',
      label: 'ID系统自动生成',
      defaultValue: undefined,
      form: {
        componentProps: {
          allowClear: false,
          placeholder: 'ID系统自动生成',
        },
        colProps,
        component: 'InputNumber',
        rules: [{ required: true, message: '请输入ID系统自动生成！' }],
      },
      table: {
      },
    },
    {
      field: 'code',
      label: 'Code',
      defaultValue: undefined,
      form: {
        componentProps: {
          allowClear: false,
          placeholder: 'Code',
        },
        colProps,
        component: 'Input',
        rules: [{ required: true, message: '请输入Code！' }],
      },
      table: {
      },
    },
    {
      field: 'value',
      label: 'Value',
      defaultValue: undefined,
      form: {
        componentProps: {
          allowClear: false,
          placeholder: 'Value',
        },
        component: 'InputTextArea',
        colProps: { span: 24 },
        rules: [{ required: true, message: '请输入Value！' }],
      },
      table: {
      },
    },
    {
      field: 'remark',
      label: '说明',
      defaultValue: undefined,
      form: {
        componentProps: {
          allowClear: true,
          placeholder: '说明',
        },
        colProps,
        component: 'Input',
      },
      table: {
      },
    },
    {
      field: 'createTime',
      label: '创建时间',
      defaultValue: undefined,
      form: {
        colProps,
        componentProps: {
          allowClear: false,
          placeholder: ['开始时间', '结束时间'],
          format: 'YYYY-MM-DD',
          showTime: false,
        },
        component: 'RangePicker',
        rules: [{ required: true, message: '请输入创建时间！' }],
      },
      table: {
      },
    },
    {
      field: 'updateTime',
      label: '更新时间',
      defaultValue: undefined,
      form: {
        colProps,
        componentProps: {
          allowClear: false,
          placeholder: ['开始时间', '结束时间'],
          format: 'YYYY-MM-DD',
          showTime: false,
        },
        component: 'RangePicker',
        rules: [{ required: true, message: '请输入更新时间！' }],
      },
      table: {
      },
    },
  ],
};

const queryFields = ['id','code','remark','createTime','updateTime'];
const editFields = ['code','value','remark'];
const tableFields = ['id','code','value','remark','createTime','updateTime'];
const descriptionFields = ['id','code','value','remark','createTime','updateTime'];

export const searchFormSchema: FormSchema[] = schema.properties.filter(item => queryFields.includes(item.field))
  .map(
    ({ field, label, form: { rules = [], ...formProps } }) =>
      ({
        field,
        label,
        defaultValue: undefined,
        rules: rules.filter((r) => !r.required),
        ...formProps,
      } as FormSchema),
  );

export const formSchema: FormSchema[] = schema.properties.filter(item => editFields.includes(item.field))
  .map(
    ({ field, label, defaultValue, form }) =>
      ({
        field,
        label,
        defaultValue,
        ...form,
        colProps: colPropsInDrawer,
      } as FormSchema),
  );

export const columns: BasicColumn[] = schema.properties.filter(item => tableFields.includes(item.field))
  .map(
    ({ field, label, table }) =>
      ({
        dataIndex: field,
        title: label,
        ...table,
      } as BasicColumn)
  );

export const descriptionColumns: BasicColumn[] = schema.properties.filter(item => descriptionFields.includes(item.field))
  .map(
    ({ field, label, table }) =>
      ({
        dataIndex: field,
        title: label,
        ...table,
      } as BasicColumn),
  );
