import * as i0 from '@angular/core';
import { InjectionToken, inject, PLATFORM_ID, ElementRef, input, Directive, booleanAttribute, output, DestroyRef, afterNextRender, numberAttribute, forwardRef, NgZone, model, effect, Pipe, Injectable, DOCUMENT, isDevMode, EventEmitter, signal } from '@angular/core';
import { isPlatformBrowser, isPlatformServer } from '@angular/common';
import { FocusMonitor, isFakeMousedownFromScreenReader, isFakeTouchstartFromScreenReader } from '@angular/cdk/a11y';
import { fromEvent, filter, merge, debounceTime, Observable, Subscription } from 'rxjs';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { NG_VALUE_ACCESSOR } from '@angular/forms';
import { normalizePassiveListenerOptions, _getEventTarget, Platform } from '@angular/cdk/platform';
import { coerceElement } from '@angular/cdk/coercion';
import { DomSanitizer, Title, Meta } from '@angular/platform-browser';
import { Router, NavigationEnd, TitleStrategy } from '@angular/router';
import { signalStore, withState, withMethods, patchState } from '@ngrx/signals';

const AUTOFOCUSABLE = new InjectionToken('AUTOFOCUSABLE');

class AutoFocusDirective {
    platformId = inject(PLATFORM_ID);
    elementRef = inject(ElementRef);
    autofocusable = inject(AUTOFOCUSABLE, { optional: true });
    enabled = input(true, { ...(ngDevMode ? { debugName: "enabled" } : /* istanbul ignore next */ {}), alias: 'ngsAutoFocus' });
    ngOnChanges(changes) {
        if (changes['enabled'] && !changes['enabled'].firstChange) {
            this._focus();
        }
    }
    ngAfterViewInit() {
        this._focus();
    }
    _focus() {
        if (this.enabled() === false || this.enabled() === 'false') {
            return;
        }
        if (this.autofocusable) {
            this.autofocusable.focus();
        }
        else {
            this.elementRef.nativeElement.focus();
        }
        this._moveCursorToEnd(this.elementRef.nativeElement);
    }
    _moveCursorToEnd(el) {
        if (!isPlatformBrowser(this.platformId)) {
            return;
        }
        const range = document.createRange();
        const sel = window.getSelection();
        range.selectNodeContents(el);
        range.collapse(false);
        sel?.removeAllRanges();
        sel?.addRange(range);
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: AutoFocusDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
    static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: AutoFocusDirective, isStandalone: true, selector: "[ngsAutoFocus]", inputs: { enabled: { classPropertyName: "enabled", publicName: "ngsAutoFocus", isSignal: true, isRequired: false, transformFunction: null } }, exportAs: ["ngsAutoFocus"], usesOnChanges: true, ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: AutoFocusDirective, decorators: [{
            type: Directive,
            args: [{
                    selector: '[ngsAutoFocus]',
                    exportAs: 'ngsAutoFocus',
                    standalone: true
                }]
        }], propDecorators: { enabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "ngsAutoFocus", required: false }] }] } });

