import * as i0 from '@angular/core';
import { Component, ViewEncapsulation, ChangeDetectionStrategy, Input, NgModule } from '@angular/core';
import { SvgComponent, SVG_OPTIONS_TOKEN, SvgModule } from '@ironsource/fusion-ui/components/svg';
import { CommonModule } from '@angular/common';
import { ICON_OPTIONS_DEFUALT_VALUE } from '@ironsource/fusion-ui/components/icon/common/entities';

class IconComponent extends SvgComponent {
    set name(val) {
        if (typeof val === 'string') {
            this.setLibPath(val);
            this.onNameChanged(this.iconName ?? val);
        }
        else {
            this.libVersion = val?.iconVersion;
            this.onNameChanged(val?.iconName);
        }
    }
    getUrlPath() {
        if (!this.iconName) {
            throw new Error(`Asset path-name '${this.svgPath}' not set`);
        }
        else {
            if (this.svgOptions?.assetsPath) {
                this.svgPath =
                    this.svgOptions.assetsPath === 'https://fusion.ironsrc.net/assets'
                        ? `${this.libVersion}/${this.iconName}`
                        : `/${this.iconName}`;
            }
        }
        return super.getUrlPath();
    }
    setLibPath(value) {
        this.removeCssClass();
        if (typeof value === 'string' && value.includes('/')) {
            const lastIndex = value.lastIndexOf('/');
            this.libVersion = value.substring(0, lastIndex);
            this.iconName = value.substring(lastIndex + 1);
            // for phosphor regular icons
            if (this.libVersion === 'ph') {
                this.libVersion += '/regular';
            }
            else if (this.libVersion === 'ph/bold') {
                this.iconName += '-bold';
            }
            else if (this.libVersion === 'ph/fill') {
                this.iconName += '-fill';
            }
        }
    }
    removeCssClass() {
        if (!!this.iconName) {
            this.renderer.removeClass(this.elementRef.nativeElement, this.iconName.replace(/[\/,_, ]/gi, '-'));
        }
        this.iconName = null;
    }
    onNameChanged(value) {
        if (!!value) {
            this.renderer.addClass(this.elementRef.nativeElement, value.replace(/[\/,_, ]/gi, '-'));
        }
        this.path = this.iconName = value;
    }
    static { this.ɵfac = /*@__PURE__*/ (() => { let ɵIconComponent_BaseFactory; return function IconComponent_Factory(t) { return (ɵIconComponent_BaseFactory || (ɵIconComponent_BaseFactory = i0.ɵɵgetInheritedFactory(IconComponent)))(t || IconComponent); }; })(); }
    static { this.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: IconComponent, selectors: [["fusion-icon"]], inputs: { name: "name" }, features: [i0.ɵɵInheritDefinitionFeature], decls: 1, vars: 0, template: function IconComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵelement(0, "span");
        } }, styles: ["fusion-icon{display:inline;color:inherit}fusion-icon svg{max-height:100%;width:inherit;height:inherit}fusion-icon.loading svg *{fill:none!important}fusion-icon:not(.fu-colored) svg *{fill:currentColor}\n"], encapsulation: 2, changeDetection: 0 }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(IconComponent, [{
        type: Component,
        args: [{ selector: 'fusion-icon', template: '<span></span>', encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, styles: ["fusion-icon{display:inline;color:inherit}fusion-icon svg{max-height:100%;width:inherit;height:inherit}fusion-icon.loading svg *{fill:none!important}fusion-icon:not(.fu-colored) svg *{fill:currentColor}\n"] }]
    }], null, { name: [{
            type: Input
        }] }); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(IconComponent, { className: "IconComponent", filePath: "icon.component.ts", lineNumber: 12 }); })();

class IconModule {
    static forRoot(options) {
        return {
            ngModule: IconModule,
            providers: [
                {
                    provide: SVG_OPTIONS_TOKEN,
                    useValue: options ? options.svgOptions : ICON_OPTIONS_DEFUALT_VALUE
                }
            ]
        };
    }
    static { this.ɵfac = function IconModule_Factory(t) { return new (t || IconModule)(); }; }
    static { this.ɵmod = /*@__PURE__*/ i0.ɵɵdefineNgModule({ type: IconModule }); }
    static { this.ɵinj = /*@__PURE__*/ i0.ɵɵdefineInjector({ imports: [CommonModule, SvgModule] }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(IconModule, [{
        type: NgModule,
        args: [{
                declarations: [IconComponent],
                exports: [IconComponent],
                imports: [CommonModule, SvgModule]
            }]
    }], null, null); })();
(function () { (typeof ngJitMode === "undefined" || ngJitMode) && i0.ɵɵsetNgModuleScope(IconModule, { declarations: [IconComponent], imports: [CommonModule, SvgModule], exports: [IconComponent] }); })();

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

export { IconComponent, IconModule };
//# sourceMappingURL=ironsource-fusion-ui-components-icon-v1.mjs.map
