import { Host, h } from "@stencil/core";
import { cls } from "../../utils/helpers";
export class XSelectOption {
    constructor() {
        this.value = undefined;
        this.selected = undefined;
        this.disabled = undefined;
        this.image = undefined;
        this.block = undefined;
        this.stretch = undefined;
    }
    /**
     * Element click event listener
     *
     * @returns
     */
    handleClick() {
        if (this.disabled) {
            return;
        }
        const parent = this.el.parentElement;
        if (parent.multiple) {
            this.selected = !this.selected;
        }
        else {
            if (this.selected && parent.unselectable) {
                this.selected = false;
            }
            else {
                parent.querySelectorAll('x-selector-item').forEach(item => {
                    item.selected = false;
                });
                this.selected = true;
            }
        }
        parent.dispatchEvent(new CustomEvent('changed'));
    }
    /**
     * Element render
     */
    render() {
        return h(Host, { key: 'e208d3f34be281e4b73df4db2e450f741fed4508', class: cls({
                'selected': this.selected,
                'disabled': this.disabled,
                'block': this.block,
            }), style: { backgroundImage: `url(${this.image})` } }, h("div", { key: '90319bc197b3b205dc16ff1967605d7f400e2e5b', class: "wrapper" }, h("slot", { key: 'e3fd24fa77d859cbebfc5df03031e3fb2bb03f11' })), h("span", { key: 'c43c5c7d506f256bc5f05b0afd826bd588e57739', class: "checkmark" }), h("div", { key: '8220f4096823e27699df1f2720c72a2b55d83966', class: "actions" }, h("slot", { key: '51656e1186c9c6dd60d6f845dac205647fa073ea', name: "actions" })));
    }
    static get is() { return "x-selector-item"; }
    static get originalStyleUrls() {
        return {
            "$": ["./style.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["style.css"]
        };
    }
    static get properties() {
        return {
            "value": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Element value"
                },
                "attribute": "value",
                "reflect": false
            },
            "selected": {
                "type": "boolean",
                "mutable": true,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Element selected state"
                },
                "attribute": "selected",
                "reflect": false
            },
            "disabled": {
                "type": "boolean",
                "mutable": true,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Element disabled state"
                },
                "attribute": "disabled",
                "reflect": false
            },
            "image": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Element image"
                },
                "attribute": "image",
                "reflect": false
            },
            "block": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Element block"
                },
                "attribute": "block",
                "reflect": false
            },
            "stretch": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Element stretch"
                },
                "attribute": "stretch",
                "reflect": false
            }
        };
    }
    static get elementRef() { return "el"; }
    static get listeners() {
        return [{
                "name": "click",
                "method": "handleClick",
                "target": undefined,
                "capture": false,
                "passive": false
            }];
    }
}
