import * as i0 from '@angular/core';
import { InjectionToken, isDevMode, forwardRef, booleanAttribute, Input, Directive, Inject, Injectable, inject, NgModule, InjectFlags, Renderer2, DestroyRef, ElementRef } from '@angular/core';
import { BehaviorSubject, Subject, Observable, of, distinctUntilChanged, filter, Subscription, skip, tap, switchMap, map as map$1 } from 'rxjs';
import { DOCUMENT } from '@angular/common';
import * as i1$1 from '@angular/router';
import { Router, ActivatedRoute } from '@angular/router';
import * as i1 from '@fundamental-ngx/cdk/utils';
import { ContentDensityService, consumerProviderFactory } from '@fundamental-ngx/cdk/utils';
import { map } from 'rxjs/operators';
import { toSignal, takeUntilDestroyed } from '@angular/core/rxjs-interop';

const ContentDensityGlobalKeyword = 'global';
const ContentDensityDefaultKeyword = 'default';

var ContentDensityMode;
(function (ContentDensityMode) {
    ContentDensityMode["COZY"] = "cozy";
    ContentDensityMode["CONDENSED"] = "condensed";
    ContentDensityMode["COMPACT"] = "compact";
})(ContentDensityMode || (ContentDensityMode = {}));

const isCompact = (density) => density === ContentDensityMode.COMPACT;
const isCondensed = (density) => density === ContentDensityMode.CONDENSED;
const isCozy = (density) => density === ContentDensityMode.COZY;
const isContentDensityMode = (density) => isCompact(density) || isCondensed(density) || isCozy(density) || density === ContentDensityGlobalKeyword;

const CONTENT_DENSITY_DIRECTIVE = new InjectionToken('ContentDensityDirective');

/**
 * Directive to control the content density of the elements.
 * This Directive is used in density controllers and consumers
 */
class ContentDensityDirective extends BehaviorSubject {
    /**
     * Update the content density of the element on the fly
     */
    set fdContentDensity(val) {
        if (!isContentDensityMode(val)) {
            if (isDevMode() && val !== '') {
                console.log(`The value "${val}" is not a valid content density mode.
                     Using "${ContentDensityGlobalKeyword}" instead.`);
            }
            val = ContentDensityGlobalKeyword;
        }
        this.next(val);
    }
    /**
     * This input is basically syntax sugar, for not writing fdContentDensity="compact",
     * instead you can just write fdCompact="true" or [fdCompact]
     */
    set fdCompact(val) {
        this.next(val ? ContentDensityMode.COMPACT : ContentDensityGlobalKeyword);
    }
    /**
     * This input is basically syntax sugar, for not writing fdContentDensity="condensed",
     * instead you can just write fdCondensed="true" or [fdCondensed]
     */
    set fdCondensed(val) {
        this.next(val ? ContentDensityMode.CONDENSED : ContentDensityGlobalKeyword);
    }
    /**
     * This input is basically syntax sugar, for not writing fdContentDensity="cozy",
     * instead you can just write fdCozy="true" or [fdCozy]
     */
    set fdCozy(val) {
        this.next(val ? ContentDensityMode.COZY : ContentDensityGlobalKeyword);
    }
    /** @hidden */
    constructor() {
        super(ContentDensityGlobalKeyword);
    }
    /** @hidden */
    ngOnDestroy() {
        this.complete();
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.3", ngImport: i0, type: ContentDensityDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
    static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "16.1.0", version: "19.2.3", type: ContentDensityDirective, isStandalone: true, selector: "[fdContentDensity]:not([fdCompact]):not([fdCondensed]):not([fdCozy]),\n                [fdCompact]:not([fdContentDensity]):not([fdCondensed]):not([fdCozy]),\n                [fdCondensed]:not([fdContentDensity]):not([fdCompact]):not([fdCozy]),\n                [fdCozy]:not([fdContentDensity]):not([fdCompact]):not([fdCondensed])", inputs: { fdContentDensity: "fdContentDensity", fdCompact: ["fdCompact", "fdCompact", booleanAttribute], fdCondensed: ["fdCondensed", "fdCondensed", booleanAttribute], fdCozy: ["fdCozy", "fdCozy", booleanAttribute] }, providers: [
            {
                provide: CONTENT_DENSITY_DIRECTIVE,
                useExisting: forwardRef(() => ContentDensityDirective)
            }
        ], exportAs: ["fdContentDensity"], usesInheritance: true, ngImport: i0 }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.3", ngImport: i0, type: ContentDensityDirective, decorators: [{
            type: Directive,
            args: [{
                    selector: `[fdContentDensity]:not([fdCompact]):not([fdCondensed]):not([fdCozy]),
                [fdCompact]:not([fdContentDensity]):not([fdCondensed]):not([fdCozy]),
                [fdCondensed]:not([fdContentDensity]):not([fdCompact]):not([fdCozy]),
                [fdCozy]:not([fdContentDensity]):not([fdCompact]):not([fdCondensed])`,
                    exportAs: 'fdContentDensity',
                    providers: [
                        {
                            provide: CONTENT_DENSITY_DIRECTIVE,
                            useExisting: forwardRef(() => ContentDensityDirective)
                        }
                    ],
                    standalone: true
                }]
        }], ctorParameters: () => [], propDecorators: { fdContentDensity: [{
                type: Input
            }], fdCompact: [{
                type: Input,
                args: [{ transform: booleanAttribute }]
            }], fdCondensed: [{
                type: Input,
                args: [{ transform: booleanAttribute }]
            }], fdCozy: [{
                type: Input,
                args: [{ transform: booleanAttribute }]
            }] } });

