import { createPath, To } from 'react-router-dom';
import { PageLocation, WixPatternsContainer } from '@wix/bex-core';

export const createPlatformizedNavigator = ({
  pageLocation,
  container,
}: {
  pageLocation: PageLocation;
  container: WixPatternsContainer;
}) => {
  return {
    createHref: createPath,
    push: (to: To) => {
      const relativeUrl = typeof to === 'string' ? to : createPath(to);
      container.navigateTo!({
        pageId: pageLocation.pageId,
        relativeUrl,
      });
    },
    replace: () => {
      throw new Error('not yet supported');
    },
    go: () => {
      throw new Error('not yet supported');
    },
  };
};
