import { createElement } from '@wordpress/element';

let iconPaths = {};

/**
 * Install the trusted icon definitions supplied by wp-admin or the public
 * Store Locator bootstrap. Definitions contain Lucide's inner SVG markup;
 * callers must never pass user-authored markup to this registry.
 */
export const setFrontendIconPaths = ( paths ) => {
	iconPaths = paths && typeof paths === 'object' ? paths : {};
};

export const getFrontendIconPaths = () => iconPaths;

/** Lightweight SVG renderer shared by the builder preview and public app. */
export const IconGlyph = ( { name, size = 15 } ) => {
	const inner = iconPaths[ name ];
	if ( ! inner ) return null;

	return createElement( 'svg', {
		xmlns: 'http://www.w3.org/2000/svg',
		width: size,
		height: size,
		viewBox: '0 0 24 24',
		fill: 'none',
		stroke: 'currentColor',
		strokeWidth: 2,
		strokeLinecap: 'round',
		strokeLinejoin: 'round',
		className: 'cliq-sl-ico',
		'aria-hidden': 'true',
		dangerouslySetInnerHTML: { __html: inner },
	} );
};
