import { SymbolRegistry, apCheck, SymbolComponent } from '@agorapulse/ui-symbol';
import * as i0 from '@angular/core';
import { forwardRef, inject, EventEmitter, booleanAttribute, Output, Input, ViewChild, ViewEncapsulation, ChangeDetectionStrategy, Component } from '@angular/core';
import { NG_VALUE_ACCESSOR, NG_VALIDATORS } from '@angular/forms';

const AP_CHECKBOX_CONTROL_VALUE_ACCESSOR = {
    provide: NG_VALUE_ACCESSOR,
    useExisting: forwardRef(() => CheckboxComponent),
    multi: true,
};
class CheckboxComponent {
    symbolRegistry = inject(SymbolRegistry);
    inputElement;
    labelElement;
    ariaLabel;
    ariaLabelledby;
    ariaDescribedby;
    disabled = false;
    set indeterminate(indeterminate) {
        if (indeterminate) {
            this.checked = false;
        }
        this._indeterminate = indeterminate;
    }
    get indeterminate() {
        return this._indeterminate;
    }
    checked = false;
    required = false;
    set name(name) {
        this._name = name;
    }
    get name() {
        return this._name;
    }
    // eslint-disable-next-line
    change = new EventEmitter();
    ariaChecked = 'false';
    hasLabel = false;
    hovered = false;
    _indeterminate = false;
    _name = '';
    _controlValueAccessorChangeFn;
    onTouched;
    ngOnChanges() {
        if (this.labelElement) {
            this.hasLabel = !!this.labelElement.nativeElement.textContent?.trim();
        }
    }
    ngOnInit() {
        this.symbolRegistry.registerSymbols([apCheck]);
    }
    ngAfterContentInit() {
        if (this.labelElement) {
            this.hasLabel = !!this.labelElement.nativeElement.textContent?.trim();
        }
    }
    onMouseEnter() {
        if (!this.disabled) {
            this.hovered = true;
        }
    }
    onMouseLeave() {
        if (!this.disabled) {
            this.hovered = false;
        }
    }
    onValueChange() {
        if (this.onTouched) {
            this.onTouched();
        }
        if (!this.disabled) {
            if (this.indeterminate) {
                this.checked = false;
                this.indeterminate = false;
            }
            else {
                this.checked = !this.checked;
                this.focus();
            }
            this.change.emit(this.checked);
            if (this._controlValueAccessorChangeFn) {
                this._controlValueAccessorChangeFn(this.checked);
            }
            // Assigning the value again here is redundant, but we have to do it in case it was
            // changed inside the `change` listener which will cause the input to be out of sync.
            if (this.inputElement) {
                this.inputElement.nativeElement.checked = this.checked;
            }
        }
    }
    focus() {
        this.inputElement.nativeElement.focus();
    }
    writeValue(value) {
        this.checked = value;
    }
    registerOnChange(fn) {
        this._controlValueAccessorChangeFn = fn;
    }
    registerOnTouched(fn) {
        this.onTouched = fn;
    }
    setDisabledState(isDisabled) {
        this.disabled = isDisabled;
    }
    validate() {
        const isNotValid = !this.checked && this.required;
        return (isNotValid && {
            invalid: true,
        });
    }
    _preventBubblingFromLabel(event) {
        if (!!event.target && this.labelElement.nativeElement.contains(event.target)) {
            event.stopPropagation();
        }
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: CheckboxComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.16", type: CheckboxComponent, isStandalone: true, selector: "ap-checkbox", inputs: { ariaLabel: ["aria-label", "ariaLabel"], ariaLabelledby: ["aria-labelledby", "ariaLabelledby"], ariaDescribedby: ["aria-describedby", "ariaDescribedby"], disabled: ["disabled", "disabled", booleanAttribute], indeterminate: ["indeterminate", "indeterminate", booleanAttribute], checked: "checked", required: ["required", "required", booleanAttribute], name: "name" }, outputs: { change: "change" }, providers: [
            AP_CHECKBOX_CONTROL_VALUE_ACCESSOR,
            {
                provide: NG_VALIDATORS,
                useExisting: CheckboxComponent,
                multi: true,
            },
        ], viewQueries: [{ propertyName: "inputElement", first: true, predicate: ["input"], descendants: true, static: true }, { propertyName: "labelElement", first: true, predicate: ["label"], descendants: true, static: true }], usesOnChanges: true, ngImport: i0, template: "<div\n    class=\"checkbox\"\n    (click)=\"_preventBubblingFromLabel($event)\">\n    <div\n        class=\"checkbox-container\"\n        [class.hover]=\"hovered\"\n        [class.checked]=\"checked\"\n        [class.indeterminate]=\"indeterminate && !checked\"\n        [class.disabled]=\"disabled\"\n        [class.has-label]=\"hasLabel\"\n        [class.required]=\"required\">\n        <input\n            #input\n            type=\"checkbox\"\n            [id]=\"name\"\n            [class.disabled]=\"disabled\"\n            [disabled]=\"disabled\"\n            [checked]=\"checked\"\n            [required]=\"required\"\n            [attr.aria-label]=\"ariaLabel\"\n            [attr.aria-labelledby]=\"ariaLabelledby\"\n            [attr.aria-describedby]=\"ariaDescribedby\"\n            [attr.data-test]=\"name\"\n            (click)=\"onValueChange()\" />\n        <span\n            class=\"checkbox\"\n            (mouseenter)=\"onMouseEnter()\"\n            (mouseleave)=\"onMouseLeave()\"\n            (click)=\"onValueChange()\">\n            @if (checked) {\n                <span class=\"checkmark\">\n                    <ap-symbol\n                        symbolId=\"check\"\n                        color=\"white\"\n                        [size]=\"10\" />\n                </span>\n            }\n            @if (indeterminate && !checked) {\n                <span class=\"indeterminate\"></span>\n            }\n        </span>\n    </div>\n    <label\n        #label\n        [class.disabled]=\"disabled\"\n        [for]=\"name\">\n        <ng-content />\n    </label>\n</div>\n", styles: ["ap-checkbox{display:flex;align-items:center}ap-checkbox.ng-invalid.ng-touched .checkbox-container.required span.checkbox{border-color:var(--ref-color-red-100)!important}ap-checkbox.bold label{font-weight:var(--ref-font-weight-bold)}ap-checkbox.full-width .checkbox{justify-content:space-between;align-items:center;width:100%}ap-checkbox .checkbox{display:flex;align-items:center;gap:var(--ref-spacing-xxs)}ap-checkbox .checkbox .checkbox-container{display:flex;justify-content:center;align-items:center;max-width:36px;height:fit-content;box-sizing:border-box;position:relative}ap-checkbox .checkbox .checkbox-container:not(.has-label){padding:10px}ap-checkbox .checkbox .checkbox-container.hover:not(.disabled):not(.has-label){border-radius:var(--ref-border-radius-md);background:var(--ref-color-grey-05)}ap-checkbox .checkbox .checkbox-container.checked:not(.disabled).hover{background:var(--ref-color-electric-blue-10)}ap-checkbox .checkbox .checkbox-container.checked:not(.disabled):active:not(.has-label){background:var(--ref-color-electric-blue-20)}ap-checkbox .checkbox .checkbox-container.checked:not(.disabled):active:not(.has-label) span.checkbox{background:var(--ref-color-electric-blue-60)}ap-checkbox .checkbox .checkbox-container.checked:not(.disabled) span.checkbox{background:var(--ref-color-electric-blue-100);border-color:var(--ref-color-electric-blue-100)}ap-checkbox .checkbox .checkbox-container.checked:not(.disabled) span.checkbox:hover{border:1px solid var(--ref-color-electric-blue-100);background:var(--ref-color-electric-blue-80)}ap-checkbox .checkbox .checkbox-container.checked:not(.disabled) span.checkbox:active{border:1px solid var(--ref-color-electric-blue-100);background:var(--ref-color-electric-blue-60)}ap-checkbox .checkbox .checkbox-container.indeterminate:not(.disabled).hover{background:var(--ref-color-electric-blue-10)}ap-checkbox .checkbox .checkbox-container.indeterminate:not(.disabled) span.checkbox{background:var(--ref-color-electric-blue-100);border-color:var(--ref-color-electric-blue-100)}ap-checkbox .checkbox .checkbox-container.indeterminate:not(.disabled) span.checkbox:hover{border:1px solid var(--ref-color-electric-blue-100);background:var(--ref-color-electric-blue-80)}ap-checkbox .checkbox .checkbox-container.disabled span.checkbox{border:1px solid var(--ref-color-grey-20);background:var(--ref-color-grey-10)}ap-checkbox .checkbox .checkbox-container.disabled.checked span.checkbox{background:var(--ref-color-grey-20)}ap-checkbox .checkbox .checkbox-container.disabled.indeterminate span.checkbox{background:var(--ref-color-grey-20)}ap-checkbox .checkbox .checkbox-container.disabled span.checkbox{pointer-events:none}ap-checkbox .checkbox .checkbox-container input[type=checkbox]{position:absolute;clip:rect(0,0,0,0)}@media(hover:hover){ap-checkbox .checkbox .checkbox-container input[type=checkbox]:focus:not(.disabled)~.checkbox{outline:3px solid var(--ref-color-electric-blue-100);outline-offset:1px}}ap-checkbox .checkbox .checkbox-container span.checkbox{display:flex;justify-content:center;align-items:center;width:16px;height:16px;min-width:16px;min-height:16px;max-height:16px;max-width:16px;border-radius:var(--sys-border-radius-sm);border:1px solid var(--ref-color-grey-60);background:var(--ref-color-white);box-sizing:border-box}ap-checkbox .checkbox .checkbox-container span.checkbox:hover{cursor:pointer;border-color:var(--ref-color-grey-80)}ap-checkbox .checkbox .checkbox-container span.checkbox:active{border-color:var(--ref-color-grey-100)}ap-checkbox .checkbox .checkbox-container span.checkbox .checkmark{display:flex;justify-content:center;align-items:center}ap-checkbox .checkbox .checkbox-container span.checkbox .indeterminate{height:1.5px;background:var(--ref-color-white);width:8px}ap-checkbox .checkbox label{display:flex;align-items:center;font-family:var(--comp-forms-label-font-family);font-size:var(--comp-forms-label-size);font-weight:var(--comp-forms-label-font-weight);line-height:var(--comp-forms-label-line-height);color:var(--comp-forms-label-text-color)}ap-checkbox .checkbox label:empty{display:none}ap-checkbox .checkbox label.disabled{color:var(--ref-color-grey-60)}ap-checkbox .checkbox label:hover:not(.disabled){cursor:pointer}form.ng-submitted ap-checkbox.ng-invalid span.checkbox{border-color:var(--ref-color-red-100)!important}\n"], dependencies: [{ kind: "component", type: SymbolComponent, selector: "ap-symbol", inputs: ["symbolId", "color", "size"], outputs: ["sizeChange"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: CheckboxComponent, decorators: [{
            type: Component,
            args: [{ changeDetection: ChangeDetectionStrategy.OnPush, selector: 'ap-checkbox', imports: [SymbolComponent], providers: [
                        AP_CHECKBOX_CONTROL_VALUE_ACCESSOR,
                        {
                            provide: NG_VALIDATORS,
                            useExisting: CheckboxComponent,
                            multi: true,
                        },
                    ], encapsulation: ViewEncapsulation.None, template: "<div\n    class=\"checkbox\"\n    (click)=\"_preventBubblingFromLabel($event)\">\n    <div\n        class=\"checkbox-container\"\n        [class.hover]=\"hovered\"\n        [class.checked]=\"checked\"\n        [class.indeterminate]=\"indeterminate && !checked\"\n        [class.disabled]=\"disabled\"\n        [class.has-label]=\"hasLabel\"\n        [class.required]=\"required\">\n        <input\n            #input\n            type=\"checkbox\"\n            [id]=\"name\"\n            [class.disabled]=\"disabled\"\n            [disabled]=\"disabled\"\n            [checked]=\"checked\"\n            [required]=\"required\"\n            [attr.aria-label]=\"ariaLabel\"\n            [attr.aria-labelledby]=\"ariaLabelledby\"\n            [attr.aria-describedby]=\"ariaDescribedby\"\n            [attr.data-test]=\"name\"\n            (click)=\"onValueChange()\" />\n        <span\n            class=\"checkbox\"\n            (mouseenter)=\"onMouseEnter()\"\n            (mouseleave)=\"onMouseLeave()\"\n            (click)=\"onValueChange()\">\n            @if (checked) {\n                <span class=\"checkmark\">\n                    <ap-symbol\n                        symbolId=\"check\"\n                        color=\"white\"\n                        [size]=\"10\" />\n                </span>\n            }\n            @if (indeterminate && !checked) {\n                <span class=\"indeterminate\"></span>\n            }\n        </span>\n    </div>\n    <label\n        #label\n        [class.disabled]=\"disabled\"\n        [for]=\"name\">\n        <ng-content />\n    </label>\n</div>\n", styles: ["ap-checkbox{display:flex;align-items:center}ap-checkbox.ng-invalid.ng-touched .checkbox-container.required span.checkbox{border-color:var(--ref-color-red-100)!important}ap-checkbox.bold label{font-weight:var(--ref-font-weight-bold)}ap-checkbox.full-width .checkbox{justify-content:space-between;align-items:center;width:100%}ap-checkbox .checkbox{display:flex;align-items:center;gap:var(--ref-spacing-xxs)}ap-checkbox .checkbox .checkbox-container{display:flex;justify-content:center;align-items:center;max-width:36px;height:fit-content;box-sizing:border-box;position:relative}ap-checkbox .checkbox .checkbox-container:not(.has-label){padding:10px}ap-checkbox .checkbox .checkbox-container.hover:not(.disabled):not(.has-label){border-radius:var(--ref-border-radius-md);background:var(--ref-color-grey-05)}ap-checkbox .checkbox .checkbox-container.checked:not(.disabled).hover{background:var(--ref-color-electric-blue-10)}ap-checkbox .checkbox .checkbox-container.checked:not(.disabled):active:not(.has-label){background:var(--ref-color-electric-blue-20)}ap-checkbox .checkbox .checkbox-container.checked:not(.disabled):active:not(.has-label) span.checkbox{background:var(--ref-color-electric-blue-60)}ap-checkbox .checkbox .checkbox-container.checked:not(.disabled) span.checkbox{background:var(--ref-color-electric-blue-100);border-color:var(--ref-color-electric-blue-100)}ap-checkbox .checkbox .checkbox-container.checked:not(.disabled) span.checkbox:hover{border:1px solid var(--ref-color-electric-blue-100);background:var(--ref-color-electric-blue-80)}ap-checkbox .checkbox .checkbox-container.checked:not(.disabled) span.checkbox:active{border:1px solid var(--ref-color-electric-blue-100);background:var(--ref-color-electric-blue-60)}ap-checkbox .checkbox .checkbox-container.indeterminate:not(.disabled).hover{background:var(--ref-color-electric-blue-10)}ap-checkbox .checkbox .checkbox-container.indeterminate:not(.disabled) span.checkbox{background:var(--ref-color-electric-blue-100);border-color:var(--ref-color-electric-blue-100)}ap-checkbox .checkbox .checkbox-container.indeterminate:not(.disabled) span.checkbox:hover{border:1px solid var(--ref-color-electric-blue-100);background:var(--ref-color-electric-blue-80)}ap-checkbox .checkbox .checkbox-container.disabled span.checkbox{border:1px solid var(--ref-color-grey-20);background:var(--ref-color-grey-10)}ap-checkbox .checkbox .checkbox-container.disabled.checked span.checkbox{background:var(--ref-color-grey-20)}ap-checkbox .checkbox .checkbox-container.disabled.indeterminate span.checkbox{background:var(--ref-color-grey-20)}ap-checkbox .checkbox .checkbox-container.disabled span.checkbox{pointer-events:none}ap-checkbox .checkbox .checkbox-container input[type=checkbox]{position:absolute;clip:rect(0,0,0,0)}@media(hover:hover){ap-checkbox .checkbox .checkbox-container input[type=checkbox]:focus:not(.disabled)~.checkbox{outline:3px solid var(--ref-color-electric-blue-100);outline-offset:1px}}ap-checkbox .checkbox .checkbox-container span.checkbox{display:flex;justify-content:center;align-items:center;width:16px;height:16px;min-width:16px;min-height:16px;max-height:16px;max-width:16px;border-radius:var(--sys-border-radius-sm);border:1px solid var(--ref-color-grey-60);background:var(--ref-color-white);box-sizing:border-box}ap-checkbox .checkbox .checkbox-container span.checkbox:hover{cursor:pointer;border-color:var(--ref-color-grey-80)}ap-checkbox .checkbox .checkbox-container span.checkbox:active{border-color:var(--ref-color-grey-100)}ap-checkbox .checkbox .checkbox-container span.checkbox .checkmark{display:flex;justify-content:center;align-items:center}ap-checkbox .checkbox .checkbox-container span.checkbox .indeterminate{height:1.5px;background:var(--ref-color-white);width:8px}ap-checkbox .checkbox label{display:flex;align-items:center;font-family:var(--comp-forms-label-font-family);font-size:var(--comp-forms-label-size);font-weight:var(--comp-forms-label-font-weight);line-height:var(--comp-forms-label-line-height);color:var(--comp-forms-label-text-color)}ap-checkbox .checkbox label:empty{display:none}ap-checkbox .checkbox label.disabled{color:var(--ref-color-grey-60)}ap-checkbox .checkbox label:hover:not(.disabled){cursor:pointer}form.ng-submitted ap-checkbox.ng-invalid span.checkbox{border-color:var(--ref-color-red-100)!important}\n"] }]
        }], propDecorators: { inputElement: [{
                type: ViewChild,
                args: ['input', { static: true }]
            }], labelElement: [{
                type: ViewChild,
                args: ['label', { static: true }]
            }], ariaLabel: [{
                type: Input,
                args: ['aria-label']
            }], ariaLabelledby: [{
                type: Input,
                args: ['aria-labelledby']
            }], ariaDescribedby: [{
                type: Input,
                args: ['aria-describedby']
            }], disabled: [{
                type: Input,
                args: [{
                        transform: booleanAttribute,
                    }]
            }], indeterminate: [{
                type: Input,
                args: [{
                        transform: booleanAttribute,
                    }]
            }], checked: [{
                type: Input
            }], required: [{
                type: Input,
                args: [{
                        transform: booleanAttribute,
                    }]
            }], name: [{
                type: Input,
                args: [{
                        required: true,
                    }]
            }], change: [{
                type: Output
            }] } });

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

export { AP_CHECKBOX_CONTROL_VALUE_ACCESSOR, CheckboxComponent };
//# sourceMappingURL=agorapulse-ui-components-checkbox.mjs.map
