'use strict';

var swapModule_entry = require('./swap-module-BZ0C_ywD.js');
var index = require('./index-CAgSYWnN.js');
require('./index-DYShkd_q.js');
var ref = require('./ref-DoziWPoT.js');
require('./index-U1WZx3oG.js');
var HelpersUtil = require('./HelpersUtil-D1BvTuCu.js');
var ifDefined = require('./if-defined-C8-lLqpT.js');
require('./index-l_GugSCx.js');
require('./index-BIxYWQ_d.js');
require('./index-D67PsI9D.js');
require('./index-Mw_M0XDo.js');
require('./index-Bq66f3r7.js');
var NavigationUtil = require('./NavigationUtil-_1tKFceM.js');
require('./index-kE_lp0w-.js');
require('buffer');
require('events');
require('ox');
require('viem');
require('viem/chains');
require('./ConstantsUtil-dVqwYT9_.js');

var styles$5 = swapModule_entry.i$1 `
  div {
    width: 100%;
  }

  [data-ready='false'] {
    transform: scale(1.05);
  }

  @media (max-width: 430px) {
    [data-ready='false'] {
      transform: translateY(-50px);
    }
  }
`;

var __decorate$7 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
const PAGE_HEIGHT = 600;
const PAGE_WIDTH = 360;
const HEADER_HEIGHT = 64;
exports.W3mApproveTransactionView = class W3mApproveTransactionView extends swapModule_entry.i {
    constructor() {
        super();
        this.bodyObserver = undefined;
        this.unsubscribe = [];
        this.iframe = document.getElementById('w3m-iframe');
        this.ready = false;
        this.unsubscribe.push(...[
            swapModule_entry.ModalController.subscribeKey('open', isOpen => {
                if (!isOpen) {
                    this.onHideIframe();
                }
            }),
            swapModule_entry.ModalController.subscribeKey('shake', val => {
                if (val) {
                    this.iframe.style.animation = `w3m-shake 500ms var(--apkt-easings-ease-out-power-2)`;
                }
                else {
                    this.iframe.style.animation = 'none';
                }
            })
        ]);
    }
    disconnectedCallback() {
        this.onHideIframe();
        this.unsubscribe.forEach(unsubscribe => unsubscribe());
        this.bodyObserver?.unobserve(window.document.body);
    }
    async firstUpdated() {
        await this.syncTheme();
        this.iframe.style.display = 'block';
        const container = this?.renderRoot?.querySelector('div');
        this.bodyObserver = new ResizeObserver(entries => {
            const contentBoxSize = entries?.[0]?.contentBoxSize;
            const width = contentBoxSize?.[0]?.inlineSize;
            this.iframe.style.height = `${PAGE_HEIGHT}px`;
            container.style.height = `${PAGE_HEIGHT}px`;
            if (swapModule_entry.OptionsController.state.enableEmbedded) {
                this.updateFrameSizeForEmbeddedMode();
            }
            else if (width && width <= 430) {
                this.iframe.style.width = '100%';
                this.iframe.style.left = '0px';
                this.iframe.style.bottom = '0px';
                this.iframe.style.top = 'unset';
                this.onShowIframe();
            }
            else {
                this.iframe.style.width = `${PAGE_WIDTH}px`;
                this.iframe.style.left = `calc(50% - ${PAGE_WIDTH / 2}px)`;
                this.iframe.style.top = `calc(50% - ${PAGE_HEIGHT / 2}px + ${HEADER_HEIGHT / 2}px)`;
                this.iframe.style.bottom = 'unset';
                this.onShowIframe();
            }
        });
        this.bodyObserver.observe(window.document.body);
    }
    render() {
        return swapModule_entry.b `<div data-ready=${this.ready} id="w3m-frame-container"></div>`;
    }
    onShowIframe() {
        const isMobile = window.innerWidth <= 430;
        this.ready = true;
        this.iframe.style.animation = isMobile
            ? 'w3m-iframe-zoom-in-mobile 200ms var(--apkt-easings-ease-out-power-2)'
            : 'w3m-iframe-zoom-in 200ms var(--apkt-easings-ease-out-power-2)';
    }
    onHideIframe() {
        this.iframe.style.display = 'none';
        this.iframe.style.animation = 'w3m-iframe-fade-out 200ms var(--apkt-easings-ease-out-power-2)';
    }
    async syncTheme() {
        const authConnector = swapModule_entry.ConnectorController.getAuthConnector();
        if (authConnector) {
            const themeMode = swapModule_entry.ThemeController.getSnapshot().themeMode;
            const themeVariables = swapModule_entry.ThemeController.getSnapshot().themeVariables;
            await authConnector.provider.syncTheme({
                themeVariables,
                w3mThemeVariables: swapModule_entry.getW3mThemeVariables(themeVariables, themeMode)
            });
        }
    }
    async updateFrameSizeForEmbeddedMode() {
        const container = this?.renderRoot?.querySelector('div');
        await new Promise(resolve => {
            setTimeout(resolve, 300);
        });
        const rect = this.getBoundingClientRect();
        container.style.width = '100%';
        this.iframe.style.left = `${rect.left}px`;
        this.iframe.style.top = `${rect.top}px`;
        this.iframe.style.width = `${rect.width}px`;
        this.iframe.style.height = `${rect.height}px`;
        this.onShowIframe();
    }
};
exports.W3mApproveTransactionView.styles = styles$5;
__decorate$7([
    index.r()
], exports.W3mApproveTransactionView.prototype, "ready", void 0);
exports.W3mApproveTransactionView = __decorate$7([
    index.customElement('w3m-approve-transaction-view')
], exports.W3mApproveTransactionView);

