/* *
 *
 *  (c) 2010-2026 Highsoft AS
 *  Author: Jedrzej Ruta
 *
 *  A commercial license may be required depending on use.
 *  See www.highcharts.com/license
 *
 *
 * */
'use strict';
/**
 * Generate and/or retrieve the icon. For pre v12, icons were fetched from
 * our servers. Since v12.x, icons are generated by JS in SVG.
 *
 * @internal
 * @param {string} iconName
 *                 Name of the icon, e.g. 'edit.svg'.
 *
 * @param {string} iconsURL
 *                 Icons URL
 *
 * @param {Record<string, string>} icons
 *                 Icons object
 *
 * @return {string} Icon string
 */
const getIcon = (iconName, iconsURL, icons) => {
    let icon = icons[iconName];
    let iconString;
    if (iconsURL === 'renderer' && icon) {
        icon = encodeURIComponent(icon);
        iconString = `url("data:image/svg+xml;charset=utf-8,${icon}")`;
    }
    else if (iconsURL.startsWith('http') &&
        iconsURL.match(/\.(png|svg|jpe?g|gif)$/ig)) {
        // Absolute icon URL support
        iconString = 'url("' + iconsURL + '")';
    }
    else {
        iconString = `url("${iconsURL}${iconName}")`;
    }
    return iconString;
};
export default getIcon;
