import { useLocationStore } from '~/stores/location'

export default defineNuxtPlugin(() => {
  const nuxtApp = useNuxtApp()
  const me = nuxtApp.ssrContext?.event.context.me ?? null
  const state = useState('me', () => null)

  if (me) {
    state.value = me

    // Заполнить locationStore сразу на сервере для SSR
    const locationStore = useLocationStore()
    if (me.activeTeam?.selectedLocation) {
      locationStore.setFromUserData(me.activeTeam.selectedLocation)
    }
  }
})
