import type { App } from 'vue';
import { watch } from 'vue';
import { useRouterHistory } from './router-history.composable';
import { useRoute } from 'vue-router';

export const routerHistoryPlugin = {
  install(app: App) {
    const history = {
      setup() {
        const { addHistoryRoute } = useRouterHistory();
        const currentRoute = useRoute();
        watch(currentRoute, () => {
          addHistoryRoute({ ...currentRoute });
        });
      },
      render() {
        return '';
      },
    };
    app.component('BmsRouterHistory', history);
    app.component('bms-router-history', history);
  },
};

export { useRouterHistory };
