<script setup lang='ts'>
import { showImagePreview } from 'vant';
const props = defineProps<{
  d: any
}>()


function formatTime(s: string) {
  return (new Date(s * 1000)).toLocaleString()
}
// TODO: 临时处理
function translateString(str: string) {
  return str.split('\n').map((item) => `<p>${item}</p>`).join('')
}

function formatFileString(s: string) {
  if(!s) return []
  return s.split(';').map((item) => window.GLOBAL_CONFIG.oss + item)
}
</script>

<template>
  <div class="space-y-4 mt-8">
    <div class="flex justify-between items-end">
      <div class="text-xl whitespace-nowrap overflow-ellipsis overflow-hidden w-max-320px">{{ d.dc_title }}</div>
      <van-tag type="primary" size="large">{{ d.dc_keyword }}</van-tag>
    </div>
    <div class="flex space-x-6 text-gray-500">
      <div>{{ d.dc_grade_name }}</div>
      <div>{{ d.dc_subject_name }}</div>
      <div>{{ d.create_user_realname }}</div>
      <div>{{ (d.create_dateline) }}</div>
    </div>

    <div class=" text-gray-600 pt-4" v-html="translateString(d.dc_content)"></div>

    <div class="mt-6 grid grid-cols-2 gap-4">
      <van-image fit="contain" v-for="(src, idx) in formatFileString(d.dc_files)" :src="src"
        :preview-src-list="formatFileString(d.dc_files)" :initial-index="idx" position="top"
        @click="showImagePreview({ images: formatFileString(d.dc_files), startPosition: idx })" />
    </div>
  </div>
</template>
