import * as i0 from '@angular/core';
import { ElementRef, Renderer2, Directive } from '@angular/core';
import { Subject, BehaviorSubject } from 'rxjs';

var StyleVersion;
(function (StyleVersion) {
    StyleVersion[StyleVersion["V1"] = 1] = "V1";
    StyleVersion[StyleVersion["V2"] = 2] = "V2";
    StyleVersion[StyleVersion["V3"] = 3] = "V3";
})(StyleVersion || (StyleVersion = {}));
const FUSION_STYLE_VERSION_PREFIX = 'fu-style-v';
const FUSION_STYLE_VERSION_CSS_VAR_NAME = '--fu-style-version';

/* eslint-disable @angular-eslint/directive-class-suffix */
class FusionBase {
    get selectedVersion() {
        return this.selectedVersion$.getValue();
    }
    constructor(injector) {
        this.injector = injector;
        this.onDestroy$ = new Subject();
        this.styleVersion = StyleVersion;
        this.selectedVersion$ = new BehaviorSubject(StyleVersion[Object.values(StyleVersion)[Object.values(StyleVersion).length / 2 - 1]] // take latest from enum
        );
    }
    ngAfterViewInit() {
        this.handleStyleVersion();
    }
    ngOnDestroy() {
        this.onDestroy$.next();
        this.onDestroy$.complete();
    }
    handleStyleVersion() {
        const element = this.injector.get(ElementRef);
        const renderer = this.injector.get(Renderer2);
        if (![...element.nativeElement.classList].some(item => item.startsWith(FUSION_STYLE_VERSION_PREFIX))) {
            let uiSelectedStyleVersion = getComputedStyle(element.nativeElement).getPropertyValue(FUSION_STYLE_VERSION_CSS_VAR_NAME).trim();
            uiSelectedStyleVersion = uiSelectedStyleVersion ? uiSelectedStyleVersion : this.selectedVersion$.getValue().toString();
            if (StyleVersion[`V${uiSelectedStyleVersion}`] !== this.selectedVersion$.getValue()) {
                setTimeout(() => {
                    this.selectedVersion$.next(StyleVersion[`V${uiSelectedStyleVersion}`]);
                });
            }
            renderer.addClass(element.nativeElement, FUSION_STYLE_VERSION_PREFIX + uiSelectedStyleVersion);
        }
    }
    static { this.ɵfac = function FusionBase_Factory(t) { return new (t || FusionBase)(i0.ɵɵdirectiveInject(i0.Injector)); }; }
    static { this.ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: FusionBase }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(FusionBase, [{
        type: Directive
    }], () => [{ type: i0.Injector }], null); })();

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

export { FUSION_STYLE_VERSION_CSS_VAR_NAME, FUSION_STYLE_VERSION_PREFIX, FusionBase, StyleVersion };
//# sourceMappingURL=ironsource-fusion-ui-components-fusion-base.mjs.map
