import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'; import { useAuth } from '../context/AuthContext'; import { birthdayApi } from '../services/api'; import { Cake, X } from 'lucide-react'; import Button from './ui/Button'; export default function BirthdayModal() { const { isCustomerPortal } = useAuth(); const queryClient = useQueryClient(); const { data } = useQuery({ queryKey: ['my-birthday'], queryFn: () => birthdayApi.getMyBirthday(), enabled: isCustomerPortal, staleTime: 60 * 60_000, // 1h (reicht völlig) }); const ackMutation = useMutation({ mutationFn: () => birthdayApi.acknowledgeMyBirthday(), onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['my-birthday'] }); }, }); const info = data?.data; if (!info?.show) return null; const handleClose = () => ackMutation.mutate(); // Anrede abhängig vom Du/Sie-Verhältnis zusammenstellen const greetingName = info.useInformalAddress ? info.firstName : [info.salutation, info.lastName].filter(Boolean).join(' ') || info.firstName; const greetingPronoun = info.useInformalAddress ? 'dir' : 'Ihnen'; const greetingPossessive = info.useInformalAddress ? 'deinem' : 'Ihrem'; const greetingYour = info.useInformalAddress ? 'Dein' : 'Ihr'; const hadBirthday = info.useInformalAddress ? 'hattest' : 'hatten'; const becameOld = info.useInformalAddress ? 'bist' : 'sind'; return (
{/* Konfetti-Header */}
🎉🎂🎈
{/* Nachricht */}
{info.isToday ? ( <>

Herzlichen Glückwunsch, {greetingName}!

Alles Gute zu {greetingPossessive} {info.age}. Geburtstag!

Wir wünschen {greetingPronoun} einen wunderschönen Tag und alles Gute für {greetingYour.toLowerCase()} neues Lebensjahr. 🌟

) : ( <>

Nachträglich alles Gute, {greetingName}!

{greetingYour === 'Ihr' ? 'Sie' : 'Du'} {hadBirthday} vor {info.daysAgo} Tag{info.daysAgo === 1 ? '' : 'en'} Geburtstag {info.age > 0 && ` und ${becameOld} ${info.age} Jahre alt geworden`}.

Wir wünschen {greetingPronoun} alles Gute nachträglich und eine tolle Zeit im neuen Lebensjahr. 🌟

)}
); }