"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, } 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 { localizePath } from "@/translations/config"; import { useI18n } from "@/translations/provider"; function formatFieldValue(value: MarriageFieldValue) { if (value === null || value === "") { return null; } if (isMarriagePhoneFieldValue(value)) { return `+${value.countryCode}${value.phoneNumber}`; } if (typeof value === "boolean") { return value ? "Yes" : "No"; } return String(value); } function isMarriagePhoneFieldValue( value: unknown, ): value is MarriagePhoneFieldValue { if (!value || typeof value !== "object") { return false; } const phoneValue = value as Partial; return ( typeof phoneValue.countryCode === "string" && typeof phoneValue.phoneNumber === "string" ); } function titleFromKey(key: string) { return key .replace(/^q\d+[_-]?/i, "") .replace(/[_-]+/g, " ") .replace(/\s+/g, " ") .trim() .replace(/\b\w/g, (letter) => letter.toUpperCase()); } 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, }: { field: MarriageField; isCandidateFemale: boolean; }) { const value = formatFieldValue(field.value); if (!value || isImageField(field)) { return null; } const label = field.label || titleFromKey(field.key); if (isCandidateFemale) { return (

{label}

{value}

); } return (

{label}

{value}

); } function MatchPublicProfileFields({ publicInfo, isCandidateFemale, }: { publicInfo: MarriageField[] | null | undefined; isCandidateFemale: boolean; }) { 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 (

اطلاعات عمومی قابل نمایشی ثبت نشده است.

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

اطلاعات عمومی و مشخصات فردی

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

{t["New Match"]}

); } 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; }); } export default function NewMatchProfilePage() { 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: profile, isLoading, refetch: refetchProfile, } = useMarriageProfileQuery(); 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 (_, variables) => { if (variables.action === "accept") { const { data: updatedProfile } = await refetchProfile(); const nextPath = getSubmitPath(updatedProfile); router.replace(localizePath(nextPath, locale)); return; } router.replace(localizePath("/finding-match", locale)); }, }); const candidateName = useMemo(() => { const publicInfo = profile?.match_summary?.public_info ?? []; const nameField = publicInfo.find( (f) => f.key === "q1_full_name" || f.key.toLowerCase().includes("name") || f.key.toLowerCase().includes("nam") || f.label.includes("نام"), ); 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?.public_info]); 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 || isRedirecting || isSubmitting) { 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 min-h-screen flex-col pb-10"; 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" ? ( ) : (
)}
); }