'use client'; import { AbstractApi } from "@/app/api/abstract-api"; import { Guest } from "@/app/lib/guest"; import { Invitation, InvitationSerializer } from "@/app/lib/invitation"; export default function InvitationsBoard({ guests, invitations }: { guests: Array, invitations: Array }) { const api = new AbstractApi(); const serializer = new InvitationSerializer(); // Filter out guests that are already in invitations const availableGuests = guests.filter( (guest) => !invitations.some((invitation) => invitation.guests.some((invitedGuest) => invitedGuest.id === guest.id) ) ); // Sort invitations to display those without guests at the top const sortedInvitations = [...invitations].sort((a, b) => { if (a.guests.length === 0 && b.guests.length > 0) return -1; if (a.guests.length > 0 && b.guests.length === 0) return 1; return 0; }); function handleCreateInvitation() { api.create(serializer, new Invitation(), () => { console.log("Invitation created successfully"); }); } return (
{/* Left Column: Guests */}

{guests.length} guests without invitation

    {availableGuests.map((guest, index) => (
  • {guest.name}

  • ))}
{/* Right Column: Invitations */}

{invitations.length} invitations

{sortedInvitations.map((invitation, index) => (
{invitation.guests.length === 0 ? (

(empty invitation)

) : (
    {invitation.guests.map((guest) => (
  • {guest.name}
  • ))}
)}
))}
); }