order-management 0.0.86 → 0.0.88

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -866,210 +866,275 @@ const useDebounce$3 = (value, delay) => {
866
866
  return debouncedValue;
867
867
  };
868
868
  const getStatusBadgeClass$7 = (status) => {
869
- const statusLower = status.toLowerCase();
870
- if (statusLower === "requested") {
871
- return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
872
- }
873
- if (statusLower === "approved") {
874
- return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
875
- }
876
- if (statusLower === "rejected") {
877
- return "bg-ui-tag-red-bg text-ui-tag-red-text";
878
- }
879
- if (statusLower === "completed") {
880
- return "bg-ui-tag-green-bg text-ui-tag-green-text";
881
- }
882
- if (statusLower === "cancelled") {
883
- return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
884
- }
869
+ const s2 = status.toLowerCase();
870
+ if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
871
+ if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
872
+ if (s2 === "error" || s2 === "canceled" || s2 === "cancelled") return "bg-ui-tag-red-bg text-ui-tag-red-text";
873
+ if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
885
874
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
886
875
  };
887
- const SwapsPage = () => {
876
+ const RefundsPage = () => {
888
877
  const navigate = reactRouterDom.useNavigate();
889
878
  const [items, setItems] = react.useState([]);
890
- const [statusFilter, setStatusFilter] = react.useState("all");
891
- const [createdByFilter, setCreatedByFilter] = react.useState("all");
892
- const [searchQuery, setSearchQuery] = react.useState("");
893
- const debouncedSearchQuery = useDebounce$3(searchQuery, 300);
879
+ const [orderIdSearch, setOrderIdSearch] = react.useState("");
880
+ const debouncedOrderId = useDebounce$3(orderIdSearch, 300);
881
+ const [paymentStatusFilter, setPaymentStatusFilter] = react.useState("all");
882
+ const [providerSearch, setProviderSearch] = react.useState("");
883
+ const debouncedProvider = useDebounce$3(providerSearch, 300);
884
+ const [currencySearch, setCurrencySearch] = react.useState("");
885
+ const debouncedCurrency = useDebounce$3(currencySearch, 300);
886
+ const [dateFrom, setDateFrom] = react.useState("");
887
+ const [dateTo, setDateTo] = react.useState("");
888
+ const [amountMin, setAmountMin] = react.useState("");
889
+ const [amountMax, setAmountMax] = react.useState("");
894
890
  const [isLoading, setIsLoading] = react.useState(true);
895
891
  const [isFetchingMore, setIsFetchingMore] = react.useState(false);
896
892
  const [error, setError] = react.useState(null);
897
893
  const [offset, setOffset] = react.useState(0);
898
894
  const [count, setCount] = react.useState(0);
899
895
  const limit = 50;
900
- const loadSwaps = react.useCallback(
901
- async (nextOffset, replace = false) => {
902
- var _a;
896
+ const loadRefunds = react.useCallback(
897
+ async (nextOffset, replace) => {
903
898
  try {
904
- if (replace) {
905
- setIsLoading(true);
906
- } else {
907
- setIsFetchingMore(true);
908
- }
899
+ if (replace) setIsLoading(true);
900
+ else setIsFetchingMore(true);
909
901
  setError(null);
910
902
  const params = new URLSearchParams();
911
903
  params.set("limit", String(limit));
912
904
  params.set("offset", String(nextOffset));
913
- if (statusFilter !== "all") {
914
- params.set("status", statusFilter);
915
- }
916
- if (debouncedSearchQuery.trim()) {
917
- params.set("order_id", debouncedSearchQuery.trim());
918
- }
919
- if (createdByFilter !== "all") {
920
- params.set("created_by", createdByFilter);
921
- }
922
- const response = await fetch(
923
- `/admin/swaps?${params.toString()}`,
924
- { credentials: "include" }
925
- );
905
+ if (debouncedOrderId.trim()) params.set("order_id", debouncedOrderId.trim());
906
+ if (paymentStatusFilter !== "all") params.set("payment_status", paymentStatusFilter);
907
+ if (debouncedProvider.trim()) params.set("provider_id", debouncedProvider.trim());
908
+ if (debouncedCurrency.trim()) params.set("currency_code", debouncedCurrency.trim());
909
+ if (dateFrom.trim()) params.set("date_from", dateFrom.trim());
910
+ if (dateTo.trim()) params.set("date_to", dateTo.trim());
911
+ const min = amountMin.trim() ? Number(amountMin) : void 0;
912
+ const max = amountMax.trim() ? Number(amountMax) : void 0;
913
+ if (min != null && !Number.isNaN(min)) params.set("amount_min", String(min));
914
+ if (max != null && !Number.isNaN(max)) params.set("amount_max", String(max));
915
+ const response = await fetch(`/admin/refunds?${params.toString()}`, {
916
+ credentials: "include"
917
+ });
926
918
  if (!response.ok) {
927
- const message = await response.text();
928
- throw new Error(message || "Unable to load swaps");
919
+ const text = await response.text();
920
+ throw new Error(text || "Failed to load refunds");
929
921
  }
930
922
  const payload = await response.json();
923
+ const list = payload.refunds ?? [];
931
924
  setCount(payload.count ?? 0);
932
- setOffset(nextOffset + (((_a = payload.swaps) == null ? void 0 : _a.length) ?? 0));
933
- setItems(
934
- (prev) => replace ? payload.swaps ?? [] : [...prev, ...payload.swaps ?? []]
935
- );
936
- } catch (loadError) {
937
- const message = loadError instanceof Error ? loadError.message : "Unable to load swaps";
938
- setError(message);
925
+ setOffset(nextOffset + list.length);
926
+ setItems((prev) => replace ? list : [...prev, ...list]);
927
+ } catch (e) {
928
+ setError(e instanceof Error ? e.message : "Failed to load");
939
929
  } finally {
940
930
  setIsLoading(false);
941
931
  setIsFetchingMore(false);
942
932
  }
943
933
  },
944
- [statusFilter, createdByFilter, debouncedSearchQuery]
934
+ [
935
+ debouncedOrderId,
936
+ paymentStatusFilter,
937
+ debouncedProvider,
938
+ debouncedCurrency,
939
+ dateFrom,
940
+ dateTo,
941
+ amountMin,
942
+ amountMax
943
+ ]
945
944
  );
946
945
  react.useEffect(() => {
947
- void loadSwaps(0, true);
948
- }, [statusFilter, createdByFilter, debouncedSearchQuery, loadSwaps]);
946
+ void loadRefunds(0, true);
947
+ }, [loadRefunds]);
949
948
  const hasMore = react.useMemo(() => offset < count, [offset, count]);
950
- const availableStatuses = react.useMemo(() => {
951
- const statuses = /* @__PURE__ */ new Set();
952
- items.forEach((item) => statuses.add(item.status));
953
- return Array.from(statuses).sort();
954
- }, [items]);
949
+ const displayAmount = (r) => {
950
+ const code = (r.currency_code ?? "USD").toUpperCase();
951
+ return `${code} ${Number(r.amount)}`;
952
+ };
953
+ const displayStatus = (r) => {
954
+ const s2 = r.payment_status ?? "";
955
+ return s2 !== "" ? s2 : "—";
956
+ };
955
957
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "mx-auto flex w-full max-w-7xl flex-col gap-6 p-6", children: [
956
958
  /* @__PURE__ */ jsxRuntime.jsxs("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
957
959
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
958
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Exchanges" }),
959
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "View and manage all customer exchange requests" })
960
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Refunds" }),
961
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Refund records — amount, order, payment status" })
960
962
  ] }),
961
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "primary", onClick: () => loadSwaps(0, true), children: "Refresh" })
963
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "primary", onClick: () => loadRefunds(0, true), children: "Refresh" })
962
964
  ] }),
963
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
965
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap items-center gap-3", children: [
964
966
  /* @__PURE__ */ jsxRuntime.jsx(
965
967
  ui.Input,
966
968
  {
967
- placeholder: "Search by swap ID or order ID",
968
- value: searchQuery,
969
- onChange: (event) => setSearchQuery(event.target.value),
970
- className: "md:max-w-sm"
969
+ placeholder: "Order ID",
970
+ value: orderIdSearch,
971
+ onChange: (e) => setOrderIdSearch(e.target.value),
972
+ className: "md:max-w-[180px]",
973
+ "aria-label": "Filter by order ID"
971
974
  }
972
975
  ),
