import { r as registerInstance, f as forceUpdate, h, g as getElement } from './index-DeR7QOsF.js';
import { E as EventBus } from './EventBus-S9juR7eS.js';

var LedgerConnectEventsEnum;
(function (LedgerConnectEventsEnum) {
    LedgerConnectEventsEnum["CONNECT_DEVICE"] = "CONNECT_DEVICE";
    LedgerConnectEventsEnum["ACCESS_WALLET"] = "ACCESS_WALLET";
    LedgerConnectEventsEnum["GO_TO_PAGE"] = "GO_TO_PAGE";
    LedgerConnectEventsEnum["CLOSE_LEDGER_CONNECT_PANEL"] = "CLOSE_LEDGER_CONNECT_PANEL";
    LedgerConnectEventsEnum["OPEN_LEDGER_CONNECT_PANEL"] = "OPEN_LEDGER_CONNECT_PANEL";
    LedgerConnectEventsEnum["DATA_UPDATE"] = "DATA_UPDATE";
    LedgerConnectEventsEnum["UI_DISCONNECTED"] = "UI_DISCONNECTED";
})(LedgerConnectEventsEnum || (LedgerConnectEventsEnum = {}));

const getLedgerAddressByIndex = ({ accounts, selectedIndex }) => { var _a; return ((_a = accounts === null || accounts === void 0 ? void 0 : accounts.find(({ index }) => index === selectedIndex)) === null || _a === void 0 ? void 0 : _a.address) || ''; };
class LedgerConnectBase {
    constructor(data) {
        this.data = data;
        this.eventBus = new EventBus();
        this.selectedIndex = 0;
        this.selectedAddress = '';
    }
    getEventBus() {
        return this.eventBus;
    }
    accessWallet() {
        var _a;
        this.eventBus.publish(LedgerConnectEventsEnum.ACCESS_WALLET, {
            addressIndex: this.selectedIndex,
            selectedAddress: this.selectedAddress || getLedgerAddressByIndex({ accounts: (_a = this.data.accountScreenData) === null || _a === void 0 ? void 0 : _a.accounts, selectedIndex: this.selectedIndex }),
        });
    }
    selectAccount(index) {
        var _a;
        this.selectedIndex = index;
        this.selectedAddress = getLedgerAddressByIndex({ accounts: (_a = this.data.accountScreenData) === null || _a === void 0 ? void 0 : _a.accounts, selectedIndex: this.selectedIndex });
    }
    goToPage(page) {
        this.eventBus.publish(LedgerConnectEventsEnum.GO_TO_PAGE, page);
    }
    subscribeEventBus({ closeFn, forceUpdateFn }) {
        this.eventBus.subscribe(LedgerConnectEventsEnum.DATA_UPDATE, (payload) => this.dataUpdate({ payload, closeFn, forceUpdateFn }));
    }
    unsubscribeEventBus({ closeFn, forceUpdateFn }) {
        this.eventBus.unsubscribe(LedgerConnectEventsEnum.DATA_UPDATE, (payload) => this.dataUpdate({ payload, closeFn, forceUpdateFn }));
    }
    dataUpdate({ payload, closeFn, forceUpdateFn }) {
        if (payload.shouldClose) {
            return closeFn();
        }
        this.data = Object.assign({}, payload);
        forceUpdateFn();
    }
}

