<template>
  <article class="solution-defail">
    <header class="solution-header">
      <h1 class="solution-title">{{ solution.title }}</h1>
      <dl class="solution-meta">
        <dt class="visually-hidden">CreatedAt:</dt>
        <dd class="solution-date">
          {{ new Date(solution.createAt).toLocaleDateString() }}
        </dd>
      </dl>
      <p class="solution-summary">{{ solution.summary }}</p>
    </header>
    <section class="solution-content">
      <!-- eslint-disable-next-line vue/no-v-html -->
      <div v-if="!hydrated" v-html="solution?.content || ''" />
      <div v-else>
        <HtmlRenderer class="html-typography" :html="solution.content || ''" />
      </div>
    </section>
  </article>
</template>

<script setup lang="ts">
  defineProps({
    solution: {
      type: Object as PropType<SolutionView>,
      default: null,
    },
  });

  const hydrated = ref(false);

  onMounted(() => {
    hydrated.value = true;
  });
</script>

<style scoped>
  .solution-title {
    font-size: 2rem;
    font-weight: bold;
    color: var(--el-color-primary);
    text-align: center;
  }

  .solution-meta {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 0.5rem;
    font-size: 0.8rem;
    color: var(--el-text-color-secondary);
  }

  .solution-summary {
    font-size: 0.8rem;
    color: var(--el-text-color-secondary);
    text-align: center;
  }

  .solution-content {
    margin-top: 1rem;
  }
</style>
