import { n as css, o as resetStyles, q as elementStyles, t as i, u as b, C as ChainController, S as SnackController, Q as AssetUtil, T as ThemeController, D as getPreferredAccountType, W as W3mFrameRpcConstants, R as RouterController, d as CoreHelperUtil } from './swap-module.js';
import { n, c as customElement, U as UiHelperUtil, r } from './p-Df1VvUwe.js';
import { o } from './p-lzr5ON0W.js';
import './p-D-0egaYJ.js';
import './p-D_dKTVNG.js';

var styles$1 = css `
  button {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: ${({ spacing }) => spacing[4]};
    background-color: ${({ tokens }) => tokens.theme.foregroundPrimary};
    border-radius: ${({ borderRadius }) => borderRadius[3]};
    border: none;
    padding: ${({ spacing }) => spacing[3]};
    transition: background-color ${({ durations }) => durations['lg']}
      ${({ easings }) => easings['ease-out-power-2']};
    will-change: background-color;
  }

  /* -- Hover & Active states ----------------------------------------------------------- */
  button:hover:enabled,
  button:active:enabled {
    background-color: ${({ tokens }) => tokens.theme.foregroundSecondary};
  }

  wui-text {
    flex: 1;
    color: ${({ tokens }) => tokens.theme.textSecondary};
  }

  wui-flex {
    width: auto;
    display: flex;
    align-items: center;
    gap: ${({ spacing }) => spacing['01']};
  }

  wui-icon {
    color: ${({ tokens }) => tokens.theme.iconDefault};
  }

  .network-icon {
    position: relative;
    width: 20px;
    height: 20px;
    border-radius: ${({ borderRadius }) => borderRadius[4]};
    overflow: hidden;
    margin-left: -8px;
  }

  .network-icon:first-child {
    margin-left: 0px;
  }

  .network-icon:after {
    position: absolute;
    inset: 0;
    content: '';
    display: block;
    height: 100%;
    width: 100%;
    border-radius: ${({ borderRadius }) => borderRadius[4]};
    box-shadow: inset 0 0 0 1px ${({ tokens }) => tokens.core.glass010};
  }
`;

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;
};
let WuiCompatibleNetwork = class WuiCompatibleNetwork extends i {
    constructor() {
        super(...arguments);
        this.networkImages = [''];
        this.text = '';
    }
    render() {
        return b `
      <button>
        <wui-text variant="md-regular" color="inherit">${this.text}</wui-text>
        <wui-flex>
          ${this.networksTemplate()}
          <wui-icon name="chevronRight" size="sm" color="inherit"></wui-icon>
        </wui-flex>
      </button>
    `;
    }
    networksTemplate() {
        const slicedNetworks = this.networkImages.slice(0, 5);
        return b ` <wui-flex class="networks">
      ${slicedNetworks?.map(network => b ` <wui-flex class="network-icon"> <wui-image src=${network}></wui-image> </wui-flex>`)}
    </wui-flex>`;
    }
};
WuiCompatibleNetwork.styles = [resetStyles, elementStyles, styles$1];
__decorate$1([
    n({ type: Array })
], WuiCompatibleNetwork.prototype, "networkImages", void 0);
__decorate$1([
    n()
], WuiCompatibleNetwork.prototype, "text", void 0);
WuiCompatibleNetwork = __decorate$1([
    customElement('wui-compatible-network')
], WuiCompatibleNetwork);

