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