class FocusElementDirective {
    _elementRef = inject(ElementRef);
    _focusMonitor = inject(FocusMonitor);
    checkChildren = input(true, { ...(ngDevMode ? { debugName: "checkChildren" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
    elementFocused = output();
    elementBlurred = output();
    ngAfterViewInit() {
        this._focusMonitor
            .monitor(this._elementRef.nativeElement, this.checkChildren())
            .subscribe(origin => {
            this._emitFocusEvent(origin);
        });
    }
    ngOnDestroy() {
        this._focusMonitor.stopMonitoring(this._elementRef.nativeElement);
    }
    _emitFocusEvent(origin) {
        if (origin) {
            this.elementFocused.emit();
        }
        else {
            this.elementBlurred.emit();
        }
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: FocusElementDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
    static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: FocusElementDirective, isStandalone: true, selector: "[ngsFocusElement]", inputs: { checkChildren: { classPropertyName: "checkChildren", publicName: "checkChildren", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { elementFocused: "elementFocused", elementBlurred: "elementBlurred" }, exportAs: ["ngsFocusElement"], ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: FocusElementDirective, decorators: [{
            type: Directive,
            args: [{
                    selector: '[ngsFocusElement]',
                    exportAs: 'ngsFocusElement',
                    standalone: true
                }]
        }], propDecorators: { checkChildren: [{ type: i0.Input, args: [{ isSignal: true, alias: "checkChildren", required: false }] }], elementFocused: [{ type: i0.Output, args: ["elementFocused"] }], elementBlurred: [{ type: i0.Output, args: ["elementBlurred"] }] } });

class SoundEffectDirective {
    soundSrc = input('assets/sound-effects/mouse-click.ogg', ...(ngDevMode ? [{ debugName: "soundSrc" }] : /* istanbul ignore next */ []));
    _elementRef = inject(ElementRef);
    _destroyRef = inject(DestroyRef);
    constructor() {
        afterNextRender(() => {
            this._init();
        });
    }
    _init() {
        const audio = new Audio(this.soundSrc());
        audio.volume = 0.15;
        fromEvent(this._elementRef.nativeElement, 'click')
            .pipe(takeUntilDestroyed(this._destroyRef))
            .subscribe(async (e) => {
            await audio.play();
        });
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: SoundEffectDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
    static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: SoundEffectDirective, isStandalone: true, selector: "[ngsSoundEffect]", inputs: { soundSrc: { classPropertyName: "soundSrc", publicName: "soundSrc", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: SoundEffectDirective, decorators: [{
            type: Directive,
            args: [{
                    selector: '[ngsSoundEffect]',
                    standalone: true
                }]
        }], ctorParameters: () => [], propDecorators: { soundSrc: [{ type: i0.Input, args: [{ isSignal: true, alias: "soundSrc", required: false }] }] } });

class DebounceTimeDirective {
    elementRef;
    renderer;
    debounceTimer;
    debounceTime = input(300, { ...(ngDevMode ? { debugName: "debounceTime" } : /* istanbul ignore next */ {}), transform: numberAttribute });
    onChange = () => { };
    onTouched = () => { };
    constructor(elementRef, renderer) {
        this.elementRef = elementRef;
        this.renderer = renderer;
    }
    writeValue(value) {
        this.renderer.setProperty(this.elementRef.nativeElement, 'value', value ?? '');
    }
    registerOnChange(fn) {
        this.onChange = fn;
    }
    registerOnTouched(fn) {
        this.onTouched = fn;
    }
    setDisabledState(isDisabled) {
        this.renderer.setProperty(this.elementRef.nativeElement, 'disabled', isDisabled);
    }
    handleInput(event) {
        clearTimeout(this.debounceTimer);
        const target = event.target;
        const value = target?.value ?? '';
        if (!this.debounceTime()) {
            this.onChange(value);
        }
        else {
            this.debounceTimer = setTimeout(() => {
                this.onChange(value);
            }, this.debounceTime());
        }
    }
    handleBlur() {
        this.onTouched();
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: DebounceTimeDirective, deps: [{ token: i0.ElementRef }, { token: i0.Renderer2 }], target: i0.ɵɵFactoryTarget.Directive });
    static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: DebounceTimeDirective, isStandalone: true, selector: "[ngsDebounceTime][ngModel]", inputs: { debounceTime: { classPropertyName: "debounceTime", publicName: "debounceTime", isSignal: true, isRequired: false, transformFunction: null } }, host: { listeners: { "input": "handleInput($event)", "blur": "handleBlur()" } }, providers: [
            {
                provide: NG_VALUE_ACCESSOR,
                useExisting: forwardRef(() => DebounceTimeDirective),
                multi: true,
            },
        ], ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: DebounceTimeDirective, decorators: [{
            type: Directive,
            args: [{
                    selector: '[ngsDebounceTime][ngModel]',
                    providers: [
                        {
                            provide: NG_VALUE_ACCESSOR,
                            useExisting: forwardRef(() => DebounceTimeDirective),
                            multi: true,
                        },
                    ],
                    host: {
                        '(input)': 'handleInput($event)',
                        '(blur)': 'handleBlur()'
                    }
                }]
        }], ctorParameters: () => [{ type: i0.ElementRef }, { type: i0.Renderer2 }], propDecorators: { debounceTime: [{ type: i0.Input, args: [{ isSignal: true, alias: "debounceTime", required: false }] }] } });

/** Possible states for a ripple element. */
var RippleState;
(function (RippleState) {
    RippleState[RippleState["FADING_IN"] = 0] = "FADING_IN";
    RippleState[RippleState["VISIBLE"] = 1] = "VISIBLE";
    RippleState[RippleState["FADING_OUT"] = 2] = "FADING_OUT";
    RippleState[RippleState["HIDDEN"] = 3] = "HIDDEN";
})(RippleState || (RippleState = {}));
/**
 * Reference to a previously launched ripple element.
 */
class RippleRef {
    _renderer;
    element;
    config;
    _animationForciblyDisabledThroughCss;
    /** Current state of the ripple. */
    state = RippleState.HIDDEN;
    constructor(_renderer, 
    /** Reference to the ripple HTML element. */
    element, 
    /** Ripple configuration used for the ripple. */
    config, 
    /* Whether animations are forcibly disabled for ripples through CSS. */
    _animationForciblyDisabledThroughCss = false) {
        this._renderer = _renderer;
        this.element = element;
        this.config = config;
        this._animationForciblyDisabledThroughCss = _animationForciblyDisabledThroughCss;
    }
    /** Fades out the ripple element. */
    fadeOut() {
        this._renderer.fadeOutRipple(this);
    }
}
/** Options used to bind a passive capturing event. */
const passiveCapturingEventOptions = normalizePassiveListenerOptions({
    passive: true,
    capture: true,
});
/** Manages events through delegation so that as few event handlers as possible are bound. */
class RippleEventManager {
    _events = new Map();
    /** Adds an event handler. */
    addHandler(ngZone, name, element, handler) {
        const handlersForEvent = this._events.get(name);
        if (handlersForEvent) {
            const handlersForElement = handlersForEvent.get(element);
            if (handlersForElement) {
                handlersForElement.add(handler);
            }
            else {
                handlersForEvent.set(element, new Set([handler]));
            }
        }
        else {
            this._events.set(name, new Map([[element, new Set([handler])]]));
            ngZone.runOutsideAngular(() => {
                document.addEventListener(name, this._delegateEventHandler, passiveCapturingEventOptions);
            });
        }
    }
    /** Removes an event handler. */
    removeHandler(name, element, handler) {
        const handlersForEvent = this._events.get(name);
        if (!handlersForEvent) {
            return;
        }
        const handlersForElement = handlersForEvent.get(element);
        if (!handlersForElement) {
            return;
        }
        handlersForElement.delete(handler);
        if (handlersForElement.size === 0) {
            handlersForEvent.delete(element);
        }
        if (handlersForEvent.size === 0) {
            this._events.delete(name);
            document.removeEventListener(name, this._delegateEventHandler, passiveCapturingEventOptions);
        }
    }
    /** Event handler that is bound and which dispatches the events to the different targets. */
    _delegateEventHandler = (event) => {
        const target = _getEventTarget(event);
        if (target) {
            this._events.get(event.type)?.forEach((handlers, element) => {
                if (element === target || element.contains(target)) {
                    handlers.forEach(handler => handler.handleEvent(event));
                }
            });
        }
    };
}
/**
 * Default ripple animation configuration for ripples without an explicit
 * animation config specified.
 */
const defaultRippleAnimationConfig = {
    enterDuration: 225,
    exitDuration: 150,
};
/**
 * Timeout for ignoring mouse events. Mouse events will be temporary ignored after touch
 * events to avoid synthetic mouse events.
 */
const ignoreMouseEventsTimeout = 800;
/** Events that signal that the pointer is down. */
const pointerDownEvents = ['mousedown', 'touchstart'];
/** Events that signal that the pointer is up. */
const pointerUpEvents = ['mouseup', 'mouseleave', 'touchend', 'touchcancel'];
/**
 * Helper service that performs DOM manipulations. Not intended to be used outside this module.
 */
class RippleRenderer {
    _target;
    _ngZone;
    _platform;
    /** Element where the ripples are being added to. */
    _containerElement;
    /** Element which triggers the ripple elements on mouse events. */
    _triggerElement = null;
    /** Whether the pointer is currently down or not. */
    _isPointerDown = false;
    /** Map of currently active ripple references. */
    _activeRipples = new Map();
    /** Latest non-persistent ripple that was triggered. */
    _mostRecentTransientRipple = null;
    /** Time in milliseconds when the last touchstart event happened. */
    _lastTouchStartEvent = null;
    /** Whether pointer-up event listeners have been registered. */
    _pointerUpEventsRegistered = false;
    /** Cached dimensions of the ripple container. */
    _containerRect = null;
    static _eventManager = new RippleEventManager();
    constructor(_target, _ngZone, elementOrElementRef, _platform) {
        this._target = _target;
        this._ngZone = _ngZone;
        this._platform = _platform;
        // Only do anything if we're on the browser.
        if (_platform.isBrowser) {
            this._containerElement = coerceElement(elementOrElementRef);
        }
    }
    /** Fades in a ripple at the given coordinates. */
    fadeInRipple(x, y, config = {}) {
        const containerRect = (this._containerRect =
            this._containerRect || this._containerElement.getBoundingClientRect());
        const animationConfig = { ...defaultRippleAnimationConfig, ...config.animation };
        if (config.centered) {
            x = containerRect.left + containerRect.width / 2;
            y = containerRect.top + containerRect.height / 2;
        }
        const radius = config.radius || distanceToFurthestCorner(x, y, containerRect);
        const offsetX = x - containerRect.left;
        const offsetY = y - containerRect.top;
        const enterDuration = animationConfig.enterDuration;
        const ripple = document.createElement('div');
        ripple.classList.add('ngs-ripple-element');
        ripple.style.left = `${offsetX - radius}px`;
        ripple.style.top = `${offsetY - radius}px`;
        ripple.style.height = `${radius * 2}px`;
        ripple.style.width = `${radius * 2}px`;
        if (config.color != null) {
            ripple.style.backgroundColor = config.color;
        }
        ripple.style.transitionDuration = `${enterDuration}ms`;
        this._containerElement.appendChild(ripple);
        const computedStyles = window.getComputedStyle(ripple);
        const userTransitionProperty = computedStyles.transitionProperty;
        const userTransitionDuration = computedStyles.transitionDuration;
        const animationForciblyDisabledThroughCss = userTransitionProperty === 'none' ||
            userTransitionDuration === '0s' ||
            userTransitionDuration === '0s, 0s' ||
            (containerRect.width === 0 && containerRect.height === 0);
        const rippleRef = new RippleRef(this, ripple, config, animationForciblyDisabledThroughCss);
        ripple.style.transform = 'scale3d(1, 1, 1)';
        rippleRef.state = RippleState.FADING_IN;
        if (!config.persistent) {
            this._mostRecentTransientRipple = rippleRef;
        }
        let eventListeners = null;
        if (!animationForciblyDisabledThroughCss && (enterDuration || animationConfig.exitDuration)) {
            this._ngZone.runOutsideAngular(() => {
                const onTransitionEnd = () => {
                    if (eventListeners) {
                        eventListeners.fallbackTimer = null;
                    }
                    clearTimeout(fallbackTimer);
                    this._finishRippleTransition(rippleRef);
                };
                const onTransitionCancel = () => this._destroyRipple(rippleRef);
                const fallbackTimer = setTimeout(onTransitionCancel, (enterDuration || 0) + 100);
                ripple.addEventListener('transitionend', onTransitionEnd);
                ripple.addEventListener('transitioncancel', onTransitionCancel);
                eventListeners = { onTransitionEnd, onTransitionCancel, fallbackTimer };
            });
        }
        this._activeRipples.set(rippleRef, eventListeners);
        if (animationForciblyDisabledThroughCss || !enterDuration) {
            this._finishRippleTransition(rippleRef);
        }
        return rippleRef;
    }
    /** Fades out a ripple reference. */
    fadeOutRipple(rippleRef) {
        if (rippleRef.state === RippleState.FADING_OUT || rippleRef.state === RippleState.HIDDEN) {
            return;
        }
        const rippleEl = rippleRef.element;
        const animationConfig = { ...defaultRippleAnimationConfig, ...rippleRef.config.animation };
        rippleEl.style.transitionDuration = `${animationConfig.exitDuration}ms`;
        rippleEl.style.opacity = '0';
        rippleRef.state = RippleState.FADING_OUT;
        if (rippleRef._animationForciblyDisabledThroughCss || !animationConfig.exitDuration) {
            this._finishRippleTransition(rippleRef);
        }
    }
    /** Fades out all currently active ripples. */
    fadeOutAll() {
        this._getActiveRipples().forEach(ripple => ripple.fadeOut());
    }
    /** Fades out all currently showing non-persistent ripples. */
    fadeOutAllNonPersistent() {
        this._getActiveRipples().forEach(ripple => {
            if (!ripple.config.persistent) {
                ripple.fadeOut();
            }
        });
    }
    /** Sets up the trigger event listeners */
    setupTriggerEvents(elementOrElementRef) {
        const element = coerceElement(elementOrElementRef);
        if (!this._platform.isBrowser || !element || element === this._triggerElement) {
            return;
        }
        this._removeTriggerEvents();
        this._triggerElement = element;
        pointerDownEvents.forEach(type => {
            RippleRenderer._eventManager.addHandler(this._ngZone, type, element, this);
        });
    }
    /** Handles all registered events. */
    handleEvent(event) {
        if (event.type === 'mousedown') {
            this._onMousedown(event);
        }
        else if (event.type === 'touchstart') {
            this._onTouchStart(event);
        }
        else {
            this._onPointerUp();
        }
        if (!this._pointerUpEventsRegistered && this._triggerElement) {
            this._ngZone.runOutsideAngular(() => {
                pointerUpEvents.forEach(type => {
                    this._triggerElement.addEventListener(type, this, passiveCapturingEventOptions);
                });
            });
            this._pointerUpEventsRegistered = true;
        }
    }
    /** Method that will be called if the fade-in or fade-in transition completed. */
    _finishRippleTransition(rippleRef) {
        if (rippleRef.state === RippleState.FADING_IN) {
            this._startFadeOutTransition(rippleRef);
        }
        else if (rippleRef.state === RippleState.FADING_OUT) {
            this._destroyRipple(rippleRef);
        }
    }
    /** Starts the fade-out transition of the given ripple. */
    _startFadeOutTransition(rippleRef) {
        const isMostRecentTransientRipple = rippleRef === this._mostRecentTransientRipple;
        const { persistent } = rippleRef.config;
        rippleRef.state = RippleState.VISIBLE;
        if (!persistent && (!isMostRecentTransientRipple || !this._isPointerDown)) {
            rippleRef.fadeOut();
        }
    }
    /** Destroys the given ripple. */
    _destroyRipple(rippleRef) {
        const eventListeners = this._activeRipples.get(rippleRef) ?? null;
        this._activeRipples.delete(rippleRef);
        if (!this._activeRipples.size) {
            this._containerRect = null;
        }
        if (rippleRef === this._mostRecentTransientRipple) {
            this._mostRecentTransientRipple = null;
        }
        rippleRef.state = RippleState.HIDDEN;
        if (eventListeners !== null) {
            rippleRef.element.removeEventListener('transitionend', eventListeners.onTransitionEnd);
            rippleRef.element.removeEventListener('transitioncancel', eventListeners.onTransitionCancel);
            if (eventListeners.fallbackTimer !== null) {
                clearTimeout(eventListeners.fallbackTimer);
            }
        }
        rippleRef.element.remove();
    }
    /** Function being called whenever the trigger is being pressed using mouse. */
    _onMousedown(event) {
        const isFakeMousedown = isFakeMousedownFromScreenReader(event);
        const isSyntheticEvent = this._lastTouchStartEvent && Date.now() < this._lastTouchStartEvent + ignoreMouseEventsTimeout;
        if (!this._target.rippleDisabled && !isFakeMousedown && !isSyntheticEvent) {
            this._isPointerDown = true;
            this.fadeInRipple(event.clientX, event.clientY, this._target.rippleConfig);
        }
    }
    /** Function being called whenever the trigger is being pressed using touch. */
    _onTouchStart(event) {
        if (!this._target.rippleDisabled && !isFakeTouchstartFromScreenReader(event)) {
            this._lastTouchStartEvent = Date.now();
            this._isPointerDown = true;
            const touches = event.changedTouches;
            if (touches) {
                for (let i = 0; i < touches.length; i++) {
                    this.fadeInRipple(touches[i].clientX, touches[i].clientY, this._target.rippleConfig);
                }
            }
        }
    }
    /** Function being called whenever the trigger is being released. */
    _onPointerUp() {
        if (!this._isPointerDown) {
            return;
        }
        this._isPointerDown = false;
        this._getActiveRipples().forEach(ripple => {
            const isVisible = ripple.state === RippleState.VISIBLE ||
                (ripple.config.terminateOnPointerUp && ripple.state === RippleState.FADING_IN);
            if (!ripple.config.persistent && isVisible) {
                ripple.fadeOut();
            }
        });
    }
    _getActiveRipples() {
        return Array.from(this._activeRipples.keys());
    }
    /** Removes previously registered event listeners from the trigger element. */
    _removeTriggerEvents() {
        const trigger = this._triggerElement;
        if (trigger) {
            pointerDownEvents.forEach(type => RippleRenderer._eventManager.removeHandler(type, trigger, this));
            if (this._pointerUpEventsRegistered) {
                pointerUpEvents.forEach(type => trigger.removeEventListener(type, this, passiveCapturingEventOptions));
                this._pointerUpEventsRegistered = false;
            }
        }
    }
}
/** Returns the distance from the point (x, y) to the furthest corner of a rectangle. */
function distanceToFurthestCorner(x, y, rect) {
    const distX = Math.max(Math.abs(x - rect.left), Math.abs(x - rect.right));
    const distY = Math.max(Math.abs(y - rect.top), Math.abs(y - rect.bottom));
    return Math.sqrt(distX * distX + distY * distY);
}
const RIPPLE_GLOBAL_OPTIONS = new InjectionToken('ngs-ripple-global-options');
class Ripple {
    _elementRef = inject(ElementRef);
    _ngZone = inject(NgZone);
    _platform = inject(Platform);
    _globalOptions = inject(RIPPLE_GLOBAL_OPTIONS, { optional: true }) || {};
    color = input(undefined, { ...(ngDevMode ? { debugName: "color" } : /* istanbul ignore next */ {}), alias: 'ngsRippleColor' });
    unbounded = input(false, { ...(ngDevMode ? { debugName: "unbounded" } : /* istanbul ignore next */ {}), alias: 'ngsRippleUnbounded', transform: booleanAttribute });
    centered = model(false, { ...(ngDevMode ? { debugName: "centered" } : /* istanbul ignore next */ {}), alias: 'ngsRippleCentered' });
    radius = input(0, { ...(ngDevMode ? { debugName: "radius" } : /* istanbul ignore next */ {}), alias: 'ngsRippleRadius', transform: numberAttribute });
    animation = input(undefined, { ...(ngDevMode ? { debugName: "animation" } : /* istanbul ignore next */ {}), alias: 'ngsRippleAnimation' });
    disabled = model(false, { ...(ngDevMode ? { debugName: "disabled" } : /* istanbul ignore next */ {}), alias: 'ngsRippleDisabled' });
    trigger = model(undefined, { ...(ngDevMode ? { debugName: "trigger" } : /* istanbul ignore next */ {}), alias: 'ngsRippleTrigger' });
    _rippleRenderer;
    _isInitialized = false;
    constructor() {
        this._rippleRenderer = new RippleRenderer(this, this._ngZone, this._elementRef, this._platform);
        effect(() => {
            if (this.disabled()) {
                this.fadeOutAllNonPersistent();
            }
            this._setupTriggerEventsIfEnabled();
        });
        effect(() => {
            this.trigger();
            this._setupTriggerEventsIfEnabled();
        });
    }
    ngOnInit() {
        this._isInitialized = true;
        this._setupTriggerEventsIfEnabled();
    }
    ngOnDestroy() {
        this._rippleRenderer._removeTriggerEvents();
    }
    /** Fades out all currently showing ripple elements. */
    fadeOutAll() {
        this._rippleRenderer.fadeOutAll();
    }
    /** Fades out all currently showing non-persistent ripple elements. */
    fadeOutAllNonPersistent() {
        this._rippleRenderer.fadeOutAllNonPersistent();
    }
    get rippleConfig() {
        return {
            centered: this.centered(),
            radius: this.radius(),
            color: this.color(),
            animation: {
                ...this._globalOptions.animation,
                ...this.animation(),
            },
            terminateOnPointerUp: this._globalOptions.terminateOnPointerUp,
        };
    }
    get rippleDisabled() {
        return this.disabled() || !!this._globalOptions.disabled;
    }
    _setupTriggerEventsIfEnabled() {
        if (!this.disabled() && this._isInitialized) {
            this._rippleRenderer.setupTriggerEvents(this.trigger() || this._elementRef.nativeElement);
        }
    }
    /** Launches a manual ripple at the specified coordinates or just by the ripple config. */
    launch(configOrX, y = 0, config) {
        if (typeof configOrX === 'number') {
            return this._rippleRenderer.fadeInRipple(configOrX, y, { ...this.rippleConfig, ...config });
        }
        else {
            return this._rippleRenderer.fadeInRipple(0, 0, { ...this.rippleConfig, ...configOrX });
        }
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: Ripple, deps: [], target: i0.ɵɵFactoryTarget.Directive });
    static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: Ripple, isStandalone: true, selector: "[ngsRipple]", inputs: { color: { classPropertyName: "color", publicName: "ngsRippleColor", isSignal: true, isRequired: false, transformFunction: null }, unbounded: { classPropertyName: "unbounded", publicName: "ngsRippleUnbounded", isSignal: true, isRequired: false, transformFunction: null }, centered: { classPropertyName: "centered", publicName: "ngsRippleCentered", isSignal: true, isRequired: false, transformFunction: null }, radius: { classPropertyName: "radius", publicName: "ngsRippleRadius", isSignal: true, isRequired: false, transformFunction: null }, animation: { classPropertyName: "animation", publicName: "ngsRippleAnimation", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "ngsRippleDisabled", isSignal: true, isRequired: false, transformFunction: null }, trigger: { classPropertyName: "trigger", publicName: "ngsRippleTrigger", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { centered: "ngsRippleCenteredChange", disabled: "ngsRippleDisabledChange", trigger: "ngsRippleTriggerChange" }, host: { properties: { "class.ngs-ripple-unbounded": "unbounded()" }, classAttribute: "ngs-ripple" }, exportAs: ["ngsRipple"], ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: Ripple, decorators: [{
            type: Directive,
            args: [{
                    selector: '[ngsRipple]',
                    standalone: true,
                    exportAs: 'ngsRipple',
                    host: {
                        'class': 'ngs-ripple',
                        '[class.ngs-ripple-unbounded]': 'unbounded()',
                    },
                }]
        }], ctorParameters: () => [], propDecorators: { color: [{ type: i0.Input, args: [{ isSignal: true, alias: "ngsRippleColor", required: false }] }], unbounded: [{ type: i0.Input, args: [{ isSignal: true, alias: "ngsRippleUnbounded", required: false }] }], centered: [{ type: i0.Input, args: [{ isSignal: true, alias: "ngsRippleCentered", required: false }] }, { type: i0.Output, args: ["ngsRippleCenteredChange"] }], radius: [{ type: i0.Input, args: [{ isSignal: true, alias: "ngsRippleRadius", required: false }] }], animation: [{ type: i0.Input, args: [{ isSignal: true, alias: "ngsRippleAnimation", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "ngsRippleDisabled", required: false }] }, { type: i0.Output, args: ["ngsRippleDisabledChange"] }], trigger: [{ type: i0.Input, args: [{ isSignal: true, alias: "ngsRippleTrigger", required: false }] }, { type: i0.Output, args: ["ngsRippleTriggerChange"] }] } });

function injectElement() {
    return inject(ElementRef).nativeElement;
}
function isElement(node) {
    return !!node && 'nodeType' in node && node.nodeType === Node.ELEMENT_NODE;
}
function getActualTarget(event) {
    return (event.target ?? event.currentTarget);
}

class TextareaAutoSize {
    _textarea = injectElement();
    _ngZone = inject(NgZone);
    _platform = inject(Platform);
    minRows = input(1, { ...(ngDevMode ? { debugName: "minRows" } : /* istanbul ignore next */ {}), transform: numberAttribute });
    maxRows = input(Number.MAX_SAFE_INTEGER, { ...(ngDevMode ? { debugName: "maxRows" } : /* istanbul ignore next */ {}), transform: numberAttribute });
    _resizeObserver;
    ngAfterViewInit() {
        if (this._platform.isBrowser) {
            this.resize();
            this._ngZone.runOutsideAngular(() => {
                this._resizeObserver = new ResizeObserver(() => this.resize());
                this._resizeObserver.observe(this._textarea);
            });
        }
    }
    ngOnDestroy() {
        this._resizeObserver?.disconnect();
    }
    resize() {
        this._textarea.style.height = 'auto';
        const style = window.getComputedStyle(this._textarea);
        let lineHeight = parseFloat(style.lineHeight);
        if (isNaN(lineHeight)) {
            lineHeight = parseFloat(style.fontSize) * 1.2;
        }
        const paddingTop = parseFloat(style.paddingTop) || 0;
        const paddingBottom = parseFloat(style.paddingBottom) || 0;
        const borderTop = parseFloat(style.borderTopWidth) || 0;
        const borderBottom = parseFloat(style.borderBottomWidth) || 0;
        const minHeight = this.minRows() * lineHeight + paddingTop + paddingBottom + borderTop + borderBottom;
        const maxHeight = this.maxRows() * lineHeight + paddingTop + paddingBottom + borderTop + borderBottom;
        this._textarea.style.height = 'auto';
        const currentScrollHeight = this._textarea.scrollHeight;
        let height = Math.max(minHeight, currentScrollHeight);
        height = Math.min(maxHeight, height);
        this._textarea.style.height = `${height}px`;
        if (currentScrollHeight > maxHeight) {
            this._textarea.style.overflowY = 'auto';
        }
        else {
            this._textarea.style.overflowY = 'hidden';
        }
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: TextareaAutoSize, deps: [], target: i0.ɵɵFactoryTarget.Directive });
    static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.4", type: TextareaAutoSize, isStandalone: true, selector: "textarea[ngsTextareaAutoSize]", inputs: { minRows: { classPropertyName: "minRows", publicName: "minRows", isSignal: true, isRequired: false, transformFunction: null }, maxRows: { classPropertyName: "maxRows", publicName: "maxRows", isSignal: true, isRequired: false, transformFunction: null } }, host: { attributes: { "rows": "1" }, listeners: { "input": "resize()" }, styleAttribute: "display: block; overflow: hidden; resize: none; box-sizing: border-box;" }, exportAs: ["ngsTextareaAutoSize"], ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: TextareaAutoSize, decorators: [{
            type: Directive,
            args: [{
                    selector: 'textarea[ngsTextareaAutoSize]',
                    exportAs: 'ngsTextareaAutoSize',
                    host: {
                        'rows': '1',
                        '(input)': 'resize()',
                        'style': 'display: block; overflow: hidden; resize: none; box-sizing: border-box;',
                    },
                }]
        }], propDecorators: { minRows: [{ type: i0.Input, args: [{ isSignal: true, alias: "minRows", required: false }] }], maxRows: [{ type: i0.Input, args: [{ isSignal: true, alias: "maxRows", required: false }] }] } });

class InitialsPipe {
    transform(value) {
        if (!value) {
            return '';
        }
        const initials = [...value.toString().matchAll(/(\p{L}{1})\p{L}+/gu)];
        const result = ((initials.shift()?.[1] || '') + (initials.pop()?.[1] || '')).toUpperCase();
        return result ? result : value[0];
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: InitialsPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
    static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "21.2.4", ngImport: i0, type: InitialsPipe, isStandalone: true, name: "initials" });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: InitialsPipe, decorators: [{
            type: Pipe,
            args: [{
                    name: 'initials',
                    standalone: true
                }]
        }] });

