import { useEffect } from 'react';
import { useLocation } from 'react-router-dom';
import { getPageTitle } from '../components/ui/Breadcrumbs';

export function usePageTitle(customTitle?: string) {
    const location = useLocation();

    useEffect(() => {
        const title = customTitle || getPageTitle(location.pathname);
        document.title = title;
    }, [location.pathname, customTitle]);
}

// Wrapper component for easy use
export function PageTitleUpdater() {
    usePageTitle();
    return null;
}
