@gentiq/ui 0.0.0-stage → 1.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2032 @@
1
+ "use client";
2
+ import { jsx as e, jsxs as s, Fragment as fe } from "react/jsx-runtime";
3
+ import * as V from "react";
4
+ import { useRef as Ee, useState as N, useEffect as F, createElement as _t, useContext as Xe, useMemo as O, useLayoutEffect as Tt, forwardRef as It, useCallback as Le, memo as qt, useId as Oe, createContext as Lt, useSyncExternalStore as Pt, Suspense as Mt } from "react";
5
+ import { useMessage as Et, useOptionsStore as zt, useServerConfig as Rt, createOptionsStore as Ye, Message as Ze, useGentiqTranslation as _, References as ze, useTheme as ie, useGentiqLanguage as ee, useGentiqOptions as K, useThreadSelection as Je, ThreadSelectionProvider as et, useThread as At, Thread as tt, GentiqRuntimeProvider as Ft, useLoginCodeExchange as Dt, useAuthSession as Ot, useGentiqApi as Re, useGentiqQueryClient as at, getLocalizedErrorMessage as se, useGentiqKeys as $t, useGentiqEntitlement as Ut, ThreadList as j, ThreadRename as ye, useThreadListItem as Ae, useGentiqStatus as jt } from "@gentiq/react";
6
+ import { Slot as Bt } from "@radix-ui/react-slot";
7
+ import { cva as Gt } from "class-variance-authority";
8
+ import { QuoteIcon as Ht, Loader2Icon as Vt, OctagonXIcon as Kt, TriangleAlertIcon as Qt, InfoIcon as Wt, CircleCheckIcon as Xt, PanelLeftIcon as Yt, User as Zt, Palette as Jt, ShieldCheck as ea, Settings as Pe, AtSign as ta, Mail as aa, Smartphone as na, Lock as ra, Save as sa, Coins as ia, Infinity as oa, Zap as la, LogOut as ca, SquarePen as nt, Check as da, X as ua, MoreVertical as ma, PinOff as ha, Pin as rt, Share2 as ga, Link2Off as pa, Pencil as fa, Trash as ba, Search as va } from "lucide-react";
9
+ import { E as st, u as oe, R as xa, U as $e, r as it, m as ya, a as Na, S as wa, b as Sa, P as ka, c as y, d as te, C as Ca, e as _a, L, I as D, B as $, f as we, g as Se, h as ke, i as Ce, j as _e, k as Ta, l as ot, T as lt, n as Ia, o as qa, p as La, q as Pa, s as Ma, t as ct, v as dt, w as ut, x as mt, y as Ue, z as Ea, A as ht, D as za, F as Ra, G as gt, H as Aa, J as pt, K as Fa, M as Da, N as Oa, O as $a, Q as Ua, V as ja, W as Ba, X as Ga, Y as Ha, Z as he } from "./shared-BNCHeyvj.js";
10
+ import { _ as kr, $ as Cr, a0 as _r, a1 as Tr, a2 as Ir, a3 as qr, a4 as Lr, a5 as Pr, a6 as Mr, a7 as Er, a8 as zr, a9 as Rr, aa as Ar, ab as Fr, ac as Dr, ad as Or, ae as $r, af as Ur, ag as jr, ah as Br, ai as Gr, aj as Hr } from "./shared-BNCHeyvj.js";
11
+ import { Toaster as Va, toast as P } from "sonner";
12
+ import { getToolName as ft, isToolUIPart as bt } from "ai";
13
+ import { createPortal as Ka } from "react-dom";
14
+ import { textOrKey as Qa, evaluateCondition as Te, getAvailableLanguages as Wa, getLanguageNativeName as Xa, isGentiqError as Ya, withAttachmentUrls as Za, toGentiqMessages as Ja } from "@gentiq/core";
15
+ function en() {
16
+ const t = Ee(null), [a, n] = N(0);
17
+ return F(() => {
18
+ const r = t.current;
19
+ if (!r) return;
20
+ const o = () => {
21
+ const m = r.offsetHeight;
22
+ n((u) => Math.abs(u - m) < 1 ? u : m);
23
+ };
24
+ o();
25
+ const i = typeof ResizeObserver > "u" ? null : new ResizeObserver(o);
26
+ return i?.observe(r), () => i?.disconnect();
27
+ }, []), [t, a];
28
+ }
29
+ const je = (t) => {
30
+ if (!t || typeof t != "object") return null;
31
+ const a = Object.values(t).filter((n) => ["string", "number", "boolean"].includes(typeof n)).slice(0, 3).map(String);
32
+ return a.length > 0 ? a.join(" · ") : null;
33
+ };
34
+ function tn(t) {
35
+ return typeof t.output == "string" ? t.output : je(t.output) ?? je(t.input) ?? ft(t);
36
+ }
37
+ function an({
38
+ part: t,
39
+ index: a,
40
+ component: n
41
+ }) {
42
+ const r = /* @__PURE__ */ e(n, { part: t, index: a });
43
+ return (
44
+ // resetKeys: a streamed part can be malformed for a token and valid on the next. Without it
45
+ // the boundary would latch for good, since the part's key never changes.
46
+ /* @__PURE__ */ e(st, { resetKeys: [t], children: bt(t) || t.type === "file" ? /* @__PURE__ */ e(nn, { part: t, index: a, children: r }) : r })
47
+ );
48
+ }
49
+ function nn({
50
+ part: t,
51
+ index: a,
52
+ children: n
53
+ }) {
54
+ const r = Et((u) => u.message), { referenceAdapters: o } = oe(), i = { messageId: r.id, partIndex: a, role: r.role, data: t };
55
+ let m;
56
+ if (bt(t)) {
57
+ const u = ft(t), g = {
58
+ ...i,
59
+ kind: "tool",
60
+ sourceId: `${r.id}-${a}-tool`,
61
+ label: u,
62
+ excerpt: tn(t)
63
+ }, c = o?.[u]?.({ part: t, message: r, toolName: u }) || {};
64
+ m = {
65
+ ...g,
66
+ ...c,
67
+ sourceId: c.sourceId || g.sourceId,
68
+ messageId: c.messageId || g.messageId,
69
+ partIndex: c.partIndex ?? g.partIndex,
70
+ role: c.role || g.role,
71
+ kind: c.kind || g.kind
72
+ };
73
+ } else if (t.type === "file")
74
+ m = {
75
+ ...i,
76
+ kind: "file",
77
+ sourceId: `${r.id}-${a}-file`,
78
+ label: t.filename || t.mediaType,
79
+ excerpt: t.filename || t.mediaType
80
+ };
81
+ else
82
+ return n;
83
+ return /* @__PURE__ */ e(xa, { reference: m, children: n });
84
+ }
85
+ const Be = /* @__PURE__ */ new WeakMap();
86
+ function rn(t) {
87
+ let a = Be.get(t);
88
+ if (!a) {
89
+ const n = t;
90
+ a = ({ part: o, index: i }) => _t(an, { part: o, index: i, component: n }), Be.set(t, a);
91
+ }
92
+ return a;
93
+ }
94
+ function vt(t) {
95
+ const a = {};
96
+ for (const [n, r] of Object.entries(t))
97
+ a[n] = r && rn(r);
98
+ return a;
99
+ }
100
+ const sn = Ye(it({}, null));
101
+ function Fe({
102
+ components: t,
103
+ children: a,
104
+ history: n,
105
+ welcome: r,
106
+ threadActions: o,
107
+ composer: i,
108
+ disclaimer: m,
109
+ settings: u
110
+ }) {
111
+ const g = Xe($e) ?? sn, c = zt(g, (T) => T.configured), h = oe(), p = Rt(), f = O(
112
+ () => it(
113
+ ya(c, {
114
+ history: n,
115
+ welcome: r,
116
+ threadActions: o,
117
+ composer: i,
118
+ disclaimer: m,
119
+ settings: u
120
+ }),
121
+ p
122
+ ),
123
+ [c, p, n, r, o, i, m, u]
124
+ ), [v] = N(() => Ye(f));
125
+ Tt(() => v.setState(f), [v, f]);
126
+ const b = O(() => Na(h, t), [h, t]), k = O(() => vt(b.parts), [b.parts]);
127
+ return /* @__PURE__ */ e(wa.Provider, { value: b, children: /* @__PURE__ */ e($e.Provider, { value: v, children: /* @__PURE__ */ e(Ze.PartsProvider, { components: k, children: a }) }) });
128
+ }
129
+ const on = {
130
+ top: "max(0.5rem, calc(var(--gentiq-selection-top) - 2.625rem))",
131
+ left: "calc(var(--gentiq-selection-left) + var(--gentiq-selection-width) / 2)"
132
+ };
133
+ function ln() {
134
+ const { t } = _(["chat"]), a = Sa();
135
+ return a ? Ka(
136
+ /* @__PURE__ */ e(
137
+ ze.SelectionQuote,
138
+ {
139
+ style: on,
140
+ className: "fixed z-50 flex size-9 -translate-x-1/2 items-center justify-center rounded-lg bg-background text-foreground shadow-lg ring-1 ring-border/60 transition hover:bg-muted",
141
+ "aria-label": t("reference_selection"),
142
+ title: t("reference_selection"),
143
+ children: /* @__PURE__ */ e(Ht, { className: "size-4" })
144
+ }
145
+ ),
146
+ a
147
+ ) : null;
148
+ }
149
+ function cn(t, a) {
150
+ if (typeof t != "object" || t === null) return t || void 0;
151
+ const n = a.split("-")[0];
152
+ return t[a] || t[n] || t.en || Object.values(t)[0];
153
+ }
154
+ function dn({
155
+ accent: t,
156
+ radius: a,
157
+ fontFamily: n
158
+ }) {
159
+ const r = {};
160
+ if (t && (r["--gentiq-primary"] = t), a && (r["--gentiq-radius"] = a), n) {
161
+ const o = n.includes(" ") && !/^['"]/.test(n) ? `"${n}"` : n;
162
+ r["--gentiq-font-family"] = `${o}, var(--gentiq-font-script)`;
163
+ }
164
+ return r;
165
+ }
166
+ const Q = It(function({ className: a, style: n, children: r, ...o }, i) {
167
+ const { resolvedTheme: m, accent: u, radius: g } = ie(), { language: c, dir: h } = ee(), p = K((b) => b.theme.typography?.fontFamily), [f, v] = N(null);
168
+ return /* @__PURE__ */ s(
169
+ "div",
170
+ {
171
+ ref: i,
172
+ ...o,
173
+ className: y("gentiq", m, a),
174
+ lang: c,
175
+ dir: h,
176
+ style: {
177
+ ...dn({ accent: u, radius: g, fontFamily: cn(p, c) }),
178
+ ...n
179
+ },
180
+ children: [
181
+ /* @__PURE__ */ e(ka.Provider, { value: f, children: r }),
182
+ /* @__PURE__ */ e("div", { ref: v, "data-gentiq-portal": "", className: "contents" })
183
+ ]
184
+ }
185
+ );
186
+ });
187
+ function un({ classNames: t = {} }) {
188
+ const { t: a, i18n: n } = _(["chat"]), { threadId: r, messages: o, status: i, send: m, addToolOutput: u } = At(), g = Le((E) => {
189
+ m({ text: E });
190
+ }, [m]), { MessageList: c, PromptInput: h, WelcomeScreen: p } = oe(), f = te((E) => E.composer), v = te((E) => E.disclaimer), b = K((E) => E.app.cacheNamespace), k = n.exists("chat:disclaimer") ? a("chat:disclaimer") : null, T = typeof v == "string" ? Qa(v, a, n, ["chat"]) : v ?? k, w = o[o.length - 1], M = w?.role === "assistant" && (i === "ready" || w.parts.some((E) => E.type === "data-chat-finished")), I = i === "error", B = r === null && o.length === 0 && i !== "submitted", W = O(() => qt(h), [h]), [ae, G] = en(), X = O(
191
+ () => G ? { "--gentiq-composer-inset": `${G}px` } : void 0,
192
+ [G]
193
+ );
194
+ return /* @__PURE__ */ s(
195
+ ze.Root,
196
+ {
197
+ enabled: f?.references?.enabled ?? !0,
198
+ maxItems: f?.references?.maxItems,
199
+ maxExcerptLength: f?.references?.maxExcerptLength,
200
+ children: [
201
+ /* @__PURE__ */ e(
202
+ Ca,
203
+ {
204
+ message: w,
205
+ disabled: !M || i !== "ready",
206
+ cacheNamespace: b,
207
+ onAnswer: u,
208
+ children: /* @__PURE__ */ s(
209
+ tt.Root,
210
+ {
211
+ className: y(
212
+ "relative flex flex-col h-full overflow-hidden bg-background",
213
+ t.container
214
+ ),
215
+ style: X,
216
+ children: [
217
+ !B && /* @__PURE__ */ e(st, { children: /* @__PURE__ */ e(c, { className: y("flex-1", t.messageList) }) }),
218
+ /* @__PURE__ */ s("div", { className: "absolute inset-0 z-10 pointer-events-none flex flex-col", children: [
219
+ /* @__PURE__ */ e("div", { className: "grow basis-0 shrink-0 min-h-0 flex flex-col items-center justify-end px-4 pb-6 md:pb-8", children: B && /* @__PURE__ */ e(p, { onSuggestionClick: g }) }),
220
+ /* @__PURE__ */ s("div", { ref: ae, className: "shrink-0 flex flex-col items-stretch", children: [
221
+ /* @__PURE__ */ e(
222
+ W,
223
+ {
224
+ onSend: m,
225
+ status: i,
226
+ isErrorVisible: I,
227
+ threadId: r,
228
+ newChat: B,
229
+ className: y(
230
+ "pointer-events-auto",
231
+ t.inputArea,
232
+ T && "pb-0 md:pb-0"
233
+ )
234
+ }
235
+ ),
236
+ T && /* @__PURE__ */ s("div", { className: "relative py-1 px-4 flex justify-center items-center pointer-events-auto", children: [
237
+ /* @__PURE__ */ e("div", { className: "absolute inset-0 bg-background pointer-events-none -z-10" }),
238
+ /* @__PURE__ */ e("p", { className: "text-xs text-muted-foreground select-none text-center leading-tight", children: T })
239
+ ] })
240
+ ] }),
241
+ /* @__PURE__ */ e(
242
+ "div",
243
+ {
244
+ className: y(
245
+ "basis-0 shrink-0 transition-[flex-grow] duration-500 ease-in-out",
246
+ B ? "grow" : "grow-0"
247
+ )
248
+ }
249
+ )
250
+ ] })
251
+ ]
252
+ }
253
+ )
254
+ }
255
+ ),
256
+ /* @__PURE__ */ e(ln, {})
257
+ ]
258
+ }
259
+ );
260
+ }
261
+ const mn = ({
262
+ threadId: t,
263
+ onThreadChange: a,
264
+ components: n,
265
+ welcome: r,
266
+ threadActions: o,
267
+ composer: i,
268
+ disclaimer: m,
269
+ ...u
270
+ }) => {
271
+ const g = Je(), c = /* @__PURE__ */ e(Q, { children: /* @__PURE__ */ e(
272
+ Fe,
273
+ {
274
+ components: n,
275
+ welcome: r,
276
+ threadActions: o,
277
+ composer: i,
278
+ disclaimer: m,
279
+ children: /* @__PURE__ */ e(un, { ...u })
280
+ }
281
+ ) });
282
+ return g && t === void 0 && a === void 0 ? c : /* @__PURE__ */ e(
283
+ et,
284
+ {
285
+ threadId: t,
286
+ onThreadChange: a,
287
+ getThreadHref: g?.getThreadHref,
288
+ children: c
289
+ }
290
+ );
291
+ };
292
+ function hn() {
293
+ return /* @__PURE__ */ e(Q, { children: /* @__PURE__ */ e("div", { className: "min-h-dvh bg-background" }) });
294
+ }
295
+ const gn = ({ theme: t = "system", ...a }) => /* @__PURE__ */ e(
296
+ Va,
297
+ {
298
+ theme: t,
299
+ className: "toaster group",
300
+ icons: {
301
+ success: /* @__PURE__ */ e(Xt, { className: "size-4" }),
302
+ info: /* @__PURE__ */ e(Wt, { className: "size-4" }),
303
+ warning: /* @__PURE__ */ e(Qt, { className: "size-4" }),
304
+ error: /* @__PURE__ */ e(Kt, { className: "size-4" }),
305
+ loading: /* @__PURE__ */ e(Vt, { className: "size-4 animate-spin" })
306
+ },
307
+ style: {
308
+ "--normal-bg": "var(--gentiq-popover)",
309
+ "--normal-text": "var(--gentiq-popover-foreground)",
310
+ "--normal-border": "var(--gentiq-border)",
311
+ "--border-radius": "var(--gentiq-radius)",
312
+ fontFamily: "var(--gentiq-font-family)"
313
+ },
314
+ ...a
315
+ }
316
+ );
317
+ function pn() {
318
+ const { resolvedTheme: t } = ie();
319
+ return /* @__PURE__ */ e(gn, { richColors: !0, theme: t });
320
+ }
321
+ const fn = vt(_a), bn = ({ message: t }) => {
322
+ P.error(t);
323
+ };
324
+ function vn({
325
+ toaster: t = !0,
326
+ fallback: a,
327
+ onConfigUnavailable: n = bn,
328
+ children: r,
329
+ ...o
330
+ }) {
331
+ return /* @__PURE__ */ e(
332
+ Ft,
333
+ {
334
+ ...o,
335
+ fallback: a ?? /* @__PURE__ */ e(hn, {}),
336
+ onConfigUnavailable: n,
337
+ overlay: t && /* @__PURE__ */ e(Q, { children: /* @__PURE__ */ e(pn, {}) }),
338
+ children: /* @__PURE__ */ e(Ze.PartsProvider, { components: fn, children: r })
339
+ }
340
+ );
341
+ }
342
+ function xn() {
343
+ const { language: t, dir: a } = ee(), { resolvedTheme: n } = ie(), r = K((i) => i.app.name), o = K((i) => i.app.favicon);
344
+ return F(() => {
345
+ const i = document.documentElement, m = { lang: i.lang, dir: i.dir };
346
+ return i.lang = t, i.dir = a, () => {
347
+ i.lang = m.lang, i.dir = m.dir;
348
+ };
349
+ }, [t, a]), F(() => {
350
+ const i = document.documentElement, m = i.style.colorScheme, u = i.classList.contains(n);
351
+ return i.classList.add(n), i.style.colorScheme = n, () => {
352
+ u || i.classList.remove(n), i.style.colorScheme = m;
353
+ };
354
+ }, [n]), F(() => {
355
+ if (!r) return;
356
+ const i = document.title;
357
+ return document.title = r, () => {
358
+ document.title = i;
359
+ };
360
+ }, [r]), F(() => {
361
+ if (!o) return;
362
+ const i = document.querySelector("link[rel~='icon']"), m = i ?? Object.assign(document.createElement("link"), { rel: "icon" }), u = m.getAttribute("href");
363
+ return m.href = o, i || document.head.appendChild(m), () => {
364
+ i ? u === null ? m.removeAttribute("href") : m.setAttribute("href", u) : m.remove();
365
+ };
366
+ }, [o]), null;
367
+ }
368
+ function yn({ children: t, fallback: a, loginCode: n, onLoginCodeUsed: r }) {
369
+ const o = Dt(), [i, m] = N(
370
+ () => n ? "pending" : "idle"
371
+ );
372
+ F(() => {
373
+ if (!n) return;
374
+ let c = !1;
375
+ return m("pending"), (async () => {
376
+ try {
377
+ await o(n);
378
+ } catch (h) {
379
+ if (c) return;
380
+ console.error("Could not sign in with the login code:", h), m("failed");
381
+ return;
382
+ }
383
+ c || (r?.(), m("idle"));
384
+ })(), () => {
385
+ c = !0;
386
+ };
387
+ }, [n]);
388
+ const u = Ot({ enabled: i === "idle" }), g = i === "failed" ? "handoff_failed" : i === "idle" && (u === "signed_out" || u === "session_expired") ? u : null;
389
+ return g ? /* @__PURE__ */ e(fe, { children: typeof a == "function" ? a(g) : a }) : i === "pending" || u === "checking" ? /* @__PURE__ */ e(Q, { children: /* @__PURE__ */ e("div", { className: "flex h-screen w-full items-center justify-center bg-background", children: /* @__PURE__ */ e("div", { className: "size-8 rounded-full border-4 border-primary border-t-transparent animate-spin" }) }) }) : /* @__PURE__ */ e(fe, { children: t });
390
+ }
391
+ const Ge = (t) => t.replace(/[^0-9]/g, "");
392
+ function Nn(t) {
393
+ return /* @__PURE__ */ e(Q, { children: /* @__PURE__ */ e(wn, { ...t }) });
394
+ }
395
+ function wn({ onSignedIn: t, reason: a }) {
396
+ const { t: n } = _(["login"]), r = K((d) => d.app), o = Re(), i = ee().dir === "rtl", m = at(), [u, g] = N("login"), c = !!r?.disableSignup, h = !!r?.disableAuthPage, p = O(
397
+ () => r?.loginFields ?? ["username"],
398
+ [r?.loginFields]
399
+ ), f = {
400
+ username: { labelKey: "username", labelDefault: "Username", inputType: "text" },
401
+ email: { labelKey: "email", labelDefault: "Email", inputType: "email" },
402
+ phone: { labelKey: "phone", labelDefault: "Phone", inputType: "tel" }
403
+ }, v = p.map((d) => n(f[d].labelKey, f[d].labelDefault)).join(" / "), b = p.length === 1 ? f[p[0]].inputType : "text", k = p.length === 1 && p[0] === "phone", T = (d) => k ? Ge(d) : d, [w, M] = N(""), [I, B] = N(""), [W, ae] = N({}), G = (d, x) => ae((R) => ({ ...R, [d]: x })), [X, E] = N(""), [le, ve] = N(""), [ce, xe] = N(""), H = O(
404
+ () => r?.userMetadataFields?.filter((d) => d.showInSignup) || [],
405
+ [r?.userMetadataFields]
406
+ ), [z, U] = N(() => {
407
+ const d = {};
408
+ return H.forEach((x) => {
409
+ x.defaultValue !== void 0 && (d[x.key] = x.defaultValue);
410
+ }), d;
411
+ });
412
+ F(() => {
413
+ const d = { ...z };
414
+ let x = !1;
415
+ H.forEach((R) => {
416
+ R.condition && !Te(R.condition, z) && d[R.key] !== void 0 && (delete d[R.key], x = !0);
417
+ }), x && U(d);
418
+ }, [z, H]);
419
+ const [q, A] = N(""), [Y, Z] = N(!1);
420
+ F(() => {
421
+ c && u === "register" && g("login");
422
+ }, [c, u]);
423
+ const de = async (d) => {
424
+ d.preventDefault(), A(""), Z(!0);
425
+ try {
426
+ await o.login(w, I), m.clear(), t();
427
+ } catch (x) {
428
+ A(se(x, n));
429
+ } finally {
430
+ Z(!1);
431
+ }
432
+ }, ue = async (d) => {
433
+ d.preventDefault(), A("");
434
+ const x = {};
435
+ for (const R of p) {
436
+ const J = W[R]?.trim();
437
+ J && (x[R] = J);
438
+ }
439
+ if (Object.keys(x).length === 0) {
440
+ A(n("at_least_one_login_field", "Please provide at least one login field."));
441
+ return;
442
+ }
443
+ Z(!0);
444
+ try {
445
+ await o.register(x, X, le, ce, z), m.clear(), t();
446
+ } catch (R) {
447
+ A(se(R, n));
448
+ } finally {
449
+ Z(!1);
450
+ }
451
+ };
452
+ if (h) {
453
+ const d = a === "handoff_failed";
454
+ return /* @__PURE__ */ e(
455
+ "div",
456
+ {
457
+ className: "min-h-screen bg-background flex items-center justify-center p-4",
458
+ dir: i ? "rtl" : "ltr",
459
+ children: /* @__PURE__ */ s("div", { className: "w-full max-w-lg bg-card border border-border rounded-xl shadow-lg p-8 text-center space-y-4", children: [
460
+ /* @__PURE__ */ e("h1", { className: "text-2xl font-bold", children: r?.name }),
461
+ /* @__PURE__ */ e("p", { className: "text-muted-foreground", children: d ? n("handoff_failed_title", "This sign-in link has expired or was already used.") : n("auth_page_disabled_title", "The sign-in page is currently disabled.") }),
462
+ /* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground/80", children: d ? n("handoff_failed_description", "Open the chat again from where you came from.") : n("auth_page_disabled_description", "Please contact the administrator for access.") })
463
+ ] })
464
+ }
465
+ );
466
+ }
467
+ return /* @__PURE__ */ e(
468
+ "div",
469
+ {
470
+ className: "min-h-screen bg-background flex flex-col items-center justify-center p-4",
471
+ dir: i ? "rtl" : "ltr",
472
+ children: /* @__PURE__ */ s("div", { className: "w-full max-w-md bg-card border border-border rounded-xl shadow-lg p-6", children: [
473
+ /* @__PURE__ */ e("div", { className: "text-center mb-6", children: /* @__PURE__ */ e("h1", { className: "text-2xl font-bold text-foreground", children: r?.name }) }),
474
+ /* @__PURE__ */ s("div", { className: "flex bg-muted p-1 rounded-lg mb-6", children: [
475
+ /* @__PURE__ */ e(
476
+ "button",
477
+ {
478
+ type: "button",
479
+ onClick: () => {
480
+ g("login"), A("");
481
+ },
482
+ className: `flex-1 py-2 text-sm font-medium rounded-md transition-all ${u === "login" ? "bg-background shadow-sm text-foreground" : "text-muted-foreground hover:text-foreground"}`,
483
+ children: n("login_tab", "Login")
484
+ }
485
+ ),
486
+ !c && /* @__PURE__ */ e(
487
+ "button",
488
+ {
489
+ type: "button",
490
+ onClick: () => {
491
+ g("register"), A("");
492
+ },
493
+ className: `flex-1 py-2 text-sm font-medium rounded-md transition-all ${u === "register" ? "bg-background shadow-sm text-foreground" : "text-muted-foreground hover:text-foreground"}`,
494
+ children: n("signup_tab", "Sign Up")
495
+ }
496
+ )
497
+ ] }),
498
+ u === "login" && /* @__PURE__ */ s("form", { onSubmit: de, className: "space-y-4", children: [
499
+ /* @__PURE__ */ s("div", { className: "space-y-3", children: [
500
+ /* @__PURE__ */ e(L, { htmlFor: "login-identity", children: v }),
501
+ /* @__PURE__ */ e(
502
+ D,
503
+ {
504
+ id: "login-identity",
505
+ type: b,
506
+ value: w,
507
+ onChange: (d) => M(T(d.target.value)),
508
+ required: !0,
509
+ className: "text-start",
510
+ placeholder: v,
511
+ dir: "ltr"
512
+ }
513
+ )
514
+ ] }),
515
+ /* @__PURE__ */ s("div", { className: "space-y-3", children: [
516
+ /* @__PURE__ */ e(L, { htmlFor: "login-pass", children: n("password", "Password") }),
517
+ /* @__PURE__ */ e(
518
+ D,
519
+ {
520
+ id: "login-pass",
521
+ type: "password",
522
+ value: I,
523
+ onChange: (d) => B(d.target.value),
524
+ required: !0,
525
+ className: "text-start",
526
+ placeholder: "••••••••",
527
+ dir: "ltr"
528
+ }
529
+ )
530
+ ] }),
531
+ q && /* @__PURE__ */ e("div", { role: "alert", className: "text-sm text-destructive", children: q }),
532
+ /* @__PURE__ */ e($, { type: "submit", disabled: Y, className: "w-full font-semibold", children: Y ? n("logging_in", "Logging in...") : n("login_button", "Login") })
533
+ ] }),
534
+ !c && u === "register" && /* @__PURE__ */ s("form", { onSubmit: ue, className: "space-y-4", children: [
535
+ p.map((d) => {
536
+ const x = f[d], R = n(x.labelKey, x.labelDefault), J = (l) => d === "phone" ? Ge(l) : l;
537
+ return /* @__PURE__ */ s("div", { className: "space-y-3", children: [
538
+ /* @__PURE__ */ e(L, { htmlFor: `reg-${d}`, children: R }),
539
+ /* @__PURE__ */ e(
540
+ D,
541
+ {
542
+ id: `reg-${d}`,
543
+ type: x.inputType,
544
+ value: W[d] ?? "",
545
+ onChange: (l) => G(d, J(l.target.value)),
546
+ required: p.length === 1,
547
+ className: "text-start",
548
+ placeholder: n(`${x.labelKey}_placeholder`, x.labelDefault),
549
+ dir: "ltr"
550
+ }
551
+ )
552
+ ] }, d);
553
+ }),
554
+ /* @__PURE__ */ s("div", { className: "space-y-3", children: [
555
+ /* @__PURE__ */ e(L, { htmlFor: "reg-pass", children: n("password", "Password") }),
556
+ /* @__PURE__ */ e(
557
+ D,
558
+ {
559
+ id: "reg-pass",
560
+ type: "password",
561
+ value: X,
562
+ onChange: (d) => E(d.target.value),
563
+ required: !0,
564
+ className: "text-start",
565
+ placeholder: "••••••••",
566
+ dir: "ltr"
567
+ }
568
+ )
569
+ ] }),
570
+ /* @__PURE__ */ s("div", { className: "grid grid-cols-2 gap-4", children: [
571
+ /* @__PURE__ */ s("div", { className: "space-y-3", children: [
572
+ /* @__PURE__ */ e(L, { htmlFor: "reg-name", children: n("name", "Name") }),
573
+ /* @__PURE__ */ e(
574
+ D,
575
+ {
576
+ id: "reg-name",
577
+ type: "text",
578
+ value: le,
579
+ onChange: (d) => ve(d.target.value),
580
+ required: !0,
581
+ className: "text-start",
582
+ placeholder: n("name_placeholder", "First Name")
583
+ }
584
+ )
585
+ ] }),
586
+ /* @__PURE__ */ s("div", { className: "space-y-3", children: [
587
+ /* @__PURE__ */ e(L, { htmlFor: "reg-surname", children: n("surname", "Surname") }),
588
+ /* @__PURE__ */ e(
589
+ D,
590
+ {
591
+ id: "reg-surname",
592
+ type: "text",
593
+ value: ce,
594
+ onChange: (d) => xe(d.target.value),
595
+ required: !0,
596
+ className: "text-start",
597
+ placeholder: n("surname_placeholder", "Last Name")
598
+ }
599
+ )
600
+ ] })
601
+ ] }),
602
+ H.map((d) => Te(d.condition, z) ? /* @__PURE__ */ s(
603
+ "div",
604
+ {
605
+ className: "space-y-3 animate-in fade-in slide-in-from-top-1 duration-200",
606
+ children: [
607
+ /* @__PURE__ */ e(L, { htmlFor: `signup-${d.key}`, children: n(d.label) }),
608
+ d.type === "select" ? /* @__PURE__ */ s(
609
+ we,
610
+ {
611
+ value: String(z[d.key] || ""),
612
+ onValueChange: (x) => U({ ...z, [d.key]: x }),
613
+ required: d.required,
614
+ dir: i ? "rtl" : "ltr",
615
+ children: [
616
+ /* @__PURE__ */ e(Se, { className: "bg-background text-start", children: /* @__PURE__ */ e(ke, { placeholder: n(d.placeholder || "select_placeholder") }) }),
617
+ /* @__PURE__ */ e(Ce, { className: "rounded-xl", children: d.options?.map((x) => /* @__PURE__ */ e(_e, { value: String(x.value), children: n(x.label) }, String(x.value))) })
618
+ ]
619
+ }
620
+ ) : d.type === "checkbox" ? /* @__PURE__ */ s("div", { className: "flex items-center gap-2 py-2", children: [
621
+ /* @__PURE__ */ e(
622
+ Ta,
623
+ {
624
+ id: `signup-${d.key}`,
625
+ checked: !!z[d.key],
626
+ onCheckedChange: (x) => U({ ...z, [d.key]: !!x }),
627
+ required: d.required
628
+ }
629
+ ),
630
+ /* @__PURE__ */ e(
631
+ "label",
632
+ {
633
+ htmlFor: `signup-${d.key}`,
634
+ className: "text-sm text-muted-foreground cursor-pointer select-none",
635
+ children: n(d.placeholder || d.label)
636
+ }
637
+ )
638
+ ] }) : /* @__PURE__ */ e(
639
+ D,
640
+ {
641
+ id: `signup-${d.key}`,
642
+ type: d.type,
643
+ value: z[d.key] || "",
644
+ onChange: (x) => U({ ...z, [d.key]: x.target.value }),
645
+ required: d.required,
646
+ className: "text-start",
647
+ placeholder: n(d.placeholder || "")
648
+ }
649
+ )
650
+ ]
651
+ },
652
+ d.key
653
+ ) : null),
654
+ q && /* @__PURE__ */ e("div", { role: "alert", className: "text-sm text-destructive", children: q }),
655
+ /* @__PURE__ */ e($, { type: "submit", disabled: Y, className: "w-full font-semibold", children: Y ? n("signing_up", "Signing up...") : n("signup_button", "Sign Up") })
656
+ ] })
657
+ ] })
658
+ }
659
+ );
660
+ }
661
+ const Sn = "sidebar_state", kn = 3600 * 24 * 7, Cn = "19rem", _n = "18rem", Tn = "3rem", In = "b", xt = V.createContext(null);
662
+ function be() {
663
+ const t = V.useContext(xt);
664
+ if (!t)
665
+ throw new Error("useSidebar must be used within a SidebarProvider.");
666
+ return t;
667
+ }
668
+ function qn({
669
+ defaultOpen: t = !0,
670
+ open: a,
671
+ onOpenChange: n,
672
+ className: r,
673
+ style: o,
674
+ children: i,
675
+ ...m
676
+ }) {
677
+ const u = ot(), [g, c] = V.useState(!1), [h, p] = V.useState(t), f = a ?? h, v = V.useCallback(
678
+ (w) => {
679
+ const M = typeof w == "function" ? w(f) : w;
680
+ n ? n(M) : p(M), document.cookie = `${Sn}=${M}; path=/; max-age=${kn}`;
681
+ },
682
+ [n, f]
683
+ ), b = V.useCallback(() => {
684
+ u ? c((w) => !w) : v((w) => !w);
685
+ }, [u, v, c]);
686
+ V.useEffect(() => {
687
+ const w = (M) => {
688
+ M.key === In && (M.metaKey || M.ctrlKey) && (M.preventDefault(), b());
689
+ };
690
+ return window.addEventListener("keydown", w), () => {
691
+ window.removeEventListener("keydown", w);
692
+ };
693
+ }, [b]);
694
+ const k = f ? "expanded" : "collapsed", T = V.useMemo(
695
+ () => ({
696
+ state: k,
697
+ open: f,
698
+ setOpen: v,
699
+ isMobile: u,
700
+ openMobile: g,
701
+ setOpenMobile: c,
702
+ toggleSidebar: b
703
+ }),
704
+ [k, f, v, u, g, c, b]
705
+ );
706
+ return /* @__PURE__ */ e(xt.Provider, { value: T, children: /* @__PURE__ */ e(lt, { delayDuration: 0, children: /* @__PURE__ */ e(
707
+ "div",
708
+ {
709
+ "data-slot": "sidebar-wrapper",
710
+ style: {
711
+ "--gentiq-sidebar-width": Cn,
712
+ "--gentiq-sidebar-width-icon": Tn,
713
+ ...o
714
+ },
715
+ className: y("group/sidebar-wrapper has-data-[variant=inset]:bg-sidebar flex min-h-svh w-full", r),
716
+ ...m,
717
+ children: i
718
+ }
719
+ ) }) });
720
+ }
721
+ function Ln({
722
+ side: t = "start",
723
+ variant: a = "sidebar",
724
+ collapsible: n = "offcanvas",
725
+ className: r,
726
+ children: o,
727
+ ...i
728
+ }) {
729
+ const { isMobile: m, state: u, openMobile: g, setOpenMobile: c } = be(), { t: h } = _("sidebar");
730
+ return n === "none" ? /* @__PURE__ */ e(
731
+ "div",
732
+ {
733
+ "data-slot": "sidebar",
734
+ className: y("bg-sidebar text-sidebar-foreground flex h-full w-(--gentiq-sidebar-width) flex-col", r),
735
+ ...i,
736
+ children: o
737
+ }
738
+ ) : m ? /* @__PURE__ */ e(Ia, { open: g, onOpenChange: c, ...i, children: /* @__PURE__ */ s(
739
+ qa,
740
+ {
741
+ onOpenAutoFocus: (p) => p.preventDefault(),
742
+ "data-sidebar": "sidebar",
743
+ "data-slot": "sidebar",
744
+ "data-mobile": "true",
745
+ className: "bg-sidebar text-sidebar-foreground w-(--gentiq-sidebar-width) p-0 [&>button]:hidden",
746
+ style: {
747
+ "--gentiq-sidebar-width": _n
748
+ },
749
+ side: t,
750
+ children: [
751
+ /* @__PURE__ */ s(La, { className: "sr-only", children: [
752
+ /* @__PURE__ */ e(Pa, { children: h("title") }),
753
+ /* @__PURE__ */ e(Ma, { children: h("mobile_description") })
754
+ ] }),
755
+ /* @__PURE__ */ e("div", { className: "flex h-full w-full flex-col", children: o })
756
+ ]
757
+ }
758
+ ) }) : /* @__PURE__ */ s(
759
+ "div",
760
+ {
761
+ className: "group peer text-sidebar-foreground hidden md:block",
762
+ "data-state": u,
763
+ "data-collapsible": u === "collapsed" ? n : "",
764
+ "data-variant": a,
765
+ "data-side": t,
766
+ "data-slot": "sidebar",
767
+ children: [
768
+ /* @__PURE__ */ e(
769
+ "div",
770
+ {
771
+ "data-slot": "sidebar-gap",
772
+ className: y(
773
+ "relative w-(--gentiq-sidebar-width) bg-transparent transition-[width] duration-200 ease-linear",
774
+ "group-data-[collapsible=offcanvas]:w-0",
775
+ a === "floating" || a === "inset" ? "group-data-[collapsible=icon]:w-[calc(var(--gentiq-sidebar-width-icon)+(--spacing(4)))]" : "group-data-[collapsible=icon]:w-(--gentiq-sidebar-width-icon)"
776
+ )
777
+ }
778
+ ),
779
+ /* @__PURE__ */ e(
780
+ "div",
781
+ {
782
+ "data-slot": "sidebar-container",
783
+ className: y(
784
+ "fixed inset-y-0 z-10 hidden h-svh w-(--gentiq-sidebar-width) transition-[inset-inline-start,inset-inline-end,width] duration-200 ease-linear md:flex",
785
+ t === "start" ? "start-0 group-data-[collapsible=offcanvas]:start-[calc(var(--gentiq-sidebar-width)*-1)]" : "end-0 group-data-[collapsible=offcanvas]:end-[calc(var(--gentiq-sidebar-width)*-1)]",
786
+ // Adjust the padding for floating and inset variants.
787
+ a === "floating" || a === "inset" ? "p-2 group-data-[collapsible=icon]:w-[calc(var(--gentiq-sidebar-width-icon)+(--spacing(4))+2px)]" : "group-data-[collapsible=icon]:w-(--gentiq-sidebar-width-icon) group-data-[side=start]:border-e group-data-[side=end]:border-s",
788
+ r
789
+ ),
790
+ ...i,
791
+ children: /* @__PURE__ */ e(
792
+ "div",
793
+ {
794
+ "data-sidebar": "sidebar",
795
+ "data-slot": "sidebar-inner",
796
+ className: "bg-sidebar group-data-[variant=floating]:border-sidebar-border flex h-full w-full flex-col group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:border group-data-[variant=floating]:shadow-sm",
797
+ children: o
798
+ }
799
+ )
800
+ }
801
+ )
802
+ ]
803
+ }
804
+ );
805
+ }
806
+ function Pn({ className: t, onClick: a, ...n }) {
807
+ const { toggleSidebar: r } = be(), { t: o } = _("sidebar");
808
+ return /* @__PURE__ */ s(
809
+ $,
810
+ {
811
+ "data-sidebar": "trigger",
812
+ "data-slot": "sidebar-trigger",
813
+ variant: "ghost",
814
+ size: "icon",
815
+ className: y("size-7", t),
816
+ onClick: (i) => {
817
+ a?.(i), r();
818
+ },
819
+ ...n,
820
+ children: [
821
+ /* @__PURE__ */ e(Yt, {}),
822
+ /* @__PURE__ */ e("span", { className: "sr-only", children: o("toggle") })
823
+ ]
824
+ }
825
+ );
826
+ }
827
+ function Mn({ className: t, ...a }) {
828
+ return /* @__PURE__ */ e(
829
+ "div",
830
+ {
831
+ "data-slot": "sidebar-content",
832
+ "data-sidebar": "content",
833
+ className: y(
834
+ "flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",
835
+ t
836
+ ),
837
+ ...a
838
+ }
839
+ );
840
+ }
841
+ function En({ className: t, ...a }) {
842
+ return /* @__PURE__ */ e(
843
+ "div",
844
+ {
845
+ "data-slot": "sidebar-group",
846
+ "data-sidebar": "group",
847
+ className: y("relative flex w-full min-w-0 flex-col p-2", t),
848
+ ...a
849
+ }
850
+ );
851
+ }
852
+ function He({ className: t, ...a }) {
853
+ return /* @__PURE__ */ e(
854
+ "div",
855
+ {
856
+ "data-slot": "sidebar-group-content",
857
+ "data-sidebar": "group-content",
858
+ className: y("w-full text-sm", t),
859
+ ...a
860
+ }
861
+ );
862
+ }
863
+ function yt({ className: t, ...a }) {
864
+ return /* @__PURE__ */ e(
865
+ "ul",
866
+ {
867
+ "data-slot": "sidebar-menu",
868
+ "data-sidebar": "menu",
869
+ className: y("flex w-full min-w-0 flex-col gap-1", t),
870
+ ...a
871
+ }
872
+ );
873
+ }
874
+ function Nt({ className: t, ...a }) {
875
+ return /* @__PURE__ */ e(
876
+ "li",
877
+ {
878
+ "data-slot": "sidebar-menu-item",
879
+ "data-sidebar": "menu-item",
880
+ className: y("group/menu-item relative", t),
881
+ ...a
882
+ }
883
+ );
884
+ }
885
+ const zn = Gt(
886
+ "peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-start text-sm outline-hidden ring-sidebar-ring transition-[width,height,padding] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 group-has-data-[sidebar=menu-action]/menu-item:pe-8 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:p-2! [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",
887
+ {
888
+ variants: {
889
+ variant: {
890
+ default: "hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",
891
+ outline: "bg-background shadow-[0_0_0_1px_hsl(var(--gentiq-sidebar-border))] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_hsl(var(--gentiq-sidebar-accent))]"
892
+ },
893
+ size: {
894
+ default: "h-8 text-sm",
895
+ sm: "h-7 text-xs",
896
+ lg: "h-12 text-sm group-data-[collapsible=icon]:p-0!"
897
+ }
898
+ },
899
+ defaultVariants: {
900
+ variant: "default",
901
+ size: "default"
902
+ }
903
+ }
904
+ );
905
+ function wt({
906
+ asChild: t = !1,
907
+ isActive: a = !1,
908
+ variant: n = "default",
909
+ size: r = "default",
910
+ tooltip: o,
911
+ className: i,
912
+ ...m
913
+ }) {
914
+ const u = t ? Bt : "button", { isMobile: g, state: c } = be(), h = /* @__PURE__ */ e(
915
+ u,
916
+ {
917
+ "data-slot": "sidebar-menu-button",
918
+ "data-sidebar": "menu-button",
919
+ "data-size": r,
920
+ "data-active": a,
921
+ className: y(zn({ variant: n, size: r }), i),
922
+ ...m
923
+ }
924
+ );
925
+ return o ? (typeof o == "string" && (o = {
926
+ children: o
927
+ }), /* @__PURE__ */ s(ct, { children: [
928
+ /* @__PURE__ */ e(dt, { asChild: !0, children: h }),
929
+ /* @__PURE__ */ e(ut, { side: "right", align: "center", hidden: c !== "collapsed" || g, ...o })
930
+ ] })) : h;
931
+ }
932
+ function St({
933
+ label: t,
934
+ detail: a,
935
+ meter: n,
936
+ remaining: r,
937
+ amount: o,
938
+ resetsAt: i,
939
+ action: m
940
+ }) {
941
+ const { t: u, i18n: g } = _(["quota"]), c = Ra(r, o);
942
+ return /* @__PURE__ */ s("div", { className: "space-y-1.5", children: [
943
+ /* @__PURE__ */ s("div", { className: "flex items-baseline justify-between gap-3 text-sm", children: [
944
+ /* @__PURE__ */ s("span", { className: "font-medium text-foreground/80", children: [
945
+ t,
946
+ " ",
947
+ a && /* @__PURE__ */ e("span", { className: "text-xs font-normal text-muted-foreground", children: a })
948
+ ] }),
949
+ /* @__PURE__ */ s("span", { className: "flex items-center gap-2", children: [
950
+ /* @__PURE__ */ s("span", { className: "font-semibold tabular-nums text-foreground", children: [
951
+ Ue(n, r, g.language),
952
+ /* @__PURE__ */ s("span", { className: "text-muted-foreground font-normal", children: [
953
+ " / ",
954
+ Ue(n, o, g.language)
955
+ ] })
956
+ ] }),
957
+ m
958
+ ] })
959
+ ] }),
960
+ /* @__PURE__ */ e(
961
+ "div",
962
+ {
963
+ className: "h-2 w-full bg-muted/50 rounded-full overflow-hidden",
964
+ role: "meter",
965
+ "aria-valuemin": 0,
966
+ "aria-valuemax": o,
967
+ "aria-valuenow": r,
968
+ "aria-label": typeof t == "string" ? t : void 0,
969
+ children: /* @__PURE__ */ e(
970
+ "div",
971
+ {
972
+ className: y("h-full rounded-full transition-all duration-700", Ea(c)),
973
+ style: { width: `${c}%` }
974
+ }
975
+ )
976
+ }
977
+ ),
978
+ i && /* @__PURE__ */ e("p", { className: "text-xs text-muted-foreground", children: u("quota:resets_at", { datetime: ht(i, g.language) }) })
979
+ ] });
980
+ }
981
+ function Rn({ windows: t, className: a, renderAction: n }) {
982
+ const { t: r } = _(["quota"]);
983
+ return /* @__PURE__ */ e("div", { className: y("space-y-4", a), children: t.map((o) => /* @__PURE__ */ e(
984
+ St,
985
+ {
986
+ label: mt(r, o.meter),
987
+ detail: za(r, o),
988
+ meter: o.meter,
989
+ remaining: o.remaining,
990
+ amount: o.amount,
991
+ resetsAt: o.resets_at,
992
+ action: n?.(o)
993
+ },
994
+ o.key
995
+ )) });
996
+ }
997
+ function An({ credits: t, action: a }) {
998
+ const { t: n } = _(["quota"]);
999
+ return /* @__PURE__ */ e(
1000
+ St,
1001
+ {
1002
+ label: n("quota:credits"),
1003
+ detail: n("quota:credits_unit", { meter: mt(n, t.meter) }),
1004
+ meter: t.meter,
1005
+ remaining: t.remaining,
1006
+ amount: t.granted,
1007
+ action: a
1008
+ }
1009
+ );
1010
+ }
1011
+ const Fn = ["system", "light", "dark"], Ve = "h-11 w-full rounded-xl border-border/50 bg-muted/30 text-base", Ke = "rounded-xl border-border/40 bg-background shadow-xl", Qe = "rounded-lg py-2 text-base focus:bg-primary/10";
1012
+ function Dn() {
1013
+ const { t, i18n: a } = _("settings"), n = K((b) => b.app), { theme: r, setTheme: o, locked: i } = ie(), { language: m, setLanguage: u, locked: g, dir: c } = ee(), h = Oe(), p = Oe(), f = Wa(a, n?.languages), v = f.find((b) => b === m) ?? m.split("-")[0];
1014
+ return /* @__PURE__ */ s("div", { className: "grid gap-6", children: [
1015
+ !i && /* @__PURE__ */ s("div", { className: "flex flex-col gap-3", children: [
1016
+ /* @__PURE__ */ e(L, { htmlFor: h, className: "px-1", children: t("general.theme") }),
1017
+ /* @__PURE__ */ s(
1018
+ we,
1019
+ {
1020
+ value: r,
1021
+ onValueChange: (b) => o(b),
1022
+ dir: c,
1023
+ children: [
1024
+ /* @__PURE__ */ e(Se, { id: h, className: Ve, children: /* @__PURE__ */ e(ke, {}) }),
1025
+ /* @__PURE__ */ e(Ce, { className: Ke, children: Fn.map((b) => /* @__PURE__ */ e(_e, { value: b, className: Qe, children: t(`general.themes.${b}`) }, b)) })
1026
+ ]
1027
+ }
1028
+ )
1029
+ ] }),
1030
+ !g && /* @__PURE__ */ s("div", { className: "flex flex-col gap-3", children: [
1031
+ /* @__PURE__ */ e(L, { htmlFor: p, className: "px-1", children: t("general.language") }),
1032
+ /* @__PURE__ */ s(we, { value: v, onValueChange: u, dir: c, children: [
1033
+ /* @__PURE__ */ e(Se, { id: p, className: Ve, children: /* @__PURE__ */ e(ke, {}) }),
1034
+ /* @__PURE__ */ e(Ce, { className: Ke, children: f.map((b) => /* @__PURE__ */ e(_e, { value: b, lang: b, className: Qe, children: Xa(b) }, b)) })
1035
+ ] })
1036
+ ] })
1037
+ ] });
1038
+ }
1039
+ function On({ trigger: t }) {
1040
+ const { t: a, i18n: n } = _(["settings"]), r = K((l) => l.app), o = te((l) => l.settings), i = Re(), m = at(), u = $t(), [g, c] = N(!1), { data: h, refetch: p } = Ut({
1041
+ enabled: g
1042
+ }), f = Ee(null), { locked: v } = ie(), { locked: b } = ee(), k = !v || !b, T = O(() => [
1043
+ { id: "profile", label: a("sections.profile", "Profile"), icon: Zt },
1044
+ { id: "general", label: a("sections.general"), icon: Jt },
1045
+ { id: "account", label: a("sections.account", "Account"), icon: ea }
1046
+ ].filter((C) => {
1047
+ if (C.id === "general") return k;
1048
+ const S = o?.sections?.[C.id];
1049
+ return (S?.mode ?? (S?.enabled === !1 ? "hidden" : "editable")) !== "hidden";
1050
+ }), [a, o, k]), [w, M] = N(T[0]?.id || "profile"), I = Le(
1051
+ (l, C, S = "editable") => {
1052
+ const me = o?.sections?.[l]?.fields;
1053
+ return me && me[C] || S;
1054
+ },
1055
+ [o]
1056
+ ), [B, W] = N(""), [ae, G] = N(""), [X, E] = N(""), [le, ve] = N(""), [ce, xe] = N(""), [H, z] = N(""), U = O(
1057
+ () => r?.userMetadataFields?.filter((l) => l.showInProfile) || [],
1058
+ [r?.userMetadataFields]
1059
+ ), [q, A] = N({}), [Y, Z] = N(!1), de = ee().dir === "rtl", ue = Le(async () => {
1060
+ try {
1061
+ p();
1062
+ const l = await i.getMe();
1063
+ W(l.name || ""), G(l.surname || ""), E(l.username || ""), ve(l.email || ""), xe(l.phone || "");
1064
+ const C = {};
1065
+ U.forEach((S) => {
1066
+ C[S.key] = l.metadata?.[S.key] ?? S.defaultValue ?? "";
1067
+ }), A(C);
1068
+ } catch (l) {
1069
+ console.error("Failed to fetch user:", l), P.error(se(l, a));
1070
+ }
1071
+ }, [a, U, i, p]);
1072
+ F(() => {
1073
+ if (!g) {
1074
+ f.current = null;
1075
+ return;
1076
+ }
1077
+ (f.current === null || w === "account") && ue(), f.current = w;
1078
+ }, [g, w, ue]), F(() => {
1079
+ const l = { ...q };
1080
+ let C = !1;
1081
+ U.forEach((S) => {
1082
+ S.condition && !Te(S.condition, q) && l[S.key] !== void 0 && (delete l[S.key], C = !0);
1083
+ }), C && A(l);
1084
+ }, [q, U]);
1085
+ const d = async () => {
1086
+ Z(!0);
1087
+ try {
1088
+ const l = {
1089
+ name: B,
1090
+ surname: ae,
1091
+ username: X || void 0,
1092
+ email: le || void 0,
1093
+ phone: ce || void 0,
1094
+ metadata: q
1095
+ };
1096
+ H && (l.password = H);
1097
+ const C = await i.updateMe(l);
1098
+ m.setQueryData(u.currentUser(), C), P.success(a("profile.success", "Profile updated successfully")), z(""), ue();
1099
+ } catch (l) {
1100
+ P.error(se(l, a));
1101
+ } finally {
1102
+ Z(!1);
1103
+ }
1104
+ }, x = async () => {
1105
+ if (window.confirm(a("account.logout_confirm", "Are you sure you want to logout?")))
1106
+ try {
1107
+ await i.logout(), window.location.reload();
1108
+ } catch (l) {
1109
+ P.error(se(l, a));
1110
+ }
1111
+ }, J = o?.sections?.account?.fields?.usage ?? "editable";
1112
+ return /* @__PURE__ */ s(gt, { open: g, onOpenChange: c, children: [
1113
+ /* @__PURE__ */ e(Aa, { asChild: !0, children: t || /* @__PURE__ */ e($, { variant: "ghost", size: "icon", className: "rounded-full", children: /* @__PURE__ */ e(Pe, { className: "h-5 w-5" }) }) }),
1114
+ /* @__PURE__ */ e(
1115
+ pt,
1116
+ {
1117
+ dir: de ? "rtl" : "ltr",
1118
+ className: y(
1119
+ "w-full sm:w-[95vw] sm:max-w-[700px] p-0 gap-0 overflow-hidden rounded-t-2xl sm:rounded-3xl border-none shadow-lg bg-background h-[90vh] sm:h-[min(750px,90vh)]",
1120
+ de && "rtl"
1121
+ ),
1122
+ children: /* @__PURE__ */ s("div", { className: "flex flex-col h-full w-full min-h-0 overflow-hidden", children: [
1123
+ /* @__PURE__ */ s("div", { className: "w-full bg-muted/20 sm:bg-muted/30 border-b border-border/40 pt-12 sm:pt-6 flex flex-col shrink-0", children: [
1124
+ /* @__PURE__ */ e("div", { className: "flex items-center justify-between px-4 sm:px-6 mb-2 sm:mb-4", children: /* @__PURE__ */ s("div", { className: "flex items-center gap-2", children: [
1125
+ /* @__PURE__ */ e("div", { className: "bg-primary/10 p-1.5 rounded-lg", children: /* @__PURE__ */ e(Pe, { className: "h-5 w-5 text-primary" }) }),
1126
+ /* @__PURE__ */ e("span", { className: "font-bold text-lg", children: a("title", "Settings") })
1127
+ ] }) }),
1128
+ /* @__PURE__ */ e("div", { className: "w-full overflow-x-auto no-scrollbar pt-2 px-2 sm:px-4", children: /* @__PURE__ */ e("nav", { className: "flex items-center gap-2 sm:gap-6 w-max", children: T.map((l) => /* @__PURE__ */ s(
1129
+ "button",
1130
+ {
1131
+ onClick: () => M(l.id),
1132
+ className: y(
1133
+ "flex items-center gap-1.5 sm:gap-2 pb-2 sm:pb-3 pt-1 px-2 sm:px-1 text-sm sm:text-base font-medium transition-all border-b-2 whitespace-nowrap shrink-0",
1134
+ w === l.id ? "border-primary text-primary" : "border-transparent text-muted-foreground hover:text-foreground hover:border-border",
1135
+ l.id !== "general" && o?.sections?.[l.id]?.mode === "faded" && "opacity-50 pointer-events-none select-none"
1136
+ ),
1137
+ children: [
1138
+ /* @__PURE__ */ e(
1139
+ l.icon,
1140
+ {
1141
+ className: y(
1142
+ "h-3.5 w-3.5 sm:h-4 sm:w-4 transition-transform",
1143
+ w === l.id && "scale-110"
1144
+ )
1145
+ }
1146
+ ),
1147
+ l.label
1148
+ ]
1149
+ },
1150
+ l.id
1151
+ )) }) })
1152
+ ] }),
1153
+ /* @__PURE__ */ e("div", { className: "flex-1 relative min-h-0 h-full bg-background", children: /* @__PURE__ */ s("div", { className: "absolute inset-0 overflow-y-auto p-5 sm:p-8 pt-12 sm:pt-12 custom-scrollbar", children: [
1154
+ w === "profile" && /* @__PURE__ */ s("div", { className: "space-y-6 animate-in fade-in slide-in-from-bottom-4 duration-300", children: [
1155
+ /* @__PURE__ */ s("div", { children: [
1156
+ /* @__PURE__ */ e("h2", { className: "text-xl font-bold tracking-tight", children: a("profile.title", "Profile Information") }),
1157
+ /* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground", children: a("profile.subtitle", "Update your personal details below.") })
1158
+ ] }),
1159
+ /* @__PURE__ */ s("div", { className: "grid gap-6", children: [
1160
+ /* @__PURE__ */ s("div", { className: "grid grid-cols-1 sm:grid-cols-2 gap-4", children: [
1161
+ I("profile", "name") !== "hidden" && /* @__PURE__ */ s(
1162
+ "div",
1163
+ {
1164
+ className: y(
1165
+ "flex flex-col gap-3",
1166
+ I("profile", "name") === "faded" && "opacity-50 pointer-events-none select-none"
1167
+ ),
1168
+ children: [
1169
+ /* @__PURE__ */ e(L, { htmlFor: "name", className: "px-1", children: a("profile.name", "First Name") }),
1170
+ /* @__PURE__ */ e(
1171
+ D,
1172
+ {
1173
+ id: "name",
1174
+ value: B,
1175
+ onChange: (l) => W(l.target.value),
1176
+ disabled: I("profile", "name") === "faded",
1177
+ className: y(
1178
+ "bg-muted/30 border-border/50 rounded-xl focus-visible:ring-primary h-11",
1179
+ "text-start"
1180
+ )
1181
+ }
1182
+ )
1183
+ ]
1184
+ }
1185
+ ),
1186
+ I("profile", "surname") !== "hidden" && /* @__PURE__ */ s(
1187
+ "div",
1188
+ {
1189
+ className: y(
1190
+ "flex flex-col gap-3",
1191
+ I("profile", "surname") === "faded" && "opacity-50 pointer-events-none select-none"
1192
+ ),
1193
+ children: [
1194
+ /* @__PURE__ */ e(L, { htmlFor: "surname", className: "px-1", children: a("profile.surname", "Last Name") }),
1195
+ /* @__PURE__ */ e(
1196
+ D,
1197
+ {
1198
+ id: "surname",
1199
+ value: ae,
1200
+ onChange: (l) => G(l.target.value),
1201
+ disabled: I("profile", "surname") === "faded",
1202
+ className: y(
1203
+ "bg-muted/30 border-border/50 rounded-xl focus-visible:ring-primary h-11",
1204
+ "text-start"
1205
+ )
1206
+ }
1207
+ )
1208
+ ]
1209
+ }
1210
+ )
1211
+ ] }),
1212
+ [
1213
+ { key: "username", icon: ta, value: X, set: E },
1214
+ { key: "email", icon: aa, value: le, set: ve },
1215
+ { key: "phone", icon: na, value: ce, set: xe }
1216
+ ].map(({ key: l, icon: C, value: S, set: me }) => {
1217
+ const Ie = I("profile", l);
1218
+ return Ie === "hidden" ? null : /* @__PURE__ */ s(
1219
+ "div",
1220
+ {
1221
+ className: y(
1222
+ "flex flex-col gap-3",
1223
+ Ie === "faded" && "opacity-50 pointer-events-none select-none"
1224
+ ),
1225
+ children: [
1226
+ /* @__PURE__ */ e(L, { htmlFor: l, className: "px-1 text-start", children: a(`profile.${l}`) }),
1227
+ /* @__PURE__ */ s("div", { className: "relative", children: [
1228
+ /* @__PURE__ */ e(C, { className: "absolute top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground start-3" }),
1229
+ /* @__PURE__ */ e(
1230
+ D,
1231
+ {
1232
+ id: l,
1233
+ type: l === "email" ? "email" : "text",
1234
+ value: S,
1235
+ onChange: (De) => me(
1236
+ l === "phone" ? De.target.value.replace(/[^0-9]/g, "") : De.target.value
1237
+ ),
1238
+ disabled: Ie === "faded",
1239
+ className: "bg-muted/30 border-border/50 rounded-xl focus-visible:ring-primary ps-10 pe-3 text-start",
1240
+ dir: "ltr"
1241
+ }
1242
+ )
1243
+ ] })
1244
+ ]
1245
+ },
1246
+ l
1247
+ );
1248
+ }),
1249
+ I("profile", "password") !== "hidden" && /* @__PURE__ */ s(
1250
+ "div",
1251
+ {
1252
+ className: y(
1253
+ "flex flex-col gap-3",
1254
+ I("profile", "password") === "faded" && "opacity-50 pointer-events-none select-none"
1255
+ ),
1256
+ children: [
1257
+ /* @__PURE__ */ e(L, { htmlFor: "pass", className: "px-1 text-start", children: a("profile.password", "New Password") }),
1258
+ /* @__PURE__ */ s("div", { className: "relative", children: [
1259
+ /* @__PURE__ */ e(ra, { className: "absolute top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground start-3" }),
1260
+ /* @__PURE__ */ e(
1261
+ D,
1262
+ {
1263
+ id: "pass",
1264
+ type: "password",
1265
+ value: H,
1266
+ onChange: (l) => z(l.target.value),
1267
+ disabled: I("profile", "password") === "faded",
1268
+ placeholder: a(
1269
+ "profile.password_placeholder",
1270
+ "Leave empty to keep current"
1271
+ ),
1272
+ className: "bg-muted/30 border-border/50 rounded-xl focus-visible:ring-primary ps-10 pe-3 text-start",
1273
+ dir: "ltr"
1274
+ }
1275
+ )
1276
+ ] })
1277
+ ]
1278
+ }
1279
+ ),
1280
+ U.map((l) => {
1281
+ const C = I("profile", l.key, l.mode || "editable");
1282
+ return C === "hidden" || !Te(l.condition, q) ? null : /* @__PURE__ */ s(
1283
+ "div",
1284
+ {
1285
+ className: y(
1286
+ "flex flex-col gap-3 animate-in fade-in slide-in-from-top-1 duration-200",
1287
+ C === "faded" && "opacity-50 pointer-events-none select-none"
1288
+ ),
1289
+ children: [
1290
+ /* @__PURE__ */ e(L, { htmlFor: `profile-${l.key}`, className: "px-1", children: a(l.label) }),
1291
+ l.type === "select" ? /* @__PURE__ */ s(
1292
+ we,
1293
+ {
1294
+ value: String(q[l.key] || ""),
1295
+ onValueChange: (S) => A({ ...q, [l.key]: S }),
1296
+ disabled: C === "faded",
1297
+ dir: de ? "rtl" : "ltr",
1298
+ children: [
1299
+ /* @__PURE__ */ e(Se, { className: "bg-muted/30 border-border/50 rounded-xl focus:ring-primary h-11", children: /* @__PURE__ */ e(
1300
+ ke,
1301
+ {
1302
+ placeholder: a(l.placeholder || "profile.select_placeholder")
1303
+ }
1304
+ ) }),
1305
+ /* @__PURE__ */ e(Ce, { className: "rounded-xl border-border/40 shadow-xl bg-background", children: l.options?.map((S) => /* @__PURE__ */ e(
1306
+ _e,
1307
+ {
1308
+ value: String(S.value),
1309
+ className: "rounded-lg focus:bg-primary/10",
1310
+ children: a(S.label)
1311
+ },
1312
+ String(S.value)
1313
+ )) })
1314
+ ]
1315
+ }
1316
+ ) : l.type === "checkbox" ? /* @__PURE__ */ s("div", { className: "flex items-center gap-3 px-1 py-1", children: [
1317
+ /* @__PURE__ */ e(
1318
+ "input",
1319
+ {
1320
+ id: `profile-${l.key}`,
1321
+ type: "checkbox",
1322
+ checked: !!q[l.key],
1323
+ disabled: C === "faded",
1324
+ onChange: (S) => A({ ...q, [l.key]: S.target.checked }),
1325
+ className: "h-5 w-5 rounded-md border-border/50 bg-muted/30 text-primary focus:ring-primary transition-all cursor-pointer"
1326
+ }
1327
+ ),
1328
+ /* @__PURE__ */ e(
1329
+ L,
1330
+ {
1331
+ htmlFor: `profile-${l.key}`,
1332
+ className: "text-sm font-medium text-muted-foreground cursor-pointer",
1333
+ children: a(l.placeholder || l.label)
1334
+ }
1335
+ )
1336
+ ] }) : /* @__PURE__ */ e(
1337
+ D,
1338
+ {
1339
+ id: `profile-${l.key}`,
1340
+ type: l.type,
1341
+ value: q[l.key] || "",
1342
+ disabled: C === "faded",
1343
+ onChange: (S) => A({ ...q, [l.key]: S.target.value }),
1344
+ placeholder: a(l.placeholder || ""),
1345
+ className: y(
1346
+ "bg-muted/30 border-border/50 rounded-xl focus-visible:ring-primary h-11",
1347
+ "text-start"
1348
+ )
1349
+ }
1350
+ )
1351
+ ]
1352
+ },
1353
+ l.key
1354
+ );
1355
+ }),
1356
+ /* @__PURE__ */ e("div", { className: "pt-4 flex justify-center", children: /* @__PURE__ */ s(
1357
+ $,
1358
+ {
1359
+ onClick: d,
1360
+ disabled: Y,
1361
+ className: "w-full sm:w-auto px-8 rounded-xl gap-2 font-semibold h-11 transition-all active:scale-[0.98]",
1362
+ children: [
1363
+ /* @__PURE__ */ e(sa, { className: "h-4 w-4" }),
1364
+ Y ? a("profile.saving", "Saving...") : a("profile.save", "Save Changes")
1365
+ ]
1366
+ }
1367
+ ) })
1368
+ ] })
1369
+ ] }),
1370
+ w === "general" && /* @__PURE__ */ s("div", { className: "space-y-6 animate-in fade-in slide-in-from-bottom-4 duration-300", children: [
1371
+ /* @__PURE__ */ s("div", { children: [
1372
+ /* @__PURE__ */ e("h2", { className: "text-xl font-bold tracking-tight", children: a("general.title") }),
1373
+ /* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground", children: a("general.subtitle") })
1374
+ ] }),
1375
+ /* @__PURE__ */ e(Dn, {})
1376
+ ] }),
1377
+ w === "account" && /* @__PURE__ */ s("div", { className: "space-y-8 animate-in fade-in slide-in-from-bottom-4 duration-300", children: [
1378
+ /* @__PURE__ */ s("div", { children: [
1379
+ /* @__PURE__ */ e("h2", { className: "text-xl font-bold tracking-tight", children: a("account.title", "Account & Usage") }),
1380
+ /* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground", children: a("account.subtitle", "Monitor your quotas and manage your session.") })
1381
+ ] }),
1382
+ /* @__PURE__ */ s("div", { className: "space-y-6", children: [
1383
+ J !== "hidden" && h && /* @__PURE__ */ s(
1384
+ "div",
1385
+ {
1386
+ className: y(
1387
+ "p-6 bg-muted/30 rounded-3xl border border-border/40 space-y-5",
1388
+ J === "faded" && "opacity-50"
1389
+ ),
1390
+ children: [
1391
+ /* @__PURE__ */ s("div", { className: "flex items-start justify-between gap-3", children: [
1392
+ /* @__PURE__ */ s(L, { className: "text-xs font-bold uppercase tracking-wider text-primary flex items-center gap-2", children: [
1393
+ h.kind === "credits" ? /* @__PURE__ */ e(ia, { className: "h-4 w-4" }) : h.kind === "unlimited" ? /* @__PURE__ */ e(oa, { className: "h-4 w-4" }) : /* @__PURE__ */ e(la, { className: "h-4 w-4" }),
1394
+ a("account.usage", "Your usage")
1395
+ ] }),
1396
+ /* @__PURE__ */ s("div", { className: "text-end", children: [
1397
+ /* @__PURE__ */ e("p", { className: "text-sm font-semibold text-foreground", children: h.kind === "credits" ? a("account.on_credits", "Credits") : h.kind === "unlimited" ? a("account.unlimited", "No usage limits") : h.plan?.name ?? a("account.custom_plan", "Custom plan") }),
1398
+ h.ends_at && /* @__PURE__ */ e("p", { className: "text-xs text-muted-foreground", children: a("account.plan_until", {
1399
+ datetime: ht(h.ends_at, n.language)
1400
+ }) })
1401
+ ] })
1402
+ ] }),
1403
+ h.kind === "plan" && (h.windows.length > 0 ? /* @__PURE__ */ e(Rn, { windows: h.windows }) : /* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground", children: a("account.unlimited", "No usage limits") })),
1404
+ h.kind === "credits" && h.credits && /* @__PURE__ */ e(An, { credits: h.credits }),
1405
+ h.kind === "unlimited" && /* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground", children: a(
1406
+ "account.unlimited_help",
1407
+ "You can use the assistant as much as you like."
1408
+ ) })
1409
+ ]
1410
+ }
1411
+ ),
1412
+ /* @__PURE__ */ e("div", { className: "pt-2 flex flex-col gap-3", children: I("account", "logout") !== "hidden" && /* @__PURE__ */ s(
1413
+ $,
1414
+ {
1415
+ variant: "destructive",
1416
+ onClick: () => {
1417
+ x();
1418
+ },
1419
+ disabled: I("account", "logout") === "faded",
1420
+ className: y(
1421
+ "rounded-2xl gap-2 font-bold h-12 transition-all active:scale-[0.98]",
1422
+ I("account", "logout") === "faded" && "opacity-50 pointer-events-none"
1423
+ ),
1424
+ children: [
1425
+ /* @__PURE__ */ e(ca, { className: "h-4 w-4" }),
1426
+ a("account.logout", "Logout from Account")
1427
+ ]
1428
+ }
1429
+ ) })
1430
+ ] })
1431
+ ] })
1432
+ ] }) }),
1433
+ r?.showVersionInSettings !== !1 && r?.version && /* @__PURE__ */ e("div", { className: "shrink-0 border-t border-border/30 px-5 sm:px-8 py-3 flex justify-center bg-background/80 opacity-70", children: /* @__PURE__ */ e("p", { className: "text-xs text-muted-foreground text-center", dir: "ltr", children: /* @__PURE__ */ s("span", { className: "font-mono text-foreground/75", children: [
1434
+ "v",
1435
+ r.version
1436
+ ] }) }) })
1437
+ ] })
1438
+ }
1439
+ )
1440
+ ] });
1441
+ }
1442
+ function kt({ hideActions: t = !1 }) {
1443
+ const a = Je(), { t: n } = _(["sidebar", "settings"]), r = K((k) => k.app), o = te((k) => k.history), i = te((k) => k.headerActionsEnabled), { HeaderActions: m, headerActions: u, UsageMeter: g } = oe(), c = O(
1444
+ () => (u ?? []).filter(
1445
+ (k) => i?.[k.id] ?? k.defaultEnabled ?? !0
1446
+ ),
1447
+ [u, i]
1448
+ ), h = ot(), { resolvedTheme: p } = ie(), f = !t && (o?.enabled ?? !0), v = O(() => r?.logo ? typeof r.logo == "string" ? r.logo : p === "dark" ? r.logo.dark : r.logo.light : Fa, [r?.logo, p]), b = r?.name || "Gentiq";
1449
+ return /* @__PURE__ */ s("header", { className: "relative flex items-center justify-between px-3 md:px-4 h-14 sticky top-0 z-40 w-full bg-background border-b border-border/30 transition-all duration-300", children: [
1450
+ /* @__PURE__ */ s("div", { className: "flex items-center gap-1.5 md:gap-2 min-w-[36px] md:min-w-[80px]", children: [
1451
+ f && /* @__PURE__ */ e(Pn, { className: "hover:bg-accent/60 transition-all duration-200 active:scale-95 rounded-lg size-9" }),
1452
+ !t && /* @__PURE__ */ s(ct, { children: [
1453
+ /* @__PURE__ */ e(dt, { asChild: !0, children: /* @__PURE__ */ e(
1454
+ "button",
1455
+ {
1456
+ type: "button",
1457
+ className: y(
1458
+ "flex items-center justify-center size-9 rounded-lg hover:bg-accent/60 transition-all duration-200 active:scale-95 text-muted-foreground hover:text-primary",
1459
+ f && "md:hidden"
1460
+ ),
1461
+ onClick: () => a?.selectThread(null),
1462
+ "aria-label": n("new_chat"),
1463
+ children: /* @__PURE__ */ e(nt, { className: "size-5" })
1464
+ }
1465
+ ) }),
1466
+ /* @__PURE__ */ e(ut, { side: "bottom", className: "text-xs", children: n("new_chat") })
1467
+ ] })
1468
+ ] }),
1469
+ /* @__PURE__ */ e("div", { className: "absolute inset-0 m-auto size-fit", children: /* @__PURE__ */ e("div", { className: "flex items-center gap-2.5 select-none animate-in fade-in zoom-in-95 duration-500", children: /* @__PURE__ */ e("img", { src: v, alt: b, className: "size-8 object-contain" }) }) }),
1470
+ /* @__PURE__ */ e("div", { className: "flex items-center gap-1.5 min-w-[36px] md:min-w-[80px] justify-end", children: !t && /* @__PURE__ */ s(fe, { children: [
1471
+ m && /* @__PURE__ */ e(m, { isMobile: h }),
1472
+ c.map(({ id: k, component: T }) => /* @__PURE__ */ e(T, { isMobile: h }, k)),
1473
+ r?.showUsageBar && /* @__PURE__ */ e(g, { details: r.showUsageDetails ?? !0, isMobile: h }),
1474
+ r?.showSettings !== !1 && /* @__PURE__ */ e(
1475
+ On,
1476
+ {
1477
+ trigger: /* @__PURE__ */ e(
1478
+ "button",
1479
+ {
1480
+ type: "button",
1481
+ "aria-label": n("settings:title"),
1482
+ className: "flex items-center justify-center size-9 rounded-lg hover:bg-accent/60 transition-all duration-200 active:scale-95 text-muted-foreground hover:text-primary",
1483
+ children: /* @__PURE__ */ e(Pe, { className: "size-5" })
1484
+ }
1485
+ )
1486
+ }
1487
+ )
1488
+ ] }) })
1489
+ ] });
1490
+ }
1491
+ function $n(t) {
1492
+ return /* @__PURE__ */ e(Q, { children: /* @__PURE__ */ e(Un, { ...t }) });
1493
+ }
1494
+ function Un({ shareId: t }) {
1495
+ const [a, n] = N(
1496
+ null
1497
+ ), [r, o] = N(!0), [i, m] = N(null), { t: u } = _(["chat", "errors"]), { MessageList: g } = oe(), c = Re(), h = Ee(/* @__PURE__ */ new Set());
1498
+ return F(() => () => {
1499
+ h.current.forEach((p) => URL.revokeObjectURL(p)), h.current.clear();
1500
+ }, []), F(() => {
1501
+ if (!t) return;
1502
+ let p = !1;
1503
+ return (async () => {
1504
+ try {
1505
+ o(!0);
1506
+ const v = await c.getSharedThread(t), b = await Za(
1507
+ Ja(v.items),
1508
+ async (k) => {
1509
+ try {
1510
+ const T = await c.getPublicAttachmentBlobUrl(t, k);
1511
+ return h.current.add(T), T;
1512
+ } catch (T) {
1513
+ return console.error("Failed to resolve shared attachment:", k, T), "";
1514
+ }
1515
+ }
1516
+ );
1517
+ p || n({ id: v.id, messages: b });
1518
+ } catch (v) {
1519
+ if (p) return;
1520
+ console.error("Failed to fetch shared chat:", v), m(v);
1521
+ } finally {
1522
+ p || o(!1);
1523
+ }
1524
+ })(), () => {
1525
+ p = !0;
1526
+ };
1527
+ }, [t, c]), r ? /* @__PURE__ */ e("div", { className: "flex h-dvh items-center justify-center bg-background", children: /* @__PURE__ */ e(Da, {}) }) : a ? /* @__PURE__ */ s("div", { className: "relative flex flex-col h-dvh overflow-hidden bg-background", children: [
1528
+ /* @__PURE__ */ e(kt, { hideActions: !0 }),
1529
+ /* @__PURE__ */ e("div", { className: "flex-1 min-h-0 overflow-hidden relative flex flex-col", children: /* @__PURE__ */ e(ze.Root, { readonly: !0, children: /* @__PURE__ */ e(tt.Root, { messages: a.messages, className: "flex min-h-0 flex-1 flex-col", children: /* @__PURE__ */ e(g, { className: "pb-8" }) }) }) })
1530
+ ] }) : /* @__PURE__ */ s("div", { className: "flex h-dvh flex-col items-center justify-center p-4 text-center bg-background", children: [
1531
+ /* @__PURE__ */ e("h1", { className: "text-2xl font-bold text-destructive mb-2 font-display", children: u("shared_not_found_title") }),
1532
+ /* @__PURE__ */ e("p", { className: "text-muted-foreground max-w-md", children: Ya(i) ? se(i, u) : u("shared_not_found_description") })
1533
+ ] });
1534
+ }
1535
+ function jn() {
1536
+ const { t } = _("sidebar"), { isMobile: a, setOpenMobile: n } = be();
1537
+ return /* @__PURE__ */ e(yt, { className: "mt-2 mb-6 px-2 group-data-[collapsible=icon]:px-0", children: /* @__PURE__ */ e(Nt, { className: "group-data-[collapsible=icon]:flex group-data-[collapsible=icon]:justify-center", children: /* @__PURE__ */ e(
1538
+ wt,
1539
+ {
1540
+ asChild: !0,
1541
+ tooltip: t("tooltip_new_conversation"),
1542
+ className: "h-10 rounded-xl bg-surface border border-border/60 shadow-sm shadow-foreground/[0.03] text-foreground/85 hover:bg-surface hover:border-border hover:text-foreground active:bg-surface transition-[width,height,padding,border-color,color] duration-200 group-data-[collapsible=icon]:mx-auto group/new-chat",
1543
+ children: /* @__PURE__ */ s(
1544
+ j.New,
1545
+ {
1546
+ onOpen: () => a && n(!1),
1547
+ className: "flex items-center gap-2.5 px-3 group-data-[collapsible=icon]:justify-center",
1548
+ children: [
1549
+ /* @__PURE__ */ e(
1550
+ nt,
1551
+ {
1552
+ "aria-hidden": !0,
1553
+ className: "size-4! shrink-0 text-muted-foreground transition-colors group-hover/new-chat:text-foreground"
1554
+ }
1555
+ ),
1556
+ /* @__PURE__ */ e("span", { className: "text-sm font-medium group-data-[collapsible=icon]:hidden", children: t("new_conversation") })
1557
+ ]
1558
+ }
1559
+ )
1560
+ }
1561
+ ) }) });
1562
+ }
1563
+ function Bn() {
1564
+ const { t } = _("sidebar");
1565
+ return /* @__PURE__ */ e(j.LoadMore, { className: "group/more min-h-4 w-full", children: /* @__PURE__ */ s(
1566
+ "div",
1567
+ {
1568
+ role: "status",
1569
+ className: "hidden group-data-[loading]/more:flex flex-col items-center gap-2 p-4 pt-0 opacity-60",
1570
+ children: [
1571
+ /* @__PURE__ */ e(
1572
+ "div",
1573
+ {
1574
+ "aria-hidden": !0,
1575
+ className: "size-4 border-2 border-primary border-t-transparent rounded-full animate-spin motion-reduce:animate-none"
1576
+ }
1577
+ ),
1578
+ /* @__PURE__ */ e("span", { className: "text-xs uppercase tracking-wider font-medium", children: t("loading_more") })
1579
+ ]
1580
+ }
1581
+ ) });
1582
+ }
1583
+ function Gn() {
1584
+ const { t } = _("sidebar");
1585
+ return /* @__PURE__ */ s(
1586
+ ye.Root,
1587
+ {
1588
+ onRenamed: () => P.success(t("rename_success")),
1589
+ onRenameFailed: () => P.error(t("rename_failed")),
1590
+ className: "flex items-center gap-1 px-2 py-1.5 w-full",
1591
+ children: [
1592
+ /* @__PURE__ */ e(
1593
+ ye.Input,
1594
+ {
1595
+ "aria-label": t("rename_label"),
1596
+ className: "h-8 min-w-0 flex-1 rounded-md border border-input bg-transparent px-2 text-sm outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50"
1597
+ }
1598
+ ),
1599
+ /* @__PURE__ */ e(ye.Save, { asChild: !0, children: /* @__PURE__ */ e(
1600
+ $,
1601
+ {
1602
+ type: "submit",
1603
+ size: "icon",
1604
+ variant: "ghost",
1605
+ "aria-label": t("save"),
1606
+ className: "size-8 shrink-0 text-primary hover:bg-primary/10",
1607
+ children: /* @__PURE__ */ e(da, { "aria-hidden": !0, className: "size-4" })
1608
+ }
1609
+ ) }),
1610
+ /* @__PURE__ */ e(ye.Cancel, { asChild: !0, children: /* @__PURE__ */ e(
1611
+ $,
1612
+ {
1613
+ type: "button",
1614
+ size: "icon",
1615
+ variant: "ghost",
1616
+ "aria-label": t("cancel"),
1617
+ className: "size-8 shrink-0 text-destructive hover:bg-destructive/10",
1618
+ children: /* @__PURE__ */ e(ua, { "aria-hidden": !0, className: "size-4" })
1619
+ }
1620
+ ) })
1621
+ ]
1622
+ }
1623
+ );
1624
+ }
1625
+ function Hn({ open: t, onOpenChange: a }) {
1626
+ const { t: n } = _(["sidebar", "errors"]), { remove: r } = Ae(), o = async () => {
1627
+ a(!1);
1628
+ try {
1629
+ await r();
1630
+ } catch {
1631
+ P.error(n("errors:thread_delete_failed"));
1632
+ return;
1633
+ }
1634
+ P.success(n("chat_deleted_success"));
1635
+ };
1636
+ return /* @__PURE__ */ e(gt, { open: t, onOpenChange: a, children: /* @__PURE__ */ s(pt, { children: [
1637
+ /* @__PURE__ */ s(Oa, { children: [
1638
+ /* @__PURE__ */ e($a, { children: n("delete_confirm_title") }),
1639
+ /* @__PURE__ */ e(Ua, { children: n("delete_confirm_description") })
1640
+ ] }),
1641
+ /* @__PURE__ */ s(ja, { children: [
1642
+ /* @__PURE__ */ e($, { variant: "outline", onClick: () => a(!1), children: n("cancel") }),
1643
+ /* @__PURE__ */ e($, { variant: "destructive", onClick: () => {
1644
+ o();
1645
+ }, autoFocus: !0, children: n("delete") })
1646
+ ] })
1647
+ ] }) });
1648
+ }
1649
+ const Ct = Lt({
1650
+ pin: !0,
1651
+ share: !0,
1652
+ rename: !0,
1653
+ delete: !0
1654
+ }), ge = "cursor-pointer flex items-center gap-2";
1655
+ function Vn() {
1656
+ const { t } = _("sidebar"), { dir: a } = ee(), n = Xe(Ct), { thread: r, setPinned: o, share: i, unshare: m, startRenaming: u } = Ae(), [g, c] = N(!1);
1657
+ if (!n.pin && !n.share && !n.rename && !n.delete) return null;
1658
+ const h = async () => {
1659
+ try {
1660
+ await o(!r.pinned), P.success(r.pinned ? t("unpinned_success") : t("pinned_success"));
1661
+ } catch {
1662
+ P.error(t("pin_failed"));
1663
+ }
1664
+ }, p = async () => {
1665
+ try {
1666
+ const v = await i();
1667
+ await navigator.clipboard.writeText(`${window.location.origin}${v}`), P.success(t("share_success"), { description: t("share_description") });
1668
+ } catch {
1669
+ P.error(t("share_failed"));
1670
+ }
1671
+ }, f = async () => {
1672
+ try {
1673
+ await m(), P.success(t("unshare_success"));
1674
+ } catch {
1675
+ P.error(t("unshare_failed"));
1676
+ }
1677
+ };
1678
+ return /* @__PURE__ */ s(fe, { children: [
1679
+ /* @__PURE__ */ s(Ba, { dir: a, children: [
1680
+ /* @__PURE__ */ e(Ga, { asChild: !0, children: /* @__PURE__ */ e(
1681
+ $,
1682
+ {
1683
+ variant: "ghost",
1684
+ size: "icon",
1685
+ "aria-label": t("thread_actions", { title: r.title ?? t("new_conversation") }),
1686
+ className: "size-7 rounded-full opacity-100 md:opacity-0 md:group-hover/sidebar-menu-item:opacity-100 md:group-focus-within/sidebar-menu-item:opacity-100 focus-visible:opacity-100 hover:bg-accent hover:text-accent-foreground data-[state=open]:opacity-100 transition-all",
1687
+ children: /* @__PURE__ */ e(ma, { "aria-hidden": !0, className: "size-3.5" })
1688
+ }
1689
+ ) }),
1690
+ /* @__PURE__ */ s(Ha, { align: "end", className: "min-w-[120px] p-1", children: [
1691
+ n.pin && /* @__PURE__ */ s(he, { onSelect: () => {
1692
+ h();
1693
+ }, className: ge, children: [
1694
+ r.pinned ? /* @__PURE__ */ e(ha, { "aria-hidden": !0, className: "size-4" }) : /* @__PURE__ */ e(rt, { "aria-hidden": !0, className: "size-4" }),
1695
+ /* @__PURE__ */ e("span", { children: r.pinned ? t("unpin_conversation") : t("pin_conversation") })
1696
+ ] }),
1697
+ n.share && /* @__PURE__ */ s(he, { onSelect: () => {
1698
+ p();
1699
+ }, className: ge, children: [
1700
+ /* @__PURE__ */ e(ga, { "aria-hidden": !0, className: "size-4" }),
1701
+ /* @__PURE__ */ e("span", { children: t("share_conversation") })
1702
+ ] }),
1703
+ n.share && r.shared && /* @__PURE__ */ s(he, { onSelect: () => {
1704
+ f();
1705
+ }, className: ge, children: [
1706
+ /* @__PURE__ */ e(pa, { "aria-hidden": !0, className: "size-4" }),
1707
+ /* @__PURE__ */ e("span", { children: t("stop_sharing") })
1708
+ ] }),
1709
+ n.rename && /* @__PURE__ */ s(he, { onSelect: u, className: ge, children: [
1710
+ /* @__PURE__ */ e(fa, { "aria-hidden": !0, className: "size-4" }),
1711
+ /* @__PURE__ */ e("span", { children: t("rename_conversation") })
1712
+ ] }),
1713
+ n.delete && /* @__PURE__ */ s(
1714
+ he,
1715
+ {
1716
+ onSelect: () => c(!0),
1717
+ className: `${ge} text-destructive focus:text-destructive focus:bg-destructive/10`,
1718
+ children: [
1719
+ /* @__PURE__ */ e(ba, { "aria-hidden": !0, className: "size-4" }),
1720
+ /* @__PURE__ */ e("span", { children: t("delete_conversation") })
1721
+ ]
1722
+ }
1723
+ )
1724
+ ] })
1725
+ ] }),
1726
+ n.delete && /* @__PURE__ */ e(Hn, { open: g, onOpenChange: c })
1727
+ ] });
1728
+ }
1729
+ function Kn() {
1730
+ const { t } = _("sidebar"), { isMobile: a, setOpenMobile: n } = be(), { thread: r, isRenaming: o } = Ae();
1731
+ return /* @__PURE__ */ e(j.Item, { asChild: !0, children: /* @__PURE__ */ e(Nt, { className: "group/sidebar-menu-item relative", children: o ? /* @__PURE__ */ e(Gn, {}) : /* @__PURE__ */ s(fe, { children: [
1732
+ /* @__PURE__ */ e(
1733
+ wt,
1734
+ {
1735
+ asChild: !0,
1736
+ className: "h-auto py-2.5 px-3 opacity-70 hover:opacity-100 aria-[current=page]:bg-accent aria-[current=page]:opacity-100 aria-busy:thread-streaming",
1737
+ children: /* @__PURE__ */ s(
1738
+ j.ItemTrigger,
1739
+ {
1740
+ onOpen: () => a && n(!1),
1741
+ className: "flex flex-col items-start gap-0.5 w-full overflow-hidden pe-16",
1742
+ children: [
1743
+ /* @__PURE__ */ e(
1744
+ j.ItemTitle,
1745
+ {
1746
+ fallback: t("new_conversation"),
1747
+ className: "truncate w-full text-start font-medium text-sm"
1748
+ }
1749
+ ),
1750
+ /* @__PURE__ */ e(j.ItemTime, { className: "w-full text-start text-xs opacity-60" })
1751
+ ]
1752
+ }
1753
+ )
1754
+ }
1755
+ ),
1756
+ /* @__PURE__ */ s("div", { className: "absolute top-1/2 -translate-y-1/2 end-1.5 flex items-center gap-1 z-10", children: [
1757
+ r.pinned && /* @__PURE__ */ s("span", { className: "md:absolute md:inset-0 md:m-auto md:size-3.5 md:group-hover/sidebar-menu-item:opacity-0 md:group-focus-within/sidebar-menu-item:opacity-0 transition-opacity pointer-events-none", children: [
1758
+ /* @__PURE__ */ e(rt, { "aria-hidden": !0, className: "size-3.5 text-primary opacity-70" }),
1759
+ /* @__PURE__ */ e("span", { className: "sr-only", children: t("pinned") })
1760
+ ] }),
1761
+ /* @__PURE__ */ e(Vn, {})
1762
+ ] })
1763
+ ] }) }) });
1764
+ }
1765
+ function Qn() {
1766
+ const { t } = _("sidebar");
1767
+ return /* @__PURE__ */ s("div", { className: "relative group/search", children: [
1768
+ /* @__PURE__ */ e(
1769
+ va,
1770
+ {
1771
+ "aria-hidden": !0,
1772
+ className: "absolute start-3 top-1/2 -translate-y-1/2 size-4 opacity-40 group-focus-within/search:opacity-70 transition-opacity"
1773
+ }
1774
+ ),
1775
+ /* @__PURE__ */ e(
1776
+ j.Search,
1777
+ {
1778
+ "aria-label": t("search_conversations"),
1779
+ placeholder: t("search_conversations"),
1780
+ className: "flex w-full min-w-0 ps-9 pe-3 h-10 text-base md:text-sm bg-accent/15 border border-border/40 rounded-xl outline-none transition-all placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-primary/20 [&::-webkit-search-cancel-button]:appearance-none"
1781
+ }
1782
+ )
1783
+ ] });
1784
+ }
1785
+ function Wn({ side: t = "start" }) {
1786
+ const { t: a } = _("sidebar"), n = te((g) => g.history), { showPin: r, showShare: o, showRename: i, showDelete: m } = n, u = O(
1787
+ () => ({ pin: r, share: o, rename: i, delete: m }),
1788
+ [r, o, i, m]
1789
+ );
1790
+ return /* @__PURE__ */ e(lt, { children: /* @__PURE__ */ e(Ln, { collapsible: "icon", side: t, children: /* @__PURE__ */ e(Mn, { className: "custom-scrollbar", children: /* @__PURE__ */ s(En, { children: [
1791
+ /* @__PURE__ */ e(jn, {}),
1792
+ n.enabled && /* @__PURE__ */ s(j.Root, { className: "group-data-[collapsible=icon]:hidden", children: [
1793
+ /* @__PURE__ */ e(He, { className: "mb-6 px-2", children: /* @__PURE__ */ e(Qn, {}) }),
1794
+ /* @__PURE__ */ s(He, { children: [
1795
+ /* @__PURE__ */ e(yt, { children: /* @__PURE__ */ e(Ct.Provider, { value: u, children: /* @__PURE__ */ e(j.Items, { component: Kn }) }) }),
1796
+ /* @__PURE__ */ e(j.Empty, { className: "px-4 py-8 text-center text-sm opacity-60", children: a("no_conversations") }),
1797
+ /* @__PURE__ */ e(Bn, {})
1798
+ ] })
1799
+ ] })
1800
+ ] }) }) }) });
1801
+ }
1802
+ function Xn({ components: t, disclaimer: a, welcome: n, ...r }) {
1803
+ return /* @__PURE__ */ e(Fe, { components: t, disclaimer: a, welcome: n, children: /* @__PURE__ */ e(Yn, { ...r }) });
1804
+ }
1805
+ function Yn({
1806
+ threadId: t,
1807
+ onThreadChange: a,
1808
+ getThreadHref: n,
1809
+ getShareHref: r,
1810
+ sidebar: o,
1811
+ header: i,
1812
+ classNames: m
1813
+ }) {
1814
+ const u = te((f) => f.history.enabled), { MaintenanceBanner: g, MaintenanceScreen: c } = oe(), h = jt(), p = h.isUnderMaintenance && h.status ? {
1815
+ status: h.status,
1816
+ title: h.title,
1817
+ message: h.message,
1818
+ endsAt: h.endsAt,
1819
+ blocksChat: h.blocksChat,
1820
+ refresh: h.refresh
1821
+ } : null;
1822
+ return p && h.display === "fullscreen" && c ? /* @__PURE__ */ e(Q, { children: /* @__PURE__ */ e(c, { ...p }) }) : /* @__PURE__ */ e(Q, { children: /* @__PURE__ */ e(
1823
+ et,
1824
+ {
1825
+ threadId: t,
1826
+ onThreadChange: a,
1827
+ getThreadHref: n,
1828
+ getShareHref: r,
1829
+ children: /* @__PURE__ */ s(qn, { defaultOpen: u, className: "bg-background", children: [
1830
+ o !== void 0 ? o : u ? /* @__PURE__ */ e(Wn, {}) : null,
1831
+ /* @__PURE__ */ s("div", { className: "flex flex-col flex-1 h-dvh overflow-hidden relative", children: [
1832
+ i !== void 0 ? i : /* @__PURE__ */ e(kt, {}),
1833
+ p && g && /* @__PURE__ */ e(g, { ...p }),
1834
+ /* @__PURE__ */ e("div", { className: "flex flex-col relative w-full flex-1 min-h-0 overflow-hidden", children: /* @__PURE__ */ e(mn, { classNames: m }) })
1835
+ ] })
1836
+ ] })
1837
+ }
1838
+ ) });
1839
+ }
1840
+ const pe = /* @__PURE__ */ new Set();
1841
+ let ne = null;
1842
+ function Me() {
1843
+ for (const t of pe) t();
1844
+ }
1845
+ function Zn(t) {
1846
+ return pe.size === 0 && window.addEventListener("popstate", Me), pe.add(t), () => {
1847
+ pe.delete(t), pe.size === 0 && window.removeEventListener("popstate", Me);
1848
+ };
1849
+ }
1850
+ function Jn() {
1851
+ const { pathname: t, search: a, hash: n } = window.location, r = window.history.state;
1852
+ return (ne?.pathname !== t || ne.search !== a || ne.hash !== n || ne.state !== r) && (ne = { pathname: t, search: a, hash: n, state: r }), ne;
1853
+ }
1854
+ const er = () => null;
1855
+ function tr() {
1856
+ return Pt(Zn, Jn, er);
1857
+ }
1858
+ function Ne(t, { replace: a = !1, state: n = null } = {}) {
1859
+ a ? window.history.replaceState(n, "", t) : window.history.pushState(n, "", t), Me();
1860
+ }
1861
+ const ar = {
1862
+ chat: "/chat",
1863
+ login: "/login",
1864
+ shared: "/shared",
1865
+ admin: "/admin"
1866
+ };
1867
+ function re(t) {
1868
+ const a = t.replace(/^\/+|\/+$/g, "");
1869
+ return a ? `/${a}` : "";
1870
+ }
1871
+ function nr(t, a = {}) {
1872
+ const n = re(t), r = { ...ar, ...a };
1873
+ return {
1874
+ chat: n + re(r.chat),
1875
+ login: n + re(r.login),
1876
+ shared: n + re(r.shared),
1877
+ admin: n + re(r.admin)
1878
+ };
1879
+ }
1880
+ function We(t, a) {
1881
+ if (t !== a && !t.startsWith(`${a}/`)) return;
1882
+ const n = t.slice(a.length).replace(/^\/+|\/+$/g, "");
1883
+ if (!n) return null;
1884
+ if (!n.includes("/"))
1885
+ try {
1886
+ return decodeURIComponent(n);
1887
+ } catch {
1888
+ return;
1889
+ }
1890
+ }
1891
+ function rr(t, a) {
1892
+ const n = re(t);
1893
+ if (n === a.admin || n.startsWith(`${a.admin}/`)) return { name: "admin" };
1894
+ if (n === a.login) return { name: "login" };
1895
+ const r = We(n, a.shared);
1896
+ return r ? { name: "shared", shareId: r } : { name: "chat", threadId: We(n, a.chat) ?? null };
1897
+ }
1898
+ function qe(t, a) {
1899
+ return t === null ? a.chat || "/" : `${a.chat}/${encodeURIComponent(t)}`;
1900
+ }
1901
+ function Nr({
1902
+ url: t,
1903
+ api: a,
1904
+ basePath: n = "/",
1905
+ paths: r,
1906
+ admin: o,
1907
+ components: i,
1908
+ history: m,
1909
+ welcome: u,
1910
+ threadActions: g,
1911
+ composer: c,
1912
+ disclaimer: h,
1913
+ settings: p,
1914
+ ...f
1915
+ }) {
1916
+ const v = tr();
1917
+ return v ? /* @__PURE__ */ s(vn, { ...f, api: { ...a, basePath: t }, children: [
1918
+ /* @__PURE__ */ e(xn, {}),
1919
+ /* @__PURE__ */ e(
1920
+ Fe,
1921
+ {
1922
+ components: i,
1923
+ history: m,
1924
+ welcome: u,
1925
+ threadActions: g,
1926
+ composer: c,
1927
+ disclaimer: h,
1928
+ settings: p,
1929
+ children: /* @__PURE__ */ e(sr, { location: v, paths: nr(n, r), admin: o })
1930
+ }
1931
+ )
1932
+ ] }) : null;
1933
+ }
1934
+ function sr({ location: t, paths: a, admin: n }) {
1935
+ const r = rr(t.pathname, a), o = qe(null, a);
1936
+ if (r.name === "admin" && n) return /* @__PURE__ */ e(Mt, { fallback: null, children: n });
1937
+ if (r.name === "login") {
1938
+ const { reason: c, from: h } = lr(t.state);
1939
+ return /* @__PURE__ */ e(Nn, { reason: c, onSignedIn: () => Ne(h ?? o, { replace: !0 }) });
1940
+ }
1941
+ if (r.name === "shared") return /* @__PURE__ */ e($n, { shareId: r.shareId });
1942
+ const i = r.name === "chat" ? r.threadId : null, m = new URLSearchParams(t.search), u = m.get("code");
1943
+ return /* @__PURE__ */ e(
1944
+ yn,
1945
+ {
1946
+ loginCode: u,
1947
+ onLoginCodeUsed: () => {
1948
+ m.delete("code");
1949
+ const c = m.toString();
1950
+ Ne(t.pathname + (c ? `?${c}` : "") + t.hash, { replace: !0 });
1951
+ },
1952
+ fallback: (c) => /* @__PURE__ */ e(cr, { to: a.login, reason: c, from: t.pathname + t.search }),
1953
+ children: /* @__PURE__ */ e(
1954
+ Xn,
1955
+ {
1956
+ threadId: i,
1957
+ onThreadChange: (c) => Ne(qe(c, a)),
1958
+ getThreadHref: (c) => qe(c, a),
1959
+ getShareHref: (c) => `${a.shared}/${encodeURIComponent(c)}`
1960
+ }
1961
+ )
1962
+ }
1963
+ );
1964
+ }
1965
+ const ir = [
1966
+ "signed_out",
1967
+ "session_expired",
1968
+ "handoff_failed"
1969
+ ];
1970
+ function or(t) {
1971
+ return typeof t == "string" && ir.includes(t);
1972
+ }
1973
+ function lr(t) {
1974
+ if (typeof t != "object" || t === null) return {};
1975
+ const { reason: a, from: n } = t;
1976
+ return {
1977
+ reason: or(a) ? a : void 0,
1978
+ // Only a path on this site: a full URL here would make the sign-in page an open redirect.
1979
+ from: typeof n == "string" && n.startsWith("/") && !n.startsWith("//") ? n : void 0
1980
+ };
1981
+ }
1982
+ function cr({ to: t, reason: a, from: n }) {
1983
+ return F(() => {
1984
+ Ne(t, { replace: !0, state: { reason: a, from: n } });
1985
+ }, [t, a, n]), null;
1986
+ }
1987
+ export {
1988
+ Wn as AppSidebar,
1989
+ mn as Chat,
1990
+ kr as ChatError,
1991
+ Xn as ChatLayout,
1992
+ Cr as ChoiceQuestionDock,
1993
+ _r as ChoiceQuestionPart,
1994
+ Ca as ChoiceQuestionProvider,
1995
+ An as CreditsBar,
1996
+ xn as DocumentSync,
1997
+ Tr as FilePart,
1998
+ Ir as FollowUpSuggestions,
1999
+ Nr as GentiqChatApp,
2000
+ vn as GentiqProvider,
2001
+ Q as GentiqRoot,
2002
+ Fe as GentiqUI,
2003
+ qr as MaintenanceBanner,
2004
+ Lr as MaintenanceScreen,
2005
+ Pr as MessageActions,
2006
+ Mr as MessageList,
2007
+ Er as PromptInputArea,
2008
+ zr as PromptInputButton,
2009
+ St as QuotaBar,
2010
+ Rn as QuotaWindows,
2011
+ Rr as ReasoningPart,
2012
+ Ar as ReferencePart,
2013
+ xa as Referenceable,
2014
+ yn as RequireAuth,
2015
+ On as SettingsDialog,
2016
+ $n as SharedChatView,
2017
+ qn as SidebarProvider,
2018
+ Fr as Suggestion,
2019
+ Dr as Suggestions,
2020
+ Or as TextPart,
2021
+ $r as ToolPart,
2022
+ ct as Tooltip,
2023
+ ut as TooltipContent,
2024
+ dt as TooltipTrigger,
2025
+ Ur as UsageMeter,
2026
+ Nn as UserLoginPage,
2027
+ jr as WelcomeScreen,
2028
+ Br as useChoiceQuestion,
2029
+ te as useGentiqUIOptions,
2030
+ Gr as useSmoothStreamingConfig,
2031
+ Hr as useSmoothText
2032
+ };