import * as i0 from '@angular/core';
import { Directive, inject, ElementRef, signal, computed, isSignal } from '@angular/core';
import { FormControl, FormGroup, FormArray } from '@angular/forms';

/** Copies the current theme from the root element.
 *
 * For use with single-component variables from the theme generator
 */
class NxThemeAttributeDirective {
    constructor(host) {
        host.nativeElement.setAttribute('data-theme', document.documentElement.getAttribute('data-theme'));
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.6", ngImport: i0, type: NxThemeAttributeDirective, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive }); }
    static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.1.6", type: NxThemeAttributeDirective, isStandalone: true, selector: "[nxThemeAttribute]", ngImport: i0 }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.6", ngImport: i0, type: NxThemeAttributeDirective, decorators: [{
            type: Directive,
            args: [{ selector: '[nxThemeAttribute]' }]
        }], ctorParameters: () => [{ type: i0.ElementRef }] });

/** Directive to disable autofill by password managers when input is readonly or disabled.
 *
 * [Source for attributes](https://www.stefanjudis.com/snippets/turn-off-password-managers/)
 */
class NxPasswordManagerDisableDirective {
    constructor() {
        this.host = inject(ElementRef);
        this.disabled = signal(false, ...(ngDevMode ? [{ debugName: "disabled" }] : []));
        this.readonly = signal(false, ...(ngDevMode ? [{ debugName: "readonly" }] : []));
        this.inputObserver = new MutationObserver(records => {
            const disabledChange = records.find(r => r.attributeName === 'disabled');
            const readOnlyChange = records.find(r => r.attributeName === 'readonly');
            if (disabledChange) {
                this.disabled.set(disabledChange.target.hasAttribute('disabled'));
            }
            if (readOnlyChange) {
                this.readonly.set(readOnlyChange.target.hasAttribute('readonly'));
            }
        });
        this.disablePwManager = computed(() => this.disabled() || this.readonly(), ...(ngDevMode ? [{ debugName: "disablePwManager" }] : []));
        this.onePassAttr = computed(() => (this.disablePwManager() ? '' : null), ...(ngDevMode ? [{ debugName: "onePassAttr" }] : []));
        this.lastpassAttr = computed(() => this.disablePwManager() ? 'true' : null, ...(ngDevMode ? [{ debugName: "lastpassAttr" }] : []));
        this.dashlaneAttr = computed(() => this.disablePwManager() ? 'other' : null, ...(ngDevMode ? [{ debugName: "dashlaneAttr" }] : []));
        this.bitwardenAttr = computed(() => (this.disablePwManager() ? '' : null), ...(ngDevMode ? [{ debugName: "bitwardenAttr" }] : []));
    }
    ngAfterViewInit() {
        const nativeElement = this.host.nativeElement;
        this.disabled.set(nativeElement.hasAttribute('disabled'));
        this.readonly.set(nativeElement.hasAttribute('readonly'));
        this.inputObserver.observe(nativeElement, { attributeFilter: ['disabled', 'readonly'] });
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.6", ngImport: i0, type: NxPasswordManagerDisableDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
    static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.1.6", type: NxPasswordManagerDisableDirective, isStandalone: true, selector: "input[nxPasswordManagerDisable]", host: { properties: { "attr.data-1p-ignore": "onePassAttr()", "attr.data-lpignore": "lastpassAttr()", "attr.data-form-type": "dashlaneAttr()", "attr.data-bwignore": "bitwardenAttr()" } }, ngImport: i0 }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.6", ngImport: i0, type: NxPasswordManagerDisableDirective, decorators: [{
            type: Directive,
            args: [{
                    selector: 'input[nxPasswordManagerDisable]',
                    host: {
                        '[attr.data-1p-ignore]': 'onePassAttr()',
                        '[attr.data-lpignore]': 'lastpassAttr()',
                        '[attr.data-form-type]': 'dashlaneAttr()',
                        '[attr.data-bwignore]': 'bitwardenAttr()',
                    },
                }]
        }] });

