import type { VbenFormSchema } from '@vben/common-ui';

import type { VxeGridProps } from '#/adapter/vxe-table';
import type { DescItem } from '#/components/description';

import { renderDict } from '#/utils';
import { getDictOptions } from '#/utils/dict';

// 表格搜索表单
export const IndexGridSchema: VbenFormSchema[] = [
  {
    fieldName: 'chanKey',
    component: 'Input',
    label: '通道编号',
    componentProps: {
      placeholder: '请输入通道编号',
    },
  },
  {
    fieldName: 'chanName',
    component: 'Input',
    label: '通道名称',
    componentProps: {
      placeholder: '请输入通道名称',
    },
  },
  {
    fieldName: 'chanStatus',
    component: 'Select',
    label: '通道状态',
    defaultValue: null,
    componentProps: {
      placeholder: '请选择通道状态',
      options: getDictOptions('sys_normal_disable', true),
    },
  },
];

// 表格列
export const IndexGridColumns: VxeGridProps['columns'] = [
  {
    type: 'checkbox',
    width: 50,
  },
  { title: 'ID', field: 'id', minWidth: 80 },
  {
    title: '通道编号',
    field: 'chanKey',
    minWidth: 120,
  },
  {
    title: '通道名称',
    field: 'chanName',
    minWidth: 120,
  },

  {
    title: '模板标识',
    field: 'tempName',
    minWidth: 120,
  },
  {
    title: '通道配置',
    field: 'chanConfig',
    minWidth: 120,
  },

  {
    title: '通道状态',
    field: 'chanStatus',
    minWidth: 120,
    slots: {
      default: ({ row }) => {
        return renderDict(row.chanStatus, 'sys_normal_disable');
      },
    },
  },
  {
    title: '通道行政区域代码(省市)',
    field: 'regionCode',
    minWidth: 120,
  },

  {
    title: '通道别名',
    field: 'chanAlias',
    minWidth: 120,
  },

  {
    title: '应用标识',
    field: 'appKey',
    minWidth: 120,
  },
  {
    title: '应用密钥',
    field: 'appSecret',
    minWidth: 120,
  },
  {
    title: '接口调用凭证',
    field: 'accessToken',
    minWidth: 120,
  },
  {
    title: '凭证申请时间',
    field: 'accessTokenCreated',
    minWidth: 120,
  },
  {
    title: '凭证过期时间',
    field: 'accessTokenExpire',
    minWidth: 120,
  },
  {
    title: '刷新凭证申请时间',
    field: 'refreshTokenCreated',
    minWidth: 120,
  },
  {
    title: '刷新凭证过期时间',
    field: 'refreshTokenExpire',
    minWidth: 120,
  },
  {
    title: '登录账号',
    field: 'loginUser',
    minWidth: 120,
  },
  {
    title: '登录密码',
    field: 'loginPassword',
    minWidth: 120,
  },
  {
    title: '登录状态',
    field: 'loginState',
    minWidth: 120,
    slots: {
      default: ({ row }) => {
        return renderDict(row.loginState, 'sys_normal_disable');
      },
    },
  },
  { title: '操作', width: 120, slots: { default: 'action' }, fixed: 'right' },
];

