import { cn } from "@/lib/utils";

type LoaderProps = {
  size?: "sm" | "md" | "lg";
  fullScreen?: boolean;
  label?: string;
  className?: string;
};

const sizeMap = {
  sm: "w-5 h-5 border-2",
  md: "w-8 h-8 border-[3px]",
  lg: "w-12 h-12 border-4",
};

export default function Loader({ size = "md", fullScreen, label, className }: LoaderProps) {
  const spinner = (
    <div className={cn("flex flex-col items-center gap-3", className)}>
      <div
        className={cn(
          "rounded-full border-gray-200 border-t-[#CC1414] animate-spin",
          sizeMap[size]
        )}
        role="status"
        aria-label="Loading"
      />
      {label ? <p className="text-sm text-gray-600">{label}</p> : null}
    </div>
  );

  if (fullScreen) {
    return (
      /* z-90: must outrank the chat FAB (70/80) and dashboard drawer (60),
         otherwise they render through a supposedly blocking overlay. */
      <div className="fixed inset-0 z-[90] flex items-center justify-center bg-white/70 backdrop-blur-sm">
        {spinner}
      </div>
    );
  }
  return spinner;
}
