/*! © 2026 Yahoo, Inc. UDS v0.0.0-development */
require("../../../../../_virtual/_rolldown/runtime.cjs");
const require_expressions = require("./expressions.cjs");
let ts_morph = require("ts-morph");
//#region ../css/dist/purger/optimized/ast/props.mjs
/*! © 2026 Yahoo, Inc. UDS CSS v0.0.0-development */
/**
* Extract all props from a JSX element (both explicit props and spread props).
*
* For explicit props like `<Box color="brand" />`, extracts the prop name and value.
* For spread props like `<Box {...props} />`, marks them as fromSpread for later resolution.
*
* @param element The JSX element to extract props from
* @returns Array of extracted props with their values
*/
const extractPropsFromElement = (element) => element.getAttributes().flatMap((attr) => {
	if (ts_morph.Node.isJsxAttribute(attr)) {
		const propName = attr.getNameNode().getText();
		const stringLiterals = attr.getDescendantsOfKind(ts_morph.SyntaxKind.StringLiteral);
		return [{
			name: propName,
			values: stringLiterals.length > 0 ? stringLiterals.map((lit) => lit.getLiteralText()) : (() => {
				const initializer = attr.getInitializer();
				if (!initializer || !ts_morph.Node.isJsxExpression(initializer)) return [];
				const expression = initializer.getExpression();
				return expression ? require_expressions.extractStringLiterals(expression) : [];
			})(),
			fromSpread: false
		}];
	}
	if (ts_morph.Node.isJsxSpreadAttribute(attr)) {
		const expression = attr.getExpression();
		return [{
			name: `__spread__:${ts_morph.Node.isIdentifier(expression) ? expression.getText() : expression.getChildren().pop()?.getText() ?? ""}`,
			values: [],
			fromSpread: true
		}];
	}
	return [];
});
/**
* Extract only explicit (non-spread) props from a JSX element.
* Used when we want to avoid including spread-derived values.
*/
const extractExplicitProps = (element) => extractPropsFromElement(element).filter((p) => !p.fromSpread);
//#endregion
exports.extractExplicitProps = extractExplicitProps;
