'use client' import { useEffect, useState } from 'react' import { Card, CardBody, CardHeader } from '@/components/heroui/Card' import { formatNumber, formatPersonName } from '@/helpers' import { formatIranianMobile, formatPersianDate } from '@/lib/formatters' import { fetchEventGuestListLinks, fetchEventInvitedGuests, type EventGuestListAccessMode, type EventGuestListLink, type EventInvitedGuest, } from '@/services/eventGuestListAccess' import { format, texts } from '@/texts' interface EventGuestListAccessPanelProps { accessMode: EventGuestListAccessMode eventId: string surface?: 'admin' | 'consumer' } const EventGuestListAccessPanel = ({ accessMode, eventId, surface = 'consumer' }: EventGuestListAccessPanelProps) => { const [links, setLinks] = useState([]) const [invitedGuests, setInvitedGuests] = useState([]) const [isLoading, setIsLoading] = useState(true) const [error, setError] = useState(null) useEffect(() => { let cancelled = false const load = async () => { try { setIsLoading(true) setError(null) const [nextLinks, nextInvitedGuests] = await Promise.all([ fetchEventGuestListLinks(eventId, accessMode), fetchEventInvitedGuests(eventId, accessMode), ]) if (!cancelled) { setLinks(nextLinks) setInvitedGuests(nextInvitedGuests) } } catch { if (!cancelled) setError(texts.events.guestAccessLoadFailed) } finally { if (!cancelled) setIsLoading(false) } } void load() return () => { cancelled = true } }, [accessMode, eventId]) const surfaceClass = surface === 'admin' ? 'admin-surface' : 'consumer-surface' return ( {texts.events.guestAccessTitle} {isLoading ?

{texts.events.guestAccessLoading}

: null} {error ?

{error}

: null} {!isLoading && !error ? ( <>

{texts.events.guestListsConnected}

{format(texts.events.guestListsCount, { count: formatNumber(links.length) })}
{links.length ? (
{links.map((link) => (

{link.listName ?? texts.events.guestListFallback}

{link.notifiedAt ? format(texts.events.guestListNotifiedAt, { date: formatPersianDate(String(link.notifiedAt)) }) : texts.events.guestListNotNotified}

))}
) : (

{texts.events.guestListsEmpty}

)}

{texts.events.invitedGuestsTitle}

{format(texts.events.personCount, { count: formatNumber(invitedGuests.length) })}
{invitedGuests.length ? (
{invitedGuests.map((guest, index) => (

{formatPersonName(guest.firstName, guest.lastName)}

{formatIranianMobile(guest.mobile)}

))}
) : (

{texts.events.invitedGuestsEmpty}

)}
) : null}
) } export default EventGuestListAccessPanel