<script lang="ts" setup>
import { reactive, ref, toRefs } from 'vue'
import { useMessage } from 'naive-ui'
import { format } from 'date-fns'

import { msgOne, readMsg } from '@/api/message/message'

const props = defineProps({
  id: {
    type: String,
    default: '',
  },
})
const message = useMessage()
const state: any = reactive({
  detail: {},
})
const { detail } = toRefs(state)
const taskDetailInfo = ref<any>({})
async function getDetail() {
  const res = await msgOne({ id: props.id })
  console.log(res)
  state.detail = res
  if (!state.detail.readFlag)
    clearMsg()

  if (res.code === 'OK')
    message.info('清除标记成功')

  else message.error(res.message)
}

async function clearMsg() {
  const res = await readMsg({ msgid: props.id })
}

getDetail()
</script>

<template>
  <div class="wrapper-message">
    <div class="left-card">
      <div class="title">
        {{ detail.titile }}
      </div>
      <div class="content" v-html="detail.msgContent" />
    </div>
    <div class="right-card">
      <img class="icon-set" src="@/assets/images/message/set.png" alt="">
      <div class="title">
        系统消息
      </div>
      <div class="form">
        <div class="form-item flex">
          <img class="icon" src="@/assets/images/message/user.png" alt="">
          <div class="label">
            创建人：
          </div>
          <div class="value">
            {{ detail.createBy }}
          </div>
        </div>
        <div class="form-item flex">
          <img class="icon" src="@/assets/images/message/time.png" alt="">
          <div class="label">
            发布时间：
          </div>
          <div class="value time">
            {{ format(detail.sendTime * 1000, 'yyyy-MM-dd HH:mm:ss') }}
          </div>
        </div>
        <div class="form-item flex margin-no">
          <img class="icon" src="@/assets/images/message/time.png" alt="">
          <div class="label">
            消息类型：
          </div>
          <div class="value">
            <div class="tag">
              {{ detail.msgCategory === 1 ? '审批通知' : '系统通知' }}
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<style lang="less" scoped>
.wrapper-message {
  display: flex;
  flex: 1;
  box-sizing: border-box;
  border-radius: 3px;
  height: calc(100vh - 88px);
  overflow-y: auto;

  .left-card{
    height: 100%;
    background: #ffffff;
    border-radius: 4px;
    flex: 1;
    padding-top: 32px;
    box-sizing: border-box;

    .title{
      font-size: 28px;
      font-family: PingFang SC, PingFang SC-Medium;
      font-weight: Medium;
      text-align: center;
      color: #333333;
      line-height: 40px;
      margin-bottom: 32px;
    }

    .content{
      padding: 0 32px;
    }

  }

  .right-card{
    width: 280px;
    height: 100%;
    box-sizing: border-box;
    background: #ffffff;
    border-radius: 4px;
    margin-left: 16px;
    padding-top: 48px;

    .title{
      font-size: 20px;
      font-family: PingFang SC, PingFang SC-Medium;
      font-weight: Medium;
      text-align: center;
      color: #333333;
      line-height: 22px;
    }

    .form{
      margin: 0 auto;
      margin-top: 32px;
      width: 235px;
      padding: 24px 0;
      border-top: 1px solid #eeeeee;
      border-bottom: 1px solid #eeeeee;
    }

    .form-item{
      align-items: center;
      margin-bottom: 16px;
    }

    .margin-no{
      margin: 0;
    }

    .icon{
      width: 16px;
      height: 16px;
      margin-right: 8px;
    }

    .label{
      width: 70px;
      font-size: 14px;
      font-family: PingFang SC, PingFang SC-Regular;
      font-weight: Regular;
      text-align: left;
      color: #666666;
    }

    .value{
      font-size: 14px;
      font-family: PingFang SC, PingFang SC-Regular;
      font-weight: Regular;
      text-align: left;
      color: #333333;
    }

    .time{
      color: #1d2129;
    }
  }

  .icon-set{
    width: 80px;
    height: 80px;
    margin: 0 auto;
    margin-bottom: 24px;
  }
}
</style>
