"use client"; import Image from "next/image"; import { useRouter } from "next/navigation"; import { useCallback, useEffect, useMemo, useState } from "react"; import { useHardwareBackHandler } from "@/hooks/use-hardware-back-handler"; import { useHabibWebReady } from "@/hooks/use-habib-web-ready"; import { Ic } from "@/icons"; import AdvisorActionsCard from "@/components/Componentes/advisor-actions-card"; import MarriageAdvisorsOverlay, { useMarriageAdvisorsOverlay, } from "@/components/Componentes/marriage-advisors-overlay"; import QuestionsListOverlay, { useQuestionsListOverlay, } from "@/components/Componentes/questions-list-overlay"; import Button from "@/components/Componentes/button"; import { FixToTheEnd } from "@/components/Componentes/fix-to-the-end"; import { PageBackground } from "@/components/Componentes/page-background"; import PageHeader from "@/components/Componentes/page-header"; import { useMarriageProfileQuery } from "@/hooks/marriage/use-profile-main"; import { useRejectionSeenMutation } from "@/hooks/marriage/use-rejection-seen"; 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/Avatar Image.png" }, { id: "advisor-tertiary", src: "/assets/images/Avatar Image.png" }, ]; export default function FindingMatchClient() { const router = useRouter(); const { dictionary: t, locale } = useI18n(); const { isAdvisorOpen, openAdvisors, closeAdvisors } = useMarriageAdvisorsOverlay(); const { isQuestionsOpen, openQuestions, closeQuestions } = useQuestionsListOverlay(); const [isQuestionsReady, setIsQuestionsReady] = useState(false); const [isOpeningEditProfile, setIsOpeningEditProfile] = useState(false); const handleQuestionsReady = useCallback(() => { setIsQuestionsReady(true); }, []); useEffect(() => { if (isQuestionsReady && isOpeningEditProfile) { setIsOpeningEditProfile(false); openQuestions(); } }, [isQuestionsReady, isOpeningEditProfile, openQuestions]); // Safety fallback if background preparation takes unexpectedly long useEffect(() => { if (!isOpeningEditProfile) return; const timer = setTimeout(() => { setIsOpeningEditProfile(false); openQuestions(); }, 2000); return () => clearTimeout(timer); }, [isOpeningEditProfile, openQuestions]); const handleEditProfileClick = useCallback(() => { if (isQuestionsReady) { openQuestions(); } else { setIsOpeningEditProfile(true); } }, [isQuestionsReady, openQuestions]); const { data: profile, isLoading, isFetched } = useMarriageProfileQuery({ refetchInterval: 3000, }); const { mutate: markRejectionSeen, isPending: isMarkingSeen } = useRejectionSeenMutation(); useHardwareBackHandler(() => { if (isAdvisorOpen) { closeAdvisors(); return true; } if (isQuestionsOpen) { closeQuestions(); return true; } return false; // Hardware back closes the service in Flutter }); useEffect(() => { console.log("🔍 [FindingMatchClient] State Evaluation:", { hasProfile: Boolean(profile), isFetched, status: profile?.status, active_case: profile?.active_case, calculatedPath: profile ? getSubmitPath(profile) : null, }); if (!profile || !isFetched) { console.log("⏳ [FindingMatchClient] Skipping redirect because !profile or !isFetched (isFetched=", isFetched, ")"); return; } const targetPath = getSubmitPath(profile); if (targetPath !== "/finding-match") { console.log("🚀 [FindingMatchClient] Redirecting to:", targetPath); router.replace(localizePath(targetPath, locale)); } }, [profile, isFetched, locale, router]); // Signal Flutter to lift its loading cover immediately so page renders with 0ms latency. useHabibWebReady(true); const isRedirecting = useMemo(() => { if (!profile) return false; return getSubmitPath(profile) !== "/finding-match"; }, [profile]); const copy = { title: t["SEARCH IN PROGRESS"], description: t[ "Our system is actively looking for compatible partners based on your criteria. This process requires time and patience. We will notify you immediately once a profile is ready for your review." ], advisorTitle: t["Get an advisor"], advisorDescription: t[ "Not sure what to do next? Our psychology section is here to guide you at every step." ], getAdvisor: t["Get Advisor"], editProfile: t["Edit Profile"], }; const matchImageSrc = "/assets/images/Group 1597880466.svg"; // This notice belongs exclusively to the gentleman whose accepted request // was later rejected by the lady. The API enforces the same rule. const unseenRejection = profile?.gender === "male" ? profile.unseen_rejection : null; return ( <> { if (typeof window !== "undefined" && (window as any).HabibApp) { (window as any).HabibApp.postMessage( JSON.stringify({ action: "close_service" }), ); } else { router.back(); } }, }} />

{copy.title}

{copy.description}

{unseenRejection && ( )}{" "}
{/* Outside
: page-slide-enter sets will-change:transform which makes main the containing block for position:fixed and narrows the button. */} {profile?.can_edit_profile === false ? (
) : ( )}
); }