import { DescItem } from '/@/components/Description';
import { BasicColumn, FormSchema } from '/@/components/Table';
import { radioBoolean } from '/@/utils/filters';

export const columns: BasicColumn[] = [
  {
    title: '配置名称',
    dataIndex: 'name',
  },
  {
    title: '主配置',
    dataIndex: 'master',
  },
  {
    title: '存储类型',
    dataIndex: 'type',
  },
];

// 表单列定义
export const searchFormSchema: FormSchema[] = [
  {
    label: '配置名称',
    field: 'name',
    component: 'Input',
    componentProps: {
      placeholder: '请输入配置名称',
    },
  },
  {
    label: '存储类型',
    field: 'type',
    component: 'Select',
    componentProps: {
      placeholder: '请选择存储类型',
      options: [
        {
          label: '阿里云',
          value: 'ali',
        },
        {
          label: '数据库',
          value: 'db',
        },
        {
          label: '本地存储',
          value: 'local',
        },
        {
          label: 'minio存储',
          value: 'minio',
        },
      ],
    },
  },
];
// 表单新增编辑
export const dataFormSchema: FormSchema[] = [
  {
    label: '配置名称',
    field: 'name',
    required: true,
    component: 'Input',
    componentProps: {
      placeholder: '请输入配置名称',
    },
  },
  {
    label: '主配置',
    field: 'master',
    required: true,
    component: 'RadioGroup',
    componentProps: {
      placeholder: '请输入主配置',
      options: radioBoolean,
      disabled: false,
    },
    defaultValue: 0,
  },
  {
    label: '存储类型',
    field: 'type',
    component: 'Select',
    required: true,
    componentProps: {
      placeholder: '请选择存储类型',
      options: [
        {
          label: '阿里云',
          value: 'ali',
        },
        {
          label: '数据库',
          value: 'db',
        },
        {
          label: '本地存储',
          value: 'local',
        },
        {
          label: 'minio存储',
          value: 'minio',
        },
      ],
    },
  },
  {
    label: '配置参数',
    helpMessage: '配置参数',
    field: 'configDividers',
    component: 'Divider',
    ifShow: ({ values }) => {
      return values.type;
    },
    helpComponentProps: {
      fontSize: '16px',
    },
  },
  /**
   * 阿里云配置
   */
  {
    label: '密令',
    field: 'config.aliAccessKey',
    required: true,
    component: 'Input',
    ifShow: ({ values }) => {
      return values.type == 'ali';
    },
    componentProps: {
      placeholder: '请输入密令',
    },
  },
  {
    label: '密钥',
    field: 'config.aliAccessSecret',
    required: true,
    component: 'Input',
    ifShow: ({ values }) => {
      return values.type == 'ali';
    },
    componentProps: {
      placeholder: '请输入密钥',
    },
  },
  {
    label: '地域节点',
    field: 'config.aliEndpoint',
    required: true,
    component: 'Input',
    ifShow: ({ values }) => {
      return values.type == 'ali';
    },
    componentProps: {
      placeholder: '请输入地域节点',
    },
  },
  {
    label: '桶名称',
    field: 'config.aliBucketName',
    required: true,
    component: 'Input',
    ifShow: ({ values }) => {
      return values.type == 'ali';
    },
    componentProps: {
      placeholder: '请输入桶名称',
    },
  },
  /**
   * 数据库配置
   */
  {
    label: '自定义域名',
    field: 'config.dbDomain',
    required: true,
    component: 'Input',
    ifShow: ({ values }) => {
      return values.type == 'db';
    },
    componentProps: {
      placeholder: '请输入自定义域名',
    },
  },
  /**
   * 本地配置
   */
  {
    label: '基础路径',
    field: 'config.localBasePath',
    required: true,
    component: 'Input',
    ifShow: ({ values }) => {
      return values.type == 'local';
    },
    componentProps: {
      placeholder: '请输入基础路径',
    },
  },
  {
    label: '自定义域名',
    field: 'config.localDomain',
    required: true,
    component: 'Input',
    ifShow: ({ values }) => {
      return values.type == 'local';
    },
    componentProps: {
      placeholder: '请输入自定义域名',
    },
  },
  /**
   * minio配置
   */
  {
    label: '上传地址',
    field: 'config.minioHttpUrl',
    required: true,
    component: 'Input',
    ifShow: ({ values }) => {
      return values.type == 'minio';
    },
    componentProps: {
      placeholder: '请输入上传地址',
    },
  },
  {
    label: '密令',
    field: 'config.minioAccessKey',
    required: true,
    component: 'Input',
    ifShow: ({ values }) => {
      return values.type == 'minio';
    },
    componentProps: {
      placeholder: '请输入密令',
    },
  },
  {
    label: ' 密钥',
    field: 'config.minioAccessSecret',
    required: true,
    component: 'Input',
    ifShow: ({ values }) => {
      return values.type == 'minio';
    },
    componentProps: {
      placeholder: '请输入密钥',
    },
  },
  {
    label: '桶名称',
    field: 'config.minioBucketName',
    required: true,
    component: 'Input',
    ifShow: ({ values }) => {
      return values.type == 'minio';
    },
    componentProps: {
      placeholder: '请输入桶名称',
    },
  },
  {
    label: '备注',
    helpMessage: '备注',
    field: 'remarkDividers',
    component: 'Divider',
    helpComponentProps: {
      fontSize: '16px',
    },
  },
  {
    label: '备注',
    field: 'remark',
    component: 'InputTextArea',
    componentProps: {
      placeholder: '请输入备注',
    },
  },
];
// 表单详情查看
export const viewSchema: DescItem[] = [
  {
    label: '配置名称',
    field: 'name',
  },
  {
    label: '主配置',
    field: 'master',
  },
  {
    label: '存储类型',
    field: 'types',
  },
  /**
   * 阿里云配置
   */
  {
    label: '密令',
    field: 'config.aliAccessKey',
    show: ({ ...values }) => {
      return values.type == 'ali';
    },
  },
  {
    label: '密钥',
    field: 'config.aliAccessSecret',
    show: ({ ...values }) => {
      return values.type == 'ali';
    },
  },
  {
    label: '地域节点',
    field: 'config.aliEndpoint',
    show: ({ ...values }) => {
      return values.type == 'ali';
    },
  },
  {
    label: '桶名称',
    field: 'config.aliBucketName',
    show: ({ ...values }) => {
      return values.type == 'ali';
    },
  },
  /**
   * 数据库配置
   */
  {
    label: '自定义域名',
    field: 'config.dbDomain',
    show: ({ ...values }) => {
      return values.type == 'db';
    },
  },
  /**
   * 本地配置
   */
  {
    label: '基础路径',
    field: 'config.localBasePath',
    show: ({ ...values }) => {
      return values.type == 'local';
    },
  },
  {
    label: '自定义域名',
    field: 'config.localDomain',
    show: ({ ...values }) => {
      return values.type == 'local';
    },
  },
  /**
   * minio配置
   */
  {
    label: '上传地址',
    field: 'config.minioHttpUrl',
    show: ({ ...values }) => {
      return values.type == 'minio';
    },
  },
  {
    label: '密令',
    field: 'config.minioAccessKey',
    show: ({ ...values }) => {
      return values.type == 'minio';
    },
  },
  {
    label: ' 密钥',
    field: 'config.minioAccessSecret',
    show: ({ ...values }) => {
      return values.type == 'minio';
    },
  },
  {
    label: '桶名称',
    field: 'config.minioBucketName',
    show: ({ ...values }) => {
      return values.type == 'minio';
    },
  },
  {
    label: '备注',
    field: 'remark',
  },
];
