/** @license MIT | @cube-dev/ui-kit v0.0.0-canary-b859c78 | Cube Dev Team */
import { parseStyle } from "../utils/styles.js";

//#region src/tasty/styles/display.ts
/**
* Handles display, hide, textOverflow, overflow, and whiteSpace styles.
*
* textOverflow syntax:
* - `textOverflow="ellipsis"` - single-line truncation with ellipsis
* - `textOverflow="ellipsis / 3"` - multi-line clamping (3 lines) with ellipsis
* - `textOverflow="clip"` - single-line truncation with clip (no ellipsis)
* - `textOverflow="clip / 2"` - multi-line clip (2 lines)
* - `textOverflow={true}` or `textOverflow="initial"` - reset to initial
*
* Priority:
* 1. `hide` takes precedence (display: none)
* 2. Multi-line `textOverflow` forces display: -webkit-box
* 3. Single-line `textOverflow` defaults white-space to nowrap, multi-line defaults to initial
* 4. Explicit `whiteSpace` overrides the default white-space from `textOverflow`
*/
function displayStyle({ display, hide, textOverflow, overflow, whiteSpace }) {
	const result = {};
	if (textOverflow != null && textOverflow !== false) if (textOverflow === true || textOverflow === "initial") result["text-overflow"] = "initial";
	else {
		const group = parseStyle(String(textOverflow)).groups[0];
		if (group) {
			const { parts } = group;
			const modePart = parts[0];
			const clampPart = parts[1];
			const hasEllipsis = modePart?.mods.includes("ellipsis");
			const hasClip = modePart?.mods.includes("clip");
			let clamp = 1;
			if (clampPart?.values[0]) {
				const parsed = parseInt(clampPart.values[0], 10);
				if (!isNaN(parsed) && parsed > 0) clamp = parsed;
			}
			if (hasEllipsis || hasClip) {
				result["overflow"] = "hidden";
				result["text-overflow"] = hasEllipsis ? "ellipsis" : "clip";
				if (clamp === 1) result["white-space"] = whiteSpace || "nowrap";
				else {
					result["display"] = "-webkit-box";
					result["-webkit-box-orient"] = "vertical";
					result["-webkit-line-clamp"] = clamp;
					result["line-clamp"] = clamp;
					result["white-space"] = whiteSpace || "initial";
				}
			}
		}
	}
	if (overflow && !result["overflow"]) result["overflow"] = overflow;
	if (whiteSpace && !result["white-space"]) result["white-space"] = whiteSpace;
	if (hide) result["display"] = "none";
	else if (!result["display"] && display) result["display"] = display;
	if (Object.keys(result).length === 0) return;
	return result;
}
displayStyle.__lookupStyles = [
	"display",
	"hide",
	"textOverflow",
	"overflow",
	"whiteSpace"
];

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