<script setup lang="ts">
// <!-- ld-v2 --> « Feux de la rampe » (Δ7) — le flux public des décisions
// prises sous ce mandat, chacune avec sa fenêtre : contestables, donc visibles.
import type { Mandate } from '~/types/domain'
import { useCollectiveStore } from '~/stores/collective'
import { MANDATE_SPOTLIGHT, MANDATE_SPOTLIGHT_SUB, STATUS_LABELS } from '~/lexicon'
import { formatDay } from './mandateUi'

const props = defineProps<{ mandate: Mandate }>()

const col = useCollectiveStore()

const traced = computed(() =>
  col.decisions
    .filter(d => d.underMandateId === props.mandate.id)
    .sort((a, b) => (a.createdAt < b.createdAt ? 1 : -1)),
)
</script>

<template>
  <!-- ld-v2 -->
  <section class="mspot ld-card">
    <h2 class="mspot__title">
      <UIcon name="i-lucide-lamp" />
      {{ MANDATE_SPOTLIGHT }}
    </h2>
    <p class="mspot__sub">{{ MANDATE_SPOTLIGHT_SUB }}</p>

    <ul v-if="traced.length" class="mspot__list">
      <li v-for="d in traced" :key="d.id" class="mspot__item">
        <NuxtLink :to="`/decisions/${d.id}`" class="mspot__link">
          <div class="mspot__main">
            <span class="mspot__decision-title">{{ d.title }}</span>
            <span class="mspot__date">{{ formatDay(d.decidedAt ?? d.createdAt) }}</span>
          </div>
          <div class="mspot__side">
            <LdCountdown
              v-if="d.windowEndsAt && !d.decidedAt"
              :ends-at="d.windowEndsAt"
              :suspended-at="d.windowSuspendedAt"
            />
            <span class="status-pill" :class="`status-${d.status}`">
              {{ STATUS_LABELS[d.status] }}
            </span>
          </div>
        </NuxtLink>
      </li>
    </ul>
    <p v-else class="mspot__empty">
      Aucune décision sous ce mandat pour l'instant — les feux s'allumeront à la première trace.
    </p>
  </section>
</template>

<style scoped>
.mspot { padding: 1.375rem 1.5rem; display: flex; flex-direction: column; gap: 0.75rem; }
.mspot__title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  font-size: 1.0625rem;
  font-weight: 800;
}
.mspot__sub {
  margin: -0.375rem 0 0;
  font-size: 0.875rem;
  font-style: italic;
  color: var(--mood-text-muted);
}
.mspot__list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.375rem; }
.mspot__link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.625rem 0.75rem;
  border-radius: var(--r-input);
  background: var(--mood-accent-soft);
  text-decoration: none;
  color: var(--mood-text);
  transition: transform 0.1s ease;
  flex-wrap: wrap;
}
.mspot__link:hover { transform: translateY(-1px); }
.mspot__main { display: flex; flex-direction: column; gap: 0.125rem; min-width: 0; flex: 1; }
.mspot__decision-title {
  font-size: 0.9375rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mspot__date { font-size: 0.75rem; color: var(--mood-text-muted); }
.mspot__side { display: flex; align-items: center; gap: 0.5rem; flex-shrink: 0; }
.mspot__empty { margin: 0; font-size: 0.875rem; color: var(--mood-text-muted); font-style: italic; }
</style>