var styles = css `
  wui-compatible-network {
    margin-top: ${({ spacing }) => spacing['4']};
    width: 100%;
  }

  wui-qr-code {
    width: unset !important;
    height: unset !important;
  }

  wui-icon {
    align-items: normal;
  }
`;

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;
};
let W3mWalletReceiveView = class W3mWalletReceiveView extends i {
    constructor() {
        super();
        this.unsubscribe = [];
        this.address = ChainController.getAccountData()?.address;
        this.profileName = ChainController.getAccountData()?.profileName;
        this.network = ChainController.state.activeCaipNetwork;
        this.unsubscribe.push(...[
            ChainController.subscribeChainProp('accountState', val => {
                if (val) {
                    this.address = val.address;
                    this.profileName = val.profileName;
                }
                else {
                    SnackController.showError('Account not found');
                }
            })
        ], ChainController.subscribeKey('activeCaipNetwork', val => {
            if (val?.id) {
                this.network = val;
            }
        }));
    }
    disconnectedCallback() {
        this.unsubscribe.forEach(unsubscribe => unsubscribe());
    }
    render() {
        if (!this.address) {
            throw new Error('w3m-wallet-receive-view: No account provided');
        }
        const networkImage = AssetUtil.getNetworkImage(this.network);
        return b ` <wui-flex
      flexDirection="column"
      .padding=${['0', '4', '4', '4']}
      alignItems="center"
    >
      <wui-chip-button
        data-testid="receive-address-copy-button"
        @click=${this.onCopyClick.bind(this)}
        text=${UiHelperUtil.getTruncateString({
            string: this.profileName || this.address || '',
            charsStart: this.profileName ? 18 : 4,
            charsEnd: this.profileName ? 0 : 4,
            truncate: this.profileName ? 'end' : 'middle'
        })}
        icon="copy"
        size="sm"
        imageSrc=${networkImage ? networkImage : ''}
        variant="gray"
      ></wui-chip-button>
      <wui-flex
        flexDirection="column"
        .padding=${['4', '0', '0', '0']}
        alignItems="center"
        gap="4"
      >
        <wui-qr-code
          size=${232}
          theme=${ThemeController.state.themeMode}
          uri=${this.address}
          ?arenaClear=${true}
          color=${o(ThemeController.state.themeVariables['--apkt-qr-color'] ??
            ThemeController.state.themeVariables['--w3m-qr-color'])}
          data-testid="wui-qr-code"
        ></wui-qr-code>
        <wui-text variant="lg-regular" color="primary" align="center">
          Copy your address or scan this QR code
        </wui-text>
        <wui-button @click=${this.onCopyClick.bind(this)} size="sm" variant="neutral-secondary">
          <wui-icon slot="iconLeft" size="sm" color="inherit" name="copy"></wui-icon>
          <wui-text variant="md-regular" color="inherit">Copy address</wui-text>
        </wui-button>
      </wui-flex>
      ${this.networkTemplate()}
    </wui-flex>`;
    }
    networkTemplate() {
        const requestedCaipNetworks = ChainController.getAllRequestedCaipNetworks();
        const isNetworkEnabledForSmartAccounts = ChainController.checkIfSmartAccountEnabled();
        const caipNetwork = ChainController.state.activeCaipNetwork;
        const namespaceNetworks = requestedCaipNetworks.filter(network => network?.chainNamespace === caipNetwork?.chainNamespace);
        if (getPreferredAccountType(caipNetwork?.chainNamespace) ===
            W3mFrameRpcConstants.ACCOUNT_TYPES.SMART_ACCOUNT &&
            isNetworkEnabledForSmartAccounts) {
            if (!caipNetwork) {
                return null;
            }
            return b `<wui-compatible-network
        @click=${this.onReceiveClick.bind(this)}
        text="Only receive assets on this network"
        .networkImages=${[AssetUtil.getNetworkImage(caipNetwork) ?? '']}
      ></wui-compatible-network>`;
        }
        const slicedNetworks = namespaceNetworks
            ?.filter(network => network?.assets?.imageId)
            ?.slice(0, 5);
        const imagesArray = slicedNetworks.map(AssetUtil.getNetworkImage).filter(Boolean);
        return b `<wui-compatible-network
      @click=${this.onReceiveClick.bind(this)}
      text="Only receive assets on these networks"
      .networkImages=${imagesArray}
    ></wui-compatible-network>`;
    }
    onReceiveClick() {
        RouterController.push('WalletCompatibleNetworks');
    }
    onCopyClick() {
        try {
            if (this.address) {
                CoreHelperUtil.copyToClopboard(this.address);
                SnackController.showSuccess('Address copied');
            }
        }
        catch {
            SnackController.showError('Failed to copy');
        }
    }
};
W3mWalletReceiveView.styles = styles;
__decorate([
    r()
], W3mWalletReceiveView.prototype, "address", void 0);
__decorate([
    r()
], W3mWalletReceiveView.prototype, "profileName", void 0);
__decorate([
    r()
], W3mWalletReceiveView.prototype, "network", void 0);
W3mWalletReceiveView = __decorate([
    customElement('w3m-wallet-receive-view')
], W3mWalletReceiveView);

export { W3mWalletReceiveView };
//# sourceMappingURL=p-CM4dH2pC.js.map

//# sourceMappingURL=p-CM4dH2pC.js.map