import { getFormId, getPartnerEngineConfig, removeQuestionPool } from "@boldpenguin/sdk-redux";
import { h } from "@stencil/core";
import store from "../../services/redux-store.service";
export class BpSdkDeleteQuestionPoolItemContainer {
    constructor() {
        this.handleSubscriptions = () => {
            this.storeUnsubscribe && this.storeUnsubscribe();
            store.mapDispatchToProps(this, { removeQuestionPool });
            this.storeUnsubscribe = store.mapStateToProps(this, this.mapStateToProps);
        };
        this.mapStateToProps = (state) => {
            return {
                applicationId: getFormId(state),
                config: getPartnerEngineConfig(state),
            };
        };
        this.handleRemoveItem = () => {
            this.removeQuestionPool({
                answer_pool_id: this.answerPoolId,
                application_id: this.applicationId,
                config: this.config,
            });
        };
        this.text = '';
        this.answerPoolId = undefined;
        this.applicationId = undefined;
        this.config = undefined;
        this.useExternal = false;
    }
    resetState() { }
    connectedCallback() {
        this.resetState();
        this.handleSubscriptions();
    }
    disconnectedCallback() {
        this.storeUnsubscribe && this.storeUnsubscribe();
    }
    componentWillLoad() {
        this.useExternal = !!customElements.get('bp-sdk-external-delete-question-pool-item-container');
        customElements.whenDefined('bp-sdk-external-delete-question-pool-item-container').then(() => {
            this.useExternal = true;
        });
        this.handleSubscriptions();
    }
    render() {
        return [this.useExternal && this.renderExternal(), !this.useExternal && this.renderInternal()];
    }
    renderExternal() {
        return (h("bp-sdk-external-delete-question-pool-item-container", { applicationId: this.applicationId, answerPoolId: this.answerPoolId, config: this.config, text: this.text }));
    }
    renderInternal() {
        return (h("div", { class: "bp-sdk-delete-question-pool-item-container__container" }, h("bp-sdk-delete-question-pool-item", { text: this.text, handleRemoveItem: this.handleRemoveItem })));
    }
    static get is() { return "bp-sdk-delete-question-pool-item-container"; }
    static get originalStyleUrls() {
        return {
            "$": ["./bp-sdk-delete-question-pool-item-container.css"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["bp-sdk-delete-question-pool-item-container.css"]
        };
    }
    static get properties() {
        return {
            "text": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Display text"
                },
                "attribute": "text",
                "reflect": false,
                "defaultValue": "''"
            },
            "answerPoolId": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "answer-pool-id",
                "reflect": false
            },
            "applicationId": {
                "type": "string",
                "mutable": true,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "application-id",
                "reflect": false
            },
            "config": {
                "type": "unknown",
                "mutable": true,
                "complexType": {
                    "original": "IPartnerEngineConfig",
                    "resolved": "IPartnerEngineConfig",
                    "references": {
                        "IPartnerEngineConfig": {
                            "location": "import",
                            "path": "@boldpenguin/sdk-types",
                            "id": "../sdk-types/dist/types.d.ts::IPartnerEngineConfig"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                }
            }
        };
    }
    static get states() {
        return {
            "useExternal": {}
        };
    }
    static get elementRef() { return "el"; }
}
