import { r as registerInstance, h, g as getElement } from './index-77a9c9e7.js';
import { a3 as Qr, h as SL, a4 as wN, a5 as ON, V as VN, i as MN, F as jN, u as up } from './index.esm.min-db2d29e8.js';
import { T } from './index.esm.min-9889e78b.js';
import { s as store } from './redux-store.service-dc54f48e.js';

const bpSdkTakeOverCss = "";
const BpSdkTakeOverStyle0 = bpSdkTakeOverCss;

const BpSdkTakeOver = class {
    constructor(hostRef) {
        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 (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() && (h("div", { class: "bp-sdk-take-over__container" }, h("bp-sdk-take-over-button", { onClick: this.takeOverHandler }))));
    }
};
BpSdkTakeOver.style = BpSdkTakeOverStyle0;

const bpSdkTakeOverContainerCss = "";
const BpSdkTakeOverContainerStyle0 = bpSdkTakeOverContainerCss;

const BpSdkTakeOverContainer = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.handleSubscriptions = () => {
            this.storeUnsubscribe && this.storeUnsubscribe();
            store.mapDispatchToProps(this, {
                cloneApplicationForm: Qr,
            });
            this.storeUnsubscribe = store.mapStateToProps(this, this.mapStateToProps);
        };
        this.mapStateToProps = (state) => {
            return {
                appFormId: SL(state),
                isLocked: wN(state),
                isCloned: ON(state),
                canTakeOver: VN(state, { permission: T.TakeOver }),
                isOwner: MN(state),
                isFormLoaded: jN(state),
                config: 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 (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 (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 getElement(this); }
};
BpSdkTakeOverContainer.style = BpSdkTakeOverContainerStyle0;

export { BpSdkTakeOver as bp_sdk_take_over, BpSdkTakeOverContainer as bp_sdk_take_over_container };
