import { useWixPatternsRouter } from '../../providers/WixPatternsRouterProvider';

export const usePatternsNavigate = <T>() => {
  const router = useWixPatternsRouter();

  if (!router) {
    throw new Error('usePatternsNavigate must be used within PatternsRouter');
  }

  return {
    navigateToEntityPage: ({ path, entity }: { path: string; entity: T }) => {
      router.navigate(path, { state: { _chosenEntity: { entity } } });
    },
    navigateToCollectionPage: ({ path }: { path: string }) => {
      router.navigate(path, { state: null });
    },
  };
};

export { useWixPatternsRouter } from '../../providers/WixPatternsRouterProvider';
