"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const bar = require("./bar.js");
const util = require("./util.js");
const constants = require("./constants.js");
const thumb2 = require("./thumb2.js");
const Vue = require("vue");
var bar_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ Vue.defineComponent({
  __name: "bar",
  props: bar.barProps,
  setup(__props, { expose: __expose }) {
    const props = __props;
    const scrollbar = Vue.inject(constants.scrollbarContextKey);
    const moveX = Vue.ref(0);
    const moveY = Vue.ref(0);
    const sizeWidth = Vue.ref("");
    const sizeHeight = Vue.ref("");
    const ratioY = Vue.ref(1);
    const ratioX = Vue.ref(1);
    const handleScroll = (wrap) => {
      if (wrap) {
        const offsetHeight = wrap.offsetHeight - util.GAP;
        const offsetWidth = wrap.offsetWidth - util.GAP;
        moveY.value = wrap.scrollTop * 100 / offsetHeight * ratioY.value;
        moveX.value = wrap.scrollLeft * 100 / offsetWidth * ratioX.value;
      }
    };
    const update = () => {
      const wrap = scrollbar == null ? void 0 : scrollbar.wrapElement;
      if (!wrap) return;
      const offsetHeight = wrap.offsetHeight - util.GAP;
      const offsetWidth = wrap.offsetWidth - util.GAP;
      const originalHeight = offsetHeight ** 2 / wrap.scrollHeight;
      const originalWidth = offsetWidth ** 2 / wrap.scrollWidth;
      const height = Math.max(originalHeight, props.minSize);
      const width = Math.max(originalWidth, props.minSize);
      ratioY.value = originalHeight / (offsetHeight - originalHeight) / (height / (offsetHeight - height));
      ratioX.value = originalWidth / (offsetWidth - originalWidth) / (width / (offsetWidth - width));
      sizeHeight.value = height + util.GAP < offsetHeight ? `${height}px` : "";
      sizeWidth.value = width + util.GAP < offsetWidth ? `${width}px` : "";
    };
    __expose({
      handleScroll,
      update
    });
    return (_ctx, _cache) => {
      return Vue.openBlock(), Vue.createElementBlock(Vue.Fragment, null, [Vue.createVNode(thumb2.default, {
        move: moveX.value,
        ratio: ratioX.value,
        size: sizeWidth.value,
        always: __props.always
      }, null, 8, [
        "move",
        "ratio",
        "size",
        "always"
      ]), Vue.createVNode(thumb2.default, {
        move: moveY.value,
        ratio: ratioY.value,
        size: sizeHeight.value,
        vertical: "",
        always: __props.always
      }, null, 8, [
        "move",
        "ratio",
        "size",
        "always"
      ])], 64);
    };
  }
});
exports.default = bar_vue_vue_type_script_setup_true_lang_default;
