"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const vueUtils = require("../_utils/vue-utils.js");
const vue = require("vue");
const OScrollbar_vue_vue_type_script_setup_true_lang = require("./OScrollbar.vue.js");
const ScrollbarClass = {
  wrapper: "o-scrollbar-wrapper"
};
function useScrollbar(options) {
  const { wrapper, target, ...rests } = options;
  const app = vue.createApp(OScrollbar_vue_vue_type_script_setup_true_lang, {
    ...rests,
    target
  });
  const div = document.createElement("div");
  const instance = app.mount(div);
  let wrapperEl;
  const mount = (wrapper2) => {
    wrapperEl = wrapper2 || document.body;
    wrapperEl == null ? void 0 : wrapperEl.appendChild(div.childNodes[0]);
    wrapperEl == null ? void 0 : wrapperEl.classList.add(ScrollbarClass.wrapper);
  };
  if (wrapper) {
    vueUtils.resolveHtmlElement(wrapper).then((el) => {
      mount(el);
    });
  } else {
    vueUtils.resolveHtmlElement(target).then((el) => {
      mount(el == null ? void 0 : el.parentNode);
    });
  }
  return {
    scrollbar: instance,
    unmount: () => {
      app.unmount();
      wrapperEl == null ? void 0 : wrapperEl.classList.remove(ScrollbarClass.wrapper);
    }
  };
}
exports.useScrollbar = useScrollbar;
