<template>
  <slot />
</template>

<script setup lang="ts">
import { provide, computed, watch } from 'vue'
import { ConfigToken } from './Token'
import { useLocale } from 'bolt-ui/locales'
import { IConfig } from './config';

const props = withDefaults(
  defineProps<IConfig>(),
  {
    locale: 'zh'
  }
)

const { setLocale } = useLocale()

watch(
  () => props.locale,
  (newVal) => {
    setLocale(newVal)
  },
  {
    immediate: true
  }
)

const state = computed(() => {
  return {
    locale: props.locale ?? 'zh'
  }
})
provide(ConfigToken, state)
</script>
