@lambda-development/erp-core 0.1.9 → 0.1.10

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/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { jsx as e, jsxs as r, Fragment as Ne } from "react/jsx-runtime";
2
- import { useState as N, useEffect as re, useCallback as we, useContext as In, createContext as Ln, useRef as H, useMemo as Ce, useLayoutEffect as tn, StrictMode as sa } from "react";
2
+ import { useState as S, useEffect as se, useCallback as we, useContext as In, createContext as Ln, useRef as H, useMemo as Ce, useLayoutEffect as tn, StrictMode as sa } from "react";
3
3
  import { createRoot as ia } from "react-dom/client";
4
- import { useQueryClient as We, useQuery as ie, useMutation as me, QueryClientProvider as la, QueryClient as oa } from "@tanstack/react-query";
4
+ import { useQueryClient as We, useQuery as le, useMutation as pe, QueryClientProvider as la, QueryClient as oa } from "@tanstack/react-query";
5
5
  import { NavLink as kt, useLocation as dt, useNavigate as Oe, Outlet as ca, Navigate as da, Link as ye, useSearchParams as wt, useParams as ut, createBrowserRouter as ua, RouterProvider as ma } from "react-router-dom";
6
6
  import { useTranslation as Z, initReactI18next as pa } from "react-i18next";
7
7
  import { BookOpen as ha, ShoppingCart as Bn, CreditCard as ga, FileText as jt, Package as En, BarChart3 as ya, Database as fa, Settings as ba, MessageCircle as xa, ChevronDown as Wt, ChevronRight as Kt, Plus as On, Trash2 as qn, LineChart as va, TrendingUp as Na, ArrowDownRight as Sa, ArrowUpRight as ka, Wallet as wa, Receipt as nn } from "lucide-react";
@@ -175,8 +175,8 @@ const O = {
175
175
  getDemoSpend: () => E("/admin/demo-spend")
176
176
  }, Vn = Ln(null);
