import { Button } from '@/Components/ui';
import type { ButtonBlock as ButtonBlockData } from '@/marketing/cms-types';
import { SafeCmsLink } from '@/marketing/safe-cms-link';

const ALIGN_CLASS: Record<NonNullable<ButtonBlockData['align']>, string> = {
    left: 'justify-start',
    center: 'justify-center',
};

export default function ButtonBlock({ block }: { block: ButtonBlockData }) {
    // Empty label = skip render entirely (matches Hero + FinalCta CTA gate).
    // Admin can't surface an empty button by saving a blank label.
    const label = (block.label ?? '').trim();
    if (label === '') {
        return null;
    }

    const variant = block.variant === 'secondary' ? 'secondary' : 'primary';
    const align = ALIGN_CLASS[block.align ?? 'left'];

    const button = (
        <Button variant={variant} size="lg" className="text-base">
            {label}
        </Button>
    );

    return (
        <div className={`mt-6 first:mt-0 flex ${align}`}>
            <SafeCmsLink href={block.href} external={block.external}>
                {button}
            </SafeCmsLink>
        </div>
    );
}
