import { listDictModel } from '/@/api/common';
import { smsChannelQueryPage } from '/@/api/sys/smsChannelApi';
import { DescItem } from '/@/components/Description';
import { BasicColumn, FormSchema } from '/@/components/Table';
import { validateStr } from '/@/utils/validate';

export const columns: BasicColumn[] = [
  {
    title: '模板编码',
    dataIndex: 'code',
  },
  {
    title: '模板名称',
    dataIndex: 'name',
  },
  {
    title: '创建类型',
    dataIndex: 'createType',
  },
  {
    title: '短信渠道',
    dataIndex: 'channelName',
  },
  {
    title: '模板类型',
    dataIndex: 'tempType',
  },

  {
    title: 'API模板编号',
    dataIndex: 'apiTempCode',
  },
  // {
  //   title: '状态',
  //   dataIndex: 'disable',
  // },
];

// 表单列定义
export const searchFormSchema: FormSchema[] = [
  {
    label: '模板类型',
    field: 'tempType',
    component: 'ApiSelect',
    componentProps: {
      api: listDictModel,
      params: {
        dictCode: 'sys_temp_type',
      },
    },
  },
];
// 表单新增编辑
export const dataFormSchema: FormSchema[] = [
  {
    label: '模板编码',
    field: 'code',
    required: true,
    component: 'Input',
    componentProps: {
      placeholder: '请输入模板编码',
    },
    dynamicRules: () => {
      return [
        {
          required: true,
          validator: async (_, value) => {
            if (!value) {
              return Promise.reject('模板编码不能为空');
            }
            if (validateStr(value)) {
              return Promise.reject('模板编码为字母或数字组成');
            }
            return Promise.resolve();
          },
        },
      ];
    },
  },
  {
    label: '模板名称',
    field: 'name',
    required: true,
    component: 'Input',
    componentProps: {
      placeholder: '请输入模板名称',
    },
  },
  {
    label: '短信渠道',
    field: 'channelId',
    required: true,
    component: 'ApiSelect',
    componentProps: {
      api: smsChannelQueryPage,
      params: {
        pageNum: 1,
        pageSize: 999,
        disable: '0',
      },
      mode: 'single',
      labelField: 'name',
      valueField: 'id',
      resultField: 'data',
      placeholder: '请选择短信渠道',
    },
  },
  {
    label: '模板类型',
    required: true,
    field: 'tempType',
    component: 'ApiSelect',
    componentProps: {
      api: listDictModel,
      params: {
        dictCode: 'sys_temp_type',
      },
    },
  },

  {
    label: '模板内容',
    field: 'content',
    required: true,
    component: 'InputTextArea',
    componentProps: {
      placeholder: '请输入模板内容',
    },
  },
  {
    label: 'API模板编号',
    field: 'apiTempCode',
    required: true,
    component: 'Input',
    componentProps: {
      placeholder: '请输入短信API模板编号',
    },
  },
  // {
  //   label: '状态',
  //   field: 'disable',
  //   required: true,
  //   component: 'ApiRadioGroup',
  //   componentProps: {
  //     api: listDictModel,
  //     params: {
  //       dictCode: 'sys_disable_type',
  //     },
  //   },
  //   defaultValue: '0',
  // },
  {
    label: '备注',
    field: 'remark',
    component: 'InputTextArea',
    componentProps: {
      placeholder: '请输入备注',
    },
  },
];
// 表单详情查看
export const viewSchema: DescItem[] = [
  {
    label: '模板编码',
    field: 'code',
  },
  {
    label: '模板名称',
    field: 'name',
  },
  {
    label: '短信渠道',
    field: 'channelName',
  },
  {
    label: '创建类型',
    field: 'createType',
  },
  {
    label: '模板类型',
    field: 'tempType',
  },

  {
    label: '模板内容',
    field: 'content',
  },
  {
    label: 'API模板编号',
    field: 'apiTempCode',
  },
  // {
  //   label: '状态',
  //   field: 'disable',
  // },
  {
    label: '备注',
    field: 'remark',
  },
];

export const dataSendFormSchema: FormSchema[] = [
  {
    label: '手机号码',

    field: 'mobile',
    required: true,
    component: 'InputTextArea',
    componentProps: {
      placeholder: '请输入手机号码,多号码以 , 隔开',
    },
  },
  // {
  //   label: '模板编码',
  //   field: 'templateCode',
  //   required: true,
  //   component: 'Input',
  //   componentProps: {
  //     placeholder: '请输入模板编码',
  //   },
  // },
  {
    label: '模板参数',
    helpMessage: '模板对应变量参数',
    field: 'codeDividers',
    component: 'Divider',
    helpComponentProps: {
      fontSize: '16px',
    },
  },
];
