import { defineComponent, ref, computed, createElementBlock, watch, nextTick, provide, reactive, onMounted, onUpdated, openBlock, normalizeClass, unref, createElementVNode, createCommentVNode, createBlock, normalizeStyle, resolveDynamicComponent, withCtx, renderSlot } from "vue";
import { useResizeObserver as K, useEventListener as v } from "../../../../../@vueuse/core/index.mjs";
import A from "./bar2.mjs";
import { scrollbarContextKey as o } from "./constants.mjs";
import { scrollbarEmits as p, scrollbarProps as n } from "./scrollbar.mjs";
import c from "../../../_virtual/plugin-vue_export-helper.mjs";
import { useNamespace as q } from "../../../hooks/use-namespace/index.mjs";
import { addUnit as u } from "../../../utils/dom/style.mjs";
import { isObject as i$1 } from "../../../../../@vue/shared/dist/shared.esm-bundler.mjs";
import { isNumber as i } from "../../../utils/types.mjs";
const d = "ElScrollbar", ee = defineComponent({
  name: d
}), re = /* @__PURE__ */ defineComponent({
  ...ee,
  props: n,
  emits: p,
  setup(E, { expose: T, emit: L }) {
    const r = E, t = q("scrollbar");
    let c2, f;
    const b = ref(), l = ref(), h = ref(), a = ref(), N = computed(() => {
      const e = {};
      return r.height && (e.height = u(r.height)), r.maxHeight && (e.maxHeight = u(r.maxHeight)), [r.wrapStyle, e];
    }), g = computed(() => [
      r.wrapClass,
      t.e("wrap"),
      { [t.em("wrap", "hidden-default")]: !r.native }
    ]), O = computed(() => [t.e("view"), r.viewClass]), y = () => {
      var e;
      l.value && ((e = a.value) == null || e.handleScroll(l.value), L("scroll", {
        scrollTop: l.value.scrollTop,
        scrollLeft: l.value.scrollLeft
      }));
    };
    function B(e, m) {
      i$1(e) ? l.value.scrollTo(e) : i(e) && i(m) && l.value.scrollTo(e, m);
    }
    const H = (e) => {
      if (!i(e)) {
        return;
      }
      l.value.scrollTop = e;
    }, K$1 = (e) => {
      if (!i(e)) {
        return;
      }
      l.value.scrollLeft = e;
    }, o$1 = () => {
      var e;
      (e = a.value) == null || e.update();
    };
    return watch(() => r.noresize, (e) => {
      e ? (c2 == null || c2(), f == null || f()) : ({ stop: c2 } = K(h, o$1), f = v("resize", o$1));
    }, { immediate: true }), watch(() => [r.maxHeight, r.height], () => {
      r.native || nextTick(() => {
        var e;
        o$1(), l.value && ((e = a.value) == null || e.handleScroll(l.value));
      });
    }), provide(o, reactive({
      scrollbarElement: b,
      wrapElement: l
    })), onMounted(() => {
      r.native || nextTick(() => {
        o$1();
      });
    }), onUpdated(() => o$1()), T({
      wrapRef: l,
      update: o$1,
      scrollTo: B,
      setScrollTop: H,
      setScrollLeft: K$1,
      handleScroll: y
    }), (e, m) => (openBlock(), createElementBlock("div", {
      ref_key: "scrollbarRef",
      ref: b,
      class: normalizeClass(unref(t).b())
    }, [
      createElementVNode("div", {
        ref_key: "wrapRef",
        ref: l,
        class: normalizeClass(unref(g)),
        style: normalizeStyle(unref(N)),
        onScroll: y
      }, [
        (openBlock(), createBlock(resolveDynamicComponent(e.tag), {
          id: e.id,
          ref_key: "resizeRef",
          ref: h,
          class: normalizeClass(unref(O)),
          style: normalizeStyle(e.viewStyle),
          role: e.role,
          "aria-label": e.ariaLabel,
          "aria-orientation": e.ariaOrientation
        }, {
          default: withCtx(() => [
            renderSlot(e.$slots, "default")
          ]),
          _: 3
        }, 8, ["id", "class", "style", "role", "aria-label", "aria-orientation"]))
      ], 38),
      e.native ? createCommentVNode("v-if", true) : (openBlock(), createBlock(A, {
        key: 0,
        ref_key: "barRef",
        ref: a,
        always: e.always,
        "min-size": e.minSize
      }, null, 8, ["always", "min-size"]))
    ], 2));
  }
});
var pe = /* @__PURE__ */ c(re, [["__file", "scrollbar.vue"]]);
export {
  pe as default
};
