order-management 0.0.98 → 0.0.99

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.
@@ -2247,16 +2247,216 @@ const getStatusBadgeClass$7 = (status) => {
2247
2247
  if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
2248
2248
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
2249
2249
  };
2250
- const RefundsPage = () => {
2250
+ const PaymentsPage = () => {
2251
2251
  const navigate = reactRouterDom.useNavigate();
2252
2252
  const [items, setItems] = react.useState([]);
2253
+ const [statusFilter, setStatusFilter] = react.useState("all");
2253
2254
  const [orderIdSearch, setOrderIdSearch] = react.useState("");
2254
2255
  const debouncedOrderId = useDebounce$3(orderIdSearch, 300);
2256
+ const [isLoading, setIsLoading] = react.useState(true);
2257
+ const [isFetchingMore, setIsFetchingMore] = react.useState(false);
2258
+ const [error, setError] = react.useState(null);
2259
+ const [offset, setOffset] = react.useState(0);
2260
+ const [count, setCount] = react.useState(0);
2261
+ const limit = 50;
2262
+ const loadTransactions = react.useCallback(
2263
+ async (nextOffset, replace) => {
2264
+ try {
2265
+ if (replace) setIsLoading(true);
2266
+ else setIsFetchingMore(true);
2267
+ setError(null);
2268
+ const params = new URLSearchParams();
2269
+ params.set("limit", String(limit));
2270
+ params.set("offset", String(nextOffset));
2271
+ if (statusFilter !== "all") params.set("status", statusFilter);
2272
+ if (debouncedOrderId.trim()) params.set("order_id", debouncedOrderId.trim());
2273
+ const response = await fetch(
2274
+ `/admin/payment-transactions?${params.toString()}`,
2275
+ { credentials: "include" }
2276
+ );
2277
+ if (!response.ok) {
2278
+ const text = await response.text();
2279
+ throw new Error(text || "Failed to load payment transactions");
2280
+ }
2281
+ const payload = await response.json();
2282
+ const list = payload.transactions ?? [];
2283
+ setCount(payload.count ?? 0);
2284
+ setOffset(nextOffset + list.length);
2285
+ setItems((prev) => replace ? list : [...prev, ...list]);
2286
+ } catch (e) {
2287
+ setError(e instanceof Error ? e.message : "Failed to load");
2288
+ } finally {
2289
+ setIsLoading(false);
2290
+ setIsFetchingMore(false);
2291
+ }
2292
+ },
2293
+ [statusFilter, debouncedOrderId]
2294
+ );
2295
+ react.useEffect(() => {
2296
+ void loadTransactions(0, true);
2297
+ }, [loadTransactions]);
2298
+ const hasMore = react.useMemo(() => offset < count, [offset, count]);
2299
+ const displayStatus = (t) => {
2300
+ const s2 = t.payment_id != null && t.payment_status != null && t.payment_status !== "" ? t.payment_status : t.session_status ?? "";
2301
+ return s2 !== "" ? s2 : "—";
2302
+ };
2303
+ const displayAmount = (t) => {
2304
+ const code = (t.currency_code ?? "USD").toUpperCase();
2305
+ return `${code} ${Number(t.amount)}`;
2306
+ };
2307
+ 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: [
2308
+ /* @__PURE__ */ jsxRuntime.jsxs("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
2309
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
2310
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Payments" }),
2311
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "All payment attempts — completed, pending, failed, requires action" })
2312
+ ] }),
2313
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "primary", onClick: () => loadTransactions(0, true), children: "Refresh" })
2314
+ ] }),
2315
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
2316
+ /* @__PURE__ */ jsxRuntime.jsx(
2317
+ ui.Input,
2318
+ {
2319
+ placeholder: "Search by Order ID",
2320
+ value: orderIdSearch,
2321
+ onChange: (e) => setOrderIdSearch(e.target.value),
2322
+ className: "md:max-w-sm",
2323
+ "aria-label": "Search by order ID"
2324
+ }
2325
+ ),
2326
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs(
2327
+ "select",
2328
+ {
2329
+ value: statusFilter,
2330
+ onChange: (e) => setStatusFilter(e.target.value),
2331
+ 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",
2332
+ "aria-label": "Filter by status",
2333
+ children: [
2334
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "all", children: "All statuses" }),
2335
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "pending", children: "Pending" }),
2336
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "requires_more", children: "Requires more" }),
2337
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "error", children: "Error" }),
2338
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "canceled", children: "Canceled" }),
2339
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "authorized", children: "Authorized" }),
2340
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "captured", children: "Captured" })
2341
+ ]
2342
+ }
2343
+ ) })
2344
+ ] }),
2345
+ error ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
2346
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
2347
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", onClick: () => loadTransactions(0, true), children: "Try again" }) })
2348
+ ] }) : null,
2349
+ isLoading ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Loading payments…" }) }) : items.length === 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-dashed border-ui-border-strong p-10 text-center", children: [
2350
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h3", className: "text-xl", children: "No payment transactions yet" }),
2351
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "mt-2 text-ui-fg-subtle", children: "Payment attempts will appear here." })
2352
+ ] }) : /* @__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: [
2353
+ /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
2354
+ /* @__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" }),
2355
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Amount" }),
2356
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Provider" }),
2357
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Status" }),
2358
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Finalized" }),
2359
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Created" }),
2360
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Actions" })
2361
+ ] }) }),
2362
+ /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((t) => /* @__PURE__ */ jsxRuntime.jsxs(
2363
+ "tr",
2364
+ {
2365
+ className: "hover:bg-ui-bg-subtle/60 cursor-pointer",
2366
+ onClick: () => navigate(`/payments/${t.payment_session_id}`),
2367
+ children: [
2368
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: t.order_id ?? "—" }),
2369
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: displayAmount(t) }),
2370
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: t.provider_id }),
2371
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(
2372
+ ui.Badge,
2373
+ {
2374
+ size: "2xsmall",
2375
+ className: `uppercase ${getStatusBadgeClass$7(displayStatus(t))}`,
2376
+ children: displayStatus(t) !== "—" ? displayStatus(t).replace(/_/g, " ") : "—"
2377
+ }
2378
+ ) }),
2379
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: t.payment_id != null ? "Yes" : "No" }),
2380
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: new Date(t.created_at).toLocaleDateString("en-US", {
2381
+ year: "numeric",
2382
+ month: "short",
2383
+ day: "numeric",
2384
+ hour: "numeric",
2385
+ minute: "2-digit",
2386
+ hour12: true
2387
+ }) }),
2388
+ /* @__PURE__ */ jsxRuntime.jsxs("td", { className: "px-4 py-4", children: [
2389
+ /* @__PURE__ */ jsxRuntime.jsx(
2390
+ ui.Button,
2391
+ {
2392
+ variant: "transparent",
2393
+ size: "small",
2394
+ onClick: (e) => {
2395
+ e.stopPropagation();
2396
+ navigate(`/payments/${t.payment_session_id}`);
2397
+ },
2398
+ children: "View details"
2399
+ }
2400
+ ),
2401
+ t.order_id ? /* @__PURE__ */ jsxRuntime.jsx(
2402
+ ui.Button,
2403
+ {
2404
+ variant: "transparent",
2405
+ size: "small",
2406
+ onClick: (e) => {
2407
+ e.stopPropagation();
2408
+ navigate(`/orders/${t.order_id}`);
2409
+ },
2410
+ children: "Order"
2411
+ }
2412
+ ) : null
2413
+ ] })
2414
+ ]
2415
+ },
2416
+ t.payment_session_id
2417
+ )) })
2418
+ ] }) }),
2419
+ hasMore ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(
2420
+ ui.Button,
2421
+ {
2422
+ variant: "secondary",
2423
+ isLoading: isFetchingMore,
2424
+ onClick: () => loadTransactions(offset, false),
2425
+ children: "Load more"
2426
+ }
2427
+ ) }) : null
2428
+ ] }) });
2429
+ };
2430
+ const config$7 = adminSdk.defineRouteConfig({
2431
+ label: "Payments",
2432
+ icon: icons.CreditCard
2433
+ });
2434
+ const useDebounce$2 = (value, delay) => {
2435
+ const [debouncedValue, setDebouncedValue] = react.useState(value);
2436
+ react.useEffect(() => {
2437
+ const handler = setTimeout(() => setDebouncedValue(value), delay);
2438
+ return () => clearTimeout(handler);
2439
+ }, [value, delay]);
2440
+ return debouncedValue;
2441
+ };
2442
+ const getStatusBadgeClass$6 = (status) => {
2443
+ const s2 = status.toLowerCase();
2444
+ if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
2445
+ if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
2446
+ if (s2 === "error" || s2 === "canceled" || s2 === "cancelled") return "bg-ui-tag-red-bg text-ui-tag-red-text";
2447
+ if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
2448
+ return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
2449
+ };
2450
+ const RefundsPage = () => {
2451
+ const navigate = reactRouterDom.useNavigate();
2452
+ const [items, setItems] = react.useState([]);
2453
+ const [orderIdSearch, setOrderIdSearch] = react.useState("");
2454
+ const debouncedOrderId = useDebounce$2(orderIdSearch, 300);
2255
2455
  const [paymentStatusFilter, setPaymentStatusFilter] = react.useState("all");
2256
2456
  const [providerSearch, setProviderSearch] = react.useState("");
2257
- const debouncedProvider = useDebounce$3(providerSearch, 300);
2457
+ const debouncedProvider = useDebounce$2(providerSearch, 300);
2258
2458
  const [currencySearch, setCurrencySearch] = react.useState("");
2259
- const debouncedCurrency = useDebounce$3(currencySearch, 300);
2459
+ const debouncedCurrency = useDebounce$2(currencySearch, 300);
2260
2460
  const [dateFrom, setDateFrom] = react.useState("");
2261
2461
  const [dateTo, setDateTo] = react.useState("");
2262
2462
  const [amountMin, setAmountMin] = react.useState("");
@@ -2468,7 +2668,7 @@ const RefundsPage = () => {
2468
2668
  ui.Badge,
2469
2669
  {
2470
2670
  size: "2xsmall",
2471
- className: `uppercase ${getStatusBadgeClass$7(displayStatus(r))}`,
2671
+ className: `uppercase ${getStatusBadgeClass$6(displayStatus(r))}`,
2472
2672
  children: displayStatus(r) !== "—" ? displayStatus(r).replace(/_/g, " ") : "—"
2473
2673
  }
2474
2674
  ) }),
