@nivaro/react 0.3.141 → 0.3.143

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.
@@ -1,25 +1,28 @@
1
- import { jsx as e, jsxs as a, Fragment as Ze } from "react/jsx-runtime";
2
- import { useQueryClient as Xe, useQuery as L, useMutation as K } from "@tanstack/react-query";
3
- import { Upload as Ye, Plus as Me, ArrowLeft as De, FileUp as et, Link2 as tt, Loader2 as pe, Sparkles as at, ArrowRight as Ee, MoreHorizontal as rt, Trash2 as st, ChevronsUpDown as lt, Check as nt } from "lucide-react";
4
- import { useState as g, useMemo as W, useEffect as Ie, useRef as Te } from "react";
5
- import { useNivaroClient as se, useNavigation as ot } from "../../context.js";
6
- import { get as Q, del as dt, post as I } from "../../lib/commands.js";
7
- import { errorSentence as it, rowErrorSentence as Ae } from "../../lib/error-message.js";
8
- import { formatNumber as P, toLocalDateString as ct, cn as v, formatRelative as mt, formatDateTime as ae } from "../../lib/utils.js";
9
- import { DataTable as pt } from "../DataTable.js";
1
+ import { jsx as e, jsxs as r, Fragment as pt } from "react/jsx-runtime";
2
+ import { useQueryClient as Je, useQuery as Q, useMutation as U } from "@tanstack/react-query";
3
+ import { Upload as ut, Plus as Ee, ArrowLeft as Ie, FileUp as ht, Link2 as xt, Loader2 as Y, Sparkles as bt, X as ft, ArrowRight as je, MoreHorizontal as gt, Download as We, Trash2 as wt, Square as Ve, ChevronsUpDown as kt, Check as vt } from "lucide-react";
4
+ import { useState as g, useMemo as J, useEffect as Z, useRef as Le } from "react";
5
+ import { useNivaroClient as te, useNavigation as Nt } from "../../context.js";
6
+ import { get as j, del as yt, post as K } from "../../lib/commands.js";
7
+ import { errorSentence as ve, rowErrorSentence as ze } from "../../lib/error-message.js";
8
+ import { formatNumber as P, toLocalDateString as _t, cn as y, formatRelative as Ct, formatDateTime as ne } from "../../lib/utils.js";
9
+ import { DataTable as St } from "../DataTable.js";
10
+ import { ConfirmButton as qt } from "../profile/primitives.js";
10
11
  import { Button as F } from "../ui/button.js";
