order-management 0.0.91 → 0.0.92

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.
@@ -2,7 +2,7 @@ import { jsxs, jsx, Fragment } from "react/jsx-runtime";
2
2
  import { defineWidgetConfig, defineRouteConfig } from "@medusajs/admin-sdk";
3
3
  import { useState, useEffect, useRef, useCallback, useMemo } from "react";
4
4
  import { Text, Container, Heading, Badge, Button, Label, Select, Textarea, Input } from "@medusajs/ui";
5
- import { CashSolid, PencilSquareSolid, Trash, CreditCard, Receipt, ArrowPath, CheckCircle, ArrowLeft } from "@medusajs/icons";
5
+ import { CashSolid, PencilSquareSolid, Trash, CreditCard, ArrowPath, Receipt, CheckCircle, ArrowLeft } from "@medusajs/icons";
6
6
  import { useNavigate, useParams } from "react-router-dom";
7
7
  function roundRectPath(ctx, x, y, w, h, r) {
8
8
  ctx.beginPath();
@@ -532,7 +532,7 @@ function getOrderIdFromPath() {
532
532
  return m ? m[1] : void 0;
533
533
  }
534
534
  const OrderRefundContextWidget = (props) => {
535
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
535
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
536
536
  const orderId = ((_a = props.order) == null ? void 0 : _a.id) ?? ((_c = (_b = props.data) == null ? void 0 : _b.order) == null ? void 0 : _c.id) ?? getOrderIdFromPath();
537
537
  const [context, setContext] = useState(null);
538
538
  const [loading, setLoading] = useState(!!orderId);
@@ -571,7 +571,9 @@ const OrderRefundContextWidget = (props) => {
571
571
  };
572
572
  }, [orderId]);
573
573
  const handleMarkRefunded = async () => {
574
- if (!(context == null ? void 0 : context.return_id) || !(context == null ? void 0 : context.refund_mapping) || context.refund_mapping.is_refunded) return;
574
+ if (!(context == null ? void 0 : context.return_id) || !(context == null ? void 0 : context.refund_mapping) || context.refund_mapping.is_refunded || !context.can_process_refund) {
575
+ return;
576
+ }
575
577
  setMarking(true);
576
578
  setMarkError(null);
577
579
  try {
@@ -590,6 +592,7 @@ const OrderRefundContextWidget = (props) => {
590
592
  var _a2;
591
593
  return prev && prev.refund_mapping ? {
592
594
  ...prev,
595
+ can_process_refund: false,
593
596
  refund_mapping: {
594
597
  ...prev.refund_mapping,
595
598
  is_refunded: ((_a2 = data.refund_payment_mapping) == null ? void 0 : _a2.is_refunded) ?? true
@@ -686,29 +689,47 @@ const OrderRefundContextWidget = (props) => {
686
689
  }
687
690
  const hasReturn = !!(context == null ? void 0 : context.return_id);
688
691
  const hasMapping = !!(context == null ? void 0 : context.refund_mapping);
689
- const canMarkRefunded = hasReturn && hasMapping && !context.refund_mapping.is_refunded;
692
+ const canMarkRefunded = Boolean(context == null ? void 0 : context.can_process_refund);
693
+ const returnStatus = (context == null ? void 0 : context.return_status) ?? null;
694
+ const showReceiveFirstHint = hasReturn && !((_d = context == null ? void 0 : context.refund_mapping) == null ? void 0 : _d.is_refunded) && returnStatus !== "received" && returnStatus !== "canceled";
690
695
  const paymentDetail = context == null ? void 0 : context.payment_detail;
696
+ const orderPayment = context == null ? void 0 : context.order_payment;
691
697
  return /* @__PURE__ */ jsx(Container, { className: "mt-6 divide-y p-0", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4 py-4", children: [
692
698
  /* @__PURE__ */ jsxs(Heading, { level: "h2", className: "flex items-center gap-2", children: [
693
699
  /* @__PURE__ */ jsx(CashSolid, { className: "text-ui-fg-subtle" }),
694
700
  "Refund payment"
695
701
  ] }),
696
702
  !hasReturn && /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "No return for this order." }),
703
+ showReceiveFirstHint && /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Receive returned items before processing a refund. Do not refund from Payments until items are received." }),
697
704
  hasMapping && /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-subtle p-4", children: [
698
705
  /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [
699
706
  /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", className: "text-ui-fg-subtle", children: "Return" }),
700
707
  /* @__PURE__ */ jsx(Text, { size: "small", children: context.return_id }),
701
- ((_d = context.refund_mapping) == null ? void 0 : _d.is_refunded) ? /* @__PURE__ */ jsx(Badge, { color: "green", children: "Refunded" }) : /* @__PURE__ */ jsx(Badge, { color: "orange", children: "Not refunded" })
708
+ ((_e = context.refund_mapping) == null ? void 0 : _e.is_refunded) ? /* @__PURE__ */ jsx(Badge, { color: "green", children: "Refunded" }) : /* @__PURE__ */ jsx(Badge, { color: "orange", children: "Not refunded" })
702
709
  ] }),
703
710
  context.refund ? /* @__PURE__ */ jsx("div", { className: "mt-3 border-t border-ui-border-base pt-3", children: /* @__PURE__ */ jsx(RefundCalculationBlock, { refund: context.refund }) }) : null,
711
+ orderPayment && /* @__PURE__ */ jsxs("div", { className: "mt-3 space-y-2 border-t border-ui-border-base pt-3", children: [
712
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", className: "text-ui-fg-subtle", children: "Order payment method" }),
713
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [
714
+ /* @__PURE__ */ jsx(Badge, { children: orderPayment.label }),
715
+ orderPayment.is_cod ? /* @__PURE__ */ jsx(Badge, { color: "orange", children: "COD" }) : null
716
+ ] }),
717
+ /* @__PURE__ */ jsx(Text, { size: "xsmall", className: "text-ui-fg-muted", children: orderPayment.provider_id })
718
+ ] }),
704
719
  /* @__PURE__ */ jsxs("div", { className: "mt-3 space-y-2 border-t border-ui-border-base pt-3", children: [
705
720
  /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2", children: [
706
721
  /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", className: "text-ui-fg-subtle", children: "Payment method (refund destination)" }),
707
- ((_e = context.refund_mapping) == null ? void 0 : _e.payment_id) ? /* @__PURE__ */ jsx(Badge, { color: "green", children: "Customer specified" }) : paymentDetail ? /* @__PURE__ */ jsx(Badge, { color: "orange", children: "Customer default" }) : null
722
+ ((_f = context.refund_mapping) == null ? void 0 : _f.payment_id) ? /* @__PURE__ */ jsx(Badge, { color: "green", children: "Customer specified" }) : paymentDetail ? /* @__PURE__ */ jsx(Badge, { color: "orange", children: "Customer default" }) : orderPayment && !orderPayment.is_cod ? /* @__PURE__ */ jsx(Badge, { color: "blue", children: "Original payment method" }) : null
708
723
  ] }),
709
- ((_f = context.refund_mapping) == null ? void 0 : _f.payment_id) && !paymentDetail && /* @__PURE__ */ jsx("div", { className: "rounded-md border border-orange-200 bg-orange-50 px-3 py-2", children: /* @__PURE__ */ jsx(Text, { size: "xsmall", className: "text-ui-fg-muted", children: "The customer specified a payment method for this return, but that payment method has since been removed from their account. Ask the customer to update their refund payment method." }) }),
710
- !((_g = context.refund_mapping) == null ? void 0 : _g.payment_id) && (paymentDetail == null ? void 0 : paymentDetail.source) === "default" && /* @__PURE__ */ jsx("div", { className: "rounded-md border border-ui-border-base bg-ui-bg-subtle px-3 py-2", children: /* @__PURE__ */ jsx(Text, { size: "xsmall", className: "text-ui-fg-muted", children: "The customer did not specify a payment method for this return. Showing their default payment method." }) }),
711
- !((_h = context.refund_mapping) == null ? void 0 : _h.payment_id) && !paymentDetail && /* @__PURE__ */ jsx("div", { className: "rounded-md border border-ui-border-base bg-ui-bg-subtle px-3 py-2", children: /* @__PURE__ */ jsx(Text, { size: "xsmall", className: "text-ui-fg-muted", children: "No payment method found for this customer." }) }),
724
+ ((_g = context.refund_mapping) == null ? void 0 : _g.payment_id) && !paymentDetail && /* @__PURE__ */ jsx("div", { className: "rounded-md border border-orange-200 bg-orange-50 px-3 py-2", children: /* @__PURE__ */ jsx(Text, { size: "xsmall", className: "text-ui-fg-muted", children: "The customer specified a payment method for this return, but that payment method has since been removed from their account. Ask the customer to update their refund payment method." }) }),
725
+ !((_h = context.refund_mapping) == null ? void 0 : _h.payment_id) && (paymentDetail == null ? void 0 : paymentDetail.source) === "default" && /* @__PURE__ */ jsx("div", { className: "rounded-md border border-ui-border-base bg-ui-bg-subtle px-3 py-2", children: /* @__PURE__ */ jsx(Text, { size: "xsmall", className: "text-ui-fg-muted", children: "The customer did not specify a payment method for this return. Showing their default payment method." }) }),
726
+ !((_i = context.refund_mapping) == null ? void 0 : _i.payment_id) && !paymentDetail && orderPayment && !orderPayment.is_cod && /* @__PURE__ */ jsx("div", { className: "rounded-md border border-ui-border-base bg-ui-bg-subtle px-3 py-2", children: /* @__PURE__ */ jsxs(Text, { size: "xsmall", className: "text-ui-fg-muted", children: [
727
+ "Refund will go to the original payment method (",
728
+ orderPayment.label,
729
+ ")."
730
+ ] }) }),
731
+ !((_j = context.refund_mapping) == null ? void 0 : _j.payment_id) && !paymentDetail && (context.is_cod || (orderPayment == null ? void 0 : orderPayment.is_cod)) && /* @__PURE__ */ jsx("div", { className: "rounded-md border border-ui-border-base bg-ui-bg-subtle px-3 py-2", children: /* @__PURE__ */ jsx(Text, { size: "xsmall", className: "text-ui-fg-muted", children: "This order was paid with Cash on Delivery. No stored bank/UPI refund destination." }) }),
732
+ !((_k = context.refund_mapping) == null ? void 0 : _k.payment_id) && !paymentDetail && !orderPayment && /* @__PURE__ */ jsx("div", { className: "rounded-md border border-ui-border-base bg-ui-bg-subtle px-3 py-2", children: /* @__PURE__ */ jsx(Text, { size: "xsmall", className: "text-ui-fg-muted", children: "No payment method found for this customer." }) }),
712
733
  paymentDetail && /* @__PURE__ */ jsxs(Fragment, { children: [
713
734
  /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap gap-2", children: [
714
735
  /* @__PURE__ */ jsx(Badge, { children: paymentDetail.type.toUpperCase() }),
@@ -862,7 +883,7 @@ const OrderRefundContextWidget = (props) => {
862
883
  ] }),
863
884
  /* @__PURE__ */ jsxs("div", { children: [
864
885
  /* @__PURE__ */ jsx(Text, { size: "xsmall", weight: "plus", className: "text-ui-fg-muted", children: "Images" }),
865
- ((_i = context.refund_mapping.images) == null ? void 0 : _i.length) ? /* @__PURE__ */ jsx("div", { className: "mt-1 flex flex-wrap gap-2", children: context.refund_mapping.images.map((url, i) => /* @__PURE__ */ jsxs(
886
+ ((_l = context.refund_mapping.images) == null ? void 0 : _l.length) ? /* @__PURE__ */ jsx("div", { className: "mt-1 flex flex-wrap gap-2", children: context.refund_mapping.images.map((url, i) => /* @__PURE__ */ jsxs(
866
887
  "a",
867
888
  {
868
889
  href: url,
@@ -891,10 +912,18 @@ const OrderRefundContextWidget = (props) => {
891
912
  }
892
913
  ),
893
914
  markError && /* @__PURE__ */ jsx(Text, { size: "small", className: "mt-2 text-ui-fg-error", children: markError })
894
- ] })
915
+ ] }),
916
+ hasMapping && !canMarkRefunded && !((_m = context.refund_mapping) == null ? void 0 : _m.is_refunded) && showReceiveFirstHint && /* @__PURE__ */ jsx(Text, { size: "small", className: "mt-4 text-ui-fg-muted", children: "Mark refunded is available after the return is received." })
895
917
  ] }),
896
918
  hasReturn && !hasMapping && /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-subtle p-4", children: [
897
919
  (context == null ? void 0 : context.refund) ? /* @__PURE__ */ jsx(RefundCalculationBlock, { refund: context.refund }) : null,
920
+ orderPayment && /* @__PURE__ */ jsxs("div", { className: "mb-3 space-y-1", children: [
921
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", className: "text-ui-fg-subtle", children: "Order payment method" }),
922
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [
923
+ /* @__PURE__ */ jsx(Badge, { children: orderPayment.label }),
924
+ orderPayment.is_cod ? /* @__PURE__ */ jsx(Badge, { color: "orange", children: "COD" }) : null
925
+ ] })
926
+ ] }),
898
927
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "No refund payment mapping for this return. Ensure the refund_payment_mapping module is registered and a mapping was created when the return was created." })
899
928
  ] })
