import { h } from "@stencil/core";
export class BpSdkVehiclePanelContent {
    constructor() {
        this.additionalAnswers = [];
        this.labelledBy = undefined;
        this.questionGroup = undefined;
        this.useExternal = false;
    }
    resetState() { }
    connectedCallback() {
        this.resetState();
    }
    componentWillLoad() {
        this.useExternal = !!customElements.get('bp-sdk-external-vehicle-panel-content');
        customElements.whenDefined('bp-sdk-external-vehicle-panel-content').then(() => {
            this.useExternal = true;
        });
    }
    shouldRenderQuestionGroup(questionGroupsWithAnswersAsKey, answer) {
        return questionGroupsWithAnswersAsKey.has(answer.id);
    }
    render() {
        return [this.useExternal && this.renderExternal(), !this.useExternal && this.renderInternal()];
    }
    renderExternal() {
        return (h("bp-sdk-external-vehicle-panel-content", { additionalAnswers: this.additionalAnswers, labelledBy: this.labelledBy, questionGroup: this.questionGroup }));
    }
    renderInternal() {
        return this.additionalAnswers.map((answer) => {
            return this.renderAnswer(answer);
        });
    }
    renderAnswer(answer) {
        var _a, _b;
        if (!answer) {
            return null;
        }
        const nestedGroupToRender = (_b = (_a = this.questionGroup) === null || _a === void 0 ? void 0 : _a.nestedGroupsWithAnswers) === null || _b === void 0 ? void 0 : _b.get(answer.id);
        return [
            !nestedGroupToRender && h("bp-sdk-dynamic-input-redux-container", { answer: answer }),
            nestedGroupToRender && h("bp-sdk-question-group-container", { questionGroup: nestedGroupToRender }),
        ];
    }
    static get is() { return "bp-sdk-vehicle-panel-content"; }
    static get originalStyleUrls() {
        return {
            "$": ["./bp-sdk-vehicle-panel-content.css"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["bp-sdk-vehicle-panel-content.css"]
        };
    }
    static get properties() {
        return {
            "additionalAnswers": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "IAnswer[]",
                    "resolved": "IAnswer[]",
                    "references": {
                        "IAnswer": {
                            "location": "import",
                            "path": "@boldpenguin/sdk-types",
                            "id": "../sdk-types/dist/types.d.ts::IAnswer"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Additional answers for a vehicle after the vehicle is saved/valid"
                },
                "defaultValue": "[]"
            },
            "labelledBy": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Labels that describe group"
                },
                "attribute": "labelled-by",
                "reflect": false
            },
            "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": "Nested question group map"
                }
            }
        };
    }
    static get states() {
        return {
            "useExternal": {}
        };
    }
}
