<script setup lang="ts">
// <!-- ld-v2 --> Période du mandat — barre de temps simple : début, fin,
// marqueur aujourd'hui. Un fait daté, pas une jauge de quoi que ce soit.
import { formatDay } from './mandateUi'

const props = defineProps<{ startsAt: string; endsAt: string }>()

const pct = computed(() => {
  const start = new Date(props.startsAt).getTime()
  const end = new Date(props.endsAt).getTime()
  if (end <= start) return 100
  return Math.min(100, Math.max(0, ((Date.now() - start) / (end - start)) * 100))
})
</script>

<template>
  <!-- ld-v2 -->
  <div class="mperiod">
    <div class="mperiod__track">
      <div class="mperiod__fill" :style="{ width: `${pct}%` }" />
      <div class="mperiod__today" :style="{ left: `${pct}%` }" title="aujourd'hui" />
    </div>
    <div class="mperiod__dates">
      <span>{{ formatDay(startsAt) }}</span>
      <span>{{ formatDay(endsAt) }}</span>
    </div>
  </div>
</template>

<style scoped>
.mperiod { display: flex; flex-direction: column; gap: 0.375rem; }
.mperiod__track {
  position: relative;
  height: 8px;
  border-radius: 4px;
  background: var(--mood-accent-soft);
}
.mperiod__fill {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 4px 0 0 4px;
  background: var(--mood-accent);
  opacity: 0.55;
}
.mperiod__today {
  position: absolute;
  top: 50%;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--mood-accent);
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 2px var(--mood-surface);
}
.mperiod__dates {
  display: flex;
  justify-content: space-between;
  font-size: 0.8125rem;
  color: var(--mood-text-muted);
  font-variant-numeric: tabular-nums;
}
</style>