@@ -2522,11 +2722,11 @@ const RefundsPage = () => {
2522
2722
  ) }) : null
2523
2723
  ] }) });
2524
2724
  };
2525
- const config$7 = adminSdk.defineRouteConfig({
2725
+ const config$6 = adminSdk.defineRouteConfig({
2526
2726
  label: "Refunds",
2527
2727
  icon: icons.Receipt
2528
2728
  });
2529
- const useDebounce$2 = (value, delay) => {
2729
+ const useDebounce$1 = (value, delay) => {
2530
2730
  const [debouncedValue, setDebouncedValue] = react.useState(value);
2531
2731
  react.useEffect(() => {
2532
2732
  const handler = setTimeout(() => setDebouncedValue(value), delay);
@@ -2534,247 +2734,47 @@ const useDebounce$2 = (value, delay) => {
2534
2734
  }, [value, delay]);
2535
2735
  return debouncedValue;
2536
2736
  };
2537
- const getStatusBadgeClass$6 = (status) => {
2538
- const s2 = status.toLowerCase();
2539
- if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
2540
- if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
2541
- if (s2 === "error" || s2 === "canceled" || s2 === "cancelled") return "bg-ui-tag-red-bg text-ui-tag-red-text";
2542
- if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
2737
+ const getStatusBadgeClass$5 = (status) => {
2738
+ const statusLower = status.toLowerCase();
2739
+ if (statusLower === "requested") {
2740
+ return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
2741
+ }
2742
+ if (statusLower === "received") {
2743
+ return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
2744
+ }
2745
+ if (statusLower === "requires_action") {
2746
+ return "bg-ui-tag-red-bg text-ui-tag-red-text";
2747
+ }
2748
+ if (statusLower === "completed") {
2749
+ return "bg-ui-tag-green-bg text-ui-tag-green-text";
2750
+ }
2751
+ if (statusLower === "canceled") {
2752
+ return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
2753
+ }
2543
2754
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
2544
2755
  };
2545
- const PaymentsPage = () => {
2756
+ const ReturnsPage = () => {
2546
2757
  const navigate = reactRouterDom.useNavigate();
2547
2758
  const [items, setItems] = react.useState([]);
2548
2759
  const [statusFilter, setStatusFilter] = react.useState("all");
2549
- const [orderIdSearch, setOrderIdSearch] = react.useState("");
2550
- const debouncedOrderId = useDebounce$2(orderIdSearch, 300);
2760
+ const [createdByFilter, setCreatedByFilter] = react.useState("all");
2761
+ const [searchQuery, setSearchQuery] = react.useState("");
2762
+ const debouncedSearchQuery = useDebounce$1(searchQuery, 300);
2551
2763
  const [isLoading, setIsLoading] = react.useState(true);
2552
2764
  const [isFetchingMore, setIsFetchingMore] = react.useState(false);
2553
2765
  const [error, setError] = react.useState(null);
2554
2766
  const [offset, setOffset] = react.useState(0);
2555
2767
  const [count, setCount] = react.useState(0);
2556
2768
  const limit = 50;
2557
- const loadTransactions = react.useCallback(
2558
- async (nextOffset, replace) => {
2769
+ const loadReturns = react.useCallback(
2770
+ async (nextOffset, replace = false) => {
2771
+ var _a;
2559
2772
  try {
2560
- if (replace) setIsLoading(true);
2561
- else setIsFetchingMore(true);
2562
- setError(null);
2563
- const params = new URLSearchParams();
2564
- params.set("limit", String(limit));
2565
- params.set("offset", String(nextOffset));
2566
- if (statusFilter !== "all") params.set("status", statusFilter);
2567
- if (debouncedOrderId.trim()) params.set("order_id", debouncedOrderId.trim());
2568
- const response = await fetch(
2569
- `/admin/payment-transactions?${params.toString()}`,
2570
- { credentials: "include" }
2571
- );
2572
- if (!response.ok) {
2573
- const text = await response.text();
2574
- throw new Error(text || "Failed to load payment transactions");
2575
- }
2576
- const payload = await response.json();
2577
- const list = payload.transactions ?? [];
2578
- setCount(payload.count ?? 0);
2579
- setOffset(nextOffset + list.length);
2580
- setItems((prev) => replace ? list : [...prev, ...list]);
2581
- } catch (e) {
2582
- setError(e instanceof Error ? e.message : "Failed to load");
2583
- } finally {
2584
- setIsLoading(false);
2585
- setIsFetchingMore(false);
2586
- }
2587
- },
2588
- [statusFilter, debouncedOrderId]
2589
- );
2590
- react.useEffect(() => {
2591
- void loadTransactions(0, true);
2592
- }, [loadTransactions]);
2593
- const hasMore = react.useMemo(() => offset < count, [offset, count]);
2594
- const displayStatus = (t) => {
2595
- const s2 = t.payment_id != null && t.payment_status != null && t.payment_status !== "" ? t.payment_status : t.session_status ?? "";
2596
- return s2 !== "" ? s2 : "—";
2597
- };
2598
- const displayAmount = (t) => {
2599
- const code = (t.currency_code ?? "USD").toUpperCase();
2600
- return `${code} ${Number(t.amount)}`;
2601
- };
2602
- 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: [
2603
- /* @__PURE__ */ jsxRuntime.jsxs("header", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
2604
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
2605
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Payments" }),
2606
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "All payment attempts — completed, pending, failed, requires action" })
2607
- ] }),
2608
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "primary", onClick: () => loadTransactions(0, true), children: "Refresh" })
2609
- ] }),
2610
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [
2611
- /* @__PURE__ */ jsxRuntime.jsx(
2612
- ui.Input,
2613
- {
2614
- placeholder: "Search by Order ID",
2615
- value: orderIdSearch,
2616
- onChange: (e) => setOrderIdSearch(e.target.value),
2617
- className: "md:max-w-sm",
2618
- "aria-label": "Search by order ID"
2619
- }
2620
- ),
2621
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs(
2622
- "select",
2623
- {
2624
- value: statusFilter,
2625
- onChange: (e) => setStatusFilter(e.target.value),
2626
- 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",
2627
- "aria-label": "Filter by status",
2628
- children: [
2629
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "all", children: "All statuses" }),
2630
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "pending", children: "Pending" }),
2631
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "requires_more", children: "Requires more" }),
2632
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "error", children: "Error" }),
2633
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "canceled", children: "Canceled" }),
2634
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "authorized", children: "Authorized" }),
2635
- /* @__PURE__ */ jsxRuntime.jsx("option", { value: "captured", children: "Captured" })
2636
- ]
2637
- }
2638
- ) })
2639
- ] }),
2640
- error ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
2641
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
2642
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-4 flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", onClick: () => loadTransactions(0, true), children: "Try again" }) })
2643
- ] }) : null,
2644
- isLoading ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center py-16", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Loading payments…" }) }) : items.length === 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-dashed border-ui-border-strong p-10 text-center", children: [
2645
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h3", className: "text-xl", children: "No payment transactions yet" }),
2646
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "mt-2 text-ui-fg-subtle", children: "Payment attempts will appear here." })
2647
- ] }) : /* @__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: [
2648
- /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
2649
- /* @__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" }),
2650
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Amount" }),
2651
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Provider" }),
2652
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Status" }),
2653
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Finalized" }),
2654
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Created" }),
2655
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Actions" })
2656
- ] }) }),
2657
- /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: items.map((t) => /* @__PURE__ */ jsxRuntime.jsxs(
2658
- "tr",
2659
- {
2660
- className: "hover:bg-ui-bg-subtle/60 cursor-pointer",
2661
- onClick: () => navigate(`/payments/${t.payment_session_id}`),
2662
- children: [
2663
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: t.order_id ?? "—" }),
2664
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: displayAmount(t) }),
2665
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: t.provider_id }),
2666
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(
2667
- ui.Badge,
2668
- {
2669
- size: "2xsmall",
2670
- className: `uppercase ${getStatusBadgeClass$6(displayStatus(t))}`,
2671
- children: displayStatus(t) !== "—" ? displayStatus(t).replace(/_/g, " ") : "—"
2672
- }
2673
- ) }),
2674
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: t.payment_id != null ? "Yes" : "No" }),
2675
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: new Date(t.created_at).toLocaleDateString("en-US", {
2676
- year: "numeric",
2677
- month: "short",
2678
- day: "numeric",
2679
- hour: "numeric",
2680
- minute: "2-digit",
2681
- hour12: true
2682
- }) }),
2683
- /* @__PURE__ */ jsxRuntime.jsxs("td", { className: "px-4 py-4", children: [
2684
- /* @__PURE__ */ jsxRuntime.jsx(
2685
- ui.Button,
2686
- {
2687
- variant: "transparent",
2688
- size: "small",
2689
- onClick: (e) => {
2690
- e.stopPropagation();
2691
- navigate(`/payments/${t.payment_session_id}`);
2692
- },
2693
- children: "View details"
2694
- }
2695
- ),
2696
- t.order_id ? /* @__PURE__ */ jsxRuntime.jsx(
2697
- ui.Button,
2698
- {
2699
- variant: "transparent",
2700
- size: "small",
2701
- onClick: (e) => {
2702
- e.stopPropagation();
2703
- navigate(`/orders/${t.order_id}`);
2704
- },
2705
- children: "Order"
2706
- }
2707
- ) : null
2708
- ] })
2709
- ]
2710
- },
2711
- t.payment_session_id
2712
- )) })
2713
- ] }) }),
2714
- hasMore ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(
2715
- ui.Button,
2716
- {
2717
- variant: "secondary",
2718
- isLoading: isFetchingMore,
2719
- onClick: () => loadTransactions(offset, false),
2720
- children: "Load more"
2721
- }
2722
- ) }) : null
2723
- ] }) });
2724
- };
2725
- const config$6 = adminSdk.defineRouteConfig({
2726
- label: "Payments",
2727
- icon: icons.CreditCard
2728
- });
2729
- const useDebounce$1 = (value, delay) => {
2730
- const [debouncedValue, setDebouncedValue] = react.useState(value);
2731
- react.useEffect(() => {
2732
- const handler = setTimeout(() => setDebouncedValue(value), delay);
2733
- return () => clearTimeout(handler);
2734
- }, [value, delay]);
2735
- return debouncedValue;
2736
- };
2737
- const getStatusBadgeClass$5 = (status) => {
2738
- const statusLower = status.toLowerCase();
2739
- if (statusLower === "requested") {
2740
- return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
2741
- }
2742
- if (statusLower === "received") {
2743
- return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
2744
- }
2745
- if (statusLower === "requires_action") {
2746
- return "bg-ui-tag-red-bg text-ui-tag-red-text";
2747
- }
2748
- if (statusLower === "completed") {
2749
- return "bg-ui-tag-green-bg text-ui-tag-green-text";
2750
- }
2751
- if (statusLower === "canceled") {
2752
- return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
2753
- }
2754
- return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
2755
- };
2756
- const ReturnsPage = () => {
2757
- const navigate = reactRouterDom.useNavigate();
2758
- const [items, setItems] = react.useState([]);
2759
- const [statusFilter, setStatusFilter] = react.useState("all");
2760
- const [createdByFilter, setCreatedByFilter] = react.useState("all");
2761
- const [searchQuery, setSearchQuery] = react.useState("");
2762
- const debouncedSearchQuery = useDebounce$1(searchQuery, 300);
2763
- const [isLoading, setIsLoading] = react.useState(true);
2764
- const [isFetchingMore, setIsFetchingMore] = react.useState(false);
2765
- const [error, setError] = react.useState(null);
2766
- const [offset, setOffset] = react.useState(0);
2767
- const [count, setCount] = react.useState(0);
2768
- const limit = 50;
2769
- const loadReturns = react.useCallback(
2770
- async (nextOffset, replace = false) => {
2771
- var _a;
2772
- try {
2773
- if (replace) {
2774
- setIsLoading(true);
2775
- } else {
2776
- setIsFetchingMore(true);
2777
- }
2773
+ if (replace) {
2774
+ setIsLoading(true);
2775
+ } else {
2776
+ setIsFetchingMore(true);
2777
+ }
2778
2778
  setError(null);
2779
2779
  const params = new URLSearchParams();
2780
2780
  params.set("limit", String(limit));
@@ -3950,18 +3950,14 @@ const getStatusBadgeClass$3 = (status) => {
3950
3950
  if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
3951
3951
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
3952
3952
  };
3953
- const formatAmount = (value) => {
3954
- return String(value);
3955
- };
3956
- const RefundDetailPage = () => {
3957
- var _a, _b, _c;
3953
+ const PaymentDetailPage = () => {
3954
+ var _a;
3958
3955
  const navigate = reactRouterDom.useNavigate();
3959
3956
  const params = reactRouterDom.useParams();
3960
3957
  const id = (_a = params == null ? void 0 : params.id) == null ? void 0 : _a.trim();
3961
3958
  const [detail, setDetail] = react.useState(null);
3962
3959
  const [loading, setLoading] = react.useState(!!id);
3963
3960
  const [error, setError] = react.useState(null);
3964
- const [gatewayExpanded, setGatewayExpanded] = react.useState(false);
3965
3961
  react.useEffect(() => {
3966
3962
  if (!id) {
3967
3963
  setLoading(false);
@@ -3970,7 +3966,7 @@ const RefundDetailPage = () => {
3970
3966
  let cancelled = false;
3971
3967
  setLoading(true);
3972
3968
  setError(null);
3973
- fetch(`/admin/refunds/${id}`, { credentials: "include" }).then((res) => {
3969
+ fetch(`/admin/payment-transactions/${id}`, { credentials: "include" }).then((res) => {
3974
3970
  if (!res.ok) throw new Error(res.statusText || "Failed to load");
3975
3971
  return res.json();
3976
3972
  }).then((data) => {
@@ -3984,207 +3980,19 @@ const RefundDetailPage = () => {
3984
3980
  cancelled = true;
3985
3981
  };
3986
3982
  }, [id]);
3987
- const paymentStatus = ((_b = detail == null ? void 0 : detail.payment) == null ? void 0 : _b.status) ?? "—";
3988
- 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;
3983
+ const displayStatus = detail ? (detail.payment_id != null && detail.payment_status != null && detail.payment_status !== "" ? detail.payment_status : detail.session_status ?? "") || "—" : "";
3984
+ const sessionStatusRaw = (detail == null ? void 0 : detail.session_status) ?? "—";
3985
+ const paymentStatusRaw = (detail == null ? void 0 : detail.payment_id) != null ? (detail == null ? void 0 : detail.payment_status) ?? "—" : "—";
3986
+ const displayAmount = detail ? `${(detail.currency_code ?? "USD").toUpperCase()} ${Number(detail.amount)}` : "";
3989
3987
  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: [
3990
3988
  /* @__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: [
3991
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "transparent", size: "small", onClick: () => navigate("/refunds"), children: "← Refunds" }),
3992
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Refund details" }),
3993
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle font-mono", children: id ?? "—" })
3989
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "transparent", size: "small", onClick: () => navigate("/payments"), children: "← Payments" }),
3990
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Payment session" }),
3991
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: id ?? "—" })
3994
3992
  ] }) }),
3995
3993
  error ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
3996
3994
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
3997
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", className: "mt-4", onClick: () => navigate("/refunds"), children: "Back to list" })
3998
- ] }) : 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: [
3999
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
4000
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "text-lg mb-4", children: "Refund summary" }),
4001
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
4002
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4003
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Refund ID" }),
4004
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block font-mono text-sm", children: detail.refund.id })
4005
- ] }),
4006
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4007
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Amount" }),
4008
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.refund.amount) })
4009
- ] }),
4010
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4011
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Note" }),
4012
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.refund.note ?? "—" })
4013
- ] }),
4014
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4015
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Created at" }),
4016
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: new Date(detail.refund.created_at).toLocaleDateString("en-US", {
4017
- year: "numeric",
4018
- month: "short",
4019
- day: "numeric",
4020
- hour: "numeric",
4021
- minute: "2-digit",
4022
- hour12: true
4023
- }) })
4024
- ] }),
4025
- detail.refund.created_by ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4026
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Created by" }),
4027
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block font-mono text-sm", children: detail.refund.created_by })
4028
- ] }) : null
4029
- ] })
4030
- ] }),
4031
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
4032
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "text-lg mb-4", children: "Payment summary" }),
4033
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
4034
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4035
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Payment amount" }),
4036
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.payment.payment_amount) })
4037
- ] }),
4038
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4039
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Captured amount" }),
4040
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.payment.captured_amount) })
4041
- ] }),
4042
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4043
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Refunded amount" }),
4044
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.payment.refunded_amount) })
4045
- ] }),
4046
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4047
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Provider" }),
4048
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.payment.provider_id || "—" })
4049
- ] }),
4050
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4051
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Status" }),
4052
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsxRuntime.jsx(
4053
- ui.Badge,
4054
- {
4055
- size: "2xsmall",
4056
- className: `uppercase ${getStatusBadgeClass$3(paymentStatus)}`,
4057
- children: paymentStatus !== "—" ? paymentStatus.replace(/_/g, " ") : "—"
4058
- }
4059
- ) })
4060
- ] }),
4061
- detail.computed ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
4062
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4063
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Full refund" }),
4064
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.computed.is_full_refund ? "Yes" : "No" })
4065
- ] }),
4066
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4067
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Remaining refundable" }),
4068
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.computed.remaining_refundable_amount) })
4069
- ] }),
4070
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4071
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Refund %" }),
4072
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { className: "mt-1 block", children: [
4073
- detail.computed.refund_percentage.toFixed(1),
4074
- "%"
4075
- ] })
4076
- ] })
4077
- ] }) : null
4078
- ] })
4079
- ] }),
4080
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
4081
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "text-lg mb-4", children: "Order summary" }),
4082
- detail.order ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
4083
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4084
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Order" }),
4085
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsxRuntime.jsx(
4086
- ui.Button,
4087
- {
4088
- variant: "transparent",
4089
- size: "small",
4090
- onClick: () => navigate(`/orders/${detail.order.order_id}`),
4091
- children: detail.order.order_number ?? detail.order.order_id
4092
- }
4093
- ) })
4094
- ] }),
4095
- detail.order.total != null ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4096
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Total" }),
4097
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.order.total) })
4098
- ] }) : null,
4099
- detail.order.customer_id ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4100
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Customer ID" }),
4101
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block font-mono text-sm", children: detail.order.customer_id })
4102
- ] }) : null,
4103
- detail.order.region ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4104
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Region" }),
4105
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.order.region })
4106
- ] }) : null,
4107
- detail.order.fulfillment_status ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4108
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Fulfillment status" }),
4109
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.order.fulfillment_status })
4110
- ] }) : null
4111
- ] }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "No order linked to this refund." })
4112
- ] }),
4113
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
4114
- /* @__PURE__ */ jsxRuntime.jsxs(
4115
- "button",
4116
- {
4117
- type: "button",
4118
- className: "flex w-full items-center justify-between text-left",
4119
- onClick: () => setGatewayExpanded((prev) => !prev),
4120
- "aria-expanded": gatewayExpanded,
4121
- "aria-label": gatewayExpanded ? "Collapse gateway data" : "Expand gateway data",
4122
- children: [
4123
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "text-lg", children: "Gateway data" }),
4124
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: gatewayExpanded ? "Collapse" : "Expand" })
4125
- ]
4126
- }
4127
- ),
4128
- 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." }) })
4129
- ] })
4130
- ] }) : null
4131
- ] }) });
4132
- };
4133
- const config$3 = adminSdk.defineRouteConfig({
4134
- label: "Refund details",
4135
- icon: icons.Receipt
4136
- });
4137
- const getStatusBadgeClass$2 = (status) => {
4138
- const s2 = status.toLowerCase();
4139
- if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
4140
- if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
4141
- if (s2 === "error" || s2 === "canceled" || s2 === "cancelled") return "bg-ui-tag-red-bg text-ui-tag-red-text";
4142
- if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
4143
- return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
4144
- };
4145
- const PaymentDetailPage = () => {
4146
- var _a;
4147
- const navigate = reactRouterDom.useNavigate();
4148
- const params = reactRouterDom.useParams();
4149
- const id = (_a = params == null ? void 0 : params.id) == null ? void 0 : _a.trim();
4150
- const [detail, setDetail] = react.useState(null);
4151
- const [loading, setLoading] = react.useState(!!id);
4152
- const [error, setError] = react.useState(null);
4153
- react.useEffect(() => {
4154
- if (!id) {
4155
- setLoading(false);
4156
- return;
4157
- }
4158
- let cancelled = false;
4159
- setLoading(true);
4160
- setError(null);
4161
- fetch(`/admin/payment-transactions/${id}`, { credentials: "include" }).then((res) => {
4162
- if (!res.ok) throw new Error(res.statusText || "Failed to load");
4163
- return res.json();
4164
- }).then((data) => {
4165
- if (!cancelled) setDetail(data);
4166
- }).catch((e) => {
4167
- if (!cancelled) setError(e instanceof Error ? e.message : "Failed to load");
4168
- }).finally(() => {
4169
- if (!cancelled) setLoading(false);
4170
- });
4171
- return () => {
4172
- cancelled = true;
4173
- };
4174
- }, [id]);
4175
- const displayStatus = detail ? (detail.payment_id != null && detail.payment_status != null && detail.payment_status !== "" ? detail.payment_status : detail.session_status ?? "") || "—" : "";
4176
- const sessionStatusRaw = (detail == null ? void 0 : detail.session_status) ?? "—";
4177
- const paymentStatusRaw = (detail == null ? void 0 : detail.payment_id) != null ? (detail == null ? void 0 : detail.payment_status) ?? "—" : "—";
4178
- const displayAmount = detail ? `${(detail.currency_code ?? "USD").toUpperCase()} ${Number(detail.amount)}` : "";
4179
- 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: [
4180
- /* @__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: [
4181
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "transparent", size: "small", onClick: () => navigate("/payments"), children: "← Payments" }),
4182
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Payment session" }),
4183
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: id ?? "—" })
4184
- ] }) }),
4185
- error ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
4186
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
4187
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", className: "mt-4", onClick: () => navigate("/payments"), children: "Back to list" })
3995
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", className: "mt-4", onClick: () => navigate("/payments"), children: "Back to list" })
4188
3996
  ] }) : 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: [
4189
3997
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-xl border border-ui-border-base p-6 flex flex-col gap-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
4190
3998
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
@@ -4213,7 +4021,7 @@ const PaymentDetailPage = () => {
4213
4021
  ui.Badge,
4214
4022
  {
4215
4023
  size: "2xsmall",
4216
- className: `uppercase ${getStatusBadgeClass$2(displayStatus)}`,
4024
+ className: `uppercase ${getStatusBadgeClass$3(displayStatus)}`,
4217
4025
  children: displayStatus !== "—" ? displayStatus.replace(/_/g, " ") : "—"
4218
4026
  }
4219
4027
  ) })
@@ -4249,11 +4057,11 @@ const PaymentDetailPage = () => {
4249
4057
  ] }) : null
4250
4058
  ] }) });
4251
4059
  };
4252
- const config$2 = adminSdk.defineRouteConfig({
4060
+ const config$3 = adminSdk.defineRouteConfig({
4253
4061
  label: "Payment details",
4254
4062
  icon: icons.CreditCard
4255
4063
  });
4256
- const getStatusBadgeClass$1 = (status) => {
4064
+ const getStatusBadgeClass$2 = (status) => {
4257
4065
  const statusLower = status.toLowerCase();
4258
4066
  if (statusLower === "requested") {
4259
4067
  return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
@@ -4264,109 +4072,105 @@ const getStatusBadgeClass$1 = (status) => {
4264
4072
  if (statusLower === "rejected") {
4265
4073
  return "bg-ui-tag-red-bg text-ui-tag-red-text";
4266
4074
  }
4075
+ if (statusLower === "received") {
4076
+ return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
4077
+ }
4078
+ if (statusLower === "refunded") {
4079
+ return "bg-ui-tag-green-bg text-ui-tag-green-text";
4080
+ }
4267
4081
  if (statusLower === "completed") {
4268
4082
  return "bg-ui-tag-green-bg text-ui-tag-green-text";
4269
4083
  }
4270
- if (statusLower === "cancelled" || statusLower === "canceled") {
4084
+ if (statusLower === "cancelled") {
4271
4085
  return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
4272
4086
  }
4273
- if (statusLower === "pending") {
4274
- return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
4275
- }
4276
4087
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
4277
4088
  };
4278
- const SwapDetailPage = () => {
4089
+ const ReturnDetailPage = () => {
4279
4090
  var _a, _b, _c;
4280
4091
  const navigate = reactRouterDom.useNavigate();
4281
4092
  const { id } = reactRouterDom.useParams();
4282
- const [swap, setSwap] = react.useState(null);
4283
- const [order, setOrder] = react.useState(null);
4093
+ const [returnOrder, setReturnOrder] = react.useState(null);
4284
4094
  const [isLoading, setIsLoading] = react.useState(true);
4285
- react.useState(false);
4286
- const [isCancelling, setIsCancelling] = react.useState(false);
4095
+ const [isRejecting, setIsRejecting] = react.useState(false);
4287
4096
  const [error, setError] = react.useState(null);
4288
4097
  const [updateError, setUpdateError] = react.useState(null);
4289
4098
  const [updateSuccess, setUpdateSuccess] = react.useState(false);
4290
4099
  react.useEffect(() => {
4291
4100
  if (!id) {
4292
- navigate("/swaps");
4101
+ navigate("/returns");
4293
4102
  return;
4294
4103
  }
4295
- const loadSwap = async () => {
4104
+ const loadReturn = async () => {
4296
4105
  try {
4297
4106
  setIsLoading(true);
4298
4107
  setError(null);
4299
- const response = await fetch(`/admin/swaps/${id}`, {
4108
+ const response = await fetch(`/admin/return/${id}`, {
4300
4109
  credentials: "include"
4301
4110
  });
4302
4111
  if (!response.ok) {
4303
4112
  const message = await response.text();
4304
- throw new Error(message || "Unable to load swap");
4113
+ throw new Error(message || "Unable to load return order");
4305
4114
  }
4306
4115
  const payload = await response.json();
4307
- setSwap(payload.swap);
4308
- setOrder(payload.order || null);
4116
+ setReturnOrder(payload.return);
4309
4117
  } catch (loadError) {
4310
- const message = loadError instanceof Error ? loadError.message : "Unable to load swap";
4118
+ const message = loadError instanceof Error ? loadError.message : "Unable to load return order";
4311
4119
  setError(message);
4312
4120
  } finally {
4313
4121
  setIsLoading(false);
4314
4122
  }
4315
4123
  };
4316
- void loadSwap();
4124
+ void loadReturn();
4317
4125
  }, [id, navigate]);
4318
- const handleCancelExchange = async () => {
4126
+ const handleReject = async () => {
4319
4127
  if (!id) {
4320
4128
  return;
4321
4129
  }
4322
4130
  try {
4323
- setIsCancelling(true);
4131
+ setIsRejecting(true);
4324
4132
  setUpdateError(null);
4325
4133
  setUpdateSuccess(false);
4326
- const response = await fetch(`/admin/swaps/${id}/cancel`, {
4134
+ const response = await fetch(`/admin/return/${id}/reject`, {
4327
4135
  method: "POST",
4328
4136
  headers: {
4329
4137
  "Content-Type": "application/json"
4330
4138
  },
4331
- credentials: "include"
4139
+ credentials: "include",
4140
+ body: JSON.stringify({ reason: "Rejected by admin" })
4332
4141
  });
4333
4142
  if (!response.ok) {
4334
4143
  const message = await response.text();
4335
- throw new Error(message || "Unable to cancel exchange");
4144
+ throw new Error(message || "Unable to reject return");
4336
4145
  }
4337
4146
  const payload = await response.json();
4338
- setSwap(payload.swap);
4147
+ setReturnOrder(payload.return);
4339
4148
  setUpdateSuccess(true);
4340
4149
  setTimeout(() => setUpdateSuccess(false), 3e3);
4341
- const detailResponse = await fetch(`/admin/swaps/${id}`, {
4150
+ const detailResponse = await fetch(`/admin/return/${id}`, {
4342
4151
  credentials: "include"
4343
4152
  });
4344
4153
  if (detailResponse.ok) {
4345
4154
  const detailPayload = await detailResponse.json();
4346
- setSwap(detailPayload.swap);
4347
- setOrder(detailPayload.order || null);
4155
+ setReturnOrder(detailPayload.return);
4348
4156
  }
4349
- } catch (cancelErr) {
4350
- const message = cancelErr instanceof Error ? cancelErr.message : "Unable to cancel exchange";
4157
+ } catch (updateErr) {
4158
+ const message = updateErr instanceof Error ? updateErr.message : "Unable to reject return";
4351
4159
  setUpdateError(message);
4352
4160
  } finally {
4353
- setIsCancelling(false);
4161
+ setIsRejecting(false);
4354
4162
  }
4355
4163
  };
4356
- const isOrderExchange = Boolean(swap == null ? void 0 : swap.exchange_id);
4357
- const canCancelExchange = isOrderExchange && swap && !["cancelled", "canceled", "completed", "declined"].includes(
4358
- ((_a = swap.status) == null ? void 0 : _a.toLowerCase()) ?? ""
4359
- );
4360
4164
  if (isLoading) {
4361
- 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..." }) }) }) });
4165
+ 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..." }) }) }) });
4362
4166
  }
4363
- if (error || !swap) {
4167
+ if (error || !returnOrder) {
4364
4168
  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: [
4365
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error || "Swap not found" }),
4366
- /* @__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" }) })
4169
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error || "Return order not found" }),
4170
+ /* @__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" }) })
4367
4171
  ] }) }) });
4368
4172
  }
4369
- const statusHistory = ((_b = swap.metadata) == null ? void 0 : _b.status_history) || [];
4173
+ const statusHistory = ((_a = returnOrder.metadata) == null ? void 0 : _a.status_history) || [];
4370
4174
  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: [
4371
4175
  /* @__PURE__ */ jsxRuntime.jsxs("header", { className: "flex flex-col gap-3", children: [
4372
4176
  /* @__PURE__ */ jsxRuntime.jsxs(
@@ -4374,7 +4178,7 @@ const SwapDetailPage = () => {
4374
4178
  {
4375
4179
  variant: "transparent",
4376
4180
  size: "small",
4377
- onClick: () => navigate("/swaps"),
4181
+ onClick: () => navigate("/returns"),
4378
4182
  className: "w-fit",
4379
4183
  children: [
4380
4184
  /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowLeft, { className: "mr-2" }),
@@ -4384,67 +4188,82 @@ const SwapDetailPage = () => {
4384
4188
  ),
4385
4189
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1 md:flex-row md:items-center md:justify-between", children: [
4386
4190
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
4387
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Exchange Details" }),
4388
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: swap.id })
4191
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Return Order Details" }),
4192
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: returnOrder.id })
4389
4193
  ] }),
4390
4194
  /* @__PURE__ */ jsxRuntime.jsx(
4391
4195
  ui.Badge,
4392
4196
  {
4393
4197
  size: "small",
4394
- className: `uppercase ${getStatusBadgeClass$1(swap.status)}`,
4395
- children: swap.status.replace(/_/g, " ")
4198
+ className: `uppercase ${getStatusBadgeClass$2(returnOrder.status)}`,
4199
+ children: returnOrder.status.replace(/_/g, " ")
4396
4200
  }
4397
4201
  )
4398
4202
  ] })
