import { getApplicationFormState } from "@boldpenguin/sdk-redux";
import { h } from "@stencil/core";
import store from "../../services/redux-store.service";
export class BpSdkFilterRemoteApplicationFormStateContainer {
    constructor() {
        this.handleSubscriptions = () => {
            this.storeUnsubscribe && this.storeUnsubscribe();
            this.storeUnsubscribe = store.mapStateToProps(this, this.mapStateToProps);
        };
        this.mapStateToProps = (state) => {
            return {
                state: getApplicationFormState(state),
            };
        };
        this.targetState = undefined;
        this.state = undefined;
        this.useExternal = false;
    }
    resetState() { }
    connectedCallback() {
        this.resetState();
        this.handleSubscriptions();
    }
    componentWillLoad() {
        this.useExternal = !!customElements.get('bp-sdk-external-filter-remote-application-form-state-container');
        customElements.whenDefined('bp-sdk-external-filter-remote-application-form-state-container').then(() => {
            this.useExternal = true;
        });
        this.handleSubscriptions();
    }
    render() {
        return [this.useExternal && this.renderExternal(), !this.useExternal && this.renderInternal()];
    }
    renderExternal() {
        return h("bp-sdk-external-filter-remote-application-form-state-container", { state: this.state, targetState: this.targetState });
    }
    renderInternal() {
        return (this.targetState === this.state && (h("div", { class: "bp-sdk-filter-remote-application-form-state-container__container" }, h("host", null))));
    }
    static get is() { return "bp-sdk-filter-remote-application-form-state-container"; }
    static get originalStyleUrls() {
        return {
            "$": ["./bp-sdk-filter-remote-application-form-state-container.css"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["bp-sdk-filter-remote-application-form-state-container.css"]
        };
    }
    static get properties() {
        return {
            "targetState": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "LoadingStates | undefined",
                    "resolved": "LoadingStates.Error | LoadingStates.Loaded | LoadingStates.Loading | LoadingStates.NotLoaded",
                    "references": {
                        "LoadingStates": {
                            "location": "import",
                            "path": "@boldpenguin/sdk-types",
                            "id": "../sdk-types/dist/types.d.ts::LoadingStates"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "target-state",
                "reflect": false
            },
            "state": {
                "type": "string",
                "mutable": true,
                "complexType": {
                    "original": "LoadingStates | undefined",
                    "resolved": "LoadingStates.Error | LoadingStates.Loaded | LoadingStates.Loading | LoadingStates.NotLoaded",
                    "references": {
                        "LoadingStates": {
                            "location": "import",
                            "path": "@boldpenguin/sdk-types",
                            "id": "../sdk-types/dist/types.d.ts::LoadingStates"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "attribute": "state",
                "reflect": false
            }
        };
    }
    static get states() {
        return {
            "useExternal": {}
        };
    }
}
