import Link from "next/link";
import { getEventCategories } from "@/lib/api/events";
import { getUsers } from "@/lib/api/admin";
import { EventForm } from "@/components/admin/event-form";

/**
 * Create a Signature Event. Reuses the exact same `EventForm` as
 * `/admin/events/new`, with two additions:
 *  - the organizer picker is pre-scoped to Kolabora Official
 *    (`getUsers({ official: true })`) so the event also satisfies the
 *    legacy single-event "Kolabora Official showcase" rule
 *    (`is_signature_event`/`assertSignatureEvent()`), which is required to
 *    call the signature-profile endpoint below without touching that guard;
 *  - `attachSignatureProfile` has the form attach a blank `signature_profile`
 *    row right after creating the event, since presence of that row — not
 *    the organizer — is what actually makes it show up under
 *    `/admin/signature/events` (see Admin\EventController::index()'s
 *    `signature` filter).
 */
export default async function NewAdminSignatureEventPage() {
  const [{ data: categories }, { data: organizers }] = await Promise.all([
    getEventCategories(),
    getUsers({ role: "organizer", official: true }),
  ]);

  return (
    <div className="max-w-xl">
      <Link href="/admin/signature/events" className="text-sm font-medium text-kolabora-primary">
        &larr; Back to Manage Signature Events
      </Link>
      <h2 className="mt-4 text-lg font-semibold">Create New Signature Event</h2>
      <p className="mt-1 text-sm text-kolabora-neutral-dark/70">
        The new event will be saved as a Draft, assigned to the &quot;Kolaborativ Official&quot; organizer.
        Publish it after adding tickets.
      </p>
      {organizers.length === 0 ? (
        <p className="mt-4 text-sm text-red-600">
          The &quot;Kolaborativ Official&quot; organizer account isn&apos;t available yet — cannot create a Signature Event.
        </p>
      ) : (
        <EventForm
          categories={categories}
          organizers={organizers}
          basePath="/admin/signature/events"
          attachSignatureProfile
        />
      )}
    </div>
  );
}
