"use strict";
'use client';
Object.defineProperty(exports, "__esModule", { value: true });
exports.PHXUseRouterBack = void 0;
const navigation_1 = require("next/navigation");
const page_tracker_store_1 = require("../stores/page-tracker/page-tracker-store");
const PHXUseRouterBack = () => {
    const router = (0, navigation_1.useRouter)();
    const searchParams = (0, navigation_1.useSearchParams)();
    const referrer = (0, page_tracker_store_1.usePageTrackerStore)((state) => state.referrer);
    const isFirstPage = (0, page_tracker_store_1.usePageTrackerStore)((state) => state.isFirstPage);
    const routerBack = (backLink) => {
        const isFromNotification = (searchParams === null || searchParams === void 0 ? void 0 : searchParams.get('ref')) === 'notification';
        if (isFromNotification) {
            router.push(backLink);
        }
        else if (isFirstPage && referrer) {
            router.push(referrer);
        }
        else if (isFirstPage) {
            router.push(backLink);
        }
        else {
            router.back();
        }
    };
    return routerBack;
};
exports.PHXUseRouterBack = PHXUseRouterBack;
//# sourceMappingURL=use-router-back.js.map