import { jsx as t, jsxs as S } from "react/jsx-runtime";
import { useState as w, useEffect as T, useMemo as D } from "react";
import { b as N, s as Q, G as U, n as j, p as q, c as L, v as _, t as P, S as G } from "../../config-D-Ik_SSx.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 K } from "../../localisation.js";
import "chroma-js";
import "hsluv";
import "../../features/ChainsDropdown/ChainItem.js";
import { SendAddress as z } from "../../features/SendAddress/index.js";
import { SuccessScreen as H } from "../../features/SuccessScreen/index.js";
import { TokensModal as J } from "../../features/TokensModal.js";
import { SwapDirectionSwitcher as V } 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 X } from "../../utils/checkers/isDebug.js";
import "../../logger.js";
import { WalletCompatibilityCheck as Y } from "../../features/WalletCompatibilityCheck/index.js";
import { ChainNotSupportedModal as Z } from "../../features/ChainNotSupportedModal/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 { useUnsupportedChain as $ } from "../../hooks/useUnsupportedChain.js";
import { useTokenInputPair as ee } from "../../hooks/useTokenInputPair.js";
import "../../utils/feeServiceTokens.js";
import "../../hooks/useOneClickExecutionStatus.js";
import { useIsCompatibilityCheckRequired as te } 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 oe } 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 { useTokenModal as re } from "../../hooks/useTokenModal.js";
import { WidgetSwapSkeleton as y } from "./WidgetSwapSkeleton.js";
const yt = ({
  isLoading: C,
  makeTransfer: A,
  onMsg: p
}) => {
  const { ctx: o } = N(), { intentsAccountType: x } = Q(), {
    chainsFilter: c,
    enableAccountAbstraction: l,
    alchemyApiKey: I,
    refetchQuoteInterval: v
  } = U(), { t: i } = K(), {
    status: M,
    refetch: B,
    isLoading: W
  } = j(), { tokenModalOpen: r, updateTokenModalState: a } = re({ onMsg: p }), { onChangeAmount: k, onChangeToken: m, lastChangedInput: u } = ee(), { walletSignOut: R } = q(), { unsupportedChain: E } = $(), n = te(), [F, d] = w(
    n
  );
  T(() => {
    n && d(n);
  }, [n]);
  const [f, h] = w();
  T(() => {
    b("reset", { clearWalletAddress: !0 });
  }, []);
  const O = () => {
    b("reset", { clearWalletAddress: !1, keepSelectedTokens: !0 });
  };
  L({
    debug: X(),
    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 = D(() => {
    if (c)
      return c;
    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"
      }
    };
  }, [c, l, o.walletAddress]);
  if (C || W)
    return /* @__PURE__ */ t(y, {});
  if (n && F)
    return /* @__PURE__ */ t(
      Y,
      {
        onMsg: (e) => {
          switch (e.type) {
            case "on_sign_out":
              R?.(x), d(!1);
              break;
            case "on_close":
              d(!1);
              break;
            default:
              s(e.type);
          }
        }
      }
    );
  if (o.state === "transfer_success" && f)
    return /* @__PURE__ */ t(
      H,
      {
        showTargetToken: !0,
        transactionType: "SWAP",
        ...f,
        onMsg: (e) => {
          switch (e.type) {
            case "on_dismiss_success":
              h(void 0), O();
              break;
            default:
              s(e.type);
          }
        }
      }
    );
  if (E)
    return /* @__PURE__ */ t(Z, {});
  switch (M) {
    case "error":
      return /* @__PURE__ */ t(
        oe,
        {
          message: "Couldn't load tokens list.",
          onClickRetry: B
        }
      );
    case "success":
      return r !== "none" ? /* @__PURE__ */ t(
        J,
        {
          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"), p?.({
                  type: e.type,
                  token: e.token,
                  variant: r
                });
                break;
              case "on_dismiss_tokens_modal":
                a("none");
                break;
              default:
                s(e);
            }
          }
        }
      ) : /* @__PURE__ */ S("div", { className: "gap-sw-lg flex flex-col w-full", children: [
        /* @__PURE__ */ S("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":
                    k("source", e.amount);
                    break;
                  case "on_click_select_token":
                    a("source");
                    break;
                  default:
                    s(e);
                }
              }
            }
          ),
          /* @__PURE__ */ t(V, {}),
          /* @__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":
                    k("target", e.amount);
                    break;
                  case "on_click_select_token":
                    a("target");
                    break;
                  default:
                    s(e);
                }
              }
            }
          )
        ] }),
        !!o.walletAddress && o.targetToken && !o.targetToken.isIntent && /* @__PURE__ */ t(z, {}),
        o.sourceToken && /* @__PURE__ */ t(P, {}),
        /* @__PURE__ */ t(
          G,
          {
            makeTransfer: A,
            label: o.sourceToken?.isIntent && o.targetToken?.isIntent ? i("submit.active.swap", "Swap") : i("submit.active.intentsSwap", "Swap & send"),
            onSuccess: (e) => {
              h(e), p?.({ type: "on_transfer_success", ...e });
            }
          }
        )
      ] });
    case "pending":
    default:
      return /* @__PURE__ */ t(y, {});
  }
};
export {
  yt as WidgetSwapContent
};
//# sourceMappingURL=WidgetSwapContent.js.map
