'use strict';

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

const index = require('./index-14914b7b.js');
const EventBus = require('./EventBus-1890a8f3.js');
const signTransactionsModalStore = require('./signTransactionsModalStore-e69ee459.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) {
        index.registerInstance(this, hostRef);
        this.eventBus = new EventBus.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(signTransactionsModalStore.state, key)) {
                signTransactionsModalStore.state[key] = data[key];
            }
        }
        signTransactionsModalStore.state.isWaitingForSignature = false;
        signTransactionsModalStore.state.isLoading = false;
    }
    componentWillLoad() {
        signTransactionsModalStore.state.onSign = () => {
            signTransactionsModalStore.state.isWaitingForSignature = true;
            this.eventBus.publish(SignEventsEnum.SIGN_TRANSACTION);
        };
    }
    render() {
        const { commonData, isLoading } = signTransactionsModalStore.state;
        const { tokenType, currentIndex, transactionsCount } = commonData;
        const SignScreen = signScreens[tokenType];
        return (index.h("generic-modal", { key: '8a5f8ec8c062fb6d1e99965dbbff6332000bad57', onClose: () => this.close(), modalTitle: "Sign transaction", modalSubtitle: `Transaction ${currentIndex + 1} of ${transactionsCount}`, body: isLoading ? (index.h("div", { class: "loading-spinner" }, index.h("generic-spinner", null))) : (index.h(SignScreen, null)) }));
    }
    async nextPage() {
        this.eventBus.publish(SignEventsEnum.NEXT_PAGE);
    }
    async prevPage() {
        this.eventBus.publish(SignEventsEnum.PREV_PAGE);
    }
    close(props = { isUserClick: true }) {
        signTransactionsModalStore.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);
        index.forceUpdate(this);
    }
    componentDidLoad() {
        this.eventBus.subscribe(SignEventsEnum.DATA_UPDATE, this.dataUpdate.bind(this));
    }
    disconnectedCallback() {
        signTransactionsModalStore.resetState();
        this.eventBus.unsubscribe(SignEventsEnum.DATA_UPDATE, this.dataUpdate.bind(this));
    }
    get hostElement() { return index.getElement(this); }
    static get watchers() { return {
        "data": ["onDataChange"]
    }; }
};
SignTransactionsModal.style = SignTransactionsModalStyle0;

exports.sign_transactions_modal = SignTransactionsModal;

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