var styles$4 = swapModule_entry.css `
  a {
    border: none;
    border-radius: ${({ borderRadius }) => borderRadius['20']};
    display: flex;
    flex-direction: row;
    align-items: center;
    padding: ${({ spacing }) => spacing[1]};
    transition:
      background-color ${({ durations }) => durations['lg']}
        ${({ easings }) => easings['ease-out-power-2']},
      box-shadow ${({ durations }) => durations['lg']}
        ${({ easings }) => easings['ease-out-power-2']},
      border ${({ durations }) => durations['lg']} ${({ easings }) => easings['ease-out-power-2']};
    will-change: background-color, box-shadow, border;
  }

  /* -- Variants --------------------------------------------------------------- */
  a[data-type='success'] {
    background-color: ${({ tokens }) => tokens.core.backgroundSuccess};
    color: ${({ tokens }) => tokens.core.textSuccess};
  }

  a[data-type='error'] {
    background-color: ${({ tokens }) => tokens.core.backgroundError};
    color: ${({ tokens }) => tokens.core.textError};
  }

  a[data-type='warning'] {
    background-color: ${({ tokens }) => tokens.core.backgroundWarning};
    color: ${({ tokens }) => tokens.core.textWarning};
  }

  /* -- Sizes --------------------------------------------------------------- */
  a[data-size='sm'] {
    height: 24px;
  }

  a[data-size='md'] {
    height: 28px;
  }

  a[data-size='lg'] {
    height: 32px;
  }

  a[data-size='sm'] > wui-image,
  a[data-size='sm'] > wui-icon {
    width: 16px;
    height: 16px;
  }

  a[data-size='md'] > wui-image,
  a[data-size='md'] > wui-icon {
    width: 20px;
    height: 20px;
  }

  a[data-size='lg'] > wui-image,
  a[data-size='lg'] > wui-icon {
    width: 24px;
    height: 24px;
  }

  wui-text {
    padding-left: ${({ spacing }) => spacing[1]};
    padding-right: ${({ spacing }) => spacing[1]};
  }

  wui-image {
    border-radius: ${({ borderRadius }) => borderRadius[3]};
    overflow: hidden;
    user-drag: none;
    user-select: none;
    -moz-user-select: none;
    -webkit-user-drag: none;
    -webkit-user-select: none;
    -ms-user-select: none;
  }

  /* -- States --------------------------------------------------------------- */
  @media (hover: hover) and (pointer: fine) {
    a[data-type='success']:not(:disabled):hover {
      background-color: ${({ tokens }) => tokens.theme.foregroundPrimary};
      box-shadow: 0px 0px 0px 1px ${({ tokens }) => tokens.core.borderSuccess};
    }

    a[data-type='error']:not(:disabled):hover {
      background-color: ${({ tokens }) => tokens.theme.foregroundPrimary};
      box-shadow: 0px 0px 0px 1px ${({ tokens }) => tokens.core.borderError};
    }

    a[data-type='warning']:not(:disabled):hover {
      background-color: ${({ tokens }) => tokens.theme.foregroundPrimary};
      box-shadow: 0px 0px 0px 1px ${({ tokens }) => tokens.core.borderWarning};
    }
  }

  a[data-type='success']:not(:disabled):focus-visible {
    box-shadow:
      0px 0px 0px 1px ${({ tokens }) => tokens.core.backgroundAccentPrimary},
      0px 0px 0px 4px ${({ tokens }) => tokens.core.foregroundAccent020};
  }

  a[data-type='error']:not(:disabled):focus-visible {
    box-shadow:
      0px 0px 0px 1px ${({ tokens }) => tokens.core.backgroundAccentPrimary},
      0px 0px 0px 4px ${({ tokens }) => tokens.core.foregroundAccent020};
  }

  a[data-type='warning']:not(:disabled):focus-visible {
    box-shadow:
      0px 0px 0px 1px ${({ tokens }) => tokens.core.backgroundAccentPrimary},
      0px 0px 0px 4px ${({ tokens }) => tokens.core.foregroundAccent020};
  }

  a:disabled {
    opacity: 0.5;
  }
`;

