/**
 * Dismissible inline alert used by the auth and settings screens.
 *
 * Now composed from the shadcn `Alert` primitive instead of four parallel
 * lookup tables of hard-coded Tailwind colour classes (`bg-red-50`,
 * `text-yellow-600`, …). Those literals sat outside the token system, so they
 * could not follow the theme and drifted from the status colours used
 * elsewhere in the app.
 *
 * The public props are unchanged, so all 10 call sites keep working.
 */

import { X, CircleCheck, Info, OctagonX, TriangleAlert } from "lucide-react";
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
import { Button } from "@/components/ui/button";
import { cn } from "@/lib/utils";

export type AlertMessageType = "error" | "success" | "warning" | "info";

export interface AlertMessageProps {
  type: AlertMessageType;
  message: string;
  onDismiss?: () => void;
  className?: string;
}

const CONFIG = {
  error: { variant: "destructive", title: "Error", Icon: OctagonX },
  success: { variant: "success", title: "Success", Icon: CircleCheck },
  warning: { variant: "warning", title: "Warning", Icon: TriangleAlert },
  info: { variant: "info", title: "Info", Icon: Info },
} as const;

export function AlertMessage({ type, message, onDismiss, className }: AlertMessageProps) {
  const { variant, title, Icon } = CONFIG[type];

  return (
    <Alert variant={variant} className={cn(onDismiss && "pr-11", className)}>
      <Icon aria-hidden />
      <AlertTitle>{title}</AlertTitle>
      <AlertDescription>{message}</AlertDescription>

      {onDismiss && (
        <Button
          type="button"
          variant="ghost"
          size="icon-sm"
          onClick={onDismiss}
          aria-label="Dismiss"
          className="absolute right-2 top-2 text-current hover:bg-current/10"
        >
          <X className="size-4" aria-hidden />
        </Button>
      )}
    </Alert>
  );
}