class FormatFileSizePipe {
    transform(bytes, decimalPoint = 2) {
        if (bytes == 0) {
            return '0 Bytes';
        }
        const k = 1000;
        const dm = decimalPoint || 2;
        const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
        const index = Math.floor(Math.log(bytes) / Math.log(k));
        return parseFloat((bytes / Math.pow(k, index)).toFixed(dm)) + ' ' + sizes[index];
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: FormatFileSizePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
    static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "21.2.4", ngImport: i0, type: FormatFileSizePipe, isStandalone: true, name: "formatFileSize" });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: FormatFileSizePipe, decorators: [{
            type: Pipe,
            args: [{
                    name: 'formatFileSize',
                    standalone: true
                }]
        }] });

class OrderByPipe {
    transform(value, property, direction = 'asc') {
        if (!Array.isArray(value)) {
            throw new Error('Order By value should be an array');
        }
        const sorted = value.sort((a, b) => {
            if (a[property] < b[property]) {
                return -1;
            }
            else if (a[property] > b[property]) {
                return 1;
            }
            else {
                return 0;
            }
        });
        if (direction === 'asc') {
            return sorted;
        }
        else if (direction === 'desc') {
            return sorted.reverse();
        }
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: OrderByPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
    static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "21.2.4", ngImport: i0, type: OrderByPipe, isStandalone: true, name: "orderBy" });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: OrderByPipe, decorators: [{
            type: Pipe,
            args: [{
                    name: 'orderBy',
                    standalone: true
                }]
        }] });