900
929
  ] }) });
@@ -1111,6 +1140,248 @@ const useDebounce$2 = (value, delay) => {
1111
1140
  return debouncedValue;
1112
1141
  };
1113
1142
  const getStatusBadgeClass$6 = (status) => {
1143
+ const statusLower = status.toLowerCase();
1144
+ if (statusLower === "requested") {
1145
+ return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
1146
+ }
1147
+ if (statusLower === "received") {
1148
+ return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
1149
+ }
1150
+ if (statusLower === "requires_action") {
1151
+ return "bg-ui-tag-red-bg text-ui-tag-red-text";
1152
+ }
1153
+ if (statusLower === "completed") {
1154
+ return "bg-ui-tag-green-bg text-ui-tag-green-text";
1155
+ }
1156
+ if (statusLower === "canceled") {
1157
+ return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
1158
+ }
1159
+ return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
1160
+ };
1161
+ const ReturnsPage = () => {
1162
+ const navigate = useNavigate();
1163
+ const [items, setItems] = useState([]);
1164
+ const [statusFilter, setStatusFilter] = useState("all");
1165
+ const [createdByFilter, setCreatedByFilter] = useState("all");
1166
+ const [searchQuery, setSearchQuery] = useState("");
1167
+ const debouncedSearchQuery = useDebounce$2(searchQuery, 300);
1168
+ const [isLoading, setIsLoading] = useState(true);
1169
+ const [isFetchingMore, setIsFetchingMore] = useState(false);
1170
+ const [error, setError] = useState(null);
1171
+ const [offset, setOffset] = useState(0);
1172
+ const [count, setCount] = useState(0);
1173
+ const limit = 50;
1174
+ const loadReturns = useCallback(
1175
+ async (nextOffset, replace = false) => {
1176
+ var _a;
1177
+ try {
1178
+ if (replace) {
1179
+ setIsLoading(true);
1180
+ } else {
1181
+ setIsFetchingMore(true);
1182
+ }
1183
+ setError(null);
1184
+ const params = new URLSearchParams();
1185
+ params.set("limit", String(limit));
1186
+ params.set("offset", String(nextOffset));
1187
+ if (statusFilter !== "all") {
1188
+ params.set("status", statusFilter);
1189
+ }
1190
+ if (debouncedSearchQuery.trim()) {
1191
+ params.set("q", debouncedSearchQuery.trim());
1192
+ }
1193
+ if (createdByFilter !== "all") {
1194
+ params.set("created_by", createdByFilter);
1195
+ }
1196
+ params.set("order", "created_at");
1197
+ const response = await fetch(
1198
+ `/admin/return?${params.toString()}`,
1199
+ { credentials: "include" }
1200
+ );
1201
+ if (!response.ok) {
1202
+ const message = await response.text();
1203
+ throw new Error(message || "Unable to load return orders");
1204
+ }
1205
+ const payload = await response.json();
1206
+ setCount(payload.count ?? 0);
1207
+ setOffset(nextOffset + (((_a = payload.returns) == null ? void 0 : _a.length) ?? 0));
1208
+ setItems(
1209
+ (prev) => replace ? payload.returns ?? [] : [...prev, ...payload.returns ?? []]
1210
+ );
1211
+ } catch (loadError) {
1212
+ const message = loadError instanceof Error ? loadError.message : "Unable to load return orders";
1213
+ setError(message);
1214
+ } finally {
1215
+ setIsLoading(false);
1216
+ setIsFetchingMore(false);
1217
+ }
1218
+ },
1219
+ [statusFilter, createdByFilter, debouncedSearchQuery]
1220
+ );
1221
+ useEffect(() => {
1222
+ void loadReturns(0, true);
1223
+ }, [statusFilter, createdByFilter, debouncedSearchQuery, loadReturns]);
1224
+ const hasMore = useMemo(() => offset < count, [offset, count]);
1225
+ const availableStatuses = useMemo(() => {
1226
+ const statuses = /* @__PURE__ */ new Set();
1227
+ items.forEach((item) => statuses.add(item.status));
1228
+ return Array.from(statuses).sort();
1229
+ }, [items]);
1230
+ return /* @__PURE__ */ jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxs(Container, { className: "mx-auto flex w-full max-w-7xl flex-col gap-6 p-6", children: [
1231
+ /* @__PURE__ */ jsxs("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
1232
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
1233
+ /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Return Orders" }),
1234
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "View and manage all customer return orders" })
1235
+ ] }),
1236
+ /* @__PURE__ */ jsx(Button, { variant: "primary", onClick: () => loadReturns(0, true), children: "Refresh" })
1237
+ ] }),
1238
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
1239
+ /* @__PURE__ */ jsx(
1240
+ Input,
1241
+ {
1242
+ placeholder: "Search by return ID, order ID, or customer email",
1243
+ value: searchQuery,
1244
+ onChange: (event) => setSearchQuery(event.target.value),
1245
+ className: "md:max-w-sm"
1246
+ }
1247
+ ),
1248
+ /* @__PURE__ */ jsxs("div", { className: "flex gap-3", children: [
1249
+ /* @__PURE__ */ jsxs(
1250
+ "select",
1251
+ {
1252
+ value: createdByFilter,
1253
+ onChange: (event) => setCreatedByFilter(event.target.value),
1254
+ 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",
1255
+ children: [
1256
+ /* @__PURE__ */ jsx("option", { value: "all", children: "All (Created by)" }),
1257
+ /* @__PURE__ */ jsx("option", { value: "customer", children: "Customer" }),
1258
+ /* @__PURE__ */ jsx("option", { value: "admin", children: "Admin" })
1259
+ ]
1260
+ }
1261
+ ),
1262
+ /* @__PURE__ */ jsxs(
1263
+ "select",
1264
+ {
1265
+ value: statusFilter,
1266
+ onChange: (event) => setStatusFilter(event.target.value),
1267
+ 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",
1268
+ children: [
1269
+ /* @__PURE__ */ jsx("option", { value: "all", children: "All Statuses" }),
1270
+ availableStatuses.map((status) => /* @__PURE__ */ jsx("option", { value: status, children: status.replace(/_/g, " ").toUpperCase() }, status))
1271
+ ]
1272
+ }
1273
+ )
1274
+ ] })
1275
+ ] }),
1276
+ error ? /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
1277
+ /* @__PURE__ */ jsx(Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
1278
+ /* @__PURE__ */ jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsx(
1279
+ Button,
1280
+ {
1281
+ variant: "secondary",
1282
+ onClick: () => loadReturns(0, true),
1283
+ children: "Try again"
1284
+ }
1285
+ ) })
1286
+ ] }) : null,
1287
+ isLoading ? /* @__PURE__ */ jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsx(Text, { children: "Loading return orders..." }) }) : items.length === 0 ? /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-dashed border-ui-border-strong p-10 text-center", children: [
1288
+ /* @__PURE__ */ jsx(Heading, { level: "h3", className: "text-xl", children: "No return orders yet" }),
1289
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "mt-2 text-ui-fg-subtle", children: "Return orders created by customers will appear here." })
1290
+ ] }) : /* @__PURE__ */ jsx("div", { className: "overflow-hidden rounded-xl border border-ui-border-base", children: /* @__PURE__ */ jsxs("table", { className: "min-w-full divide-y divide-ui-border-base", children: [
1291
+ /* @__PURE__ */ jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxs("tr", { children: [
1292
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Return ID" }),
1293
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Order ID" }),
1294
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Customer" }),
1295
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Status" }),
1296
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Refund Amount" }),
1297
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Created" }),
1298
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Actions" })
1299
+ ] }) }),
1300
+ /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((returnOrder) => /* @__PURE__ */ jsxs(
1301
+ "tr",
1302
+ {
1303
+ className: "hover:bg-ui-bg-subtle/60 cursor-pointer",
1304
+ onClick: () => navigate(`/returns/${returnOrder.id}`),
1305
+ children: [
1306
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-0.5", children: /* @__PURE__ */ jsx("span", { children: returnOrder.id }) }) }),
1307
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: returnOrder.order_id }),
1308
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: returnOrder.customer_email || returnOrder.order_email || "—" }),
1309
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsx(
1310
+ Badge,
1311
+ {
1312
+ size: "2xsmall",
1313
+ className: `uppercase ${getStatusBadgeClass$6(returnOrder.status)}`,
1314
+ children: returnOrder.status.replace(/_/g, " ")
1315
+ }
1316
+ ) }),
1317
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: (() => {
1318
+ const calc = returnOrder.refund;
1319
+ if ((calc == null ? void 0 : calc.is_processed) && calc.final_refund_amount != null) {
1320
+ return formatRefundCurrency(
1321
+ calc.final_refund_amount,
1322
+ calc.currency_code || returnOrder.currency_code
1323
+ );
1324
+ }
1325
+ if (calc) {
1326
+ return "Pending";
1327
+ }
1328
+ if (returnOrder.refund_amount == null) {
1329
+ return "—";
1330
+ }
1331
+ return formatRefundCurrency(
1332
+ Number(returnOrder.refund_amount),
1333
+ returnOrder.currency_code
1334
+ );
1335
+ })() }),
1336
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: new Date(returnOrder.created_at).toLocaleDateString("en-US", {
1337
+ year: "numeric",
1338
+ month: "short",
1339
+ day: "numeric",
1340
+ hour: "numeric",
1341
+ minute: "2-digit",
1342
+ hour12: true
1343
+ }) }),
1344
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsx(
1345
+ Button,
1346
+ {
1347
+ variant: "transparent",
1348
+ size: "small",
1349
+ onClick: (e) => {
1350
+ e.stopPropagation();
1351
+ navigate(`/app/orders/${returnOrder.order_id}`);
1352
+ },
1353
+ children: "Go to order"
1354
+ }
1355
+ ) })
1356
+ ]
1357
+ },
1358
+ returnOrder.id
1359
+ )) })
1360
+ ] }) }),
1361
+ hasMore ? /* @__PURE__ */ jsx("div", { className: "flex justify-center", children: /* @__PURE__ */ jsx(
1362
+ Button,
1363
+ {
1364
+ variant: "secondary",
1365
+ isLoading: isFetchingMore,
1366
+ onClick: () => loadReturns(offset, false),
1367
+ children: "Load more"
1368
+ }
1369
+ ) }) : null
1370
+ ] }) });
1371
+ };
1372
+ const config$6 = defineRouteConfig({
1373
+ label: "Return Orders",
1374
+ icon: ArrowPath
1375
+ });
1376
+ const useDebounce$1 = (value, delay) => {
1377
+ const [debouncedValue, setDebouncedValue] = useState(value);
1378
+ useEffect(() => {
1379
+ const handler = setTimeout(() => setDebouncedValue(value), delay);
1380
+ return () => clearTimeout(handler);
1381
+ }, [value, delay]);
1382
+ return debouncedValue;
1383
+ };
1384
+ const getStatusBadgeClass$5 = (status) => {
1114
1385
  const s2 = status.toLowerCase();
1115
1386
  if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
1116
1387
  if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
@@ -1122,12 +1393,12 @@ const RefundsPage = () => {
1122
1393
  const navigate = useNavigate();
1123
1394
  const [items, setItems] = useState([]);
1124
1395
  const [orderIdSearch, setOrderIdSearch] = useState("");
1125
- const debouncedOrderId = useDebounce$2(orderIdSearch, 300);
1396
+ const debouncedOrderId = useDebounce$1(orderIdSearch, 300);
1126
1397
  const [paymentStatusFilter, setPaymentStatusFilter] = useState("all");
1127
1398
  const [providerSearch, setProviderSearch] = useState("");
1128
- const debouncedProvider = useDebounce$2(providerSearch, 300);
1399
+ const debouncedProvider = useDebounce$1(providerSearch, 300);
1129
1400
  const [currencySearch, setCurrencySearch] = useState("");
1130
- const debouncedCurrency = useDebounce$2(currencySearch, 300);
1401
+ const debouncedCurrency = useDebounce$1(currencySearch, 300);
1131
1402
  const [dateFrom, setDateFrom] = useState("");
1132
1403
  const [dateTo, setDateTo] = useState("");
1133
1404
  const [amountMin, setAmountMin] = useState("");
@@ -1339,7 +1610,7 @@ const RefundsPage = () => {
1339
1610
  Badge,
1340
1611
  {
1341
1612
  size: "2xsmall",
1342
- className: `uppercase ${getStatusBadgeClass$6(displayStatus(r))}`,
1613
+ className: `uppercase ${getStatusBadgeClass$5(displayStatus(r))}`,
1343
1614
  children: displayStatus(r) !== "—" ? displayStatus(r).replace(/_/g, " ") : "—"
1344
1615
  }
1345
1616
  ) }),
