export const useTourState = defineStore('tour_state', () => {
  const tourState = ref<{ [key: string]: boolean }>({})

  const isTourDone = (tourId: string) => tourState.value[tourId] || false
  const setTourDone = (tourId: string) => {
    tourState.value = {
      ...tourState.value,
      [tourId]: true,
    }
  }
  const autoDriveTour = (tourId: string, driver: ReturnType<typeof useDriver>) => {
    if (isTourDone(tourId)) return
    driver.setConfig({
      ...driver.getConfig(),
      onDestroyed: () => setTourDone(tourId),
    })
    driver.drive()
  }

  return {
    tourState,
    isTourDone,
    setTourDone,
    autoDriveTour,
  }
}, {
  persist: {
    key: 'xsh_assistant_tour_state',
    storage: persistedState.localStorage,
    paths: ['tourState'],
  },
})