import { jsx as t, jsxs as w } from "react/jsx-runtime";
import { useState as S, useEffect as T, useMemo as O } from "react";
import { b as D, s as Q, G as j, n as q, p as L, c as N, v as _, t as P, S as U } from "../../config-C5f_rI5O.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 s } from "../../utils/notReachable.js";
import { useTypedTranslation as G } 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 z } from "../../features/SuccessScreen/index.js";
import { TokensModal as H } from "../../features/TokensModal.js";
import { SwapDirectionSwitcher as J } from "../../features/SwapDirectionSwitcher.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 "../../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 "../../components/Notes.js";
import "virtua";
import "@material-symbols-svg/react-rounded/icons/error";
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/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/close";
import "@material-symbols-svg/react-rounded/icons/emergency";
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 "@material-symbols-svg/react-rounded/icons/arrow-downward";
import "../../components/Input.js";
import "../../components/InputAmount.js";
import "@material-symbols-svg/react-rounded/icons/graphic-eq";
import "../../components/ChainShortcut.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 { WidgetSwapSkeleton as y } from "./WidgetSwapSkeleton.js";
import { useTokenModal as ee } from "../../hooks/useTokenModal.js";
const wt = ({
  isLoading: C,
  makeTransfer: A,
  onMsg: c
}) => {
  const { ctx: o } = D(), { intentsAccountType: x } = Q(), {
    chainsFilter: p,
    enableAccountAbstraction: l,
    alchemyApiKey: I,
    refetchQuoteInterval: v
  } = j(), { t: i } = G(), {
    status: B,
    refetch: M,
    isLoading: W
  } = q(), { tokenModalOpen: r, updateTokenModalState: a } = ee({ onMsg: c }), { onChangeAmount: d, onChangeToken: m, lastChangedInput: u } = Y(), { walletSignOut: R } = L(), n = Z(), [E, k] = S(
    n
  );
  T(() => {
    n && k(n);
  }, [n]);
  const [f, h] = S();
  T(() => {
    b("reset", { clearWalletAddress: !0 });
  }, []);
  const F = () => {
    b("reset", { clearWalletAddress: !1, keepSelectedTokens: !0 });
  };
  N({
    debug: V(),
    listenTo: [
      "updateBalances",
      "checkWalletConnection",
      "setSourceTokenBalance",
      ["setDefaultSelectedTokens", { skipIntents: !1 }],
      [
        "makeQuote",
        {
          message: void 0,
          type: u === "target" ? "exact_out" : "exact_in",
          refetchQuoteInterval: v
        }
      ],
      ["setBalancesUsingAlchemyExt", { alchemyApiKey: I }]
    ]
  });
  const g = O(() => {
    if (p)
      return p;
    const e = o.walletAddress ? "with-balance" : "all";
    return {
      source: {
        intents: l ? e : "none",
        external: o.walletAddress ? "wallet-supported" : "all"
      },
      target: {
        intents: l ? "all" : "none",
        external: "all"
      }
    };
  }, [p, l, o.walletAddress]);
  if (C || W)
    return /* @__PURE__ */ t(y, {});
  if (n && E)
    return /* @__PURE__ */ t(
      X,
      {
        onMsg: (e) => {
          switch (e.type) {
            case "on_sign_out":
              R?.(x), k(!1);
              break;
            case "on_close":
              k(!1);
              break;
            default:
              s(e.type);
          }
        }
      }
    );
  if (o.state === "transfer_success" && f)
    return /* @__PURE__ */ t(
      z,
      {
        showTargetToken: !0,
        transactionType: "SWAP",
        ...f,
        onMsg: (e) => {
          switch (e.type) {
            case "on_dismiss_success":
              h(void 0), F();
              break;
            default:
              s(e.type);
          }
        }
      }
    );
  switch (B) {
    case "error":
      return /* @__PURE__ */ t(
        $,
        {
          message: "Couldn't load tokens list.",
          onClickRetry: M
        }
      );
    case "success":
      return r !== "none" ? /* @__PURE__ */ t(
        H,
        {
          showBalances: !0,
          showChainsSelector: !0,
          variant: r,
          groupTokens: r === "source",
          chainsFilter: r === "source" ? g.source : g.target,
          onMsg: (e) => {
            switch (e.type) {
              case "on_select_token":
                m(r, e.token), a("none"), c?.({
                  type: e.type,
                  token: e.token,
                  variant: r
                });
                break;
              case "on_dismiss_tokens_modal":
                a("none");
                break;
              default:
                s(e);
            }
          }
        }
      ) : /* @__PURE__ */ w("div", { className: "gap-sw-lg flex flex-col w-full", children: [
        /* @__PURE__ */ w("div", { className: "gap-[10px] relative flex flex-col", children: [
          /* @__PURE__ */ t(
            _.Source,
            {
              heading: i("tokenInput.heading.source.swap", "Sell"),
              isChanging: u === "source",
              onMsg: (e) => {
                switch (e.type) {
                  case "on_select_token":
                    m("source", e.token);
                    break;
                  case "on_change_amount":
                    d("source", e.amount);
                    break;
                  case "on_click_select_token":
                    a("source");
                    break;
                  default:
                    s(e);
                }
              }
            }
          ),
          /* @__PURE__ */ t(J, {}),
          /* @__PURE__ */ t(
            _.Target,
            {
              heading: i("tokenInput.heading.target.swap", "Buy"),
              isChanging: u === "target",
              onMsg: (e) => {
                switch (e.type) {
                  case "on_select_token":
                    m("target", e.token);
                    break;
                  case "on_change_amount":
                    d("target", e.amount);
                    break;
                  case "on_click_select_token":
                    a("target");
                    break;
                  default:
                    s(e);
                }
              }
            }
          )
        ] }),
        !!o.walletAddress && o.targetToken && !o.targetToken.isIntent && /* @__PURE__ */ t(K, {}),
        o.sourceToken && /* @__PURE__ */ t(P, {}),
        /* @__PURE__ */ t(
          U,
          {
            makeTransfer: A,
            label: o.sourceToken?.isIntent && o.targetToken?.isIntent ? i("submit.active.swap", "Swap") : i("submit.active.intentsSwap", "Swap & send"),
            onSuccess: (e) => {
              h(e), c?.({ type: "on_transfer_success" });
            }
          }
        )
      ] });
    case "pending":
    default:
      return /* @__PURE__ */ t(y, {});
  }
};
export {
  wt as WidgetSwapContent
};
//# sourceMappingURL=WidgetSwapContent.js.map