var __decorate$6 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
const TEXT_BY_SIZE = {
    sm: 'md-regular',
    md: 'lg-regular',
    lg: 'lg-regular'
};
const ICON_BY_TYPE = {
    success: 'sealCheck',
    error: 'warning',
    warning: 'exclamationCircle'
};
let WuiSemanticChip = class WuiSemanticChip extends swapModule_entry.i {
    constructor() {
        super(...arguments);
        this.type = 'success';
        this.size = 'md';
        this.imageSrc = undefined;
        this.disabled = false;
        this.href = '';
        this.text = undefined;
    }
    render() {
        return swapModule_entry.b `
      <a
        rel="noreferrer"
        target="_blank"
        href=${this.href}
        class=${this.disabled ? 'disabled' : ''}
        data-type=${this.type}
        data-size=${this.size}
      >
        ${this.imageTemplate()}
        <wui-text variant=${TEXT_BY_SIZE[this.size]} color="inherit">${this.text}</wui-text>
      </a>
    `;
    }
    imageTemplate() {
        if (this.imageSrc) {
            return swapModule_entry.b `<wui-image src=${this.imageSrc} size="inherit"></wui-image>`;
        }
        return swapModule_entry.b `<wui-icon
      name=${ICON_BY_TYPE[this.type]}
      weight="fill"
      color="inherit"
      size="inherit"
      class="image-icon"
    ></wui-icon>`;
    }
};
WuiSemanticChip.styles = [swapModule_entry.resetStyles, swapModule_entry.elementStyles, styles$4];
__decorate$6([
    index.n()
], WuiSemanticChip.prototype, "type", void 0);
__decorate$6([
    index.n()
], WuiSemanticChip.prototype, "size", void 0);
__decorate$6([
    index.n()
], WuiSemanticChip.prototype, "imageSrc", void 0);
__decorate$6([
    index.n({ type: Boolean })
], WuiSemanticChip.prototype, "disabled", void 0);
__decorate$6([
    index.n()
], WuiSemanticChip.prototype, "href", void 0);
__decorate$6([
    index.n()
], WuiSemanticChip.prototype, "text", void 0);
WuiSemanticChip = __decorate$6([
    index.customElement('wui-semantic-chip')
], WuiSemanticChip);

var __decorate$5 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
exports.W3mUpgradeWalletView = class W3mUpgradeWalletView extends swapModule_entry.i {
    render() {
        return swapModule_entry.b `
      <wui-flex flexDirection="column" alignItems="center" gap="5" padding="5">
        <wui-text variant="md-regular" color="primary">Follow the instructions on</wui-text>
        <wui-semantic-chip
          icon="externalLink"
          variant="fill"
          text=${swapModule_entry.ConstantsUtil.SECURE_SITE_DASHBOARD}
          href=${swapModule_entry.ConstantsUtil.SECURE_SITE_DASHBOARD}
          imageSrc=${swapModule_entry.ConstantsUtil.SECURE_SITE_FAVICON}
          data-testid="w3m-secure-website-button"
        >
        </wui-semantic-chip>
        <wui-text variant="sm-regular" color="secondary">
          You will have to reconnect for security reasons
        </wui-text>
      </wui-flex>
    `;
    }
};
exports.W3mUpgradeWalletView = __decorate$5([
    index.customElement('w3m-upgrade-wallet-view')
], exports.W3mUpgradeWalletView);