class SafeHtmlPipe {
    _domSanitizer = inject(DomSanitizer);
    transform(value) {
        return this._domSanitizer.bypassSecurityTrustHtml(value);
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: SafeHtmlPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
    static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "21.2.4", ngImport: i0, type: SafeHtmlPipe, isStandalone: true, name: "safeHtml" });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: SafeHtmlPipe, decorators: [{
            type: Pipe,
            args: [{
                    name: 'safeHtml',
                    standalone: true
                }]
        }] });

class SafeResourceUrlPipe {
    _domSanitizer = inject(DomSanitizer);
    transform(value) {
        return this._domSanitizer.bypassSecurityTrustResourceUrl(value);
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: SafeResourceUrlPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
    static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "21.2.4", ngImport: i0, type: SafeResourceUrlPipe, isStandalone: true, name: "safeResourceUrl" });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: SafeResourceUrlPipe, decorators: [{
            type: Pipe,
            args: [{
                    name: 'safeResourceUrl',
                    standalone: true
                }]
        }] });

class FilterByPropertyPipe {
    getNestedValue(obj, path) {
        return path.split('.').reduce((acc, part) => acc && acc[part], obj);
    }
    transform(items, propPath, value, strict = false) {
        if (!items) {
            return [];
        }
        if (value === undefined || typeof value === 'undefined') {
            return items;
        }
        if (!strict && (value === null || value === '')) {
            return items;
        }
        return items.filter(item => {
            const propertyValue = this.getNestedValue(item, propPath);
            return propertyValue === value;
        });
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: FilterByPropertyPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
    static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "21.2.4", ngImport: i0, type: FilterByPropertyPipe, isStandalone: true, name: "filterByProperty" });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: FilterByPropertyPipe, decorators: [{
            type: Pipe,
            args: [{
                    name: 'filterByProperty',
                }]
        }] });

class SearchByPropertyPipe {
    getNestedValue(obj, path) {
        return path.split('.').reduce((acc, part) => acc && acc[part], obj);
    }
    transform(items, propPath, searchValue) {
        if (!items) {
            return [];
        }
        if (!searchValue) {
            return items;
        }
        const lowercasedSearchValue = searchValue.toLowerCase();
        return items.filter(item => {
            const propertyValue = this.getNestedValue(item, propPath);
            if (typeof propertyValue === 'string') {
                return propertyValue.toLowerCase().includes(lowercasedSearchValue);
            }
            return false;
        });
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: SearchByPropertyPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
    static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "21.2.4", ngImport: i0, type: SearchByPropertyPipe, isStandalone: true, name: "searchByProperty" });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: SearchByPropertyPipe, decorators: [{
            type: Pipe,
            args: [{
                    name: 'searchByProperty',
                }]
        }] });

const ENVIRONMENT = new InjectionToken('ENVIRONMENT');
class EnvironmentService {
    _environment = inject(ENVIRONMENT, {
        optional: true
    }) || {};
    getValue(key, defaultValue) {
        return this._environment[key] || defaultValue;
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: EnvironmentService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
    static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: EnvironmentService, providedIn: 'root' });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: EnvironmentService, decorators: [{
            type: Injectable,
            args: [{
                    providedIn: 'root'
                }]
        }] });

class AnalyticsService {
    _platformId = inject(PLATFORM_ID);
    _router = inject(Router);
    _document = inject(DOCUMENT);
    _environmentService = inject(EnvironmentService);
    trackPageViews() {
        const googleAnalyticsId = this._environmentService.getValue('googleAnalyticsId');
        if (isDevMode() || !googleAnalyticsId) {
            return;
        }
        try {
            const url = 'https://www.googletagmanager.com/gtag/js?id=';
            const gTagScript = this._document.createElement('script');
            gTagScript.async = true;
            gTagScript.src = `${url}${googleAnalyticsId}`;
            this._document.head.appendChild(gTagScript);
            const dataLayerScript = this._document.createElement('script');
            dataLayerScript.innerHTML = `
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
        gtag('js', new Date());
        gtag('config', '${googleAnalyticsId}');`;
            this._document.head.appendChild(dataLayerScript);
            if (isPlatformServer(this._platformId)) {
                return;
            }
            this._router.events.pipe(filter((event) => event instanceof NavigationEnd)).subscribe((event) => {
                gtag('event', 'page_view', {
                    page_title: this._document.head.title,
                    page_path: event.urlAfterRedirects,
                    page_location: this._document.location.href
                });
            });
        }
        catch (e) {
        }
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: AnalyticsService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
    static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: AnalyticsService, providedIn: 'root' });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: AnalyticsService, decorators: [{
            type: Injectable,
            args: [{
                    providedIn: 'root'
                }]
        }] });

class InactivityTrackerService {
    _destroyRef = inject(DestroyRef);
    _document = inject(DOCUMENT);
    _interval = 10000 * 60; // 5 minutes
    _timeout;
    _interactionEvents$ = merge(fromEvent(this._document, 'click'), fromEvent(this._document, 'keydown'), fromEvent(this._document, 'mousemove'), fromEvent(this._document, 'scroll')).pipe(debounceTime(250));
    _noInteraction = new EventEmitter();
    setupInactivityTimer(interval) {
        if (interval) {
            this._interval = interval;
        }
        this._setupTimer();
        this._interactionEvents$.pipe(takeUntilDestroyed(this._destroyRef)).subscribe(() => {
            this._setupTimer();
        });
        return this._noInteraction.pipe(takeUntilDestroyed(this._destroyRef));
    }
    reset() {
        this._setupTimer();
    }
    _setupTimer() {
        clearTimeout(this._timeout);
        this._timeout = setTimeout(() => {
            this._noInteraction.emit();
        }, this._interval);
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: InactivityTrackerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
    static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: InactivityTrackerService, providedIn: 'root' });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: InactivityTrackerService, decorators: [{
            type: Injectable,
            args: [{
                    providedIn: 'root'
                }]
        }] });

