"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const error = require("../../../utils/error.js");
const index = require("../../../../node_modules/@vueuse/core/index.js");
const Vue = require("vue");
const index$1 = require("../../../../node_modules/@vueuse/shared/index.js");
const useBackTop = (props, emit, componentName) => {
  const el = Vue.shallowRef();
  const container = Vue.shallowRef();
  const visible = Vue.ref(false);
  const handleScroll = () => {
    if (el.value) visible.value = el.value.scrollTop >= props.visibilityHeight;
  };
  const handleClick = (event) => {
    var _a;
    (_a = el.value) == null ? void 0 : _a.scrollTo({
      top: 0,
      behavior: "smooth"
    });
    emit("click", event);
  };
  index.useEventListener(container, "scroll", index$1.useThrottleFn(handleScroll, 300, true));
  Vue.onMounted(() => {
    container.value = document;
    el.value = document.documentElement;
    if (props.target) {
      el.value = document.querySelector(props.target) ?? void 0;
      if (!el.value) error.throwError(componentName, `target does not exist: ${props.target}`);
      container.value = el.value;
    }
    handleScroll();
  });
  return {
    visible,
    handleClick
  };
};
exports.useBackTop = useBackTop;
