"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const vue = require("vue");
const keys = require("../../../keys-D70E9HED.js");
require("../../../BootstrapVueOptions-B17IcLXU.js");
require("../../../ConditionalTeleport.vue_vue_type_script_lang-BL9AAILt.js");
const src_composables_orchestratorShared_index = require("../orchestratorShared/index.umd.js");
require("../../../ConditionalWrapper.vue_vue_type_script_lang-CFfEbslT.js");
const floatingUi = require("../../../floatingUi-DunCtfmV.js");
require("../../../useTransitions-C9Xv-y_E.js");
require("../../../tableUtils-MbGcRaD0.js");
const BTooltip_vue_vue_type_script_setup_true_lang = require("../../../BTooltip.vue_vue_type_script_setup_true_lang-Cw6yZ-Zh.js");
const usePopover = () => {
  const orchestratorRegistry = vue.inject(keys.orchestratorRegistryKey, null);
  if (!orchestratorRegistry) {
    throw new Error(
      "usePopover() must be called within setup(), and BApp, useRegistry or plugin must be installed/provided."
    );
  }
  const { store, _isOrchestratorInstalled } = orchestratorRegistry;
  const create = (obj, tooltip2, options = { keep: true }) => {
    if (!_isOrchestratorInstalled.value) {
      throw new Error("The BApp component must be mounted to use the popover controller");
    }
    const resolvedProps = vue.isRef(obj) ? obj : vue.shallowRef(obj);
    const _self = resolvedProps.value?.id || /* @__PURE__ */ Symbol("Popover controller");
    const promise = src_composables_orchestratorShared_index.buildPromise(_self, store);
    promise.stop = vue.watch(
      resolvedProps,
      (_newValue) => {
        const newValue = { ...vue.toValue(_newValue) };
        const previousIndex = store.value.findIndex((el) => el._self === _self);
        const previous = previousIndex === -1 ? { _component: tooltip2 ? vue.markRaw(BTooltip_vue_vue_type_script_setup_true_lang._sfc_main) : vue.markRaw(floatingUi._sfc_main) } : store.value[previousIndex];
        const v = tooltip2 ? {
          ...previous,
          type: "tooltip",
          _self,
          position: "popover",
          promise,
          options
        } : {
          ...previous,
          type: "popover",
          _self,
          position: "popover",
          promise,
          options
        };
        for (const key in newValue) {
          if (key.startsWith("on")) {
            v[key] = newValue[key];
          } else if (key === "component" && newValue.component) {
            v._component = vue.markRaw(newValue.component);
          } else if (key === "slots" && newValue.slots) {
            v.slots = vue.markRaw(newValue.slots);
          } else {
            v[key] = vue.toValue(
              newValue[key]
            );
          }
        }
        v.modelValue = v.modelValue ?? false;
        v["onUpdate:modelValue"] = (val) => {
          newValue["onUpdate:modelValue"]?.(val);
          const { modelValue } = vue.toValue(obj);
          if (vue.isRef(obj) && !vue.isRef(modelValue)) obj.value.modelValue = val;
          if (vue.isRef(modelValue) && !vue.isReadonly(modelValue)) {
            modelValue.value = val;
          }
          if (v.modelValue !== val) {
            const popover2 = store.value.find((el) => el._self === _self);
            if (popover2) {
              popover2.modelValue = val;
            }
          }
        };
        if (previousIndex === -1) {
          store.value.push(v);
        } else {
          store.value.splice(previousIndex, 1, v);
        }
      },
      {
        immediate: true,
        deep: true
      }
    );
    vue.onScopeDispose(() => {
      const popover2 = store.value.find((el) => el._self === _self);
      if (popover2) {
        popover2.promise.value.destroy?.();
      }
    }, true);
    return promise.value;
  };
  const tooltip = (obj, options = { keep: true }) => create(obj, true, options);
  const popover = (obj, options = { keep: true }) => create(obj, false, options);
  return {
    _isOrchestratorInstalled,
    create,
    popover,
    tooltip,
    store
  };
};
const usePopoverController = usePopover;
exports.usePopover = usePopover;
exports.usePopoverController = usePopoverController;
//# sourceMappingURL=index.umd.js.map
