import { useUserStore } from '@/store/user'
import { ListFormOption } from '@/types'
import { DictTypeDic } from '@/enums/upms/dict-type'

export default () => {
  const userStore = useUserStore()
  const option = computed<ListFormOption>(() => {
    return {
      api: '/sys/dict',
      permissionPrefix: 'sys_dict_',
      permissions: userStore.permissions,
      tabsProps: {
        columns: [
          {
            title: '字典项',
            slotName: 'dictItem',
            permission: 'sys_dict_edit'
          }
        ]
      },
      addBtn: {
        display: userStore.user.claims.platformType === 'sys'
      },
      editBtn: {
        display: userStore.user.claims.platformType === 'sys'
      },
      delBtn: {
        display: userStore.user.claims.platformType === 'sys'
      },
      columns: [
        {
          name: '字典名称',
          prop: 'name',
          rules: [
            { required: true, message: '名称不能为空' },
            { maxLength: 50, message: '不能超过50个字符' }
          ]
        },
        {
          name: '字典编码',
          prop: 'dicCode',
          rules: [
            { required: true, message: '名称不能为空' },
            { maxLength: 50, message: '不能超过50个字符' }
          ]
        },
        {
          name: '描述',
          prop: 'description',
          type: 'textarea',
          rules: [{ maxLength: 200, message: '不能超过200个字符' }]
        },
        {
          name: '类型',
          prop: 'type',
          type: 'radio',
          tooltip:
            '全局字典：仅平台端可配置，作用于所有租户，例如存放性别等\n默认字典：仅平台端可配置，租户创建时初始化会取值作为普通字典',
          dicData: DictTypeDic,
          value: userStore.user.claims.platformType === 'sys' ? undefined : 'normal',
          addDisplay: userStore.user.claims.platformType === 'sys',
          editDisplay: userStore.user.claims.platformType === 'sys',
          rules: { required: true, message: '不能为空' }
        }
      ]
    }
  })
  return {
    option
  }
}