/**
 * Abstract provider class for providing content density storage functionality
 * Default implementation is MemoryContentDensityStorage
 */
class ContentDensityStorage {
}

const CONTENT_DENSITY_STORAGE_KEY = new InjectionToken('Content density storage key for local storage or for url param', {
    factory: () => '__ContentDensity__'
});

const DEFAULT_CONTENT_DENSITY = new InjectionToken('Default global content density', {
    factory: () => ContentDensityMode.COZY
});

class LocalContentDensityStorage {
    /** @hidden */
    constructor(_defaultContentDensity, _storageKey, _storage) {
        this._defaultContentDensity = _defaultContentDensity;
        this._storageKey = _storageKey;
        this._storage = _storage;
        /** @hidden */
        this._update$ = new Subject();
        this._initialize();
    }
    /** Content density observable */
    getContentDensity() {
        return new Observable((subscriber) => {
            subscriber.next(this._storage.get(this._storageKey));
            const subscription = this._update$.subscribe(() => {
                subscriber.next(this._storage.get(this._storageKey));
            });
            return () => {
                subscription.unsubscribe();
            };
        });
    }
    /** Change content density */
    setContentDensity(density) {
        this._storage.set(this._storageKey, density);
        this._update$.next();
        return of(undefined);
    }
    /** @hidden */
    _initialize() {
        if (!this._storage.get(this._storageKey)) {
            this._storage.set(this._storageKey, this._defaultContentDensity);
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.3", ngImport: i0, type: LocalContentDensityStorage, deps: [{ token: DEFAULT_CONTENT_DENSITY }, { token: CONTENT_DENSITY_STORAGE_KEY }, { token: i1.LocalStorageService }], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.3", ngImport: i0, type: LocalContentDensityStorage }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.3", ngImport: i0, type: LocalContentDensityStorage, decorators: [{
            type: Injectable
        }], ctorParameters: () => [{ type: ContentDensityMode, decorators: [{
                    type: Inject,
                    args: [DEFAULT_CONTENT_DENSITY]
                }] }, { type: undefined, decorators: [{
                    type: Inject,
                    args: [CONTENT_DENSITY_STORAGE_KEY]
                }] }, { type: i1.LocalStorageService }] });

class MemoryContentDensityStorage {
    /** @hidden */
    constructor(defaultContentDensity) {
        this._currentContentDensity$ = new BehaviorSubject(defaultContentDensity);
    }
    /** Content density observable */
    getContentDensity() {
        return this._currentContentDensity$.asObservable();
    }
    /** Change content density */
    setContentDensity(density) {
        this._currentContentDensity$.next(density);
        return of(undefined);
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.3", ngImport: i0, type: MemoryContentDensityStorage, deps: [{ token: DEFAULT_CONTENT_DENSITY }], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.3", ngImport: i0, type: MemoryContentDensityStorage }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.3", ngImport: i0, type: MemoryContentDensityStorage, decorators: [{
            type: Injectable
        }], ctorParameters: () => [{ type: ContentDensityMode, decorators: [{
                    type: Inject,
                    args: [DEFAULT_CONTENT_DENSITY]
                }] }] });

