import { useState as a, useEffect as g } from "react";
import { THROTTLE_RESIZE_TIMEOUT as R } from "./contants.js";
import T from "lodash-es/throttle";
function b(t, c) {
  const { throttleTime: r = R, excludePadding: o = !1, leading: i = !1, trailing: s = !0 } = c || {}, [d, f] = a(void 0);
  return g(() => {
    if (!t)
      return;
    const n = T((e) => {
      f(e);
    }, r, {
      leading: i,
      // Evento de resizing (Por defecto false)
      trailing: s
      // Incluir siempre el ultimo evento en la cola, para que no quede se quedee a la mitad de resizing
    }), h = new ResizeObserver((e) => {
      if (o)
        n({
          containerWidth: Math.round(t.clientWidth),
          containerHeight: Math.round(t.clientHeight)
        });
      else
        for (const u of e)
          n({
            containerWidth: Math.round(u.contentRect.width),
            containerHeight: Math.round(u.contentRect.height)
          });
    });
    return h.observe(t), () => {
      t && h.unobserve(t);
    };
  }, [t, o, i, r, s]), d;
}
export {
  b as useSizeContainer
};
