<template>
  <component
    :is="url ? 'a' : 'div'"
    v-bind="url ? { href: url, target: '_blank', rel: 'noopener noreferrer' } : {}"
    class="outil-card"
    :class="{ 'outil-card--link': !!url, 'outil-card--disabled': !url }"
  >
    <div class="outil-card__header">
      <span class="outil-card__icon" aria-hidden="true">{{ icon }}</span>
      <span :class="['outil-card__badge', `outil-card__badge--${tag}`]">{{ tagLabel }}</span>
    </div>
    <h3 class="outil-card__titre">{{ titre }}</h3>
    <p class="outil-card__desc">{{ description }}</p>
    <span v-if="cta && url" class="outil-card__cta">{{ cta }}</span>
    <span v-else-if="!url" class="outil-card__cta outil-card__cta--disabled">Bientôt disponible</span>
  </component>
</template>

<script setup lang="ts">
const props = defineProps<{
  icon?: string
  titre: string
  url?: string | null
  description?: string
  cta?: string
  tag?: string
}>()

const tagLabels: Record<string, string> = {
  'outil-aep': 'Outil AEP',
  'inspiration-externe': 'Inspiration',
  'disponible': 'Disponible',
  'recommande': 'Recommandé',
  'a-venir': 'À venir',
}

const tagLabel = computed(() => props.tag ? (tagLabels[props.tag] ?? props.tag) : '')
</script>

<style scoped>
.outil-card {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1rem 1.25rem;
  border-radius: 10px;
  border: 1px solid var(--nav-bg-alt);
  background: var(--nav-surface);
  text-decoration: none;
  color: var(--nav-text);
  transition: box-shadow 0.15s, border-color 0.15s;
}

.outil-card--link:hover {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  border-color: var(--nav-primary-solid);
}

.outil-card--disabled {
  opacity: 0.65;
}

.outil-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.outil-card__icon {
  font-size: 1.3rem;
  line-height: 1;
}

.outil-card__badge {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 7px;
  border-radius: 999px;
}

.outil-card__badge--outil-aep {
  background: #d1fae5;
  color: #065f46;
}
.outil-card__badge--inspiration-externe {
  background: #fef3c7;
  color: #92400e;
}
.outil-card__badge--disponible {
  background: #d1fae5;
  color: #065f46;
}
.outil-card__badge--recommande {
  background: #dbeafe;
  color: #1e40af;
}
.outil-card__badge--a-venir {
  background: var(--nav-bg-alt);
  color: var(--nav-text-muted);
}

.outil-card__titre {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--nav-text);
  margin: 0;
  line-height: 1.35;
}

.outil-card__desc {
  font-size: 0.82rem;
  color: var(--nav-text-muted);
  margin: 0;
  line-height: 1.5;
}

.outil-card__cta {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--nav-primary-solid);
  margin-top: 0.25rem;
}

.outil-card__cta--disabled {
  color: var(--nav-text-muted);
  font-weight: 400;
  font-style: italic;
}

/* Dark mode badge overrides */
:global(.dark) .outil-card__badge--outil-aep {
  background: #064e3b;
  color: #a7f3d0;
}
:global(.dark) .outil-card__badge--inspiration-externe {
  background: #78350f;
  color: #fde68a;
}
:global(.dark) .outil-card__badge--disponible {
  background: #064e3b;
  color: #a7f3d0;
}
:global(.dark) .outil-card__badge--recommande {
  background: #1e3a5f;
  color: #93c5fd;
}
</style>