var __decorate$4 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
exports.W3mSmartAccountSettingsView = class W3mSmartAccountSettingsView extends swapModule_entry.i {
    constructor() {
        super(...arguments);
        this.loading = false;
        this.switched = false;
        this.text = '';
        this.network = swapModule_entry.ChainController.state.activeCaipNetwork;
    }
    render() {
        return swapModule_entry.b `
      <wui-flex flexDirection="column" gap="2" .padding=${['6', '4', '3', '4']}>
        ${this.togglePreferredAccountTypeTemplate()} ${this.toggleSmartAccountVersionTemplate()}
      </wui-flex>
    `;
    }
    toggleSmartAccountVersionTemplate() {
        return swapModule_entry.b `
      <w3m-tooltip-trigger text="Changing the smart account version will reload the page">
        <wui-list-item
          icon=${this.isV6() ? 'arrowTop' : 'arrowBottom'}
          ?rounded=${true}
          ?chevron=${true}
          data-testid="account-toggle-smart-account-version"
          @click=${this.toggleSmartAccountVersion.bind(this)}
        >
          <wui-text variant="lg-regular" color="primary"
            >Force Smart Account Version ${this.isV6() ? '7' : '6'}</wui-text
          >
        </wui-list-item>
      </w3m-tooltip-trigger>
    `;
    }
    isV6() {
        const currentVersion = swapModule_entry.W3mFrameStorage.get('dapp_smart_account_version') || 'v6';
        return currentVersion === 'v6';
    }
    toggleSmartAccountVersion() {
        swapModule_entry.W3mFrameStorage.set('dapp_smart_account_version', this.isV6() ? 'v7' : 'v6');
        if (typeof window !== 'undefined') {
            window?.location?.reload();
        }
    }
    togglePreferredAccountTypeTemplate() {
        const namespace = this.network?.chainNamespace;
        const isNetworkEnabled = swapModule_entry.ChainController.checkIfSmartAccountEnabled();
        const connectorId = swapModule_entry.ConnectorController.getConnectorId(namespace);
        const authConnector = swapModule_entry.ConnectorController.getAuthConnector();
        if (!authConnector || connectorId !== swapModule_entry.ConstantsUtil$1.CONNECTOR_ID.AUTH || !isNetworkEnabled) {
            return null;
        }
        if (!this.switched) {
            this.text =
                swapModule_entry.getPreferredAccountType(namespace) === swapModule_entry.W3mFrameRpcConstants.ACCOUNT_TYPES.SMART_ACCOUNT
                    ? 'Switch to your EOA'
                    : 'Switch to your Smart Account';
        }
        return swapModule_entry.b `
      <wui-list-item
        icon="swapHorizontal"
        ?rounded=${true}
        ?chevron=${true}
        ?loading=${this.loading}
        @click=${this.changePreferredAccountType.bind(this)}
        data-testid="account-toggle-preferred-account-type"
      >
        <wui-text variant="lg-regular" color="primary">${this.text}</wui-text>
      </wui-list-item>
    `;
    }
    async changePreferredAccountType() {
        const namespace = this.network?.chainNamespace;
        const isSmartAccountEnabled = swapModule_entry.ChainController.checkIfSmartAccountEnabled();
        const accountTypeTarget = swapModule_entry.getPreferredAccountType(namespace) === swapModule_entry.W3mFrameRpcConstants.ACCOUNT_TYPES.SMART_ACCOUNT ||
            !isSmartAccountEnabled
            ? swapModule_entry.W3mFrameRpcConstants.ACCOUNT_TYPES.EOA
            : swapModule_entry.W3mFrameRpcConstants.ACCOUNT_TYPES.SMART_ACCOUNT;
        const authConnector = swapModule_entry.ConnectorController.getAuthConnector();
        if (!authConnector) {
            return;
        }
        this.loading = true;
        await swapModule_entry.ConnectionController.setPreferredAccountType(accountTypeTarget, namespace);
        this.text =
            accountTypeTarget === swapModule_entry.W3mFrameRpcConstants.ACCOUNT_TYPES.SMART_ACCOUNT
                ? 'Switch to your EOA'
                : 'Switch to your Smart Account';
        this.switched = true;
        swapModule_entry.SendController.resetSend();
        this.loading = false;
        this.requestUpdate();
    }
};
__decorate$4([
    index.r()
], exports.W3mSmartAccountSettingsView.prototype, "loading", void 0);
__decorate$4([
    index.r()
], exports.W3mSmartAccountSettingsView.prototype, "switched", void 0);
__decorate$4([
    index.r()
], exports.W3mSmartAccountSettingsView.prototype, "text", void 0);
__decorate$4([
    index.r()
], exports.W3mSmartAccountSettingsView.prototype, "network", void 0);
exports.W3mSmartAccountSettingsView = __decorate$4([
    index.customElement('w3m-smart-account-settings-view')
], exports.W3mSmartAccountSettingsView);