// 编辑字段列表
export const EditFormSchema: VbenFormSchema[] = [
  {
    fieldName: 'id',
    component: 'Input',
    label: 'ID',
    dependencies: { show: () => false, triggerFields: [''] },
    componentProps: {
      placeholder: '',
    },
  },
  {
    fieldName: 'tempKey',
    component: 'Select',
    label: '模板标识',
    componentProps: {
      placeholder: '请选择模板标识',
      options: [],
    },
    rules: 'required',
  },
  {
    fieldName: 'chanKey',
    component: 'Input',
    label: '通道编号',
    componentProps: {
      placeholder: '请输入通道编号',
    },
    rules: 'required',
  },
  {
    fieldName: 'chanName',
    component: 'Input',
    label: '通道名称',
    componentProps: {
      placeholder: '请输入通道名称',
    },
    rules: 'required',
  },
  {
    fieldName: 'chanConfig',
    component: 'Input',
    label: '通道配置',
    componentProps: {
      placeholder: '请输入通道配置',
    },
  },
  {
    fieldName: 'chanStatus',
    component: 'Select',
    label: '通道状态(0未启用,1启用)',
    defaultValue: null,
    componentProps: {
      placeholder: '请选择通道状态(0未启用,1启用)',
      options: getDictOptions('sys_normal_disable', true),
    },
  },
  {
    fieldName: 'chanAlias',
    component: 'Input',
    label: '通道别名',
    componentProps: {
      placeholder: '请输入通道别名',
    },
    rules: 'required',
  },
  {
    fieldName: 'regionCode',
    component: 'Input',
    label: '通道行政区域代码(省市)',
    componentProps: {
      placeholder: '请输入通道行政区域代码(省市)',
    },
  },
  {
    fieldName: 'appKey',
    component: 'Input',
    label: '应用标识',
    componentProps: {
      placeholder: '请输入应用标识',
    },
    rules: 'required',
  },
  {
    fieldName: 'appSecret',
    component: 'Input',
    label: '应用密钥',
    componentProps: {
      placeholder: '请输入应用密钥',
    },
    rules: 'required',
  },
  {
    fieldName: 'remark',
    component: 'Input',
    label: '备注',
    componentProps: {
      placeholder: '请输入备注',
    },
  },
  {
    fieldName: 'loginUser',
    component: 'Input',
    label: '登录账号',
    componentProps: {
      placeholder: '请输入登录账号',
    },
  },
  {
    fieldName: 'loginPassword',
    component: 'Input',
    label: '登录密码',
    componentProps: {
      placeholder: '请输入登录密码',
    },
  },
  {
    fieldName: 'loginUrl',
    component: 'Input',
    label: '登录地址',
    componentProps: {
      placeholder: '请输入登录地址',
    },
    rules: 'required',
  },
  {
    fieldName: 'loginState',
    component: 'Select',
    label: '登录状态(0未启用,1启用)',
    componentProps: {
      placeholder: '请输入登录状态(0未启用,1启用)',
      options: getDictOptions('sys_normal_disable', true),
    },
  },
];

// 查看字段列表
export const ViewDescSchema: DescItem[] = [
  { field: 'id', label: 'ID' },
  { field: 'tempKey', label: '模板标识' },
  { field: 'tempName', label: '模板名称' },
  { field: 'chanKey', label: '通道编号' },
  { field: 'chanName', label: '通道名称' },
  { field: 'chanConfig', label: '通道配置' },
  {
    field: 'chanStatus',
    label: '通道状态(0未启用,1启用)',
    render(chanStatus) {
      return renderDict(chanStatus, 'sys_normal_disable');
    },
  },
  { field: 'chanAlias', label: '通道别名' },
  { field: 'regionCode', label: '通道行政区域代码(省市)' },
  { field: 'appKey', label: '应用标识' },
  { field: 'appSecret', label: '应用密钥' },
  { field: 'accessToken', label: '接口调用凭证' },
  { field: 'accessTokenCreated', label: '凭证申请时间' },
  { field: 'accessTokenExpire', label: '凭证过期时间' },
  { field: 'refreshToken', label: '刷新凭证' },
  { field: 'refreshTokenCreated', label: '刷新凭证申请时间' },
  { field: 'refreshTokenExpire', label: '刷新凭证过期时间' },
  { field: 'remark', label: '备注' },
  { field: 'loginUser', label: '登录账号' },
  { field: 'loginPassword', label: '登录密码' },
  { field: 'loginUrl', label: '登录地址' },
  {
    field: 'loginState',
    label: '登录状态(0未启用,1启用)',
    render(loginState) {
      return renderDict(loginState, 'sys_normal_disable');
    },
  },
];
