"use client"; import React, { useState, useCallback } from "react"; import { Button } from "@/components/ui/Button"; import { useI18n } from "./i18n-context"; interface FloatingChatButtonProps { onClick: () => void; isOpen?: boolean; unreadCount?: number; position?: "bottom-right" | "bottom-left" | "top-right" | "top-left"; size?: "sm" | "md" | "lg"; color?: string; className?: string; disabled?: boolean; ariaLabel?: string; } export function FloatingChatButton({ onClick, isOpen = false, unreadCount = 0, position = "bottom-right", size = "md", color = "#3B82F6", className = "", disabled = false, ariaLabel, }: FloatingChatButtonProps) { // Use i18n context const { t } = useI18n(); // Use default aria label from translations if not provided const displayAriaLabel = ariaLabel || t("openChat"); const [isHovered, setIsHovered] = useState(false); const handleClick = useCallback(() => { if (!disabled) { onClick(); } }, [onClick, disabled]); const handleKeyDown = useCallback( (event: React.KeyboardEvent) => { if (event.key === "Enter" || event.key === " ") { event.preventDefault(); handleClick(); } }, [handleClick] ); const getPositionClasses = () => { switch (position) { case "bottom-left": return "bottom-6 left-6"; case "top-right": return "top-6 right-6"; case "top-left": return "top-6 left-6"; default: return "bottom-6 right-6"; } }; const getSizeClasses = () => { switch (size) { case "sm": return "w-12 h-12 text-sm"; case "lg": return "w-20 h-20 text-xl"; default: return "w-16 h-16 text-lg"; } }; const getIconSize = () => { switch (size) { case "sm": return "w-6 h-6"; case "lg": return "w-10 h-10"; default: return "w-8 h-8"; } }; const ChatIcon = () => ( {isOpen ? ( ) : ( )} ); return (
{/* Tooltip */} {isHovered && !isOpen && (
{displayAriaLabel}
)}
); } export default FloatingChatButton;