const initialGlobalState = {
    screenLoading: true,
    sidebarHidden: false,
    pageTitle: ''
};
const GlobalStore = signalStore({ providedIn: 'root' }, withState(initialGlobalState), withMethods((store) => ({
    setScreenLoading(isLoading) {
        patchState(store, {
            screenLoading: isLoading
        });
    },
    setPageTitle(pageTitle) {
        patchState(store, {
            pageTitle
        });
    }
})));

class PageTitleStrategyService extends TitleStrategy {
    _title = inject(Title);
    _globalStore = inject(GlobalStore);
    _environmentService = inject(EnvironmentService);
    updateTitle(routerState) {
        const title = this.cleanTitle(this.buildTitle(routerState));
        const pageTitle = this.cleanTitle(this._globalStore.pageTitle())
            || this.cleanTitle(this._environmentService.getValue('pageTitle'));
        const currentTitle = this.cleanTitle(this._title.getTitle());
        const nextTitle = title && pageTitle ? `${title} | ${pageTitle}` : title || pageTitle || currentTitle;
        if (nextTitle) {
            this._title.setTitle(nextTitle);
        }
    }
    cleanTitle(title) {
        if (!title) {
            return null;
        }
        const clean = title
            .split('/')
            .map((part) => part.trim())
            .filter((part) => part && part.toLowerCase() !== 'undefined')
            .join(' - ')
            .trim();
        return clean || null;
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: PageTitleStrategyService, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
    static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: PageTitleStrategyService, providedIn: 'root' });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: PageTitleStrategyService, decorators: [{
            type: Injectable,
            args: [{
                    providedIn: 'root'
                }]
        }] });

class ScreenLoaderService {
    _globalStore = inject(GlobalStore);
    show() {
        this._globalStore.setScreenLoading(true);
    }
    hide() {
        this._globalStore.setScreenLoading(false);
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: ScreenLoaderService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
    static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: ScreenLoaderService, providedIn: 'root' });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: ScreenLoaderService, decorators: [{
            type: Injectable,
            args: [{
                    providedIn: 'root'
                }]
        }] });

class SeoService {
    _router = inject(Router);
    _destroyRef = inject(DestroyRef);
    _document = inject(DOCUMENT);
    _platformId = inject(PLATFORM_ID);
    _linkCanonical;
    _title = inject(Title);
    _meta = inject(Meta);
    _globalStore = inject(GlobalStore);
    get meta() {
        return this._meta;
    }
    updateDescription(content) {
        if (!content) {
            return;
        }
        this.meta.updateTag({
            name: 'description',
            content
        });
        this.meta.updateTag({
            name: 'og:description',
            content
        });
    }
    updateOgUrl(content) {
        if (!content) {
            return;
        }
        this.meta.updateTag({
            name: 'og:url',
            content
        });
    }
    updateOgImage(content) {
        if (!content) {
            return;
        }
        this.meta.updateTag({
            name: 'og:image',
            content
        });
    }
    trackCanonicalChanges(siteUrl) {
        this._createCanonicalTag(siteUrl);
        if (isPlatformServer(this._platformId)) {
            return;
        }
        this._router.events
            .pipe(filter((event) => event instanceof NavigationEnd), takeUntilDestroyed(this._destroyRef))
            .subscribe(() => {
            const href = this.getCanonicalUrl(siteUrl);
            this._linkCanonical?.setAttribute('href', href);
            this.updateOgUrl(href);
        });
    }
    updateTitle(title) {
        this._title.setTitle(`${title} | ${this._globalStore.pageTitle()}`);
        this.meta.updateTag({
            name: 'og:title',
            content: title
        });
    }
    getCanonicalUrl(siteUrl) {
        if (this._document.URL.startsWith('http')) {
            return this._document.URL;
        }
        return siteUrl + this._document.URL;
    }
    _createCanonicalTag(siteUrl) {
        this._linkCanonical = this._document.querySelector('link[rel="canonical"]');
        if (!this._linkCanonical) {
            this._linkCanonical = this._document.createElement('link');
            this._linkCanonical.setAttribute('rel', 'canonical');
            this._document.head.appendChild(this._linkCanonical);
        }
        this._linkCanonical.setAttribute('href', this.getCanonicalUrl(siteUrl));
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: SeoService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
    static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: SeoService, providedIn: 'root' });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: SeoService, decorators: [{
            type: Injectable,
            args: [{
                    providedIn: 'root'
                }]
        }] });

const NGS_THEME_OPTIONS = new InjectionToken('NGS_THEME_OPTIONS', {
    factory: () => ({
        theme: 'default',
        colorScheme: 'auto',
        radius: 'medium',
        persist: true,
        storageKey: 'ngs-admin',
    }),
});
function provideNgsTheme(options = {}) {
    return {
        provide: NGS_THEME_OPTIONS,
        useValue: {
            theme: 'default',
            colorScheme: 'auto',
            radius: 'medium',
            persist: true,
            storageKey: 'ngs-admin',
            ...options,
        },
    };
}

