import * as i0 from '@angular/core';
import { EventEmitter, forwardRef, Component, Input, Output, ViewChild, HostListener, NgModule } from '@angular/core';
import { NG_VALUE_ACCESSOR } from '@angular/forms';

/**
 * @description Componente de chave tipo switch (liga/desliga) que implementa
 * `ControlValueAccessor` para uso em formulários Angular. Suporta rótulos
 * personalizados para os estados verdadeiro e falso, além de modo somente leitura.
 *
 * @example
 * ```html
 * <s-switch formControlName="ativo" trueLabel="Ativo" falseLabel="Inativo" />
 * ```
 *
 * @category Inputs
 */
class SwitchComponent {
    /** @description Impede alterações pelo usuário sem desabilitar o campo. @default false */
    readonly = false;
    /** @description Rótulo exibido quando o valor é `true`. @default 'Ligado' */
    trueLabel = 'Ligado';
    /** @description Rótulo exibido quando o valor é `false`. @default 'Desligado' */
    falseLabel = 'Desligado';
    /** @description `id` do elemento `<input>` interno para associação com `<label>`. */
    inputId;
    /** @description Nome acessível descritivo do switch para tecnologias assistivas (aria-label). */
    label;
    /** @description Atributo `name` do `<input>` interno. */
    inputName;
    /** @description Desabilita o componente, impedindo interação e alterações. @default false */
    disabled = false;
    /** @description Emitido quando o valor do switch muda, com o novo estado booleano. */
    valueChanged = new EventEmitter();
    /** @description Valor atual do switch. @default false */
    value = false;
    /** @description Controla se deve ou não exibir o value do componente. @default true */
    showStatusLabel = true;
    switchRef;
    _onChange;
    _onTouched;
    onFocusIn() {
        const switchElement = this.switchRef.nativeElement;
        switchElement.classList.add('switch--focus');
    }
    onFocusOut() {
        const switchElement = this.switchRef.nativeElement;
        switchElement.classList.remove('switch--focus');
    }
    writeValue(value) {
        if (!this.disabled) {
            this.value = value;
        }
    }
    registerOnChange(onChange) {
        this._onChange = onChange;
    }
    registerOnTouched(onTouched) {
        this._onTouched = onTouched;
    }
    setDisabledState(disabled) {
        this.disabled = disabled;
    }
    toggleCheck() {
        if (this.readonly) {
            return;
        }
        this.value = !this.value;
        this.valueChanged.emit(this.value);
        if (this._onChange) {
            this._onChange(this.value);
        }
        if (this._onTouched) {
            this._onTouched(this.value);
        }
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: SwitchComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.14", type: SwitchComponent, isStandalone: true, selector: "s-switch", inputs: { readonly: "readonly", trueLabel: "trueLabel", falseLabel: "falseLabel", inputId: "inputId", label: "label", inputName: "inputName", disabled: "disabled", value: "value", showStatusLabel: "showStatusLabel" }, outputs: { valueChanged: "valueChanged" }, host: { listeners: { "focusin": "onFocusIn()", "focusout": "onFocusOut()" } }, providers: [
            {
                provide: NG_VALUE_ACCESSOR,
                useExisting: forwardRef(() => SwitchComponent),
                multi: true,
            },
        ], viewQueries: [{ propertyName: "switchRef", first: true, predicate: ["switch"], descendants: true, static: true }], ngImport: i0, template: "<div\n    #switch\n    class=\"inline-flex items-center\"\n    [class.opacity-50]=\"disabled\"\n    [attr.aria-disabled]=\"disabled || null\"\n>\n    <label class=\"inline-block h-6 m-0 relative w-10\">\n        <input\n            #input\n            [id]=\"inputId\"\n            [name]=\"inputName\"\n            type=\"checkbox\"\n            role=\"switch\"\n            class=\"h-0 opacity-0 w-0\"\n            [attr.aria-checked]=\"value\"\n            [attr.aria-label]=\"label || null\"\n            [checked]=\"value\"\n            [disabled]=\"disabled\"\n            [attr.aria-readonly]=\"readonly || null\"\n            (change)=\"toggleCheck()\"\n        />\n        <span\n            class=\"slider bg-grayscale-40 rounded-[15px] inset-0 absolute cursor-pointer transition-all duration-[400ms]\"\n            aria-hidden=\"true\"\n        ></span>\n    </label>\n    @if (showStatusLabel) {\n        <span class=\"text-grayscale-90 font-open-sans text-sm font-normal leading-[150%] ml-3\">{{ value ? trueLabel : falseLabel }}</span>\n    }\n</div>\n\n", styles: [".slider:before{background-color:#fff;border-radius:50%;bottom:4px;content:\"\";height:16px;left:4px;position:absolute;transition:.4s;width:16px}input:checked+.slider{background-color:#428bca}input:checked+.slider:before{transform:translate(16px)}input:focus-visible+.slider{box-shadow:0 0 0 2px #000;outline:2px solid #000;outline-offset:1px}.switch--focus .slider{box-shadow:0 0 0 2px #428bca80}\n"] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: SwitchComponent, decorators: [{
            type: Component,
            args: [{ selector: 's-switch', providers: [
                        {
                            provide: NG_VALUE_ACCESSOR,
                            useExisting: forwardRef(() => SwitchComponent),
                            multi: true,
                        },
                    ], standalone: true, imports: [], template: "<div\n    #switch\n    class=\"inline-flex items-center\"\n    [class.opacity-50]=\"disabled\"\n    [attr.aria-disabled]=\"disabled || null\"\n>\n    <label class=\"inline-block h-6 m-0 relative w-10\">\n        <input\n            #input\n            [id]=\"inputId\"\n            [name]=\"inputName\"\n            type=\"checkbox\"\n            role=\"switch\"\n            class=\"h-0 opacity-0 w-0\"\n            [attr.aria-checked]=\"value\"\n            [attr.aria-label]=\"label || null\"\n            [checked]=\"value\"\n            [disabled]=\"disabled\"\n            [attr.aria-readonly]=\"readonly || null\"\n            (change)=\"toggleCheck()\"\n        />\n        <span\n            class=\"slider bg-grayscale-40 rounded-[15px] inset-0 absolute cursor-pointer transition-all duration-[400ms]\"\n            aria-hidden=\"true\"\n        ></span>\n    </label>\n    @if (showStatusLabel) {\n        <span class=\"text-grayscale-90 font-open-sans text-sm font-normal leading-[150%] ml-3\">{{ value ? trueLabel : falseLabel }}</span>\n    }\n</div>\n\n", styles: [".slider:before{background-color:#fff;border-radius:50%;bottom:4px;content:\"\";height:16px;left:4px;position:absolute;transition:.4s;width:16px}input:checked+.slider{background-color:#428bca}input:checked+.slider:before{transform:translate(16px)}input:focus-visible+.slider{box-shadow:0 0 0 2px #000;outline:2px solid #000;outline-offset:1px}.switch--focus .slider{box-shadow:0 0 0 2px #428bca80}\n"] }]
        }], propDecorators: { readonly: [{
                type: Input
            }], trueLabel: [{
                type: Input
            }], falseLabel: [{
                type: Input
            }], inputId: [{
                type: Input
            }], label: [{
                type: Input
            }], inputName: [{
                type: Input
            }], disabled: [{
                type: Input
            }], valueChanged: [{
                type: Output
            }], value: [{
                type: Input
            }], showStatusLabel: [{
                type: Input
            }], switchRef: [{
                type: ViewChild,
                args: ['switch', { static: true }]
            }], onFocusIn: [{
                type: HostListener,
                args: ['focusin']
            }], onFocusOut: [{
                type: HostListener,
                args: ['focusout']
            }] } });

class SwitchModule {
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: SwitchModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
    static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.14", ngImport: i0, type: SwitchModule, imports: [SwitchComponent], exports: [SwitchComponent] });
    static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: SwitchModule });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: SwitchModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [SwitchComponent],
                    exports: [SwitchComponent],
                }]
        }] });

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

export { SwitchComponent, SwitchModule };
//# sourceMappingURL=seniorsistemas-angular-components-switch.mjs.map
