import * as i0 from '@angular/core';
import { Injectable, Input, Component, NgModule } from '@angular/core';

class AdsIconRegistry {
    constructor() {
        this.registry = new Map();
    }
    register(icons) {
        if (Array.isArray(icons)) {
            icons.forEach((icon) => this.registry.set(icon.name, icon.data));
        }
        else {
            this.registry.set(icons.name, icons.data);
        }
    }
    get(iconName) {
        if (!this.registry.has(iconName)) {
            console.warn(`Could not find a Ads Icon with the name ${iconName}. Did you add it to the icon registry?`);
        }
        return this.registry.get(iconName);
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: AdsIconRegistry, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: AdsIconRegistry, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: AdsIconRegistry, decorators: [{
            type: Injectable,
            args: [{
                    providedIn: 'root',
                }]
        }] });

class AdsIconComponent {
    /** @ignore */
    static { this.instanceCounter = 0; }
    /** @ignore */
    constructor(element, registry, renderer) {
        this.element = element;
        this.registry = registry;
        this.renderer = renderer;
        /**
         * The size of the icon
         */
        this.size = 'md';
        /** @ignore */
        this.sizes = {
            xxl: '128px',
            xl: '64px',
            lg: '48px',
            md: '32px',
            sm: '24px',
            xs: '20px',
            xxs_16: '16px',
            xxs: '14px',
            xxxs: '12px',
            xxxxs: '8px',
            auto: 'auto',
        };
        /** @ignore */
        this.themes = {
            iconPrimary: '--color-medium',
            'medium-50': '--color-medium-50',
            secondary: '--color-secondary',
            success: '--color-success',
            warn: '--color-error',
            primary: '--color-primary',
            white: '--color-white',
            'dark-50': '--color-dark-50',
            dark: '--color-dark',
            link: '--color-link',
            secondaryHover: '--color-secondary-hover',
            light: '--color-light',
        };
        this.instanceId = AdsIconComponent.instanceCounter++;
    }
    /** @ignore */
    ngOnInit() {
        this.renderIcon();
    }
    /** @ignore */
    ngOnChanges(changes) {
        if (changes.size || changes.color || changes.theme || changes.stroke || changes.fill || changes.name) {
            this.renderIcon();
        }
    }
    /** @ignore */
    renderIcon() {
        let iconSVG = this.registry.get(this.name);
        if (iconSVG) {
            // Make clip-path and other ID references unique to avoid conflicts with multiple instances
            iconSVG = this.makeIdsUnique(iconSVG);
            this.element.nativeElement.innerHTML = iconSVG;
            this.updateSize();
            this.updateColor();
            this.updateTheme();
            this.updateStroke();
        }
        else {
            console.warn(`${this.name} is missing from the icon registry`);
        }
    }
    /** @ignore */
    makeIdsUnique(svg) {
        // Find all id definitions and their references, make them unique
        const idRegex = /id="([^"]+)"/g;
        const ids = new Set();
        let match;
        // Collect all IDs
        while ((match = idRegex.exec(svg)) !== null) {
            ids.add(match[1]);
        }
        // Replace each ID and its references with unique versions
        let result = svg;
        ids.forEach((id) => {
            const uniqueId = `${id}_${this.instanceId}`;
            // Escape special regex characters in the ID
            const escapedId = id.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
            result = result.replace(new RegExp(`id="${escapedId}"`, 'g'), `id="${uniqueId}"`);
            result = result.replace(new RegExp(`url\\(#${escapedId}\\)`, 'g'), `url(#${uniqueId})`);
            // Also update xlink:href and href references (used by flag icons with embedded images)
            result = result.replace(new RegExp(`xlink:href="#${escapedId}"`, 'g'), `xlink:href="#${uniqueId}"`);
            result = result.replace(new RegExp(`href="#${escapedId}"`, 'g'), `href="#${uniqueId}"`);
        });
        return result;
    }
    /** @ignore */
    updateSize() {
        const size = this.sizes[this.size];
        this.renderer.setStyle(this.element.nativeElement, 'fontSize', size);
        this.renderer.setStyle(this.element.nativeElement, 'width', size);
        this.renderer.setStyle(this.element.nativeElement, 'height', size);
        const svgElement = this.getSvgElement();
        if (svgElement) {
            this.renderer.setStyle(svgElement, 'width', size);
            this.renderer.setStyle(svgElement, 'height', size);
        }
    }
    /** @ignore */
    updateColor() {
        if (this.color) {
            const svg = this.element.nativeElement.querySelector('svg');
            this.renderer.setStyle(svg, 'fill', `var(${this.color})`);
        }
    }
    /** @ignore */
    updateTheme() {
        if (this.theme) {
            const themeColor = this.themes[this.theme];
            if (themeColor) {
                this.renderer.setStyle(this.element.nativeElement, 'color', `var(${themeColor})`);
            }
            else {
                console.warn(`${this.theme} is not a valid ads-icon theme. Valid themes include: 'iconPrimary', 'primary', 'secondary', 'success', 'warn', 'white'`);
            }
        }
    }
    /** @ignore */
    updateStroke() {
        if (this.stroke) {
            const strokeColor = this.themes[this.stroke];
            if (strokeColor) {
                this.renderer.setStyle(this.element.nativeElement, 'stroke', `var(${strokeColor})`);
            }
            else {
                console.warn(`${this.stroke} is not a valid ads-icon stroke. Valid strokes include: 'iconPrimary', 'primary', 'secondary', 'success', 'warn', 'white', 'dark-50', 'dark'`);
            }
        }
    }
    /** @ignore */
    getSvgElement() {
        return this.element.nativeElement.querySelector('svg');
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: AdsIconComponent, deps: [{ token: i0.ElementRef }, { token: AdsIconRegistry }, { token: i0.Renderer2 }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.0.6", type: AdsIconComponent, isStandalone: false, selector: "ads-icon", inputs: { size: "size", name: "name", color: "color", theme: "theme", stroke: "stroke" }, usesOnChanges: true, ngImport: i0, template: '', isInline: true, styles: [":host{display:inline-flex;justify-content:center;align-items:center;width:32px;height:32px;font-size:32px;fill:currentColor}:host ::ng-deep [data-no-fill]{fill:none!important}:host ::ng-deep [data-no-stroke]{stroke:none!important}:host ::ng-deep [data-stroke-white]{stroke:var(--color-white)}:host ::ng-deep [data-fill-white]{fill:var(--color-white)}:host ::ng-deep [data-fill-logo]{fill:var(--color-logo)}\n"] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: AdsIconComponent, decorators: [{
            type: Component,
            args: [{ selector: 'ads-icon', template: '', standalone: false, styles: [":host{display:inline-flex;justify-content:center;align-items:center;width:32px;height:32px;font-size:32px;fill:currentColor}:host ::ng-deep [data-no-fill]{fill:none!important}:host ::ng-deep [data-no-stroke]{stroke:none!important}:host ::ng-deep [data-stroke-white]{stroke:var(--color-white)}:host ::ng-deep [data-fill-white]{fill:var(--color-white)}:host ::ng-deep [data-fill-logo]{fill:var(--color-logo)}\n"] }]
        }], ctorParameters: () => [{ type: i0.ElementRef }, { type: AdsIconRegistry }, { type: i0.Renderer2 }], propDecorators: { size: [{
                type: Input
            }], name: [{
                type: Input
            }], color: [{
                type: Input
            }], theme: [{
                type: Input
            }], stroke: [{
                type: Input
            }] } });

class AdsIconModule {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: AdsIconModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "21.0.6", ngImport: i0, type: AdsIconModule, declarations: [AdsIconComponent], exports: [AdsIconComponent] }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: AdsIconModule }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: AdsIconModule, decorators: [{
            type: NgModule,
            args: [{
                    declarations: [AdsIconComponent],
                    exports: [AdsIconComponent],
                }]
        }] });

/*
 * Public API Surface of ads-icons
 */

/**
 * Generated bundle index. Do not edit.
 */

export { AdsIconComponent, AdsIconModule, AdsIconRegistry };
//# sourceMappingURL=ascentgl-ads-icons.mjs.map
