import * as i0 from '@angular/core';
import { contentChild, input, output, signal, Component, NgModule } from '@angular/core';
import { NgControl } from '@angular/forms';
import { elementShow, elementHide } from '@siemens/element-icons';
import { addIcons, SiIconComponent } from '@siemens/element-ng/icon';
import { t, SiTranslatePipe } from '@siemens/element-translate-ng/translate';

/**
 * Copyright (c) Siemens 2016 - 2026
 * SPDX-License-Identifier: MIT
 */
class SiPasswordToggleComponent {
    ngControl = contentChild(NgControl, ...(ngDevMode ? [{ debugName: "ngControl" }] : []));
    /**
     * Whether to show the visibility toggle icon.
     *
     * @defaultValue true
     */
    showVisibilityIcon = input(true, ...(ngDevMode ? [{ debugName: "showVisibilityIcon" }] : []));
    /**
     * Emits the `type` attribute for the `<input>` ('password' | 'text')
     * whenever the password visibility is getting toggled.
     */
    typeChange = output();
    /**
     * The aria-label (translatable) for the password show icon.
     *
     * @defaultValue
     * ```
     * t(() => $localize`:@@SI_PASSWORD_TOGGLE.SHOW:show password`)
     * ```
     */
    showLabel = input(t(() => $localize `:@@SI_PASSWORD_TOGGLE.SHOW:show password`), ...(ngDevMode ? [{ debugName: "showLabel" }] : []));
    /**
     * The aria-label (translatable) for the password hide icon.
     *
     * @defaultValue
     * ```
     * t(() => $localize`:@@SI_PASSWORD_TOGGLE.HIDE:hide password`)
     * ```
     */
    hideLabel = input(t(() => $localize `:@@SI_PASSWORD_TOGGLE.HIDE:hide password`), ...(ngDevMode ? [{ debugName: "hideLabel" }] : []));
    showPassword = signal(false, ...(ngDevMode ? [{ debugName: "showPassword" }] : []));
    icons = addIcons({ elementHide, elementShow });
    /** The `type` attribute for the `<input>` ('password' | 'text'). */
    get inputType() {
        return this.showPassword() ? 'text' : 'password';
    }
    toggle() {
        this.showPassword.set(!this.showPassword());
        this.typeChange.emit(this.inputType);
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.8", ngImport: i0, type: SiPasswordToggleComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.0.8", type: SiPasswordToggleComponent, isStandalone: true, selector: "si-password-toggle", inputs: { showVisibilityIcon: { classPropertyName: "showVisibilityIcon", publicName: "showVisibilityIcon", isSignal: true, isRequired: false, transformFunction: null }, showLabel: { classPropertyName: "showLabel", publicName: "showLabel", isSignal: true, isRequired: false, transformFunction: null }, hideLabel: { classPropertyName: "hideLabel", publicName: "hideLabel", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { typeChange: "typeChange" }, host: { properties: { "class.show-visibility-icon": "showVisibilityIcon()" }, classAttribute: "form-control-wrapper" }, queries: [{ propertyName: "ngControl", first: true, predicate: NgControl, descendants: true, isSignal: true }], ngImport: i0, template: "<ng-content />\n@if (showVisibilityIcon()) {\n  <button\n    type=\"button\"\n    class=\"btn btn-tertiary btn-icon btn-sm text-body password-visibility-icon\"\n    [attr.aria-label]=\"(showPassword() ? hideLabel() : showLabel()) | translate\"\n    (click)=\"toggle()\"\n  >\n    <si-icon [icon]=\"showPassword() ? icons.elementHide : icons.elementShow\" />\n  </button>\n}\n", styles: [":host{display:block;position:relative;inline-size:100%}:host.show-visibility-icon{--si-action-icon-offset: 28px}:host ::ng-deep input::-ms-reveal{display:none}.password-visibility-icon{position:absolute;font-size:1.25rem;inset-inline-end:4px;inset-block-start:4px;z-index:2}\n"], dependencies: [{ kind: "component", type: SiIconComponent, selector: "si-icon", inputs: ["icon"] }, { kind: "pipe", type: SiTranslatePipe, name: "translate" }] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.8", ngImport: i0, type: SiPasswordToggleComponent, decorators: [{
            type: Component,
            args: [{ selector: 'si-password-toggle', imports: [SiIconComponent, SiTranslatePipe], host: {
                        class: 'form-control-wrapper',
                        '[class.show-visibility-icon]': 'showVisibilityIcon()'
                    }, template: "<ng-content />\n@if (showVisibilityIcon()) {\n  <button\n    type=\"button\"\n    class=\"btn btn-tertiary btn-icon btn-sm text-body password-visibility-icon\"\n    [attr.aria-label]=\"(showPassword() ? hideLabel() : showLabel()) | translate\"\n    (click)=\"toggle()\"\n  >\n    <si-icon [icon]=\"showPassword() ? icons.elementHide : icons.elementShow\" />\n  </button>\n}\n", styles: [":host{display:block;position:relative;inline-size:100%}:host.show-visibility-icon{--si-action-icon-offset: 28px}:host ::ng-deep input::-ms-reveal{display:none}.password-visibility-icon{position:absolute;font-size:1.25rem;inset-inline-end:4px;inset-block-start:4px;z-index:2}\n"] }]
        }], propDecorators: { ngControl: [{ type: i0.ContentChild, args: [i0.forwardRef(() => NgControl), { isSignal: true }] }], showVisibilityIcon: [{ type: i0.Input, args: [{ isSignal: true, alias: "showVisibilityIcon", required: false }] }], typeChange: [{ type: i0.Output, args: ["typeChange"] }], showLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "showLabel", required: false }] }], hideLabel: [{ type: i0.Input, args: [{ isSignal: true, alias: "hideLabel", required: false }] }] } });

/**
 * Copyright (c) Siemens 2016 - 2026
 * SPDX-License-Identifier: MIT
 */
class SiPasswordToggleModule {
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.8", ngImport: i0, type: SiPasswordToggleModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
    static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "21.0.8", ngImport: i0, type: SiPasswordToggleModule, imports: [SiPasswordToggleComponent], exports: [SiPasswordToggleComponent] });
    static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "21.0.8", ngImport: i0, type: SiPasswordToggleModule, imports: [SiPasswordToggleComponent] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.8", ngImport: i0, type: SiPasswordToggleModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [SiPasswordToggleComponent],
                    exports: [SiPasswordToggleComponent]
                }]
        }] });

/**
 * Copyright (c) Siemens 2016 - 2026
 * SPDX-License-Identifier: MIT
 */

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

export { SiPasswordToggleComponent, SiPasswordToggleModule };
//# sourceMappingURL=siemens-element-ng-password-toggle.mjs.map
