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';
import * as i1 from '@angular/common';
import { CommonModule } from '@angular/common';

class SwitchComponent {
    readonly = false;
    trueLabel;
    falseLabel;
    inputId;
    inputName;
    disabled = false;
    valueChanged = new EventEmitter();
    value = false;
    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() {
        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: "14.0.0", version: "18.2.14", type: SwitchComponent, selector: "s-switch", inputs: { readonly: "readonly", trueLabel: "trueLabel", falseLabel: "falseLabel", inputId: "inputId", inputName: "inputName", disabled: "disabled", value: "value" }, 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=\"switch\"\n    [ngClass]=\"{ 'switch--disabled': disabled }\"\n>\n    <label class=\"switch-toggle\">\n        <input\n            #input\n            [id]=\"inputId\"\n            [name]=\"inputName\"\n            type=\"checkbox\"\n            [checked]=\"value\"\n            [disabled]=\"readonly || disabled\"\n            (change)=\"toggleCheck()\"\n        />\n        <span class=\"slider\"></span>\n    </label>\n    <span class=\"label\">\n        {{ value ? trueLabel : falseLabel }}\n    </span>\n</div>\n", styles: [".switch{display:inline-flex;align-items:center}.switch .switch-toggle{display:inline-block;height:24px;margin:0;position:relative;width:40px}.switch .switch-toggle input{height:0;opacity:0;width:0}.switch .switch-toggle input:checked+.slider{background-color:#428bca;border-radius:15px}.switch .switch-toggle input:checked+.slider:before{transform:translate(16px)}.switch .switch-toggle .slider{background-color:#a5a5b2;border-radius:15px;cursor:pointer;inset:0;position:absolute;transition:.4s}.switch .switch-toggle .slider:before{background-color:#fff;border-radius:50%;bottom:4px;content:\"\";height:16px;left:4px;position:absolute;transition:.4s;width:16px}.switch .label{color:#212533;font-family:\"Open Sans\" sans-serif;font-size:.875rem;font-weight:400;line-height:150%;margin-left:12px}.switch--disabled{opacity:.5}.switch--focus .switch-toggle .slider{box-shadow:0 0 0 2px #428bca80}\n"], dependencies: [{ kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }] });
}
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,
                        },
                    ], template: "<div\n    #switch\n    class=\"switch\"\n    [ngClass]=\"{ 'switch--disabled': disabled }\"\n>\n    <label class=\"switch-toggle\">\n        <input\n            #input\n            [id]=\"inputId\"\n            [name]=\"inputName\"\n            type=\"checkbox\"\n            [checked]=\"value\"\n            [disabled]=\"readonly || disabled\"\n            (change)=\"toggleCheck()\"\n        />\n        <span class=\"slider\"></span>\n    </label>\n    <span class=\"label\">\n        {{ value ? trueLabel : falseLabel }}\n    </span>\n</div>\n", styles: [".switch{display:inline-flex;align-items:center}.switch .switch-toggle{display:inline-block;height:24px;margin:0;position:relative;width:40px}.switch .switch-toggle input{height:0;opacity:0;width:0}.switch .switch-toggle input:checked+.slider{background-color:#428bca;border-radius:15px}.switch .switch-toggle input:checked+.slider:before{transform:translate(16px)}.switch .switch-toggle .slider{background-color:#a5a5b2;border-radius:15px;cursor:pointer;inset:0;position:absolute;transition:.4s}.switch .switch-toggle .slider:before{background-color:#fff;border-radius:50%;bottom:4px;content:\"\";height:16px;left:4px;position:absolute;transition:.4s;width:16px}.switch .label{color:#212533;font-family:\"Open Sans\" sans-serif;font-size:.875rem;font-weight:400;line-height:150%;margin-left:12px}.switch--disabled{opacity:.5}.switch--focus .switch-toggle .slider{box-shadow:0 0 0 2px #428bca80}\n"] }]
        }], propDecorators: { readonly: [{
                type: Input
            }], trueLabel: [{
                type: Input
            }], falseLabel: [{
                type: Input
            }], inputId: [{
                type: Input
            }], inputName: [{
                type: Input
            }], disabled: [{
                type: Input
            }], valueChanged: [{
                type: Output
            }], value: [{
                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, declarations: [SwitchComponent], imports: [CommonModule], exports: [SwitchComponent] });
    static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: SwitchModule, imports: [CommonModule] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: SwitchModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [CommonModule],
                    declarations: [SwitchComponent],
                    exports: [SwitchComponent],
                }]
        }] });

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

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