<template>
  <div class="rounded-lg border border-[var(--brand-border)] bg-[var(--brand-surface)] p-4">
    <div class="flex items-center justify-between mb-3">
      <h3 class="text-lg font-semibold text-[var(--brand-text)]">{{ title }}</h3>
      <div :class="colorClasses" class="w-3 h-3 rounded-full"></div>
    </div>

    <div class="space-y-2">
      <div class="flex justify-between items-center">
        <span class="text-xs text-[var(--brand-text-muted)]">Cantidad</span>
        <span class="text-sm font-medium text-[var(--brand-text)]">
          {{ formatNumber(data.total_cantidad) }} {{ unidad }}
        </span>
      </div>

      <div class="flex justify-between items-center">
        <span class="text-xs text-[var(--brand-text-muted)]">Total Cobrado</span>
        <span class="text-sm font-bold text-green-400">
          {{ formatCurrency(data.total_cobrado) }}
        </span>
      </div>

      <div class="flex justify-between items-center">
        <span class="text-xs text-[var(--brand-text-muted)]">Precio Promedio</span>
        <span class="text-sm font-medium text-[var(--brand-text)]">
          {{ formatCurrency(data.precio_promedio) }}
        </span>
      </div>

      <div class="flex justify-between items-center pt-2 border-t border-[var(--brand-border)]">
        <span class="text-xs text-[var(--brand-text-muted)]">Registros</span>
        <span class="text-xs font-medium text-[var(--brand-text)]">
          {{ data.num_registros }}
        </span>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
const props = defineProps<{
  title: string
  data: {
    tipo: string
    num_registros: number
    total_cantidad: number
    total_cobrado: number
    precio_promedio: number
  }
  unidad: string
  color: string
}>()

const colorClasses = computed(() => {
  const colors: Record<string, string> = {
    blue: 'bg-blue-500',
    green: 'bg-green-500',
    yellow: 'bg-yellow-500',
    red: 'bg-red-500',
    purple: 'bg-purple-500',
    pink: 'bg-pink-500'
  }
  return colors[props.color] || 'bg-gray-500'
})

const formatNumber = (value: number) => {
  return new Intl.NumberFormat('es-HN', {
    minimumFractionDigits: 2,
    maximumFractionDigits: 2
  }).format(value)
}

const formatCurrency = (value: number) => {
  if (!value) return 'L 0.00'
  return new Intl.NumberFormat('es-HN', {
    style: 'currency',
    currency: 'HNL',
    minimumFractionDigits: 2,
    maximumFractionDigits: 2
  }).format(value).replace('HNL', 'L')
}
</script>