class UrlContentDensityStorage {
    /** @hidden */
    constructor(_router, _activatedRoute, _defaultContentDensity, _storageKey) {
        this._router = _router;
        this._activatedRoute = _activatedRoute;
        this._defaultContentDensity = _defaultContentDensity;
        this._storageKey = _storageKey;
        this._initialize();
    }
    /** Content density observable */
    getContentDensity() {
        return this._current$.asObservable().pipe(distinctUntilChanged());
    }
    /** Change content density */
    setContentDensity(density) {
        this._current$.next(density);
        this._setUrlQueryParam(density);
        return of(undefined);
    }
    /** @hidden */
    _initialize() {
        this._current$ = new BehaviorSubject(this._defaultContentDensity);
        this._activatedRoute.queryParams
            .pipe(filter((queryParams) => !!queryParams[this._storageKey]))
            .subscribe((queryParams) => {
            this._current$.next(queryParams[this._storageKey]);
        });
    }
    /** @hidden */
    _setUrlQueryParam(density) {
        const url = new URL(`https://google.com${this._router.url}`);
        url.searchParams.delete(this._storageKey);
        url.searchParams.append(this._storageKey, density);
        const queryParams = {};
        url.searchParams.forEach((value, key) => (queryParams[key] = value));
        this._router.navigateByUrl(url.pathname + '?' + url.searchParams.toString());
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.3", ngImport: i0, type: UrlContentDensityStorage, deps: [{ token: i1$1.Router }, { token: i1$1.ActivatedRoute }, { token: DEFAULT_CONTENT_DENSITY }, { token: CONTENT_DENSITY_STORAGE_KEY }], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.3", ngImport: i0, type: UrlContentDensityStorage }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.3", ngImport: i0, type: UrlContentDensityStorage, decorators: [{
            type: Injectable
        }], ctorParameters: () => [{ type: i1$1.Router }, { type: i1$1.ActivatedRoute }, { type: ContentDensityMode, decorators: [{
                    type: Inject,
                    args: [DEFAULT_CONTENT_DENSITY]
                }] }, { type: undefined, decorators: [{
                    type: Inject,
                    args: [CONTENT_DENSITY_STORAGE_KEY]
                }] }] });

/**
 * Service for managing global content density state.
 */
class GlobalContentDensityService {
    /** @hidden */
    constructor(_storage) {
        this._storage = _storage;
        /** @hidden */
        this._subscription = new Subscription();
        this._subscription.add(this.contentDensityListener().subscribe((density) => {
            this.currentContentDensity = density;
        }));
    }
    /** Listen to current content density changes */
    contentDensityListener() {
        return this._storage.getContentDensity();
    }
    /** Update content density */
    updateContentDensity(density) {
        return this._storage.setContentDensity(density);
    }
    /** @hidden */
    ngOnDestroy() {
        this._subscription.unsubscribe();
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.3", ngImport: i0, type: GlobalContentDensityService, deps: [{ token: ContentDensityStorage }], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.3", ngImport: i0, type: GlobalContentDensityService }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.3", ngImport: i0, type: GlobalContentDensityService, decorators: [{
            type: Injectable
        }], ctorParameters: () => [{ type: ContentDensityStorage, decorators: [{
                    type: Inject,
                    args: [ContentDensityStorage]
                }] }] });

/**
 * Temporary replacement for ContentDensityService
 */
class DeprecatedContentDensityService {
    /** @hidden */
    constructor(_contentDensityController) {
        this._contentDensityController = _contentDensityController;
        this.contentDensity = new BehaviorSubject(inject(DEFAULT_CONTENT_DENSITY));
        this.contentDensity
            .pipe(skip(1), tap((d) => this._contentDensityController.updateContentDensity(d)))
            .subscribe();
    }
    /** @hidden */
    get _contentDensityListener() {
        return this._contentDensityController.contentDensityListener();
    }
    /** @hidden */
    get _isCompactDensity() {
        return this._contentDensityController.contentDensityListener().pipe(map(isCompact));
    }
    /** @hidden */
    ngOnDestroy() {
        this.contentDensity.complete();
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.3", ngImport: i0, type: DeprecatedContentDensityService, deps: [{ token: GlobalContentDensityService }], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.3", ngImport: i0, type: DeprecatedContentDensityService }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.3", ngImport: i0, type: DeprecatedContentDensityService, decorators: [{
            type: Injectable
        }], ctorParameters: () => [{ type: GlobalContentDensityService }] });

