import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '@views/Home.vue'
// import StaticView from '@views/Static.vue'
// import ConcernementView from '@views/Concernement.vue'

import { ConcernementsStore } from '@/stores/concernements'


const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      component: HomeView
    },
    {
      path: '/static/:id',
      name: 'static',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/Static.vue'),
      props: true
    },
    {
      path: '/concernement/:id/:eid?',
      name: 'concernement',
      // component: ConcernementView,
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/Concernement.vue'),
      props: true
    }
  ]
})

// set map_mode on first load
router.afterEach((to, from) => {
  const concernement_store = ConcernementsStore();
  // console.log('router afterEach', from, to, concernement_store.map_mode);
  if (!from.name) { // we are at first load
    if (to.hash) {
      console.log("we have a hash");
      concernement_store.setMapMode(to.hash.replace('#', ''));
    }else{ // default terraindevie
      concernement_store.setMapMode("terraindevie");
    }
  }

})
export default router
