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 U } from "../WidgetDeposit/WidgetDepositContent.js";
import { WidgetWithdrawContent as q } from "../WidgetWithdraw/WidgetWithdrawContent.js";
import { WidgetDepositModeContent as F } from "../WidgetDepositMode/WidgetDepositModeContent.js";
import { G, b as I, H as K } from "../../config-C5f_rI5O.js";
import { WidgetProfileButton as O } from "./WidgetProfileButton.js";
import { WidgetHistoryButton as V } from "./WidgetHistoryButton.js";
import { TransactionHistory as z } from "../../features/TransactionHistory/index.js";
import "ethers";
import "../../machine/machine.js";
import { cn as J } from "../../utils/cn.js";
const l = (n, o) => {
  if (n)
    return (i) => n(i, o);
}, ct = ({
  defaultTab: n = "swap",
  tabs: o = ["swap", "deposit", "withdraw"],
  makeTransfer: i,
  onMsg: T,
  ...a
}) => {
  const [S, d] = r(!1), [p, f] = r(n), [s, u] = r(!1), [W, w] = r(null), [x, y] = r(0), {
    enableAccountAbstraction: m,
    showProfileButton: v,
    showTransactionHistory: M,
    apiKey: b
  } = G(), { ctx: h } = I(), g = o.includes(p) ? p : n, k = (t) => {
    f(t), u(!1);
  }, c = (t, A) => {
    t.type === "on_tokens_modal_toggled" && d(t.isOpen), t.type === "on_select_token" && d(!1), T?.(t, A);
  };
  H(() => {
    o.includes(p) || f(n);
  }, [o, n]), H(() => {
    m || f("swap");
  }, [m]);
  const _ = j((t) => {
    y(t);
  }, []), B = (!S || s) && h.state !== "transfer_success";
  return /* @__PURE__ */ e(K, { children: /* @__PURE__ */ C(N, { children: [
    B && /* @__PURE__ */ C("div", { className: "mb-sw-xl h-[34px] w-full flex items-center", children: [
      m || o.includes("topup") ? /* @__PURE__ */ e(
        E,
        {
          tabs: o,
          isEnabled: h.quoteStatus !== "pending",
          activeTab: s ? null : g,
          onSelect: k
        }
      ) : /* @__PURE__ */ e("div", { className: "w-full flex items-center", children: s && /* @__PURE__ */ e(D, { onClick: () => u(!1) }) }),
      !!M && !!b && /* @__PURE__ */ e(
        V,
        {
          isActive: s,
          pendingTransactionsCount: x,
          onClick: () => {
            d(!1), u((t) => !t), w(null);
          }
        }
      ),
      v && /* @__PURE__ */ e(O, {})
    ] }),
    /* @__PURE__ */ e("div", { className: J("w-full", { hidden: !s }), children: /* @__PURE__ */ e(
      z,
      {
        isVisible: s,
        onPendingTransactionsCountChange: _,
        selectedTransaction: W,
        onSelectTransaction: w
      }
    ) }),
    !s && (() => {
      switch (g) {
        case "swap":
          return /* @__PURE__ */ e(
            P,
            {
              ...a,
              makeTransfer: l(i, "swap"),
              onMsg: (t) => {
                c(t, "swap");
              }
            }
          );
        case "deposit":
          return /* @__PURE__ */ e(
            U,
            {
              ...a,
              makeTransfer: l(i, "deposit"),
              onMsg: (t) => {
                c(t, "deposit");
              }
            }
          );
        case "topup":
          return /* @__PURE__ */ e(
            F,
            {
              ...a,
              makeTransfer: l(i, "deposit"),
              onMsg: (t) => {
                c(t, "deposit");
              }
            }
          );
        case "withdraw":
          return /* @__PURE__ */ e(
            q,
            {
              ...a,
              makeTransfer: l(i, "withdraw"),
              onMsg: (t) => {
                c(t, "withdraw");
              }
            }
          );
        default:
          return null;
      }
    })()
  ] }) });
};
export {
  ct as WidgetContent
};
//# sourceMappingURL=WidgetContent.js.map
