import { resolveHtmlElement } from "../_utils/vue-utils.mjs";
import { createApp } from "vue";
import _sfc_main from "./OScrollbar.vue.mjs";
const ScrollbarClass = {
  wrapper: "o-scrollbar-wrapper"
};
function useScrollbar(options) {
  const { wrapper, target, ...rests } = options;
  const app = createApp(_sfc_main, {
    ...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) {
    resolveHtmlElement(wrapper).then((el) => {
      mount(el);
    });
  } else {
    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);
    }
  };
}
export {
  useScrollbar
};
