import { fetchData as y } from "@argent/x-shared";
import { isArray as p, lowerCase as v } from "lodash-es";
import T from "object-hash";
import { useCallback as m, useMemo as d } from "react";
import h from "url-join";
import { useConditionallyEnabledSWR as l } from "../../http/swr.js";
const N = ({ apiData: { apiBaseUrl: e, apiHeaders: o }, address: t, network: r, transactionReviewEnabled: i = !0, transactions: n }) => {
  const s = m(async () => {
    if (!t || !r)
      return;
    if (!e)
      throw "Transaction review endpoint is not defined";
    const c = h(e, "reviewer/transactions/review/starknet"), f = p(n) ? n : [n], u = {
      network: r,
      account: t,
      calls: f
    };
    return y(c, {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        ...o
      },
      body: JSON.stringify(u)
    });
  }, [t, r, n]), a = d(() => T({ transactions: n, address: t, network: r }), [n, t, r]);
  return l(!!i, [a, "transactionReview"], s);
}, C = (e) => {
  if (!e)
    return {};
  const o = e.assessment === "warn" && e.reason !== "contract_is_not_verified", t = e.reason ? ` (Reason: ${v(e.reason)})` : "", r = o ? e.reason === "recipient_is_token_address" ? "You are sending tokens to their own address. This is likely to burn them." : `This transaction has been flagged as dangerous. We recommend you reject this transaction unless you are sure.${t}` : void 0;
  return {
    warn: o,
    reason: r
  };
}, w = (e) => {
  var o;
  if (e) {
    for (const t of e.reviews)
      if (((o = t.activity) == null ? void 0 : o.type) === "swap")
        return t;
  }
}, E = (e) => {
}, W = (e, o) => {
  var t;
  if (o) {
    for (const r of o.reviews)
      if (((t = r.activity) == null ? void 0 : t.type) === e)
        return r.activity;
  }
}, O = (e) => !!w(e), j = (e) => {
  var o, t;
  if (e) {
    for (const r of e.reviews)
      if ((o = r.activity) != null && o.type)
        return {
          ...r,
          type: (t = r.activity) == null ? void 0 : t.type
        };
  }
};
export {
  C as getDisplayWarnAndReasonForTransactionReview,
  E as getNFTTransferActivity,
  W as getTransactionReviewActivityOfType,
  O as getTransactionReviewHasSwap,
  w as getTransactionReviewSwap,
  j as getTransactionReviewWithType,
  N as useTransactionReview
};