4399
4203
  ] }),
4400
- canCancelExchange && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
4204
+ returnOrder.status === "requested" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
4401
4205
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex gap-3", children: /* @__PURE__ */ jsxRuntime.jsx(
4402
4206
  ui.Button,
4403
4207
  {
4404
4208
  variant: "danger",
4405
- onClick: handleCancelExchange,
4406
- disabled: isCancelling,
4407
- isLoading: isCancelling,
4408
- children: "Cancel Exchange"
4409
- }
4410
- ) }),
4411
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This will cancel the exchange request. The order will remain unchanged." })
4209
+ onClick: handleReject,
4210
+ disabled: isRejecting,
4211
+ isLoading: isRejecting,
4212
+ children: "Reject (Cancel) Return"
4213
+ }
4214
+ ) }),
4215
+ /* @__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.' })
4216
+ ] }),
4217
+ returnOrder.refund ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: /* @__PURE__ */ jsxRuntime.jsx(RefundCalculationBlock, { refund: returnOrder.refund }) }) : null,
4218
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
4219
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Information" }),
4220
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
4221
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4222
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Return ID" }),
4223
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.id })
4224
+ ] }),
4225
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(
4226
+ ui.Button,
4227
+ {
4228
+ variant: "secondary",
4229
+ onClick: () => {
4230
+ window.open(
4231
+ `/app/orders/${returnOrder.order_id}`,
4232
+ "_blank"
4233
+ );
4234
+ },
4235
+ children: "View order"
4236
+ }
4237
+ ) })
4238
+ ] })
4412
4239
  ] }),
