import { h } from "@stencil/core";
import { buildClassList, generateId } from "@boldpenguin/sdk-utility";
export class BpSdkQuestionGroupContainer {
    constructor() {
        this.questionGroup = undefined;
        this.classes = 'bp-sdk-question-group-content';
        this.labelId = generateId(8);
        this.type = undefined;
        this.useExternal = false;
    }
    onQuestionGroupChange(questionGroup) {
        if (this.type !== (questionGroup === null || questionGroup === void 0 ? void 0 : questionGroup.group_type)) {
            this.type = questionGroup === null || questionGroup === void 0 ? void 0 : questionGroup.group_type;
        }
    }
    onTypeChange(type) {
        this.updateClasses(type);
    }
    resetState() {
        var _a;
        this.type = (_a = this.questionGroup) === null || _a === void 0 ? void 0 : _a.group_type;
    }
    connectedCallback() {
        this.resetState();
    }
    componentWillLoad() {
        var _a;
        this.useExternal = !!customElements.get('bp-sdk-external-question-group-container');
        customElements.whenDefined('bp-sdk-external-question-group-container').then(() => {
            this.useExternal = true;
        });
        this.type = (_a = this.questionGroup) === null || _a === void 0 ? void 0 : _a.group_type;
    }
    render() {
        return [this.useExternal && this.renderExternal(), !this.useExternal && this.renderInternal()];
    }
    renderExternal() {
        return h("bp-sdk-external-question-group-container", { questionGroup: this.questionGroup });
    }
    renderInternal() {
        var _a, _b, _c;
        return (h("bp-sdk-question-group", { answers: (_a = this.questionGroup) === null || _a === void 0 ? void 0 : _a.answers, classes: this.classes, label: (_b = this.questionGroup) === null || _b === void 0 ? void 0 : _b.label, labelId: this.labelId, questionGroup: this.questionGroup, type: (_c = this.questionGroup) === null || _c === void 0 ? void 0 : _c.group_type }));
    }
    updateClasses(type) {
        if (!type) {
            this.classes = 'bp-sdk-question-group-content';
            return;
        }
        this.classes = buildClassList('bp-sdk-question-group-content', {
            'bp-sdk-row': type === 'split_horizontal',
            'bp-sdk-column': type !== 'split_horizontal',
            'bp-sdk-space-between': type === 'split_horizontal',
        });
    }
    static get is() { return "bp-sdk-question-group-container"; }
    static get originalStyleUrls() {
        return {
            "$": ["./bp-sdk-question-group-container.css"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["bp-sdk-question-group-container.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": "Question Group"
                }
            }
        };
    }
    static get states() {
        return {
            "classes": {},
            "labelId": {},
            "type": {},
            "useExternal": {}
        };
    }
    static get watchers() {
        return [{
                "propName": "questionGroup",
                "methodName": "onQuestionGroupChange"
            }, {
                "propName": "type",
                "methodName": "onTypeChange"
            }];
    }
}
