import { jsxs as m, jsx as e, Fragment as E } from "react/jsx-runtime";
import { useRef as O, useState as _, useEffect as q } from "react";
import { ArrowDownward as D, OpenInNew as P } from "@material-symbols-svg/react-rounded/w700";
import { Notes as p } from "../../components/Notes.js";
import { b as w, z as b } from "../../config-C5f_rI5O.js";
import { CloseButton as F } from "../../components/CloseButton.js";
import { Accordion as C } from "../../components/Accordion.js";
import { TransactionStatusBadge as B } from "../TransactionHistory/TransactionStatusBadge.js";
import { guardStates as j } from "../../machine/guards/index.js";
import { formatUsdAmount as z } from "../../utils/formatters/formatUsdAmount.js";
import { formatTinyNumber as G } from "../../utils/formatters/formatTinyNumber.js";
import { formatBigToHuman as A } from "../../utils/formatters/formatBigToHuman.js";
import { getTransactionStatusLabel as H } from "../../utils/transactions/getTransactionStatusLabel.js";
import { useTypedTranslation as R } from "../../localisation.js";
import "../../constants/chains.js";
import "@tanstack/react-query";
import "@defuse-protocol/one-click-sdk-typescript";
import "../../utils/feeServiceTokens.js";
import { logger as V } from "../../logger.js";
import "@scure/base";
import "zod";
import "../../utils/near/rpc.js";
import "../../machine/machine.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 "ethers";
import "@ton/core";
import "../../utils/cn.js";
import "../../hooks/useMakeNearTransfer/nearClient.js";
import "../../hooks/useOneClickExecutionStatus.js";
import { useHandleKeyDown as M } from "../../hooks/useHandleKeyDown.js";
import { useTransferResultStatus as Q } from "./useTransferResultStatus.js";
import { useSummaryItemsCount as W } from "./useSummaryItemsCount.js";
import { CopyableValue as y } from "./CopyableValue.js";
import { TokenRow as k } from "./TokenRow.js";
const $ = 41, N = ({
  amount: t,
  amountUsd: s,
  decimals: u,
  price: i
}) => {
  const c = A(t, u), l = s ? parseFloat(s) : i * parseFloat(c);
  return {
    amount: c,
    amountUsd: l
  };
}, L = (t) => {
  const { ctx: s } = w();
  if (!(!s.quote || !t?.amount || s.quote.type !== "QUOTE_DEPOSIT_ANY_AMOUNT"))
    return N({
      amount: t.amount,
      amountUsd: t.amountUsd,
      decimals: s.sourceToken.decimals,
      price: s.sourceToken.price
    });
}, Y = () => {
  const { ctx: t } = w();
  if (!t.quote || t.quote.type === "QUOTE_DEPOSIT_ANY_AMOUNT")
    return;
  const s = A(
    t.quote?.amountIn ?? t.sourceTokenAmount,
    t.sourceToken.decimals
  ), u = A(
    t.quote?.amountOut ?? t.targetTokenAmount,
    t.targetToken.decimals
  ), i = t.quote?.amountInUsd ? parseFloat(t.quote.amountInUsd) : t.sourceToken.price * parseFloat(s), c = t.quote?.amountOutUsd ? parseFloat(t.quote.amountOutUsd) : t.targetToken.price * parseFloat(u), l = c / parseFloat(u), n = G(
    l / (parseFloat(s) / i)
  );
  return {
    sourceAmount: s,
    targetAmount: u,
    sourceAmountUsd: i,
    targetAmountUsd: c,
    targetTokenUnitPrice: l,
    sourceTokenUnitAmount: n
  };
}, Bt = ({
  transactionType: t = "SWAP",
  message: s,
  showTargetToken: u = !0,
  transactionLink: i,
  backButtonLabel: c,
  onMsg: l,
  ...n
}) => {
  const { t: a } = R(), { ctx: o } = w(), S = j(o, ["transfer_success"]), x = W(!!n.intent), r = Y(), g = L(n), d = O(null), [f, v] = _(!1), T = Q(n, {
    disabled: f
  });
  q(() => {
    if (!(f || !(T === "PENDING" || T === "PROCESSING")))
      return d.current && clearTimeout(d.current), d.current = setTimeout(
        () => v(!0),
        3e4
      ), () => {
        d.current && clearTimeout(d.current);
      };
  }, [T]);
  const U = f ? "UNRESOLVED" : T, I = H(
    U,
    t
  ), h = () => l({ type: "on_dismiss_success" });
  return M("Escape", h), S ? /* @__PURE__ */ m("div", { className: "flex flex-col gap-sw-lg w-full", children: [
    /* @__PURE__ */ m("header", { className: "flex items-center justify-between", children: [
      /* @__PURE__ */ e(B, { variant: "title", status: I }),
      /* @__PURE__ */ e(F, { onClick: h })
    ] }),
    !!s && /* @__PURE__ */ e("p", { className: "text-sw-body-md text-sw-gray-200", children: s }),
    f && /* @__PURE__ */ e("p", { className: "text-sw-body-md text-sw-status-warning", children: a(
      "transfer.success.statusUnresolved",
      "Resolving the status of your swap is taking longer than usual. Please check the explorer or your wallet for the latest state."
    ) }),
    /* @__PURE__ */ m("div", { className: "flex flex-col", children: [
      g ? /* @__PURE__ */ e(
        k,
        {
          token: o.sourceToken,
          amount: g.amount,
          amountUsd: g.amountUsd
        }
      ) : r ? /* @__PURE__ */ e(
        k,
        {
          token: o.sourceToken,
          amount: r.sourceAmount,
          amountUsd: r.sourceAmountUsd
        }
      ) : /* @__PURE__ */ e(
        k,
        {
          token: o.sourceToken,
          ...N({
            amountUsd: void 0,
            amount: o.sourceTokenAmount,
            decimals: o.sourceToken.decimals,
            price: o.sourceToken.price
          })
        }
      ),
      r && u && o.sourceToken.symbol !== o.targetToken.symbol && /* @__PURE__ */ m(E, { children: [
        /* @__PURE__ */ e("div", { className: "flex items-center justify-center w-full h-[12px] z-1", children: /* @__PURE__ */ e("div", { className: "flex items-center justify-center p-sw-md bg-sw-gray-950 rounded-sw-md w-fit", children: /* @__PURE__ */ e(D, { size: 18, className: "text-sw-gray-200" }) }) }),
        /* @__PURE__ */ e(
          k,
          {
            token: o.targetToken,
            amount: r.targetAmount,
            amountUsd: r.targetAmountUsd
          }
        )
      ] })
    ] }),
    /* @__PURE__ */ e(
      C,
      {
        expandedByDefault: !1,
        expandedHeightPx: (
          // edge case if only Rate is present
          x === 1 ? 58 : x * $
        ),
        title: a("transfer.success.details.label", "Transaction details"),
        children: /* @__PURE__ */ m(p, { children: [
          o.sourceToken.symbol !== o.targetToken.symbol && r && /* @__PURE__ */ e(
            p.Item,
            {
              label: a("transfer.success.details.rate", "Rate"),
              value: /* @__PURE__ */ m(
                "span",
                {
                  className: "text-sw-gray-50",
                  style: { borderBottomWidth: "2px", borderStyle: "dotted" },
                  children: [
                    `1 ${o.targetToken.symbol} ≈ `,
                    " ",
                    r.sourceTokenUnitAmount,
                    " ",
                    `${o.sourceToken.symbol}`,
                    /* @__PURE__ */ e("span", { children: ` (${z(r.targetTokenUnitPrice)})` })
                  ]
                }
              )
            }
          ),
          !!o.sendAddress && /* @__PURE__ */ e(
            p.Item,
            {
              label: a(
                "transfer.success.details.recipient",
                "Recipient address"
              ),
              value: /* @__PURE__ */ e(y, { value: o.sendAddress })
            }
          ),
          !!n.intent && /* @__PURE__ */ e(
            p.Item,
            {
              label: a("transfer.success.details.intent", "Intent hash"),
              value: /* @__PURE__ */ e(y, { value: n.intent })
            }
          ),
          /* @__PURE__ */ e(
            p.Item,
            {
              label: a("transfer.success.details.hash", "Transaction hash"),
              value: /* @__PURE__ */ e(y, { value: n.hash })
            }
          )
        ] })
      }
    ),
    /* @__PURE__ */ m("div", { className: "flex flex-col gap-sw-lg", children: [
      /* @__PURE__ */ e(
        b,
        {
          fluid: !0,
          as: "a",
          size: "lg",
          target: "_blank",
          variant: "primary",
          iconPosition: "tail",
          href: i,
          state: i && U !== "PENDING" ? "default" : "disabled",
          icon: P,
          children: a("transfer.success.action.viewOnExplorer", "View in explorer")
        }
      ),
      /* @__PURE__ */ e(b, { fluid: !0, size: "lg", variant: "outlined", onClick: h, children: c ?? a("transfer.success.action.backToSwap", "Back to swap") })
    ] })
  ] }) : (V.warn(
    "[WIDGET] Success screen can be rendered only in transfer_success state"
  ), null);
};
export {
  Bt as SuccessScreen
};
//# sourceMappingURL=index.js.map