177
177
  function Ea({ children: t }) {
178
- const [n, a] = N(null), [s, l] = N(!0);
179
- re(() => {
178
+ const [n, a] = S(null), [s, l] = S(!0);
179
+ se(() => {
180
180
  O.authMe().then((m) => a(m)).catch(() => a(null)).finally(() => l(!1));
181
181
  }, []);
182
182
  const i = we(async (m, d) => {
@@ -284,61 +284,61 @@ function Ve(t) {
284
284
  return Number.isNaN(a) ? 0 : a;
285
285
  }
286
286
  function za({ children: t }) {
287
- const n = We(), [a, s] = N([]), [l, i] = N({}), [c, o] = N({}), [m, d] = N({}), [u, p] = N({}), [v, w] = N({}), [g, y] = N({}), [I, L] = N({}), [C, b] = N(null), [h, A] = N("connecting"), [B, k] = N(0), q = H(null), x = H(null), z = H(/* @__PURE__ */ new Map()), j = H(null), U = H({}), Y = H({}), ce = H(null);
288
- function T(S) {
287
+ const n = We(), [a, s] = S([]), [l, i] = S({}), [c, o] = S({}), [m, d] = S({}), [u, p] = S({}), [v, D] = S({}), [h, y] = S({}), [R, B] = S({}), [C, b] = S(null), [g, _] = S("connecting"), [w, N] = S(0), q = H(null), x = H(null), z = H(/* @__PURE__ */ new Map()), j = H(null), U = H({}), Y = H({}), de = H(null);
288
+ function P(k) {
289
289
  for (const G of z.current.values())
290
- G.reject(new Error(S));
290
+ G.reject(new Error(k));
291
291
  z.current.clear();
292
292
  }
293
- function K(S, G) {
293
+ function K(k, G) {
294
294
  i((W) => ({
295
295
  ...W,
296
- [S]: G(W[S] ?? [])
296
+ [k]: G(W[k] ?? [])
297
297
  }));
298
298
  }
299
- function se(S, G) {
300
- w((W) => ({ ...W, [S]: G }));
299
+ function ie(k, G) {
300
+ D((W) => ({ ...W, [k]: G }));
301
301
  }
302
- function le(S, G) {
303
- y((W) => ({ ...W, [S]: G }));
302
+ function oe(k, G) {
303
+ y((W) => ({ ...W, [k]: G }));
304
304
  }
305
- function ge(S, G) {
306
- L((W) => ({ ...W, [S]: G }));
305
+ function ge(k, G) {
306
+ B((W) => ({ ...W, [k]: G }));
307
307
  }
308
- function _(S, G) {
309
- ce.current !== null && window.clearTimeout(ce.current), b({ group: S, item: G, key: Date.now() }), ce.current = window.setTimeout(() => {
310
- b((W) => (W == null ? void 0 : W.group) === S && (W == null ? void 0 : W.item) === G ? null : W), ce.current = null;
308
+ function T(k, G) {
309
+ de.current !== null && window.clearTimeout(de.current), b({ group: k, item: G, key: Date.now() }), de.current = window.setTimeout(() => {
310
+ b((W) => (W == null ? void 0 : W.group) === k && (W == null ? void 0 : W.item) === G ? null : W), de.current = null;
311
311
  }, 1100);
312
312
  }
313
- function Q(S) {
314
- return [...S].sort((G, W) => {
313
+ function Q(k) {
314
+ return [...k].sort((G, W) => {
315
315
  const Se = Ve(U.current[G.id]) || Ve(G.last_message_at || void 0) || Ve(G.created_at);
316
316
  return (Ve(U.current[W.id]) || Ve(W.last_message_at || void 0) || Ve(W.created_at)) - Se;
317
317
  });
318
318
  }
319
- function oe(S) {
320
- s((G) => Q(S(G)));
319
+ function ce(k) {
320
+ s((G) => Q(k(G)));
321
321
  }
322
- function ne(S, G) {
323
- const W = G || (/* @__PURE__ */ new Date()).toISOString(), Se = U.current[S];
322
+ function ae(k, G) {
323
+ const W = G || (/* @__PURE__ */ new Date()).toISOString(), Se = U.current[k];
324
324
  Ve(W) >= Ve(Se) && (U.current = {
325
325
  ...U.current,
326
- [S]: W
326
+ [k]: W
327
327
  });
328
328
  }
329
- function Be(S) {
329
+ function Be(k) {
330
330
  const G = { ...U.current };
331
- for (const W of S)
331
+ for (const W of k)
332
332
  W.last_message_at && !G[W.id] && (G[W.id] = W.last_message_at);
333
333
  U.current = G;
334
334
  }
335
- function Pe(S) {
335
+ function Pe(k) {
336
336
  const G = q.current;
337
337
  if (!G || G.readyState !== WebSocket.OPEN)
338
338
  throw new Error("Chat is disconnected.");
339
- G.send(JSON.stringify(S));
339
+ G.send(JSON.stringify(k));
340
340
  }
341
- function _e(S, G, W) {
341
+ function _e(k, G, W) {
342
342
  return new Promise((Se, fe) => {
343
343
  const ve = qa();
344
344
  z.current.set(ve, {
@@ -347,40 +347,40 @@ function za({ children: t }) {
347
347
  reject: fe
348
348
  });
349
349
  try {
350
- Pe({ type: S, request_id: ve, ...G });
350
+ Pe({ type: k, request_id: ve, ...G });
351
351
  } catch (Je) {
352
352
  z.current.delete(ve), fe(Je instanceof Error ? Je : new Error("Chat request failed."));
353
353
  }
354
354
  });
355
355
  }
356
- re(() => {
357
- let S = !1;
356
+ se(() => {
357
+ let k = !1;
358
358
  function G() {
359
- if (S) return;
360
- A("connecting");
359
+ if (k) return;
360
+ _("connecting");
361
361
  const Se = `${window.location.protocol === "https:" ? "wss:" : "ws:"}//${window.location.host}/ws/chat`, fe = new WebSocket(Se);
362
362
  q.current = fe, fe.onopen = () => {
363
- if (S) {
363
+ if (k) {
364
364
  fe.close();
365
365
  return;
366
366
  }
367
- A("connected"), k((ve) => ve + 1);
367
+ _("connected"), N((ve) => ve + 1);
368
368
  }, fe.onmessage = (ve) => {
369
369
  var Je;
370
370
  try {
371
- const F = JSON.parse(ve.data), Ye = typeof F.request_id == "string" ? F.request_id : null, de = typeof F.type == "string" ? F.type : null, P = typeof F.session_id == "string" ? F.session_id : null;
371
+ const F = JSON.parse(ve.data), Ye = typeof F.request_id == "string" ? F.request_id : null, ue = typeof F.type == "string" ? F.type : null, I = typeof F.session_id == "string" ? F.session_id : null;
372
372
  if (Ye) {
373
- const R = z.current.get(Ye);
374
- R && (de === "error" ? (z.current.delete(Ye), R.reject(new Error(String(F.content || "Request failed.")))) : de === R.expectedType && (z.current.delete(Ye), R.resolve(F)));
373
+ const L = z.current.get(Ye);
374
+ L && (ue === "error" ? (z.current.delete(Ye), L.reject(new Error(String(F.content || "Request failed.")))) : ue === L.expectedType && (z.current.delete(Ye), L.resolve(F)));
375
375
  }
376
- if (de === "sessions_list") {
377
- const R = Array.isArray(F.sessions) ? F.sessions : [];
378
- Be(R), s(
376
+ if (ue === "sessions_list") {
377
+ const L = Array.isArray(F.sessions) ? F.sessions : [];
378
+ Be(L), s(
379
379
  Q(
380
- R
380
+ L
381
381
  )
382
382
  );
383
- const M = new Set(R.map((be) => be.id)), Te = [...Qt()].filter((be) => !M.has(be));
383
+ const M = new Set(L.map((be) => be.id)), Te = [...Qt()].filter((be) => !M.has(be));
384
384
  Te.length > 0 && Promise.all(
385
385
  Te.map(async (be) => {
386
386
  try {
@@ -391,115 +391,115 @@ function za({ children: t }) {
391
391
  }
392
392
  })
393
393
  ).then((be) => {
394
- const f = be.filter((D) => !!D);
395
- f.length && (Be(f), oe((D) => [
396
- ...f.filter((ee) => !D.some((ae) => ae.id === ee.id)),
397
- ...D
394
+ const f = be.filter((A) => !!A);
395
+ f.length && (Be(f), ce((A) => [
396
+ ...f.filter((te) => !A.some((re) => re.id === te.id)),
397
+ ...A
398
398
  ]));
399
399
  });
400
400
  return;
401
401
  }
402
- if (de === "session_created") {
403
- const R = F.session;
404
- if (!R) return;
405
- Wn(R.id), Be([R]), oe((M) => [R, ...M.filter(($) => $.id !== R.id)]);
402
+ if (ue === "session_created") {
403
+ const L = F.session;
404
+ if (!L) return;
405
+ Wn(L.id), Be([L]), ce((M) => [L, ...M.filter(($) => $.id !== L.id)]);
406
406
  return;
407
407
  }
408
- if (de === "session_deleted" && P) {
409
- dn(P), oe((M) => M.filter(($) => $.id !== P)), i((M) => {
408
+ if (ue === "session_deleted" && I) {
409
+ dn(I), ce((M) => M.filter(($) => $.id !== I)), i((M) => {
410
410
  const $ = { ...M };
411
- return delete $[P], $;
412
- }), w((M) => {
411
+ return delete $[I], $;
412
+ }), D((M) => {
413
413
  const $ = { ...M };
414
- return delete $[P], $;
414
+ return delete $[I], $;
415
415
  }), y((M) => {
416
416
  const $ = { ...M };
417
- return delete $[P], $;
418
- }), L((M) => {
417
+ return delete $[I], $;
418
+ }), B((M) => {
419
419
  const $ = { ...M };
420
- return delete $[P], $;
420
+ return delete $[I], $;
421
421
  }), o((M) => {
422
422
  const $ = { ...M };
423
- return delete $[P], $;
423
+ return delete $[I], $;
424
424
  }), d((M) => {
425
425
  const $ = { ...M };
426
- return delete $[P], $;
426
+ return delete $[I], $;
427
427
  }), p((M) => {
428
428
  const $ = { ...M };
429
- return delete $[P], $;
429
+ return delete $[I], $;
430
430
  });
431
- const R = { ...U.current };
432
- delete R[P], U.current = R;
431
+ const L = { ...U.current };
432
+ delete L[I], U.current = L;
433
433
  return;
434
434
  }
435
- if (de === "history_loaded" && P) {
436
- const R = Array.isArray(F.messages) ? F.messages.map(cn) : [], M = F.before_id != null, $ = !!F.has_more, Te = typeof F.oldest_id == "number" ? F.oldest_id : null;
435
+ if (ue === "history_loaded" && I) {
436
+ const L = Array.isArray(F.messages) ? F.messages.map(cn) : [], M = F.before_id != null, $ = !!F.has_more, Te = typeof F.oldest_id == "number" ? F.oldest_id : null;
437
437
  i((f) => {
438
438
  if (M) {
439
- const D = f[P] ?? [], ee = new Set(
440
- D.map((te) => te.id).filter((te) => typeof te == "number")
441
- ), ae = R.filter(
442
- (te) => te.id === void 0 || !ee.has(te.id)
439
+ const A = f[I] ?? [], te = new Set(
440
+ A.map((ne) => ne.id).filter((ne) => typeof ne == "number")
441
+ ), re = L.filter(
442
+ (ne) => ne.id === void 0 || !te.has(ne.id)
443
443
  );
444
- return { ...f, [P]: [...ae, ...D] };
444
+ return { ...f, [I]: [...re, ...A] };
445
445
  }
446
- return { ...f, [P]: R };
447
- }), o((f) => ({ ...f, [P]: $ })), d((f) => ({ ...f, [P]: Te })), p((f) => ({ ...f, [P]: !1 }));
446
+ return { ...f, [I]: L };
447
+ }), o((f) => ({ ...f, [I]: $ })), d((f) => ({ ...f, [I]: Te })), p((f) => ({ ...f, [I]: !1 }));
448
448
  const be = typeof F.title == "string" ? F.title : null;
449
- if (be && oe(
450
- (f) => f.map((D) => D.id === P ? { ...D, title: be } : D)
449
+ if (be && ce(
450
+ (f) => f.map((A) => A.id === I ? { ...A, title: be } : A)
451
451
  ), !M) {
452
- const f = R[R.length - 1];
453
- f != null && f.timestamp && (ne(P, f.timestamp), oe((D) => D));
452
+ const f = L[L.length - 1];
453
+ f != null && f.timestamp && (ae(I, f.timestamp), ce((A) => A));
454
454
  }
455
455
  return;
456
456
  }
457
- if (de === "history_cleared" && P) {
458
- i((R) => ({ ...R, [P]: [] })), o((R) => ({ ...R, [P]: !1 })), d((R) => ({ ...R, [P]: null })), p((R) => ({ ...R, [P]: !1 })), se(P, !1), le(P, "idle"), ge(P, null);
457
+ if (ue === "history_cleared" && I) {
458
+ i((L) => ({ ...L, [I]: [] })), o((L) => ({ ...L, [I]: !1 })), d((L) => ({ ...L, [I]: null })), p((L) => ({ ...L, [I]: !1 })), ie(I, !1), oe(I, "idle"), ge(I, null);
459
459
  return;
460
460
  }
461
- if (de === "message_added" && P) {
462
- const R = F.message;
463
- if (!R) return;
464
- ne(P, R.created_at), R.role === "user" && ge(P, null), K(P, (M) => [
461
+ if (ue === "message_added" && I) {
462
+ const L = F.message;
463
+ if (!L) return;
464
+ ae(I, L.created_at), L.role === "user" && ge(I, null), K(I, (M) => [
465
465
  ...M.filter(($) => $.type !== "thinking"),
466
- cn(R)
467
- ]), oe((M) => M);
466
+ cn(L)
467
+ ]), ce((M) => M);
468
468
  return;
469
469
  }
470
- if (de === "demo_started" && P) {
471
- le(P, "running"), ge(P, null);
470
+ if (ue === "demo_started" && I) {
471
+ oe(I, "running"), ge(I, null);
472
472
  return;
473
473
  }
474
- if (de === "demo_typing" && P) {
475
- le(P, "running"), ge(P, {
474
+ if (ue === "demo_typing" && I) {
475
+ oe(I, "running"), ge(I, {
476
476
  content: String(F.content || ""),
477
477
  seq: Math.max(0, Number(F.seq || 0)),
478
478
  typingMs: Math.max(0, Number(F.typing_ms || 0))
479
479
  });
480
480
  return;
481
481
  }
482
- if (de === "demo_replay_complete" && P) {
483
- le(P, "complete"), ge(P, null);
482
+ if (ue === "demo_replay_complete" && I) {
483
+ oe(I, "complete"), ge(I, null);
484
484
  return;
485
485
  }
486
- if (de === "navigation_flash") {
487
- const R = typeof F.group == "string" ? F.group : "", M = typeof F.item == "string" ? F.item : void 0;
488
- R && _(R, M);
486
+ if (ue === "navigation_flash") {
487
+ const L = typeof F.group == "string" ? F.group : "", M = typeof F.item == "string" ? F.item : void 0;
488
+ L && T(L, M);
489
489
  return;
490
490
  }
491
- if (de === "session_title_updated" && P) {
492
- const R = typeof F.title == "string" ? F.title : "";
493
- oe(
494
- (M) => M.map(($) => $.id === P ? { ...$, title: R } : $)
491
+ if (ue === "session_title_updated" && I) {
492
+ const L = typeof F.title == "string" ? F.title : "";
493
+ ce(
494
+ (M) => M.map(($) => $.id === I ? { ...$, title: L } : $)
495
495
  );
496
496
  return;
497
497
  }
498
- if (de === "thinking" && P) {
499
- se(P, !0), K(P, (R) => {
500
- const M = R.find(($) => $.type === "thinking");
498
+ if (ue === "thinking" && I) {
499
+ ie(I, !0), K(I, (L) => {
500
+ const M = L.find(($) => $.type === "thinking");
501
501
  return [
502
- ...R.filter(($) => $.type !== "thinking"),
502
+ ...L.filter(($) => $.type !== "thinking"),
503
503
  {
504
504
  type: "thinking",
505
505
  content: `Thinking (step ${F.iteration})...`,
@@ -510,33 +510,33 @@ function za({ children: t }) {
510
510
  });
511
511
  return;
512
512
  }
513
- if (de === "llm_provider" && P) {
514
- const R = typeof F.provider == "string" ? F.provider : void 0, M = typeof F.model == "string" ? F.model : void 0, Te = (typeof F.role == "string" ? F.role : void 0) === "code_specialist" ? "Delegating to code specialist..." : void 0;
515
- se(P, !0), K(P, (be) => be.some((D) => D.type === "thinking") ? be.map((D) => D.type === "thinking" ? {
516
- ...D,
517
- provider: R,
513
+ if (ue === "llm_provider" && I) {
514
+ const L = typeof F.provider == "string" ? F.provider : void 0, M = typeof F.model == "string" ? F.model : void 0, Te = (typeof F.role == "string" ? F.role : void 0) === "code_specialist" ? "Delegating to code specialist..." : void 0;
515
+ ie(I, !0), K(I, (be) => be.some((A) => A.type === "thinking") ? be.map((A) => A.type === "thinking" ? {
516
+ ...A,
517
+ provider: L,
518
518
  model: M,
519
519
  ...Te ? { content: Te } : {}
520
- } : D) : [
520
+ } : A) : [
521
521
  ...be,
522
522
  {
523
523
  type: "thinking",
524
524
  content: Te ?? "Thinking...",
525
- provider: R,
525
+ provider: L,
526
526
  model: M
527
527
  }
528
528
  ]);
529
529
  return;
530
530
  }
531
- if (de === "tool_call" && P) {
531
+ if (ue === "tool_call" && I) {
532
532
  Y.current = {
533
533
  ...Y.current,
534
- [P]: {
534
+ [I]: {
535
535
  tool: String(F.tool || ""),
536
536
  args: F.args
537
537
  }
538
- }, K(P, (R) => [
539
- ...R.filter((M) => M.type !== "thinking"),
538
+ }, K(I, (L) => [
539
+ ...L.filter((M) => M.type !== "thinking"),
540
540
  {
541
541
  type: "tool_call",
542
542
  content: `Calling ${F.tool}...`,
@@ -546,20 +546,20 @@ function za({ children: t }) {
546
546
  ]);
547
547
  return;
548
548
  }
549
- if (de === "tool_result" && P) {
550
- const R = Y.current[P];
551
- if (R && R.tool === String(F.tool || "") && F.success)
552
- if (R.tool === "create_custom_analytics_report" || R.tool === "update_custom_analytics_report") {
553
- const $ = typeof F.report_id == "string" ? F.report_id : void 0, Te = typeof ((Je = R.args) == null ? void 0 : Je.report_id) == "string" ? R.args.report_id : void 0;
554
- _("Custom Analytics", $ || Te || ""), n.invalidateQueries({ queryKey: ["runtime-drafts"] });
549
+ if (ue === "tool_result" && I) {
550
+ const L = Y.current[I];
551
+ if (L && L.tool === String(F.tool || "") && F.success)
552
+ if (L.tool === "create_custom_analytics_report" || L.tool === "update_custom_analytics_report") {
553
+ const $ = typeof F.report_id == "string" ? F.report_id : void 0, Te = typeof ((Je = L.args) == null ? void 0 : Je.report_id) == "string" ? L.args.report_id : void 0;
554
+ T("Custom Analytics", $ || Te || ""), n.invalidateQueries({ queryKey: ["runtime-drafts"] });
555
555
  } else {
556
- const $ = Oa(R.tool, R.args);
557
- $ && _($.group, $.item);
556
+ const $ = Oa(L.tool, L.args);
557
+ $ && T($.group, $.item);
558
558
  }
559
559
  Y.current = {
560
560
  ...Y.current,
561
- [P]: null
562
- }, K(P, (M) => [
561
+ [I]: null
562
+ }, K(I, (M) => [
563
563
  ...M,
564
564
  {
565
565
  type: "tool_result",
@@ -570,15 +570,15 @@ function za({ children: t }) {
570
570
  ]);
571
571
  return;
572
572
  }
573
- if (de === "complete" && P) {
574
- se(P, !1), K(P, (R) => R.filter((M) => M.type !== "thinking"));
573
+ if (ue === "complete" && I) {
574
+ ie(I, !1), K(I, (L) => L.filter((M) => M.type !== "thinking"));
575
575
  return;
576
576
  }
577
- if (de === "error") {
577
+ if (ue === "error") {
578
578
  if (Ye)
579
579
  return;
580
- P && (se(P, !1), K(P, (R) => [
581
- ...R.filter((M) => M.type !== "thinking"),
580
+ I && (ie(I, !1), K(I, (L) => [
581
+ ...L.filter((M) => M.type !== "thinking"),
582
582
  { type: "error", content: String(F.content || "Chat error.") }
583
583
  ]));
584
584
  }
@@ -587,7 +587,7 @@ function za({ children: t }) {
587
587
  }, fe.onerror = () => {
588
588
  fe.close();
589
589
  }, fe.onclose = (ve) => {
590
- if (q.current === fe && (q.current = null), T("Chat disconnected."), A("disconnected"), !S) {
590
+ if (q.current === fe && (q.current = null), P("Chat disconnected."), _("disconnected"), !k) {
591
591
  if (ve.code === 4001 || ve.code === 4003) {
592
592
  window.location.href = "/login";
593
593
  return;
@@ -597,7 +597,7 @@ function za({ children: t }) {
597
597
  };
598
598
  }
599
599
  return G(), () => {
600
- if (S = !0, x.current !== null && window.clearTimeout(x.current), ce.current !== null && window.clearTimeout(ce.current), T("Chat disconnected."), q.current) {
600
+ if (k = !0, x.current !== null && window.clearTimeout(x.current), de.current !== null && window.clearTimeout(de.current), P("Chat disconnected."), q.current) {
601
601
  const W = q.current;
602
602
  q.current = null, W.close();
603
603
  }
@@ -606,90 +606,90 @@ function za({ children: t }) {
606
606
  async function $e() {
607
607
  if (j.current)
608
608
  return j.current;
609
- const S = _e("create_session", {}, "session_created").then((G) => G.session).finally(() => {
610
- j.current === S && (j.current = null);
609
+ const k = _e("create_session", {}, "session_created").then((G) => G.session).finally(() => {
610
+ j.current === k && (j.current = null);
611
611
  });
612
- return j.current = S, S;
612
+ return j.current = k, k;
613
613
  }
614
- async function Re(S) {
615
- le(S, "running"), ge(S, null);
614
+ async function Re(k) {
615
+ oe(k, "running"), ge(k, null);
616
616
  try {
617
- await _e("start_demo", { session_id: S }, "demo_started");
617
+ await _e("start_demo", { session_id: k }, "demo_started");
618
618
  } catch (G) {
619
- throw le(S, "idle"), G;
619
+ throw oe(k, "idle"), G;
620
620
  }
621
621
  }
622
- function he(S, G) {
622
+ function he(k, G) {
623
623
  try {
624
- Pe({ type: "demo_typing_done", session_id: S, seq: G });
624
+ Pe({ type: "demo_typing_done", session_id: k, seq: G });
625
625
  } catch {
626
626
  }
627
627
  }
628
- async function xe(S) {
629
- await _e("delete_session", { session_id: S }, "session_deleted");
628
+ async function xe(k) {
629
+ await _e("delete_session", { session_id: k }, "session_deleted");
630
630
  }
631
- async function qe(S) {
632
- await _e("load_history", { session_id: S }, "history_loaded");
631
+ async function qe(k) {
632
+ await _e("load_history", { session_id: k }, "history_loaded");
633
633
  }
634
- async function ze(S) {
635
- if (u[S]) return;
636
- const G = m[S];
637
- if (G != null && c[S]) {
638
- p((W) => ({ ...W, [S]: !0 }));
634
+ async function ze(k) {
635
+ if (u[k]) return;
636
+ const G = m[k];
637
+ if (G != null && c[k]) {
638
+ p((W) => ({ ...W, [k]: !0 }));
639
639
  try {
640
640
  await _e(
641
641
  "load_history",
642
- { session_id: S, before_id: G },
642
+ { session_id: k, before_id: G },
643
643
  "history_loaded"
644
644
  );
645
645
  } catch (W) {
646
- throw p((Se) => ({ ...Se, [S]: !1 })), W;
646
+ throw p((Se) => ({ ...Se, [k]: !1 })), W;
647
647
  }
648
648
  }
649
649
  }
650
- async function Ae(S) {
651
- await _e("clear_history", { session_id: S }, "history_cleared");
650
+ async function Ae(k) {
651
+ await _e("clear_history", { session_id: k }, "history_cleared");
652
652
  }
653
- function nt(S, G, W) {
653
+ function nt(k, G, W) {
654
654
  const Se = G.trim(), fe = ((W == null ? void 0 : W.length) ?? 0) > 0;
655
655
  if (!Se && !fe) return !1;
656
656
  try {
657
- se(S, !0);
657
+ ie(k, !0);
658
658
  const ve = {
659
659
  type: "send_message",
660
- session_id: S,
660
+ session_id: k,
661
661
  content: Se
662
662
  };
663
663
  return fe && (ve.attachment_ids = W), Pe(ve), !0;
664
664
  } catch {
665
- return se(S, !1), !1;
665
+ return ie(k, !1), !1;
666
666
  }
667
667
  }
668
- function Qe(S) {
669
- return S ? l[S] ?? [] : [];
668
+ function Qe(k) {
669
+ return k ? l[k] ?? [] : [];
670
670
  }
671
- function at(S) {
672
- return S ? !!v[S] : !1;
671
+ function at(k) {
672
+ return k ? !!v[k] : !1;
673
673
  }
674
- function _t(S) {
675
- return S ? !!c[S] : !1;
674
+ function _t(k) {
675
+ return k ? !!c[k] : !1;
676
676
  }
677
- function He(S) {
678
- return S ? !!u[S] : !1;
677
+ function He(k) {
678
+ return k ? !!u[k] : !1;
679
679
  }
680
- function pt(S) {
681
- return S ? g[S] ?? "idle" : "idle";
680
+ function pt(k) {
681
+ return k ? h[k] ?? "idle" : "idle";
682
682
  }
683
- function At(S) {
684
- return S ? I[S] ?? null : null;
683
+ function At(k) {
684
+ return k ? R[k] ?? null : null;
685
685
  }
686
686
  return /* @__PURE__ */ e(
687
687
  Un.Provider,
688
688
  {
689
689
  value: {
690
690
  sessions: a,
691
- connectionStatus: h,
692
- connectionVersion: B,
691
+ connectionStatus: g,
692
+ connectionVersion: w,
693
693
  navigationFlash: C,
694
694
  createSession: $e,
695
695
  startDemo: Re,
@@ -865,7 +865,7 @@ function un(t) {
865
865
  localStorage.setItem(Kn, JSON.stringify([...t]));
866
866
  }
867
867
  function Ht(t) {
868
- const [n, a] = N(() => !Bt().has(t)), s = we(() => {
868
+ const [n, a] = S(() => !Bt().has(t)), s = we(() => {
869
869
  a((i) => {
870
870
  const c = Bt();
871
871
  return i ? c.add(t) : c.delete(t), un(c), !i;
@@ -969,24 +969,24 @@ function Yt() {
969
969
  );
970
970
  }
971
971
  function Va() {
972
- const [t, n, a] = Ht("custom-analytics"), s = dt(), l = Oe(), i = We(), { t: c } = Z(), { navigationFlash: o, sessions: m, createSession: d } = tt(), u = (o == null ? void 0 : o.group) === "Custom Analytics", p = Jt["Custom Analytics"], { data: v } = ie({
972
+ const [t, n, a] = Ht("custom-analytics"), s = dt(), l = Oe(), i = We(), { t: c } = Z(), { navigationFlash: o, sessions: m, createSession: d } = tt(), u = (o == null ? void 0 : o.group) === "Custom Analytics", p = Jt["Custom Analytics"], { data: v } = le({
973
973
  queryKey: ["runtime-drafts"],
974
974
  queryFn: () => O.listRuntimeDrafts(),
975
975
  staleTime: 3e4
976
- }), w = (v == null ? void 0 : v.drafts) ?? [];
977
- re(() => {
976
+ }), D = (v == null ? void 0 : v.drafts) ?? [];
977
+ se(() => {
978
978
  (o == null ? void 0 : o.group) === "Custom Analytics" && (a(), i.invalidateQueries({ queryKey: ["runtime-drafts"] }));
979
979
  }, [o == null ? void 0 : o.key, i, a]);
980
- const g = me({
981
- mutationFn: (L) => O.deleteRuntimeDraft(L),
982
- onSuccess: (L, C) => {
980
+ const h = pe({
981
+ mutationFn: (B) => O.deleteRuntimeDraft(B),
982
+ onSuccess: (B, C) => {
983
983
  i.invalidateQueries({ queryKey: ["runtime-drafts"] }), s.search.includes(`report_id=${C}`) && l("/reports/analytics");
984
984
  }
985
- }), y = async (L, C) => {
986
- L.preventDefault(), L.stopPropagation(), g.mutate(C);
987
- }, I = async () => {
985
+ }), y = async (B, C) => {
986
+ B.preventDefault(), B.stopPropagation(), h.mutate(C);
987
+ }, R = async () => {
988
988
  var b;
989
- const L = "Build me a custom analytics report: <describe what you want — e.g. top 10 customers by revenue for the last quarter, or monthly purchases trend by supplier>";
989
+ const B = "Build me a custom analytics report: <describe what you want — e.g. top 10 customers by revenue for the last quarter, or monthly purchases trend by supplier>";
990
990
  let C = ((b = m[0]) == null ? void 0 : b.id) || "";
991
991
  if (!C)
992
992
  try {
@@ -995,7 +995,7 @@ function Va() {
995
995
  l("/reports/analytics");
996
996
  return;
997
997
  }
998
- l(`/chat/${C}`, { state: { prefillMessage: L } });
998
+ l(`/chat/${C}`, { state: { prefillMessage: B } });
999
999
  };
1000
1000
  return /* @__PURE__ */ r("div", { children: [
1001
1001
  /* @__PURE__ */ r(
@@ -1018,7 +1018,7 @@ function Va() {
1018
1018
  /* @__PURE__ */ e("li", { children: /* @__PURE__ */ r(
1019
1019
  "button",
1020
1020
  {
1021
- onClick: I,
1021
+ onClick: R,
1022
1022
  className: "flex w-full items-center gap-2 px-4 py-1.5 pl-10 text-sm text-brand transition-colors hover:bg-brand/5",
1023
1023
  children: [
1024
1024
  /* @__PURE__ */ e(On, { className: "h-3.5 w-3.5" }),
@@ -1026,8 +1026,8 @@ function Va() {
1026
1026
  ]
1027
1027
  }
1028
1028
  ) }),
1029
- w.map((L) => {
1030
- const C = `/reports/analytics?report_id=${L.id}`, b = s.pathname === "/reports/analytics" && s.search.includes(`report_id=${L.id}`), h = (o == null ? void 0 : o.group) === "Custom Analytics" && (o == null ? void 0 : o.item) === L.id;
1029
+ D.map((B) => {
1030
+ const C = `/reports/analytics?report_id=${B.id}`, b = s.pathname === "/reports/analytics" && s.search.includes(`report_id=${B.id}`), g = (o == null ? void 0 : o.group) === "Custom Analytics" && (o == null ? void 0 : o.item) === B.id;
1031
1031
  return /* @__PURE__ */ r("li", { className: "group relative", children: [
1032
1032
  /* @__PURE__ */ e(
1033
1033
  kt,
@@ -1037,23 +1037,23 @@ function Va() {
1037
1037
  "relative block truncate px-4 py-1.5 pl-10 pr-8 text-sm transition-all duration-300",
1038
1038
  !b && "text-fg-muted hover:bg-surface-subtle hover:text-fg",
1039
1039
  b && "bg-surface-subtle font-medium text-fg",
1040
- h && p
1040
+ g && p
1041
1041
  ),
1042
- title: L.title,
1043
- children: L.title
1042
+ title: B.title,
1043
+ children: B.title
1044
1044
  }
1045
1045
  ),
1046
1046
  b && /* @__PURE__ */ e(Yt, {}),
1047
1047
  /* @__PURE__ */ e(
1048
1048
  "button",
1049
1049
  {
1050
- onClick: (A) => y(A, L.id),
1050
+ onClick: (_) => y(_, B.id),
1051
1051
  className: "absolute right-2 top-1/2 -translate-y-1/2 rounded p-0.5 text-fg-muted opacity-0 transition-opacity hover:text-red-500 group-hover:opacity-100",
1052
1052
  title: c("nav.deleteReport"),
1053
1053
  children: /* @__PURE__ */ e(qn, { className: "h-3.5 w-3.5" })
1054
1054
  }
1055
1055
  )
1056
- ] }, L.id);
1056
+ ] }, B.id);
1057
1057
  })
1058
1058
  ] })
1059
1059
  ] });
@@ -1106,11 +1106,11 @@ const Ga = {
1106
1106
  };
1107
1107
  function ja({ isMobileOpen: t = !1, onClose: n }) {
1108
1108
  var o;
1109
- const { data: a } = ie({
1109
+ const { data: a } = le({
1110
1110
  queryKey: ["settings"],
1111
1111
  queryFn: () => O.getSettings(),
1112
1112
  staleTime: 6e4
1113
- }), { data: s } = ie({
1113
+ }), { data: s } = le({
1114
1114
  queryKey: ["setup-status"],
1115
1115
  queryFn: () => O.setupStatus(),
1116
1116
  staleTime: 6e4
@@ -1197,8 +1197,8 @@ function Ka() {
1197
1197
  return /* @__PURE__ */ e(za, { children: /* @__PURE__ */ e(Qa, {}) });
1198
1198
  }
1199
1199
  function Qa() {
1200
- const { pathname: t } = dt(), { user: n, logout: a } = mt(), { navigationFlash: s } = tt(), { t: l } = Z(), i = Wa(t, l), [c, o] = N(!1);
1201
- re(() => {
1200
+ const { pathname: t } = dt(), { user: n, logout: a } = mt(), { navigationFlash: s } = tt(), { t: l } = Z(), i = Wa(t, l), [c, o] = S(!1);
1201
+ se(() => {
1202
1202
  o(!1);
1203
1203
  }, [t]);
1204
1204
  const m = s ? Jt[s.group] : null;
@@ -1315,7 +1315,7 @@ function Zt({ status: t }) {
1315
1315
  }
1316
1316
  function Fe(t) {
1317
1317
  var s;
1318
- const { data: n } = ie({
1318
+ const { data: n } = le({
1319
1319
  queryKey: ["setup-status"],
1320
1320
  queryFn: () => O.setupStatus(),
1321
1321
  staleTime: 3e5
@@ -1385,7 +1385,7 @@ function ot() {
1385
1385
  ] });
1386
1386
  }
1387
1387
  function tr() {
1388
- const { t } = Z(), { data: n, isLoading: a } = ie({
1388
+ const { t } = Z(), { data: n, isLoading: a } = le({
1389
1389
  queryKey: ["dashboard-summary"],
1390
1390
  queryFn: () => O.dashboardSummary()
1391
1391
  });
@@ -1443,7 +1443,7 @@ function tr() {
1443
1443
  ] });
1444
1444
  }
1445
1445
  function nr(t, n) {
1446
- const { data: a, isLoading: s, error: l, refetch: i } = ie({
1446
+ const { data: a, isLoading: s, error: l, refetch: i } = le({
1447
1447
  queryKey: ["documents", t, n],
1448
1448
  queryFn: () => O.listDocuments(t, n),
1449
1449
  enabled: !!t
@@ -2128,7 +2128,7 @@ const ar = {
2128
2128
  md: "h-10 px-4 text-sm",
2129
2129
  lg: "h-11 px-5 text-sm"
2130
2130
  };
2131
- function X({
2131
+ function ee({
2132
2132
  variant: t = "primary",
2133
2133
  size: n = "md",
2134
2134
  disabled: a,
@@ -2159,7 +2159,7 @@ function X({
2159
2159
  }
2160
2160
  );
2161
2161
  }
2162
- function pe({ label: t, hint: n, error: a, className: s, id: l, ...i }) {
2162
+ function X({ label: t, hint: n, error: a, className: s, id: l, ...i }) {
2163
2163
  const c = l || (t ? t.toLowerCase().replace(/\s+/g, "-") : void 0);
2164
2164
  return /* @__PURE__ */ r("div", { children: [
2165
2165
  t && /* @__PURE__ */ e(
@@ -2248,7 +2248,7 @@ function Ke({ label: t, options: n, value: a, onChange: s, className: l, require
2248
2248
  ] });
2249
2249
  }
2250
2250
  function ir({ text: t }) {
2251
- const [n, a] = N(!1);
2251
+ const [n, a] = S(!1);
2252
2252
  return /* @__PURE__ */ r("span", { className: "relative ml-1 inline-flex", children: [
2253
2253
  /* @__PURE__ */ e(
2254
2254
  "button",
@@ -2268,7 +2268,7 @@ function ir({ text: t }) {
2268
2268
  ] });
2269
2269
  }
2270
2270
  function lr(t, n = !0) {
2271
- const { data: a } = ie({
2271
+ const { data: a } = le({
2272
2272
  queryKey: ["currencies", ""],
2273
2273
  queryFn: () => O.currencies(t),
2274
2274
  enabled: n,
@@ -2298,19 +2298,19 @@ function dr({
2298
2298
  disabled: s,
2299
2299
  hideLabel: l
2300
2300
  }) {
2301
- const [i, c] = N(n ?? ""), [o, m] = N(!1), { data: d } = ie({
2301
+ const [i, c] = S(n ?? ""), [o, m] = S(!1), { data: d } = le({
2302
2302
  queryKey: ["link-search", t.linkDoctype, i],
2303
2303
  queryFn: () => O.searchLink(t.linkDoctype, i),
2304
2304
  enabled: !!t.linkDoctype && o
2305
2305
  });
2306
- return re(() => {
2306
+ return se(() => {
2307
2307
  c(n ?? "");
2308
2308
  }, [n]), s ? /* @__PURE__ */ r("div", { children: [
2309
2309
  !l && /* @__PURE__ */ e("label", { className: "mb-1.5 block text-sm font-medium text-fg", children: t.label }),
2310
2310
  /* @__PURE__ */ e("p", { className: "py-2 text-sm text-fg", children: n || "-" })
2311
2311
  ] }) : /* @__PURE__ */ r("div", { className: "relative", children: [
2312
2312
  /* @__PURE__ */ e(
2313
- pe,
2313
+ X,
2314
2314
  {
2315
2315
  label: l ? void 0 : t.label,
2316
2316
  value: i,
@@ -2343,38 +2343,38 @@ function Vt({
2343
2343
  hideLabel: i,
2344
2344
  currency: c = "USD"
2345
2345
  }) {
2346
- var w;
2346
+ var D;
2347
2347
  const { t: o } = Z(), m = s || !!t.readOnly, d = () => i ? null : /* @__PURE__ */ e(cr, { label: o(`fields.${t.label}`, { defaultValue: t.label }), hint: t.hint }), u = t.type === "select" && t.optionsSource === "currency", p = lr(void 0, u);
2348
2348
  if (m) {
2349
2349
  if (t.type === "link" && n) {
2350
- const y = t.linkDoctypeField && l ? String(l[t.linkDoctypeField] ?? "").toLowerCase().replace(/\s+/g, "-") : t.linkDoctype, I = $t(y, String(n));
2351
- if (I)
2350
+ const y = t.linkDoctypeField && l ? String(l[t.linkDoctypeField] ?? "").toLowerCase().replace(/\s+/g, "-") : t.linkDoctype, R = $t(y, String(n));
2351
+ if (R)
2352
2352
  return /* @__PURE__ */ r("div", { children: [
2353
2353
  /* @__PURE__ */ e(d, {}),
2354
2354
  /* @__PURE__ */ e("p", { className: i ? "text-sm" : "py-2 text-sm", children: /* @__PURE__ */ e(
2355
2355
  ye,
2356
2356
  {
2357
- to: I,
2357
+ to: R,
2358
2358
  className: "text-sky-600 hover:text-sky-800 hover:underline",
2359
2359
  children: n
2360
2360
  }
2361
2361
  ) })
2362
2362
  ] });
2363
2363
  }
2364
- let g = n ?? "-";
2365
- return t.type === "currency" && typeof n == "number" && (g = Le(n, c)), /* @__PURE__ */ r("div", { children: [
2364
+ let h = n ?? "-";
2365
+ return t.type === "currency" && typeof n == "number" && (h = Le(n, c)), /* @__PURE__ */ r("div", { children: [
2366
2366
  /* @__PURE__ */ e(d, {}),
2367
- /* @__PURE__ */ e("p", { className: i ? "text-sm text-fg" : "py-2 text-sm text-fg", children: g })
2367
+ /* @__PURE__ */ e("p", { className: i ? "text-sm text-fg" : "py-2 text-sm text-fg", children: h })
2368
2368
  ] });
2369
2369
  }
2370
2370
  if (t.type === "link") {
2371
- const g = t.linkDoctypeField && l ? { ...t, linkDoctype: (w = l[t.linkDoctypeField]) == null ? void 0 : w.toLowerCase().replace(/\s+/g, "-") } : t;
2371
+ const h = t.linkDoctypeField && l ? { ...t, linkDoctype: (D = l[t.linkDoctypeField]) == null ? void 0 : D.toLowerCase().replace(/\s+/g, "-") } : t;
2372
2372
  return /* @__PURE__ */ r("div", { children: [
2373
2373
  /* @__PURE__ */ e(d, {}),
2374
2374
  /* @__PURE__ */ e(
2375
2375
  dr,
2376
2376
  {
2377
- field: g,
2377
+ field: h,
2378
2378
  value: n ?? "",
2379
2379
  onChange: a,
2380
2380
  disabled: m,
@@ -2384,13 +2384,13 @@ function Vt({
2384
2384
  ] });
2385
2385
  }
2386
2386
  if (t.type === "select" && (t.options || u)) {
2387
- const g = u ? n && !p.includes(n) ? [n, ...p] : p : t.options;
2387
+ const h = u ? n && !p.includes(n) ? [n, ...p] : p : t.options;
2388
2388
  return /* @__PURE__ */ r("div", { children: [
2389
2389
  /* @__PURE__ */ e(d, {}),
2390
2390
  /* @__PURE__ */ e(
2391
2391
  Ke,
2392
2392
  {
2393
- options: g,
2393
+ options: h,
2394
2394
  value: n ?? "",
2395
2395
  onChange: (y) => a(y.target.value)
2396
2396
  }
@@ -2406,7 +2406,7 @@ function Vt({
2406
2406
  className: "block w-full rounded-lg bg-surface px-3 py-2 text-sm text-fg ring-1 ring-line transition-all placeholder:text-fg-muted/70 focus:outline-none focus:ring-2 focus:ring-brand/30",
2407
2407
  rows: 3,
2408
2408
  value: n ?? "",
2409
- onChange: (g) => a(g.target.value)
2409
+ onChange: (h) => a(h.target.value)
2410
2410
  }
2411
2411
  )
2412
2412
  ] });
@@ -2414,13 +2414,13 @@ function Vt({
2414
2414
  return /* @__PURE__ */ r("div", { children: [
2415
2415
  /* @__PURE__ */ e(d, {}),
2416
2416
  /* @__PURE__ */ e(
2417
- pe,
2417
+ X,
2418
2418
  {
2419
2419
  type: v,
2420
2420
  step: t.type === "currency" ? "0.01" : void 0,
2421
2421
  value: n ?? "",
2422
- onChange: (g) => a(
2423
- v === "number" ? parseFloat(g.target.value) || 0 : g.target.value
2422
+ onChange: (h) => a(
2423
+ v === "number" ? parseFloat(h.target.value) || 0 : h.target.value
2424
2424
  )
2425
2425
  }
2426
2426
  )
@@ -2435,7 +2435,7 @@ function ur({
2435
2435
  }) {
2436
2436
  const { t: i } = Z(), c = (d, u, p) => {
2437
2437
  const v = n.map(
2438
- (w, g) => g === d ? { ...w, [u]: p } : w
2438
+ (D, h) => h === d ? { ...D, [u]: p } : D
2439
2439
  );
2440
2440
  a(v);
2441
2441
  }, o = () => {
@@ -2475,7 +2475,7 @@ function ur({
2475
2475
  }
2476
2476
  ) }, p.name)),
2477
2477
  !s && /* @__PURE__ */ e("td", { className: "px-2 py-1", children: /* @__PURE__ */ e(
2478
- X,
2478
+ ee,
2479
2479
  {
2480
2480
  variant: "ghost",
2481
2481
  size: "sm",
@@ -2485,7 +2485,7 @@ function ur({
2485
2485
  ) })
2486
2486
  ] }, u)) })
2487
2487
  ] }) }),
2488
- !s && /* @__PURE__ */ e("div", { className: "mt-2", children: /* @__PURE__ */ e(X, { variant: "secondary", size: "sm", onClick: o, children: i("common.addRow") }) })
2488
+ !s && /* @__PURE__ */ e("div", { className: "mt-2", children: /* @__PURE__ */ e(ee, { variant: "secondary", size: "sm", onClick: o, children: i("common.addRow") }) })
2489
2489
  ] });
2490
2490
  }
2491
2491
  function mr({
@@ -2504,12 +2504,12 @@ function mr({
2504
2504
  if (!i) return null;
2505
2505
  const p = !t && n && a ? `/api/documents/${n}/${encodeURIComponent(a)}/pdf` : null;
2506
2506
  return /* @__PURE__ */ r("div", { className: "flex flex-wrap gap-2", children: [
2507
- p && /* @__PURE__ */ e(X, { variant: "secondary", onClick: () => window.open(p, "_blank"), children: u("common.pdf") }),
2508
- s < 1 && /* @__PURE__ */ e(X, { onClick: c, disabled: l, children: u(l ? "common.saving" : "common.save") }),
2509
- !t && i.canSubmit && s === 0 && /* @__PURE__ */ e(X, { variant: "secondary", onClick: o, children: u("common.submit") }),
2510
- !t && i.canCancel && s === 1 && /* @__PURE__ */ e(X, { variant: "danger", onClick: m, children: u("common.cancelDoc") }),
2507
+ p && /* @__PURE__ */ e(ee, { variant: "secondary", onClick: () => window.open(p, "_blank"), children: u("common.pdf") }),
2508
+ s < 1 && /* @__PURE__ */ e(ee, { onClick: c, disabled: l, children: u(l ? "common.saving" : "common.save") }),
2509
+ !t && i.canSubmit && s === 0 && /* @__PURE__ */ e(ee, { variant: "secondary", onClick: o, children: u("common.submit") }),
2510
+ !t && i.canCancel && s === 1 && /* @__PURE__ */ e(ee, { variant: "danger", onClick: m, children: u("common.cancelDoc") }),
2511
2511
  !t && s === 1 && i.conversions.map((v) => /* @__PURE__ */ e(
2512
- X,
2512
+ ee,
2513
2513
  {
2514
2514
  variant: "secondary",
2515
2515
  onClick: () => d(v.targetDoctype),
@@ -2543,96 +2543,96 @@ function pn(t, n) {
2543
2543
  }
2544
2544
  function hn() {
2545
2545
  var ge;
2546
- const { doctype: t, name: n } = ut(), a = Oe(), s = We(), { t: l } = Z(), i = Qn(t ?? ""), c = !n, [o, m] = N({}), [d, u] = N(!1), { data: p, isLoading: v } = ie({
2546
+ const { doctype: t, name: n } = ut(), a = Oe(), s = We(), { t: l } = Z(), i = Qn(t ?? ""), c = !n, [o, m] = S({}), [d, u] = S(!1), { data: p, isLoading: v } = le({
2547
2547
  queryKey: ["document", t, n],
2548
2548
  queryFn: () => O.getDocument(t, n),
2549
2549
  enabled: !!t && !!n && !c
2550
- }), w = Ce(
2551
- () => !!(i != null && i.fields.some((_) => _.name === "currency")),
2550
+ }), D = Ce(
2551
+ () => !!(i != null && i.fields.some((T) => T.name === "currency")),
2552
2552
  [i]
2553
- ), g = i == null ? void 0 : i.partyField, y = g ? o[g] : void 0, I = Fe(o.company), { data: L } = ie({
2554
- queryKey: ["master", g, y],
2555
- queryFn: () => O.getMaster(g, y),
2556
- enabled: c && w && !!g && !!y,
2553
+ ), h = i == null ? void 0 : i.partyField, y = h ? o[h] : void 0, R = Fe(o.company), { data: B } = le({
2554
+ queryKey: ["master", h, y],
2555
+ queryFn: () => O.getMaster(h, y),
2556
+ enabled: c && D && !!h && !!y,
2557
2557
  staleTime: 300 * 1e3
2558
2558
  });
2559
- re(() => {
2560
- if (!c || !w || d) return;
2561
- let _;
2559
+ se(() => {
2560
+ if (!c || !D || d) return;
2561
+ let T;
2562
2562
  if (y) {
2563
- if (!L) return;
2564
- _ = L.default_currency || I;
2563
+ if (!B) return;
2564
+ T = B.default_currency || R;
2565
2565
  } else
2566
- _ = I;
2567
- _ && _ !== o.currency && m((Q) => ({ ...Q, currency: _ }));
2566
+ T = R;
2567
+ T && T !== o.currency && m((Q) => ({ ...Q, currency: T }));
2568
2568
  }, [
2569
2569
  c,
2570
- w,
2570
+ D,
2571
2571
  d,
2572
2572
  y,
2573
- L,
2574
- I,
2573
+ B,
2574
+ R,
2575
2575
  o.currency
2576
- ]), re(() => {
2576
+ ]), se(() => {
2577
2577
  if (c && i) {
2578
- const _ = {};
2578
+ const T = {};
2579
2579
  i.fields.forEach((Q) => {
2580
- Q.type === "date" ? _[Q.name] = (/* @__PURE__ */ new Date()).toISOString().split("T")[0] : _[Q.name] = Q.default ?? "";
2580
+ Q.type === "date" ? T[Q.name] = (/* @__PURE__ */ new Date()).toISOString().split("T")[0] : T[Q.name] = Q.default ?? "";
2581
2581
  }), i.childTables.forEach((Q) => {
2582
- _[Q.key] = [];
2583
- }), _.docstatus = 0, m(_);
2582
+ T[Q.key] = [];
2583
+ }), T.docstatus = 0, m(T);
2584
2584
  } else p && m(p);
2585
2585
  }, [c, p, i]);
2586
- const C = me({
2587
- mutationFn: (_) => O.createDocument(t, _),
2588
- onSuccess: (_) => {
2589
- s.invalidateQueries({ queryKey: ["documents", t] }), a(`/app/${t}/${_.name}`, { replace: !0 });
2586
+ const C = pe({
2587
+ mutationFn: (T) => O.createDocument(t, T),
2588
+ onSuccess: (T) => {
2589
+ s.invalidateQueries({ queryKey: ["documents", t] }), a(`/app/${t}/${T.name}`, { replace: !0 });
2590
2590
  }
2591
- }), b = me({
2592
- mutationFn: (_) => O.updateDocument(t, n, _),
2593
- onSuccess: (_) => {
2594
- s.invalidateQueries({ queryKey: ["document", t, n] }), s.invalidateQueries({ queryKey: ["documents", t] }), m(_);
2591
+ }), b = pe({
2592
+ mutationFn: (T) => O.updateDocument(t, n, T),
2593
+ onSuccess: (T) => {
2594
+ s.invalidateQueries({ queryKey: ["document", t, n] }), s.invalidateQueries({ queryKey: ["documents", t] }), m(T);
2595
2595
  }
2596
- }), h = me({
2596
+ }), g = pe({
2597
2597
  mutationFn: () => O.submitDocument(t, n),
2598
- onSuccess: (_) => {
2599
- m(_), s.invalidateQueries({ queryKey: ["document", t, n] }), s.invalidateQueries({ queryKey: ["documents", t] });
2598
+ onSuccess: (T) => {
2599
+ m(T), s.invalidateQueries({ queryKey: ["document", t, n] }), s.invalidateQueries({ queryKey: ["documents", t] });
2600
2600
  }
2601
- }), A = me({
2601
+ }), _ = pe({
2602
2602
  mutationFn: () => O.cancelDocument(t, n),
2603
- onSuccess: (_) => {
2604
- m(_), s.invalidateQueries({ queryKey: ["document", t, n] }), s.invalidateQueries({ queryKey: ["documents", t] });
2603
+ onSuccess: (T) => {
2604
+ m(T), s.invalidateQueries({ queryKey: ["document", t, n] }), s.invalidateQueries({ queryKey: ["documents", t] });
2605
2605
  }
2606
- }), B = me({
2607
- mutationFn: (_) => O.convertDocument(t, n, _),
2608
- onSuccess: (_, Q) => {
2609
- const oe = Q.toLowerCase().replace(/\s+/g, "-");
2610
- a(`/app/${oe}/${_.name}`);
2606
+ }), w = pe({
2607
+ mutationFn: (T) => O.convertDocument(t, n, T),
2608
+ onSuccess: (T, Q) => {
2609
+ const ce = Q.toLowerCase().replace(/\s+/g, "-");
2610
+ a(`/app/${ce}/${T.name}`);
2611
2611
  }
2612
- }), k = we(
2613
- (_, Q) => {
2614
- _ === "currency" && u(!0), m((oe) => {
2615
- const ne = { ...oe, [_]: Q };
2616
- return _ === "currency" && (ne.conversion_rate = 0), pn(ne, i);
2612
+ }), N = we(
2613
+ (T, Q) => {
2614
+ T === "currency" && u(!0), m((ce) => {
2615
+ const ae = { ...ce, [T]: Q };
2616
+ return T === "currency" && (ae.conversion_rate = 0), pn(ae, i);
2617
2617
  });
2618
2618
  },
2619
2619
  [i]
2620
2620
  ), q = we(
2621
- (_, Q) => {
2622
- m((oe) => {
2623
- const ne = { ...oe, [_]: Q };
2624
- return pn(ne, i);
2621
+ (T, Q) => {
2622
+ m((ce) => {
2623
+ const ae = { ...ce, [T]: Q };
2624
+ return pn(ae, i);
2625
2625
  });
2626
2626
  },
2627
2627
  [i]
2628
2628
  ), x = () => {
2629
2629
  c ? C.mutate(o) : b.mutate(o);
2630
2630
  }, z = () => {
2631
- h.mutate();
2631
+ g.mutate();
2632
2632
  }, j = () => {
2633
- A.mutate();
2634
- }, U = (_) => {
2635
- B.mutate(_);
2633
+ _.mutate();
2634
+ }, U = (T) => {
2635
+ w.mutate(T);
2636
2636
  };
2637
2637
  if (!i)
2638
2638
  return /* @__PURE__ */ r("p", { className: "text-fg-muted", children: [
@@ -2641,7 +2641,7 @@ function hn() {
2641
2641
  ] });
2642
2642
  if (!c && v)
2643
2643
  return /* @__PURE__ */ e("p", { className: "text-fg-muted", children: l("common.loading") });
2644
- const Y = o.docstatus ?? 0, ce = Y >= 1, T = o.currency || "USD", K = Ee(o.conversion_rate ?? 1), se = i.fields.filter((_) => !_.readOnly), le = i.fields.filter((_) => _.readOnly);
2644
+ const Y = o.docstatus ?? 0, de = Y >= 1, P = o.currency || "USD", K = Ee(o.conversion_rate ?? 1), ie = i.fields.filter((T) => !T.readOnly), oe = i.fields.filter((T) => T.readOnly);
2645
2645
  return /* @__PURE__ */ r("div", { className: "space-y-6", children: [
2646
2646
  /* @__PURE__ */ r("div", { className: "flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between", children: [
2647
2647
  /* @__PURE__ */ r("div", { className: "flex items-center gap-3", children: [
@@ -2650,9 +2650,9 @@ function hn() {
2650
2650
  "span",
2651
2651
  {
2652
2652
  className: "inline-flex items-center gap-1 rounded-full bg-surface-subtle px-2.5 py-0.5 text-xs font-medium text-fg-muted ring-1 ring-line",
2653
- title: K !== 1 ? `1 ${T} = ${K} base currency` : void 0,
2653
+ title: K !== 1 ? `1 ${P} = ${K} base currency` : void 0,
2654
2654
  children: [
2655
- T,
2655
+ P,
2656
2656
  K !== 1 && /* @__PURE__ */ r("span", { className: "text-fg-muted/70", children: [
2657
2657
  "@ ",
2658
2658
  K
@@ -2677,45 +2677,45 @@ function hn() {
2677
2677
  }
2678
2678
  )
2679
2679
  ] }),
2680
- (C.error || b.error || h.error || A.error) && /* @__PURE__ */ e("div", { className: "rounded-lg bg-rose-50 p-4 text-sm text-rose-700 ring-1 ring-rose-200", children: ((ge = C.error ?? b.error ?? h.error ?? A.error) == null ? void 0 : ge.message) ?? l("common.errorOccurred") }),
2681
- /* @__PURE__ */ e(V, { children: /* @__PURE__ */ e("div", { className: "grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3", children: se.map((_) => /* @__PURE__ */ e(
2680
+ (C.error || b.error || g.error || _.error) && /* @__PURE__ */ e("div", { className: "rounded-lg bg-rose-50 p-4 text-sm text-rose-700 ring-1 ring-rose-200", children: ((ge = C.error ?? b.error ?? g.error ?? _.error) == null ? void 0 : ge.message) ?? l("common.errorOccurred") }),
2681
+ /* @__PURE__ */ e(V, { children: /* @__PURE__ */ e("div", { className: "grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3", children: ie.map((T) => /* @__PURE__ */ e(
2682
2682
  Vt,
2683
2683
  {
2684
- field: _,
2685
- value: o[_.name],
2686
- onChange: (Q) => k(_.name, Q),
2687
- readOnly: ce,
2684
+ field: T,
2685
+ value: o[T.name],
2686
+ onChange: (Q) => N(T.name, Q),
2687
+ readOnly: de,
2688
2688
  rowData: o,
2689
- currency: T
2689
+ currency: P
2690
2690
  },
2691
- _.name
2691
+ T.name
2692
2692
  )) }) }),
2693
- i.childTables.map((_) => /* @__PURE__ */ e(
2693
+ i.childTables.map((T) => /* @__PURE__ */ e(
2694
2694
  ur,
2695
2695
  {
2696
- tableDef: _,
2697
- rows: o[_.key] ?? [],
2698
- onChange: (Q) => q(_.key, Q),
2699
- readOnly: ce,
2700
- currency: T
2696
+ tableDef: T,
2697
+ rows: o[T.key] ?? [],
2698
+ onChange: (Q) => q(T.key, Q),
2699
+ readOnly: de,
2700
+ currency: P
2701
2701
  },
2702
- _.key
2702
+ T.key
2703
2703
  )),
2704
- le.length > 0 && /* @__PURE__ */ e(V, { title: l("common.totals"), children: /* @__PURE__ */ e("div", { className: "grid grid-cols-1 gap-4 sm:grid-cols-3", children: le.map((_) => /* @__PURE__ */ e(
2704
+ oe.length > 0 && /* @__PURE__ */ e(V, { title: l("common.totals"), children: /* @__PURE__ */ e("div", { className: "grid grid-cols-1 gap-4 sm:grid-cols-3", children: oe.map((T) => /* @__PURE__ */ e(
2705
2705
  Vt,
2706
2706
  {
2707
- field: _,
2708
- value: o[_.name],
2707
+ field: T,
2708
+ value: o[T.name],
2709
2709
  onChange: () => {
2710
2710
  },
2711
2711
  readOnly: !0,
2712
- currency: T
2712
+ currency: P
2713
2713
  },
2714
- _.name
2714
+ T.name
2715
2715
  )) }) })
2716
2716
  ] });
2717
2717
  }
2718
- function ue(t) {
2718
+ function me(t) {
2719
2719
  return t.toISOString().split("T")[0];
2720
2720
  }
2721
2721
  function Hn(t) {
@@ -2750,45 +2750,45 @@ const hr = [
2750
2750
  {
2751
2751
  label: "Today",
2752
2752
  range: () => {
2753
- const t = ue(/* @__PURE__ */ new Date());
2753
+ const t = me(/* @__PURE__ */ new Date());
2754
2754
  return [t, t];
2755
2755
  }
2756
2756
  },
2757
2757
  {
2758
2758
  label: "This Week",
2759
- range: () => [ue(Hn(/* @__PURE__ */ new Date())), ue(pr(/* @__PURE__ */ new Date()))]
2759
+ range: () => [me(Hn(/* @__PURE__ */ new Date())), me(pr(/* @__PURE__ */ new Date()))]
2760
2760
  },
2761
2761
  {
2762
2762
  label: "This Month",
2763
- range: () => [ue(gn(/* @__PURE__ */ new Date())), ue(vt(/* @__PURE__ */ new Date()))]
2763
+ range: () => [me(gn(/* @__PURE__ */ new Date())), me(vt(/* @__PURE__ */ new Date()))]
2764
2764
  },
2765
2765
  {
2766
2766
  label: "This Quarter",
2767
- range: () => [ue(Ut(/* @__PURE__ */ new Date())), ue(Gt(/* @__PURE__ */ new Date()))]
2767
+ range: () => [me(Ut(/* @__PURE__ */ new Date())), me(Gt(/* @__PURE__ */ new Date()))]
2768
2768
  },
2769
2769
  {
2770
2770
  label: "This Year",
2771
- range: () => [ue(yn(/* @__PURE__ */ new Date())), ue(Nt(/* @__PURE__ */ new Date()))]
2771
+ range: () => [me(yn(/* @__PURE__ */ new Date())), me(Nt(/* @__PURE__ */ new Date()))]
2772
2772
  },
2773
2773
  {
2774
2774
  label: "Last Month",
2775
2775
  range: () => {
2776
2776
  const t = /* @__PURE__ */ new Date(), n = new Date(t.getFullYear(), t.getMonth() - 1, 1);
2777
- return [ue(gn(n)), ue(vt(n))];
2777
+ return [me(gn(n)), me(vt(n))];
2778
2778
  }
2779
2779
  },
2780
2780
  {
2781
2781
  label: "Last Quarter",
2782
2782
  range: () => {
2783
2783
  const t = /* @__PURE__ */ new Date(), n = new Date(t.getFullYear(), t.getMonth() - 3, 1);
2784
- return [ue(Ut(n)), ue(Gt(n))];
2784
+ return [me(Ut(n)), me(Gt(n))];
2785
2785
  }
2786
2786
  },
2787
2787
  {
2788
2788
  label: "Last Year",
2789
2789
  range: () => {
2790
2790
  const t = new Date((/* @__PURE__ */ new Date()).getFullYear() - 1, 6, 1);
2791
- return [ue(yn(t)), ue(Nt(t))];
2791
+ return [me(yn(t)), me(Nt(t))];
2792
2792
  }
2793
2793
  }
2794
2794
  ];
@@ -2809,15 +2809,15 @@ function Dt({ onSelect: t }) {
2809
2809
  }
2810
2810
  function en({ onSelect: t }) {
2811
2811
  return /* @__PURE__ */ e("div", { className: "flex flex-wrap gap-1.5", children: [
2812
- { label: "Today", value: () => ue(/* @__PURE__ */ new Date()) },
2813
- { label: "End of This Month", value: () => ue(vt(/* @__PURE__ */ new Date())) },
2812
+ { label: "Today", value: () => me(/* @__PURE__ */ new Date()) },
2813
+ { label: "End of This Month", value: () => me(vt(/* @__PURE__ */ new Date())) },
2814
2814
  { label: "End of Last Month", value: () => {
2815
2815
  const a = /* @__PURE__ */ new Date();
2816
- return ue(vt(new Date(a.getFullYear(), a.getMonth() - 1, 1)));
2816
+ return me(vt(new Date(a.getFullYear(), a.getMonth() - 1, 1)));
2817
2817
  } },
2818
- { label: "End of This Quarter", value: () => ue(Gt(/* @__PURE__ */ new Date())) },
2819
- { label: "End of This Year", value: () => ue(Nt(/* @__PURE__ */ new Date())) },
2820
- { label: "End of Last Year", value: () => ue(Nt(new Date((/* @__PURE__ */ new Date()).getFullYear() - 1, 0, 1))) }
2818
+ { label: "End of This Quarter", value: () => me(Gt(/* @__PURE__ */ new Date())) },
2819
+ { label: "End of This Year", value: () => me(Nt(/* @__PURE__ */ new Date())) },
2820
+ { label: "End of Last Year", value: () => me(Nt(new Date((/* @__PURE__ */ new Date()).getFullYear() - 1, 0, 1))) }
2821
2821
  ].map((a) => /* @__PURE__ */ e(
2822
2822
  "button",
2823
2823
  {
@@ -2860,10 +2860,10 @@ function br(t) {
2860
2860
  }
2861
2861
  const xr = ["25", "50", "100", "200"];
2862
2862
  function vr() {
2863
- const { t } = Z(), { doctype: n } = ut(), a = Qn(n ?? ""), [s] = J("status", "All"), [l] = J("from", ""), [i] = J("to", ""), [c] = J("per_page", 50), [o] = J("page", 1), m = o - 1, d = Me(), u = (x) => d({ page: x === 0 ? null : x + 1 }), p = (x) => d({ status: x === "All" ? null : x, page: null }), v = (x) => d({ from: x || null, page: null }), w = (x) => d({ to: x || null, page: null }), g = (x) => d({ per_page: x, page: null }), y = Ce(() => {
2863
+ const { t } = Z(), { doctype: n } = ut(), a = Qn(n ?? ""), [s] = J("status", "All"), [l] = J("from", ""), [i] = J("to", ""), [c] = J("per_page", 50), [o] = J("page", 1), m = o - 1, d = Me(), u = (x) => d({ page: x === 0 ? null : x + 1 }), p = (x) => d({ status: x === "All" ? null : x, page: null }), v = (x) => d({ from: x || null, page: null }), D = (x) => d({ to: x || null, page: null }), h = (x) => d({ per_page: x, page: null }), y = Ce(() => {
2864
2864
  const x = {};
2865
2865
  return s !== "All" && (x.status = s), l && (x.from_date = l), i && (x.to_date = i), x.limit = c, x.offset = m * c, x;
2866
- }, [s, l, i, c, m]), { data: I, isLoading: L } = nr(n ?? "", y), C = (I == null ? void 0 : I.rows) ?? [], b = (I == null ? void 0 : I.total) ?? 0, h = Math.max(1, Math.ceil(b / c)), A = b === 0 ? 0 : m * c + 1, B = Math.min(b, (m + 1) * c), k = Ce(() => {
2866
+ }, [s, l, i, c, m]), { data: R, isLoading: B } = nr(n ?? "", y), C = (R == null ? void 0 : R.rows) ?? [], b = (R == null ? void 0 : R.total) ?? 0, g = Math.max(1, Math.ceil(b / c)), _ = b === 0 ? 0 : m * c + 1, w = Math.min(b, (m + 1) * c), N = Ce(() => {
2867
2867
  if (!a) return [];
2868
2868
  const x = zn(), z = (j) => {
2869
2869
  const U = j.split("_").map((Y) => Y.charAt(0).toUpperCase() + Y.slice(1)).join(" ");
@@ -2901,11 +2901,11 @@ function vr() {
2901
2901
  cell: (U) => {
2902
2902
  const Y = U.getValue();
2903
2903
  if (!Y) return "-";
2904
- const ce = br(U.row.original.party_type), T = ce ? $t(ce, String(Y)) : null;
2905
- return T ? /* @__PURE__ */ e(
2904
+ const de = br(U.row.original.party_type), P = de ? $t(de, String(Y)) : null;
2905
+ return P ? /* @__PURE__ */ e(
2906
2906
  ye,
2907
2907
  {
2908
- to: T,
2908
+ to: P,
2909
2909
  onClick: (K) => K.stopPropagation(),
2910
2910
  className: "text-brand transition-colors hover:text-brand/80 hover:underline",
2911
2911
  children: Y
@@ -2918,18 +2918,18 @@ function vr() {
2918
2918
  return x.accessor(j, {
2919
2919
  header: z(j),
2920
2920
  cell: (Y) => {
2921
- const ce = Y.getValue();
2922
- if (!ce) return "-";
2923
- const T = $t(U, String(ce));
2924
- return T ? /* @__PURE__ */ e(
2921
+ const de = Y.getValue();
2922
+ if (!de) return "-";
2923
+ const P = $t(U, String(de));
2924
+ return P ? /* @__PURE__ */ e(
2925
2925
  ye,
2926
2926
  {
2927
- to: T,
2927
+ to: P,
2928
2928
  onClick: (K) => K.stopPropagation(),
2929
2929
  className: "text-brand transition-colors hover:text-brand/80 hover:underline",
2930
- children: ce
2930
+ children: de
2931
2931
  }
2932
- ) : String(ce);
2932
+ ) : String(de);
2933
2933
  }
2934
2934
  });
2935
2935
  }
@@ -2942,11 +2942,11 @@ function vr() {
2942
2942
  });
2943
2943
  }, [a, t]), q = Fn({
2944
2944
  data: C,
2945
- columns: k,
2945
+ columns: N,
2946
2946
  getCoreRowModel: Mn()
2947
2947
  });
2948
2948
  return a ? /* @__PURE__ */ r("div", { className: "space-y-4", children: [
2949
- /* @__PURE__ */ e("div", { className: "flex items-center justify-end", children: /* @__PURE__ */ e(ye, { to: `/app/${a.slug}/new`, children: /* @__PURE__ */ e(X, { children: t("common.new") }) }) }),
2949
+ /* @__PURE__ */ e("div", { className: "flex items-center justify-end", children: /* @__PURE__ */ e(ye, { to: `/app/${a.slug}/new`, children: /* @__PURE__ */ e(ee, { children: t("common.new") }) }) }),
2950
2950
  /* @__PURE__ */ r("div", { className: "flex flex-wrap items-end gap-4", children: [
2951
2951
  /* @__PURE__ */ e(
2952
2952
  Ke,
@@ -2961,7 +2961,7 @@ function vr() {
2961
2961
  }
2962
2962
  ),
2963
2963
  /* @__PURE__ */ e(
2964
- pe,
2964
+ X,
2965
2965
  {
2966
2966
  label: t("fields.From Date", { defaultValue: "From Date" }),
2967
2967
  type: "date",
@@ -2970,17 +2970,17 @@ function vr() {
2970
2970
  }
2971
2971
  ),
2972
2972
  /* @__PURE__ */ e(
2973
- pe,
2973
+ X,
2974
2974
  {
2975
2975
  label: t("fields.To Date", { defaultValue: "To Date" }),
2976
2976
  type: "date",
2977
2977
  value: i,
2978
- onChange: (x) => w(x.target.value)
2978
+ onChange: (x) => D(x.target.value)
2979
2979
  }
2980
2980
  )
2981
2981
  ] }),
2982
2982
  /* @__PURE__ */ e(Dt, { onSelect: (x, z) => d({ from: x, to: z, page: null }) }),
2983
- L ? /* @__PURE__ */ e("p", { className: "text-fg-muted", children: t("common.loading") }) : C.length === 0 ? /* @__PURE__ */ e("p", { className: "py-8 text-center text-fg-muted", children: t("reports.noDocuments") }) : /* @__PURE__ */ r(Ne, { children: [
2983
+ B ? /* @__PURE__ */ e("p", { className: "text-fg-muted", children: t("common.loading") }) : C.length === 0 ? /* @__PURE__ */ e("p", { className: "py-8 text-center text-fg-muted", children: t("reports.noDocuments") }) : /* @__PURE__ */ r(Ne, { children: [
2984
2984
  /* @__PURE__ */ e("div", { className: "overflow-x-auto rounded-xl bg-surface ring-1 ring-line shadow-card", children: /* @__PURE__ */ r("table", { className: "min-w-full divide-y divide-line text-sm", children: [
2985
2985
  /* @__PURE__ */ e("thead", { className: "bg-surface-subtle", children: q.getHeaderGroups().map((x) => /* @__PURE__ */ e("tr", { children: x.headers.map((z) => /* @__PURE__ */ e(
2986
2986
  "th",
@@ -3003,9 +3003,9 @@ function vr() {
3003
3003
  t("common.showing"),
3004
3004
  " ",
3005
3005
  /* @__PURE__ */ r("span", { className: "font-medium text-fg", children: [
3006
- A,
3006
+ _,
3007
3007
  "–",
3008
- B
3008
+ w
3009
3009
  ] }),
3010
3010
  " ",
3011
3011
  t("common.of"),
@@ -3019,7 +3019,7 @@ function vr() {
3019
3019
  "select",
3020
3020
  {
3021
3021
  value: c,
3022
- onChange: (x) => g(Number(x.target.value)),
3022
+ onChange: (x) => h(Number(x.target.value)),
3023
3023
  className: "h-8 rounded-md bg-surface px-2 text-sm text-fg ring-1 ring-line transition-all focus:outline-none focus:ring-2 focus:ring-brand/30",
3024
3024
  children: xr.map((x) => /* @__PURE__ */ e("option", { value: x, children: x }, x))
3025
3025
  }
@@ -3041,13 +3041,13 @@ function vr() {
3041
3041
  " ",
3042
3042
  t("common.of"),
3043
3043
  " ",
3044
- /* @__PURE__ */ e("span", { className: "font-medium text-fg", children: h })
3044
+ /* @__PURE__ */ e("span", { className: "font-medium text-fg", children: g })
3045
3045
  ] }),
3046
3046
  /* @__PURE__ */ e(
3047
3047
  "button",
3048
3048
  {
3049
- onClick: () => u(Math.min(h - 1, m + 1)),
3050
- disabled: m >= h - 1,
3049
+ onClick: () => u(Math.min(g - 1, m + 1)),
3050
+ disabled: m >= g - 1,
3051
3051
  className: "rounded-md bg-surface px-3 py-1 text-sm text-fg ring-1 ring-line transition-colors hover:bg-surface-subtle disabled:cursor-not-allowed disabled:opacity-40",
3052
3052
  children: t("common.next")
3053
3053
  }
@@ -3063,7 +3063,7 @@ function vr() {
3063
3063
  const Nr = ["25", "50", "100", "200"];
3064
3064
  function Sr() {
3065
3065
  var b;
3066
- const { type: t } = ut(), n = Oe(), s = (b = dt().state) == null ? void 0 : b.notice, [l] = J("per_page", 50), [i] = J("page", 1), c = i - 1, o = Me(), m = (h) => o({ page: h === 0 ? null : h + 1 }), d = (h) => o({ per_page: h, page: null }), { data: u, isLoading: p } = ie({
3066
+ const { type: t } = ut(), n = Oe(), s = (b = dt().state) == null ? void 0 : b.notice, [l] = J("per_page", 50), [i] = J("page", 1), c = i - 1, o = Me(), m = (g) => o({ page: g === 0 ? null : g + 1 }), d = (g) => o({ per_page: g, page: null }), { data: u, isLoading: p } = le({
3067
3067
  queryKey: ["masters", t, c, l],
3068
3068
  queryFn: () => O.listMasters(t, {
3069
3069
  include_disabled: 1,
@@ -3071,16 +3071,16 @@ function Sr() {
3071
3071
  offset: c * l
3072
3072
  }),
3073
3073
  enabled: !!t
3074
- }), v = (u == null ? void 0 : u.rows) ?? [], w = (u == null ? void 0 : u.total) ?? 0, g = Math.max(1, Math.ceil(w / l)), y = w === 0 ? 0 : c * l + 1, I = Math.min(w, (c + 1) * l), L = Ce(() => {
3074
+ }), v = (u == null ? void 0 : u.rows) ?? [], D = (u == null ? void 0 : u.total) ?? 0, h = Math.max(1, Math.ceil(D / l)), y = D === 0 ? 0 : c * l + 1, R = Math.min(D, (c + 1) * l), B = Ce(() => {
3075
3075
  if (!v || v.length === 0) return [];
3076
- const h = zn();
3076
+ const g = zn();
3077
3077
  return Object.keys(v[0]).map(
3078
- (B) => h.accessor(B, {
3079
- header: B.split("_").map((k) => k.charAt(0).toUpperCase() + k.slice(1)).join(" "),
3080
- cell: (k) => {
3081
- const q = k.getValue();
3082
- if (B === "name") {
3083
- const x = k.row.original.disabled === 1;
3078
+ (w) => g.accessor(w, {
3079
+ header: w.split("_").map((N) => N.charAt(0).toUpperCase() + N.slice(1)).join(" "),
3080
+ cell: (N) => {
3081
+ const q = N.getValue();
3082
+ if (w === "name") {
3083
+ const x = N.row.original.disabled === 1;
3084
3084
  return /* @__PURE__ */ e(
3085
3085
  ye,
3086
3086
  {
@@ -3090,42 +3090,42 @@ function Sr() {
3090
3090
  }
3091
3091
  );
3092
3092
  }
3093
- return B === "disabled" ? q === 1 ? "Disabled" : "Active" : q ?? "-";
3093
+ return w === "disabled" ? q === 1 ? "Disabled" : "Active" : q ?? "-";
3094
3094
  }
3095
3095
  })
3096
3096
  );
3097
3097
  }, [v, t]), C = Fn({
3098
3098
  data: v,
3099
- columns: L,
3099
+ columns: B,
3100
3100
  getCoreRowModel: Mn()
3101
3101
  });
3102
3102
  return /* @__PURE__ */ r("div", { className: "space-y-4", children: [
3103
3103
  s && /* @__PURE__ */ e("div", { className: "rounded-md bg-amber-50 px-4 py-3 text-sm text-amber-800", children: s }),
3104
- /* @__PURE__ */ e("div", { className: "flex items-center justify-end", children: /* @__PURE__ */ e(ye, { to: `/masters/${t}/new`, children: /* @__PURE__ */ e(X, { children: "New" }) }) }),
3104
+ /* @__PURE__ */ e("div", { className: "flex items-center justify-end", children: /* @__PURE__ */ e(ye, { to: `/masters/${t}/new`, children: /* @__PURE__ */ e(ee, { children: "New" }) }) }),
3105
3105
  p ? /* @__PURE__ */ e("p", { className: "text-fg-muted", children: "Loading..." }) : v.length === 0 ? /* @__PURE__ */ e("p", { className: "py-8 text-center text-fg-muted", children: "No records found" }) : /* @__PURE__ */ r(Ne, { children: [
3106
3106
  /* @__PURE__ */ e("div", { className: "overflow-x-auto rounded-xl bg-surface ring-1 ring-line shadow-card", children: /* @__PURE__ */ r("table", { className: "min-w-full divide-y divide-line text-sm", children: [
3107
- /* @__PURE__ */ e("thead", { className: "bg-surface-subtle", children: C.getHeaderGroups().map((h) => /* @__PURE__ */ e("tr", { children: h.headers.map((A) => /* @__PURE__ */ e(
3107
+ /* @__PURE__ */ e("thead", { className: "bg-surface-subtle", children: C.getHeaderGroups().map((g) => /* @__PURE__ */ e("tr", { children: g.headers.map((_) => /* @__PURE__ */ e(
3108
3108
  "th",
3109
3109
  {
3110
3110
  className: "px-4 py-3 text-left text-xs font-medium uppercase tracking-wide text-fg-muted",
3111
- children: A.isPlaceholder ? null : bt(
3112
- A.column.columnDef.header,
3113
- A.getContext()
3111
+ children: _.isPlaceholder ? null : bt(
3112
+ _.column.columnDef.header,
3113
+ _.getContext()
3114
3114
  )
3115
3115
  },
3116
- A.id
3117
- )) }, h.id)) }),
3118
- /* @__PURE__ */ e("tbody", { className: "divide-y divide-line", children: C.getRowModel().rows.map((h) => /* @__PURE__ */ e(
3116
+ _.id
3117
+ )) }, g.id)) }),
3118
+ /* @__PURE__ */ e("tbody", { className: "divide-y divide-line", children: C.getRowModel().rows.map((g) => /* @__PURE__ */ e(
3119
3119
  "tr",
3120
3120
  {
3121
- className: h.original.disabled === 1 ? "cursor-pointer bg-surface-subtle text-fg-muted transition-colors hover:bg-surface-subtle/80" : "cursor-pointer text-fg transition-colors hover:bg-surface-subtle",
3122
- onClick: () => n(`/masters/${t}/${h.original.name}`),
3123
- children: h.getVisibleCells().map((A) => /* @__PURE__ */ e("td", { className: "px-4 py-2.5", children: bt(
3124
- A.column.columnDef.cell,
3125
- A.getContext()
3126
- ) }, A.id))
3121
+ className: g.original.disabled === 1 ? "cursor-pointer bg-surface-subtle text-fg-muted transition-colors hover:bg-surface-subtle/80" : "cursor-pointer text-fg transition-colors hover:bg-surface-subtle",
3122
+ onClick: () => n(`/masters/${t}/${g.original.name}`),
3123
+ children: g.getVisibleCells().map((_) => /* @__PURE__ */ e("td", { className: "px-4 py-2.5", children: bt(
3124
+ _.column.columnDef.cell,
3125
+ _.getContext()
3126
+ ) }, _.id))
3127
3127
  },
3128
- h.id
3128
+ g.id
3129
3129
  )) })
3130
3130
  ] }) }),
3131
3131
  /* @__PURE__ */ r("div", { className: "flex flex-wrap items-center justify-between gap-3 text-sm text-fg-muted", children: [
@@ -3134,11 +3134,11 @@ function Sr() {
3134
3134
  /* @__PURE__ */ r("span", { className: "font-medium text-fg", children: [
3135
3135
  y,
3136
3136
  "–",
3137
- I
3137
+ R
3138
3138
  ] }),
3139
3139
  " ",
3140
3140
  "of ",
3141
- /* @__PURE__ */ e("span", { className: "font-medium text-fg", children: w })
3141
+ /* @__PURE__ */ e("span", { className: "font-medium text-fg", children: D })
3142
3142
  ] }),
3143
3143
  /* @__PURE__ */ r("div", { className: "flex items-center gap-2", children: [
3144
3144
  /* @__PURE__ */ r("label", { className: "flex items-center gap-1.5", children: [
@@ -3147,9 +3147,9 @@ function Sr() {
3147
3147
  "select",
3148
3148
  {
3149
3149
  value: l,
3150
- onChange: (h) => d(Number(h.target.value)),
3150
+ onChange: (g) => d(Number(g.target.value)),
3151
3151
  className: "h-8 rounded-md bg-surface px-2 text-sm text-fg ring-1 ring-line transition-all focus:outline-none focus:ring-2 focus:ring-brand/30",
3152
- children: Nr.map((h) => /* @__PURE__ */ e("option", { value: h, children: h }, h))
3152
+ children: Nr.map((g) => /* @__PURE__ */ e("option", { value: g, children: g }, g))
3153
3153
  }
3154
3154
  )
3155
3155
  ] }),
@@ -3167,13 +3167,13 @@ function Sr() {
3167
3167
  /* @__PURE__ */ e("span", { className: "font-medium text-fg", children: c + 1 }),
3168
3168
  " of",
3169
3169
  " ",
3170
- /* @__PURE__ */ e("span", { className: "font-medium text-fg", children: g })
3170
+ /* @__PURE__ */ e("span", { className: "font-medium text-fg", children: h })
3171
3171
  ] }),
3172
3172
  /* @__PURE__ */ e(
3173
3173
  "button",
3174
3174
  {
3175
- onClick: () => m(Math.min(g - 1, c + 1)),
3176
- disabled: c >= g - 1,
3175
+ onClick: () => m(Math.min(h - 1, c + 1)),
3176
+ disabled: c >= h - 1,
3177
3177
  className: "rounded-md bg-surface px-3 py-1 text-sm text-fg ring-1 ring-line transition-colors hover:bg-surface-subtle disabled:cursor-not-allowed disabled:opacity-40",
3178
3178
  children: "Next"
3179
3179
  }
@@ -3246,41 +3246,41 @@ const kr = {
3246
3246
  company: "Company"
3247
3247
  }, bn = /* @__PURE__ */ new Set(["customer", "supplier", "item", "warehouse"]);
3248
3248
  function xn() {
3249
- var B;
3250
- const { type: t, name: n } = ut(), a = Oe(), s = We(), { t: l } = Z(), i = !n || n === "new", c = wr[t ?? ""] ?? t ?? "", o = l(`masters.${t}.one`, { defaultValue: c }), m = kr[t ?? ""] ?? [], d = (k) => l(`fields.${k.label}`, { defaultValue: k.label }), [u, p] = N({}), { data: v, isLoading: w } = ie({
3249
+ var w;
3250
+ const { type: t, name: n } = ut(), a = Oe(), s = We(), { t: l } = Z(), i = !n || n === "new", c = wr[t ?? ""] ?? t ?? "", o = l(`masters.${t}.one`, { defaultValue: c }), m = kr[t ?? ""] ?? [], d = (N) => l(`fields.${N.label}`, { defaultValue: N.label }), [u, p] = S({}), { data: v, isLoading: D } = le({
3251
3251
  queryKey: ["master", t, n],
3252
3252
  queryFn: () => O.getMaster(t, n),
3253
3253
  enabled: !!t && !!n && !i
3254
3254
  });
3255
- re(() => {
3255
+ se(() => {
3256
3256
  if (i) {
3257
- const k = {};
3257
+ const N = {};
3258
3258
  m.forEach((q) => {
3259
- k[q.name] = q.default ?? "";
3260
- }), p(k);
3259
+ N[q.name] = q.default ?? "";
3260
+ }), p(N);
3261
3261
  } else v && p(v);
3262
3262
  }, [i, v, m]);
3263
- const g = me({
3264
- mutationFn: (k) => O.createMaster(t, k),
3265
- onSuccess: (k) => {
3266
- s.invalidateQueries({ queryKey: ["masters", t] }), a(`/masters/${t}/${k.name}`, { replace: !0 });
3263
+ const h = pe({
3264
+ mutationFn: (N) => O.createMaster(t, N),
3265
+ onSuccess: (N) => {
3266
+ s.invalidateQueries({ queryKey: ["masters", t] }), a(`/masters/${t}/${N.name}`, { replace: !0 });
3267
3267
  }
3268
- }), y = me({
3269
- mutationFn: (k) => O.updateMaster(t, n, k),
3268
+ }), y = pe({
3269
+ mutationFn: (N) => O.updateMaster(t, n, N),
3270
3270
  onSuccess: () => {
3271
3271
  s.invalidateQueries({ queryKey: ["master", t, n] }), s.invalidateQueries({ queryKey: ["masters", t] });
3272
3272
  }
3273
- }), I = me({
3273
+ }), R = pe({
3274
3274
  mutationFn: () => O.deleteMaster(t, n),
3275
- onSuccess: (k) => {
3276
- if (s.invalidateQueries({ queryKey: ["masters", t] }), (k == null ? void 0 : k.status) === "disabled") {
3275
+ onSuccess: (N) => {
3276
+ if (s.invalidateQueries({ queryKey: ["masters", t] }), (N == null ? void 0 : N.status) === "disabled") {
3277
3277
  a(`/masters/${t}`, {
3278
3278
  replace: !0,
3279
3279
  state: {
3280
3280
  notice: l("masterForm.disabledOnDelete", {
3281
3281
  label: o,
3282
3282
  name: n,
3283
- reason: k.reason ?? "other records"
3283
+ reason: N.reason ?? "other records"
3284
3284
  })
3285
3285
  }
3286
3286
  });
@@ -3288,133 +3288,133 @@ function xn() {
3288
3288
  }
3289
3289
  a(`/masters/${t}`, { replace: !0 });
3290
3290
  }
3291
- }), L = () => {
3292
- if (A.length > 0) return;
3293
- const k = t === "company" && !u.name ? { ...u, name: u.company_name } : u;
3294
- i ? g.mutate(k) : y.mutate(k);
3291
+ }), B = () => {
3292
+ if (_.length > 0) return;
3293
+ const N = t === "company" && !u.name ? { ...u, name: u.company_name } : u;
3294
+ i ? h.mutate(N) : y.mutate(N);
3295
3295
  }, C = () => {
3296
- window.confirm(l("masterForm.deleteConfirm", { label: o })) && I.mutate();
3297
- }, b = (k, q) => {
3298
- p((x) => ({ ...x, [k]: q }));
3296
+ window.confirm(l("masterForm.deleteConfirm", { label: o })) && R.mutate();
3297
+ }, b = (N, q) => {
3298
+ p((x) => ({ ...x, [N]: q }));
3299
3299
  };
3300
- if (!i && w)
3300
+ if (!i && D)
3301
3301
  return /* @__PURE__ */ e("p", { className: "text-fg-muted", children: l("common.loading") });
3302
- const h = g.isPending || y.isPending, A = m.filter((k) => {
3303
- if (!k.required || k.readOnly || i && k.name === "name" && bn.has(t ?? "")) return !1;
3304
- const q = u[k.name];
3302
+ const g = h.isPending || y.isPending, _ = m.filter((N) => {
3303
+ if (!N.required || N.readOnly || i && N.name === "name" && bn.has(t ?? "")) return !1;
3304
+ const q = u[N.name];
3305
3305
  return q == null || String(q).trim() === "";
3306
3306
  });
3307
3307
  return /* @__PURE__ */ r("div", { className: "space-y-6", children: [
3308
3308
  /* @__PURE__ */ e("div", { className: "flex items-center justify-end", children: /* @__PURE__ */ r("div", { className: "flex gap-2", children: [
3309
- /* @__PURE__ */ e(X, { onClick: L, disabled: h || A.length > 0, children: l(h ? "common.saving" : "common.save") }),
3309
+ /* @__PURE__ */ e(ee, { onClick: B, disabled: g || _.length > 0, children: l(g ? "common.saving" : "common.save") }),
3310
3310
  !i && /* @__PURE__ */ e(
3311
- X,
3311
+ ee,
3312
3312
  {
3313
3313
  variant: "danger",
3314
3314
  onClick: C,
3315
- disabled: I.isPending,
3315
+ disabled: R.isPending,
3316
3316
  children: l("common.delete")
3317
3317
  }
3318
3318
  )
3319
3319
  ] }) }),
3320
- (g.error || y.error || I.error) && /* @__PURE__ */ e("div", { className: "rounded-lg bg-rose-50 p-4 text-sm text-rose-700 ring-1 ring-rose-200", children: ((B = g.error ?? y.error ?? I.error) == null ? void 0 : B.message) ?? l("common.errorOccurred") }),
3321
- A.length > 0 && /* @__PURE__ */ e("div", { className: "rounded-lg bg-amber-50 p-4 text-sm text-amber-800 ring-1 ring-amber-200", children: l("masterForm.required", { fields: A.map(d).join(", ") }) }),
3320
+ (h.error || y.error || R.error) && /* @__PURE__ */ e("div", { className: "rounded-lg bg-rose-50 p-4 text-sm text-rose-700 ring-1 ring-rose-200", children: ((w = h.error ?? y.error ?? R.error) == null ? void 0 : w.message) ?? l("common.errorOccurred") }),
3321
+ _.length > 0 && /* @__PURE__ */ e("div", { className: "rounded-lg bg-amber-50 p-4 text-sm text-amber-800 ring-1 ring-amber-200", children: l("masterForm.required", { fields: _.map(d).join(", ") }) }),
3322
3322
  u.disabled === 1 && /* @__PURE__ */ e("div", { className: "rounded-lg bg-amber-50 p-4 text-sm text-amber-800 ring-1 ring-amber-200", children: l("masterForm.disabledNotice", { label: o }) }),
3323
- /* @__PURE__ */ e(V, { children: /* @__PURE__ */ e("div", { className: "grid grid-cols-1 gap-4 sm:grid-cols-2", children: m.map((k) => {
3324
- const x = k.name === "name" && !i || k.readOnly, z = k.required && !(i && k.name === "name" && bn.has(t ?? ""));
3325
- if (k.type === "select" && k.options)
3323
+ /* @__PURE__ */ e(V, { children: /* @__PURE__ */ e("div", { className: "grid grid-cols-1 gap-4 sm:grid-cols-2", children: m.map((N) => {
3324
+ const x = N.name === "name" && !i || N.readOnly, z = N.required && !(i && N.name === "name" && bn.has(t ?? ""));
3325
+ if (N.type === "select" && N.options)
3326
3326
  return /* @__PURE__ */ e("div", { children: /* @__PURE__ */ e(
3327
3327
  Ke,
3328
3328
  {
3329
- label: d(k),
3330
- options: k.options,
3331
- value: u[k.name] ?? "",
3329
+ label: d(N),
3330
+ options: N.options,
3331
+ value: u[N.name] ?? "",
3332
3332
  required: z,
3333
3333
  disabled: x,
3334
- onChange: (U) => b(k.name, U.target.value)
3334
+ onChange: (U) => b(N.name, U.target.value)
3335
3335
  }
3336
- ) }, k.name);
3337
- if (k.type === "textarea")
3336
+ ) }, N.name);
3337
+ if (N.type === "textarea")
3338
3338
  return /* @__PURE__ */ r("div", { className: "sm:col-span-2", children: [
3339
- /* @__PURE__ */ e("label", { className: "mb-1.5 block text-sm font-medium text-fg", children: d(k) }),
3339
+ /* @__PURE__ */ e("label", { className: "mb-1.5 block text-sm font-medium text-fg", children: d(N) }),
3340
3340
  /* @__PURE__ */ e(
3341
3341
  "textarea",
3342
3342
  {
3343
3343
  className: "block w-full rounded-lg bg-surface px-3 py-2 text-sm text-fg ring-1 ring-line transition-all placeholder:text-fg-muted/70 focus:outline-none focus:ring-2 focus:ring-brand/30 disabled:bg-surface-subtle disabled:text-fg-muted",
3344
3344
  rows: 3,
3345
- value: u[k.name] ?? "",
3345
+ value: u[N.name] ?? "",
3346
3346
  required: z,
3347
3347
  readOnly: x,
3348
3348
  disabled: x,
3349
- onChange: (U) => b(k.name, U.target.value)
3349
+ onChange: (U) => b(N.name, U.target.value)
3350
3350
  }
3351
3351
  )
3352
- ] }, k.name);
3353
- const j = k.type === "number" || k.type === "currency" ? "number" : k.type === "date" ? "date" : "text";
3352
+ ] }, N.name);
3353
+ const j = N.type === "number" || N.type === "currency" ? "number" : N.type === "date" ? "date" : "text";
3354
3354
  return /* @__PURE__ */ e(
3355
- pe,
3355
+ X,
3356
3356
  {
3357
- label: d(k),
3357
+ label: d(N),
3358
3358
  type: j,
3359
- step: k.type === "currency" ? "0.01" : void 0,
3359
+ step: N.type === "currency" ? "0.01" : void 0,
3360
3360
  required: z,
3361
3361
  readOnly: x,
3362
3362
  disabled: x,
3363
- value: u[k.name] ?? "",
3363
+ value: u[N.name] ?? "",
3364
3364
  onChange: (U) => b(
3365
- k.name,
3365
+ N.name,
3366
3366
  j === "number" ? parseFloat(U.target.value) || 0 : U.target.value
3367
3367
  )
3368
3368
  },
3369
- k.name
3369
+ N.name
3370
3370
  );
3371
3371
  }) }) })
3372
3372
  ] });
3373
3373
  }
3374
3374
  function Cr(t) {
3375
- const { data: n, isLoading: a, error: s, refetch: l } = ie({
3375
+ const { data: n, isLoading: a, error: s, refetch: l } = le({
3376
3376
  queryKey: ["report", "trial-balance", t],
3377
3377
  queryFn: () => O.trialBalance(t)
3378
3378
  });
3379
3379
  return { data: n, isLoading: a, error: s, refetch: l };
3380
3380
  }
3381
3381
  function Dr(t) {
3382
- const { data: n, isLoading: a, error: s, refetch: l } = ie({
3382
+ const { data: n, isLoading: a, error: s, refetch: l } = le({
3383
3383
  queryKey: ["report", "general-ledger", t],
3384
3384
  queryFn: () => O.generalLedger(t)
3385
3385
  });
3386
3386
  return { data: n, isLoading: a, error: s, refetch: l };
3387
3387
  }
3388
3388
  function _r(t) {
3389
- const { data: n, isLoading: a, error: s, refetch: l } = ie({
3389
+ const { data: n, isLoading: a, error: s, refetch: l } = le({
3390
3390
  queryKey: ["report", "stock-balance", t],
3391
3391
  queryFn: () => O.stockBalance(t)
3392
3392
  });
3393
3393
  return { data: n, isLoading: a, error: s, refetch: l };
3394
3394
  }
3395
3395
  function Ar(t) {
3396
- const { data: n, isLoading: a, error: s, refetch: l } = ie({
3396
+ const { data: n, isLoading: a, error: s, refetch: l } = le({
3397
3397
  queryKey: ["report", "profit-and-loss", t],
3398
3398
  queryFn: () => O.profitAndLoss(t)
3399
3399
  });
3400
3400
  return { data: n, isLoading: a, error: s, refetch: l };
3401
3401
  }
3402
3402
  function Tr(t) {
3403
- const { data: n, isLoading: a, error: s, refetch: l } = ie({
3403
+ const { data: n, isLoading: a, error: s, refetch: l } = le({
3404
3404
  queryKey: ["report", "balance-sheet", t],
3405
3405
  queryFn: () => O.balanceSheet(t)
3406
3406
  });
3407
3407
  return { data: n, isLoading: a, error: s, refetch: l };
3408
3408
  }
3409
3409
  function Pr(t) {
3410
- const { data: n, isLoading: a, error: s, refetch: l } = ie({
3410
+ const { data: n, isLoading: a, error: s, refetch: l } = le({
3411
3411
  queryKey: ["report", "ar-aging", t],
3412
3412
  queryFn: () => O.arAging(t)
3413
3413
  });
3414
3414
  return { data: n, isLoading: a, error: s, refetch: l };
3415
3415
  }
3416
3416
  function Rr(t) {
3417
- const { data: n, isLoading: a, error: s, refetch: l } = ie({
3417
+ const { data: n, isLoading: a, error: s, refetch: l } = le({
3418
3418
  queryKey: ["report", "ap-aging", t],
3419
3419
  queryFn: () => O.apAging(t)
3420
3420
  });
@@ -3427,14 +3427,14 @@ function ke({
3427
3427
  linkDoctype: s,
3428
3428
  readOnly: l
3429
3429
  }) {
3430
- const [i, c] = N(n ?? ""), [o, m] = N([]), [d, u] = N(!1), [p, v] = N(!1), [w, g] = N({}), y = H(null), I = H(null), L = H(null), C = H(null), b = H(!1);
3431
- re(() => {
3430
+ const [i, c] = S(n ?? ""), [o, m] = S([]), [d, u] = S(!1), [p, v] = S(!1), [D, h] = S({}), y = H(null), R = H(null), B = H(null), C = H(null), b = H(!1);
3431
+ se(() => {
3432
3432
  c(n ?? "");
3433
3433
  }, [n]);
3434
- const h = we(() => {
3434
+ const g = we(() => {
3435
3435
  if (C.current) {
3436
3436
  const x = C.current.getBoundingClientRect();
3437
- g({
3437
+ h({
3438
3438
  position: "fixed",
3439
3439
  top: x.bottom + 4,
3440
3440
  left: x.left,
@@ -3442,7 +3442,7 @@ function ke({
3442
3442
  zIndex: 9999
3443
3443
  });
3444
3444
  }
3445
- }, []), A = we(
3445
+ }, []), _ = we(
3446
3446
  (x) => {
3447
3447
  y.current && clearTimeout(y.current), y.current = setTimeout(async () => {
3448
3448
  v(!0);
@@ -3457,10 +3457,10 @@ function ke({
3457
3457
  }, 300);
3458
3458
  },
3459
3459
  [s]
3460
- ), B = (x) => {
3460
+ ), w = (x) => {
3461
3461
  const z = x.target.value;
3462
- c(z), A(z);
3463
- }, k = (x) => {
3462
+ c(z), _(z);
3463
+ }, N = (x) => {
3464
3464
  const z = x.name ?? x.id ?? String(x);
3465
3465
  c(z), a(z), u(!1), m([]);
3466
3466
  }, q = () => {
@@ -3472,17 +3472,17 @@ function ke({
3472
3472
  u(!1), i !== n && a(i);
3473
3473
  }, 150);
3474
3474
  };
3475
- return re(() => {
3475
+ return se(() => {
3476
3476
  const x = (z) => {
3477
3477
  var U, Y;
3478
3478
  const j = z.target;
3479
- (U = I.current) != null && U.contains(j) || (Y = L.current) != null && Y.contains(j) || u(!1);
3479
+ (U = R.current) != null && U.contains(j) || (Y = B.current) != null && Y.contains(j) || u(!1);
3480
3480
  };
3481
3481
  return document.addEventListener("mousedown", x), () => document.removeEventListener("mousedown", x);
3482
3482
  }, []), l ? /* @__PURE__ */ r("div", { children: [
3483
3483
  t && /* @__PURE__ */ e("span", { className: "mb-1.5 block text-sm font-medium text-fg", children: t }),
3484
3484
  /* @__PURE__ */ e("span", { className: "text-sm text-fg", children: n || "—" })
3485
- ] }) : /* @__PURE__ */ r("div", { ref: I, className: "relative", children: [
3485
+ ] }) : /* @__PURE__ */ r("div", { ref: R, className: "relative", children: [
3486
3486
  t && /* @__PURE__ */ e("label", { className: "mb-1.5 block text-sm font-medium text-fg", children: t }),
3487
3487
  /* @__PURE__ */ e(
3488
3488
  "input",
@@ -3490,9 +3490,9 @@ function ke({
3490
3490
  ref: C,
3491
3491
  type: "text",
3492
3492
  value: i,
3493
- onChange: B,
3493
+ onChange: w,
3494
3494
  onFocus: () => {
3495
- h(), A(i);
3495
+ g(), _(i);
3496
3496
  },
3497
3497
  onBlur: q,
3498
3498
  placeholder: `Search ${s}...`,
@@ -3503,7 +3503,7 @@ function ke({
3503
3503
  }
3504
3504
  ),
3505
3505
  d && o.length > 0 && Ca(
3506
- /* @__PURE__ */ e("div", { ref: L, style: w, className: "max-h-48 overflow-y-auto rounded-lg bg-surface ring-1 ring-line shadow-card-hover", children: o.map((x, z) => {
3506
+ /* @__PURE__ */ e("div", { ref: B, style: D, className: "max-h-48 overflow-y-auto rounded-lg bg-surface ring-1 ring-line shadow-card-hover", children: o.map((x, z) => {
3507
3507
  const j = x.name ?? x.id ?? String(x);
3508
3508
  return /* @__PURE__ */ e(
3509
3509
  "button",
@@ -3512,7 +3512,7 @@ function ke({
3512
3512
  onMouseDown: () => {
3513
3513
  b.current = !0;
3514
3514
  },
3515
- onClick: () => k(x),
3515
+ onClick: () => N(x),
3516
3516
  className: "block w-full px-3 py-1.5 text-left text-sm text-fg transition-colors hover:bg-surface-subtle",
3517
3517
  children: j
3518
3518
  },
@@ -3524,16 +3524,16 @@ function ke({
3524
3524
  ] });
3525
3525
  }
3526
3526
  function Ir() {
3527
- const { t } = Z(), [n] = J("company", ""), [a] = J("from", ""), [s] = J("to", ""), l = Me(), [i, c] = N(n), [o, m] = N(a), [d, u] = N(s), p = Fe(i), v = (b) => Le(b, p), w = Ce(() => {
3527
+ const { t } = Z(), [n] = J("company", ""), [a] = J("from", ""), [s] = J("to", ""), l = Me(), [i, c] = S(n), [o, m] = S(a), [d, u] = S(s), p = Fe(i), v = (b) => Le(b, p), D = Ce(() => {
3528
3528
  const b = {};
3529
3529
  return n && (b.company = n), a && (b.from_date = a), s && (b.to_date = s), b;
3530
- }, [n, a, s]), { data: g, isLoading: y, refetch: I } = Cr(w), L = () => {
3530
+ }, [n, a, s]), { data: h, isLoading: y, refetch: R } = Cr(D), B = () => {
3531
3531
  l({
3532
3532
  company: i || null,
3533
3533
  from: o || null,
3534
3534
  to: d || null
3535
- }), I();
3536
- }, C = g ? g.difference === 0 : !1;
3535
+ }), R();
3536
+ }, C = h ? h.difference === 0 : !1;
3537
3537
  return /* @__PURE__ */ r("div", { className: "space-y-4", children: [
3538
3538
  /* @__PURE__ */ r("div", { className: "flex flex-wrap items-end gap-4", children: [
3539
3539
  /* @__PURE__ */ e(
@@ -3547,7 +3547,7 @@ function Ir() {
3547
3547
  }
3548
3548
  ),
3549
3549
  /* @__PURE__ */ e(
3550
- pe,
3550
+ X,
3551
3551
  {
3552
3552
  label: t("fields.From Date", { defaultValue: "From Date" }),
3553
3553
  type: "date",
@@ -3556,7 +3556,7 @@ function Ir() {
3556
3556
  }
3557
3557
  ),
3558
3558
  /* @__PURE__ */ e(
3559
- pe,
3559
+ X,
3560
3560
  {
3561
3561
  label: t("fields.To Date", { defaultValue: "To Date" }),
3562
3562
  type: "date",
@@ -3564,12 +3564,12 @@ function Ir() {
3564
3564
  onChange: (b) => u(b.target.value)
3565
3565
  }
3566
3566
  ),
3567
- /* @__PURE__ */ e(X, { onClick: L, children: t("common.apply") })
3567
+ /* @__PURE__ */ e(ee, { onClick: B, children: t("common.apply") })
3568
3568
  ] }),
3569
- /* @__PURE__ */ e(Dt, { onSelect: (b, h) => {
3570
- m(b), u(h), l({ from: b, to: h });
3569
+ /* @__PURE__ */ e(Dt, { onSelect: (b, g) => {
3570
+ m(b), u(g), l({ from: b, to: g });
3571
3571
  } }),
3572
- y ? /* @__PURE__ */ e("p", { className: "text-fg-muted", children: t("common.loading") }) : !g || !g.rows || g.rows.length === 0 ? /* @__PURE__ */ e("p", { className: "py-8 text-center text-fg-muted", children: t("reports.noData") }) : /* @__PURE__ */ r(V, { children: [
3572
+ y ? /* @__PURE__ */ e("p", { className: "text-fg-muted", children: t("common.loading") }) : !h || !h.rows || h.rows.length === 0 ? /* @__PURE__ */ e("p", { className: "py-8 text-center text-fg-muted", children: t("reports.noData") }) : /* @__PURE__ */ r(V, { children: [
3573
3573
  /* @__PURE__ */ e("div", { className: "overflow-x-auto", children: /* @__PURE__ */ r("table", { className: "min-w-full divide-y divide-line text-sm", children: [
3574
3574
  /* @__PURE__ */ e("thead", { className: "bg-surface-subtle", children: /* @__PURE__ */ r("tr", { children: [
3575
3575
  /* @__PURE__ */ e("th", { className: "px-4 py-3 text-left text-xs font-medium uppercase tracking-wide text-fg-muted", children: t("fields.Account", { defaultValue: "Account" }) }),
@@ -3577,17 +3577,17 @@ function Ir() {
3577
3577
  /* @__PURE__ */ e("th", { className: "px-4 py-3 text-right text-xs font-medium uppercase tracking-wide text-fg-muted", children: t("fields.Credit", { defaultValue: "Credit" }) }),
3578
3578
  /* @__PURE__ */ e("th", { className: "px-4 py-3 text-right text-xs font-medium uppercase tracking-wide text-fg-muted", children: t("fields.Balance", { defaultValue: "Balance" }) })
3579
3579
  ] }) }),
3580
- /* @__PURE__ */ e("tbody", { className: "divide-y divide-line", children: g.rows.map((b, h) => /* @__PURE__ */ r("tr", { className: "transition-colors hover:bg-surface-subtle", children: [
3580
+ /* @__PURE__ */ e("tbody", { className: "divide-y divide-line", children: h.rows.map((b, g) => /* @__PURE__ */ r("tr", { className: "transition-colors hover:bg-surface-subtle", children: [
3581
3581
  /* @__PURE__ */ e("td", { className: "px-4 py-2 text-fg", children: b.account }),
3582
3582
  /* @__PURE__ */ e("td", { className: "px-4 py-2 text-right tabular-nums text-fg", children: v(b.debit) }),
3583
3583
  /* @__PURE__ */ e("td", { className: "px-4 py-2 text-right tabular-nums text-fg", children: v(b.credit) }),
3584
3584
  /* @__PURE__ */ e("td", { className: "px-4 py-2 text-right font-medium tabular-nums text-fg", children: v(b.balance) })
3585
- ] }, h)) }),
3585
+ ] }, g)) }),
3586
3586
  /* @__PURE__ */ e("tfoot", { className: "border-t border-line bg-surface-subtle font-semibold", children: /* @__PURE__ */ r("tr", { children: [
3587
3587
  /* @__PURE__ */ e("td", { className: "px-4 py-3 text-fg", children: t("common.total") }),
3588
- /* @__PURE__ */ e("td", { className: "px-4 py-3 text-right tabular-nums text-fg", children: v(g.total_debit) }),
3589
- /* @__PURE__ */ e("td", { className: "px-4 py-3 text-right tabular-nums text-fg", children: v(g.total_credit) }),
3590
- /* @__PURE__ */ e("td", { className: "px-4 py-3 text-right tabular-nums text-fg", children: v(g.difference) })
3588
+ /* @__PURE__ */ e("td", { className: "px-4 py-3 text-right tabular-nums text-fg", children: v(h.total_debit) }),
3589
+ /* @__PURE__ */ e("td", { className: "px-4 py-3 text-right tabular-nums text-fg", children: v(h.total_credit) }),
3590
+ /* @__PURE__ */ e("td", { className: "px-4 py-3 text-right tabular-nums text-fg", children: v(h.difference) })
3591
3591
  ] }) })
3592
3592
  ] }) }),
3593
3593
  /* @__PURE__ */ e("div", { className: "mt-4 text-center", children: C ? /* @__PURE__ */ r("span", { className: "inline-flex items-center gap-1.5 rounded-full bg-emerald-50 px-4 py-1.5 text-sm font-semibold text-emerald-700 ring-1 ring-emerald-200", children: [
@@ -3605,15 +3605,15 @@ function Lr(t) {
3605
3605
  }
3606
3606
  const Br = ["25", "50", "100", "200"];
3607
3607
  function Er() {
3608
- const { t } = Z(), [n] = J("account", ""), [a] = J("party", ""), [s] = J("from", ""), [l] = J("to", ""), [i] = J("per_page", 50), [c] = J("page", 1), o = c - 1, m = Me(), d = (T) => m({ page: T === 0 ? null : T + 1 }), u = (T) => m({ per_page: T, page: null }), [p, v] = N(n), [w, g] = N(a), [y, I] = N(s), [L, C] = N(l), b = Fe(), h = (T) => Le(T, b), A = Ce(() => {
3609
- const T = {};
3610
- return n && (T.account = n), a && (T.party = a), s && (T.from_date = s), l && (T.to_date = l), T.limit = String(i), T.offset = String(o * i), T;
3611
- }, [n, a, s, l, i, o]), { data: B, isLoading: k, refetch: q } = Dr(A), x = (B == null ? void 0 : B.rows) ?? [], z = (B == null ? void 0 : B.total) ?? 0, j = Math.max(1, Math.ceil(z / i)), U = z === 0 ? 0 : o * i + 1, Y = Math.min(z, (o + 1) * i), ce = () => {
3608
+ const { t } = Z(), [n] = J("account", ""), [a] = J("party", ""), [s] = J("from", ""), [l] = J("to", ""), [i] = J("per_page", 50), [c] = J("page", 1), o = c - 1, m = Me(), d = (P) => m({ page: P === 0 ? null : P + 1 }), u = (P) => m({ per_page: P, page: null }), [p, v] = S(n), [D, h] = S(a), [y, R] = S(s), [B, C] = S(l), b = Fe(), g = (P) => Le(P, b), _ = Ce(() => {
3609
+ const P = {};
3610
+ return n && (P.account = n), a && (P.party = a), s && (P.from_date = s), l && (P.to_date = l), P.limit = String(i), P.offset = String(o * i), P;
3611
+ }, [n, a, s, l, i, o]), { data: w, isLoading: N, refetch: q } = Dr(_), x = (w == null ? void 0 : w.rows) ?? [], z = (w == null ? void 0 : w.total) ?? 0, j = Math.max(1, Math.ceil(z / i)), U = z === 0 ? 0 : o * i + 1, Y = Math.min(z, (o + 1) * i), de = () => {
3612
3612
  m({
3613
3613
  account: p || null,
3614
- party: w || null,
3614
+ party: D || null,
3615
3615
  from: y || null,
3616
- to: L || null,
3616
+ to: B || null,
3617
3617
  page: null
3618
3618
  }), q();
3619
3619
  };
@@ -3633,36 +3633,36 @@ function Er() {
3633
3633
  ke,
3634
3634
  {
3635
3635
  label: t("fields.Party", { defaultValue: "Party" }),
3636
- value: w,
3637
- onChange: g,
3636
+ value: D,
3637
+ onChange: h,
3638
3638
  linkDoctype: "customer",
3639
3639
  readOnly: !1
3640
3640
  }
3641
3641
  ),
3642
3642
  /* @__PURE__ */ e(
3643
- pe,
3643
+ X,
3644
3644
  {
3645
3645
  label: t("fields.From Date", { defaultValue: "From Date" }),
3646
3646
  type: "date",
3647
3647
  value: y,
3648
- onChange: (T) => I(T.target.value)
3648
+ onChange: (P) => R(P.target.value)
3649
3649
  }
3650
3650
  ),
3651
3651
  /* @__PURE__ */ e(
3652
- pe,
3652
+ X,
3653
3653
  {
3654
3654
  label: t("fields.To Date", { defaultValue: "To Date" }),
3655
3655
  type: "date",
3656
- value: L,
3657
- onChange: (T) => C(T.target.value)
3656
+ value: B,
3657
+ onChange: (P) => C(P.target.value)
3658
3658
  }
3659
3659
  ),
3660
- /* @__PURE__ */ e(X, { onClick: ce, children: t("common.apply") })
3660
+ /* @__PURE__ */ e(ee, { onClick: de, children: t("common.apply") })
3661
3661
  ] }),
3662
- /* @__PURE__ */ e(Dt, { onSelect: (T, K) => {
3663
- I(T), C(K), m({ from: T, to: K, page: null });
3662
+ /* @__PURE__ */ e(Dt, { onSelect: (P, K) => {
3663
+ R(P), C(K), m({ from: P, to: K, page: null });
3664
3664
  } }),
3665
- k ? /* @__PURE__ */ e("p", { className: "text-gray-500", children: t("common.loading") }) : x.length === 0 ? /* @__PURE__ */ e("p", { className: "py-8 text-center text-gray-400", children: t("reports.noEntries") }) : /* @__PURE__ */ r(Ne, { children: [
3665
+ N ? /* @__PURE__ */ e("p", { className: "text-gray-500", children: t("common.loading") }) : x.length === 0 ? /* @__PURE__ */ e("p", { className: "py-8 text-center text-gray-400", children: t("reports.noEntries") }) : /* @__PURE__ */ r(Ne, { children: [
3666
3666
  /* @__PURE__ */ e(V, { children: /* @__PURE__ */ e("div", { className: "overflow-x-auto", children: /* @__PURE__ */ r("table", { className: "min-w-full divide-y divide-gray-200 text-sm", children: [
3667
3667
  /* @__PURE__ */ e("thead", { className: "bg-gray-50", children: /* @__PURE__ */ r("tr", { children: [
3668
3668
  /* @__PURE__ */ e("th", { className: "px-4 py-3 text-left font-medium text-gray-500", children: t("fields.Date", { defaultValue: "Date" }) }),
@@ -3674,22 +3674,22 @@ function Er() {
3674
3674
  /* @__PURE__ */ e("th", { className: "px-4 py-3 text-left font-medium text-gray-500", children: t("fields.Voucher Type", { defaultValue: "Voucher Type" }) }),
3675
3675
  /* @__PURE__ */ e("th", { className: "px-4 py-3 text-left font-medium text-gray-500", children: t("fields.Voucher No", { defaultValue: "Voucher No" }) })
3676
3676
  ] }) }),
3677
- /* @__PURE__ */ e("tbody", { className: "divide-y divide-gray-100", children: x.map((T, K) => /* @__PURE__ */ r("tr", { className: "hover:bg-gray-50", children: [
3678
- /* @__PURE__ */ e("td", { className: "px-4 py-2 text-gray-500", children: Ct(T.posting_date ?? T.date) }),
3679
- /* @__PURE__ */ e("td", { className: "px-4 py-2 text-gray-900", children: T.account }),
3680
- /* @__PURE__ */ e("td", { className: "px-4 py-2 text-gray-700", children: T.party ?? "-" }),
3681
- /* @__PURE__ */ e("td", { className: "px-4 py-2 text-right", children: h(T.debit) }),
3682
- /* @__PURE__ */ e("td", { className: "px-4 py-2 text-right", children: h(T.credit) }),
3683
- /* @__PURE__ */ e("td", { className: "px-4 py-2 text-right font-medium", children: h(T.balance) }),
3684
- /* @__PURE__ */ e("td", { className: "px-4 py-2 text-gray-700", children: T.voucher_type ?? "-" }),
3685
- /* @__PURE__ */ e("td", { className: "px-4 py-2", children: T.voucher_type && T.voucher_no ? /* @__PURE__ */ e(
3677
+ /* @__PURE__ */ e("tbody", { className: "divide-y divide-gray-100", children: x.map((P, K) => /* @__PURE__ */ r("tr", { className: "hover:bg-gray-50", children: [
3678
+ /* @__PURE__ */ e("td", { className: "px-4 py-2 text-gray-500", children: Ct(P.posting_date ?? P.date) }),
3679
+ /* @__PURE__ */ e("td", { className: "px-4 py-2 text-gray-900", children: P.account }),
3680
+ /* @__PURE__ */ e("td", { className: "px-4 py-2 text-gray-700", children: P.party ?? "-" }),
3681
+ /* @__PURE__ */ e("td", { className: "px-4 py-2 text-right", children: g(P.debit) }),
3682
+ /* @__PURE__ */ e("td", { className: "px-4 py-2 text-right", children: g(P.credit) }),
3683
+ /* @__PURE__ */ e("td", { className: "px-4 py-2 text-right font-medium", children: g(P.balance) }),
3684
+ /* @__PURE__ */ e("td", { className: "px-4 py-2 text-gray-700", children: P.voucher_type ?? "-" }),
3685
+ /* @__PURE__ */ e("td", { className: "px-4 py-2", children: P.voucher_type && P.voucher_no ? /* @__PURE__ */ e(
3686
3686
  ye,
3687
3687
  {
3688
- to: `/app/${Lr(T.voucher_type)}/${T.voucher_no}`,
3688
+ to: `/app/${Lr(P.voucher_type)}/${P.voucher_no}`,
3689
3689
  className: "font-medium text-blue-600 hover:text-blue-800",
3690
- children: T.voucher_no
3690
+ children: P.voucher_no
3691
3691
  }
3692
- ) : T.voucher_no ?? "-" })
3692
+ ) : P.voucher_no ?? "-" })
3693
3693
  ] }, K)) })
3694
3694
  ] }) }) }),
3695
3695
  /* @__PURE__ */ r("div", { className: "flex flex-wrap items-center justify-between gap-3 text-sm text-gray-600", children: [
@@ -3713,9 +3713,9 @@ function Er() {
3713
3713
  "select",
3714
3714
  {
3715
3715
  value: i,
3716
- onChange: (T) => u(Number(T.target.value)),
3716
+ onChange: (P) => u(Number(P.target.value)),
3717
3717
  className: "rounded border border-gray-300 bg-white px-2 py-1 text-sm",
3718
- children: Br.map((T) => /* @__PURE__ */ e("option", { value: T, children: T }, T))
3718
+ children: Br.map((P) => /* @__PURE__ */ e("option", { value: P, children: P }, P))
3719
3719
  }
3720
3720
  )
3721
3721
  ] }),
@@ -3752,14 +3752,14 @@ function Er() {
3752
3752
  ] });
3753
3753
  }
3754
3754
  function Or() {
3755
- const { t } = Z(), [n] = J("item_code", ""), [a] = J("warehouse", ""), s = Me(), [l, i] = N(n), [c, o] = N(a), m = Fe(), d = (y) => Le(y, m), u = Ce(() => {
3755
+ const { t } = Z(), [n] = J("item_code", ""), [a] = J("warehouse", ""), s = Me(), [l, i] = S(n), [c, o] = S(a), m = Fe(), d = (y) => Le(y, m), u = Ce(() => {
3756
3756
  const y = {};
3757
3757
  return n && (y.item_code = n), a && (y.warehouse = a), y;
3758
- }, [n, a]), { data: p, isLoading: v, refetch: w } = _r(u), g = () => {
3758
+ }, [n, a]), { data: p, isLoading: v, refetch: D } = _r(u), h = () => {
3759
3759
  s({
3760
3760
  item_code: l || null,
3761
3761
  warehouse: c || null
3762
- }), w();
3762
+ }), D();
3763
3763
  };
3764
3764
  return /* @__PURE__ */ r("div", { className: "space-y-4", children: [
3765
3765
  /* @__PURE__ */ r("div", { className: "flex flex-wrap items-end gap-4", children: [
@@ -3783,7 +3783,7 @@ function Or() {
3783
3783
  readOnly: !1
3784
3784
  }
3785
3785
  ),
3786
- /* @__PURE__ */ e(X, { onClick: g, children: t("common.apply") })
3786
+ /* @__PURE__ */ e(ee, { onClick: h, children: t("common.apply") })
3787
3787
  ] }),
3788
3788
  v ? /* @__PURE__ */ e("p", { className: "text-gray-500", children: t("common.loading") }) : !p || !p.rows || p.rows.length === 0 ? /* @__PURE__ */ e("p", { className: "py-8 text-center text-gray-400", children: t("reports.noStockData") }) : /* @__PURE__ */ e(V, { children: /* @__PURE__ */ e("div", { className: "overflow-x-auto", children: /* @__PURE__ */ r("table", { className: "min-w-full divide-y divide-gray-200 text-sm", children: [
3789
3789
  /* @__PURE__ */ e("thead", { className: "bg-gray-50", children: /* @__PURE__ */ r("tr", { children: [
@@ -3794,37 +3794,37 @@ function Or() {
3794
3794
  /* @__PURE__ */ e("th", { className: "px-4 py-3 text-right font-medium text-gray-500", children: t("fields.Valuation Rate", { defaultValue: "Valuation Rate" }) }),
3795
3795
  /* @__PURE__ */ e("th", { className: "px-4 py-3 text-right font-medium text-gray-500", children: t("fields.Stock Value", { defaultValue: "Stock Value" }) })
3796
3796
  ] }) }),
3797
- /* @__PURE__ */ e("tbody", { className: "divide-y divide-gray-100", children: p.rows.map((y, I) => /* @__PURE__ */ r("tr", { className: "hover:bg-gray-50", children: [
3797
+ /* @__PURE__ */ e("tbody", { className: "divide-y divide-gray-100", children: p.rows.map((y, R) => /* @__PURE__ */ r("tr", { className: "hover:bg-gray-50", children: [
3798
3798
  /* @__PURE__ */ e("td", { className: "px-4 py-2 font-medium text-gray-900", children: y.item_code }),
3799
3799
  /* @__PURE__ */ e("td", { className: "px-4 py-2 text-gray-700", children: y.item_name }),
3800
3800
  /* @__PURE__ */ e("td", { className: "px-4 py-2 text-gray-700", children: y.warehouse }),
3801
3801
  /* @__PURE__ */ e("td", { className: "px-4 py-2 text-right", children: Mt(y.actual_qty) }),
3802
3802
  /* @__PURE__ */ e("td", { className: "px-4 py-2 text-right", children: d(y.valuation_rate) }),
3803
3803
  /* @__PURE__ */ e("td", { className: "px-4 py-2 text-right font-medium", children: d(y.stock_value) })
3804
- ] }, I)) })
3804
+ ] }, R)) })
3805
3805
  ] }) }) })
3806
3806
  ] });
3807
3807
  }
3808
3808
  function qr() {
3809
- const { t } = Z(), [n] = J("company", ""), [a] = J("from", ""), [s] = J("to", ""), l = Me(), [i, c] = N(n), o = Fe(i), m = (b) => Le(b, o), [d, u] = N(a), [p, v] = N(s), w = Ce(() => {
3809
+ const { t } = Z(), [n] = J("company", ""), [a] = J("from", ""), [s] = J("to", ""), l = Me(), [i, c] = S(n), o = Fe(i), m = (b) => Le(b, o), [d, u] = S(a), [p, v] = S(s), D = Ce(() => {
3810
3810
  const b = {};
3811
3811
  return n && (b.company = n), a && (b.from_date = a), s && (b.to_date = s), b;
3812
- }, [n, a, s]), { data: g, isLoading: y, refetch: I } = Ar(w), L = () => {
3812
+ }, [n, a, s]), { data: h, isLoading: y, refetch: R } = Ar(D), B = () => {
3813
3813
  l({
3814
3814
  company: i || null,
3815
3815
  from: d || null,
3816
3816
  to: p || null
3817
- }), I();
3818
- }, C = g && (g.income && g.income.length > 0 || g.expense && g.expense.length > 0);
3817
+ }), R();
3818
+ }, C = h && (h.income && h.income.length > 0 || h.expense && h.expense.length > 0);
3819
3819
  return /* @__PURE__ */ r("div", { className: "space-y-4", children: [
3820
3820
  /* @__PURE__ */ r("div", { className: "flex flex-wrap items-end gap-4", children: [
3821
3821
  /* @__PURE__ */ e(ke, { label: t("fields.Company", { defaultValue: "Company" }), value: i, onChange: c, linkDoctype: "company", readOnly: !1 }),
3822
- /* @__PURE__ */ e(pe, { label: t("fields.From Date", { defaultValue: "From Date" }), type: "date", value: d, onChange: (b) => u(b.target.value) }),
3823
- /* @__PURE__ */ e(pe, { label: t("fields.To Date", { defaultValue: "To Date" }), type: "date", value: p, onChange: (b) => v(b.target.value) }),
3824
- /* @__PURE__ */ e(X, { onClick: L, children: t("common.apply") })
3822
+ /* @__PURE__ */ e(X, { label: t("fields.From Date", { defaultValue: "From Date" }), type: "date", value: d, onChange: (b) => u(b.target.value) }),
3823
+ /* @__PURE__ */ e(X, { label: t("fields.To Date", { defaultValue: "To Date" }), type: "date", value: p, onChange: (b) => v(b.target.value) }),
3824
+ /* @__PURE__ */ e(ee, { onClick: B, children: t("common.apply") })
3825
3825
  ] }),
3826
- /* @__PURE__ */ e(Dt, { onSelect: (b, h) => {
3827
- u(b), v(h), l({ from: b, to: h });
3826
+ /* @__PURE__ */ e(Dt, { onSelect: (b, g) => {
3827
+ u(b), v(g), l({ from: b, to: g });
3828
3828
  } }),
3829
3829
  y ? /* @__PURE__ */ e("p", { className: "text-gray-500", children: t("common.loading") }) : C ? /* @__PURE__ */ r("div", { className: "space-y-4", children: [
3830
3830
  /* @__PURE__ */ r(V, { children: [
@@ -3834,13 +3834,13 @@ function qr() {
3834
3834
  /* @__PURE__ */ e("th", { className: "px-4 py-3 text-left font-medium text-gray-500", children: t("fields.Account", { defaultValue: "Account" }) }),
3835
3835
  /* @__PURE__ */ e("th", { className: "px-4 py-3 text-right font-medium text-gray-500", children: t("fields.Amount", { defaultValue: "Amount" }) })
3836
3836
  ] }) }),
3837
- /* @__PURE__ */ e("tbody", { className: "divide-y divide-gray-100", children: (g.income || []).map((b, h) => /* @__PURE__ */ r("tr", { className: "hover:bg-gray-50", children: [
3837
+ /* @__PURE__ */ e("tbody", { className: "divide-y divide-gray-100", children: (h.income || []).map((b, g) => /* @__PURE__ */ r("tr", { className: "hover:bg-gray-50", children: [
3838
3838
  /* @__PURE__ */ e("td", { className: "px-4 py-2 text-gray-900", children: b.account }),
3839
3839
  /* @__PURE__ */ e("td", { className: "px-4 py-2 text-right", children: m(b.amount) })
3840
- ] }, h)) }),
3840
+ ] }, g)) }),
3841
3841
  /* @__PURE__ */ e("tfoot", { className: "border-t-2 border-gray-300 bg-gray-50 font-semibold", children: /* @__PURE__ */ r("tr", { children: [
3842
3842
  /* @__PURE__ */ e("td", { className: "px-4 py-3 text-gray-900", children: t("reports.totalIncome") }),
3843
- /* @__PURE__ */ e("td", { className: "px-4 py-3 text-right", children: m(g.total_income) })
3843
+ /* @__PURE__ */ e("td", { className: "px-4 py-3 text-right", children: m(h.total_income) })
3844
3844
  ] }) })
3845
3845
  ] })
3846
3846
  ] }),
@@ -3851,20 +3851,20 @@ function qr() {
3851
3851
  /* @__PURE__ */ e("th", { className: "px-4 py-3 text-left font-medium text-gray-500", children: t("fields.Account", { defaultValue: "Account" }) }),
3852
3852
  /* @__PURE__ */ e("th", { className: "px-4 py-3 text-right font-medium text-gray-500", children: t("fields.Amount", { defaultValue: "Amount" }) })
3853
3853
  ] }) }),
3854
- /* @__PURE__ */ e("tbody", { className: "divide-y divide-gray-100", children: (g.expense || []).map((b, h) => /* @__PURE__ */ r("tr", { className: "hover:bg-gray-50", children: [
3854
+ /* @__PURE__ */ e("tbody", { className: "divide-y divide-gray-100", children: (h.expense || []).map((b, g) => /* @__PURE__ */ r("tr", { className: "hover:bg-gray-50", children: [
3855
3855
  /* @__PURE__ */ e("td", { className: "px-4 py-2 text-gray-900", children: b.account }),
3856
3856
  /* @__PURE__ */ e("td", { className: "px-4 py-2 text-right", children: m(b.amount) })
3857
- ] }, h)) }),
3857
+ ] }, g)) }),
3858
3858
  /* @__PURE__ */ e("tfoot", { className: "border-t-2 border-gray-300 bg-gray-50 font-semibold", children: /* @__PURE__ */ r("tr", { children: [
3859
3859
  /* @__PURE__ */ e("td", { className: "px-4 py-3 text-gray-900", children: t("reports.totalExpenses") }),
3860
- /* @__PURE__ */ e("td", { className: "px-4 py-3 text-right", children: m(g.total_expense) })
3860
+ /* @__PURE__ */ e("td", { className: "px-4 py-3 text-right", children: m(h.total_expense) })
3861
3861
  ] }) })
3862
3862
  ] })
3863
3863
  ] }),
3864
- /* @__PURE__ */ e("div", { className: "text-center", children: /* @__PURE__ */ r("span", { className: `inline-flex items-center rounded-full px-5 py-2 text-sm font-semibold ${g.net_profit >= 0 ? "bg-green-100 text-green-800" : "bg-red-100 text-red-800"}`, children: [
3865
- g.net_profit >= 0 ? t("reports.netProfit") : t("reports.netLoss"),
3864
+ /* @__PURE__ */ e("div", { className: "text-center", children: /* @__PURE__ */ r("span", { className: `inline-flex items-center rounded-full px-5 py-2 text-sm font-semibold ${h.net_profit >= 0 ? "bg-green-100 text-green-800" : "bg-red-100 text-red-800"}`, children: [
3865
+ h.net_profit >= 0 ? t("reports.netProfit") : t("reports.netLoss"),
3866
3866
  ": ",
3867
- m(Math.abs(g.net_profit))
3867
+ m(Math.abs(h.net_profit))
3868
3868
  ] }) })
3869
3869
  ] }) : /* @__PURE__ */ e("p", { className: "py-8 text-center text-gray-400", children: t("reports.noData") })
3870
3870
  ] });
@@ -3890,21 +3890,21 @@ function Et({ title: t, rows: n, total: a, totalLabel: s, currency: l }) {
3890
3890
  ] });
3891
3891
  }
3892
3892
  function zr() {
3893
- var L, C, b;
3894
- const { t } = Z(), [n] = J("company", ""), [a] = J("as_of_date", ""), s = Me(), [l, i] = N(n), [c, o] = N(a), m = Fe(l), d = (h) => Le(h, m), u = Ce(() => {
3895
- const h = {};
3896
- return n && (h.company = n), a && (h.as_of_date = a), h;
3897
- }, [n, a]), { data: p, isLoading: v, refetch: w } = Tr(u), g = () => {
3898
- s({ company: l || null, as_of_date: c || null }), w();
3899
- }, y = p && (((L = p.assets) == null ? void 0 : L.length) > 0 || ((C = p.liabilities) == null ? void 0 : C.length) > 0 || ((b = p.equity) == null ? void 0 : b.length) > 0), I = p ? Math.abs(p.total_assets - p.total_liabilities_and_equity) < 0.01 : !1;
3893
+ var B, C, b;
3894
+ const { t } = Z(), [n] = J("company", ""), [a] = J("as_of_date", ""), s = Me(), [l, i] = S(n), [c, o] = S(a), m = Fe(l), d = (g) => Le(g, m), u = Ce(() => {
3895
+ const g = {};
3896
+ return n && (g.company = n), a && (g.as_of_date = a), g;
3897
+ }, [n, a]), { data: p, isLoading: v, refetch: D } = Tr(u), h = () => {
3898
+ s({ company: l || null, as_of_date: c || null }), D();
3899
+ }, y = p && (((B = p.assets) == null ? void 0 : B.length) > 0 || ((C = p.liabilities) == null ? void 0 : C.length) > 0 || ((b = p.equity) == null ? void 0 : b.length) > 0), R = p ? Math.abs(p.total_assets - p.total_liabilities_and_equity) < 0.01 : !1;
3900
3900
  return /* @__PURE__ */ r("div", { className: "space-y-4", children: [
3901
3901
  /* @__PURE__ */ r("div", { className: "flex flex-wrap items-end gap-4", children: [
3902
3902
  /* @__PURE__ */ e(ke, { label: t("fields.Company", { defaultValue: "Company" }), value: l, onChange: i, linkDoctype: "company", readOnly: !1 }),
3903
- /* @__PURE__ */ e(pe, { label: t("fields.As of Date", { defaultValue: "As of Date" }), type: "date", value: c, onChange: (h) => o(h.target.value) }),
3904
- /* @__PURE__ */ e(X, { onClick: g, children: t("common.apply") })
3903
+ /* @__PURE__ */ e(X, { label: t("fields.As of Date", { defaultValue: "As of Date" }), type: "date", value: c, onChange: (g) => o(g.target.value) }),
3904
+ /* @__PURE__ */ e(ee, { onClick: h, children: t("common.apply") })
3905
3905
  ] }),
3906
- /* @__PURE__ */ e(en, { onSelect: (h) => {
3907
- o(h), s({ as_of_date: h });
3906
+ /* @__PURE__ */ e(en, { onSelect: (g) => {
3907
+ o(g), s({ as_of_date: g });
3908
3908
  } }),
3909
3909
  v ? /* @__PURE__ */ e("p", { className: "text-gray-500", children: t("common.loading") }) : y ? /* @__PURE__ */ r("div", { className: "space-y-4", children: [
3910
3910
  /* @__PURE__ */ e(Et, { title: t("reports.assets"), rows: p.assets || [], total: p.total_assets, totalLabel: t("reports.totalAssets"), currency: m }),
@@ -3923,23 +3923,23 @@ function zr() {
3923
3923
  /* @__PURE__ */ e("span", { className: "font-semibold text-gray-900", children: d(p.total_liabilities_and_equity) })
3924
3924
  ] })
3925
3925
  ] }),
3926
- I ? /* @__PURE__ */ e("span", { className: "inline-flex items-center rounded-full bg-green-100 px-4 py-1.5 text-sm font-semibold text-green-800", children: t("reports.balanced") }) : /* @__PURE__ */ e("span", { className: "inline-flex items-center rounded-full bg-red-100 px-4 py-1.5 text-sm font-semibold text-red-800", children: t("reports.imbalanced") })
3926
+ R ? /* @__PURE__ */ e("span", { className: "inline-flex items-center rounded-full bg-green-100 px-4 py-1.5 text-sm font-semibold text-green-800", children: t("reports.balanced") }) : /* @__PURE__ */ e("span", { className: "inline-flex items-center rounded-full bg-red-100 px-4 py-1.5 text-sm font-semibold text-red-800", children: t("reports.imbalanced") })
3927
3927
  ] }) })
3928
3928
  ] }) : /* @__PURE__ */ e("p", { className: "py-8 text-center text-gray-400", children: t("reports.noData") })
3929
3929
  ] });
3930
3930
  }
3931
3931
  function Fr() {
3932
- const { t } = Z(), [n] = J("company", ""), [a] = J("as_of_date", ""), s = Me(), [l, i] = N(n), [c, o] = N(a), m = Fe(l), d = (y) => Le(y, m), u = Ce(() => {
3932
+ const { t } = Z(), [n] = J("company", ""), [a] = J("as_of_date", ""), s = Me(), [l, i] = S(n), [c, o] = S(a), m = Fe(l), d = (y) => Le(y, m), u = Ce(() => {
3933
3933
  const y = {};
3934
3934
  return n && (y.company = n), a && (y.as_of_date = a), y;
3935
- }, [n, a]), { data: p, isLoading: v, refetch: w } = Pr(u), g = () => {
3936
- s({ company: l || null, as_of_date: c || null }), w();
3935
+ }, [n, a]), { data: p, isLoading: v, refetch: D } = Pr(u), h = () => {
3936
+ s({ company: l || null, as_of_date: c || null }), D();
3937
3937
  };
3938
3938
  return /* @__PURE__ */ r("div", { className: "space-y-4", children: [
3939
3939
  /* @__PURE__ */ r("div", { className: "flex flex-wrap items-end gap-4", children: [
3940
3940
  /* @__PURE__ */ e(ke, { label: t("fields.Company", { defaultValue: "Company" }), value: l, onChange: i, linkDoctype: "company", readOnly: !1 }),
3941
- /* @__PURE__ */ e(pe, { label: t("fields.As of Date", { defaultValue: "As of Date" }), type: "date", value: c, onChange: (y) => o(y.target.value) }),
3942
- /* @__PURE__ */ e(X, { onClick: g, children: t("common.apply") })
3941
+ /* @__PURE__ */ e(X, { label: t("fields.As of Date", { defaultValue: "As of Date" }), type: "date", value: c, onChange: (y) => o(y.target.value) }),
3942
+ /* @__PURE__ */ e(ee, { onClick: h, children: t("common.apply") })
3943
3943
  ] }),
3944
3944
  /* @__PURE__ */ e(en, { onSelect: (y) => {
3945
3945
  o(y), s({ as_of_date: y });
@@ -3956,7 +3956,7 @@ function Fr() {
3956
3956
  /* @__PURE__ */ e("th", { className: "px-3 py-3 text-right font-medium text-gray-500", children: "61-90" }),
3957
3957
  /* @__PURE__ */ e("th", { className: "px-3 py-3 text-right font-medium text-gray-500", children: "90+" })
3958
3958
  ] }) }),
3959
- /* @__PURE__ */ e("tbody", { className: "divide-y divide-gray-100", children: p.rows.map((y, I) => /* @__PURE__ */ r("tr", { className: "hover:bg-gray-50", children: [
3959
+ /* @__PURE__ */ e("tbody", { className: "divide-y divide-gray-100", children: p.rows.map((y, R) => /* @__PURE__ */ r("tr", { className: "hover:bg-gray-50", children: [
3960
3960
  /* @__PURE__ */ e("td", { className: "px-3 py-2", children: /* @__PURE__ */ e(
3961
3961
  ye,
3962
3962
  {
@@ -3973,7 +3973,7 @@ function Fr() {
3973
3973
  /* @__PURE__ */ e("td", { className: "px-3 py-2 text-right", children: y.b31_60 ? d(y.b31_60) : "" }),
3974
3974
  /* @__PURE__ */ e("td", { className: "px-3 py-2 text-right", children: y.b61_90 ? d(y.b61_90) : "" }),
3975
3975
  /* @__PURE__ */ e("td", { className: "px-3 py-2 text-right text-red-600", children: y.b90_plus ? d(y.b90_plus) : "" })
3976
- ] }, I)) }),
3976
+ ] }, R)) }),
3977
3977
  /* @__PURE__ */ e("tfoot", { className: "border-t-2 border-gray-300 bg-gray-50 font-semibold", children: /* @__PURE__ */ r("tr", { children: [
3978
3978
  /* @__PURE__ */ e("td", { className: "px-3 py-3", colSpan: 3, children: t("common.total") }),
3979
3979
  /* @__PURE__ */ e("td", { className: "px-3 py-3 text-right", children: d(p.totals.outstanding) }),
@@ -3987,17 +3987,17 @@ function Fr() {
3987
3987
  ] });
3988
3988
  }
3989
3989
  function Mr() {
3990
- const { t } = Z(), [n] = J("company", ""), [a] = J("as_of_date", ""), s = Me(), [l, i] = N(n), [c, o] = N(a), m = Fe(l), d = (y) => Le(y, m), u = Ce(() => {
3990
+ const { t } = Z(), [n] = J("company", ""), [a] = J("as_of_date", ""), s = Me(), [l, i] = S(n), [c, o] = S(a), m = Fe(l), d = (y) => Le(y, m), u = Ce(() => {
3991
3991
  const y = {};
3992
3992
  return n && (y.company = n), a && (y.as_of_date = a), y;
3993
- }, [n, a]), { data: p, isLoading: v, refetch: w } = Rr(u), g = () => {
3994
- s({ company: l || null, as_of_date: c || null }), w();
3993
+ }, [n, a]), { data: p, isLoading: v, refetch: D } = Rr(u), h = () => {
3994
+ s({ company: l || null, as_of_date: c || null }), D();
3995
3995
  };
3996
3996
  return /* @__PURE__ */ r("div", { className: "space-y-4", children: [
3997
3997
  /* @__PURE__ */ r("div", { className: "flex flex-wrap items-end gap-4", children: [
3998
3998
  /* @__PURE__ */ e(ke, { label: t("fields.Company", { defaultValue: "Company" }), value: l, onChange: i, linkDoctype: "company", readOnly: !1 }),
3999
- /* @__PURE__ */ e(pe, { label: t("fields.As of Date", { defaultValue: "As of Date" }), type: "date", value: c, onChange: (y) => o(y.target.value) }),
4000
- /* @__PURE__ */ e(X, { onClick: g, children: t("common.apply") })
3999
+ /* @__PURE__ */ e(X, { label: t("fields.As of Date", { defaultValue: "As of Date" }), type: "date", value: c, onChange: (y) => o(y.target.value) }),
4000
+ /* @__PURE__ */ e(ee, { onClick: h, children: t("common.apply") })
4001
4001
  ] }),
4002
4002
  /* @__PURE__ */ e(en, { onSelect: (y) => {
4003
4003
  o(y), s({ as_of_date: y });
@@ -4014,7 +4014,7 @@ function Mr() {
4014
4014
  /* @__PURE__ */ e("th", { className: "px-3 py-3 text-right font-medium text-gray-500", children: "61-90" }),
4015
4015
  /* @__PURE__ */ e("th", { className: "px-3 py-3 text-right font-medium text-gray-500", children: "90+" })
4016
4016
  ] }) }),
4017
- /* @__PURE__ */ e("tbody", { className: "divide-y divide-gray-100", children: p.rows.map((y, I) => /* @__PURE__ */ r("tr", { className: "hover:bg-gray-50", children: [
4017
+ /* @__PURE__ */ e("tbody", { className: "divide-y divide-gray-100", children: p.rows.map((y, R) => /* @__PURE__ */ r("tr", { className: "hover:bg-gray-50", children: [
4018
4018
  /* @__PURE__ */ e("td", { className: "px-3 py-2", children: /* @__PURE__ */ e(
4019
4019
  ye,
4020
4020
  {
@@ -4031,7 +4031,7 @@ function Mr() {
4031
4031
  /* @__PURE__ */ e("td", { className: "px-3 py-2 text-right", children: y.b31_60 ? d(y.b31_60) : "" }),
4032
4032
  /* @__PURE__ */ e("td", { className: "px-3 py-2 text-right", children: y.b61_90 ? d(y.b61_90) : "" }),
4033
4033
  /* @__PURE__ */ e("td", { className: "px-3 py-2 text-right text-red-600", children: y.b90_plus ? d(y.b90_plus) : "" })
4034
- ] }, I)) }),
4034
+ ] }, R)) }),
4035
4035
  /* @__PURE__ */ e("tfoot", { className: "border-t-2 border-gray-300 bg-gray-50 font-semibold", children: /* @__PURE__ */ r("tr", { children: [
4036
4036
  /* @__PURE__ */ e("td", { className: "px-3 py-3", colSpan: 3, children: t("common.total") }),
4037
4037
  /* @__PURE__ */ e("td", { className: "px-3 py-3 text-right", children: d(p.totals.outstanding) }),
@@ -4139,7 +4139,7 @@ return {
4139
4139
  }
4140
4140
  const Yn = Vr();
4141
4141
  function Ur() {
4142
- const t = Oe(), { sessions: n, createSession: a } = tt(), [s] = J("report_id", ""), [l] = J("metric", ""), [i] = J("group_by", ""), [c] = J("from", ""), [o] = J("to", ""), [m] = J("company", ""), [d, u] = N(Yn), [p, v] = N([]), [w, g] = N(null), [y, I] = N(""), [L, C] = N(!1), [b, h] = N(!1), [A, B] = N(""), k = H(null), q = H(""), x = H(""), z = H(0), j = Ce(() => !l || !i ? "" : JSON.stringify(Kr({
4142
+ const t = Oe(), { sessions: n, createSession: a } = tt(), [s] = J("report_id", ""), [l] = J("metric", ""), [i] = J("group_by", ""), [c] = J("from", ""), [o] = J("to", ""), [m] = J("company", ""), [d, u] = S(Yn), [p, v] = S([]), [D, h] = S(null), [y, R] = S(""), [B, C] = S(!1), [b, g] = S(!1), [_, w] = S(""), N = H(null), q = H(""), x = H(""), z = H(0), j = Ce(() => !l || !i ? "" : JSON.stringify(Kr({
4143
4143
  metric: l,
4144
4144
  groupBy: i,
4145
4145
  fromDate: c || void 0,
@@ -4147,66 +4147,66 @@ function Ur() {
4147
4147
  company: m || void 0
4148
4148
  }), null, 2), [l, i, c, o, m]), U = async (K) => {
4149
4149
  var ge;
4150
- const se = ++z.current, le = () => z.current === se;
4151
- I(""), C(!0);
4150
+ const ie = ++z.current, oe = () => z.current === ie;
4151
+ R(""), C(!0);
4152
4152
  try {
4153
- const Q = JSON.parse(K ?? d), oe = await O.runtimeData({ requests: Q.data_requests || [] });
4154
- if (!le()) return;
4155
- v(oe.datasets), (ge = k.current) == null || ge.terminate();
4156
- const ne = new $r();
4157
- k.current = ne;
4153
+ const Q = JSON.parse(K ?? d), ce = await O.runtimeData({ requests: Q.data_requests || [] });
4154
+ if (!oe()) return;
4155
+ v(ce.datasets), (ge = N.current) == null || ge.terminate();
4156
+ const ae = new $r();
4157
+ N.current = ae;
4158
4158
  const Be = await new Promise((Pe, _e) => {
4159
4159
  const $e = window.setTimeout(() => {
4160
- ne.terminate(), _e(new Error("Report runtime exceeded 4 seconds"));
4160
+ ae.terminate(), _e(new Error("Report runtime exceeded 4 seconds"));
4161
4161
  }, 4e3);
4162
- ne.onmessage = (Re) => {
4162
+ ae.onmessage = (Re) => {
4163
4163
  var he, xe;
4164
- window.clearTimeout($e), ne.terminate(), k.current === ne && (k.current = null), (he = Re.data) != null && he.ok ? Pe(Re.data.output) : _e(new Error(((xe = Re.data) == null ? void 0 : xe.error) || "Runtime failed"));
4165
- }, ne.postMessage({
4166
- datasets: oe.datasets,
4164
+ window.clearTimeout($e), ae.terminate(), N.current === ae && (N.current = null), (he = Re.data) != null && he.ok ? Pe(Re.data.output) : _e(new Error(((xe = Re.data) == null ? void 0 : xe.error) || "Runtime failed"));
4165
+ }, ae.postMessage({
4166
+ datasets: ce.datasets,
4167
4167
  params: {},
4168
4168
  transformJs: Q.transform_js || "return {};"
4169
4169
  });
4170
4170
  });
4171
- if (!le()) return;
4172
- g(Be);
4173
- } catch (_) {
4174
- if (!le()) return;
4175
- g(null), I(_ instanceof Error ? _.message : String(_));
4171
+ if (!oe()) return;
4172
+ h(Be);
4173
+ } catch (T) {
4174
+ if (!oe()) return;
4175
+ h(null), R(T instanceof Error ? T.message : String(T));
4176
4176
  } finally {
4177
- le() && C(!1);
4177
+ oe() && C(!1);
4178
4178
  }
4179
4179
  };
4180
- re(() => {
4180
+ se(() => {
4181
4181
  let K = !1;
4182
- return s ? q.current === s ? void 0 : (h(!0), I(""), O.getRuntimeDraft(s).then((se) => {
4182
+ return s ? q.current === s ? void 0 : (g(!0), R(""), O.getRuntimeDraft(s).then((ie) => {
4183
4183
  if (K) return;
4184
- const le = JSON.stringify(se.definition, null, 2);
4185
- return q.current = s, x.current = le, B(se.source_chat_session_id || ""), u(le), U(le);
4186
- }).catch((se) => {
4187
- K || (g(null), I(se instanceof Error ? se.message : String(se)));
4184
+ const oe = JSON.stringify(ie.definition, null, 2);
4185
+ return q.current = s, x.current = oe, w(ie.source_chat_session_id || ""), u(oe), U(oe);
4186
+ }).catch((ie) => {
4187
+ K || (h(null), R(ie instanceof Error ? ie.message : String(ie)));
4188
4188
  }).finally(() => {
4189
- K || h(!1);
4189
+ K || g(!1);
4190
4190
  }), () => {
4191
4191
  K = !0;
4192
- }) : (q.current = "", x.current = "", B(""), j && (x.current = j, u(j), U(j)), () => {
4192
+ }) : (q.current = "", x.current = "", w(""), j && (x.current = j, u(j), U(j)), () => {
4193
4193
  K = !0;
4194
4194
  });
4195
4195
  }, [s, j]);
4196
- const Y = !!(!s && j), ce = Ce(() => Wr(w), [w]), T = async () => {
4197
- var oe;
4198
- const K = d.trim() !== x.current.trim(), se = s || "unsaved-runtime-report", le = p.map((ne) => ({
4199
- name: ne.name,
4200
- dataset: ne.dataset,
4201
- row_count: ne.row_count,
4202
- sample_rows: ne.rows.slice(0, 3)
4196
+ const Y = !!(!s && j), de = Ce(() => Wr(D), [D]), P = async () => {
4197
+ var ce;
4198
+ const K = d.trim() !== x.current.trim(), ie = s || "unsaved-runtime-report", oe = p.map((ae) => ({
4199
+ name: ae.name,
4200
+ dataset: ae.dataset,
4201
+ row_count: ae.row_count,
4202
+ sample_rows: ae.rows.slice(0, 3)
4203
4203
  })), ge = [
4204
4204
  "This custom analytics report does not work yet. Please repair the existing report draft instead of creating a new one.",
4205
4205
  "",
4206
- `Report ID: ${se}`,
4206
+ `Report ID: ${ie}`,
4207
4207
  "",
4208
4208
  "Current issue summary:",
4209
- y || ce.join(`
4209
+ y || de.join(`
4210
4210
  `) || "No runtime error captured; please review and improve the report definition."
4211
4211
  ];
4212
4212
  K ? ge.push(
@@ -4218,17 +4218,17 @@ function Ur() {
4218
4218
  ) : ge.push(
4219
4219
  "",
4220
4220
  "Load the current saved draft with `get_custom_analytics_report` before making changes."
4221
- ), le.length > 0 && ge.push(
4221
+ ), oe.length > 0 && ge.push(
4222
4222
  "",
4223
4223
  "Fetched dataset preview:",
4224
4224
  "```json",
4225
- JSON.stringify(le, null, 2),
4225
+ JSON.stringify(oe, null, 2),
4226
4226
  "```"
4227
4227
  );
4228
- const _ = ge.join(`
4228
+ const T = ge.join(`
4229
4229
  `);
4230
- let Q = A;
4231
- Q || (Q = ((oe = n[0]) == null ? void 0 : oe.id) || ""), Q || (Q = (await a()).id), t(`/chat/${Q}`, { state: { prefillMessage: _ } });
4230
+ let Q = _;
4231
+ Q || (Q = ((ce = n[0]) == null ? void 0 : ce.id) || ""), Q || (Q = (await a()).id), t(`/chat/${Q}`, { state: { prefillMessage: T } });
4232
4232
  };
4233
4233
  return /* @__PURE__ */ r("div", { className: "space-y-4", children: [
4234
4234
  /* @__PURE__ */ e(V, { children: /* @__PURE__ */ r("div", { className: "flex flex-wrap items-center justify-between gap-3", children: [
@@ -4241,11 +4241,11 @@ function Ur() {
4241
4241
  "Loaded draft: ",
4242
4242
  s
4243
4243
  ] }) : Y ? /* @__PURE__ */ e("div", { className: "text-xs text-gray-500", children: "Loaded runtime report from legacy URL filters." }) : null,
4244
- s ? /* @__PURE__ */ e(X, { variant: "secondary", onClick: () => void T(), children: "Fix In Chat" }) : null,
4245
- /* @__PURE__ */ e(X, { onClick: () => void U(), disabled: L, children: L ? "Running..." : "Run Report" })
4244
+ s ? /* @__PURE__ */ e(ee, { variant: "secondary", onClick: () => void P(), children: "Fix In Chat" }) : null,
4245
+ /* @__PURE__ */ e(ee, { onClick: () => void U(), disabled: B, children: B ? "Running..." : "Run Report" })
4246
4246
  ] })
4247
4247
  ] }) }),
4248
- b ? /* @__PURE__ */ e(V, { children: /* @__PURE__ */ e("p", { className: "text-sm text-gray-600", children: "Loading draft..." }) }) : y ? /* @__PURE__ */ e(V, { children: /* @__PURE__ */ e("p", { className: "text-sm text-red-600", children: y }) }) : w ? /* @__PURE__ */ e(Gr, { output: w }) : /* @__PURE__ */ e(V, { children: /* @__PURE__ */ e("p", { className: "text-sm text-gray-600", children: "Edit the runtime JSON below or open a draft from chat, then run the report." }) }),
4248
+ b ? /* @__PURE__ */ e(V, { children: /* @__PURE__ */ e("p", { className: "text-sm text-gray-600", children: "Loading draft..." }) }) : y ? /* @__PURE__ */ e(V, { children: /* @__PURE__ */ e("p", { className: "text-sm text-red-600", children: y }) }) : D ? /* @__PURE__ */ e(Gr, { output: D }) : /* @__PURE__ */ e(V, { children: /* @__PURE__ */ e("p", { className: "text-sm text-gray-600", children: "Edit the runtime JSON below or open a draft from chat, then run the report." }) }),
4249
4249
  p.length > 0 && /* @__PURE__ */ e(V, { title: "Fetched Datasets", children: /* @__PURE__ */ e("div", { className: "space-y-4", children: p.map((K) => /* @__PURE__ */ r("div", { className: "rounded-md border border-gray-200 p-4", children: [
4250
4250
  /* @__PURE__ */ r("div", { className: "flex items-baseline justify-between gap-4", children: [
4251
4251
  /* @__PURE__ */ r("div", { children: [
@@ -4316,7 +4316,7 @@ function Gr({ output: t }) {
4316
4316
  /* @__PURE__ */ e(Aa, { type: "monotone", dataKey: i.y, stroke: "#3b82f6", strokeWidth: 2, dot: { r: 3 } })
4317
4317
  ] }) : i.type === "pie" ? /* @__PURE__ */ r(Ta, { children: [
4318
4318
  /* @__PURE__ */ e(It, { formatter: (v) => ct(v, Ot(o, i.y)) }),
4319
- /* @__PURE__ */ e(Pa, { data: m, dataKey: i.y, nameKey: i.x, outerRadius: 110, children: m.map((v, w) => /* @__PURE__ */ e(Ra, { fill: Sn[w % Sn.length] }, w)) })
4319
+ /* @__PURE__ */ e(Pa, { data: m, dataKey: i.y, nameKey: i.x, outerRadius: 110, children: m.map((v, D) => /* @__PURE__ */ e(Ra, { fill: Sn[D % Sn.length] }, D)) })
4320
4320
  ] }) : /* @__PURE__ */ r(Ia, { data: m, margin: { top: 10, right: 20, left: 0, bottom: 0 }, children: [
4321
4321
  /* @__PURE__ */ e(an, { strokeDasharray: "3 3", stroke: "#f3f4f6" }),
4322
4322
  /* @__PURE__ */ e(
@@ -4568,57 +4568,65 @@ function Yr(t) {
4568
4568
  }
4569
4569
  const Zr = ["USD", "EUR", "GBP", "CHF", "JPY", "CAD", "AUD", "CNY", "INR"];
4570
4570
  function Xr() {
4571
- const t = We(), { data: n, isLoading: a } = ie({
4571
+ const t = We(), { data: n, isLoading: a } = le({
4572
4572
  queryKey: ["setup-status"],
4573
4573
  queryFn: () => O.setupStatus()
4574
- }), [s, l] = N(""), [i, c] = N("USD"), [o, m] = N("quick"), [d, u] = N(!1), [p, v] = N(null), w = me({
4575
- mutationFn: () => O.createCompany({ name: s, currency: i })
4576
- }), g = me({
4574
+ }), [s, l] = S(""), [i, c] = S("USD"), [o, m] = S({
4575
+ address: "",
4576
+ city: "",
4577
+ zip_code: "",
4578
+ country: "",
4579
+ email: "",
4580
+ phone: "",
4581
+ tax_id: ""
4582
+ }), d = (w) => (N) => m((q) => ({ ...q, [w]: N.target.value })), [u, p] = S("quick"), [v, D] = S(!1), [h, y] = S(null), R = pe({
4583
+ mutationFn: () => O.createCompany({ name: s, currency: i, ...o })
4584
+ }), B = pe({
4577
4585
  mutationFn: () => O.seedDemo()
4578
- }), y = me({
4586
+ }), C = pe({
4579
4587
  mutationFn: () => O.seedHistory()
4580
- }), I = async () => {
4588
+ }), b = async () => {
4581
4589
  if (s.trim())
4582
4590
  try {
4583
- if (await w.mutateAsync(), o === "history") {
4584
- const b = await y.mutateAsync();
4585
- v(b.stats);
4586
- } else o === "quick" && await g.mutateAsync();
4587
- t.invalidateQueries({ queryKey: ["setup-status"] }), u(!0);
4591
+ if (await R.mutateAsync(), u === "history") {
4592
+ const w = await C.mutateAsync();
4593
+ y(w.stats);
4594
+ } else u === "quick" && await B.mutateAsync();
4595
+ t.invalidateQueries({ queryKey: ["setup-status"] }), D(!0);
4588
4596
  } catch {
4589
4597
  }
4590
4598
  };
4591
4599
  if (a)
4592
4600
  return /* @__PURE__ */ e("p", { className: "text-gray-500", children: "Loading..." });
4593
- if (n != null && n.setup_complete && !d)
4601
+ if (n != null && n.setup_complete && !v)
4594
4602
  return /* @__PURE__ */ r("div", { className: "space-y-6", children: [
4595
- /* @__PURE__ */ e(V, { title: "Companies", children: n.companies && n.companies.length > 0 ? /* @__PURE__ */ e("ul", { className: "divide-y divide-gray-100", children: n.companies.map((b, h) => /* @__PURE__ */ e("li", { className: "py-3", children: /* @__PURE__ */ e(es, { company: b }) }, h)) }) : /* @__PURE__ */ e("p", { className: "text-gray-400", children: "No companies found" }) }),
4603
+ /* @__PURE__ */ e(V, { title: "Companies", children: n.companies && n.companies.length > 0 ? /* @__PURE__ */ e("ul", { className: "divide-y divide-gray-100", children: n.companies.map((w, N) => /* @__PURE__ */ e("li", { className: "py-3", children: /* @__PURE__ */ e(es, { company: w }) }, N)) }) : /* @__PURE__ */ e("p", { className: "text-gray-400", children: "No companies found" }) }),
4596
4604
  /* @__PURE__ */ e(ye, { to: "/", className: "text-blue-600 hover:text-blue-800 text-sm font-medium", children: "Go to Dashboard" })
4597
4605
  ] });
4598
- if (d)
4606
+ if (v)
4599
4607
  return /* @__PURE__ */ e("div", { className: "space-y-6", children: /* @__PURE__ */ e(V, { children: /* @__PURE__ */ r("div", { className: "py-8 text-center", children: [
4600
4608
  /* @__PURE__ */ e("p", { className: "text-lg font-semibold text-green-700", children: "Setup complete!" }),
4601
- /* @__PURE__ */ e("p", { className: "mt-2 text-sm text-gray-500", children: o === "history" ? "Your company has been created and three years of history has been simulated." : o === "quick" ? "Your company has been created and demo data has been seeded." : "Your company has been created. No demo data was added." }),
4602
- p && /* @__PURE__ */ r("div", { className: "mx-auto mt-6 max-w-sm text-left", children: [
4609
+ /* @__PURE__ */ e("p", { className: "mt-2 text-sm text-gray-500", children: u === "history" ? "Your company has been created and three years of history has been simulated." : u === "quick" ? "Your company has been created and demo data has been seeded." : "Your company has been created. No demo data was added." }),
4610
+ h && /* @__PURE__ */ r("div", { className: "mx-auto mt-6 max-w-sm text-left", children: [
4603
4611
  /* @__PURE__ */ e("p", { className: "mb-2 text-sm font-medium text-gray-700", children: "Generated documents:" }),
4604
- /* @__PURE__ */ e("ul", { className: "divide-y divide-gray-100 text-sm", children: Object.entries(p).sort(([b], [h]) => b.localeCompare(h)).map(([b, h]) => /* @__PURE__ */ r("li", { className: "flex justify-between py-1", children: [
4605
- /* @__PURE__ */ e("span", { className: "text-gray-600", children: b.replace(/_/g, " ") }),
4606
- /* @__PURE__ */ e("span", { className: "font-mono text-gray-900", children: h.toLocaleString() })
4607
- ] }, b)) })
4612
+ /* @__PURE__ */ e("ul", { className: "divide-y divide-gray-100 text-sm", children: Object.entries(h).sort(([w], [N]) => w.localeCompare(N)).map(([w, N]) => /* @__PURE__ */ r("li", { className: "flex justify-between py-1", children: [
4613
+ /* @__PURE__ */ e("span", { className: "text-gray-600", children: w.replace(/_/g, " ") }),
4614
+ /* @__PURE__ */ e("span", { className: "font-mono text-gray-900", children: N.toLocaleString() })
4615
+ ] }, w)) })
4608
4616
  ] }),
4609
- /* @__PURE__ */ e("div", { className: "mt-6", children: /* @__PURE__ */ e(ye, { to: "/", children: /* @__PURE__ */ e(X, { children: "Go to Dashboard" }) }) })
4617
+ /* @__PURE__ */ e("div", { className: "mt-6", children: /* @__PURE__ */ e(ye, { to: "/", children: /* @__PURE__ */ e(ee, { children: "Go to Dashboard" }) }) })
4610
4618
  ] }) }) });
4611
- const L = w.isPending || g.isPending || y.isPending, C = w.error ?? g.error ?? y.error;
4619
+ const g = R.isPending || B.isPending || C.isPending, _ = R.error ?? B.error ?? C.error;
4612
4620
  return /* @__PURE__ */ r("div", { className: "mx-auto max-w-lg space-y-6", children: [
4613
4621
  /* @__PURE__ */ e("p", { className: "text-sm text-gray-500", children: "Set up your first company to get started." }),
4614
- C && /* @__PURE__ */ e("div", { className: "rounded-md bg-red-50 p-4 text-sm text-red-700", children: C.message ?? "An error occurred during setup" }),
4622
+ _ && /* @__PURE__ */ e("div", { className: "rounded-md bg-red-50 p-4 text-sm text-red-700", children: _.message ?? "An error occurred during setup" }),
4615
4623
  /* @__PURE__ */ e(V, { children: /* @__PURE__ */ r("div", { className: "space-y-4", children: [
4616
4624
  /* @__PURE__ */ e(
4617
- pe,
4625
+ X,
4618
4626
  {
4619
4627
  label: "Company Name",
4620
4628
  value: s,
4621
- onChange: (b) => l(b.target.value),
4629
+ onChange: (w) => l(w.target.value),
4622
4630
  placeholder: "e.g. My Company Ltd",
4623
4631
  required: !0
4624
4632
  }
@@ -4629,9 +4637,34 @@ function Xr() {
4629
4637
  label: "Currency",
4630
4638
  options: Zr,
4631
4639
  value: i,
4632
- onChange: (b) => c(b.target.value)
4640
+ onChange: (w) => c(w.target.value)
4633
4641
  }
4634
4642
  ),
4643
+ /* @__PURE__ */ r("fieldset", { className: "space-y-3", children: [
4644
+ /* @__PURE__ */ e("legend", { className: "mb-1 text-sm font-medium text-gray-700", children: "Company details" }),
4645
+ /* @__PURE__ */ e("p", { className: "text-xs text-gray-500", children: "These appear on your invoices and other PDFs. Optional now — you can fill or change them later under Masters → Company." }),
4646
+ /* @__PURE__ */ e(
4647
+ X,
4648
+ {
4649
+ label: "Address",
4650
+ value: o.address,
4651
+ onChange: d("address"),
4652
+ placeholder: "e.g. 42 Market Street"
4653
+ }
4654
+ ),
4655
+ /* @__PURE__ */ r("div", { className: "grid grid-cols-2 gap-3", children: [
4656
+ /* @__PURE__ */ e(X, { label: "City", value: o.city, onChange: d("city") }),
4657
+ /* @__PURE__ */ e(X, { label: "ZIP / Postal code", value: o.zip_code, onChange: d("zip_code") })
4658
+ ] }),
4659
+ /* @__PURE__ */ r("div", { className: "grid grid-cols-2 gap-3", children: [
4660
+ /* @__PURE__ */ e(X, { label: "Country", value: o.country, onChange: d("country") }),
4661
+ /* @__PURE__ */ e(X, { label: "Tax ID / VAT", value: o.tax_id, onChange: d("tax_id") })
4662
+ ] }),
4663
+ /* @__PURE__ */ r("div", { className: "grid grid-cols-2 gap-3", children: [
4664
+ /* @__PURE__ */ e(X, { label: "Email", value: o.email, onChange: d("email") }),
4665
+ /* @__PURE__ */ e(X, { label: "Phone", value: o.phone, onChange: d("phone") })
4666
+ ] })
4667
+ ] }),
4635
4668
  /* @__PURE__ */ r("fieldset", { className: "space-y-2", children: [
4636
4669
  /* @__PURE__ */ e("legend", { className: "mb-1 text-sm font-medium text-gray-700", children: "Seed data" }),
4637
4670
  /* @__PURE__ */ r("label", { className: "flex cursor-pointer items-start gap-3 rounded-md border border-gray-200 p-3 hover:bg-gray-50", children: [
@@ -4641,8 +4674,8 @@ function Xr() {
4641
4674
  type: "radio",
4642
4675
  name: "seed-mode",
4643
4676
  value: "quick",
4644
- checked: o === "quick",
4645
- onChange: () => m("quick"),
4677
+ checked: u === "quick",
4678
+ onChange: () => p("quick"),
4646
4679
  className: "mt-1"
4647
4680
  }
4648
4681
  ),
@@ -4658,8 +4691,8 @@ function Xr() {
4658
4691
  type: "radio",
4659
4692
  name: "seed-mode",
4660
4693
  value: "history",
4661
- checked: o === "history",
4662
- onChange: () => m("history"),
4694
+ checked: u === "history",
4695
+ onChange: () => p("history"),
4663
4696
  className: "mt-1"
4664
4697
  }
4665
4698
  ),
@@ -4675,8 +4708,8 @@ function Xr() {
4675
4708
  type: "radio",
4676
4709
  name: "seed-mode",
4677
4710
  value: "none",
4678
- checked: o === "none",
4679
- onChange: () => m("none"),
4711
+ checked: u === "none",
4712
+ onChange: () => p("none"),
4680
4713
  className: "mt-1"
4681
4714
  }
4682
4715
  ),
@@ -4687,11 +4720,11 @@ function Xr() {
4687
4720
  ] })
4688
4721
  ] }),
4689
4722
  /* @__PURE__ */ e("div", { className: "pt-2", children: /* @__PURE__ */ e(
4690
- X,
4723
+ ee,
4691
4724
  {
4692
- onClick: I,
4693
- disabled: L || !s.trim(),
4694
- children: L ? o === "history" ? "Simulating three years..." : "Setting up..." : o === "history" ? "Create Company & Simulate History" : o === "quick" ? "Create Company & Seed Demo Data" : "Create Company"
4725
+ onClick: b,
4726
+ disabled: g || !s.trim(),
4727
+ children: g ? u === "history" ? "Simulating three years..." : "Setting up..." : u === "history" ? "Create Company & Simulate History" : u === "quick" ? "Create Company & Seed Demo Data" : "Create Company"
4695
4728
  }
4696
4729
  ) })
4697
4730
  ] }) })
@@ -5171,152 +5204,152 @@ function wn(t) {
5171
5204
  });
5172
5205
  }
5173
5206
  function Cn() {
5174
- const { t } = Z(), { sessionId: n } = ut(), a = Oe(), s = dt(), [l] = wt(), i = l.get("demo") === "1", [c, o] = N(""), [m, d] = N(""), [u, p] = N([]), [v, w] = N(""), [g, y] = N(!1), I = H(null), {
5175
- connectionStatus: L,
5207
+ const { t } = Z(), { sessionId: n } = ut(), a = Oe(), s = dt(), [l] = wt(), i = l.get("demo") === "1", [c, o] = S(""), [m, d] = S(""), [u, p] = S([]), [v, D] = S(""), [h, y] = S(!1), R = H(null), {
5208
+ connectionStatus: B,
5176
5209
  connectionVersion: C,
5177
5210
  createSession: b,
5178
- startDemo: h,
5179
- completeDemoTyping: A,
5180
- loadHistory: B,
5181
- loadMoreHistory: k,
5211
+ startDemo: g,
5212
+ completeDemoTyping: _,
5213
+ loadHistory: w,
5214
+ loadMoreHistory: N,
5182
5215
  sendMessage: q,
5183
5216
  getMessages: x,
5184
5217
  hasMoreHistory: z,
5185
5218
  isLoadingOlder: j,
5186
5219
  isThinking: U,
5187
5220
  getDemoStatus: Y,
5188
- getDemoTypingCue: ce
5189
- } = tt(), T = H(null), K = H(null), se = H(null), le = H(null), [ge, _] = N(0), Q = H(!1), oe = H(null), ne = H(0), Be = H(!0), Pe = H(null), _e = H(!1), $e = H(null), Re = x(n), he = L === "connected", xe = U(n), qe = Y(n), ze = ce(n), Ae = i || qe === "running", nt = z(n), Qe = j(n), at = Re[Re.length - 1], _t = at ? `${at.type}:${at.timestamp || ""}:${at.content}` : "empty", He = we(() => {
5221
+ getDemoTypingCue: de
5222
+ } = tt(), P = H(null), K = H(null), ie = H(null), oe = H(null), [ge, T] = S(0), Q = H(!1), ce = H(null), ae = H(0), Be = H(!0), Pe = H(null), _e = H(!1), $e = H(null), Re = x(n), he = B === "connected", xe = U(n), qe = Y(n), ze = de(n), Ae = i || qe === "running", nt = z(n), Qe = j(n), at = Re[Re.length - 1], _t = at ? `${at.type}:${at.timestamp || ""}:${at.content}` : "empty", He = we(() => {
5190
5223
  _e.current = !0, $e.current !== null && window.clearTimeout($e.current), $e.current = window.setTimeout(() => {
5191
5224
  _e.current = !1, $e.current = null;
5192
5225
  }, 600);
5193
5226
  }, []), pt = we((f = "smooth") => {
5194
- const D = T.current;
5195
- if (!D) return;
5196
- He(), D.scrollTo({ top: D.scrollHeight, behavior: f });
5197
- const ee = () => {
5198
- const ae = T.current;
5199
- ae && (!Be.current && !Ae && !xe || ae.scrollTop + ae.clientHeight >= ae.scrollHeight - 2 || (He(), ae.scrollTo({ top: ae.scrollHeight, behavior: "auto" })));
5227
+ const A = P.current;
5228
+ if (!A) return;
5229
+ He(), A.scrollTo({ top: A.scrollHeight, behavior: f });
5230
+ const te = () => {
5231
+ const re = P.current;
5232
+ re && (!Be.current && !Ae && !xe || re.scrollTop + re.clientHeight >= re.scrollHeight - 2 || (He(), re.scrollTo({ top: re.scrollHeight, behavior: "auto" })));
5200
5233
  };
5201
- requestAnimationFrame(ee), window.setTimeout(ee, 120);
5234
+ requestAnimationFrame(te), window.setTimeout(te, 120);
5202
5235
  }, [Ae, xe, He]);
5203
5236
  tn(() => {
5204
- const f = T.current, D = Pe.current;
5205
- if (!f || D === null) return;
5206
- const ee = f.scrollHeight - D;
5207
- ee > 0 && (f.scrollTop = f.scrollTop + ee), Pe.current = null;
5208
- }, [Re.length]), re(() => {
5237
+ const f = P.current, A = Pe.current;
5238
+ if (!f || A === null) return;
5239
+ const te = f.scrollHeight - A;
5240
+ te > 0 && (f.scrollTop = f.scrollTop + te), Pe.current = null;
5241
+ }, [Re.length]), se(() => {
5209
5242
  Pe.current === null && (!Be.current && !Ae && !xe || pt(Ae ? "auto" : "smooth"));
5210
- }, [_t, Ae, xe, pt]), re(() => {
5211
- const f = T.current;
5243
+ }, [_t, Ae, xe, pt]), se(() => {
5244
+ const f = P.current;
5212
5245
  if (!f || typeof ResizeObserver > "u") return;
5213
- let D = 0;
5214
- const ee = new ResizeObserver(() => {
5215
- Pe.current === null && (!Be.current && !Ae && !xe || (cancelAnimationFrame(D), D = requestAnimationFrame(() => {
5216
- const te = T.current;
5217
- if (!te) return;
5218
- te.scrollHeight - te.scrollTop - te.clientHeight <= 120 && (He(), te.scrollTo({ top: te.scrollHeight, behavior: "auto" }));
5246
+ let A = 0;
5247
+ const te = new ResizeObserver(() => {
5248
+ Pe.current === null && (!Be.current && !Ae && !xe || (cancelAnimationFrame(A), A = requestAnimationFrame(() => {
5249
+ const ne = P.current;
5250
+ if (!ne) return;
5251
+ ne.scrollHeight - ne.scrollTop - ne.clientHeight <= 120 && (He(), ne.scrollTo({ top: ne.scrollHeight, behavior: "auto" }));
5219
5252
  })));
5220
- }), ae = f.firstElementChild;
5221
- return ae && ee.observe(ae), ee.observe(f), () => {
5222
- ee.disconnect(), cancelAnimationFrame(D);
5253
+ }), re = f.firstElementChild;
5254
+ return re && te.observe(re), te.observe(f), () => {
5255
+ te.disconnect(), cancelAnimationFrame(A);
5223
5256
  };
5224
5257
  }, [Ae, xe, He]), tn(() => {
5225
- const f = le.current;
5226
- if (!f || (_(f.offsetHeight), typeof ResizeObserver > "u")) return;
5227
- const D = new ResizeObserver(() => _(f.offsetHeight));
5228
- return D.observe(f), () => D.disconnect();
5258
+ const f = oe.current;
5259
+ if (!f || (T(f.offsetHeight), typeof ResizeObserver > "u")) return;
5260
+ const A = new ResizeObserver(() => T(f.offsetHeight));
5261
+ return A.observe(f), () => A.disconnect();
5229
5262
  }, []);
5230
5263
  const At = we(() => {
5231
5264
  if (!n || Qe || !nt) return;
5232
- const f = T.current;
5233
- Pe.current = f ? f.scrollHeight : null, Be.current = !1, k(n).catch(() => {
5265
+ const f = P.current;
5266
+ Pe.current = f ? f.scrollHeight : null, Be.current = !1, N(n).catch(() => {
5234
5267
  Pe.current = null;
5235
5268
  });
5236
- }, [n, Qe, nt, k]), S = H(null);
5237
- re(() => {
5238
- d(""), oe.current = null, ne.current += 1, n && Wn(n);
5269
+ }, [n, Qe, nt, N]), k = H(null);
5270
+ se(() => {
5271
+ d(""), ce.current = null, ae.current += 1, n && Wn(n);
5239
5272
  const f = s.state;
5240
- f != null && f.prefillMessage && S.current !== f ? (S.current = f, o(f.prefillMessage), window.setTimeout(() => {
5241
- var D;
5242
- return (D = se.current) == null ? void 0 : D.focus();
5243
- }, 50)) : f != null && f.prefillMessage || (S.current = null, o(""));
5244
- }, [n, i, s.state]), re(() => {
5273
+ f != null && f.prefillMessage && k.current !== f ? (k.current = f, o(f.prefillMessage), window.setTimeout(() => {
5274
+ var A;
5275
+ return (A = ie.current) == null ? void 0 : A.focus();
5276
+ }, 50)) : f != null && f.prefillMessage || (k.current = null, o(""));
5277
+ }, [n, i, s.state]), se(() => {
5245
5278
  if (n || !he) return;
5246
5279
  let f = !1;
5247
- return b().then((D) => {
5248
- f || a(`/chat/${D.id}`, { replace: !0 });
5280
+ return b().then((A) => {
5281
+ f || a(`/chat/${A.id}`, { replace: !0 });
5249
5282
  }).catch(() => {
5250
5283
  }), () => {
5251
5284
  f = !0;
5252
5285
  };
5253
5286
  }, [n, he, a]);
5254
- const G = H(B);
5255
- re(() => {
5256
- G.current = B;
5257
- }, [B]), re(() => {
5287
+ const G = H(w);
5288
+ se(() => {
5289
+ G.current = w;
5290
+ }, [w]), se(() => {
5258
5291
  !n || !he || i || qe === "running" || G.current(n).catch(() => {
5259
5292
  });
5260
- }, [n, he, C, i, qe]), re(() => {
5293
+ }, [n, he, C, i, qe]), se(() => {
5261
5294
  Q.current && !xe && he && setTimeout(() => {
5262
5295
  var f;
5263
- return (f = se.current) == null ? void 0 : f.focus();
5296
+ return (f = ie.current) == null ? void 0 : f.focus();
5264
5297
  }, 50), Q.current = xe;
5265
5298
  }, [xe, he]);
5266
5299
  function W(f) {
5267
5300
  if (_e.current) return;
5268
- const D = f.currentTarget, ee = D.scrollHeight - D.scrollTop - D.clientHeight;
5269
- Be.current = ee < 80;
5301
+ const A = f.currentTarget, te = A.scrollHeight - A.scrollTop - A.clientHeight;
5302
+ Be.current = te < 80;
5270
5303
  }
5271
- re(() => {
5272
- !n || !he || !i || oe.current !== n && (oe.current = n, d(""), h(n).catch((f) => {
5273
- oe.current = null, d(f instanceof Error ? f.message : t("chat.demoError"));
5304
+ se(() => {
5305
+ !n || !he || !i || ce.current !== n && (ce.current = n, d(""), g(n).catch((f) => {
5306
+ ce.current = null, d(f instanceof Error ? f.message : t("chat.demoError"));
5274
5307
  }));
5275
- }, [n, he, i, h]), re(() => {
5308
+ }, [n, he, i, g]), se(() => {
5276
5309
  !n || !i || qe !== "complete" || (o(""), a(`/chat/${n}`, { replace: !0 }));
5277
5310
  }, [n, i, qe, a]);
5278
- const Se = H(A);
5279
- re(() => {
5280
- Se.current = A;
5281
- }, [A]);
5311
+ const Se = H(_);
5312
+ se(() => {
5313
+ Se.current = _;
5314
+ }, [_]);
5282
5315
  const fe = H(null);
5283
- re(() => {
5316
+ se(() => {
5284
5317
  if (!ze || !n || fe.current === ze.seq) return;
5285
5318
  fe.current = ze.seq;
5286
- const f = n, D = ze.content, ee = D.length > 0 ? Math.max(8, ze.typingMs / D.length) : 0, ae = ze.seq, te = ++ne.current;
5319
+ const f = n, A = ze.content, te = A.length > 0 ? Math.max(8, ze.typingMs / A.length) : 0, re = ze.seq, ne = ++ae.current;
5287
5320
  async function rt() {
5288
5321
  o("");
5289
- for (const Tt of D) {
5290
- if (te !== ne.current) return;
5291
- o((Pt) => Pt + Tt), await os(ee);
5322
+ for (const Tt of A) {
5323
+ if (ne !== ae.current) return;
5324
+ o((Pt) => Pt + Tt), await os(te);
5292
5325
  }
5293
- te === ne.current && Se.current(f, ae);
5326
+ ne === ae.current && Se.current(f, re);
5294
5327
  }
5295
5328
  rt();
5296
- }, [ze, n]), re(() => {
5297
- qe === "complete" && (ne.current += 1, o(""));
5329
+ }, [ze, n]), se(() => {
5330
+ qe === "complete" && (ae.current += 1, o(""));
5298
5331
  }, [qe]);
5299
5332
  const ve = we((f) => {
5300
5333
  if (!n) return;
5301
- w("");
5302
- const D = Array.from(f);
5303
- p((ee) => {
5304
- const ae = [...ee];
5305
- for (const te of D) {
5306
- if (ae.length >= zt) {
5307
- w(`Maximum ${zt} attachments per message.`);
5334
+ D("");
5335
+ const A = Array.from(f);
5336
+ p((te) => {
5337
+ const re = [...te];
5338
+ for (const ne of A) {
5339
+ if (re.length >= zt) {
5340
+ D(`Maximum ${zt} attachments per message.`);
5308
5341
  break;
5309
5342
  }
5310
- if (!ls.has(te.type)) {
5311
- w(`Unsupported file type: ${te.type || te.name}`);
5343
+ if (!ls.has(ne.type)) {
5344
+ D(`Unsupported file type: ${ne.type || ne.name}`);
5312
5345
  continue;
5313
5346
  }
5314
- if (te.size > is) {
5315
- w(`"${te.name}" is too large (max 10 MB).`);
5347
+ if (ne.size > is) {
5348
+ D(`"${ne.name}" is too large (max 10 MB).`);
5316
5349
  continue;
5317
5350
  }
5318
- const rt = `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`, Tt = te.type.startsWith("image/") ? URL.createObjectURL(te) : void 0, Pt = { localId: rt, file: te, previewUrl: Tt, uploading: !0 };
5319
- ae.push(Pt), O.uploadChatAttachment(n, te).then((it) => {
5351
+ const rt = `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`, Tt = ne.type.startsWith("image/") ? URL.createObjectURL(ne) : void 0, Pt = { localId: rt, file: ne, previewUrl: Tt, uploading: !0 };
5352
+ re.push(Pt), O.uploadChatAttachment(n, ne).then((it) => {
5320
5353
  p(
5321
5354
  (ht) => ht.map(
5322
5355
  (lt) => lt.localId === rt ? { ...lt, uploading: !1, uploadedId: it.id } : lt
@@ -5324,42 +5357,42 @@ function Cn() {
5324
5357
  );
5325
5358
  }).catch((it) => {
5326
5359
  const ht = (it == null ? void 0 : it.message) || "Upload failed";
5327
- w(`"${te.name}": ${ht}`), p(
5360
+ D(`"${ne.name}": ${ht}`), p(
5328
5361
  (lt) => lt.map(
5329
5362
  (Rt) => Rt.localId === rt ? { ...Rt, uploading: !1, error: ht } : Rt
5330
5363
  )
5331
5364
  );
5332
5365
  });
5333
5366
  }
5334
- return ae;
5367
+ return re;
5335
5368
  });
5336
5369
  }, [n]), Je = (f) => {
5337
- p((D) => {
5338
- const ee = D.find((ae) => ae.localId === f);
5339
- return ee != null && ee.previewUrl && URL.revokeObjectURL(ee.previewUrl), D.filter((ae) => ae.localId !== f);
5370
+ p((A) => {
5371
+ const te = A.find((re) => re.localId === f);
5372
+ return te != null && te.previewUrl && URL.revokeObjectURL(te.previewUrl), A.filter((re) => re.localId !== f);
5340
5373
  });
5341
5374
  }, F = (f) => {
5342
5375
  f.dataTransfer.types.includes("Files") && (f.preventDefault(), y(!0));
5343
5376
  }, Ye = (f) => {
5344
- const D = f.relatedTarget;
5345
- (!D || !f.currentTarget.contains(D)) && y(!1);
5346
- }, de = (f) => {
5377
+ const A = f.relatedTarget;
5378
+ (!A || !f.currentTarget.contains(A)) && y(!1);
5379
+ }, ue = (f) => {
5347
5380
  f.preventDefault(), y(!1), f.dataTransfer.files && f.dataTransfer.files.length > 0 && ve(f.dataTransfer.files);
5348
- }, P = (f) => {
5349
- const D = [];
5350
- for (const ee of f.clipboardData.items)
5351
- if (ee.kind === "file") {
5352
- const ae = ee.getAsFile();
5353
- ae && D.push(ae);
5381
+ }, I = (f) => {
5382
+ const A = [];
5383
+ for (const te of f.clipboardData.items)
5384
+ if (te.kind === "file") {
5385
+ const re = te.getAsFile();
5386
+ re && A.push(re);
5354
5387
  }
5355
- D.length > 0 && (f.preventDefault(), ve(D));
5356
- }, R = u.some((f) => f.uploading), M = u.some((f) => f.error), $ = u.filter((f) => f.uploadedId && !f.error).map((f) => f.uploadedId);
5388
+ A.length > 0 && (f.preventDefault(), ve(A));
5389
+ }, L = u.some((f) => f.uploading), M = u.some((f) => f.error), $ = u.filter((f) => f.uploadedId && !f.error).map((f) => f.uploadedId);
5357
5390
  function Te() {
5358
5391
  const f = c.trim();
5359
- if (n && !(!f && $.length === 0) && !R && q(n, f, $.length > 0 ? $ : void 0)) {
5360
- for (const D of u)
5361
- D.previewUrl && URL.revokeObjectURL(D.previewUrl);
5362
- p([]), w(""), o("");
5392
+ if (n && !(!f && $.length === 0) && !L && q(n, f, $.length > 0 ? $ : void 0)) {
5393
+ for (const A of u)
5394
+ A.previewUrl && URL.revokeObjectURL(A.previewUrl);
5395
+ p([]), D(""), o("");
5363
5396
  }
5364
5397
  }
5365
5398
  function be(f) {
@@ -5371,13 +5404,13 @@ function Cn() {
5371
5404
  className: "relative -m-4 h-[calc(100%+2rem)] overflow-hidden md:-m-6 md:h-[calc(100%+3rem)]",
5372
5405
  onDragOver: F,
5373
5406
  onDragLeave: Ye,
5374
- onDrop: de,
5407
+ onDrop: ue,
5375
5408
  children: [
5376
- g && /* @__PURE__ */ e("div", { className: "pointer-events-none absolute inset-3 z-50 flex items-center justify-center rounded-lg border-2 border-dashed border-brand bg-brand/5 text-sm font-medium text-brand", children: t("chat.dropToAttach") }),
5409
+ h && /* @__PURE__ */ e("div", { className: "pointer-events-none absolute inset-3 z-50 flex items-center justify-center rounded-lg border-2 border-dashed border-brand bg-brand/5 text-sm font-medium text-brand", children: t("chat.dropToAttach") }),
5377
5410
  /* @__PURE__ */ e(
5378
5411
  "div",
5379
5412
  {
5380
- ref: T,
5413
+ ref: P,
5381
5414
  className: "absolute inset-0 overflow-y-auto px-4 py-6",
5382
5415
  onScroll: W,
5383
5416
  children: /* @__PURE__ */ r(
@@ -5408,8 +5441,8 @@ function Cn() {
5408
5441
  "button",
5409
5442
  {
5410
5443
  onClick: () => {
5411
- var D;
5412
- o(f), (D = se.current) == null || D.focus();
5444
+ var A;
5445
+ o(f), (A = ie.current) == null || A.focus();
5413
5446
  },
5414
5447
  className: "rounded-full bg-surface px-3 py-1.5 text-xs text-fg-muted ring-1 ring-line transition-all hover:bg-surface-subtle hover:text-fg hover:ring-brand/30",
5415
5448
  children: f
@@ -5417,7 +5450,7 @@ function Cn() {
5417
5450
  f
5418
5451
  )) })
5419
5452
  ] }),
5420
- Re.map((f, D) => /* @__PURE__ */ e(ds, { message: f }, D)),
5453
+ Re.map((f, A) => /* @__PURE__ */ e(ds, { message: f }, A)),
5421
5454
  /* @__PURE__ */ e("div", { ref: K })
5422
5455
  ]
5423
5456
  }
@@ -5427,7 +5460,7 @@ function Cn() {
5427
5460
  /* @__PURE__ */ e(
5428
5461
  "div",
5429
5462
  {
5430
- ref: le,
5463
+ ref: oe,
5431
5464
  className: "absolute bottom-0 left-0 right-0 bg-surface-muted px-4 pb-[max(0.75rem,env(safe-area-inset-bottom))] md:right-6 md:pl-6 md:pr-0",
5432
5465
  children: /* @__PURE__ */ r("div", { className: "mx-auto max-w-3xl", children: [
5433
5466
  u.length > 0 && /* @__PURE__ */ e("div", { className: "mb-2 flex flex-wrap gap-2", children: u.map((f) => /* @__PURE__ */ r(
@@ -5457,7 +5490,7 @@ function Cn() {
5457
5490
  /* @__PURE__ */ e(
5458
5491
  "input",
5459
5492
  {
5460
- ref: I,
5493
+ ref: R,
5461
5494
  type: "file",
5462
5495
  accept: "image/png,image/jpeg,image/gif,image/webp,application/pdf",
5463
5496
  multiple: !0,
@@ -5471,19 +5504,19 @@ function Cn() {
5471
5504
  /* @__PURE__ */ e(
5472
5505
  "textarea",
5473
5506
  {
5474
- ref: se,
5507
+ ref: ie,
5475
5508
  value: c,
5476
5509
  onChange: (f) => o(f.target.value),
5477
5510
  onKeyDown: be,
5478
- onPaste: P,
5511
+ onPaste: I,
5479
5512
  placeholder: t(Ae ? "chat.placeholderDemo" : he ? "chat.placeholderType" : "chat.placeholderConnecting"),
5480
5513
  disabled: !he || !n || xe || Ae,
5481
5514
  rows: 2,
5482
5515
  className: "block flex-1 resize-none bg-transparent px-2.5 py-1.5 text-sm text-fg outline-none placeholder:text-fg-muted/70 disabled:text-fg-muted",
5483
5516
  style: { minHeight: "3rem", maxHeight: "120px" },
5484
5517
  onInput: (f) => {
5485
- const D = f.target;
5486
- D.style.height = "auto", D.style.height = Math.min(Math.max(D.scrollHeight, 48), 120) + "px";
5518
+ const A = f.target;
5519
+ A.style.height = "auto", A.style.height = Math.min(Math.max(A.scrollHeight, 48), 120) + "px";
5487
5520
  }
5488
5521
  }
5489
5522
  ),
@@ -5492,7 +5525,7 @@ function Cn() {
5492
5525
  {
5493
5526
  onClick: () => {
5494
5527
  var f;
5495
- return (f = I.current) == null ? void 0 : f.click();
5528
+ return (f = R.current) == null ? void 0 : f.click();
5496
5529
  },
5497
5530
  disabled: !he || !n || xe || Ae || u.length >= zt,
5498
5531
  className: "flex h-11 w-11 shrink-0 items-center justify-center rounded-lg text-fg-muted transition-all hover:bg-surface-subtle hover:text-fg disabled:cursor-not-allowed disabled:opacity-40 md:h-10 md:w-10",
@@ -5504,7 +5537,7 @@ function Cn() {
5504
5537
  "button",
5505
5538
  {
5506
5539
  onClick: Te,
5507
- disabled: !c.trim() && $.length === 0 || !he || !n || xe || Ae || R || M,
5540
+ disabled: !c.trim() && $.length === 0 || !he || !n || xe || Ae || L || M,
5508
5541
  className: "flex h-11 w-11 shrink-0 items-center justify-center rounded-lg text-brand transition-all hover:bg-brand/10 active:translate-y-px disabled:cursor-not-allowed disabled:text-fg-muted disabled:active:translate-y-0 md:h-10 md:w-10",
5509
5542
  children: /* @__PURE__ */ e(
5510
5543
  "svg",
@@ -5526,7 +5559,7 @@ function Cn() {
5526
5559
  className: `inline-block h-1.5 w-1.5 rounded-full ${he ? "bg-emerald-500" : "bg-rose-500"} ${he ? "" : "animate-pulse"}`
5527
5560
  }
5528
5561
  ),
5529
- /* @__PURE__ */ e("span", { className: "text-[11px] text-fg-muted", children: he ? "Connected" : L === "connecting" ? "Connecting..." : "Disconnected" })
5562
+ /* @__PURE__ */ e("span", { className: "text-[11px] text-fg-muted", children: he ? "Connected" : B === "connecting" ? "Connecting..." : "Disconnected" })
5530
5563
  ] })
5531
5564
  ] })
5532
5565
  }
@@ -5692,35 +5725,35 @@ function ps(t, n) {
5692
5725
  return s < t.length && a.push(t.slice(s)), a.length > 0 ? a : [t];
5693
5726
  }
5694
5727
  function hs() {
5695
- const t = Oe(), [n] = wt(), { user: a, login: s, register: l } = mt(), { t: i } = Z(), c = n.get("invite") || "", [o, m] = N(c ? "register" : "login"), [d, u] = N(!1), [p, v] = N(!0), [w, g] = N(""), [y, I] = N(""), [L, C] = N(""), [b, h] = N(""), [A, B] = N("");
5696
- re(() => {
5728
+ const t = Oe(), [n] = wt(), { user: a, login: s, register: l } = mt(), { t: i } = Z(), c = n.get("invite") || "", [o, m] = S(c ? "register" : "login"), [d, u] = S(!1), [p, v] = S(!0), [D, h] = S(""), [y, R] = S(""), [B, C] = S(""), [b, g] = S(""), [_, w] = S("");
5729
+ se(() => {
5697
5730
  a && a.role !== "public_manager" && t("/", { replace: !0 });
5698
- }, [a, t]), re(() => {
5731
+ }, [a, t]), se(() => {
5699
5732
  O.authSetupStatus().then((q) => {
5700
5733
  u(q.registration_open), q.registration_open && m("register");
5701
5734
  }).catch(() => {
5702
5735
  }).finally(() => v(!1));
5703
5736
  }, []);
5704
- const k = async (q) => {
5705
- if (q.preventDefault(), g(""), o === "register") {
5706
- if (b !== A) {
5707
- g(i("login.passwordsNoMatch"));
5737
+ const N = async (q) => {
5738
+ if (q.preventDefault(), h(""), o === "register") {
5739
+ if (b !== _) {
5740
+ h(i("login.passwordsNoMatch"));
5708
5741
  return;
5709
5742
  }
5710
5743
  if (b.length < 6) {
5711
- g(i("login.passwordTooShort"));
5744
+ h(i("login.passwordTooShort"));
5712
5745
  return;
5713
5746
  }
5714
5747
  try {
5715
- await l(y, L, b, c || void 0), t("/", { replace: !0 });
5748
+ await l(y, B, b, c || void 0), t("/", { replace: !0 });
5716
5749
  } catch (x) {
5717
- g(x instanceof et ? x.message : i("login.registrationFailed"));
5750
+ h(x instanceof et ? x.message : i("login.registrationFailed"));
5718
5751
  }
5719
5752
  } else
5720
5753
  try {
5721
5754
  await s(y, b), t("/", { replace: !0 });
5722
5755
  } catch (x) {
5723
- g(x instanceof et ? x.message : i("login.loginFailed"));
5756
+ h(x instanceof et ? x.message : i("login.loginFailed"));
5724
5757
  }
5725
5758
  };
5726
5759
  return p ? /* @__PURE__ */ e("div", { className: "flex h-dvh items-center justify-center bg-surface-muted", children: /* @__PURE__ */ e("div", { className: "text-fg-muted", children: i("common.loading") }) }) : /* @__PURE__ */ e("div", { className: "flex min-h-dvh items-center justify-center bg-surface-muted px-4", children: /* @__PURE__ */ r("div", { className: "w-full max-w-sm space-y-6", children: [
@@ -5729,48 +5762,48 @@ function hs() {
5729
5762
  /* @__PURE__ */ e("p", { className: "mt-1 text-sm text-fg-muted", children: i(d ? "login.taglineFirstRun" : o === "register" ? "login.taglineRegister" : "login.taglineSignIn") }),
5730
5763
  (a == null ? void 0 : a.role) === "public_manager" && /* @__PURE__ */ e("p", { className: "mt-2 text-xs text-amber-700", children: i("login.demoBanner") })
5731
5764
  ] }),
5732
- w && /* @__PURE__ */ e("div", { className: "rounded-lg bg-rose-50 px-4 py-3 text-sm text-rose-700 ring-1 ring-rose-200", children: w }),
5733
- /* @__PURE__ */ e(V, { children: /* @__PURE__ */ r("form", { onSubmit: k, className: "space-y-4", children: [
5765
+ D && /* @__PURE__ */ e("div", { className: "rounded-lg bg-rose-50 px-4 py-3 text-sm text-rose-700 ring-1 ring-rose-200", children: D }),
5766
+ /* @__PURE__ */ e(V, { children: /* @__PURE__ */ r("form", { onSubmit: N, className: "space-y-4", children: [
5734
5767
  o === "register" && /* @__PURE__ */ e(
5735
- pe,
5768
+ X,
5736
5769
  {
5737
5770
  label: i("login.fullName"),
5738
- value: L,
5771
+ value: B,
5739
5772
  onChange: (q) => C(q.target.value),
5740
5773
  required: !0
5741
5774
  }
5742
5775
  ),
5743
5776
  /* @__PURE__ */ e(
5744
- pe,
5777
+ X,
5745
5778
  {
5746
5779
  label: i("login.email"),
5747
5780
  type: "email",
5748
5781
  value: y,
5749
- onChange: (q) => I(q.target.value),
5782
+ onChange: (q) => R(q.target.value),
5750
5783
  required: !0
5751
5784
  }
5752
5785
  ),
5753
5786
  /* @__PURE__ */ e(
5754
- pe,
5787
+ X,
5755
5788
  {
5756
5789
  label: i("login.password"),
5757
5790
  type: "password",
5758
5791
  value: b,
5759
- onChange: (q) => h(q.target.value),
5792
+ onChange: (q) => g(q.target.value),
5760
5793
  required: !0
5761
5794
  }
5762
5795
  ),
5763
5796
  o === "register" && /* @__PURE__ */ e(
5764
- pe,
5797
+ X,
5765
5798
  {
5766
5799
  label: i("login.confirmPassword"),
5767
5800
  type: "password",
5768
- value: A,
5769
- onChange: (q) => B(q.target.value),
5801
+ value: _,
5802
+ onChange: (q) => w(q.target.value),
5770
5803
  required: !0
5771
5804
  }
5772
5805
  ),
5773
- /* @__PURE__ */ e(X, { type: "submit", className: "w-full", children: i(o === "register" ? d ? "login.createAdmin" : "login.register" : "login.signIn") })
5806
+ /* @__PURE__ */ e(ee, { type: "submit", className: "w-full", children: i(o === "register" ? d ? "login.createAdmin" : "login.register" : "login.signIn") })
5774
5807
  ] }) }),
5775
5808
  (a == null ? void 0 : a.role) === "public_manager" && /* @__PURE__ */ e(V, { children: /* @__PURE__ */ r("div", { className: "space-y-3", children: [
5776
5809
  /* @__PURE__ */ r("div", { children: [
@@ -5778,7 +5811,7 @@ function hs() {
5778
5811
  /* @__PURE__ */ e("p", { className: "mt-1 text-sm text-fg-muted", children: i("login.browsingBody") })
5779
5812
  ] }),
5780
5813
  /* @__PURE__ */ e(
5781
- X,
5814
+ ee,
5782
5815
  {
5783
5816
  type: "button",
5784
5817
  className: "w-full",
@@ -5799,8 +5832,8 @@ function hs() {
5799
5832
  ] }) });
5800
5833
  }
5801
5834
  function gs() {
5802
- const t = Oe(), n = H(!1), [a, s] = N("");
5803
- return re(() => {
5835
+ const t = Oe(), n = H(!1), [a, s] = S("");
5836
+ return se(() => {
5804
5837
  n.current || (n.current = !0, O.createChatSession().then((l) => {
5805
5838
  t(`/chat/${l.id}?demo=1`, { replace: !0 });
5806
5839
  }).catch((l) => {
@@ -5831,54 +5864,54 @@ function An() {
5831
5864
  return { type: "sales", party: "", amount: "", due_date: "", remarks: "" };
5832
5865
  }
5833
5866
  function ys() {
5834
- const t = Oe(), n = We(), [a, s] = N(""), [l, i] = N((/* @__PURE__ */ new Date()).toISOString().split("T")[0]), [c, o] = N(""), [m, d] = N([Dn()]), [u, p] = N([_n()]), [v, w] = N([An()]), [g, y] = N({}), I = me({
5867
+ const t = Oe(), n = We(), [a, s] = S(""), [l, i] = S((/* @__PURE__ */ new Date()).toISOString().split("T")[0]), [c, o] = S(""), [m, d] = S([Dn()]), [u, p] = S([_n()]), [v, D] = S([An()]), [h, y] = S({}), R = pe({
5835
5868
  mutationFn: () => O.importAccountBalances({
5836
5869
  company: a,
5837
5870
  posting_date: l,
5838
- entries: m.filter((h) => h.account && (h.debit || h.credit)).map((h) => ({
5839
- account: h.account,
5840
- debit: parseFloat(h.debit) || 0,
5841
- credit: parseFloat(h.credit) || 0,
5842
- party_type: h.party_type || void 0,
5843
- party: h.party || void 0
5871
+ entries: m.filter((g) => g.account && (g.debit || g.credit)).map((g) => ({
5872
+ account: g.account,
5873
+ debit: parseFloat(g.debit) || 0,
5874
+ credit: parseFloat(g.credit) || 0,
5875
+ party_type: g.party_type || void 0,
5876
+ party: g.party || void 0
5844
5877
  }))
5845
5878
  }),
5846
- onSuccess: (h) => y((A) => ({ ...A, accounts: h }))
5847
- }), L = me({
5879
+ onSuccess: (g) => y((_) => ({ ..._, accounts: g }))
5880
+ }), B = pe({
5848
5881
  mutationFn: () => O.importStockBalances({
5849
5882
  company: a,
5850
5883
  posting_date: l,
5851
5884
  warehouse: c,
5852
- items: u.filter((h) => h.item_code && h.qty).map((h) => ({
5853
- item_code: h.item_code,
5854
- qty: parseFloat(h.qty) || 0,
5855
- rate: parseFloat(h.rate) || 0
5885
+ items: u.filter((g) => g.item_code && g.qty).map((g) => ({
5886
+ item_code: g.item_code,
5887
+ qty: parseFloat(g.qty) || 0,
5888
+ rate: parseFloat(g.rate) || 0
5856
5889
  }))
5857
5890
  }),
5858
- onSuccess: (h) => y((A) => ({ ...A, stock: h }))
5859
- }), C = me({
5891
+ onSuccess: (g) => y((_) => ({ ..._, stock: g }))
5892
+ }), C = pe({
5860
5893
  mutationFn: () => O.importOutstandingInvoices({
5861
5894
  company: a,
5862
- invoices: v.filter((h) => h.party && h.amount).map((h) => ({
5863
- type: h.type,
5864
- party: h.party,
5865
- amount: parseFloat(h.amount) || 0,
5866
- due_date: h.due_date || void 0,
5867
- remarks: h.remarks || void 0,
5895
+ invoices: v.filter((g) => g.party && g.amount).map((g) => ({
5896
+ type: g.type,
5897
+ party: g.party,
5898
+ amount: parseFloat(g.amount) || 0,
5899
+ due_date: g.due_date || void 0,
5900
+ remarks: g.remarks || void 0,
5868
5901
  posting_date: l
5869
5902
  }))
5870
5903
  }),
5871
- onSuccess: (h) => y((A) => ({ ...A, invoices: h }))
5904
+ onSuccess: (g) => y((_) => ({ ..._, invoices: g }))
5872
5905
  });
5873
- function b(h, A, B, k, q) {
5874
- const x = [...h];
5875
- x[B][k] = q, A(x);
5906
+ function b(g, _, w, N, q) {
5907
+ const x = [...g];
5908
+ x[w][N] = q, _(x);
5876
5909
  }
5877
5910
  return /* @__PURE__ */ r("div", { className: "space-y-6", children: [
5878
5911
  /* @__PURE__ */ e("p", { className: "text-sm text-gray-500", children: "Import balances from your previous system. Each section creates the appropriate documents (Journal Entry, Stock Entry, or Invoices) and submits them automatically." }),
5879
5912
  /* @__PURE__ */ e(V, { title: "Common Settings", children: /* @__PURE__ */ r("div", { className: "flex flex-wrap items-end gap-4", children: [
5880
5913
  /* @__PURE__ */ e(ke, { label: "Company", value: a, onChange: s, linkDoctype: "company", readOnly: !1 }),
5881
- /* @__PURE__ */ e(pe, { label: "As-of Date", type: "date", value: l, onChange: (h) => i(h.target.value) })
5914
+ /* @__PURE__ */ e(X, { label: "As-of Date", type: "date", value: l, onChange: (g) => i(g.target.value) })
5882
5915
  ] }) }),
5883
5916
  /* @__PURE__ */ r(V, { title: "1. Account Balances", children: [
5884
5917
  /* @__PURE__ */ e("p", { className: "mb-3 text-xs text-gray-500", children: "Enter your trial balance from the old system. The difference will be automatically balanced against Opening Balance Equity. For receivable/payable accounts, also set the party type and party." }),
@@ -5890,25 +5923,25 @@ function ys() {
5890
5923
  /* @__PURE__ */ e("th", { className: "px-2 py-2 text-right font-medium text-gray-500", children: "Debit" }),
5891
5924
  /* @__PURE__ */ e("th", { className: "px-2 py-2 text-right font-medium text-gray-500", children: "Credit" })
5892
5925
  ] }) }),
5893
- /* @__PURE__ */ e("tbody", { children: m.map((h, A) => /* @__PURE__ */ r("tr", { children: [
5894
- /* @__PURE__ */ e("td", { className: "px-2 py-1", children: /* @__PURE__ */ e(ke, { value: h.account, onChange: (B) => b(m, d, A, "account", B), linkDoctype: "account", readOnly: !1, label: "" }) }),
5895
- /* @__PURE__ */ e("td", { className: "px-2 py-1", children: /* @__PURE__ */ r("select", { value: h.party_type, onChange: (B) => b(m, d, A, "party_type", B.target.value), className: "w-full rounded border border-gray-300 px-2 py-1.5 text-sm", children: [
5926
+ /* @__PURE__ */ e("tbody", { children: m.map((g, _) => /* @__PURE__ */ r("tr", { children: [
5927
+ /* @__PURE__ */ e("td", { className: "px-2 py-1", children: /* @__PURE__ */ e(ke, { value: g.account, onChange: (w) => b(m, d, _, "account", w), linkDoctype: "account", readOnly: !1, label: "" }) }),
5928
+ /* @__PURE__ */ e("td", { className: "px-2 py-1", children: /* @__PURE__ */ r("select", { value: g.party_type, onChange: (w) => b(m, d, _, "party_type", w.target.value), className: "w-full rounded border border-gray-300 px-2 py-1.5 text-sm", children: [
5896
5929
  /* @__PURE__ */ e("option", { value: "", children: "—" }),
5897
5930
  /* @__PURE__ */ e("option", { value: "Customer", children: "Customer" }),
5898
5931
  /* @__PURE__ */ e("option", { value: "Supplier", children: "Supplier" })
5899
5932
  ] }) }),
5900
- /* @__PURE__ */ e("td", { className: "px-2 py-1", children: h.party_type ? /* @__PURE__ */ e(ke, { label: "", value: h.party, onChange: (B) => b(m, d, A, "party", B), linkDoctype: h.party_type.toLowerCase(), readOnly: !1 }) : /* @__PURE__ */ e("span", { className: "text-gray-300 text-xs", children: "set party type first" }) }),
5901
- /* @__PURE__ */ e("td", { className: "px-2 py-1", children: /* @__PURE__ */ e("input", { type: "number", value: h.debit, onChange: (B) => b(m, d, A, "debit", B.target.value), className: "w-24 rounded border border-gray-300 px-2 py-1.5 text-right text-sm", placeholder: "0.00" }) }),
5902
- /* @__PURE__ */ e("td", { className: "px-2 py-1", children: /* @__PURE__ */ e("input", { type: "number", value: h.credit, onChange: (B) => b(m, d, A, "credit", B.target.value), className: "w-24 rounded border border-gray-300 px-2 py-1.5 text-right text-sm", placeholder: "0.00" }) })
5903
- ] }, A)) })
5933
+ /* @__PURE__ */ e("td", { className: "px-2 py-1", children: g.party_type ? /* @__PURE__ */ e(ke, { label: "", value: g.party, onChange: (w) => b(m, d, _, "party", w), linkDoctype: g.party_type.toLowerCase(), readOnly: !1 }) : /* @__PURE__ */ e("span", { className: "text-gray-300 text-xs", children: "set party type first" }) }),
5934
+ /* @__PURE__ */ e("td", { className: "px-2 py-1", children: /* @__PURE__ */ e("input", { type: "number", value: g.debit, onChange: (w) => b(m, d, _, "debit", w.target.value), className: "w-24 rounded border border-gray-300 px-2 py-1.5 text-right text-sm", placeholder: "0.00" }) }),
5935
+ /* @__PURE__ */ e("td", { className: "px-2 py-1", children: /* @__PURE__ */ e("input", { type: "number", value: g.credit, onChange: (w) => b(m, d, _, "credit", w.target.value), className: "w-24 rounded border border-gray-300 px-2 py-1.5 text-right text-sm", placeholder: "0.00" }) })
5936
+ ] }, _)) })
5904
5937
  ] }) }),
5905
5938
  /* @__PURE__ */ e("div", { className: "mt-2 flex gap-2", children: /* @__PURE__ */ e("button", { onClick: () => d([...m, Dn()]), className: "text-xs text-blue-600 hover:text-blue-800", children: "+ Add Row" }) }),
5906
5939
  /* @__PURE__ */ r("div", { className: "mt-3 flex items-center gap-3", children: [
5907
- /* @__PURE__ */ e(X, { onClick: () => I.mutate(), disabled: !a || I.isPending, children: I.isPending ? "Importing..." : "Import Account Balances" }),
5908
- I.error && /* @__PURE__ */ e("span", { className: "text-xs text-red-600", children: I.error.message }),
5909
- g.accounts && /* @__PURE__ */ r("span", { className: "text-xs text-green-600", children: [
5940
+ /* @__PURE__ */ e(ee, { onClick: () => R.mutate(), disabled: !a || R.isPending, children: R.isPending ? "Importing..." : "Import Account Balances" }),
5941
+ R.error && /* @__PURE__ */ e("span", { className: "text-xs text-red-600", children: R.error.message }),
5942
+ h.accounts && /* @__PURE__ */ r("span", { className: "text-xs text-green-600", children: [
5910
5943
  "Created ",
5911
- g.accounts.journal_entry
5944
+ h.accounts.journal_entry
5912
5945
  ] })
5913
5946
  ] })
5914
5947
  ] }),
@@ -5921,21 +5954,21 @@ function ys() {
5921
5954
  /* @__PURE__ */ e("th", { className: "px-2 py-2 text-right font-medium text-gray-500", children: "Qty" }),
5922
5955
  /* @__PURE__ */ e("th", { className: "px-2 py-2 text-right font-medium text-gray-500", children: "Rate" })
5923
5956
  ] }) }),
5924
- /* @__PURE__ */ e("tbody", { children: u.map((h, A) => /* @__PURE__ */ r("tr", { children: [
5925
- /* @__PURE__ */ e("td", { className: "px-2 py-1", children: /* @__PURE__ */ e(ke, { label: "", value: h.item_code, onChange: (B) => b(u, p, A, "item_code", B), linkDoctype: "item", readOnly: !1 }) }),
5926
- /* @__PURE__ */ e("td", { className: "px-2 py-1", children: /* @__PURE__ */ e("input", { type: "number", value: h.qty, onChange: (B) => b(u, p, A, "qty", B.target.value), className: "w-24 rounded border border-gray-300 px-2 py-1.5 text-right text-sm", placeholder: "0" }) }),
5927
- /* @__PURE__ */ e("td", { className: "px-2 py-1", children: /* @__PURE__ */ e("input", { type: "number", value: h.rate, onChange: (B) => b(u, p, A, "rate", B.target.value), className: "w-24 rounded border border-gray-300 px-2 py-1.5 text-right text-sm", placeholder: "0.00" }) })
5928
- ] }, A)) })
5957
+ /* @__PURE__ */ e("tbody", { children: u.map((g, _) => /* @__PURE__ */ r("tr", { children: [
5958
+ /* @__PURE__ */ e("td", { className: "px-2 py-1", children: /* @__PURE__ */ e(ke, { label: "", value: g.item_code, onChange: (w) => b(u, p, _, "item_code", w), linkDoctype: "item", readOnly: !1 }) }),
5959
+ /* @__PURE__ */ e("td", { className: "px-2 py-1", children: /* @__PURE__ */ e("input", { type: "number", value: g.qty, onChange: (w) => b(u, p, _, "qty", w.target.value), className: "w-24 rounded border border-gray-300 px-2 py-1.5 text-right text-sm", placeholder: "0" }) }),
5960
+ /* @__PURE__ */ e("td", { className: "px-2 py-1", children: /* @__PURE__ */ e("input", { type: "number", value: g.rate, onChange: (w) => b(u, p, _, "rate", w.target.value), className: "w-24 rounded border border-gray-300 px-2 py-1.5 text-right text-sm", placeholder: "0.00" }) })
5961
+ ] }, _)) })
5929
5962
  ] }) }),
5930
5963
  /* @__PURE__ */ e("div", { className: "mt-2", children: /* @__PURE__ */ e("button", { onClick: () => p([...u, _n()]), className: "text-xs text-blue-600 hover:text-blue-800", children: "+ Add Row" }) }),
5931
5964
  /* @__PURE__ */ r("div", { className: "mt-3 flex items-center gap-3", children: [
5932
- /* @__PURE__ */ e(X, { onClick: () => L.mutate(), disabled: !a || !c || L.isPending, children: L.isPending ? "Importing..." : "Import Stock Balances" }),
5933
- L.error && /* @__PURE__ */ e("span", { className: "text-xs text-red-600", children: L.error.message }),
5934
- g.stock && /* @__PURE__ */ r("span", { className: "text-xs text-green-600", children: [
5965
+ /* @__PURE__ */ e(ee, { onClick: () => B.mutate(), disabled: !a || !c || B.isPending, children: B.isPending ? "Importing..." : "Import Stock Balances" }),
5966
+ B.error && /* @__PURE__ */ e("span", { className: "text-xs text-red-600", children: B.error.message }),
5967
+ h.stock && /* @__PURE__ */ r("span", { className: "text-xs text-green-600", children: [
5935
5968
  "Created ",
5936
- g.stock.stock_entry,
5969
+ h.stock.stock_entry,
5937
5970
  " (",
5938
- g.stock.items_count,
5971
+ h.stock.items_count,
5939
5972
  " items)"
5940
5973
  ] })
5941
5974
  ] })
@@ -5950,8 +5983,8 @@ function ys() {
5950
5983
  /* @__PURE__ */ e("th", { className: "px-2 py-2 text-left font-medium text-gray-500", children: "Due Date" }),
5951
5984
  /* @__PURE__ */ e("th", { className: "px-2 py-2 text-left font-medium text-gray-500", children: "Ref / Remarks" })
5952
5985
  ] }) }),
5953
- /* @__PURE__ */ e("tbody", { children: v.map((h, A) => /* @__PURE__ */ r("tr", { children: [
5954
- /* @__PURE__ */ e("td", { className: "px-2 py-1", children: /* @__PURE__ */ r("select", { value: h.type, onChange: (B) => b(v, w, A, "type", B.target.value), className: "rounded border border-gray-300 px-2 py-1.5 text-sm", children: [
5986
+ /* @__PURE__ */ e("tbody", { children: v.map((g, _) => /* @__PURE__ */ r("tr", { children: [
5987
+ /* @__PURE__ */ e("td", { className: "px-2 py-1", children: /* @__PURE__ */ r("select", { value: g.type, onChange: (w) => b(v, D, _, "type", w.target.value), className: "rounded border border-gray-300 px-2 py-1.5 text-sm", children: [
5955
5988
  /* @__PURE__ */ e("option", { value: "sales", children: "Sales (AR)" }),
5956
5989
  /* @__PURE__ */ e("option", { value: "purchase", children: "Purchase (AP)" })
5957
5990
  ] }) }),
@@ -5959,24 +5992,24 @@ function ys() {
5959
5992
  ke,
5960
5993
  {
5961
5994
  label: "",
5962
- value: h.party,
5963
- onChange: (B) => b(v, w, A, "party", B),
5964
- linkDoctype: h.type === "sales" ? "customer" : "supplier",
5995
+ value: g.party,
5996
+ onChange: (w) => b(v, D, _, "party", w),
5997
+ linkDoctype: g.type === "sales" ? "customer" : "supplier",
5965
5998
  readOnly: !1
5966
5999
  }
5967
6000
  ) }),
5968
- /* @__PURE__ */ e("td", { className: "px-2 py-1", children: /* @__PURE__ */ e("input", { type: "number", value: h.amount, onChange: (B) => b(v, w, A, "amount", B.target.value), className: "w-28 rounded border border-gray-300 px-2 py-1.5 text-right text-sm", placeholder: "0.00" }) }),
5969
- /* @__PURE__ */ e("td", { className: "px-2 py-1", children: /* @__PURE__ */ e("input", { type: "date", value: h.due_date, onChange: (B) => b(v, w, A, "due_date", B.target.value), className: "rounded border border-gray-300 px-2 py-1.5 text-sm" }) }),
5970
- /* @__PURE__ */ e("td", { className: "px-2 py-1", children: /* @__PURE__ */ e("input", { type: "text", value: h.remarks, onChange: (B) => b(v, w, A, "remarks", B.target.value), className: "w-full rounded border border-gray-300 px-2 py-1.5 text-sm", placeholder: "Old invoice ref" }) })
5971
- ] }, A)) })
6001
+ /* @__PURE__ */ e("td", { className: "px-2 py-1", children: /* @__PURE__ */ e("input", { type: "number", value: g.amount, onChange: (w) => b(v, D, _, "amount", w.target.value), className: "w-28 rounded border border-gray-300 px-2 py-1.5 text-right text-sm", placeholder: "0.00" }) }),
6002
+ /* @__PURE__ */ e("td", { className: "px-2 py-1", children: /* @__PURE__ */ e("input", { type: "date", value: g.due_date, onChange: (w) => b(v, D, _, "due_date", w.target.value), className: "rounded border border-gray-300 px-2 py-1.5 text-sm" }) }),
6003
+ /* @__PURE__ */ e("td", { className: "px-2 py-1", children: /* @__PURE__ */ e("input", { type: "text", value: g.remarks, onChange: (w) => b(v, D, _, "remarks", w.target.value), className: "w-full rounded border border-gray-300 px-2 py-1.5 text-sm", placeholder: "Old invoice ref" }) })
6004
+ ] }, _)) })
5972
6005
  ] }) }),
5973
- /* @__PURE__ */ e("div", { className: "mt-2", children: /* @__PURE__ */ e("button", { onClick: () => w([...v, An()]), className: "text-xs text-blue-600 hover:text-blue-800", children: "+ Add Row" }) }),
6006
+ /* @__PURE__ */ e("div", { className: "mt-2", children: /* @__PURE__ */ e("button", { onClick: () => D([...v, An()]), className: "text-xs text-blue-600 hover:text-blue-800", children: "+ Add Row" }) }),
5974
6007
  /* @__PURE__ */ r("div", { className: "mt-3 flex items-center gap-3", children: [
5975
- /* @__PURE__ */ e(X, { onClick: () => C.mutate(), disabled: !a || C.isPending, children: C.isPending ? "Importing..." : "Import Outstanding Invoices" }),
6008
+ /* @__PURE__ */ e(ee, { onClick: () => C.mutate(), disabled: !a || C.isPending, children: C.isPending ? "Importing..." : "Import Outstanding Invoices" }),
5976
6009
  C.error && /* @__PURE__ */ e("span", { className: "text-xs text-red-600", children: C.error.message }),
5977
- g.invoices && /* @__PURE__ */ r("span", { className: "text-xs text-green-600", children: [
6010
+ h.invoices && /* @__PURE__ */ r("span", { className: "text-xs text-green-600", children: [
5978
6011
  "Created ",
5979
- g.invoices.invoices_created,
6012
+ h.invoices.invoices_created,
5980
6013
  " invoices"
5981
6014
  ] })
5982
6015
  ] })
@@ -5997,22 +6030,22 @@ function ys() {
5997
6030
  ] });
5998
6031
  }
5999
6032
  function fs() {
6000
- const { user: t } = mt(), n = We(), { data: a, isLoading: s } = ie({
6033
+ const { user: t } = mt(), n = We(), { data: a, isLoading: s } = le({
6001
6034
  queryKey: ["auth-users"],
6002
6035
  queryFn: () => O.authListUsers()
6003
- }), { data: l } = ie({
6036
+ }), { data: l } = le({
6004
6037
  queryKey: ["auth-invites"],
6005
6038
  queryFn: () => O.authListInvites()
6006
- }), [i, c] = N(""), [o, m] = N("viewer"), [d, u] = N(null), p = me({
6039
+ }), [i, c] = S(""), [o, m] = S("viewer"), [d, u] = S(null), p = pe({
6007
6040
  mutationFn: () => O.authInvite(i, o),
6008
- onSuccess: (g) => {
6009
- u(g), c(""), n.invalidateQueries({ queryKey: ["auth-invites"] });
6041
+ onSuccess: (h) => {
6042
+ u(h), c(""), n.invalidateQueries({ queryKey: ["auth-invites"] });
6010
6043
  }
6011
- }), v = me({
6012
- mutationFn: ({ name: g, role: y }) => O.authChangeRole(g, y),
6044
+ }), v = pe({
6045
+ mutationFn: ({ name: h, role: y }) => O.authChangeRole(h, y),
6013
6046
  onSuccess: () => n.invalidateQueries({ queryKey: ["auth-users"] })
6014
- }), w = me({
6015
- mutationFn: (g) => O.authDisableUser(g),
6047
+ }), D = pe({
6048
+ mutationFn: (h) => O.authDisableUser(h),
6016
6049
  onSuccess: () => n.invalidateQueries({ queryKey: ["auth-users"] })
6017
6050
  });
6018
6051
  return (t == null ? void 0 : t.role) !== "admin" ? /* @__PURE__ */ e("p", { className: "py-8 text-center text-gray-400", children: "Admin access required" }) : /* @__PURE__ */ r("div", { className: "space-y-6", children: [
@@ -6033,12 +6066,12 @@ function fs() {
6033
6066
  /* @__PURE__ */ r(V, { title: "Invite User", children: [
6034
6067
  /* @__PURE__ */ r("div", { className: "flex flex-wrap items-end gap-4", children: [
6035
6068
  /* @__PURE__ */ e(
6036
- pe,
6069
+ X,
6037
6070
  {
6038
6071
  label: "Email",
6039
6072
  type: "email",
6040
6073
  value: i,
6041
- onChange: (g) => c(g.target.value),
6074
+ onChange: (h) => c(h.target.value),
6042
6075
  placeholder: "colleague@company.com"
6043
6076
  }
6044
6077
  ),
@@ -6048,11 +6081,11 @@ function fs() {
6048
6081
  label: "Role",
6049
6082
  options: ["viewer", "manager", "admin"],
6050
6083
  value: o,
6051
- onChange: (g) => m(g.target.value)
6084
+ onChange: (h) => m(h.target.value)
6052
6085
  }
6053
6086
  ),
6054
6087
  /* @__PURE__ */ e(
6055
- X,
6088
+ ee,
6056
6089
  {
6057
6090
  onClick: () => p.mutate(),
6058
6091
  disabled: !i.trim() || p.isPending,
@@ -6073,19 +6106,19 @@ function fs() {
6073
6106
  ] })
6074
6107
  ] })
6075
6108
  ] }),
6076
- l && l.filter((g) => !g.used).length > 0 && /* @__PURE__ */ e(V, { title: "Pending Invites", children: /* @__PURE__ */ r("table", { className: "min-w-full divide-y divide-gray-200 text-sm", children: [
6109
+ l && l.filter((h) => !h.used).length > 0 && /* @__PURE__ */ e(V, { title: "Pending Invites", children: /* @__PURE__ */ r("table", { className: "min-w-full divide-y divide-gray-200 text-sm", children: [
6077
6110
  /* @__PURE__ */ e("thead", { className: "bg-gray-50", children: /* @__PURE__ */ r("tr", { children: [
6078
6111
  /* @__PURE__ */ e("th", { className: "px-4 py-2 text-left font-medium text-gray-500", children: "Email" }),
6079
6112
  /* @__PURE__ */ e("th", { className: "px-4 py-2 text-left font-medium text-gray-500", children: "Role" }),
6080
6113
  /* @__PURE__ */ e("th", { className: "px-4 py-2 text-left font-medium text-gray-500", children: "Created" })
6081
6114
  ] }) }),
6082
- /* @__PURE__ */ e("tbody", { className: "divide-y divide-gray-100", children: l.filter((g) => !g.used).map((g) => {
6115
+ /* @__PURE__ */ e("tbody", { className: "divide-y divide-gray-100", children: l.filter((h) => !h.used).map((h) => {
6083
6116
  var y;
6084
6117
  return /* @__PURE__ */ r("tr", { children: [
6085
- /* @__PURE__ */ e("td", { className: "px-4 py-2", children: g.email }),
6086
- /* @__PURE__ */ e("td", { className: "px-4 py-2", children: /* @__PURE__ */ e("span", { className: "rounded bg-gray-100 px-2 py-0.5 text-xs font-medium", children: g.role }) }),
6087
- /* @__PURE__ */ e("td", { className: "px-4 py-2 text-gray-500", children: (y = g.creation) == null ? void 0 : y.split("T")[0] })
6088
- ] }, g.token);
6118
+ /* @__PURE__ */ e("td", { className: "px-4 py-2", children: h.email }),
6119
+ /* @__PURE__ */ e("td", { className: "px-4 py-2", children: /* @__PURE__ */ e("span", { className: "rounded bg-gray-100 px-2 py-0.5 text-xs font-medium", children: h.role }) }),
6120
+ /* @__PURE__ */ e("td", { className: "px-4 py-2 text-gray-500", children: (y = h.creation) == null ? void 0 : y.split("T")[0] })
6121
+ ] }, h.token);
6089
6122
  }) })
6090
6123
  ] }) }),
6091
6124
  /* @__PURE__ */ e(V, { title: "Team Members", children: s ? /* @__PURE__ */ e("p", { className: "text-gray-500", children: "Loading..." }) : /* @__PURE__ */ r("table", { className: "min-w-full divide-y divide-gray-200 text-sm", children: [
@@ -6096,16 +6129,16 @@ function fs() {
6096
6129
  /* @__PURE__ */ e("th", { className: "px-4 py-2 text-left font-medium text-gray-500", children: "Status" }),
6097
6130
  /* @__PURE__ */ e("th", { className: "px-4 py-2 text-right font-medium text-gray-500", children: "Actions" })
6098
6131
  ] }) }),
6099
- /* @__PURE__ */ e("tbody", { className: "divide-y divide-gray-100", children: (a || []).map((g) => /* @__PURE__ */ r("tr", { className: "hover:bg-gray-50", children: [
6100
- /* @__PURE__ */ e("td", { className: "px-4 py-2 font-medium text-gray-900", children: g.full_name }),
6101
- /* @__PURE__ */ e("td", { className: "px-4 py-2 text-gray-600", children: g.email }),
6102
- /* @__PURE__ */ e("td", { className: "px-4 py-2", children: g.role === "public_manager" ? /* @__PURE__ */ e("span", { className: "rounded bg-amber-100 px-2 py-0.5 text-xs font-medium text-amber-800", children: "public_manager (system)" }) : /* @__PURE__ */ r(
6132
+ /* @__PURE__ */ e("tbody", { className: "divide-y divide-gray-100", children: (a || []).map((h) => /* @__PURE__ */ r("tr", { className: "hover:bg-gray-50", children: [
6133
+ /* @__PURE__ */ e("td", { className: "px-4 py-2 font-medium text-gray-900", children: h.full_name }),
6134
+ /* @__PURE__ */ e("td", { className: "px-4 py-2 text-gray-600", children: h.email }),
6135
+ /* @__PURE__ */ e("td", { className: "px-4 py-2", children: h.role === "public_manager" ? /* @__PURE__ */ e("span", { className: "rounded bg-amber-100 px-2 py-0.5 text-xs font-medium text-amber-800", children: "public_manager (system)" }) : /* @__PURE__ */ r(
6103
6136
  "select",
6104
6137
  {
6105
- value: g.role,
6106
- onChange: (y) => v.mutate({ name: g.name, role: y.target.value }),
6107
- disabled: g.name === (t == null ? void 0 : t.name),
6108
- className: `rounded border px-2 py-1 text-xs ${g.name === (t == null ? void 0 : t.name) ? "border-gray-200 bg-gray-50 text-gray-400" : "border-gray-300 bg-white text-gray-900"}`,
6138
+ value: h.role,
6139
+ onChange: (y) => v.mutate({ name: h.name, role: y.target.value }),
6140
+ disabled: h.name === (t == null ? void 0 : t.name),
6141
+ className: `rounded border px-2 py-1 text-xs ${h.name === (t == null ? void 0 : t.name) ? "border-gray-200 bg-gray-50 text-gray-400" : "border-gray-300 bg-white text-gray-900"}`,
6109
6142
  children: [
6110
6143
  /* @__PURE__ */ e("option", { value: "viewer", children: "viewer" }),
6111
6144
  /* @__PURE__ */ e("option", { value: "manager", children: "manager" }),
@@ -6113,16 +6146,16 @@ function fs() {
6113
6146
  ]
6114
6147
  }
6115
6148
  ) }),
6116
- /* @__PURE__ */ e("td", { className: "px-4 py-2", children: /* @__PURE__ */ e("span", { className: `rounded px-2 py-0.5 text-xs font-medium ${g.enabled ? "bg-green-100 text-green-800" : "bg-red-100 text-red-800"}`, children: g.enabled ? "Active" : "Disabled" }) }),
6117
- /* @__PURE__ */ e("td", { className: "px-4 py-2 text-right", children: g.name !== (t == null ? void 0 : t.name) && g.enabled ? /* @__PURE__ */ e(
6149
+ /* @__PURE__ */ e("td", { className: "px-4 py-2", children: /* @__PURE__ */ e("span", { className: `rounded px-2 py-0.5 text-xs font-medium ${h.enabled ? "bg-green-100 text-green-800" : "bg-red-100 text-red-800"}`, children: h.enabled ? "Active" : "Disabled" }) }),
6150
+ /* @__PURE__ */ e("td", { className: "px-4 py-2 text-right", children: h.name !== (t == null ? void 0 : t.name) && h.enabled ? /* @__PURE__ */ e(
6118
6151
  "button",
6119
6152
  {
6120
- onClick: () => w.mutate(g.name),
6153
+ onClick: () => D.mutate(h.name),
6121
6154
  className: "text-xs text-red-500 hover:text-red-700",
6122
6155
  children: "Disable"
6123
6156
  }
6124
6157
  ) : null })
6125
- ] }, g.name)) })
6158
+ ] }, h.name)) })
6126
6159
  ] }) })
6127
6160
  ] });
6128
6161
  }
@@ -6245,13 +6278,13 @@ function Ze(t) {
6245
6278
  return t === 0 ? "$0.00" : t < 0.01 ? `$${t.toFixed(4)}` : `$${t.toFixed(2)}`;
6246
6279
  }
6247
6280
  function Ci() {
6248
- var I, L;
6249
- const { t } = Z(), [n, a] = N("1h"), { data: s, isLoading: l, isFetching: i, error: c, refetch: o, dataUpdatedAt: m } = ie({
6281
+ var R, B;
6282
+ const { t } = Z(), [n, a] = S("1h"), { data: s, isLoading: l, isFetching: i, error: c, refetch: o, dataUpdatedAt: m } = le({
6250
6283
  queryKey: ["demo-spend"],
6251
6284
  queryFn: () => O.getDemoSpend(),
6252
6285
  // Refresh once a minute — demo spend changes slowly; no need to poll harder.
6253
6286
  refetchInterval: 6e4
6254
- }), d = Tn.find((C) => C.value === n), u = (I = s == null ? void 0 : s.windows) == null ? void 0 : I[n], p = ((L = s == null ? void 0 : s.caps) == null ? void 0 : L.global_hourly_usd) ?? 0, v = u ? u.demo_usd / d.hours : 0, w = u ? u.total_usd / d.hours : 0, g = p > 0 ? Math.min(100, v / p * 100) : 0, y = g >= 90 ? "bg-red-500" : g >= 60 ? "bg-amber-500" : "bg-emerald-500";
6287
+ }), d = Tn.find((C) => C.value === n), u = (R = s == null ? void 0 : s.windows) == null ? void 0 : R[n], p = ((B = s == null ? void 0 : s.caps) == null ? void 0 : B.global_hourly_usd) ?? 0, v = u ? u.demo_usd / d.hours : 0, D = u ? u.total_usd / d.hours : 0, h = p > 0 ? Math.min(100, v / p * 100) : 0, y = h >= 90 ? "bg-red-500" : h >= 60 ? "bg-amber-500" : "bg-emerald-500";
6255
6288
  return /* @__PURE__ */ r(V, { title: t("settings.demoSpendTitle"), children: [
6256
6289
  /* @__PURE__ */ r("div", { className: "flex flex-wrap items-end justify-between gap-4", children: [
6257
6290
  /* @__PURE__ */ r("div", { className: "max-w-lg text-sm text-gray-600", children: [
@@ -6334,17 +6367,17 @@ function Ci() {
6334
6367
  Ze(u.total_usd),
6335
6368
  /* @__PURE__ */ r("span", { className: "ml-1 text-xs font-normal text-gray-500", children: [
6336
6369
  "(",
6337
- Ze(w),
6370
+ Ze(D),
6338
6371
  "/hr)"
6339
6372
  ] })
6340
6373
  ] })
6341
6374
  ] })
6342
6375
  ] }),
6343
- /* @__PURE__ */ e("div", { className: "mt-2 h-2 w-full overflow-hidden rounded-full bg-gray-100", children: /* @__PURE__ */ e("div", { className: `h-full ${y} transition-all`, style: { width: `${g}%` } }) }),
6376
+ /* @__PURE__ */ e("div", { className: "mt-2 h-2 w-full overflow-hidden rounded-full bg-gray-100", children: /* @__PURE__ */ e("div", { className: `h-full ${y} transition-all`, style: { width: `${h}%` } }) }),
6344
6377
  /* @__PURE__ */ r("div", { className: "mt-1 text-xs text-gray-400", children: [
6345
- g.toFixed(0),
6378
+ h.toFixed(0),
6346
6379
  "% of the hourly cap",
6347
- g >= 100 && " — demo visitors are currently blocked"
6380
+ h >= 100 && " — demo visitors are currently blocked"
6348
6381
  ] })
6349
6382
  ] }),
6350
6383
  /* @__PURE__ */ r("div", { className: "grid grid-cols-2 gap-3 sm:grid-cols-4", children: [
@@ -6405,21 +6438,21 @@ function ft({ label: t, value: n }) {
6405
6438
  ] });
6406
6439
  }
6407
6440
  function Di() {
6408
- const { user: t } = mt(), { t: n } = Z(), a = We(), s = (t == null ? void 0 : t.role) === "admin", { data: l, isLoading: i } = ie({
6441
+ const { user: t } = mt(), { t: n } = Z(), a = We(), s = (t == null ? void 0 : t.role) === "admin", { data: l, isLoading: i } = le({
6409
6442
  queryKey: ["settings"],
6410
6443
  queryFn: () => O.getSettings()
6411
- }), c = me({
6444
+ }), c = pe({
6412
6445
  mutationFn: (v) => O.updateSettings(v),
6413
6446
  onSuccess: () => a.invalidateQueries({ queryKey: ["settings"] })
6414
- }), { data: o } = ie({
6447
+ }), { data: o } = le({
6415
6448
  queryKey: ["public-manager"],
6416
6449
  queryFn: () => O.getPublicManagerStatus()
6417
- }), [m, d] = N(!1), u = me({
6450
+ }), [m, d] = S(!1), u = pe({
6418
6451
  mutationFn: () => O.createPublicManager(),
6419
6452
  onSuccess: () => {
6420
6453
  a.invalidateQueries({ queryKey: ["public-manager"] }), d(!1);
6421
6454
  }
6422
- }), p = me({
6455
+ }), p = pe({
6423
6456
  mutationFn: () => O.removePublicManager(),
6424
6457
  onSuccess: () => a.invalidateQueries({ queryKey: ["public-manager"] })
6425
6458
  });