import { jsxs as l, jsx as o, Fragment as x } from "react/jsx-runtime";
import { prettifyCurrencyValue as C } from "@argent/x-shared";
import f from "../../features/icons/ChevronDownPrimaryIcon.js";
import y from "../../features/icons/InfoCircleSecondaryIcon.js";
import { Flex as a, Input as I, Button as m, Circle as v } from "@chakra-ui/react";
import { useTranslation as h } from "react-i18next";
import { useCompoundInputContext as d } from "./context.js";
import { getRadius as w } from "./utils.js";
import { P3 as p, H5 as g, L2Bold as s, L1Bold as S } from "../typography.generated.js";
import { LoadingPulse as W } from "../LoadingPulse.js";
import { TokenIcon as b } from "../TokenIcon.js";
function z({ children: t, ...r }) {
  return /* @__PURE__ */ o(a, { children: /* @__PURE__ */ o(p, { fontWeight: "bold", fontSize: "sm", ...r, children: t }) });
}
function R({ ...t }) {
  const { id: r, amount: e, isDisabled: n, isLoading: i, error: c } = d();
  return e ? /* @__PURE__ */ o(W, { isLoading: i && !e.value, mr: "3", children: /* @__PURE__ */ o(I, { placeholder: "0", color: c ? "text-danger" : "text-primary", p: "0", minH: "min-content", backgroundColor: "transparent", variant: "flat", fontSize: "2xl", fontWeight: "600", lineHeight: "6.5", value: e.value, onChange: e.onChange, isDisabled: n, isReadOnly: e.isReadOnly, _disabled: { opacity: 1, cursor: "default" }, _hover: {
    backgroundColor: "transparent"
  }, _focus: {
    boxShadow: "none",
    backgroundColor: "transparent"
  }, _readOnly: {
    pointerEvents: "none",
    border: "none",
    cursor: "default"
  }, tabIndex: e.isReadOnly ? -1 : 1, "data-testid": r, ...t }) }) : null;
}
function T({ children: t, showChevron: r = !0, ...e }) {
  var i, c;
  const { token: n } = d();
  return /* @__PURE__ */ o(a, { alignItems: "center", children: /* @__PURE__ */ o(m, { px: r ? n != null && n.selected ? "1" : "3" : "2", py: r ? "1" : "1.5", height: "min-content", minH: "min-content", width: "min-content", rounded: "full", onClick: n == null ? void 0 : n.onClick, leftIcon: n != null && n.selected ? /* @__PURE__ */ o(b, { name: ((i = n == null ? void 0 : n.selected) == null ? void 0 : i.name) || "?", url: (c = n == null ? void 0 : n.selected) == null ? void 0 : c.iconUrl, size: "5", borderRadius: "50%" }) : void 0, rightIcon: r ? /* @__PURE__ */ o(f, {}) : void 0, fontWeight: "500", backgroundColor: "surface-sunken", ...e, children: /* @__PURE__ */ o(g, { children: n != null && n.selected ? n.selected.symbol || n.selected.name : t }) }) });
}
function _({ children: t, ...r }) {
  var n, i;
  const { token: e } = d();
  return /* @__PURE__ */ o(a, { alignItems: "center", width: "100%", children: /* @__PURE__ */ l(m, { p: "0", gap: "2", width: "100%", rounded: "full", onClick: e == null ? void 0 : e.onClick, fontWeight: "500", backgroundColor: "transparent", _hover: {
    backgroundColor: "transparent"
  }, _active: {
    transform: "scale(1)"
  }, ...r, children: [
    e === void 0 || e != null && e.selected || !(e != null && e.PlaceholderIcon) ? /* @__PURE__ */ o(b, { name: ((n = e == null ? void 0 : e.selected) == null ? void 0 : n.name) || "?", url: (i = e == null ? void 0 : e.selected) == null ? void 0 : i.iconUrl, size: "8", borderRadius: "50%" }) : /* @__PURE__ */ o(v, { backgroundColor: "icon-background", size: "8", children: /* @__PURE__ */ o(e.PlaceholderIcon, { color: "icon-secondary" }) }),
    /* @__PURE__ */ o(g, { color: e != null && e.selected ? "" : "text-subtle", children: e != null && e.selected ? e.selected.name : t }),
    /* @__PURE__ */ o(f, { ml: "auto" })
  ] }) });
}
function B({ children: t, ...r }) {
  const { amount: e } = d();
  if (e != null && e.max)
    return /* @__PURE__ */ o(s, { onClick: e.max.onClick, cursor: "pointer", role: "button", color: "text-brand", fontWeight: "600", fontSize: "xs", whiteSpace: "nowrap", ...r, children: t });
}
function D({ ...t }) {
  var n, i, c;
  const { amount: r } = d(), e = ((n = r == null ? void 0 : r.fiat) == null ? void 0 : n.value) || "0";
  return /* @__PURE__ */ l(s, { color: "text-secondary", fontSize: "sm", fontWeight: "400", ...t, children: [
    ((i = r == null ? void 0 : r.fiat) == null ? void 0 : i.approx) && /* @__PURE__ */ o(x, { children: "≈ " }),
    C(e, (c = r == null ? void 0 : r.fiat) == null ? void 0 : c.symbol)
  ] });
}
function L({ ...t }) {
  var n;
  const { t: r } = h(), { token: e } = d();
  if (((n = e == null ? void 0 : e.selected) == null ? void 0 : n.balance) !== void 0)
    return /* @__PURE__ */ l(s, { color: "text-secondary", fontSize: "sm", fontWeight: "400", textAlign: "right", ...t, children: [
      r("components.balance"),
      e == null ? void 0 : e.selected.balance
    ] });
}
function P({ ...t }) {
  const { error: r } = d();
  if (r)
    return /* @__PURE__ */ l(S, { as: a, alignItems: "center", gap: "0.5", color: "text-danger", ...t, children: [
      /* @__PURE__ */ o(y, { w: "4", h: "4", color: "inherit" }),
      /* @__PURE__ */ o(p, { fontWeight: "bold", children: r })
    ] });
}
function j({ children: t, ...r }) {
  const { position: e } = d();
  return /* @__PURE__ */ o(a, { position: "relative", flexDirection: "column", gap: "2", padding: "4", backgroundColor: "surface-elevated", width: "100%", ...w(e, "lg"), ...r, children: t });
}
function K({ title: t, selectLabel: r = "Select token", ...e }) {
  var c, u;
  const { t: n } = h(), { amount: i } = d();
  return /* @__PURE__ */ l(j, { ...e, children: [
    /* @__PURE__ */ o(z, { children: t }),
    /* @__PURE__ */ l(a, { flexDirection: "column", gap: "1", children: [
      /* @__PURE__ */ l(a, { justifyContent: "space-between", alignItems: "center", children: [
        i && /* @__PURE__ */ o(R, {}),
        i ? /* @__PURE__ */ o(T, { showChevron: !1, children: r }) : /* @__PURE__ */ l(_, { children: [
          r,
          "fff"
        ] })
      ] }),
      i && /* @__PURE__ */ l(a, { justifyContent: "space-between", children: [
        /* @__PURE__ */ l(a, { gap: "1", children: [
          ((c = i.fiat) == null ? void 0 : c.value) && /* @__PURE__ */ o(D, {}),
          ((u = i.max) == null ? void 0 : u.show) && /* @__PURE__ */ o(B, { children: n("components.useMax") })
        ] }),
        /* @__PURE__ */ o(L, { marginLeft: "auto" })
      ] })
    ] }),
    /* @__PURE__ */ o(P, {})
  ] });
}
export {
  j as Container,
  K as Default,
  P as Error,
  D as FiatValue,
  R as InputAmount,
  T as InputToken,
  B as MaxButton,
  z as Title,
  L as TokenBalance
};
