//#region components/_utils/transition.ts
var DEFAULT_ROOT_PREFIX_CLS = "ant";
var DEFAULT_MOTION_DEADLINE = 500;
var setCollapsedHeight = (node) => {
	node.style.height = "0px";
	node.style.opacity = "0";
};
var setRealHeight = (node) => {
	node.style.height = `${node.scrollHeight}px`;
	node.style.opacity = "1";
};
var setCurrentHeight = (node) => {
	node.style.height = `${node.offsetHeight}px`;
	node.style.opacity = "1";
};
var clearHeightStyle = (node) => {
	node.style.height = "";
	node.style.opacity = "";
};
var stopTransition = (node, done, timeout) => {
	if (!done) return;
	let called = false;
	let timer;
	const clear = () => {
		if (called) return;
		called = true;
		if (timer) clearTimeout(timer);
		node.removeEventListener("transitionend", onTransitionEnd);
		done();
	};
	const onTransitionEnd = (event) => {
		if (event.target !== node) return;
		if (event.propertyName !== "height") return;
		clear();
	};
	node.addEventListener("transitionend", onTransitionEnd);
	timer = setTimeout(clear, timeout);
};
var initCollapseTransition = (rootCls = DEFAULT_ROOT_PREFIX_CLS, options = {}) => {
	const motionName = `${rootCls}-motion-collapse`;
	const motionDeadline = options.motionDeadline ?? DEFAULT_MOTION_DEADLINE;
	return {
		onBeforeEnter(el) {
			const node = el;
			node.classList.remove(motionName);
			node.classList.add(`${motionName}-legacy`);
			setCollapsedHeight(node);
		},
		onEnter(el, done) {
			const node = el;
			node.classList.add(`${motionName}-legacy-active`);
			node.offsetHeight;
			setRealHeight(node);
			stopTransition(node, done, motionDeadline);
		},
		onAfterEnter(el) {
			const node = el;
			node.classList.remove(`${motionName}-legacy`);
			node.classList.remove(`${motionName}-legacy-active`);
			clearHeightStyle(node);
		},
		onBeforeLeave(el) {
			const node = el;
			node.classList.remove(`${motionName}-legacy`);
			node.classList.remove(`${motionName}-legacy-active`);
			node.classList.add(motionName);
			setCurrentHeight(node);
		},
		onLeave(el, done) {
			const node = el;
			node.offsetHeight;
			setCollapsedHeight(node);
			stopTransition(node, done, motionDeadline);
		},
		onAfterLeave(el) {
			const node = el;
			node.classList.remove(motionName);
			clearHeightStyle(node);
		}
	};
};
//#endregion
export { initCollapseTransition as default };
