<template>
  <BasicModal v-bind="$attrs" @register="registerModal" title="消息" @ok="submit">
    <Description
      :collapseOptions="{ canExpand: true, helpMessage: 'help me' }"
      :column="1"
      :data="mockData"
      :schema="schema"
    />
  </BasicModal>
</template>
<script lang="ts" setup>
  import { ref, computed, unref, h } from 'vue';
  import { Tag } from 'ant-design-vue';
  import { BasicModal, useModalInner } from '@/components/Modal';
  import { Description, DescItem, useDescription } from '@/components/Description';

  defineOptions({ name: 'AccountModal' });
  const mockData = ref();
  const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
    setModalProps({ confirmLoading: false });
    console.log(data);
    mockData.value = data.record;
  });
  const schema: DescItem[] = [
    {
      field: 'content',
      label: '内容',
    },
    {
      field: 'isRead',
      label: '状态',
      render: (curVal, data) => {
        const isRead = data.isRead;
        const enable = ~~isRead === 1;
        const color = enable ? 'green' : 'red';
        const text = enable ? '已读' : '未读';
        return h(Tag, { color: color }, () => text);
      },
    },
    {
      field: 'createDate',
      label: '创建时间',
    },
  ];
  function submit() {
    closeModal();
  }
</script>
