import { jsx as t, jsxs as b } from "react/jsx-runtime";
import { useState as S, useEffect as u, useMemo as R } from "react";
import { b as O, G as N, s as U, n as j, p as q, c as L, v as w, S as C } from "../../config-BDnHptBC.js";
import "@tanstack/react-query";
import "ethers";
import "../../machine/machine.js";
import { fireEvent as d } 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 s } 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 G } from "../../utils/noop.js";
import "@scure/base";
import { SuccessScreen as K } from "../../features/SuccessScreen/index.js";
import { TokensModal as z } 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 H } from "../../features/DepositMethodSwitcher.js";
import { WalletCompatibilityCheck as J } from "../../features/WalletCompatibilityCheck/index.js";
import { ChainNotSupportedModal as V } from "../../features/ChainNotSupportedModal/index.js";
import { DepositSummary as X } from "../../features/DepositSummary.js";
import "virtua";
import "zod";
import "../../utils/near/rpc.js";
import "../../index-DEq3oXQF.js";
import "@defuse-protocol/intents-sdk";
import "change-case";
import "../../localstorage-DVS0q1yC.js";
import "@defuse-protocol/internal-utils";
import "bs58";
import "@defuse-protocol/one-click-sdk-typescript";
import "axios";
import "../../network.js";
import "../../hooks/useMakeNearTransfer/nearClient.js";
import { useUnsupportedChain as Y } from "../../hooks/useUnsupportedChain.js";
import { useTokenInputPair as Z } from "../../hooks/useTokenInputPair.js";
import "../../utils/feeServiceTokens.js";
import "../../hooks/useOneClickExecutionStatus.js";
import { useIsCompatibilityCheckRequired as $ } from "../../hooks/useIsCompatibilityCheckRequired.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 ee } 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 { useTokenModal as te } from "../../hooks/useTokenModal.js";
import { WidgetDepositSkeleton as T } from "./WidgetDepositSkeleton.js";
const wt = ({
  onMsg: n,
  makeTransfer: f,
  isLoading: g
}) => {
  const { ctx: o } = O(), { t: a } = P(), {
    chainsFilter: p,
    alchemyApiKey: x,
    refetchQuoteInterval: D
  } = N(), { intentsAccountType: E } = U(), { onChangeAmount: k, onChangeToken: c } = Z(), {
    status: W,
    refetch: v,
    isLoading: F
  } = j(), { tokenModalOpen: r, updateTokenModalState: i } = te({ onMsg: n }), { walletSignOut: I } = q(), { unsupportedChain: M } = Y(), h = $(), [A, l] = S(!1);
  u(() => {
    h && l(!0);
  }, [h]);
  const [_, m] = S();
  u(() => (d("reset", { clearWalletAddress: !0 }), () => {
    d("depositTypeSet", { isExternal: !1 });
  }), []), L({
    debug: Q(),
    listenTo: [
      "updateBalances",
      "checkWalletConnection",
      "setSourceTokenBalance",
      "setSourceTokenIntentsTarget",
      ["makeQuote", { message: void 0, refetchQuoteInterval: D }],
      ["setBalancesUsingAlchemyExt", { alchemyApiKey: x }]
    ]
  }), u(() => {
    n?.({
      type: "on_change_deposit_type",
      isExternal: o.isDepositFromExternalWallet
    });
  }, [o.isDepositFromExternalWallet]);
  const y = R(() => p || {
    source: {
      intents: "none",
      external: o.isDepositFromExternalWallet ? "all" : "wallet-supported"
    },
    target: { intents: "all", external: "none" }
  }, [p, o.isDepositFromExternalWallet]), B = () => {
    d("reset", { clearWalletAddress: !1, keepSelectedTokens: !0 });
  };
  if (g || F)
    return /* @__PURE__ */ t(T, {});
  if (A)
    return /* @__PURE__ */ t(
      J,
      {
        onMsg: (e) => {
          switch (e.type) {
            case "on_sign_out":
              I?.(E), l(!1);
              break;
            case "on_close":
              l(!1);
              break;
            default:
              s(e.type);
          }
        }
      }
    );
  if (o.state === "transfer_success" && _)
    return /* @__PURE__ */ t(
      K,
      {
        ..._,
        transactionType: "DEPOSIT",
        onMsg: (e) => {
          switch (e.type) {
            case "on_dismiss_success":
              m(void 0), B();
              break;
            default:
              s(e.type);
          }
        }
      }
    );
  if (M)
    return /* @__PURE__ */ t(V, {});
  switch (W) {
    case "error":
      return /* @__PURE__ */ t(
        ee,
        {
          message: "Couldn't load tokens list.",
          onClickRetry: v
        }
      );
    case "success":
      return r !== "none" ? /* @__PURE__ */ t(
        z,
        {
          showBalances: !0,
          showChainsSelector: !0,
          variant: r,
          groupTokens: r === "source",
          chainsFilter: r === "source" ? y.source : y.target,
          onMsg: (e) => {
            switch (e.type) {
              case "on_select_token":
                c(r, e.token), i("none"), n?.({
                  type: e.type,
                  token: e.token,
                  variant: r
                });
                break;
              case "on_dismiss_tokens_modal":
                i("none");
                break;
              default:
                s(e);
            }
          }
        }
      ) : o.walletAddress ? /* @__PURE__ */ b("div", { className: "gap-sw-lg flex flex-col w-full", children: [
        o.isDepositFromExternalWallet ? null : /* @__PURE__ */ t(
          w.Source,
          {
            showBalance: !o.isDepositFromExternalWallet,
            heading: a("tokenInput.heading.source.deposit", "Deposit"),
            onMsg: (e) => {
              switch (e.type) {
                case "on_select_token":
                  c("source", e.token);
                  break;
                case "on_change_amount":
                  k("source", e.amount);
                  break;
                case "on_click_select_token":
                  i("source");
                  break;
                default:
                  s(e);
              }
            }
          }
        ),
        /* @__PURE__ */ t(
          H,
          {
            onMsg: (e) => {
              switch (e.type) {
                case "on_toggle_tokens_modal":
                  i(e.isOpen ? "source" : "none");
                  break;
                case "on_successful_transfer":
                  m(e.transferResult);
                  break;
                case "on_transaction_received":
                  break;
                default:
                  s(e);
              }
            }
          }
        ),
        !!o.walletAddress && /* @__PURE__ */ t(X, {}),
        /* @__PURE__ */ t(
          C,
          {
            makeTransfer: f,
            label: a("submit.active.deposit", "Confirm deposit in your wallet"),
            onSuccess: (e) => {
              m(e), n?.({ type: "on_transfer_success", ...e });
            }
          }
        )
      ] }) : /* @__PURE__ */ b("div", { className: "gap-sw-lg flex flex-col w-full", children: [
        /* @__PURE__ */ t(
          w.Source,
          {
            showBalance: !0,
            heading: a("tokenInput.heading.source.deposit", "Deposit"),
            onMsg: (e) => {
              switch (e.type) {
                case "on_select_token":
                  c("source", e.token);
                  break;
                case "on_change_amount":
                  k("source", e.amount);
                  break;
                case "on_click_select_token":
                  i("source");
                  break;
                default:
                  s(e);
              }
            }
          }
        ),
        /* @__PURE__ */ t(
          C,
          {
            makeTransfer: f,
            label: a(
              "submit.active.deposit",
              "Confirm deposit in your wallet"
            ),
            onSuccess: G
          }
        )
      ] });
    case "pending":
    default:
      return /* @__PURE__ */ t(T, {});
  }
};
export {
  wt as WidgetDepositContent
};
//# sourceMappingURL=WidgetDepositContent.js.map
