import { jsx as e, jsxs as C, Fragment as N } from "react/jsx-runtime";
import { useState as r, useEffect as H, useCallback as j } from "react";
import { CloseButton as D } from "../../components/CloseButton.js";
import { WidgetTabs as E } from "../../components/WidgetTabs.js";
import { WidgetSwapContent as P } from "../WidgetSwap/WidgetSwapContent.js";
import { WidgetDepositContent as q } from "../WidgetDeposit/WidgetDepositContent.js";
import { WidgetWithdrawContent as F } from "../WidgetWithdraw/WidgetWithdrawContent.js";
import { WidgetDepositModeContent as G } from "../WidgetDepositMode/WidgetDepositModeContent.js";
import { G as I, b as K, H as O } from "../../config-BDnHptBC.js";
import { WidgetProfileButton as V } from "./WidgetProfileButton.js";
import { WidgetHistoryButton as z } from "./WidgetHistoryButton.js";
import { TransactionHistory as J } from "../../features/TransactionHistory/index.js";
import "ethers";
import "../../machine/machine.js";
import { cn as L } from "../../utils/cn.js";
import "../../constants/chains.js";
import "@tanstack/react-query";
import "@defuse-protocol/one-click-sdk-typescript";
import "../../constants/aurora-assets.js";
import "../../utils/feeServiceTokens.js";
import "../../logger.js";
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 "axios";
import "../../network.js";
import "@ton/core";
import "../../hooks/useMakeNearTransfer/nearClient.js";
import { useUnsupportedChain as Q } from "../../hooks/useUnsupportedChain.js";
import "../../hooks/useOneClickExecutionStatus.js";
const p = (o, i) => {
  if (o)
    return (s) => o(s, i);
}, Ut = ({
  defaultTab: o = "swap",
  tabs: i = ["swap", "deposit", "withdraw"],
  makeTransfer: s,
  onMsg: T,
  ...a
}) => {
  const [S, l] = r(!1), [d, m] = r(o), [n, u] = r(!1), [W, w] = r(null), { clearUnsupportedChain: x } = Q(), [y, v] = r(0), {
    enableAccountAbstraction: f,
    showProfileButton: M,
    showTransactionHistory: b,
    apiKey: k
  } = I(), { ctx: h } = K(), g = i.includes(d) ? d : o, _ = (t) => {
    m(t), u(!1), x();
  }, c = (t, A) => {
    t.type === "on_tokens_modal_toggled" && l(t.isOpen), t.type === "on_select_token" && l(!1), T?.(t, A);
  };
  H(() => {
    i.includes(d) || m(o);
  }, [i, o]), H(() => {
    f || m("swap");
  }, [f]);
  const B = j((t) => {
    v(t);
  }, []), U = (!S || n) && h.state !== "transfer_success";
  return /* @__PURE__ */ e(O, { children: /* @__PURE__ */ C(N, { children: [
    U && /* @__PURE__ */ C("div", { className: "mb-sw-xl h-[34px] w-full flex items-center", children: [
      f || i.includes("topup") ? /* @__PURE__ */ e(
        E,
        {
          tabs: i,
          isEnabled: h.quoteStatus !== "pending",
          activeTab: n ? null : g,
          onSelect: _
        }
      ) : /* @__PURE__ */ e("div", { className: "w-full flex items-center", children: n && /* @__PURE__ */ e(D, { onClick: () => u(!1) }) }),
      !!b && !!k && /* @__PURE__ */ e(
        z,
        {
          isActive: n,
          pendingTransactionsCount: y,
          onClick: () => {
            l(!1), u((t) => !t), w(null);
          }
        }
      ),
      M && /* @__PURE__ */ e(V, {})
    ] }),
    /* @__PURE__ */ e("div", { className: L("w-full", { hidden: !n }), children: /* @__PURE__ */ e(
      J,
      {
        isVisible: n,
        onPendingTransactionsCountChange: B,
        selectedTransaction: W,
        onSelectTransaction: w
      }
    ) }),
    !n && (() => {
      switch (g) {
        case "swap":
          return /* @__PURE__ */ e(
            P,
            {
              ...a,
              makeTransfer: p(s, "swap"),
              onMsg: (t) => {
                c(t, "swap");
              }
            }
          );
        case "deposit":
          return /* @__PURE__ */ e(
            q,
            {
              ...a,
              makeTransfer: p(s, "deposit"),
              onMsg: (t) => {
                c(t, "deposit");
              }
            }
          );
        case "topup":
          return /* @__PURE__ */ e(
            G,
            {
              ...a,
              makeTransfer: p(s, "deposit"),
              onMsg: (t) => {
                c(t, "deposit");
              }
            }
          );
        case "withdraw":
          return /* @__PURE__ */ e(
            F,
            {
              ...a,
              makeTransfer: p(s, "withdraw"),
              onMsg: (t) => {
                c(t, "withdraw");
              }
            }
          );
        default:
          return null;
      }
    })()
  ] }) });
};
export {
  Ut as WidgetContent
};
//# sourceMappingURL=WidgetContent.js.map