4413
4240
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid gap-6 md:grid-cols-2", children: [
4414
4241
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
4415
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Exchange Information" }),
4242
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Details" }),
4416
4243
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
4417
4244
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4418
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Exchange ID" }),
4419
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.id })
4245
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Return ID" }),
4246
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.id })
4420
4247
  ] }),
4421
4248
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4422
4249
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Status" }),
4423
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.status })
4424
- ] }),
4425
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4426
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Difference Due" }),
4427
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.difference_due != null ? `${swap.currency_code || "$"}${(Number(swap.difference_due) / 100).toFixed(2)}` : "—" })
4250
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.status })
4428
4251
  ] }),
4429
- swap.reason && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4252
+ returnOrder.reason && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4430
4253
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Reason" }),
4431
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.reason })
4254
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.reason })
4432
4255
  ] }),
4433
- swap.note && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4256
+ returnOrder.note && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4434
4257
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Note" }),
4435
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.note })
4258
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.note })
4436
4259
  ] }),
4437
4260
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4438
4261
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Created" }),
4439
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: new Date(swap.created_at).toLocaleString() })
4262
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: new Date(returnOrder.created_at).toLocaleString() })
4440
4263
  ] }),
4441
4264
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4442
4265
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Last Updated" }),
4443
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: new Date(swap.updated_at).toLocaleString() })
4444
- ] }),
4445
- swap.exchange_id && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4446
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Exchange ID" }),
4447
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.exchange_id })
4266
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: new Date(returnOrder.updated_at).toLocaleString() })
4448
4267
  ] })
