import { Host, h } from "@stencil/core";
import { cls } from "../../utils/helpers";
export class XSelectOption {
    constructor() {
        /**
         * Element has not empty actions slot
         */
        this.hasActionsSlot = false;
        this.value = undefined;
        this.selected = undefined;
        this.disabled = undefined;
        this.image = undefined;
        this.block = undefined;
        this.stretch = undefined;
        this.skew = undefined;
    }
    /**
     * On component will be loaded hook
     */
    componentWillLoad() {
        this.hasActionsSlot = !!this.el.querySelector('[slot="actions"]');
    }
    /**
     * Listen for keyboard events for confirmation
     */
    handleKeyDown(ev) {
        if ([' ', 'Enter'].includes(ev.key)) {
            this.handleClick();
        }
    }
    /**
     * 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 Event('changed'));
    }
    /**
     * Element render
     */
    render() {
        return h(Host, { key: '3001f7d7d87078f656c915f7252cc6c2383f9ae9', class: cls({
                'selected': this.selected,
                'disabled': this.disabled,
                'block': this.block,
                'skew': this.skew,
                'with-actions': this.hasActionsSlot,
            }), style: { backgroundImage: this.image ? `url(${this.image})` : 'none' }, tabindex: "0" }, h("div", { key: '66a276a331488fbddec231fd8e9efce3c177fbe4', class: "wrapper" }, h("slot", { key: '75fad044493014ddf8d8bfc9a55abfa39a2051b4' })), h("span", { key: 'd7c9d1a00acc04d3884c9273b1c1c9991310e9ee', class: "checkmark" }), h("div", { key: '595d329d3bc25c2657ce3ba395dc240cadac355c', class: "actions" }, h("slot", { key: 'e681a96c53672ed3bcc1f389e9c6f73e55c39fad', 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
            },
            "skew": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Element skew image background style"
                },
                "attribute": "skew",
                "reflect": false
            }
        };
    }
    static get elementRef() { return "el"; }
    static get listeners() {
        return [{
                "name": "keydown",
                "method": "handleKeyDown",
                "target": undefined,
                "capture": false,
                "passive": false
            }, {
                "name": "click",
                "method": "handleClick",
                "target": undefined,
                "capture": false,
                "passive": false
            }];
    }
}
