'use strict';

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

const index = require('./index-9564483d.js');
const dataTestIds_enum = require('./dataTestIds.enum-f00213b8.js');
const LedgerConnectBase = require('./LedgerConnectBase-6b394ac2.js');
require('./EventBus-1890a8f3.js');

const LedgerConnectModal = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.data = {
            accountScreenData: null,
            confirmScreenData: null,
            connectScreenData: {},
        };
        this.selectedIndex = 0;
        this.getModalProps = () => {
            const { accountScreenData, confirmScreenData, connectScreenData } = this.data;
            if (accountScreenData) {
                return {
                    modalTitle: index.h("div", { "data-testid": `${dataTestIds_enum.DataTestIdsEnum.addressTableContainer}Title` }, "Access your wallet"),
                    modalSubtitle: index.h("div", { "data-testid": `${dataTestIds_enum.DataTestIdsEnum.addressTableContainer}SubTitle` }, "Choose the wallet you want to access"),
                    body: (index.h("ledger-account-screen", { accountScreenData: accountScreenData, selectedIndex: this.selectedIndex, onSelectAccount: (event) => this.selectAccount(event.detail), onAccessWallet: () => this.accessWallet(), onPrevPage: () => this.prevPage(), onNextPage: () => this.nextPage() })),
                };
            }
            if (confirmScreenData) {
                return {
                    modalTitle: 'Confirm',
                    modalSubtitle: 'Confirm Ledger Address',
                    body: index.h("ledger-confirm-screen", { confirmScreenData: confirmScreenData }),
                };
            }
            return {
                modalTitle: 'Connect Ledger',
                modalSubtitle: 'Unlock your device & open the MultiversX App',
                body: index.h("ledger-connect-screen", { connectScreenData: connectScreenData, onConnect: () => this.ledgerConnectBase.eventBus.publish(LedgerConnectBase.LedgerConnectEventsEnum.CONNECT_DEVICE) }),
            };
        };
    }
    componentWillLoad() {
        this.ledgerConnectBase = new LedgerConnectBase.LedgerConnectBase(this.data);
    }
    async getEventBus() {
        return this.ledgerConnectBase.getEventBus();
    }
    render() {
        const modalProps = this.getModalProps();
        return index.h("generic-modal", Object.assign({ key: 'd01d92ca0fcc5501f254543498ab565ce2007361' }, modalProps, { onClose: () => this.close() }));
    }
    accessWallet() {
        this.ledgerConnectBase.accessWallet();
    }
    selectAccount(index) {
        this.ledgerConnectBase.selectAccount(index);
        // this is needed for the UI to be reactive
        this.selectedIndex = this.ledgerConnectBase.selectedIndex;
    }
    async nextPage() {
        this.ledgerConnectBase.nextPage();
    }
    async prevPage() {
        this.ledgerConnectBase.prevPage();
    }
    close(props = { isUserClick: true }) {
        var _a;
        if (props.isUserClick) {
            this.ledgerConnectBase.eventBus.publish(LedgerConnectBase.LedgerConnectEventsEnum.CLOSE);
        }
        if ((_a = this.hostElement) === null || _a === void 0 ? void 0 : _a.parentNode) {
            this.hostElement.parentNode.removeChild(this.hostElement);
        }
    }
    componentDidLoad() {
        this.ledgerConnectBase.subscribeEventBus({
            closeFn: () => this.close({ isUserClick: false }),
            forceUpdateFn: () => {
                // this is needed for the UI to be reactive
                this.data = this.ledgerConnectBase.data;
                index.forceUpdate(this);
            },
        });
    }
    disconnectedCallback() {
        this.ledgerConnectBase.unsubscribeEventBus({
            closeFn: () => this.close({ isUserClick: false }),
            forceUpdateFn: () => {
                // this is needed for the UI to be reactive
                this.data = this.ledgerConnectBase.data;
                index.forceUpdate(this);
            },
        });
    }
    get hostElement() { return index.getElement(this); }
};

exports.ledger_connect_modal = LedgerConnectModal;

//# sourceMappingURL=ledger-connect-modal.cjs.entry.js.map