4449
4268
  ] })
4450
4269
  ] }),
@@ -4459,7 +4278,7 @@ const SwapDetailPage = () => {
4459
4278
  ui.Badge,
4460
4279
  {
4461
4280
  size: "2xsmall",
4462
- className: `uppercase ${getStatusBadgeClass$1(entry.status)}`,
4281
+ className: `uppercase ${getStatusBadgeClass$2(entry.status)}`,
4463
4282
  children: entry.status.replace(/_/g, " ")
4464
4283
  }
4465
4284
  ) }),
@@ -4474,31 +4293,35 @@ const SwapDetailPage = () => {
4474
4293
  )) }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "No status history available" })
4475
4294
  ] })
4476
4295
  ] }),
4477
- order && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
4296
+ returnOrder.order && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
4478
4297
  /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Related Order Information" }),
4479
4298
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
4480
4299
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4481
4300
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Order ID" }),
4482
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: order.id })
4301
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.order.id })
4483
4302
  ] }),
4484
4303
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4485
4304
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Status" }),
4486
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: order.status || "—" })
4305
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.order.status || "—" })
4487
4306
  ] }),
4488
4307
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4489
4308
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Customer" }),
4490
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: ((_c = order.customer) == null ? void 0 : _c.email) || order.email || "—" })
4309
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: ((_b = returnOrder.order.customer) == null ? void 0 : _b.email) || returnOrder.order.email || "—" })
4491
4310
  ] }),
4492
- order.total && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4311
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4312
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Payment method" }),
4313
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: ((_c = returnOrder.order.order_payment) == null ? void 0 : _c.label) || "—" })
4314
+ ] }),
4315
+ returnOrder.order.total && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4493
4316
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Total" }),
4494
4317
  /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { className: "font-medium", children: [
4495
- order.currency_code || "$",
4496
- (Number(order.total) / 100).toFixed(2)
4318
+ returnOrder.order.currency_code || "$",
4319
+ (Number(returnOrder.order.total) / 100).toFixed(2)
4497
4320
  ] })
4498
4321
  ] })
