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  <svg width=\"20\" height=\"20\" viewBox=\"-4 -4 26 26\" aria-hidden=\"true\" focusable=\"false\">\n    <rect class=\"shape\" width=\"24\" height=\"24\" x=\"-3\" y=\"-3\" rx=\"6\" ry=\"6\" stroke=\"currentColor\" stroke-width=\"1.5\" fill=\"none\"></rect>\n    <polyline class=\"checkmark\" points=\"2 9 8 15 16 3\" stroke=\"transparent\" stroke-width=\"2\" stroke-linecap=\"round\" fill=\"none\" stroke-dasharray=\"30\" stroke-dashoffset=\"30\"></polyline>\n  </svg>\n  <span>\n    <ng-content></ng-content>\n  </span>\n</label>\n\n<ui-validation-errors *ngIf=\"invalid\" [errors]=\"control.errors\" class=\"checkbox-error\"></ui-validation-errors>\n",
            providers: [
                {
                    provide: NG_VALUE_ACCESSOR,
                    useExisting: forwardRef(function () { return CheckboxComponent_1; }),
                    multi: true
                }
            ],
            styles: ["label{display:grid;grid-template-columns:auto 1fr;gap:8px;line-height:1.4}input:checked,input:not(:checked){position:absolute;width:20px;height:20px;opacity:.00001}input:checked+span,input:not(:checked)+span{position:relative;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}input:focus+svg .shape{stroke:var(--checkRadioBorderColorFocus)}input:focus:not(:focus-visible)+svg .shape{stroke:var(--checkRadioBorderColor)}input:hover+svg .shape{stroke:var(--checkRadioBackgroundCheck)}input+svg .shape{color:var(--checkRadioBorderColor);transition:.2s}input+svg .checkmark{transition:stroke-dashoffset .4s linear}input:checked+svg .shape,input:checked:focus+svg .shape{fill:var(--checkRadioBackgroundCheck);stroke:var(--checkRadioBackgroundCheck)}input:checked+svg .checkmark,input:checked:focus+svg .checkmark{stroke:var(--checkRadioMarkColor);stroke-dashoffset:0}input:disabled:checked+svg .shape,input:disabled:not(:checked)+svg .shape{fill:var(--checkRadioBackgroundDisabled);stroke:var(--checkRadioBackgroundDisabled)}input:disabled:checked+svg .checkmark{stroke:var(--checkRadioMarkColorDisabled)}input:disabled+span{color:var(--checkRadioLabelDisabled)}input.invalid+svg .shape,input.invalid:focus+svg .shape{stroke:var(--color-error)}"]
        }),
        __param(1, Optional()),
        __param(2, Optional())
    ], CheckboxComponent);
    return CheckboxComponent;
}());
export { CheckboxComponent };
//# sourceMappingURL=data:application/json;base64, 