"use client"; import Image from "next/image"; import { useRouter } from "next/navigation"; import { useEffect, useMemo, useState } from "react"; import Button from "@/components/Componentes/button"; import DismissReasonSheet from "@/components/Componentes/dismiss-reason-sheet"; import FemaleConsentSheet from "@/components/Componentes/female-consent-sheet"; import InformationSheet from "@/components/Componentes/information-sheet"; import { LoadingSkeleton } from "@/components/Componentes/loading-skeleton"; import { LoadingThreeDot } from "@/components/Componentes/loading-three-dot"; import NavigationButton from "@/components/Componentes/navigation-button"; import { PageBackground } from "@/components/Componentes/page-background"; import StickyHeader from "@/components/Componentes/sticky-header"; import type { MarriageCaseStatus, MarriageField, MarriageFieldValue, MarriageGender, MarriagePhoneFieldValue, MarriageProfileResponse, } from "@/hooks/marriage/types"; import { useRespondToMarriageCaseMutation } from "@/hooks/marriage/use-case-respond"; import { useMarriageProfileQuery } from "@/hooks/marriage/use-profile-main"; import { getSubmitPath } from "@/lib/get-submit-path"; import { markMatchStarted } from "@/lib/match-start-grace"; import { localizePath } from "@/translations/config"; import { useI18n } from "@/translations/provider"; import { formatFieldLabel, formatFieldValue, formatOptionValue, isMarriagePhoneFieldValue, titleFromKey, } from "@/lib/marriage-field-formatter"; function isImageField(field: MarriageField) { return /(avatar|image|photo|picture|portrait|upload)/i.test( `${field.key} ${field.label}`, ); } function canAcceptProfile( gender: MarriageGender | null | undefined, status: MarriageCaseStatus | null | undefined, ) { if (!gender || !status) { return false; } if (gender === "female") { return status === "introduced" || status === "male_accepted"; } return status === "introduced"; } function MatchField({ field, isCandidateFemale, dictionary, }: { field: MarriageField; isCandidateFemale: boolean; dictionary?: Record; }) { const value = formatOptionValue(field.value, dictionary); if (!value || isImageField(field)) { return null; } const label = formatFieldLabel(field, dictionary); if (isCandidateFemale) { return (

{label}

{value}

); } return (

{label}

{value}

); } function MatchPublicProfileFields({ publicInfo, isCandidateFemale, dictionary, }: { publicInfo: MarriageField[] | null | undefined; isCandidateFemale: boolean; dictionary?: Record; }) { const visibleFields = useMemo(() => { if (!publicInfo) return []; return publicInfo.filter((field) => { if (field.value === null || field.value === "" || isImageField(field)) { return false; } if ((field as any).private === true) { return false; } return true; }); }, [publicInfo]); if (!visibleFields.length) { return (

{dictionary?.["No public information is available to display."] || "No public information is available to display."}

); } if (isCandidateFemale) { return (
{visibleFields.map((field) => ( ))}
); } return (

{dictionary?.["General Information & Personal Details"] || "General Information & Personal Details"}

{visibleFields.map((field) => ( ))}
); } function NewMatchProfileSkeleton({ hideBackButton = false, onClose, }: { hideBackButton?: boolean; onClose?: () => void; }) { const { dictionary: t } = useI18n(); return ( <>
{!hideBackButton ? ( ) : (
)}

{t["More detail"]}

); } function formatBoldText(text: string) { if (!text) return ""; const parts = text.split(/\*\*([^*]+)\*\*/g); return parts.map((part, index) => { if (index % 2 === 1) { return ( {part} ); } return part; }); } type NewMatchProfilePageProps = { onClose?: () => void; profile?: MarriageProfileResponse; }; export default function NewMatchProfilePage({ onClose, profile: profileProp, }: NewMatchProfilePageProps = {}) { const { dictionary: t, locale } = useI18n(); const router = useRouter(); const [isRequestSheetOpen, setIsRequestSheetOpen] = useState(false); const [isFemaleConsentChecked, setIsFemaleConsentChecked] = useState(false); const [isRejectSheetOpen, setIsRejectSheetOpen] = useState(false); const [isMaleRejectWarningOpen, setIsMaleRejectWarningOpen] = useState(false); const [isDismissReasonSheetOpen, setIsDismissReasonSheetOpen] = useState(false); const { data: queriedProfile, isLoading: isQueryLoading, refetch: refetchProfile, } = useMarriageProfileQuery({ enabled: !profileProp, }); const profile = profileProp ?? queriedProfile; const isLoading = !profileProp && isQueryLoading; useEffect(() => { if (!profile) { return; } const targetPath = getSubmitPath(profile); const caseStatus = profile?.active_case?.status; const isProfileMatched = profile?.status === "matched"; const isViewingAllowed = caseStatus === "payment_done" || caseStatus === "contacted" || caseStatus === "finalized" || isProfileMatched; if ( targetPath !== "/new-match" && targetPath !== "/request-sent" && !isViewingAllowed ) { router.replace(localizePath(targetPath, locale)); } }, [profile, locale, router]); const caseId = profile?.active_case?.case_id; const caseStatus = profile?.active_case?.status; const isFemaleProfile = profile?.gender === "female"; const respondMutation = useRespondToMarriageCaseMutation(caseId ?? "", { onSuccess: async (data, variables) => { onClose?.(); if (variables.action === "accept") { const nextPath = profile?.gender === "female" ? "/request-accepted" : "/request-sent"; router.replace(localizePath(nextPath, locale)); return; } router.replace(localizePath("/finding-match", locale)); }, }); const candidateName = useMemo(() => { const publicInfo = profile?.match_summary?.public_info ?? []; const firstNameIdx = publicInfo.findIndex( (f) => f.key === "personal_identity.first_name" || f.key?.endsWith(".first_name"), ); const lastNameIdx = publicInfo.findIndex( (f) => f.key === "personal_identity.last_name" || f.key?.endsWith(".last_name"), ); if (firstNameIdx !== -1 && publicInfo[firstNameIdx].value) { const firstName = formatFieldValue(publicInfo[firstNameIdx].value); if (lastNameIdx !== -1 && publicInfo[lastNameIdx].value) { const lastName = formatFieldValue(publicInfo[lastNameIdx].value); return `${firstName} ${lastName}`.trim(); } return firstName || ""; } const nameField = publicInfo.find( (f) => f.key === "q1_full_name" || f.key.endsWith(".full_name") || f.key.toLowerCase().includes("fullname") || f.key.toLowerCase().includes("display_name"), ); const formatted = formatFieldValue(nameField?.value ?? null); if (formatted) return formatted; const firstVal = publicInfo.find((f) => Boolean(f.value))?.value ?? null; return ( formatFieldValue(firstVal) || (profile?.match_summary?.id ? `Profile #${profile.match_summary.id}` : "Profile") ); }, [profile?.match_summary]); const isCandidateFemale = profile?.match_summary?.gender === "female" || profile?.gender === "male"; const avatarSrc = isCandidateFemale ? "/assets/images/female_avatar.svg" : "/assets/images/Group 1597880481.png"; const isRedirecting = useMemo(() => { if (!profile) return false; const targetPath = getSubmitPath(profile); const caseStatus = profile?.active_case?.status; const isProfileMatched = profile?.status === "matched"; const isViewingAllowed = caseStatus === "payment_done" || caseStatus === "contacted" || caseStatus === "finalized" || isProfileMatched; return ( targetPath !== "/new-match" && targetPath !== "/request-sent" && !isViewingAllowed ); }, [profile]); const isSubmitting = respondMutation.isPending; if ((isLoading && !profile) || !profile) { return ( ); } const isAcceptProfileEnabled = Boolean(caseId) && !isSubmitting && canAcceptProfile(profile?.gender, caseStatus); const isRejectProfileEnabled = isAcceptProfileEnabled; const nameParts = candidateName.trim().split(/\s+/); const _firstName = nameParts[0] || ""; const _lastName = nameParts.slice(1).join(" ") || ""; const mainClass = "-mx-[17px] flex h-dvh flex-col overflow-hidden"; const mainStyle = { backgroundImage: `url("/assets/images/islamic_pattern_2_2892_3864.svg")`, backgroundColor: "#F5F5F5", backgroundRepeat: "repeat-y", backgroundSize: "100% auto", }; return ( <> {isRequestSheetOpen ? ( isFemaleProfile ? ( (
)} onClose={() => { setIsFemaleConsentChecked(false); setIsRequestSheetOpen(false); }} /> ) : ( (
)} onClose={() => setIsRequestSheetOpen(false)} /> ) ) : null} {isRejectSheetOpen ? ( (
)} onClose={() => setIsRejectSheetOpen(false)} /> ) : null} {isMaleRejectWarningOpen ? ( (
)} onClose={() => setIsMaleRejectWarningOpen(false)} /> ) : null} {isDismissReasonSheetOpen ? ( setIsDismissReasonSheetOpen(false)} onSubmit={async (reason) => { if (!caseId) { return; } await respondMutation.mutateAsync({ action: "reject", custom_note: reason, }); }} /> ) : null}

{t["More detail"]}

{/* Frame 2095586585 - Avatar Section */}
{/* Avatar Group */}
{/* Frame 2095586663 - Names Section */}
{candidateName}
{caseStatus === "payment_done" || caseStatus === "contacted" || caseStatus === "finalized" || profile?.status === "matched" ? ( ) : (
)}
); }