973
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-3", children: [
974
- /* @__PURE__ */ jsxRuntime.jsxs(
975
- "select",
976
- {
977
- value: createdByFilter,
978
- onChange: (event) => setCreatedByFilter(event.target.value),
979
- className: "h-9 rounded-md border border-ui-border-base bg-transparent px-3 text-sm text-ui-fg-base outline-none transition focus:ring-2 focus:ring-ui-fg-interactive md:max-w-xs",
980
- children: [
981
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "all", children: "All (Created by)" }),
982
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "customer", children: "Customer" }),
983
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "admin", children: "Admin" })
984
- ]
985
- }
986
- ),
987
- /* @__PURE__ */ jsxRuntime.jsxs(
988
- "select",
989
- {
990
- value: statusFilter,
991
- onChange: (event) => setStatusFilter(event.target.value),
992
- className: "h-9 rounded-md border border-ui-border-base bg-transparent px-3 text-sm text-ui-fg-base outline-none transition focus:ring-2 focus:ring-ui-fg-interactive md:max-w-xs",
993
- children: [
994
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "all", children: "All Statuses" }),
995
- availableStatuses.map((status) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: status, children: status.replace(/_/g, " ").toUpperCase() }, status))
996
- ]
997
- }
998
- )
999
- ] })
1000
- ] }),
1001
- error ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
1002
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
1003
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(
1004
- ui.Button,
976
+ /* @__PURE__ */ jsxRuntime.jsx(
977
+ ui.Input,
1005
978
  {
1006
- variant: "secondary",
1007
- onClick: () => loadSwaps(0, true),
1008
- children: "Try again"
979
+ placeholder: "Provider",
980
+ value: providerSearch,
981
+ onChange: (e) => setProviderSearch(e.target.value),
982
+ className: "md:max-w-[140px]",
983
+ "aria-label": "Filter by provider"
1009
984
  }
1010
- ) })
1011
- ] }) : null,
1012
- isLoading ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Loading swaps..." }) }) : items.length === 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-dashed border-ui-border-strong p-10 text-center", children: [
1013
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h3", className: "text-xl", children: "No exchanges yet" }),
1014
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "mt-2 text-ui-fg-subtle", children: "Exchange requests created by customers will appear here." })
1015
- ] }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "overflow-hidden rounded-xl border border-ui-border-base", children: /* @__PURE__ */ jsxRuntime.jsxs("table", { className: "min-w-full divide-y divide-ui-border-base", children: [
1016
- /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
1017
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Exchange ID" }),
1018
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Order ID" }),
1019
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Status" }),
1020
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Difference Due" }),
1021
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Created" }),
1022
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Actions" })
1023
- ] }) }),
1024
- /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((swap) => /* @__PURE__ */ jsxRuntime.jsxs(
1025
- "tr",
985
+ ),
986
+ /* @__PURE__ */ jsxRuntime.jsx(
987
+ ui.Input,
1026
988
  {
1027
- className: "hover:bg-ui-bg-subtle/60 cursor-pointer",
1028
- onClick: () => navigate(`/swaps/${swap.id}`),
989
+ placeholder: "Currency",
990
+ value: currencySearch,
991
+ onChange: (e) => setCurrencySearch(e.target.value),
992
+ className: "md:max-w-[100px]",
993
+ "aria-label": "Filter by currency"
994
+ }
995
+ ),
996
+ /* @__PURE__ */ jsxRuntime.jsxs(
997
+ "select",
998
+ {
999
+ value: paymentStatusFilter,
1000
+ onChange: (e) => setPaymentStatusFilter(e.target.value),
1001
+ className: "h-9 rounded-md border border-ui-border-base bg-transparent px-3 text-sm text-ui-fg-base outline-none transition focus:ring-2 focus:ring-ui-fg-interactive md:max-w-[160px]",
1002
+ "aria-label": "Filter by payment status",
1029
1003
  children: [
1030
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-0.5", children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: swap.id }) }) }),
1031
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: swap.order_id }),
1032
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(
1033
- ui.Badge,
1034
- {
1035
- size: "2xsmall",
1036
- className: `uppercase ${getStatusBadgeClass$7(swap.status)}`,
1037
- children: swap.status.replace(/_/g, " ")
1038
- }
1039
- ) }),
1040
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: (() => {
1041
- const amount = swap.difference_due;
1042
- if (amount == null || amount === void 0) {
1043
- return "—";
1044
- }
1045
- const displayAmount = Number(amount) / 100;
1046
- const currency = swap.currency_code || "$";
1047
- const sign = displayAmount >= 0 ? "+" : "";
1048
- return `${sign}${currency}${displayAmount.toFixed(2)}`;
1049
- })() }),
1050
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: new Date(swap.created_at).toLocaleDateString("en-US", {
1051
- year: "numeric",
1052
- month: "short",
1053
- day: "numeric",
1054
- hour: "numeric",
1055
- minute: "2-digit",
1056
- hour12: true
1057
- }) }),
1058
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(
1059
- ui.Button,
1060
- {
1061
- variant: "transparent",
1062
- size: "small",
1063
- onClick: (e) => {
1064
- e.stopPropagation();
1065
- navigate(`/app/orders/${swap.order_id}`);
1066
- },
1067
- children: "Go to order"
1068
- }
1069
- ) })
1004
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "all", children: "All statuses" }),
1005
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "pending", children: "Pending" }),
1006
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "requires_more", children: "Requires more" }),
1007
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "error", children: "Error" }),
1008
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "canceled", children: "Canceled" }),
1009
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "authorized", children: "Authorized" }),
1010
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "captured", children: "Captured" })
1011
+ ]
1012
+ }
1013
+ ),
1014
+ /* @__PURE__ */ jsxRuntime.jsx(
1015
+ ui.Input,
1016
+ {
1017
+ type: "date",
1018
+ placeholder: "From",
1019
+ value: dateFrom,
1020
+ onChange: (e) => setDateFrom(e.target.value),
1021
+ className: "md:max-w-[140px]",
1022
+ "aria-label": "Date from"
1023
+ }
1024
+ ),
1025
+ /* @__PURE__ */ jsxRuntime.jsx(
1026
+ ui.Input,
1027
+ {
1028
+ type: "date",
1029
+ placeholder: "To",
1030
+ value: dateTo,
1031
+ onChange: (e) => setDateTo(e.target.value),
1032
+ className: "md:max-w-[140px]",
1033
+ "aria-label": "Date to"
1034
+ }
1035
+ ),
1036
+ /* @__PURE__ */ jsxRuntime.jsx(
1037
+ ui.Input,
1038
+ {
1039
+ placeholder: "Amount min",
1040
+ value: amountMin,
1041
+ onChange: (e) => setAmountMin(e.target.value),
1042
+ type: "number",
1043
+ min: 0,
1044
+ className: "md:max-w-[100px]",
1045
+ "aria-label": "Refund amount minimum"
1046
+ }
1047
+ ),
1048
+ /* @__PURE__ */ jsxRuntime.jsx(
1049
+ ui.Input,
1050
+ {
1051
+ placeholder: "Amount max",
1052
+ value: amountMax,
1053
+ onChange: (e) => setAmountMax(e.target.value),
1054
+ type: "number",
1055
+ min: 0,
1056
+ className: "md:max-w-[100px]",
1057
+ "aria-label": "Refund amount maximum"
1058
+ }
1059
+ )
1060
+ ] }) }),
1061
+ error ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
1062
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
1063
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", onClick: () => loadRefunds(0, true), children: "Try again" }) })
1064
+ ] }) : null,
1065
+ isLoading ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Loading refunds…" }) }) : items.length === 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-dashed border-ui-border-strong p-10 text-center", children: [
1066
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h3", className: "text-xl", children: "No refunds yet" }),
1067
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "mt-2 text-ui-fg-subtle", children: "Refund records will appear here." })
1068
+ ] }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full overflow-x-auto rounded-xl border border-ui-border-base", children: /* @__PURE__ */ jsxRuntime.jsxs("table", { className: "w-full table-fixed divide-y divide-ui-border-base", style: { minWidth: 0 }, children: [
1069
+ /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
1070
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "w-[11%] min-w-0 px-3 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Refund ID" }),
1071
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "w-[11%] min-w-0 px-3 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Order ID" }),
1072
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "w-[11%] min-w-0 px-3 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Payment ID" }),
1073
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "w-[8%] min-w-0 px-3 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Amount" }),
1074
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "w-[6%] min-w-0 px-3 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Currency" }),
1075
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "w-[10%] min-w-0 px-3 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Provider" }),
1076
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "w-[10%] min-w-0 px-3 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Payment Status" }),
1077
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "w-[14%] min-w-0 px-3 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Note" }),
1078
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "w-[11%] min-w-0 px-3 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Created" }),
1079
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "w-[8%] min-w-0 px-3 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Actions" })
1080
+ ] }) }),
1081
+ /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((r) => /* @__PURE__ */ jsxRuntime.jsxs(
1082
+ "tr",
1083
+ {
1084
+ className: "cursor-pointer hover:bg-ui-bg-subtle/60",
1085
+ onClick: () => navigate(`/refunds/${r.refund_id}`),
1086
+ children: [
1087
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 truncate px-3 py-3 font-mono text-sm text-ui-fg-base", title: r.refund_id, children: r.refund_id }),
1088
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 truncate px-3 py-3 font-medium text-ui-fg-base", title: r.order_id ?? void 0, children: r.order_id ?? "—" }),
1089
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 truncate px-3 py-3 font-mono text-sm text-ui-fg-subtle", title: r.payment_id, children: r.payment_id }),
1090
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 truncate px-3 py-3 text-ui-fg-subtle", children: displayAmount(r) }),
1091
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 truncate px-3 py-3 text-ui-fg-subtle uppercase", children: r.currency_code || "—" }),
1092
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 truncate px-3 py-3 text-ui-fg-subtle", title: r.provider_id || void 0, children: r.provider_id || "—" }),
1093
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 px-3 py-3", children: /* @__PURE__ */ jsxRuntime.jsx(
1094
+ ui.Badge,
1095
+ {
1096
+ size: "2xsmall",
1097
+ className: `uppercase ${getStatusBadgeClass$7(displayStatus(r))}`,
1098
+ children: displayStatus(r) !== "—" ? displayStatus(r).replace(/_/g, " ") : "—"
1099
+ }
1100
+ ) }),
1101
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 truncate px-3 py-3 text-ui-fg-subtle", title: r.note ?? void 0, children: r.note ?? "—" }),
1102
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 truncate px-3 py-3 text-ui-fg-subtle text-xs", children: new Date(r.created_at).toLocaleDateString("en-US", {
1103
+ month: "short",
1104
+ day: "numeric",
1105
+ hour: "numeric",
1106
+ minute: "2-digit",
1107
+ hour12: true
1108
+ }) }),
1109
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 px-3 py-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap gap-1", children: [
1110
+ /* @__PURE__ */ jsxRuntime.jsx(
1111
+ ui.Button,
1112
+ {
1113
+ variant: "transparent",
1114
+ size: "small",
1115
+ onClick: (e) => {
1116
+ e.stopPropagation();
1117
+ navigate(`/refunds/${r.refund_id}`);
1118
+ },
1119
+ children: "Details"
1120
+ }
1121
+ ),
1122
+ r.order_id ? /* @__PURE__ */ jsxRuntime.jsx(
1123
+ ui.Button,
1124
+ {
1125
+ variant: "transparent",
1126
+ size: "small",
1127
+ onClick: (e) => {
1128
+ e.stopPropagation();
1129
+ navigate(`/orders/${r.order_id}`);
1130
+ },
1131
+ children: "Order"
1132
+ }
1133
+ ) : null
1134
+ ] }) })
1070
1135
  ]
1071
1136
  },
1072
- swap.id
1137
+ r.refund_id
1073
1138
  )) })
1074
1139
  ] }) }),
1075
1140
  hasMore ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(
@@ -1077,15 +1142,15 @@ const SwapsPage = () => {
1077
1142
  {
1078
1143
  variant: "secondary",
1079
1144
  isLoading: isFetchingMore,
1080
- onClick: () => loadSwaps(offset, false),
1145
+ onClick: () => loadRefunds(offset, false),
1081
1146
  children: "Load more"
1082
1147
  }
1083
1148
  ) }) : null
1084
1149
  ] }) });
1085
1150
  };
1086
1151
  const config$7 = adminSdk.defineRouteConfig({
1087
- label: "Exchanges",
1088
- icon: icons.ArrowPath
1152
+ label: "Refunds",
1153
+ icon: icons.Receipt
1089
1154
  });
