import EventsView from "@/components/admin/EventsView";
import InvitationMessages from "@/components/admin/InvitationMessages";
import { readSession } from "@/lib/api/admin-server";

export const dynamic = "force-dynamic";

export default async function EventsPage() {
  const session = await readSession();
  // Hides the controls only. The API decides on its own authority — `test_admin_route_guards`
  // and task 8.8 cover the case of a Host calling the endpoints directly.
  const canEdit = (session?.permissions ?? []).includes("edit_content");

  return (
    <>
      <h1 className="mb-1 text-lg font-semibold tracking-tight">Events</h1>
      <p className="mb-4 text-sm text-stone-600">
        Each event owns its guest list and its invitation card. Changing a date re-points
        every queued reminder at the new one.
      </p>
      <EventsView canEdit={canEdit} />

      {/* Wedding-wide, not per event: the greeting is the couple's voice, and it would be
          odd for the same guest to be greeted differently at the Mehedi and the Walima. */}
      <div className="mt-6">
        <InvitationMessages canEdit={canEdit} />
      </div>
    </>
  );
}