function writeOnlySignal(s) {
    return s;
}
/** Coerce a value to a signal */
function coerceSignal(value) {
    return isSignal(value) ? value : signal(value);
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
var Compass8;
(function (Compass8) {
    Compass8["N"] = "North";
    Compass8["NE"] = "Northeast";
    Compass8["E"] = "East";
    Compass8["SE"] = "Southeast";
    Compass8["S"] = "South";
    Compass8["SW"] = "Southwest";
    Compass8["W"] = "West";
    Compass8["NW"] = "Northwest";
})(Compass8 || (Compass8 = {}));
function compass8ToAngularPosition(direction) {
    switch (direction) {
        case 'N':
            return { x: 'center', y: 'top' };
        case 'NE':
            return { x: 'end', y: 'top' };
        case 'E':
            return { x: 'end', y: 'center' };
        case 'SE':
            return { x: 'end', y: 'bottom' };
        case 'S':
            return { x: 'center', y: 'bottom' };
        case 'SW':
            return { x: 'start', y: 'bottom' };
        case 'W':
            return { x: 'start', y: 'center' };
        case 'NW':
            return { x: 'start', y: 'top' };
    }
}
function cdkOriginPosition(direction) {
    const { x, y } = compass8ToAngularPosition(direction);
    return { originX: x, originY: y };
}
function cdkOverlayPosition(direction) {
    const { x, y } = compass8ToAngularPosition(direction);
    return { overlayX: x, overlayY: y };
}
function connectedPosition(position) {
    const { originPoint, overlayPoint, ...other } = position;
    return {
        ...cdkOriginPosition(originPoint),
        ...cdkOverlayPosition(overlayPoint),
        ...other,
    };
}

function ariaBoolean(state) {
    return state ? 'true' : 'false';
}
/** Compute aria boolean from signals */
function ariaComputed(...signals) {
    return computed(() => ariaBoolean(signals.some(s => s())));
}
/** Check whether a mouse event is inside an element */
function clickedInside({ clientX: eventX, clientY: eventY }, element) {
    const elemRect = element.getBoundingClientRect();
    const withinHorizontal = elemRect.left <= eventX && eventX <= elemRect.right;
    const withinVertical = elemRect.top <= eventY && eventY <= elemRect.bottom;
    return withinHorizontal && withinVertical;
}
/**
 * Scroll an item into view inside in a list container like a dropdown
 *
 * The list container element must be the ancestor the browser uses for calculating coordinates.
 *
 * https://javascript.info/size-and-scroll#offsetparent-offsetleft-top
 *
 * @param item The item element to scroll to
 * @param container The container element of the item
 */
function scrollItemIntoView(item, container) {
    const itemTop = item.offsetTop;
    const itemBottom = itemTop + item.offsetHeight;
    const containerVisibleTop = container.scrollTop;
    const containerVisibleBottom = containerVisibleTop + container.offsetHeight;
    if (itemTop < containerVisibleTop) {
        item.scrollIntoView(true); // alignToTop
    }
    else if (itemBottom > containerVisibleBottom) {
        item.scrollIntoView(false);
    }
}

/** Function to mark all child controls as dirty.
 *
 * Source: https://stackoverflow.com/a/67402215
 */
function markAllAsDirty(controls) {
    const controlsArray = Array.isArray(controls) ? controls : Object.values(controls);
    controlsArray.forEach(control => {
        if (control instanceof FormControl) {
            control.markAsDirty();
        }
        else if (control instanceof FormGroup) {
            markAllAsDirty(control.controls);
        }
        else if (control instanceof FormArray) {
            markAllAsDirty(control.controls);
        }
    });
}

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

export { NxPasswordManagerDisableDirective, NxThemeAttributeDirective, ariaBoolean, ariaComputed, cdkOriginPosition, cdkOverlayPosition, clickedInside, coerceSignal, connectedPosition, markAllAsDirty, scrollItemIntoView, writeOnlySignal };
//# sourceMappingURL=networkoptix-nx-shared.mjs.map