1090
1155
  const useDebounce$2 = (value, delay) => {
1091
1156
  const [debouncedValue, setDebouncedValue] = react.useState(value);
@@ -1528,275 +1593,210 @@ const useDebounce = (value, delay) => {
1528
1593
  return debouncedValue;
1529
1594
  };
1530
1595
  const getStatusBadgeClass$4 = (status) => {
1531
- const s2 = status.toLowerCase();
1532
- if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
1533
- if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
1534
- if (s2 === "error" || s2 === "canceled" || s2 === "cancelled") return "bg-ui-tag-red-bg text-ui-tag-red-text";
1535
- if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
1596
+ const statusLower = status.toLowerCase();
1597
+ if (statusLower === "requested") {
1598
+ return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
1599
+ }
1600
+ if (statusLower === "approved") {
1601
+ return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
1602
+ }
1603
+ if (statusLower === "rejected") {
1604
+ return "bg-ui-tag-red-bg text-ui-tag-red-text";
1605
+ }
1606
+ if (statusLower === "completed") {
1607
+ return "bg-ui-tag-green-bg text-ui-tag-green-text";
1608
+ }
1609
+ if (statusLower === "cancelled") {
1610
+ return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
1611
+ }
1536
1612
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
1537
1613
  };
1538
- const RefundsPage = () => {
1614
+ const SwapsPage = () => {
1539
1615
  const navigate = reactRouterDom.useNavigate();
1540
1616
  const [items, setItems] = react.useState([]);
1541
- const [orderIdSearch, setOrderIdSearch] = react.useState("");
1542
- const debouncedOrderId = useDebounce(orderIdSearch, 300);
1543
- const [paymentStatusFilter, setPaymentStatusFilter] = react.useState("all");
1544
- const [providerSearch, setProviderSearch] = react.useState("");
1545
- const debouncedProvider = useDebounce(providerSearch, 300);
1546
- const [currencySearch, setCurrencySearch] = react.useState("");
1547
- const debouncedCurrency = useDebounce(currencySearch, 300);
1548
- const [dateFrom, setDateFrom] = react.useState("");
1549
- const [dateTo, setDateTo] = react.useState("");
1550
- const [amountMin, setAmountMin] = react.useState("");
1551
- const [amountMax, setAmountMax] = react.useState("");
1617
+ const [statusFilter, setStatusFilter] = react.useState("all");
1618
+ const [createdByFilter, setCreatedByFilter] = react.useState("all");
1619
+ const [searchQuery, setSearchQuery] = react.useState("");
1620
+ const debouncedSearchQuery = useDebounce(searchQuery, 300);
1552
1621
  const [isLoading, setIsLoading] = react.useState(true);
1553
1622
  const [isFetchingMore, setIsFetchingMore] = react.useState(false);
1554
1623
  const [error, setError] = react.useState(null);
1555
1624
  const [offset, setOffset] = react.useState(0);
1556
1625
  const [count, setCount] = react.useState(0);
1557
1626
  const limit = 50;
1558
- const loadRefunds = react.useCallback(
1559
- async (nextOffset, replace) => {
1627
+ const loadSwaps = react.useCallback(
1628
+ async (nextOffset, replace = false) => {
1629
+ var _a;
1560
1630
  try {
1561
- if (replace) setIsLoading(true);
1562
- else setIsFetchingMore(true);
1631
+ if (replace) {
1632
+ setIsLoading(true);
1633
+ } else {
1634
+ setIsFetchingMore(true);
1635
+ }
1563
1636
  setError(null);
1564
1637
  const params = new URLSearchParams();
1565
1638
  params.set("limit", String(limit));
1566
1639
  params.set("offset", String(nextOffset));
1567
- if (debouncedOrderId.trim()) params.set("order_id", debouncedOrderId.trim());
1568
- if (paymentStatusFilter !== "all") params.set("payment_status", paymentStatusFilter);
1569
- if (debouncedProvider.trim()) params.set("provider_id", debouncedProvider.trim());
1570
- if (debouncedCurrency.trim()) params.set("currency_code", debouncedCurrency.trim());
1571
- if (dateFrom.trim()) params.set("date_from", dateFrom.trim());
1572
- if (dateTo.trim()) params.set("date_to", dateTo.trim());
1573
- const min = amountMin.trim() ? Number(amountMin) : void 0;
1574
- const max = amountMax.trim() ? Number(amountMax) : void 0;
1575
- if (min != null && !Number.isNaN(min)) params.set("amount_min", String(min));
1576
- if (max != null && !Number.isNaN(max)) params.set("amount_max", String(max));
1577
- const response = await fetch(`/admin/refunds?${params.toString()}`, {
1578
- credentials: "include"
1579
- });
1640
+ if (statusFilter !== "all") {
1641
+ params.set("status", statusFilter);
1642
+ }
1643
+ if (debouncedSearchQuery.trim()) {
1644
+ params.set("order_id", debouncedSearchQuery.trim());
1645
+ }
1646
+ if (createdByFilter !== "all") {
1647
+ params.set("created_by", createdByFilter);
1648
+ }
1649
+ const response = await fetch(
1650
+ `/admin/swaps?${params.toString()}`,
1651
+ { credentials: "include" }
1652
+ );
1580
1653
  if (!response.ok) {
1581
- const text = await response.text();
1582
- throw new Error(text || "Failed to load refunds");
1654
+ const message = await response.text();
1655
+ throw new Error(message || "Unable to load swaps");
1583
1656
  }
1584
1657
  const payload = await response.json();
1585
- const list = payload.refunds ?? [];
1586
1658
  setCount(payload.count ?? 0);
1587
- setOffset(nextOffset + list.length);
1588
- setItems((prev) => replace ? list : [...prev, ...list]);
1589
- } catch (e) {
1590
- setError(e instanceof Error ? e.message : "Failed to load");
1659
+ setOffset(nextOffset + (((_a = payload.swaps) == null ? void 0 : _a.length) ?? 0));
1660
+ setItems(
1661
+ (prev) => replace ? payload.swaps ?? [] : [...prev, ...payload.swaps ?? []]
1662
+ );
1663
+ } catch (loadError) {
1664
+ const message = loadError instanceof Error ? loadError.message : "Unable to load swaps";
1665
+ setError(message);
1591
1666
  } finally {
1592
1667
  setIsLoading(false);
1593
1668
  setIsFetchingMore(false);
1594
1669
  }
1595
1670
  },
1596
- [
1597
- debouncedOrderId,
1598
- paymentStatusFilter,
1599
- debouncedProvider,
1600
- debouncedCurrency,
1601
- dateFrom,
1602
- dateTo,
1603
- amountMin,
1604
- amountMax
1605
- ]
1671
+ [statusFilter, createdByFilter, debouncedSearchQuery]
1606
1672
  );
1607
1673
  react.useEffect(() => {
1608
- void loadRefunds(0, true);
1609
- }, [loadRefunds]);
1674
+ void loadSwaps(0, true);
1675
+ }, [statusFilter, createdByFilter, debouncedSearchQuery, loadSwaps]);
1610
1676
  const hasMore = react.useMemo(() => offset < count, [offset, count]);
1611
- const displayAmount = (r) => {
1612
- const code = (r.currency_code ?? "USD").toUpperCase();
1613
- return `${code} ${Number(r.amount)}`;
1614
- };
1615
- const displayStatus = (r) => {
1616
- const s2 = r.payment_status ?? "";
1617
- return s2 !== "" ? s2 : "—";
1618
- };
1677
+ const availableStatuses = react.useMemo(() => {
1678
+ const statuses = /* @__PURE__ */ new Set();
1679
+ items.forEach((item) => statuses.add(item.status));
1680
+ return Array.from(statuses).sort();
1681
+ }, [items]);
1619
1682
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "mx-auto flex w-full max-w-7xl flex-col gap-6 p-6", children: [
1620
1683
  /* @__PURE__ */ jsxRuntime.jsxs("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
1621
1684
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
1622
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Refunds" }),
1623
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Refund records — amount, order, payment status" })
1685
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Exchanges" }),
1686
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "View and manage all customer exchange requests" })
1624
1687
  ] }),
1625
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "primary", onClick: () => loadRefunds(0, true), children: "Refresh" })
1688
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "primary", onClick: () => loadSwaps(0, true), children: "Refresh" })
1626
1689
  ] }),
1627
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap items-center gap-3", children: [
1690
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
1628
1691
  /* @__PURE__ */ jsxRuntime.jsx(
1629
1692
  ui.Input,
1630
1693
  {
1631
- placeholder: "Order ID",
1632
- value: orderIdSearch,
1633
- onChange: (e) => setOrderIdSearch(e.target.value),
1634
- className: "md:max-w-[180px]",
1635
- "aria-label": "Filter by order ID"
1636
- }
1637
- ),
1638
- /* @__PURE__ */ jsxRuntime.jsx(
1639
- ui.Input,
1640
- {
1641
- placeholder: "Provider",
1642
- value: providerSearch,
1643
- onChange: (e) => setProviderSearch(e.target.value),
1644
- className: "md:max-w-[140px]",
1645
- "aria-label": "Filter by provider"
1646
- }
1647
- ),
1648
- /* @__PURE__ */ jsxRuntime.jsx(
1649
- ui.Input,
1650
- {
1651
- placeholder: "Currency",
1652
- value: currencySearch,
1653
- onChange: (e) => setCurrencySearch(e.target.value),
1654
- className: "md:max-w-[100px]",
1655
- "aria-label": "Filter by currency"
1656
- }
1657
- ),
1658
- /* @__PURE__ */ jsxRuntime.jsxs(
1659
- "select",
1660
- {
1661
- value: paymentStatusFilter,
1662
- onChange: (e) => setPaymentStatusFilter(e.target.value),
1663
- className: "h-9 rounded-md border border-ui-border-base bg-transparent px-3 text-sm text-ui-fg-base outline-none transition focus:ring-2 focus:ring-ui-fg-interactive md:max-w-[160px]",
1664
- "aria-label": "Filter by payment status",
1665
- children: [
1666
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "all", children: "All statuses" }),
1667
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "pending", children: "Pending" }),
1668
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "requires_more", children: "Requires more" }),
1669
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "error", children: "Error" }),
1670
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "canceled", children: "Canceled" }),
1671
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "authorized", children: "Authorized" }),
1672
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "captured", children: "Captured" })
1673
- ]
1674
- }
1675
- ),
1676
- /* @__PURE__ */ jsxRuntime.jsx(
1677
- ui.Input,
1678
- {
1679
- type: "date",
1680
- placeholder: "From",
1681
- value: dateFrom,
1682
- onChange: (e) => setDateFrom(e.target.value),
1683
- className: "md:max-w-[140px]",
1684
- "aria-label": "Date from"
1685
- }
1686
- ),
1687
- /* @__PURE__ */ jsxRuntime.jsx(
1688
- ui.Input,
1689
- {
1690
- type: "date",
1691
- placeholder: "To",
1692
- value: dateTo,
1693
- onChange: (e) => setDateTo(e.target.value),
1694
- className: "md:max-w-[140px]",
1695
- "aria-label": "Date to"
1696
- }
1697
- ),
1698
- /* @__PURE__ */ jsxRuntime.jsx(
1699
- ui.Input,
1700
- {
1701
- placeholder: "Amount min",
1702
- value: amountMin,
1703
- onChange: (e) => setAmountMin(e.target.value),
1704
- type: "number",
1705
- min: 0,
1706
- className: "md:max-w-[100px]",
1707
- "aria-label": "Refund amount minimum"
1694
+ placeholder: "Search by swap ID or order ID",
1695
+ value: searchQuery,
1696
+ onChange: (event) => setSearchQuery(event.target.value),
1697
+ className: "md:max-w-sm"
1708
1698
  }
1709
1699
  ),
1710
- /* @__PURE__ */ jsxRuntime.jsx(
1711
- ui.Input,
1712
- {
1713
- placeholder: "Amount max",
1714
- value: amountMax,
1715
- onChange: (e) => setAmountMax(e.target.value),
1716
- type: "number",
1717
- min: 0,
1718
- className: "md:max-w-[100px]",
1719
- "aria-label": "Refund amount maximum"
1720
- }
1721
- )
1722
- ] }) }),
1700
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-3", children: [
1701
+ /* @__PURE__ */ jsxRuntime.jsxs(
1702
+ "select",
1703
+ {
1704
+ value: createdByFilter,
1705
+ onChange: (event) => setCreatedByFilter(event.target.value),
1706
+ className: "h-9 rounded-md border border-ui-border-base bg-transparent px-3 text-sm text-ui-fg-base outline-none transition focus:ring-2 focus:ring-ui-fg-interactive md:max-w-xs",
1707
+ children: [
1708
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "all", children: "All (Created by)" }),
1709
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "customer", children: "Customer" }),
1710
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "admin", children: "Admin" })
1711
+ ]
1712
+ }
1713
+ ),
1714
+ /* @__PURE__ */ jsxRuntime.jsxs(
1715
+ "select",
1716
+ {
1717
+ value: statusFilter,
1718
+ onChange: (event) => setStatusFilter(event.target.value),
1719
+ className: "h-9 rounded-md border border-ui-border-base bg-transparent px-3 text-sm text-ui-fg-base outline-none transition focus:ring-2 focus:ring-ui-fg-interactive md:max-w-xs",
1720
+ children: [
1721
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "all", children: "All Statuses" }),
1722
+ availableStatuses.map((status) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: status, children: status.replace(/_/g, " ").toUpperCase() }, status))
1723
+ ]
1724
+ }
1725
+ )
1726
+ ] })
1727
+ ] }),
1723
1728
  error ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
1724
1729
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
1725
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", onClick: () => loadRefunds(0, true), children: "Try again" }) })
1730
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(
1731
+ ui.Button,
1732
+ {
1733
+ variant: "secondary",
1734
+ onClick: () => loadSwaps(0, true),
1735
+ children: "Try again"
1736
+ }
1737
+ ) })
1726
1738
  ] }) : null,
1727
- isLoading ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Loading refunds…" }) }) : items.length === 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-dashed border-ui-border-strong p-10 text-center", children: [
1728
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h3", className: "text-xl", children: "No refunds yet" }),
1729
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "mt-2 text-ui-fg-subtle", children: "Refund records will appear here." })
1730
- ] }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full overflow-x-auto rounded-xl border border-ui-border-base", children: /* @__PURE__ */ jsxRuntime.jsxs("table", { className: "w-full table-fixed divide-y divide-ui-border-base", style: { minWidth: 0 }, children: [
1739
+ isLoading ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Loading swaps..." }) }) : items.length === 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-dashed border-ui-border-strong p-10 text-center", children: [
1740
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h3", className: "text-xl", children: "No exchanges yet" }),
1741
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "mt-2 text-ui-fg-subtle", children: "Exchange requests created by customers will appear here." })
1742
+ ] }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "overflow-hidden rounded-xl border border-ui-border-base", children: /* @__PURE__ */ jsxRuntime.jsxs("table", { className: "min-w-full divide-y divide-ui-border-base", children: [
1731
1743
  /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
1732
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "w-[11%] min-w-0 px-3 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Refund ID" }),
1733
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "w-[11%] min-w-0 px-3 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Order ID" }),
1734
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "w-[11%] min-w-0 px-3 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Payment ID" }),
1735
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "w-[8%] min-w-0 px-3 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Amount" }),
1736
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "w-[6%] min-w-0 px-3 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Currency" }),
1737
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "w-[10%] min-w-0 px-3 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Provider" }),
1738
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "w-[10%] min-w-0 px-3 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Payment Status" }),
1739
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "w-[14%] min-w-0 px-3 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Note" }),
1740
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "w-[11%] min-w-0 px-3 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Created" }),
1741
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "w-[8%] min-w-0 px-3 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Actions" })
1744
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Exchange ID" }),
1745
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Order ID" }),
1746
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Status" }),
1747
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Difference Due" }),
1748
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Created" }),
1749
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Actions" })
1742
1750
  ] }) }),
