import { createClientConfigService } from "../composables/clientConfig.js";
import { defineNuxtPlugin } from "nuxt/app";
import { ref } from "vue";
export default defineNuxtPlugin(async (nuxtApp) => {
  const clientConfigService = createClientConfigService({
    storageKey: "client_config"
  });
  const clientConfig = ref(clientConfigService.get() ?? {});
  nuxtApp.provide("clientConfig", clientConfig);
  nuxtApp.provide("clientConfigRefresh", async () => {
    const loaded = await clientConfigService.load();
    clientConfig.value = loaded ?? {};
    return clientConfig.value;
  });
  try {
    const loaded = await clientConfigService.load();
    clientConfig.value = loaded ?? {};
  } catch (e) {
    console.warn("[client-config] init load failed:", e?.message || e);
    clientConfig.value = clientConfigService.get() ?? {};
  }
});
