"use client";
import type { IndividualSignupExtrasValues } from "./individualSignupExtrasRules";

import dynamic from "next/dynamic";
import type { SocialAuthPayload } from "@/features/auth/services/authApi";

/** The mandate form's shape and its lazy country-code picker. */

export const CountryCodeSelect = dynamic(
  () => import("@/components/ui/CountryCodeSelect"),
  {
    ssr: false,
    loading: () => (
      <div className="h-[48px] rounded-2xl bg-gray-100 animate-pulse mb-4" />
    ),
  }
);

/**
 * The half-made user a social sign-up or a fresh registration hands to the
 * mandate form.
 *
 * Only the two names are read, to prefill the form; everything else is spread
 * verbatim into the `social-auth` body — so the right type is "a partial of
 * that body", not an open bag. An earlier version here used an index
 * signature, which accepted any key at all; because `socialAuth` validates a
 * closed list of thirteen and Laravel drops the rest silently, an unaccepted
 * key would have been lost with nothing to show for it.
 */
export type MandatePrefillUser = Partial<SocialAuthPayload>;

export interface MandateFormValues extends IndividualSignupExtrasValues {
  receive_reminder_emails: boolean;
  first_name: string;
  last_name: string;
  phone_number: string;
  nickname: string;
  dob: string;
  gender: string;
  country_code: string;
  civil_id: string;
  passport_number: string;
  /** Combined nationality/residency choice; split into API fields on submit. */
  nationality: string;
  /** BE-77 — "" | "true" | "false"; blank stays unanswered on the wire. */
  speaks_arabic: string;
  health_concerns: string;
  interest_ids: string[];
  termsAccepted: boolean;
  emergency_contact_name: string;
  emergency_contact_phone: string;
  emergency_contact_country_code: string;
  emergency_contact_civil_id: string;
  emergency_contact_relationship: string;
}

export default CountryCodeSelect;
