import { Loader2 } from "lucide-react";
import { cn } from "@/lib/utils";

interface LoadingSpinnerProps {
  size?: "sm" | "md" | "lg";
  className?: string;
  text?: string;
}

export function LoadingSpinner({ size = "md", className, text = "로딩 중..." }: LoadingSpinnerProps) {
  const sizeClasses = {
    sm: "h-4 w-4",
    md: "h-6 w-6",
    lg: "h-8 w-8",
  };

  return (
    <div className={cn("flex items-center justify-center", className)}>
      <div className="flex items-center space-x-2">
        <Loader2 className={cn("animate-spin", sizeClasses[size])} />
        {text && <span className="text-sm text-slate-600">{text}</span>}
      </div>
    </div>
  );
}

// 페이지 전체 로딩 오버레이
export function LoadingOverlay({
  isLoading,
  text = "로딩 중...",
  children,
}: {
  isLoading: boolean;
  text?: string;
  children: React.ReactNode;
}) {
  if (!isLoading) {
    return <>{children}</>;
  }

  return (
    <div className="relative">
      <div className="pointer-events-none opacity-50">{children}</div>
      <div className="absolute inset-0 flex items-center justify-center bg-white/50 backdrop-blur-sm">
        <LoadingSpinner size="lg" text={text} />
      </div>
    </div>
  );
}

// 인라인 로딩 스피너 (버튼 내부 등에서 사용)
export function InlineSpinner({ className }: { className?: string }) {
  return <Loader2 className={cn("h-4 w-4 animate-spin", className)} />;
}
