import { jsx as r, jsxs as y } from "react/jsx-runtime";
import { useState as I, useEffect as u, useMemo as R } from "react";
import { b as N, G as O, n as U, c as j, v as C, S as x } from "../../config-D-Ik_SSx.js";
import "@tanstack/react-query";
import "ethers";
import "../../machine/machine.js";
import { fireEvent as c } from "../../machine/events/utils/fireEvent.js";
import "@ton/core";
import "../../constants/chains.js";
import "@headlessui/react";
import "@material-symbols-svg/react-rounded/icons/chevron-left";
import "framer-motion";
import "../../utils/cn.js";
import { notReachable as d } from "../../utils/notReachable.js";
import { useTypedTranslation as P } from "../../localisation.js";
import "chroma-js";
import "hsluv";
import "../../features/ChainsDropdown/ChainItem.js";
import "@material-symbols-svg/react-rounded/icons/wand-shine";
import "../../components/Input.js";
import "@material-symbols-svg/react-rounded/icons/close";
import "@material-symbols-svg/react-rounded/icons/emergency";
import "@material-symbols-svg/react-rounded/icons/error";
import "@material-symbols-svg/react-rounded/icons/verified";
import { isDebug as Q } from "../../utils/checkers/isDebug.js";
import "../../logger.js";
import { noop as V } from "../../utils/noop.js";
import "@scure/base";
import { SuccessScreen as G } from "../../features/SuccessScreen/index.js";
import { TokensModal as K } from "../../features/TokensModal.js";
import "@material-symbols-svg/react-rounded/icons/arrow-downward";
import "@material-symbols-svg/react-rounded/icons/progress-activity";
import { DepositMethodSwitcher as q } from "../../features/DepositMethodSwitcher.js";
import "../../localstorage-DVS0q1yC.js";
import "../../index-DEq3oXQF.js";
import "@defuse-protocol/internal-utils";
import "../../utils/near/rpc.js";
import { ChainNotSupportedModal as z } from "../../features/ChainNotSupportedModal/index.js";
import { DepositSummary as H } from "../../features/DepositSummary.js";
import "virtua";
import "zod";
import "@defuse-protocol/intents-sdk";
import "change-case";
import "bs58";
import "@defuse-protocol/one-click-sdk-typescript";
import "axios";
import "../../network.js";
import "../../hooks/useMakeNearTransfer/nearClient.js";
import { useUnsupportedChain as J } from "../../hooks/useUnsupportedChain.js";
import { useTokenInputPair as X } from "../../hooks/useTokenInputPair.js";
import "../../utils/feeServiceTokens.js";
import "../../hooks/useOneClickExecutionStatus.js";
import "@material-symbols-svg/react-rounded/icons/check-circle";
import "@material-symbols-svg/react-rounded/icons/cancel";
import "@material-symbols-svg/react-rounded/icons/arrow-circle-left";
import "@material-symbols-svg/react-rounded/icons/info";
import { BlockingError as m } from "../../components/BlockingError.js";
import "copy-text-to-clipboard";
import "@material-symbols-svg/react-rounded/icons/content-copy";
import "@material-symbols-svg/react-rounded/icons/check";
import "../../components/InputAmount.js";
import "../../components/Notes.js";
import "@material-symbols-svg/react-rounded/icons/graphic-eq";
import "../../components/ChainShortcut.js";
import "@radix-ui/react-tooltip";
import "../../components/Steps.js";
import "@material-symbols-svg/react-rounded/icons/open-in-new";
import "@material-symbols-svg/react-rounded/icons/receipt";
import "@material-symbols-svg/react-rounded/icons/account-balance-wallet";
import { isValidChainAddress as Y } from "../../utils/checkers/isValidChainAddress.js";
import { useTokenModal as Z } from "../../hooks/useTokenModal.js";
import { WidgetDepositModeSkeleton as A } from "./WidgetDepositModeSkeleton.js";
const g = (s, n) => !s || !n ? !1 : s.toLowerCase() === "wnear" ? ["near", "wnear"].includes(n.toLowerCase()) : n.toLowerCase() === "wnear" ? ["near", "wnear"].includes(s.toLowerCase()) : s.toLowerCase() === n.toLowerCase(), ht = ({
  onMsg: s,
  makeTransfer: n,
  isLoading: v
}) => {
  const { ctx: t } = N(), { t: l } = P(), {
    alchemyApiKey: D,
    refetchQuoteInterval: E,
    chainsFilter: k,
    ...o
  } = O(), { onChangeAmount: b, onChangeToken: f } = X(), {
    status: M,
    refetch: L,
    isLoading: T,
    tokens: a
  } = U(), { tokenModalOpen: i, updateTokenModalState: p } = Z({ onMsg: s }), { unsupportedChain: W } = J(), [w, h] = I();
  u(() => {
    if (!(T || a.length === 0) && (o.sendAddress && t.sendAddress !== o.sendAddress && c("addressSet", o.sendAddress), !(t.targetToken && o.defaultTargetToken && o.defaultTargetToken.blockchain === t.targetToken.blockchain && g(
      o.defaultTargetToken.symbol,
      t.targetToken.symbol
    )) && o.defaultTargetToken)) {
      const e = a.find((S) => g(S.symbol, o.defaultTargetToken?.symbol) && S.blockchain.toLowerCase() === o.defaultTargetToken?.blockchain.toLowerCase());
      c("tokenSelect", {
        token: e,
        variant: "target"
      });
    }
  }, [
    a.length,
    T,
    o.defaultTargetToken,
    o.sendAddress,
    t.sendAddress,
    t.targetToken
  ]), u(() => (c("reset", { clearWalletAddress: !0 }), () => {
    c("depositTypeSet", { isExternal: !1 });
  }), []), j({
    debug: Q(),
    listenTo: [
      "updateBalances",
      "checkWalletConnection",
      "setSourceTokenBalance",
      ["makeQuote", { message: void 0, refetchQuoteInterval: E }],
      ["setBalancesUsingAlchemyExt", { alchemyApiKey: D }]
    ]
  }), u(() => {
    !t.sourceToken && o.defaultSourceToken && a.length > 0 && c("tokenSelect", { variant: "source", token: a[0] });
  }, [t.walletAddress, a.length]), u(() => {
    s?.({
      type: "on_change_deposit_type",
      isExternal: t.isDepositFromExternalWallet
    });
  }, [t.isDepositFromExternalWallet]);
  const _ = R(() => k || {
    source: {
      intents: "none",
      external: t.isDepositFromExternalWallet ? "all" : "wallet-supported"
    },
    target: { intents: "all", external: "none" }
  }, [k, t.isDepositFromExternalWallet]), F = () => {
    c("reset", { clearWalletAddress: !1, keepSelectedTokens: !0 });
  }, B = t.sendAddress && t.targetToken?.blockchain && Y(t.targetToken?.blockchain, t.sendAddress);
  if (v || T || // wait for useEffect to set target token
  o.sendAddress && !t.sendAddress || o.defaultTargetToken && !t.targetToken)
    return /* @__PURE__ */ r(A, {});
  if (!o.sendAddress || !o.defaultTargetToken)
    return /* @__PURE__ */ r(m, { message: "Target token & send address must be explicitly set via config for Deposit Mode." });
  if (!B)
    return /* @__PURE__ */ r(m, { message: "Target token chain doesn't match chain of a given address/account." });
  if (o.sendAddress !== t.sendAddress || o.defaultTargetToken.blockchain !== t.targetToken?.blockchain || !g(
    o.defaultTargetToken.symbol,
    t.targetToken?.symbol
  ))
    return /* @__PURE__ */ r(m, { message: "Target for Deposit Mode set via config does not match the current context." });
  if (t.state === "transfer_success" && w)
    return /* @__PURE__ */ r(
      G,
      {
        ...w,
        transactionType: "DEPOSIT",
        backButtonLabel: l(
          "transfer.success.deposit.backToDeposit",
          "Back to deposit"
        ),
        onMsg: (e) => {
          switch (e.type) {
            case "on_dismiss_success":
              h(void 0), F();
              break;
            default:
              d(e.type);
          }
        }
      }
    );
  if (W)
    return /* @__PURE__ */ r(z, {});
  switch (M) {
    case "error":
      return /* @__PURE__ */ r(
        m,
        {
          message: "Couldn't load tokens list.",
          onClickRetry: L
        }
      );
    case "success":
      return i !== "none" ? /* @__PURE__ */ r(
        K,
        {
          showBalances: !0,
          showChainsSelector: !0,
          variant: i,
          groupTokens: i === "source",
          chainsFilter: i === "source" ? _.source : _.target,
          onMsg: (e) => {
            switch (e.type) {
              case "on_select_token":
                f(i, e.token), p("none"), s?.({
                  type: e.type,
                  token: e.token,
                  variant: i
                });
                break;
              case "on_dismiss_tokens_modal":
                p("none");
                break;
              default:
                d(e);
            }
          }
        }
      ) : t.walletAddress ? /* @__PURE__ */ y("div", { className: "gap-sw-lg flex flex-col w-full", children: [
        t.isDepositFromExternalWallet ? null : /* @__PURE__ */ r(
          C.Source,
          {
            showBalance: !t.isDepositFromExternalWallet,
            heading: l("tokenInput.heading.source.deposit", "Deposit"),
            onMsg: (e) => {
              switch (e.type) {
                case "on_select_token":
                  f("source", e.token);
                  break;
                case "on_change_amount":
                  b("source", e.amount);
                  break;
                case "on_click_select_token":
                  p("source");
                  break;
                default:
                  d(e);
              }
            }
          }
        ),
        /* @__PURE__ */ r(
          q,
          {
            onMsg: (e) => {
              switch (e.type) {
                case "on_toggle_tokens_modal":
                  p(e.isOpen ? "source" : "none");
                  break;
                case "on_successful_transfer":
                  h(e.transferResult);
                  break;
                case "on_transaction_received":
                  break;
                default:
                  d(e);
              }
            }
          }
        ),
        !!t.walletAddress && /* @__PURE__ */ r(H, {}),
        /* @__PURE__ */ r(
          x,
          {
            makeTransfer: n,
            label: l("submit.active.deposit", "Confirm deposit in your wallet"),
            onSuccess: (e) => {
              h(e), s?.({ type: "on_transfer_success", ...e });
            }
          }
        )
      ] }) : /* @__PURE__ */ y("div", { className: "gap-sw-lg flex flex-col w-full", children: [
        /* @__PURE__ */ r(
          C.Source,
          {
            showBalance: !0,
            heading: l("tokenInput.heading.source.deposit", "Deposit"),
            onMsg: (e) => {
              switch (e.type) {
                case "on_select_token":
                  f("source", e.token);
                  break;
                case "on_change_amount":
                  b("source", e.amount);
                  break;
                case "on_click_select_token":
                  p("source");
                  break;
                default:
                  d(e);
              }
            }
          }
        ),
        /* @__PURE__ */ r(
          x,
          {
            makeTransfer: n,
            label: l(
              "submit.active.deposit",
              "Confirm deposit in your wallet"
            ),
            onSuccess: V
          }
        )
      ] });
    case "pending":
    default:
      return /* @__PURE__ */ r(A, {});
  }
};
export {
  ht as WidgetDepositModeContent
};
//# sourceMappingURL=WidgetDepositModeContent.js.map
