import { h } from "@stencil/core";
export class BpSdkParentQuestionPoolSelector {
    constructor() {
        this.selectValueUpdate = (ev) => {
            ev.stopPropagation();
            this.selectedChoiceId = ev.detail[0];
        };
        this.handleSubmit = () => {
            if (this.selectedChoiceId) {
                this.selectedAnswerPoolId.emit(this.selectedChoiceId);
                this.selectedChoiceId = undefined;
            }
        };
        this.choices = [];
        this.label = undefined;
        this.useExternal = false;
        this.selectedChoiceId = '';
    }
    componentWillLoad() {
        this.useExternal = !!customElements.get('bp-sdk-external-parent-question-pool-selector');
        customElements.whenDefined('bp-sdk-external-parent-question-pool-selector').then(() => {
            this.useExternal = true;
        });
    }
    render() {
        return [this.useExternal && this.renderExternal(), !this.useExternal && this.renderInternal()];
    }
    renderExternal() {
        return h("bp-sdk-external-parent-question-pool-selector", { choices: this.choices, label: this.label });
    }
    renderInternal() {
        return (h("div", { class: "bp-sdk-parent-question-pool-selector__container" }, h("bp-sdk-select-input", { choices: this.choices, label: this.label, onValueUpdate: this.selectValueUpdate, choiceId: this.selectedChoiceId }), this.selectedChoiceId && this.renderSubmitButton()));
    }
    renderSubmitButton() {
        if (!!this.selectedChoiceId) {
            return h("bp-sdk-button", { class: "bp-sdk-parent-pool-selector__submit-button", onClick: this.handleSubmit, text: "Next" });
        }
    }
    static get is() { return "bp-sdk-parent-question-pool-selector"; }
    static get originalStyleUrls() {
        return {
            "$": ["./bp-sdk-parent-question-pool-selector.css"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["bp-sdk-parent-question-pool-selector.css"]
        };
    }
    static get properties() {
        return {
            "choices": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "IChoice[]",
                    "resolved": "IChoice[]",
                    "references": {
                        "IChoice": {
                            "location": "import",
                            "path": "@boldpenguin/sdk-types",
                            "id": "../sdk-types/dist/types.d.ts::IChoice"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "defaultValue": "[]"
            },
            "label": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "label",
                "reflect": false
            }
        };
    }
    static get states() {
        return {
            "useExternal": {},
            "selectedChoiceId": {}
        };
    }
    static get events() {
        return [{
                "method": "selectedAnswerPoolId",
                "name": "selectedAnswerPoolId",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                }
            }];
    }
}
