import { h } from "@stencil/core";
export class BpSdkStepperGroup {
    constructor() {
        this.questionGroup = undefined;
        this.useExternal = false;
    }
    resetState() { }
    connectedCallback() {
        this.resetState();
    }
    componentWillLoad() {
        this.useExternal = !!customElements.get('bp-sdk-external-stepper-group');
        customElements.whenDefined('bp-sdk-external-stepper-group').then(() => {
            this.useExternal = true;
        });
    }
    render() {
        return [this.useExternal && this.renderExternal(), !this.useExternal && this.renderInternal()];
    }
    renderAnswers(questionGroup) {
        var _a;
        return (_a = questionGroup === null || questionGroup === void 0 ? void 0 : questionGroup.answers) === null || _a === void 0 ? void 0 : _a.map((answer) => {
            if (this.displayAsQuestionGroup(answer.id)) {
                const nestedGroup = this.questionGroup.nestedGroupsWithAnswers.get(answer.id);
                if (nestedGroup.answers.length > 0) {
                    return h("bp-sdk-stepper-group", { questionGroup: nestedGroup });
                }
                return h("bp-sdk-stepper-group", { questionGroup: this.questionGroup.nestedGroupsWithAnswers.get(answer.id) });
            }
            else {
                return (h("bp-sdk-dynamic-input-redux-container", { answer: answer, labelledBy: "", id: `bp-sdk-question-group__${answer.question.id}`, class: "bp-sdk-question-group__question-set" }));
            }
        });
    }
    renderExternal() {
        return h("bp-sdk-external-stepper-group", { questionGroup: this.questionGroup });
    }
    renderInternal() {
        return h("div", { class: "bp-sdk-stepper-group__container" }, this.renderAnswers(this.questionGroup));
    }
    displayAsQuestionGroup(id) {
        return this.questionGroup.nestedGroupsWithAnswers.has(id);
    }
    static get is() { return "bp-sdk-stepper-group"; }
    static get originalStyleUrls() {
        return {
            "$": ["./bp-sdk-stepper-group.css"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["bp-sdk-stepper-group.css"]
        };
    }
    static get properties() {
        return {
            "questionGroup": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "IMappedQuestionGroupAnswers",
                    "resolved": "IMappedQuestionGroupAnswers",
                    "references": {
                        "IMappedQuestionGroupAnswers": {
                            "location": "import",
                            "path": "@boldpenguin/sdk-types",
                            "id": "../sdk-types/dist/types.d.ts::IMappedQuestionGroupAnswers"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Group of answers"
                }
            }
        };
    }
    static get states() {
        return {
            "useExternal": {}
        };
    }
}
