import { h } from "@stencil/core";
export class SpwCheckbox {
    constructor() {
        /** Détermine si la case à cocher est désactivée, rendant l'élément inutilisable */
        this.disabled = false;
        /** Propriété mutable qui reflète si la case à cocher est cochée ou non */
        this.checked = false;
        /** Indique s'il y a une erreur associée à la case à cocher, pour un affichage visuel */
        this.error = false;
        /** Icône à afficher lorsque la case à cocher est cochée */
        this.icon = 'fa-check';
        /** Valeur soumise dans le formulaire lorsque la case est cochée (défaut : 'on') */
        this.value = 'on';
        /** Type de variant pour la checkbox */
        this.variant = 'default';
    }
    handleCheckbox(event) {
        if (this.disabled) {
            event === null || event === void 0 ? void 0 : event.preventDefault();
            event === null || event === void 0 ? void 0 : event.stopPropagation();
            return;
        }
        this.internalChecked = !this.internalChecked;
        this.checked = this.internalChecked;
        this.updateFormValue();
        this.spwChange.emit(this.internalChecked);
    }
    /** Méthode publique pour changer l'état de la case à cocher. */
    async toggleCheckedState(newVal) {
        if (this.disabled)
            return;
        this.internalChecked = newVal;
        this.checked = newVal;
        this.updateFormValue();
    }
    checkedChanged(newChecked) {
        this.internalChecked = newChecked;
        this.inputElement.checked = newChecked;
        this.updateFormValue();
    }
    updateFormValue() {
        if (this.internalChecked) {
            this.internals.setFormValue(this.value);
        }
        else {
            this.internals.setFormValue(null);
        }
    }
    handleKeydown(event) {
        if (event.key === ' ' || event.key === 'Enter') {
            // Space or Enter keys
            this.handleCheckbox();
            event.preventDefault();
        }
    }
    componentWillLoad() {
        this.internalChecked = this.checked;
        this.defaultChecked = this.checked;
        this.updateFormValue();
    }
    formResetCallback() {
        this.internalChecked = this.defaultChecked;
        this.checked = this.defaultChecked;
        this.updateFormValue();
    }
    get elementClass() {
        return {
            'spw-checkbox__wrapper': true,
            [`spw-checkbox__wrapper--${this.variant}`]: true,
            'spw-checkbox__wrapper--disabled': this.disabled,
            'spw-checkbox__wrapper--checked': this.internalChecked,
            'spw-checkbox__wrapper--error': this.error,
        };
    }
    render() {
        const slot = this.el.innerHTML;
        const hasSlot = Boolean(slot);
        return (h("div", { key: 'c38a01b2898e391335b55297929b50109d892434', class: "spw-checkbox" }, h("input", { key: '2e696c49a36c92eed15f06e64b4a52722fab8062', type: "checkbox", ref: el => (this.inputElement = el), checked: this.internalChecked, onChange: this.handleCheckbox.bind(this), name: this.name, disabled: this.disabled, style: { display: 'none' } }), hasSlot && (h("label", { key: 'aaa5422e96bd40d32972996be19f389cdb276e70', htmlFor: this.name, class: `spw-checkbox__label ${this.disabled ? 'spw-checkbox__label--disabled' : ''}`, onClick: e => this.handleCheckbox(e) }, h("slot", { key: 'baa3fbdb4b6a17b91dba5c6077bd50a1f8207b61' }))), h("div", { key: '36a552efdb1a0afe004d8e518978175cfb788ccb', tabindex: this.disabled ? -1 : 0, onClick: e => this.handleCheckbox(e), onKeyDown: this.handleKeydown.bind(this), role: "checkbox", "aria-checked": this.internalChecked ? 'true' : 'false', "aria-disabled": this.disabled ? 'true' : 'false', "aria-label": this.accAriaLabel || this.name || 'Label', class: this.elementClass }, this.internalChecked && h("spw-icon", { key: '95cdfbb6513f76bb570e3707cf34cb8ccf8e1107', icon: this.icon }))));
    }
    static get is() { return "spw-checkbox"; }
    static get encapsulation() { return "shadow"; }
    static get formAssociated() { return true; }
    static get originalStyleUrls() {
        return {
            "$": ["spw-checkbox.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["spw-checkbox.css"]
        };
    }
    static get properties() {
        return {
            "disabled": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "D\u00E9termine si la case \u00E0 cocher est d\u00E9sactiv\u00E9e, rendant l'\u00E9l\u00E9ment inutilisable"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "disabled",
                "defaultValue": "false"
            },
            "checked": {
                "type": "boolean",
                "mutable": true,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Propri\u00E9t\u00E9 mutable qui refl\u00E8te si la case \u00E0 cocher est coch\u00E9e ou non"
                },
                "getter": false,
                "setter": false,
                "reflect": true,
                "attribute": "checked",
                "defaultValue": "false"
            },
            "error": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Indique s'il y a une erreur associ\u00E9e \u00E0 la case \u00E0 cocher, pour un affichage visuel"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "error",
                "defaultValue": "false"
            },
            "icon": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Ic\u00F4ne \u00E0 afficher lorsque la case \u00E0 cocher est coch\u00E9e"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "icon",
                "defaultValue": "'fa-check'"
            },
            "name": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Nom de l'\u00E9l\u00E9ment utilis\u00E9 dans les formulaires"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "name"
            },
            "value": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Valeur soumise dans le formulaire lorsque la case est coch\u00E9e (d\u00E9faut : 'on')"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "value",
                "defaultValue": "'on'"
            },
            "variant": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "'default' | 'toggle'",
                    "resolved": "\"default\" | \"toggle\"",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": "Type de variant pour la checkbox"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "variant",
                "defaultValue": "'default'"
            },
            "accAriaLabel": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": "Remplit l'attribut aria-label, utilis\u00E9 \u00E0 des fins d'accessibilit\u00E9"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "acc-aria-label"
            }
        };
    }
    static get states() {
        return {
            "internalChecked": {}
        };
    }
    static get events() {
        return [{
                "method": "spwChange",
                "name": "spwChange",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": "\u00C9v\u00E9nement d\u00E9clench\u00E9 lors d'un changement d'\u00E9tat de la case \u00E0 cocher (coch\u00E9e ou d\u00E9coch\u00E9e)"
                },
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                }
            }];
    }
    static get methods() {
        return {
            "toggleCheckedState": {
                "complexType": {
                    "signature": "(newVal: boolean) => Promise<void>",
                    "parameters": [{
                            "name": "newVal",
                            "type": "boolean",
                            "docs": ""
                        }],
                    "references": {
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        }
                    },
                    "return": "Promise<void>"
                },
                "docs": {
                    "text": "M\u00E9thode publique pour changer l'\u00E9tat de la case \u00E0 cocher.",
                    "tags": []
                }
            }
        };
    }
    static get elementRef() { return "el"; }
    static get watchers() {
        return [{
                "propName": "checked",
                "methodName": "checkedChanged"
            }];
    }
    static get attachInternalsMemberName() { return "internals"; }
}
