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 "@angular/common";
import * as i4 from "../validation/validation-errors/validation-errors.component";
export class CheckboxComponent {
    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) {
        if (this.onChange) {
            this.onChange(insideValue);
        }
        if (this.onTouched) {
            this.onTouched();
        }
    }
}
CheckboxComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.4", ngImport: i0, type: CheckboxComponent, deps: [{ token: i0.Injector }, { token: i1.NgForm, optional: true }, { token: i2.FormDisabledDirective, optional: true }], target: i0.ɵɵFactoryTarget.Component });
CheckboxComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.0.4", type: CheckboxComponent, selector: "ui-checkbox", inputs: { name: "name", value: "value", setRequired: ["required", "setRequired"], setDisabled: ["disabled", "setDisabled"] }, providers: [
        {
            provide: NG_VALUE_ACCESSOR,
            useExisting: forwardRef(() => CheckboxComponent),
            multi: true
        }
    ], ngImport: i0, 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\"></ui-validation-errors>\n", styles: ["label{display:inline-grid;grid-template-columns:auto 1fr;gap:8px;line-height:var(--field-line-height)}input{cursor:pointer}input:not(:checked),input:checked{position:absolute;width:20px;height:20px;opacity:.00001}input:not(:checked)+span,input:checked+span{position:relative;cursor:pointer;padding:3px 0 3px 36px;-webkit-user-select:none;-moz-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:all .2s ease}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:not(:checked),input:disabled:checked{cursor:not-allowed}input:disabled:not(:checked)+svg .shape,input:disabled: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)}\n"], dependencies: [{ kind: "directive", type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i1.CheckboxControlValueAccessor, selector: "input[type=checkbox][formControlName],input[type=checkbox][formControl],input[type=checkbox][ngModel]" }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "component", type: i4.ValidationErrorsComponent, selector: "ui-validation-errors", inputs: ["errors"] }] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.4", ngImport: i0, type: CheckboxComponent, decorators: [{
            type: Component,
            args: [{ selector: 'ui-checkbox', providers: [
                        {
                            provide: NG_VALUE_ACCESSOR,
                            useExisting: forwardRef(() => CheckboxComponent),
                            multi: true
                        }
                    ], 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\"></ui-validation-errors>\n", styles: ["label{display:inline-grid;grid-template-columns:auto 1fr;gap:8px;line-height:var(--field-line-height)}input{cursor:pointer}input:not(:checked),input:checked{position:absolute;width:20px;height:20px;opacity:.00001}input:not(:checked)+span,input:checked+span{position:relative;cursor:pointer;padding:3px 0 3px 36px;-webkit-user-select:none;-moz-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:all .2s ease}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:not(:checked),input:disabled:checked{cursor:not-allowed}input:disabled:not(:checked)+svg .shape,input:disabled: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)}\n"] }]
        }], ctorParameters: function () { return [{ type: i0.Injector }, { type: i1.NgForm, decorators: [{
                    type: Optional
                }] }, { type: i2.FormDisabledDirective, decorators: [{
                    type: Optional
                }] }]; }, propDecorators: { name: [{
                type: Input
            }], value: [{
                type: Input
            }], setRequired: [{
                type: Input,
                args: ['required']
            }], setDisabled: [{
                type: Input,
                args: ['disabled']
            }] } });
//# sourceMappingURL=data:application/json;base64, 