import { Button } from '@/site/components/ui/button';
import { WhatsApp } from '@/site/components/ui/icons';
import { useShared } from '@/site/hooks/use-shared';
import { useT } from '@/site/i18n';
import { cx } from '@/site/lib/cx';
import { openWhatsAppForm } from '@/site/lib/whatsapp-form';

type WhatsAppButtonProps = {
    size?: 'md' | 'lg';
    className?: string;
};

/**
 * "Write on WhatsApp" as an outline button. It is a button, never a link
 * to a WhatsApp number: it opens the short form in the panel of the
 * floating button — name and phone first, the chat afterwards
 * (docs/DECISIONS.md K39). Left out while WhatsApp is not offered; without
 * JavaScript it could do nothing, so it keeps its place but is not shown.
 */
export function WhatsAppButton({ size, className }: WhatsAppButtonProps) {
    const { site } = useShared();
    const t = useT();

    if (!site.whatsapp) {
        return null;
    }

    return (
        <Button
            variant="outline"
            size={size}
            onClick={openWhatsAppForm}
            aria-haspopup="dialog"
            className={cx('needs-js', className)}
        >
            <span className="inline-flex items-center gap-2.5">
                <WhatsApp className="size-5" />
                {t.common.whatsapp}
            </span>
        </Button>
    );
}