const LIGHT_TEXT = '#ffffff';
const DARK_TEXT = '#0f172a';
const NGS_GENERATED_THEME_PROPERTY_NAMES = [
    '--ngs-color-primary-seed',
    '--ngs-color-primary',
    '--ngs-color-on-primary',
    '--ngs-color-primary-container',
    '--ngs-color-on-primary-container',
    '--ngs-color-secondary',
    '--ngs-color-on-secondary',
    '--ngs-color-secondary-container',
    '--ngs-color-on-secondary-container',
    '--ngs-color-tertiary',
    '--ngs-color-on-tertiary',
    '--ngs-color-tertiary-container',
    '--ngs-color-on-tertiary-container',
    '--ngs-color-info',
    '--ngs-color-on-info',
    '--ngs-color-info-container',
    '--ngs-color-on-info-container',
    '--ngs-color-danger',
    '--ngs-color-on-danger',
    '--ngs-color-danger-container',
    '--ngs-color-on-danger-container',
    '--ngs-color-danger-container-lowest',
    '--ngs-color-danger-container-low',
    '--ngs-color-danger-container-high',
    '--ngs-color-danger-container-highest',
    '--ngs-color-success',
    '--ngs-color-on-success',
    '--ngs-color-success-container',
    '--ngs-color-on-success-container',
    '--ngs-color-warning',
    '--ngs-color-on-warning',
    '--ngs-color-warning-container',
    '--ngs-color-on-warning-container',
    '--ngs-color-orange-container',
    '--ngs-color-on-orange-container',
    '--ngs-color-green-500',
    '--ngs-color-background',
    '--ngs-color-on-background',
    '--ngs-color-surface',
    '--ngs-color-surface-bright',
    '--ngs-color-on-surface',
    '--ngs-color-on-surface-variant',
    '--ngs-color-neutral-50',
    '--ngs-color-neutral-100',
    '--ngs-color-neutral-200',
    '--ngs-color-neutral-300',
    '--ngs-color-neutral-400',
    '--ngs-color-neutral-500',
    '--ngs-color-neutral-600',
    '--ngs-color-neutral-650',
    '--ngs-color-neutral-700',
    '--ngs-color-neutral-800',
    '--ngs-color-neutral-900',
    '--ngs-color-neutral-950',
    '--ngs-color-surface-container-lowest',
    '--ngs-color-surface-container-low',
    '--ngs-color-surface-container',
    '--ngs-color-surface-container-high',
    '--ngs-color-surface-container-highest',
    '--ngs-color-outline',
    '--ngs-color-outline-variant',
    '--ngs-color-border',
    '--ngs-color-faint',
    '--ngs-color-subtle',
    '--ngs-color-muted',
    '--ngs-color-emphasis',
    '--ngs-color-strong',
    '--ngs-state-hover-bg',
    '--ngs-state-active-bg',
    '--ngs-state-selected-bg',
    '--ngs-state-selected-color',
    '--ngs-state-focus-ring',
    '--ngs-state-disabled-bg',
    '--ngs-state-disabled-color',
    '--ngs-state-disabled-border',
    '--ngs-color-primary-100',
    '--ngs-color-primary-200',
    '--ngs-color-primary-300',
    '--ngs-color-primary-400',
    '--ngs-color-primary-500',
    '--ngs-color-primary-600',
    '--ngs-color-secondary-100',
    '--ngs-color-secondary-200',
    '--ngs-color-secondary-300',
    '--ngs-color-secondary-400',
    '--ngs-color-secondary-fixed',
    '--ngs-color-on-secondary-fixed',
    '--ngs-color-tertiary-100',
    '--ngs-color-tertiary-200',
    '--ngs-color-tertiary-300',
    '--ngs-color-tertiary-700',
    '--ngs-color-tertiary-800',
    '--ngs-button-tonal-bg',
    '--ngs-button-tonal-color',
    '--ngs-button-outlined-border',
    '--ngs-field-border-color',
    '--ngs-field-border-focus-color',
    '--ngs-field-filled-bg',
    '--ngs-dropdown-item-selected-bg',
    '--ngs-dropdown-item-selected-color',
    '--ngs-nav-item-active-color',
    '--ngs-nav-item-active-bg',
    '--ngs-nav-item-active-icon-color',
];
function generateNgsThemeProperties(primaryColor, colorScheme = 'light') {
    const seed = parseColor(primaryColor);
    if (!seed) {
        return {
            '--ngs-color-primary-seed': primaryColor,
            '--ngs-color-primary': primaryColor,
        };
    }
    return colorScheme === 'dark'
        ? generateDarkThemeProperties(seed)
        : generateLightThemeProperties(seed);
}
function generateNgsThemeCssText(primaryColor, colorScheme = 'light') {
    return Object.entries(generateNgsThemeProperties(primaryColor, colorScheme))
        .map(([name, value]) => `${name}: ${value};`)
        .join('\n');
}
function generateLightThemeProperties(seed) {
    const source = rgbToHsl(seed);
    const primary = toHex(seed);
    const primaryContainer = colorFromTone(source, 93, 0.62);
    const secondary = colorFromTone(source, 36, 0.36, -8);
    const secondaryContainer = colorFromTone(source, 92, 0.28, -8);
    const tertiary = colorFromTone(source, 42, 0.72, 48);
    const tertiaryContainer = colorFromTone(source, 92, 0.42, 48);
    const info = colorFromTone(source, 48, 0.9, 8);
    const infoContainer = colorFromTone(source, 92, 0.38, 8);
    const status = makeStatusColors('light');
    const neutral = makeNeutralScale(source, 'light');
    const border = colorFromTone(source, 90, 0.08);
    const outline = colorFromTone(source, 56, 0.12);
    const outlineVariant = colorFromTone(source, 86, 0.08);
    return withSharedGeneratedProperties({
        '--ngs-color-primary': primary,
        '--ngs-color-primary-seed': primary,
        '--ngs-color-on-primary': readableOn(primary),
        '--ngs-color-primary-container': primaryContainer,
        '--ngs-color-on-primary-container': readableOn(primaryContainer, DARK_TEXT, primary),
        '--ngs-color-secondary': secondary,
        '--ngs-color-on-secondary': readableOn(secondary),
        '--ngs-color-secondary-container': secondaryContainer,
        '--ngs-color-on-secondary-container': readableOn(secondaryContainer, DARK_TEXT, secondary),
        '--ngs-color-tertiary': tertiary,
        '--ngs-color-on-tertiary': readableOn(tertiary),
        '--ngs-color-tertiary-container': tertiaryContainer,
        '--ngs-color-on-tertiary-container': readableOn(tertiaryContainer, DARK_TEXT, tertiary),
        '--ngs-color-info': info,
        '--ngs-color-on-info': readableOn(info),
        '--ngs-color-info-container': infoContainer,
        '--ngs-color-on-info-container': readableOn(infoContainer, DARK_TEXT, info),
        ...status,
        '--ngs-color-background': neutral[0],
        '--ngs-color-on-background': neutral[11],
        '--ngs-color-surface': neutral[1],
        '--ngs-color-surface-bright': '#ffffff',
        '--ngs-color-on-surface': neutral[11],
        '--ngs-color-on-surface-variant': neutral[6],
        '--ngs-color-neutral-50': neutral[0],
        '--ngs-color-neutral-100': neutral[1],
        '--ngs-color-neutral-200': neutral[2],
        '--ngs-color-neutral-300': neutral[3],
        '--ngs-color-neutral-400': neutral[4],
        '--ngs-color-neutral-500': neutral[5],
        '--ngs-color-neutral-600': neutral[6],
        '--ngs-color-neutral-650': neutral[7],
        '--ngs-color-neutral-700': neutral[8],
        '--ngs-color-neutral-800': neutral[9],
        '--ngs-color-neutral-900': neutral[10],
        '--ngs-color-neutral-950': neutral[11],
        '--ngs-color-surface-container-lowest': '#ffffff',
        '--ngs-color-surface-container-low': neutral[0],
        '--ngs-color-surface-container': neutral[1],
        '--ngs-color-surface-container-high': neutral[2],
        '--ngs-color-surface-container-highest': neutral[3],
        '--ngs-color-outline': outline,
        '--ngs-color-outline-variant': outlineVariant,
        '--ngs-color-border': border,
        '--ngs-color-faint': neutral[1],
        '--ngs-color-subtle': neutral[2],
        '--ngs-color-muted': neutral[3],
        '--ngs-color-emphasis': neutral[5],
        '--ngs-color-strong': neutral[6],
        '--ngs-state-selected-color': primary,
        '--ngs-button-tonal-bg': secondaryContainer,
        '--ngs-button-tonal-color': readableOn(secondaryContainer, DARK_TEXT, secondary),
        '--ngs-button-outlined-border': outlineVariant,
        '--ngs-field-border-color': outlineVariant,
        '--ngs-field-border-focus-color': primary,
        '--ngs-field-filled-bg': neutral[1],
        '--ngs-dropdown-item-selected-bg': primaryContainer,
        '--ngs-dropdown-item-selected-color': readableOn(primaryContainer, DARK_TEXT, primary),
        '--ngs-nav-item-active-color': primary,
        '--ngs-nav-item-active-bg': primaryContainer,
        '--ngs-nav-item-active-icon-color': primary,
    });
}
function generateDarkThemeProperties(seed) {
    const source = rgbToHsl(seed);
    const primary = colorFromTone(source, 76, 0.82);
    const primaryContainer = colorFromTone(source, 28, 0.78);
    const secondary = colorFromTone(source, 78, 0.36, -8);
    const secondaryContainer = colorFromTone(source, 28, 0.3, -8);
    const tertiary = colorFromTone(source, 78, 0.62, 48);
    const tertiaryContainer = colorFromTone(source, 30, 0.52, 48);
    const info = colorFromTone(source, 76, 0.84, 8);
    const infoContainer = colorFromTone(source, 30, 0.62, 8);
    const status = makeStatusColors('dark');
    const neutral = makeNeutralScale(source, 'dark');
    const border = colorFromTone(source, 22, 0.08);
    const outline = colorFromTone(source, 66, 0.12);
    const outlineVariant = colorFromTone(source, 28, 0.08);
    return withSharedGeneratedProperties({
        '--ngs-color-primary': primary,
        '--ngs-color-primary-seed': toHex(seed),
        '--ngs-color-on-primary': readableOn(primary),
        '--ngs-color-primary-container': primaryContainer,
        '--ngs-color-on-primary-container': readableOn(primaryContainer),
        '--ngs-color-secondary': secondary,
        '--ngs-color-on-secondary': readableOn(secondary),
        '--ngs-color-secondary-container': secondaryContainer,
        '--ngs-color-on-secondary-container': readableOn(secondaryContainer),
        '--ngs-color-tertiary': tertiary,
        '--ngs-color-on-tertiary': readableOn(tertiary),
        '--ngs-color-tertiary-container': tertiaryContainer,
        '--ngs-color-on-tertiary-container': readableOn(tertiaryContainer),
        '--ngs-color-info': info,
        '--ngs-color-on-info': readableOn(info),
        '--ngs-color-info-container': infoContainer,
        '--ngs-color-on-info-container': readableOn(infoContainer),
        ...status,
        '--ngs-color-background': neutral[0],
        '--ngs-color-on-background': neutral[11],
        '--ngs-color-surface': neutral[1],
        '--ngs-color-surface-bright': neutral[2],
        '--ngs-color-on-surface': neutral[11],
        '--ngs-color-on-surface-variant': neutral[8],
        '--ngs-color-neutral-50': neutral[0],
        '--ngs-color-neutral-100': neutral[1],
        '--ngs-color-neutral-200': neutral[2],
        '--ngs-color-neutral-300': neutral[3],
        '--ngs-color-neutral-400': neutral[4],
        '--ngs-color-neutral-500': neutral[5],
        '--ngs-color-neutral-600': neutral[6],
        '--ngs-color-neutral-650': neutral[7],
        '--ngs-color-neutral-700': neutral[8],
        '--ngs-color-neutral-800': neutral[9],
        '--ngs-color-neutral-900': neutral[10],
        '--ngs-color-neutral-950': neutral[11],
        '--ngs-color-surface-container-lowest': neutral[0],
        '--ngs-color-surface-container-low': neutral[1],
        '--ngs-color-surface-container': neutral[2],
        '--ngs-color-surface-container-high': neutral[3],
        '--ngs-color-surface-container-highest': neutral[4],
        '--ngs-color-outline': outline,
        '--ngs-color-outline-variant': outlineVariant,
        '--ngs-color-border': border,
        '--ngs-color-faint': neutral[1],
        '--ngs-color-subtle': neutral[2],
        '--ngs-color-muted': neutral[3],
        '--ngs-color-emphasis': neutral[7],
        '--ngs-color-strong': neutral[9],
        '--ngs-state-selected-color': primary,
        '--ngs-button-tonal-bg': secondaryContainer,
        '--ngs-button-tonal-color': readableOn(secondaryContainer),
        '--ngs-button-outlined-border': outlineVariant,
        '--ngs-field-border-color': outlineVariant,
        '--ngs-field-border-focus-color': primary,
        '--ngs-field-filled-bg': neutral[2],
        '--ngs-dropdown-item-selected-bg': primaryContainer,
        '--ngs-dropdown-item-selected-color': readableOn(primaryContainer),
        '--ngs-nav-item-active-color': primary,
        '--ngs-nav-item-active-bg': primaryContainer,
        '--ngs-nav-item-active-icon-color': primary,
    });
}
function withSharedGeneratedProperties(properties) {
    return {
        ...properties,
        '--ngs-state-hover-bg': 'color-mix(in srgb, var(--ngs-color-on-surface), transparent 94%)',
        '--ngs-state-active-bg': 'color-mix(in srgb, var(--ngs-color-on-surface), transparent 90%)',
        '--ngs-state-selected-bg': 'color-mix(in srgb, var(--ngs-color-primary), transparent 88%)',
        '--ngs-state-focus-ring': 'var(--ngs-field-border-focus-color)',
        '--ngs-state-disabled-bg': 'color-mix(in srgb, var(--ngs-color-on-surface), transparent 95%)',
        '--ngs-state-disabled-color': 'color-mix(in srgb, var(--ngs-color-on-surface), transparent 62%)',
        '--ngs-state-disabled-border': 'color-mix(in srgb, var(--ngs-color-on-surface), transparent 90%)',
        '--ngs-color-primary-100': 'color-mix(in srgb, var(--ngs-color-primary), transparent 90%)',
        '--ngs-color-primary-200': 'color-mix(in srgb, var(--ngs-color-primary), transparent 80%)',
        '--ngs-color-primary-300': 'color-mix(in srgb, var(--ngs-color-primary), transparent 70%)',
        '--ngs-color-primary-400': 'color-mix(in srgb, var(--ngs-color-primary), transparent 60%)',
        '--ngs-color-primary-500': 'color-mix(in srgb, var(--ngs-color-primary), transparent 50%)',
        '--ngs-color-primary-600': 'color-mix(in srgb, var(--ngs-color-primary), transparent 40%)',
        '--ngs-color-secondary-100': 'color-mix(in srgb, var(--ngs-color-secondary), transparent 90%)',
        '--ngs-color-secondary-200': 'color-mix(in srgb, var(--ngs-color-secondary), transparent 80%)',
        '--ngs-color-secondary-300': 'color-mix(in srgb, var(--ngs-color-secondary), transparent 70%)',
        '--ngs-color-secondary-400': 'color-mix(in srgb, var(--ngs-color-secondary), transparent 60%)',
        '--ngs-color-secondary-fixed': 'var(--ngs-color-secondary-container)',
        '--ngs-color-on-secondary-fixed': 'var(--ngs-color-on-secondary-container)',
        '--ngs-color-tertiary-100': 'color-mix(in srgb, var(--ngs-color-tertiary), transparent 90%)',
        '--ngs-color-tertiary-200': 'color-mix(in srgb, var(--ngs-color-tertiary), transparent 80%)',
        '--ngs-color-tertiary-300': 'color-mix(in srgb, var(--ngs-color-tertiary), transparent 70%)',
        '--ngs-color-tertiary-700': 'color-mix(in srgb, var(--ngs-color-tertiary), #000000 35%)',
        '--ngs-color-tertiary-800': 'color-mix(in srgb, var(--ngs-color-tertiary), #000000 50%)',
    };
}
function makeNeutralScale(source, colorScheme) {
    const saturation = Math.min(source.s * 0.12, 8);
    const lightness = colorScheme === 'dark'
        ? [5, 8, 12, 17, 24, 39, 55, 64, 73, 84, 92, 97]
        : [98, 96, 91, 84, 72, 56, 43, 36, 28, 19, 11, 4];
    return lightness.map(l => hslToHex({ h: source.h, s: saturation, l }));
}
function makeStatusColors(colorScheme) {
    if (colorScheme === 'dark') {
        return {
            '--ngs-color-danger': '#f87171',
            '--ngs-color-on-danger': '#450a0a',
            '--ngs-color-danger-container': '#7f1d1d',
            '--ngs-color-on-danger-container': '#fef2f2',
            '--ngs-color-danger-container-lowest': '#1f0707',
            '--ngs-color-danger-container-low': '#2f0b0b',
            '--ngs-color-danger-container-high': '#5f1717',
            '--ngs-color-danger-container-highest': '#7f1d1d',
            '--ngs-color-success': '#4ade80',
            '--ngs-color-on-success': '#052e16',
            '--ngs-color-success-container': '#166534',
            '--ngs-color-on-success-container': '#dcfce7',
            '--ngs-color-warning': '#fbbf24',
            '--ngs-color-on-warning': '#451a03',
            '--ngs-color-warning-container': '#78350f',
            '--ngs-color-on-warning-container': '#fef3c7',
            '--ngs-color-orange-container': '#78350f',
            '--ngs-color-on-orange-container': '#fef3c7',
            '--ngs-color-green-500': '#4ade80',
        };
    }
    return {
        '--ngs-color-danger': '#dc2626',
        '--ngs-color-on-danger': '#ffffff',
        '--ngs-color-danger-container': '#fee2e2',
        '--ngs-color-on-danger-container': '#7f1d1d',
        '--ngs-color-danger-container-lowest': '#fffafa',
        '--ngs-color-danger-container-low': '#fef2f2',
        '--ngs-color-danger-container-high': '#fecaca',
        '--ngs-color-danger-container-highest': '#fca5a5',
        '--ngs-color-success': '#16a34a',
        '--ngs-color-on-success': '#ffffff',
        '--ngs-color-success-container': '#dcfce7',
        '--ngs-color-on-success-container': '#14532d',
        '--ngs-color-warning': '#d97706',
        '--ngs-color-on-warning': '#ffffff',
        '--ngs-color-warning-container': '#fef3c7',
        '--ngs-color-on-warning-container': '#78350f',
        '--ngs-color-orange-container': '#fef3c7',
        '--ngs-color-on-orange-container': '#78350f',
        '--ngs-color-green-500': '#16a34a',
    };
}
function colorFromTone(source, lightness, saturationMultiplier = 1, hueShift = 0) {
    return hslToHex({
        h: normalizeHue(source.h + hueShift),
        s: clamp(source.s * saturationMultiplier, 8, 92),
        l: lightness,
    });
}
function readableOn(color, dark = DARK_TEXT, light = LIGHT_TEXT) {
    const bg = parseColor(color);
    if (!bg) {
        return light;
    }
    const darkContrast = contrastRatio(bg, parseColor(dark) ?? { r: 15, g: 23, b: 42 });
    const lightContrast = contrastRatio(bg, parseColor(light) ?? { r: 255, g: 255, b: 255 });
    return darkContrast >= lightContrast ? dark : light;
}
function parseColor(color) {
    const value = color.trim().toLowerCase();
    if (value.startsWith('#')) {
        return parseHexColor(value);
    }
    if (value.startsWith('rgb(') || value.startsWith('rgba(')) {
        return parseRgbColor(value);
    }
    if (value.startsWith('hsl(') || value.startsWith('hsla(')) {
        return parseHslColor(value);
    }
    return null;
}
function parseHexColor(value) {
    const hex = value.slice(1);
    if (!/^[\da-f]+$/i.test(hex)) {
        return null;
    }
    if (hex.length === 3 || hex.length === 4) {
        return {
            r: parseInt(hex[0] + hex[0], 16),
            g: parseInt(hex[1] + hex[1], 16),
            b: parseInt(hex[2] + hex[2], 16),
        };
    }
    if (hex.length === 6 || hex.length === 8) {
        return {
            r: parseInt(hex.slice(0, 2), 16),
            g: parseInt(hex.slice(2, 4), 16),
            b: parseInt(hex.slice(4, 6), 16),
        };
    }
    return null;
}
function parseRgbColor(value) {
    const matches = value.match(/rgba?\(([^)]+)\)/);
    if (!matches) {
        return null;
    }
    const channels = matches[1]
        .replace(/\s*\/\s*[\d.]+%?\s*$/, '')
        .split(/[\s,]+/)
        .filter(Boolean)
        .slice(0, 3)
        .map(channel => parseFloat(channel));
    if (channels.length < 3 || channels.some(Number.isNaN)) {
        return null;
    }
    return {
        r: clamp(Math.round(channels[0]), 0, 255),
        g: clamp(Math.round(channels[1]), 0, 255),
        b: clamp(Math.round(channels[2]), 0, 255),
    };
}
function parseHslColor(value) {
    const matches = value.match(/hsla?\(([^)]+)\)/);
    if (!matches) {
        return null;
    }
    const channels = matches[1]
        .replace(/\s*\/\s*[\d.]+%?\s*$/, '')
        .split(/[\s,]+/)
        .filter(Boolean)
        .slice(0, 3);
    if (channels.length < 3) {
        return null;
    }
    const h = parseFloat(channels[0]);
    const s = parseFloat(channels[1]);
    const l = parseFloat(channels[2]);
    if ([h, s, l].some(Number.isNaN)) {
        return null;
    }
    return hslToRgb({ h, s, l });
}
function rgbToHsl({ r, g, b }) {
    const red = r / 255;
    const green = g / 255;
    const blue = b / 255;
    const max = Math.max(red, green, blue);
    const min = Math.min(red, green, blue);
    const delta = max - min;
    const lightness = (max + min) / 2;
    if (delta === 0) {
        return { h: 0, s: 0, l: lightness * 100 };
    }
    const saturation = delta / (1 - Math.abs(2 * lightness - 1));
    let hue = 0;
    if (max === red) {
        hue = ((green - blue) / delta) % 6;
    }
    else if (max === green) {
        hue = (blue - red) / delta + 2;
    }
    else {
        hue = (red - green) / delta + 4;
    }
    return {
        h: normalizeHue(hue * 60),
        s: saturation * 100,
        l: lightness * 100,
    };
}
function hslToRgb({ h, s, l }) {
    const saturation = clamp(s, 0, 100) / 100;
    const lightness = clamp(l, 0, 100) / 100;
    const chroma = (1 - Math.abs(2 * lightness - 1)) * saturation;
    const hue = normalizeHue(h) / 60;
    const x = chroma * (1 - Math.abs((hue % 2) - 1));
    const match = lightness - chroma / 2;
    let red = 0;
    let green = 0;
    let blue = 0;
    if (hue >= 0 && hue < 1) {
        red = chroma;
        green = x;
    }
    else if (hue >= 1 && hue < 2) {
        red = x;
        green = chroma;
    }
    else if (hue >= 2 && hue < 3) {
        green = chroma;
        blue = x;
    }
    else if (hue >= 3 && hue < 4) {
        green = x;
        blue = chroma;
    }
    else if (hue >= 4 && hue < 5) {
        red = x;
        blue = chroma;
    }
    else if (hue >= 5 && hue < 6) {
        red = chroma;
        blue = x;
    }
    return {
        r: Math.round((red + match) * 255),
        g: Math.round((green + match) * 255),
        b: Math.round((blue + match) * 255),
    };
}
function hslToHex(hsl) {
    return toHex(hslToRgb(hsl));
}
function toHex({ r, g, b }) {
    return `#${toHexChannel(r)}${toHexChannel(g)}${toHexChannel(b)}`;
}
function toHexChannel(value) {
    return clamp(Math.round(value), 0, 255).toString(16).padStart(2, '0');
}
function contrastRatio(first, second) {
    const firstLuminance = relativeLuminance(first);
    const secondLuminance = relativeLuminance(second);
    const lighter = Math.max(firstLuminance, secondLuminance);
    const darker = Math.min(firstLuminance, secondLuminance);
    return (lighter + 0.05) / (darker + 0.05);
}
function relativeLuminance({ r, g, b }) {
    return [r, g, b]
        .map(channel => {
        const value = channel / 255;
        return value <= 0.03928 ? value / 12.92 : Math.pow((value + 0.055) / 1.055, 2.4);
    })
        .reduce((total, value, index) => total + value * [0.2126, 0.7152, 0.0722][index], 0);
}
function normalizeHue(hue) {
    return ((hue % 360) + 360) % 360;
}
function clamp(value, min, max) {
    return Math.min(max, Math.max(min, value));
}