const ledgerFlowCss = "/*! tailwindcss v4.1.3 | MIT License | https://tailwindcss.com */@layer theme{:host,:root{--mvx-font-sans:ui-sans-serif,system-ui,sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\",\"Segoe UI Symbol\",\"Noto Color Emoji\";--mvx-font-mono:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,\"Liberation Mono\",\"Courier New\",monospace;--mvx-default-font-family:var(--mvx-font-sans);--mvx-default-mono-font-family:var(--mvx-font-mono)}}@layer base{*,::backdrop,:after,:before{border:0 solid;box-sizing:border-box;margin:0;padding:0}::file-selector-button{appearance:button;background-color:#0000;border:0 solid;border-radius:0;box-sizing:border-box;color:inherit;font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;margin:0;margin-inline-end:4px;opacity:1;padding:0}:host,html{-webkit-text-size-adjust:100%;font-family:var(--mvx-default-font-family,ui-sans-serif,system-ui,sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\",\"Segoe UI Symbol\",\"Noto Color Emoji\");font-feature-settings:var(--mvx-default-font-feature-settings,normal);font-variation-settings:var(--mvx-default-font-variation-settings,normal);line-height:1.5;tab-size:4;-webkit-tap-highlight-color:transparent}hr{border-top-width:1px;color:inherit;height:0}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;-webkit-text-decoration:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,pre,samp{font-family:var(--mvx-default-mono-font-family,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,\"Liberation Mono\",\"Courier New\",monospace);font-feature-settings:var(--mvx-default-mono-font-feature-settings,normal);font-size:1em;font-variation-settings:var(--mvx-default-mono-font-variation-settings,normal)}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{border-collapse:collapse;border-color:inherit;text-indent:0}:-moz-focusring{outline:auto}progress{vertical-align:baseline}summary{display:list-item}menu,ol,ul{list-style:none}audio,canvas,embed,iframe,img,object,svg,video{display:block;vertical-align:middle}img,video{height:auto;max-width:100%}button,input,optgroup,select,textarea{background-color:#0000;border-radius:0;color:inherit;font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;opacity:1}:where(select:is([multiple],[size])) optgroup{font-weight:bolder}:where(select:is([multiple],[size])) optgroup option{padding-inline-start:20px}::placeholder{opacity:1}@supports (not ((-webkit-appearance:-apple-pay-button))) or (contain-intrinsic-size:1px){::placeholder{color:currentColor}@supports (color:color-mix(in lab,red,red)){::placeholder{color:color-mix(in oklab,currentColor 50%,transparent)}}}textarea{resize:vertical}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-date-and-time-value{min-height:1lh;text-align:inherit}::-webkit-datetime-edit{display:inline-flex;padding-block:0}::-webkit-datetime-edit-fields-wrapper{padding:0}::-webkit-datetime-edit-month-field,::-webkit-datetime-edit-year-field{padding-block:0}::-webkit-datetime-edit-day-field,::-webkit-datetime-edit-hour-field{padding-block:0}::-webkit-datetime-edit-minute-field,::-webkit-datetime-edit-second-field{padding-block:0}::-webkit-datetime-edit-meridiem-field,::-webkit-datetime-edit-millisecond-field{padding-block:0}:-moz-ui-invalid{box-shadow:none}button,input:where([type=button],[type=reset],[type=submit]){appearance:button}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[hidden]:where(:not([hidden=until-found])){display:none!important}}@layer components,utilities; /*! tailwindcss v4.1.3 | MIT License | https://tailwindcss.com */@layer base{}@layer components,utilities; /*! tailwindcss v4.1.3 | MIT License | https://tailwindcss.com */@layer base{}@layer components,utilities; /*! tailwindcss v4.1.3 | MIT License | https://tailwindcss.com */@layer base{}@layer components,utilities; /*! tailwindcss v4.1.3 | MIT License | https://tailwindcss.com */@layer base{}@layer components,utilities; /*! tailwindcss v4.1.3 | MIT License | https://tailwindcss.com */@layer base{}@layer components,utilities; /*! tailwindcss v4.1.3 | MIT License | https://tailwindcss.com */@layer base{}@layer components,utilities; /*! tailwindcss v4.1.3 | MIT License | https://tailwindcss.com */@layer base{}@layer components,utilities; /*! tailwindcss v4.1.3 | MIT License | https://tailwindcss.com */@layer base{}@layer components,utilities; /*! tailwindcss v4.1.3 | MIT License | https://tailwindcss.com */@layer base{}@layer components,utilities; /*! tailwindcss v4.1.3 | MIT License | https://tailwindcss.com */@layer base{}@layer components,utilities; /*! tailwindcss v4.1.3 | MIT License | https://tailwindcss.com */@layer base{}@layer components,utilities;:host{display:flex;flex:1;flex-direction:column}";

const LedgerFlow = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.selectedIndex = 0;
        this.data = {
            accountScreenData: null,
            confirmScreenData: null,
            connectScreenData: {},
        };
    }
    async getEventBus() {
        return this.ledgerConnectBase.getEventBus();
    }
    selectAccount(index) {
        this.ledgerConnectBase.selectAccount(index);
        this.selectedIndex = this.ledgerConnectBase.selectedIndex;
    }
    removeComponent() {
        var _a;
        if ((_a = this.hostElement) === null || _a === void 0 ? void 0 : _a.parentNode) {
            this.hostElement.parentNode.removeChild(this.hostElement);
        }
    }
    getEventSubscription() {
        return {
            closeFn: () => this.removeComponent(),
            forceUpdateFn: () => {
                this.data = this.ledgerConnectBase.data;
                forceUpdate(this);
            },
        };
    }
    componentWillLoad() {
        this.ledgerConnectBase = new LedgerConnectBase(this.data);
    }
    componentDidLoad() {
        this.ledgerConnectBase.subscribeEventBus(this.getEventSubscription());
    }
    disconnectedCallback() {
        this.ledgerConnectBase.eventBus.publish(LedgerConnectEventsEnum.UI_DISCONNECTED);
        this.ledgerConnectBase.unsubscribeEventBus(this.getEventSubscription());
    }
    handleIntroConnect(event) {
        event.preventDefault();
        this.ledgerConnectBase.eventBus.publish(LedgerConnectEventsEnum.CONNECT_DEVICE);
    }
    render() {
        if (this.data.accountScreenData) {
            return (h("mvx-ledger-addresses", { selectedIndex: this.selectedIndex, accountScreenData: this.data.accountScreenData, onAccessWallet: () => this.ledgerConnectBase.accessWallet(), onSelectAccount: (event) => this.selectAccount(event.detail), onPageChange: (event) => this.ledgerConnectBase.goToPage(event.detail) }));
        }
        if (this.data.confirmScreenData) {
            return h("mvx-ledger-confirm", { confirmScreenData: this.data.confirmScreenData });
        }
        return h("mvx-ledger-intro", { connectScreenData: this.data.connectScreenData, onConnect: this.handleIntroConnect.bind(this) });
    }
    get hostElement() { return getElement(this); }
};
LedgerFlow.style = ledgerFlowCss;

export { LedgerFlow as mvx_ledger_flow };
//# sourceMappingURL=mvx-ledger-flow.entry.js.map

//# sourceMappingURL=mvx-ledger-flow.entry.js.map