<template>
  <div class="notice-card w-full">
    <div v-if="!detailOpen" class="notice-card__summary bg-[#FFFBEB] rounded-[24px] w-full">
      <div class="notice-card__summary-title color-B45309 text-[16px] font-bold">
        {{ summary.title }}
      </div>
      <div class="notice-card__summary-content text-[#D97706] text-[14px] font-bold">
        {{ summary.content }}
      </div>
      <div class="notice-card__summary-footer flex items-center justify-between">
        <div class="notice-card__summary-time text-[#D97706] text-[12px] font-bold">
          {{ summary.publishTime }}
        </div>
        <div class="notice-card__summary-link color-B45309 text-[14px] font-bold" :class="{ 'is-disabled': disabled }"
          @click="openDetail">
          {{ summary.actionText }}
        </div>
      </div>
    </div>

    <div v-else class="notice-card__detail bg-white rounded-[24px] overflow-hidden w-full">
      <div class="notice-card__detail-head flex items-center">
        <div class="notice-card__back flex items-center justify-center rounded-full shrink-0" @click="closeDetail">
          <uni-icons type="left" size="16" color="#CBD5E1"></uni-icons>
        </div>
        <div class="notice-card__head-title text-[#1e293b] text-[18px] font-bold">
          {{ detail.navTitle }}
        </div>
      </div>

      <image class="notice-card__image block w-full" :src="detail.image" mode="aspectFill" />

      <div class="notice-card__detail-body">
        <div class="notice-card__detail-title text-[#1e293b] font-size-20 font-bold">
          {{ detail.title }}
        </div>
        <div class="notice-card__time-pill flex items-center bg-[#f8fafc] text-[#475569] text-[13px] font-bold">
          <span class="notice-card__time-icon">{{ detail.timeIcon }}</span>
          <span>{{ detail.publishTime }}</span>
        </div>
        <div class="notice-card__divider"></div>
        <div v-for="paragraph in paragraphs" :key="paragraph.id"
          class="notice-card__paragraph text-[#475569] text-[14px] font-bold">
          <span v-for="segment in paragraph.segments" :key="segment.text"
            :class="{ 'notice-card__strong': segment.strong }">
            {{ segment.text }}
          </span>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { computed, ref } from "vue";

const props = defineProps({
  data: {
    type: Object,
    default: () => ({}),
  },
  disabled: {
    type: Boolean,
    default: false,
  },
});

const emit = defineEmits(["select", "back", "action"]);

const detailOpen = ref(false);
const summary = computed(() => props.data.summary || {});
const detail = computed(() => props.data.detail || {});
const paragraphs = computed(() => detail.value.paragraphs || []);

const openDetail = () => {
  if (props.disabled) return;
  detailOpen.value = true;
  emit("select", props.data);
  emit("action", props.data);
};

const closeDetail = () => {
  detailOpen.value = false;
  emit("back");
};
</script>

<style scoped lang="scss">
@import "./styles/index.scss";
</style>