4499
4322
  ] })
4500
4323
  ] }),
4501
- 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: [
4324
+ 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: [
4502
4325
  /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Items" }),
4503
4326
  /* @__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: [
4504
4327
  /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
@@ -4506,31 +4329,212 @@ const SwapDetailPage = () => {
4506
4329
  /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Quantity" }),
4507
4330
  /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Reason" })
4508
4331
  ] }) }),
4509
- /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: swap.return_items.map((item, index) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
4332
+ /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: returnOrder.return_items.map((item, index) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
4510
4333
  /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: item.id }),
4511
4334
  /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity }),
4512
4335
  /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.reason || "—" })
4513
4336
  ] }, item.id || index)) })
4514
4337
  ] }) })
4515
4338
  ] }),
4516
- 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: [
4517
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "New Items" }),
4518
- /* @__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: [
4519
- /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
4520
- /* @__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" }),
4521
- /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Quantity" })
4522
- ] }) }),
4523
- /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: swap.new_items.map((item, index) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
4524
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: item.variant_id }),
4525
- /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity })
4526
- ] }, item.variant_id || index)) })
4527
- ] }) })
4528
- ] })
4339
+ 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 }) }),
4340
+ 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" }) })
4341
+ ] }) });
4342
+ };
4343
+ const config$2 = adminSdk.defineRouteConfig({
4344
+ label: "Return Order Details",
4345
+ icon: icons.CheckCircle
4346
+ });
4347
+ const getStatusBadgeClass$1 = (status) => {
4348
+ const s2 = status.toLowerCase();
4349
+ if (s2 === "captured" || s2 === "completed") return "bg-ui-tag-green-bg text-ui-tag-green-text";
4350
+ if (s2 === "authorized") return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
4351
+ if (s2 === "error" || s2 === "canceled" || s2 === "cancelled") return "bg-ui-tag-red-bg text-ui-tag-red-text";
4352
+ if (s2 === "pending" || s2 === "requires_more") return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
4353
+ return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
4354
+ };
4355
+ const formatAmount = (value) => {
4356
+ return String(value);
4357
+ };
4358
+ const RefundDetailPage = () => {
4359
+ var _a, _b, _c;
4360
+ const navigate = reactRouterDom.useNavigate();
4361
+ const params = reactRouterDom.useParams();
4362
+ const id = (_a = params == null ? void 0 : params.id) == null ? void 0 : _a.trim();
4363
+ const [detail, setDetail] = react.useState(null);
4364
+ const [loading, setLoading] = react.useState(!!id);
4365
+ const [error, setError] = react.useState(null);
4366
+ const [gatewayExpanded, setGatewayExpanded] = react.useState(false);
4367
+ react.useEffect(() => {
4368
+ if (!id) {
4369
+ setLoading(false);
4370
+ return;
4371
+ }
4372
+ let cancelled = false;
4373
+ setLoading(true);
4374
+ setError(null);
4375
+ fetch(`/admin/refunds/${id}`, { credentials: "include" }).then((res) => {
4376
+ if (!res.ok) throw new Error(res.statusText || "Failed to load");
4377
+ return res.json();
4378
+ }).then((data) => {
4379
+ if (!cancelled) setDetail(data);
4380
+ }).catch((e) => {
4381
+ if (!cancelled) setError(e instanceof Error ? e.message : "Failed to load");
4382
+ }).finally(() => {
4383
+ if (!cancelled) setLoading(false);
4384
+ });
4385
+ return () => {
4386
+ cancelled = true;
4387
+ };
4388
+ }, [id]);
4389
+ const paymentStatus = ((_b = detail == null ? void 0 : detail.payment) == null ? void 0 : _b.status) ?? "—";
4390
+ 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;
4391
+ 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: [
4392
+ /* @__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: [
4393
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "transparent", size: "small", onClick: () => navigate("/refunds"), children: "← Refunds" }),
4394
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Refund details" }),
4395
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle font-mono", children: id ?? "—" })
4396
+ ] }) }),
4397
+ error ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-strong p-6 text-center", children: [
4398
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error }),
4399
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", className: "mt-4", onClick: () => navigate("/refunds"), children: "Back to list" })
4400
+ ] }) : 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: [
4401
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
4402
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "text-lg mb-4", children: "Refund summary" }),
4403
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
4404
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4405
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Refund ID" }),
4406
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block font-mono text-sm", children: detail.refund.id })
4407
+ ] }),
4408
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4409
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Amount" }),
4410
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.refund.amount) })
4411
+ ] }),
4412
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4413
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Note" }),
4414
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.refund.note ?? "—" })
4415
+ ] }),
4416
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4417
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Created at" }),
4418
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: new Date(detail.refund.created_at).toLocaleDateString("en-US", {
4419
+ year: "numeric",
4420
+ month: "short",
4421
+ day: "numeric",
4422
+ hour: "numeric",
4423
+ minute: "2-digit",
4424
+ hour12: true
4425
+ }) })
4426
+ ] }),
4427
+ detail.refund.created_by ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4428
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Created by" }),
4429
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block font-mono text-sm", children: detail.refund.created_by })
4430
+ ] }) : null
4431
+ ] })
4432
+ ] }),
4433
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
4434
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "text-lg mb-4", children: "Payment summary" }),
4435
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
4436
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4437
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Payment amount" }),
4438
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.payment.payment_amount) })
4439
+ ] }),
4440
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4441
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Captured amount" }),
4442
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.payment.captured_amount) })
4443
+ ] }),
4444
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4445
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Refunded amount" }),
4446
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.payment.refunded_amount) })
4447
+ ] }),
4448
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4449
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Provider" }),
4450
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.payment.provider_id || "—" })
4451
+ ] }),
4452
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4453
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Status" }),
4454
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsxRuntime.jsx(
4455
+ ui.Badge,
4456
+ {
4457
+ size: "2xsmall",
4458
+ className: `uppercase ${getStatusBadgeClass$1(paymentStatus)}`,
4459
+ children: paymentStatus !== "—" ? paymentStatus.replace(/_/g, " ") : "—"
4460
+ }
4461
+ ) })
4462
+ ] }),
4463
+ detail.computed ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
4464
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4465
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Full refund" }),
4466
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.computed.is_full_refund ? "Yes" : "No" })
4467
+ ] }),
4468
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4469
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Remaining refundable" }),
4470
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.computed.remaining_refundable_amount) })
4471
+ ] }),
4472
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4473
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Refund %" }),
4474
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { className: "mt-1 block", children: [
4475
+ detail.computed.refund_percentage.toFixed(1),
4476
+ "%"
4477
+ ] })
4478
+ ] })
4479
+ ] }) : null
4480
+ ] })
4481
+ ] }),
4482
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
4483
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "text-lg mb-4", children: "Order summary" }),
4484
+ detail.order ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
4485
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4486
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Order" }),
4487
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1", children: /* @__PURE__ */ jsxRuntime.jsx(
4488
+ ui.Button,
4489
+ {
4490
+ variant: "transparent",
4491
+ size: "small",
4492
+ onClick: () => navigate(`/orders/${detail.order.order_id}`),
4493
+ children: detail.order.order_number ?? detail.order.order_id
4494
+ }
4495
+ ) })
4496
+ ] }),
4497
+ detail.order.total != null ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4498
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Total" }),
4499
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: formatAmount(detail.order.total) })
4500
+ ] }) : null,
4501
+ detail.order.customer_id ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4502
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Customer ID" }),
4503
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block font-mono text-sm", children: detail.order.customer_id })
4504
+ ] }) : null,
4505
+ detail.order.region ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4506
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Region" }),
4507
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.order.region })
4508
+ ] }) : null,
4509
+ detail.order.fulfillment_status ? /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4510
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "Fulfillment status" }),
4511
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-1 block", children: detail.order.fulfillment_status })
4512
+ ] }) : null
4513
+ ] }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: "No order linked to this refund." })
4514
+ ] }),
4515
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-xl border border-ui-border-base p-6", children: [
4516
+ /* @__PURE__ */ jsxRuntime.jsxs(
4517
+ "button",
4518
+ {
4519
+ type: "button",
4520
+ className: "flex w-full items-center justify-between text-left",
4521
+ onClick: () => setGatewayExpanded((prev) => !prev),
4522
+ "aria-expanded": gatewayExpanded,
4523
+ "aria-label": gatewayExpanded ? "Collapse gateway data" : "Expand gateway data",
4524
+ children: [
4525
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "text-lg", children: "Gateway data" }),
4526
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-muted", children: gatewayExpanded ? "Collapse" : "Expand" })
4527
+ ]
4528
+ }
4529
+ ),
4530
+ 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." }) })
4531
+ ] })
4532
+ ] }) : null
4529
4533
  ] }) });
4530
4534
  };
4531
4535
  const config$1 = adminSdk.defineRouteConfig({
4532
- label: "Swap Details",
4533
- icon: icons.ArrowPath
4536
+ label: "Refund details",
4537
+ icon: icons.Receipt
4534
4538
  });
