#!/usr/bin/env node
import {
  init_esm_shims
} from "./chunk-DHET7RCE.js";

// src/cli/components/hooks/use-measured-height.ts
init_esm_shims();
import { useRef, useState, useEffect } from "react";
import { measureElement, useStdout } from "ink";
function useMeasuredHeight() {
  const ref = useRef(null);
  const [measuredHeight, setMeasuredHeight] = useState(0);
  const { stdout } = useStdout();
  const measure = () => {
    if (ref.current) {
      const { height } = measureElement(ref.current);
      setMeasuredHeight((prev) => prev !== height ? height : prev);
    }
  };
  useEffect(() => {
    measure();
  });
  useEffect(() => {
    const RETRY_DELAYS_MS = [0, 16, 50];
    const timers = [];
    for (const delay of RETRY_DELAYS_MS) {
      timers.push(setTimeout(measure, delay));
    }
    return () => {
      for (const timer of timers) {
        clearTimeout(timer);
      }
    };
  }, []);
  useEffect(() => {
    stdout.on("resize", measure);
    return () => {
      stdout.off("resize", measure);
    };
  }, [stdout]);
  return { ref, measuredHeight };
}

export {
  useMeasuredHeight
};
//# sourceMappingURL=chunk-K77I4XGL.js.map