import { _objectSpread2 } from "../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { _objectWithoutProperties } from "../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectWithoutProperties.js";
import { autoTextSize } from "./auto-text-size-standalone.js";
import React, { useCallback, useEffect, useRef } from "react";
//#region ../materials/src/components/auto-resize-text/index.tsx
const _excluded = [
	"mode",
	"minFontSizePx",
	"maxFontSizePx",
	"fontSizePrecisionPx",
	"scrollToEnd",
	"as",
	"children"
];
function AutoResizeText(_ref) {
	let { mode, minFontSizePx, maxFontSizePx, fontSizePrecisionPx, scrollToEnd, as: Comp = "div", children } = _ref, rest = _objectWithoutProperties(_ref, _excluded);
	const updateTextSizeRef = useRef();
	useEffect(() => {
		var _updateTextSizeRef$cu;
		(_updateTextSizeRef$cu = updateTextSizeRef.current) === null || _updateTextSizeRef$cu === void 0 || _updateTextSizeRef$cu.call(updateTextSizeRef);
	}, [children]);
	const refCallback = useCallback((innerEl) => {
		var _updateTextSizeRef$cu2;
		(_updateTextSizeRef$cu2 = updateTextSizeRef.current) === null || _updateTextSizeRef$cu2 === void 0 || _updateTextSizeRef$cu2.disconnect();
		const containerEl = innerEl === null || innerEl === void 0 ? void 0 : innerEl.parentElement;
		if (!innerEl || !containerEl) return;
		updateTextSizeRef.current = autoTextSize({
			innerEl,
			containerEl,
			mode,
			minFontSizePx,
			maxFontSizePx,
			fontSizePrecisionPx,
			scrollToEnd
		});
	}, [
		mode,
		minFontSizePx,
		maxFontSizePx,
		fontSizePrecisionPx,
		scrollToEnd
	]);
	return /* @__PURE__ */ React.createElement(Comp, _objectSpread2({ ref: refCallback }, rest), children);
}
//#endregion
export { AutoResizeText as default };
