import { jsx as t, jsxs as b } from "react/jsx-runtime";
import { useState as S, useEffect as u, useMemo as M } from "react";
import { b as R, G as O, s as j, n as q, p as L, c as N, v as w, S as T } from "../../config-C5f_rI5O.js";
import "@tanstack/react-query";
import "ethers";
import "../../machine/machine.js";
import { fireEvent as f } 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 U } 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 z } from "../../features/DepositMethodSwitcher.js";
import { WalletCompatibilityCheck as H } from "../../features/WalletCompatibilityCheck/index.js";
import { DepositSummary as J } 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 { useTokenInputPair as V } from "../../hooks/useTokenInputPair.js";
import "../../utils/feeServiceTokens.js";
import "../../hooks/useOneClickExecutionStatus.js";
import { useIsCompatibilityCheckRequired as X } 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 Y } 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 { WidgetDepositSkeleton as g } from "./WidgetDepositSkeleton.js";
import { useTokenModal as Z } from "../../hooks/useTokenModal.js";
const ht = ({
  onMsg: n,
  makeTransfer: d,
  isLoading: C
}) => {
  const { ctx: o } = R(), { t: a } = P(), {
    chainsFilter: p,
    alchemyApiKey: x,
    refetchQuoteInterval: D
  } = O(), { intentsAccountType: E } = j(), { onChangeAmount: k, onChangeToken: c } = V(), {
    status: W,
    refetch: v,
    isLoading: F
  } = q(), { tokenModalOpen: r, updateTokenModalState: i } = Z({ onMsg: n }), { walletSignOut: I } = L(), h = X(), [A, l] = S(!1);
  u(() => {
    h && l(!0);
  }, [h]);
  const [_, m] = S();
  u(() => (f("reset", { clearWalletAddress: !0 }), () => {
    f("depositTypeSet", { isExternal: !1 });
  }), []), N({
    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 = M(() => p || {
    source: {
      intents: "none",
      external: o.isDepositFromExternalWallet ? "all" : "wallet-supported"
    },
    target: { intents: "all", external: "none" }
  }, [p, o.isDepositFromExternalWallet]), B = () => {
    f("reset", { clearWalletAddress: !1, keepSelectedTokens: !0 });
  };
  if (C || F)
    return /* @__PURE__ */ t(g, {});
  if (A)
    return /* @__PURE__ */ t(
      H,
      {
        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(
      G,
      {
        ..._,
        transactionType: "DEPOSIT",
        onMsg: (e) => {
          switch (e.type) {
            case "on_dismiss_success":
              m(void 0), B();
              break;
            default:
              s(e.type);
          }
        }
      }
    );
  switch (W) {
    case "error":
      return /* @__PURE__ */ t(
        Y,
        {
          message: "Couldn't load tokens list.",
          onClickRetry: v
        }
      );
    case "success":
      return r !== "none" ? /* @__PURE__ */ t(
        K,
        {
          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(
          z,
          {
            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(J, {}),
        /* @__PURE__ */ t(
          T,
          {
            makeTransfer: d,
            label: a("submit.active.deposit", "Confirm deposit in your wallet"),
            onSuccess: (e) => {
              m(e), n?.({ type: "on_transfer_success" });
            }
          }
        )
      ] }) : /* @__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(
          T,
          {
            makeTransfer: d,
            label: a(
              "submit.active.deposit",
              "Confirm deposit in your wallet"
            ),
            onSuccess: U
          }
        )
      ] });
    case "pending":
    default:
      return /* @__PURE__ */ t(g, {});
  }
};
export {
  ht as WidgetDepositContent
};
//# sourceMappingURL=WidgetDepositContent.js.map