function generateContentDensityStorage(config) {
    if (config.storage === 'localStorage') {
        return {
            provide: ContentDensityStorage,
            useClass: LocalContentDensityStorage
        };
    }
    if (config.storage === 'memory') {
        return {
            provide: ContentDensityStorage,
            useClass: MemoryContentDensityStorage
        };
    }
    if (config.storage === 'url') {
        return {
            provide: ContentDensityStorage,
            useClass: UrlContentDensityStorage,
            deps: [Router, ActivatedRoute, DEFAULT_CONTENT_DENSITY, CONTENT_DENSITY_STORAGE_KEY, DOCUMENT]
        };
    }
    return [];
}
/**
 * Provides content density services and configurations
 * @param config
 */
function provideContentDensity(config) {
    let storage;
    const conf = config || { storage: 'memory' };
    if (typeof conf.storage === 'string') {
        storage = generateContentDensityStorage(conf);
    }
    else if (typeof conf.storage === 'object') {
        storage = conf.storage;
    }
    else {
        storage = {
            provide: ContentDensityStorage,
            useClass: MemoryContentDensityStorage
        };
    }
    return [
        {
            provide: DEFAULT_CONTENT_DENSITY,
            useValue: conf.defaultGlobalContentDensity || ContentDensityMode.COZY
        },
        {
            provide: CONTENT_DENSITY_STORAGE_KEY,
            useValue: conf.storageKey || '__ContentDensity__'
        },
        {
            provide: ContentDensityService,
            useClass: DeprecatedContentDensityService
        },
        GlobalContentDensityService,
        storage
    ];
}

class ContentDensityModule {
    /** Module with providers */
    static forRoot(config) {
        return {
            ngModule: ContentDensityModule,
            providers: [provideContentDensity(config)]
        };
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.3", ngImport: i0, type: ContentDensityModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.3", ngImport: i0, type: ContentDensityModule, imports: [ContentDensityDirective], exports: [ContentDensityDirective] }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.3", ngImport: i0, type: ContentDensityModule }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.3", ngImport: i0, type: ContentDensityModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [ContentDensityDirective],
                    exports: [ContentDensityDirective]
                }]
        }] });

class ContentDensityObserverSettings {
}

const getChangesSource$ = (params) => {
    const serviceValue$ = params.contentDensityService
        ? params.contentDensityService.contentDensityListener()
        : of(params.defaultContentDensity);
    const changesSource$ = params.parentContentDensityService
        ? params.parentContentDensityService
        : params.contentDensityDirective
            ? params.contentDensityDirective
            : serviceValue$;
    return changesSource$.pipe(switchMap((mode) => {
        if (mode === ContentDensityDefaultKeyword) {
            return of(params.defaultContentDensity);
        }
        if (mode === ContentDensityGlobalKeyword) {
            return serviceValue$;
        }
        return of(mode);
    }));
};

const defaultContentDensityObserverConfigs = {
    modifiers: {
        [ContentDensityMode.COMPACT]: 'is-compact',
        [ContentDensityMode.COZY]: 'is-cozy',
        [ContentDensityMode.CONDENSED]: 'is-condensed'
    },
    supportedContentDensity: [ContentDensityMode.COMPACT, ContentDensityMode.COZY],
    defaultContentDensity: ContentDensityMode.COZY,
    debug: false,
    alwaysAddModifiers: false,
    restrictChildContentDensity: false
};

