'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-ceff47a0.js');
const index_esm_min = require('./index.esm.min-f57d151c.js');
const index_esm_min$1 = require('./index.esm.min-1101deb1.js');
const reduxStore_service = require('./redux-store.service-10b7725a.js');

const bpSdkTakeOverCss = "";
const BpSdkTakeOverStyle0 = bpSdkTakeOverCss;

const BpSdkTakeOver = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.isLocked = undefined;
        this.isCloned = undefined;
        this.canTakeOver = undefined;
        this.isOwner = undefined;
        this.isFormLoaded = undefined;
        this.takeOverHandler = undefined;
        this.useExternal = false;
    }
    resetState() { }
    connectedCallback() {
        this.resetState();
    }
    componentWillLoad() {
        this.useExternal = !!customElements.get('bp-sdk-external-take-over');
        customElements.whenDefined('bp-sdk-external-take-over').then(() => {
            this.useExternal = true;
        });
    }
    shouldRender() {
        return this.isFormLoaded && this.canTakeOver && !this.isOwner && !this.isCloned && !this.isLocked;
    }
    render() {
        return [this.useExternal && this.renderExternal(), !this.useExternal && this.renderInternal()];
    }
    renderExternal() {
        return (index.h("bp-sdk-external-take-over", { canTakeOver: this.canTakeOver, isCloned: this.isCloned, isLocked: this.isLocked, isOwner: this.isOwner, isFormLoaded: this.isFormLoaded, shouldRender: this.shouldRender(), takeOverHandler: this.takeOverHandler }));
    }
    renderInternal() {
        return (this.shouldRender() && (index.h("div", { class: "bp-sdk-take-over__container" }, index.h("bp-sdk-take-over-button", { onClick: this.takeOverHandler }))));
    }
};
BpSdkTakeOver.style = BpSdkTakeOverStyle0;

const bpSdkTakeOverContainerCss = "";
const BpSdkTakeOverContainerStyle0 = bpSdkTakeOverContainerCss;

const BpSdkTakeOverContainer = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.handleSubscriptions = () => {
            this.storeUnsubscribe && this.storeUnsubscribe();
            reduxStore_service.store.mapDispatchToProps(this, {
                cloneApplicationForm: index_esm_min.Qr,
            });
            this.storeUnsubscribe = reduxStore_service.store.mapStateToProps(this, this.mapStateToProps);
        };
        this.mapStateToProps = (state) => {
            return {
                appFormId: index_esm_min.SL(state),
                isLocked: index_esm_min.wN(state),
                isCloned: index_esm_min.ON(state),
                canTakeOver: index_esm_min.VN(state, { permission: index_esm_min$1.T.TakeOver }),
                isOwner: index_esm_min.MN(state),
                isFormLoaded: index_esm_min.jN(state),
                config: index_esm_min.up(state),
            };
        };
        this.takeOverHandler = () => {
            this.cloneApplicationForm({
                appFormId: this.appFormId,
                config: this.config,
            });
        };
        this.isLocked = undefined;
        this.isCloned = undefined;
        this.canTakeOver = undefined;
        this.isOwner = undefined;
        this.isFormLoaded = undefined;
        this.appFormId = undefined;
        this.config = undefined;
        this.useExternal = false;
    }
    resetState() { }
    connectedCallback() {
        this.resetState();
        this.handleSubscriptions();
    }
    componentWillLoad() {
        this.useExternal = !!customElements.get('bp-sdk-external-take-over-container');
        customElements.whenDefined('bp-sdk-external-take-over-container').then(() => {
            this.useExternal = true;
        });
        this.handleSubscriptions();
    }
    disconnectedCallback() {
        this.storeUnsubscribe && this.storeUnsubscribe();
    }
    render() {
        return [this.useExternal && this.renderExternal(), !this.useExternal && this.renderInternal()];
    }
    renderExternal() {
        return (index.h("bp-sdk-external-take-over-container", { appFormId: this.appFormId, canTakeOver: this.canTakeOver, config: this.config, isCloned: this.isCloned, isLocked: this.isLocked, isOwner: this.isOwner, isFormLoaded: this.isFormLoaded, takeOverHandler: this.takeOverHandler }));
    }
    renderInternal() {
        return (index.h("bp-sdk-take-over", { canTakeOver: this.canTakeOver, isCloned: this.isCloned, isLocked: this.isLocked, isOwner: this.isOwner, isFormLoaded: this.isFormLoaded, takeOverHandler: this.takeOverHandler }));
    }
    get el() { return index.getElement(this); }
};
BpSdkTakeOverContainer.style = BpSdkTakeOverContainerStyle0;

exports.bp_sdk_take_over = BpSdkTakeOver;
exports.bp_sdk_take_over_container = BpSdkTakeOverContainer;