1743
- /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((r) => /* @__PURE__ */ jsxRuntime.jsxs(
1751
+ /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((swap) => /* @__PURE__ */ jsxRuntime.jsxs(
1744
1752
  "tr",
1745
1753
  {
1746
- className: "cursor-pointer hover:bg-ui-bg-subtle/60",
1747
- onClick: () => navigate(`/refunds/${r.refund_id}`),
1754
+ className: "hover:bg-ui-bg-subtle/60 cursor-pointer",
1755
+ onClick: () => navigate(`/swaps/${swap.id}`),
1748
1756
  children: [
1749
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 truncate px-3 py-3 font-mono text-sm text-ui-fg-base", title: r.refund_id, children: r.refund_id }),
1750
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 truncate px-3 py-3 font-medium text-ui-fg-base", title: r.order_id ?? void 0, children: r.order_id ?? "—" }),
1751
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 truncate px-3 py-3 font-mono text-sm text-ui-fg-subtle", title: r.payment_id, children: r.payment_id }),
1752
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 truncate px-3 py-3 text-ui-fg-subtle", children: displayAmount(r) }),
1753
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 truncate px-3 py-3 text-ui-fg-subtle uppercase", children: r.currency_code || "—" }),
1754
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 truncate px-3 py-3 text-ui-fg-subtle", title: r.provider_id || void 0, children: r.provider_id || "—" }),
1755
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 px-3 py-3", children: /* @__PURE__ */ jsxRuntime.jsx(
1757
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-0.5", children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: swap.id }) }) }),
1758
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: swap.order_id }),
1759
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(
1756
1760
  ui.Badge,
1757
1761
  {
1758
1762
  size: "2xsmall",
1759
- className: `uppercase ${getStatusBadgeClass$4(displayStatus(r))}`,
1760
- children: displayStatus(r) !== "—" ? displayStatus(r).replace(/_/g, " ") : "—"
1763
+ className: `uppercase ${getStatusBadgeClass$4(swap.status)}`,
1764
+ children: swap.status.replace(/_/g, " ")
1761
1765
  }
1762
1766
  ) }),
1763
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 truncate px-3 py-3 text-ui-fg-subtle", title: r.note ?? void 0, children: r.note ?? "—" }),
1764
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 truncate px-3 py-3 text-ui-fg-subtle text-xs", children: new Date(r.created_at).toLocaleDateString("en-US", {
1767
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: (() => {
1768
+ const amount = swap.difference_due;
1769
+ if (amount == null || amount === void 0) {
1770
+ return "—";
1771
+ }
1772
+ const displayAmount = Number(amount) / 100;
1773
+ const currency = swap.currency_code || "$";
1774
+ const sign = displayAmount >= 0 ? "+" : "";
1775
+ return `${sign}${currency}${displayAmount.toFixed(2)}`;
1776
+ })() }),
1777
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: new Date(swap.created_at).toLocaleDateString("en-US", {
1778
+ year: "numeric",
1765
1779
  month: "short",
1766
1780
  day: "numeric",
1767
1781
  hour: "numeric",
1768
1782
  minute: "2-digit",
1769
1783
  hour12: true
1770
1784
  }) }),
1771
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "min-w-0 px-3 py-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap gap-1", children: [
1772
- /* @__PURE__ */ jsxRuntime.jsx(
1773
- ui.Button,
1774
- {
1775
- variant: "transparent",
1776
- size: "small",
1777
- onClick: (e) => {
1778
- e.stopPropagation();
1779
- navigate(`/refunds/${r.refund_id}`);
1780
- },
1781
- children: "Details"
1782
- }
1783
- ),
1784
- r.order_id ? /* @__PURE__ */ jsxRuntime.jsx(
1785
- ui.Button,
1786
- {
1787
- variant: "transparent",
1788
- size: "small",
1789
- onClick: (e) => {
1790
- e.stopPropagation();
1791
- navigate(`/orders/${r.order_id}`);
1792
- },
1793
- children: "Order"
1794
- }
1795
- ) : null
1796
- ] }) })
1785
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(
1786
+ ui.Button,
1787
+ {
1788
+ variant: "transparent",
1789
+ size: "small",
1790
+ onClick: (e) => {
1791
+ e.stopPropagation();
1792
+ navigate(`/app/orders/${swap.order_id}`);
1793
+ },
1794
+ children: "Go to order"
1795
+ }
1796
+ ) })
1797
1797
  ]
1798
1798
  },
1799
- r.refund_id
1799
+ swap.id
1800
1800
  )) })
1801
1801
  ] }) }),
1802
1802
  hasMore ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(
@@ -1804,294 +1804,207 @@ const RefundsPage = () => {
1804
1804
  {
1805
1805
  variant: "secondary",
1806
1806
  isLoading: isFetchingMore,
1807
- onClick: () => loadRefunds(offset, false),
1807
+ onClick: () => loadSwaps(offset, false),
1808
1808
  children: "Load more"
1809
1809
  }
1810
1810
  ) }) : null
1811
1811
  ] }) });
1812
1812
  };
1813
1813
  const config$4 = adminSdk.defineRouteConfig({
1814
- label: "Refunds",
1815
- icon: icons.Receipt
1814
+ label: "Exchanges",
1815
+ icon: icons.ArrowPath
1816
1816
  });
1817
1817
  const getStatusBadgeClass$3 = (status) => {
1818
- const statusLower = status.toLowerCase();
1819
- if (statusLower === "requested") {
1820
- return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
1821
- }
1822
- if (statusLower === "approved") {
1823
- return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
1824
- }
1825
- if (statusLower === "rejected") {
1826
- return "bg-ui-tag-red-bg text-ui-tag-red-text";
1827
- }
1828
- if (statusLower === "completed") {
1829
- return "bg-ui-tag-green-bg text-ui-tag-green-text";
1830
- }
1831
- if (statusLower === "cancelled" || statusLower === "canceled") {
1832
- return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
1833
- }
1834
- if (statusLower === "pending") {
1835
- return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
1836
- }
1818
+ const s2 = status.toLowerCase();
1819
+ if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
1820
+ if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
1821
+ if (s2 === "error" || s2 === "canceled" || s2 === "cancelled") return "bg-ui-tag-red-bg text-ui-tag-red-text";
1822
+ if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
1837
1823
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
1838
1824
  };
1839
- const SwapDetailPage = () => {
1825
+ const formatAmount = (value) => {
1826
+ return String(value);
1827
+ };
1828
+ const RefundDetailPage = () => {
1840
1829
  var _a, _b, _c;
1841
1830
  const navigate = reactRouterDom.useNavigate();
1842
- const { id } = reactRouterDom.useParams();
1843
- const [swap, setSwap] = react.useState(null);
1844
- const [order, setOrder] = react.useState(null);
1845
- const [isLoading, setIsLoading] = react.useState(true);
1846
- react.useState(false);
1847
- const [isCancelling, setIsCancelling] = react.useState(false);
1831
+ const params = reactRouterDom.useParams();
1832
+ const id = (_a = params == null ? void 0 : params.id) == null ? void 0 : _a.trim();
1833
+ const [detail, setDetail] = react.useState(null);
1834
+ const [loading, setLoading] = react.useState(!!id);
1848
1835
  const [error, setError] = react.useState(null);
1849
- const [updateError, setUpdateError] = react.useState(null);
1850
- const [updateSuccess, setUpdateSuccess] = react.useState(false);
1836
+ const [gatewayExpanded, setGatewayExpanded] = react.useState(false);
1851
1837
  react.useEffect(() => {
1852
1838
  if (!id) {
1853
- navigate("/swaps");
1839
+ setLoading(false);
1854
1840
  return;
1855
1841
  }
1856
- const loadSwap = async () => {
1857
- try {
1858
- setIsLoading(true);
1859
- setError(null);
1860
- const response = await fetch(`/admin/swaps/${id}`, {
1861
- credentials: "include"
1862
- });
1863
- if (!response.ok) {
1864
- const message = await response.text();
1865
- throw new Error(message || "Unable to load swap");
1866
- }
1867
- const payload = await response.json();
1868
- setSwap(payload.swap);
1869
- setOrder(payload.order || null);
1870
- } catch (loadError) {
1871
- const message = loadError instanceof Error ? loadError.message : "Unable to load swap";
1872
- setError(message);
1873
- } finally {
1874
- setIsLoading(false);
1875
- }
1842
+ let cancelled = false;
1843
+ setLoading(true);
1844
+ setError(null);
1845
+ fetch(`/admin/refunds/${id}`, { credentials: "include" }).then((res) => {
1846
+ if (!res.ok) throw new Error(res.statusText || "Failed to load");
1847
+ return res.json();
1848
+ }).then((data) => {
1849
+ if (!cancelled) setDetail(data);
1850
+ }).catch((e) => {
1851
+ if (!cancelled) setError(e instanceof Error ? e.message : "Failed to load");
1852
+ }).finally(() => {
1853
+ if (!cancelled) setLoading(false);
1854
+ });
1855
+ return () => {
1856
+ cancelled = true;
1876
1857
  };
1877
- void loadSwap();
1878
- }, [id, navigate]);
1879
- const handleCancelExchange = async () => {
1880
- if (!id) {
1881
- return;
1882
- }
1883
- try {
1884
- setIsCancelling(true);
1885
- setUpdateError(null);
1886
- setUpdateSuccess(false);
1887
- const response = await fetch(`/admin/swaps/${id}/cancel`, {
1888
- method: "POST",
1889
- headers: {
1890
- "Content-Type": "application/json"
1891
- },
1892
- credentials: "include"
1893
- });
1894
- if (!response.ok) {
1895
- const message = await response.text();
1896
- throw new Error(message || "Unable to cancel exchange");
1897
- }
1898
- const payload = await response.json();
1899
- setSwap(payload.swap);
1900
- setUpdateSuccess(true);
1901
- setTimeout(() => setUpdateSuccess(false), 3e3);
1902
- const detailResponse = await fetch(`/admin/swaps/${id}`, {
1903
- credentials: "include"
1904
- });
1905
- if (detailResponse.ok) {
1906
- const detailPayload = await detailResponse.json();
1907
- setSwap(detailPayload.swap);
1908
- setOrder(detailPayload.order || null);
1909
- }
1910
- } catch (cancelErr) {
1911
- const message = cancelErr instanceof Error ? cancelErr.message : "Unable to cancel exchange";
1912
- setUpdateError(message);
1913
- } finally {
1914
- setIsCancelling(false);
1915
- }
1916
- };
1917
- const isOrderExchange = Boolean(swap == null ? void 0 : swap.exchange_id);
1918
- const canCancelExchange = isOrderExchange && swap && !["cancelled", "canceled", "completed", "declined"].includes(
1919
- ((_a = swap.status) == null ? void 0 : _a.toLowerCase()) ?? ""
1920
- );
1921
- if (isLoading) {
1922
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "mx-auto flex w-full max-w-5xl flex-col gap-6 p-6", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Loading swap..." }) }) }) });
1923
- }
1924
- if (error || !swap) {
1925
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "mx-auto flex w-full max-w-5xl flex-col gap-6 p-6", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
1926
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error || "Swap not found" }),
1927
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", onClick: () => navigate("/swaps"), children: "Back to list" }) })
1928
- ] }) }) });
1929
- }
1930
- const statusHistory = ((_b = swap.metadata) == null ? void 0 : _b.status_history) || [];
1931
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "mx-auto flex w-full max-w-5xl flex-col gap-6 p-6", children: [
1932
- /* @__PURE__ */ jsxRuntime.jsxs("header", { className: "flex flex-col gap-3", children: [
1933
- /* @__PURE__ */ jsxRuntime.jsxs(
1934
- ui.Button,
1935
- {
1936
- variant: "transparent",
1937
- size: "small",
1938
- onClick: () => navigate("/swaps"),
1939
- className: "w-fit",
1940
- children: [
1941
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowLeft, { className: "mr-2" }),
1942
- "Back to list"
1943
- ]
1944
- }
1945
- ),
1946
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1 md:flex-row md:items-center md:justify-between", children: [
1947
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
1948
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Exchange Details" }),
1949
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: swap.id })
1950
- ] }),
1951
- /* @__PURE__ */ jsxRuntime.jsx(
1952
- ui.Badge,
1953
- {
1954
- size: "small",
1955
- className: `uppercase ${getStatusBadgeClass$3(swap.status)}`,
1956
- children: swap.status.replace(/_/g, " ")
1957
- }
1958
- )
1959
- ] })
1960
- ] }),
1961
- canCancelExchange && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
1962
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex gap-3", children: /* @__PURE__ */ jsxRuntime.jsx(
1963
- ui.Button,
1964
- {
1965
- variant: "danger",
1966
- onClick: handleCancelExchange,
1967
- disabled: isCancelling,
1968
- isLoading: isCancelling,
1969
- children: "Cancel Exchange"
1970
- }
1971
- ) }),
1972
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This will cancel the exchange request. The order will remain unchanged." })
1973
- ] }),
1974
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid gap-6 md:grid-cols-2", children: [
1975
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
1976
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Exchange Information" }),
1977
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
1858
+ }, [id]);
1859
+ const paymentStatus = ((_b = detail == null ? void 0 : detail.payment) == null ? void 0 : _b.status) ?? "—";
1860
+ const hasGatewayData = ((_c = detail == null ? void 0 : detail.payment) == null ? void 0 : _c.payment_data) && typeof detail.payment.payment_data === "object" && Object.keys(detail.payment.payment_data).length > 0;
1861
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "mx-auto flex w-full max-w-4xl flex-col gap-6 p-6", children: [
1862
+ /* @__PURE__ */ jsxRuntime.jsx("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
1863
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "transparent", size: "small", onClick: () => navigate("/refunds"), children: "← Refunds" }),
1864
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Refund details" }),
1865
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle font-mono", children: id ?? "—" })
1866
+ ] }) }),
1867
+ error ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
1868
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
1869
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", className: "mt-4", onClick: () => navigate("/refunds"), children: "Back to list" })
1870
+ ] }) : loading ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Loading…" }) }) : detail ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-6", children: [
1871
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
1872
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "text-lg mb-4", children: "Refund summary" }),
1873
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
1978
1874
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1979
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Exchange ID" }),
1980
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.id })
1875
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Refund ID" }),
1876
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block font-mono text-sm", children: detail.refund.id })
1981
1877
  ] }),
