"use client";

import { Button } from "@/components/ui/button";
import { supabaseClient } from "@/lib/supabase-client";
import { cn } from "@/lib/utils";

interface LoginButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
    text?: string;
    variant?: "default" | "outline" | "secondary" | "ghost";
    redirectTo?: string;
}

export function LoginButton({
    text = "Sign In",
    variant = "default",
    className,
    redirectTo = "/",
    ...props
}: LoginButtonProps) {

    const handleLogin = async () => {
        await supabaseClient.auth.signInWithOAuth({
            provider: "google",
            options: {
                redirectTo: `${location.origin}/auth/callback?next=${redirectTo}`,
            },
        });
    };

    return (
        <Button
            variant={variant}
            className={cn(className)}
            onClick={handleLogin}
            {...props}
        >
            {text}
        </Button>
    );
}