class ThemeManagerService {
    _document = inject(DOCUMENT);
    _window = this._document.defaultView;
    _options = inject(NGS_THEME_OPTIONS);
    _theme = signal('default', ...(ngDevMode ? [{ debugName: "_theme" }] : /* istanbul ignore next */ []));
    _colorScheme = signal('light', ...(ngDevMode ? [{ debugName: "_colorScheme" }] : /* istanbul ignore next */ []));
    _radius = signal('medium', ...(ngDevMode ? [{ debugName: "_radius" }] : /* istanbul ignore next */ []));
    _primaryColor = signal(null, ...(ngDevMode ? [{ debugName: "_primaryColor" }] : /* istanbul ignore next */ []));
    theme = this._theme.asReadonly();
    colorScheme = this._colorScheme.asReadonly();
    radius = this._radius.asReadonly();
    primaryColor = this._primaryColor.asReadonly();
    constructor() {
        this.applyTheme(this._getInitialState());
        effect(() => {
            this._syncDocumentAttributes();
        });
        afterNextRender(() => {
            if (this._window !== null && this._window.matchMedia) {
                this._window
                    .matchMedia('(prefers-color-scheme: dark)')
                    .addEventListener('change', () => {
                    const storedColorScheme = this._getStoredColorScheme();
                    if (storedColorScheme !== 'light' && storedColorScheme !== 'dark') {
                        this.setColorScheme(this.getPreferredColorScheme(), false);
                    }
                });
            }
        });
    }
    getColorScheme() {
        return this._colorScheme();
    }
    toggleColorScheme() {
        if (this._getStoredColorScheme() === 'dark') {
            this.changeColorScheme('light');
        }
        else {
            this.changeColorScheme('dark');
        }
    }
    changeColorScheme(colorScheme) {
        this.setColorScheme(colorScheme);
    }
    setTheme(theme, persist = true) {
        this._theme.set(theme);
        this._persist({ theme }, persist);
    }
    setRadius(radius, persist = true) {
        this._radius.set(radius);
        this._persist({ radius }, persist);
    }
    setPrimaryColor(primaryColor, persist = true) {
        this._primaryColor.set(primaryColor);
        this._persist({ primaryColor: primaryColor || undefined }, persist);
    }
    applyTheme(options, persist = false) {
        if (options.theme) {
            this._theme.set(options.theme);
        }
        if (options.radius) {
            this._radius.set(options.radius);
        }
        if (options.primaryColor !== undefined) {
            this._primaryColor.set(options.primaryColor || null);
        }
        this.setColorScheme(options.colorScheme || 'auto', persist);
        this._persist(options, persist);
    }
    _getStoredColorScheme() {
        return this._getStoredState().colorScheme;
    }
    ;
    _getStoredState() {
        if (!this._options.persist || typeof localStorage === 'undefined') {
            return {};
        }
        const rawValue = localStorage.getItem(this._storageKey);
        if (!rawValue) {
            return {};
        }
        try {
            return JSON.parse(rawValue);
        }
        catch {
            return {};
        }
    }
    ;
    _persist(state, persist = true) {
        if (!persist || !this._options.persist || typeof localStorage === 'undefined') {
            return;
        }
        const meta = this._getStoredState();
        localStorage.setItem(this._storageKey, JSON.stringify({ ...meta, ...state }));
    }
    ;
    _setStoredColorScheme(colorScheme) {
        this._persist({ colorScheme: colorScheme });
    }
    ;
    getPreferredColorScheme() {
        const storedTheme = this._getStoredColorScheme();
        if (storedTheme === 'light' || storedTheme === 'dark') {
            return storedTheme;
        }
        if (this._window !== null && this._window.matchMedia) {
            return this._window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
        }
        return 'light';
    }
    ;
    setColorScheme(colorScheme, persist = true) {
        if (colorScheme === 'auto') {
            this._colorScheme.set(this.getPreferredColorScheme());
        }
        else {
            this._colorScheme.set(colorScheme);
        }
        if (persist) {
            this._setStoredColorScheme(colorScheme);
        }
    }
    ;
    _getInitialState() {
        return {
            ...this._options,
            ...this._getStoredState(),
        };
    }
    _syncDocumentAttributes() {
        const root = this._document.documentElement;
        const primaryColor = this._primaryColor();
        if (!root) {
            return;
        }
        root.classList?.toggle('dark', this._colorScheme() === 'dark');
        root.setAttribute('data-ngs-theme', this._theme());
        root.setAttribute('data-ngs-color-scheme', this._colorScheme());
        root.setAttribute('data-ngs-radius', this._radius());
        if (!root.style) {
            return;
        }
        if (primaryColor) {
            for (const name of NGS_GENERATED_THEME_PROPERTY_NAMES) {
                root.style.removeProperty(name);
            }
            root.style.setProperty('--ngs-color-primary-seed', primaryColor);
        }
        else {
            for (const name of NGS_GENERATED_THEME_PROPERTY_NAMES) {
                root.style.removeProperty(name);
            }
        }
    }
    get _storageKey() {
        return this._options.storageKey || 'ngs-admin';
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: ThemeManagerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
    static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: ThemeManagerService, providedIn: 'root' });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: ThemeManagerService, decorators: [{
            type: Injectable,
            args: [{
                    providedIn: 'root'
                }]
        }], ctorParameters: () => [] });

