<script setup lang="tsx">
import { PropType, ref } from 'vue'
import { TableData } from '@/api/csck/CsckModelDetailTarget/types'
import { Descriptions, DescriptionsSchema } from '@/components/Descriptions'
import { IS_NULL_DICT_LIST, IS_PKID_DICT_LIST } from '../constants';

const detailSchema = ref<DescriptionsSchema[]>([
  {
    field: 'fieldCode',
    label: '字段编码'
  },
  {
    field: 'fieldName',
    label: '字段名称'
  },
  {
    field: 'dbType',
    label: '数据库类型'
  },
  {
    field: 'fieldType',
    label: '字段类型'
  },
  {
    field: 'fieldLength',
    label: '字段长度'
  },
  {
    field: 'fieldPrecision',
    label: '字段精度'
  },
  {
    field: 'isNull',
    label: '是否为空',
    slots: {
      default(row) {
        const isNull = IS_NULL_DICT_LIST.find((item) => item.value === row.isNull)
        if (isNull) {
          return <span>{isNull.label}</span>
        }
        return <span>{row.isNull ?? '-'}</span>
      }
    }
  },
  {
    field: 'isPkid',
    label: '是否主键',
    slots: {
      default(row) {
        const isPkid = IS_PKID_DICT_LIST.find((item) => item.value === row.isPkid)
        if (isPkid) {
          return <span>{isPkid.label}</span>
        }
        return <span>{row.isPkid ?? '-'}</span>
      }
    }
  }
])

defineProps({
  currentRow: {
    type: Object as PropType<TableData>,
    default: () => {}
  }
})
</script>

<template>
  <Descriptions :schema="detailSchema" :data="currentRow || {}" />
</template>
