"use client";
import Image from "next/image";
import { useRouter } from "next/navigation";
import { useEffect, useMemo } 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 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 { data: profile, isLoading, isFetched } = useMarriageProfileQuery({
refetchInterval: 3000,
});
const { mutate: markRejectionSeen, isPending: isMarkingSeen } =
useRejectionSeenMutation();
useHardwareBackHandler(() => {
if (isAdvisorOpen) {
closeAdvisors();
return true;
}
return false; // Hardware back closes the service in Flutter
});
useEffect(() => {
if (!profile) {
return;
}
// Don't bounce away from finding-match if we only have preliminary initialData
// with pending_info before the fresh server query finishes
if (!isFetched && profile.status === "pending_info") {
return;
}
const targetPath = getSubmitPath(profile);
if (targetPath !== "/finding-match") {
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();
}
},
}}
/>