1982
1878
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1983
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Status" }),
1984
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.status })
1879
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Amount" }),
1880
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.refund.amount) })
1985
1881
  ] }),
1986
1882
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1987
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Difference Due" }),
1988
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.difference_due != null ? `${swap.currency_code || "$"}${(Number(swap.difference_due) / 100).toFixed(2)}` : "—" })
1883
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Note" }),
1884
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.refund.note ?? "—" })
1989
1885
  ] }),
1990
- swap.reason && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1991
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Reason" }),
1992
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.reason })
1886
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1887
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Created at" }),
1888
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: new Date(detail.refund.created_at).toLocaleDateString("en-US", {
1889
+ year: "numeric",
1890
+ month: "short",
1891
+ day: "numeric",
1892
+ hour: "numeric",
1893
+ minute: "2-digit",
1894
+ hour12: true
1895
+ }) })
1993
1896
  ] }),
1994
- swap.note && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1995
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Note" }),
1996
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.note })
1897
+ detail.refund.created_by ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1898
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Created by" }),
1899
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block font-mono text-sm", children: detail.refund.created_by })
1900
+ ] }) : null
1901
+ ] })
1902
+ ] }),
1903
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
1904
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "text-lg mb-4", children: "Payment summary" }),
1905
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
1906
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1907
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Payment amount" }),
1908
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.payment.payment_amount) })
1997
1909
  ] }),
1998
1910
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1999
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Created" }),
2000
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: new Date(swap.created_at).toLocaleString() })
1911
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Captured amount" }),
1912
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.payment.captured_amount) })
2001
1913
  ] }),
2002
1914
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2003
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Last Updated" }),
2004
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: new Date(swap.updated_at).toLocaleString() })
1915
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Refunded amount" }),
1916
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.payment.refunded_amount) })
2005
1917
  ] }),
2006
- swap.exchange_id && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2007
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Exchange ID" }),
2008
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.exchange_id })
2009
- ] })
2010
- ] })
2011
- ] }),
2012
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2013
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Status History" }),
2014
- statusHistory.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-2", children: statusHistory.map((entry, index) => /* @__PURE__ */ jsxRuntime.jsx(
2015
- "div",
2016
- {
2017
- className: "flex items-center justify-between border-b border-ui-border-subtle pb-2 last:border-0",
2018
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
2019
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center gap-2", children: /* @__PURE__ */ jsxRuntime.jsx(
2020
- ui.Badge,
2021
- {
2022
- size: "2xsmall",
2023
- className: `uppercase ${getStatusBadgeClass$3(entry.status)}`,
2024
- children: entry.status.replace(/_/g, " ")
2025
- }
2026
- ) }),
2027
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
2028
- new Date(entry.timestamp).toLocaleString(),
2029
- entry.admin_id && ` by ${entry.admin_id}`,
2030
- entry.reason && ` - ${entry.reason}`
1918
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1919
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Provider" }),
1920
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.payment.provider_id || "—" })
1921
+ ] }),
1922
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1923
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Status" }),
1924
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsxRuntime.jsx(
1925
+ ui.Badge,
1926
+ {
1927
+ size: "2xsmall",
1928
+ className: `uppercase ${getStatusBadgeClass$3(paymentStatus)}`,
1929
+ children: paymentStatus !== "—" ? paymentStatus.replace(/_/g, " ") : "—"
1930
+ }
1931
+ ) })
1932
+ ] }),
1933
+ detail.computed ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1934
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1935
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Full refund" }),
1936
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.computed.is_full_refund ? "Yes" : "No" })
1937
+ ] }),
1938
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1939
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Remaining refundable" }),
1940
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.computed.remaining_refundable_amount) })
1941
+ ] }),
1942
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1943
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Refund %" }),
1944
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { className: "mt-1 block", children: [
1945
+ detail.computed.refund_percentage.toFixed(1),
1946
+ "%"
2031
1947
  ] })
2032
1948
  ] })
2033
- },
2034
- index
2035
- )) }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "No status history available" })
2036
- ] })
2037
- ] }),
2038
- order && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2039
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Related Order Information" }),
2040
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
2041
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2042
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Order ID" }),
2043
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: order.id })
2044
- ] }),
2045
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2046
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Status" }),
2047
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: order.status || "—" })
2048
- ] }),
2049
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2050
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Customer" }),
2051
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: ((_c = order.customer) == null ? void 0 : _c.email) || order.email || "—" })
2052
- ] }),
2053
- order.total && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2054
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Total" }),
2055
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { className: "font-medium", children: [
2056
- order.currency_code || "$",
2057
- (Number(order.total) / 100).toFixed(2)
2058
- ] })
1949
+ ] }) : null
2059
1950
  ] })
1951
+ ] }),
1952
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
1953
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "text-lg mb-4", children: "Order summary" }),
1954
+ detail.order ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
1955
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1956
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Order" }),
1957
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsxRuntime.jsx(
1958
+ ui.Button,
1959
+ {
1960
+ variant: "transparent",
1961
+ size: "small",
1962
+ onClick: () => navigate(`/orders/${detail.order.order_id}`),
1963
+ children: detail.order.order_number ?? detail.order.order_id
1964
+ }
1965
+ ) })
1966
+ ] }),
1967
+ detail.order.total != null ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1968
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Total" }),
1969
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.order.total) })
1970
+ ] }) : null,
1971
+ detail.order.customer_id ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1972
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Customer ID" }),
1973
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block font-mono text-sm", children: detail.order.customer_id })
1974
+ ] }) : null,
1975
+ detail.order.region ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1976
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Region" }),
1977
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.order.region })
1978
+ ] }) : null,
1979
+ detail.order.fulfillment_status ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1980
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Fulfillment status" }),
1981
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.order.fulfillment_status })
1982
+ ] }) : null
1983
+ ] }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "No order linked to this refund." })
1984
+ ] }),
1985
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
1986
+ /* @__PURE__ */ jsxRuntime.jsxs(
1987
+ "button",
1988
+ {
1989
+ type: "button",
1990
+ className: "flex w-full items-center justify-between text-left",
1991
+ onClick: () => setGatewayExpanded((prev) => !prev),
1992
+ "aria-expanded": gatewayExpanded,
1993
+ "aria-label": gatewayExpanded ? "Collapse gateway data" : "Expand gateway data",
1994
+ children: [
1995
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "text-lg", children: "Gateway data" }),
1996
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: gatewayExpanded ? "Collapse" : "Expand" })
1997
+ ]
1998
+ }
1999
+ ),
2000
+ gatewayExpanded && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-4", children: hasGatewayData ? /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "text-xs bg-ui-bg-subtle p-4 rounded-lg overflow-auto max-h-96", children: JSON.stringify(detail.payment.payment_data, null, 2) }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "No gateway payload for this payment." }) })
2060
2001
  ] })
2061
- ] }),
2062
- swap.return_items && swap.return_items.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2063
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Items" }),
2064
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "overflow-hidden rounded-xl border border-ui-border-base", children: /* @__PURE__ */ jsxRuntime.jsxs("table", { className: "min-w-full divide-y divide-ui-border-base", children: [
2065
- /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
2066
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Item ID" }),
2067
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Quantity" }),
2068
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Reason" })
2069
- ] }) }),
2070
- /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: swap.return_items.map((item, index) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
2071
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: item.id }),
2072
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity }),
2073
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.reason || "—" })
2074
- ] }, item.id || index)) })
2075
- ] }) })
2076
- ] }),
2077
- swap.new_items && swap.new_items.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2078
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "New Items" }),
2079
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "overflow-hidden rounded-xl border border-ui-border-base", children: /* @__PURE__ */ jsxRuntime.jsxs("table", { className: "min-w-full divide-y divide-ui-border-base", children: [
2080
- /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
2081
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Variant ID" }),
2082
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Quantity" })
2083
- ] }) }),
2084
- /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: swap.new_items.map((item, index) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
2085
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: item.variant_id }),
2086
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity })
2087
- ] }, item.variant_id || index)) })
2088
- ] }) })
2089
- ] })
2002
+ ] }) : null
2090
2003
  ] }) });
2091
2004
  };
2092
2005
  const config$3 = adminSdk.defineRouteConfig({
2093
- label: "Swap Details",
2094
- icon: icons.ArrowPath
2006
+ label: "Refund details",
2007
+ icon: icons.Receipt
2095
2008
  });
