import { Badge } from "@/components/ui/badge";
import { cn } from "@/lib/utils";

export type Tone = "success" | "warning" | "error" | "info" | "neutral";

const TONE: Record<Tone, string> = {
  success: "border-status-success-border bg-status-success-bg text-status-success-text",
  warning: "border-status-warning-border bg-status-warning-bg text-status-warning-text",
  error: "border-status-error-border bg-status-error-bg text-status-error-text",
  info: "border-status-info-border bg-status-info-bg text-status-info-text",
  neutral: "border-border bg-muted text-muted-foreground",
};

export const toneText: Record<Exclude<Tone, "neutral" | "info">, string> = {
  success: "text-status-success-text",
  warning: "text-status-warning-text",
  error: "text-status-error-text",
};

/** A Badge coloured with the Medora status tokens. */
export function StatusBadge({ tone, children, className }: { tone: Tone; children: React.ReactNode; className?: string }) {
  return (
    <Badge variant="outline" className={cn("rounded-md", TONE[tone], className)}>
      {children}
    </Badge>
  );
}

export const stockTone = (s: string): Tone => (s === "In stock" ? "success" : s === "Low stock" ? "warning" : "error");
export const saleTone = (s: string): Tone => (s === "Completed" ? "success" : s === "Held" ? "warning" : "error");
export const rxTone = (s: string): Tone =>
  s === "Dispensed" ? "success" : s === "Pending" ? "warning" : s === "Rejected" ? "error" : s === "Verified" ? "info" : "neutral";
