<template>
  <div class="section-padding">
    <div class="container-content">
      <div class="mx-auto max-w-2xl">
        <div class="section-icon mx-auto mb-6">
          <div :class="`i-lucide-${content?.icon ?? 'landmark'}`" class="h-12 w-12" />
        </div>

        <p class="mb-2 font-mono text-sm tracking-widest text-primary uppercase text-center">
          {{ content?.kicker }}
        </p>

        <h1 class="font-display text-3xl font-bold mb-4 text-center" style="color: hsl(var(--color-text))">
          {{ content?.title ?? slug }}
        </h1>

        <p class="text-lg leading-relaxed mb-8 text-center" style="color: hsl(var(--color-text-muted))">
          {{ content?.description }}
        </p>

        <!-- Features grid (for decision page) -->
        <div v-if="content?.features" class="grid gap-4 sm:grid-cols-2 mb-12">
          <div v-for="feature in content.features" :key="feature.title" class="feature-card">
            <div class="feature-icon">
              <div :class="`i-lucide-${feature.icon} h-5 w-5`" />
            </div>
            <h3 class="font-display font-semibold mb-1" style="color: hsl(var(--color-text))">{{ feature.title }}</h3>
            <p class="text-sm leading-relaxed" style="color: hsl(var(--color-text-muted))">{{ feature.text }}</p>
          </div>
        </div>

        <!-- Project card -->
        <div v-if="content?.project" class="project-card mb-8">
          <div class="project-icon">
            <div class="i-lucide-rocket h-5 w-5" />
          </div>
          <h2 class="font-display text-xl font-semibold mb-2" style="color: hsl(var(--color-text))">
            {{ content.project.name }}
          </h2>
          <p style="color: hsl(var(--color-text-muted))" class="leading-relaxed">
            {{ content.project.text }}
          </p>
          <span v-if="content?.gestation" class="gestation-badge mt-3">
            <div class="i-lucide-flask-conical h-3 w-3" />
            En gestation
          </span>
        </div>

        <!-- Extended content -->
        <div v-if="content?.content" class="prose-block mb-10">
          <p class="leading-relaxed whitespace-pre-line" style="color: hsl(var(--color-text-muted))">
            {{ content.content }}
          </p>
        </div>

        <div class="text-center flex flex-col items-center gap-3 sm:flex-row sm:justify-center">
          <UiBaseButton v-if="slug === 'decision'" :href="decisionUrl" target="_blank">
            <div class="i-lucide-external-link mr-2 h-4 w-4" />
            Ouvrir Glibredecision
          </UiBaseButton>
          <UiBaseButton v-if="slug === 'tarifs-eau'" :href="sejeteral0Url" target="_blank">
            <div class="i-lucide-external-link mr-2 h-4 w-4" />
            Lancer SejeteralO
          </UiBaseButton>
          <UiBaseButton variant="ghost" to="/citoyenne">
            <div class="i-lucide-arrow-left mr-2 h-4 w-4" />
            Autonomie citoyenne
          </UiBaseButton>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
const route = useRoute()
const slug = route.params.slug as string

const { data: content } = await usePageContent(`citoyenne/${slug}`)

const appConfig = useAppConfig()
const decisionUrl = (appConfig.libredecision as { url: string })?.url ?? '#'
const sejeteral0Url = (appConfig.sejeteral0 as { url: string })?.url ?? '#'

useHead({
  title: content.value?.meta?.title ?? slug,
})
</script>

<style scoped>
.section-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 5rem;
  height: 5rem;
  border-radius: 1rem;
  background: hsl(var(--color-primary) / 0.1);
  border: 1px solid hsl(var(--color-primary) / 0.2);
  color: hsl(var(--color-primary));
}

.feature-card {
  padding: 1.25rem;
  border-radius: 0.75rem;
  border: 1px solid hsl(var(--color-text) / 0.08);
  background: hsl(var(--color-surface));
}

.feature-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.5rem;
  background: hsl(var(--color-primary) / 0.1);
  color: hsl(var(--color-primary));
  margin-bottom: 0.75rem;
}

.project-card {
  padding: 1.5rem;
  border-radius: 0.75rem;
  border: 1px solid hsl(var(--color-primary) / 0.15);
  background: hsl(var(--color-surface));
}

.project-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 0.5rem;
  background: hsl(var(--color-primary) / 0.1);
  color: hsl(var(--color-primary));
  margin-bottom: 1rem;
}

.gestation-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  background: hsl(var(--color-accent) / 0.12);
  color: hsl(var(--color-accent));
  font-size: 0.7rem;
  font-weight: 500;
  font-family: var(--font-mono);
}

.prose-block {
  padding: 1.5rem;
  border-radius: 0.75rem;
  background: hsl(var(--color-surface));
}
</style>
