import { jsxs as a, jsx as t, Fragment as F } from "react/jsx-runtime";
import { OpenInNewW700 as v } from "@material-symbols-svg/react-rounded/icons/open-in-new";
import { ArrowDownwardW700 as I } from "@material-symbols-svg/react-rounded/icons/arrow-downward";
import { Card as T } from "../../components/Card.js";
import { CloseButton as k } from "../../components/CloseButton.js";
import { TinyNumber as h } from "../../components/TinyNumber.js";
import { CopyButton as S } from "../../components/CopyButton.js";
import { Hr as f } from "../../components/Hr.js";
import { formatUsdAmount as A } from "../../utils/formatters/formatUsdAmount.js";
import { formatAddressTruncate as g } from "../../utils/formatters/formatAddressTruncate.js";
import { getTransactionStatusLabel as U } from "../../utils/transactions/getTransactionStatusLabel.js";
import { findTransactionToken as y } from "../../utils/transactions/findTransactionToken.js";
import { TransactionStatusBadge as D } from "./TransactionStatusBadge.js";
import { TransactionDetailsToken as x } from "./TransactionDetailsToken.js";
const r = ({
  label: e,
  children: s
}) => /* @__PURE__ */ a("div", { className: "flex items-center justify-between", children: [
  /* @__PURE__ */ t("span", { className: "text-sw-label-md text-sw-gray-200", children: e }),
  /* @__PURE__ */ t("div", { className: "flex items-center gap-x-sw-sm", children: s })
] }), d = (e) => "intentHashes" in e, H = (e) => {
  if (!d(e) || !e.appFees || e.appFees.length === 0)
    return 0;
  const s = parseFloat(e.amountInFormatted);
  return e.appFees.reduce((l, { fee: m }) => l + s * m / 1e4, 0);
}, K = ({
  transaction: e,
  tokens: s,
  onClose: l
}) => {
  const m = U(e.status), b = new Date(e.createdAt).toLocaleString("en-US", {
    month: "short",
    day: "numeric",
    year: "numeric",
    hour: "numeric",
    minute: "2-digit",
    hour12: !0
  }), n = y(s, e, "source"), o = y(s, e, "destination"), i = d(e) ? e.depositAddress : null, c = H(e), u = parseFloat(e.amountInFormatted), N = parseFloat(e.amountOutFormatted), p = u > 0 ? N / u : null;
  return /* @__PURE__ */ a(T, { className: "w-full", children: [
    /* @__PURE__ */ a("div", { className: "flex items-center justify-between pb-sw-2xl", children: [
      /* @__PURE__ */ a("div", { className: "flex flex-col", children: [
        /* @__PURE__ */ t("span", { className: "text-sw-label-lg text-sw-gray-50 mb-sw-md", children: "Swap" }),
        /* @__PURE__ */ t("span", { className: "text-sw-label-sm text-sw-gray-200", children: b })
      ] }),
      /* @__PURE__ */ t(
        k,
        {
          transparent: !0,
          onClick: l,
          className: "relative -top-[10px] -right-[8px]"
        }
      )
    ] }),
    /* @__PURE__ */ t(f, {}),
    /* @__PURE__ */ a("div", { className: "flex flex-col gap-y-sw-md py-sw-2xl", children: [
      !!n && /* @__PURE__ */ t(
        x,
        {
          token: n,
          amount: e.amountInFormatted,
          usdAmount: e.amountInUsd
        }
      ),
      !!o && /* @__PURE__ */ a(F, { children: [
        /* @__PURE__ */ t("div", { className: "w-[40px] h-[40px] flex items-center justify-center", children: /* @__PURE__ */ t(I, { className: "h-sw-xl w-sw-xl text-sw-gray-200" }) }),
        /* @__PURE__ */ t(
          x,
          {
            token: o,
            amount: e.amountOutFormatted,
            usdAmount: e.amountOutUsd
          }
        )
      ] })
    ] }),
    /* @__PURE__ */ t(f, {}),
    /* @__PURE__ */ a("div", { className: "flex flex-col px-sw-lg pt-sw-2xl gap-y-sw-2xl", children: [
      /* @__PURE__ */ t(r, { label: "Status", children: /* @__PURE__ */ t(D, { status: m }) }),
      p !== null && !!o && !!n && /* @__PURE__ */ t(r, { label: "Rate", children: /* @__PURE__ */ a("span", { className: "text-sw-body-md text-sw-gray-50", children: [
        "1 ",
        o.symbol,
        " = ",
        /* @__PURE__ */ t(h, { value: String(p) }),
        " ",
        n.symbol
      ] }) }),
      c > 0 && n && /* @__PURE__ */ t(r, { label: "Fee", children: /* @__PURE__ */ a("span", { className: "text-sw-body-md text-sw-gray-50", children: [
        /* @__PURE__ */ t(h, { value: String(c) }),
        " ",
        n.symbol,
        (() => {
          const w = e.amountInUsd && parseFloat(e.amountInFormatted) > 0 ? c * (parseFloat(e.amountInUsd) / parseFloat(e.amountInFormatted)) : 0;
          return w >= 5e-3 ? /* @__PURE__ */ a("span", { className: "text-sw-gray-400", children: [
            " ",
            "(",
            A(w),
            ")"
          ] }) : null;
        })()
      ] }) }),
      !!i && /* @__PURE__ */ t(r, { label: "Explorer link", children: /* @__PURE__ */ a(
        "a",
        {
          href: `https://explorer.near-intents.org/transactions/${i}`,
          target: "_blank",
          rel: "noopener noreferrer",
          className: "flex items-center gap-x-sw-sm text-sw-body-md text-sw-gray-50 hover:text-sw-accent-50 transition-colors",
          children: [
            g(i, 14),
            /* @__PURE__ */ t(v, { className: "h-sw-lg w-sw-lg" })
          ]
        }
      ) }),
      d(e) && !!e.intentHashes && /* @__PURE__ */ a(r, { label: "Intent hash", children: [
        /* @__PURE__ */ t("span", { className: "text-sw-body-md text-sw-gray-50", children: g(e.intentHashes, 14) }),
        /* @__PURE__ */ t(S, { value: e.intentHashes })
      ] })
    ] })
  ] });
};
export {
  K as TransactionDetails
};
//# sourceMappingURL=TransactionDetails.js.map
