"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }"use client";

// src/hooks/ui/use-auto-limit-tags.ts
var _react = require('react');
function useAutoLimitTags({
  count,
  limitTags = "auto",
  placeholder = "",
  reserveInputWidth = true
}) {
  const middleRef = _react.useRef.call(void 0, null);
  const measureRef = _react.useRef.call(void 0, null);
  const textMeasureRef = _react.useRef.call(void 0, null);
  const badgeRef = _react.useRef.call(void 0, null);
  const inputRef = _react.useRef.call(void 0, null);
  const [visibleCount, setVisibleCount] = _react.useState.call(void 0, count);
  const recalculate = _react.useCallback.call(void 0, () => {
    if (limitTags !== "auto") {
      setVisibleCount(Math.min(limitTags, count));
      return;
    }
    const middle = middleRef.current;
    const measure = measureRef.current;
    if (!middle || !measure) {
      setVisibleCount(count);
      return;
    }
    if (count === 0) {
      setVisibleCount(0);
      return;
    }
    const cs = getComputedStyle(middle);
    const padL = parseFloat(cs.paddingLeft) || 0;
    const padR = parseFloat(cs.paddingRight) || 0;
    const gap = parseFloat(cs.gap) || 0;
    const middleW = middle.clientWidth;
    let inputReservedW = 0;
    let trailingGap = 0;
    if (reserveInputWidth) {
      const textW = _nullishCoalesce(_optionalChain([textMeasureRef, 'access', _ => _.current, 'optionalAccess', _2 => _2.offsetWidth]), () => ( 60));
      const inputMinW = inputRef.current ? parseFloat(getComputedStyle(inputRef.current).minWidth) || 60 : 60;
      inputReservedW = Math.max(textW + 8, inputMinW);
      trailingGap = gap;
    }
    const available = middleW - padL - padR - inputReservedW - trailingGap;
    const tagEls = Array.from(measure.children);
    const widths = tagEls.map((el) => el.offsetWidth);
    let total = 0;
    for (let i = 0; i < widths.length; i++) {
      total += widths[i] + (i > 0 ? gap : 0);
    }
    if (total <= available) {
      setVisibleCount(count);
      return;
    }
    const badgeW = _nullishCoalesce(_optionalChain([badgeRef, 'access', _3 => _3.current, 'optionalAccess', _4 => _4.offsetWidth]), () => ( 40));
    const spaceWithBadge = available - badgeW - gap;
    let used = 0;
    let fitCount = 0;
    for (let i = 0; i < widths.length; i++) {
      const need = widths[i] + (i > 0 ? gap : 0);
      if (used + need > spaceWithBadge) break;
      used += need;
      fitCount++;
    }
    setVisibleCount(Math.max(0, fitCount));
  }, [count, limitTags, placeholder, reserveInputWidth]);
  _react.useEffect.call(void 0, () => {
    recalculate();
  }, [recalculate]);
  _react.useEffect.call(void 0, () => {
    const el = middleRef.current;
    if (!el) return;
    const ro = new ResizeObserver(recalculate);
    ro.observe(el);
    return () => ro.disconnect();
  }, [recalculate]);
  return { visibleCount, middleRef, measureRef, textMeasureRef, badgeRef, inputRef };
}

// src/hooks/ui/use-debounce.ts

function useDebounce(value, delay = 500) {
  const [debouncedValue, setDebouncedValue] = _react.useState.call(void 0, value);
  _react.useEffect.call(void 0, () => {
    const timer = setTimeout(() => {
      setDebouncedValue(value);
    }, delay);
    return () => {
      clearTimeout(timer);
    };
  }, [value, delay]);
  return debouncedValue;
}

// src/hooks/use-near-viewport.ts

var observers = /* @__PURE__ */ new Map();
var subscribers = /* @__PURE__ */ new WeakMap();
function getObserverFor(rootMargin) {
  const existing = observers.get(rootMargin);
  if (existing) return existing;
  const io = new IntersectionObserver(
    (entries) => {
      entries.forEach((entry) => {
        if (!entry.isIntersecting) return;
        const cb = subscribers.get(entry.target);
        if (cb) {
          cb();
          io.unobserve(entry.target);
          subscribers.delete(entry.target);
        }
      });
    },
    { rootMargin }
  );
  observers.set(rootMargin, io);
  return io;
}
function useNearViewport(rootMargin = "500px") {
  const [isNear, setIsNear] = _react.useState.call(void 0, false);
  const elRef = _react.useRef.call(void 0, null);
  const ref = _react.useCallback.call(void 0, 
    (node) => {
      const prev = elRef.current;
      if (prev) {
        const stillOurs = subscribers.get(prev);
        if (stillOurs) {
          subscribers.delete(prev);
          _optionalChain([observers, 'access', _5 => _5.get, 'call', _6 => _6(rootMargin), 'optionalAccess', _7 => _7.unobserve, 'call', _8 => _8(prev)]);
        }
      }
      elRef.current = node;
      if (!node) return;
      const cb = () => setIsNear(true);
      subscribers.set(node, cb);
      getObserverFor(rootMargin).observe(node);
    },
    [rootMargin]
  );
  _react.useEffect.call(void 0, () => {
    return () => {
      const el = elRef.current;
      if (!el) return;
      if (subscribers.get(el)) {
        subscribers.delete(el);
        _optionalChain([observers, 'access', _9 => _9.get, 'call', _10 => _10(rootMargin), 'optionalAccess', _11 => _11.unobserve, 'call', _12 => _12(el)]);
      }
    };
  }, [rootMargin]);
  return { ref, isNear };
}

// src/hooks/use-og-placeholder.ts

function useOgPlaceholder(buildUrl, title, siteName = "", enabled = true, aspect = "wide") {
  return _react.useMemo.call(void 0, () => {
    if (!enabled || !title) return null;
    const options = {};
    if (siteName) options.site = siteName;
    if (aspect === "square") options.aspect = "square";
    return buildUrl(title, options);
  }, [buildUrl, title, siteName, enabled, aspect]);
}






exports.useAutoLimitTags = useAutoLimitTags; exports.useDebounce = useDebounce; exports.useNearViewport = useNearViewport; exports.useOgPlaceholder = useOgPlaceholder;
//# sourceMappingURL=chunk-DAAFVOTL.cjs.map