2096
2009
  const getStatusBadgeClass$2 = (status) => {
2097
2010
  const statusLower = status.toLowerCase();
@@ -2104,105 +2017,109 @@ const getStatusBadgeClass$2 = (status) => {
2104
2017
  if (statusLower === "rejected") {
2105
2018
  return "bg-ui-tag-red-bg text-ui-tag-red-text";
2106
2019
  }
2107
- if (statusLower === "received") {
2108
- return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
2109
- }
2110
- if (statusLower === "refunded") {
2111
- return "bg-ui-tag-green-bg text-ui-tag-green-text";
2112
- }
2113
2020
  if (statusLower === "completed") {
2114
2021
  return "bg-ui-tag-green-bg text-ui-tag-green-text";
2115
2022
  }
2116
- if (statusLower === "cancelled") {
2023
+ if (statusLower === "cancelled" || statusLower === "canceled") {
2117
2024
  return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
2118
2025
  }
2026
+ if (statusLower === "pending") {
2027
+ return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
2028
+ }
2119
2029
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
2120
2030
  };
2121
- const ReturnDetailPage = () => {
2122
- var _a, _b;
2031
+ const SwapDetailPage = () => {
2032
+ var _a, _b, _c;
2123
2033
  const navigate = reactRouterDom.useNavigate();
2124
2034
  const { id } = reactRouterDom.useParams();
2125
- const [returnOrder, setReturnOrder] = react.useState(null);
2035
+ const [swap, setSwap] = react.useState(null);
2036
+ const [order, setOrder] = react.useState(null);
2126
2037
  const [isLoading, setIsLoading] = react.useState(true);
2127
- const [isRejecting, setIsRejecting] = react.useState(false);
2038
+ react.useState(false);
2039
+ const [isCancelling, setIsCancelling] = react.useState(false);
2128
2040
  const [error, setError] = react.useState(null);
2129
2041
  const [updateError, setUpdateError] = react.useState(null);
2130
2042
  const [updateSuccess, setUpdateSuccess] = react.useState(false);
2131
2043
  react.useEffect(() => {
2132
2044
  if (!id) {
2133
- navigate("/returns");
2045
+ navigate("/swaps");
2134
2046
  return;
2135
2047
  }
2136
- const loadReturn = async () => {
2048
+ const loadSwap = async () => {
2137
2049
  try {
2138
2050
  setIsLoading(true);
2139
2051
  setError(null);
2140
- const response = await fetch(`/admin/returns/${id}`, {
2052
+ const response = await fetch(`/admin/swaps/${id}`, {
2141
2053
  credentials: "include"
2142
2054
  });
2143
2055
  if (!response.ok) {
2144
2056
  const message = await response.text();
2145
- throw new Error(message || "Unable to load return order");
2057
+ throw new Error(message || "Unable to load swap");
2146
2058
  }
2147
2059
  const payload = await response.json();
2148
- setReturnOrder(payload.return);
2060
+ setSwap(payload.swap);
2061
+ setOrder(payload.order || null);
2149
2062
  } catch (loadError) {
2150
- const message = loadError instanceof Error ? loadError.message : "Unable to load return order";
2063
+ const message = loadError instanceof Error ? loadError.message : "Unable to load swap";
2151
2064
  setError(message);
2152
2065
  } finally {
2153
2066
  setIsLoading(false);
2154
2067
  }
2155
2068
  };
2156
- void loadReturn();
2069
+ void loadSwap();
2157
2070
  }, [id, navigate]);
2158
- const handleReject = async () => {
2071
+ const handleCancelExchange = async () => {
2159
2072
  if (!id) {
2160
2073
  return;
2161
2074
  }
2162
2075
  try {
2163
- setIsRejecting(true);
2076
+ setIsCancelling(true);
2164
2077
  setUpdateError(null);
2165
2078
  setUpdateSuccess(false);
2166
- const response = await fetch(`/admin/returns/${id}/reject`, {
2079
+ const response = await fetch(`/admin/swaps/${id}/cancel`, {
2167
2080
  method: "POST",
2168
2081
  headers: {
2169
2082
  "Content-Type": "application/json"
2170
2083
  },
2171
- credentials: "include",
2172
- body: JSON.stringify({ reason: "Rejected by admin" })
2084
+ credentials: "include"
2173
2085
  });
2174
2086
  if (!response.ok) {
2175
2087
  const message = await response.text();
2176
- throw new Error(message || "Unable to reject return");
2088
+ throw new Error(message || "Unable to cancel exchange");
2177
2089
  }
2178
2090
  const payload = await response.json();
2179
- setReturnOrder(payload.return);
2091
+ setSwap(payload.swap);
2180
2092
  setUpdateSuccess(true);
2181
2093
  setTimeout(() => setUpdateSuccess(false), 3e3);
2182
- const detailResponse = await fetch(`/admin/returns/${id}`, {
2094
+ const detailResponse = await fetch(`/admin/swaps/${id}`, {
2183
2095
  credentials: "include"
2184
2096
  });
2185
2097
  if (detailResponse.ok) {
2186
2098
  const detailPayload = await detailResponse.json();
2187
- setReturnOrder(detailPayload.return);
2099
+ setSwap(detailPayload.swap);
2100
+ setOrder(detailPayload.order || null);
2188
2101
  }
2189
- } catch (updateErr) {
2190
- const message = updateErr instanceof Error ? updateErr.message : "Unable to reject return";
2102
+ } catch (cancelErr) {
2103
+ const message = cancelErr instanceof Error ? cancelErr.message : "Unable to cancel exchange";
2191
2104
  setUpdateError(message);
2192
2105
  } finally {
2193
- setIsRejecting(false);
2106
+ setIsCancelling(false);
2194
2107
  }
2195
2108
  };
2109
+ const isOrderExchange = Boolean(swap == null ? void 0 : swap.exchange_id);
2110
+ const canCancelExchange = isOrderExchange && swap && !["cancelled", "canceled", "completed", "declined"].includes(
2111
+ ((_a = swap.status) == null ? void 0 : _a.toLowerCase()) ?? ""
2112
+ );
2196
2113
  if (isLoading) {
2197
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "mx-auto flex w-full max-w-5xl flex-col gap-6 p-6", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Loading return order..." }) }) }) });
2114
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "mx-auto flex w-full max-w-5xl flex-col gap-6 p-6", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Loading swap..." }) }) }) });
2198
2115
  }
2199
- if (error || !returnOrder) {
2116
+ if (error || !swap) {
2200
2117
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "mx-auto flex w-full max-w-5xl flex-col gap-6 p-6", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
2201
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error || "Return order not found" }),
2202
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", onClick: () => navigate("/returns"), children: "Back to list" }) })
2118
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error || "Swap not found" }),
2119
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", onClick: () => navigate("/swaps"), children: "Back to list" }) })
2203
2120
  ] }) }) });
2204
2121
  }
2205
- const statusHistory = ((_a = returnOrder.metadata) == null ? void 0 : _a.status_history) || [];
2122
+ const statusHistory = ((_b = swap.metadata) == null ? void 0 : _b.status_history) || [];
2206
2123
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "mx-auto flex w-full max-w-5xl flex-col gap-6 p-6", children: [
2207
2124
  /* @__PURE__ */ jsxRuntime.jsxs("header", { className: "flex flex-col gap-3", children: [
2208
2125
  /* @__PURE__ */ jsxRuntime.jsxs(
@@ -2210,7 +2127,7 @@ const ReturnDetailPage = () => {
2210
2127
  {
2211
2128
  variant: "transparent",
2212
2129
  size: "small",
2213
- onClick: () => navigate("/returns"),
2130
+ onClick: () => navigate("/swaps"),
2214
2131
  className: "w-fit",
2215
2132
  children: [
2216
2133
  /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowLeft, { className: "mr-2" }),
@@ -2220,81 +2137,67 @@ const ReturnDetailPage = () => {
2220
2137
  ),
2221
2138
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1 md:flex-row md:items-center md:justify-between", children: [
2222
2139
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
2223
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Return Order Details" }),
2224
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: returnOrder.id })
2140
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Exchange Details" }),
2141
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: swap.id })
2225
2142
  ] }),
2226
2143
  /* @__PURE__ */ jsxRuntime.jsx(
2227
2144
  ui.Badge,
2228
2145
  {
2229
2146
  size: "small",
2230
- className: `uppercase ${getStatusBadgeClass$2(returnOrder.status)}`,
2231
- children: returnOrder.status.replace(/_/g, " ")
2147
+ className: `uppercase ${getStatusBadgeClass$2(swap.status)}`,
2148
+ children: swap.status.replace(/_/g, " ")
2232
2149
  }
2233
2150
  )
2234
2151
  ] })
2235
2152
  ] }),
2236
- returnOrder.status === "requested" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
2153
+ canCancelExchange && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
2237
2154
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex gap-3", children: /* @__PURE__ */ jsxRuntime.jsx(
2238
2155
  ui.Button,
2239
2156
  {
2240
2157
  variant: "danger",
2241
- onClick: handleReject,
2242
- disabled: isRejecting,
2243
- isLoading: isRejecting,
2244
- children: "Reject (Cancel) Return"
2158
+ onClick: handleCancelExchange,
2159
+ disabled: isCancelling,
2160
+ isLoading: isCancelling,
2161
+ children: "Cancel Exchange"
2245
2162
  }
2246
2163
  ) }),
2247
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: 'Cancel this return request. Use "Mark as received" when items are received.' })
2248
- ] }),
2249
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2250
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Information" }),
2251
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
2252
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2253
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Return ID" }),
2254
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.id })
2255
- ] }),
2256
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(
2257
- ui.Button,
2258
- {
2259
- variant: "secondary",
2260
- onClick: () => {
2261
- window.open(
2262
- `/app/orders/${returnOrder.order_id}`,
2263
- "_blank"
2264
- );
2265
- },
2266
- children: "View order"
2267
- }
2268
- ) })
2269
- ] })
2164
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This will cancel the exchange request. The order will remain unchanged." })
2270
2165
  ] }),
2271
2166
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid gap-6 md:grid-cols-2", children: [
2272
2167
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2273
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Details" }),
2168
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Exchange Information" }),
2274
2169
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
2275
2170
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2276
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Return ID" }),
2277
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.id })
2171
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Exchange ID" }),
2172
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.id })
2278
2173
  ] }),
2279
2174
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2280
2175
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Status" }),
2281
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.status })
2176
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.status })
2177
+ ] }),
2178
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2179
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Difference Due" }),
2180
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.difference_due != null ? `${swap.currency_code || "$"}${(Number(swap.difference_due) / 100).toFixed(2)}` : "—" })
2282
2181
  ] }),
2283
- returnOrder.reason && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2182
+ swap.reason && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2284
2183
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Reason" }),
2285
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.reason })
2184
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.reason })
2286
2185
  ] }),
2287
- returnOrder.note && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2186
+ swap.note && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2288
2187
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Note" }),
2289
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.note })
2188
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.note })
2290
2189
  ] }),
2291
2190
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2292
2191
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Created" }),
2293
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: new Date(returnOrder.created_at).toLocaleString() })
2192
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: new Date(swap.created_at).toLocaleString() })
2294
2193
  ] }),
2295
2194
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2296
2195
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Last Updated" }),
2297
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: new Date(returnOrder.updated_at).toLocaleString() })
2196
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: new Date(swap.updated_at).toLocaleString() })
2197
+ ] }),
2198
+ swap.exchange_id && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2199
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Exchange ID" }),
2200
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.exchange_id })
2298
2201
  ] })
2299
2202
  ] })
2300
2203
  ] }),
@@ -2324,31 +2227,31 @@ const ReturnDetailPage = () => {
2324
2227
  )) }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "No status history available" })
2325
2228
  ] })
2326
2229
  ] }),
2327
- returnOrder.order && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2230
+ order && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2328
2231
  /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Related Order Information" }),
2329
2232
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
2330
2233
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2331
2234
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Order ID" }),
2332
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.order.id })
2235
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: order.id })
2333
2236
  ] }),
2334
2237
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2335
2238
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Status" }),
2336
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.order.status || "—" })
2239
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: order.status || "—" })
2337
2240
  ] }),
2338
2241
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2339
2242
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Customer" }),
2340
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: ((_b = returnOrder.order.customer) == null ? void 0 : _b.email) || returnOrder.order.email || "—" })
2243
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: ((_c = order.customer) == null ? void 0 : _c.email) || order.email || "—" })
2341
2244
  ] }),