var styles$3 = swapModule_entry.css `
  :host {
    width: 100%;
  }

  button {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: ${({ tokens }) => tokens.theme.foregroundPrimary};
    border-radius: ${({ borderRadius }) => borderRadius[4]};
    padding: ${({ spacing }) => spacing[4]};
  }

  .name {
    max-width: 75%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  @media (hover: hover) and (pointer: fine) {
    button:hover:enabled {
      cursor: pointer;
      background-color: ${({ tokens }) => tokens.theme.foregroundSecondary};
      border-radius: ${({ borderRadius }) => borderRadius[6]};
    }
  }

  button:disabled {
    opacity: 0.5;
    cursor: default;
  }

  button:focus-visible:enabled {
    box-shadow: 0 0 0 4px ${({ tokens }) => tokens.core.foregroundAccent040};
    background-color: ${({ tokens }) => tokens.theme.foregroundSecondary};
  }
`;

var __decorate$3 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
let WuiAccountNameSuggestionItem = class WuiAccountNameSuggestionItem extends swapModule_entry.i {
    constructor() {
        super(...arguments);
        this.name = '';
        this.registered = false;
        this.loading = false;
        this.disabled = false;
    }
    render() {
        return swapModule_entry.b `
      <button ?disabled=${this.disabled}>
        <wui-text class="name" color="primary" variant="md-regular">${this.name}</wui-text>
        ${this.templateRightContent()}
      </button>
    `;
    }
    templateRightContent() {
        if (this.loading) {
            return swapModule_entry.b `<wui-loading-spinner size="lg" color="primary"></wui-loading-spinner>`;
        }
        return this.registered
            ? swapModule_entry.b `<wui-tag variant="info" size="sm">Registered</wui-tag>`
            : swapModule_entry.b `<wui-tag variant="success" size="sm">Available</wui-tag>`;
    }
};
WuiAccountNameSuggestionItem.styles = [swapModule_entry.resetStyles, swapModule_entry.elementStyles, styles$3];
__decorate$3([
    index.n()
], WuiAccountNameSuggestionItem.prototype, "name", void 0);
__decorate$3([
    index.n({ type: Boolean })
], WuiAccountNameSuggestionItem.prototype, "registered", void 0);
__decorate$3([
    index.n({ type: Boolean })
], WuiAccountNameSuggestionItem.prototype, "loading", void 0);
__decorate$3([
    index.n({ type: Boolean })
], WuiAccountNameSuggestionItem.prototype, "disabled", void 0);
WuiAccountNameSuggestionItem = __decorate$3([
    index.customElement('wui-account-name-suggestion-item')
], WuiAccountNameSuggestionItem);

var styles$2 = swapModule_entry.css `
  :host {
    position: relative;
    width: 100%;
    display: inline-block;
  }

  :host([disabled]) {
    opacity: 0.5;
    cursor: not-allowed;
  }

  .base-name {
    position: absolute;
    right: ${({ spacing }) => spacing[4]};
    top: 50%;
    transform: translateY(-50%);
    text-align: right;
    padding: ${({ spacing }) => spacing[1]};
    background-color: ${({ tokens }) => tokens.theme.foregroundSecondary};
    border-radius: ${({ borderRadius }) => borderRadius[1]};
  }
`;

