@djangocfg/ext-support 1.0.1 → 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.
package/dist/hooks.js ADDED
@@ -0,0 +1,2755 @@
1
+ import { createConsola, consola } from 'consola';
2
+ import pRetry, { AbortError } from 'p-retry';
3
+ import { z } from 'zod';
4
+ import { createExtensionAPI } from '@djangocfg/ext-base/api';
5
+ import React7, { createContext, useContext, useState, useCallback, useEffect, useRef } from 'react';
6
+ import useSWR, { useSWRConfig } from 'swr';
7
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
8
+ import { useAuth } from '@djangocfg/api/auth';
9
+ import useSWRInfinite from 'swr/infinite';
10
+ import { Card, cn, CardContent, Badge, Skeleton, ScrollArea, Button, useToast, Textarea, Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, Form, FormField, FormItem, FormLabel, FormControl, Input, FormMessage, Avatar, AvatarImage, AvatarFallback, ResizablePanelGroup, ResizablePanel, ResizableHandle } from '@djangocfg/ui-nextjs';
11
+ import { Clock, MessageSquare, Loader2, Send, Plus, Headphones, User, ArrowLeft, LifeBuoy } from 'lucide-react';
12
+ import { useForm } from 'react-hook-form';
13
+ import { zodResolver } from '@hookform/resolvers/zod';
14
+ import { createExtensionConfig } from '@djangocfg/ext-base';
15
+
16
+ var __defProp = Object.defineProperty;
17
+ var __export = (target, all) => {
18
+ for (var name in all)
19
+ __defProp(target, name, { get: all[name], enumerable: true });
20
+ };
21
+
22
+ // src/api/generated/ext_support/ext_support__support/client.ts
23
+ var ExtSupportSupport = class {
24
+ client;
25
+ constructor(client) {
26
+ this.client = client;
27
+ }
28
+ /**
29
+ * ViewSet for managing support tickets. Requires authenticated user (JWT
30
+ * or Session). Staff users can see all tickets, regular users see only
31
+ * their own.
32
+ */
33
+ async ticketsList(...args) {
34
+ const isParamsObject = args.length === 1 && typeof args[0] === "object" && args[0] !== null && !Array.isArray(args[0]);
35
+ let params;
36
+ if (isParamsObject) {
37
+ params = args[0];
38
+ } else {
39
+ params = { page: args[0], page_size: args[1] };
40
+ }
41
+ const response = await this.client.request("GET", "/cfg/support/tickets/", { params });
42
+ return response;
43
+ }
44
+ /**
45
+ * ViewSet for managing support tickets. Requires authenticated user (JWT
46
+ * or Session). Staff users can see all tickets, regular users see only
47
+ * their own.
48
+ */
49
+ async ticketsCreate(data) {
50
+ const response = await this.client.request("POST", "/cfg/support/tickets/", { body: data });
51
+ return response;
52
+ }
53
+ /**
54
+ * ViewSet for managing support messages. Requires authenticated user (JWT
55
+ * or Session). Users can only access messages for their own tickets.
56
+ */
57
+ async ticketsMessagesList(...args) {
58
+ const ticket_uuid = args[0];
59
+ const isParamsObject = args.length === 2 && typeof args[1] === "object" && args[1] !== null && !Array.isArray(args[1]);
60
+ let params;
61
+ if (isParamsObject) {
62
+ params = args[1];
63
+ } else {
64
+ params = { page: args[1], page_size: args[2] };
65
+ }
66
+ const response = await this.client.request("GET", `/cfg/support/tickets/${ticket_uuid}/messages/`, { params });
67
+ return response;
68
+ }
69
+ /**
70
+ * ViewSet for managing support messages. Requires authenticated user (JWT
71
+ * or Session). Users can only access messages for their own tickets.
72
+ */
73
+ async ticketsMessagesCreate(ticket_uuid, data) {
74
+ const response = await this.client.request("POST", `/cfg/support/tickets/${ticket_uuid}/messages/`, { body: data });
75
+ return response;
76
+ }
77
+ /**
78
+ * ViewSet for managing support messages. Requires authenticated user (JWT
79
+ * or Session). Users can only access messages for their own tickets.
80
+ */
81
+ async ticketsMessagesRetrieve(ticket_uuid, uuid) {
82
+ const response = await this.client.request("GET", `/cfg/support/tickets/${ticket_uuid}/messages/${uuid}/`);
83
+ return response;
84
+ }
85
+ /**
86
+ * ViewSet for managing support messages. Requires authenticated user (JWT
87
+ * or Session). Users can only access messages for their own tickets.
88
+ */
89
+ async ticketsMessagesUpdate(ticket_uuid, uuid, data) {
90
+ const response = await this.client.request("PUT", `/cfg/support/tickets/${ticket_uuid}/messages/${uuid}/`, { body: data });
91
+ return response;
92
+ }
93
+ /**
94
+ * ViewSet for managing support messages. Requires authenticated user (JWT
95
+ * or Session). Users can only access messages for their own tickets.
96
+ */
97
+ async ticketsMessagesPartialUpdate(ticket_uuid, uuid, data) {
98
+ const response = await this.client.request("PATCH", `/cfg/support/tickets/${ticket_uuid}/messages/${uuid}/`, { body: data });
99
+ return response;
100
+ }
101
+ /**
102
+ * ViewSet for managing support messages. Requires authenticated user (JWT
103
+ * or Session). Users can only access messages for their own tickets.
104
+ */
105
+ async ticketsMessagesDestroy(ticket_uuid, uuid) {
106
+ await this.client.request("DELETE", `/cfg/support/tickets/${ticket_uuid}/messages/${uuid}/`);
107
+ return;
108
+ }
109
+ /**
110
+ * ViewSet for managing support tickets. Requires authenticated user (JWT
111
+ * or Session). Staff users can see all tickets, regular users see only
112
+ * their own.
113
+ */
114
+ async ticketsRetrieve(uuid) {
115
+ const response = await this.client.request("GET", `/cfg/support/tickets/${uuid}/`);
116
+ return response;
117
+ }
118
+ /**
119
+ * ViewSet for managing support tickets. Requires authenticated user (JWT
120
+ * or Session). Staff users can see all tickets, regular users see only
121
+ * their own.
122
+ */
123
+ async ticketsUpdate(uuid, data) {
124
+ const response = await this.client.request("PUT", `/cfg/support/tickets/${uuid}/`, { body: data });
125
+ return response;
126
+ }
127
+ /**
128
+ * ViewSet for managing support tickets. Requires authenticated user (JWT
129
+ * or Session). Staff users can see all tickets, regular users see only
130
+ * their own.
131
+ */
132
+ async ticketsPartialUpdate(uuid, data) {
133
+ const response = await this.client.request("PATCH", `/cfg/support/tickets/${uuid}/`, { body: data });
134
+ return response;
135
+ }
136
+ /**
137
+ * ViewSet for managing support tickets. Requires authenticated user (JWT
138
+ * or Session). Staff users can see all tickets, regular users see only
139
+ * their own.
140
+ */
141
+ async ticketsDestroy(uuid) {
142
+ await this.client.request("DELETE", `/cfg/support/tickets/${uuid}/`);
143
+ return;
144
+ }
145
+ };
146
+
147
+ // src/api/generated/ext_support/ext_support__support/models.ts
148
+ var models_exports = {};
149
+
150
+ // src/api/generated/ext_support/http.ts
151
+ var FetchAdapter = class {
152
+ async request(request) {
153
+ const { method, url, headers, body, params, formData } = request;
154
+ let finalUrl = url;
155
+ if (params) {
156
+ const searchParams = new URLSearchParams();
157
+ Object.entries(params).forEach(([key, value]) => {
158
+ if (value !== null && value !== void 0) {
159
+ searchParams.append(key, String(value));
160
+ }
161
+ });
162
+ const queryString = searchParams.toString();
163
+ if (queryString) {
164
+ finalUrl = url.includes("?") ? `${url}&${queryString}` : `${url}?${queryString}`;
165
+ }
166
+ }
167
+ const finalHeaders = { ...headers };
168
+ let requestBody;
169
+ if (formData) {
170
+ requestBody = formData;
171
+ } else if (body) {
172
+ finalHeaders["Content-Type"] = "application/json";
173
+ requestBody = JSON.stringify(body);
174
+ }
175
+ const response = await fetch(finalUrl, {
176
+ method,
177
+ headers: finalHeaders,
178
+ body: requestBody,
179
+ credentials: "include"
180
+ // Include Django session cookies
181
+ });
182
+ let data = null;
183
+ const contentType = response.headers.get("content-type");
184
+ if (response.status !== 204 && contentType?.includes("application/json")) {
185
+ data = await response.json();
186
+ } else if (response.status !== 204) {
187
+ data = await response.text();
188
+ }
189
+ const responseHeaders = {};
190
+ response.headers.forEach((value, key) => {
191
+ responseHeaders[key] = value;
192
+ });
193
+ return {
194
+ data,
195
+ status: response.status,
196
+ statusText: response.statusText,
197
+ headers: responseHeaders
198
+ };
199
+ }
200
+ };
201
+
202
+ // src/api/generated/ext_support/errors.ts
203
+ var APIError = class extends Error {
204
+ constructor(statusCode, statusText, response, url, message) {
205
+ super(message || `HTTP ${statusCode}: ${statusText}`);
206
+ this.statusCode = statusCode;
207
+ this.statusText = statusText;
208
+ this.response = response;
209
+ this.url = url;
210
+ this.name = "APIError";
211
+ }
212
+ /**
213
+ * Get error details from response.
214
+ * DRF typically returns: { "detail": "Error message" } or { "field": ["error1", "error2"] }
215
+ */
216
+ get details() {
217
+ if (typeof this.response === "object" && this.response !== null) {
218
+ return this.response;
219
+ }
220
+ return null;
221
+ }
222
+ /**
223
+ * Get field-specific validation errors from DRF.
224
+ * Returns: { "field_name": ["error1", "error2"], ... }
225
+ */
226
+ get fieldErrors() {
227
+ const details = this.details;
228
+ if (!details) return null;
229
+ const fieldErrors = {};
230
+ for (const [key, value] of Object.entries(details)) {
231
+ if (Array.isArray(value)) {
232
+ fieldErrors[key] = value;
233
+ }
234
+ }
235
+ return Object.keys(fieldErrors).length > 0 ? fieldErrors : null;
236
+ }
237
+ /**
238
+ * Get single error message from DRF.
239
+ * Checks for "detail", "message", or first field error.
240
+ */
241
+ get errorMessage() {
242
+ const details = this.details;
243
+ if (!details) return this.message;
244
+ if (details.detail) {
245
+ return Array.isArray(details.detail) ? details.detail.join(", ") : String(details.detail);
246
+ }
247
+ if (details.message) {
248
+ return String(details.message);
249
+ }
250
+ const fieldErrors = this.fieldErrors;
251
+ if (fieldErrors) {
252
+ const firstField = Object.keys(fieldErrors)[0];
253
+ if (firstField) {
254
+ return `${firstField}: ${fieldErrors[firstField]?.join(", ")}`;
255
+ }
256
+ }
257
+ return this.message;
258
+ }
259
+ // Helper methods for common HTTP status codes
260
+ get isValidationError() {
261
+ return this.statusCode === 400;
262
+ }
263
+ get isAuthError() {
264
+ return this.statusCode === 401;
265
+ }
266
+ get isPermissionError() {
267
+ return this.statusCode === 403;
268
+ }
269
+ get isNotFoundError() {
270
+ return this.statusCode === 404;
271
+ }
272
+ get isServerError() {
273
+ return this.statusCode >= 500 && this.statusCode < 600;
274
+ }
275
+ };
276
+ var NetworkError = class extends Error {
277
+ constructor(message, url, originalError) {
278
+ super(message);
279
+ this.url = url;
280
+ this.originalError = originalError;
281
+ this.name = "NetworkError";
282
+ }
283
+ };
284
+ var DEFAULT_CONFIG = {
285
+ enabled: process.env.NODE_ENV !== "production",
286
+ logRequests: true,
287
+ logResponses: true,
288
+ logErrors: true,
289
+ logBodies: true,
290
+ logHeaders: false
291
+ };
292
+ var SENSITIVE_HEADERS = [
293
+ "authorization",
294
+ "cookie",
295
+ "set-cookie",
296
+ "x-api-key",
297
+ "x-csrf-token"
298
+ ];
299
+ var APILogger = class {
300
+ config;
301
+ consola;
302
+ constructor(config = {}) {
303
+ this.config = { ...DEFAULT_CONFIG, ...config };
304
+ this.consola = config.consola || createConsola({
305
+ level: this.config.enabled ? 4 : 0
306
+ });
307
+ }
308
+ /**
309
+ * Enable logging
310
+ */
311
+ enable() {
312
+ this.config.enabled = true;
313
+ }
314
+ /**
315
+ * Disable logging
316
+ */
317
+ disable() {
318
+ this.config.enabled = false;
319
+ }
320
+ /**
321
+ * Update configuration
322
+ */
323
+ setConfig(config) {
324
+ this.config = { ...this.config, ...config };
325
+ }
326
+ /**
327
+ * Filter sensitive headers
328
+ */
329
+ filterHeaders(headers) {
330
+ if (!headers) return {};
331
+ const filtered = {};
332
+ Object.keys(headers).forEach((key) => {
333
+ const lowerKey = key.toLowerCase();
334
+ if (SENSITIVE_HEADERS.includes(lowerKey)) {
335
+ filtered[key] = "***";
336
+ } else {
337
+ filtered[key] = headers[key] || "";
338
+ }
339
+ });
340
+ return filtered;
341
+ }
342
+ /**
343
+ * Log request
344
+ */
345
+ logRequest(request) {
346
+ if (!this.config.enabled || !this.config.logRequests) return;
347
+ const { method, url, headers, body } = request;
348
+ this.consola.start(`${method} ${url}`);
349
+ if (this.config.logHeaders && headers) {
350
+ this.consola.debug("Headers:", this.filterHeaders(headers));
351
+ }
352
+ if (this.config.logBodies && body) {
353
+ this.consola.debug("Body:", body);
354
+ }
355
+ }
356
+ /**
357
+ * Log response
358
+ */
359
+ logResponse(request, response) {
360
+ if (!this.config.enabled || !this.config.logResponses) return;
361
+ const { method, url } = request;
362
+ const { status, statusText, data, duration } = response;
363
+ this.consola.success(
364
+ `${method} ${url} ${status} ${statusText} (${duration}ms)`
365
+ );
366
+ if (this.config.logBodies && data) {
367
+ this.consola.debug("Response:", data);
368
+ }
369
+ }
370
+ /**
371
+ * Log error
372
+ */
373
+ logError(request, error) {
374
+ if (!this.config.enabled || !this.config.logErrors) return;
375
+ const { method, url } = request;
376
+ const { message, statusCode, fieldErrors, duration } = error;
377
+ this.consola.error(
378
+ `${method} ${url} ${statusCode || "Network"} Error (${duration}ms)`
379
+ );
380
+ this.consola.error("Message:", message);
381
+ if (fieldErrors && Object.keys(fieldErrors).length > 0) {
382
+ this.consola.error("Field Errors:");
383
+ Object.entries(fieldErrors).forEach(([field, errors]) => {
384
+ errors.forEach((err) => {
385
+ this.consola.error(` \u2022 ${field}: ${err}`);
386
+ });
387
+ });
388
+ }
389
+ }
390
+ /**
391
+ * Log general info
392
+ */
393
+ info(message, ...args) {
394
+ if (!this.config.enabled) return;
395
+ this.consola.info(message, ...args);
396
+ }
397
+ /**
398
+ * Log warning
399
+ */
400
+ warn(message, ...args) {
401
+ if (!this.config.enabled) return;
402
+ this.consola.warn(message, ...args);
403
+ }
404
+ /**
405
+ * Log error
406
+ */
407
+ error(message, ...args) {
408
+ if (!this.config.enabled) return;
409
+ this.consola.error(message, ...args);
410
+ }
411
+ /**
412
+ * Log debug
413
+ */
414
+ debug(message, ...args) {
415
+ if (!this.config.enabled) return;
416
+ this.consola.debug(message, ...args);
417
+ }
418
+ /**
419
+ * Log success
420
+ */
421
+ success(message, ...args) {
422
+ if (!this.config.enabled) return;
423
+ this.consola.success(message, ...args);
424
+ }
425
+ /**
426
+ * Create a sub-logger with prefix
427
+ */
428
+ withTag(tag) {
429
+ return this.consola.withTag(tag);
430
+ }
431
+ };
432
+ new APILogger();
433
+ var DEFAULT_RETRY_CONFIG = {
434
+ retries: 3,
435
+ factor: 2,
436
+ minTimeout: 1e3,
437
+ maxTimeout: 6e4,
438
+ randomize: true,
439
+ onFailedAttempt: () => {
440
+ }
441
+ };
442
+ function shouldRetry(error) {
443
+ if (error instanceof NetworkError) {
444
+ return true;
445
+ }
446
+ if (error instanceof APIError) {
447
+ const status = error.statusCode;
448
+ if (status >= 500 && status < 600) {
449
+ return true;
450
+ }
451
+ if (status === 429) {
452
+ return true;
453
+ }
454
+ return false;
455
+ }
456
+ return true;
457
+ }
458
+ async function withRetry(fn, config) {
459
+ const finalConfig = { ...DEFAULT_RETRY_CONFIG, ...config };
460
+ return pRetry(
461
+ async () => {
462
+ try {
463
+ return await fn();
464
+ } catch (error) {
465
+ if (!shouldRetry(error)) {
466
+ throw new AbortError(error);
467
+ }
468
+ throw error;
469
+ }
470
+ },
471
+ {
472
+ retries: finalConfig.retries,
473
+ factor: finalConfig.factor,
474
+ minTimeout: finalConfig.minTimeout,
475
+ maxTimeout: finalConfig.maxTimeout,
476
+ randomize: finalConfig.randomize,
477
+ onFailedAttempt: finalConfig.onFailedAttempt ? (error) => {
478
+ const pRetryError = error;
479
+ finalConfig.onFailedAttempt({
480
+ error: pRetryError,
481
+ attemptNumber: pRetryError.attemptNumber,
482
+ retriesLeft: pRetryError.retriesLeft
483
+ });
484
+ } : void 0
485
+ }
486
+ );
487
+ }
488
+
489
+ // src/api/generated/ext_support/client.ts
490
+ var APIClient = class {
491
+ baseUrl;
492
+ httpClient;
493
+ logger = null;
494
+ retryConfig = null;
495
+ // Sub-clients
496
+ ext_support_support;
497
+ constructor(baseUrl, options) {
498
+ this.baseUrl = baseUrl.replace(/\/$/, "");
499
+ this.httpClient = options?.httpClient || new FetchAdapter();
500
+ if (options?.loggerConfig !== void 0) {
501
+ this.logger = new APILogger(options.loggerConfig);
502
+ }
503
+ if (options?.retryConfig !== void 0) {
504
+ this.retryConfig = options.retryConfig;
505
+ }
506
+ this.ext_support_support = new ExtSupportSupport(this);
507
+ }
508
+ /**
509
+ * Get CSRF token from cookies (for SessionAuthentication).
510
+ *
511
+ * Returns null if cookie doesn't exist (JWT-only auth).
512
+ */
513
+ getCsrfToken() {
514
+ const name = "csrftoken";
515
+ const value = `; ${document.cookie}`;
516
+ const parts = value.split(`; ${name}=`);
517
+ if (parts.length === 2) {
518
+ return parts.pop()?.split(";").shift() || null;
519
+ }
520
+ return null;
521
+ }
522
+ /**
523
+ * Make HTTP request with Django CSRF and session handling.
524
+ * Automatically retries on network errors and 5xx server errors.
525
+ */
526
+ async request(method, path, options) {
527
+ if (this.retryConfig) {
528
+ return withRetry(() => this._makeRequest(method, path, options), {
529
+ ...this.retryConfig,
530
+ onFailedAttempt: (info) => {
531
+ if (this.logger) {
532
+ this.logger.warn(
533
+ `Retry attempt ${info.attemptNumber}/${info.retriesLeft + info.attemptNumber} for ${method} ${path}: ${info.error.message}`
534
+ );
535
+ }
536
+ this.retryConfig?.onFailedAttempt?.(info);
537
+ }
538
+ });
539
+ }
540
+ return this._makeRequest(method, path, options);
541
+ }
542
+ /**
543
+ * Internal request method (without retry wrapper).
544
+ * Used by request() method with optional retry logic.
545
+ */
546
+ async _makeRequest(method, path, options) {
547
+ const url = this.baseUrl ? `${this.baseUrl}${path}` : path;
548
+ const startTime = Date.now();
549
+ const headers = {
550
+ ...options?.headers || {}
551
+ };
552
+ if (!options?.formData && !headers["Content-Type"]) {
553
+ headers["Content-Type"] = "application/json";
554
+ }
555
+ if (this.logger) {
556
+ this.logger.logRequest({
557
+ method,
558
+ url,
559
+ headers,
560
+ body: options?.formData || options?.body,
561
+ timestamp: startTime
562
+ });
563
+ }
564
+ try {
565
+ const response = await this.httpClient.request({
566
+ method,
567
+ url,
568
+ headers,
569
+ params: options?.params,
570
+ body: options?.body,
571
+ formData: options?.formData
572
+ });
573
+ const duration = Date.now() - startTime;
574
+ if (response.status >= 400) {
575
+ const error = new APIError(
576
+ response.status,
577
+ response.statusText,
578
+ response.data,
579
+ url
580
+ );
581
+ if (this.logger) {
582
+ this.logger.logError(
583
+ {
584
+ method,
585
+ url,
586
+ headers,
587
+ body: options?.formData || options?.body,
588
+ timestamp: startTime
589
+ },
590
+ {
591
+ message: error.message,
592
+ statusCode: response.status,
593
+ duration,
594
+ timestamp: Date.now()
595
+ }
596
+ );
597
+ }
598
+ throw error;
599
+ }
600
+ if (this.logger) {
601
+ this.logger.logResponse(
602
+ {
603
+ method,
604
+ url,
605
+ headers,
606
+ body: options?.formData || options?.body,
607
+ timestamp: startTime
608
+ },
609
+ {
610
+ status: response.status,
611
+ statusText: response.statusText,
612
+ data: response.data,
613
+ duration,
614
+ timestamp: Date.now()
615
+ }
616
+ );
617
+ }
618
+ return response.data;
619
+ } catch (error) {
620
+ const duration = Date.now() - startTime;
621
+ if (error instanceof APIError) {
622
+ throw error;
623
+ }
624
+ const isCORSError = error instanceof TypeError && (error.message.toLowerCase().includes("cors") || error.message.toLowerCase().includes("failed to fetch") || error.message.toLowerCase().includes("network request failed"));
625
+ if (this.logger) {
626
+ if (isCORSError) {
627
+ this.logger.error(`\u{1F6AB} CORS Error: ${method} ${url}`);
628
+ this.logger.error(` \u2192 ${error instanceof Error ? error.message : String(error)}`);
629
+ this.logger.error(` \u2192 Configure security_domains parameter on the server`);
630
+ } else {
631
+ this.logger.error(`\u26A0\uFE0F Network Error: ${method} ${url}`);
632
+ this.logger.error(` \u2192 ${error instanceof Error ? error.message : String(error)}`);
633
+ }
634
+ }
635
+ if (typeof window !== "undefined") {
636
+ try {
637
+ if (isCORSError) {
638
+ window.dispatchEvent(new CustomEvent("cors-error", {
639
+ detail: {
640
+ url,
641
+ method,
642
+ error: error instanceof Error ? error.message : String(error),
643
+ timestamp: /* @__PURE__ */ new Date()
644
+ },
645
+ bubbles: true,
646
+ cancelable: false
647
+ }));
648
+ } else {
649
+ window.dispatchEvent(new CustomEvent("network-error", {
650
+ detail: {
651
+ url,
652
+ method,
653
+ error: error instanceof Error ? error.message : String(error),
654
+ timestamp: /* @__PURE__ */ new Date()
655
+ },
656
+ bubbles: true,
657
+ cancelable: false
658
+ }));
659
+ }
660
+ } catch (eventError) {
661
+ }
662
+ }
663
+ const networkError = error instanceof Error ? new NetworkError(error.message, url, error) : new NetworkError("Unknown error", url);
664
+ if (this.logger) {
665
+ this.logger.logError(
666
+ {
667
+ method,
668
+ url,
669
+ headers,
670
+ body: options?.formData || options?.body,
671
+ timestamp: startTime
672
+ },
673
+ {
674
+ message: networkError.message,
675
+ duration,
676
+ timestamp: Date.now()
677
+ }
678
+ );
679
+ }
680
+ throw networkError;
681
+ }
682
+ }
683
+ };
684
+
685
+ // src/api/generated/ext_support/storage.ts
686
+ var LocalStorageAdapter = class {
687
+ logger;
688
+ constructor(logger2) {
689
+ this.logger = logger2;
690
+ }
691
+ getItem(key) {
692
+ try {
693
+ if (typeof window !== "undefined" && window.localStorage) {
694
+ const value = localStorage.getItem(key);
695
+ this.logger?.debug(`LocalStorage.getItem("${key}"): ${value ? "found" : "not found"}`);
696
+ return value;
697
+ }
698
+ this.logger?.warn("LocalStorage not available: window.localStorage is undefined");
699
+ } catch (error) {
700
+ this.logger?.error("LocalStorage.getItem failed:", error);
701
+ }
702
+ return null;
703
+ }
704
+ setItem(key, value) {
705
+ try {
706
+ if (typeof window !== "undefined" && window.localStorage) {
707
+ localStorage.setItem(key, value);
708
+ this.logger?.debug(`LocalStorage.setItem("${key}"): success`);
709
+ } else {
710
+ this.logger?.warn("LocalStorage not available: window.localStorage is undefined");
711
+ }
712
+ } catch (error) {
713
+ this.logger?.error("LocalStorage.setItem failed:", error);
714
+ }
715
+ }
716
+ removeItem(key) {
717
+ try {
718
+ if (typeof window !== "undefined" && window.localStorage) {
719
+ localStorage.removeItem(key);
720
+ this.logger?.debug(`LocalStorage.removeItem("${key}"): success`);
721
+ } else {
722
+ this.logger?.warn("LocalStorage not available: window.localStorage is undefined");
723
+ }
724
+ } catch (error) {
725
+ this.logger?.error("LocalStorage.removeItem failed:", error);
726
+ }
727
+ }
728
+ };
729
+ var CookieStorageAdapter = class {
730
+ logger;
731
+ constructor(logger2) {
732
+ this.logger = logger2;
733
+ }
734
+ getItem(key) {
735
+ try {
736
+ if (typeof document === "undefined") {
737
+ this.logger?.warn("Cookies not available: document is undefined (SSR context?)");
738
+ return null;
739
+ }
740
+ const value = `; ${document.cookie}`;
741
+ const parts = value.split(`; ${key}=`);
742
+ if (parts.length === 2) {
743
+ const result = parts.pop()?.split(";").shift() || null;
744
+ this.logger?.debug(`CookieStorage.getItem("${key}"): ${result ? "found" : "not found"}`);
745
+ return result;
746
+ }
747
+ this.logger?.debug(`CookieStorage.getItem("${key}"): not found`);
748
+ } catch (error) {
749
+ this.logger?.error("CookieStorage.getItem failed:", error);
750
+ }
751
+ return null;
752
+ }
753
+ setItem(key, value) {
754
+ try {
755
+ if (typeof document !== "undefined") {
756
+ document.cookie = `${key}=${value}; path=/; max-age=31536000`;
757
+ this.logger?.debug(`CookieStorage.setItem("${key}"): success`);
758
+ } else {
759
+ this.logger?.warn("Cookies not available: document is undefined (SSR context?)");
760
+ }
761
+ } catch (error) {
762
+ this.logger?.error("CookieStorage.setItem failed:", error);
763
+ }
764
+ }
765
+ removeItem(key) {
766
+ try {
767
+ if (typeof document !== "undefined") {
768
+ document.cookie = `${key}=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT`;
769
+ this.logger?.debug(`CookieStorage.removeItem("${key}"): success`);
770
+ } else {
771
+ this.logger?.warn("Cookies not available: document is undefined (SSR context?)");
772
+ }
773
+ } catch (error) {
774
+ this.logger?.error("CookieStorage.removeItem failed:", error);
775
+ }
776
+ }
777
+ };
778
+ var MemoryStorageAdapter = class {
779
+ storage = /* @__PURE__ */ new Map();
780
+ logger;
781
+ constructor(logger2) {
782
+ this.logger = logger2;
783
+ }
784
+ getItem(key) {
785
+ const value = this.storage.get(key) || null;
786
+ this.logger?.debug(`MemoryStorage.getItem("${key}"): ${value ? "found" : "not found"}`);
787
+ return value;
788
+ }
789
+ setItem(key, value) {
790
+ this.storage.set(key, value);
791
+ this.logger?.debug(`MemoryStorage.setItem("${key}"): success`);
792
+ }
793
+ removeItem(key) {
794
+ this.storage.delete(key);
795
+ this.logger?.debug(`MemoryStorage.removeItem("${key}"): success`);
796
+ }
797
+ };
798
+
799
+ // src/api/generated/ext_support/enums.ts
800
+ var enums_exports = {};
801
+ __export(enums_exports, {
802
+ PatchedTicketRequestStatus: () => PatchedTicketRequestStatus,
803
+ TicketRequestStatus: () => TicketRequestStatus,
804
+ TicketStatus: () => TicketStatus
805
+ });
806
+ var PatchedTicketRequestStatus = /* @__PURE__ */ ((PatchedTicketRequestStatus2) => {
807
+ PatchedTicketRequestStatus2["OPEN"] = "open";
808
+ PatchedTicketRequestStatus2["WAITING_FOR_USER"] = "waiting_for_user";
809
+ PatchedTicketRequestStatus2["WAITING_FOR_ADMIN"] = "waiting_for_admin";
810
+ PatchedTicketRequestStatus2["RESOLVED"] = "resolved";
811
+ PatchedTicketRequestStatus2["CLOSED"] = "closed";
812
+ return PatchedTicketRequestStatus2;
813
+ })(PatchedTicketRequestStatus || {});
814
+ var TicketStatus = /* @__PURE__ */ ((TicketStatus2) => {
815
+ TicketStatus2["OPEN"] = "open";
816
+ TicketStatus2["WAITING_FOR_USER"] = "waiting_for_user";
817
+ TicketStatus2["WAITING_FOR_ADMIN"] = "waiting_for_admin";
818
+ TicketStatus2["RESOLVED"] = "resolved";
819
+ TicketStatus2["CLOSED"] = "closed";
820
+ return TicketStatus2;
821
+ })(TicketStatus || {});
822
+ var TicketRequestStatus = /* @__PURE__ */ ((TicketRequestStatus2) => {
823
+ TicketRequestStatus2["OPEN"] = "open";
824
+ TicketRequestStatus2["WAITING_FOR_USER"] = "waiting_for_user";
825
+ TicketRequestStatus2["WAITING_FOR_ADMIN"] = "waiting_for_admin";
826
+ TicketRequestStatus2["RESOLVED"] = "resolved";
827
+ TicketRequestStatus2["CLOSED"] = "closed";
828
+ return TicketRequestStatus2;
829
+ })(TicketRequestStatus || {});
830
+
831
+ // src/api/generated/ext_support/_utils/schemas/index.ts
832
+ var schemas_exports = {};
833
+ __export(schemas_exports, {
834
+ MessageCreateRequestSchema: () => MessageCreateRequestSchema,
835
+ MessageCreateSchema: () => MessageCreateSchema,
836
+ MessageRequestSchema: () => MessageRequestSchema,
837
+ MessageSchema: () => MessageSchema,
838
+ PaginatedMessageListSchema: () => PaginatedMessageListSchema,
839
+ PaginatedTicketListSchema: () => PaginatedTicketListSchema,
840
+ PatchedMessageRequestSchema: () => PatchedMessageRequestSchema,
841
+ PatchedTicketRequestSchema: () => PatchedTicketRequestSchema,
842
+ SenderSchema: () => SenderSchema,
843
+ TicketRequestSchema: () => TicketRequestSchema,
844
+ TicketSchema: () => TicketSchema
845
+ });
846
+ var SenderSchema = z.object({
847
+ id: z.int(),
848
+ display_username: z.string(),
849
+ email: z.email(),
850
+ avatar: z.string().nullable(),
851
+ initials: z.string(),
852
+ is_staff: z.boolean(),
853
+ is_superuser: z.boolean()
854
+ });
855
+
856
+ // src/api/generated/ext_support/_utils/schemas/Message.schema.ts
857
+ var MessageSchema = z.object({
858
+ uuid: z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),
859
+ ticket: z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),
860
+ sender: SenderSchema,
861
+ is_from_author: z.boolean(),
862
+ text: z.string(),
863
+ created_at: z.iso.datetime()
864
+ });
865
+ var MessageCreateSchema = z.object({
866
+ text: z.string()
867
+ });
868
+ var MessageCreateRequestSchema = z.object({
869
+ text: z.string().min(1)
870
+ });
871
+ var MessageRequestSchema = z.object({
872
+ text: z.string().min(1)
873
+ });
874
+ var PaginatedMessageListSchema = z.object({
875
+ count: z.int(),
876
+ page: z.int(),
877
+ pages: z.int(),
878
+ page_size: z.int(),
879
+ has_next: z.boolean(),
880
+ has_previous: z.boolean(),
881
+ next_page: z.int().nullable().optional(),
882
+ previous_page: z.int().nullable().optional(),
883
+ results: z.array(MessageSchema)
884
+ });
885
+ var TicketSchema = z.object({
886
+ uuid: z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),
887
+ user: z.int(),
888
+ subject: z.string().max(255),
889
+ status: z.nativeEnum(TicketStatus).optional(),
890
+ created_at: z.iso.datetime(),
891
+ unanswered_messages_count: z.int()
892
+ });
893
+
894
+ // src/api/generated/ext_support/_utils/schemas/PaginatedTicketList.schema.ts
895
+ var PaginatedTicketListSchema = z.object({
896
+ count: z.int(),
897
+ page: z.int(),
898
+ pages: z.int(),
899
+ page_size: z.int(),
900
+ has_next: z.boolean(),
901
+ has_previous: z.boolean(),
902
+ next_page: z.int().nullable().optional(),
903
+ previous_page: z.int().nullable().optional(),
904
+ results: z.array(TicketSchema)
905
+ });
906
+ var PatchedMessageRequestSchema = z.object({
907
+ text: z.string().min(1).optional()
908
+ });
909
+ var PatchedTicketRequestSchema = z.object({
910
+ user: z.int().optional(),
911
+ subject: z.string().min(1).max(255).optional(),
912
+ status: z.nativeEnum(PatchedTicketRequestStatus).optional()
913
+ });
914
+ var TicketRequestSchema = z.object({
915
+ user: z.int(),
916
+ subject: z.string().min(1).max(255),
917
+ status: z.nativeEnum(TicketRequestStatus).optional()
918
+ });
919
+
920
+ // src/api/generated/ext_support/validation-events.ts
921
+ function dispatchValidationError(detail) {
922
+ if (typeof window === "undefined") {
923
+ return;
924
+ }
925
+ try {
926
+ const event = new CustomEvent("zod-validation-error", {
927
+ detail,
928
+ bubbles: true,
929
+ cancelable: false
930
+ });
931
+ window.dispatchEvent(event);
932
+ } catch (error) {
933
+ console.warn("Failed to dispatch validation error event:", error);
934
+ }
935
+ }
936
+ function onValidationError(callback) {
937
+ if (typeof window === "undefined") {
938
+ return () => {
939
+ };
940
+ }
941
+ const handler = (event) => {
942
+ if (event instanceof CustomEvent) {
943
+ callback(event.detail);
944
+ }
945
+ };
946
+ window.addEventListener("zod-validation-error", handler);
947
+ return () => {
948
+ window.removeEventListener("zod-validation-error", handler);
949
+ };
950
+ }
951
+ function formatZodError(error) {
952
+ const issues = error.issues.map((issue, index) => {
953
+ const path = issue.path.join(".") || "root";
954
+ const parts = [`${index + 1}. ${path}: ${issue.message}`];
955
+ if ("expected" in issue && issue.expected) {
956
+ parts.push(` Expected: ${issue.expected}`);
957
+ }
958
+ if ("received" in issue && issue.received) {
959
+ parts.push(` Received: ${issue.received}`);
960
+ }
961
+ return parts.join("\n");
962
+ });
963
+ return issues.join("\n");
964
+ }
965
+
966
+ // src/api/generated/ext_support/_utils/fetchers/index.ts
967
+ var fetchers_exports = {};
968
+ __export(fetchers_exports, {
969
+ createSupportTicketsCreate: () => createSupportTicketsCreate,
970
+ createSupportTicketsMessagesCreate: () => createSupportTicketsMessagesCreate,
971
+ deleteSupportTicketsDestroy: () => deleteSupportTicketsDestroy,
972
+ deleteSupportTicketsMessagesDestroy: () => deleteSupportTicketsMessagesDestroy,
973
+ getSupportTicketsList: () => getSupportTicketsList,
974
+ getSupportTicketsMessagesList: () => getSupportTicketsMessagesList,
975
+ getSupportTicketsMessagesRetrieve: () => getSupportTicketsMessagesRetrieve,
976
+ getSupportTicketsRetrieve: () => getSupportTicketsRetrieve,
977
+ partialUpdateSupportTicketsMessagesPartialUpdate: () => partialUpdateSupportTicketsMessagesPartialUpdate,
978
+ partialUpdateSupportTicketsPartialUpdate: () => partialUpdateSupportTicketsPartialUpdate,
979
+ updateSupportTicketsMessagesUpdate: () => updateSupportTicketsMessagesUpdate,
980
+ updateSupportTicketsUpdate: () => updateSupportTicketsUpdate
981
+ });
982
+
983
+ // src/api/generated/ext_support/api-instance.ts
984
+ var globalAPI = null;
985
+ function getAPIInstance() {
986
+ if (!globalAPI) {
987
+ throw new Error(
988
+ 'API not configured. Call configureAPI() with your base URL before using fetchers or hooks.\n\nExample:\n import { configureAPI } from "./api-instance"\n configureAPI({ baseUrl: "https://api.example.com" })'
989
+ );
990
+ }
991
+ return globalAPI;
992
+ }
993
+ function isAPIConfigured() {
994
+ return globalAPI !== null;
995
+ }
996
+ function configureAPI(config) {
997
+ globalAPI = new API(config.baseUrl, config.options);
998
+ if (config.token) {
999
+ globalAPI.setToken(config.token, config.refreshToken);
1000
+ }
1001
+ return globalAPI;
1002
+ }
1003
+ function reconfigureAPI(updates) {
1004
+ const instance = getAPIInstance();
1005
+ if (updates.baseUrl) {
1006
+ instance.setBaseUrl(updates.baseUrl);
1007
+ }
1008
+ if (updates.token) {
1009
+ instance.setToken(updates.token, updates.refreshToken);
1010
+ }
1011
+ return instance;
1012
+ }
1013
+ function clearAPITokens() {
1014
+ const instance = getAPIInstance();
1015
+ instance.clearTokens();
1016
+ }
1017
+ function resetAPI() {
1018
+ if (globalAPI) {
1019
+ globalAPI.clearTokens();
1020
+ }
1021
+ globalAPI = null;
1022
+ }
1023
+
1024
+ // src/api/generated/ext_support/_utils/fetchers/ext_support__support.ts
1025
+ async function getSupportTicketsList(params, client) {
1026
+ const api = client || getAPIInstance();
1027
+ const response = await api.ext_support_support.ticketsList(params?.page, params?.page_size);
1028
+ try {
1029
+ return PaginatedTicketListSchema.parse(response);
1030
+ } catch (error) {
1031
+ consola.error("\u274C Zod Validation Failed");
1032
+ consola.box(`getSupportTicketsList
1033
+ Path: /cfg/support/tickets/
1034
+ Method: GET`);
1035
+ if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1036
+ consola.error("Validation Issues:");
1037
+ error.issues.forEach((issue, index) => {
1038
+ consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1039
+ consola.error(` \u251C\u2500 Message: ${issue.message}`);
1040
+ if (issue.expected) consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1041
+ if (issue.received) consola.error(` \u2514\u2500 Received: ${issue.received}`);
1042
+ });
1043
+ }
1044
+ consola.error("Response data:", response);
1045
+ if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1046
+ try {
1047
+ const event = new CustomEvent("zod-validation-error", {
1048
+ detail: {
1049
+ operation: "getSupportTicketsList",
1050
+ path: "/cfg/support/tickets/",
1051
+ method: "GET",
1052
+ error,
1053
+ response,
1054
+ timestamp: /* @__PURE__ */ new Date()
1055
+ },
1056
+ bubbles: true,
1057
+ cancelable: false
1058
+ });
1059
+ window.dispatchEvent(event);
1060
+ } catch (eventError) {
1061
+ consola.warn("Failed to dispatch validation error event:", eventError);
1062
+ }
1063
+ }
1064
+ throw error;
1065
+ }
1066
+ }
1067
+ async function createSupportTicketsCreate(data, client) {
1068
+ const api = client || getAPIInstance();
1069
+ const response = await api.ext_support_support.ticketsCreate(data);
1070
+ try {
1071
+ return TicketSchema.parse(response);
1072
+ } catch (error) {
1073
+ consola.error("\u274C Zod Validation Failed");
1074
+ consola.box(`createSupportTicketsCreate
1075
+ Path: /cfg/support/tickets/
1076
+ Method: POST`);
1077
+ if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1078
+ consola.error("Validation Issues:");
1079
+ error.issues.forEach((issue, index) => {
1080
+ consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1081
+ consola.error(` \u251C\u2500 Message: ${issue.message}`);
1082
+ if (issue.expected) consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1083
+ if (issue.received) consola.error(` \u2514\u2500 Received: ${issue.received}`);
1084
+ });
1085
+ }
1086
+ consola.error("Response data:", response);
1087
+ if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1088
+ try {
1089
+ const event = new CustomEvent("zod-validation-error", {
1090
+ detail: {
1091
+ operation: "createSupportTicketsCreate",
1092
+ path: "/cfg/support/tickets/",
1093
+ method: "POST",
1094
+ error,
1095
+ response,
1096
+ timestamp: /* @__PURE__ */ new Date()
1097
+ },
1098
+ bubbles: true,
1099
+ cancelable: false
1100
+ });
1101
+ window.dispatchEvent(event);
1102
+ } catch (eventError) {
1103
+ consola.warn("Failed to dispatch validation error event:", eventError);
1104
+ }
1105
+ }
1106
+ throw error;
1107
+ }
1108
+ }
1109
+ async function getSupportTicketsMessagesList(ticket_uuid, params, client) {
1110
+ const api = client || getAPIInstance();
1111
+ const response = await api.ext_support_support.ticketsMessagesList(ticket_uuid, params?.page, params?.page_size);
1112
+ try {
1113
+ return PaginatedMessageListSchema.parse(response);
1114
+ } catch (error) {
1115
+ consola.error("\u274C Zod Validation Failed");
1116
+ consola.box(`getSupportTicketsMessagesList
1117
+ Path: /cfg/support/tickets/{ticket_uuid}/messages/
1118
+ Method: GET`);
1119
+ if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1120
+ consola.error("Validation Issues:");
1121
+ error.issues.forEach((issue, index) => {
1122
+ consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1123
+ consola.error(` \u251C\u2500 Message: ${issue.message}`);
1124
+ if (issue.expected) consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1125
+ if (issue.received) consola.error(` \u2514\u2500 Received: ${issue.received}`);
1126
+ });
1127
+ }
1128
+ consola.error("Response data:", response);
1129
+ if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1130
+ try {
1131
+ const event = new CustomEvent("zod-validation-error", {
1132
+ detail: {
1133
+ operation: "getSupportTicketsMessagesList",
1134
+ path: "/cfg/support/tickets/{ticket_uuid}/messages/",
1135
+ method: "GET",
1136
+ error,
1137
+ response,
1138
+ timestamp: /* @__PURE__ */ new Date()
1139
+ },
1140
+ bubbles: true,
1141
+ cancelable: false
1142
+ });
1143
+ window.dispatchEvent(event);
1144
+ } catch (eventError) {
1145
+ consola.warn("Failed to dispatch validation error event:", eventError);
1146
+ }
1147
+ }
1148
+ throw error;
1149
+ }
1150
+ }
1151
+ async function createSupportTicketsMessagesCreate(ticket_uuid, data, client) {
1152
+ const api = client || getAPIInstance();
1153
+ const response = await api.ext_support_support.ticketsMessagesCreate(ticket_uuid, data);
1154
+ try {
1155
+ return MessageCreateSchema.parse(response);
1156
+ } catch (error) {
1157
+ consola.error("\u274C Zod Validation Failed");
1158
+ consola.box(`createSupportTicketsMessagesCreate
1159
+ Path: /cfg/support/tickets/{ticket_uuid}/messages/
1160
+ Method: POST`);
1161
+ if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1162
+ consola.error("Validation Issues:");
1163
+ error.issues.forEach((issue, index) => {
1164
+ consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1165
+ consola.error(` \u251C\u2500 Message: ${issue.message}`);
1166
+ if (issue.expected) consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1167
+ if (issue.received) consola.error(` \u2514\u2500 Received: ${issue.received}`);
1168
+ });
1169
+ }
1170
+ consola.error("Response data:", response);
1171
+ if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1172
+ try {
1173
+ const event = new CustomEvent("zod-validation-error", {
1174
+ detail: {
1175
+ operation: "createSupportTicketsMessagesCreate",
1176
+ path: "/cfg/support/tickets/{ticket_uuid}/messages/",
1177
+ method: "POST",
1178
+ error,
1179
+ response,
1180
+ timestamp: /* @__PURE__ */ new Date()
1181
+ },
1182
+ bubbles: true,
1183
+ cancelable: false
1184
+ });
1185
+ window.dispatchEvent(event);
1186
+ } catch (eventError) {
1187
+ consola.warn("Failed to dispatch validation error event:", eventError);
1188
+ }
1189
+ }
1190
+ throw error;
1191
+ }
1192
+ }
1193
+ async function getSupportTicketsMessagesRetrieve(ticket_uuid, uuid, client) {
1194
+ const api = client || getAPIInstance();
1195
+ const response = await api.ext_support_support.ticketsMessagesRetrieve(ticket_uuid, uuid);
1196
+ try {
1197
+ return MessageSchema.parse(response);
1198
+ } catch (error) {
1199
+ consola.error("\u274C Zod Validation Failed");
1200
+ consola.box(`getSupportTicketsMessagesRetrieve
1201
+ Path: /cfg/support/tickets/{ticket_uuid}/messages/{uuid}/
1202
+ Method: GET`);
1203
+ if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1204
+ consola.error("Validation Issues:");
1205
+ error.issues.forEach((issue, index) => {
1206
+ consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1207
+ consola.error(` \u251C\u2500 Message: ${issue.message}`);
1208
+ if (issue.expected) consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1209
+ if (issue.received) consola.error(` \u2514\u2500 Received: ${issue.received}`);
1210
+ });
1211
+ }
1212
+ consola.error("Response data:", response);
1213
+ if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1214
+ try {
1215
+ const event = new CustomEvent("zod-validation-error", {
1216
+ detail: {
1217
+ operation: "getSupportTicketsMessagesRetrieve",
1218
+ path: "/cfg/support/tickets/{ticket_uuid}/messages/{uuid}/",
1219
+ method: "GET",
1220
+ error,
1221
+ response,
1222
+ timestamp: /* @__PURE__ */ new Date()
1223
+ },
1224
+ bubbles: true,
1225
+ cancelable: false
1226
+ });
1227
+ window.dispatchEvent(event);
1228
+ } catch (eventError) {
1229
+ consola.warn("Failed to dispatch validation error event:", eventError);
1230
+ }
1231
+ }
1232
+ throw error;
1233
+ }
1234
+ }
1235
+ async function updateSupportTicketsMessagesUpdate(ticket_uuid, uuid, data, client) {
1236
+ const api = client || getAPIInstance();
1237
+ const response = await api.ext_support_support.ticketsMessagesUpdate(ticket_uuid, uuid, data);
1238
+ try {
1239
+ return MessageSchema.parse(response);
1240
+ } catch (error) {
1241
+ consola.error("\u274C Zod Validation Failed");
1242
+ consola.box(`updateSupportTicketsMessagesUpdate
1243
+ Path: /cfg/support/tickets/{ticket_uuid}/messages/{uuid}/
1244
+ Method: PUT`);
1245
+ if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1246
+ consola.error("Validation Issues:");
1247
+ error.issues.forEach((issue, index) => {
1248
+ consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1249
+ consola.error(` \u251C\u2500 Message: ${issue.message}`);
1250
+ if (issue.expected) consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1251
+ if (issue.received) consola.error(` \u2514\u2500 Received: ${issue.received}`);
1252
+ });
1253
+ }
1254
+ consola.error("Response data:", response);
1255
+ if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1256
+ try {
1257
+ const event = new CustomEvent("zod-validation-error", {
1258
+ detail: {
1259
+ operation: "updateSupportTicketsMessagesUpdate",
1260
+ path: "/cfg/support/tickets/{ticket_uuid}/messages/{uuid}/",
1261
+ method: "PUT",
1262
+ error,
1263
+ response,
1264
+ timestamp: /* @__PURE__ */ new Date()
1265
+ },
1266
+ bubbles: true,
1267
+ cancelable: false
1268
+ });
1269
+ window.dispatchEvent(event);
1270
+ } catch (eventError) {
1271
+ consola.warn("Failed to dispatch validation error event:", eventError);
1272
+ }
1273
+ }
1274
+ throw error;
1275
+ }
1276
+ }
1277
+ async function partialUpdateSupportTicketsMessagesPartialUpdate(ticket_uuid, uuid, data, client) {
1278
+ const api = client || getAPIInstance();
1279
+ const response = await api.ext_support_support.ticketsMessagesPartialUpdate(ticket_uuid, uuid, data);
1280
+ try {
1281
+ return MessageSchema.parse(response);
1282
+ } catch (error) {
1283
+ consola.error("\u274C Zod Validation Failed");
1284
+ consola.box(`partialUpdateSupportTicketsMessagesPartialUpdate
1285
+ Path: /cfg/support/tickets/{ticket_uuid}/messages/{uuid}/
1286
+ Method: PATCH`);
1287
+ if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1288
+ consola.error("Validation Issues:");
1289
+ error.issues.forEach((issue, index) => {
1290
+ consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1291
+ consola.error(` \u251C\u2500 Message: ${issue.message}`);
1292
+ if (issue.expected) consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1293
+ if (issue.received) consola.error(` \u2514\u2500 Received: ${issue.received}`);
1294
+ });
1295
+ }
1296
+ consola.error("Response data:", response);
1297
+ if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1298
+ try {
1299
+ const event = new CustomEvent("zod-validation-error", {
1300
+ detail: {
1301
+ operation: "partialUpdateSupportTicketsMessagesPartialUpdate",
1302
+ path: "/cfg/support/tickets/{ticket_uuid}/messages/{uuid}/",
1303
+ method: "PATCH",
1304
+ error,
1305
+ response,
1306
+ timestamp: /* @__PURE__ */ new Date()
1307
+ },
1308
+ bubbles: true,
1309
+ cancelable: false
1310
+ });
1311
+ window.dispatchEvent(event);
1312
+ } catch (eventError) {
1313
+ consola.warn("Failed to dispatch validation error event:", eventError);
1314
+ }
1315
+ }
1316
+ throw error;
1317
+ }
1318
+ }
1319
+ async function deleteSupportTicketsMessagesDestroy(ticket_uuid, uuid, client) {
1320
+ const api = client || getAPIInstance();
1321
+ const response = await api.ext_support_support.ticketsMessagesDestroy(ticket_uuid, uuid);
1322
+ return response;
1323
+ }
1324
+ async function getSupportTicketsRetrieve(uuid, client) {
1325
+ const api = client || getAPIInstance();
1326
+ const response = await api.ext_support_support.ticketsRetrieve(uuid);
1327
+ try {
1328
+ return TicketSchema.parse(response);
1329
+ } catch (error) {
1330
+ consola.error("\u274C Zod Validation Failed");
1331
+ consola.box(`getSupportTicketsRetrieve
1332
+ Path: /cfg/support/tickets/{uuid}/
1333
+ Method: GET`);
1334
+ if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1335
+ consola.error("Validation Issues:");
1336
+ error.issues.forEach((issue, index) => {
1337
+ consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1338
+ consola.error(` \u251C\u2500 Message: ${issue.message}`);
1339
+ if (issue.expected) consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1340
+ if (issue.received) consola.error(` \u2514\u2500 Received: ${issue.received}`);
1341
+ });
1342
+ }
1343
+ consola.error("Response data:", response);
1344
+ if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1345
+ try {
1346
+ const event = new CustomEvent("zod-validation-error", {
1347
+ detail: {
1348
+ operation: "getSupportTicketsRetrieve",
1349
+ path: "/cfg/support/tickets/{uuid}/",
1350
+ method: "GET",
1351
+ error,
1352
+ response,
1353
+ timestamp: /* @__PURE__ */ new Date()
1354
+ },
1355
+ bubbles: true,
1356
+ cancelable: false
1357
+ });
1358
+ window.dispatchEvent(event);
1359
+ } catch (eventError) {
1360
+ consola.warn("Failed to dispatch validation error event:", eventError);
1361
+ }
1362
+ }
1363
+ throw error;
1364
+ }
1365
+ }
1366
+ async function updateSupportTicketsUpdate(uuid, data, client) {
1367
+ const api = client || getAPIInstance();
1368
+ const response = await api.ext_support_support.ticketsUpdate(uuid, data);
1369
+ try {
1370
+ return TicketSchema.parse(response);
1371
+ } catch (error) {
1372
+ consola.error("\u274C Zod Validation Failed");
1373
+ consola.box(`updateSupportTicketsUpdate
1374
+ Path: /cfg/support/tickets/{uuid}/
1375
+ Method: PUT`);
1376
+ if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1377
+ consola.error("Validation Issues:");
1378
+ error.issues.forEach((issue, index) => {
1379
+ consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1380
+ consola.error(` \u251C\u2500 Message: ${issue.message}`);
1381
+ if (issue.expected) consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1382
+ if (issue.received) consola.error(` \u2514\u2500 Received: ${issue.received}`);
1383
+ });
1384
+ }
1385
+ consola.error("Response data:", response);
1386
+ if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1387
+ try {
1388
+ const event = new CustomEvent("zod-validation-error", {
1389
+ detail: {
1390
+ operation: "updateSupportTicketsUpdate",
1391
+ path: "/cfg/support/tickets/{uuid}/",
1392
+ method: "PUT",
1393
+ error,
1394
+ response,
1395
+ timestamp: /* @__PURE__ */ new Date()
1396
+ },
1397
+ bubbles: true,
1398
+ cancelable: false
1399
+ });
1400
+ window.dispatchEvent(event);
1401
+ } catch (eventError) {
1402
+ consola.warn("Failed to dispatch validation error event:", eventError);
1403
+ }
1404
+ }
1405
+ throw error;
1406
+ }
1407
+ }
1408
+ async function partialUpdateSupportTicketsPartialUpdate(uuid, data, client) {
1409
+ const api = client || getAPIInstance();
1410
+ const response = await api.ext_support_support.ticketsPartialUpdate(uuid, data);
1411
+ try {
1412
+ return TicketSchema.parse(response);
1413
+ } catch (error) {
1414
+ consola.error("\u274C Zod Validation Failed");
1415
+ consola.box(`partialUpdateSupportTicketsPartialUpdate
1416
+ Path: /cfg/support/tickets/{uuid}/
1417
+ Method: PATCH`);
1418
+ if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1419
+ consola.error("Validation Issues:");
1420
+ error.issues.forEach((issue, index) => {
1421
+ consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1422
+ consola.error(` \u251C\u2500 Message: ${issue.message}`);
1423
+ if (issue.expected) consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1424
+ if (issue.received) consola.error(` \u2514\u2500 Received: ${issue.received}`);
1425
+ });
1426
+ }
1427
+ consola.error("Response data:", response);
1428
+ if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1429
+ try {
1430
+ const event = new CustomEvent("zod-validation-error", {
1431
+ detail: {
1432
+ operation: "partialUpdateSupportTicketsPartialUpdate",
1433
+ path: "/cfg/support/tickets/{uuid}/",
1434
+ method: "PATCH",
1435
+ error,
1436
+ response,
1437
+ timestamp: /* @__PURE__ */ new Date()
1438
+ },
1439
+ bubbles: true,
1440
+ cancelable: false
1441
+ });
1442
+ window.dispatchEvent(event);
1443
+ } catch (eventError) {
1444
+ consola.warn("Failed to dispatch validation error event:", eventError);
1445
+ }
1446
+ }
1447
+ throw error;
1448
+ }
1449
+ }
1450
+ async function deleteSupportTicketsDestroy(uuid, client) {
1451
+ const api = client || getAPIInstance();
1452
+ const response = await api.ext_support_support.ticketsDestroy(uuid);
1453
+ return response;
1454
+ }
1455
+
1456
+ // src/api/generated/ext_support/index.ts
1457
+ var TOKEN_KEY = "auth_token";
1458
+ var REFRESH_TOKEN_KEY = "refresh_token";
1459
+ var API = class {
1460
+ baseUrl;
1461
+ _client;
1462
+ _token = null;
1463
+ _refreshToken = null;
1464
+ storage;
1465
+ options;
1466
+ // Sub-clients
1467
+ ext_support_support;
1468
+ constructor(baseUrl, options) {
1469
+ this.baseUrl = baseUrl;
1470
+ this.options = options;
1471
+ const logger2 = options?.loggerConfig ? new APILogger(options.loggerConfig) : void 0;
1472
+ this.storage = options?.storage || new LocalStorageAdapter(logger2);
1473
+ this._loadTokensFromStorage();
1474
+ this._client = new APIClient(this.baseUrl, {
1475
+ retryConfig: this.options?.retryConfig,
1476
+ loggerConfig: this.options?.loggerConfig
1477
+ });
1478
+ this._injectAuthHeader();
1479
+ this.ext_support_support = this._client.ext_support_support;
1480
+ }
1481
+ _loadTokensFromStorage() {
1482
+ this._token = this.storage.getItem(TOKEN_KEY);
1483
+ this._refreshToken = this.storage.getItem(REFRESH_TOKEN_KEY);
1484
+ }
1485
+ _reinitClients() {
1486
+ this._client = new APIClient(this.baseUrl, {
1487
+ retryConfig: this.options?.retryConfig,
1488
+ loggerConfig: this.options?.loggerConfig
1489
+ });
1490
+ this._injectAuthHeader();
1491
+ this.ext_support_support = this._client.ext_support_support;
1492
+ }
1493
+ _injectAuthHeader() {
1494
+ const originalRequest = this._client.request.bind(this._client);
1495
+ this._client.request = async (method, path, options) => {
1496
+ const token = this.getToken();
1497
+ const mergedOptions = {
1498
+ ...options,
1499
+ headers: {
1500
+ ...options?.headers || {},
1501
+ ...token ? { "Authorization": `Bearer ${token}` } : {}
1502
+ }
1503
+ };
1504
+ return originalRequest(method, path, mergedOptions);
1505
+ };
1506
+ }
1507
+ /**
1508
+ * Get current JWT token
1509
+ */
1510
+ getToken() {
1511
+ return this.storage.getItem(TOKEN_KEY);
1512
+ }
1513
+ /**
1514
+ * Get current refresh token
1515
+ */
1516
+ getRefreshToken() {
1517
+ return this.storage.getItem(REFRESH_TOKEN_KEY);
1518
+ }
1519
+ /**
1520
+ * Set JWT token and refresh token
1521
+ * @param token - JWT access token
1522
+ * @param refreshToken - JWT refresh token (optional)
1523
+ */
1524
+ setToken(token, refreshToken) {
1525
+ this._token = token;
1526
+ this.storage.setItem(TOKEN_KEY, token);
1527
+ if (refreshToken) {
1528
+ this._refreshToken = refreshToken;
1529
+ this.storage.setItem(REFRESH_TOKEN_KEY, refreshToken);
1530
+ }
1531
+ this._reinitClients();
1532
+ }
1533
+ /**
1534
+ * Clear all tokens
1535
+ */
1536
+ clearTokens() {
1537
+ this._token = null;
1538
+ this._refreshToken = null;
1539
+ this.storage.removeItem(TOKEN_KEY);
1540
+ this.storage.removeItem(REFRESH_TOKEN_KEY);
1541
+ this._reinitClients();
1542
+ }
1543
+ /**
1544
+ * Check if user is authenticated
1545
+ */
1546
+ isAuthenticated() {
1547
+ return !!this.getToken();
1548
+ }
1549
+ /**
1550
+ * Update base URL and reinitialize clients
1551
+ * @param url - New base URL
1552
+ */
1553
+ setBaseUrl(url) {
1554
+ this.baseUrl = url;
1555
+ this._reinitClients();
1556
+ }
1557
+ /**
1558
+ * Get current base URL
1559
+ */
1560
+ getBaseUrl() {
1561
+ return this.baseUrl;
1562
+ }
1563
+ /**
1564
+ * Get OpenAPI schema path
1565
+ * @returns Path to the OpenAPI schema JSON file
1566
+ *
1567
+ * Note: The OpenAPI schema is available in the schema.json file.
1568
+ * You can load it dynamically using:
1569
+ * ```typescript
1570
+ * const schema = await fetch('./schema.json').then(r => r.json());
1571
+ * // or using fs in Node.js:
1572
+ * // const schema = JSON.parse(fs.readFileSync('./schema.json', 'utf-8'));
1573
+ * ```
1574
+ */
1575
+ getSchemaPath() {
1576
+ return "./schema.json";
1577
+ }
1578
+ };
1579
+ var apiSupport = createExtensionAPI(API);
1580
+ function useSupportTicketsList(params, client) {
1581
+ return useSWR(
1582
+ params ? ["cfg-support-tickets", params] : "cfg-support-tickets",
1583
+ () => getSupportTicketsList(params, client)
1584
+ );
1585
+ }
1586
+ function useCreateSupportTicketsCreate() {
1587
+ const { mutate } = useSWRConfig();
1588
+ return async (data, client) => {
1589
+ const result = await createSupportTicketsCreate(data, client);
1590
+ mutate("cfg-support-tickets");
1591
+ return result;
1592
+ };
1593
+ }
1594
+ function useSupportTicketsMessagesList(ticket_uuid, params, client) {
1595
+ return useSWR(
1596
+ ["cfg-support-tickets-messages", ticket_uuid],
1597
+ () => getSupportTicketsMessagesList(ticket_uuid, params, client)
1598
+ );
1599
+ }
1600
+ function useCreateSupportTicketsMessagesCreate() {
1601
+ const { mutate } = useSWRConfig();
1602
+ return async (ticket_uuid, data, client) => {
1603
+ const result = await createSupportTicketsMessagesCreate(ticket_uuid, data, client);
1604
+ mutate("cfg-support-tickets-messages");
1605
+ return result;
1606
+ };
1607
+ }
1608
+ function useSupportTicketsMessagesRetrieve(ticket_uuid, uuid, client) {
1609
+ return useSWR(
1610
+ ["cfg-support-tickets-message", ticket_uuid],
1611
+ () => getSupportTicketsMessagesRetrieve(ticket_uuid, uuid, client)
1612
+ );
1613
+ }
1614
+ function useUpdateSupportTicketsMessagesUpdate() {
1615
+ const { mutate } = useSWRConfig();
1616
+ return async (ticket_uuid, uuid, data, client) => {
1617
+ const result = await updateSupportTicketsMessagesUpdate(ticket_uuid, uuid, data, client);
1618
+ mutate("cfg-support-tickets-messages");
1619
+ mutate("cfg-support-tickets-message");
1620
+ return result;
1621
+ };
1622
+ }
1623
+ function usePartialUpdateSupportTicketsMessagesPartialUpdate() {
1624
+ const { mutate } = useSWRConfig();
1625
+ return async (ticket_uuid, uuid, data, client) => {
1626
+ const result = await partialUpdateSupportTicketsMessagesPartialUpdate(ticket_uuid, uuid, data, client);
1627
+ mutate("cfg-support-tickets-messages-partial");
1628
+ return result;
1629
+ };
1630
+ }
1631
+ function useDeleteSupportTicketsMessagesDestroy() {
1632
+ const { mutate } = useSWRConfig();
1633
+ return async (ticket_uuid, uuid, client) => {
1634
+ const result = await deleteSupportTicketsMessagesDestroy(ticket_uuid, uuid, client);
1635
+ mutate("cfg-support-tickets-messages");
1636
+ mutate("cfg-support-tickets-message");
1637
+ return result;
1638
+ };
1639
+ }
1640
+ function useSupportTicketsRetrieve(uuid, client) {
1641
+ return useSWR(
1642
+ ["cfg-support-ticket", uuid],
1643
+ () => getSupportTicketsRetrieve(uuid, client)
1644
+ );
1645
+ }
1646
+ function useUpdateSupportTicketsUpdate() {
1647
+ const { mutate } = useSWRConfig();
1648
+ return async (uuid, data, client) => {
1649
+ const result = await updateSupportTicketsUpdate(uuid, data, client);
1650
+ mutate("cfg-support-tickets");
1651
+ mutate("cfg-support-ticket");
1652
+ return result;
1653
+ };
1654
+ }
1655
+ function usePartialUpdateSupportTicketsPartialUpdate() {
1656
+ const { mutate } = useSWRConfig();
1657
+ return async (uuid, data, client) => {
1658
+ const result = await partialUpdateSupportTicketsPartialUpdate(uuid, data, client);
1659
+ mutate("cfg-support-tickets-partial");
1660
+ return result;
1661
+ };
1662
+ }
1663
+ function useDeleteSupportTicketsDestroy() {
1664
+ const { mutate } = useSWRConfig();
1665
+ return async (uuid, client) => {
1666
+ const result = await deleteSupportTicketsDestroy(uuid, client);
1667
+ mutate("cfg-support-tickets");
1668
+ mutate("cfg-support-ticket");
1669
+ return result;
1670
+ };
1671
+ }
1672
+ var SupportContext = createContext(void 0);
1673
+ function SupportProvider({ children }) {
1674
+ const {
1675
+ data: ticketsData,
1676
+ error: ticketsError,
1677
+ isLoading: isLoadingTickets,
1678
+ mutate: mutateTickets
1679
+ } = useSupportTicketsList({ page: 1, page_size: 1 });
1680
+ const refreshTickets = async () => {
1681
+ await mutateTickets();
1682
+ };
1683
+ const createTicketMutation = useCreateSupportTicketsCreate();
1684
+ const updateTicketMutation = useUpdateSupportTicketsUpdate();
1685
+ usePartialUpdateSupportTicketsPartialUpdate();
1686
+ const deleteTicketMutation = useDeleteSupportTicketsDestroy();
1687
+ const createMessageMutation = useCreateSupportTicketsMessagesCreate();
1688
+ const updateMessageMutation = useUpdateSupportTicketsMessagesUpdate();
1689
+ usePartialUpdateSupportTicketsMessagesPartialUpdate();
1690
+ const deleteMessageMutation = useDeleteSupportTicketsMessagesDestroy();
1691
+ const getTicket = async (uuid) => {
1692
+ const { data } = useSupportTicketsRetrieve(uuid);
1693
+ return data;
1694
+ };
1695
+ const createTicket = async (data) => {
1696
+ const result = await createTicketMutation(data);
1697
+ await refreshTickets();
1698
+ return result;
1699
+ };
1700
+ const updateTicket = async (uuid, data) => {
1701
+ const result = await updateTicketMutation(uuid, data);
1702
+ await refreshTickets();
1703
+ return result;
1704
+ };
1705
+ const partialUpdateTicket = async (uuid, data) => {
1706
+ const result = await updateTicketMutation(uuid, data);
1707
+ await refreshTickets();
1708
+ return result;
1709
+ };
1710
+ const deleteTicket = async (uuid) => {
1711
+ await deleteTicketMutation(uuid);
1712
+ await refreshTickets();
1713
+ };
1714
+ const getMessages = async (ticketUuid) => {
1715
+ const { data } = useSupportTicketsMessagesList(ticketUuid, { page: 1, page_size: 100 });
1716
+ return data?.results;
1717
+ };
1718
+ const getMessage = async (ticketUuid, messageUuid) => {
1719
+ const { data } = useSupportTicketsMessagesRetrieve(
1720
+ ticketUuid,
1721
+ messageUuid
1722
+ );
1723
+ return data;
1724
+ };
1725
+ const createMessage = async (ticketUuid, data) => {
1726
+ const result = await createMessageMutation(ticketUuid, data);
1727
+ return result;
1728
+ };
1729
+ const updateMessage = async (ticketUuid, messageUuid, data) => {
1730
+ const result = await updateMessageMutation(
1731
+ ticketUuid,
1732
+ messageUuid,
1733
+ data
1734
+ );
1735
+ return result;
1736
+ };
1737
+ const partialUpdateMessage = async (ticketUuid, messageUuid, data) => {
1738
+ const result = await updateMessageMutation(
1739
+ ticketUuid,
1740
+ messageUuid,
1741
+ data
1742
+ );
1743
+ return result;
1744
+ };
1745
+ const deleteMessage = async (ticketUuid, messageUuid) => {
1746
+ await deleteMessageMutation(ticketUuid, messageUuid);
1747
+ };
1748
+ const refreshMessages = async (ticketUuid) => {
1749
+ await refreshTickets();
1750
+ };
1751
+ const value = {
1752
+ tickets: ticketsData?.results,
1753
+ isLoadingTickets,
1754
+ ticketsError,
1755
+ refreshTickets,
1756
+ getTicket,
1757
+ createTicket,
1758
+ updateTicket,
1759
+ partialUpdateTicket,
1760
+ deleteTicket,
1761
+ getMessages,
1762
+ getMessage,
1763
+ createMessage,
1764
+ updateMessage,
1765
+ partialUpdateMessage,
1766
+ deleteMessage,
1767
+ refreshMessages
1768
+ };
1769
+ return /* @__PURE__ */ jsx(SupportContext.Provider, { value, children });
1770
+ }
1771
+ function useSupportContext() {
1772
+ const context = useContext(SupportContext);
1773
+ if (!context) {
1774
+ throw new Error("useSupportContext must be used within SupportProvider");
1775
+ }
1776
+ return context;
1777
+ }
1778
+
1779
+ // src/layouts/SupportLayout/events.ts
1780
+ var SUPPORT_LAYOUT_EVENTS = {
1781
+ // Dialog events
1782
+ OPEN_CREATE_DIALOG: "support-layout:open-create-dialog",
1783
+ CLOSE_CREATE_DIALOG: "support-layout:close-create-dialog",
1784
+ // Ticket events
1785
+ TICKET_SELECTED: "support-layout:ticket-selected",
1786
+ TICKET_CREATED: "support-layout:ticket-created",
1787
+ // Message events
1788
+ MESSAGE_SENT: "support-layout:message-sent"
1789
+ };
1790
+ var openCreateTicketDialog = () => {
1791
+ if (typeof window !== "undefined") {
1792
+ window.dispatchEvent(new CustomEvent(SUPPORT_LAYOUT_EVENTS.OPEN_CREATE_DIALOG));
1793
+ }
1794
+ };
1795
+ var closeCreateTicketDialog = () => {
1796
+ if (typeof window !== "undefined") {
1797
+ window.dispatchEvent(new CustomEvent(SUPPORT_LAYOUT_EVENTS.CLOSE_CREATE_DIALOG));
1798
+ }
1799
+ };
1800
+ var PAGE_SIZE = 20;
1801
+ function useInfiniteTickets() {
1802
+ const getKey = (pageIndex, previousPageData) => {
1803
+ if (previousPageData && !previousPageData.has_next) return null;
1804
+ if (pageIndex === 0) return ["cfg-support-tickets-infinite", 1, PAGE_SIZE];
1805
+ return ["cfg-support-tickets-infinite", pageIndex + 1, PAGE_SIZE];
1806
+ };
1807
+ const fetcher = async ([, page, pageSize]) => {
1808
+ return getSupportTicketsList(
1809
+ { page, page_size: pageSize }
1810
+ );
1811
+ };
1812
+ const {
1813
+ data,
1814
+ error,
1815
+ isLoading,
1816
+ isValidating,
1817
+ size,
1818
+ setSize,
1819
+ mutate
1820
+ } = useSWRInfinite(getKey, fetcher, {
1821
+ revalidateFirstPage: false,
1822
+ parallel: false
1823
+ });
1824
+ const tickets = data ? data.flatMap((page) => page.results) : [];
1825
+ const hasMore = data && data[data.length - 1]?.has_next;
1826
+ const totalCount = data && data[data.length - 1]?.count;
1827
+ const isLoadingMore = isValidating && data && typeof data[size - 1] !== "undefined";
1828
+ const loadMore = () => {
1829
+ if (hasMore && !isLoadingMore) {
1830
+ setSize(size + 1);
1831
+ }
1832
+ };
1833
+ const refresh = async () => {
1834
+ await mutate();
1835
+ };
1836
+ return {
1837
+ tickets,
1838
+ isLoading,
1839
+ isLoadingMore: isLoadingMore || false,
1840
+ error,
1841
+ hasMore: hasMore || false,
1842
+ totalCount: totalCount || 0,
1843
+ loadMore,
1844
+ refresh
1845
+ };
1846
+ }
1847
+ var PAGE_SIZE2 = 20;
1848
+ function useInfiniteMessages(ticketUuid) {
1849
+ const getKey = (pageIndex, previousPageData) => {
1850
+ if (!ticketUuid) return null;
1851
+ if (previousPageData && !previousPageData.has_next) return null;
1852
+ if (pageIndex === 0) return ["cfg-support-messages-infinite", ticketUuid, 1, PAGE_SIZE2];
1853
+ return ["cfg-support-messages-infinite", ticketUuid, pageIndex + 1, PAGE_SIZE2];
1854
+ };
1855
+ const fetcher = async ([, ticket_uuid, page, pageSize]) => {
1856
+ return getSupportTicketsMessagesList(
1857
+ ticket_uuid,
1858
+ { page, page_size: pageSize }
1859
+ );
1860
+ };
1861
+ const {
1862
+ data,
1863
+ error,
1864
+ isLoading,
1865
+ isValidating,
1866
+ size,
1867
+ setSize,
1868
+ mutate
1869
+ } = useSWRInfinite(getKey, fetcher, {
1870
+ revalidateFirstPage: false,
1871
+ parallel: false
1872
+ });
1873
+ const messages = data ? data.flatMap((page) => page.results) : [];
1874
+ const hasMore = data && data[data.length - 1]?.has_next;
1875
+ const totalCount = data && data[data.length - 1]?.count;
1876
+ const isLoadingMore = !!(isValidating && data && typeof data[size - 1] !== "undefined");
1877
+ const loadMore = () => {
1878
+ if (hasMore && !isLoadingMore) {
1879
+ setSize(size + 1);
1880
+ }
1881
+ };
1882
+ const refresh = async () => {
1883
+ await mutate();
1884
+ };
1885
+ const addMessage = (message) => {
1886
+ if (!data || !data[0]) return;
1887
+ const newData = [...data];
1888
+ const firstPage = newData[0];
1889
+ if (firstPage) {
1890
+ newData[0] = {
1891
+ ...firstPage,
1892
+ results: [message, ...firstPage.results],
1893
+ count: firstPage.count + 1,
1894
+ page: firstPage.page || 1,
1895
+ pages: firstPage.pages || 1
1896
+ };
1897
+ }
1898
+ mutate(newData, false);
1899
+ };
1900
+ return {
1901
+ messages,
1902
+ isLoading,
1903
+ isLoadingMore: isLoadingMore || false,
1904
+ error,
1905
+ hasMore: hasMore || false,
1906
+ totalCount: totalCount || 0,
1907
+ loadMore,
1908
+ refresh,
1909
+ addMessage
1910
+ };
1911
+ }
1912
+ var SupportLayoutContext = createContext(void 0);
1913
+ function SupportLayoutProvider({ children }) {
1914
+ const support = useSupportContext();
1915
+ const { user } = useAuth();
1916
+ const [uiState, setUIState] = useState({
1917
+ selectedTicketUuid: null,
1918
+ isCreateDialogOpen: false,
1919
+ viewMode: "list"
1920
+ });
1921
+ const selectedTicket = support.tickets?.find((t) => t.uuid === uiState.selectedTicketUuid);
1922
+ const {
1923
+ messages: selectedTicketMessages,
1924
+ isLoading: isLoadingMessages,
1925
+ isLoadingMore: isLoadingMoreMessages,
1926
+ hasMore: hasMoreMessages,
1927
+ totalCount: totalMessagesCount,
1928
+ loadMore: loadMoreMessages,
1929
+ refresh: refreshMessages,
1930
+ addMessage: addMessageOptimistically
1931
+ } = useInfiniteMessages(selectedTicket?.uuid || null);
1932
+ const selectTicket = useCallback(async (ticket) => {
1933
+ setUIState((prev) => ({ ...prev, selectedTicketUuid: ticket?.uuid || null }));
1934
+ if (ticket?.uuid) {
1935
+ window.dispatchEvent(
1936
+ new CustomEvent(SUPPORT_LAYOUT_EVENTS.TICKET_SELECTED, { detail: { ticket } })
1937
+ );
1938
+ }
1939
+ }, []);
1940
+ const createTicket = useCallback(async (data) => {
1941
+ if (!user?.id) {
1942
+ throw new Error("User must be authenticated to create tickets");
1943
+ }
1944
+ const ticket = await support.createTicket({
1945
+ user: user.id,
1946
+ subject: data.subject
1947
+ });
1948
+ if (ticket.uuid && data.message) {
1949
+ await support.createMessage(ticket.uuid, {
1950
+ text: data.message
1951
+ });
1952
+ }
1953
+ setUIState((prev) => ({ ...prev, isCreateDialogOpen: false }));
1954
+ await support.refreshTickets();
1955
+ window.dispatchEvent(
1956
+ new CustomEvent(SUPPORT_LAYOUT_EVENTS.TICKET_CREATED, { detail: { ticket } })
1957
+ );
1958
+ setUIState((prev) => ({ ...prev, selectedTicketUuid: ticket.uuid }));
1959
+ window.dispatchEvent(
1960
+ new CustomEvent(SUPPORT_LAYOUT_EVENTS.TICKET_SELECTED, { detail: { ticket } })
1961
+ );
1962
+ }, [support, user]);
1963
+ const sendMessage = useCallback(async (message) => {
1964
+ if (!selectedTicket?.uuid) return;
1965
+ const messageData = {
1966
+ text: message
1967
+ };
1968
+ const newMessage = await support.createMessage(selectedTicket.uuid, messageData);
1969
+ if (newMessage) {
1970
+ const fullMessage = {
1971
+ uuid: newMessage.uuid || `temp-${Date.now()}`,
1972
+ ticket: selectedTicket.uuid,
1973
+ sender: {
1974
+ id: user?.id || 0,
1975
+ display_username: user?.display_username || "",
1976
+ email: user?.email || "",
1977
+ avatar: user?.avatar || null,
1978
+ initials: user?.initials || "",
1979
+ is_staff: user?.is_staff || false,
1980
+ is_superuser: user?.is_superuser || false
1981
+ },
1982
+ is_from_author: true,
1983
+ text: message,
1984
+ created_at: (/* @__PURE__ */ new Date()).toISOString()
1985
+ };
1986
+ addMessageOptimistically(fullMessage);
1987
+ }
1988
+ await refreshMessages();
1989
+ window.dispatchEvent(
1990
+ new CustomEvent(SUPPORT_LAYOUT_EVENTS.MESSAGE_SENT, { detail: { message: newMessage } })
1991
+ );
1992
+ }, [selectedTicket, support, user, addMessageOptimistically, refreshMessages]);
1993
+ const openCreateDialog = useCallback(() => {
1994
+ setUIState((prev) => ({ ...prev, isCreateDialogOpen: true }));
1995
+ }, []);
1996
+ const closeCreateDialog = useCallback(() => {
1997
+ setUIState((prev) => ({ ...prev, isCreateDialogOpen: false }));
1998
+ }, []);
1999
+ const getUnreadCount = useCallback(() => {
2000
+ return support.tickets?.reduce((count, ticket) => count + (ticket.unanswered_messages_count || 0), 0) || 0;
2001
+ }, [support.tickets]);
2002
+ useEffect(() => {
2003
+ const handleOpenDialog = () => openCreateDialog();
2004
+ const handleCloseDialog = () => closeCreateDialog();
2005
+ window.addEventListener(SUPPORT_LAYOUT_EVENTS.OPEN_CREATE_DIALOG, handleOpenDialog);
2006
+ window.addEventListener(SUPPORT_LAYOUT_EVENTS.CLOSE_CREATE_DIALOG, handleCloseDialog);
2007
+ return () => {
2008
+ window.removeEventListener(SUPPORT_LAYOUT_EVENTS.OPEN_CREATE_DIALOG, handleOpenDialog);
2009
+ window.removeEventListener(SUPPORT_LAYOUT_EVENTS.CLOSE_CREATE_DIALOG, handleCloseDialog);
2010
+ };
2011
+ }, [openCreateDialog, closeCreateDialog]);
2012
+ const value = {
2013
+ tickets: support.tickets,
2014
+ isLoadingTickets: support.isLoadingTickets,
2015
+ ticketsError: support.ticketsError,
2016
+ selectedTicket,
2017
+ selectedTicketMessages,
2018
+ isLoadingMessages,
2019
+ isLoadingMoreMessages,
2020
+ hasMoreMessages,
2021
+ totalMessagesCount,
2022
+ loadMoreMessages,
2023
+ uiState,
2024
+ selectTicket,
2025
+ createTicket,
2026
+ sendMessage,
2027
+ refreshTickets: support.refreshTickets,
2028
+ refreshMessages,
2029
+ openCreateDialog,
2030
+ closeCreateDialog,
2031
+ getUnreadCount
2032
+ };
2033
+ return /* @__PURE__ */ jsx(SupportLayoutContext.Provider, { value, children });
2034
+ }
2035
+ function useSupportLayoutContext() {
2036
+ const context = useContext(SupportLayoutContext);
2037
+ if (!context) {
2038
+ throw new Error("useSupportLayoutContext must be used within SupportLayoutProvider");
2039
+ }
2040
+ return context;
2041
+ }
2042
+ var getStatusBadgeVariant = (status) => {
2043
+ switch (status) {
2044
+ case "open":
2045
+ return "default";
2046
+ case "waiting_for_user":
2047
+ return "secondary";
2048
+ case "waiting_for_admin":
2049
+ return "outline";
2050
+ case "resolved":
2051
+ return "outline";
2052
+ case "closed":
2053
+ return "secondary";
2054
+ default:
2055
+ return "default";
2056
+ }
2057
+ };
2058
+ var formatRelativeTime = (date) => {
2059
+ if (!date) return "N/A";
2060
+ const now = /* @__PURE__ */ new Date();
2061
+ const messageDate = new Date(date);
2062
+ const diffInSeconds = Math.floor((now.getTime() - messageDate.getTime()) / 1e3);
2063
+ if (diffInSeconds < 60) return "Just now";
2064
+ if (diffInSeconds < 3600) return `${Math.floor(diffInSeconds / 60)}m ago`;
2065
+ if (diffInSeconds < 86400) return `${Math.floor(diffInSeconds / 3600)}h ago`;
2066
+ if (diffInSeconds < 604800) return `${Math.floor(diffInSeconds / 86400)}d ago`;
2067
+ return new Date(date).toLocaleDateString("en-US", {
2068
+ year: "numeric",
2069
+ month: "short",
2070
+ day: "numeric"
2071
+ });
2072
+ };
2073
+ var TicketCard = ({ ticket, isSelected, onClick }) => {
2074
+ return /* @__PURE__ */ jsx(
2075
+ Card,
2076
+ {
2077
+ className: cn(
2078
+ "cursor-pointer transition-all duration-200 ease-out",
2079
+ "hover:bg-accent/50 hover:shadow-md hover:scale-[1.02]",
2080
+ "active:scale-[0.98]",
2081
+ isSelected && "bg-accent border-primary shadow-sm"
2082
+ ),
2083
+ onClick,
2084
+ children: /* @__PURE__ */ jsxs(CardContent, { className: "p-4", children: [
2085
+ /* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between mb-2", children: [
2086
+ /* @__PURE__ */ jsx("h3", { className: "font-semibold text-sm line-clamp-2 flex-1", children: ticket.subject }),
2087
+ (ticket.unanswered_messages_count || 0) > 0 && /* @__PURE__ */ jsx(
2088
+ Badge,
2089
+ {
2090
+ variant: "destructive",
2091
+ className: "ml-2 shrink-0 animate-pulse",
2092
+ children: ticket.unanswered_messages_count
2093
+ }
2094
+ )
2095
+ ] }),
2096
+ /* @__PURE__ */ jsx("div", { className: "flex items-center justify-between text-xs text-muted-foreground", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
2097
+ /* @__PURE__ */ jsx(Badge, { variant: getStatusBadgeVariant(ticket.status || "open"), className: "text-xs", children: ticket.status || "open" }),
2098
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
2099
+ /* @__PURE__ */ jsx(Clock, { className: "h-3 w-3" }),
2100
+ /* @__PURE__ */ jsx("span", { children: formatRelativeTime(ticket.created_at) })
2101
+ ] })
2102
+ ] }) })
2103
+ ] })
2104
+ }
2105
+ );
2106
+ };
2107
+ var TicketList = () => {
2108
+ const { selectedTicket, selectTicket } = useSupportLayoutContext();
2109
+ const {
2110
+ tickets,
2111
+ isLoading,
2112
+ isLoadingMore,
2113
+ hasMore,
2114
+ loadMore,
2115
+ totalCount,
2116
+ refresh
2117
+ } = useInfiniteTickets();
2118
+ const scrollRef = useRef(null);
2119
+ const observerRef = useRef(null);
2120
+ const loadMoreRef = useRef(null);
2121
+ useEffect(() => {
2122
+ const handleTicketCreated = () => {
2123
+ refresh();
2124
+ };
2125
+ window.addEventListener(SUPPORT_LAYOUT_EVENTS.TICKET_CREATED, handleTicketCreated);
2126
+ return () => {
2127
+ window.removeEventListener(SUPPORT_LAYOUT_EVENTS.TICKET_CREATED, handleTicketCreated);
2128
+ };
2129
+ }, [refresh]);
2130
+ useEffect(() => {
2131
+ if (observerRef.current) {
2132
+ observerRef.current.disconnect();
2133
+ }
2134
+ observerRef.current = new IntersectionObserver(
2135
+ (entries) => {
2136
+ if (entries[0]?.isIntersecting && hasMore && !isLoadingMore) {
2137
+ loadMore();
2138
+ }
2139
+ },
2140
+ { threshold: 0.1 }
2141
+ );
2142
+ if (loadMoreRef.current) {
2143
+ observerRef.current.observe(loadMoreRef.current);
2144
+ }
2145
+ return () => {
2146
+ if (observerRef.current) {
2147
+ observerRef.current.disconnect();
2148
+ }
2149
+ };
2150
+ }, [hasMore, isLoadingMore, loadMore]);
2151
+ if (isLoading) {
2152
+ return /* @__PURE__ */ jsx("div", { className: "p-4 space-y-2", children: [1, 2, 3, 4, 5].map((i) => /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
2153
+ Skeleton,
2154
+ {
2155
+ className: "h-24 w-full animate-pulse",
2156
+ style: { animationDelay: `${i * 100}ms` }
2157
+ }
2158
+ ) }, i)) });
2159
+ }
2160
+ if (!tickets || tickets.length === 0) {
2161
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center justify-center h-full p-8 text-center animate-in fade-in zoom-in-95 duration-300", children: [
2162
+ /* @__PURE__ */ jsx(MessageSquare, { className: "h-16 w-16 text-muted-foreground mb-4 animate-bounce" }),
2163
+ /* @__PURE__ */ jsx("h3", { className: "text-lg font-semibold mb-2", children: "No tickets yet" }),
2164
+ /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground max-w-sm", children: "Create your first support ticket to get help from our team" })
2165
+ ] });
2166
+ }
2167
+ return /* @__PURE__ */ jsx(ScrollArea, { className: "h-full", viewportRef: scrollRef, children: /* @__PURE__ */ jsxs("div", { className: "p-4 space-y-2", children: [
2168
+ tickets.map((ticket, index) => /* @__PURE__ */ jsx(
2169
+ "div",
2170
+ {
2171
+ className: "animate-in fade-in slide-in-from-left-2 duration-300",
2172
+ style: { animationDelay: `${Math.min(index, 10) * 50}ms` },
2173
+ children: /* @__PURE__ */ jsx(
2174
+ TicketCard,
2175
+ {
2176
+ ticket,
2177
+ isSelected: selectedTicket?.uuid === ticket.uuid,
2178
+ onClick: () => selectTicket(ticket)
2179
+ }
2180
+ )
2181
+ },
2182
+ ticket.uuid
2183
+ )),
2184
+ /* @__PURE__ */ jsx("div", { ref: loadMoreRef, className: "h-2" }),
2185
+ isLoadingMore && /* @__PURE__ */ jsx("div", { className: "flex justify-center py-4", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 text-muted-foreground", children: [
2186
+ /* @__PURE__ */ jsx(Loader2, { className: "h-4 w-4 animate-spin" }),
2187
+ /* @__PURE__ */ jsx("span", { className: "text-sm", children: "Loading more tickets..." })
2188
+ ] }) }),
2189
+ hasMore && !isLoadingMore && /* @__PURE__ */ jsx("div", { className: "flex justify-center pt-2 pb-4", children: /* @__PURE__ */ jsxs(
2190
+ Button,
2191
+ {
2192
+ variant: "outline",
2193
+ size: "sm",
2194
+ onClick: loadMore,
2195
+ className: "text-xs",
2196
+ children: [
2197
+ "Load more (",
2198
+ totalCount > 0 ? `${tickets.length}/${totalCount}` : "",
2199
+ ")"
2200
+ ]
2201
+ }
2202
+ ) }),
2203
+ !hasMore && tickets.length > 0 && /* @__PURE__ */ jsxs("div", { className: "text-center py-4 text-sm text-muted-foreground", children: [
2204
+ "All ",
2205
+ totalCount,
2206
+ " tickets loaded"
2207
+ ] })
2208
+ ] }) });
2209
+ };
2210
+ var formatTime = (date) => {
2211
+ if (!date) return "";
2212
+ return new Date(date).toLocaleTimeString("en-US", {
2213
+ hour: "2-digit",
2214
+ minute: "2-digit"
2215
+ });
2216
+ };
2217
+ var formatDate = (date) => {
2218
+ if (!date) return "";
2219
+ return new Date(date).toLocaleDateString("en-US", {
2220
+ year: "numeric",
2221
+ month: "short",
2222
+ day: "numeric"
2223
+ });
2224
+ };
2225
+ var MessageBubble = ({ message, isFromUser, currentUser }) => {
2226
+ const sender = message.sender;
2227
+ return /* @__PURE__ */ jsxs(
2228
+ "div",
2229
+ {
2230
+ className: `flex gap-3 ${isFromUser ? "justify-end" : "justify-start"}
2231
+ animate-in fade-in slide-in-from-bottom-2 duration-300`,
2232
+ children: [
2233
+ !isFromUser && /* @__PURE__ */ jsx(Avatar, { className: "h-8 w-8 shrink-0", children: sender?.avatar ? /* @__PURE__ */ jsx(AvatarImage, { src: sender.avatar, alt: sender.display_username || "Support" }) : /* @__PURE__ */ jsx(AvatarFallback, { className: "bg-primary text-primary-foreground", children: sender?.is_staff ? /* @__PURE__ */ jsx(Headphones, { className: "h-4 w-4" }) : sender?.display_username?.charAt(0)?.toUpperCase() || sender?.initials || "S" }) }),
2234
+ /* @__PURE__ */ jsxs("div", { className: `flex flex-col gap-1 flex-1 max-w-[80%] ${isFromUser ? "items-end" : "items-start"}`, children: [
2235
+ !isFromUser && sender && /* @__PURE__ */ jsxs("span", { className: "text-xs text-muted-foreground px-1", children: [
2236
+ sender.display_username || sender.email || "Support Team",
2237
+ sender.is_staff && " (Staff)"
2238
+ ] }),
2239
+ /* @__PURE__ */ jsx(
2240
+ Card,
2241
+ {
2242
+ className: `${isFromUser ? "bg-primary text-primary-foreground" : "bg-muted"} transition-all duration-200 hover:shadow-md`,
2243
+ children: /* @__PURE__ */ jsx(CardContent, { className: "p-3", children: /* @__PURE__ */ jsx("p", { className: "text-sm whitespace-pre-wrap break-words", children: message.text }) })
2244
+ }
2245
+ ),
2246
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground px-1", children: formatTime(message.created_at) })
2247
+ ] }),
2248
+ isFromUser && /* @__PURE__ */ jsx(Avatar, { className: "h-8 w-8 shrink-0", children: currentUser?.avatar ? /* @__PURE__ */ jsx(AvatarImage, { src: currentUser.avatar, alt: currentUser.display_username || currentUser.email || "You" }) : /* @__PURE__ */ jsx(AvatarFallback, { className: "bg-primary/10 text-primary font-semibold", children: currentUser?.display_username?.charAt(0)?.toUpperCase() || currentUser?.email?.charAt(0)?.toUpperCase() || currentUser?.initials || /* @__PURE__ */ jsx(User, { className: "h-4 w-4" }) }) })
2249
+ ]
2250
+ }
2251
+ );
2252
+ };
2253
+ var MessageList = () => {
2254
+ const { selectedTicket } = useSupportLayoutContext();
2255
+ const { user } = useAuth();
2256
+ const {
2257
+ messages,
2258
+ isLoading,
2259
+ isLoadingMore,
2260
+ hasMore,
2261
+ totalCount,
2262
+ loadMore
2263
+ } = useInfiniteMessages(selectedTicket?.uuid || null);
2264
+ const scrollRef = useRef(null);
2265
+ const scrollAreaRef = useRef(null);
2266
+ const observerRef = useRef(null);
2267
+ const loadMoreRef = useRef(null);
2268
+ const firstRender = useRef(true);
2269
+ useEffect(() => {
2270
+ if (observerRef.current) {
2271
+ observerRef.current.disconnect();
2272
+ }
2273
+ observerRef.current = new IntersectionObserver(
2274
+ (entries) => {
2275
+ if (entries[0]?.isIntersecting && hasMore && !isLoadingMore) {
2276
+ loadMore();
2277
+ }
2278
+ },
2279
+ { threshold: 0.1 }
2280
+ );
2281
+ if (loadMoreRef.current) {
2282
+ observerRef.current.observe(loadMoreRef.current);
2283
+ }
2284
+ return () => {
2285
+ if (observerRef.current) {
2286
+ observerRef.current.disconnect();
2287
+ }
2288
+ };
2289
+ }, [hasMore, isLoadingMore, loadMore]);
2290
+ useEffect(() => {
2291
+ if (firstRender.current && messages.length > 0) {
2292
+ const scrollContainer = scrollAreaRef.current?.querySelector("[data-radix-scroll-area-viewport]");
2293
+ if (scrollContainer) {
2294
+ scrollContainer.scrollTop = scrollContainer.scrollHeight;
2295
+ }
2296
+ firstRender.current = false;
2297
+ }
2298
+ }, [messages]);
2299
+ const handleLoadMore = useCallback(() => {
2300
+ const scrollContainer = scrollAreaRef.current?.querySelector("[data-radix-scroll-area-viewport]");
2301
+ const previousHeight = scrollContainer?.scrollHeight || 0;
2302
+ loadMore();
2303
+ setTimeout(() => {
2304
+ if (scrollContainer) {
2305
+ const newHeight = scrollContainer.scrollHeight;
2306
+ scrollContainer.scrollTop = newHeight - previousHeight;
2307
+ }
2308
+ }, 100);
2309
+ }, [loadMore]);
2310
+ if (!selectedTicket) {
2311
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center justify-center h-full p-8 text-center animate-in fade-in zoom-in-95 duration-300", children: [
2312
+ /* @__PURE__ */ jsx(MessageSquare, { className: "h-16 w-16 text-muted-foreground mb-4 animate-bounce" }),
2313
+ /* @__PURE__ */ jsx("h3", { className: "text-lg font-semibold mb-2", children: "No ticket selected" }),
2314
+ /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground max-w-sm", children: "Select a ticket from the list to view the conversation" })
2315
+ ] });
2316
+ }
2317
+ if (isLoading) {
2318
+ return /* @__PURE__ */ jsx("div", { className: "p-6 space-y-4", children: [1, 2, 3].map((i) => /* @__PURE__ */ jsxs(
2319
+ "div",
2320
+ {
2321
+ className: "flex gap-3 animate-pulse",
2322
+ style: { animationDelay: `${i * 100}ms` },
2323
+ children: [
2324
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-8 w-8 rounded-full" }),
2325
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-16 flex-1 max-w-[70%]" })
2326
+ ]
2327
+ },
2328
+ i
2329
+ )) });
2330
+ }
2331
+ if (!messages || messages.length === 0) {
2332
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center justify-center h-full p-8 text-center animate-in fade-in zoom-in-95 duration-300", children: [
2333
+ /* @__PURE__ */ jsx(MessageSquare, { className: "h-16 w-16 text-muted-foreground mb-4 animate-bounce" }),
2334
+ /* @__PURE__ */ jsx("h3", { className: "text-lg font-semibold mb-2", children: "No messages yet" }),
2335
+ /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground max-w-sm", children: "Start the conversation by sending a message below" })
2336
+ ] });
2337
+ }
2338
+ return /* @__PURE__ */ jsx(ScrollArea, { className: "h-full bg-muted/50", viewportRef: scrollAreaRef, children: /* @__PURE__ */ jsxs("div", { className: "p-6 space-y-4", ref: scrollRef, children: [
2339
+ /* @__PURE__ */ jsx("div", { ref: loadMoreRef, className: "h-2" }),
2340
+ isLoadingMore && /* @__PURE__ */ jsx("div", { className: "flex justify-center py-4", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 text-muted-foreground", children: [
2341
+ /* @__PURE__ */ jsx(Loader2, { className: "h-4 w-4 animate-spin" }),
2342
+ /* @__PURE__ */ jsx("span", { className: "text-sm", children: "Loading older messages..." })
2343
+ ] }) }),
2344
+ hasMore && !isLoadingMore && /* @__PURE__ */ jsx("div", { className: "flex justify-center pt-2 pb-4", children: /* @__PURE__ */ jsxs(
2345
+ Button,
2346
+ {
2347
+ variant: "outline",
2348
+ size: "sm",
2349
+ onClick: handleLoadMore,
2350
+ className: "text-xs",
2351
+ children: [
2352
+ "Load older messages (",
2353
+ totalCount > 0 ? `${messages.length}/${totalCount}` : "",
2354
+ ")"
2355
+ ]
2356
+ }
2357
+ ) }),
2358
+ messages.length > 0 && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 my-4", children: [
2359
+ /* @__PURE__ */ jsx("div", { className: "flex-1 h-px bg-border" }),
2360
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: formatDate(messages[0]?.created_at) }),
2361
+ /* @__PURE__ */ jsx("div", { className: "flex-1 h-px bg-border" })
2362
+ ] }),
2363
+ messages.map((message, index) => {
2364
+ const isFromUser = message.sender?.id && user?.id && String(message.sender.id) === String(user.id) || message.sender?.email && user?.email && message.sender.email === user.email || message.is_from_author && selectedTicket?.user && user?.id && String(selectedTicket.user) === String(user.id);
2365
+ const previousMessage = index > 0 ? messages[index - 1] : null;
2366
+ const showDateSeparator = previousMessage && new Date(previousMessage.created_at || "").toDateString() !== new Date(message.created_at || "").toDateString();
2367
+ return /* @__PURE__ */ jsxs(React7.Fragment, { children: [
2368
+ showDateSeparator && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 my-4", children: [
2369
+ /* @__PURE__ */ jsx("div", { className: "flex-1 h-px bg-border" }),
2370
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: formatDate(message.created_at) }),
2371
+ /* @__PURE__ */ jsx("div", { className: "flex-1 h-px bg-border" })
2372
+ ] }),
2373
+ /* @__PURE__ */ jsx("div", { style: { animationDelay: `${Math.min(index, 10) * 50}ms` }, children: /* @__PURE__ */ jsx(
2374
+ MessageBubble,
2375
+ {
2376
+ message,
2377
+ isFromUser: !!isFromUser,
2378
+ currentUser: user
2379
+ }
2380
+ ) })
2381
+ ] }, message.uuid);
2382
+ })
2383
+ ] }) });
2384
+ };
2385
+ var isDevelopment = process.env.NODE_ENV === "development";
2386
+ var showLogs = isDevelopment;
2387
+ var logger = createConsola({
2388
+ level: showLogs ? 4 : 1
2389
+ }).withTag("ext-support");
2390
+ var supportLogger = logger;
2391
+ var MessageInput = () => {
2392
+ const { selectedTicket, sendMessage } = useSupportLayoutContext();
2393
+ const { toast } = useToast();
2394
+ const [message, setMessage] = useState("");
2395
+ const [isSending, setIsSending] = useState(false);
2396
+ const handleSubmit = async (e) => {
2397
+ e.preventDefault();
2398
+ if (!message.trim() || !selectedTicket) return;
2399
+ setIsSending(true);
2400
+ try {
2401
+ await sendMessage(message.trim());
2402
+ setMessage("");
2403
+ toast({
2404
+ title: "Success",
2405
+ description: "Message sent successfully"
2406
+ });
2407
+ } catch (error) {
2408
+ supportLogger.error("Failed to send message:", error);
2409
+ toast({
2410
+ title: "Error",
2411
+ description: "Failed to send message",
2412
+ variant: "destructive"
2413
+ });
2414
+ } finally {
2415
+ setIsSending(false);
2416
+ }
2417
+ };
2418
+ const handleKeyDown = (e) => {
2419
+ if (e.key === "Enter" && !e.shiftKey) {
2420
+ e.preventDefault();
2421
+ handleSubmit(e);
2422
+ }
2423
+ };
2424
+ if (!selectedTicket) {
2425
+ return null;
2426
+ }
2427
+ const canSendMessage = selectedTicket.status !== "closed";
2428
+ return /* @__PURE__ */ jsxs("form", { onSubmit: handleSubmit, className: "p-4 border-t bg-background/50 backdrop-blur-sm flex-shrink-0", children: [
2429
+ /* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
2430
+ /* @__PURE__ */ jsx(
2431
+ Textarea,
2432
+ {
2433
+ value: message,
2434
+ onChange: (e) => setMessage(e.target.value),
2435
+ onKeyDown: handleKeyDown,
2436
+ placeholder: canSendMessage ? "Type your message... (Shift+Enter for new line)" : "This ticket is closed",
2437
+ className: "min-h-[60px] max-h-[200px] transition-all duration-200 \n focus:ring-2 focus:ring-primary/20",
2438
+ disabled: !canSendMessage || isSending
2439
+ }
2440
+ ),
2441
+ /* @__PURE__ */ jsx(
2442
+ Button,
2443
+ {
2444
+ type: "submit",
2445
+ size: "icon",
2446
+ disabled: !message.trim() || !canSendMessage || isSending,
2447
+ className: "shrink-0 transition-all duration-200 \n hover:scale-110 active:scale-95 disabled:scale-100",
2448
+ children: /* @__PURE__ */ jsx(Send, { className: "h-4 w-4" })
2449
+ }
2450
+ )
2451
+ ] }),
2452
+ !canSendMessage && /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground mt-2 animate-in fade-in slide-in-from-top-1 duration-200", children: "This ticket is closed. You cannot send new messages." })
2453
+ ] });
2454
+ };
2455
+ var createTicketSchema = z.object({
2456
+ subject: z.string().min(1, "Subject is required").max(200, "Subject too long"),
2457
+ message: z.string().min(1, "Message is required").max(5e3, "Message too long")
2458
+ });
2459
+ var CreateTicketDialog = () => {
2460
+ const { uiState, createTicket, closeCreateDialog } = useSupportLayoutContext();
2461
+ const { toast } = useToast();
2462
+ const [isSubmitting, setIsSubmitting] = React7.useState(false);
2463
+ const form = useForm({
2464
+ resolver: zodResolver(createTicketSchema),
2465
+ defaultValues: {
2466
+ subject: "",
2467
+ message: ""
2468
+ }
2469
+ });
2470
+ const onSubmit = async (data) => {
2471
+ setIsSubmitting(true);
2472
+ try {
2473
+ await createTicket(data);
2474
+ form.reset();
2475
+ toast({
2476
+ title: "Success",
2477
+ description: "Support ticket created successfully"
2478
+ });
2479
+ } catch (error) {
2480
+ supportLogger.error("Failed to create ticket:", error);
2481
+ toast({
2482
+ title: "Error",
2483
+ description: "Failed to create ticket. Please try again.",
2484
+ variant: "destructive"
2485
+ });
2486
+ } finally {
2487
+ setIsSubmitting(false);
2488
+ }
2489
+ };
2490
+ const handleClose = () => {
2491
+ form.reset();
2492
+ closeCreateDialog();
2493
+ };
2494
+ return /* @__PURE__ */ jsx(Dialog, { open: uiState.isCreateDialogOpen, onOpenChange: (open) => !open && handleClose(), children: /* @__PURE__ */ jsxs(DialogContent, { className: "sm:max-w-[600px] animate-in fade-in slide-in-from-bottom-4 duration-300", children: [
2495
+ /* @__PURE__ */ jsxs(DialogHeader, { children: [
2496
+ /* @__PURE__ */ jsxs(DialogTitle, { className: "flex items-center gap-2", children: [
2497
+ /* @__PURE__ */ jsx(Plus, { className: "h-5 w-5" }),
2498
+ "Create Support Ticket"
2499
+ ] }),
2500
+ /* @__PURE__ */ jsx(DialogDescription, { children: "Describe your issue and we'll help you resolve it as quickly as possible." })
2501
+ ] }),
2502
+ /* @__PURE__ */ jsx(Form, { ...form, children: /* @__PURE__ */ jsxs("form", { onSubmit: form.handleSubmit(onSubmit), className: "space-y-6", children: [
2503
+ /* @__PURE__ */ jsx(
2504
+ FormField,
2505
+ {
2506
+ control: form.control,
2507
+ name: "subject",
2508
+ render: ({ field }) => /* @__PURE__ */ jsxs(FormItem, { children: [
2509
+ /* @__PURE__ */ jsx(FormLabel, { children: "Subject" }),
2510
+ /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(Input, { placeholder: "Brief description of your issue...", ...field }) }),
2511
+ /* @__PURE__ */ jsx(FormMessage, {})
2512
+ ] })
2513
+ }
2514
+ ),
2515
+ /* @__PURE__ */ jsx(
2516
+ FormField,
2517
+ {
2518
+ control: form.control,
2519
+ name: "message",
2520
+ render: ({ field }) => /* @__PURE__ */ jsxs(FormItem, { children: [
2521
+ /* @__PURE__ */ jsx(FormLabel, { children: "Message" }),
2522
+ /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(
2523
+ Textarea,
2524
+ {
2525
+ placeholder: "Describe your issue in detail. Include any error messages, steps to reproduce, or relevant information...",
2526
+ className: "min-h-[120px]",
2527
+ ...field
2528
+ }
2529
+ ) }),
2530
+ /* @__PURE__ */ jsx(FormMessage, {})
2531
+ ] })
2532
+ }
2533
+ ),
2534
+ /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-3 pt-4", children: [
2535
+ /* @__PURE__ */ jsx(
2536
+ Button,
2537
+ {
2538
+ type: "button",
2539
+ variant: "outline",
2540
+ onClick: handleClose,
2541
+ disabled: isSubmitting,
2542
+ children: "Cancel"
2543
+ }
2544
+ ),
2545
+ /* @__PURE__ */ jsx(Button, { type: "submit", disabled: isSubmitting, children: isSubmitting ? /* @__PURE__ */ jsxs(Fragment, { children: [
2546
+ /* @__PURE__ */ jsx(Loader2, { className: "h-4 w-4 mr-2 animate-spin" }),
2547
+ "Creating..."
2548
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
2549
+ /* @__PURE__ */ jsx(Plus, { className: "h-4 w-4 mr-2" }),
2550
+ "Create Ticket"
2551
+ ] }) })
2552
+ ] })
2553
+ ] }) })
2554
+ ] }) });
2555
+ };
2556
+ var SupportLayoutContent = () => {
2557
+ const { selectedTicket, selectTicket, openCreateDialog, getUnreadCount } = useSupportLayoutContext();
2558
+ const [isMobile, setIsMobile] = React7.useState(false);
2559
+ React7.useEffect(() => {
2560
+ const checkMobile = () => setIsMobile(window.innerWidth <= 768);
2561
+ checkMobile();
2562
+ window.addEventListener("resize", checkMobile);
2563
+ return () => window.removeEventListener("resize", checkMobile);
2564
+ }, []);
2565
+ const unreadCount = getUnreadCount();
2566
+ if (isMobile) {
2567
+ return /* @__PURE__ */ jsxs("div", { className: "h-screen flex flex-col overflow-hidden", children: [
2568
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between p-4 border-b bg-background flex-shrink-0", children: [
2569
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
2570
+ selectedTicket ? /* @__PURE__ */ jsx(
2571
+ Button,
2572
+ {
2573
+ variant: "ghost",
2574
+ size: "sm",
2575
+ onClick: () => selectTicket(null),
2576
+ className: "p-1",
2577
+ children: /* @__PURE__ */ jsx(ArrowLeft, { className: "h-5 w-5" })
2578
+ }
2579
+ ) : /* @__PURE__ */ jsx(LifeBuoy, { className: "h-6 w-6 text-primary" }),
2580
+ /* @__PURE__ */ jsx("h1", { className: "text-xl font-semibold", children: selectedTicket ? selectedTicket.subject : "Support" }),
2581
+ unreadCount > 0 && !selectedTicket && /* @__PURE__ */ jsx("div", { className: "h-5 w-5 bg-red-500 text-white text-xs rounded-full flex items-center justify-center", children: unreadCount })
2582
+ ] }),
2583
+ !selectedTicket && /* @__PURE__ */ jsxs(Button, { onClick: openCreateDialog, size: "sm", children: [
2584
+ /* @__PURE__ */ jsx(Plus, { className: "h-4 w-4 mr-2" }),
2585
+ "New Ticket"
2586
+ ] })
2587
+ ] }),
2588
+ /* @__PURE__ */ jsx("div", { className: "flex-1 min-h-0 overflow-hidden", children: selectedTicket ? (
2589
+ // Show messages when ticket is selected
2590
+ /* @__PURE__ */ jsxs("div", { className: "h-full flex flex-col", children: [
2591
+ /* @__PURE__ */ jsx("div", { className: "flex-1 min-h-0 overflow-hidden", children: /* @__PURE__ */ jsx(MessageList, {}) }),
2592
+ /* @__PURE__ */ jsx("div", { className: "flex-shrink-0", children: /* @__PURE__ */ jsx(MessageInput, {}) })
2593
+ ] })
2594
+ ) : (
2595
+ // Show ticket list when no ticket is selected
2596
+ /* @__PURE__ */ jsx(TicketList, {})
2597
+ ) }),
2598
+ /* @__PURE__ */ jsx(CreateTicketDialog, {})
2599
+ ] });
2600
+ }
2601
+ return /* @__PURE__ */ jsxs("div", { className: "h-screen flex flex-col overflow-hidden", children: [
2602
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between p-6 border-b bg-background flex-shrink-0", children: [
2603
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
2604
+ /* @__PURE__ */ jsx(LifeBuoy, { className: "h-7 w-7 text-primary" }),
2605
+ /* @__PURE__ */ jsxs("div", { children: [
2606
+ /* @__PURE__ */ jsx("h1", { className: "text-2xl font-bold", children: "Support Center" }),
2607
+ /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "Get help from our support team" })
2608
+ ] }),
2609
+ unreadCount > 0 && /* @__PURE__ */ jsx("div", { className: "h-6 w-6 bg-red-500 text-white text-sm rounded-full flex items-center justify-center", children: unreadCount })
2610
+ ] }),
2611
+ /* @__PURE__ */ jsxs(Button, { onClick: openCreateDialog, children: [
2612
+ /* @__PURE__ */ jsx(Plus, { className: "h-4 w-4 mr-2" }),
2613
+ "New Ticket"
2614
+ ] })
2615
+ ] }),
2616
+ /* @__PURE__ */ jsx("div", { className: "flex-1 min-h-0 overflow-hidden", children: /* @__PURE__ */ jsxs(ResizablePanelGroup, { direction: "horizontal", className: "h-full", children: [
2617
+ /* @__PURE__ */ jsx(ResizablePanel, { defaultSize: 35, minSize: 25, maxSize: 50, children: /* @__PURE__ */ jsx("div", { className: "h-full border-r overflow-hidden", children: /* @__PURE__ */ jsx(TicketList, {}) }) }),
2618
+ /* @__PURE__ */ jsx(ResizableHandle, { withHandle: true, className: "hover:bg-accent transition-colors" }),
2619
+ /* @__PURE__ */ jsx(ResizablePanel, { defaultSize: 65, minSize: 50, children: /* @__PURE__ */ jsxs("div", { className: "h-full flex flex-col overflow-hidden", children: [
2620
+ /* @__PURE__ */ jsx("div", { className: "flex-1 min-h-0 overflow-hidden", children: /* @__PURE__ */ jsx(MessageList, {}) }),
2621
+ /* @__PURE__ */ jsx("div", { className: "flex-shrink-0", children: /* @__PURE__ */ jsx(MessageInput, {}) })
2622
+ ] }) })
2623
+ ] }) }),
2624
+ /* @__PURE__ */ jsx(CreateTicketDialog, {})
2625
+ ] });
2626
+ };
2627
+ var SupportLayout = () => {
2628
+ return /* @__PURE__ */ jsx("div", { className: "h-screen w-full overflow-hidden", children: /* @__PURE__ */ jsx(SupportProvider, { children: /* @__PURE__ */ jsx(SupportLayoutProvider, { children: /* @__PURE__ */ jsx(SupportLayoutContent, {}) }) }) });
2629
+ };
2630
+
2631
+ // package.json
2632
+ var package_default = {
2633
+ name: "@djangocfg/ext-support",
2634
+ version: "1.0.3",
2635
+ description: "Support ticket system extension for DjangoCFG",
2636
+ keywords: [
2637
+ "django",
2638
+ "djangocfg",
2639
+ "extension",
2640
+ "support",
2641
+ "tickets",
2642
+ "helpdesk",
2643
+ "customer-service",
2644
+ "typescript",
2645
+ "react"
2646
+ ],
2647
+ author: {
2648
+ name: "DjangoCFG",
2649
+ url: "https://djangocfg.com"
2650
+ },
2651
+ homepage: "https://hub.djangocfg.com/extensions/djangocfg-ext-support",
2652
+ repository: {
2653
+ type: "git",
2654
+ url: "https://github.com/markolofsen/django-cfg.git",
2655
+ directory: "extensions/support"
2656
+ },
2657
+ bugs: {
2658
+ url: "https://github.com/markolofsen/django-cfg/issues"
2659
+ },
2660
+ license: "MIT",
2661
+ type: "module",
2662
+ main: "./dist/index.cjs",
2663
+ module: "./dist/index.js",
2664
+ types: "./dist/index.d.ts",
2665
+ exports: {
2666
+ ".": {
2667
+ types: "./dist/index.d.ts",
2668
+ import: "./dist/index.js",
2669
+ require: "./dist/index.cjs"
2670
+ },
2671
+ "./hooks": {
2672
+ types: "./dist/hooks.d.ts",
2673
+ import: "./dist/hooks.js",
2674
+ require: "./dist/hooks.cjs"
2675
+ },
2676
+ "./config": {
2677
+ types: "./dist/config.d.ts",
2678
+ import: "./dist/config.js",
2679
+ require: "./dist/config.cjs"
2680
+ }
2681
+ },
2682
+ files: [
2683
+ "dist",
2684
+ "src",
2685
+ "preview.png"
2686
+ ],
2687
+ scripts: {
2688
+ build: "tsup",
2689
+ dev: "tsup --watch",
2690
+ check: "tsc --noEmit"
2691
+ },
2692
+ peerDependencies: {
2693
+ "@djangocfg/api": "workspace:*",
2694
+ "@djangocfg/ext-base": "workspace:*",
2695
+ "@djangocfg/ui-nextjs": "workspace:*",
2696
+ consola: "^3.4.2",
2697
+ "lucide-react": "^0.545.0",
2698
+ next: "^15.5.7",
2699
+ "p-retry": "^7.0.0",
2700
+ react: "^18 || ^19",
2701
+ "react-hook-form": "7.65.0",
2702
+ swr: "^2.3.7",
2703
+ zod: "^4.1.13"
2704
+ },
2705
+ devDependencies: {
2706
+ "@djangocfg/api": "workspace:*",
2707
+ "@djangocfg/ext-base": "workspace:*",
2708
+ "@djangocfg/typescript-config": "workspace:*",
2709
+ "@types/node": "^24.7.2",
2710
+ "@types/react": "^19.0.0",
2711
+ consola: "^3.4.2",
2712
+ "p-retry": "^7.0.0",
2713
+ swr: "^2.3.7",
2714
+ tsup: "^8.5.0",
2715
+ typescript: "^5.9.3"
2716
+ }
2717
+ };
2718
+
2719
+ // src/config.ts
2720
+ var extensionConfig = createExtensionConfig(package_default, {
2721
+ name: "support",
2722
+ displayName: "Support & Tickets",
2723
+ category: "support",
2724
+ features: [
2725
+ "Ticket management system",
2726
+ "Live chat support",
2727
+ "Knowledge base integration",
2728
+ "Multi-channel support",
2729
+ "Agent assignment",
2730
+ "SLA tracking"
2731
+ ],
2732
+ minVersion: "2.0.0",
2733
+ examples: [
2734
+ {
2735
+ title: "Support Ticket Widget",
2736
+ description: "Add a support ticket system",
2737
+ code: `import { TicketWidget, useTickets } from '@djangocfg/ext-support';
2738
+
2739
+ export default function SupportPage() {
2740
+ const { tickets, createTicket } = useTickets();
2741
+
2742
+ return (
2743
+ <TicketWidget
2744
+ onTicketCreate={(ticket) => {
2745
+ console.log('Ticket created:', ticket.id);
2746
+ }}
2747
+ />
2748
+ );
2749
+ }`,
2750
+ language: "tsx"
2751
+ }
2752
+ ]
2753
+ });
2754
+
2755
+ export { API, APIClient, APIError, APILogger, CookieStorageAdapter, CreateTicketDialog, DEFAULT_RETRY_CONFIG, enums_exports as Enums, models_exports as ExtSupportSupportTypes, FetchAdapter, fetchers_exports as Fetchers, LocalStorageAdapter, MemoryStorageAdapter, MessageCreateRequestSchema, MessageCreateSchema, MessageInput, MessageList, MessageRequestSchema, MessageSchema, NetworkError, PaginatedMessageListSchema, PaginatedTicketListSchema, PatchedMessageRequestSchema, PatchedTicketRequestSchema, REFRESH_TOKEN_KEY, SUPPORT_LAYOUT_EVENTS, schemas_exports as Schemas, SenderSchema, SupportLayout, SupportLayoutProvider, SupportProvider, TOKEN_KEY, TicketCard, TicketList, TicketRequestSchema, TicketSchema, apiSupport, clearAPITokens, closeCreateTicketDialog, configureAPI, createSupportTicketsCreate, createSupportTicketsMessagesCreate, deleteSupportTicketsDestroy, deleteSupportTicketsMessagesDestroy, dispatchValidationError, extensionConfig, formatZodError, getAPIInstance, getSupportTicketsList, getSupportTicketsMessagesList, getSupportTicketsMessagesRetrieve, getSupportTicketsRetrieve, isAPIConfigured, onValidationError, openCreateTicketDialog, partialUpdateSupportTicketsMessagesPartialUpdate, partialUpdateSupportTicketsPartialUpdate, reconfigureAPI, resetAPI, shouldRetry, updateSupportTicketsMessagesUpdate, updateSupportTicketsUpdate, useCreateSupportTicketsCreate, useCreateSupportTicketsMessagesCreate, useDeleteSupportTicketsDestroy, useDeleteSupportTicketsMessagesDestroy, useInfiniteMessages, useInfiniteTickets, usePartialUpdateSupportTicketsMessagesPartialUpdate, usePartialUpdateSupportTicketsPartialUpdate, useSupportContext, useSupportLayoutContext, useSupportTicketsList, useSupportTicketsMessagesList, useSupportTicketsMessagesRetrieve, useSupportTicketsRetrieve, useUpdateSupportTicketsMessagesUpdate, useUpdateSupportTicketsUpdate, withRetry };