11
- import { Command as ut, CommandInput as ht, CommandList as xt, CommandEmpty as bt, CommandGroup as ft, CommandItem as gt } from "../ui/command.js";
12
- import { DropdownMenu as vt, DropdownMenuTrigger as kt, DropdownMenuContent as wt, DropdownMenuItem as xe } from "../ui/dropdown-menu.js";
13
- import { Input as Re } from "../ui/input.js";
14
- import { Label as V } from "../ui/label.js";
15
- import { Popover as Nt, PopoverTrigger as yt, PopoverContent as _t } from "../ui/popover.js";
16
- import { SimpleSelect as Ct } from "../ui/SimpleSelect.js";
17
- import { Sheet as St, SheetContent as Pt } from "../ui/sheet.js";
18
- import { Switch as $t } from "../ui/switch.js";
19
- import { Textarea as qt } from "../ui/textarea.js";
20
- import { ImportDuplicatesNotice as Mt } from "./ImportDuplicatesNotice.js";
21
- import { collectionPickerOptions as Dt, fieldPickerOptions as Fe } from "./import-picker-options.js";
22
- const ue = 25, he = ["Source", "Map columns", "Options", "Confirm"], H = {
12
+ import { Command as $t, CommandInput as Pt, CommandList as Mt, CommandEmpty as Tt, CommandGroup as Dt, CommandItem as At } from "../ui/command.js";
13
+ import { DropdownMenu as Ot, DropdownMenuTrigger as Rt, DropdownMenuContent as Ft, DropdownMenuItem as de } from "../ui/dropdown-menu.js";
14
+ import { Input as Ke } from "../ui/input.js";
15
+ import { Label as X } from "../ui/label.js";
16
+ import { Popover as Et, PopoverTrigger as It, PopoverContent as Lt } from "../ui/popover.js";
17
+ import { SimpleSelect as zt } from "../ui/SimpleSelect.js";
18
+ import { Sheet as Kt, SheetContent as Qt } from "../ui/sheet.js";
19
+ import { Switch as He } from "../ui/switch.js";
20
+ import { Textarea as Ut } from "../ui/textarea.js";
21
+ import { ImportDuplicatesNotice as Bt } from "./ImportDuplicatesNotice.js";
22
+ import { collectionPickerOptions as Jt, fieldPickerOptions as Qe } from "./import-picker-options.js";
23
+ import { parseMatchFields as Ge, matchFieldOptions as jt, canStartImport as Wt, noMatchWarning as Vt } from "./match-fields.js";
24
+ import { useDownload as Xe } from "./RunDetailSheet.js";
25
+ const ge = 25, we = ["Source", "Map columns", "Options", "Confirm"], ee = {
23
26
  pending: { dot: "bg-slate-400", text: "text-slate-600 dark:text-slate-300", label: "Pending" },
24
27
  processing: {
25
28
  dot: "bg-nvr-cyan",
@@ -31,120 +34,159 @@ const ue = 25, he = ["Source", "Map columns", "Options", "Confirm"], H = {
31
34
  text: "text-emerald-700 dark:text-emerald-400",
32
35
  label: "Complete"
33
36
  },
34
- failed: { dot: "bg-red-500", text: "text-red-700 dark:text-red-400", label: "Failed" }
35
- }, Tt = "Roll back this import? Created rows are deleted (to trash) and overwritten rows restored to their prior values. One-shot.";
36
- function At({
37
- disabled: c,
38
- rolledBack: o,
39
- onConfirm: n
37
+ failed: { dot: "bg-red-500", text: "text-red-700 dark:text-red-400", label: "Failed" },
38
+ cancelled: {
39
+ dot: "bg-amber-500",
40
+ text: "text-amber-700 dark:text-amber-400",
41
+ label: "Cancelled"
42
+ }
43
+ }, ke = /* @__PURE__ */ new Set(["pending", "processing"]), Ht = "Stop this import? Rows already written stay — roll the import back afterwards to undo them.", Gt = "Roll back this import? Created rows are deleted (to trash) and overwritten rows restored to their prior values. One-shot.";
44
+ function Ye({
45
+ disabled: n,
46
+ question: i,
47
+ confirmLabel: o,
48
+ onConfirm: p,
49
+ children: c
40
50
  }) {
41
- const [p, m] = g(!1);
51
+ const [s, k] = g(!1);
42
52
  return /* @__PURE__ */ e(
43
- xe,
53
+ de,
44
54
  {
45
- disabled: c,
46
- "data-armed": p ? "" : void 0,
47
- className: v(
48
- p && "max-w-[300px] whitespace-normal bg-red-50 font-medium text-red-700 focus:bg-red-100 focus:text-red-800 dark:bg-red-500/10 dark:text-red-400 dark:focus:bg-red-500/20 dark:focus:text-red-300"
55
+ disabled: n,
56
+ "data-armed": s ? "" : void 0,
57
+ className: y(
58
+ s && "max-w-[300px] whitespace-normal bg-red-50 font-medium text-red-700 focus:bg-red-100 focus:text-red-800 dark:bg-red-500/10 dark:text-red-400 dark:focus:bg-red-500/20 dark:focus:text-red-300"
49
59
  ),
50
- onSelect: (s) => {
51
- if (!p) {
52
- s.preventDefault(), m(!0);
60
+ onSelect: (T) => {
61
+ if (!s) {
62
+ T.preventDefault(), k(!0);
53
63
  return;
54
64
  }
55
- m(!1), n();
65
+ k(!1), p();
56
66
  },
57
- children: p ? /* @__PURE__ */ a("span", { className: "block", children: [
58
- Tt,
59
- /* @__PURE__ */ e("span", { className: "mt-1 block text-[11px] font-semibold", children: "Choose again to roll back" })
60
- ] }) : o ? "Rolled back" : "Roll back this import"
67
+ children: s ? /* @__PURE__ */ r("span", { className: "block", children: [
68
+ i,
69
+ /* @__PURE__ */ e("span", { className: "mt-1 block text-[11px] font-semibold", children: o })
70
+ ] }) : c
71
+ }
72
+ );
73
+ }
74
+ function Xt({
75
+ disabled: n,
76
+ rolledBack: i,
77
+ onConfirm: o
78
+ }) {
79
+ return /* @__PURE__ */ e(
80
+ Ye,
81
+ {
82
+ disabled: n,
83
+ question: Gt,
84
+ confirmLabel: "Choose again to roll back",
85
+ onConfirm: o,
86
+ children: i ? "Rolled back" : "Roll back this import"
87
+ }
88
+ );
89
+ }
90
+ function Yt({ onConfirm: n }) {
91
+ return /* @__PURE__ */ r(
92
+ Ye,
93
+ {
94
+ disabled: !1,
95
+ question: Ht,
96
+ confirmLabel: "Choose again to stop",
97
+ onConfirm: n,
98
+ children: [
99
+ /* @__PURE__ */ e(Ve, { className: "h-3.5 w-3.5" }),
100
+ " Stop import"
101
+ ]
61
102
  }
62
103
  );
63
104
  }
64
- function Le({ status: c }) {
65
- const o = H[c] ?? H.pending;
66
- return /* @__PURE__ */ a("span", { className: v("flex items-center gap-1.5 text-[12px] font-medium", o.text), children: [
67
- /* @__PURE__ */ a("span", { className: "relative flex h-1.5 w-1.5 shrink-0", children: [
68
- c === "processing" && /* @__PURE__ */ e(
105
+ function Ze({ status: n }) {
106
+ const i = ee[n] ?? ee.pending;
107
+ return /* @__PURE__ */ r("span", { className: y("flex items-center gap-1.5 text-[12px] font-medium", i.text), children: [
108
+ /* @__PURE__ */ r("span", { className: "relative flex h-1.5 w-1.5 shrink-0", children: [
109
+ n === "processing" && /* @__PURE__ */ e(
69
110
  "span",
70
111
  {
71
- className: v(
112
+ className: y(
72
113
  "absolute inline-flex h-full w-full rounded-full opacity-75 motion-safe:animate-ping",
73
- o.dot
114
+ i.dot
74
115
  )
75
116
  }
76
117
  ),
77
- /* @__PURE__ */ e("span", { className: v("relative inline-flex h-1.5 w-1.5 rounded-full", o.dot) })
118
+ /* @__PURE__ */ e("span", { className: y("relative inline-flex h-1.5 w-1.5 rounded-full", i.dot) })
78
119
  ] }),
79
- o.label
120
+ i.label
80
121
  ] });
81
122
  }
82
- function Rt({
83
- processed: c,
84
- total: o,
85
- failed: n
123
+ function Zt({
124
+ processed: n,
125
+ total: i,
126
+ failed: o,
127
+ stopped: p
86
128
  }) {
87
- if (!o) return /* @__PURE__ */ e("span", { className: "text-[12px] text-slate-300", children: "—" });
88
- const p = Math.min(100, Math.round((c ?? 0) / o * 100));
89
- return /* @__PURE__ */ a("div", { className: "flex min-w-[92px] items-center gap-2", children: [
129
+ if (!i) return /* @__PURE__ */ e("span", { className: "text-[12px] text-slate-300", children: "—" });
130
+ const c = Math.min(100, Math.round((n ?? 0) / i * 100));
131
+ return /* @__PURE__ */ r("div", { className: "flex min-w-[92px] items-center gap-2", children: [
90
132
  /* @__PURE__ */ e("div", { className: "h-1.5 flex-1 overflow-hidden rounded-full bg-slate-100 dark:bg-muted", children: /* @__PURE__ */ e(
91
133
  "div",
92
134
  {
93
- className: v(
135
+ className: y(
94
136
  "h-full rounded-full transition-[width] duration-500",
95
- n ? "bg-red-500" : "bg-nvr-cyan"
137
+ o ? "bg-red-500" : p ? "bg-amber-500" : "bg-nvr-cyan"
96
138
  ),
97
- style: { width: `${p}%` }
139
+ style: { width: `${c}%` }
98
140
  }
99
141
  ) }),
100
- /* @__PURE__ */ a("span", { className: "w-8 text-right text-[11px] tabular-nums text-slate-400", children: [
101
- p,
142
+ /* @__PURE__ */ r("span", { className: "w-8 text-right text-[11px] tabular-nums text-slate-400", children: [
143
+ c,
102
144
  "%"
103
145
  ] })
104
146
  ] });
105
147
  }
106
- function re(c) {
107
- const o = [];
108
- let n = "", p = !1;
109
- for (let m = 0; m < c.length; m++) {
110
- const s = c[m];
111
- p ? s === '"' && c[m + 1] === '"' ? (n += '"', m++) : s === '"' ? p = !1 : n += s : s === '"' ? p = !0 : s === "," ? (o.push(n), n = "") : n += s;
148
+ function ie(n) {
149
+ const i = [];
150
+ let o = "", p = !1;
151
+ for (let c = 0; c < n.length; c++) {
152
+ const s = n[c];
153
+ p ? s === '"' && n[c + 1] === '"' ? (o += '"', c++) : s === '"' ? p = !1 : o += s : s === '"' ? p = !0 : s === "," ? (i.push(o), o = "") : o += s;
112
154
  }
113
- return o.push(n), o.map((m) => m.trim());
155
+ return i.push(o), i.map((c) => c.trim());
114
156
  }
115
- function Ft(c) {
116
- const o = c.split(/\r?\n/).filter((m) => m.trim());
117
- if (o.length === 0) return { headers: [], rows: [], rowCount: 0 };
118
- const n = re(o[0]), p = o.slice(1, 6).map(re);
119
- return { headers: n, rows: p, rowCount: Math.max(0, o.length - 1) };
157
+ function er(n) {
158
+ const i = n.split(/\r?\n/).filter((c) => c.trim());
159
+ if (i.length === 0) return { headers: [], rows: [], rowCount: 0 };
160
+ const o = ie(i[0]), p = i.slice(1, 6).map(ie);
161
+ return { headers: o, rows: p, rowCount: Math.max(0, i.length - 1) };
120
162
  }
121
- function Y({
122
- value: c,
123
- onChange: o,
124
- options: n,
163
+ function se({
164
+ value: n,
165
+ onChange: i,
166
+ options: o,
125
167
  placeholder: p = "Select…",
126
- className: m,
168
+ className: c,
127
169
  wide: s = !1
128
170
  }) {
129
- const [k, q] = g(!1), x = n.find((d) => d.value === c), $ = [];
130
- for (const d of n) {
131
- const i = $[$.length - 1];
132
- i && i.name === d.group ? i.items.push(d) : $.push({ name: d.group, items: [d] });
171
+ const [k, T] = g(!1), x = o.find((b) => b.value === n), C = [];
172
+ for (const b of o) {
173
+ const m = C[C.length - 1];
174
+ m && m.name === b.group ? m.items.push(b) : C.push({ name: b.group, items: [b] });
133
175
  }
134
- return /* @__PURE__ */ a(Nt, { open: k, onOpenChange: q, children: [
135
- /* @__PURE__ */ e(yt, { asChild: !0, children: /* @__PURE__ */ a(
176
+ return /* @__PURE__ */ r(Et, { open: k, onOpenChange: T, children: [
177
+ /* @__PURE__ */ e(It, { asChild: !0, children: /* @__PURE__ */ r(
136
178
  "button",
137
179
  {
138
180
  type: "button",
139
- className: v(
181
+ className: y(
140
182
  "flex h-8 w-full items-center justify-between gap-2 rounded-md border border-slate-200 bg-white px-2.5 text-left text-[12.5px] transition-colors hover:border-slate-300 dark:border-border dark:bg-card",
141
- m
183
+ c
142
184
  ),
143
185
  children: [
144
186
  /* @__PURE__ */ e(
145
187
  "span",
146
188
  {
147
- className: v(
189
+ className: y(
148
190
  "truncate",
149
191
  x != null && x.value ? "text-slate-800 dark:text-foreground" : "text-slate-400"
150
192
  ),
@@ -152,127 +194,130 @@ function Y({
152
194
  children: (x == null ? void 0 : x.label) ?? p
153
195
  }
154
196
  ),
155
- /* @__PURE__ */ e(lt, { className: "h-3.5 w-3.5 shrink-0 text-slate-400" })
197
+ /* @__PURE__ */ e(kt, { className: "h-3.5 w-3.5 shrink-0 text-slate-400" })
156
198
  ]
157
199
  }
158
200
  ) }),
159
- /* @__PURE__ */ e(_t, { className: v("p-0", s ? "w-[320px]" : "w-[260px]"), align: "start", children: /* @__PURE__ */ a(ut, { children: [
160
- /* @__PURE__ */ e(ht, { placeholder: "Search by name…", className: "h-8 text-[12px]" }),
161
- /* @__PURE__ */ a(xt, { className: "max-h-[340px]", children: [
162
- /* @__PURE__ */ e(bt, { children: "Nothing matches." }),
163
- $.map((d, i) => /* @__PURE__ */ e(ft, { heading: d.name, children: d.items.map((u) => /* @__PURE__ */ a(
164
- gt,
201
+ /* @__PURE__ */ e(Lt, { className: y("p-0", s ? "w-[320px]" : "w-[260px]"), align: "start", children: /* @__PURE__ */ r($t, { children: [
202
+ /* @__PURE__ */ e(Pt, { placeholder: "Search by name…", className: "h-8 text-[12px]" }),
203
+ /* @__PURE__ */ r(Mt, { className: "max-h-[340px]", children: [
204
+ /* @__PURE__ */ e(Tt, { children: "Nothing matches." }),
205
+ C.map((b, m) => /* @__PURE__ */ e(Dt, { heading: b.name, children: b.items.map((h) => /* @__PURE__ */ r(
206
+ At,
165
207
  {
166
- value: `${u.label} ${u.hint ?? ""} ${u.value}`,
208
+ value: `${h.label} ${h.hint ?? ""} ${h.value}`,
167
209
  onSelect: () => {
168
- o(u.value), q(!1);
210
+ i(h.value), T(!1);
169
211
  },
170
212
  className: "items-start text-[12.5px]",
171
213
  children: [
172
214
  /* @__PURE__ */ e(
173
- nt,
215
+ vt,
174
216
  {
175
- className: v(
217
+ className: y(
176
218
  "mt-0.5 h-3.5 w-3.5 shrink-0",
177
- u.value === c ? "text-nvr-cyan opacity-100" : "opacity-0"
219
+ h.value === n ? "text-nvr-cyan opacity-100" : "opacity-0"
178
220
  )
179
221
  }
180
222
  ),
181
- /* @__PURE__ */ a("span", { className: "min-w-0", children: [
182
- /* @__PURE__ */ e("span", { className: "block truncate", children: u.label }),
183
- u.hint && /* @__PURE__ */ e("span", { className: "block truncate font-mono text-[10.5px] text-slate-400 dark:text-slate-500", children: u.hint })
223
+ /* @__PURE__ */ r("span", { className: "min-w-0", children: [
224
+ /* @__PURE__ */ e("span", { className: "block truncate", children: h.label }),
225
+ h.hint && /* @__PURE__ */ e("span", { className: "block truncate font-mono text-[10.5px] text-slate-400 dark:text-slate-500", children: h.hint })
184
226
  ] })
185
227
  ]
186
228
  },
187
- u.value || "__skip__"
188
- )) }, `${d.name ?? ""}-${i}`))
229
+ h.value || "__skip__"
230
+ )) }, `${b.name ?? ""}-${m}`))
189
231
  ] })
190
232
  ] }) })
191
233
  ] });
192
234
  }
193
- function Ot({ confidence: c }) {
194
- const o = Math.round(c * 100), n = o >= 80 ? "text-emerald-700 dark:text-emerald-400" : o >= 50 ? "text-amber-700 dark:text-amber-400" : "text-slate-500";
195
- return /* @__PURE__ */ a(
235
+ function tr({ confidence: n }) {
236
+ const i = Math.round(n * 100), o = i >= 80 ? "text-emerald-700 dark:text-emerald-400" : i >= 50 ? "text-amber-700 dark:text-amber-400" : "text-slate-500";
237
+ return /* @__PURE__ */ r(
196
238
  "span",
197
239
  {
198
- className: v("shrink-0 text-[10.5px] font-medium tabular-nums", n),
240
+ className: y("shrink-0 text-[10.5px] font-medium tabular-nums", o),
199
241
  title: "AI mapping confidence",
200
242
  children: [
201
243
  "AI ",
202
- o,
244
+ i,
203
245
  "%"
204
246
  ]
205
247
  }
206
248
  );
207
249
  }
208
- function da({
209
- initialJobId: c,
210
- onJobOpen: o
250
+ function Mr({
251
+ initialJobId: n,
252
+ onJobOpen: i
211
253
  }) {
212
- var B;
213
- const n = se(), p = Xe(), [m, s] = g("list"), [k, q] = g(c ?? null), [x, $] = g("all"), [d, i] = g(1), [u, y] = g(null), h = L({
254
+ var V;
255
+ const o = te(), p = Je(), [c, s] = g("list"), [k, T] = g(n ?? null), [x, C] = g("all"), [b, m] = g(1), [h, _] = g(null), d = Q({
214
256
  queryKey: ["collection-import-jobs"],
215
257
  // The endpoint returns every job the caller may see, so the counters below
216
258
  // are exact rather than page-scoped.
217
- queryFn: () => n.request(Q("/imports")),
218
- refetchInterval: (r) => {
219
- var _;
220
- return (((_ = r.state.data) == null ? void 0 : _.data) ?? []).some((R) => R.status === "pending" || R.status === "processing") ? 3e3 : !1;
259
+ queryFn: () => o.request(j("/imports")),
260
+ refetchInterval: (a) => {
261
+ var $;
262
+ return ((($ = a.state.data) == null ? void 0 : $.data) ?? []).some((L) => L.status === "pending" || L.status === "processing") ? 3e3 : !1;
221
263
  },
222
- placeholderData: (r) => r
223
- }), D = W(() => {
224
- var r;
225
- return ((r = h.data) == null ? void 0 : r.data) ?? [];
226
- }, [(B = h.data) == null ? void 0 : B.data]), C = W(() => {
227
- const r = {};
228
- for (const _ of D) r[_.status] = (r[_.status] ?? 0) + 1;
229
- return r;
230
- }, [D]), A = W(
231
- () => D.reduce(
232
- (r, _) => ({
233
- created: r.created + (_.created_rows ?? 0),
234
- updated: r.updated + (_.updated_rows ?? 0),
235
- skipped: r.skipped + (_.skipped_rows ?? 0),
236
- errors: r.errors + (_.error_rows ?? 0)
264
+ placeholderData: (a) => a
265
+ }), S = J(() => {
266
+ var a;
267
+ return ((a = d.data) == null ? void 0 : a.data) ?? [];
268
+ }, [(V = d.data) == null ? void 0 : V.data]), v = J(() => {
269
+ const a = {};
270
+ for (const $ of S) a[$.status] = (a[$.status] ?? 0) + 1;
271
+ return a;
272
+ }, [S]), O = J(
273
+ () => S.reduce(
274
+ (a, $) => ({
275
+ created: a.created + ($.created_rows ?? 0),
276
+ updated: a.updated + ($.updated_rows ?? 0),
277
+ skipped: a.skipped + ($.skipped_rows ?? 0),
278
+ errors: a.errors + ($.error_rows ?? 0)
237
279
  }),
238
280
  { created: 0, updated: 0, skipped: 0, errors: 0 }
239
281
  ),
240
- [D]
241
- ), z = x === "all" ? D : D.filter((r) => r.status === x), G = z.slice((d - 1) * ue, d * ue);
242
- Ie(() => i(1), [x]);
243
- const O = K({
244
- mutationFn: (r) => n.request(dt(`/imports/${r}`)),
282
+ [S]
283
+ ), E = x === "all" ? S : S.filter((a) => a.status === x), re = E.slice((b - 1) * ge, b * ge);
284
+ Z(() => m(1), [x]);
285
+ const z = U({
286
+ mutationFn: (a) => o.request(yt(`/imports/${a}`)),
245
287
  onSuccess: () => {
246
- y(null), p.invalidateQueries({ queryKey: ["collection-import-jobs"] });
288
+ _(null), p.invalidateQueries({ queryKey: ["collection-import-jobs"] });
247
289
  },
248
- onError: (r) => y(r.message)
249
- }), Z = K({
250
- mutationFn: (r) => n.request(I(`/imports/${r}/rollback`, {})),
290
+ onError: (a) => _(a.message)
291
+ }), ae = U({
292
+ mutationFn: (a) => o.request(K(`/imports/${a}/rollback`, {})),
251
293
  onSuccess: () => {
252
- y(null), p.invalidateQueries({ queryKey: ["collection-import-jobs"] });
294
+ _(null), p.invalidateQueries({ queryKey: ["collection-import-jobs"] });
253
295
  },
254
- onError: (r) => y(r.message)
255
- });
256
- function T(r) {
257
- q(r), o == null || o(r);
296
+ onError: (a) => _(a.message)
297
+ }), q = et((a) => _(a ? ve(a) : null)), R = Xe();
298
+ Z(() => {
299
+ R.error && _(`Could not download the file: ${R.error}`);
300
+ }, [R.error]);
301
+ function I(a) {
302
+ T(a), i == null || i(a);
258
303
  }
259
- const X = [
304
+ const W = [
260
305
  {
261
306
  key: "status",
262
307
  header: "Status",
263
308
  className: "w-[110px]",
264
- render: (r) => /* @__PURE__ */ e(Le, { status: r.status })
309
+ render: (a) => /* @__PURE__ */ e(Ze, { status: a.status })
265
310
  },
266
311
  {
267
312
  key: "file_name",
268
313
  header: "File",
269
314
  className: "max-w-[220px]",
270
- render: (r) => /* @__PURE__ */ e(
315
+ render: (a) => /* @__PURE__ */ e(
271
316
  "span",
272
317
  {
273
318
  className: "block truncate font-mono text-[11.5px] text-slate-800 dark:text-foreground",
274
- title: r.file_name,
275
- children: r.file_name
319
+ title: a.file_name,
320
+ children: a.file_name
276
321
  }
277
322
  )
278
323
  },
@@ -280,18 +325,19 @@ function da({
280
325
  key: "collection",
281
326
  header: "Collection",
282
327
  className: "w-[170px]",
283
- render: (r) => /* @__PURE__ */ e("span", { className: "truncate font-mono text-[11.5px] text-slate-600 dark:text-muted-foreground", children: r.collection })
328
+ render: (a) => /* @__PURE__ */ e("span", { className: "truncate font-mono text-[11.5px] text-slate-600 dark:text-muted-foreground", children: a.collection })
284
329
  },
285
330
  {
286
331
  key: "progress",
287
332
  header: "Progress",
288
333
  className: "w-[130px]",
289
- render: (r) => /* @__PURE__ */ e(
290
- Rt,
334
+ render: (a) => /* @__PURE__ */ e(
335
+ Zt,
291
336
  {
292
- processed: r.processed_rows,
293
- total: r.total_rows,
294
- failed: r.status === "failed"
337
+ processed: a.processed_rows,
338
+ total: a.total_rows,
339
+ failed: a.status === "failed",
340
+ stopped: a.status === "cancelled"
295
341
  }
296
342
  )
297
343
  },
@@ -300,39 +346,39 @@ function da({
300
346
  header: "Created",
301
347
  className: "w-[76px] text-right",
302
348
  headerClassName: "text-right",
303
- render: (r) => /* @__PURE__ */ e(ee, { n: r.created_rows })
349
+ render: (a) => /* @__PURE__ */ e(le, { n: a.created_rows })
304
350
  },
305
351
  {
306
352
  key: "updated_rows",
307
353
  header: "Updated",
308
354
  className: "w-[76px] text-right",
309
355
  headerClassName: "text-right",
310
- render: (r) => /* @__PURE__ */ e(ee, { n: r.updated_rows })
356
+ render: (a) => /* @__PURE__ */ e(le, { n: a.updated_rows })
311
357
  },
312
358
  {
313
359
  key: "skipped_rows",
314
360
  header: "Skipped",
315
361
  className: "w-[76px] text-right",
316
362
  headerClassName: "text-right",
317
- render: (r) => /* @__PURE__ */ e(ee, { n: r.skipped_rows })
363
+ render: (a) => /* @__PURE__ */ e(le, { n: a.skipped_rows })
318
364
  },
319
365
  {
320
366
  key: "error_rows",
321
367
  header: "Errors",
322
368
  className: "w-[70px] text-right",
323
369
  headerClassName: "text-right",
324
- render: (r) => (r.error_rows ?? 0) > 0 ? /* @__PURE__ */ e("span", { className: "font-mono text-[11.5px] font-medium tabular-nums text-red-600 dark:text-red-400", children: P(r.error_rows ?? 0) }) : /* @__PURE__ */ e(ee, { n: 0 })
370
+ render: (a) => (a.error_rows ?? 0) > 0 ? /* @__PURE__ */ e("span", { className: "font-mono text-[11.5px] font-medium tabular-nums text-red-600 dark:text-red-400", children: P(a.error_rows ?? 0) }) : /* @__PURE__ */ e(le, { n: 0 })
325
371
  },
326
372
  {
327
373
  key: "created_at",
328
374
  header: "Queued",
329
375
  className: "w-[110px]",
330
- render: (r) => /* @__PURE__ */ e(
376
+ render: (a) => /* @__PURE__ */ e(
331
377
  "span",
332
378
  {
333
379
  className: "text-[12px] text-slate-500 dark:text-muted-foreground",
334
- title: ae(r.created_at),
335
- children: mt(r.created_at)
380
+ title: ne(a.created_at),
381
+ children: Ct(a.created_at)
336
382
  }
337
383
  )
338
384
  },
@@ -340,33 +386,45 @@ function da({
340
386
  key: "__actions__",
341
387
  header: "",
342
388
  className: "w-[44px]",
343
- render: (r) => /* @__PURE__ */ e("div", { onClick: (_) => _.stopPropagation(), onKeyDown: (_) => _.stopPropagation(), children: /* @__PURE__ */ a(vt, { children: [
344
- /* @__PURE__ */ e(kt, { asChild: !0, children: /* @__PURE__ */ e(
389
+ render: (a) => /* @__PURE__ */ e("div", { onClick: ($) => $.stopPropagation(), onKeyDown: ($) => $.stopPropagation(), children: /* @__PURE__ */ r(Ot, { children: [
390
+ /* @__PURE__ */ e(Rt, { asChild: !0, children: /* @__PURE__ */ e(
345
391
  "button",
346
392
  {
347
393
  type: "button",
348
394
  className: "rounded p-1 text-slate-400 transition-colors hover:bg-slate-100 hover:text-slate-700 dark:hover:bg-muted",
349
- "aria-label": `Actions for ${r.file_name}`,
350
- children: /* @__PURE__ */ e(rt, { className: "h-4 w-4" })
395
+ "aria-label": `Actions for ${a.file_name}`,
396
+ children: /* @__PURE__ */ e(gt, { className: "h-4 w-4" })
351
397
  }
352
398
  ) }),
353
- /* @__PURE__ */ a(wt, { align: "end", className: "text-[12.5px]", children: [
354
- /* @__PURE__ */ e(xe, { onSelect: () => T(r.id), children: "View details" }),
399
+ /* @__PURE__ */ r(Ft, { align: "end", className: "text-[12.5px]", children: [
400
+ /* @__PURE__ */ e(de, { onSelect: () => I(a.id), children: "View details" }),
401
+ ke.has(a.status) && /* @__PURE__ */ e(Yt, { onConfirm: () => q.mutate(a.id) }),
402
+ /* @__PURE__ */ r(
403
+ de,
404
+ {
405
+ disabled: !!R.busy,
406
+ onSelect: () => void R.download(`/imports/${a.id}/file`, a.file_name || "import.csv"),
407
+ children: [
408
+ /* @__PURE__ */ e(We, { className: "h-3.5 w-3.5" }),
409
+ " Download file"
410
+ ]
411
+ }
412
+ ),
355
413
  /* @__PURE__ */ e(
356
- At,
414
+ Xt,
357
415
  {
358
- disabled: r.status !== "complete" || !!r.rolled_back_at,
359
- rolledBack: !!r.rolled_back_at,
360
- onConfirm: () => Z.mutate(r.id)
416
+ disabled: a.status !== "complete" && a.status !== "cancelled" || !!a.rolled_back_at,
417
+ rolledBack: !!a.rolled_back_at,
418
+ onConfirm: () => ae.mutate(a.id)
361
419
  }
362
420
  ),
363
- /* @__PURE__ */ a(
364
- xe,
421
+ /* @__PURE__ */ r(
422
+ de,
365
423
  {
366
- disabled: r.status !== "complete" && r.status !== "failed",
367
- onSelect: () => O.mutate(r.id),
424
+ disabled: ke.has(a.status),
425
+ onSelect: () => z.mutate(a.id),
368
426
  children: [
369
- /* @__PURE__ */ e(st, { className: "h-3.5 w-3.5" }),
427
+ /* @__PURE__ */ e(wt, { className: "h-3.5 w-3.5" }),
370
428
  " Delete job"
371
429
  ]
372
430
  }
@@ -375,294 +433,314 @@ function da({
375
433
  ] }) })
376
434
  }
377
435
  ];
378
- return m === "wizard" ? /* @__PURE__ */ e(
379
- Et,
436
+ return c === "wizard" ? /* @__PURE__ */ e(
437
+ rr,
380
438
  {
381
439
  onCancel: () => s("list"),
382
- onCreated: (r) => {
383
- s("list"), p.invalidateQueries({ queryKey: ["collection-import-jobs"] }), T(r);
440
+ onCreated: (a) => {
441
+ s("list"), p.invalidateQueries({ queryKey: ["collection-import-jobs"] }), I(a);
384
442
  }
385
443
  }
386
- ) : /* @__PURE__ */ a("div", { className: "flex min-h-0 flex-1 flex-col gap-3", children: [
387
- u && /* @__PURE__ */ e("p", { className: "rounded-md border border-red-200 bg-red-50 px-3 py-2 text-[12px] text-red-700 dark:border-red-900 dark:bg-red-950/40 dark:text-red-400", children: u }),
388
- /* @__PURE__ */ a("div", { className: "flex flex-wrap items-stretch divide-x divide-slate-200 overflow-hidden rounded-lg border border-slate-200 bg-white dark:divide-border dark:border-border dark:bg-card", children: [
444
+ ) : /* @__PURE__ */ r("div", { className: "flex min-h-0 flex-1 flex-col gap-3", children: [
445
+ h && /* @__PURE__ */ e("p", { className: "rounded-md border border-red-200 bg-red-50 px-3 py-2 text-[12px] text-red-700 dark:border-red-900 dark:bg-red-950/40 dark:text-red-400", children: h }),
446
+ /* @__PURE__ */ r("div", { className: "flex flex-wrap items-stretch divide-x divide-slate-200 overflow-hidden rounded-lg border border-slate-200 bg-white dark:divide-border dark:border-border dark:bg-card", children: [
389
447
  /* @__PURE__ */ e(
390
- Oe,
448
+ Ue,
391
449
  {
392
450
  label: "All",
393
- count: D.length,
451
+ count: S.length,
394
452
  active: x === "all",
395
- onClick: () => $("all")
453
+ onClick: () => C("all")
396
454
  }
397
455
  ),
398
- Object.keys(H).map((r) => /* @__PURE__ */ e(
399
- Oe,
456
+ Object.keys(ee).map((a) => /* @__PURE__ */ e(
457
+ Ue,
400
458
  {
401
- label: H[r].label,
402
- dot: H[r].dot,
403
- count: C[r] ?? 0,
404
- active: x === r,
405
- onClick: () => $(x === r ? "all" : r)
459
+ label: ee[a].label,
460
+ dot: ee[a].dot,
461
+ count: v[a] ?? 0,
462
+ active: x === a,
463
+ onClick: () => C(x === a ? "all" : a)
406
464
  },
407
- r
465
+ a
408
466
  )),
409
- /* @__PURE__ */ a("div", { className: "ml-auto flex items-stretch divide-x divide-slate-200 dark:divide-border", children: [
410
- /* @__PURE__ */ e(te, { label: "Records created", value: P(A.created) }),
411
- /* @__PURE__ */ e(te, { label: "Records updated", value: P(A.updated) }),
412
- /* @__PURE__ */ e(te, { label: "Skipped", value: P(A.skipped) }),
467
+ /* @__PURE__ */ r("div", { className: "ml-auto flex items-stretch divide-x divide-slate-200 dark:divide-border", children: [
468
+ /* @__PURE__ */ e(oe, { label: "Records created", value: P(O.created) }),
469
+ /* @__PURE__ */ e(oe, { label: "Records updated", value: P(O.updated) }),
470
+ /* @__PURE__ */ e(oe, { label: "Skipped", value: P(O.skipped) }),
413
471
  /* @__PURE__ */ e(
414
- te,
472
+ oe,
415
473
  {
416
474
  label: "Row errors",
417
- value: P(A.errors),
418
- tone: A.errors > 0 ? "red" : void 0
475
+ value: P(O.errors),
476
+ tone: O.errors > 0 ? "red" : void 0
419
477
  }
420
478
  )
421
479
  ] })
422
480
  ] }),
423
- D.length === 0 && !h.isLoading ? /* @__PURE__ */ e("div", { className: "rounded-lg border border-dashed border-slate-300 bg-white px-6 py-12 dark:border-border dark:bg-card", children: /* @__PURE__ */ a("div", { className: "max-w-[58ch]", children: [
424
- /* @__PURE__ */ e(Ye, { className: "h-5 w-5 text-slate-300" }),
481
+ S.length === 0 && !d.isLoading ? /* @__PURE__ */ e("div", { className: "rounded-lg border border-dashed border-slate-300 bg-white px-6 py-12 dark:border-border dark:bg-card", children: /* @__PURE__ */ r("div", { className: "max-w-[58ch]", children: [
482
+ /* @__PURE__ */ e(ut, { className: "h-5 w-5 text-slate-300" }),
425
483
  /* @__PURE__ */ e("h3", { className: "mt-3 text-[15px] font-semibold text-slate-900 dark:text-foreground", children: "No collection imports yet" }),
426
484
  /* @__PURE__ */ e("p", { className: "mt-1.5 text-[12.5px] leading-relaxed text-slate-500 dark:text-muted-foreground", children: "This is the row-by-row importer: a CSV's columns are mapped onto a collection's fields, and each row is created or updated through the normal item API — so validation, hooks and permissions all apply. Use it when you want records, not a staging table." }),
427
- /* @__PURE__ */ a(F, { size: "sm", className: "mt-4", onClick: () => s("wizard"), children: [
428
- /* @__PURE__ */ e(Me, { className: "h-3.5 w-3.5" }),
485
+ /* @__PURE__ */ r(F, { size: "sm", className: "mt-4", onClick: () => s("wizard"), children: [
486
+ /* @__PURE__ */ e(Ee, { className: "h-3.5 w-3.5" }),
429
487
  " Start an import"
430
488
  ] })
431
489
  ] }) }) : /* @__PURE__ */ e("div", { className: "min-h-0 flex-1", children: /* @__PURE__ */ e(
432
- pt,
490
+ St,
433
491
  {
434
- columns: X,
435
- rows: G,
436
- rowKey: (r) => r.id,
437
- total: z.length,
438
- page: d,
439
- limit: ue,
440
- onPageChange: i,
441
- isLoading: h.isLoading,
442
- onRowClick: (r) => T(r.id),
492
+ columns: W,
493
+ rows: re,
494
+ rowKey: (a) => a.id,
495
+ total: E.length,
496
+ page: b,
497
+ limit: ge,
498
+ onPageChange: m,
499
+ isLoading: d.isLoading,
500
+ onRowClick: (a) => I(a.id),
443
501
  nowrapCells: !0,
444
502
  minBodyHeight: 280,
445
503
  emptyMessage: "No import jobs match this filter.",
446
- rowClassName: (r) => r.status === "processing" ? "bg-nvr-cyan/5 dark:bg-nvr-cyan/10" : void 0,
447
- toolbarRight: /* @__PURE__ */ a(F, { size: "sm", className: "h-7", onClick: () => s("wizard"), children: [
448
- /* @__PURE__ */ e(Me, { className: "h-3.5 w-3.5" }),
504
+ rowClassName: (a) => a.status === "processing" ? "bg-nvr-cyan/5 dark:bg-nvr-cyan/10" : void 0,
505
+ toolbarRight: /* @__PURE__ */ r(F, { size: "sm", className: "h-7", onClick: () => s("wizard"), children: [
506
+ /* @__PURE__ */ e(Ee, { className: "h-3.5 w-3.5" }),
449
507
  " New collection import"
450
508
  ] })
451
509
  }
452
510
  ) }),
453
- /* @__PURE__ */ e(Lt, { jobId: k, onClose: () => T(null) })
511
+ /* @__PURE__ */ e(sr, { jobId: k, onClose: () => I(null) })
454
512
  ] });
455
513
  }
456
- function ee({ n: c }) {
457
- return /* @__PURE__ */ e("span", { className: "font-mono text-[11.5px] tabular-nums text-slate-600 dark:text-muted-foreground", children: P(c ?? 0) });
514
+ function le({ n }) {
515
+ return /* @__PURE__ */ e("span", { className: "font-mono text-[11.5px] tabular-nums text-slate-600 dark:text-muted-foreground", children: P(n ?? 0) });
458
516
  }
459
- function te({ label: c, value: o, tone: n }) {
460
- return /* @__PURE__ */ a("div", { className: "px-3.5 py-2", children: [
461
- /* @__PURE__ */ e("p", { className: "text-[10.5px] font-medium text-slate-400 dark:text-muted-foreground", children: c }),
517
+ function oe({ label: n, value: i, tone: o }) {
518
+ return /* @__PURE__ */ r("div", { className: "px-3.5 py-2", children: [
519
+ /* @__PURE__ */ e("p", { className: "text-[10.5px] font-medium text-slate-400 dark:text-muted-foreground", children: n }),
462
520
  /* @__PURE__ */ e(
463
521
  "p",
464
522
  {
465
- className: v(
523
+ className: y(
466
524
  "mt-0.5 text-[15px] font-semibold leading-none tabular-nums",
467
- n === "red" ? "text-red-600 dark:text-red-400" : "text-slate-900 dark:text-foreground"
525
+ o === "red" ? "text-red-600 dark:text-red-400" : "text-slate-900 dark:text-foreground"
468
526
  ),
469
- children: o
527
+ children: i
470
528
  }
471
529
  )
472
530
  ] });
473
531
  }
474
- function Oe({
475
- label: c,
476
- count: o,
477
- dot: n,
532
+ function Ue({
533
+ label: n,
534
+ count: i,
535
+ dot: o,
478
536
  active: p,
479
- onClick: m
537
+ onClick: c
480
538
  }) {
481
- return /* @__PURE__ */ a(
539
+ return /* @__PURE__ */ r(
482
540
  "button",
483
541
  {
484
542
  type: "button",
485
- onClick: m,
543
+ onClick: c,
486
544
  "aria-pressed": p,
487
- className: v(
545
+ className: y(
488
546
  "flex items-center gap-1.5 px-3 py-2 transition-colors hover:bg-slate-50 dark:hover:bg-muted/40",
489
547
  p && "bg-nvr-cyan/10 ring-1 ring-inset ring-nvr-cyan dark:bg-nvr-cyan/15",
490
- !p && o === 0 && "opacity-45"
548
+ !p && i === 0 && "opacity-45"
491
549
  ),
492
550
  children: [
493
- n && /* @__PURE__ */ e("span", { className: v("h-1.5 w-1.5 shrink-0 rounded-full", n) }),
494
- /* @__PURE__ */ e("span", { className: "text-[14px] font-semibold leading-none tabular-nums text-slate-900 dark:text-foreground", children: P(o) }),
495
- /* @__PURE__ */ e("span", { className: "text-[11px] font-medium leading-none text-slate-400 dark:text-muted-foreground", children: c })
551
+ o && /* @__PURE__ */ e("span", { className: y("h-1.5 w-1.5 shrink-0 rounded-full", o) }),
552
+ /* @__PURE__ */ e("span", { className: "text-[14px] font-semibold leading-none tabular-nums text-slate-900 dark:text-foreground", children: P(i) }),
553
+ /* @__PURE__ */ e("span", { className: "text-[11px] font-medium leading-none text-slate-400 dark:text-muted-foreground", children: n })
496
554
  ]
497
555
  }
498
556
  );
499
557
  }
500
- function Et({
501
- onCancel: c,
502
- onCreated: o
558
+ function rr({
559
+ onCancel: n,
560
+ onCreated: i
503
561
  }) {
504
- var ye, _e, Ce, Se;
505
- const n = se(), p = Te(null), [m, s] = g(0), [k, q] = g(""), [x, $] = g({}), [d, i] = g(""), [u, y] = g(""), [h, D] = g(""), [C, A] = g({}), [z, G] = g({}), [O, Z] = g("skip"), [T, X] = g(""), [B, r] = g(!1), [_, R] = g(null), [ze, le] = g(!1), [Ue, Ke] = g(null), be = Te(null), { headers: S, rows: fe, rowCount: ne } = W(() => Ft(k), [k]);
506
- Ie(() => {
507
- if (!h || S.length === 0) return;
508
- const t = `${h}|${S.join("")}`;
509
- be.current !== t && (be.current = t, n.request(I("/imports/mappings/lookup", { collection: h, headers: S })).then((l) => {
510
- const b = l.data;
511
- b && A((w) => {
512
- if (Object.values(w).some((f) => f == null ? void 0 : f.trim())) return w;
513
- const M = {};
514
- for (const f of S) b.column_map[f] && (M[f] = b.column_map[f]);
515
- return Object.keys(M).length === 0 ? w : (Ke(
516
- b.updated_at ? `Applied your saved mapping from ${ct(b.updated_at)}` : "Applied your saved mapping"
517
- ), b.id_field && X((f) => f || b.id_field || ""), b.duplicate_strategy && Z((f) => f === "skip" && b.duplicate_strategy || f), M);
562
+ var Me, Te, De, Ae;
563
+ const o = te(), p = Le(null), [c, s] = g(0), [k, T] = g(""), [x, C] = g({}), [b, m] = g(""), [h, _] = g(""), [d, S] = g(""), [v, O] = g({}), [E, re] = g({}), [z, ae] = g("skip"), [q, R] = g([]), [I, W] = g(!1);
564
+ Z(() => {
565
+ q.length > 0 && W(!1);
566
+ }, [q.length]);
567
+ const [V, a] = g(!1), [$, L] = g(null), [tt, ce] = g(!1), [rt, at] = g(null), Ne = Le(null), { headers: M, rows: ye, rowCount: me } = J(() => er(k), [k]);
568
+ Z(() => {
569
+ if (!d || M.length === 0) return;
570
+ const t = `${d}|${M.join("")}`;
571
+ Ne.current !== t && (Ne.current = t, o.request(K("/imports/mappings/lookup", { collection: d, headers: M })).then((l) => {
572
+ const u = l.data;
573
+ u && O((N) => {
574
+ if (Object.values(N).some((w) => w == null ? void 0 : w.trim())) return N;
575
+ const A = {};
576
+ for (const w of M) u.column_map[w] && (A[w] = u.column_map[w]);
577
+ if (Object.keys(A).length === 0) return N;
578
+ at(
579
+ u.updated_at ? `Applied your saved mapping from ${_t(u.updated_at)}` : "Applied your saved mapping"
580
+ );
581
+ const D = u.match_fields ?? Ge(u.id_field);
582
+ return D.length > 0 && R((w) => w.length ? w : D), u.duplicate_strategy && ae((w) => w === "skip" && u.duplicate_strategy || w), A;
518
583
  });
519
584
  }).catch(() => {
520
585
  }));
521
- }, [h, S, n]);
522
- const ge = L({
586
+ }, [d, M, o]);
587
+ const _e = Q({
523
588
  queryKey: [
524
589
  "import-diff-preview",
525
- h,
526
- T,
527
- O,
590
+ d,
591
+ q.join(","),
592
+ z,
528
593
  k.length,
529
- JSON.stringify(C)
594
+ JSON.stringify(v)
530
595
  ],
531
- queryFn: () => n.request(
532
- I("/imports/preview", {
533
- collection: h,
596
+ queryFn: () => o.request(
597
+ K("/imports/preview", {
598
+ collection: d,
534
599
  csv_data: k,
535
- column_map: C,
536
- id_field: T || null,
537
- duplicate_strategy: O
600
+ column_map: v,
601
+ match_fields: q,
602
+ duplicate_strategy: z
538
603
  })
539
604
  ),
540
- enabled: m === 3 && !!h && !!k,
605
+ enabled: c === 3 && !!d && !!k,
541
606
  staleTime: 3e4,
542
607
  retry: !1
543
- }), N = (ye = ge.data) == null ? void 0 : ye.data, Qe = L({
608
+ }), f = (Me = _e.data) == null ? void 0 : Me.data, st = Q({
544
609
  queryKey: ["import-collections"],
545
- queryFn: () => n.request(Q("/collections")),
610
+ queryFn: () => o.request(j("/collections")),
546
611
  staleTime: 6e4
547
- }), Be = L({
612
+ }), lt = Q({
548
613
  queryKey: ["import-collections-links"],
549
- queryFn: () => n.request(Q("/collections/overview-stats")).then(
614
+ queryFn: () => o.request(j("/collections/overview-stats")).then(
550
615
  (t) => new Set(
551
616
  Object.entries(t.data ?? {}).filter(([, l]) => l == null ? void 0 : l.link).map(([l]) => l)
552
617
  )
553
618
  ).catch(() => /* @__PURE__ */ new Set()),
554
619
  staleTime: 5 * 6e4,
555
620
  retry: !1
556
- }), je = Dt(
557
- ((_e = Qe.data) == null ? void 0 : _e.data) ?? [],
558
- Be.data,
559
- h
560
- ), oe = L({
561
- queryKey: ["import-collection-meta", h],
562
- queryFn: () => n.request(
563
- Q(`/collections/${h}`)
621
+ }), ot = Jt(
622
+ ((Te = st.data) == null ? void 0 : Te.data) ?? [],
623
+ lt.data,
624
+ d
625
+ ), pe = Q({
626
+ queryKey: ["import-collection-meta", d],
627
+ queryFn: () => o.request(
628
+ j(`/collections/${d}`)
564
629
  ),
565
- enabled: !!h,
630
+ enabled: !!d,
566
631
  staleTime: 6e4
567
- }), j = Fe(((Se = (Ce = oe.data) == null ? void 0 : Ce.data) == null ? void 0 : Se.fields) ?? []), Je = j.map((t) => t.value), Ve = (t) => {
568
- var l, b;
569
- return t && !j.some((w) => w.value === t) ? [
570
- ...j,
571
- ...Fe(((b = (l = oe.data) == null ? void 0 : l.data) == null ? void 0 : b.fields) ?? [], t).filter(
572
- (w) => w.value === t
632
+ }), H = Qe(((Ae = (De = pe.data) == null ? void 0 : De.data) == null ? void 0 : Ae.fields) ?? []), nt = H.map((t) => t.value), ue = J(
633
+ () => new Set(Object.values(v).filter((t) => t == null ? void 0 : t.trim())),
634
+ [v]
635
+ ), Ce = jt(H, ue);
636
+ Z(() => {
637
+ R((t) => {
638
+ const l = t.filter((u) => ue.has(u));
639
+ return l.length === t.length ? t : l;
640
+ });
641
+ }, [ue]);
642
+ const dt = (t) => {
643
+ var l, u;
644
+ return t && !H.some((N) => N.value === t) ? [
645
+ ...H,
646
+ ...Qe(((u = (l = pe.data) == null ? void 0 : l.data) == null ? void 0 : u.fields) ?? [], t).filter(
647
+ (N) => N.value === t
573
648
  )
574
- ] : j;
575
- }, ve = (t) => {
576
- var w, M, f;
577
- const l = t ? (f = (M = (w = oe.data) == null ? void 0 : w.data) == null ? void 0 : M.fields) == null ? void 0 : f.find((E) => E.field === t) : void 0, b = `${[(l == null ? void 0 : l.special) ?? ""].flat().join(" ")} ${(l == null ? void 0 : l.interface) ?? ""}`.toLowerCase();
578
- return /m2m|many-to-many/.test(b) ? "Links several: separate names (or ids) with commas" : /m2o|many-to-one/.test(b) ? "Matched by name or id" : null;
579
- }, de = K({
580
- mutationFn: (t) => n.request(
581
- I("/imports/from-url", {
649
+ ] : H;
650
+ }, Se = (t) => {
651
+ var N, A, D;
652
+ const l = t ? (D = (A = (N = pe.data) == null ? void 0 : N.data) == null ? void 0 : A.fields) == null ? void 0 : D.find((w) => w.field === t) : void 0, u = `${[(l == null ? void 0 : l.special) ?? ""].flat().join(" ")} ${(l == null ? void 0 : l.interface) ?? ""}`.toLowerCase();
653
+ return /m2m|many-to-many/.test(u) ? "Links several: separate names (or ids) with commas" : /m2o|many-to-one/.test(u) ? "Matched by name or id" : null;
654
+ }, he = U({
655
+ mutationFn: (t) => o.request(
656
+ K("/imports/from-url", {
582
657
  url: t,
583
658
  preview: !0
584
659
  })
585
660
  ),
586
661
  onSuccess: (t) => {
587
- R(null), q(t.data.csv_data), i(t.data.file_name);
662
+ L(null), T(t.data.csv_data), m(t.data.file_name);
588
663
  },
589
- onError: (t) => R(t.message)
590
- }), ie = K({
591
- mutationFn: () => n.request(
592
- I("/ai/map-columns", {
593
- collection: h,
594
- columns: S,
595
- sample_rows: fe.slice(0, 5)
664
+ onError: (t) => L(t.message)
665
+ }), xe = U({
666
+ mutationFn: () => o.request(
667
+ K("/ai/map-columns", {
668
+ collection: d,
669
+ columns: M,
670
+ sample_rows: ye.slice(0, 5)
596
671
  })
597
672
  ),
598
673
  onSuccess: (t) => {
599
- var M;
600
- const l = ((M = t.data) == null ? void 0 : M.mappings) ?? t.mappings ?? [], b = { ...C }, w = {};
601
- for (const f of l)
602
- S.includes(f.column) && (b[f.column] = f.field ?? "", f.field && (w[f.column] = f.confidence ?? 0));
603
- A(b), G(w), R(null);
674
+ var A;
675
+ const l = ((A = t.data) == null ? void 0 : A.mappings) ?? t.mappings ?? [], u = { ...v }, N = {};
676
+ for (const D of l)
677
+ M.includes(D.column) && (u[D.column] = D.field ?? "", D.field && (N[D.column] = D.confidence ?? 0));
678
+ O(u), re(N), L(null);
604
679
  },
605
- onError: (t) => R(
680
+ onError: (t) => L(
606
681
  t.status === 503 ? "AI mapping needs an Anthropic API key — add one in Settings, or map the columns by hand." : t.message
607
682
  )
608
- }), ce = K({
609
- mutationFn: () => n.request(
610
- I("/imports", {
611
- collection: h,
683
+ }), be = U({
684
+ mutationFn: () => o.request(
685
+ K("/imports", {
686
+ collection: d,
612
687
  csv_data: k,
613
- column_map: C,
688
+ column_map: v,
614
689
  transforms: Object.fromEntries(Object.entries(x).filter(([, t]) => t)),
615
- duplicate_strategy: O,
616
- id_field: T || void 0,
617
- file_name: d || "import.csv",
618
- through_items: B
690
+ duplicate_strategy: z,
691
+ match_fields: q,
692
+ // Sent only after the explicit "create every row" confirm (the server refuses
693
+ // overwrite / merge without match fields otherwise).
694
+ confirm_no_match: q.length === 0 && I,
695
+ file_name: b || "import.csv",
696
+ through_items: V
619
697
  })
620
698
  ),
621
- onSuccess: (t) => o(t.data.id),
622
- onError: (t) => R(t.message)
699
+ onSuccess: (t) => i(t.data.id),
700
+ onError: (t) => L(t.message)
623
701
  });
624
- function ke(t, l) {
625
- A((b) => ({ ...b, [t]: l })), z[t] !== void 0 && G((b) => {
626
- const w = { ...b };
627
- return delete w[t], w;
702
+ function qe(t, l) {
703
+ O((u) => ({ ...u, [t]: l })), E[t] !== void 0 && re((u) => {
704
+ const N = { ...u };
705
+ return delete N[t], N;
628
706
  });
629
707
  }
630
- async function we(t) {
631
- t && (R(null), q(await t.text()), i(t.name));
708
+ async function $e(t) {
709
+ t && (L(null), T(await t.text()), m(t.name));
632
710
  }
633
- const U = W(() => {
634
- const t = k.split(/\r?\n/).filter((M) => M.trim());
711
+ const B = J(() => {
712
+ const t = k.split(/\r?\n/).filter((A) => A.trim());
635
713
  if (t.length < 2) return {};
636
- const l = re(t[0]), b = t.slice(1, 2001).map(re), w = {};
637
- return l.forEach((M, f) => {
638
- let E = 0, Pe = 0, $e = 0, qe = 0;
639
- for (const Ge of b) {
640
- const J = (Ge[f] ?? "").trim();
641
- J && (E++, /^-?\$?[\d,]+(\.\d+)?$/.test(J) ? Pe++ : /^\d{4}-\d{2}-\d{2}/.test(J) || /^\d{1,2}\/\d{1,2}\/\d{2,4}$/.test(J) ? $e++ : /^(true|false|yes|no|y|n)$/i.test(J) && qe++);
714
+ const l = ie(t[0]), u = t.slice(1, 2001).map(ie), N = {};
715
+ return l.forEach((A, D) => {
716
+ let w = 0, Oe = 0, Re = 0, Fe = 0;
717
+ for (const mt of u) {
718
+ const G = (mt[D] ?? "").trim();
719
+ G && (w++, /^-?\$?[\d,]+(\.\d+)?$/.test(G) ? Oe++ : /^\d{4}-\d{2}-\d{2}/.test(G) || /^\d{1,2}\/\d{1,2}\/\d{2,4}$/.test(G) ? Re++ : /^(true|false|yes|no|y|n)$/i.test(G) && Fe++);
642
720
  }
643
- const He = E === 0 ? "empty" : Pe / E > 0.9 ? "number" : $e / E > 0.9 ? "date" : qe / E > 0.9 ? "boolean" : "text";
644
- w[M] = { fill: Math.round(E / b.length * 100), guess: He };
645
- }), w;
646
- }, [k]), me = S.filter((t) => {
721
+ const ct = w === 0 ? "empty" : Oe / w > 0.9 ? "number" : Re / w > 0.9 ? "date" : Fe / w > 0.9 ? "boolean" : "text";
722
+ N[A] = { fill: Math.round(w / u.length * 100), guess: ct };
723
+ }), N;
724
+ }, [k]), fe = M.filter((t) => {
647
725
  var l;
648
- return (l = C[t]) == null ? void 0 : l.trim();
649
- }).length, Ne = Ue, We = m === 0 ? S.length > 0 : m === 1 ? !!h && me > 0 : !0;
650
- return /* @__PURE__ */ a("div", { className: "flex min-h-0 flex-1 flex-col gap-4", children: [
651
- /* @__PURE__ */ a("div", { className: "flex items-center gap-3", children: [
652
- /* @__PURE__ */ a(F, { variant: "ghost", size: "sm", className: "h-7 px-2", onClick: c, children: [
653
- /* @__PURE__ */ e(De, { className: "h-3.5 w-3.5" }),
726
+ return (l = v[t]) == null ? void 0 : l.trim();
727
+ }).length, Pe = rt, it = c === 0 ? M.length > 0 : c === 1 ? !!d && fe > 0 : !0;
728
+ return /* @__PURE__ */ r("div", { className: "flex min-h-0 flex-1 flex-col gap-4", children: [
729
+ /* @__PURE__ */ r("div", { className: "flex items-center gap-3", children: [
730
+ /* @__PURE__ */ r(F, { variant: "ghost", size: "sm", className: "h-7 px-2", onClick: n, children: [
731
+ /* @__PURE__ */ e(Ie, { className: "h-3.5 w-3.5" }),
654
732
  " Back to jobs"
655
733
  ] }),
656
- /* @__PURE__ */ e("ol", { className: "flex items-center gap-1.5", children: he.map((t, l) => /* @__PURE__ */ a("li", { className: "flex items-center gap-1.5", children: [
657
- /* @__PURE__ */ a(
734
+ /* @__PURE__ */ e("ol", { className: "flex items-center gap-1.5", children: we.map((t, l) => /* @__PURE__ */ r("li", { className: "flex items-center gap-1.5", children: [
735
+ /* @__PURE__ */ r(
658
736
  "button",
659
737
  {
660
738
  type: "button",
661
- onClick: () => l < m && s(l),
662
- disabled: l > m,
663
- className: v(
739
+ onClick: () => l < c && s(l),
740
+ disabled: l > c,
741
+ className: y(
664
742
  "flex items-center gap-1.5 rounded-md px-2 py-1 text-[12px] font-medium transition-colors",
665
- l === m ? "bg-nvr-cyan/15 text-nvr-navy dark:bg-nvr-cyan/20 dark:text-nvr-cyan" : l < m ? "text-slate-600 hover:bg-slate-100 dark:text-muted-foreground dark:hover:bg-muted" : "text-slate-300 dark:text-slate-600"
743
+ l === c ? "bg-nvr-cyan/15 text-nvr-navy dark:bg-nvr-cyan/20 dark:text-nvr-cyan" : l < c ? "text-slate-600 hover:bg-slate-100 dark:text-muted-foreground dark:hover:bg-muted" : "text-slate-300 dark:text-slate-600"
666
744
  ),
667
745
  children: [
668
746
  /* @__PURE__ */ e("span", { className: "tabular-nums", children: l + 1 }),
@@ -670,11 +748,11 @@ function Et({
670
748
  ]
671
749
  }
672
750
  ),
673
- l < he.length - 1 && /* @__PURE__ */ e("span", { className: "text-slate-300", children: "›" })
751
+ l < we.length - 1 && /* @__PURE__ */ e("span", { className: "text-slate-300", children: "›" })
674
752
  ] }, t)) })
675
753
  ] }),
676
- /* @__PURE__ */ a("div", { className: "min-h-0 flex-1 overflow-y-auto rounded-lg border border-slate-200 bg-white p-5 dark:border-border dark:bg-card", children: [
677
- m === 0 && /* @__PURE__ */ a("div", { className: "max-w-[980px] space-y-5", children: [
754
+ /* @__PURE__ */ r("div", { className: "min-h-0 flex-1 overflow-y-auto rounded-lg border border-slate-200 bg-white p-5 dark:border-border dark:bg-card", children: [
755
+ c === 0 && /* @__PURE__ */ r("div", { className: "max-w-[980px] space-y-5", children: [
678
756
  /* @__PURE__ */ e(
679
757
  "input",
680
758
  {
@@ -684,12 +762,12 @@ function Et({
684
762
  className: "hidden",
685
763
  onChange: (t) => {
686
764
  var l;
687
- we(((l = t.target.files) == null ? void 0 : l[0]) ?? null), t.target.value = "";
765
+ $e(((l = t.target.files) == null ? void 0 : l[0]) ?? null), t.target.value = "";
688
766
  }
689
767
  }
690
768
  ),
691
- /* @__PURE__ */ a("div", { className: "grid gap-4 lg:grid-cols-2", children: [
692
- /* @__PURE__ */ a(
769
+ /* @__PURE__ */ r("div", { className: "grid gap-4 lg:grid-cols-2", children: [
770
+ /* @__PURE__ */ r(
693
771
  "button",
694
772
  {
695
773
  type: "button",
@@ -698,42 +776,42 @@ function Et({
698
776
  return (t = p.current) == null ? void 0 : t.click();
699
777
  },
700
778
  onDragOver: (t) => {
701
- t.preventDefault(), le(!0);
779
+ t.preventDefault(), ce(!0);
702
780
  },
703
- onDragLeave: () => le(!1),
781
+ onDragLeave: () => ce(!1),
704
782
  onDrop: (t) => {
705
783
  var l;
706
- t.preventDefault(), le(!1), we(((l = t.dataTransfer.files) == null ? void 0 : l[0]) ?? null);
784
+ t.preventDefault(), ce(!1), $e(((l = t.dataTransfer.files) == null ? void 0 : l[0]) ?? null);
707
785
  },
708
- className: v(
786
+ className: y(
709
787
  "flex flex-col items-center justify-center gap-1.5 rounded-md border border-dashed px-4 py-8 transition-colors",
710
- ze ? "border-nvr-cyan bg-nvr-cyan/10" : "border-slate-300 hover:border-slate-400 hover:bg-slate-50 dark:border-border dark:hover:bg-muted/30"
788
+ tt ? "border-nvr-cyan bg-nvr-cyan/10" : "border-slate-300 hover:border-slate-400 hover:bg-slate-50 dark:border-border dark:hover:bg-muted/30"
711
789
  ),
712
790
  children: [
713
- /* @__PURE__ */ e(et, { className: "h-4 w-4 text-slate-400" }),
791
+ /* @__PURE__ */ e(ht, { className: "h-4 w-4 text-slate-400" }),
714
792
  /* @__PURE__ */ e("span", { className: "text-[12.5px] font-medium text-slate-700 dark:text-foreground", children: "Drop a CSV, or click to choose" }),
715
- d && /* @__PURE__ */ e("span", { className: "font-mono text-[11px] text-slate-500", children: d })
793
+ b && /* @__PURE__ */ e("span", { className: "font-mono text-[11px] text-slate-500", children: b })
716
794
  ]
717
795
  }
718
796
  ),
719
- /* @__PURE__ */ a("div", { className: "space-y-1.5", children: [
720
- /* @__PURE__ */ a(V, { className: "flex items-center gap-1.5 text-[11.5px]", children: [
721
- /* @__PURE__ */ e(tt, { className: "h-3.5 w-3.5 text-slate-400" }),
797
+ /* @__PURE__ */ r("div", { className: "space-y-1.5", children: [
798
+ /* @__PURE__ */ r(X, { className: "flex items-center gap-1.5 text-[11.5px]", children: [
799
+ /* @__PURE__ */ e(xt, { className: "h-3.5 w-3.5 text-slate-400" }),
722
800
  " Or fetch from a URL"
723
801
  ] }),
724
- /* @__PURE__ */ a(
802
+ /* @__PURE__ */ r(
725
803
  "form",
726
804
  {
727
805
  className: "flex items-center gap-2",
728
806
  onSubmit: (t) => {
729
- t.preventDefault(), u.trim() && de.mutate(u.trim());
807
+ t.preventDefault(), h.trim() && he.mutate(h.trim());
730
808
  },
731
809
  children: [
732
810
  /* @__PURE__ */ e(
733
- Re,
811
+ Ke,
734
812
  {
735
- value: u,
736
- onChange: (t) => y(t.target.value),
813
+ value: h,
814
+ onChange: (t) => _(t.target.value),
737
815
  placeholder: "https://example.com/data.csv",
738
816
  className: "h-8 font-mono text-[12px]"
739
817
  }
@@ -745,8 +823,8 @@ function Et({
745
823
  variant: "outline",
746
824
  size: "sm",
747
825
  className: "h-8 shrink-0",
748
- disabled: !u.trim() || de.isPending,
749
- children: de.isPending ? /* @__PURE__ */ e(pe, { className: "h-3.5 w-3.5 animate-spin" }) : "Fetch"
826
+ disabled: !h.trim() || he.isPending,
827
+ children: he.isPending ? /* @__PURE__ */ e(Y, { className: "h-3.5 w-3.5 animate-spin" }) : "Fetch"
750
828
  }
751
829
  )
752
830
  ]
@@ -755,14 +833,14 @@ function Et({
755
833
  /* @__PURE__ */ e("p", { className: "text-[11px] leading-snug text-slate-400", children: "The server fetches it (25MB max, CSV or plain text) so the file never has to round-trip through your machine." })
756
834
  ] })
757
835
  ] }),
758
- /* @__PURE__ */ a("div", { className: "space-y-1.5", children: [
759
- /* @__PURE__ */ e(V, { className: "text-[11.5px]", children: "Or paste the rows" }),
836
+ /* @__PURE__ */ r("div", { className: "space-y-1.5", children: [
837
+ /* @__PURE__ */ e(X, { className: "text-[11.5px]", children: "Or paste the rows" }),
760
838
  /* @__PURE__ */ e(
761
- qt,
839
+ Ut,
762
840
  {
763
841
  value: k,
764
842
  onChange: (t) => {
765
- q(t.target.value), d || i("pasted.csv");
843
+ T(t.target.value), b || m("pasted.csv");
766
844
  },
767
845
  rows: 5,
768
846
  spellCheck: !1,
@@ -772,110 +850,110 @@ val1,val2,val3`,
772
850
  }
773
851
  )
774
852
  ] }),
775
- S.length > 0 && /* @__PURE__ */ a("div", { className: "space-y-2", children: [
776
- /* @__PURE__ */ a("p", { className: "text-[12px] text-slate-600 dark:text-muted-foreground", children: [
777
- /* @__PURE__ */ e("span", { className: "font-semibold text-slate-900 dark:text-foreground", children: P(ne) }),
853
+ M.length > 0 && /* @__PURE__ */ r("div", { className: "space-y-2", children: [
854
+ /* @__PURE__ */ r("p", { className: "text-[12px] text-slate-600 dark:text-muted-foreground", children: [
855
+ /* @__PURE__ */ e("span", { className: "font-semibold text-slate-900 dark:text-foreground", children: P(me) }),
778
856
  " ",
779
857
  "data rows ×",
780
858
  " ",
781
- /* @__PURE__ */ e("span", { className: "font-semibold text-slate-900 dark:text-foreground", children: S.length }),
859
+ /* @__PURE__ */ e("span", { className: "font-semibold text-slate-900 dark:text-foreground", children: M.length }),
782
860
  " ",
783
861
  "columns"
784
862
  ] }),
785
- /* @__PURE__ */ e(It, { headers: S, rows: fe })
863
+ /* @__PURE__ */ e(ar, { headers: M, rows: ye })
786
864
  ] })
787
865
  ] }),
788
- m === 1 && // Bounded width: a mapping row is a form field, and stretching the
866
+ c === 1 && // Bounded width: a mapping row is a form field, and stretching the
789
867
  // pickers to a 1600px viewport puts the CSV column and the field it
790
868
  // maps to half a screen apart.
791
- /* @__PURE__ */ a("div", { className: "max-w-[860px] space-y-4", children: [
792
- /* @__PURE__ */ a("div", { className: "flex flex-wrap items-end justify-between gap-3", children: [
793
- /* @__PURE__ */ a("div", { className: "space-y-1.5", children: [
794
- /* @__PURE__ */ e(V, { className: "text-[11.5px]", children: "Target collection" }),
869
+ /* @__PURE__ */ r("div", { className: "max-w-[860px] space-y-4", children: [
870
+ /* @__PURE__ */ r("div", { className: "flex flex-wrap items-end justify-between gap-3", children: [
871
+ /* @__PURE__ */ r("div", { className: "space-y-1.5", children: [
872
+ /* @__PURE__ */ e(X, { className: "text-[11.5px]", children: "Target collection" }),
795
873
  /* @__PURE__ */ e("div", { className: "w-[260px]", children: /* @__PURE__ */ e(
796
- Y,
874
+ se,
797
875
  {
798
- value: h,
799
- onChange: D,
800
- options: je,
876
+ value: d,
877
+ onChange: S,
878
+ options: ot,
801
879
  placeholder: "Choose a collection…",
802
880
  wide: !0
803
881
  }
804
882
  ) }),
805
883
  /* @__PURE__ */ e("p", { className: "text-[11px] text-slate-400", children: "Rows are written through the item API, so this collection's validation, hooks and permissions all apply." })
806
884
  ] }),
807
- /* @__PURE__ */ a(
885
+ /* @__PURE__ */ r(
808
886
  F,
809
887
  {
810
888
  variant: "outline",
811
889
  size: "sm",
812
890
  className: "h-8",
813
- disabled: !h || S.length === 0 || ie.isPending,
814
- onClick: () => ie.mutate(),
891
+ disabled: !d || M.length === 0 || xe.isPending,
892
+ onClick: () => xe.mutate(),
815
893
  children: [
816
- ie.isPending ? /* @__PURE__ */ e(pe, { className: "h-3.5 w-3.5 animate-spin" }) : /* @__PURE__ */ e(at, { className: "h-3.5 w-3.5 text-nvr-cyan" }),
894
+ xe.isPending ? /* @__PURE__ */ e(Y, { className: "h-3.5 w-3.5 animate-spin" }) : /* @__PURE__ */ e(bt, { className: "h-3.5 w-3.5 text-nvr-cyan" }),
817
895
  "Match columns with AI"
818
896
  ]
819
897
  }
820
898
  )
821
899
  ] }),
822
- /* @__PURE__ */ e("div", { className: "overflow-hidden rounded-md border border-slate-200 dark:border-border", children: /* @__PURE__ */ a("table", { className: "w-full border-collapse", children: [
823
- /* @__PURE__ */ e("thead", { children: /* @__PURE__ */ a("tr", { className: "bg-slate-50 dark:bg-muted/40", children: [
900
+ /* @__PURE__ */ e("div", { className: "overflow-hidden rounded-md border border-slate-200 dark:border-border", children: /* @__PURE__ */ r("table", { className: "w-full border-collapse", children: [
901
+ /* @__PURE__ */ e("thead", { children: /* @__PURE__ */ r("tr", { className: "bg-slate-50 dark:bg-muted/40", children: [
824
902
  /* @__PURE__ */ e("th", { className: "w-[45%] border-b border-slate-200 px-3 py-1.5 text-left text-[10.5px] font-medium uppercase tracking-wide text-slate-400 dark:border-border", children: "CSV column" }),
825
903
  /* @__PURE__ */ e("th", { className: "border-b border-slate-200 px-3 py-1.5 text-left text-[10.5px] font-medium uppercase tracking-wide text-slate-400 dark:border-border", children: "Collection field" })
826
904
  ] }) }),
827
- /* @__PURE__ */ e("tbody", { children: S.map((t) => /* @__PURE__ */ a(
905
+ /* @__PURE__ */ e("tbody", { children: M.map((t) => /* @__PURE__ */ r(
828
906
  "tr",
829
907
  {
830
908
  className: "border-b border-slate-100 last:border-b-0 dark:border-border/60",
831
909
  children: [
832
- /* @__PURE__ */ a("td", { className: "px-3 py-1.5 font-mono text-[11.5px] text-slate-600 dark:text-muted-foreground", children: [
910
+ /* @__PURE__ */ r("td", { className: "px-3 py-1.5 font-mono text-[11.5px] text-slate-600 dark:text-muted-foreground", children: [
833
911
  t,
834
- U[t] && /* @__PURE__ */ a(
912
+ B[t] && /* @__PURE__ */ r(
835
913
  "span",
836
914
  {
837
- className: v(
915
+ className: y(
838
916
  "ml-2 rounded px-1 py-0.5 font-sans text-[9.5px] font-medium",
839
- U[t].fill < 50 ? "bg-amber-100 text-amber-700 dark:bg-amber-400/15 dark:text-amber-400" : "bg-slate-100 text-slate-500 dark:bg-muted dark:text-slate-400"
917
+ B[t].fill < 50 ? "bg-amber-100 text-amber-700 dark:bg-amber-400/15 dark:text-amber-400" : "bg-slate-100 text-slate-500 dark:bg-muted dark:text-slate-400"
840
918
  ),
841
- "data-tip": `${U[t].fill}% of rows have a value · looks like ${U[t].guess}`,
919
+ "data-tip": `${B[t].fill}% of rows have a value · looks like ${B[t].guess}`,
842
920
  children: [
843
- U[t].guess,
921
+ B[t].guess,
844
922
  " · ",
845
- U[t].fill,
923
+ B[t].fill,
846
924
  "%"
847
925
  ]
848
926
  }
849
927
  )
850
928
  ] }),
851
- /* @__PURE__ */ a("td", { className: "px-3 py-1.5", children: [
852
- /* @__PURE__ */ a("div", { className: "flex items-center gap-2", children: [
853
- /* @__PURE__ */ e("div", { className: "w-[220px]", children: Je.length > 0 ? /* @__PURE__ */ e(
854
- Y,
929
+ /* @__PURE__ */ r("td", { className: "px-3 py-1.5", children: [
930
+ /* @__PURE__ */ r("div", { className: "flex items-center gap-2", children: [
931
+ /* @__PURE__ */ e("div", { className: "w-[220px]", children: nt.length > 0 ? /* @__PURE__ */ e(
932
+ se,
855
933
  {
856
- value: C[t] ?? "",
857
- onChange: (l) => ke(t, l),
934
+ value: v[t] ?? "",
935
+ onChange: (l) => qe(t, l),
858
936
  options: [
859
937
  { value: "", label: "Skip this column" },
860
- ...Ve(C[t])
938
+ ...dt(v[t])
861
939
  ],
862
940
  placeholder: "Skip this column"
863
941
  }
864
942
  ) : /* @__PURE__ */ e(
865
- Re,
943
+ Ke,
866
944
  {
867
- value: C[t] ?? "",
868
- onChange: (l) => ke(t, l.target.value),
945
+ value: v[t] ?? "",
946
+ onChange: (l) => qe(t, l.target.value),
869
947
  placeholder: "field_name",
870
948
  className: "h-8 font-mono text-[12px]"
871
949
  }
872
950
  ) }),
873
- z[t] !== void 0 && C[t] && /* @__PURE__ */ e(Ot, { confidence: z[t] }),
874
- C[t] && /* @__PURE__ */ e("div", { className: "w-[120px]", children: /* @__PURE__ */ e(
875
- Y,
951
+ E[t] !== void 0 && v[t] && /* @__PURE__ */ e(tr, { confidence: E[t] }),
952
+ v[t] && /* @__PURE__ */ e("div", { className: "w-[120px]", children: /* @__PURE__ */ e(
953
+ se,
876
954
  {
877
955
  value: x[t] ?? "",
878
- onChange: (l) => $((b) => ({ ...b, [t]: l })),
956
+ onChange: (l) => C((u) => ({ ...u, [t]: l })),
879
957
  options: [
880
958
  { value: "", label: "As-is" },
881
959
  { value: "trim", label: "Trim" },
@@ -888,29 +966,29 @@ val1,val2,val3`,
888
966
  }
889
967
  ) })
890
968
  ] }),
891
- ve(C[t]) && /* @__PURE__ */ e("p", { className: "mt-1 text-[11px] text-slate-500 dark:text-muted-foreground", children: ve(C[t]) })
969
+ Se(v[t]) && /* @__PURE__ */ e("p", { className: "mt-1 text-[11px] text-slate-500 dark:text-muted-foreground", children: Se(v[t]) })
892
970
  ] })
893
971
  ]
894
972
  },
895
973
  t
896
974
  )) })
897
975
  ] }) }),
898
- /* @__PURE__ */ a("p", { className: "text-[11.5px] text-slate-500 dark:text-muted-foreground", children: [
899
- me,
976
+ /* @__PURE__ */ r("p", { className: "text-[11.5px] text-slate-500 dark:text-muted-foreground", children: [
977
+ fe,
900
978
  " of ",
901
- S.length,
979
+ M.length,
902
980
  " columns mapped — unmapped columns are ignored.",
903
- Ne && /* @__PURE__ */ e("span", { className: "ml-1.5 rounded bg-sky-500/10 px-1.5 py-0.5 text-[10.5px] font-medium text-sky-700 dark:text-sky-400", children: Ne })
981
+ Pe && /* @__PURE__ */ e("span", { className: "ml-1.5 rounded bg-sky-500/10 px-1.5 py-0.5 text-[10.5px] font-medium text-sky-700 dark:text-sky-400", children: Pe })
904
982
  ] })
905
983
  ] }),
906
- m === 2 && /* @__PURE__ */ a("div", { className: "max-w-[520px] space-y-4", children: [
907
- /* @__PURE__ */ a("div", { className: "space-y-1.5", children: [
908
- /* @__PURE__ */ e(V, { className: "text-[11.5px]", children: "When a record already exists" }),
984
+ c === 2 && /* @__PURE__ */ r("div", { className: "max-w-[520px] space-y-4", children: [
985
+ /* @__PURE__ */ r("div", { className: "space-y-1.5", children: [
986
+ /* @__PURE__ */ e(X, { className: "text-[11.5px]", children: "When a record already exists" }),
909
987
  /* @__PURE__ */ e(
910
- Ct,
988
+ zt,
911
989
  {
912
- value: O,
913
- onChange: Z,
990
+ value: z,
991
+ onChange: ae,
914
992
  options: [
915
993
  { value: "skip", label: "Skip — leave the existing record alone" },
916
994
  { value: "overwrite", label: "Overwrite — replace every mapped field" },
@@ -920,73 +998,114 @@ val1,val2,val3`,
920
998
  }
921
999
  )
922
1000
  ] }),
923
- /* @__PURE__ */ a("div", { className: "flex items-start gap-2.5 rounded-md border border-slate-200 bg-white px-3 py-2 dark:border-border dark:bg-card", children: [
1001
+ /* @__PURE__ */ r("div", { className: "flex items-start gap-2.5 rounded-md border border-slate-200 bg-white px-3 py-2 dark:border-border dark:bg-card", children: [
924
1002
  /* @__PURE__ */ e(
925
- $t,
1003
+ He,
926
1004
  {
927
1005
  id: "csv-through-items",
928
- checked: B,
929
- onCheckedChange: r,
1006
+ checked: V,
1007
+ onCheckedChange: a,
930
1008
  className: "mt-0.5",
931
1009
  "data-csv-through-items": !0
932
1010
  }
933
1011
  ),
934
- /* @__PURE__ */ a("label", { htmlFor: "csv-through-items", className: "cursor-pointer", children: [
1012
+ /* @__PURE__ */ r("label", { htmlFor: "csv-through-items", className: "cursor-pointer", children: [
935
1013
  /* @__PURE__ */ e("span", { className: "block text-[12px] font-medium text-slate-800 dark:text-foreground", children: "Apply rules and keep history" }),
936
1014
  /* @__PURE__ */ e("span", { className: "block text-[11px] leading-snug text-slate-500 dark:text-muted-foreground", children: "Each row is saved the way the form saves it: field rules, validation, automations, and a revision on every record, credited to you. Rows that break a rule are reported instead of written. Unchanged fields are left alone. Slower on large files." })
937
1015
  ] })
938
1016
  ] }),
939
- /* @__PURE__ */ a("div", { className: "space-y-1.5", children: [
940
- /* @__PURE__ */ e(V, { className: "text-[11.5px]", children: "Match records on" }),
1017
+ /* @__PURE__ */ r("div", { className: "space-y-1.5", children: [
1018
+ /* @__PURE__ */ e(X, { className: "text-[11.5px]", children: "Match records on" }),
1019
+ q.length > 0 && /* @__PURE__ */ e("div", { className: "flex flex-wrap gap-1.5", "data-csv-match-fields": !0, children: q.map((t) => {
1020
+ var l;
1021
+ return /* @__PURE__ */ r(
1022
+ "span",
1023
+ {
1024
+ className: "inline-flex h-6 items-center gap-1 rounded-md border border-slate-200 bg-white pl-2 pr-1 font-mono text-[11.5px] text-slate-700 dark:border-border dark:bg-card dark:text-foreground",
1025
+ children: [
1026
+ ((l = Ce.find((u) => u.value === t)) == null ? void 0 : l.label) ?? t,
1027
+ /* @__PURE__ */ e(
1028
+ "button",
1029
+ {
1030
+ type: "button",
1031
+ className: "rounded p-0.5 text-slate-400 hover:bg-slate-100 hover:text-slate-700 dark:hover:bg-muted dark:hover:text-foreground",
1032
+ "aria-label": `Stop matching on ${t}`,
1033
+ onClick: () => R((u) => u.filter((N) => N !== t)),
1034
+ children: /* @__PURE__ */ e(ft, { className: "h-3 w-3" })
1035
+ }
1036
+ )
1037
+ ]
1038
+ },
1039
+ t
1040
+ );
1041
+ }) }),
941
1042
  /* @__PURE__ */ e(
942
- Y,
1043
+ se,
943
1044
  {
944
- value: T,
945
- onChange: X,
946
- options: [
947
- { value: "", label: "Always create new records" },
948
- // Match on a plain value: the record's id or any field a link list is not.
949
- { value: "id", label: "ID", hint: "id" },
950
- ...j.filter(
951
- (t) => t.value !== "id" && !/links several/.test(t.hint ?? "")
952
- )
953
- ],
954
- placeholder: "Always create new records",
1045
+ value: "",
1046
+ onChange: (t) => {
1047
+ t && R((l) => l.includes(t) ? l : [...l, t]);
1048
+ },
1049
+ options: Ce.filter((t) => !q.includes(t.value)),
1050
+ placeholder: q.length ? "Add another match field…" : "Pick a match field…",
955
1051
  className: "w-[260px]"
956
1052
  }
957
1053
  ),
958
- /* @__PURE__ */ e("p", { className: "text-[11px] leading-snug text-slate-400", children: "The field used to decide whether a row is a duplicate. Leave it empty and every row becomes a new record." })
1054
+ /* @__PURE__ */ e("p", { className: "text-[11px] leading-snug text-slate-400", children: "A row updates the existing record whose match fields ALL equal the row's (pick several when one is not unique, e.g. warehouse and item). Two matching records make that row an error. Only fields a column of the file is mapped to can be picked." }),
1055
+ /* @__PURE__ */ e(
1056
+ Be,
1057
+ {
1058
+ matchFields: q,
1059
+ confirmed: I,
1060
+ onConfirm: W
1061
+ }
1062
+ )
959
1063
  ] })
960
1064
  ] }),
961
- m === 3 && /* @__PURE__ */ a("div", { className: "max-w-[620px] space-y-4", children: [
962
- ge.isLoading && /* @__PURE__ */ e("p", { className: "text-[12px] text-slate-400", children: "Comparing against the live data…" }),
963
- N && /* @__PURE__ */ a("div", { className: "space-y-2", children: [
964
- /* @__PURE__ */ a("div", { className: "flex flex-wrap gap-2", children: [
1065
+ c === 3 && /* @__PURE__ */ r("div", { className: "max-w-[620px] space-y-4", children: [
1066
+ /* @__PURE__ */ e(
1067
+ Be,
1068
+ {
1069
+ matchFields: q,
1070
+ confirmed: I,
1071
+ onConfirm: W
1072
+ }
1073
+ ),
1074
+ _e.isLoading && /* @__PURE__ */ e("p", { className: "text-[12px] text-slate-400", children: "Comparing against the live data…" }),
1075
+ f && /* @__PURE__ */ r("div", { className: "space-y-2", children: [
1076
+ /* @__PURE__ */ r("div", { className: "flex flex-wrap gap-2", children: [
965
1077
  [
966
1078
  {
967
1079
  label: "new",
968
- n: N.new,
1080
+ n: f.new,
969
1081
  cls: "border-emerald-300 text-emerald-700 dark:border-emerald-500/40 dark:text-emerald-400"
970
1082
  },
971
1083
  {
972
1084
  label: "changed",
973
- n: N.changed,
1085
+ n: f.changed,
974
1086
  cls: "border-amber-300 text-amber-700 dark:border-amber-500/40 dark:text-amber-400"
975
1087
  },
976
1088
  {
977
- label: N.conflicts === 1 ? "conflict" : "conflicts",
978
- n: N.conflicts,
1089
+ label: f.conflicts === 1 ? "conflict" : "conflicts",
1090
+ n: f.conflicts,
979
1091
  cls: "border-red-300 text-red-700 dark:border-red-500/40 dark:text-red-400"
980
1092
  },
981
1093
  {
982
1094
  label: "unchanged",
983
- n: N.unchanged,
1095
+ n: f.unchanged,
984
1096
  cls: "border-slate-200 text-slate-500 dark:border-border dark:text-slate-400"
985
- }
986
- ].map((t) => /* @__PURE__ */ a(
1097
+ },
1098
+ ...(f.ambiguous ?? 0) > 0 ? [
1099
+ {
1100
+ label: "match several records",
1101
+ n: f.ambiguous ?? 0,
1102
+ cls: "border-red-300 text-red-700 dark:border-red-500/40 dark:text-red-400"
1103
+ }
1104
+ ] : []
1105
+ ].map((t) => /* @__PURE__ */ r(
987
1106
  "span",
988
1107
  {
989
- className: v(
1108
+ className: y(
990
1109
  "inline-flex items-center gap-1.5 rounded-full border bg-white px-2.5 py-1 text-[12px] font-medium dark:bg-card",
991
1110
  t.cls
992
1111
  ),
@@ -998,22 +1117,22 @@ val1,val2,val3`,
998
1117
  },
999
1118
  t.label
1000
1119
  )),
1001
- N.truncated && /* @__PURE__ */ a("span", { className: "self-center text-[11px] text-slate-400", children: [
1120
+ f.truncated && /* @__PURE__ */ r("span", { className: "self-center text-[11px] text-slate-400", children: [
1002
1121
  "(first ",
1003
- P(N.total),
1122
+ P(f.total),
1004
1123
  " rows scanned)"
1005
1124
  ] })
1006
1125
  ] }),
1007
- N.diffs.length > 0 && /* @__PURE__ */ e("div", { className: "max-h-56 overflow-y-auto rounded-md border border-slate-200 dark:border-border", children: N.diffs.map((t) => /* @__PURE__ */ a(
1126
+ f.diffs.length > 0 && /* @__PURE__ */ e("div", { className: "max-h-56 overflow-y-auto rounded-md border border-slate-200 dark:border-border", children: f.diffs.map((t) => /* @__PURE__ */ r(
1008
1127
  "div",
1009
1128
  {
1010
1129
  className: "border-b border-slate-100 px-3 py-2 text-[12px] last:border-b-0 dark:border-border/60",
1011
1130
  children: [
1012
- /* @__PURE__ */ a("p", { className: "flex items-center gap-2", children: [
1131
+ /* @__PURE__ */ r("p", { className: "flex items-center gap-2", children: [
1013
1132
  /* @__PURE__ */ e(
1014
1133
  "span",
1015
1134
  {
1016
- className: v(
1135
+ className: y(
1017
1136
  "rounded px-1.5 py-0.5 text-[10.5px] font-semibold uppercase tracking-wide",
1018
1137
  t.kind === "conflict" ? "bg-red-500/10 text-red-600 dark:text-red-400" : "bg-amber-400/10 text-amber-600 dark:text-amber-400"
1019
1138
  ),
@@ -1021,14 +1140,14 @@ val1,val2,val3`,
1021
1140
  }
1022
1141
  ),
1023
1142
  /* @__PURE__ */ e("span", { className: "font-mono text-[11.5px]", children: t.id }),
1024
- /* @__PURE__ */ a("span", { className: "text-[11px] text-slate-400", children: [
1143
+ /* @__PURE__ */ r("span", { className: "text-[11px] text-slate-400", children: [
1025
1144
  "row ",
1026
1145
  t.row
1027
1146
  ] })
1028
1147
  ] }),
1029
1148
  t.reason && /* @__PURE__ */ e("p", { className: "mt-0.5 text-[11px] text-slate-500 dark:text-muted-foreground", children: t.reason }),
1030
- t.fields.map((l) => /* @__PURE__ */ a("p", { className: "mt-0.5 font-mono text-[11px]", children: [
1031
- /* @__PURE__ */ a("span", { className: "text-slate-400", children: [
1149
+ t.fields.map((l) => /* @__PURE__ */ r("p", { className: "mt-0.5 font-mono text-[11px]", children: [
1150
+ /* @__PURE__ */ r("span", { className: "text-slate-400", children: [
1032
1151
  l.field,
1033
1152
  ":"
1034
1153
  ] }),
@@ -1041,19 +1160,38 @@ val1,val2,val3`,
1041
1160
  },
1042
1161
  `${t.row}-${t.id}`
1043
1162
  )) }),
1044
- N.conflicts > 0 && /* @__PURE__ */ e("p", { className: "text-[11.5px] text-red-600 dark:text-red-400", children: "Conflicts need a look before you start — they are rows the import will silently drop or resolve by last-write-wins." }),
1045
- N.duplicates && /* @__PURE__ */ e(Mt, { dup: N.duplicates }),
1046
- (N.link_error_rows ?? 0) > 0 && /* @__PURE__ */ a("div", { className: "rounded-md border border-red-200 bg-red-50 px-3 py-2 dark:border-red-500/30 dark:bg-red-500/10", children: [
1047
- /* @__PURE__ */ a("p", { className: "text-[12px] font-medium text-red-700 dark:text-red-300", children: [
1048
- P(N.link_error_rows ?? 0),
1163
+ f.conflicts > 0 && /* @__PURE__ */ e("p", { className: "text-[11.5px] text-red-600 dark:text-red-400", children: "Conflicts need a look before you start — they are rows the import will silently drop or resolve by last-write-wins." }),
1164
+ f.duplicates && /* @__PURE__ */ e(Bt, { dup: f.duplicates }),
1165
+ (f.value_error_rows ?? 0) > 0 && /* @__PURE__ */ r("div", { className: "rounded-md border border-red-200 bg-red-50 px-3 py-2 dark:border-red-500/30 dark:bg-red-500/10", children: [
1166
+ /* @__PURE__ */ r("p", { className: "text-[12px] font-medium text-red-700 dark:text-red-300", children: [
1167
+ P(f.value_error_rows ?? 0),
1049
1168
  " ",
1050
- N.link_error_rows === 1 ? "row names" : "rows name",
1169
+ f.value_error_rows === 1 ? "row has a value" : "rows have values",
1170
+ " its field cannot hold — ",
1171
+ f.value_error_rows === 1 ? "it" : "they",
1172
+ " will not be imported"
1173
+ ] }),
1174
+ /* @__PURE__ */ e("ul", { className: "mt-1 max-h-32 space-y-0.5 overflow-y-auto text-[11.5px] text-red-700 dark:text-red-300", children: (f.value_problems ?? []).map((t) => /* @__PURE__ */ r("li", { children: [
1175
+ /* @__PURE__ */ r("span", { className: "text-red-500/80 dark:text-red-400/70", children: [
1176
+ "Row ",
1177
+ t.row,
1178
+ ":"
1179
+ ] }),
1180
+ " ",
1181
+ t.error
1182
+ ] }, `${t.row}-${t.error}`)) })
1183
+ ] }),
1184
+ (f.link_error_rows ?? 0) > 0 && /* @__PURE__ */ r("div", { className: "rounded-md border border-red-200 bg-red-50 px-3 py-2 dark:border-red-500/30 dark:bg-red-500/10", children: [
1185
+ /* @__PURE__ */ r("p", { className: "text-[12px] font-medium text-red-700 dark:text-red-300", children: [
1186
+ P(f.link_error_rows ?? 0),
1187
+ " ",
1188
+ f.link_error_rows === 1 ? "row names" : "rows name",
1051
1189
  " a record that does not exist — ",
1052
- N.link_error_rows === 1 ? "it" : "they",
1190
+ f.link_error_rows === 1 ? "it" : "they",
1053
1191
  " will not be imported"
1054
1192
  ] }),
1055
- /* @__PURE__ */ e("ul", { className: "mt-1 max-h-32 space-y-0.5 overflow-y-auto text-[11.5px] text-red-700 dark:text-red-300", children: (N.link_problems ?? []).map((t) => /* @__PURE__ */ a("li", { children: [
1056
- /* @__PURE__ */ a("span", { className: "text-red-500/80 dark:text-red-400/70", children: [
1193
+ /* @__PURE__ */ e("ul", { className: "mt-1 max-h-32 space-y-0.5 overflow-y-auto text-[11.5px] text-red-700 dark:text-red-300", children: (f.link_problems ?? []).map((t) => /* @__PURE__ */ r("li", { children: [
1194
+ /* @__PURE__ */ r("span", { className: "text-red-500/80 dark:text-red-400/70", children: [
1057
1195
  "Row ",
1058
1196
  t.row,
1059
1197
  ":"
@@ -1064,20 +1202,20 @@ val1,val2,val3`,
1064
1202
  ] })
1065
1203
  ] }),
1066
1204
  /* @__PURE__ */ e("div", { className: "overflow-hidden rounded-md border border-slate-200 dark:border-border", children: [
1067
- { label: "File", value: d || "pasted.csv", mono: !0 },
1068
- { label: "Collection", value: h, mono: !0 },
1069
- { label: "Data rows", value: P(ne) },
1070
- { label: "Mapped columns", value: `${me} of ${S.length}` },
1205
+ { label: "File", value: b || "pasted.csv", mono: !0 },
1206
+ { label: "Collection", value: d, mono: !0 },
1207
+ { label: "Data rows", value: P(me) },
1208
+ { label: "Mapped columns", value: `${fe} of ${M.length}` },
1071
1209
  {
1072
1210
  label: "Duplicates",
1073
- value: O === "skip" ? "Skipped" : O === "overwrite" ? "Overwritten" : "Merged"
1211
+ value: z === "skip" ? "Skipped" : z === "overwrite" ? "Overwritten" : "Merged"
1074
1212
  },
1075
1213
  {
1076
1214
  label: "Matched on",
1077
- value: T || "nothing — every row is new",
1078
- mono: !!T
1215
+ value: q.join(" + ") || "nothing — every row is new",
1216
+ mono: q.length > 0
1079
1217
  }
1080
- ].map((t) => /* @__PURE__ */ a(
1218
+ ].map((t) => /* @__PURE__ */ r(
1081
1219
  "div",
1082
1220
  {
1083
1221
  className: "flex items-center gap-4 border-b border-slate-100 px-3.5 py-2 last:border-b-0 dark:border-border/60",
@@ -1086,7 +1224,7 @@ val1,val2,val3`,
1086
1224
  /* @__PURE__ */ e(
1087
1225
  "span",
1088
1226
  {
1089
- className: v(
1227
+ className: y(
1090
1228
  "truncate text-[12.5px] text-slate-800 dark:text-foreground",
1091
1229
  t.mono && "font-mono text-[12px]"
1092
1230
  ),
@@ -1097,103 +1235,197 @@ val1,val2,val3`,
1097
1235
  },
1098
1236
  t.label
1099
1237
  )) }),
1100
- /* @__PURE__ */ a("p", { className: "text-[12px] leading-relaxed text-slate-500 dark:text-muted-foreground", children: [
1238
+ /* @__PURE__ */ r("p", { className: "text-[12px] leading-relaxed text-slate-500 dark:text-muted-foreground", children: [
1101
1239
  "Starting the import writes ",
1102
- P(ne),
1240
+ P(me),
1103
1241
  " rows into",
1104
1242
  " ",
1105
- /* @__PURE__ */ e("span", { className: "font-mono text-slate-700 dark:text-foreground", children: h }),
1243
+ /* @__PURE__ */ e("span", { className: "font-mono text-slate-700 dark:text-foreground", children: d }),
1106
1244
  " ",
1107
1245
  "one at a time. Progress appears in the job list as it runs."
1108
1246
  ] })
1109
1247
  ] })
1110
1248
  ] }),
1111
- /* @__PURE__ */ a("div", { className: "flex shrink-0 items-center gap-2", children: [
1112
- m > 0 && /* @__PURE__ */ a(F, { variant: "ghost", size: "sm", onClick: () => s((t) => t - 1), children: [
1113
- /* @__PURE__ */ e(De, { className: "h-3.5 w-3.5" }),
1249
+ /* @__PURE__ */ r("div", { className: "flex shrink-0 items-center gap-2", children: [
1250
+ c > 0 && /* @__PURE__ */ r(F, { variant: "ghost", size: "sm", onClick: () => s((t) => t - 1), children: [
1251
+ /* @__PURE__ */ e(Ie, { className: "h-3.5 w-3.5" }),
1114
1252
  " Back"
1115
1253
  ] }),
1116
- _ && /* @__PURE__ */ e("p", { className: "text-[12px] text-red-600 dark:text-red-400", children: _ }),
1117
- /* @__PURE__ */ a("div", { className: "ml-auto flex items-center gap-2", children: [
1118
- /* @__PURE__ */ e(F, { variant: "ghost", size: "sm", onClick: c, children: "Cancel" }),
1119
- m < he.length - 1 ? /* @__PURE__ */ a(F, { size: "sm", disabled: !We, onClick: () => s((t) => t + 1), children: [
1254
+ $ && /* @__PURE__ */ e("p", { className: "text-[12px] text-red-600 dark:text-red-400", children: $ }),
1255
+ /* @__PURE__ */ r("div", { className: "ml-auto flex items-center gap-2", children: [
1256
+ /* @__PURE__ */ e(F, { variant: "ghost", size: "sm", onClick: n, children: "Cancel" }),
1257
+ c < we.length - 1 ? /* @__PURE__ */ r(F, { size: "sm", disabled: !it, onClick: () => s((t) => t + 1), children: [
1120
1258
  "Next ",
1121
- /* @__PURE__ */ e(Ee, { className: "h-3.5 w-3.5" })
1122
- ] }) : /* @__PURE__ */ e(F, { size: "sm", disabled: ce.isPending, onClick: () => ce.mutate(), children: ce.isPending ? /* @__PURE__ */ a(Ze, { children: [
1123
- /* @__PURE__ */ e(pe, { className: "h-3.5 w-3.5 animate-spin" }),
1124
- " Starting…"
1125
- ] }) : "Start import" })
1259
+ /* @__PURE__ */ e(je, { className: "h-3.5 w-3.5" })
1260
+ ] }) : /* @__PURE__ */ e(
1261
+ F,
1262
+ {
1263
+ size: "sm",
1264
+ disabled: be.isPending || !Wt(q, I),
1265
+ onClick: () => be.mutate(),
1266
+ children: be.isPending ? /* @__PURE__ */ r(pt, { children: [
1267
+ /* @__PURE__ */ e(Y, { className: "h-3.5 w-3.5 animate-spin" }),
1268
+ " Starting…"
1269
+ ] }) : "Start import"
1270
+ }
1271
+ )
1126
1272
  ] })
1127
1273
  ] })
1128
1274
  ] });
1129
1275
  }
1130
- function It({ headers: c, rows: o }) {
1131
- return /* @__PURE__ */ e("div", { className: "overflow-x-auto rounded-md border border-slate-200 dark:border-border", children: /* @__PURE__ */ a("table", { className: "w-full border-collapse", children: [
1132
- /* @__PURE__ */ e("thead", { children: /* @__PURE__ */ e("tr", { className: "bg-slate-50 dark:bg-muted/40", children: c.map((n) => /* @__PURE__ */ e(
1276
+ function Be({
1277
+ matchFields: n,
1278
+ confirmed: i,
1279
+ onConfirm: o
1280
+ }) {
1281
+ const p = Vt(n);
1282
+ return p ? /* @__PURE__ */ r(
1283
+ "div",
1284
+ {
1285
+ className: "rounded-md border border-amber-300 bg-amber-50 px-3 py-2 dark:border-amber-500/40 dark:bg-amber-500/10",
1286
+ "data-csv-no-match": !0,
1287
+ children: [
1288
+ /* @__PURE__ */ e("p", { className: "text-[12px] font-medium text-amber-800 dark:text-amber-300", children: p }),
1289
+ /* @__PURE__ */ e("p", { className: "mt-0.5 text-[11px] leading-snug text-amber-700 dark:text-amber-400", children: "Existing records are never updated or skipped, whatever you chose above. Running the same file twice creates every record twice." }),
1290
+ /* @__PURE__ */ r("div", { className: "mt-2 flex items-center gap-2", children: [
1291
+ /* @__PURE__ */ e(
1292
+ He,
1293
+ {
1294
+ id: "csv-confirm-no-match",
1295
+ checked: i,
1296
+ onCheckedChange: o,
1297
+ "data-csv-confirm-no-match": !0
1298
+ }
1299
+ ),
1300
+ /* @__PURE__ */ e(
1301
+ "label",
1302
+ {
1303
+ htmlFor: "csv-confirm-no-match",
1304
+ className: "cursor-pointer text-[11.5px] font-medium text-amber-800 dark:text-amber-300",
1305
+ children: "Yes, create every row as a new record"
1306
+ }
1307
+ )
1308
+ ] })
1309
+ ]
1310
+ }
1311
+ ) : null;
1312
+ }
1313
+ function ar({ headers: n, rows: i }) {
1314
+ return /* @__PURE__ */ e("div", { className: "overflow-x-auto rounded-md border border-slate-200 dark:border-border", children: /* @__PURE__ */ r("table", { className: "w-full border-collapse", children: [
1315
+ /* @__PURE__ */ e("thead", { children: /* @__PURE__ */ e("tr", { className: "bg-slate-50 dark:bg-muted/40", children: n.map((o) => /* @__PURE__ */ e(
1133
1316
  "th",
1134
1317
  {
1135
1318
  className: "whitespace-nowrap border-b border-slate-200 px-2.5 py-1.5 text-left font-mono text-[10.5px] font-medium text-slate-500 dark:border-border dark:text-muted-foreground",
1136
- children: n
1319
+ children: o
1137
1320
  },
1138
- n
1321
+ o
1139
1322
  )) }) }),
1140
- /* @__PURE__ */ e("tbody", { children: o.map((n, p) => (
1323
+ /* @__PURE__ */ e("tbody", { children: i.map((o, p) => (
1141
1324
  // eslint-disable-next-line react/no-array-index-key
1142
- /* @__PURE__ */ e("tr", { className: "border-b border-slate-100 last:border-b-0 dark:border-border/60", children: c.map((m, s) => /* @__PURE__ */ e(
1325
+ /* @__PURE__ */ e("tr", { className: "border-b border-slate-100 last:border-b-0 dark:border-border/60", children: n.map((c, s) => /* @__PURE__ */ e(
1143
1326
  "td",
1144
1327
  {
1145
1328
  className: "max-w-[200px] truncate whitespace-nowrap px-2.5 py-1 font-mono text-[11px] text-slate-700 dark:text-foreground",
1146
- title: n[s] ?? "",
1147
- children: n[s] || /* @__PURE__ */ e("span", { className: "text-slate-300", children: "—" })
1329
+ title: o[s] ?? "",
1330
+ children: o[s] || /* @__PURE__ */ e("span", { className: "text-slate-300", children: "—" })
1148
1331
  },
1149
1332
  s
1150
1333
  )) }, p)
1151
1334
  )) })
1152
1335
  ] }) });
1153
1336
  }
1154
- function Lt({ jobId: c, onClose: o }) {
1155
- var x, $;
1156
- const n = ot(), p = se(), s = (x = L({
1157
- queryKey: ["collection-import-job", c],
1158
- queryFn: () => p.request(Q(`/imports/${c}`)),
1159
- enabled: !!c,
1337
+ function et(n) {
1338
+ const i = te(), o = Je();
1339
+ return U({
1340
+ mutationFn: (p) => i.request(K(`/imports/${p}/cancel`, {})),
1341
+ onSuccess: (p, c) => {
1342
+ n(null), o.invalidateQueries({ queryKey: ["collection-import-jobs"] }), o.invalidateQueries({ queryKey: ["collection-import-job", c] });
1343
+ },
1344
+ onError: (p) => n(p)
1345
+ });
1346
+ }
1347
+ function sr({ jobId: n, onClose: i }) {
1348
+ var h, _;
1349
+ const o = Nt(), p = te(), s = (h = Q({
1350
+ queryKey: ["collection-import-job", n],
1351
+ queryFn: () => p.request(j(`/imports/${n}`)),
1352
+ enabled: !!n,
1160
1353
  refetchInterval: (d) => {
1161
- var i, u, y, h;
1162
- return ((u = (i = d.state.data) == null ? void 0 : i.data) == null ? void 0 : u.status) === "processing" || ((h = (y = d.state.data) == null ? void 0 : y.data) == null ? void 0 : h.status) === "pending" ? 2e3 : !1;
1354
+ var S, v, O, E;
1355
+ return ((v = (S = d.state.data) == null ? void 0 : S.data) == null ? void 0 : v.status) === "processing" || ((E = (O = d.state.data) == null ? void 0 : O.data) == null ? void 0 : E.status) === "pending" ? 2e3 : !1;
1163
1356
  }
1164
- }).data) == null ? void 0 : x.data, k = Array.isArray(s == null ? void 0 : s.errors) ? s.errors : [], q = s != null && s.total_rows ? Math.min(100, Math.round((s.processed_rows ?? 0) / s.total_rows * 100)) : (s == null ? void 0 : s.status) === "complete" ? 100 : 0;
1165
- return /* @__PURE__ */ e(St, { open: !!c, onOpenChange: (d) => !d && o(), children: /* @__PURE__ */ e(Pt, { side: "right", className: "w-[min(560px,94vw)] p-0 sm:max-w-none", children: s ? /* @__PURE__ */ a("div", { className: "flex h-full flex-col", children: [
1166
- /* @__PURE__ */ a("header", { className: "shrink-0 border-b border-slate-200 px-5 py-4 dark:border-border", children: [
1167
- /* @__PURE__ */ e(Le, { status: s.status }),
1357
+ }).data) == null ? void 0 : h.data, [k, T] = g(null), x = et(
1358
+ (d) => T(d ? ve(d, "The import could not be stopped") : null)
1359
+ ), C = Xe(), b = Array.isArray(s == null ? void 0 : s.errors) ? s.errors : [], m = s != null && s.total_rows ? Math.min(100, Math.round((s.processed_rows ?? 0) / s.total_rows * 100)) : (s == null ? void 0 : s.status) === "complete" ? 100 : 0;
1360
+ return /* @__PURE__ */ e(Kt, { open: !!n, onOpenChange: (d) => !d && i(), children: /* @__PURE__ */ e(Qt, { side: "right", className: "w-[min(560px,94vw)] p-0 sm:max-w-none", children: s ? /* @__PURE__ */ r("div", { className: "flex h-full flex-col", children: [
1361
+ /* @__PURE__ */ r("header", { className: "shrink-0 border-b border-slate-200 px-5 py-4 dark:border-border", children: [
1362
+ /* @__PURE__ */ e(Ze, { status: s.status }),
1168
1363
  /* @__PURE__ */ e("h2", { className: "mt-1.5 truncate font-mono text-[15px] font-semibold text-slate-900 dark:text-foreground", children: s.file_name }),
1169
- /* @__PURE__ */ a("p", { className: "text-[11.5px] text-slate-400", children: [
1364
+ /* @__PURE__ */ r("p", { className: "text-[11.5px] text-slate-400", children: [
1170
1365
  "into ",
1171
1366
  /* @__PURE__ */ e("span", { className: "font-mono", children: s.collection }),
1172
1367
  " ·",
1173
1368
  " ",
1174
- ae(s.created_at)
1175
- ] })
1369
+ ne(s.created_at)
1370
+ ] }),
1371
+ /* @__PURE__ */ r("div", { className: "mt-3 flex flex-wrap items-center gap-2", children: [
1372
+ ke.has(s.status) && /* @__PURE__ */ r(
1373
+ qt,
1374
+ {
1375
+ onConfirm: () => x.mutate(String(s.id)),
1376
+ disabled: x.isPending,
1377
+ title: "Stop this import",
1378
+ confirmLabel: "Stop now? Written rows stay",
1379
+ className: "relative inline-flex h-7 items-center gap-1.5 rounded-md border border-red-200 bg-white px-2.5 text-[12px] font-medium text-red-700 transition-colors hover:bg-red-50 disabled:opacity-50 dark:border-red-500/30 dark:bg-card dark:text-red-400 dark:hover:bg-red-500/10",
1380
+ armedClassName: "border-red-500 bg-red-600 text-white hover:bg-red-700 dark:bg-red-600 dark:text-white dark:hover:bg-red-700",
1381
+ children: [
1382
+ x.isPending ? /* @__PURE__ */ e(Y, { className: "h-3.5 w-3.5 animate-spin" }) : /* @__PURE__ */ e(Ve, { className: "h-3.5 w-3.5" }),
1383
+ "Stop import"
1384
+ ]
1385
+ }
1386
+ ),
1387
+ /* @__PURE__ */ r(
1388
+ F,
1389
+ {
1390
+ size: "sm",
1391
+ variant: "outline",
1392
+ className: "h-7",
1393
+ disabled: !!C.busy,
1394
+ onClick: () => void C.download(
1395
+ `/imports/${s.id}/file`,
1396
+ s.file_name || "import.csv"
1397
+ ),
1398
+ "data-tip": "The file as it was uploaded",
1399
+ children: [
1400
+ C.busy ? /* @__PURE__ */ e(Y, { className: "h-3.5 w-3.5 animate-spin" }) : /* @__PURE__ */ e(We, { className: "h-3.5 w-3.5" }),
1401
+ "Download file"
1402
+ ]
1403
+ }
1404
+ )
1405
+ ] }),
1406
+ (k || C.error) && /* @__PURE__ */ e("p", { className: "mt-2 text-[11.5px] text-red-600 dark:text-red-400", children: k ?? `Could not download the file: ${C.error}` }),
1407
+ s.status === "cancelled" && /* @__PURE__ */ e("p", { className: "mt-2 text-[11.5px] leading-snug text-amber-700 dark:text-amber-400", children: "This import was stopped. Rows it wrote before stopping stay — roll it back from the job list to undo them." })
1176
1408
  ] }),
1177
- /* @__PURE__ */ a("div", { className: "min-h-0 flex-1 space-y-5 overflow-y-auto px-5 py-4", children: [
1178
- /* @__PURE__ */ a("section", { className: "space-y-2", children: [
1179
- /* @__PURE__ */ a("div", { className: "flex items-center justify-between", children: [
1409
+ /* @__PURE__ */ r("div", { className: "min-h-0 flex-1 space-y-5 overflow-y-auto px-5 py-4", children: [
1410
+ /* @__PURE__ */ r("section", { className: "space-y-2", children: [
1411
+ /* @__PURE__ */ r("div", { className: "flex items-center justify-between", children: [
1180
1412
  /* @__PURE__ */ e("h3", { className: "text-[11.5px] font-semibold text-slate-500 dark:text-muted-foreground", children: "Progress" }),
1181
- /* @__PURE__ */ a("span", { className: "text-[12px] font-medium tabular-nums text-slate-700 dark:text-foreground", children: [
1182
- q,
1413
+ /* @__PURE__ */ r("span", { className: "text-[12px] font-medium tabular-nums text-slate-700 dark:text-foreground", children: [
1414
+ m,
1183
1415
  "%"
1184
1416
  ] })
1185
1417
  ] }),
1186
1418
  /* @__PURE__ */ e("div", { className: "h-2 overflow-hidden rounded-full bg-slate-100 dark:bg-muted", children: /* @__PURE__ */ e(
1187
1419
  "div",
1188
1420
  {
1189
- className: v(
1421
+ className: y(
1190
1422
  "h-full rounded-full transition-[width] duration-500",
1191
- s.status === "failed" ? "bg-red-500" : "bg-nvr-cyan"
1423
+ s.status === "failed" ? "bg-red-500" : s.status === "cancelled" ? "bg-amber-500" : "bg-nvr-cyan"
1192
1424
  ),
1193
- style: { width: `${q}%` }
1425
+ style: { width: `${m}%` }
1194
1426
  }
1195
1427
  ) }),
1196
- /* @__PURE__ */ a("p", { className: "text-[11.5px] text-slate-500 dark:text-muted-foreground", children: [
1428
+ /* @__PURE__ */ r("p", { className: "text-[11.5px] text-slate-500 dark:text-muted-foreground", children: [
1197
1429
  P(s.processed_rows ?? 0),
1198
1430
  " of",
1199
1431
  " ",
@@ -1206,12 +1438,12 @@ function Lt({ jobId: c, onClose: o }) {
1206
1438
  { label: "Updated", value: s.updated_rows ?? 0 },
1207
1439
  { label: "Skipped", value: s.skipped_rows ?? 0 },
1208
1440
  { label: "Errors", value: s.error_rows ?? 0, bad: (s.error_rows ?? 0) > 0 }
1209
- ].map((d) => /* @__PURE__ */ a("div", { className: "bg-white px-3 py-2 dark:bg-card", children: [
1441
+ ].map((d) => /* @__PURE__ */ r("div", { className: "bg-white px-3 py-2 dark:bg-card", children: [
1210
1442
  /* @__PURE__ */ e("p", { className: "text-[10.5px] text-slate-400", children: d.label }),
1211
1443
  /* @__PURE__ */ e(
1212
1444
  "p",
1213
1445
  {
1214
- className: v(
1446
+ className: y(
1215
1447
  "text-[15px] font-semibold tabular-nums",
1216
1448
  d.bad ? "text-red-600 dark:text-red-400" : "text-slate-900 dark:text-foreground"
1217
1449
  ),
@@ -1219,7 +1451,7 @@ function Lt({ jobId: c, onClose: o }) {
1219
1451
  }
1220
1452
  )
1221
1453
  ] }, d.label)) }),
1222
- /* @__PURE__ */ a("section", { children: [
1454
+ /* @__PURE__ */ r("section", { children: [
1223
1455
  /* @__PURE__ */ e("h3", { className: "mb-1 text-[11.5px] font-semibold text-slate-500 dark:text-muted-foreground", children: "Settings" }),
1224
1456
  [
1225
1457
  { label: "Duplicates", value: s.duplicate_strategy },
@@ -1227,16 +1459,19 @@ function Lt({ jobId: c, onClose: o }) {
1227
1459
  label: "Written",
1228
1460
  value: s.through_items ? "Through the items service" : "Directly (raw)"
1229
1461
  },
1230
- { label: "Matched on", value: s.id_field ?? "— always create" },
1462
+ {
1463
+ label: "Matched on",
1464
+ value: (s.match_fields ?? Ge(s.id_field)).join(" + ") || "— always create"
1465
+ },
1231
1466
  {
1232
1467
  label: "Started",
1233
- value: s.started_at ? ae(s.started_at) : "—"
1468
+ value: s.started_at ? ne(s.started_at) : "—"
1234
1469
  },
1235
1470
  {
1236
1471
  label: "Completed",
1237
- value: s.completed_at ? ae(s.completed_at) : "—"
1472
+ value: s.completed_at ? ne(s.completed_at) : "—"
1238
1473
  }
1239
- ].map((d) => /* @__PURE__ */ a(
1474
+ ].map((d) => /* @__PURE__ */ r(
1240
1475
  "div",
1241
1476
  {
1242
1477
  className: "flex items-baseline justify-between gap-4 border-b border-slate-100 py-1.5 last:border-b-0 dark:border-border/60",
@@ -1248,28 +1483,28 @@ function Lt({ jobId: c, onClose: o }) {
1248
1483
  d.label
1249
1484
  ))
1250
1485
  ] }),
1251
- s.column_map && Object.keys(s.column_map).length > 0 && /* @__PURE__ */ a("section", { children: [
1486
+ s.column_map && Object.keys(s.column_map).length > 0 && /* @__PURE__ */ r("section", { children: [
1252
1487
  /* @__PURE__ */ e("h3", { className: "mb-1.5 text-[11.5px] font-semibold text-slate-500 dark:text-muted-foreground", children: "Column mapping" }),
1253
- /* @__PURE__ */ e("div", { className: "overflow-hidden rounded-md border border-slate-200 dark:border-border", children: Object.entries(s.column_map).map(([d, i]) => /* @__PURE__ */ a(
1488
+ /* @__PURE__ */ e("div", { className: "overflow-hidden rounded-md border border-slate-200 dark:border-border", children: Object.entries(s.column_map).map(([d, S]) => /* @__PURE__ */ r(
1254
1489
  "div",
1255
1490
  {
1256
1491
  className: "flex items-center gap-2 border-b border-slate-100 px-3 py-1.5 font-mono text-[11.5px] last:border-b-0 dark:border-border/60",
1257
1492
  children: [
1258
1493
  /* @__PURE__ */ e("span", { className: "flex-1 truncate text-slate-500 dark:text-muted-foreground", children: d }),
1259
- /* @__PURE__ */ e(Ee, { className: "h-3 w-3 shrink-0 text-slate-300" }),
1260
- /* @__PURE__ */ e("span", { className: "flex-1 truncate text-slate-800 dark:text-foreground", children: i || /* @__PURE__ */ e("span", { className: "font-sans text-slate-400", children: "skipped" }) })
1494
+ /* @__PURE__ */ e(je, { className: "h-3 w-3 shrink-0 text-slate-300" }),
1495
+ /* @__PURE__ */ e("span", { className: "flex-1 truncate text-slate-800 dark:text-foreground", children: S || /* @__PURE__ */ e("span", { className: "font-sans text-slate-400", children: "skipped" }) })
1261
1496
  ]
1262
1497
  },
1263
1498
  d
1264
1499
  )) })
1265
1500
  ] }),
1266
- s.created_ids && ((($ = s.created_ids) == null ? void 0 : $.length) ?? 0) > 0 && /* @__PURE__ */ e("section", { children: /* @__PURE__ */ a(
1501
+ s.created_ids && (((_ = s.created_ids) == null ? void 0 : _.length) ?? 0) > 0 && /* @__PURE__ */ e("section", { children: /* @__PURE__ */ r(
1267
1502
  "button",
1268
1503
  {
1269
1504
  type: "button",
1270
1505
  onClick: () => {
1271
1506
  const d = (s.created_ids ?? []).map(String).join(",");
1272
- n.navigate(
1507
+ o.navigate(
1273
1508
  `/collections/${s.collection}?ids=${encodeURIComponent(d)}`
1274
1509
  );
1275
1510
  },
@@ -1285,102 +1520,105 @@ function Lt({ jobId: c, onClose: o }) {
1285
1520
  ]
1286
1521
  }
1287
1522
  ) }),
1288
- k.length > 0 && /* @__PURE__ */ e(zt, { jobId: String(s.id), errors: k })
1523
+ b.length > 0 && /* @__PURE__ */ e(lr, { jobId: String(s.id), errors: b })
1289
1524
  ] })
1290
1525
  ] }) : /* @__PURE__ */ e("div", { className: "p-5 text-[12.5px] text-slate-400", children: "Loading job…" }) }) });
1291
1526
  }
1292
- function zt({
1293
- jobId: c,
1294
- errors: o
1527
+ function lr({
1528
+ jobId: n,
1529
+ errors: i
1295
1530
  }) {
1296
- const n = se(), [p, m] = g({}), [s, k] = g({}), { data: q } = L({
1297
- queryKey: ["import-failed-rows", c],
1298
- queryFn: () => n.request(
1299
- Q(`/imports/${c}/failed-rows`)
1300
- ).then((i) => i.data ?? []),
1531
+ const o = te(), [p, c] = g({}), [s, k] = g({}), { data: T } = Q({
1532
+ queryKey: ["import-failed-rows", n],
1533
+ queryFn: () => o.request(
1534
+ j(`/imports/${n}/failed-rows`)
1535
+ ).then((m) => m.data ?? []),
1301
1536
  staleTime: 3e4
1302
- }), x = q ?? [], $ = x[0] ? Object.keys(x[0].values) : [], d = K({
1303
- mutationFn: ({ row: i, values: u }) => n.request(I(`/imports/${c}/repair-row`, { values: u })).then(() => i),
1304
- onSuccess: (i) => k((u) => ({ ...u, [i]: "ok" })),
1305
- onError: (i, u) => k((y) => ({ ...y, [u.row]: it(i, "The row was not created") }))
1537
+ }), x = T ?? [], C = x[0] ? Object.keys(x[0].values) : [], b = U({
1538
+ mutationFn: ({ row: m, values: h }) => o.request(K(`/imports/${n}/repair-row`, { values: h })).then(() => m),
1539
+ onSuccess: (m) => k((h) => ({ ...h, [m]: "ok" })),
1540
+ onError: (m, h) => k((_) => ({ ..._, [h.row]: ve(m, "The row was not created") }))
1306
1541
  });
1307
- return x.length === 0 ? /* @__PURE__ */ a("section", { children: [
1308
- /* @__PURE__ */ a("h3", { className: "mb-1.5 text-[11.5px] font-semibold text-red-700 dark:text-red-400", children: [
1542
+ return x.length === 0 ? /* @__PURE__ */ r("section", { children: [
1543
+ /* @__PURE__ */ r("h3", { className: "mb-1.5 text-[11.5px] font-semibold text-red-700 dark:text-red-400", children: [
1309
1544
  "Row errors (",
1310
- o.length,
1545
+ i.length,
1311
1546
  ")"
1312
1547
  ] }),
1313
- /* @__PURE__ */ e("div", { className: "max-h-[200px] overflow-auto rounded-md border border-red-200 dark:border-red-900", children: o.map((i) => /* @__PURE__ */ e(
1548
+ /* @__PURE__ */ e("div", { className: "max-h-[200px] overflow-auto rounded-md border border-red-200 dark:border-red-900", children: i.map((m) => /* @__PURE__ */ e(
1314
1549
  "div",
1315
1550
  {
1316
1551
  className: "flex gap-3 border-b border-red-100 px-3 py-1.5 text-[11.5px] last:border-b-0 dark:border-red-900/60",
1317
- children: /* @__PURE__ */ a("span", { className: "text-red-700 dark:text-red-400", children: [
1318
- /* @__PURE__ */ a("span", { className: "font-medium tabular-nums", children: [
1552
+ children: /* @__PURE__ */ r("span", { className: "text-red-700 dark:text-red-400", children: [
1553
+ /* @__PURE__ */ r("span", { className: "font-medium tabular-nums", children: [
1319
1554
  "Row ",
1320
- i.row,
1555
+ m.row,
1321
1556
  ":"
1322
1557
  ] }),
1323
1558
  " ",
1324
- Ae(i.error)
1559
+ ze(m.error)
1325
1560
  ] })
1326
1561
  },
1327
- `${i.row}-${i.error}`
1562
+ `${m.row}-${m.error}`
1328
1563
  )) })
1329
- ] }) : /* @__PURE__ */ a("section", { children: [
1330
- /* @__PURE__ */ a("h3", { className: "mb-1.5 text-[11.5px] font-semibold text-red-700 dark:text-red-400", children: [
1564
+ ] }) : /* @__PURE__ */ r("section", { children: [
1565
+ /* @__PURE__ */ r("h3", { className: "mb-1.5 text-[11.5px] font-semibold text-red-700 dark:text-red-400", children: [
1331
1566
  "Failed rows (",
1332
1567
  x.length,
1333
1568
  ") — fix and resubmit"
1334
1569
  ] }),
1335
- /* @__PURE__ */ e("div", { className: "max-h-[320px] overflow-auto rounded-md border border-red-200 dark:border-red-900", children: /* @__PURE__ */ a("table", { className: "w-full text-[11.5px]", children: [
1336
- /* @__PURE__ */ e("thead", { children: /* @__PURE__ */ a("tr", { className: "bg-red-50/60 text-left text-[10px] uppercase tracking-wide text-slate-400 dark:bg-red-950/30", children: [
1570
+ /* @__PURE__ */ e("div", { className: "max-h-[320px] overflow-auto rounded-md border border-red-200 dark:border-red-900", children: /* @__PURE__ */ r("table", { className: "w-full text-[11.5px]", children: [
1571
+ /* @__PURE__ */ e("thead", { children: /* @__PURE__ */ r("tr", { className: "bg-red-50/60 text-left text-[10px] uppercase tracking-wide text-slate-400 dark:bg-red-950/30", children: [
1337
1572
  /* @__PURE__ */ e("th", { className: "px-2 py-1", children: "Row" }),
1338
- $.map((i) => /* @__PURE__ */ e("th", { className: "px-2 py-1 font-mono normal-case", children: i }, i)),
1573
+ C.map((m) => /* @__PURE__ */ e("th", { className: "px-2 py-1 font-mono normal-case", children: m }, m)),
1339
1574
  /* @__PURE__ */ e("th", { className: "px-2 py-1" })
1340
1575
  ] }) }),
1341
- /* @__PURE__ */ e("tbody", { children: x.map((i) => {
1342
- const u = p[i.row] ?? i.values, y = s[i.row];
1343
- return /* @__PURE__ */ a(
1576
+ /* @__PURE__ */ e("tbody", { children: x.map((m) => {
1577
+ const h = p[m.row] ?? m.values, _ = s[m.row];
1578
+ return /* @__PURE__ */ r(
1344
1579
  "tr",
1345
1580
  {
1346
1581
  className: "border-t border-red-100 align-top dark:border-red-900/50",
1347
1582
  children: [
1348
- /* @__PURE__ */ a("td", { className: "px-2 py-1 font-mono tabular-nums text-slate-400", children: [
1349
- i.row,
1350
- /* @__PURE__ */ e("p", { className: "max-w-[120px] whitespace-normal text-[10px] text-red-500", children: Ae(i.error) })
1583
+ /* @__PURE__ */ r("td", { className: "px-2 py-1 font-mono tabular-nums text-slate-400", children: [
1584
+ m.row,
1585
+ /* @__PURE__ */ e("p", { className: "max-w-[120px] whitespace-normal text-[10px] text-red-500", children: ze(m.error) })
1351
1586
  ] }),
1352
- $.map((h) => /* @__PURE__ */ e("td", { className: "px-1 py-1", children: /* @__PURE__ */ e(
1587
+ C.map((d) => /* @__PURE__ */ e("td", { className: "px-1 py-1", children: /* @__PURE__ */ e(
1353
1588
  "input",
1354
1589
  {
1355
- value: String(u[h] ?? ""),
1356
- disabled: y === "ok",
1357
- onChange: (D) => m((C) => ({ ...C, [i.row]: { ...u, [h]: D.target.value } })),
1590
+ value: String(h[d] ?? ""),
1591
+ disabled: _ === "ok",
1592
+ onChange: (S) => c((v) => ({ ...v, [m.row]: { ...h, [d]: S.target.value } })),
1358
1593
  className: "h-6 w-full min-w-[80px] rounded border border-slate-200 bg-background px-1 text-[11px] dark:border-border"
1359
1594
  }
1360
- ) }, h)),
1361
- /* @__PURE__ */ e("td", { className: "px-2 py-1", children: y === "ok" ? /* @__PURE__ */ e("span", { className: "text-[10.5px] font-medium text-emerald-600", children: "✓ Created" }) : /* @__PURE__ */ a("div", { children: [
1595
+ ) }, d)),
1596
+ /* @__PURE__ */ e("td", { className: "px-2 py-1", children: _ === "ok" ? /* @__PURE__ */ e("span", { className: "text-[10.5px] font-medium text-emerald-600", children: "✓ Created" }) : /* @__PURE__ */ r("div", { children: [
1362
1597
  /* @__PURE__ */ e(
1363
1598
  "button",
1364
1599
  {
1365
1600
  type: "button",
1366
- disabled: d.isPending,
1367
- onClick: () => d.mutate({ row: i.row, values: u }),
1601
+ disabled: b.isPending,
1602
+ onClick: () => b.mutate({ row: m.row, values: h }),
1368
1603
  className: "rounded border border-slate-200 px-1.5 py-0.5 text-[10.5px] hover:bg-muted disabled:opacity-50 dark:border-border",
1369
1604
  children: "Resubmit"
1370
1605
  }
1371
1606
  ),
1372
- y && y !== "ok" && /* @__PURE__ */ e("p", { className: "max-w-[140px] whitespace-normal text-[9.5px] text-red-500", children: y })
1607
+ _ && _ !== "ok" && /* @__PURE__ */ e("p", { className: "max-w-[140px] whitespace-normal text-[9.5px] text-red-500", children: _ })
1373
1608
  ] }) })
1374
1609
  ]
1375
1610
  },
1376
- i.row
1611
+ m.row
1377
1612
  );
1378
1613
  }) })
1379
1614
  ] }) })
1380
1615
  ] });
1381
1616
  }
1382
1617
  export {
1383
- da as CollectionImportPanel,
1384
- Tt as ROLLBACK_QUESTION,
1385
- At as RollbackJobItem
1618
+ Mr as CollectionImportPanel,
1619
+ Gt as ROLLBACK_QUESTION,
1620
+ Xt as RollbackJobItem,
1621
+ ke as STOPPABLE,
1622
+ Ht as STOP_QUESTION,
1623
+ Yt as StopJobItem
1386
1624
  };