import { __decorate, __param } from "tslib";
import { Component, forwardRef, Injector, Input, OnInit, Optional } from '@angular/core';
import { coerceBooleanProperty } from '@angular/cdk/coercion';
import { ControlValueAccessor, NG_VALUE_ACCESSOR, NgControl, NgForm } from '@angular/forms';
import { FormDisabledDirective } from '../form-disabled.directive';
var CheckboxComponent = /** @class */ (function () {
    function CheckboxComponent(injector, form, formDisabled) {
        this.injector = injector;
        this.form = form;
        this.formDisabled = formDisabled;
    }
    CheckboxComponent_1 = CheckboxComponent;
    Object.defineProperty(CheckboxComponent.prototype, "setRequired", {
        set: function (value) {
            this.required = coerceBooleanProperty(value);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CheckboxComponent.prototype, "setDisabled", {
        set: function (value) {
            this.disabled = coerceBooleanProperty(value);
        },
        enumerable: true,
        configurable: true
    });
    CheckboxComponent.prototype.ngOnInit = function () {
        this.control = this.injector.get(NgControl, null);
    };
    Object.defineProperty(CheckboxComponent.prototype, "invalid", {
        get: function () {
            var _a, _b, _c;
            return (((_a = this.control) === null || _a === void 0 ? void 0 : _a.touched) || ((_b = this.form) === null || _b === void 0 ? void 0 : _b.submitted)) && ((_c = this.control) === null || _c === void 0 ? void 0 : _c.invalid);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CheckboxComponent.prototype, "viewDisabled", {
        get: function () {
            var _a;
            return this.disabled || ((_a = this.formDisabled) === null || _a === void 0 ? void 0 : _a.disabled);
        },
        enumerable: true,
        configurable: true
    });
    CheckboxComponent.prototype.registerOnChange = function (fn) {
        this.onChange = fn;
    };
    CheckboxComponent.prototype.registerOnTouched = function (fn) {
        this.onTouched = fn;
    };
    CheckboxComponent.prototype.writeValue = function (outsideValue) {
        this.value = outsideValue;
    };
    CheckboxComponent.prototype.setDisabledState = function (isDisabled) {
        this.disabled = isDisabled;
    };
    CheckboxComponent.prototype.updateValue = function (insideValue) {
        if (this.onChange) {
            this.onChange(insideValue);
        }
        if (this.onTouched) {
            this.onTouched();
        }
    };
    var CheckboxComponent_1;
    CheckboxComponent.ctorParameters = function () { return [
        { type: Injector },
        { type: NgForm, decorators: [{ type: Optional }] },
        { type: FormDisabledDirective, decorators: [{ type: Optional }] }
    ]; };
    __decorate([
        Input()
    ], CheckboxComponent.prototype, "name", void 0);
    __decorate([
        Input()
    ], CheckboxComponent.prototype, "value", void 0);
    __decorate([
        Input('required')
    ], CheckboxComponent.prototype, "setRequired", null);
    __decorate([
        Input('disabled')
    ], CheckboxComponent.prototype, "setDisabled", null);
    CheckboxComponent = CheckboxComponent_1 = __decorate([
        Component({
            selector: 'ui-checkbox',
            template: "<label>\n  <input type=\"checkbox\"\n         [(ngModel)]=\"value\"\n         (ngModelChange)=\"updateValue($event)\"\n         [name]=\"name\"\n         [disabled]=\"viewDisabled\"\n         [class.invalid]=\"invalid\">\n  <span>\n    <ng-content></ng-content>\n  </span>\n</label>\n\n<div class=\"error\" *ngIf=\"invalid\">\n  <div *ngFor=\"let error of control.errors | parseMessages\">{{error}}</div>\n</div>\n\n",
            providers: [
                {
                    provide: NG_VALUE_ACCESSOR,
                    useExisting: forwardRef(function () { return CheckboxComponent_1; }),
                    multi: true
                }
            ],
            styles: ["input:checked,input:not(:checked){position:absolute;left:-9999px}input:checked+span:before,input:not(:checked)+span:before{content:\"\";position:absolute;left:0;top:0;width:20px;height:20px;border:var(--checkRadioBorderWidth) solid var(--checkRadioBorderColor);background:var(--checkRadioBackground);box-shadow:var(--checkRadioShadow);transition:.2s;border-radius:var(--checkRadioRadius)}input:checked+span:hover:before,input:not(:checked)+span:hover:before{border-color:var(--checkRadioBorderColor)}input:checked+span,input:not(:checked)+span{cursor:pointer;padding:3px 0 3px 36px;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;display:block;line-height:1.3;position:relative}input:checked+span:after,input:not(:checked)+span:after{content:\"\";transition:.2s;content:\" \";z-index:1;display:block;position:absolute;top:7px;margin-top:-5px;left:7px;width:6px;height:12px;border:2px solid var(--checkRadioBorderColor);border-top:none;border-left:none;transform:rotate(45deg)}input:not(:checked)+span:after{opacity:0;transform:rotate(45deg) translateY(-3px)}input:checked+span:after{opacity:1;transform:rotate(45deg) translateY(0)}input:disabled:checked+span,input:disabled:not(:checked)+span{color:#d0d0d0}input:disabled:checked+span:before,input:disabled:not(:checked)+span:before{box-shadow:none;border-color:#d0d0d0;background-color:#f0f0f0}input:disabled:checked+span:after{color:#999}input:disabled+span{color:#aaa}input:checked:focus+span:before,input:not(:checked):focus+span:before{border:var(--checkRadioBorderWidth) solid var(--checkRadioBorderColor)}input.invalid+span:before{border-color:var(--color-error)}.error{font-size:.875rem;color:var(--color-error);padding-left:35px}"]
        }),
        __param(1, Optional()),
        __param(2, Optional())
    ], CheckboxComponent);
    return CheckboxComponent;
}());
export { CheckboxComponent };
//# sourceMappingURL=data:application/json;base64, 