import { Component, forwardRef, Input, Optional } from '@angular/core';
import { coerceBooleanProperty } from '@angular/cdk/coercion';
import { NG_VALUE_ACCESSOR, NgControl } from '@angular/forms';
import * as i0 from "@angular/core";
import * as i1 from "@angular/forms";
import * as i2 from "../form-disabled.directive";
import * as i3 from "../validation/validation-errors/validation-errors.component";
import * as i4 from "@angular/common";
export class SwitchComponent {
    constructor(injector, form, formDisabled) {
        this.injector = injector;
        this.form = form;
        this.formDisabled = formDisabled;
    }
    set setRequired(value) {
        this.required = coerceBooleanProperty(value);
    }
    set setDisabled(value) {
        this.disabled = coerceBooleanProperty(value);
    }
    ngOnInit() {
        this.control = this.injector.get(NgControl, null);
    }
    get invalid() {
        return (this.control?.touched || this.form?.submitted) && this.control?.invalid;
    }
    get viewDisabled() {
        return this.disabled || this.formDisabled?.disabled;
    }
    registerOnChange(fn) {
        this.onChange = fn;
    }
    registerOnTouched(fn) {
        this.onTouched = fn;
    }
    writeValue(outsideValue) {
        this.value = outsideValue;
    }
    setDisabledState(isDisabled) {
        this.disabled = isDisabled;
    }
    updateValue(insideValue) {
        this.value = insideValue;
        if (this.onChange) {
            this.onChange(insideValue);
        }
        if (this.onTouched) {
            this.onTouched();
        }
    }
}
SwitchComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.4", ngImport: i0, type: SwitchComponent, deps: [{ token: i0.Injector }, { token: i1.NgForm, optional: true }, { token: i2.FormDisabledDirective, optional: true }], target: i0.ɵɵFactoryTarget.Component });
SwitchComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.4", type: SwitchComponent, selector: "ui-switch", inputs: { name: "name", setRequired: ["required", "setRequired"], setDisabled: ["disabled", "setDisabled"] }, providers: [
        {
            provide: NG_VALUE_ACCESSOR,
            useExisting: forwardRef(() => SwitchComponent),
            multi: true
        }
    ], ngImport: i0, template: "<label>\n  <input type=\"checkbox\"\n         [(ngModel)]=\"value\"\n         (ngModelChange)=\"updateValue($event)\"\n         [name]=\"name\"\n         [disabled]=\"viewDisabled\"\n         [required]=\"required\">\n  <span>\n    <ng-content></ng-content>\n  </span>\n</label>\n\n<ui-validation-errors *ngIf=\"invalid\" [errors]=\"control.errors\"></ui-validation-errors>\n", styles: ["input{position:absolute;left:-9999px}input+span{position:relative;display:block;width:52px;height:26px;background-color:var(--color-contrast-10);border-radius:13px;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;user-select:none;transition:background-color .2s}input+span:before{content:\"\";position:absolute;left:0;top:0;margin:1px;width:24px;height:24px;background:var(--color-primary-contrast);border-radius:50%;transition:left .2s}input:checked+span{background-color:var(--color-primary)}input:checked+span:before{left:calc(100% - 26px)}input:disabled+span{opacity:.5;cursor:not-allowed}\n"], components: [{ type: i3.ValidationErrorsComponent, selector: "ui-validation-errors", inputs: ["errors"] }], directives: [{ type: i1.CheckboxControlValueAccessor, selector: "input[type=checkbox][formControlName],input[type=checkbox][formControl],input[type=checkbox][ngModel]" }, { type: i1.CheckboxRequiredValidator, selector: "input[type=checkbox][required][formControlName],input[type=checkbox][required][formControl],input[type=checkbox][required][ngModel]" }, { type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { type: i1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { type: i4.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.4", ngImport: i0, type: SwitchComponent, decorators: [{
            type: Component,
            args: [{ selector: 'ui-switch', providers: [
                        {
                            provide: NG_VALUE_ACCESSOR,
                            useExisting: forwardRef(() => SwitchComponent),
                            multi: true
                        }
                    ], template: "<label>\n  <input type=\"checkbox\"\n         [(ngModel)]=\"value\"\n         (ngModelChange)=\"updateValue($event)\"\n         [name]=\"name\"\n         [disabled]=\"viewDisabled\"\n         [required]=\"required\">\n  <span>\n    <ng-content></ng-content>\n  </span>\n</label>\n\n<ui-validation-errors *ngIf=\"invalid\" [errors]=\"control.errors\"></ui-validation-errors>\n", styles: ["input{position:absolute;left:-9999px}input+span{position:relative;display:block;width:52px;height:26px;background-color:var(--color-contrast-10);border-radius:13px;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;user-select:none;transition:background-color .2s}input+span:before{content:\"\";position:absolute;left:0;top:0;margin:1px;width:24px;height:24px;background:var(--color-primary-contrast);border-radius:50%;transition:left .2s}input:checked+span{background-color:var(--color-primary)}input:checked+span:before{left:calc(100% - 26px)}input:disabled+span{opacity:.5;cursor:not-allowed}\n"] }]
        }], ctorParameters: function () { return [{ type: i0.Injector }, { type: i1.NgForm, decorators: [{
                    type: Optional
                }] }, { type: i2.FormDisabledDirective, decorators: [{
                    type: Optional
                }] }]; }, propDecorators: { name: [{
                type: Input
            }], setRequired: [{
                type: Input,
                args: ['required']
            }], setDisabled: [{
                type: Input,
                args: ['disabled']
            }] } });
//# sourceMappingURL=data:application/json;base64, 