4535
4539
  const getStatusBadgeClass = (status) => {
4536
4540
  const statusLower = status.toLowerCase();
@@ -4543,105 +4547,109 @@ const getStatusBadgeClass = (status) => {
4543
4547
  if (statusLower === "rejected") {
4544
4548
  return "bg-ui-tag-red-bg text-ui-tag-red-text";
4545
4549
  }
4546
- if (statusLower === "received") {
4547
- return "bg-ui-tag-blue-bg text-ui-tag-blue-text";
4548
- }
4549
- if (statusLower === "refunded") {
4550
- return "bg-ui-tag-green-bg text-ui-tag-green-text";
4551
- }
4552
4550
  if (statusLower === "completed") {
4553
4551
  return "bg-ui-tag-green-bg text-ui-tag-green-text";
4554
4552
  }
4555
- if (statusLower === "cancelled") {
4553
+ if (statusLower === "cancelled" || statusLower === "canceled") {
4556
4554
  return "bg-ui-tag-grey-bg text-ui-tag-grey-text";
4557
4555
  }
4556
+ if (statusLower === "pending") {
4557
+ return "bg-ui-tag-orange-bg text-ui-tag-orange-text";
4558
+ }
4558
4559
  return "bg-ui-tag-purple-bg text-ui-tag-purple-text";
4559
4560
  };
4560
- const ReturnDetailPage = () => {
4561
+ const SwapDetailPage = () => {
4561
4562
  var _a, _b, _c;
4562
4563
  const navigate = reactRouterDom.useNavigate();
4563
4564
  const { id } = reactRouterDom.useParams();
4564
- const [returnOrder, setReturnOrder] = react.useState(null);
4565
+ const [swap, setSwap] = react.useState(null);
4566
+ const [order, setOrder] = react.useState(null);
4565
4567
  const [isLoading, setIsLoading] = react.useState(true);
4566
- const [isRejecting, setIsRejecting] = react.useState(false);
4568
+ react.useState(false);
4569
+ const [isCancelling, setIsCancelling] = react.useState(false);
4567
4570
  const [error, setError] = react.useState(null);
4568
4571
  const [updateError, setUpdateError] = react.useState(null);
4569
4572
  const [updateSuccess, setUpdateSuccess] = react.useState(false);
4570
4573
  react.useEffect(() => {
4571
4574
  if (!id) {
4572
- navigate("/returns");
4575
+ navigate("/swaps");
4573
4576
  return;
4574
4577
  }
4575
- const loadReturn = async () => {
4578
+ const loadSwap = async () => {
4576
4579
  try {
4577
4580
  setIsLoading(true);
4578
4581
  setError(null);
4579
- const response = await fetch(`/admin/return/${id}`, {
4582
+ const response = await fetch(`/admin/swaps/${id}`, {
4580
4583
  credentials: "include"
4581
4584
  });
4582
4585
  if (!response.ok) {
4583
4586
  const message = await response.text();
4584
- throw new Error(message || "Unable to load return order");
4587
+ throw new Error(message || "Unable to load swap");
4585
4588
  }
4586
4589
  const payload = await response.json();
4587
- setReturnOrder(payload.return);
4590
+ setSwap(payload.swap);
4591
+ setOrder(payload.order || null);
4588
4592
  } catch (loadError) {
4589
- const message = loadError instanceof Error ? loadError.message : "Unable to load return order";
4593
+ const message = loadError instanceof Error ? loadError.message : "Unable to load swap";
4590
4594
  setError(message);
4591
4595
  } finally {
4592
4596
  setIsLoading(false);
4593
4597
  }
4594
4598
  };
4595
- void loadReturn();
4599
+ void loadSwap();
4596
4600
  }, [id, navigate]);
4597
- const handleReject = async () => {
4601
+ const handleCancelExchange = async () => {
4598
4602
  if (!id) {
4599
4603
  return;
4600
4604
  }
4601
4605
  try {
4602
- setIsRejecting(true);
4606
+ setIsCancelling(true);
4603
4607
  setUpdateError(null);
4604
4608
  setUpdateSuccess(false);
4605
- const response = await fetch(`/admin/return/${id}/reject`, {
4609
+ const response = await fetch(`/admin/swaps/${id}/cancel`, {
4606
4610
  method: "POST",
4607
4611
  headers: {
4608
4612
  "Content-Type": "application/json"
4609
4613
  },
4610
- credentials: "include",
4611
- body: JSON.stringify({ reason: "Rejected by admin" })
4614
+ credentials: "include"
4612
4615
  });
4613
4616
  if (!response.ok) {
4614
4617
  const message = await response.text();
4615
- throw new Error(message || "Unable to reject return");
4618
+ throw new Error(message || "Unable to cancel exchange");
4616
4619
  }
4617
4620
  const payload = await response.json();
4618
- setReturnOrder(payload.return);
4621
+ setSwap(payload.swap);
4619
4622
  setUpdateSuccess(true);
4620
4623
  setTimeout(() => setUpdateSuccess(false), 3e3);
4621
- const detailResponse = await fetch(`/admin/return/${id}`, {
4624
+ const detailResponse = await fetch(`/admin/swaps/${id}`, {
4622
4625
  credentials: "include"
4623
4626
  });
4624
4627
  if (detailResponse.ok) {
4625
4628
  const detailPayload = await detailResponse.json();
4626
- setReturnOrder(detailPayload.return);
4629
+ setSwap(detailPayload.swap);
4630
+ setOrder(detailPayload.order || null);
4627
4631
  }
4628
- } catch (updateErr) {
4629
- const message = updateErr instanceof Error ? updateErr.message : "Unable to reject return";
4632
+ } catch (cancelErr) {
4633
+ const message = cancelErr instanceof Error ? cancelErr.message : "Unable to cancel exchange";
4630
4634
  setUpdateError(message);
4631
4635
  } finally {
4632
- setIsRejecting(false);
4636
+ setIsCancelling(false);
4633
4637
  }
4634
4638
  };
4639
+ const isOrderExchange = Boolean(swap == null ? void 0 : swap.exchange_id);
4640
+ const canCancelExchange = isOrderExchange && swap && !["cancelled", "canceled", "completed", "declined"].includes(
4641
+ ((_a = swap.status) == null ? void 0 : _a.toLowerCase()) ?? ""
4642
+ );
4635
4643
  if (isLoading) {
4636
- 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..." }) }) }) });
4644
+ 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..." }) }) }) });
4637
4645
  }
4638
- if (error || !returnOrder) {
4646
+ if (error || !swap) {
4639
4647
  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: [
4640
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error || "Return order not found" }),
4641
- /* @__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" }) })
4648
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { weight: "plus", className: "text-ui-fg-error", children: error || "Swap not found" }),
4649
+ /* @__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" }) })
4642
4650
  ] }) }) });
4643
4651
  }
4644
- const statusHistory = ((_a = returnOrder.metadata) == null ? void 0 : _a.status_history) || [];
4652
+ const statusHistory = ((_b = swap.metadata) == null ? void 0 : _b.status_history) || [];
4645
4653
  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: [
4646
4654
  /* @__PURE__ */ jsxRuntime.jsxs("header", { className: "flex flex-col gap-3", children: [
4647
4655
  /* @__PURE__ */ jsxRuntime.jsxs(
@@ -4649,7 +4657,7 @@ const ReturnDetailPage = () => {
4649
4657
  {
4650
4658
  variant: "transparent",
4651
4659
  size: "small",
4652
- onClick: () => navigate("/returns"),
4660
+ onClick: () => navigate("/swaps"),
4653
4661
  className: "w-fit",
4654
4662
  children: [
4655
4663
  /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowLeft, { className: "mr-2" }),
@@ -4659,82 +4667,67 @@ const ReturnDetailPage = () => {
4659
4667
  ),
4660
4668
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1 md:flex-row md:items-center md:justify-between", children: [
4661
4669
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1", children: [
4662
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Return Order Details" }),
4663
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: returnOrder.id })
4670
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h1", children: "Exchange Details" }),
4671
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: swap.id })
4664
4672
  ] }),
4665
4673
  /* @__PURE__ */ jsxRuntime.jsx(
4666
4674
  ui.Badge,
4667
4675
  {
4668
4676
  size: "small",
4669
- className: `uppercase ${getStatusBadgeClass(returnOrder.status)}`,
4670
- children: returnOrder.status.replace(/_/g, " ")
4677
+ className: `uppercase ${getStatusBadgeClass(swap.status)}`,
4678
+ children: swap.status.replace(/_/g, " ")
4671
4679
  }
4672
4680
  )
4673
4681
  ] })
4674
4682
  ] }),
4675
- returnOrder.status === "requested" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
4683
+ canCancelExchange && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
4676
4684
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex gap-3", children: /* @__PURE__ */ jsxRuntime.jsx(
4677
4685
  ui.Button,
4678
4686
  {
4679
4687
  variant: "danger",
4680
- onClick: handleReject,
4681
- disabled: isRejecting,
4682
- isLoading: isRejecting,
4683
- children: "Reject (Cancel) Return"
4688
+ onClick: handleCancelExchange,
4689
+ disabled: isCancelling,
4690
+ isLoading: isCancelling,
4691
+ children: "Cancel Exchange"
4684
4692
  }
4685
4693
  ) }),
4686
- /* @__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.' })
4687
- ] }),
4688
- returnOrder.refund ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: /* @__PURE__ */ jsxRuntime.jsx(RefundCalculationBlock, { refund: returnOrder.refund }) }) : null,
4689
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
4690
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Information" }),
4691
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
4692
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4693
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Return ID" }),
4694
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.id })
4695
- ] }),
4696
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(
4697
- ui.Button,
4698
- {
4699
- variant: "secondary",
4700
- onClick: () => {
4701
- window.open(
4702
- `/app/orders/${returnOrder.order_id}`,
4703
- "_blank"
4704
- );
4705
- },
4706
- children: "View order"
4707
- }
4708
- ) })
4709
- ] })
4694
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This will cancel the exchange request. The order will remain unchanged." })
4710
4695
  ] }),
