/*! © 2026 Yahoo, Inc. UDS v0.0.0-development */
import { configurableProperties } from "../packages/automated-config/dist/properties.js";
import { getRuntimeDefaultPropSelector, getRuntimeDefaultPropValue, getRuntimeFieldSelector, getRuntimeFieldStaticValue, getRuntimeFieldTokenValue, getRuntimeSelectorParamValues } from "../runtimeConfig/hookMetadata.js";
//#region ../css/dist/css/utils.mjs
/*! © 2026 Yahoo, Inc. UDS CSS v0.0.0-development */
/**
* Extract variant defaults from a UniversalTokensConfig.
* Converts from config structure to a simpler lookup format.
* e.g., { button: { defaults: { size: 'md' } } } -> { Button: { size: 'md' } }
*/
const extractVariantDefaults = (config) => {
	const componentNameMap = {
		avatar: "Avatar",
		badge: "Badge",
		button: "Button",
		checkbox: "Checkbox",
		chip: "Chip",
		divider: "Divider",
		iconButton: "IconButton",
		input: "Input",
		link: "Link",
		menu: "Menu",
		radio: "Radio",
		switch: "Switch",
		tab: "Tab",
		tabs: "Tabs"
	};
	return Object.entries(config).reduce((acc, [configKey, componentConfig]) => {
		const pascalName = componentNameMap[configKey];
		if (!pascalName || !componentConfig || typeof componentConfig !== "object") return acc;
		const configWithDefaults = componentConfig;
		return configWithDefaults.defaults ? {
			...acc,
			[pascalName]: configWithDefaults.defaults
		} : acc;
	}, {});
};
const extractRuntimeConfigValues = (config) => {
	const values = {};
	const setRuntimeValue = (selector, value) => {
		if (!selector || value === void 0) return;
		values[selector] = value;
	};
	const bottomSheetBackgroundColor = getRuntimeFieldTokenValue(config, "useBottomSheetConfig", "backgroundColor", { variant: "default" });
	if (bottomSheetBackgroundColor !== void 0) setRuntimeValue(getRuntimeFieldSelector("useBottomSheetConfig", "backgroundColor", { variant: "default" }), bottomSheetBackgroundColor);
	if (config.toast?.variables && config.toast?.defaults) {
		setRuntimeValue(getRuntimeFieldSelector("useToastConfig", "autoClose"), getRuntimeFieldStaticValue("useToastConfig", "autoClose") ?? void 0);
		setRuntimeValue(getRuntimeFieldSelector("useToastConfig", "position"), getRuntimeFieldStaticValue("useToastConfig", "position") ?? void 0);
		setRuntimeValue(getRuntimeDefaultPropSelector("useToastConfig", "size"), getRuntimeDefaultPropValue(config, "useToastConfig", "size"));
		setRuntimeValue(getRuntimeDefaultPropSelector("useToastConfig", "variant"), getRuntimeDefaultPropValue(config, "useToastConfig", "variant"));
		getRuntimeSelectorParamValues("useToastConfig", "size").forEach((size) => {
			const textVariant = getRuntimeFieldTokenValue(config, "useToastConfig", "textVariant", { size });
			const iconSize = getRuntimeFieldTokenValue(config, "useToastConfig", "iconSize", { size });
			const buttonSize = getRuntimeFieldTokenValue(config, "useToastConfig", "buttonSize", { size });
			setRuntimeValue(getRuntimeFieldSelector("useToastConfig", "textVariant", { size }), textVariant);
			setRuntimeValue(getRuntimeFieldSelector("useToastConfig", "iconSize", { size }), iconSize);
			setRuntimeValue(getRuntimeFieldSelector("useToastConfig", "buttonSize", { size }), buttonSize);
		});
		getRuntimeSelectorParamValues("useToastConfig", "variant").forEach((variant) => {
			const textColor = getRuntimeFieldTokenValue(config, "useToastConfig", "textColor", { variant });
			const buttonVariant = getRuntimeFieldTokenValue(config, "useToastConfig", "buttonVariant", { variant });
			const iconVariant = getRuntimeFieldTokenValue(config, "useToastConfig", "iconVariant", { variant });
			const backgroundColor = getRuntimeFieldTokenValue(config, "useToastConfig", "backgroundColor", { variant });
			setRuntimeValue(getRuntimeFieldSelector("useToastConfig", "textColor", { variant }), textColor);
			setRuntimeValue(getRuntimeFieldSelector("useToastConfig", "buttonVariant", { variant }), buttonVariant);
			setRuntimeValue(getRuntimeFieldSelector("useToastConfig", "iconVariant", { variant }), iconVariant);
			setRuntimeValue(getRuntimeFieldSelector("useToastConfig", "backgroundColor", { variant }), backgroundColor);
		});
	}
	const tooltipBorderRadius = getRuntimeFieldTokenValue(config, "useTooltipConfig", "borderRadius", { size: "default" });
	if (tooltipBorderRadius !== void 0) {
		setRuntimeValue(getRuntimeFieldSelector("useTooltipConfig", "animationDuration"), getRuntimeFieldStaticValue("useTooltipConfig", "animationDuration") ?? void 0);
		setRuntimeValue(getRuntimeFieldSelector("useTooltipConfig", "placement"), getRuntimeFieldStaticValue("useTooltipConfig", "placement") ?? void 0);
		setRuntimeValue(getRuntimeFieldSelector("useTooltipConfig", "borderRadius", { size: "default" }), tooltipBorderRadius);
	}
	if (config.popover?.variables && config.scaleMode?.medium) {
		setRuntimeValue(getRuntimeDefaultPropSelector("usePopoverConfig", "size"), getRuntimeDefaultPropValue(config, "usePopoverConfig", "size") ?? void 0);
		setRuntimeValue(getRuntimeDefaultPropSelector("usePopoverConfig", "variant"), getRuntimeDefaultPropValue(config, "usePopoverConfig", "variant") ?? void 0);
		setRuntimeValue(getRuntimeFieldSelector("usePopoverConfig", "animationDuration"), getRuntimeFieldStaticValue("usePopoverConfig", "animationDuration") ?? void 0);
		setRuntimeValue(getRuntimeFieldSelector("usePopoverConfig", "placement"), getRuntimeFieldStaticValue("usePopoverConfig", "placement") ?? void 0);
		getRuntimeSelectorParamValues("usePopoverConfig", "size").forEach((size) => {
			const borderRadius = getRuntimeFieldTokenValue(config, "usePopoverConfig", "borderRadius", { size });
			const gap = getRuntimeFieldTokenValue(config, "usePopoverConfig", "gap", { size });
			const spacingHorizontal = getRuntimeFieldTokenValue(config, "usePopoverConfig", "spacingHorizontal", { size });
			const spacingVertical = getRuntimeFieldTokenValue(config, "usePopoverConfig", "spacingVertical", { size });
			const dismissButtonSpacing = getRuntimeFieldTokenValue(config, "usePopoverConfig", "dismissButtonSpacing", { size });
			const dismissIconSize = getRuntimeFieldTokenValue(config, "usePopoverConfig", "dismissIconSize", { size });
			setRuntimeValue(getRuntimeFieldSelector("usePopoverConfig", "borderRadius", { size }), borderRadius);
			setRuntimeValue(getRuntimeFieldSelector("usePopoverConfig", "gap", { size }), gap);
			setRuntimeValue(getRuntimeFieldSelector("usePopoverConfig", "spacingHorizontal", { size }), spacingHorizontal);
			setRuntimeValue(getRuntimeFieldSelector("usePopoverConfig", "spacingVertical", { size }), spacingVertical);
			setRuntimeValue(getRuntimeFieldSelector("usePopoverConfig", "dismissButtonSpacing", { size }), dismissButtonSpacing);
			setRuntimeValue(getRuntimeFieldSelector("usePopoverConfig", "dismissIconSize", { size }), dismissIconSize);
		});
	}
	if (config.modal?.variables) {
		setRuntimeValue(getRuntimeDefaultPropSelector("useModalConfig", "size"), getRuntimeDefaultPropValue(config, "useModalConfig", "size") ?? void 0);
		setRuntimeValue(getRuntimeDefaultPropSelector("useModalConfig", "variant"), getRuntimeDefaultPropValue(config, "useModalConfig", "variant") ?? void 0);
		getRuntimeSelectorParamValues("useModalConfig", "size").forEach((size) => {
			const gutter = getRuntimeFieldTokenValue(config, "useModalConfig", "gutter", { size });
			setRuntimeValue(getRuntimeFieldSelector("useModalConfig", "gutter", { size }), gutter);
		});
	}
	return values;
};
/**
* Format bytes to human readable string
*/
const formatBytes = (bytes) => {
	if (bytes < 1024) return `${bytes} B`;
	const kb = bytes / 1024;
	if (kb < 1024) return `${kb.toFixed(1)} KB`;
	return `${(kb / 1024).toFixed(2)} MB`;
};
/**
* Get motion CSS variable prefixes needed by a set of components.
* Looks up motionVarPrefixes from componentData.json for each component.
*/
const getMotionVarPrefixes = (componentData, components) => {
	const prefixes = components.flatMap((componentName) => {
		return componentData[componentName]?.motionVarPrefixes ?? [];
	});
	return [...new Set(prefixes)];
};
/**
* Collect css variable names exposed by configurable properties.
*/
const getConfigurableCssVariables = () => {
	const udsVarPrefix = "--uds";
	const cssVars = Object.values(configurableProperties).flatMap(({ cssProperties }) => {
		if (typeof cssProperties === "string") return cssProperties.startsWith(udsVarPrefix) ? [cssProperties] : [];
		if (Array.isArray(cssProperties)) return cssProperties.filter((cssProperty) => typeof cssProperty === "string" && cssProperty.startsWith(udsVarPrefix));
		return [];
	});
	return [...new Set(["--uds-button-gap", ...cssVars])];
};
//#endregion
export { extractRuntimeConfigValues, extractVariantDefaults, formatBytes, getConfigurableCssVariables, getMotionVarPrefixes };
