"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const types = require("../../utils/types.js");
const Vue = require("vue");
const shared_esmBundler = require("../../../../@vue/shared/dist/shared.esm-bundler.js");
const useThrottleRender = (loading, throttle = 0) => {
  if (throttle === 0) return loading;
  const throttled = Vue.ref(shared_esmBundler.isObject(throttle) && Boolean(throttle.initVal));
  let timeoutHandle = null;
  const dispatchThrottling = (timer) => {
    if (types.isUndefined(timer)) {
      throttled.value = loading.value;
      return;
    }
    if (timeoutHandle) clearTimeout(timeoutHandle);
    timeoutHandle = setTimeout(() => {
      throttled.value = loading.value;
    }, timer);
  };
  const dispatcher = (type) => {
    if (type === "leading") if (types.isNumber(throttle)) dispatchThrottling(throttle);
    else dispatchThrottling(throttle.leading);
    else if (shared_esmBundler.isObject(throttle)) dispatchThrottling(throttle.trailing);
    else throttled.value = false;
  };
  Vue.onMounted(() => dispatcher("leading"));
  Vue.watch(() => loading.value, (val) => {
    dispatcher(val ? "leading" : "trailing");
  });
  return throttled;
};
exports.useThrottleRender = useThrottleRender;