var __decorate$2 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
let WuiEnsInput = class WuiEnsInput extends swapModule_entry.i {
    constructor() {
        super(...arguments);
        this.disabled = false;
        this.loading = false;
    }
    render() {
        return swapModule_entry.b `
      <wui-input-text
        value=${ifDefined.o(this.value)}
        ?disabled=${this.disabled}
        .value=${this.value || ''}
        data-testid="wui-ens-input"
        icon="search"
        inputRightPadding="5xl"
        .onKeyDown=${this.onKeyDown}
      ></wui-input-text>
    `;
    }
};
WuiEnsInput.styles = [swapModule_entry.resetStyles, styles$2];
__decorate$2([
    index.n()
], WuiEnsInput.prototype, "errorMessage", void 0);
__decorate$2([
    index.n({ type: Boolean })
], WuiEnsInput.prototype, "disabled", void 0);
__decorate$2([
    index.n()
], WuiEnsInput.prototype, "value", void 0);
__decorate$2([
    index.n({ type: Boolean })
], WuiEnsInput.prototype, "loading", void 0);
__decorate$2([
    index.n({ attribute: false })
], WuiEnsInput.prototype, "onKeyDown", void 0);
WuiEnsInput = __decorate$2([
    index.customElement('wui-ens-input')
], WuiEnsInput);

var styles$1 = swapModule_entry.css `
  wui-flex {
    width: 100%;
  }

  .suggestion {
    background-color: ${({ tokens }) => tokens.theme.foregroundPrimary};
    border-radius: ${({ borderRadius }) => borderRadius[4]};
  }

  .suggestion:hover:not(:disabled) {
    cursor: pointer;
    border: none;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: ${({ tokens }) => tokens.theme.foregroundSecondary};
    border-radius: ${({ borderRadius }) => borderRadius[6]};
    padding: ${({ spacing }) => spacing[4]};
  }

  .suggestion:disabled {
    opacity: 0.5;
    cursor: default;
  }

  .suggestion:focus-visible:not(:disabled) {
    box-shadow: 0 0 0 4px ${({ tokens }) => tokens.core.foregroundAccent040};
    background-color: ${({ tokens }) => tokens.theme.foregroundSecondary};
  }

  .suggested-name {
    max-width: 75%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  form {
    width: 100%;
    position: relative;
  }

  .input-submit-button,
  .input-loading-spinner {
    position: absolute;
    top: 22px;
    transform: translateY(-50%);
    right: 10px;
  }
`;

