<script setup lang="ts">
// <!-- ld-v2 --> Carte d'une clause dans la vue structurée : code, titre,
// mini-jauge de session réelle, pastille d'inertie câblée, statut — tap pour
// déplier le détail complet (ClauseDetail).
import type { ClauseView } from './textsModel'

defineProps<{
  view: ClauseView
  expanded: boolean
}>()

defineEmits<{ (e: 'toggle'): void }>()
</script>

<template>
  <!-- ld-v2 -->
  <article class="clause-card ld-card">
    <button type="button" class="clause-card__row" @click="$emit('toggle')">
      <span class="clause-card__code">{{ view.clause.code }}</span>
      <span class="clause-card__title">{{ view.clause.title }}</span>
      <span class="clause-card__side">
        <SessionMiniGauge v-if="view.gauge" :gauge="view.gauge" @click.stop />
        <InertiaBadge
          :preset="view.clause.inertia"
          :amend-protocol="view.amendProtocol"
          :protected-clause="view.protectedClause"
          compact
        />
        <span class="status-pill clause-card__status" :class="view.status.css">
          {{ view.status.label }}
        </span>
      </span>
    </button>

    <p v-if="view.settingText && !expanded" class="clause-card__setting">
      {{ view.settingText }}
    </p>

    <ClauseDetail
      v-if="expanded"
      class="clause-card__detail"
      :clause="view.clause"
      :current-version="view.current"
      :proposed="view.proposed"
      :founding="view.founding"
      :amendments="view.amendments"
      :setting-text="view.settingText"
      :gauge="view.gauge"
      :atelier-link="view.atelierLink"
    />
  </article>
</template>

<style scoped>
.clause-card { overflow: hidden; }
.clause-card__row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.7rem 0.9rem;
  background: none;
  cursor: pointer;
  text-align: left;
  flex-wrap: wrap;
}
.clause-card__row:hover { background: color-mix(in srgb, var(--mood-accent) 4%, transparent); }
.clause-card__code {
  font-family: monospace;
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--mood-accent);
  background: var(--mood-accent-soft);
  padding: 2px 8px;
  border-radius: 7px;
  flex-shrink: 0;
}
.clause-card__title {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--mood-text);
  flex: 1;
  min-width: 10rem;
}
.clause-card__side { display: inline-flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.clause-card__status { font-size: 0.6875rem; padding: 2px 9px; }
.clause-card__setting {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--mood-accent);
  padding: 0 0.9rem 0.7rem;
}
.clause-card__detail { margin: 0 0.55rem 0.55rem; }
</style>
