import { jsx as t, jsxs as g } from "react/jsx-runtime";
import { useState as w, useEffect as _, useMemo as O } from "react";
import { b as D, s as L, G as Q, n as j, p as q, c as N, v as T, t as U, S as G } from "../../config-BDnHptBC.js";
import "@tanstack/react-query";
import "ethers";
import "../../machine/machine.js";
import { fireEvent as b } 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 n } from "../../utils/notReachable.js";
import { useTypedTranslation as H } from "../../localisation.js";
import "chroma-js";
import "hsluv";
import "../../features/ChainsDropdown/ChainItem.js";
import { SendAddress as K } from "../../features/SendAddress/index.js";
import { SuccessScreen as P } from "../../features/SuccessScreen/index.js";
import { TokensModal as z } from "../../features/TokensModal.js";
import { DirectionSwitcher as J } from "../../components/DirectionSwitcher.js";
import "@material-symbols-svg/react-rounded/icons/qr-code";
import "@material-symbols-svg/react-rounded/icons/progress-activity";
import "@material-symbols-svg/react-rounded/icons/refresh";
import { Card as y } from "../../components/Card.js";
import "../../components/Steps.js";
import "@radix-ui/react-tooltip";
import "@material-symbols-svg/react-rounded/icons/info";
import { isDebug as V } from "../../utils/checkers/isDebug.js";
import "../../logger.js";
import { WalletCompatibilityCheck as X } from "../../features/WalletCompatibilityCheck/index.js";
import "@material-symbols-svg/react-rounded/icons/gpp-bad";
import "@scure/base";
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 Y } from "../../hooks/useTokenInputPair.js";
import "../../utils/feeServiceTokens.js";
import "../../hooks/useOneClickExecutionStatus.js";
import { useIsCompatibilityCheckRequired as Z } from "../../hooks/useIsCompatibilityCheckRequired.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 { BlockingError as $ } 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/Input.js";
import "../../components/InputAmount.js";
import "../../components/Notes.js";
import "@material-symbols-svg/react-rounded/icons/graphic-eq";
import "../../components/ChainShortcut.js";
import "virtua";
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/open-in-new";
import "@material-symbols-svg/react-rounded/icons/arrow-downward";
import "@material-symbols-svg/react-rounded/icons/receipt";
import "@material-symbols-svg/react-rounded/icons/account-balance-wallet";
import { useTokenModal as ee } from "../../hooks/useTokenModal.js";
import { WidgetWithdrawSkeleton as C } from "./WidgetWithdrawSkeleton.js";
const Tt = ({
  makeTransfer: S,
  onMsg: s,
  isLoading: x
}) => {
  const { t: a } = H(), { ctx: o } = D(), { intentsAccountType: v } = L(), {
    chainsFilter: c,
    alchemyApiKey: A,
    refetchQuoteInterval: W
  } = Q(), {
    status: I,
    refetch: M,
    isLoading: R
  } = j(), { tokenModalOpen: r, updateTokenModalState: i } = ee({ onMsg: s }), { onChangeAmount: u, onChangeToken: p, lastChangedInput: m } = Y(), { walletSignOut: B } = q(), d = Z(), [E, l] = w(!1);
  _(() => {
    d && l(!0);
  }, [d]);
  const [k, f] = w();
  _(() => {
    b("reset", { clearWalletAddress: !0 });
  }, []), N({
    debug: V(),
    listenTo: [
      "updateBalances",
      "checkWalletConnection",
      "setSourceTokenBalance",
      [
        "makeQuote",
        {
          message: void 0,
          type: m === "target" ? "exact_out" : "exact_in",
          refetchQuoteInterval: W
        }
      ],
      ["setBalancesUsingAlchemyExt", { alchemyApiKey: A }]
    ]
  });
  const h = O(() => c || {
    source: {
      intents: "with-balance",
      external: "none"
    },
    target: {
      intents: "none",
      external: "all"
    }
  }, [c, o.walletAddress]), F = () => {
    b("reset", { clearWalletAddress: !1, keepSelectedTokens: !0 });
  };
  if (x || R)
    return /* @__PURE__ */ t(C, {});
  if (E)
    return /* @__PURE__ */ t(
      X,
      {
        onMsg: (e) => {
          switch (e.type) {
            case "on_sign_out":
              B?.(v), l(!1);
              break;
            case "on_close":
              l(!1);
              break;
            default:
              n(e.type);
          }
        }
      }
    );
  if (o.state === "transfer_success" && k)
    return /* @__PURE__ */ t(
      P,
      {
        showTargetToken: !0,
        transactionType: "WITHDRAWAL",
        ...k,
        onMsg: (e) => {
          switch (e.type) {
            case "on_dismiss_success":
              f(void 0), F();
              break;
            default:
              n(e.type);
          }
        }
      }
    );
  switch (I) {
    case "error":
      return /* @__PURE__ */ t(
        $,
        {
          message: "Couldn't load tokens list.",
          onClickRetry: M
        }
      );
    case "success":
      return r !== "none" ? /* @__PURE__ */ t(
        z,
        {
          showBalances: !0,
          variant: r,
          showChainsSelector: r === "target",
          groupTokens: !1,
          chainsFilter: r === "source" ? h.source : h.target,
          onMsg: (e) => {
            switch (e.type) {
              case "on_select_token":
                p(r, e.token), i("none"), s?.({
                  type: e.type,
                  token: e.token,
                  variant: r
                });
                break;
              case "on_dismiss_tokens_modal":
                i("none");
                break;
              default:
                n(e);
            }
          }
        }
      ) : /* @__PURE__ */ g("div", { className: "gap-sw-lg relative flex flex-col w-full", children: [
        /* @__PURE__ */ g("div", { className: "gap-[10px] relative flex flex-col", children: [
          /* @__PURE__ */ t(y, { padding: "none", children: /* @__PURE__ */ t(
            T.Source,
            {
              heading: a(
                "tokenInput.heading.source.withdraw",
                "Withdraw token"
              ),
              isChanging: m === "source",
              onMsg: (e) => {
                switch (e.type) {
                  case "on_select_token":
                    p("source", e.token);
                    break;
                  case "on_change_amount":
                    u("source", e.amount);
                    break;
                  case "on_click_select_token":
                    i("source");
                    break;
                  default:
                    n(e);
                }
              }
            }
          ) }),
          /* @__PURE__ */ t(J, { isEnabled: !1 }),
          /* @__PURE__ */ t(y, { padding: "none", children: /* @__PURE__ */ t(
            T.Target,
            {
              heading: a(
                "tokenInput.heading.target.withdraw",
                "Receive token"
              ),
              isChanging: m === "target",
              onMsg: (e) => {
                switch (e.type) {
                  case "on_select_token":
                    p("target", e.token);
                    break;
                  case "on_change_amount":
                    u("target", e.amount);
                    break;
                  case "on_click_select_token":
                    i("target");
                    break;
                  default:
                    n(e);
                }
              }
            }
          ) })
        ] }),
        !!o.walletAddress && o.targetToken && !o.targetToken.isIntent && /* @__PURE__ */ t(K, {}),
        o.sourceToken && /* @__PURE__ */ t(U, {}),
        /* @__PURE__ */ t(
          G,
          {
            makeTransfer: S,
            label: a("submit.active.withdraw", "Swap & withdraw"),
            onSuccess: (e) => {
              f(e), s?.({ type: "on_transfer_success", ...e });
            }
          }
        )
      ] });
    case "pending":
    default:
      return /* @__PURE__ */ t(C, {});
  }
};
export {
  Tt as WidgetWithdrawContent
};
//# sourceMappingURL=WidgetWithdrawContent.js.map