const isFactoryProvider = (obj) => !!(obj && obj.useFactory);
const getDeps = (injector, defaultContentDensity) => (defaultContentDensity.deps || []).map((dep) => {
    if (Array.isArray(dep)) {
        let type;
        let flags = InjectFlags.Default;
        for (let index = 0; index < dep.length; index++) {
            const flag = dep[index]['__NG_DI_FLAG__'];
            if (typeof flag === 'number') {
                // eslint-disable-next-line no-bitwise
                flags |= flag;
            }
            else {
                type = dep[index];
            }
        }
        return injector.get(type, undefined, flags);
    }
    return injector.get(dep, undefined, InjectFlags.Default);
});
const getDefaultContentDensity = (injector, configuration) => {
    if (typeof configuration.defaultContentDensity === 'string') {
        return configuration.defaultContentDensity;
    }
    if (isFactoryProvider(configuration.defaultContentDensity)) {
        const deps = getDeps(injector, configuration.defaultContentDensity);
        return configuration.defaultContentDensity.useFactory(...deps);
    }
    return injector.get(configuration.defaultContentDensity, undefined, undefined);
};
const initialContentDensity = (injector, configuration) => {
    const serviceValue = injector.get(GlobalContentDensityService, null, InjectFlags.Optional)?.currentContentDensity;
    if (serviceValue) {
        return serviceValue;
    }
    return getDefaultContentDensity(injector, {
        ...defaultContentDensityObserverConfigs,
        ...(configuration || {})
    });
};
class ContentDensityObserver extends BehaviorSubject {
    /** @hidden */
    get isCompact() {
        return this._isCompact$.value;
    }
    /** @hidden */
    get isCozy() {
        return this._isCozy$.value;
    }
    /** @hidden */
    get isCondensed() {
        return this._isCondensed$.value;
    }
    /** @hidden */
    constructor(_injector, _providedConfig) {
        super(initialContentDensity(_injector, _providedConfig));
        /** @hidden */
        this.contentDensity$ = toSignal(this);
        /** @hidden */
        this._isCompact$ = new BehaviorSubject(false);
        /** @hidden */
        this._isCozy$ = new BehaviorSubject(false);
        /** @hidden */
        this._isCondensed$ = new BehaviorSubject(false);
        /** @hidden */
        this._globalContentDensityService = inject(GlobalContentDensityService, {
            optional: true
        });
        /** @hidden */
        this._contentDensityDirective = inject(CONTENT_DENSITY_DIRECTIVE, {
            optional: true
        });
        /** @hidden */
        this._parentContentDensityObserver = inject(ContentDensityObserver, {
            optional: true,
            skipSelf: true
        });
        /** @hidden */
        this._renderer = inject(Renderer2);
        /** @hidden */
        this._destroyRef = inject(DestroyRef);
        /** @hidden */
        this._elementRef = inject(ElementRef);
        /** @hidden */
        this._elements = [this._elementRef];
        /** @hidden */
        this._alternativeTo = {
            [ContentDensityMode.COMPACT]: () => this._isSupported(ContentDensityMode.CONDENSED) ? ContentDensityMode.CONDENSED : ContentDensityMode.COZY,
            [ContentDensityMode.CONDENSED]: () => this._isSupported(ContentDensityMode.COMPACT) ? ContentDensityMode.COMPACT : ContentDensityMode.COZY,
            [ContentDensityMode.COZY]: () => ContentDensityMode.COZY // No alternative here, everyone should support it
        };
        this.isCompact$ = this._isCompact$.asObservable();
        this.isCozy$ = this._isCozy$.asObservable();
        this.isCondensed$ = this._isCondensed$.asObservable();
        this.isCompactSignal = toSignal(this.isCompact$, { initialValue: this._isCompact$.value });
        this.isCozySignal = toSignal(this.isCozy$, { initialValue: this._isCozy$.value });
        this.isCondensedSignal = toSignal(this.isCondensed$, { initialValue: this._isCondensed$.value });
        this._destroyRef.onDestroy(() => {
            this.complete();
            if (this.config.debug) {
                console.log('ContentDensityObserver: destroyed');
            }
        });
        this.config = {
            ...defaultContentDensityObserverConfigs,
            ...(this._parentContentDensityObserver?.config ?? {}),
            ...(_providedConfig || {})
        };
        getChangesSource$({
            defaultContentDensity: this.value,
            contentDensityDirective: this._contentDensityDirective ?? undefined,
            contentDensityService: this._globalContentDensityService ?? undefined,
            parentContentDensityService: this.config.restrictChildContentDensity
                ? (this._parentContentDensityObserver?.asObservable() ?? undefined)
                : undefined
        })
            .pipe(map$1((density) => {
            if (this.config.debug) {
                console.log(`ContentDensityObserver: density changed to ${density}`);
            }
            if (!this._isSupported(density)) {
                try {
                    if (this.config.debug) {
                        console.log(`ContentDensityObserver: ${density} is not supported. Failing back to alternative one.`);
                    }
                    return this._alternativeTo[density]();
                }
                catch {
                    throw new Error(`ContentDensityObserver: density ${density} is not supported`);
                }
            }
            return density;
        }), distinctUntilChanged(), takeUntilDestroyed(this._destroyRef))
            .subscribe((density) => {
            this.next(density);
            this._applyClass();
            this._isCompact$.next(density === ContentDensityMode.COMPACT);
            this._isCozy$.next(density === ContentDensityMode.COZY);
            this._isCondensed$.next(density === ContentDensityMode.CONDENSED);
        });
    }
    /** @hidden */
    consume(...consumers) {
        this._elements.concat(...consumers.map((c) => c.elementRef));
    }
    /**
     * Completes the stream and closes all internal subscriptions.
     */
    complete() {
        super.complete();
        this._isCondensed$.complete();
        this._isCozy$.complete();
        this._isCompact$.complete();
        this._parentContentDensityObserver = null;
        this._contentDensityDirective = null;
        this._globalContentDensityService = null;
        this._elementRef = null;
        this._renderer = null;
        this._elements = [];
    }
    /** @hidden */
    removeConsumer(consumer) {
        this._elements.splice(this._elements.indexOf(consumer.elementRef), 1);
    }
    /** @hidden */
    _applyClass() {
        if (!this.config?.modifiers) {
            return;
        }
        const modifiers = this.config.modifiers;
        const parentContentDensityEqual = this._parentContentDensityObserver?.value === this.value;
        this._elements.forEach((element) => {
            Object.values(modifiers).forEach((className) => {
                this._renderer?.removeClass(element?.nativeElement, className);
            });
            // Simply remove all modifiers from current element. Content density state is covered by parent element.
            if (parentContentDensityEqual && !this.config.alwaysAddModifiers) {
                return;
            }
            const modifierClass = modifiers[this.value];
            if (modifierClass) {
                this._renderer?.addClass(element?.nativeElement, modifierClass);
            }
            this._renderer?.addClass(element?.nativeElement, modifiers[this.value]);
        });
    }
    /** Check if the given density is supported */
    _isSupported(density) {
        return this.config.supportedContentDensity?.includes(density) ?? false;
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.3", ngImport: i0, type: ContentDensityObserver, deps: [{ token: i0.Injector }, { token: ContentDensityObserverSettings }], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.3", ngImport: i0, type: ContentDensityObserver }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.3", ngImport: i0, type: ContentDensityObserver, decorators: [{
            type: Injectable
        }], ctorParameters: () => [{ type: i0.Injector }, { type: ContentDensityObserverSettings }] });

/**
 * Creates provider for ContentDensityObserver
 */
function contentDensityObserverProviders(params) {
    return [consumerProviderFactory(ContentDensityObserver, params)];
}

/** @hidden */
function mockedLocalContentDensityDirective(defaultValue = ContentDensityGlobalKeyword) {
    const behaviorSubject = new BehaviorSubject(defaultValue);
    return {
        contentDensityDirectiveProvider: {
            provide: CONTENT_DENSITY_DIRECTIVE,
            useValue: behaviorSubject.asObservable()
        },
        setContentDensity: (cd) => behaviorSubject.next(cd)
    };
}

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

export { CONTENT_DENSITY_DIRECTIVE, ContentDensityDefaultKeyword, ContentDensityDirective, ContentDensityGlobalKeyword, ContentDensityMode, ContentDensityModule, ContentDensityObserver, ContentDensityObserverSettings, ContentDensityStorage, GlobalContentDensityService, contentDensityObserverProviders, defaultContentDensityObserverConfigs, isCompact, isCondensed, isContentDensityMode, isCozy, mockedLocalContentDensityDirective, provideContentDensity };
//# sourceMappingURL=fundamental-ngx-core-content-density.mjs.map
