@matija2209/payload-plugin-admin-feedback 1.0.0 → 1.0.3

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.
@@ -0,0 +1,2851 @@
1
+ 'use strict';
2
+
3
+ var lucideReact = require('lucide-react');
4
+ var React2 = require('react');
5
+ var jsxRuntime = require('react/jsx-runtime');
6
+ var navigation = require('next/navigation');
7
+
8
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
+
10
+ var React2__default = /*#__PURE__*/_interopDefault(React2);
11
+
12
+ // src/client/FeedbackWidget.tsx
13
+
14
+ // src/client/ui.ts
15
+ var theme = {
16
+ accent: "#5eead4",
17
+ text: "#f8fafc",
18
+ textSoft: "rgba(226, 232, 240, 0.78)",
19
+ textMuted: "rgba(148, 163, 184, 0.78)",
20
+ dangerSoft: "rgba(248, 113, 113, 0.18)",
21
+ border: "rgba(148, 163, 184, 0.18)",
22
+ borderStrong: "rgba(148, 163, 184, 0.28)",
23
+ panel: "linear-gradient(180deg, rgba(15, 23, 42, 0.96) 0%, rgba(6, 13, 24, 0.96) 100%)",
24
+ card: "linear-gradient(180deg, rgba(30, 41, 59, 0.54) 0%, rgba(15, 23, 42, 0.7) 100%)",
25
+ inset: "rgba(15, 23, 42, 0.82)",
26
+ shadow: "0 28px 70px rgba(2, 8, 23, 0.48)",
27
+ subtleShadow: "0 18px 40px rgba(2, 8, 23, 0.24)"
28
+ };
29
+ var floatingLauncherStyle = {
30
+ position: "fixed",
31
+ right: "20px",
32
+ bottom: "20px",
33
+ zIndex: 9999,
34
+ display: "inline-flex",
35
+ alignItems: "center",
36
+ gap: "8px",
37
+ borderRadius: "999px",
38
+ border: `1px solid ${theme.borderStrong}`,
39
+ background: "linear-gradient(135deg, rgba(45, 212, 191, 0.96) 0%, rgba(15, 118, 110, 0.96) 100%)",
40
+ color: "#03131f",
41
+ padding: "10px 14px",
42
+ fontWeight: 700,
43
+ fontSize: "13px",
44
+ letterSpacing: "-0.01em",
45
+ cursor: "pointer",
46
+ boxShadow: "0 24px 55px rgba(15, 118, 110, 0.34)"
47
+ };
48
+ var panelStyle = {
49
+ position: "fixed",
50
+ right: "12px",
51
+ bottom: "calc(12px + env(safe-area-inset-bottom, 0px))",
52
+ width: "min(396px, calc(100vw - 24px))",
53
+ maxHeight: "min(780px, calc(100dvh - 24px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)))",
54
+ height: "min(780px, calc(100dvh - 24px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)))",
55
+ overflow: "hidden",
56
+ display: "flex",
57
+ flexDirection: "column",
58
+ overscrollBehavior: "contain",
59
+ background: theme.panel,
60
+ color: theme.text,
61
+ borderRadius: "22px",
62
+ border: `1px solid ${theme.border}`,
63
+ zIndex: 9999,
64
+ boxShadow: theme.shadow,
65
+ backdropFilter: "blur(18px)"
66
+ };
67
+ var panelHeaderStyle = {
68
+ padding: "14px 14px 12px",
69
+ borderBottom: `1px solid ${theme.border}`,
70
+ background: "radial-gradient(circle at top right, rgba(45, 212, 191, 0.14), transparent 38%), transparent"
71
+ };
72
+ var surfaceCardStyle = {
73
+ background: theme.card,
74
+ border: `1px solid ${theme.border}`,
75
+ borderRadius: "16px",
76
+ boxShadow: theme.subtleShadow
77
+ };
78
+ var innerCardStyle = {
79
+ background: theme.inset,
80
+ border: `1px solid ${theme.border}`,
81
+ borderRadius: "14px"
82
+ };
83
+ var fieldStyle = {
84
+ width: "100%",
85
+ borderRadius: "14px",
86
+ border: `1px solid ${theme.border}`,
87
+ background: "rgba(15, 23, 42, 0.86)",
88
+ color: theme.text,
89
+ padding: "12px 14px",
90
+ fontSize: "13px",
91
+ lineHeight: 1.5,
92
+ outline: "none",
93
+ boxSizing: "border-box",
94
+ boxShadow: "inset 0 1px 0 rgba(255,255,255,0.03)"
95
+ };
96
+ var metaTextStyle = {
97
+ margin: 0,
98
+ fontSize: "12px",
99
+ lineHeight: 1.5,
100
+ color: theme.textMuted
101
+ };
102
+ var sectionLabelStyle = {
103
+ margin: 0,
104
+ fontSize: "11px",
105
+ fontWeight: 700,
106
+ letterSpacing: "0.08em",
107
+ textTransform: "uppercase",
108
+ color: theme.textMuted
109
+ };
110
+ var statusTextStyle = {
111
+ margin: 0,
112
+ fontSize: "12px",
113
+ lineHeight: 1.5,
114
+ color: theme.textSoft
115
+ };
116
+ function buttonStyle(variant, options = {}) {
117
+ const { active = false, disabled = false, iconOnly = false, compact = false, justify = "center" } = options;
118
+ const base = {
119
+ display: "inline-flex",
120
+ alignItems: "center",
121
+ justifyContent: justify,
122
+ gap: "8px",
123
+ minHeight: compact ? "32px" : "38px",
124
+ padding: iconOnly ? compact ? "7px" : "9px" : compact ? "7px 11px" : "9px 13px",
125
+ borderRadius: iconOnly ? "12px" : "14px",
126
+ border: `1px solid ${theme.border}`,
127
+ color: theme.text,
128
+ cursor: disabled ? "not-allowed" : "pointer",
129
+ fontSize: compact ? "12px" : "13px",
130
+ fontWeight: 600,
131
+ letterSpacing: "-0.01em",
132
+ transition: "transform 0.18s ease, opacity 0.18s ease, border-color 0.18s ease",
133
+ opacity: disabled ? 0.45 : 1,
134
+ boxSizing: "border-box"
135
+ };
136
+ const variants = {
137
+ primary: {
138
+ background: "linear-gradient(135deg, rgba(94, 234, 212, 0.98) 0%, rgba(20, 184, 166, 0.98) 100%)",
139
+ borderColor: "rgba(153, 246, 228, 0.38)",
140
+ color: "#04111c",
141
+ boxShadow: "0 18px 35px rgba(20, 184, 166, 0.22)"
142
+ },
143
+ secondary: {
144
+ background: active ? "rgba(94, 234, 212, 0.14)" : theme.card,
145
+ borderColor: active ? "rgba(94, 234, 212, 0.34)" : theme.border,
146
+ color: active ? "#d1fae5" : theme.text
147
+ },
148
+ ghost: {
149
+ background: active ? "rgba(94, 234, 212, 0.12)" : "transparent",
150
+ borderColor: active ? "rgba(94, 234, 212, 0.28)" : "transparent",
151
+ color: active ? theme.text : theme.textSoft
152
+ },
153
+ danger: {
154
+ background: active ? "rgba(248, 113, 113, 0.18)" : theme.dangerSoft,
155
+ borderColor: "rgba(248, 113, 113, 0.28)",
156
+ color: "#fecaca"
157
+ }
158
+ };
159
+ return { ...base, ...variants[variant] };
160
+ }
161
+ function pillStyle(variant) {
162
+ const variants = {
163
+ neutral: {
164
+ background: "rgba(148, 163, 184, 0.16)",
165
+ color: theme.textSoft,
166
+ border: `1px solid ${theme.border}`
167
+ },
168
+ success: {
169
+ background: "rgba(34, 197, 94, 0.16)",
170
+ color: "#86efac",
171
+ border: "1px solid rgba(34, 197, 94, 0.24)"
172
+ },
173
+ warning: {
174
+ background: "rgba(234, 179, 8, 0.18)",
175
+ color: "#fde68a",
176
+ border: "1px solid rgba(234, 179, 8, 0.24)"
177
+ },
178
+ muted: {
179
+ background: "rgba(148, 163, 184, 0.16)",
180
+ color: "#cbd5e1",
181
+ border: `1px solid ${theme.border}`
182
+ },
183
+ danger: {
184
+ background: theme.dangerSoft,
185
+ color: "#fecaca",
186
+ border: "1px solid rgba(248, 113, 113, 0.24)"
187
+ }
188
+ };
189
+ return {
190
+ display: "inline-flex",
191
+ alignItems: "center",
192
+ gap: "6px",
193
+ borderRadius: "999px",
194
+ padding: "5px 10px",
195
+ fontSize: "11px",
196
+ fontWeight: 700,
197
+ letterSpacing: "0.01em",
198
+ ...variants[variant]
199
+ };
200
+ }
201
+ var formatDate = (iso) => {
202
+ try {
203
+ return new Date(iso).toLocaleString("en-US", {
204
+ month: "short",
205
+ day: "numeric",
206
+ year: "numeric",
207
+ hour: "2-digit",
208
+ minute: "2-digit"
209
+ });
210
+ } catch {
211
+ return iso;
212
+ }
213
+ };
214
+ var getScreenshotInfo = (feedback) => {
215
+ if (!feedback.screenshot || typeof feedback.screenshot !== "object") return null;
216
+ const screenshot = feedback.screenshot;
217
+ if (screenshot.url) return { id: screenshot.id, url: screenshot.url };
218
+ if (screenshot.filename) return { id: screenshot.id, url: screenshot.filename };
219
+ return null;
220
+ };
221
+ var getCreatorId = (feedback) => {
222
+ if (!feedback.createdBy) return null;
223
+ if (typeof feedback.createdBy === "object") return feedback.createdBy.id;
224
+ return feedback.createdBy;
225
+ };
226
+ var canvasToFile = async (canvas, fileName = `feedback-${Date.now()}.png`) => {
227
+ const blob = await new Promise((resolve) => {
228
+ canvas.toBlob((nextBlob) => resolve(nextBlob), "image/png");
229
+ });
230
+ if (!blob) throw new Error("Failed to prepare screenshot.");
231
+ return new File([blob], fileName.replace(/\.[a-z0-9]+$/i, "") + ".png", { type: "image/png" });
232
+ };
233
+ var captureScreenshotFile = async () => {
234
+ if (!navigator.mediaDevices?.getDisplayMedia) {
235
+ throw new Error("Browser does not support screen capture.");
236
+ }
237
+ const stream = await navigator.mediaDevices.getDisplayMedia({
238
+ video: { displaySurface: "browser" },
239
+ audio: false,
240
+ preferCurrentTab: true
241
+ });
242
+ const track = stream.getVideoTracks()[0];
243
+ if (!track) {
244
+ stream.getTracks().forEach((nextTrack) => nextTrack.stop());
245
+ throw new Error("Screen capture failed.");
246
+ }
247
+ const video = document.createElement("video");
248
+ try {
249
+ video.srcObject = stream;
250
+ video.muted = true;
251
+ video.playsInline = true;
252
+ await video.play();
253
+ await new Promise((resolve) => {
254
+ if ("requestVideoFrameCallback" in video) {
255
+ video.requestVideoFrameCallback(() => resolve());
256
+ } else {
257
+ requestAnimationFrame(() => resolve());
258
+ }
259
+ });
260
+ const width = video.videoWidth || window.innerWidth;
261
+ const height = video.videoHeight || window.innerHeight;
262
+ if (!width || !height) throw new Error("Screen capture failed.");
263
+ const canvas = document.createElement("canvas");
264
+ canvas.width = width;
265
+ canvas.height = height;
266
+ const context = canvas.getContext("2d");
267
+ if (!context) throw new Error("Browser does not support canvas context.");
268
+ context.drawImage(video, 0, 0, width, height);
269
+ return canvasToFile(canvas);
270
+ } finally {
271
+ video.pause();
272
+ video.srcObject = null;
273
+ stream.getTracks().forEach((nextTrack) => nextTrack.stop());
274
+ }
275
+ };
276
+ function FeedbackDetail({
277
+ feedback,
278
+ currentUserId,
279
+ capturePolicy: _capturePolicy,
280
+ onBack,
281
+ onUpdate,
282
+ onDelete,
283
+ onUpload,
284
+ onDeleteScreenshot
285
+ }) {
286
+ const [editing, setEditing] = React2__default.default.useState(false);
287
+ const [message, setMessage] = React2__default.default.useState(feedback.message);
288
+ const [screenshotId, setScreenshotId] = React2__default.default.useState(getScreenshotInfo(feedback)?.id ?? null);
289
+ const [screenshotUrl, setScreenshotUrl] = React2__default.default.useState(getScreenshotInfo(feedback)?.url ?? null);
290
+ const [uploading, setUploading] = React2__default.default.useState(false);
291
+ const [removing, setRemoving] = React2__default.default.useState(false);
292
+ const [saving, setSaving] = React2__default.default.useState(false);
293
+ const [deleting, setDeleting] = React2__default.default.useState(false);
294
+ const [error, setError] = React2__default.default.useState(null);
295
+ const isOwner = getCreatorId(feedback) === currentUserId;
296
+ const screenshot = getScreenshotInfo(feedback);
297
+ const currentScreenshotId = screenshotId ?? screenshot?.id ?? null;
298
+ const uploadFile = async (file) => {
299
+ setUploading(true);
300
+ setError(null);
301
+ try {
302
+ const formData = new FormData();
303
+ formData.append("file", file);
304
+ formData.append("alt", file.name);
305
+ const result = await onUpload(formData);
306
+ if (!result.success) {
307
+ setError(result.error);
308
+ return null;
309
+ }
310
+ setScreenshotId(result.mediaId);
311
+ setScreenshotUrl(URL.createObjectURL(file));
312
+ return result.mediaId;
313
+ } catch (nextError) {
314
+ setError(nextError instanceof Error ? nextError.message : "Upload failed.");
315
+ return null;
316
+ } finally {
317
+ setUploading(false);
318
+ }
319
+ };
320
+ const handleRemoveScreenshot = async () => {
321
+ if (!currentScreenshotId) return;
322
+ setRemoving(true);
323
+ setError(null);
324
+ try {
325
+ const result = await onDeleteScreenshot(currentScreenshotId);
326
+ if (!result.success) {
327
+ setError(result.error);
328
+ return;
329
+ }
330
+ setScreenshotId(null);
331
+ setScreenshotUrl(null);
332
+ } catch (nextError) {
333
+ setError(nextError instanceof Error ? nextError.message : "Failed to remove screenshot.");
334
+ } finally {
335
+ setRemoving(false);
336
+ }
337
+ };
338
+ const handleCapture = async () => {
339
+ try {
340
+ const file = await captureScreenshotFile();
341
+ await uploadFile(file);
342
+ } catch (nextError) {
343
+ setError(nextError instanceof Error ? nextError.message : "Screen capture failed.");
344
+ }
345
+ };
346
+ const handleFileUpload = async (event) => {
347
+ const file = event.target.files?.[0];
348
+ if (file) await uploadFile(file);
349
+ event.target.value = "";
350
+ };
351
+ React2__default.default.useEffect(() => {
352
+ if (!editing) return;
353
+ const onPaste = async (event) => {
354
+ const file = Array.from(event.clipboardData?.items || []).find((item) => item.type.startsWith("image/"))?.getAsFile();
355
+ if (file) {
356
+ event.preventDefault();
357
+ await uploadFile(file);
358
+ }
359
+ };
360
+ window.addEventListener("paste", onPaste);
361
+ return () => window.removeEventListener("paste", onPaste);
362
+ }, [editing]);
363
+ const handleSave = async () => {
364
+ if (!message.trim()) {
365
+ setError("Message cannot be empty.");
366
+ return;
367
+ }
368
+ setSaving(true);
369
+ setError(null);
370
+ try {
371
+ const updateData = {};
372
+ if (message.trim() !== feedback.message) {
373
+ updateData.message = message.trim();
374
+ }
375
+ if ((screenshotId ?? null) !== (feedback.screenshot && typeof feedback.screenshot === "object" ? feedback.screenshot.id : feedback.screenshot)) {
376
+ updateData.screenshotId = screenshotId ?? null;
377
+ }
378
+ const success = await onUpdate(feedback.id, updateData);
379
+ if (success) {
380
+ setEditing(false);
381
+ } else {
382
+ setError("Failed to save changes.");
383
+ }
384
+ } catch (nextError) {
385
+ setError(nextError instanceof Error ? nextError.message : "Save failed.");
386
+ } finally {
387
+ setSaving(false);
388
+ }
389
+ };
390
+ const handleDelete = async () => {
391
+ if (!window.confirm("Delete this feedback? This cannot be undone.")) {
392
+ return;
393
+ }
394
+ setDeleting(true);
395
+ setError(null);
396
+ try {
397
+ const success = await onDelete(feedback.id);
398
+ if (!success) {
399
+ setError("Failed to delete feedback.");
400
+ }
401
+ } catch (nextError) {
402
+ setError(nextError instanceof Error ? nextError.message : "Delete failed.");
403
+ } finally {
404
+ setDeleting(false);
405
+ }
406
+ };
407
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "grid", gap: "12px" }, children: [
408
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between", gap: "10px" }, children: [
409
+ /* @__PURE__ */ jsxRuntime.jsxs("button", { type: "button", onClick: onBack, style: buttonStyle("ghost", { compact: true }), children: [
410
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ArrowLeft, { size: 15 }),
411
+ "Back"
412
+ ] }),
413
+ isOwner && !editing ? /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", gap: "8px", flexWrap: "wrap", justifyContent: "flex-end" }, children: [
414
+ /* @__PURE__ */ jsxRuntime.jsxs(
415
+ "button",
416
+ {
417
+ type: "button",
418
+ onClick: () => {
419
+ setEditing(true);
420
+ setError(null);
421
+ },
422
+ style: buttonStyle("secondary", { compact: true }),
423
+ children: [
424
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.PencilLine, { size: 15 }),
425
+ "Edit"
426
+ ]
427
+ }
428
+ ),
429
+ /* @__PURE__ */ jsxRuntime.jsxs(
430
+ "button",
431
+ {
432
+ type: "button",
433
+ onClick: handleDelete,
434
+ disabled: deleting,
435
+ style: buttonStyle("danger", { compact: true, disabled: deleting }),
436
+ children: [
437
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Trash2, { size: 15 }),
438
+ deleting ? "Deleting..." : "Delete"
439
+ ]
440
+ }
441
+ )
442
+ ] }) : null
443
+ ] }),
444
+ editing ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
445
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { ...surfaceCardStyle, padding: "16px" }, children: [
446
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: { ...sectionLabelStyle, marginBottom: "10px" }, children: "Message" }),
447
+ /* @__PURE__ */ jsxRuntime.jsx(
448
+ "textarea",
449
+ {
450
+ value: message,
451
+ onChange: (event) => setMessage(event.target.value),
452
+ rows: 6,
453
+ style: { ...fieldStyle, resize: "vertical", minHeight: "140px" },
454
+ placeholder: "Describe what changed or what still needs attention..."
455
+ }
456
+ )
457
+ ] }),
458
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { ...surfaceCardStyle, padding: "16px" }, children: [
459
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between", gap: "8px", marginBottom: "12px" }, children: [
460
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
461
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: sectionLabelStyle, children: "Screenshot" }),
462
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: { ...metaTextStyle, marginTop: "4px" }, children: "Paste an image, capture the current tab, or upload a replacement." })
463
+ ] }),
464
+ screenshotId ? /* @__PURE__ */ jsxRuntime.jsxs("span", { style: pillStyle("neutral"), children: [
465
+ "Media #",
466
+ screenshotId
467
+ ] }) : null
468
+ ] }),
469
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { ...innerCardStyle, overflow: "hidden" }, children: screenshotUrl ? (
470
+ // eslint-disable-next-line @next/next/no-img-element
471
+ /* @__PURE__ */ jsxRuntime.jsx(
472
+ "img",
473
+ {
474
+ src: screenshotUrl,
475
+ alt: "Screenshot",
476
+ style: { width: "100%", height: "auto", display: "block", maxHeight: "280px", objectFit: "cover" }
477
+ }
478
+ )
479
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
480
+ "div",
481
+ {
482
+ style: {
483
+ minHeight: "180px",
484
+ display: "grid",
485
+ placeItems: "center",
486
+ color: theme.textMuted,
487
+ background: "rgba(15, 23, 42, 0.72)"
488
+ },
489
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { textAlign: "center" }, children: [
490
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ImageIcon, { size: 24, style: { marginBottom: "8px" } }),
491
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: metaTextStyle, children: "No screenshot attached." })
492
+ ] })
493
+ }
494
+ ) }),
495
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", gap: "8px", flexWrap: "wrap", marginTop: "12px" }, children: [
496
+ /* @__PURE__ */ jsxRuntime.jsx(
497
+ "button",
498
+ {
499
+ type: "button",
500
+ onClick: handleCapture,
501
+ disabled: uploading,
502
+ "aria-label": uploading ? "Capturing screen" : "Capture screen",
503
+ title: uploading ? "Capturing screen" : "Capture screen",
504
+ style: buttonStyle("secondary", { compact: true, disabled: uploading, iconOnly: true }),
505
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Camera, { size: 15 })
506
+ }
507
+ ),
508
+ /* @__PURE__ */ jsxRuntime.jsxs(
509
+ "label",
510
+ {
511
+ "aria-label": "Upload image",
512
+ title: "Upload image",
513
+ style: buttonStyle("secondary", { compact: true, iconOnly: true }),
514
+ children: [
515
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Upload, { size: 15 }),
516
+ /* @__PURE__ */ jsxRuntime.jsx("input", { type: "file", accept: "image/png,image/jpeg,image/webp", onChange: handleFileUpload, hidden: true })
517
+ ]
518
+ }
519
+ ),
520
+ currentScreenshotId && screenshotUrl ? /* @__PURE__ */ jsxRuntime.jsxs("button", { type: "button", onClick: handleRemoveScreenshot, disabled: removing, style: buttonStyle("danger", { compact: true, disabled: removing }), children: [
521
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Trash2, { size: 15 }),
522
+ removing ? "Removing..." : "Remove"
523
+ ] }) : null
524
+ ] })
525
+ ] }),
526
+ error ? /* @__PURE__ */ jsxRuntime.jsx("div", { style: { ...surfaceCardStyle, padding: "12px 14px", borderColor: "rgba(248, 113, 113, 0.24)" }, children: /* @__PURE__ */ jsxRuntime.jsx("p", { style: { ...statusTextStyle, color: "#fecaca" }, children: error }) }) : null,
527
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", justifyContent: "flex-end", gap: "8px", flexWrap: "wrap" }, children: [
528
+ /* @__PURE__ */ jsxRuntime.jsxs(
529
+ "button",
530
+ {
531
+ type: "button",
532
+ onClick: () => {
533
+ setEditing(false);
534
+ setMessage(feedback.message);
535
+ setScreenshotId(screenshot?.id ?? null);
536
+ setScreenshotUrl(screenshot?.url ?? null);
537
+ setError(null);
538
+ },
539
+ style: buttonStyle("ghost"),
540
+ children: [
541
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { size: 15 }),
542
+ "Cancel"
543
+ ]
544
+ }
545
+ ),
546
+ /* @__PURE__ */ jsxRuntime.jsxs("button", { type: "button", onClick: handleSave, disabled: saving, style: buttonStyle("primary", { disabled: saving }), children: [
547
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Save, { size: 15 }),
548
+ saving ? "Saving..." : "Save changes"
549
+ ] })
550
+ ] })
551
+ ] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
552
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { ...surfaceCardStyle, padding: "18px" }, children: /* @__PURE__ */ jsxRuntime.jsx("p", { style: { margin: 0, fontSize: "15px", lineHeight: 1.7, whiteSpace: "pre-wrap", wordBreak: "break-word" }, children: feedback.message }) }),
553
+ screenshot ? /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { ...surfaceCardStyle, padding: "12px" }, children: [
554
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center", gap: "8px", marginBottom: "10px" }, children: [
555
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: sectionLabelStyle, children: "Screenshot" }),
556
+ /* @__PURE__ */ jsxRuntime.jsxs(
557
+ "button",
558
+ {
559
+ type: "button",
560
+ onClick: () => window.open(screenshot.url, "_blank"),
561
+ style: buttonStyle("ghost", { compact: true }),
562
+ children: [
563
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ExternalLink, { size: 14 }),
564
+ "Open full size"
565
+ ]
566
+ }
567
+ )
568
+ ] }),
569
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { ...innerCardStyle, overflow: "hidden" }, children: /* @__PURE__ */ jsxRuntime.jsx(
570
+ "img",
571
+ {
572
+ src: screenshot.url,
573
+ alt: "Feedback screenshot",
574
+ style: { width: "100%", height: "auto", display: "block", cursor: "pointer" },
575
+ onClick: () => window.open(screenshot.url, "_blank")
576
+ }
577
+ ) })
578
+ ] }) : null,
579
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { ...surfaceCardStyle, padding: "16px", display: "grid", gap: "12px" }, children: [
580
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
581
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: sectionLabelStyle, children: "Page" }),
582
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", alignItems: "center", gap: "8px", marginTop: "6px" }, children: [
583
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.MapPin, { size: 15, color: theme.textMuted }),
584
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: { ...metaTextStyle, wordBreak: "break-all" }, children: feedback.pagePath })
585
+ ] })
586
+ ] }),
587
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
588
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: sectionLabelStyle, children: "Created" }),
589
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", alignItems: "center", gap: "8px", marginTop: "6px" }, children: [
590
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CalendarClock, { size: 15, color: theme.textMuted }),
591
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: metaTextStyle, children: formatDate(feedback.createdAt) })
592
+ ] })
593
+ ] })
594
+ ] }),
595
+ error ? /* @__PURE__ */ jsxRuntime.jsx("div", { style: { ...surfaceCardStyle, padding: "12px 14px", borderColor: "rgba(248, 113, 113, 0.24)" }, children: /* @__PURE__ */ jsxRuntime.jsx("p", { style: { ...statusTextStyle, color: "#fecaca" }, children: error }) }) : null
596
+ ] })
597
+ ] });
598
+ }
599
+ var STATUS_VARIANTS = {
600
+ new: "success",
601
+ triaged: "warning",
602
+ resolved: "muted"
603
+ };
604
+ var STATUS_LABELS = {
605
+ new: "New",
606
+ triaged: "Triaged",
607
+ resolved: "Resolved"
608
+ };
609
+ var formatRelativeTime = (iso) => {
610
+ const now = Date.now();
611
+ const then = new Date(iso).getTime();
612
+ const diff = now - then;
613
+ const minutes = Math.floor(diff / 6e4);
614
+ if (minutes < 1) return "Just now";
615
+ if (minutes < 60) return `${minutes}m ago`;
616
+ const hours = Math.floor(minutes / 60);
617
+ if (hours < 24) return `${hours}h ago`;
618
+ const days = Math.floor(hours / 24);
619
+ if (days < 7) return `${days}d ago`;
620
+ const weeks = Math.floor(days / 7);
621
+ if (weeks < 5) return `${weeks}w ago`;
622
+ return new Date(iso).toLocaleDateString();
623
+ };
624
+ var getScreenshotThumb = (item) => {
625
+ if (!item.screenshot || typeof item.screenshot !== "object") return null;
626
+ return item.screenshot.url || null;
627
+ };
628
+ var getCreatorId2 = (createdBy) => {
629
+ if (!createdBy) return null;
630
+ if (typeof createdBy === "object") return createdBy.id;
631
+ return createdBy;
632
+ };
633
+ function FeedbackHistory({
634
+ feedbacks,
635
+ totalPages,
636
+ currentPage,
637
+ loading,
638
+ error,
639
+ currentUserId,
640
+ onSelectFeedback,
641
+ onPageChange,
642
+ onRefetch
643
+ }) {
644
+ if (loading) {
645
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { style: { display: "grid", gap: "10px" }, children: [1, 2, 3].map((item) => /* @__PURE__ */ jsxRuntime.jsx(
646
+ "div",
647
+ {
648
+ style: {
649
+ ...surfaceCardStyle,
650
+ padding: "14px"
651
+ },
652
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", gap: "12px", alignItems: "center" }, children: [
653
+ /* @__PURE__ */ jsxRuntime.jsx(
654
+ "div",
655
+ {
656
+ style: {
657
+ width: "52px",
658
+ height: "52px",
659
+ borderRadius: "14px",
660
+ background: "rgba(148, 163, 184, 0.14)",
661
+ flexShrink: 0
662
+ }
663
+ }
664
+ ),
665
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { flex: 1 }, children: [
666
+ /* @__PURE__ */ jsxRuntime.jsx(
667
+ "div",
668
+ {
669
+ style: {
670
+ height: "14px",
671
+ width: "72%",
672
+ borderRadius: "999px",
673
+ background: "rgba(148, 163, 184, 0.18)",
674
+ marginBottom: "10px"
675
+ }
676
+ }
677
+ ),
678
+ /* @__PURE__ */ jsxRuntime.jsx(
679
+ "div",
680
+ {
681
+ style: {
682
+ height: "10px",
683
+ width: "48%",
684
+ borderRadius: "999px",
685
+ background: "rgba(148, 163, 184, 0.12)"
686
+ }
687
+ }
688
+ )
689
+ ] })
690
+ ] })
691
+ },
692
+ item
693
+ )) });
694
+ }
695
+ if (error) {
696
+ return /* @__PURE__ */ jsxRuntime.jsxs(
697
+ "div",
698
+ {
699
+ style: {
700
+ ...surfaceCardStyle,
701
+ padding: "18px",
702
+ textAlign: "center"
703
+ },
704
+ children: [
705
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: { ...statusTextStyle, color: "#fecaca", marginBottom: "12px" }, children: error }),
706
+ /* @__PURE__ */ jsxRuntime.jsxs("button", { type: "button", onClick: onRefetch, style: buttonStyle("secondary"), children: [
707
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.RefreshCw, { size: 15 }),
708
+ "Retry"
709
+ ] })
710
+ ]
711
+ }
712
+ );
713
+ }
714
+ if (feedbacks.length === 0) {
715
+ return /* @__PURE__ */ jsxRuntime.jsxs(
716
+ "div",
717
+ {
718
+ style: {
719
+ ...surfaceCardStyle,
720
+ padding: "26px 18px",
721
+ textAlign: "center"
722
+ },
723
+ children: [
724
+ /* @__PURE__ */ jsxRuntime.jsx(
725
+ "div",
726
+ {
727
+ style: {
728
+ width: "44px",
729
+ height: "44px",
730
+ borderRadius: "14px",
731
+ margin: "0 auto 12px",
732
+ display: "grid",
733
+ placeItems: "center",
734
+ background: "rgba(94, 234, 212, 0.12)",
735
+ color: theme.accent
736
+ },
737
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.MessageSquareText, { size: 20 })
738
+ }
739
+ ),
740
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: { margin: "0 0 4px", fontSize: "14px", fontWeight: 600 }, children: "No feedback yet" }),
741
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: metaTextStyle, children: "New reports will appear here with screenshots, status, and page context." })
742
+ ]
743
+ }
744
+ );
745
+ }
746
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "grid", gap: "10px" }, children: [
747
+ feedbacks.map((item) => {
748
+ const thumb = getScreenshotThumb(item);
749
+ const preview = item.message.length > 110 ? `${item.message.slice(0, 110)}...` : item.message;
750
+ const isMine = currentUserId !== null && getCreatorId2(item.createdBy) === currentUserId;
751
+ return /* @__PURE__ */ jsxRuntime.jsxs(
752
+ "button",
753
+ {
754
+ type: "button",
755
+ onClick: () => onSelectFeedback(item.id),
756
+ style: {
757
+ ...surfaceCardStyle,
758
+ display: "flex",
759
+ width: "100%",
760
+ gap: "12px",
761
+ padding: "14px",
762
+ color: theme.text,
763
+ textAlign: "left",
764
+ cursor: "pointer"
765
+ },
766
+ children: [
767
+ /* @__PURE__ */ jsxRuntime.jsx(
768
+ "div",
769
+ {
770
+ style: {
771
+ ...innerCardStyle,
772
+ width: "56px",
773
+ height: "56px",
774
+ overflow: "hidden",
775
+ flexShrink: 0,
776
+ display: "grid",
777
+ placeItems: "center",
778
+ color: theme.textMuted
779
+ },
780
+ children: thumb ? (
781
+ // eslint-disable-next-line @next/next/no-img-element
782
+ /* @__PURE__ */ jsxRuntime.jsx(
783
+ "img",
784
+ {
785
+ src: thumb,
786
+ alt: "",
787
+ style: {
788
+ width: "100%",
789
+ height: "100%",
790
+ objectFit: "cover",
791
+ display: "block"
792
+ }
793
+ }
794
+ )
795
+ ) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ImageIcon, { size: 18 })
796
+ }
797
+ ),
798
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { flex: 1, minWidth: 0 }, children: [
799
+ /* @__PURE__ */ jsxRuntime.jsxs(
800
+ "div",
801
+ {
802
+ style: {
803
+ display: "flex",
804
+ alignItems: "flex-start",
805
+ gap: "8px",
806
+ justifyContent: "space-between",
807
+ marginBottom: "8px"
808
+ },
809
+ children: [
810
+ /* @__PURE__ */ jsxRuntime.jsx(
811
+ "p",
812
+ {
813
+ style: {
814
+ margin: 0,
815
+ fontSize: "14px",
816
+ lineHeight: 1.5,
817
+ color: theme.text,
818
+ overflow: "hidden",
819
+ display: "-webkit-box",
820
+ WebkitBoxOrient: "vertical",
821
+ WebkitLineClamp: 2
822
+ },
823
+ children: preview
824
+ }
825
+ ),
826
+ /* @__PURE__ */ jsxRuntime.jsx("span", { style: pillStyle(STATUS_VARIANTS[item.status] || "success"), children: STATUS_LABELS[item.status] || "New" })
827
+ ]
828
+ }
829
+ ),
830
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", alignItems: "center", gap: "8px", flexWrap: "wrap" }, children: [
831
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { style: pillStyle("neutral"), children: [
832
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Clock3, { size: 12 }),
833
+ formatRelativeTime(item.createdAt)
834
+ ] }),
835
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { style: pillStyle("neutral"), children: [
836
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.MapPin, { size: 12 }),
837
+ item.pagePath
838
+ ] }),
839
+ isMine ? /* @__PURE__ */ jsxRuntime.jsx("span", { style: pillStyle("success"), children: "Mine" }) : null
840
+ ] })
841
+ ] })
842
+ ]
843
+ },
844
+ item.id
845
+ );
846
+ }),
847
+ totalPages > 1 ? /* @__PURE__ */ jsxRuntime.jsxs(
848
+ "div",
849
+ {
850
+ style: {
851
+ ...surfaceCardStyle,
852
+ padding: "12px",
853
+ display: "flex",
854
+ alignItems: "center",
855
+ justifyContent: "space-between",
856
+ gap: "10px"
857
+ },
858
+ children: [
859
+ /* @__PURE__ */ jsxRuntime.jsxs(
860
+ "button",
861
+ {
862
+ type: "button",
863
+ disabled: currentPage <= 1,
864
+ onClick: () => onPageChange(currentPage - 1),
865
+ style: buttonStyle("secondary", { compact: true, disabled: currentPage <= 1 }),
866
+ children: [
867
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronLeft, { size: 15 }),
868
+ "Previous"
869
+ ]
870
+ }
871
+ ),
872
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { textAlign: "center" }, children: [
873
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: sectionLabelStyle, children: "Page" }),
874
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { style: { ...metaTextStyle, marginTop: "2px" }, children: [
875
+ currentPage,
876
+ " of ",
877
+ totalPages
878
+ ] })
879
+ ] }),
880
+ /* @__PURE__ */ jsxRuntime.jsxs(
881
+ "button",
882
+ {
883
+ type: "button",
884
+ disabled: currentPage >= totalPages,
885
+ onClick: () => onPageChange(currentPage + 1),
886
+ style: buttonStyle("secondary", { compact: true, disabled: currentPage >= totalPages }),
887
+ children: [
888
+ "Next",
889
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronRight, { size: 15 })
890
+ ]
891
+ }
892
+ )
893
+ ]
894
+ }
895
+ ) : null
896
+ ] });
897
+ }
898
+ var DEFAULT_COLORS = ["#ef4444", "#f97316", "#eab308", "#22c55e", "#06b6d4", "#3b82f6", "#a855f7"];
899
+ var DEFAULT_HISTORY = {
900
+ operations: [],
901
+ redoStack: [],
902
+ undoStack: []
903
+ };
904
+ var createOperationId = () => `annotation-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
905
+ var getCssSelector = (element) => {
906
+ if (element.id) {
907
+ return `#${CSS.escape(element.id)}`;
908
+ }
909
+ const parts = [];
910
+ let current = element;
911
+ while (current && current.nodeType === Node.ELEMENT_NODE && current !== document.body) {
912
+ const tag = current.tagName.toLowerCase();
913
+ if (tag === "body" || tag === "html") {
914
+ break;
915
+ }
916
+ let part = tag;
917
+ const className = current.className;
918
+ if (typeof className === "string") {
919
+ const firstClass = className.split(" ").map((value) => value.trim()).filter(Boolean)[0];
920
+ if (firstClass) {
921
+ part += `.${CSS.escape(firstClass)}`;
922
+ }
923
+ }
924
+ const parent = current.parentElement;
925
+ if (parent) {
926
+ const siblings = Array.from(parent.children).filter(
927
+ (candidate) => candidate.tagName === current?.tagName
928
+ );
929
+ if (siblings.length > 1) {
930
+ const index = siblings.indexOf(current);
931
+ part += `:nth-of-type(${index + 1})`;
932
+ }
933
+ }
934
+ parts.unshift(part);
935
+ current = current.parentElement;
936
+ }
937
+ return parts.join(" > ");
938
+ };
939
+ var fileToDataUrl = async (file) => new Promise((resolve, reject) => {
940
+ const reader = new FileReader();
941
+ reader.onload = () => {
942
+ if (typeof reader.result === "string") {
943
+ resolve(reader.result);
944
+ return;
945
+ }
946
+ reject(new Error("Unsupported image format."));
947
+ };
948
+ reader.onerror = () => reject(new Error("Could not read image."));
949
+ reader.readAsDataURL(file);
950
+ });
951
+ var loadImage = async (src) => new Promise((resolve, reject) => {
952
+ const image = new Image();
953
+ image.onload = () => resolve(image);
954
+ image.onerror = () => reject(new Error("Could not load image."));
955
+ image.src = src;
956
+ });
957
+ var createEditorImage = async (file) => {
958
+ const src = await fileToDataUrl(file);
959
+ const element = await loadImage(src);
960
+ return {
961
+ element,
962
+ fileName: file.name,
963
+ height: element.naturalHeight || element.height,
964
+ src,
965
+ width: element.naturalWidth || element.width
966
+ };
967
+ };
968
+ var canvasToFile2 = async (canvas, fileName = `feedback-${Date.now()}.png`) => {
969
+ const blob = await new Promise((resolve) => {
970
+ canvas.toBlob((nextBlob) => resolve(nextBlob), "image/png");
971
+ });
972
+ if (!blob) {
973
+ throw new Error("Failed to prepare annotated screenshot.");
974
+ }
975
+ return new File([blob], fileName.replace(/\.[a-z0-9]+$/i, "") + ".png", { type: "image/png" });
976
+ };
977
+ var waitForRenderedVideoFrame = async (video) => {
978
+ if ("requestVideoFrameCallback" in video) {
979
+ await new Promise((resolve) => {
980
+ video.requestVideoFrameCallback(() => resolve());
981
+ });
982
+ return;
983
+ }
984
+ await new Promise((resolve) => {
985
+ window.requestAnimationFrame(() => resolve());
986
+ });
987
+ };
988
+ var captureScreenshotFile2 = async (capturePolicy) => {
989
+ if (!navigator.mediaDevices?.getDisplayMedia) {
990
+ throw new Error("Browser does not support screen capture.");
991
+ }
992
+ const options = capturePolicy === "any-surface" ? {
993
+ video: true,
994
+ audio: false
995
+ } : {
996
+ video: {
997
+ displaySurface: "browser"
998
+ },
999
+ audio: false,
1000
+ preferCurrentTab: true,
1001
+ selfBrowserSurface: "include",
1002
+ surfaceSwitching: "exclude"
1003
+ };
1004
+ const stream = await navigator.mediaDevices.getDisplayMedia(options);
1005
+ const track = stream.getVideoTracks()[0];
1006
+ if (!track) {
1007
+ stream.getTracks().forEach((item) => item.stop());
1008
+ throw new Error("Screen capture failed.");
1009
+ }
1010
+ const settings = track.getSettings();
1011
+ const surface = typeof settings.displaySurface === "string" ? settings.displaySurface : null;
1012
+ if (capturePolicy === "strict-current-tab" && surface !== "browser") {
1013
+ stream.getTracks().forEach((item) => item.stop());
1014
+ throw new Error("Please share the current browser tab to capture a screenshot.");
1015
+ }
1016
+ const video = document.createElement("video");
1017
+ try {
1018
+ video.srcObject = stream;
1019
+ video.muted = true;
1020
+ video.playsInline = true;
1021
+ await video.play();
1022
+ await waitForRenderedVideoFrame(video);
1023
+ const width = video.videoWidth || window.innerWidth;
1024
+ const height = video.videoHeight || window.innerHeight;
1025
+ if (!width || !height) {
1026
+ throw new Error("Screen capture failed.");
1027
+ }
1028
+ const canvas = document.createElement("canvas");
1029
+ canvas.width = width;
1030
+ canvas.height = height;
1031
+ const context = canvas.getContext("2d");
1032
+ if (!context) {
1033
+ throw new Error("Browser does not support canvas context.");
1034
+ }
1035
+ context.drawImage(video, 0, 0, width, height);
1036
+ return {
1037
+ file: await canvasToFile2(canvas),
1038
+ surface
1039
+ };
1040
+ } finally {
1041
+ video.pause();
1042
+ video.srcObject = null;
1043
+ stream.getTracks().forEach((item) => item.stop());
1044
+ }
1045
+ };
1046
+ var getCanvasPoint = (event, canvas) => {
1047
+ const bounds = canvas.getBoundingClientRect();
1048
+ const scaleX = bounds.width === 0 ? 1 : canvas.width / bounds.width;
1049
+ const scaleY = bounds.height === 0 ? 1 : canvas.height / bounds.height;
1050
+ return {
1051
+ x: (event.clientX - bounds.left) * scaleX,
1052
+ y: (event.clientY - bounds.top) * scaleY
1053
+ };
1054
+ };
1055
+ var drawPenOperation = (context, operation) => {
1056
+ if (operation.points.length === 0) {
1057
+ return;
1058
+ }
1059
+ context.save();
1060
+ context.strokeStyle = operation.style.color;
1061
+ context.lineWidth = operation.style.size;
1062
+ context.lineCap = "round";
1063
+ context.lineJoin = "round";
1064
+ context.beginPath();
1065
+ context.moveTo(operation.points[0].x, operation.points[0].y);
1066
+ for (const point of operation.points.slice(1)) {
1067
+ context.lineTo(point.x, point.y);
1068
+ }
1069
+ if (operation.points.length === 1) {
1070
+ const point = operation.points[0];
1071
+ context.lineTo(point.x + 0.01, point.y + 0.01);
1072
+ }
1073
+ context.stroke();
1074
+ context.restore();
1075
+ };
1076
+ var drawRectangleOperation = (context, operation) => {
1077
+ const left = Math.min(operation.start.x, operation.end.x);
1078
+ const top = Math.min(operation.start.y, operation.end.y);
1079
+ const width = Math.abs(operation.end.x - operation.start.x);
1080
+ const height = Math.abs(operation.end.y - operation.start.y);
1081
+ context.save();
1082
+ context.strokeStyle = operation.style.color;
1083
+ context.lineWidth = operation.style.size;
1084
+ context.strokeRect(left, top, width, height);
1085
+ context.restore();
1086
+ };
1087
+ var drawArrowOperation = (context, operation) => {
1088
+ const angle = Math.atan2(operation.end.y - operation.start.y, operation.end.x - operation.start.x);
1089
+ const headLength = Math.max(14, operation.style.size * 4);
1090
+ context.save();
1091
+ context.strokeStyle = operation.style.color;
1092
+ context.fillStyle = operation.style.color;
1093
+ context.lineWidth = operation.style.size;
1094
+ context.lineCap = "round";
1095
+ context.lineJoin = "round";
1096
+ context.beginPath();
1097
+ context.moveTo(operation.start.x, operation.start.y);
1098
+ context.lineTo(operation.end.x, operation.end.y);
1099
+ context.stroke();
1100
+ context.beginPath();
1101
+ context.moveTo(operation.end.x, operation.end.y);
1102
+ context.lineTo(
1103
+ operation.end.x - headLength * Math.cos(angle - Math.PI / 6),
1104
+ operation.end.y - headLength * Math.sin(angle - Math.PI / 6)
1105
+ );
1106
+ context.lineTo(
1107
+ operation.end.x - headLength * Math.cos(angle + Math.PI / 6),
1108
+ operation.end.y - headLength * Math.sin(angle + Math.PI / 6)
1109
+ );
1110
+ context.closePath();
1111
+ context.fill();
1112
+ context.restore();
1113
+ };
1114
+ var drawTextOperation = (context, operation) => {
1115
+ const fontSize = Math.max(16, operation.style.size * 6);
1116
+ context.save();
1117
+ context.fillStyle = operation.style.color;
1118
+ context.font = `600 ${fontSize}px ui-sans-serif, system-ui, sans-serif`;
1119
+ context.textBaseline = "top";
1120
+ context.fillText(operation.text, operation.point.x, operation.point.y);
1121
+ context.restore();
1122
+ };
1123
+ var drawOperation = (context, operation) => {
1124
+ switch (operation.type) {
1125
+ case "pen":
1126
+ drawPenOperation(context, operation);
1127
+ return;
1128
+ case "rectangle":
1129
+ drawRectangleOperation(context, operation);
1130
+ return;
1131
+ case "arrow":
1132
+ drawArrowOperation(context, operation);
1133
+ return;
1134
+ case "text":
1135
+ drawTextOperation(context, operation);
1136
+ return;
1137
+ }
1138
+ };
1139
+ var isShapeMeaningful = (start, end) => Math.abs(end.x - start.x) > 3 || Math.abs(end.y - start.y) > 3;
1140
+ function FeedbackWidget({
1141
+ title = "Admin feedback",
1142
+ submitLabel = "Send",
1143
+ uploadLabel = "Upload image",
1144
+ allowScreenshotUpload = true,
1145
+ screenshotMaxFileSizeBytes = 5 * 1024 * 1024,
1146
+ screenshotAllowedMimeTypes = ["image/png", "image/jpeg", "image/webp"],
1147
+ capturePolicy = "current-tab-first",
1148
+ onSubmit,
1149
+ onUpload,
1150
+ onDeleteScreenshot,
1151
+ onDeleteFeedback,
1152
+ showHistory,
1153
+ currentUserId,
1154
+ onUpdateFeedback,
1155
+ history
1156
+ }) {
1157
+ const [open, setOpen] = React2__default.default.useState(false);
1158
+ const [view, setView] = React2__default.default.useState("form");
1159
+ const [selectedFeedback, setSelectedFeedback] = React2__default.default.useState(null);
1160
+ const [message, setMessage] = React2__default.default.useState("");
1161
+ const [captureMode, setCaptureMode] = React2__default.default.useState(false);
1162
+ const [captureData, setCaptureData] = React2__default.default.useState(null);
1163
+ const [screenshotId, setScreenshotId] = React2__default.default.useState(null);
1164
+ const [screenshotPreviewUrl, setScreenshotPreviewUrl] = React2__default.default.useState(null);
1165
+ const [uploading, setUploading] = React2__default.default.useState(false);
1166
+ const [deletingScreenshot, setDeletingScreenshot] = React2__default.default.useState(false);
1167
+ const [submitting, setSubmitting] = React2__default.default.useState(false);
1168
+ const [error, setError] = React2__default.default.useState(null);
1169
+ const [notice, setNotice] = React2__default.default.useState(null);
1170
+ const [annotating, setAnnotating] = React2__default.default.useState(false);
1171
+ const [editorImage, setEditorImage] = React2__default.default.useState(null);
1172
+ const [editorHistory, setEditorHistory] = React2__default.default.useState(DEFAULT_HISTORY);
1173
+ const [draftOperation, setDraftOperation] = React2__default.default.useState(null);
1174
+ const [annotationTool, setAnnotationTool] = React2__default.default.useState("pen");
1175
+ const [annotationColor, setAnnotationColor] = React2__default.default.useState(DEFAULT_COLORS[0]);
1176
+ const [annotationSize, setAnnotationSize] = React2__default.default.useState(4);
1177
+ const [annotationText, setAnnotationText] = React2__default.default.useState("");
1178
+ const hoverTargetRef = React2__default.default.useRef(null);
1179
+ const annotationCanvasRef = React2__default.default.useRef(null);
1180
+ const pointerIdRef = React2__default.default.useRef(null);
1181
+ const draftOperationRef = React2__default.default.useRef(null);
1182
+ React2__default.default.useEffect(() => {
1183
+ draftOperationRef.current = draftOperation;
1184
+ }, [draftOperation]);
1185
+ React2__default.default.useEffect(() => {
1186
+ if (!captureMode) {
1187
+ return;
1188
+ }
1189
+ const clearOutline = () => {
1190
+ if (hoverTargetRef.current instanceof HTMLElement) {
1191
+ hoverTargetRef.current.style.outline = "";
1192
+ }
1193
+ hoverTargetRef.current = null;
1194
+ };
1195
+ const onMouseMove = (event) => {
1196
+ const target = event.target;
1197
+ if (!(target instanceof HTMLElement)) {
1198
+ return;
1199
+ }
1200
+ if (hoverTargetRef.current !== target) {
1201
+ clearOutline();
1202
+ target.style.outline = "2px dashed #22c55e";
1203
+ hoverTargetRef.current = target;
1204
+ }
1205
+ };
1206
+ const onClick = (event) => {
1207
+ event.preventDefault();
1208
+ event.stopPropagation();
1209
+ const target = event.target;
1210
+ if (!(target instanceof HTMLElement)) {
1211
+ return;
1212
+ }
1213
+ setCaptureData({
1214
+ selector: getCssSelector(target),
1215
+ selectedText: target.textContent?.trim().slice(0, 200) || ""
1216
+ });
1217
+ clearOutline();
1218
+ setCaptureMode(false);
1219
+ };
1220
+ document.addEventListener("mousemove", onMouseMove, true);
1221
+ document.addEventListener("click", onClick, true);
1222
+ return () => {
1223
+ clearOutline();
1224
+ document.removeEventListener("mousemove", onMouseMove, true);
1225
+ document.removeEventListener("click", onClick, true);
1226
+ };
1227
+ }, [captureMode]);
1228
+ React2__default.default.useEffect(() => {
1229
+ if (!annotating) {
1230
+ return;
1231
+ }
1232
+ const previousOverflow = document.body.style.overflow;
1233
+ document.body.style.overflow = "hidden";
1234
+ return () => {
1235
+ document.body.style.overflow = previousOverflow;
1236
+ };
1237
+ }, [annotating]);
1238
+ React2__default.default.useEffect(() => {
1239
+ if (!annotating || !editorImage || !annotationCanvasRef.current) {
1240
+ return;
1241
+ }
1242
+ const canvas = annotationCanvasRef.current;
1243
+ canvas.width = editorImage.width;
1244
+ canvas.height = editorImage.height;
1245
+ const context = canvas.getContext("2d");
1246
+ if (!context) {
1247
+ setError("Browser does not support canvas context.");
1248
+ return;
1249
+ }
1250
+ context.clearRect(0, 0, canvas.width, canvas.height);
1251
+ context.drawImage(editorImage.element, 0, 0, canvas.width, canvas.height);
1252
+ for (const operation of editorHistory.operations) {
1253
+ drawOperation(context, operation);
1254
+ }
1255
+ if (draftOperation) {
1256
+ drawOperation(context, draftOperation);
1257
+ }
1258
+ }, [annotating, draftOperation, editorHistory.operations, editorImage]);
1259
+ const validateImageFile = React2__default.default.useCallback(
1260
+ (file) => {
1261
+ if (!screenshotAllowedMimeTypes.includes(file.type)) {
1262
+ return `Supported image types: ${screenshotAllowedMimeTypes.join(", ")}`;
1263
+ }
1264
+ if (file.size > screenshotMaxFileSizeBytes) {
1265
+ return `Image is too large. Maximum size: ${Math.round(screenshotMaxFileSizeBytes / 1024 / 1024)}MB.`;
1266
+ }
1267
+ return null;
1268
+ },
1269
+ [screenshotAllowedMimeTypes, screenshotMaxFileSizeBytes]
1270
+ );
1271
+ const uploadImageFile = React2__default.default.useCallback(
1272
+ async (file) => {
1273
+ if (!onUpload) {
1274
+ return false;
1275
+ }
1276
+ setError(null);
1277
+ setUploading(true);
1278
+ try {
1279
+ const formData = new FormData();
1280
+ formData.append("file", file);
1281
+ formData.append("alt", file.name);
1282
+ const result = await onUpload(formData);
1283
+ if (result.success) {
1284
+ setScreenshotId(result.mediaId);
1285
+ setNotice("Annotated screenshot uploaded.");
1286
+ return true;
1287
+ }
1288
+ setError(result.error);
1289
+ return false;
1290
+ } finally {
1291
+ setUploading(false);
1292
+ }
1293
+ },
1294
+ [onUpload]
1295
+ );
1296
+ const closeAnnotationEditor = React2__default.default.useCallback(() => {
1297
+ setAnnotating(false);
1298
+ setEditorImage(null);
1299
+ setEditorHistory(DEFAULT_HISTORY);
1300
+ setDraftOperation(null);
1301
+ draftOperationRef.current = null;
1302
+ }, []);
1303
+ const handleStartAnnotation = React2__default.default.useCallback(
1304
+ async (file) => {
1305
+ const validationError = validateImageFile(file);
1306
+ if (validationError) {
1307
+ setError(validationError);
1308
+ return;
1309
+ }
1310
+ try {
1311
+ const nextImage = await createEditorImage(file);
1312
+ setEditorImage(nextImage);
1313
+ setEditorHistory(DEFAULT_HISTORY);
1314
+ setDraftOperation(null);
1315
+ draftOperationRef.current = null;
1316
+ setAnnotating(true);
1317
+ setError(null);
1318
+ } catch (nextError) {
1319
+ setError(nextError instanceof Error ? nextError.message : "Failed to process image.");
1320
+ }
1321
+ },
1322
+ [validateImageFile]
1323
+ );
1324
+ React2__default.default.useEffect(() => {
1325
+ if (!open || !allowScreenshotUpload) {
1326
+ return;
1327
+ }
1328
+ const onPaste = async (event) => {
1329
+ const file = Array.from(event.clipboardData?.items || []).find((item) => item.type.startsWith("image/"))?.getAsFile();
1330
+ if (!file) {
1331
+ return;
1332
+ }
1333
+ event.preventDefault();
1334
+ await handleStartAnnotation(file);
1335
+ };
1336
+ window.addEventListener("paste", onPaste);
1337
+ return () => window.removeEventListener("paste", onPaste);
1338
+ }, [allowScreenshotUpload, handleStartAnnotation, open]);
1339
+ const handleSelectFeedback = React2__default.default.useCallback(
1340
+ async (id) => {
1341
+ const found = history?.feedbacks.find((f) => f.id === id);
1342
+ if (found) {
1343
+ setSelectedFeedback(found);
1344
+ setView("detail");
1345
+ return;
1346
+ }
1347
+ try {
1348
+ const res = await fetch(`/api/admin-feedback/${id}?depth=2`, { credentials: "include" });
1349
+ if (res.ok) {
1350
+ const data = await res.json();
1351
+ setSelectedFeedback(data);
1352
+ setView("detail");
1353
+ }
1354
+ } catch {
1355
+ }
1356
+ },
1357
+ [history?.feedbacks]
1358
+ );
1359
+ React2__default.default.useEffect(() => {
1360
+ const handler = (e) => {
1361
+ const detail = e.detail;
1362
+ if (detail?.feedbackId) {
1363
+ setOpen(true);
1364
+ handleSelectFeedback(detail.feedbackId);
1365
+ }
1366
+ };
1367
+ window.addEventListener("feedback:show-detail", handler);
1368
+ return () => window.removeEventListener("feedback:show-detail", handler);
1369
+ }, [handleSelectFeedback]);
1370
+ const commitOperations = React2__default.default.useCallback((nextOperations) => {
1371
+ setEditorHistory((current) => ({
1372
+ operations: nextOperations,
1373
+ redoStack: [],
1374
+ undoStack: [...current.undoStack, current.operations]
1375
+ }));
1376
+ }, []);
1377
+ const appendOperation = React2__default.default.useCallback((operation) => {
1378
+ setEditorHistory((current) => ({
1379
+ operations: [...current.operations, operation],
1380
+ redoStack: [],
1381
+ undoStack: [...current.undoStack, current.operations]
1382
+ }));
1383
+ }, []);
1384
+ const handleUpload = async (event) => {
1385
+ const file = event.target.files?.[0];
1386
+ if (file) {
1387
+ await handleStartAnnotation(file);
1388
+ }
1389
+ event.target.value = "";
1390
+ };
1391
+ const handleCaptureScreenshot = async () => {
1392
+ try {
1393
+ setError(null);
1394
+ const { file, surface } = await captureScreenshotFile2(capturePolicy);
1395
+ if (capturePolicy === "current-tab-first") {
1396
+ if (surface === "browser") {
1397
+ setNotice("Captured the current tab.");
1398
+ } else if (surface) {
1399
+ setNotice(`Captured a ${surface} surface because the browser allowed a broader selection.`);
1400
+ } else {
1401
+ setNotice("Captured a screenshot.");
1402
+ }
1403
+ } else if (capturePolicy === "strict-current-tab") {
1404
+ setNotice("Captured the current tab.");
1405
+ } else {
1406
+ setNotice("Captured a screenshot.");
1407
+ }
1408
+ await handleStartAnnotation(file);
1409
+ } catch (nextError) {
1410
+ setError(nextError instanceof Error ? nextError.message : "Screen capture failed.");
1411
+ }
1412
+ };
1413
+ const handleUndo = () => {
1414
+ setEditorHistory((current) => {
1415
+ if (current.undoStack.length === 0) {
1416
+ return current;
1417
+ }
1418
+ const previousOperations = current.undoStack[current.undoStack.length - 1];
1419
+ return {
1420
+ operations: previousOperations,
1421
+ redoStack: [current.operations, ...current.redoStack],
1422
+ undoStack: current.undoStack.slice(0, -1)
1423
+ };
1424
+ });
1425
+ };
1426
+ const handleRedo = () => {
1427
+ setEditorHistory((current) => {
1428
+ if (current.redoStack.length === 0) {
1429
+ return current;
1430
+ }
1431
+ const [nextOperations, ...remainingRedo] = current.redoStack;
1432
+ return {
1433
+ operations: nextOperations,
1434
+ redoStack: remainingRedo,
1435
+ undoStack: [...current.undoStack, current.operations]
1436
+ };
1437
+ });
1438
+ };
1439
+ const handleClearAnnotations = () => {
1440
+ if (editorHistory.operations.length === 0) {
1441
+ return;
1442
+ }
1443
+ commitOperations([]);
1444
+ };
1445
+ const handleRevertLastAnnotation = () => {
1446
+ setDraftOperation(null);
1447
+ draftOperationRef.current = null;
1448
+ pointerIdRef.current = null;
1449
+ setEditorHistory((current) => {
1450
+ if (current.operations.length === 0) {
1451
+ return current;
1452
+ }
1453
+ return {
1454
+ operations: current.operations.slice(0, -1),
1455
+ redoStack: [],
1456
+ undoStack: [...current.undoStack, current.operations]
1457
+ };
1458
+ });
1459
+ };
1460
+ const handleCanvasPointerDown = (event) => {
1461
+ if (!annotationCanvasRef.current) {
1462
+ return;
1463
+ }
1464
+ setError(null);
1465
+ const canvas = annotationCanvasRef.current;
1466
+ const point = getCanvasPoint(event, canvas);
1467
+ if (annotationTool === "text") {
1468
+ const text = annotationText.trim();
1469
+ if (!text) {
1470
+ setError("Enter text before placing it on the image.");
1471
+ return;
1472
+ }
1473
+ const operation = {
1474
+ id: createOperationId(),
1475
+ type: "text",
1476
+ style: { color: annotationColor, size: annotationSize },
1477
+ point,
1478
+ text
1479
+ };
1480
+ appendOperation(operation);
1481
+ return;
1482
+ }
1483
+ event.preventDefault();
1484
+ canvas.setPointerCapture(event.pointerId);
1485
+ pointerIdRef.current = event.pointerId;
1486
+ const style = { color: annotationColor, size: annotationSize };
1487
+ const nextDraft = annotationTool === "pen" ? {
1488
+ id: createOperationId(),
1489
+ type: "pen",
1490
+ style,
1491
+ points: [point]
1492
+ } : annotationTool === "rectangle" ? {
1493
+ id: createOperationId(),
1494
+ type: "rectangle",
1495
+ style,
1496
+ start: point,
1497
+ end: point
1498
+ } : {
1499
+ id: createOperationId(),
1500
+ type: "arrow",
1501
+ style,
1502
+ start: point,
1503
+ end: point
1504
+ };
1505
+ draftOperationRef.current = nextDraft;
1506
+ setDraftOperation(nextDraft);
1507
+ };
1508
+ const handleCanvasPointerMove = (event) => {
1509
+ if (!annotationCanvasRef.current || pointerIdRef.current !== event.pointerId) {
1510
+ return;
1511
+ }
1512
+ const activeDraft = draftOperationRef.current;
1513
+ if (!activeDraft) {
1514
+ return;
1515
+ }
1516
+ const point = getCanvasPoint(event, annotationCanvasRef.current);
1517
+ const nextDraft = activeDraft.type === "pen" ? {
1518
+ ...activeDraft,
1519
+ points: [...activeDraft.points, point]
1520
+ } : {
1521
+ ...activeDraft,
1522
+ end: point
1523
+ };
1524
+ draftOperationRef.current = nextDraft;
1525
+ setDraftOperation(nextDraft);
1526
+ };
1527
+ const handleCanvasPointerUp = (event) => {
1528
+ if (!annotationCanvasRef.current || pointerIdRef.current !== event.pointerId) {
1529
+ return;
1530
+ }
1531
+ const canvas = annotationCanvasRef.current;
1532
+ if (canvas.hasPointerCapture(event.pointerId)) {
1533
+ canvas.releasePointerCapture(event.pointerId);
1534
+ }
1535
+ pointerIdRef.current = null;
1536
+ const activeDraft = draftOperationRef.current;
1537
+ draftOperationRef.current = null;
1538
+ setDraftOperation(null);
1539
+ if (!activeDraft) {
1540
+ return;
1541
+ }
1542
+ if (activeDraft.type === "pen") {
1543
+ const points = activeDraft.points.length === 1 ? [...activeDraft.points, activeDraft.points[0]] : activeDraft.points;
1544
+ appendOperation({ ...activeDraft, points });
1545
+ return;
1546
+ }
1547
+ if (!isShapeMeaningful(activeDraft.start, activeDraft.end)) {
1548
+ return;
1549
+ }
1550
+ appendOperation(activeDraft);
1551
+ };
1552
+ const handleCanvasPointerCancel = (event) => {
1553
+ if (annotationCanvasRef.current && pointerIdRef.current === event.pointerId && annotationCanvasRef.current.hasPointerCapture(event.pointerId)) {
1554
+ annotationCanvasRef.current.releasePointerCapture(event.pointerId);
1555
+ }
1556
+ pointerIdRef.current = null;
1557
+ draftOperationRef.current = null;
1558
+ setDraftOperation(null);
1559
+ };
1560
+ const handleApplyAnnotation = async () => {
1561
+ if (!annotationCanvasRef.current || !editorImage) {
1562
+ return;
1563
+ }
1564
+ try {
1565
+ const previewUrl = annotationCanvasRef.current.toDataURL("image/png");
1566
+ const file = await canvasToFile2(annotationCanvasRef.current, editorImage.fileName);
1567
+ const uploaded = await uploadImageFile(file);
1568
+ if (uploaded) {
1569
+ setScreenshotPreviewUrl(previewUrl);
1570
+ closeAnnotationEditor();
1571
+ }
1572
+ } catch (nextError) {
1573
+ setError(nextError instanceof Error ? nextError.message : "Failed to export image.");
1574
+ }
1575
+ };
1576
+ const handleRemoveScreenshot = async () => {
1577
+ if (!screenshotId) {
1578
+ setScreenshotPreviewUrl(null);
1579
+ return;
1580
+ }
1581
+ if (!onDeleteScreenshot) {
1582
+ setScreenshotId(null);
1583
+ setScreenshotPreviewUrl(null);
1584
+ return;
1585
+ }
1586
+ setDeletingScreenshot(true);
1587
+ setError(null);
1588
+ try {
1589
+ const result = await onDeleteScreenshot(screenshotId);
1590
+ if (!result.success) {
1591
+ setError(result.error);
1592
+ return;
1593
+ }
1594
+ setScreenshotId(null);
1595
+ setScreenshotPreviewUrl(null);
1596
+ setNotice("Screenshot removed.");
1597
+ } finally {
1598
+ setDeletingScreenshot(false);
1599
+ }
1600
+ };
1601
+ const handleSubmit = async () => {
1602
+ if (!message.trim()) {
1603
+ setError("Please enter a message.");
1604
+ return;
1605
+ }
1606
+ setSubmitting(true);
1607
+ setError(null);
1608
+ const result = await onSubmit({
1609
+ message: message.trim(),
1610
+ pagePath: typeof window !== "undefined" ? window.location.pathname : "/",
1611
+ selector: captureData?.selector,
1612
+ selectedText: captureData?.selectedText,
1613
+ screenshotId,
1614
+ meta: {
1615
+ userAgent: window.navigator.userAgent,
1616
+ locale: window.navigator.language,
1617
+ viewport: `${window.innerWidth}x${window.innerHeight}`
1618
+ }
1619
+ });
1620
+ setSubmitting(false);
1621
+ if (!result.success) {
1622
+ setError(result.error);
1623
+ return;
1624
+ }
1625
+ setMessage("");
1626
+ setCaptureData(null);
1627
+ setScreenshotId(null);
1628
+ setScreenshotPreviewUrl(null);
1629
+ setNotice(null);
1630
+ setView("form");
1631
+ setOpen(false);
1632
+ };
1633
+ const currentHasUndo = editorHistory.undoStack.length > 0;
1634
+ const currentHasRedo = editorHistory.redoStack.length > 0;
1635
+ const hasAnnotations = editorHistory.operations.length > 0;
1636
+ const currentPath = typeof window !== "undefined" ? window.location.pathname : "/";
1637
+ const canManageScreenshots = allowScreenshotUpload && onUpload;
1638
+ const annotationTools = [
1639
+ { tool: "pen", label: "Pen", icon: lucideReact.PenTool },
1640
+ { tool: "rectangle", label: "Box", icon: lucideReact.Square },
1641
+ { tool: "arrow", label: "Arrow", icon: lucideReact.ArrowRight },
1642
+ { tool: "text", label: "Text", icon: lucideReact.Type }
1643
+ ];
1644
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1645
+ /* @__PURE__ */ jsxRuntime.jsxs(
1646
+ "button",
1647
+ {
1648
+ type: "button",
1649
+ onClick: () => {
1650
+ setOpen((value) => !value);
1651
+ if (!open) setView("form");
1652
+ },
1653
+ style: floatingLauncherStyle,
1654
+ children: [
1655
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.MessageSquarePlus, { size: 18 }),
1656
+ "Feedback"
1657
+ ]
1658
+ }
1659
+ ),
1660
+ open ? /* @__PURE__ */ jsxRuntime.jsxs("div", { style: panelStyle, children: [
1661
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: panelHeaderStyle, children: [
1662
+ /* @__PURE__ */ jsxRuntime.jsxs(
1663
+ "div",
1664
+ {
1665
+ style: {
1666
+ display: "flex",
1667
+ alignItems: "flex-start",
1668
+ justifyContent: "space-between",
1669
+ gap: "12px",
1670
+ marginBottom: showHistory ? "14px" : 0
1671
+ },
1672
+ children: [
1673
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1674
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { display: "flex", alignItems: "center", gap: "8px", marginBottom: "8px" }, children: /* @__PURE__ */ jsxRuntime.jsxs("span", { style: pillStyle("success"), children: [
1675
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Sparkles, { size: 12 }),
1676
+ "Feedback"
1677
+ ] }) }),
1678
+ /* @__PURE__ */ jsxRuntime.jsx("h3", { style: { margin: 0, fontSize: "16px", lineHeight: 1.2, letterSpacing: "-0.02em" }, children: title }),
1679
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: { ...metaTextStyle, marginTop: "6px" }, children: "Collect issues, context, and screenshots without leaving the current page." })
1680
+ ] }),
1681
+ /* @__PURE__ */ jsxRuntime.jsx(
1682
+ "button",
1683
+ {
1684
+ type: "button",
1685
+ onClick: () => {
1686
+ setOpen(false);
1687
+ setCaptureMode(false);
1688
+ },
1689
+ "aria-label": "Close feedback panel",
1690
+ style: buttonStyle("ghost", { compact: true, iconOnly: true }),
1691
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { size: 16 })
1692
+ }
1693
+ )
1694
+ ]
1695
+ }
1696
+ ),
1697
+ showHistory ? /* @__PURE__ */ jsxRuntime.jsxs(
1698
+ "div",
1699
+ {
1700
+ style: {
1701
+ ...surfaceCardStyle,
1702
+ padding: "5px",
1703
+ display: "flex",
1704
+ gap: "6px"
1705
+ },
1706
+ children: [
1707
+ /* @__PURE__ */ jsxRuntime.jsxs(
1708
+ "button",
1709
+ {
1710
+ type: "button",
1711
+ onClick: () => setView("form"),
1712
+ style: { ...buttonStyle("secondary", { active: view === "form", compact: true }), flex: 1 },
1713
+ children: [
1714
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.MessageSquare, { size: 15 }),
1715
+ "New"
1716
+ ]
1717
+ }
1718
+ ),
1719
+ /* @__PURE__ */ jsxRuntime.jsxs(
1720
+ "button",
1721
+ {
1722
+ type: "button",
1723
+ onClick: () => setView("history"),
1724
+ style: {
1725
+ ...buttonStyle("secondary", {
1726
+ active: view === "history" || view === "detail",
1727
+ compact: true
1728
+ }),
1729
+ flex: 1
1730
+ },
1731
+ children: [
1732
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.History, { size: 15 }),
1733
+ "History"
1734
+ ]
1735
+ }
1736
+ )
1737
+ ]
1738
+ }
1739
+ ) : null
1740
+ ] }),
1741
+ /* @__PURE__ */ jsxRuntime.jsx(
1742
+ "div",
1743
+ {
1744
+ style: {
1745
+ padding: "14px",
1746
+ display: "grid",
1747
+ gap: "10px",
1748
+ flex: 1,
1749
+ minHeight: 0,
1750
+ overflowY: "auto",
1751
+ overflowX: "hidden"
1752
+ },
1753
+ children: view === "form" ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1754
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { ...surfaceCardStyle, padding: "14px" }, children: [
1755
+ /* @__PURE__ */ jsxRuntime.jsxs(
1756
+ "div",
1757
+ {
1758
+ style: {
1759
+ display: "flex",
1760
+ alignItems: "flex-start",
1761
+ justifyContent: "space-between",
1762
+ gap: "10px",
1763
+ flexWrap: "wrap",
1764
+ marginBottom: "10px"
1765
+ },
1766
+ children: [
1767
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1768
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: sectionLabelStyle, children: "New report" }),
1769
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: { margin: "4px 0 0", fontSize: "13px", lineHeight: 1.5, color: theme.textSoft }, children: "Describe the issue, attach context, and send it with the current page path." })
1770
+ ] }),
1771
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { style: { ...pillStyle("neutral"), maxWidth: "100%", overflow: "hidden" }, children: [
1772
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.MapPin, { size: 12 }),
1773
+ /* @__PURE__ */ jsxRuntime.jsx(
1774
+ "span",
1775
+ {
1776
+ style: {
1777
+ overflow: "hidden",
1778
+ textOverflow: "ellipsis",
1779
+ whiteSpace: "nowrap",
1780
+ display: "inline-block"
1781
+ },
1782
+ children: currentPath
1783
+ }
1784
+ )
1785
+ ] })
1786
+ ]
1787
+ }
1788
+ ),
1789
+ /* @__PURE__ */ jsxRuntime.jsx(
1790
+ "textarea",
1791
+ {
1792
+ value: message,
1793
+ onChange: (event) => setMessage(event.target.value),
1794
+ rows: 5,
1795
+ placeholder: "Describe the issue, the expected behavior, and what you were doing...",
1796
+ style: { ...fieldStyle, resize: "vertical", minHeight: "116px" }
1797
+ }
1798
+ )
1799
+ ] }),
1800
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { ...surfaceCardStyle, padding: "14px" }, children: [
1801
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginBottom: "10px" }, children: [
1802
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: sectionLabelStyle, children: "Context and attachments" }),
1803
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: { ...metaTextStyle, marginTop: "4px" }, children: "Paste an image with Ctrl/Cmd+V or attach a screenshot from the current tab." })
1804
+ ] }),
1805
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", gap: "8px", flexWrap: "wrap" }, children: [
1806
+ canManageScreenshots ? /* @__PURE__ */ jsxRuntime.jsx(
1807
+ "button",
1808
+ {
1809
+ type: "button",
1810
+ onClick: handleCaptureScreenshot,
1811
+ "aria-label": "Capture screen",
1812
+ title: "Capture screen",
1813
+ style: buttonStyle("secondary", { compact: true, iconOnly: true }),
1814
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Camera, { size: 15 })
1815
+ }
1816
+ ) : null,
1817
+ /* @__PURE__ */ jsxRuntime.jsx(
1818
+ "button",
1819
+ {
1820
+ type: "button",
1821
+ onClick: () => setCaptureMode((value) => !value),
1822
+ "aria-label": captureMode ? "Capture element: click target" : "Capture element",
1823
+ title: captureMode ? "Capture element: click target" : "Capture element",
1824
+ style: buttonStyle("secondary", { compact: true, active: captureMode, iconOnly: true }),
1825
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.MousePointerClick, { size: 15 })
1826
+ }
1827
+ ),
1828
+ canManageScreenshots ? /* @__PURE__ */ jsxRuntime.jsxs(
1829
+ "label",
1830
+ {
1831
+ "aria-label": uploading ? "Uploading image" : uploadLabel,
1832
+ title: uploading ? "Uploading image" : uploadLabel,
1833
+ style: buttonStyle("secondary", { compact: true, iconOnly: true }),
1834
+ children: [
1835
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Upload, { size: 15 }),
1836
+ /* @__PURE__ */ jsxRuntime.jsx(
1837
+ "input",
1838
+ {
1839
+ type: "file",
1840
+ accept: screenshotAllowedMimeTypes.join(","),
1841
+ onChange: handleUpload,
1842
+ hidden: true
1843
+ }
1844
+ )
1845
+ ]
1846
+ }
1847
+ ) : null
1848
+ ] })
1849
+ ] }),
1850
+ captureMode || captureData ? /* @__PURE__ */ jsxRuntime.jsxs(
1851
+ "div",
1852
+ {
1853
+ style: {
1854
+ ...surfaceCardStyle,
1855
+ padding: "12px 14px",
1856
+ borderColor: captureMode ? "rgba(94, 234, 212, 0.3)" : theme.border
1857
+ },
1858
+ children: [
1859
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", alignItems: "center", gap: "8px", flexWrap: "wrap" }, children: [
1860
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { style: pillStyle(captureMode ? "success" : "neutral"), title: captureData?.selector || void 0, children: [
1861
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.MousePointerClick, { size: 12 }),
1862
+ captureMode ? "Element capture active" : "Element captured"
1863
+ ] }),
1864
+ captureData?.selectedText ? /* @__PURE__ */ jsxRuntime.jsxs("span", { style: pillStyle("neutral"), title: captureData.selectedText, children: [
1865
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.MessageSquare, { size: 12 }),
1866
+ "Text preview"
1867
+ ] }) : null
1868
+ ] }),
1869
+ !captureData ? /* @__PURE__ */ jsxRuntime.jsx("p", { style: { ...metaTextStyle, marginTop: "8px" }, children: "Click any visible element to attach its selector." }) : null
1870
+ ]
1871
+ }
1872
+ ) : null,
1873
+ screenshotId ? /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { ...surfaceCardStyle, padding: "10px" }, children: [
1874
+ /* @__PURE__ */ jsxRuntime.jsxs(
1875
+ "div",
1876
+ {
1877
+ style: {
1878
+ display: "flex",
1879
+ alignItems: "center",
1880
+ justifyContent: "space-between",
1881
+ gap: "10px",
1882
+ marginBottom: screenshotPreviewUrl ? "10px" : 0
1883
+ },
1884
+ children: [
1885
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { style: pillStyle("neutral"), children: [
1886
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ImageIcon, { size: 12 }),
1887
+ "Media #",
1888
+ screenshotId
1889
+ ] }),
1890
+ /* @__PURE__ */ jsxRuntime.jsxs(
1891
+ "button",
1892
+ {
1893
+ type: "button",
1894
+ onClick: handleRemoveScreenshot,
1895
+ disabled: deletingScreenshot,
1896
+ style: buttonStyle("danger", { compact: true, disabled: deletingScreenshot }),
1897
+ children: [
1898
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Trash2, { size: 15 }),
1899
+ deletingScreenshot ? "Removing..." : "Remove"
1900
+ ]
1901
+ }
1902
+ )
1903
+ ]
1904
+ }
1905
+ ),
1906
+ screenshotPreviewUrl ? /* @__PURE__ */ jsxRuntime.jsx("div", { style: { ...innerCardStyle, overflow: "hidden" }, children: /* @__PURE__ */ jsxRuntime.jsx(
1907
+ "img",
1908
+ {
1909
+ src: screenshotPreviewUrl,
1910
+ alt: "Annotated screenshot preview",
1911
+ style: { width: "100%", height: "auto", display: "block", maxHeight: "180px", objectFit: "cover" }
1912
+ }
1913
+ ) }) : null
1914
+ ] }) : null,
1915
+ notice ? /* @__PURE__ */ jsxRuntime.jsx("div", { style: { ...surfaceCardStyle, padding: "12px 14px", borderColor: "rgba(94, 234, 212, 0.28)" }, children: /* @__PURE__ */ jsxRuntime.jsxs("p", { style: { ...metaTextStyle, color: "#ccfbf1" }, children: [
1916
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CheckCircle2, { size: 14, style: { verticalAlign: "text-bottom", marginRight: "6px" } }),
1917
+ notice
1918
+ ] }) }) : null,
1919
+ error ? /* @__PURE__ */ jsxRuntime.jsx("div", { style: { ...surfaceCardStyle, padding: "12px 14px", borderColor: "rgba(248, 113, 113, 0.24)" }, children: /* @__PURE__ */ jsxRuntime.jsx("p", { style: { ...metaTextStyle, color: "#fecaca" }, children: error }) }) : null
1920
+ ] }) : view === "history" && history ? /* @__PURE__ */ jsxRuntime.jsx(
1921
+ FeedbackHistory,
1922
+ {
1923
+ feedbacks: history.feedbacks,
1924
+ totalPages: history.totalPages,
1925
+ currentPage: history.currentPage,
1926
+ loading: history.loading,
1927
+ error: history.error,
1928
+ currentUserId: currentUserId ?? null,
1929
+ onSelectFeedback: (id) => handleSelectFeedback(id),
1930
+ onPageChange: history.onPageChange,
1931
+ onRefetch: history.refetch
1932
+ }
1933
+ ) : view === "detail" && selectedFeedback && onUpload && onDeleteScreenshot ? /* @__PURE__ */ jsxRuntime.jsx(
1934
+ FeedbackDetail,
1935
+ {
1936
+ feedback: selectedFeedback,
1937
+ currentUserId: currentUserId ?? null,
1938
+ capturePolicy,
1939
+ onBack: () => setView("history"),
1940
+ onUpdate: async (id, data) => {
1941
+ if (!onUpdateFeedback) return false;
1942
+ const result = await onUpdateFeedback(id, data);
1943
+ if (result && history) {
1944
+ history.refetch();
1945
+ setSelectedFeedback((prev) => {
1946
+ if (!prev) return prev;
1947
+ return {
1948
+ ...prev,
1949
+ message: data.message ?? prev.message,
1950
+ screenshot: data.screenshotId !== void 0 ? data.screenshotId ? { id: data.screenshotId, url: void 0 } : null : prev.screenshot
1951
+ };
1952
+ });
1953
+ }
1954
+ return result;
1955
+ },
1956
+ onDelete: async (id) => {
1957
+ if (!onDeleteFeedback) return false;
1958
+ const result = await onDeleteFeedback(id);
1959
+ if (result.success) {
1960
+ setSelectedFeedback(null);
1961
+ setView("history");
1962
+ history?.refetch();
1963
+ return true;
1964
+ }
1965
+ setError(result.error);
1966
+ return false;
1967
+ },
1968
+ onUpload,
1969
+ onDeleteScreenshot
1970
+ }
1971
+ ) : null
1972
+ }
1973
+ ),
1974
+ view === "form" ? /* @__PURE__ */ jsxRuntime.jsxs(
1975
+ "div",
1976
+ {
1977
+ style: {
1978
+ display: "flex",
1979
+ justifyContent: "space-between",
1980
+ alignItems: "stretch",
1981
+ gap: "8px",
1982
+ flexWrap: "wrap",
1983
+ flexShrink: 0,
1984
+ padding: "12px 14px",
1985
+ paddingBottom: "calc(12px + env(safe-area-inset-bottom, 0px))",
1986
+ borderTop: `1px solid ${theme.border}`,
1987
+ background: "linear-gradient(180deg, rgba(8, 15, 30, 0.94) 0%, rgba(15, 23, 42, 0.96) 100%)"
1988
+ },
1989
+ children: [
1990
+ /* @__PURE__ */ jsxRuntime.jsxs(
1991
+ "button",
1992
+ {
1993
+ type: "button",
1994
+ onClick: () => {
1995
+ setOpen(false);
1996
+ setView("form");
1997
+ },
1998
+ style: {
1999
+ ...buttonStyle("ghost", { compact: true }),
2000
+ flex: "1 1 132px"
2001
+ },
2002
+ children: [
2003
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { size: 15 }),
2004
+ "Close"
2005
+ ]
2006
+ }
2007
+ ),
2008
+ /* @__PURE__ */ jsxRuntime.jsxs(
2009
+ "button",
2010
+ {
2011
+ type: "button",
2012
+ onClick: handleSubmit,
2013
+ disabled: submitting,
2014
+ style: {
2015
+ ...buttonStyle("primary", { compact: true, disabled: submitting }),
2016
+ flex: "1 1 132px"
2017
+ },
2018
+ children: [
2019
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.SendHorizontal, { size: 15 }),
2020
+ submitting ? "Sending..." : submitLabel
2021
+ ]
2022
+ }
2023
+ )
2024
+ ]
2025
+ }
2026
+ ) : null
2027
+ ] }) : null,
2028
+ annotating && editorImage ? /* @__PURE__ */ jsxRuntime.jsxs(
2029
+ "div",
2030
+ {
2031
+ style: {
2032
+ position: "fixed",
2033
+ inset: "0",
2034
+ zIndex: 1e4,
2035
+ background: "rgba(2, 8, 23, 0.96)",
2036
+ color: theme.text,
2037
+ display: "flex",
2038
+ flexDirection: "column"
2039
+ },
2040
+ children: [
2041
+ /* @__PURE__ */ jsxRuntime.jsxs(
2042
+ "div",
2043
+ {
2044
+ style: {
2045
+ display: "flex",
2046
+ flexWrap: "wrap",
2047
+ gap: "12px",
2048
+ alignItems: "flex-start",
2049
+ justifyContent: "space-between",
2050
+ padding: "16px 18px",
2051
+ borderBottom: `1px solid ${theme.border}`,
2052
+ background: "linear-gradient(180deg, rgba(15, 23, 42, 0.96) 0%, rgba(8, 15, 30, 0.94) 100%)"
2053
+ },
2054
+ children: [
2055
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "grid", gap: "12px", flex: 1, minWidth: 0 }, children: [
2056
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", alignItems: "center", gap: "10px", flexWrap: "wrap" }, children: [
2057
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { style: pillStyle("success"), children: [
2058
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Sparkles, { size: 12 }),
2059
+ "Annotate screenshot"
2060
+ ] }),
2061
+ /* @__PURE__ */ jsxRuntime.jsx("span", { style: pillStyle("neutral"), children: editorImage.fileName })
2062
+ ] }),
2063
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { display: "flex", gap: "8px", flexWrap: "wrap" }, children: annotationTools.map(({ tool, label, icon: Icon }) => /* @__PURE__ */ jsxRuntime.jsxs(
2064
+ "button",
2065
+ {
2066
+ type: "button",
2067
+ onClick: () => setAnnotationTool(tool),
2068
+ "aria-label": label,
2069
+ style: buttonStyle("secondary", {
2070
+ compact: true,
2071
+ active: annotationTool === tool
2072
+ }),
2073
+ children: [
2074
+ /* @__PURE__ */ jsxRuntime.jsx(Icon, { size: 15 }),
2075
+ label
2076
+ ]
2077
+ },
2078
+ tool
2079
+ )) })
2080
+ ] }),
2081
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "grid", gap: "10px", justifyItems: "start" }, children: [
2082
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", gap: "6px", alignItems: "center", flexWrap: "wrap" }, children: [
2083
+ DEFAULT_COLORS.map((color) => /* @__PURE__ */ jsxRuntime.jsx(
2084
+ "button",
2085
+ {
2086
+ type: "button",
2087
+ onClick: () => setAnnotationColor(color),
2088
+ "aria-label": `Select ${color} color`,
2089
+ style: {
2090
+ width: "28px",
2091
+ height: "28px",
2092
+ borderRadius: "999px",
2093
+ border: annotationColor === color ? "2px solid #f8fafc" : `1px solid ${theme.borderStrong}`,
2094
+ background: color,
2095
+ cursor: "pointer"
2096
+ }
2097
+ },
2098
+ color
2099
+ )),
2100
+ /* @__PURE__ */ jsxRuntime.jsx(
2101
+ "input",
2102
+ {
2103
+ type: "color",
2104
+ value: annotationColor,
2105
+ onChange: (event) => setAnnotationColor(event.target.value),
2106
+ "aria-label": "Annotation color",
2107
+ style: { width: "36px", height: "36px", border: "none", background: "transparent" }
2108
+ }
2109
+ )
2110
+ ] }),
2111
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { style: { display: "flex", alignItems: "center", gap: "10px", fontSize: "12px", color: theme.textSoft }, children: [
2112
+ "Size ",
2113
+ annotationSize,
2114
+ /* @__PURE__ */ jsxRuntime.jsx(
2115
+ "input",
2116
+ {
2117
+ type: "range",
2118
+ min: 1,
2119
+ max: 18,
2120
+ value: annotationSize,
2121
+ onChange: (event) => setAnnotationSize(Number(event.target.value)),
2122
+ "aria-label": "Annotation size"
2123
+ }
2124
+ )
2125
+ ] }),
2126
+ annotationTool === "text" ? /* @__PURE__ */ jsxRuntime.jsx(
2127
+ "input",
2128
+ {
2129
+ type: "text",
2130
+ value: annotationText,
2131
+ onChange: (event) => setAnnotationText(event.target.value),
2132
+ placeholder: "Text to place",
2133
+ "aria-label": "Annotation text",
2134
+ style: {
2135
+ ...fieldStyle,
2136
+ minWidth: "220px",
2137
+ padding: "10px 12px"
2138
+ }
2139
+ }
2140
+ ) : null,
2141
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", gap: "8px", flexWrap: "wrap" }, children: [
2142
+ /* @__PURE__ */ jsxRuntime.jsxs(
2143
+ "button",
2144
+ {
2145
+ type: "button",
2146
+ onClick: handleUndo,
2147
+ disabled: !currentHasUndo,
2148
+ style: buttonStyle("secondary", { compact: true, disabled: !currentHasUndo }),
2149
+ children: [
2150
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Undo2, { size: 15 }),
2151
+ "Undo"
2152
+ ]
2153
+ }
2154
+ ),
2155
+ /* @__PURE__ */ jsxRuntime.jsxs(
2156
+ "button",
2157
+ {
2158
+ type: "button",
2159
+ onClick: handleRedo,
2160
+ disabled: !currentHasRedo,
2161
+ style: buttonStyle("secondary", { compact: true, disabled: !currentHasRedo }),
2162
+ children: [
2163
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Redo2, { size: 15 }),
2164
+ "Redo"
2165
+ ]
2166
+ }
2167
+ ),
2168
+ /* @__PURE__ */ jsxRuntime.jsxs(
2169
+ "button",
2170
+ {
2171
+ type: "button",
2172
+ onClick: handleClearAnnotations,
2173
+ disabled: !hasAnnotations,
2174
+ style: buttonStyle("secondary", { compact: true, disabled: !hasAnnotations }),
2175
+ children: [
2176
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Eraser, { size: 15 }),
2177
+ "Clear"
2178
+ ]
2179
+ }
2180
+ ),
2181
+ /* @__PURE__ */ jsxRuntime.jsxs(
2182
+ "button",
2183
+ {
2184
+ type: "button",
2185
+ onClick: handleRevertLastAnnotation,
2186
+ disabled: !hasAnnotations,
2187
+ style: buttonStyle("secondary", { compact: true, disabled: !hasAnnotations }),
2188
+ children: [
2189
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.RotateCcw, { size: 15 }),
2190
+ "Revert last"
2191
+ ]
2192
+ }
2193
+ )
2194
+ ] })
2195
+ ] })
2196
+ ]
2197
+ }
2198
+ ),
2199
+ /* @__PURE__ */ jsxRuntime.jsx(
2200
+ "div",
2201
+ {
2202
+ style: {
2203
+ flex: 1,
2204
+ overflow: "auto",
2205
+ padding: "18px",
2206
+ display: "flex",
2207
+ alignItems: "center",
2208
+ justifyContent: "center"
2209
+ },
2210
+ children: /* @__PURE__ */ jsxRuntime.jsx(
2211
+ "canvas",
2212
+ {
2213
+ ref: annotationCanvasRef,
2214
+ onPointerDown: handleCanvasPointerDown,
2215
+ onPointerMove: handleCanvasPointerMove,
2216
+ onPointerUp: handleCanvasPointerUp,
2217
+ onPointerCancel: handleCanvasPointerCancel,
2218
+ style: {
2219
+ width: "min(100%, 1400px)",
2220
+ height: "auto",
2221
+ display: "block",
2222
+ borderRadius: "22px",
2223
+ background: "#ffffff",
2224
+ boxShadow: "0 34px 90px rgba(2, 8, 23, 0.5)",
2225
+ touchAction: "none",
2226
+ cursor: annotationTool === "text" ? "copy" : "crosshair"
2227
+ }
2228
+ }
2229
+ )
2230
+ }
2231
+ ),
2232
+ /* @__PURE__ */ jsxRuntime.jsxs(
2233
+ "div",
2234
+ {
2235
+ style: {
2236
+ display: "flex",
2237
+ justifyContent: "space-between",
2238
+ alignItems: "center",
2239
+ gap: "12px",
2240
+ flexWrap: "wrap",
2241
+ padding: "16px 18px",
2242
+ borderTop: `1px solid ${theme.border}`,
2243
+ background: "linear-gradient(180deg, rgba(8, 15, 30, 0.94) 0%, rgba(15, 23, 42, 0.96) 100%)"
2244
+ },
2245
+ children: [
2246
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: { ...metaTextStyle, maxWidth: "720px" }, children: "Use mouse, touch, or pen input. Text is placed where you click on the image." }),
2247
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", gap: "8px", flexWrap: "wrap" }, children: [
2248
+ /* @__PURE__ */ jsxRuntime.jsxs("button", { type: "button", onClick: closeAnnotationEditor, style: buttonStyle("ghost"), children: [
2249
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { size: 15 }),
2250
+ "Cancel"
2251
+ ] }),
2252
+ /* @__PURE__ */ jsxRuntime.jsxs(
2253
+ "button",
2254
+ {
2255
+ type: "button",
2256
+ onClick: handleApplyAnnotation,
2257
+ disabled: uploading,
2258
+ style: buttonStyle("primary", { disabled: uploading }),
2259
+ children: [
2260
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Upload, { size: 15 }),
2261
+ uploading ? "Uploading..." : "Save screenshot"
2262
+ ]
2263
+ }
2264
+ )
2265
+ ] })
2266
+ ]
2267
+ }
2268
+ )
2269
+ ]
2270
+ }
2271
+ ) : null
2272
+ ] });
2273
+ }
2274
+ function useFeedbackQuery(params) {
2275
+ const { pagePath, page = 1, limit = 20 } = params;
2276
+ const [feedbacks, setFeedbacks] = React2__default.default.useState([]);
2277
+ const [totalPages, setTotalPages] = React2__default.default.useState(0);
2278
+ const [loading, setLoading] = React2__default.default.useState(true);
2279
+ const [error, setError] = React2__default.default.useState(null);
2280
+ const [fetchKey, setFetchKey] = React2__default.default.useState(0);
2281
+ const refetch = React2__default.default.useCallback(() => {
2282
+ setFetchKey((key) => key + 1);
2283
+ }, []);
2284
+ React2__default.default.useEffect(() => {
2285
+ let cancelled = false;
2286
+ const fetchFeedbacks = async () => {
2287
+ setLoading(true);
2288
+ setError(null);
2289
+ try {
2290
+ const url = new URL("/api/admin-feedback", window.location.origin);
2291
+ url.searchParams.set("depth", "2");
2292
+ url.searchParams.set("sort", "-createdAt");
2293
+ url.searchParams.set("limit", String(limit));
2294
+ url.searchParams.set("page", String(page));
2295
+ if (pagePath) {
2296
+ url.searchParams.set("where[pagePath][equals]", pagePath);
2297
+ }
2298
+ const response = await fetch(url.toString(), {
2299
+ credentials: "include"
2300
+ });
2301
+ if (!response.ok) {
2302
+ if (response.status === 401 || response.status === 403) {
2303
+ if (!cancelled) {
2304
+ setFeedbacks([]);
2305
+ setTotalPages(0);
2306
+ setLoading(false);
2307
+ }
2308
+ return;
2309
+ }
2310
+ throw new Error(`Failed to fetch feedback (${response.status})`);
2311
+ }
2312
+ const data = await response.json();
2313
+ if (!cancelled) {
2314
+ setFeedbacks(data.docs);
2315
+ setTotalPages(data.totalPages);
2316
+ setLoading(false);
2317
+ }
2318
+ } catch (err) {
2319
+ if (!cancelled) {
2320
+ setError(err instanceof Error ? err.message : "Failed to load feedback.");
2321
+ setLoading(false);
2322
+ }
2323
+ }
2324
+ };
2325
+ fetchFeedbacks();
2326
+ return () => {
2327
+ cancelled = true;
2328
+ };
2329
+ }, [pagePath, page, limit, fetchKey]);
2330
+ return {
2331
+ feedbacks,
2332
+ totalPages,
2333
+ currentPage: page,
2334
+ loading,
2335
+ error,
2336
+ refetch
2337
+ };
2338
+ }
2339
+ function useCurrentUser() {
2340
+ const [userId, setUserId] = React2__default.default.useState(null);
2341
+ const [loading, setLoading] = React2__default.default.useState(true);
2342
+ React2__default.default.useEffect(() => {
2343
+ let cancelled = false;
2344
+ const fetchUser = async () => {
2345
+ try {
2346
+ const response = await fetch("/api/users/me", {
2347
+ credentials: "include"
2348
+ });
2349
+ if (!response.ok) {
2350
+ if (!cancelled) {
2351
+ setUserId(null);
2352
+ setLoading(false);
2353
+ }
2354
+ return;
2355
+ }
2356
+ const data = await response.json();
2357
+ if (!cancelled) {
2358
+ setUserId(data.user?.id ?? data.id ?? null);
2359
+ setLoading(false);
2360
+ }
2361
+ } catch {
2362
+ if (!cancelled) {
2363
+ setUserId(null);
2364
+ setLoading(false);
2365
+ }
2366
+ }
2367
+ };
2368
+ fetchUser();
2369
+ return () => {
2370
+ cancelled = true;
2371
+ };
2372
+ }, []);
2373
+ return { userId, loading };
2374
+ }
2375
+ function AdminFeedbackWidget() {
2376
+ const { userId, loading: userLoading } = useCurrentUser();
2377
+ const [page, setPage] = React2__default.default.useState(1);
2378
+ const query = useFeedbackQuery({ page });
2379
+ const handleUpdateFeedback = React2__default.default.useCallback(
2380
+ async (id, data) => {
2381
+ const response = await fetch(`/api/admin-feedback/update/${id}`, {
2382
+ method: "PATCH",
2383
+ credentials: "include",
2384
+ headers: { "content-type": "application/json" },
2385
+ body: JSON.stringify(data)
2386
+ });
2387
+ const result = await response.json();
2388
+ if (!result.success) {
2389
+ return false;
2390
+ }
2391
+ return true;
2392
+ },
2393
+ []
2394
+ );
2395
+ return /* @__PURE__ */ jsxRuntime.jsx(
2396
+ FeedbackWidget,
2397
+ {
2398
+ title: "Admin feedback",
2399
+ submitLabel: "Send",
2400
+ uploadLabel: "Upload image",
2401
+ allowScreenshotUpload: true,
2402
+ showHistory: true,
2403
+ currentUserId: userLoading ? null : userId,
2404
+ onUpdateFeedback: handleUpdateFeedback,
2405
+ history: {
2406
+ feedbacks: query.feedbacks,
2407
+ totalPages: query.totalPages,
2408
+ currentPage: query.currentPage,
2409
+ loading: query.loading,
2410
+ error: query.error,
2411
+ refetch: query.refetch,
2412
+ onPageChange: setPage
2413
+ },
2414
+ onSubmit: async (payload) => {
2415
+ const response = await fetch("/api/admin-feedback/submit", {
2416
+ method: "POST",
2417
+ credentials: "include",
2418
+ headers: { "content-type": "application/json" },
2419
+ body: JSON.stringify(payload)
2420
+ });
2421
+ const result = await response.json();
2422
+ if (!result.success) {
2423
+ return { success: false, error: result.error || "Submit failed." };
2424
+ }
2425
+ query.refetch();
2426
+ return { success: true };
2427
+ },
2428
+ onDeleteFeedback: async (id) => {
2429
+ const response = await fetch(`/api/admin-feedback/delete/${id}`, {
2430
+ method: "DELETE",
2431
+ credentials: "include"
2432
+ });
2433
+ const result = await response.json();
2434
+ if (!result.success) {
2435
+ return { success: false, error: result.error || "Delete failed." };
2436
+ }
2437
+ query.refetch();
2438
+ return { success: true };
2439
+ },
2440
+ onUpload: async (formData) => {
2441
+ const response = await fetch("/api/admin-feedback/upload", {
2442
+ method: "POST",
2443
+ credentials: "include",
2444
+ body: formData
2445
+ });
2446
+ const result = await response.json();
2447
+ if (!result.success || typeof result.mediaId !== "number") {
2448
+ return { success: false, error: result.error || "Upload failed." };
2449
+ }
2450
+ return { success: true, mediaId: result.mediaId };
2451
+ },
2452
+ onDeleteScreenshot: async (mediaId) => {
2453
+ const response = await fetch(`/api/admin-feedback/upload/${mediaId}`, {
2454
+ method: "DELETE",
2455
+ credentials: "include"
2456
+ });
2457
+ const result = await response.json();
2458
+ if (!result.success) {
2459
+ return { success: false, error: result.error || "Delete failed." };
2460
+ }
2461
+ return { success: true };
2462
+ }
2463
+ }
2464
+ );
2465
+ }
2466
+ var DOT_SIZE = 14;
2467
+ var DOT_OFFSET = 8;
2468
+ var STATUS_COLORS = {
2469
+ new: "#5eead4",
2470
+ triaged: "#facc15",
2471
+ resolved: "#cbd5e1"
2472
+ };
2473
+ var STATUS_LABELS2 = {
2474
+ new: "New",
2475
+ triaged: "Triaged",
2476
+ resolved: "Resolved"
2477
+ };
2478
+ var formatRelativeTime2 = (iso) => {
2479
+ const now = Date.now();
2480
+ const diff = now - new Date(iso).getTime();
2481
+ const minutes = Math.floor(diff / 6e4);
2482
+ if (minutes < 1) return "Just now";
2483
+ if (minutes < 60) return `${minutes}m ago`;
2484
+ const hours = Math.floor(minutes / 60);
2485
+ if (hours < 24) return `${hours}h ago`;
2486
+ const days = Math.floor(hours / 24);
2487
+ if (days < 7) return `${days}d ago`;
2488
+ return new Date(iso).toLocaleDateString();
2489
+ };
2490
+ function FeedbackIndicators({ pagePath }) {
2491
+ const containerRef = React2__default.default.useRef(null);
2492
+ const dotsRef = React2__default.default.useRef(/* @__PURE__ */ new Map());
2493
+ const tooltipRef = React2__default.default.useRef(null);
2494
+ const rafRef = React2__default.default.useRef(0);
2495
+ const indicatorDataRef = React2__default.default.useRef([]);
2496
+ const createContainer = React2__default.default.useCallback(() => {
2497
+ if (containerRef.current) return containerRef.current;
2498
+ const element = document.createElement("div");
2499
+ element.style.cssText = "position:fixed;inset:0;pointer-events:none;z-index:9998;";
2500
+ document.body.appendChild(element);
2501
+ containerRef.current = element;
2502
+ return element;
2503
+ }, []);
2504
+ const createTooltip = React2__default.default.useCallback(() => {
2505
+ if (tooltipRef.current) return tooltipRef.current;
2506
+ const element = document.createElement("div");
2507
+ element.style.cssText = `
2508
+ position:fixed;
2509
+ z-index:9999;
2510
+ pointer-events:none;
2511
+ opacity:0;
2512
+ max-width:260px;
2513
+ padding:12px 14px;
2514
+ border-radius:16px;
2515
+ border:1px solid rgba(148, 163, 184, 0.18);
2516
+ background:linear-gradient(180deg, rgba(15, 23, 42, 0.96) 0%, rgba(6, 13, 24, 0.96) 100%);
2517
+ color:#f8fafc;
2518
+ box-shadow:0 18px 40px rgba(2, 8, 23, 0.4);
2519
+ backdrop-filter:blur(16px);
2520
+ transition:opacity 0.15s ease;
2521
+ white-space:normal;
2522
+ `;
2523
+ document.body.appendChild(element);
2524
+ tooltipRef.current = element;
2525
+ return element;
2526
+ }, []);
2527
+ const renderTooltip = React2__default.default.useCallback((tooltip, indicator) => {
2528
+ tooltip.replaceChildren();
2529
+ const message = document.createElement("p");
2530
+ message.textContent = indicator.message.length > 80 ? `${indicator.message.slice(0, 80)}...` : indicator.message;
2531
+ message.style.cssText = "margin:0 0 8px;font-size:12px;line-height:1.5;word-break:break-word;";
2532
+ const metaRow = document.createElement("div");
2533
+ metaRow.style.cssText = "display:flex;align-items:center;gap:8px;flex-wrap:wrap;";
2534
+ const status = document.createElement("span");
2535
+ status.textContent = STATUS_LABELS2[indicator.status] || "New";
2536
+ status.style.cssText = `
2537
+ display:inline-flex;
2538
+ align-items:center;
2539
+ border-radius:999px;
2540
+ padding:4px 8px;
2541
+ font-size:10px;
2542
+ font-weight:700;
2543
+ background:rgba(148, 163, 184, 0.12);
2544
+ color:${STATUS_COLORS[indicator.status] || STATUS_COLORS.new};
2545
+ border:1px solid rgba(148, 163, 184, 0.18);
2546
+ `;
2547
+ const time = document.createElement("span");
2548
+ time.textContent = formatRelativeTime2(indicator.createdAt);
2549
+ time.style.cssText = "font-size:10px;color:rgba(148, 163, 184, 0.86);";
2550
+ metaRow.append(status, time);
2551
+ tooltip.append(message, metaRow);
2552
+ }, []);
2553
+ const positionDot = React2__default.default.useCallback((dot, selector) => {
2554
+ let target = null;
2555
+ try {
2556
+ target = document.querySelector(selector);
2557
+ } catch {
2558
+ dot.style.display = "none";
2559
+ return false;
2560
+ }
2561
+ if (!(target instanceof HTMLElement)) {
2562
+ dot.style.display = "none";
2563
+ return false;
2564
+ }
2565
+ const rect = target.getBoundingClientRect();
2566
+ if (rect.width > window.innerWidth * 0.9 || rect.height > window.innerHeight * 0.9) {
2567
+ dot.style.display = "none";
2568
+ return false;
2569
+ }
2570
+ dot.style.display = "";
2571
+ dot.style.left = `${rect.right + DOT_OFFSET}px`;
2572
+ dot.style.top = `${rect.top - DOT_OFFSET - DOT_SIZE / 2}px`;
2573
+ return true;
2574
+ }, []);
2575
+ const repositionAll = React2__default.default.useCallback(() => {
2576
+ dotsRef.current.forEach((dot, id) => {
2577
+ const indicator = indicatorDataRef.current.find((item) => item.id === id);
2578
+ if (indicator) {
2579
+ positionDot(dot, indicator.selector);
2580
+ }
2581
+ });
2582
+ }, [positionDot]);
2583
+ React2__default.default.useEffect(() => {
2584
+ if (typeof window === "undefined" || typeof document === "undefined") return;
2585
+ let cancelled = false;
2586
+ const fetchAndRender = async () => {
2587
+ try {
2588
+ const authCheck = await fetch("/api/admin-feedback?limit=1", {
2589
+ credentials: "include"
2590
+ });
2591
+ if (!authCheck.ok) return;
2592
+ } catch {
2593
+ return;
2594
+ }
2595
+ const path = pagePath || window.location.pathname;
2596
+ const url = new URL("/api/admin-feedback", window.location.origin);
2597
+ url.searchParams.set("where[selector][exists]", "true");
2598
+ url.searchParams.set("depth", "2");
2599
+ url.searchParams.set("limit", "50");
2600
+ url.searchParams.set("sort", "-createdAt");
2601
+ try {
2602
+ const response = await fetch(url.toString(), { credentials: "include" });
2603
+ if (!response.ok) return;
2604
+ const data = await response.json();
2605
+ if (cancelled) return;
2606
+ const indicators = data.docs.filter((item) => item.selector && item.pagePath === path).map((item) => ({
2607
+ id: item.id,
2608
+ message: item.message,
2609
+ status: item.status,
2610
+ createdAt: item.createdAt,
2611
+ selector: item.selector
2612
+ }));
2613
+ indicatorDataRef.current = indicators;
2614
+ const container = createContainer();
2615
+ const tooltip = createTooltip();
2616
+ const currentIds = new Set(indicators.map((item) => item.id));
2617
+ dotsRef.current.forEach((dot, id) => {
2618
+ if (!currentIds.has(id)) {
2619
+ dot.remove();
2620
+ dotsRef.current.delete(id);
2621
+ }
2622
+ });
2623
+ for (const indicator of indicators) {
2624
+ let dot = dotsRef.current.get(indicator.id);
2625
+ if (!dot) {
2626
+ const element = document.createElement("div");
2627
+ element.style.cssText = `
2628
+ position:fixed;
2629
+ width:${DOT_SIZE}px;
2630
+ height:${DOT_SIZE}px;
2631
+ border-radius:999px;
2632
+ cursor:pointer;
2633
+ pointer-events:auto;
2634
+ z-index:9999;
2635
+ border:2px solid rgba(255,255,255,0.95);
2636
+ box-shadow:0 0 0 6px rgba(15, 23, 42, 0.2), 0 10px 22px rgba(2, 8, 23, 0.34);
2637
+ transition:transform 0.15s ease, box-shadow 0.15s ease;
2638
+ `;
2639
+ element.addEventListener("mouseenter", () => {
2640
+ element.style.transform = "scale(1.25)";
2641
+ element.style.boxShadow = "0 0 0 8px rgba(15, 23, 42, 0.28), 0 14px 28px rgba(2, 8, 23, 0.42)";
2642
+ renderTooltip(tooltip, indicator);
2643
+ const dotRect = element.getBoundingClientRect();
2644
+ tooltip.style.left = `${dotRect.right + 10}px`;
2645
+ tooltip.style.top = `${Math.max(12, dotRect.top - 6)}px`;
2646
+ tooltip.style.opacity = "1";
2647
+ });
2648
+ element.addEventListener("mouseleave", () => {
2649
+ element.style.transform = "";
2650
+ element.style.boxShadow = "0 0 0 6px rgba(15, 23, 42, 0.2), 0 10px 22px rgba(2, 8, 23, 0.34)";
2651
+ tooltip.style.opacity = "0";
2652
+ });
2653
+ element.addEventListener("click", (event) => {
2654
+ event.stopPropagation();
2655
+ window.dispatchEvent(
2656
+ new CustomEvent("feedback:show-detail", {
2657
+ detail: { feedbackId: indicator.id }
2658
+ })
2659
+ );
2660
+ });
2661
+ container.appendChild(element);
2662
+ dotsRef.current.set(indicator.id, element);
2663
+ dot = element;
2664
+ }
2665
+ dot.style.background = STATUS_COLORS[indicator.status] || STATUS_COLORS.new;
2666
+ positionDot(dot, indicator.selector);
2667
+ }
2668
+ } catch {
2669
+ }
2670
+ };
2671
+ const onScroll = () => {
2672
+ if (rafRef.current) return;
2673
+ rafRef.current = requestAnimationFrame(() => {
2674
+ rafRef.current = 0;
2675
+ repositionAll();
2676
+ });
2677
+ };
2678
+ fetchAndRender();
2679
+ window.addEventListener("scroll", onScroll, { passive: true });
2680
+ window.addEventListener("resize", onScroll);
2681
+ return () => {
2682
+ cancelled = true;
2683
+ window.removeEventListener("scroll", onScroll);
2684
+ window.removeEventListener("resize", onScroll);
2685
+ if (rafRef.current) {
2686
+ cancelAnimationFrame(rafRef.current);
2687
+ rafRef.current = 0;
2688
+ }
2689
+ };
2690
+ }, [pagePath, createContainer, createTooltip, positionDot, renderTooltip, repositionAll]);
2691
+ React2__default.default.useEffect(() => {
2692
+ return () => {
2693
+ dotsRef.current.forEach((dot) => dot.remove());
2694
+ dotsRef.current.clear();
2695
+ if (containerRef.current) {
2696
+ containerRef.current.remove();
2697
+ containerRef.current = null;
2698
+ }
2699
+ if (tooltipRef.current) {
2700
+ tooltipRef.current.remove();
2701
+ tooltipRef.current = null;
2702
+ }
2703
+ };
2704
+ }, []);
2705
+ return null;
2706
+ }
2707
+
2708
+ // src/client/routeMatcher.ts
2709
+ var escapeRegex = (input) => input.replace(/[.+^${}()|[\]\\]/g, "\\$&");
2710
+ var toRegExp = (pattern) => {
2711
+ const escaped = pattern.split("*").map((segment) => escapeRegex(segment)).join(".*");
2712
+ return new RegExp(`^${escaped}$`);
2713
+ };
2714
+ var pathMatchesAllowlist = (pathname, patterns) => {
2715
+ if (patterns.length === 0) {
2716
+ return false;
2717
+ }
2718
+ return patterns.some((pattern) => toRegExp(pattern).test(pathname));
2719
+ };
2720
+ var normalizePathname = (pathname, locales) => {
2721
+ if (locales.length === 0) {
2722
+ return pathname;
2723
+ }
2724
+ const segments = pathname.split("/").filter(Boolean);
2725
+ const maybeLocale = segments[0];
2726
+ if (maybeLocale && locales.includes(maybeLocale)) {
2727
+ return `/${segments.slice(1).join("/")}`;
2728
+ }
2729
+ return pathname;
2730
+ };
2731
+ function FrontendFeedbackWidget({
2732
+ include,
2733
+ locales = [],
2734
+ title = "Feedback",
2735
+ submitLabel = "Send",
2736
+ uploadLabel = "Upload image",
2737
+ showIndicators = false,
2738
+ showHistory = false
2739
+ }) {
2740
+ const pathname = navigation.usePathname();
2741
+ const normalizedPathname = normalizePathname(pathname, locales);
2742
+ const { userId, loading: userLoading } = useCurrentUser();
2743
+ const [page, setPage] = React2__default.default.useState(1);
2744
+ const query = useFeedbackQuery({ pagePath: normalizedPathname, page });
2745
+ const handleUpdateFeedback = React2__default.default.useCallback(
2746
+ async (id, data) => {
2747
+ const response = await fetch(`/api/admin-feedback/update/${id}`, {
2748
+ method: "PATCH",
2749
+ credentials: "include",
2750
+ headers: { "content-type": "application/json" },
2751
+ body: JSON.stringify(data)
2752
+ });
2753
+ const result = await response.json();
2754
+ if (!result.success) {
2755
+ return false;
2756
+ }
2757
+ return true;
2758
+ },
2759
+ []
2760
+ );
2761
+ if (!pathMatchesAllowlist(normalizedPathname, include)) {
2762
+ return null;
2763
+ }
2764
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2765
+ showIndicators ? /* @__PURE__ */ jsxRuntime.jsx(FeedbackIndicators, { pagePath: normalizedPathname }) : null,
2766
+ /* @__PURE__ */ jsxRuntime.jsx(
2767
+ FeedbackWidget,
2768
+ {
2769
+ title,
2770
+ submitLabel,
2771
+ uploadLabel,
2772
+ allowScreenshotUpload: true,
2773
+ showHistory,
2774
+ currentUserId: userLoading ? null : userId,
2775
+ onUpdateFeedback: showHistory ? handleUpdateFeedback : void 0,
2776
+ history: showHistory ? {
2777
+ feedbacks: query.feedbacks,
2778
+ totalPages: query.totalPages,
2779
+ currentPage: query.currentPage,
2780
+ loading: query.loading,
2781
+ error: query.error,
2782
+ refetch: query.refetch,
2783
+ onPageChange: setPage
2784
+ } : void 0,
2785
+ onSubmit: async (payload) => {
2786
+ const response = await fetch("/api/admin-feedback/submit", {
2787
+ method: "POST",
2788
+ credentials: "include",
2789
+ headers: { "content-type": "application/json" },
2790
+ body: JSON.stringify(payload)
2791
+ });
2792
+ const result = await response.json();
2793
+ if (!result.success) {
2794
+ return { success: false, error: result.error || "Submit failed." };
2795
+ }
2796
+ if (showHistory) {
2797
+ query.refetch();
2798
+ }
2799
+ return { success: true };
2800
+ },
2801
+ onDeleteFeedback: async (id) => {
2802
+ const response = await fetch(`/api/admin-feedback/delete/${id}`, {
2803
+ method: "DELETE",
2804
+ credentials: "include"
2805
+ });
2806
+ const result = await response.json();
2807
+ if (!result.success) {
2808
+ return { success: false, error: result.error || "Delete failed." };
2809
+ }
2810
+ if (showHistory) {
2811
+ query.refetch();
2812
+ }
2813
+ return { success: true };
2814
+ },
2815
+ onUpload: async (formData) => {
2816
+ const response = await fetch("/api/admin-feedback/upload", {
2817
+ method: "POST",
2818
+ credentials: "include",
2819
+ body: formData
2820
+ });
2821
+ const result = await response.json();
2822
+ if (!result.success || typeof result.mediaId !== "number") {
2823
+ return { success: false, error: result.error || "Upload failed." };
2824
+ }
2825
+ return { success: true, mediaId: result.mediaId };
2826
+ },
2827
+ onDeleteScreenshot: async (mediaId) => {
2828
+ const response = await fetch(`/api/admin-feedback/upload/${mediaId}`, {
2829
+ method: "DELETE",
2830
+ credentials: "include"
2831
+ });
2832
+ const result = await response.json();
2833
+ if (!result.success) {
2834
+ return { success: false, error: result.error || "Delete failed." };
2835
+ }
2836
+ return { success: true };
2837
+ }
2838
+ }
2839
+ )
2840
+ ] });
2841
+ }
2842
+
2843
+ exports.AdminFeedbackWidget = AdminFeedbackWidget;
2844
+ exports.FeedbackDetail = FeedbackDetail;
2845
+ exports.FeedbackHistory = FeedbackHistory;
2846
+ exports.FeedbackIndicators = FeedbackIndicators;
2847
+ exports.FeedbackWidget = FeedbackWidget;
2848
+ exports.FrontendFeedbackWidget = FrontendFeedbackWidget;
2849
+ exports.pathMatchesAllowlist = pathMatchesAllowlist;
2850
+ exports.useCurrentUser = useCurrentUser;
2851
+ exports.useFeedbackQuery = useFeedbackQuery;