var __decorate$1 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
exports.W3mRegisterAccountNameView = class W3mRegisterAccountNameView extends swapModule_entry.i {
    constructor() {
        super();
        this.formRef = ref.e();
        this.usubscribe = [];
        this.name = '';
        this.error = '';
        this.loading = swapModule_entry.EnsController.state.loading;
        this.suggestions = swapModule_entry.EnsController.state.suggestions;
        this.profileName = swapModule_entry.ChainController.getAccountData()?.profileName;
        this.onDebouncedNameInputChange = swapModule_entry.CoreHelperUtil.debounce((value) => {
            if (value.length < 4) {
                this.error = 'Name must be at least 4 characters long';
            }
            else if (!HelpersUtil.HelpersUtil.isValidReownName(value)) {
                this.error = 'The value is not a valid username';
            }
            else {
                this.error = '';
                swapModule_entry.EnsController.getSuggestions(value);
            }
        });
        this.usubscribe.push(...[
            swapModule_entry.EnsController.subscribe(val => {
                this.suggestions = val.suggestions;
                this.loading = val.loading;
            }),
            swapModule_entry.ChainController.subscribeChainProp('accountState', val => {
                this.profileName = val?.profileName;
                if (val?.profileName) {
                    this.error = 'You already own a name';
                }
            })
        ]);
    }
    firstUpdated() {
        this.formRef.value?.addEventListener('keydown', this.onEnterKey.bind(this));
    }
    disconnectedCallback() {
        super.disconnectedCallback();
        this.usubscribe.forEach(unsub => unsub());
        this.formRef.value?.removeEventListener('keydown', this.onEnterKey.bind(this));
    }
    render() {
        return swapModule_entry.b `
      <wui-flex
        flexDirection="column"
        alignItems="center"
        gap="4"
        .padding=${['1', '3', '4', '3']}
      >
        <form ${ref.n(this.formRef)} @submit=${this.onSubmitName.bind(this)}>
          <wui-ens-input
            @inputChange=${this.onNameInputChange.bind(this)}
            .errorMessage=${this.error}
            .value=${this.name}
            .onKeyDown=${this.onKeyDown.bind(this)}
          >
          </wui-ens-input>
          ${this.submitButtonTemplate()}
          <input type="submit" hidden />
        </form>
        ${this.templateSuggestions()}
      </wui-flex>
    `;
    }
    submitButtonTemplate() {
        const isRegistered = this.suggestions.find(s => s.name?.split('.')?.[0] === this.name && s.registered);
        if (this.loading) {
            return swapModule_entry.b `<wui-loading-spinner
        class="input-loading-spinner"
        color="secondary"
      ></wui-loading-spinner>`;
        }
        const reownName = `${this.name}${swapModule_entry.ConstantsUtil$1.WC_NAME_SUFFIX}`;
        return swapModule_entry.b `
      <wui-icon-link
        ?disabled=${Boolean(isRegistered)}
        class="input-submit-button"
        size="sm"
        icon="chevronRight"
        iconColor=${isRegistered ? 'default' : 'accent-primary'}
        @click=${() => this.onSubmitName(reownName)}
      >
      </wui-icon-link>
    `;
    }
    onNameInputChange(event) {
        const value = HelpersUtil.HelpersUtil.validateReownName(event.detail || '');
        this.name = value;
        this.onDebouncedNameInputChange(value);
    }
    onKeyDown(event) {
        if (event.key.length === 1 && !HelpersUtil.HelpersUtil.isValidReownName(event.key)) {
            event.preventDefault();
        }
    }
    templateSuggestions() {
        if (!this.name || this.name.length < 4 || this.error) {
            return null;
        }
        return swapModule_entry.b `<wui-flex flexDirection="column" gap="1" alignItems="center">
      ${this.suggestions.map(suggestion => swapModule_entry.b `<wui-account-name-suggestion-item
            name=${suggestion.name}
            ?registered=${suggestion.registered}
            ?loading=${this.loading}
            ?disabled=${suggestion.registered || this.loading}
            data-testid="account-name-suggestion"
            @click=${() => this.onSubmitName(suggestion.name)}
          ></wui-account-name-suggestion-item>`)}
    </wui-flex>`;
    }
    isAllowedToSubmit(name) {
        const pureName = name.split('.')?.[0];
        const isRegistered = this.suggestions.find(s => s.name?.split('.')?.[0] === pureName && s.registered);
        return (!this.loading &&
            !this.error &&
            !this.profileName &&
            pureName &&
            swapModule_entry.EnsController.validateName(pureName) &&
            !isRegistered);
    }
    async onSubmitName(name) {
        try {
            if (!this.isAllowedToSubmit(name)) {
                return;
            }
            swapModule_entry.EventsController.sendEvent({
                type: 'track',
                event: 'REGISTER_NAME_INITIATED',
                properties: {
                    isSmartAccount: swapModule_entry.getPreferredAccountType(swapModule_entry.ChainController.state.activeChain) ===
                        swapModule_entry.W3mFrameRpcConstants.ACCOUNT_TYPES.SMART_ACCOUNT,
                    ensName: name
                }
            });
            await swapModule_entry.EnsController.registerName(name);
            swapModule_entry.EventsController.sendEvent({
                type: 'track',
                event: 'REGISTER_NAME_SUCCESS',
                properties: {
                    isSmartAccount: swapModule_entry.getPreferredAccountType(swapModule_entry.ChainController.state.activeChain) ===
                        swapModule_entry.W3mFrameRpcConstants.ACCOUNT_TYPES.SMART_ACCOUNT,
                    ensName: name
                }
            });
        }
        catch (error) {
            swapModule_entry.SnackController.showError(error.message);
            swapModule_entry.EventsController.sendEvent({
                type: 'track',
                event: 'REGISTER_NAME_ERROR',
                properties: {
                    isSmartAccount: swapModule_entry.getPreferredAccountType(swapModule_entry.ChainController.state.activeChain) ===
                        swapModule_entry.W3mFrameRpcConstants.ACCOUNT_TYPES.SMART_ACCOUNT,
                    ensName: name,
                    error: swapModule_entry.CoreHelperUtil.parseError(error)
                }
            });
        }
    }
    onEnterKey(event) {
        if (event.key === 'Enter' && this.name && this.isAllowedToSubmit(this.name)) {
            const reownName = `${this.name}${swapModule_entry.ConstantsUtil$1.WC_NAME_SUFFIX}`;
            this.onSubmitName(reownName);
        }
    }
};
exports.W3mRegisterAccountNameView.styles = styles$1;
__decorate$1([
    index.n()
], exports.W3mRegisterAccountNameView.prototype, "errorMessage", void 0);
__decorate$1([
    index.r()
], exports.W3mRegisterAccountNameView.prototype, "name", void 0);
__decorate$1([
    index.r()
], exports.W3mRegisterAccountNameView.prototype, "error", void 0);
__decorate$1([
    index.r()
], exports.W3mRegisterAccountNameView.prototype, "loading", void 0);
__decorate$1([
    index.r()
], exports.W3mRegisterAccountNameView.prototype, "suggestions", void 0);
__decorate$1([
    index.r()
], exports.W3mRegisterAccountNameView.prototype, "profileName", void 0);
exports.W3mRegisterAccountNameView = __decorate$1([
    index.customElement('w3m-register-account-name-view')
], exports.W3mRegisterAccountNameView);

