"use client"; import Image from "next/image"; import { useRouter } from "next/navigation"; import { useState } from "react"; import Button from "@/components/ui/button"; import DismissReasonSheet from "@/components/ui/dismiss-reason-sheet"; import FemaleConsentSheet from "@/components/ui/female-consent-sheet"; import InformationSheet from "@/components/ui/information-sheet"; import NavigationButton from "@/components/ui/navigation-button"; import StickyHeader from "@/components/ui/sticky-header"; import { PageBackground } from "@/components/utils/page-background"; 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 { 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 }: { field: MarriageField }) { const value = formatFieldValue(field.value); if (!value || isImageField(field)) { return null; } const label = field.label || titleFromKey(field.key); return (

{label}

{value}

); } 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 [isDismissReasonSheetOpen, setIsDismissReasonSheetOpen] = useState(false); const { data: profile } = useMarriageProfileQuery(); const caseId = profile?.active_case?.case_id; const caseStatus = profile?.active_case?.status; const isFemaleProfile = profile?.gender === "female"; const isMaleAccepted = caseStatus === "male_accepted"; const respondMutation = useRespondToMarriageCaseMutation(caseId ?? "", { onSuccess: async (_, variables) => { if (variables.action === "accept") { router.push(localizePath("/request-sent", locale)); return; } router.push(localizePath("/candidate-contact", locale)); }, }); const isSubmitting = respondMutation.isPending; const isAcceptProfileEnabled = Boolean(caseId) && !isSubmitting && canAcceptProfile(profile?.gender, caseStatus); return ( <> {isRequestSheetOpen ? ( isFemaleProfile ? ( (
)} onClose={() => { setIsFemaleConsentChecked(false); setIsRequestSheetOpen(false); }} /> ) : ( (
)} onClose={() => setIsRequestSheetOpen(false)} /> ) ) : null} {isRejectSheetOpen ? ( (
)} onClose={() => setIsRejectSheetOpen(false)} /> ) : null} {isDismissReasonSheetOpen ? ( setIsDismissReasonSheetOpen(false)} onSubmit={async (reason) => { if (!caseId) { return; } await respondMutation.mutateAsync({ action: "reject", custom_note: reason, }); }} /> ) : null}

{t.match.title}

{formatFieldValue( profile?.match_summary?.public_info.find( (field) => field.key === "q1_full_name", )?.value ?? null, ) || "Name not available"}

{formatFieldValue( profile?.match_summary?.public_info.find( (field) => field.key === "q1_full_name", )?.value ?? null, ) || "Name not available"}

{profile?.match_summary?.public_info.map((field) => ( ))}
); }