'use client'
import { resetRouter } from "@/lib/redux/features/route";
import { useAppDispatch, useAppSelector } from "@/lib/redux/hooks";
import { useRouter } from "next/navigation";
import { useEffect } from "react";

const RouterWatcher = () => {
    const router = useRouter();
    const { path, actionType } = useAppSelector(state => state.route);
    const dispatch = useAppDispatch();

    useEffect(() => {
        if (path && path !== '') {
            console.log('path: ', path);
            actionType === 'replace' ? router.replace(path) : router.push(path);
            dispatch(resetRouter());
        }
    }, [path]);

    return <div></div>;
};

export default RouterWatcher;