"use client"; import Image from "next/image"; import { useRouter } from "next/navigation"; import { useEffect, useMemo, useState } from "react"; import { useHabibWebReady } from "@/hooks/use-habib-web-ready"; import { LoadingThreeDot } from "@/components/Componentes/loading-three-dot"; import { PageLoadingSkeleton } from "@/components/Componentes/page-loading-skeleton"; import CallResultSheet from "@/components/Componentes/call-result-sheet"; import DismissReasonSheet from "@/components/Componentes/dismiss-reason-sheet"; import OutcomeSelectionSheet from "@/components/Componentes/outcome-selection-sheet"; import PageHeader from "@/components/Componentes/page-header"; import AdvisorActionsCard from "@/components/Componentes/advisor-actions-card"; import MarriageAdvisorsOverlay, { useMarriageAdvisorsOverlay, } from "@/components/Componentes/marriage-advisors-overlay"; import MatchProfileOverlay, { useMatchProfileOverlay, } from "@/components/Componentes/match-profile-overlay"; import { PageBackground } from "@/components/Componentes/page-background"; import { useMarriageProfileQuery } from "@/hooks/marriage/use-profile-main"; import { useSubmitMarriageContactStatusMutation, useSubmitMarriageOutcomeMutation, } from "@/hooks/marriage/use-contact-status"; import { getSubmitPath } from "@/lib/get-submit-path"; import { localizePath } from "@/translations/config"; import { useI18n } from "@/translations/provider"; const advisorAvatars = [ { id: "advisor-primary", src: "/assets/images/Avatar Image.png" }, { id: "advisor-secondary", src: "/assets/images/Ellipse 370.png" }, { id: "advisor-tertiary", src: "/assets/images/Avatar Image.png" }, ]; export default function CandidateContactClient() { const { dictionary: t, locale } = useI18n(); const router = useRouter(); const [isOutcomeSheetOpen, setIsOutcomeSheetOpen] = useState(false); const [isCallResultSheetOpen, setIsCallResultSheetOpen] = useState(false); const [isDismissReasonSheetOpen, setIsDismissReasonSheetOpen] = useState(false); const { isAdvisorOpen, openAdvisors, closeAdvisors } = useMarriageAdvisorsOverlay(); const { isProfileOpen, openProfile, closeProfile } = useMatchProfileOverlay(); const { data: profile, isLoading: isProfileLoading } = useMarriageProfileQuery({ refetchInterval: 3000, }); useEffect(() => { if (!profile) { return; } const targetPath = getSubmitPath(profile); if (targetPath !== "/candidate-contact") { router.replace(localizePath(targetPath, locale)); } }, [profile, router, locale]); // Signal Flutter to lift its loading cover once the profile is available. useHabibWebReady(!!profile && !isProfileLoading); const isRedirecting = useMemo(() => { if (!profile) return false; return getSubmitPath(profile) !== "/candidate-contact"; }, [profile]); const caseId = profile?.active_case?.case_id; const caseStatus = profile?.active_case?.status; const isFemale = profile?.gender === "female"; const isFinalized = caseStatus === "finalized" || profile?.status === "matched"; const contactStatusMutation = useSubmitMarriageContactStatusMutation( caseId ?? "", ); const outcomeMutation = useSubmitMarriageOutcomeMutation(caseId ?? ""); const handleNoContactReport = async () => { if (!caseId || contactStatusMutation.isPending) return; await contactStatusMutation.mutateAsync({ action: "no_contact", custom_note: "No contact reported by female candidate after decision window", }); }; if (isProfileLoading || isRedirecting) { return ; } // If female, render the beautiful, customized layout matching the design if (isFemale) { return ( <> {isOutcomeSheetOpen ? ( setIsOutcomeSheetOpen(false)} onSubmit={async (status) => { if (status === "success") { if (caseId) { await outcomeMutation.mutateAsync({ status: "success", }); } } else { setIsDismissReasonSheetOpen(true); } }} /> ) : null} {isDismissReasonSheetOpen ? ( setIsDismissReasonSheetOpen(false)} onSubmit={async (value) => { if (caseId) { await outcomeMutation.mutateAsync({ status: "failure", custom_note: value, }); } }} /> ) : null}
{isFinalized ? (
🎉

{t["Congratulations! 🎉"]}

{ t[ "Wishing you a lifetime of love, joy, and happiness. Your profile has been successfully closed." ] }

) : ( <> {/* Illustration section */}
{t["Selected
{/* Title / Status message */}

{ t[ "The selected candidate will contact your family shortly." ] }

{caseStatus === "contacted" ? ( <> {/* Outcome instructions and button */}

{ t[ "Thank you for giving us feedback, we would be very happy if you also let us know the final result." ] }

) : ( <> {/* Action Buttons Row */}
{/* Red warning box */}

{ t[ "To keep the process moving smoothly, the other party has a 48-hour (2-day) window to make initial contact with you or your family. If no contact is established after 2 days, you have the option to decline his request or notify us that he hasn't reached out." ] }

)} )}
{/* Advisor section */} {/* Profile Locked banner */}
lock

{t["Profile is locked"]}

); } // Fallback UI for male/other users return ( <> {isCallResultSheetOpen ? ( setIsCallResultSheetOpen(false)} onOtherReasonsClick={() => setIsDismissReasonSheetOpen(true)} onSubmit={async (value) => { if (caseId) { await contactStatusMutation.mutateAsync({ action: "contacted", custom_note: value, }); } }} /> ) : null} {isDismissReasonSheetOpen ? ( setIsDismissReasonSheetOpen(false)} onSubmit={async (value) => { if (caseId) { await contactStatusMutation.mutateAsync({ action: "contacted", custom_note: value, }); } }} /> ) : null}
{t["Selected

{t["The selected candidate will contact your family shortly."]}

); }