4711
4696
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid gap-6 md:grid-cols-2", children: [
4712
4697
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
4713
- /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Details" }),
4698
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Exchange Information" }),
4714
4699
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
4715
4700
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4716
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Return ID" }),
4717
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.id })
4701
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Exchange ID" }),
4702
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.id })
4718
4703
  ] }),
4719
4704
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4720
4705
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Status" }),
4721
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.status })
4706
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.status })
4722
4707
  ] }),
4723
- returnOrder.reason && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4708
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4709
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Difference Due" }),
4710
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.difference_due != null ? `${swap.currency_code || "$"}${(Number(swap.difference_due) / 100).toFixed(2)}` : "—" })
4711
+ ] }),
4712
+ swap.reason && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4724
4713
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Reason" }),
4725
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.reason })
4714
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.reason })
4726
4715
  ] }),
4727
- returnOrder.note && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4716
+ swap.note && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4728
4717
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Note" }),
4729
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.note })
4718
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.note })
4730
4719
  ] }),
4731
4720
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4732
4721
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Created" }),
4733
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: new Date(returnOrder.created_at).toLocaleString() })
4722
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: new Date(swap.created_at).toLocaleString() })
4734
4723
  ] }),
4735
4724
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4736
4725
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Last Updated" }),
4737
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: new Date(returnOrder.updated_at).toLocaleString() })
4726
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: new Date(swap.updated_at).toLocaleString() })
4727
+ ] }),
4728
+ swap.exchange_id && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4729
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Exchange ID" }),
4730
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: swap.exchange_id })
4738
4731
  ] })
4739
4732
  ] })
4740
4733
  ] }),
@@ -4764,35 +4757,31 @@ const ReturnDetailPage = () => {
4764
4757
  )) }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "No status history available" })
4765
4758
  ] })
4766
4759
  ] }),
4767
- returnOrder.order && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
4760
+ order && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-ui-border-base bg-ui-bg-base p-6", children: [
4768
4761
  /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Related Order Information" }),
4769
4762
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
4770
4763
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4771
4764
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Order ID" }),
4772
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.order.id })
4765
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: order.id })
4773
4766
  ] }),
4774
4767
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4775
4768
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Status" }),
4776
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: returnOrder.order.status || "—" })
4769
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: order.status || "—" })
4777
4770
  ] }),
4778
4771
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4779
4772
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Customer" }),
4780
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: ((_b = returnOrder.order.customer) == null ? void 0 : _b.email) || returnOrder.order.email || "—" })
4781
- ] }),
4782
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4783
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Payment method" }),
4784
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: ((_c = returnOrder.order.order_payment) == null ? void 0 : _c.label) || "—" })
4773
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: ((_c = order.customer) == null ? void 0 : _c.email) || order.email || "—" })
4785
4774
  ] }),
4786
- returnOrder.order.total && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4775
+ order.total && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
4787
4776
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Order Total" }),
4788
4777
  /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { className: "font-medium", children: [
4789
- returnOrder.order.currency_code || "$",
4790
- (Number(returnOrder.order.total) / 100).toFixed(2)
4778
+ order.currency_code || "$",
4779
+ (Number(order.total) / 100).toFixed(2)
4791
4780
  ] })
4792
4781
  ] })
4793
4782
  ] })
4794
4783
  ] }),
4795
- 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: [
4784
+ 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: [
4796
4785
  /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "Return Items" }),
4797
4786
  /* @__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: [
4798
4787
  /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
@@ -4800,20 +4789,31 @@ const ReturnDetailPage = () => {
4800
4789
  /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Quantity" }),
4801
4790
  /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Reason" })
4802
4791
  ] }) }),
4803
- /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: returnOrder.return_items.map((item, index) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
4792
+ /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: swap.return_items.map((item, index) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
4804
4793
  /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: item.id }),
4805
4794
  /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity }),
4806
4795
  /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.reason || "—" })
4807
4796
  ] }, item.id || index)) })
4808
4797
  ] }) })
4809
4798
  ] }),
4810
- 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 }) }),
4811
- 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" }) })
4799
+ 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: [
4800
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", className: "mb-4 text-lg", children: "New Items" }),
4801
+ /* @__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: [
4802
+ /* @__PURE__ */ jsxRuntime.jsx("thead", { className: "bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
4803
+ /* @__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" }),
4804
+ /* @__PURE__ */ jsxRuntime.jsx("th", { className: "px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide text-ui-fg-muted", children: "Quantity" })
4805
+ ] }) }),
4806
+ /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "divide-y divide-ui-border-subtle", children: swap.new_items.map((item, index) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
4807
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 font-medium text-ui-fg-base", children: item.variant_id }),
4808
+ /* @__PURE__ */ jsxRuntime.jsx("td", { className: "px-4 py-4 text-ui-fg-subtle", children: item.quantity })
4809
+ ] }, item.variant_id || index)) })
4810
+ ] }) })
4811
+ ] })
4812
4812
  ] }) });
4813
4813
  };
4814
4814
  const config = adminSdk.defineRouteConfig({
4815
- label: "Return Order Details",
4816
- icon: icons.CheckCircle
4815
+ label: "Swap Details",
4816
+ icon: icons.ArrowPath
4817
4817
  });
4818
4818
  const i18nTranslations0 = {};
4819
4819
  const widgetModule = { widgets: [
@@ -4832,14 +4832,14 @@ const routeModule = {
4832
4832
  Component: DeletedRecordsPage,
4833
4833
  path: "/deleted-records-audit"
4834
4834
  },
4835
- {
4836
- Component: RefundsPage,
4837
- path: "/refunds"
4838
- },
4839
4835
  {
4840
4836
  Component: PaymentsPage,
4841
4837
  path: "/payments"
4842
4838
  },
4839
+ {
4840
+ Component: RefundsPage,
4841
+ path: "/refunds"
4842
+ },
4843
4843
  {
4844
4844
  Component: ReturnsPage,
4845
4845
  path: "/returns"
@@ -4852,32 +4852,26 @@ const routeModule = {
4852
4852
  Component: DeletedRecordDetailPage,
4853
4853
  path: "/deleted-records-audit/:id"
4854
4854
  },
4855
- {
4856
- Component: RefundDetailPage,
4857
- path: "/refunds/:id"
4858
- },
4859
4855
  {
4860
4856
  Component: PaymentDetailPage,
4861
4857
  path: "/payments/:id"
4862
4858
  },
4863
- {
4864
- Component: SwapDetailPage,
4865
- path: "/swaps/:id"
4866
- },
4867
4859
  {
4868
4860
  Component: ReturnDetailPage,
4869
4861
  path: "/returns/:id"
4862
+ },
4863
+ {
4864
+ Component: RefundDetailPage,
4865
+ path: "/refunds/:id"
4866
+ },
4867
+ {
4868
+ Component: SwapDetailPage,
4869
+ path: "/swaps/:id"
4870
4870
  }
4871
4871
  ]
4872
4872
  };
4873
4873
  const menuItemModule = {
4874
4874
  menuItems: [
4875
- {
4876
- label: config$6.label,
4877
- icon: config$6.icon,
4878
- path: "/payments",
4879
- nested: void 0
4880
- },
4881
4875
  {
4882
4876
  label: config$8.label,
4883
4877
  icon: config$8.icon,
@@ -4885,17 +4879,23 @@ const menuItemModule = {
4885
4879
  nested: void 0
4886
4880
  },
4887
4881
  {
4888
- label: config$5.label,
4889
- icon: config$5.icon,
4890
- path: "/returns",
4882
+ label: config$7.label,
4883
+ icon: config$7.icon,
4884
+ path: "/payments",
4891
4885
  nested: void 0
4892
4886
  },
4893
4887
  {
4894
- label: config$7.label,
4895
- icon: config$7.icon,
4888
+ label: config$6.label,
4889
+ icon: config$6.icon,
4896
4890
  path: "/refunds",
4897
4891
  nested: void 0
4898
4892
  },
4893
+ {
4894
+ label: config$5.label,
4895
+ icon: config$5.icon,
4896
+ path: "/returns",
4897
+ nested: void 0
4898
+ },
4899
4899
  {
4900
4900
  label: config$4.label,
4901
4901
  icon: config$4.icon,
@@ -4903,26 +4903,26 @@ const menuItemModule = {
4903
4903
  nested: void 0
4904
4904
  },
4905
4905
  {
4906
- label: config$2.label,
4907
- icon: config$2.icon,
4908
- path: "/payments/:id",
4906
+ label: config$1.label,
4907
+ icon: config$1.icon,
4908
+ path: "/refunds/:id",
4909
4909
  nested: void 0
4910
4910
  },
4911
4911
  {
4912
- label: config.label,
4913
- icon: config.icon,
4914
- path: "/returns/:id",
4912
+ label: config$3.label,
4913
+ icon: config$3.icon,
4914
+ path: "/payments/:id",
4915
4915
  nested: void 0
4916
4916
  },
4917
4917
  {
4918
- label: config$3.label,
4919
- icon: config$3.icon,
4920
- path: "/refunds/:id",
4918
+ label: config$2.label,
4919
+ icon: config$2.icon,
4920
+ path: "/returns/:id",
4921
4921
  nested: void 0
4922
4922
  },
4923
4923
  {
4924
- label: config$1.label,
4925
- icon: config$1.icon,
4924
+ label: config.label,
4925
+ icon: config.icon,
4926
4926
  path: "/swaps/:id",
4927
4927
  nested: void 0
4928
4928
  }