import { type ReactNode } from "react"; import SmartLink from "@/front/Components/Shared/SmartLink"; type CtaButtonSize = "sm" | "md" | "lg"; type CtaButtonVariant = "filled" | "outline"; interface CtaButtonProps { children: ReactNode; href?: string; onClick?: () => void; icon?: ReactNode; iconPosition?: "left" | "right"; color?: "bleu" | "rouge"; variant?: CtaButtonVariant; size?: CtaButtonSize; width?: string; type?: "button" | "submit" | "reset"; rounded?: string; className?: string; } const SIZE_CLASSES: Record = { sm: "px-4 py-2.5 gap-2", md: "px-6 py-3.5 gap-3", lg: "px-8 py-4.5 gap-4", }; const ICON_SIZE: Record = { sm: 18, md: 24, lg: 28, }; const COLOR_CLASSES: Record< "bleu" | "rouge", Record > = { bleu: { filled: "bg-bleu hover:bg-bleu/90", outline: "border-4 border-bleu bg-white hover:bg-bleu/5", }, rouge: { filled: "bg-rouge hover:bg-rouge/90", outline: "border-4 border-rouge bg-white hover:bg-rouge/5", }, }; export default function CtaButton({ children, href, onClick, icon, iconPosition = "left", color = "bleu", variant = "filled", size = "md", width = "", type = "button", rounded = "rounded-full", className = "", }: Readonly) { const colorClasses = COLOR_CLASSES[color][variant]; const textColorClass = variant === "outline" ? color === "rouge" ? "text-rouge" : "text-bleu" : "text-white"; const iconSize = ICON_SIZE[size]; const renderIconWrapper = () => { if (!icon) return null; return ( svg]:w-full [&>svg]:h-full ${textColorClass}`} style={{ width: iconSize, height: iconSize }} > {icon} ); }; const resolvedIcon = renderIconWrapper(); const content = ( <> {resolvedIcon && iconPosition === "left" && resolvedIcon} {children} {resolvedIcon && iconPosition === "right" && resolvedIcon} ); const classes = `inline-flex items-center justify-center ${rounded} transition-colors cursor-pointer ${SIZE_CLASSES[size]} ${colorClasses} ${width} ${className}`; return ( {content} ); }