import { cva, type VariantProps } from "class-variance-authority";
import { cn } from "@/shared/utils";

const statusIndicatorVariants = cva("inline-flex items-center gap-1.5", {
  variants: {
    size: {
      sm: "text-xs",
      md: "text-sm",
      lg: "text-base",
    },
  },
  defaultVariants: {
    size: "md",
  },
});

const dotVariants = cva("rounded-full flex-shrink-0", {
  variants: {
    status: {
      active: "bg-success",
      warning: "bg-warning",
      error: "bg-danger",
      inactive: "bg-muted-foreground/30",
      pending: "bg-info",
    },
    size: {
      sm: "h-1.5 w-1.5",
      md: "h-2 w-2",
      lg: "h-2.5 w-2.5",
    },
    pulse: {
      true: "animate-pulse",
      false: "",
    },
  },
  defaultVariants: {
    status: "active",
    size: "md",
    pulse: false,
  },
});

export type StatusIndicatorStatus = "active" | "warning" | "error" | "inactive" | "pending";

interface StatusIndicatorProps extends VariantProps<typeof statusIndicatorVariants> {
  status: StatusIndicatorStatus;
  label?: string;
  pulse?: boolean;
  className?: string;
}

export function StatusIndicator({ status, label, size, pulse, className }: StatusIndicatorProps) {
  return (
    <span className={cn(statusIndicatorVariants({ size }), className)}>
      <span className={dotVariants({ status, size, pulse: pulse ?? status === "pending" })} />
      {label && <span className="text-muted-foreground">{label}</span>}
    </span>
  );
}