2342
- returnOrder.order.total && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2245
+ order.total && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2343
2246
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Total" }),
2344
2247
  /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { className: "font-medium", children: [
2345
- returnOrder.order.currency_code || "$",
2346
- (Number(returnOrder.order.total) / 100).toFixed(2)
2248
+ order.currency_code || "$",
2249
+ (Number(order.total) / 100).toFixed(2)
2347
2250
  ] })
2348
2251
  ] })
2349
2252
  ] })
2350
2253
  ] }),
2351
- returnOrder.return_items && returnOrder.return_items.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2254
+ swap.return_items && swap.return_items.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2352
2255
  /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Items" }),
2353
2256
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "overflow-hidden rounded-xl border border-ui-border-base", children: /* @__PURE__ */ jsxRuntime.jsxs("table", { className: "min-w-full divide-y divide-ui-border-base", children: [
2354
2257
  /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
@@ -2356,20 +2259,31 @@ const ReturnDetailPage = () => {
2356
2259
  /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Quantity" }),
2357
2260
  /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Reason" })
2358
2261
  ] }) }),
2359
- /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: returnOrder.return_items.map((item, index) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
2262
+ /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: swap.return_items.map((item, index) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
2360
2263
  /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: item.id }),
2361
2264
  /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity }),
2362
2265
  /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.reason || "—" })
2363
2266
  ] }, item.id || index)) })
2364
2267
  ] }) })
2365
2268
  ] }),
2366
- updateError && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-lg border border-ui-border-error bg-ui-bg-error-subtle p-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-error", children: updateError }) }),
2367
- updateSuccess && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-lg border border-ui-border-success bg-ui-bg-success-subtle p-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-success", children: "Action completed successfully" }) })
2269
+ swap.new_items && swap.new_items.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2270
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "New Items" }),
2271
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "overflow-hidden rounded-xl border border-ui-border-base", children: /* @__PURE__ */ jsxRuntime.jsxs("table", { className: "min-w-full divide-y divide-ui-border-base", children: [
2272
+ /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
2273
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Variant ID" }),
2274
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Quantity" })
2275
+ ] }) }),
2276
+ /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: swap.new_items.map((item, index) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
2277
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: item.variant_id }),
2278
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity })
2279
+ ] }, item.variant_id || index)) })
2280
+ ] }) })
2281
+ ] })
2368
2282
  ] }) });
2369
2283
  };
2370
2284
  const config$2 = adminSdk.defineRouteConfig({
2371
- label: "Return Order Details",
2372
- icon: icons.CheckCircle
2285
+ label: "Swap Details",
2286
+ icon: icons.ArrowPath
2373
2287
  });
2374
2288
  const getStatusBadgeClass$1 = (status) => {
2375
2289
  const s2 = status.toLowerCase();
@@ -2491,196 +2405,282 @@ const config$1 = adminSdk.defineRouteConfig({
2491
2405
  icon: icons.CreditCard
2492
2406
  });
2493
2407
  const getStatusBadgeClass = (status) => {
2494
- const s2 = status.toLowerCase();
2495
- if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
2496
- if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
2497
- if (s2 === "error" || s2 === "canceled" || s2 === "cancelled") return "bg-ui-tag-red-bg text-ui-tag-red-text";
2498
- if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
2408
+ const statusLower = status.toLowerCase();
2409
+ if (statusLower === "requested") {
2410
+ return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
2411
+ }
2412
+ if (statusLower === "approved") {
2413
+ return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
2414
+ }
2415
+ if (statusLower === "rejected") {
2416
+ return "bg-ui-tag-red-bg text-ui-tag-red-text";
2417
+ }
2418
+ if (statusLower === "received") {
2419
+ return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
2420
+ }
2421
+ if (statusLower === "refunded") {
2422
+ return "bg-ui-tag-green-bg text-ui-tag-green-text";
2423
+ }
2424
+ if (statusLower === "completed") {
2425
+ return "bg-ui-tag-green-bg text-ui-tag-green-text";
2426
+ }
2427
+ if (statusLower === "cancelled") {
2428
+ return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
2429
+ }
2499
2430
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
2500
2431
  };
2501
- const formatAmount = (value) => {
2502
- return String(value);
2503
- };
2504
- const RefundDetailPage = () => {
2505
- var _a, _b, _c;
2432
+ const ReturnDetailPage = () => {
2433
+ var _a, _b;
2506
2434
  const navigate = reactRouterDom.useNavigate();
2507
- const params = reactRouterDom.useParams();
2508
- const id = (_a = params == null ? void 0 : params.id) == null ? void 0 : _a.trim();
2509
- const [detail, setDetail] = react.useState(null);
2510
- const [loading, setLoading] = react.useState(!!id);
2435
+ const { id } = reactRouterDom.useParams();
2436
+ const [returnOrder, setReturnOrder] = react.useState(null);
2437
+ const [isLoading, setIsLoading] = react.useState(true);
2438
+ const [isRejecting, setIsRejecting] = react.useState(false);
2511
2439
  const [error, setError] = react.useState(null);
2512
- const [gatewayExpanded, setGatewayExpanded] = react.useState(false);
2440
+ const [updateError, setUpdateError] = react.useState(null);
2441
+ const [updateSuccess, setUpdateSuccess] = react.useState(false);
2513
2442
  react.useEffect(() => {
2514
2443
  if (!id) {
2515
- setLoading(false);
2444
+ navigate("/returns");
2516
2445
  return;
2517
2446
  }
2518
- let cancelled = false;
2519
- setLoading(true);
2520
- setError(null);
2521
- fetch(`/admin/refunds/${id}`, { credentials: "include" }).then((res) => {
2522
- if (!res.ok) throw new Error(res.statusText || "Failed to load");
2523
- return res.json();
2524
- }).then((data) => {
2525
- if (!cancelled) setDetail(data);
2526
- }).catch((e) => {
2527
- if (!cancelled) setError(e instanceof Error ? e.message : "Failed to load");
2528
- }).finally(() => {
2529
- if (!cancelled) setLoading(false);
2530
- });
2531
- return () => {
2532
- cancelled = true;
2447
+ const loadReturn = async () => {
2448
+ try {
2449
+ setIsLoading(true);
2450
+ setError(null);
2451
+ const response = await fetch(`/admin/returns/${id}`, {
2452
+ credentials: "include"
2453
+ });
2454
+ if (!response.ok) {
2455
+ const message = await response.text();
2456
+ throw new Error(message || "Unable to load return order");
2457
+ }
2458
+ const payload = await response.json();
2459
+ setReturnOrder(payload.return);
2460
+ } catch (loadError) {
2461
+ const message = loadError instanceof Error ? loadError.message : "Unable to load return order";
2462
+ setError(message);
2463
+ } finally {
2464
+ setIsLoading(false);
2465
+ }
2533
2466
  };
2534
- }, [id]);
2535
- const paymentStatus = ((_b = detail == null ? void 0 : detail.payment) == null ? void 0 : _b.status) ?? "—";
2536
- const hasGatewayData = ((_c = detail == null ? void 0 : detail.payment) == null ? void 0 : _c.payment_data) && typeof detail.payment.payment_data === "object" && Object.keys(detail.payment.payment_data).length > 0;
2537
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "mx-auto flex w-full max-w-4xl flex-col gap-6 p-6", children: [
2538
- /* @__PURE__ */ jsxRuntime.jsx("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
2539
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "transparent", size: "small", onClick: () => navigate("/refunds"), children: "← Refunds" }),
2540
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Refund details" }),
2541
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle font-mono", children: id ?? "—" })
2542
- ] }) }),
2543
- error ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
2544
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
2545
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", className: "mt-4", onClick: () => navigate("/refunds"), children: "Back to list" })
2546
- ] }) : loading ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Loading…" }) }) : detail ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-6", children: [
2547
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2548
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "text-lg mb-4", children: "Refund summary" }),
2549
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
2550
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2551
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Refund ID" }),
2552
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block font-mono text-sm", children: detail.refund.id })
2553
- ] }),
2554
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2555
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Amount" }),
2556
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.refund.amount) })
2557
- ] }),
2558
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2559
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Note" }),
2560
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.refund.note ?? "—" })
2561
- ] }),
2467
+ void loadReturn();
2468
+ }, [id, navigate]);
2469
+ const handleReject = async () => {
2470
+ if (!id) {
2471
+ return;
2472
+ }
2473
+ try {
2474
+ setIsRejecting(true);
2475
+ setUpdateError(null);
2476
+ setUpdateSuccess(false);
2477
+ const response = await fetch(`/admin/returns/${id}/reject`, {
2478
+ method: "POST",
2479
+ headers: {
2480
+ "Content-Type": "application/json"
2481
+ },
2482
+ credentials: "include",
2483
+ body: JSON.stringify({ reason: "Rejected by admin" })
2484
+ });
2485
+ if (!response.ok) {
2486
+ const message = await response.text();
2487
+ throw new Error(message || "Unable to reject return");
2488
+ }
2489
+ const payload = await response.json();
2490
+ setReturnOrder(payload.return);
2491
+ setUpdateSuccess(true);
2492
+ setTimeout(() => setUpdateSuccess(false), 3e3);
2493
+ const detailResponse = await fetch(`/admin/returns/${id}`, {
2494
+ credentials: "include"
2495
+ });
2496
+ if (detailResponse.ok) {
2497
+ const detailPayload = await detailResponse.json();
2498
+ setReturnOrder(detailPayload.return);
2499
+ }
2500
+ } catch (updateErr) {
2501
+ const message = updateErr instanceof Error ? updateErr.message : "Unable to reject return";
2502
+ setUpdateError(message);
2503
+ } finally {
2504
+ setIsRejecting(false);
2505
+ }
2506
+ };
2507
+ if (isLoading) {
2508
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "mx-auto flex w-full max-w-5xl flex-col gap-6 p-6", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Loading return order..." }) }) }) });
2509
+ }
2510
+ if (error || !returnOrder) {
2511
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "mx-auto flex w-full max-w-5xl flex-col gap-6 p-6", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
2512
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error || "Return order not found" }),
2513
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", onClick: () => navigate("/returns"), children: "Back to list" }) })
2514
+ ] }) }) });
2515
+ }
2516
+ const statusHistory = ((_a = returnOrder.metadata) == null ? void 0 : _a.status_history) || [];
2517
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "mx-auto flex w-full max-w-5xl flex-col gap-6 p-6", children: [
2518
+ /* @__PURE__ */ jsxRuntime.jsxs("header", { className: "flex flex-col gap-3", children: [
2519
+ /* @__PURE__ */ jsxRuntime.jsxs(
2520
+ ui.Button,
2521
+ {
2522
+ variant: "transparent",
2523
+ size: "small",
2524
+ onClick: () => navigate("/returns"),
2525
+ className: "w-fit",
2526
+ children: [
2527
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowLeft, { className: "mr-2" }),
2528
+ "Back to list"
2529
+ ]
2530
+ }
2531
+ ),
2532
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1 md:flex-row md:items-center md:justify-between", children: [
2533
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
2534
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Return Order Details" }),
2535
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: returnOrder.id })
2536
+ ] }),
2537
+ /* @__PURE__ */ jsxRuntime.jsx(
2538
+ ui.Badge,
2539
+ {
2540
+ size: "small",
2541
+ className: `uppercase ${getStatusBadgeClass(returnOrder.status)}`,
2542
+ children: returnOrder.status.replace(/_/g, " ")
2543
+ }
2544
+ )
2545
+ ] })
2546
+ ] }),
2547
+ returnOrder.status === "requested" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
2548
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex gap-3", children: /* @__PURE__ */ jsxRuntime.jsx(
2549
+ ui.Button,
2550
+ {
2551
+ variant: "danger",
2552
+ onClick: handleReject,
2553
+ disabled: isRejecting,
2554
+ isLoading: isRejecting,
2555
+ children: "Reject (Cancel) Return"
2556
+ }
2557
+ ) }),
2558
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: 'Cancel this return request. Use "Mark as received" when items are received.' })
2559
+ ] }),
2560
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2561
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Information" }),
2562
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
2563
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2564
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Return ID" }),
2565
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.id })
2566
+ ] }),
2567
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(
2568
+ ui.Button,
2569
+ {
2570
+ variant: "secondary",
2571
+ onClick: () => {
2572
+ window.open(
2573
+ `/app/orders/${returnOrder.order_id}`,
2574
+ "_blank"
2575
+ );
2576
+ },
2577
+ children: "View order"
2578
+ }
2579
+ ) })
2580
+ ] })
2581
+ ] }),
2582
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid gap-6 md:grid-cols-2", children: [
2583
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2584
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Details" }),
2585
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
2562
2586
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2563
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Created at" }),
2564
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: new Date(detail.refund.created_at).toLocaleDateString("en-US", {
2565
- year: "numeric",
2566
- month: "short",
2567
- day: "numeric",
2568
- hour: "numeric",
2569
- minute: "2-digit",
2570
- hour12: true
2571
- }) })
2587
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Return ID" }),
2588
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.id })
2572
2589
  ] }),
