import { r as registerInstance, h, f as forceUpdate, a as getElement } from './index-3c959d8a.js';
import { E as EventBus } from './EventBus-56ba7d6d.js';
import { s as state, r as resetState } from './signTransactionsModalStore-b5c1de6f.js';

var SignEventsEnum;
(function (SignEventsEnum) {
    SignEventsEnum["SIGN_TRANSACTION"] = "SIGN_TRANSACTION";
    SignEventsEnum["NEXT_PAGE"] = "NEXT_PAGE";
    SignEventsEnum["PREV_PAGE"] = "PREV_PAGE";
    SignEventsEnum["CLOSE"] = "CLOSE";
    SignEventsEnum["DATA_UPDATE"] = "DATA_UPDATE";
})(SignEventsEnum || (SignEventsEnum = {}));

const signTransactionsModalCss = "*{margin:0;padding:0;box-sizing:border-box}.transaction-header-container{display:flex;flex-direction:column}.loading-spinner{display:flex;justify-content:center;align-items:center;min-height:350px}";
const SignTransactionsModalStyle0 = signTransactionsModalCss;

const signScreens = {
    FungibleESDT: 'token-component',
    SemiFungibleESDT: 'fungible-component',
    NonFungibleESDT: 'fungible-component',
};
const SignTransactionsModal = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.eventBus = new EventBus();
        this.data = {
            commonData: { egldLabel: '', feeLimit: '', feeInFiatLimit: '', transactionsCount: 0, currentIndex: 0 },
            tokenTransaction: null,
            nftTransaction: null,
            sftTransaction: null,
        };
    }
    async getEventBus() {
        return this.eventBus;
    }
    onDataChange(data) {
        for (const key in data) {
            if (Object.prototype.hasOwnProperty.call(state, key)) {
                state[key] = data[key];
            }
        }
        state.isWaitingForSignature = false;
        state.isLoading = false;
    }
    componentWillLoad() {
        state.onSign = () => {
            state.isWaitingForSignature = true;
            this.eventBus.publish(SignEventsEnum.SIGN_TRANSACTION);
        };
    }
    render() {
        const { commonData, isLoading } = state;
        const { tokenType, currentIndex, transactionsCount } = commonData;
        const SignScreen = signScreens[tokenType];
        return (h("generic-modal", { key: '8a5f8ec8c062fb6d1e99965dbbff6332000bad57', onClose: () => this.close(), modalTitle: "Sign transaction", modalSubtitle: `Transaction ${currentIndex + 1} of ${transactionsCount}`, body: isLoading ? (h("div", { class: "loading-spinner" }, h("generic-spinner", null))) : (h(SignScreen, null)) }));
    }
    async nextPage() {
        this.eventBus.publish(SignEventsEnum.NEXT_PAGE);
    }
    async prevPage() {
        this.eventBus.publish(SignEventsEnum.PREV_PAGE);
    }
    close(props = { isUserClick: true }) {
        resetState();
        if (props.isUserClick) {
            this.eventBus.publish(SignEventsEnum.CLOSE);
        }
        if (this.hostElement && this.hostElement.parentNode) {
            this.hostElement.parentNode.removeChild(this.hostElement);
        }
    }
    dataUpdate(payload) {
        this.data = Object.assign({}, payload);
        forceUpdate(this);
    }
    componentDidLoad() {
        this.eventBus.subscribe(SignEventsEnum.DATA_UPDATE, this.dataUpdate.bind(this));
    }
    disconnectedCallback() {
        resetState();
        this.eventBus.unsubscribe(SignEventsEnum.DATA_UPDATE, this.dataUpdate.bind(this));
    }
    get hostElement() { return getElement(this); }
    static get watchers() { return {
        "data": ["onDataChange"]
    }; }
};
SignTransactionsModal.style = SignTransactionsModalStyle0;

export { SignTransactionsModal as sign_transactions_modal };

//# sourceMappingURL=sign-transactions-modal.entry.js.map