import { isClient } from "@scalar/api-client/v2/blocks/operation-code-sample";
import { safeLocalStorage, REFERENCE_LS_KEYS } from "@scalar/helpers/object/local-storage";
import { useSeoMeta } from "@unhead/vue";
import { useFavicon } from "@vueuse/core";
import { onBeforeMount, watch, toValue, computed } from "vue";
const mapConfigToWorkspaceStore = ({
  config,
  store,
  isDarkMode
}) => {
  onBeforeMount(() => {
    const storedClient = safeLocalStorage().getItem(REFERENCE_LS_KEYS.SELECTED_CLIENT);
    if (isClient(storedClient) && !store.workspace["x-scalar-default-client"]) {
      store.update("x-scalar-default-client", storedClient);
    }
  });
  watch(
    () => toValue(config).defaultHttpClient,
    (newValue) => {
      if (newValue) {
        const { targetKey, clientKey } = newValue;
        const clientId = `${targetKey}/${clientKey}`;
        if (isClient(clientId)) {
          store.update("x-scalar-default-client", clientId);
        }
      }
    },
    { immediate: true }
  );
  watch(
    () => toValue(config).darkMode,
    (isDark) => store.update("x-scalar-color-mode", isDark ? "dark" : "light")
  );
  watch(
    () => isDarkMode.value,
    (newIsDark) => store.update("x-scalar-color-mode", newIsDark ? "dark" : "light"),
    { immediate: true }
  );
  if (toValue(config).metaData) {
    useSeoMeta(toValue(config).metaData);
  }
  const favicon = computed(() => toValue(config).favicon);
  useFavicon(favicon);
};
export {
  mapConfigToWorkspaceStore
};