class ResizeObserverService {
    ngZone;
    constructor(ngZone) {
        this.ngZone = ngZone;
    }
    observe(element) {
        return new Observable(observer => {
            const resizeObserver = new ResizeObserver(entries => {
                this.ngZone.run(() => {
                    observer.next(entries);
                });
            });
            resizeObserver.observe(element);
            return () => {
                resizeObserver.disconnect();
            };
        });
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: ResizeObserverService, deps: [{ token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Injectable });
    static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: ResizeObserverService, providedIn: 'root' });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: ResizeObserverService, decorators: [{
            type: Injectable,
            args: [{
                    providedIn: 'root',
                }]
        }], ctorParameters: () => [{ type: i0.NgZone }] });

class MutationObserverService {
    ngZone;
    constructor(ngZone) {
        this.ngZone = ngZone;
    }
    observe(element, options) {
        return new Observable(observer => {
            const mutationObserver = new MutationObserver(mutations => {
                this.ngZone.run(() => {
                    observer.next(mutations);
                });
            });
            mutationObserver.observe(element, options);
            return () => {
                mutationObserver.disconnect();
            };
        });
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: MutationObserverService, deps: [{ token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Injectable });
    static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: MutationObserverService, providedIn: 'root' });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: MutationObserverService, decorators: [{
            type: Injectable,
            args: [{
                    providedIn: 'root',
                }]
        }], ctorParameters: () => [{ type: i0.NgZone }] });

/** Provider for managing the error state of a form control. */
class ErrorStateMatcher {
    /**
     * Whether a control should be in an error state.
     * @param control The form control to check.
     * @param form The parent form that contains the control.
     * @returns Whether the control should be in an error state.
     */
    isErrorState(control, form) {
        return !!(control && control.invalid && (control.touched || (form && form.submitted)));
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: ErrorStateMatcher, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
    static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: ErrorStateMatcher, providedIn: 'root' });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: ErrorStateMatcher, decorators: [{
            type: Injectable,
            args: [{ providedIn: 'root' }]
        }] });
/** Error state matcher that displays an error when a control is dirty and invalid. */
class ShowOnDirtyErrorStateMatcher {
    isErrorState(control, form) {
        return !!(control && control.invalid && (control.dirty || (form && form.submitted)));
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: ShowOnDirtyErrorStateMatcher, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
    static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: ShowOnDirtyErrorStateMatcher });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: ShowOnDirtyErrorStateMatcher, decorators: [{
            type: Injectable
        }] });

function px(value) {
    return `${value}px`;
}
function arrayShallowEquals(a, b) {
    return a.length === b.length && a.every((item, index) => item === b[index]);
}

function zonefreeScheduler() {
    const zone = inject(NgZone);
    return {
        now: () => Date.now(),
        schedule: (work, delay, state) => {
            return zone.runOutsideAngular(() => {
                const id = setTimeout(() => work(state), delay);
                return new Subscription(() => clearTimeout(id));
            });
        },
    };
}

function typedFromEvent(target, event, options) {
    return fromEvent(target, event, options);
}

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

export { AUTOFOCUSABLE, AnalyticsService, AutoFocusDirective, DebounceTimeDirective, ENVIRONMENT, EnvironmentService, ErrorStateMatcher, FilterByPropertyPipe, FocusElementDirective, FormatFileSizePipe, GlobalStore, InactivityTrackerService, InitialsPipe, MutationObserverService, NGS_GENERATED_THEME_PROPERTY_NAMES, NGS_THEME_OPTIONS, OrderByPipe, PageTitleStrategyService, RIPPLE_GLOBAL_OPTIONS, ResizeObserverService, Ripple, RippleRef, RippleRenderer, RippleState, SafeHtmlPipe, SafeResourceUrlPipe, ScreenLoaderService, SearchByPropertyPipe, SeoService, ShowOnDirtyErrorStateMatcher, SoundEffectDirective, TextareaAutoSize, ThemeManagerService, arrayShallowEquals, defaultRippleAnimationConfig, generateNgsThemeCssText, generateNgsThemeProperties, getActualTarget, injectElement, isElement, provideNgsTheme, px, typedFromEvent, zonefreeScheduler };
//# sourceMappingURL=ngstarter-ui-components-core.mjs.map
