<script setup lang="ts">
const props = defineProps<{
  status: string
  type?: 'document' | 'decision' | 'mandate' | 'version' | 'vote'
}>()

const statusConfig: Record<string, Record<string, { color: string; label: string }>> = {
  document: {
    draft: { color: 'warning', label: 'Brouillon' },
    active: { color: 'success', label: 'Actif' },
    archived: { color: 'neutral', label: 'Archive' },
  },
  version: {
    proposed: { color: 'info', label: 'Propose' },
    voting: { color: 'warning', label: 'En vote' },
    accepted: { color: 'success', label: 'Accepte' },
    rejected: { color: 'error', label: 'Rejete' },
  },
  decision: {
    draft: { color: 'warning', label: 'Brouillon' },
    qualification: { color: 'info', label: 'Qualification' },
    review: { color: 'info', label: 'Revue' },
    voting: { color: 'primary', label: 'En vote' },
    executed: { color: 'success', label: 'Execute' },
    closed: { color: 'neutral', label: 'Clos' },
  },
  mandate: {
    draft: { color: 'warning', label: 'Brouillon' },
    candidacy: { color: 'info', label: 'Candidature' },
    voting: { color: 'primary', label: 'En vote' },
    active: { color: 'success', label: 'Actif' },
    reporting: { color: 'info', label: 'Rapport' },
    completed: { color: 'neutral', label: 'Termine' },
    revoked: { color: 'error', label: 'Revoque' },
  },
  vote: {
    open: { color: 'success', label: 'Ouvert' },
    closed: { color: 'warning', label: 'Ferme' },
    tallied: { color: 'neutral', label: 'Depouille' },
  },
}

const resolved = computed(() => {
  const typeKey = props.type || 'document'
  const typeMap = statusConfig[typeKey]
  if (typeMap && typeMap[props.status]) {
    return typeMap[props.status]
  }
  return { color: 'neutral', label: props.status }
})
</script>

<template>
  <UBadge
    :color="(resolved.color as any)"
    variant="subtle"
    size="xs"
  >
    {{ resolved.label }}
  </UBadge>
</template>
