import { FocusMonitor } from '@angular/cdk/a11y';
import { NgClass } from '@angular/common';
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, inject, Input, numberAttribute, ViewChild, ViewEncapsulation } from '@angular/core';
import { KBQ_FORM_FIELD_REF, kbqInjectNativeElement, PopUpTriggers } from '@koobiq/components/core';
import { KbqIconButton, KbqIconModule } from '@koobiq/components/icon';
import { KbqToolTipModule, KbqTooltipTrigger } from '@koobiq/components/tooltip';
import * as i0 from "@angular/core";
// @TODO Temporary solution to resolve circular dependency (#DS-3893)
const isInputPassword = (control) => {
    return 'elementType' in control;
};
const getKbqPasswordToggleMissingControlError = () => {
    return Error('kbq-password-toggle should use with kbqInputPassword');
};
/** Component which changes password visibility. */
export class KbqPasswordToggle extends KbqTooltipTrigger {
    get content() {
        return this.control.elementType === 'password' ? this.kbqTooltipHidden : this._content;
    }
    set content(content) {
        this._content = content;
        this.updateData();
    }
    /** Form field password control. */
    get control() {
        const control = this.formField?.control;
        if (!control || !isInputPassword(control)) {
            throw getKbqPasswordToggleMissingControlError();
        }
        return control;
    }
    /**
     * @docs-private
     */
    get hidden() {
        return this.control.elementType === 'password';
    }
    /**
     * @docs-private
     */
    get iconClass() {
        return this.hidden ? 'kbq-eye_16' : 'kbq-eye-slash_16';
    }
    /**
     * @docs-private
     */
    get visibility() {
        return this.control.disabled || this.control.empty ? 'hidden' : 'visible';
    }
    constructor() {
        super();
        this.nativeElement = kbqInjectNativeElement();
        this.focusMonitor = inject(FocusMonitor);
        this.changeDetectorRef = inject(ChangeDetectorRef);
        // @TODO fix types (#DS-2915)
        this.formField = inject(KBQ_FORM_FIELD_REF, { optional: true });
        this.tabindex = 0;
        this.hasError = false;
        this.updateState = () => {
            this.hasError = !!this.formField?.control?.errorState;
            this.changeDetectorRef.markForCheck();
        };
        this.trigger = `${PopUpTriggers.Hover}`;
    }
    /**
     * @docs-private
     */
    ngAfterContentInit() {
        this.formField?.control?.stateChanges.subscribe(this.updateState);
        this.updateState();
    }
    /**
     * @docs-private
     */
    ngAfterViewInit() {
        this.focusMonitor.monitor(this.nativeElement, true);
    }
    /**
     * @docs-private
     */
    ngOnDestroy() {
        this.focusMonitor.stopMonitoring(this.nativeElement);
    }
    /**
     * @docs-private
     */
    toggle(event) {
        this.hide();
        const input = this.control;
        input.toggleType();
        this.updateData();
        event.preventDefault();
    }
    /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: KbqPasswordToggle, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
    /** @nocollapse */ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "16.1.0", version: "18.2.14", type: KbqPasswordToggle, isStandalone: true, selector: "kbq-password-toggle", inputs: { tabindex: ["tabindex", "tabindex", numberAttribute], content: ["kbqTooltipNotHidden", "content"], kbqTooltipHidden: "kbqTooltipHidden" }, host: { listeners: { "click": "toggle($event)", "keydown.ENTER": "toggle($event)", "keydown.SPACE": "toggle($event)" }, properties: { "class.kbq-error": "hasError", "class.kbq-eye_16": "hidden", "class.kbq-eye-slash_16": "!hidden", "style.visibility": "visibility", "class.cdk-visually-hidden": "visibility === \"hidden\"", "attr.aria-hidden": "visibility === \"hidden\"", "attr.tabindex": "tabindex" }, classAttribute: "kbq-password-toggle kbq kbq-icon-button kbq-contrast-fade" }, viewQueries: [{ propertyName: "icon", first: true, predicate: KbqIconButton, descendants: true }], exportAs: ["kbqPasswordToggle"], usesInheritance: true, ngImport: i0, template: `
        <ng-content />
    `, isInline: true, styles: [".kbq-password-toggle{display:flex;align-items:center;justify-content:center;width:26px;height:var(--kbq-size-xxl);border-radius:var(--kbq-size-xxs);outline:none}\n", ".kbq-icon-button{padding:var(--kbq-icon-button-size-normal-vertical-padding) var(--kbq-icon-button-size-normal-horizontal-padding)}.kbq-icon-button:not(.kbq-disabled){cursor:pointer}.kbq-icon-button.kbq-disabled:not(button){pointer-events:none}.kbq-icon-button.kbq-icon-button_small{padding:var(--kbq-icon-button-size-small-vertical-padding) var(--kbq-icon-button-size-small-horizontal-padding)}.kbq-icon-button:focus{outline:none}.kbq-icon-button.kbq-theme{color:var(--kbq-icon-button-theme-default)}.kbq-icon-button.kbq-theme:hover{color:var(--kbq-icon-button-theme-states-hover)}.kbq-icon-button.kbq-theme:active,.kbq-icon-button.kbq-theme.kbq-active{color:var(--kbq-icon-button-theme-states-active)}.kbq-icon-button.kbq-theme.kbq-disabled{color:var(--kbq-icon-button-theme-states-disabled)}.kbq-icon-button.kbq-contrast{color:var(--kbq-icon-button-contrast-default)}.kbq-icon-button.kbq-contrast:hover{color:var(--kbq-icon-button-contrast-states-hover)}.kbq-icon-button.kbq-contrast:active,.kbq-icon-button.kbq-contrast.kbq-active{color:var(--kbq-icon-button-contrast-states-active)}.kbq-icon-button.kbq-contrast.kbq-disabled{color:var(--kbq-icon-button-contrast-states-disabled)}.kbq-icon-button.kbq-contrast-fade{color:var(--kbq-icon-button-fade-contrast-default)}.kbq-icon-button.kbq-contrast-fade:hover{color:var(--kbq-icon-button-fade-contrast-states-hover)}.kbq-icon-button.kbq-contrast-fade:active,.kbq-icon-button.kbq-contrast-fade.kbq-active{color:var(--kbq-icon-button-fade-contrast-states-active)}.kbq-icon-button.kbq-contrast-fade.kbq-disabled{color:var(--kbq-icon-button-fade-contrast-states-disabled)}.kbq-icon-button.kbq-error{color:var(--kbq-icon-button-error-default)}.kbq-icon-button.kbq-error:hover{color:var(--kbq-icon-button-error-states-hover)}.kbq-icon-button.kbq-error:active,.kbq-icon-button.kbq-error.kbq-active{color:var(--kbq-icon-button-error-states-active)}.kbq-icon-button.kbq-error.kbq-disabled{color:var(--kbq-icon-button-error-states-disabled)}.kbq-icon-button.kbq-success{color:var(--kbq-icon-button-success-default)}.kbq-icon-button.kbq-success:hover{color:var(--kbq-icon-button-success-states-hover)}.kbq-icon-button.kbq-success:active,.kbq-icon-button.kbq-success.kbq-active{color:var(--kbq-icon-button-success-states-active)}.kbq-icon-button.kbq-success.kbq-disabled{color:var(--kbq-icon-button-success-states-disabled)}.kbq-icon-button.kbq-warning{color:var(--kbq-icon-button-warning-default)}.kbq-icon-button.kbq-warning:hover{color:var(--kbq-icon-button-warning-states-hover)}.kbq-icon-button.kbq-warning:active,.kbq-icon-button.kbq-warning.kbq-active{color:var(--kbq-icon-button-warning-states-active)}.kbq-icon-button.kbq-warning.kbq-disabled{color:var(--kbq-icon-button-warning-states-disabled)}.kbq-icon-button.cdk-keyboard-focused{box-shadow:inset 0 0 0 1px var(--kbq-states-line-focus-theme),0 0 0 1px var(--kbq-states-line-focus-theme)}.kbq-icon-button.cdk-keyboard-focused.kbq-error{box-shadow:inset 0 0 0 1px var(--kbq-states-line-focus-error),0 0 0 1px var(--kbq-states-line-focus-error)}\n", ".kbq-icon-button{--kbq-icon-button-size-horizontal-padding: var(--kbq-size-s);--kbq-icon-button-size-left-icon-padding: var(--kbq-size-xs);--kbq-icon-button-size-normal-horizontal-padding: 0;--kbq-icon-button-size-normal-vertical-padding: 0;--kbq-icon-button-size-small-horizontal-padding: var(--kbq-size-xxs);--kbq-icon-button-size-small-vertical-padding: var(--kbq-size-xxs);--kbq-icon-button-theme-default: var(--kbq-icon-theme);--kbq-icon-button-theme-states-hover: var(--kbq-states-icon-theme-hover);--kbq-icon-button-theme-states-active: var(--kbq-states-icon-theme-active);--kbq-icon-button-theme-states-disabled: var(--kbq-states-icon-disabled);--kbq-icon-button-contrast-default: var(--kbq-icon-contrast);--kbq-icon-button-contrast-states-hover: var(--kbq-states-icon-contrast-hover);--kbq-icon-button-contrast-states-active: var(--kbq-states-icon-contrast-active);--kbq-icon-button-contrast-states-disabled: var(--kbq-states-icon-disabled);--kbq-icon-button-fade-contrast-default: var(--kbq-icon-contrast-fade);--kbq-icon-button-fade-contrast-states-hover: var(--kbq-states-icon-contrast-fade-hover);--kbq-icon-button-fade-contrast-states-active: var(--kbq-states-icon-contrast-fade-active);--kbq-icon-button-fade-contrast-states-disabled: var(--kbq-states-icon-disabled);--kbq-icon-button-error-default: var(--kbq-icon-error);--kbq-icon-button-error-states-hover: var(--kbq-states-icon-error-hover);--kbq-icon-button-error-states-active: var(--kbq-states-icon-error-active);--kbq-icon-button-error-states-disabled: var(--kbq-states-icon-disabled);--kbq-icon-button-success-default: var(--kbq-icon-success);--kbq-icon-button-success-states-hover: var(--kbq-states-icon-success-hover);--kbq-icon-button-success-states-active: var(--kbq-states-icon-success-active);--kbq-icon-button-success-states-disabled: var(--kbq-states-icon-disabled);--kbq-icon-button-warning-default: var(--kbq-icon-warning);--kbq-icon-button-warning-states-hover: var(--kbq-states-icon-warning-hover);--kbq-icon-button-warning-states-active: var(--kbq-states-icon-warning-active);--kbq-icon-button-warning-states-disabled: var(--kbq-states-icon-disabled)}\n"], dependencies: [{ kind: "ngmodule", type: KbqIconModule }, { kind: "ngmodule", type: KbqToolTipModule }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: KbqPasswordToggle, decorators: [{
            type: Component,
            args: [{ standalone: true, imports: [NgClass, KbqIconModule, KbqToolTipModule], selector: `kbq-password-toggle`, exportAs: 'kbqPasswordToggle', template: `
        <ng-content />
    `, host: {
                        class: 'kbq-password-toggle kbq kbq-icon-button kbq-contrast-fade',
                        '[class.kbq-error]': 'hasError',
                        '[class.kbq-eye_16]': 'hidden',
                        '[class.kbq-eye-slash_16]': '!hidden',
                        // legacy style for backward compatibility
                        '[style.visibility]': 'visibility',
                        '[class.cdk-visually-hidden]': 'visibility === "hidden"',
                        '[attr.aria-hidden]': 'visibility === "hidden"',
                        '[attr.tabindex]': 'tabindex',
                        '(click)': 'toggle($event)',
                        '(keydown.ENTER)': 'toggle($event)',
                        '(keydown.SPACE)': 'toggle($event)'
                    }, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, styles: [".kbq-password-toggle{display:flex;align-items:center;justify-content:center;width:26px;height:var(--kbq-size-xxl);border-radius:var(--kbq-size-xxs);outline:none}\n", ".kbq-icon-button{padding:var(--kbq-icon-button-size-normal-vertical-padding) var(--kbq-icon-button-size-normal-horizontal-padding)}.kbq-icon-button:not(.kbq-disabled){cursor:pointer}.kbq-icon-button.kbq-disabled:not(button){pointer-events:none}.kbq-icon-button.kbq-icon-button_small{padding:var(--kbq-icon-button-size-small-vertical-padding) var(--kbq-icon-button-size-small-horizontal-padding)}.kbq-icon-button:focus{outline:none}.kbq-icon-button.kbq-theme{color:var(--kbq-icon-button-theme-default)}.kbq-icon-button.kbq-theme:hover{color:var(--kbq-icon-button-theme-states-hover)}.kbq-icon-button.kbq-theme:active,.kbq-icon-button.kbq-theme.kbq-active{color:var(--kbq-icon-button-theme-states-active)}.kbq-icon-button.kbq-theme.kbq-disabled{color:var(--kbq-icon-button-theme-states-disabled)}.kbq-icon-button.kbq-contrast{color:var(--kbq-icon-button-contrast-default)}.kbq-icon-button.kbq-contrast:hover{color:var(--kbq-icon-button-contrast-states-hover)}.kbq-icon-button.kbq-contrast:active,.kbq-icon-button.kbq-contrast.kbq-active{color:var(--kbq-icon-button-contrast-states-active)}.kbq-icon-button.kbq-contrast.kbq-disabled{color:var(--kbq-icon-button-contrast-states-disabled)}.kbq-icon-button.kbq-contrast-fade{color:var(--kbq-icon-button-fade-contrast-default)}.kbq-icon-button.kbq-contrast-fade:hover{color:var(--kbq-icon-button-fade-contrast-states-hover)}.kbq-icon-button.kbq-contrast-fade:active,.kbq-icon-button.kbq-contrast-fade.kbq-active{color:var(--kbq-icon-button-fade-contrast-states-active)}.kbq-icon-button.kbq-contrast-fade.kbq-disabled{color:var(--kbq-icon-button-fade-contrast-states-disabled)}.kbq-icon-button.kbq-error{color:var(--kbq-icon-button-error-default)}.kbq-icon-button.kbq-error:hover{color:var(--kbq-icon-button-error-states-hover)}.kbq-icon-button.kbq-error:active,.kbq-icon-button.kbq-error.kbq-active{color:var(--kbq-icon-button-error-states-active)}.kbq-icon-button.kbq-error.kbq-disabled{color:var(--kbq-icon-button-error-states-disabled)}.kbq-icon-button.kbq-success{color:var(--kbq-icon-button-success-default)}.kbq-icon-button.kbq-success:hover{color:var(--kbq-icon-button-success-states-hover)}.kbq-icon-button.kbq-success:active,.kbq-icon-button.kbq-success.kbq-active{color:var(--kbq-icon-button-success-states-active)}.kbq-icon-button.kbq-success.kbq-disabled{color:var(--kbq-icon-button-success-states-disabled)}.kbq-icon-button.kbq-warning{color:var(--kbq-icon-button-warning-default)}.kbq-icon-button.kbq-warning:hover{color:var(--kbq-icon-button-warning-states-hover)}.kbq-icon-button.kbq-warning:active,.kbq-icon-button.kbq-warning.kbq-active{color:var(--kbq-icon-button-warning-states-active)}.kbq-icon-button.kbq-warning.kbq-disabled{color:var(--kbq-icon-button-warning-states-disabled)}.kbq-icon-button.cdk-keyboard-focused{box-shadow:inset 0 0 0 1px var(--kbq-states-line-focus-theme),0 0 0 1px var(--kbq-states-line-focus-theme)}.kbq-icon-button.cdk-keyboard-focused.kbq-error{box-shadow:inset 0 0 0 1px var(--kbq-states-line-focus-error),0 0 0 1px var(--kbq-states-line-focus-error)}\n", ".kbq-icon-button{--kbq-icon-button-size-horizontal-padding: var(--kbq-size-s);--kbq-icon-button-size-left-icon-padding: var(--kbq-size-xs);--kbq-icon-button-size-normal-horizontal-padding: 0;--kbq-icon-button-size-normal-vertical-padding: 0;--kbq-icon-button-size-small-horizontal-padding: var(--kbq-size-xxs);--kbq-icon-button-size-small-vertical-padding: var(--kbq-size-xxs);--kbq-icon-button-theme-default: var(--kbq-icon-theme);--kbq-icon-button-theme-states-hover: var(--kbq-states-icon-theme-hover);--kbq-icon-button-theme-states-active: var(--kbq-states-icon-theme-active);--kbq-icon-button-theme-states-disabled: var(--kbq-states-icon-disabled);--kbq-icon-button-contrast-default: var(--kbq-icon-contrast);--kbq-icon-button-contrast-states-hover: var(--kbq-states-icon-contrast-hover);--kbq-icon-button-contrast-states-active: var(--kbq-states-icon-contrast-active);--kbq-icon-button-contrast-states-disabled: var(--kbq-states-icon-disabled);--kbq-icon-button-fade-contrast-default: var(--kbq-icon-contrast-fade);--kbq-icon-button-fade-contrast-states-hover: var(--kbq-states-icon-contrast-fade-hover);--kbq-icon-button-fade-contrast-states-active: var(--kbq-states-icon-contrast-fade-active);--kbq-icon-button-fade-contrast-states-disabled: var(--kbq-states-icon-disabled);--kbq-icon-button-error-default: var(--kbq-icon-error);--kbq-icon-button-error-states-hover: var(--kbq-states-icon-error-hover);--kbq-icon-button-error-states-active: var(--kbq-states-icon-error-active);--kbq-icon-button-error-states-disabled: var(--kbq-states-icon-disabled);--kbq-icon-button-success-default: var(--kbq-icon-success);--kbq-icon-button-success-states-hover: var(--kbq-states-icon-success-hover);--kbq-icon-button-success-states-active: var(--kbq-states-icon-success-active);--kbq-icon-button-success-states-disabled: var(--kbq-states-icon-disabled);--kbq-icon-button-warning-default: var(--kbq-icon-warning);--kbq-icon-button-warning-states-hover: var(--kbq-states-icon-warning-hover);--kbq-icon-button-warning-states-active: var(--kbq-states-icon-warning-active);--kbq-icon-button-warning-states-disabled: var(--kbq-states-icon-disabled)}\n"] }]
        }], ctorParameters: () => [], propDecorators: { tabindex: [{
                type: Input,
                args: [{ transform: numberAttribute }]
            }], icon: [{
                type: ViewChild,
                args: [KbqIconButton]
            }], content: [{
                type: Input,
                args: ['kbqTooltipNotHidden']
            }], kbqTooltipHidden: [{
                type: Input
            }] } });
//# sourceMappingURL=data:application/json;base64, 