import { isEFTemporal } from "../../elements/EFTemporal.js";
import { EFTimegroup } from "../../elements/EFTimegroup.js";

//#region src/gui/timeline/flattenHierarchy.ts
/**
* Flattens a hierarchical temporal element tree into a flat array of rows.
* Each row contains the element and its depth in the hierarchy.
*
* @param root - The root temporal element to flatten
* @param startDepth - Starting depth (default 0)
* @returns Array of {element, depth} in depth-first order
*/
function flattenHierarchy(root, startDepth = 0) {
	const rows = [{
		element: root,
		depth: startDepth
	}];
	if (root instanceof EFTimegroup) {
		for (const child of root.children) if (isEFTemporal(child)) {
			const tagName = child.tagName?.toUpperCase();
			if (tagName === "EF-CAPTIONS-ACTIVE-WORD" || tagName === "EF-CAPTIONS-SEGMENT" || tagName === "EF-CAPTIONS-BEFORE-ACTIVE-WORD" || tagName === "EF-CAPTIONS-AFTER-ACTIVE-WORD") continue;
			if (tagName === "EF-TEXT-SEGMENT") continue;
			rows.push(...flattenHierarchy(child, startDepth + 1));
		}
	}
	return rows;
}

//#endregion
export { flattenHierarchy };
//# sourceMappingURL=flattenHierarchy.js.map