2573
- detail.refund.created_by ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2574
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Created by" }),
2575
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block font-mono text-sm", children: detail.refund.created_by })
2576
- ] }) : null
2577
- ] })
2578
- ] }),
2579
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2580
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "text-lg mb-4", children: "Payment summary" }),
2581
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
2582
2590
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2583
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Payment amount" }),
2584
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.payment.payment_amount) })
2591
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Status" }),
2592
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.status })
2585
2593
  ] }),
2586
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2587
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Captured amount" }),
2588
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.payment.captured_amount) })
2594
+ returnOrder.reason && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2595
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Reason" }),
2596
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.reason })
2589
2597
  ] }),
2590
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2591
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Refunded amount" }),
2592
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.payment.refunded_amount) })
2598
+ returnOrder.note && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2599
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Note" }),
2600
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.note })
2593
2601
  ] }),
2594
2602
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2595
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Provider" }),
2596
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.payment.provider_id || "—" })
2603
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Created" }),
2604
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: new Date(returnOrder.created_at).toLocaleString() })
2597
2605
  ] }),
2598
2606
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2599
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Status" }),
2600
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsxRuntime.jsx(
2601
- ui.Badge,
2602
- {
2603
- size: "2xsmall",
2604
- className: `uppercase ${getStatusBadgeClass(paymentStatus)}`,
2605
- children: paymentStatus !== "—" ? paymentStatus.replace(/_/g, " ") : "—"
2606
- }
2607
- ) })
2608
- ] }),
2609
- detail.computed ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2610
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2611
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Full refund" }),
2612
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.computed.is_full_refund ? "Yes" : "No" })
2613
- ] }),
2614
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2615
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Remaining refundable" }),
2616
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.computed.remaining_refundable_amount) })
2617
- ] }),
2618
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2619
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Refund %" }),
2620
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { className: "mt-1 block", children: [
2621
- detail.computed.refund_percentage.toFixed(1),
2622
- "%"
2623
- ] })
2624
- ] })
2625
- ] }) : null
2607
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Last Updated" }),
2608
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: new Date(returnOrder.updated_at).toLocaleString() })
2609
+ ] })
2626
2610
  ] })
2627
2611
  ] }),
2628
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2629
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "text-lg mb-4", children: "Order summary" }),
2630
- detail.order ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
2631
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2632
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Order" }),
2633
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsxRuntime.jsx(
2634
- ui.Button,
2635
- {
2636
- variant: "transparent",
2637
- size: "small",
2638
- onClick: () => navigate(`/orders/${detail.order.order_id}`),
2639
- children: detail.order.order_number ?? detail.order.order_id
2640
- }
2641
- ) })
2642
- ] }),
2643
- detail.order.total != null ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2644
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Total" }),
2645
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.order.total) })
2646
- ] }) : null,
2647
- detail.order.customer_id ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2648
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Customer ID" }),
2649
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block font-mono text-sm", children: detail.order.customer_id })
2650
- ] }) : null,
2651
- detail.order.region ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2652
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Region" }),
2653
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.order.region })
2654
- ] }) : null,
2655
- detail.order.fulfillment_status ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2656
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Fulfillment status" }),
2657
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.order.fulfillment_status })
2658
- ] }) : null
2659
- ] }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "No order linked to this refund." })
2660
- ] }),
2661
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2662
- /* @__PURE__ */ jsxRuntime.jsxs(
2663
- "button",
2612
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2613
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Status History" }),
2614
+ statusHistory.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-2", children: statusHistory.map((entry, index) => /* @__PURE__ */ jsxRuntime.jsx(
2615
+ "div",
2664
2616
  {
2665
- type: "button",
2666
- className: "flex w-full items-center justify-between text-left",
2667
- onClick: () => setGatewayExpanded((prev) => !prev),
2668
- "aria-expanded": gatewayExpanded,
2669
- "aria-label": gatewayExpanded ? "Collapse gateway data" : "Expand gateway data",
2670
- children: [
2671
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "text-lg", children: "Gateway data" }),
2672
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: gatewayExpanded ? "Collapse" : "Expand" })
2673
- ]
2674
- }
2675
- ),
2676
- gatewayExpanded && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-4", children: hasGatewayData ? /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "text-xs bg-ui-bg-subtle p-4 rounded-lg overflow-auto max-h-96", children: JSON.stringify(detail.payment.payment_data, null, 2) }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "No gateway payload for this payment." }) })
2617
+ className: "flex items-center justify-between border-b border-ui-border-subtle pb-2 last:border-0",
2618
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
2619
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center gap-2", children: /* @__PURE__ */ jsxRuntime.jsx(
2620
+ ui.Badge,
2621
+ {
2622
+ size: "2xsmall",
2623
+ className: `uppercase ${getStatusBadgeClass(entry.status)}`,
2624
+ children: entry.status.replace(/_/g, " ")
2625
+ }
2626
+ ) }),
2627
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
2628
+ new Date(entry.timestamp).toLocaleString(),
2629
+ entry.admin_id && ` by ${entry.admin_id}`,
2630
+ entry.reason && ` - ${entry.reason}`
2631
+ ] })
2632
+ ] })
2633
+ },
2634
+ index
2635
+ )) }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "No status history available" })
2677
2636
  ] })
2678
- ] }) : null
2637
+ ] }),
2638
+ returnOrder.order && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2639
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Related Order Information" }),
2640
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
2641
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2642
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Order ID" }),
2643
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.order.id })
2644
+ ] }),
2645
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2646
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Status" }),
2647
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.order.status || "—" })
2648
+ ] }),
2649
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2650
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Customer" }),
2651
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: ((_b = returnOrder.order.customer) == null ? void 0 : _b.email) || returnOrder.order.email || "—" })
2652
+ ] }),
2653
+ returnOrder.order.total && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
2654
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Total" }),
2655
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { className: "font-medium", children: [
2656
+ returnOrder.order.currency_code || "$",
2657
+ (Number(returnOrder.order.total) / 100).toFixed(2)
2658
+ ] })
2659
+ ] })
2660
+ ] })
2661
+ ] }),
2662
+ returnOrder.return_items && returnOrder.return_items.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
2663
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Items" }),
2664
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "overflow-hidden rounded-xl border border-ui-border-base", children: /* @__PURE__ */ jsxRuntime.jsxs("table", { className: "min-w-full divide-y divide-ui-border-base", children: [
2665
+ /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
2666
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Item ID" }),
2667
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Quantity" }),
2668
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Reason" })
2669
+ ] }) }),
2670
+ /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: returnOrder.return_items.map((item, index) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
2671
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: item.id }),
2672
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity }),
2673
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.reason || "—" })
2674
+ ] }, item.id || index)) })
2675
+ ] }) })
2676
+ ] }),
2677
+ updateError && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-lg border border-ui-border-error bg-ui-bg-error-subtle p-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-error", children: updateError }) }),
2678
+ updateSuccess && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-lg border border-ui-border-success bg-ui-bg-success-subtle p-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-success", children: "Action completed successfully" }) })
2679
2679
  ] }) });
2680
2680
  };
2681
2681
  const config = adminSdk.defineRouteConfig({
2682
- label: "Refund details",
2683
- icon: icons.Receipt
2682
+ label: "Return Order Details",
2683
+ icon: icons.CheckCircle
2684
2684
  });
2685
2685
  const i18nTranslations0 = {};
2686
2686
  const widgetModule = { widgets: [
@@ -2696,8 +2696,8 @@ const widgetModule = { widgets: [
2696
2696
  const routeModule = {
2697
2697
  routes: [
2698
2698
  {
2699
- Component: SwapsPage,
2700
- path: "/swaps"
2699
+ Component: RefundsPage,
2700
+ path: "/refunds"
2701
2701
  },
2702
2702
  {
2703
2703
  Component: ReturnsPage,
@@ -2708,57 +2708,57 @@ const routeModule = {
2708
2708
  path: "/payments"
2709
2709
  },
2710
2710
  {
2711
- Component: RefundsPage,
2712
- path: "/refunds"
2711
+ Component: SwapsPage,
2712
+ path: "/swaps"
2713
2713
  },
2714
2714
  {
2715
- Component: SwapDetailPage,
2716
- path: "/swaps/:id"
2715
+ Component: RefundDetailPage,
2716
+ path: "/refunds/:id"
2717
2717
  },
2718
2718
  {
2719
- Component: ReturnDetailPage,
2720
- path: "/returns/:id"
2719
+ Component: SwapDetailPage,
2720
+ path: "/swaps/:id"
2721
2721
  },
2722
2722
  {
2723
2723
  Component: PaymentDetailPage,
2724
2724
  path: "/payments/:id"
2725
2725
  },
2726
2726
  {
2727
- Component: RefundDetailPage,
2728
- path: "/refunds/:id"
2727
+ Component: ReturnDetailPage,
2728
+ path: "/returns/:id"
2729
2729
  }
2730
2730
  ]
2731
2731
  };
2732
2732
  const menuItemModule = {
2733
2733
  menuItems: [
2734
- {
2735
- label: config$4.label,
2736
- icon: config$4.icon,
2737
- path: "/refunds",
2738
- nested: void 0
2739
- },
2740
2734
  {
2741
2735
  label: config$5.label,
2742
2736
  icon: config$5.icon,
2743
2737
  path: "/payments",
2744
2738
  nested: void 0
2745
2739
  },
2740
+ {
2741
+ label: config$6.label,
2742
+ icon: config$6.icon,
2743
+ path: "/returns",
2744
+ nested: void 0
2745
+ },
2746
2746
  {
2747
2747
  label: config$7.label,
2748
2748
  icon: config$7.icon,
2749
- path: "/swaps",
2749
+ path: "/refunds",
2750
2750
  nested: void 0
2751
2751
  },
2752
2752
  {
2753
- label: config$6.label,
2754
- icon: config$6.icon,
2755
- path: "/returns",
2753
+ label: config$4.label,
2754
+ icon: config$4.icon,
2755
+ path: "/swaps",
2756
2756
  nested: void 0
2757
2757
  },
2758
2758
  {
2759
2759
  label: config.label,
2760
2760
  icon: config.icon,
2761
- path: "/refunds/:id",
2761
+ path: "/returns/:id",
2762
2762
  nested: void 0
2763
2763
  },
2764
2764
  {
@@ -2770,13 +2770,13 @@ const menuItemModule = {
2770
2770
  {
2771
2771
  label: config$2.label,
2772
2772
  icon: config$2.icon,
2773
- path: "/returns/:id",
2773
+ path: "/swaps/:id",
2774
2774
  nested: void 0
2775
2775
  },
2776
2776
  {
2777
2777
  label: config$3.label,
2778
2778
  icon: config$3.icon,
2779
- path: "/swaps/:id",
2779
+ path: "/refunds/:id",
2780
2780
  nested: void 0
2781
2781
  }
2782
2782
  ]