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: 'dc56a94ecef71b987393bc8110cac2d2d4b981c5', class: cls({
                'selected': this.selected,
                'disabled': this.disabled,
                'block': this.block,
            }), style: { backgroundImage: `url(${this.image})` } }, h("div", { key: 'c001d597afbdb35580ac557b4d4ec983b1b2e742', class: "wrapper" }, h("slot", { key: 'f43fbd595737523ae957b8bf4d6bc861beea801d' })), h("span", { key: 'e465332aad3713660ed2d0400e2aef2f13a27cb9', class: "checkmark" }), h("div", { key: 'b12763d97ba20fe7562d3dee2d78a31b5f3dec05', class: "actions" }, h("slot", { key: '709434c0c8123081f8c724e08aa79cc1a054db9b', 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
            }];
    }
}
