/*! © 2026 Yahoo, Inc. UDS v0.0.0-development */
const require_getButtonControlHeight = require("./getButtonControlHeight.cjs");
const require_getButtonControlHeightPx = require("./getButtonControlHeightPx.cjs");
//#region ../automated-config/dist/utils/iconButtonMatchButtonHeight.js
/*! © 2026 Yahoo, Inc. UDS Default Config v0.0.0-development */
function asMatchButtonHeightConfig(config) {
	return config;
}
function getMatchButtonHeightMap(config) {
	return config.iconButton?.matchButtonHeight ?? config.matchButtonHeight;
}
function getIconButtonVariables(config) {
	return config.iconButton?.variables ?? config.variables;
}
function isMatchButtonHeightSize(size) {
	return require_getButtonControlHeight.SHARED_BUTTON_ICONBUTTON_SIZES.has(size);
}
function isIconButtonMatchButtonHeightEnabled(config, size) {
	if (!isMatchButtonHeightSize(size)) return false;
	return getMatchButtonHeightMap(asMatchButtonHeightConfig(config))?.[size] === true;
}
function getIconButtonSpacingRestValue(config, size) {
	const rootKey = `size/${size}/root`;
	const value = (getIconButtonVariables(config)?.[rootKey]?.spacing)?.rest?.value;
	return typeof value === "string" ? value : void 0;
}
function setIconButtonSpacingRestValue(config, size, spacing) {
	const matchConfig = asMatchButtonHeightConfig(config);
	const rootKey = `size/${size}/root`;
	const iconButton = matchConfig.iconButton ?? { variables: {} };
	const existingRoot = iconButton.variables?.[rootKey] ?? {};
	return {
		...config,
		iconButton: {
			...iconButton,
			variables: {
				...iconButton.variables,
				[rootKey]: {
					...existingRoot,
					spacing: { rest: {
						type: "spacingAliases",
						value: spacing,
						valueType: "alias"
					} }
				}
			}
		}
	};
}
function removeIconButtonControlHeight(config, size) {
	const matchConfig = asMatchButtonHeightConfig(config);
	const rootKey = `size/${size}/root`;
	const iconButton = matchConfig.iconButton;
	const rootLayer = iconButton?.variables?.[rootKey];
	if (!rootLayer?.controlHeight) return config;
	const { controlHeight: _, ...restRoot } = rootLayer;
	return {
		...config,
		iconButton: {
			...iconButton,
			variables: {
				...iconButton?.variables,
				[rootKey]: restRoot
			}
		}
	};
}
function enableIconButtonMatchButtonHeight(config, size) {
	const matchConfig = asMatchButtonHeightConfig(config);
	const currentSpacing = getIconButtonSpacingRestValue(matchConfig, size);
	const iconButton = {
		...matchConfig.iconButton,
		matchButtonHeight: {
			...matchConfig.iconButton?.matchButtonHeight,
			[size]: true
		}
	};
	if (currentSpacing !== void 0) iconButton.spacingBeforeMatchButtonHeight = {
		...matchConfig.iconButton?.spacingBeforeMatchButtonHeight,
		[size]: currentSpacing
	};
	let nextConfig = {
		...config,
		iconButton
	};
	nextConfig = require_getButtonControlHeightPx.syncButtonControlHeightVarForSize(nextConfig, size);
	return nextConfig;
}
function disableIconButtonMatchButtonHeight(config, size) {
	const spacingSnapshot = asMatchButtonHeightConfig(config).iconButton?.spacingBeforeMatchButtonHeight?.[size];
	let nextConfig = removeIconButtonControlHeight(config, size);
	if (spacingSnapshot !== void 0) nextConfig = setIconButtonSpacingRestValue(nextConfig, size, spacingSnapshot);
	nextConfig = require_getButtonControlHeightPx.syncIconButtonOnlyControlHeightVarForSize(nextConfig, size);
	const nextMatchConfig = asMatchButtonHeightConfig(nextConfig);
	const { [size]: _removedFlag, ...remainingMatchButtonHeight } = nextMatchConfig.iconButton?.matchButtonHeight ?? {};
	const { [size]: _removedSnapshot, ...remainingSpacingSnapshot } = nextMatchConfig.iconButton?.spacingBeforeMatchButtonHeight ?? {};
	const iconButton = { ...nextMatchConfig.iconButton };
	if (Object.keys(remainingMatchButtonHeight).length > 0) iconButton.matchButtonHeight = remainingMatchButtonHeight;
	else delete iconButton.matchButtonHeight;
	if (Object.keys(remainingSpacingSnapshot).length > 0) iconButton.spacingBeforeMatchButtonHeight = remainingSpacingSnapshot;
	else delete iconButton.spacingBeforeMatchButtonHeight;
	return {
		...nextConfig,
		iconButton
	};
}
//#endregion
exports.disableIconButtonMatchButtonHeight = disableIconButtonMatchButtonHeight;
exports.enableIconButtonMatchButtonHeight = enableIconButtonMatchButtonHeight;
exports.isIconButtonMatchButtonHeightEnabled = isIconButtonMatchButtonHeightEnabled;