@@ -1393,11 +1664,11 @@ const RefundsPage = () => {
1393
1664
  ) }) : null
1394
1665
  ] }) });
1395
1666
  };
1396
- const config$6 = defineRouteConfig({
1667
+ const config$5 = defineRouteConfig({
1397
1668
  label: "Refunds",
1398
1669
  icon: Receipt
1399
1670
  });
1400
- const useDebounce$1 = (value, delay) => {
1671
+ const useDebounce = (value, delay) => {
1401
1672
  const [debouncedValue, setDebouncedValue] = useState(value);
1402
1673
  useEffect(() => {
1403
1674
  const handler = setTimeout(() => setDebouncedValue(value), delay);
@@ -1405,249 +1676,7 @@ const useDebounce$1 = (value, delay) => {
1405
1676
  }, [value, delay]);
1406
1677
  return debouncedValue;
1407
1678
  };
1408
- const getStatusBadgeClass$5 = (status) => {
1409
- const statusLower = status.toLowerCase();
1410
- if (statusLower === "requested") {
1411
- return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
1412
- }
1413
- if (statusLower === "received") {
1414
- return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
1415
- }
1416
- if (statusLower === "requires_action") {
1417
- return "bg-ui-tag-red-bg text-ui-tag-red-text";
1418
- }
1419
- if (statusLower === "completed") {
1420
- return "bg-ui-tag-green-bg text-ui-tag-green-text";
1421
- }
1422
- if (statusLower === "canceled") {
1423
- return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
1424
- }
1425
- return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
1426
- };
1427
- const ReturnsPage = () => {
1428
- const navigate = useNavigate();
1429
- const [items, setItems] = useState([]);
1430
- const [statusFilter, setStatusFilter] = useState("all");
1431
- const [createdByFilter, setCreatedByFilter] = useState("all");
1432
- const [searchQuery, setSearchQuery] = useState("");
1433
- const debouncedSearchQuery = useDebounce$1(searchQuery, 300);
1434
- const [isLoading, setIsLoading] = useState(true);
1435
- const [isFetchingMore, setIsFetchingMore] = useState(false);
1436
- const [error, setError] = useState(null);
1437
- const [offset, setOffset] = useState(0);
1438
- const [count, setCount] = useState(0);
1439
- const limit = 50;
1440
- const loadReturns = useCallback(
1441
- async (nextOffset, replace = false) => {
1442
- var _a;
1443
- try {
1444
- if (replace) {
1445
- setIsLoading(true);
1446
- } else {
1447
- setIsFetchingMore(true);
1448
- }
1449
- setError(null);
1450
- const params = new URLSearchParams();
1451
- params.set("limit", String(limit));
1452
- params.set("offset", String(nextOffset));
1453
- if (statusFilter !== "all") {
1454
- params.set("status", statusFilter);
1455
- }
1456
- if (debouncedSearchQuery.trim()) {
1457
- params.set("q", debouncedSearchQuery.trim());
1458
- }
1459
- if (createdByFilter !== "all") {
1460
- params.set("created_by", createdByFilter);
1461
- }
1462
- params.set("order", "created_at");
1463
- const response = await fetch(
1464
- `/admin/return?${params.toString()}`,
1465
- { credentials: "include" }
1466
- );
1467
- if (!response.ok) {
1468
- const message = await response.text();
1469
- throw new Error(message || "Unable to load return orders");
1470
- }
1471
- const payload = await response.json();
1472
- setCount(payload.count ?? 0);
1473
- setOffset(nextOffset + (((_a = payload.returns) == null ? void 0 : _a.length) ?? 0));
1474
- setItems(
1475
- (prev) => replace ? payload.returns ?? [] : [...prev, ...payload.returns ?? []]
1476
- );
1477
- } catch (loadError) {
1478
- const message = loadError instanceof Error ? loadError.message : "Unable to load return orders";
1479
- setError(message);
1480
- } finally {
1481
- setIsLoading(false);
1482
- setIsFetchingMore(false);
1483
- }
1484
- },
1485
- [statusFilter, createdByFilter, debouncedSearchQuery]
1486
- );
1487
- useEffect(() => {
1488
- void loadReturns(0, true);
1489
- }, [statusFilter, createdByFilter, debouncedSearchQuery, loadReturns]);
1490
- const hasMore = useMemo(() => offset < count, [offset, count]);
1491
- const availableStatuses = useMemo(() => {
1492
- const statuses = /* @__PURE__ */ new Set();
1493
- items.forEach((item) => statuses.add(item.status));
1494
- return Array.from(statuses).sort();
1495
- }, [items]);
1496
- return /* @__PURE__ */ jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxs(Container, { className: "mx-auto flex w-full max-w-7xl flex-col gap-6 p-6", children: [
1497
- /* @__PURE__ */ jsxs("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
1498
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
1499
- /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Return Orders" }),
1500
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "View and manage all customer return orders" })
1501
- ] }),
1502
- /* @__PURE__ */ jsx(Button, { variant: "primary", onClick: () => loadReturns(0, true), children: "Refresh" })
1503
- ] }),
1504
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
1505
- /* @__PURE__ */ jsx(
1506
- Input,
1507
- {
1508
- placeholder: "Search by return ID, order ID, or customer email",
1509
- value: searchQuery,
1510
- onChange: (event) => setSearchQuery(event.target.value),
1511
- className: "md:max-w-sm"
1512
- }
1513
- ),
1514
- /* @__PURE__ */ jsxs("div", { className: "flex gap-3", children: [
1515
- /* @__PURE__ */ jsxs(
1516
- "select",
1517
- {
1518
- value: createdByFilter,
1519
- onChange: (event) => setCreatedByFilter(event.target.value),
1520
- 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",
1521
- children: [
1522
- /* @__PURE__ */ jsx("option", { value: "all", children: "All (Created by)" }),
1523
- /* @__PURE__ */ jsx("option", { value: "customer", children: "Customer" }),
1524
- /* @__PURE__ */ jsx("option", { value: "admin", children: "Admin" })
1525
- ]
1526
- }
1527
- ),
1528
- /* @__PURE__ */ jsxs(
1529
- "select",
1530
- {
1531
- value: statusFilter,
1532
- onChange: (event) => setStatusFilter(event.target.value),
1533
- 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",
1534
- children: [
1535
- /* @__PURE__ */ jsx("option", { value: "all", children: "All Statuses" }),
1536
- availableStatuses.map((status) => /* @__PURE__ */ jsx("option", { value: status, children: status.replace(/_/g, " ").toUpperCase() }, status))
1537
- ]
1538
- }
1539
- )
1540
- ] })
1541
- ] }),
1542
- error ? /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
1543
- /* @__PURE__ */ jsx(Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
1544
- /* @__PURE__ */ jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsx(
1545
- Button,
1546
- {
1547
- variant: "secondary",
1548
- onClick: () => loadReturns(0, true),
1549
- children: "Try again"
1550
- }
1551
- ) })
1552
- ] }) : null,
1553
- isLoading ? /* @__PURE__ */ jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsx(Text, { children: "Loading return orders..." }) }) : items.length === 0 ? /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-dashed border-ui-border-strong p-10 text-center", children: [
1554
- /* @__PURE__ */ jsx(Heading, { level: "h3", className: "text-xl", children: "No return orders yet" }),
1555
- /* @__PURE__ */ jsx(Text, { size: "small", className: "mt-2 text-ui-fg-subtle", children: "Return orders created by customers will appear here." })
1556
- ] }) : /* @__PURE__ */ jsx("div", { className: "overflow-hidden rounded-xl border border-ui-border-base", children: /* @__PURE__ */ jsxs("table", { className: "min-w-full divide-y divide-ui-border-base", children: [
1557
- /* @__PURE__ */ jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxs("tr", { children: [
1558
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Return ID" }),
1559
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Order ID" }),
1560
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Customer" }),
1561
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Status" }),
1562
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Refund Amount" }),
1563
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Created" }),
1564
- /* @__PURE__ */ jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Actions" })
1565
- ] }) }),
1566
- /* @__PURE__ */ jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((returnOrder) => /* @__PURE__ */ jsxs(
1567
- "tr",
1568
- {
1569
- className: "hover:bg-ui-bg-subtle/60 cursor-pointer",
1570
- onClick: () => navigate(`/returns/${returnOrder.id}`),
1571
- children: [
1572
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-0.5", children: /* @__PURE__ */ jsx("span", { children: returnOrder.id }) }) }),
1573
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: returnOrder.order_id }),
1574
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: returnOrder.customer_email || returnOrder.order_email || "—" }),
1575
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsx(
1576
- Badge,
1577
- {
1578
- size: "2xsmall",
1579
- className: `uppercase ${getStatusBadgeClass$5(returnOrder.status)}`,
1580
- children: returnOrder.status.replace(/_/g, " ")
1581
- }
1582
- ) }),
1583
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: (() => {
1584
- const calc = returnOrder.refund;
1585
- if ((calc == null ? void 0 : calc.is_processed) && calc.final_refund_amount != null) {
1586
- return formatRefundCurrency(
1587
- calc.final_refund_amount,
1588
- calc.currency_code || returnOrder.currency_code
1589
- );
1590
- }
1591
- if (calc) {
1592
- return "Pending";
1593
- }
1594
- if (returnOrder.refund_amount == null) {
1595
- return "—";
1596
- }
1597
- return formatRefundCurrency(
1598
- Number(returnOrder.refund_amount),
1599
- returnOrder.currency_code
1600
- );
1601
- })() }),
1602
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: new Date(returnOrder.created_at).toLocaleDateString("en-US", {
1603
- year: "numeric",
1604
- month: "short",
1605
- day: "numeric",
1606
- hour: "numeric",
1607
- minute: "2-digit",
1608
- hour12: true
1609
- }) }),
1610
- /* @__PURE__ */ jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsx(
1611
- Button,
1612
- {
1613
- variant: "transparent",
1614
- size: "small",
1615
- onClick: (e) => {
1616
- e.stopPropagation();
1617
- navigate(`/app/orders/${returnOrder.order_id}`);
1618
- },
1619
- children: "Go to order"
1620
- }
1621
- ) })
1622
- ]
1623
- },
1624
- returnOrder.id
1625
- )) })
1626
- ] }) }),
1627
- hasMore ? /* @__PURE__ */ jsx("div", { className: "flex justify-center", children: /* @__PURE__ */ jsx(
1628
- Button,
1629
- {
1630
- variant: "secondary",
1631
- isLoading: isFetchingMore,
1632
- onClick: () => loadReturns(offset, false),
1633
- children: "Load more"
1634
- }
1635
- ) }) : null
1636
- ] }) });
1637
- };
1638
- const config$5 = defineRouteConfig({
1639
- label: "Return Orders",
1640
- icon: ArrowPath
1641
- });
1642
- const useDebounce = (value, delay) => {
1643
- const [debouncedValue, setDebouncedValue] = useState(value);
1644
- useEffect(() => {
1645
- const handler = setTimeout(() => setDebouncedValue(value), delay);
1646
- return () => clearTimeout(handler);
1647
- }, [value, delay]);
1648
- return debouncedValue;
1649
- };
1650
- const getStatusBadgeClass$4 = (status) => {
1679
+ const getStatusBadgeClass$4 = (status) => {
1651
1680
  const statusLower = status.toLowerCase();
1652
1681
  if (statusLower === "requested") {
1653
1682
  return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
@@ -1967,220 +1996,28 @@ const PaymentDetailPage = () => {
1967
1996
  ] }),
1968
1997
  /* @__PURE__ */ jsxs("div", { children: [
1969
1998
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Created" }),
1970
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: new Date(detail.created_at).toLocaleDateString("en-US", {
1971
- year: "numeric",
1972
- month: "short",
1973
- day: "numeric",
1974
- hour: "numeric",
1975
- minute: "2-digit",
1976
- hour12: true
1977
- }) })
1978
- ] })
1979
- ] }) }),
1980
- Object.keys(detail.data ?? {}).length > 0 ? /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
1981
- /* @__PURE__ */ jsx(Heading, { level: "h2", className: "text-lg mb-4", children: "Provider data" }),
1982
- /* @__PURE__ */ jsx("pre", { className: "text-xs bg-ui-bg-subtle p-4 rounded-lg overflow-auto max-h-96", children: JSON.stringify(detail.data, null, 2) })
1983
- ] }) : /* @__PURE__ */ jsx("div", { className: "rounded-xl border border-ui-border-base p-6", children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "No provider data for this session." }) })
1984
- ] }) : null
1985
- ] }) });
1986
- };
1987
- const config$3 = defineRouteConfig({
1988
- label: "Payment details",
1989
- icon: CreditCard
1990
- });
1991
- const getStatusBadgeClass$2 = (status) => {
1992
- const s2 = status.toLowerCase();
1993
- if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
1994
- if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
1995
- if (s2 === "error" || s2 === "canceled" || s2 === "cancelled") return "bg-ui-tag-red-bg text-ui-tag-red-text";
1996
- if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
1997
- return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
1998
- };
1999
- const formatAmount = (value) => {
2000
- return String(value);
2001
- };
2002
- const RefundDetailPage = () => {
2003
- var _a, _b, _c;
2004
- const navigate = useNavigate();
2005
- const params = useParams();
2006
- const id = (_a = params == null ? void 0 : params.id) == null ? void 0 : _a.trim();
2007
- const [detail, setDetail] = useState(null);
2008
- const [loading, setLoading] = useState(!!id);
2009
- const [error, setError] = useState(null);
2010
- const [gatewayExpanded, setGatewayExpanded] = useState(false);
2011
- useEffect(() => {
2012
- if (!id) {
2013
- setLoading(false);
2014
- return;
2015
- }
2016
- let cancelled = false;
2017
- setLoading(true);
2018
- setError(null);
2019
- fetch(`/admin/refunds/${id}`, { credentials: "include" }).then((res) => {
2020
- if (!res.ok) throw new Error(res.statusText || "Failed to load");
2021
- return res.json();
2022
- }).then((data) => {
2023
- if (!cancelled) setDetail(data);
2024
- }).catch((e) => {
2025
- if (!cancelled) setError(e instanceof Error ? e.message : "Failed to load");
2026
- }).finally(() => {
2027
- if (!cancelled) setLoading(false);
2028
- });
2029
- return () => {
2030
- cancelled = true;
2031
- };
2032
- }, [id]);
2033
- const paymentStatus = ((_b = detail == null ? void 0 : detail.payment) == null ? void 0 : _b.status) ?? "—";
2034
- 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;
2035
- return /* @__PURE__ */ jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxs(Container, { className: "mx-auto flex w-full max-w-4xl flex-col gap-6 p-6", children: [
2036
- /* @__PURE__ */ jsx("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
2037
- /* @__PURE__ */ jsx(Button, { variant: "transparent", size: "small", onClick: () => navigate("/refunds"), children: "← Refunds" }),
2038
- /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Refund details" }),
2039
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle font-mono", children: id ?? "—" })
2040
- ] }) }),
2041
- error ? /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
2042
- /* @__PURE__ */ jsx(Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
2043
- /* @__PURE__ */ jsx(Button, { variant: "secondary", className: "mt-4", onClick: () => navigate("/refunds"), children: "Back to list" })
2044
- ] }) : loading ? /* @__PURE__ */ jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsx(Text, { children: "Loading…" }) }) : detail ? /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-6", children: [
2045
- /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2046
- /* @__PURE__ */ jsx(Heading, { level: "h2", className: "text-lg mb-4", children: "Refund summary" }),
2047
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
2048
- /* @__PURE__ */ jsxs("div", { children: [
2049
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Refund ID" }),
2050
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block font-mono text-sm", children: detail.refund.id })
2051
- ] }),
2052
- /* @__PURE__ */ jsxs("div", { children: [
2053
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Amount" }),
2054
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: formatAmount(detail.refund.amount) })
2055
- ] }),
2056
- /* @__PURE__ */ jsxs("div", { children: [
2057
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Note" }),
2058
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.refund.note ?? "—" })
2059
- ] }),
2060
- /* @__PURE__ */ jsxs("div", { children: [
2061
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Created at" }),
2062
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: new Date(detail.refund.created_at).toLocaleDateString("en-US", {
2063
- year: "numeric",
2064
- month: "short",
2065
- day: "numeric",
2066
- hour: "numeric",
2067
- minute: "2-digit",
2068
- hour12: true
2069
- }) })
2070
- ] }),
2071
- detail.refund.created_by ? /* @__PURE__ */ jsxs("div", { children: [
2072
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Created by" }),
2073
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block font-mono text-sm", children: detail.refund.created_by })
2074
- ] }) : null
2075
- ] })
2076
- ] }),
2077
- /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2078
- /* @__PURE__ */ jsx(Heading, { level: "h2", className: "text-lg mb-4", children: "Payment summary" }),
2079
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
2080
- /* @__PURE__ */ jsxs("div", { children: [
2081
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Payment amount" }),
2082
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: formatAmount(detail.payment.payment_amount) })
2083
- ] }),
2084
- /* @__PURE__ */ jsxs("div", { children: [
2085
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Captured amount" }),
2086
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: formatAmount(detail.payment.captured_amount) })
2087
- ] }),
2088
- /* @__PURE__ */ jsxs("div", { children: [
2089
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Refunded amount" }),
2090
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: formatAmount(detail.payment.refunded_amount) })
2091
- ] }),
2092
- /* @__PURE__ */ jsxs("div", { children: [
2093
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Provider" }),
2094
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.payment.provider_id || "—" })
2095
- ] }),
2096
- /* @__PURE__ */ jsxs("div", { children: [
2097
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Status" }),
2098
- /* @__PURE__ */ jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsx(
2099
- Badge,
2100
- {
2101
- size: "2xsmall",
2102
- className: `uppercase ${getStatusBadgeClass$2(paymentStatus)}`,
2103
- children: paymentStatus !== "—" ? paymentStatus.replace(/_/g, " ") : "—"
2104
- }
2105
- ) })
2106
- ] }),
2107
- detail.computed ? /* @__PURE__ */ jsxs(Fragment, { children: [
2108
- /* @__PURE__ */ jsxs("div", { children: [
2109
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Full refund" }),
2110
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.computed.is_full_refund ? "Yes" : "No" })
2111
- ] }),
2112
- /* @__PURE__ */ jsxs("div", { children: [
2113
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Remaining refundable" }),
2114
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: formatAmount(detail.computed.remaining_refundable_amount) })
2115
- ] }),
2116
- /* @__PURE__ */ jsxs("div", { children: [
2117
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Refund %" }),
2118
- /* @__PURE__ */ jsxs(Text, { className: "mt-1 block", children: [
2119
- detail.computed.refund_percentage.toFixed(1),
2120
- "%"
2121
- ] })
2122
- ] })
2123
- ] }) : null
2124
- ] })
2125
- ] }),
2126
- /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2127
- /* @__PURE__ */ jsx(Heading, { level: "h2", className: "text-lg mb-4", children: "Order summary" }),
2128
- detail.order ? /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
2129
- /* @__PURE__ */ jsxs("div", { children: [
2130
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Order" }),
2131
- /* @__PURE__ */ jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsx(
2132
- Button,
2133
- {
2134
- variant: "transparent",
2135
- size: "small",
2136
- onClick: () => navigate(`/orders/${detail.order.order_id}`),
2137
- children: detail.order.order_number ?? detail.order.order_id
2138
- }
2139
- ) })
2140
- ] }),
2141
- detail.order.total != null ? /* @__PURE__ */ jsxs("div", { children: [
2142
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Total" }),
2143
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: formatAmount(detail.order.total) })
2144
- ] }) : null,
2145
- detail.order.customer_id ? /* @__PURE__ */ jsxs("div", { children: [
2146
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Customer ID" }),
2147
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block font-mono text-sm", children: detail.order.customer_id })
2148
- ] }) : null,
2149
- detail.order.region ? /* @__PURE__ */ jsxs("div", { children: [
2150
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Region" }),
2151
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.order.region })
2152
- ] }) : null,
2153
- detail.order.fulfillment_status ? /* @__PURE__ */ jsxs("div", { children: [
2154
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Fulfillment status" }),
2155
- /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.order.fulfillment_status })
2156
- ] }) : null
2157
- ] }) : /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "No order linked to this refund." })
2158
- ] }),
2159
- /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2160
- /* @__PURE__ */ jsxs(
2161
- "button",
2162
- {
2163
- type: "button",
2164
- className: "flex w-full items-center justify-between text-left",
2165
- onClick: () => setGatewayExpanded((prev) => !prev),
2166
- "aria-expanded": gatewayExpanded,
2167
- "aria-label": gatewayExpanded ? "Collapse gateway data" : "Expand gateway data",
2168
- children: [
2169
- /* @__PURE__ */ jsx(Heading, { level: "h2", className: "text-lg", children: "Gateway data" }),
2170
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: gatewayExpanded ? "Collapse" : "Expand" })
2171
- ]
2172
- }
2173
- ),
2174
- gatewayExpanded && /* @__PURE__ */ jsx("div", { className: "mt-4", children: hasGatewayData ? /* @__PURE__ */ 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__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "No gateway payload for this payment." }) })
2175
- ] })
1999
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: new Date(detail.created_at).toLocaleDateString("en-US", {
2000
+ year: "numeric",
2001
+ month: "short",
2002
+ day: "numeric",
2003
+ hour: "numeric",
2004
+ minute: "2-digit",
2005
+ hour12: true
2006
+ }) })
2007
+ ] })
2008
+ ] }) }),
2009
+ Object.keys(detail.data ?? {}).length > 0 ? /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2010
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "text-lg mb-4", children: "Provider data" }),
2011
+ /* @__PURE__ */ jsx("pre", { className: "text-xs bg-ui-bg-subtle p-4 rounded-lg overflow-auto max-h-96", children: JSON.stringify(detail.data, null, 2) })
2012
+ ] }) : /* @__PURE__ */ jsx("div", { className: "rounded-xl border border-ui-border-base p-6", children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "No provider data for this session." }) })
2176
2013
  ] }) : null
