/*! © 2026 Yahoo, Inc. UDS v0.0.0-development */
import { entries } from "../../utils/dist/entries.js";
import { FONT_DECLARATIONS_MAP } from "../../fonts/dist/index.js";
//#region src/tokens/utils/getFontUrls.ts
/**
* Get all font URLs organized by font ID.
*
* @example
* ```ts
* import { getFontUrls } from '@yahoo/uds/tokens';
*
* const fontUrls = getFontUrls();
*
* // Variable font - single URL
* fontUrls.yas // => 'https://s.yimg.com/bw/fonts/yas-vf.woff2'
*
* // Non-variable font - URLs by weight
* fontUrls['centra-no2'][400] // => 'https://s.yimg.com/bw/fonts/centra-no2-book.woff2'
* fontUrls['centra-no2'][700] // => 'https://s.yimg.com/bw/fonts/centra-no2-bold.woff2'
*
* // Preload fonts
* if (typeof fontUrls.yas === 'string') {
*   ReactDOM.preload(fontUrls.yas, { as: 'font', crossOrigin: '', type: 'font/woff2' });
* }
* ```
*/
function getFontUrls() {
	const result = {};
	for (const [fontId, config] of entries(FONT_DECLARATIONS_MAP)) if (config.isVariableFont) result[fontId] = config.declarations[0].src;
	else {
		const urlsByWeight = {};
		for (const declaration of config.declarations) if (!declaration.fontStyle || declaration.fontStyle === "normal") {
			const weight = declaration.fontWeight;
			if (weight) urlsByWeight[weight] = declaration.src;
		}
		result[fontId] = urlsByWeight;
	}
	return result;
}
/**
* Get URLs for specific fonts.
*
* @param fontIds - Array of font IDs to get URLs for
* @returns Array of font URLs
*
* @example
* ```ts
* import { getFontUrlsByIds } from '@yahoo/uds/tokens';
*
* const urls = getFontUrlsByIds(['yahoo-sans', 'centra-no2']);
* urls.forEach(url => {
*   ReactDOM.preload(url, { as: 'font', crossOrigin: '', type: 'font/woff2' });
* });
* ```
*/
function getFontUrlsByIds(fontIds) {
	const fontUrls = getFontUrls();
	const urls = [];
	for (const fontId of fontIds) {
		const config = fontUrls[fontId];
		if (!config) continue;
		if (typeof config === "string") urls.push(config);
		else urls.push(...Object.values(config));
	}
	return urls;
}
/**
* Convenience constant for accessing font URLs.
* Use `getFontUrls()` function for better tree-shaking if you only need specific fonts.
*
* @example
* ```ts
* import { fontUrls } from '@yahoo/uds/tokens';
*
* // Variable font
* ReactDOM.preload(fontUrls.inter, { as: 'font', crossOrigin: '', type: 'font/woff2' });
*
* // Non-variable font
* ReactDOM.preload(fontUrls['centra-no2'][400], { as: 'font', crossOrigin: '', type: 'font/woff2' });
* ```
*/
const fontUrls = getFontUrls();
//#endregion
export { fontUrls, getFontUrls, getFontUrlsByIds };
