/**
 * The shapes and fixed lists the development-opportunity detail page works in.
 *
 * `LearnServeOpportunityData` is what `GET /learn-serve-opportunities/{id}/`
 * returns, as this page reads it — kept beside the page rather than in it so
 * the sections can be typed against the same record.
 */
/** Re-exported so existing importers keep working off one definition. */
export type { ChoiceDisplay } from "@/lib/choices";
import type { ChoiceDisplay } from "@/lib/choices";

export interface OpportunityImage {
  id: number;
  image: string;
  is_after_completed?: boolean;
}

export interface LearnServeOpportunityData {
  id: string | number;
  title_en: string;
  title_ar: string;
  /**
   * BE-125 — a paid opportunity registers through the gateway: the same
   * registration endpoint answers `{ registration, transaction }` and the
   * payer has to be sent to `transaction.gateway_checkout_url`. Both are on
   * `LearnServeOpportunityResource` (`:99` and `:100`); `price` is `null` on a
   * free one.
   */
  is_paid?: boolean | null;
  has_active_payments?: boolean;
  has_successful_payments?: boolean;
  /** Server capability flags (`OpportunityCapabilities`); absent on older APIs. */
  can_edit?: boolean;
  can_delete?: boolean;
  can_message?: boolean;
  can_request_deletion?: boolean;
  /** `approval_status` (pending / approved / rejected); `rejected_reason` is sent to the owner only. */
  approval_status?: string | null;
  rejected_reason?: string | null;
  /** not_requested / pending / approved / rejected: a deletion request with administration. */
  deletion_status?: string | null;
  start_at?: string | null;
  end_at?: string | null;
  time_slots?: { date?: string | null; start_time?: string | null; end_time?: string | null }[] | null;
  timeslots_display?: { date?: string | null; start_time?: string | null; end_time?: string | null }[] | null;
  registration_closes_at?: string | null;
  /** `CancellationRequestService::statusFor` — null unless the viewer holds a paid booking. */
  cancellation_status?: "available" | "awaiting_trainer" | "pending" | "refunding" | "refund_failed" | "approved" | "rejected" | null;
  payment_status?: string | null;
  /** `ParticipantRefundState` (backend `bf3140b`): the viewer's own refund on a refund-all course. */
  refund_status?: "processing" | "refunded" | "failed" | null;
  /** Owner only: the publisher's latest refund-all request (`OwnerPaymentFlags`), null for anyone else. */
  refund_all_status?: "pending" | "processing" | "completed" | "rejected" | null;
  price?: number | string | null;
  description_en?: string;
  description_ar?: string;
  primary_language?: string;
  due_date?: string;
  start_date: string;
  end_date: string;
  start_time: string;
  end_time: string;
  location_en?: string;
  location_ar?: string;
  location_url?: string | null;
  /** The map pin's label; new records carry it instead of a text location. */
  map_desc?: string | null;
  latitude?: number | string;
  longitude?: number | string;
  link?: string;
  /**
   * BE-65 — the opportunity's own WhatsApp contact, ungated. Distinct from
   * `link`, which on this model is the online meeting URL and is revealed only
   * to registered participants.
   */
  whatsapp_link?: string | null;
  from_age?: number;
  to_age?: number;
  participants_needed?: number;
  registered_volunteers_count?: number;
  opportunity_status?: string;
  action_state?: string;
  is_creator?: boolean;
  /** Per-viewer: "organizer" | "sponsor" | "registered" | "attended". */
  relationship_tags?: string[] | null;
  is_registration_closed?: boolean;
  is_registration_open?: boolean;
  is_registered?: boolean;
  is_attended?: boolean;
  is_kuwaitis?: boolean;
  /**
   * BE-77 — the four-way audience that replaces `is_kuwaitis`. Absent
   * until the backend ships it; `opportunityNationalityFrom` falls back
   * to the boolean, so this page reads correctly either way.
   */
  opportunity_nationality?: string | null;
  /** All development types require actual attendance under the reviewed policy. */
  requires_check_in?: boolean;
  manual_attendance_enabled?: boolean;
  preparation_valid_until?: string | null;
  preparation_valid_until_at?: string | null;
  is_preparation_window_closed?: boolean;
  preparation_reopened_until?: string | null;
  /** A14: the final-day scan window (Kuwait instants with offset). */
  scan_opens_at?: string | null;
  scan_closes_at?: string | null;
  after_completed_images_count?: number;
  gender_display?: ChoiceDisplay;
  format_display?: ChoiceDisplay;
  learning_type_display?: ChoiceDisplay;
  certificate_type_display?: ChoiceDisplay;
  interest_display?: Array<{
    id: string | number;
    value_en: string;
    value_ar: string;
  }> | null;
  interests?: Array<{
    id: number | string;
    name_en: string;
    name_ar: string;
    interest_type?: string;
  }> | null;
  opportunity_images?: OpportunityImage[];
  opportunity_sponsor_images?: Array<{
    id: number | string;
    image: string;
    organization: number;
    position: number;
  }>;
  created_by: {
    id: string | number;
    full_name?: string;
    profile_pic?: string | null;
    is_public?: boolean;
    gender_display?: ChoiceDisplay;
    facebook_link?: string | null;
    twitter_link?: string | null;
    whatsapp_link?: string | null;
    instagram_link?: string | null;
    linkedin_link?: string | null;
  };
}

export const SOCIAL_LINKS = [
  { key: "facebook_link", icon: "/assets/profile/facebook.svg" },
  { key: "twitter_link", icon: "/assets/profile/twitter.svg" },
  { key: "whatsapp_link", icon: "/assets/profile/whatsapp.svg" },
  { key: "instagram_link", icon: "/assets/profile/instagram.svg" },
  { key: "linkedin_link", icon: "/assets/profile/linkdin.svg" },
] as const;

export const TAG_BACKGROUNDS = ["#70B4C2", "#FC9555", "#D9EF61", "#5271FF"];
export const TAG_TEXT_COLORS = [
  "text-primary-5",
  "text-primary-5",
  "text-primary-5",
  "text-white",
];

/** Learning types that always carry a certificate, and so a check-in. */
export const CERTIFICATE_TYPES = ["Course", "Internship"];

/**
 * Consultations are booked against a specific time slot instead of a plain
 * yes/no confirmation. Matched on the master-choice label, which is
 * `Consultation` / `استشارة` — the previous check looked for `"consultationss"`
 * and `"استشارات"`, neither of which exists, so the slot picker never opened and
 * consultations were registered with no slot at all.
 */
export const isConsultationType = (display?: ChoiceDisplay | null): boolean => {
  const en = display?.value_en?.trim().toLowerCase();
  const ar = display?.value_ar?.trim();
  return en === "consultation" || ar === "استشارة" || ar === "استشارات";
};
