"use client";

import { Badge } from "@/presentation/components/ui/badge";
import { cn } from "@/shared/lib/utils";
import type { EntityStatus } from "@/shared/types";

const statusConfig: Record<EntityStatus, { label: string; className: string }> = {
  pending: { label: "En attente", className: "bg-amber-100 text-amber-800 border-amber-200" },
  active: { label: "Actif", className: "bg-emerald-100 text-emerald-800 border-emerald-200" },
  disabled: { label: "Desactive", className: "bg-red-100 text-red-800 border-red-200" },
};

interface StatusBadgeProps {
  status: string;
  className?: string;
}

export function StatusBadge({ status, className }: StatusBadgeProps) {
  const config = statusConfig[status as EntityStatus] ?? { label: status, className: "bg-gray-100 text-gray-800 border-gray-200" };
  return (
    <Badge variant="outline" className={cn("text-xs font-medium", config.className, className)}>
      {config.label}
    </Badge>
  );
}

// Shared semantic color keys for label+color badges (connection status, company access status, …).
const statusColorMap: Record<string, string> = {
  success: "bg-emerald-100 text-emerald-800 border-emerald-200",
  indigo: "bg-indigo-100 text-indigo-800 border-indigo-200",
  warning: "bg-amber-100 text-amber-800 border-amber-200",
  failure: "bg-red-100 text-red-800 border-red-200",
  danger: "bg-red-100 text-red-800 border-red-200",
  info: "bg-blue-100 text-blue-800 border-blue-200",
};

interface ColorStatusBadgeProps {
  label: string;
  color: string;
  className?: string;
}

export function ConnectionStatusBadge({ label, color, className }: ColorStatusBadgeProps) {
  const colorClass = statusColorMap[color] ?? "bg-gray-100 text-gray-800 border-gray-200";
  return (
    <Badge variant="outline" className={cn("text-xs font-medium", colorClass, className)}>
      {label}
    </Badge>
  );
}

export function AccessStatusBadge({ label, color, className }: ColorStatusBadgeProps) {
  const colorClass = statusColorMap[color] ?? "bg-gray-100 text-gray-800 border-gray-200";
  return (
    <Badge variant="outline" className={cn("text-xs font-medium", colorClass, className)}>
      {label}
    </Badge>
  );
}
