<template>
  <div class="section-padding">
    <div class="container-content mx-auto max-w-3xl">
      <h1 class="font-display text-3xl font-bold text-gradient mb-2">Messages des visiteurs</h1>
      <p class="text-white/50 mb-8">Les mots laissés par celles et ceux qui passent par ici.</p>

      <div v-if="messages?.length" class="space-y-4">
        <div v-for="msg in messages" :key="msg.id" class="message-card">
          <p class="text-white/80 leading-relaxed">{{ msg.text }}</p>
          <div class="mt-3 flex items-center gap-2 text-xs text-white/40">
            <span class="font-semibold text-white/60">{{ msg.author }}</span>
            <span>&middot;</span>
            <span>{{ formatDate(msg.createdAt) }}</span>
          </div>
        </div>
      </div>

      <p v-else class="text-center text-white/40 py-12">Aucun message pour l'instant.</p>

      <div class="mt-8 text-center">
        <NuxtLink to="/" class="btn-ghost text-sm">
          <div class="i-lucide-arrow-left mr-1 h-3.5 w-3.5" />
          Retour à l'accueil
        </NuxtLink>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
useHead({
  title: 'Messages',
})

const { data: messages } = await useFetch('/api/messages')

function formatDate(iso: string) {
  const date = new Date(iso)
  return date.toLocaleDateString('fr-FR', { day: 'numeric', month: 'long', year: 'numeric' })
}
</script>

<style scoped>
.message-card {
  background: hsl(var(--color-surface));
  border: 1px solid hsl(var(--color-text) / 0.1);
  border-radius: 0.75rem;
  padding: 1.25rem 1.5rem;
}
</style>