2177
2014
  ] }) });
2178
2015
  };
2179
- const config$2 = defineRouteConfig({
2180
- label: "Refund details",
2181
- icon: Receipt
2016
+ const config$3 = defineRouteConfig({
2017
+ label: "Payment details",
2018
+ icon: CreditCard
2182
2019
  });
2183
- const getStatusBadgeClass$1 = (status) => {
2020
+ const getStatusBadgeClass$2 = (status) => {
2184
2021
  const statusLower = status.toLowerCase();
2185
2022
  if (statusLower === "requested") {
2186
2023
  return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
@@ -2206,7 +2043,7 @@ const getStatusBadgeClass$1 = (status) => {
2206
2043
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
2207
2044
  };
2208
2045
  const ReturnDetailPage = () => {
2209
- var _a, _b;
2046
+ var _a, _b, _c;
2210
2047
  const navigate = useNavigate();
2211
2048
  const { id } = useParams();
2212
2049
  const [returnOrder, setReturnOrder] = useState(null);
@@ -2314,7 +2151,7 @@ const ReturnDetailPage = () => {
2314
2151
  Badge,
2315
2152
  {
2316
2153
  size: "small",
2317
- className: `uppercase ${getStatusBadgeClass$1(returnOrder.status)}`,
2154
+ className: `uppercase ${getStatusBadgeClass$2(returnOrder.status)}`,
2318
2155
  children: returnOrder.status.replace(/_/g, " ")
2319
2156
  }
2320
2157
  )
@@ -2397,7 +2234,7 @@ const ReturnDetailPage = () => {
2397
2234
  Badge,
2398
2235
  {
2399
2236
  size: "2xsmall",
2400
- className: `uppercase ${getStatusBadgeClass$1(entry.status)}`,
2237
+ className: `uppercase ${getStatusBadgeClass$2(entry.status)}`,
2401
2238
  children: entry.status.replace(/_/g, " ")
2402
2239
  }
2403
2240
  ) }),
@@ -2427,6 +2264,10 @@ const ReturnDetailPage = () => {
2427
2264
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Customer" }),
2428
2265
  /* @__PURE__ */ jsx(Text, { className: "font-medium", children: ((_b = returnOrder.order.customer) == null ? void 0 : _b.email) || returnOrder.order.email || "—" })
2429
2266
  ] }),
2267
+ /* @__PURE__ */ jsxs("div", { children: [
2268
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Payment method" }),
2269
+ /* @__PURE__ */ jsx(Text, { className: "font-medium", children: ((_c = returnOrder.order.order_payment) == null ? void 0 : _c.label) || "—" })
2270
+ ] }),
2430
2271
  returnOrder.order.total && /* @__PURE__ */ jsxs("div", { children: [
2431
2272
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Total" }),
2432
2273
  /* @__PURE__ */ jsxs(Text, { className: "font-medium", children: [
@@ -2455,10 +2296,202 @@ const ReturnDetailPage = () => {
2455
2296
  updateSuccess && /* @__PURE__ */ jsx("div", { className: "rounded-lg border border-ui-border-success bg-ui-bg-success-subtle p-4", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-success", children: "Action completed successfully" }) })
2456
2297
  ] }) });
2457
2298
  };
2458
- const config$1 = defineRouteConfig({
2299
+ const config$2 = defineRouteConfig({
2459
2300
  label: "Return Order Details",
2460
2301
  icon: CheckCircle
2461
2302
  });
2303
+ const getStatusBadgeClass$1 = (status) => {
2304
+ const s2 = status.toLowerCase();
2305
+ if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
2306
+ if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
2307
+ if (s2 === "error" || s2 === "canceled" || s2 === "cancelled") return "bg-ui-tag-red-bg text-ui-tag-red-text";
2308
+ if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
2309
+ return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
2310
+ };
2311
+ const formatAmount = (value) => {
2312
+ return String(value);
2313
+ };
2314
+ const RefundDetailPage = () => {
2315
+ var _a, _b, _c;
2316
+ const navigate = useNavigate();
2317
+ const params = useParams();
2318
+ const id = (_a = params == null ? void 0 : params.id) == null ? void 0 : _a.trim();
2319
+ const [detail, setDetail] = useState(null);
2320
+ const [loading, setLoading] = useState(!!id);
2321
+ const [error, setError] = useState(null);
2322
+ const [gatewayExpanded, setGatewayExpanded] = useState(false);
2323
+ useEffect(() => {
2324
+ if (!id) {
2325
+ setLoading(false);
2326
+ return;
2327
+ }
2328
+ let cancelled = false;
2329
+ setLoading(true);
2330
+ setError(null);
2331
+ fetch(`/admin/refunds/${id}`, { credentials: "include" }).then((res) => {
2332
+ if (!res.ok) throw new Error(res.statusText || "Failed to load");
2333
+ return res.json();
2334
+ }).then((data) => {
2335
+ if (!cancelled) setDetail(data);
2336
+ }).catch((e) => {
2337
+ if (!cancelled) setError(e instanceof Error ? e.message : "Failed to load");
2338
+ }).finally(() => {
2339
+ if (!cancelled) setLoading(false);
2340
+ });
2341
+ return () => {
2342
+ cancelled = true;
2343
+ };
2344
+ }, [id]);
2345
+ const paymentStatus = ((_b = detail == null ? void 0 : detail.payment) == null ? void 0 : _b.status) ?? "—";
2346
+ 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;
2347
+ return /* @__PURE__ */ jsx("div", { className: "w-full p-6", children: /* @__PURE__ */ jsxs(Container, { className: "mx-auto flex w-full max-w-4xl flex-col gap-6 p-6", children: [
2348
+ /* @__PURE__ */ jsx("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
2349
+ /* @__PURE__ */ jsx(Button, { variant: "transparent", size: "small", onClick: () => navigate("/refunds"), children: "← Refunds" }),
2350
+ /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Refund details" }),
2351
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle font-mono", children: id ?? "—" })
2352
+ ] }) }),
2353
+ error ? /* @__PURE__ */ jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
2354
+ /* @__PURE__ */ jsx(Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
2355
+ /* @__PURE__ */ jsx(Button, { variant: "secondary", className: "mt-4", onClick: () => navigate("/refunds"), children: "Back to list" })
2356
+ ] }) : loading ? /* @__PURE__ */ jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsx(Text, { children: "Loading…" }) }) : detail ? /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-6", children: [
2357
+ /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2358
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "text-lg mb-4", children: "Refund summary" }),
2359
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
2360
+ /* @__PURE__ */ jsxs("div", { children: [
2361
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Refund ID" }),
2362
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block font-mono text-sm", children: detail.refund.id })
2363
+ ] }),
2364
+ /* @__PURE__ */ jsxs("div", { children: [
2365
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Amount" }),
2366
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: formatAmount(detail.refund.amount) })
2367
+ ] }),
2368
+ /* @__PURE__ */ jsxs("div", { children: [
2369
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Note" }),
2370
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.refund.note ?? "—" })
2371
+ ] }),
2372
+ /* @__PURE__ */ jsxs("div", { children: [
2373
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Created at" }),
2374
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: new Date(detail.refund.created_at).toLocaleDateString("en-US", {
2375
+ year: "numeric",
2376
+ month: "short",
2377
+ day: "numeric",
2378
+ hour: "numeric",
2379
+ minute: "2-digit",
2380
+ hour12: true
2381
+ }) })
2382
+ ] }),
2383
+ detail.refund.created_by ? /* @__PURE__ */ jsxs("div", { children: [
2384
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Created by" }),
2385
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block font-mono text-sm", children: detail.refund.created_by })
2386
+ ] }) : null
2387
+ ] })
2388
+ ] }),
2389
+ /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2390
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "text-lg mb-4", children: "Payment summary" }),
2391
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
2392
+ /* @__PURE__ */ jsxs("div", { children: [
2393
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Payment amount" }),
2394
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: formatAmount(detail.payment.payment_amount) })
2395
+ ] }),
2396
+ /* @__PURE__ */ jsxs("div", { children: [
2397
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Captured amount" }),
2398
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: formatAmount(detail.payment.captured_amount) })
2399
+ ] }),
2400
+ /* @__PURE__ */ jsxs("div", { children: [
2401
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Refunded amount" }),
2402
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: formatAmount(detail.payment.refunded_amount) })
2403
+ ] }),
2404
+ /* @__PURE__ */ jsxs("div", { children: [
2405
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Provider" }),
2406
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.payment.provider_id || "—" })
2407
+ ] }),
2408
+ /* @__PURE__ */ jsxs("div", { children: [
2409
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Status" }),
2410
+ /* @__PURE__ */ jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsx(
2411
+ Badge,
2412
+ {
2413
+ size: "2xsmall",
2414
+ className: `uppercase ${getStatusBadgeClass$1(paymentStatus)}`,
2415
+ children: paymentStatus !== "—" ? paymentStatus.replace(/_/g, " ") : "—"
2416
+ }
2417
+ ) })
2418
+ ] }),
2419
+ detail.computed ? /* @__PURE__ */ jsxs(Fragment, { children: [
2420
+ /* @__PURE__ */ jsxs("div", { children: [
2421
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Full refund" }),
2422
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.computed.is_full_refund ? "Yes" : "No" })
2423
+ ] }),
2424
+ /* @__PURE__ */ jsxs("div", { children: [
2425
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Remaining refundable" }),
2426
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: formatAmount(detail.computed.remaining_refundable_amount) })
2427
+ ] }),
2428
+ /* @__PURE__ */ jsxs("div", { children: [
2429
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Refund %" }),
2430
+ /* @__PURE__ */ jsxs(Text, { className: "mt-1 block", children: [
2431
+ detail.computed.refund_percentage.toFixed(1),
2432
+ "%"
2433
+ ] })
2434
+ ] })
2435
+ ] }) : null
2436
+ ] })
2437
+ ] }),
2438
+ /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2439
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "text-lg mb-4", children: "Order summary" }),
2440
+ detail.order ? /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
2441
+ /* @__PURE__ */ jsxs("div", { children: [
2442
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Order" }),
2443
+ /* @__PURE__ */ jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsx(
2444
+ Button,
2445
+ {
2446
+ variant: "transparent",
2447
+ size: "small",
2448
+ onClick: () => navigate(`/orders/${detail.order.order_id}`),
2449
+ children: detail.order.order_number ?? detail.order.order_id
2450
+ }
2451
+ ) })
2452
+ ] }),
2453
+ detail.order.total != null ? /* @__PURE__ */ jsxs("div", { children: [
2454
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Total" }),
2455
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: formatAmount(detail.order.total) })
2456
+ ] }) : null,
2457
+ detail.order.customer_id ? /* @__PURE__ */ jsxs("div", { children: [
2458
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Customer ID" }),
2459
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block font-mono text-sm", children: detail.order.customer_id })
2460
+ ] }) : null,
2461
+ detail.order.region ? /* @__PURE__ */ jsxs("div", { children: [
2462
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Region" }),
2463
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.order.region })
2464
+ ] }) : null,
2465
+ detail.order.fulfillment_status ? /* @__PURE__ */ jsxs("div", { children: [
2466
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "Fulfillment status" }),
2467
+ /* @__PURE__ */ jsx(Text, { className: "mt-1 block", children: detail.order.fulfillment_status })
2468
+ ] }) : null
2469
+ ] }) : /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "No order linked to this refund." })
2470
+ ] }),
2471
+ /* @__PURE__ */ jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
2472
+ /* @__PURE__ */ jsxs(
2473
+ "button",
2474
+ {
2475
+ type: "button",
2476
+ className: "flex w-full items-center justify-between text-left",
2477
+ onClick: () => setGatewayExpanded((prev) => !prev),
2478
+ "aria-expanded": gatewayExpanded,
2479
+ "aria-label": gatewayExpanded ? "Collapse gateway data" : "Expand gateway data",
2480
+ children: [
2481
+ /* @__PURE__ */ jsx(Heading, { level: "h2", className: "text-lg", children: "Gateway data" }),
2482
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: gatewayExpanded ? "Collapse" : "Expand" })
2483
+ ]
2484
+ }
2485
+ ),
2486
+ gatewayExpanded && /* @__PURE__ */ jsx("div", { className: "mt-4", children: hasGatewayData ? /* @__PURE__ */ 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__ */ jsx(Text, { size: "small", className: "text-ui-fg-muted", children: "No gateway payload for this payment." }) })
2487
+ ] })
2488
+ ] }) : null
2489
+ ] }) });
2490
+ };
2491
+ const config$1 = defineRouteConfig({
2492
+ label: "Refund details",
2493
+ icon: Receipt
2494
+ });
2462
2495
  const getStatusBadgeClass = (status) => {
2463
2496
  const statusLower = status.toLowerCase();
2464
2497
  if (statusLower === "requested") {
@@ -2755,14 +2788,14 @@ const routeModule = {
2755
2788
  Component: PaymentsPage,
2756
2789
  path: "/payments"
2757
2790
  },
2758
- {
2759
- Component: RefundsPage,
2760
- path: "/refunds"
2761
- },
2762
2791
  {
2763
2792
  Component: ReturnsPage,
2764
2793
  path: "/returns"
2765
2794
  },
2795
+ {
2796
+ Component: RefundsPage,
2797
+ path: "/refunds"
2798
+ },
2766
2799
  {
2767
2800
  Component: SwapsPage,
2768
2801
  path: "/swaps"
@@ -2771,14 +2804,14 @@ const routeModule = {
2771
2804
  Component: PaymentDetailPage,
2772
2805
  path: "/payments/:id"
2773
2806
  },
2774
- {
2775
- Component: RefundDetailPage,
2776
- path: "/refunds/:id"
2777
- },
2778
2807
  {
2779
2808
  Component: ReturnDetailPage,
2780
2809
  path: "/returns/:id"
2781
2810
  },
2811
+ {
2812
+ Component: RefundDetailPage,
2813
+ path: "/refunds/:id"
2814
+ },
2782
2815
  {
2783
2816
  Component: SwapDetailPage,
2784
2817
  path: "/swaps/:id"
@@ -2790,12 +2823,6 @@ const menuItemModule = {
2790
2823
  {
2791
2824
  label: config$6.label,
2792
2825
  icon: config$6.icon,
2793
- path: "/refunds",
2794
- nested: void 0
2795
- },
2796
- {
2797
- label: config$5.label,
2798
- icon: config$5.icon,
2799
2826
  path: "/returns",
2800
2827
  nested: void 0
2801
2828
  },
@@ -2812,14 +2839,14 @@ const menuItemModule = {
2812
2839
  nested: void 0
2813
2840
  },
2814
2841
  {
2815
- label: config$2.label,
2816
- icon: config$2.icon,
2817
- path: "/refunds/:id",
2842
+ label: config$5.label,
2843
+ icon: config$5.icon,
2844
+ path: "/refunds",
2818
2845
  nested: void 0
2819
2846
  },
2820
2847
  {
2821
- label: config$1.label,
2822
- icon: config$1.icon,
2848
+ label: config$2.label,
2849
+ icon: config$2.icon,
2823
2850
  path: "/returns/:id",
2824
2851
  nested: void 0
2825
2852
  },
@@ -2834,6 +2861,12 @@ const menuItemModule = {
2834
2861
  icon: config$3.icon,
2835
2862
  path: "/payments/:id",
2836
2863
  nested: void 0
2864
+ },
2865
+ {
2866
+ label: config$1.label,
2867
+ icon: config$1.icon,
2868
+ path: "/refunds/:id",
2869
+ nested: void 0
2837
2870
  }
2838
2871
  ]
2839
2872
  };