"use client";

import { Button } from "@/components/ui/button";
import { getPhoneNumber, getContactLink } from "@/lib/constants";
import { cn } from "@/lib/utils";

interface CallButtonProps {
    variant?: "lime" | "amber";
    fullWidth?: boolean;
    text?: string;
    showIcon?: boolean;
    rounded?: boolean;
    page?: string;
}

export default function CallButton({
    variant = "lime",
    fullWidth,
    text,
    rounded,
    page,
}: CallButtonProps) {
    const handleClick = () => {
        if (
            typeof window !== "undefined" &&
            typeof window.gtag_report_conversion === "function"
        ) {
            window.gtag_report_conversion();
            console.log("called conversion tracking");
        } else {
            console.error("gtag_report_conversion function not found");
        }
    };

    const phoneNumber = getPhoneNumber(page);
    const contactLink = getContactLink(page);

    return (
        <a href={contactLink}>
            <Button
                size="lg"
                variant={variant}
                onClick={handleClick}
                className={cn(fullWidth ? "w-full" : "")}
                rounded={rounded ? "full" : "default"}
            >
                <p>{text ? text : `Call ${phoneNumber}`}</p>
            </Button>
        </a>
    );
}
