import { NAV_STATE_KEYS, setNavState } from "@/lib/navigationState";
import type { LearnServeOpportunityData } from "./learnServeDetailsTypes";

/**
 * The payload `/leran-share-register-list` reads on mount.
 *
 * App Router has no `navigate(path, { state })`, so this object *is* the
 * contract between the detail page and the registrations list — which is
 * exactly why it does not belong inline in a click handler. Every field is one
 * the list cannot work without and cannot re-derive.
 */
export function stashLearnServeRegisterListNavState(
  opportunityData?: LearnServeOpportunityData | null
): void {
  setNavState(NAV_STATE_KEYS.registerList, {
  id: opportunityData?.id,
  start_at: opportunityData?.start_at,
  end_at: opportunityData?.end_at,
  time_slots: opportunityData?.time_slots,
  start_date: opportunityData?.start_date,
  end_date: opportunityData?.end_date,
  start_time: opportunityData?.start_time,
  end_time: opportunityData?.end_time,
  registration_closes_at: opportunityData?.registration_closes_at,
  // All reviewed development types require recorded final-day presence.
  requires_check_in: opportunityData?.requires_check_in,
  manual_attendance_enabled: opportunityData?.manual_attendance_enabled,
  preparation_valid_until: opportunityData?.preparation_valid_until,
  preparation_valid_until_at: opportunityData?.preparation_valid_until_at,
  is_preparation_window_closed:
    opportunityData?.is_preparation_window_closed,
  preparation_reopened_until: opportunityData?.preparation_reopened_until,
  // Manual «حضر» is refused before the final-day session start (A14).
  scan_opens_at: opportunityData?.scan_opens_at,
  // BE-102 — «إرسال الشهادات» decides visibility from the learning type and
  // pressability from the status, and the list screen fetches neither.
  opportunity_status: opportunityData?.opportunity_status,
  learning_type_display: opportunityData?.learning_type_display,
  certificate_type_display: opportunityData?.certificate_type_display,
  // BE-125 — whether there is a payments table to offer at all. The
  // participants-and-payments screen reads this same payload rather than
  // stashing a second copy of the opportunity under its own key.
  is_paid: opportunityData?.is_paid === true,
  });
}