var styles = swapModule_entry.i$1 `
  .continue-button-container {
    width: 100%;
  }
`;

var __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
exports.W3mRegisterAccountNameSuccess = class W3mRegisterAccountNameSuccess extends swapModule_entry.i {
    render() {
        return swapModule_entry.b `
      <wui-flex
        flexDirection="column"
        alignItems="center"
        gap="6"
        .padding=${['0', '0', '4', '0']}
      >
        ${this.onboardingTemplate()} ${this.buttonsTemplate()}
        <wui-link
          @click=${() => {
            swapModule_entry.CoreHelperUtil.openHref(NavigationUtil.NavigationUtil.URLS.FAQ, '_blank');
        }}
        >
          Learn more
          <wui-icon color="inherit" slot="iconRight" name="externalLink"></wui-icon>
        </wui-link>
      </wui-flex>
    `;
    }
    onboardingTemplate() {
        return swapModule_entry.b ` <wui-flex
      flexDirection="column"
      gap="6"
      alignItems="center"
      .padding=${['0', '6', '0', '6']}
    >
      <wui-flex gap="3" alignItems="center" justifyContent="center">
        <wui-icon-box size="xl" color="success" icon="checkmark"></wui-icon-box>
      </wui-flex>
      <wui-flex flexDirection="column" alignItems="center" gap="3">
        <wui-text align="center" variant="md-medium" color="primary">
          Account name chosen successfully
        </wui-text>
        <wui-text align="center" variant="md-regular" color="primary">
          You can now fund your account and trade crypto
        </wui-text>
      </wui-flex>
    </wui-flex>`;
    }
    buttonsTemplate() {
        return swapModule_entry.b `<wui-flex
      .padding=${['0', '4', '0', '4']}
      gap="3"
      class="continue-button-container"
    >
      <wui-button fullWidth size="lg" borderRadius="xs" @click=${this.redirectToAccount.bind(this)}
        >Let's Go!
      </wui-button>
    </wui-flex>`;
    }
    redirectToAccount() {
        swapModule_entry.RouterController.replace('Account');
    }
};
exports.W3mRegisterAccountNameSuccess.styles = styles;
exports.W3mRegisterAccountNameSuccess = __decorate([
    index.customElement('w3m-register-account-name-success-view')
], exports.W3mRegisterAccountNameSuccess);
//# sourceMappingURL=embedded-wallet-C8w-SvwT.js.map

//# sourceMappingURL=embedded-wallet-C8w-SvwT.js.map