@lambda-development/erp-core 0.1.8 → 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
  ] });
@@ -1077,22 +1077,28 @@ function Ua({ group: t }) {
1077
1077
  ]
1078
1078
  }
1079
1079
  ),
1080
- n && /* @__PURE__ */ e("ul", { className: "mb-1", children: t.items.map((o) => /* @__PURE__ */ e("li", { className: "relative", children: /* @__PURE__ */ e(
1081
- kt,
1082
- {
1083
- to: o.path,
1084
- className: ({ isActive: m }) => De(
1085
- "relative block px-4 py-1.5 pl-10 text-sm transition-all duration-300",
1086
- !m && "text-fg-muted hover:bg-surface-subtle hover:text-fg",
1087
- m && "bg-surface-subtle font-medium text-fg",
1088
- (l == null ? void 0 : l.group) === t.label && (l == null ? void 0 : l.item) === o.label && c
1089
- ),
1090
- children: ({ isActive: m }) => /* @__PURE__ */ r(Ne, { children: [
1091
- m && /* @__PURE__ */ e(Yt, {}),
1092
- s(`nav.items.${o.label}`, { defaultValue: o.label })
1093
- ] })
1094
- }
1095
- ) }, o.path)) })
1080
+ n && /* @__PURE__ */ e("ul", { className: "mb-1", children: t.items.map((o) => {
1081
+ const m = t.items.some(
1082
+ (d) => d.path !== o.path && d.path.startsWith(o.path + "/")
1083
+ );
1084
+ return /* @__PURE__ */ e("li", { className: "relative", children: /* @__PURE__ */ e(
1085
+ kt,
1086
+ {
1087
+ to: o.path,
1088
+ end: m,
1089
+ className: ({ isActive: d }) => De(
1090
+ "relative block px-4 py-1.5 pl-10 text-sm transition-all duration-300",
1091
+ !d && "text-fg-muted hover:bg-surface-subtle hover:text-fg",
1092
+ d && "bg-surface-subtle font-medium text-fg",
1093
+ (l == null ? void 0 : l.group) === t.label && (l == null ? void 0 : l.item) === o.label && c
1094
+ ),
1095
+ children: ({ isActive: d }) => /* @__PURE__ */ r(Ne, { children: [
1096
+ d && /* @__PURE__ */ e(Yt, {}),
1097
+ s(`nav.items.${o.label}`, { defaultValue: o.label })
1098
+ ] })
1099
+ }
1100
+ ) }, o.path);
1101
+ }) })
1096
1102
  ] });
1097
1103
  }
1098
1104
  const Ga = {
@@ -1100,11 +1106,11 @@ const Ga = {
1100
1106
  };
1101
1107
  function ja({ isMobileOpen: t = !1, onClose: n }) {
1102
1108
  var o;
1103
- const { data: a } = ie({
1109
+ const { data: a } = le({
1104
1110
  queryKey: ["settings"],
1105
1111
  queryFn: () => O.getSettings(),
1106
1112
  staleTime: 6e4
1107
- }), { data: s } = ie({
1113
+ }), { data: s } = le({
1108
1114
  queryKey: ["setup-status"],
1109
1115
  queryFn: () => O.setupStatus(),
1110
1116
  staleTime: 6e4
@@ -1191,8 +1197,8 @@ function Ka() {
1191
1197
  return /* @__PURE__ */ e(za, { children: /* @__PURE__ */ e(Qa, {}) });
1192
1198
  }
1193
1199
  function Qa() {
1194
- const { pathname: t } = dt(), { user: n, logout: a } = mt(), { navigationFlash: s } = tt(), { t: l } = Z(), i = Wa(t, l), [c, o] = N(!1);
1195
- 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(() => {
1196
1202
  o(!1);
1197
1203
  }, [t]);
1198
1204
  const m = s ? Jt[s.group] : null;
@@ -1309,7 +1315,7 @@ function Zt({ status: t }) {
1309
1315
  }
1310
1316
  function Fe(t) {
1311
1317
  var s;
1312
- const { data: n } = ie({
1318
+ const { data: n } = le({
1313
1319
  queryKey: ["setup-status"],
1314
1320
  queryFn: () => O.setupStatus(),
1315
1321
  staleTime: 3e5
@@ -1379,7 +1385,7 @@ function ot() {
1379
1385
  ] });
1380
1386
  }
1381
1387
  function tr() {
1382
- const { t } = Z(), { data: n, isLoading: a } = ie({
1388
+ const { t } = Z(), { data: n, isLoading: a } = le({
1383
1389
  queryKey: ["dashboard-summary"],
1384
1390
  queryFn: () => O.dashboardSummary()
1385
1391
  });
@@ -1437,7 +1443,7 @@ function tr() {
1437
1443
  ] });
1438
1444
  }
1439
1445
  function nr(t, n) {
1440
- const { data: a, isLoading: s, error: l, refetch: i } = ie({
1446
+ const { data: a, isLoading: s, error: l, refetch: i } = le({
1441
1447
  queryKey: ["documents", t, n],
1442
1448
  queryFn: () => O.listDocuments(t, n),
1443
1449
  enabled: !!t
@@ -2122,7 +2128,7 @@ const ar = {
2122
2128
  md: "h-10 px-4 text-sm",
2123
2129
  lg: "h-11 px-5 text-sm"
2124
2130
  };
2125
- function X({
2131
+ function ee({
2126
2132
  variant: t = "primary",
2127
2133
  size: n = "md",
2128
2134
  disabled: a,
@@ -2153,7 +2159,7 @@ function X({
2153
2159
  }
2154
2160
  );
2155
2161
  }
2156
- 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 }) {
2157
2163
  const c = l || (t ? t.toLowerCase().replace(/\s+/g, "-") : void 0);
2158
2164
  return /* @__PURE__ */ r("div", { children: [
2159
2165
  t && /* @__PURE__ */ e(
@@ -2242,7 +2248,7 @@ function Ke({ label: t, options: n, value: a, onChange: s, className: l, require
2242
2248
  ] });
2243
2249
  }
2244
2250
  function ir({ text: t }) {
2245
- const [n, a] = N(!1);
2251
+ const [n, a] = S(!1);
2246
2252
  return /* @__PURE__ */ r("span", { className: "relative ml-1 inline-flex", children: [
2247
2253
  /* @__PURE__ */ e(
2248
2254
  "button",
@@ -2262,7 +2268,7 @@ function ir({ text: t }) {
2262
2268
  ] });
2263
2269
  }
2264
2270
  function lr(t, n = !0) {
2265
- const { data: a } = ie({
2271
+ const { data: a } = le({
2266
2272
  queryKey: ["currencies", ""],
2267
2273
  queryFn: () => O.currencies(t),
2268
2274
  enabled: n,
@@ -2292,19 +2298,19 @@ function dr({
2292
2298
  disabled: s,
2293
2299
  hideLabel: l
2294
2300
  }) {
2295
- 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({
2296
2302
  queryKey: ["link-search", t.linkDoctype, i],
2297
2303
  queryFn: () => O.searchLink(t.linkDoctype, i),
2298
2304
  enabled: !!t.linkDoctype && o
2299
2305
  });
2300
- return re(() => {
2306
+ return se(() => {
2301
2307
  c(n ?? "");
2302
2308
  }, [n]), s ? /* @__PURE__ */ r("div", { children: [
2303
2309
  !l && /* @__PURE__ */ e("label", { className: "mb-1.5 block text-sm font-medium text-fg", children: t.label }),
2304
2310
  /* @__PURE__ */ e("p", { className: "py-2 text-sm text-fg", children: n || "-" })
2305
2311
  ] }) : /* @__PURE__ */ r("div", { className: "relative", children: [
2306
2312
  /* @__PURE__ */ e(
2307
- pe,
2313
+ X,
2308
2314
  {
2309
2315
  label: l ? void 0 : t.label,
2310
2316
  value: i,
@@ -2337,38 +2343,38 @@ function Vt({
2337
2343
  hideLabel: i,
2338
2344
  currency: c = "USD"
2339
2345
  }) {
2340
- var w;
2346
+ var D;
2341
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);
2342
2348
  if (m) {
2343
2349
  if (t.type === "link" && n) {
2344
- const y = t.linkDoctypeField && l ? String(l[t.linkDoctypeField] ?? "").toLowerCase().replace(/\s+/g, "-") : t.linkDoctype, I = $t(y, String(n));
2345
- 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)
2346
2352
  return /* @__PURE__ */ r("div", { children: [
2347
2353
  /* @__PURE__ */ e(d, {}),
2348
2354
  /* @__PURE__ */ e("p", { className: i ? "text-sm" : "py-2 text-sm", children: /* @__PURE__ */ e(
2349
2355
  ye,
2350
2356
  {
2351
- to: I,
2357
+ to: R,
2352
2358
  className: "text-sky-600 hover:text-sky-800 hover:underline",
2353
2359
  children: n
2354
2360
  }
2355
2361
  ) })
2356
2362
  ] });
2357
2363
  }
2358
- let g = n ?? "-";
2359
- 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: [
2360
2366
  /* @__PURE__ */ e(d, {}),
2361
- /* @__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 })
2362
2368
  ] });
2363
2369
  }
2364
2370
  if (t.type === "link") {
2365
- 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;
2366
2372
  return /* @__PURE__ */ r("div", { children: [
2367
2373
  /* @__PURE__ */ e(d, {}),
2368
2374
  /* @__PURE__ */ e(
2369
2375
  dr,
2370
2376
  {
2371
- field: g,
2377
+ field: h,
2372
2378
  value: n ?? "",
2373
2379
  onChange: a,
2374
2380
  disabled: m,
@@ -2378,13 +2384,13 @@ function Vt({
2378
2384
  ] });
2379
2385
  }
2380
2386
  if (t.type === "select" && (t.options || u)) {
2381
- 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;
2382
2388
  return /* @__PURE__ */ r("div", { children: [
2383
2389
  /* @__PURE__ */ e(d, {}),
2384
2390
  /* @__PURE__ */ e(
2385
2391
  Ke,
2386
2392
  {
2387
- options: g,
2393
+ options: h,
2388
2394
  value: n ?? "",
2389
2395
  onChange: (y) => a(y.target.value)
2390
2396
  }
@@ -2400,7 +2406,7 @@ function Vt({
2400
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",
2401
2407
  rows: 3,
2402
2408
  value: n ?? "",
2403
- onChange: (g) => a(g.target.value)
2409
+ onChange: (h) => a(h.target.value)
2404
2410
  }
2405
2411
  )
2406
2412
  ] });
@@ -2408,13 +2414,13 @@ function Vt({
2408
2414
  return /* @__PURE__ */ r("div", { children: [
2409
2415
  /* @__PURE__ */ e(d, {}),
2410
2416
  /* @__PURE__ */ e(
2411
- pe,
2417
+ X,
2412
2418
  {
2413
2419
  type: v,
2414
2420
  step: t.type === "currency" ? "0.01" : void 0,
2415
2421
  value: n ?? "",
2416
- onChange: (g) => a(
2417
- 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
2418
2424
  )
2419
2425
  }
2420
2426
  )
@@ -2429,7 +2435,7 @@ function ur({
2429
2435
  }) {
2430
2436
  const { t: i } = Z(), c = (d, u, p) => {
2431
2437
  const v = n.map(
2432
- (w, g) => g === d ? { ...w, [u]: p } : w
2438
+ (D, h) => h === d ? { ...D, [u]: p } : D
2433
2439
  );
2434
2440
  a(v);
2435
2441
  }, o = () => {
@@ -2469,7 +2475,7 @@ function ur({
2469
2475
  }
2470
2476
  ) }, p.name)),
2471
2477
  !s && /* @__PURE__ */ e("td", { className: "px-2 py-1", children: /* @__PURE__ */ e(
2472
- X,
2478
+ ee,
2473
2479
  {
2474
2480
  variant: "ghost",
2475
2481
  size: "sm",
@@ -2479,7 +2485,7 @@ function ur({
2479
2485
  ) })
2480
2486
  ] }, u)) })
2481
2487
  ] }) }),
2482
- !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") }) })
2483
2489
  ] });
2484
2490
  }
2485
2491
  function mr({
@@ -2498,12 +2504,12 @@ function mr({
2498
2504
  if (!i) return null;
2499
2505
  const p = !t && n && a ? `/api/documents/${n}/${encodeURIComponent(a)}/pdf` : null;
2500
2506
  return /* @__PURE__ */ r("div", { className: "flex flex-wrap gap-2", children: [
2501
- p && /* @__PURE__ */ e(X, { variant: "secondary", onClick: () => window.open(p, "_blank"), children: u("common.pdf") }),
2502
- s < 1 && /* @__PURE__ */ e(X, { onClick: c, disabled: l, children: u(l ? "common.saving" : "common.save") }),
2503
- !t && i.canSubmit && s === 0 && /* @__PURE__ */ e(X, { variant: "secondary", onClick: o, children: u("common.submit") }),
2504
- !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") }),
2505
2511
  !t && s === 1 && i.conversions.map((v) => /* @__PURE__ */ e(
2506
- X,
2512
+ ee,
2507
2513
  {
2508
2514
  variant: "secondary",
2509
2515
  onClick: () => d(v.targetDoctype),
@@ -2537,96 +2543,96 @@ function pn(t, n) {
2537
2543
  }
2538
2544
  function hn() {
2539
2545
  var ge;
2540
- 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({
2541
2547
  queryKey: ["document", t, n],
2542
2548
  queryFn: () => O.getDocument(t, n),
2543
2549
  enabled: !!t && !!n && !c
2544
- }), w = Ce(
2545
- () => !!(i != null && i.fields.some((_) => _.name === "currency")),
2550
+ }), D = Ce(
2551
+ () => !!(i != null && i.fields.some((T) => T.name === "currency")),
2546
2552
  [i]
2547
- ), g = i == null ? void 0 : i.partyField, y = g ? o[g] : void 0, I = Fe(o.company), { data: L } = ie({
2548
- queryKey: ["master", g, y],
2549
- queryFn: () => O.getMaster(g, y),
2550
- 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,
2551
2557
  staleTime: 300 * 1e3
2552
2558
  });
2553
- re(() => {
2554
- if (!c || !w || d) return;
2555
- let _;
2559
+ se(() => {
2560
+ if (!c || !D || d) return;
2561
+ let T;
2556
2562
  if (y) {
2557
- if (!L) return;
2558
- _ = L.default_currency || I;
2563
+ if (!B) return;
2564
+ T = B.default_currency || R;
2559
2565
  } else
2560
- _ = I;
2561
- _ && _ !== o.currency && m((Q) => ({ ...Q, currency: _ }));
2566
+ T = R;
2567
+ T && T !== o.currency && m((Q) => ({ ...Q, currency: T }));
2562
2568
  }, [
2563
2569
  c,
2564
- w,
2570
+ D,
2565
2571
  d,
2566
2572
  y,
2567
- L,
2568
- I,
2573
+ B,
2574
+ R,
2569
2575
  o.currency
2570
- ]), re(() => {
2576
+ ]), se(() => {
2571
2577
  if (c && i) {
2572
- const _ = {};
2578
+ const T = {};
2573
2579
  i.fields.forEach((Q) => {
2574
- 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 ?? "";
2575
2581
  }), i.childTables.forEach((Q) => {
2576
- _[Q.key] = [];
2577
- }), _.docstatus = 0, m(_);
2582
+ T[Q.key] = [];
2583
+ }), T.docstatus = 0, m(T);
2578
2584
  } else p && m(p);
2579
2585
  }, [c, p, i]);
2580
- const C = me({
2581
- mutationFn: (_) => O.createDocument(t, _),
2582
- onSuccess: (_) => {
2583
- 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 });
2584
2590
  }
2585
- }), b = me({
2586
- mutationFn: (_) => O.updateDocument(t, n, _),
2587
- onSuccess: (_) => {
2588
- 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);
2589
2595
  }
2590
- }), h = me({
2596
+ }), g = pe({
2591
2597
  mutationFn: () => O.submitDocument(t, n),
2592
- onSuccess: (_) => {
2593
- 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] });
2594
2600
  }
2595
- }), A = me({
2601
+ }), _ = pe({
2596
2602
  mutationFn: () => O.cancelDocument(t, n),
2597
- onSuccess: (_) => {
2598
- 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] });
2599
2605
  }
2600
- }), B = me({
2601
- mutationFn: (_) => O.convertDocument(t, n, _),
2602
- onSuccess: (_, Q) => {
2603
- const oe = Q.toLowerCase().replace(/\s+/g, "-");
2604
- 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}`);
2605
2611
  }
2606
- }), k = we(
2607
- (_, Q) => {
2608
- _ === "currency" && u(!0), m((oe) => {
2609
- const ne = { ...oe, [_]: Q };
2610
- 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);
2611
2617
  });
2612
2618
  },
2613
2619
  [i]
2614
2620
  ), q = we(
2615
- (_, Q) => {
2616
- m((oe) => {
2617
- const ne = { ...oe, [_]: Q };
2618
- return pn(ne, i);
2621
+ (T, Q) => {
2622
+ m((ce) => {
2623
+ const ae = { ...ce, [T]: Q };
2624
+ return pn(ae, i);
2619
2625
  });
2620
2626
  },
2621
2627
  [i]
2622
2628
  ), x = () => {
2623
2629
  c ? C.mutate(o) : b.mutate(o);
2624
2630
  }, z = () => {
2625
- h.mutate();
2631
+ g.mutate();
2626
2632
  }, j = () => {
2627
- A.mutate();
2628
- }, U = (_) => {
2629
- B.mutate(_);
2633
+ _.mutate();
2634
+ }, U = (T) => {
2635
+ w.mutate(T);
2630
2636
  };
2631
2637
  if (!i)
2632
2638
  return /* @__PURE__ */ r("p", { className: "text-fg-muted", children: [
@@ -2635,7 +2641,7 @@ function hn() {
2635
2641
  ] });
2636
2642
  if (!c && v)
2637
2643
  return /* @__PURE__ */ e("p", { className: "text-fg-muted", children: l("common.loading") });
2638
- 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);
2639
2645
  return /* @__PURE__ */ r("div", { className: "space-y-6", children: [
2640
2646
  /* @__PURE__ */ r("div", { className: "flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between", children: [
2641
2647
  /* @__PURE__ */ r("div", { className: "flex items-center gap-3", children: [
@@ -2644,9 +2650,9 @@ function hn() {
2644
2650
  "span",
2645
2651
  {
2646
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",
2647
- title: K !== 1 ? `1 ${T} = ${K} base currency` : void 0,
2653
+ title: K !== 1 ? `1 ${P} = ${K} base currency` : void 0,
2648
2654
  children: [
2649
- T,
2655
+ P,
2650
2656
  K !== 1 && /* @__PURE__ */ r("span", { className: "text-fg-muted/70", children: [
2651
2657
  "@ ",
2652
2658
  K
@@ -2671,45 +2677,45 @@ function hn() {
2671
2677
  }
2672
2678
  )
2673
2679
  ] }),
2674
- (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") }),
2675
- /* @__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(
2676
2682
  Vt,
2677
2683
  {
2678
- field: _,
2679
- value: o[_.name],
2680
- onChange: (Q) => k(_.name, Q),
2681
- readOnly: ce,
2684
+ field: T,
2685
+ value: o[T.name],
2686
+ onChange: (Q) => N(T.name, Q),
2687
+ readOnly: de,
2682
2688
  rowData: o,
2683
- currency: T
2689
+ currency: P
2684
2690
  },
2685
- _.name
2691
+ T.name
2686
2692
  )) }) }),
2687
- i.childTables.map((_) => /* @__PURE__ */ e(
2693
+ i.childTables.map((T) => /* @__PURE__ */ e(
2688
2694
  ur,
2689
2695
  {
2690
- tableDef: _,
2691
- rows: o[_.key] ?? [],
2692
- onChange: (Q) => q(_.key, Q),
2693
- readOnly: ce,
2694
- currency: T
2696
+ tableDef: T,
2697
+ rows: o[T.key] ?? [],
2698
+ onChange: (Q) => q(T.key, Q),
2699
+ readOnly: de,
2700
+ currency: P
2695
2701
  },
2696
- _.key
2702
+ T.key
2697
2703
  )),
2698
- 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(
2699
2705
  Vt,
2700
2706
  {
2701
- field: _,
2702
- value: o[_.name],
2707
+ field: T,
2708
+ value: o[T.name],
2703
2709
  onChange: () => {
2704
2710
  },
2705
2711
  readOnly: !0,
2706
- currency: T
2712
+ currency: P
2707
2713
  },
2708
- _.name
2714
+ T.name
2709
2715
  )) }) })
2710
2716
  ] });
2711
2717
  }
2712
- function ue(t) {
2718
+ function me(t) {
2713
2719
  return t.toISOString().split("T")[0];
2714
2720
  }
2715
2721
  function Hn(t) {
@@ -2744,45 +2750,45 @@ const hr = [
2744
2750
  {
2745
2751
  label: "Today",
2746
2752
  range: () => {
2747
- const t = ue(/* @__PURE__ */ new Date());
2753
+ const t = me(/* @__PURE__ */ new Date());
2748
2754
  return [t, t];
2749
2755
  }
2750
2756
  },
2751
2757
  {
2752
2758
  label: "This Week",
2753
- range: () => [ue(Hn(/* @__PURE__ */ new Date())), ue(pr(/* @__PURE__ */ new Date()))]
2759
+ range: () => [me(Hn(/* @__PURE__ */ new Date())), me(pr(/* @__PURE__ */ new Date()))]
2754
2760
  },
2755
2761
  {
2756
2762
  label: "This Month",
2757
- range: () => [ue(gn(/* @__PURE__ */ new Date())), ue(vt(/* @__PURE__ */ new Date()))]
2763
+ range: () => [me(gn(/* @__PURE__ */ new Date())), me(vt(/* @__PURE__ */ new Date()))]
2758
2764
  },
2759
2765
  {
2760
2766
  label: "This Quarter",
2761
- range: () => [ue(Ut(/* @__PURE__ */ new Date())), ue(Gt(/* @__PURE__ */ new Date()))]
2767
+ range: () => [me(Ut(/* @__PURE__ */ new Date())), me(Gt(/* @__PURE__ */ new Date()))]
2762
2768
  },
2763
2769
  {
2764
2770
  label: "This Year",
2765
- range: () => [ue(yn(/* @__PURE__ */ new Date())), ue(Nt(/* @__PURE__ */ new Date()))]
2771
+ range: () => [me(yn(/* @__PURE__ */ new Date())), me(Nt(/* @__PURE__ */ new Date()))]
2766
2772
  },
2767
2773
  {
2768
2774
  label: "Last Month",
2769
2775
  range: () => {
2770
2776
  const t = /* @__PURE__ */ new Date(), n = new Date(t.getFullYear(), t.getMonth() - 1, 1);
2771
- return [ue(gn(n)), ue(vt(n))];
2777
+ return [me(gn(n)), me(vt(n))];
2772
2778
  }
2773
2779
  },
2774
2780
  {
2775
2781
  label: "Last Quarter",
2776
2782
  range: () => {
2777
2783
  const t = /* @__PURE__ */ new Date(), n = new Date(t.getFullYear(), t.getMonth() - 3, 1);
2778
- return [ue(Ut(n)), ue(Gt(n))];
2784
+ return [me(Ut(n)), me(Gt(n))];
2779
2785
  }
2780
2786
  },
2781
2787
  {
2782
2788
  label: "Last Year",
2783
2789
  range: () => {
2784
2790
  const t = new Date((/* @__PURE__ */ new Date()).getFullYear() - 1, 6, 1);
2785
- return [ue(yn(t)), ue(Nt(t))];
2791
+ return [me(yn(t)), me(Nt(t))];
2786
2792
  }
2787
2793
  }
2788
2794
  ];
@@ -2803,15 +2809,15 @@ function Dt({ onSelect: t }) {
2803
2809
  }
2804
2810
  function en({ onSelect: t }) {
2805
2811
  return /* @__PURE__ */ e("div", { className: "flex flex-wrap gap-1.5", children: [
2806
- { label: "Today", value: () => ue(/* @__PURE__ */ new Date()) },
2807
- { 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())) },
2808
2814
  { label: "End of Last Month", value: () => {
2809
2815
  const a = /* @__PURE__ */ new Date();
2810
- return ue(vt(new Date(a.getFullYear(), a.getMonth() - 1, 1)));
2816
+ return me(vt(new Date(a.getFullYear(), a.getMonth() - 1, 1)));
2811
2817
  } },
2812
- { label: "End of This Quarter", value: () => ue(Gt(/* @__PURE__ */ new Date())) },
2813
- { label: "End of This Year", value: () => ue(Nt(/* @__PURE__ */ new Date())) },
2814
- { 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))) }
2815
2821
  ].map((a) => /* @__PURE__ */ e(
2816
2822
  "button",
2817
2823
  {
@@ -2854,10 +2860,10 @@ function br(t) {
2854
2860
  }
2855
2861
  const xr = ["25", "50", "100", "200"];
2856
2862
  function vr() {
2857
- 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(() => {
2858
2864
  const x = {};
2859
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;
2860
- }, [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(() => {
2861
2867
  if (!a) return [];
2862
2868
  const x = zn(), z = (j) => {
2863
2869
  const U = j.split("_").map((Y) => Y.charAt(0).toUpperCase() + Y.slice(1)).join(" ");
@@ -2895,11 +2901,11 @@ function vr() {
2895
2901
  cell: (U) => {
2896
2902
  const Y = U.getValue();
2897
2903
  if (!Y) return "-";
2898
- const ce = br(U.row.original.party_type), T = ce ? $t(ce, String(Y)) : null;
2899
- 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(
2900
2906
  ye,
2901
2907
  {
2902
- to: T,
2908
+ to: P,
2903
2909
  onClick: (K) => K.stopPropagation(),
2904
2910
  className: "text-brand transition-colors hover:text-brand/80 hover:underline",
2905
2911
  children: Y
@@ -2912,18 +2918,18 @@ function vr() {
2912
2918
  return x.accessor(j, {
2913
2919
  header: z(j),
2914
2920
  cell: (Y) => {
2915
- const ce = Y.getValue();
2916
- if (!ce) return "-";
2917
- const T = $t(U, String(ce));
2918
- 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(
2919
2925
  ye,
2920
2926
  {
2921
- to: T,
2927
+ to: P,
2922
2928
  onClick: (K) => K.stopPropagation(),
2923
2929
  className: "text-brand transition-colors hover:text-brand/80 hover:underline",
2924
- children: ce
2930
+ children: de
2925
2931
  }
2926
- ) : String(ce);
2932
+ ) : String(de);
2927
2933
  }
2928
2934
  });
2929
2935
  }
@@ -2936,11 +2942,11 @@ function vr() {
2936
2942
  });
2937
2943
  }, [a, t]), q = Fn({
2938
2944
  data: C,
2939
- columns: k,
2945
+ columns: N,
2940
2946
  getCoreRowModel: Mn()
2941
2947
  });
2942
2948
  return a ? /* @__PURE__ */ r("div", { className: "space-y-4", children: [
2943
- /* @__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") }) }) }),
2944
2950
  /* @__PURE__ */ r("div", { className: "flex flex-wrap items-end gap-4", children: [
2945
2951
  /* @__PURE__ */ e(
2946
2952
  Ke,
@@ -2955,7 +2961,7 @@ function vr() {
2955
2961
  }
2956
2962
  ),
2957
2963
  /* @__PURE__ */ e(
2958
- pe,
2964
+ X,
2959
2965
  {
2960
2966
  label: t("fields.From Date", { defaultValue: "From Date" }),
2961
2967
  type: "date",
@@ -2964,17 +2970,17 @@ function vr() {
2964
2970
  }
2965
2971
  ),
2966
2972
  /* @__PURE__ */ e(
2967
- pe,
2973
+ X,
2968
2974
  {
2969
2975
  label: t("fields.To Date", { defaultValue: "To Date" }),
2970
2976
  type: "date",
2971
2977
  value: i,
2972
- onChange: (x) => w(x.target.value)
2978
+ onChange: (x) => D(x.target.value)
2973
2979
  }
2974
2980
  )
2975
2981
  ] }),
2976
2982
  /* @__PURE__ */ e(Dt, { onSelect: (x, z) => d({ from: x, to: z, page: null }) }),
2977
- 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: [
2978
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: [
2979
2985
  /* @__PURE__ */ e("thead", { className: "bg-surface-subtle", children: q.getHeaderGroups().map((x) => /* @__PURE__ */ e("tr", { children: x.headers.map((z) => /* @__PURE__ */ e(
2980
2986
  "th",
@@ -2997,9 +3003,9 @@ function vr() {
2997
3003
  t("common.showing"),
2998
3004
  " ",
2999
3005
  /* @__PURE__ */ r("span", { className: "font-medium text-fg", children: [
3000
- A,
3006
+ _,
3001
3007
  "–",
3002
- B
3008
+ w
3003
3009
  ] }),
3004
3010
  " ",
3005
3011
  t("common.of"),
@@ -3013,7 +3019,7 @@ function vr() {
3013
3019
  "select",
3014
3020
  {
3015
3021
  value: c,
3016
- onChange: (x) => g(Number(x.target.value)),
3022
+ onChange: (x) => h(Number(x.target.value)),
3017
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",
3018
3024
  children: xr.map((x) => /* @__PURE__ */ e("option", { value: x, children: x }, x))
3019
3025
  }
@@ -3035,13 +3041,13 @@ function vr() {
3035
3041
  " ",
3036
3042
  t("common.of"),
3037
3043
  " ",
3038
- /* @__PURE__ */ e("span", { className: "font-medium text-fg", children: h })
3044
+ /* @__PURE__ */ e("span", { className: "font-medium text-fg", children: g })
3039
3045
  ] }),
3040
3046
  /* @__PURE__ */ e(
3041
3047
  "button",
3042
3048
  {
3043
- onClick: () => u(Math.min(h - 1, m + 1)),
3044
- disabled: m >= h - 1,
3049
+ onClick: () => u(Math.min(g - 1, m + 1)),
3050
+ disabled: m >= g - 1,
3045
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",
3046
3052
  children: t("common.next")
3047
3053
  }
@@ -3057,7 +3063,7 @@ function vr() {
3057
3063
  const Nr = ["25", "50", "100", "200"];
3058
3064
  function Sr() {
3059
3065
  var b;
3060
- 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({
3061
3067
  queryKey: ["masters", t, c, l],
3062
3068
  queryFn: () => O.listMasters(t, {
3063
3069
  include_disabled: 1,
@@ -3065,16 +3071,16 @@ function Sr() {
3065
3071
  offset: c * l
3066
3072
  }),
3067
3073
  enabled: !!t
3068
- }), 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(() => {
3069
3075
  if (!v || v.length === 0) return [];
3070
- const h = zn();
3076
+ const g = zn();
3071
3077
  return Object.keys(v[0]).map(
3072
- (B) => h.accessor(B, {
3073
- header: B.split("_").map((k) => k.charAt(0).toUpperCase() + k.slice(1)).join(" "),
3074
- cell: (k) => {
3075
- const q = k.getValue();
3076
- if (B === "name") {
3077
- 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;
3078
3084
  return /* @__PURE__ */ e(
3079
3085
  ye,
3080
3086
  {
@@ -3084,42 +3090,42 @@ function Sr() {
3084
3090
  }
3085
3091
  );
3086
3092
  }
3087
- return B === "disabled" ? q === 1 ? "Disabled" : "Active" : q ?? "-";
3093
+ return w === "disabled" ? q === 1 ? "Disabled" : "Active" : q ?? "-";
3088
3094
  }
3089
3095
  })
3090
3096
  );
3091
3097
  }, [v, t]), C = Fn({
3092
3098
  data: v,
3093
- columns: L,
3099
+ columns: B,
3094
3100
  getCoreRowModel: Mn()
3095
3101
  });
3096
3102
  return /* @__PURE__ */ r("div", { className: "space-y-4", children: [
3097
3103
  s && /* @__PURE__ */ e("div", { className: "rounded-md bg-amber-50 px-4 py-3 text-sm text-amber-800", children: s }),
3098
- /* @__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" }) }) }),
3099
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: [
3100
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: [
3101
- /* @__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(
3102
3108
  "th",
3103
3109
  {
3104
3110
  className: "px-4 py-3 text-left text-xs font-medium uppercase tracking-wide text-fg-muted",
3105
- children: A.isPlaceholder ? null : bt(
3106
- A.column.columnDef.header,
3107
- A.getContext()
3111
+ children: _.isPlaceholder ? null : bt(
3112
+ _.column.columnDef.header,
3113
+ _.getContext()
3108
3114
  )
3109
3115
  },
3110
- A.id
3111
- )) }, h.id)) }),
3112
- /* @__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(
3113
3119
  "tr",
3114
3120
  {
3115
- 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",
3116
- onClick: () => n(`/masters/${t}/${h.original.name}`),
3117
- children: h.getVisibleCells().map((A) => /* @__PURE__ */ e("td", { className: "px-4 py-2.5", children: bt(
3118
- A.column.columnDef.cell,
3119
- A.getContext()
3120
- ) }, 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))
3121
3127
  },
3122
- h.id
3128
+ g.id
3123
3129
  )) })
3124
3130
  ] }) }),
3125
3131
  /* @__PURE__ */ r("div", { className: "flex flex-wrap items-center justify-between gap-3 text-sm text-fg-muted", children: [
@@ -3128,11 +3134,11 @@ function Sr() {
3128
3134
  /* @__PURE__ */ r("span", { className: "font-medium text-fg", children: [
3129
3135
  y,
3130
3136
  "–",
3131
- I
3137
+ R
3132
3138
  ] }),
3133
3139
  " ",
3134
3140
  "of ",
3135
- /* @__PURE__ */ e("span", { className: "font-medium text-fg", children: w })
3141
+ /* @__PURE__ */ e("span", { className: "font-medium text-fg", children: D })
3136
3142
  ] }),
3137
3143
  /* @__PURE__ */ r("div", { className: "flex items-center gap-2", children: [
3138
3144
  /* @__PURE__ */ r("label", { className: "flex items-center gap-1.5", children: [
@@ -3141,9 +3147,9 @@ function Sr() {
3141
3147
  "select",
3142
3148
  {
3143
3149
  value: l,
3144
- onChange: (h) => d(Number(h.target.value)),
3150
+ onChange: (g) => d(Number(g.target.value)),
3145
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",
3146
- 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))
3147
3153
  }
3148
3154
  )
3149
3155
  ] }),
@@ -3161,13 +3167,13 @@ function Sr() {
3161
3167
  /* @__PURE__ */ e("span", { className: "font-medium text-fg", children: c + 1 }),
3162
3168
  " of",
3163
3169
  " ",
3164
- /* @__PURE__ */ e("span", { className: "font-medium text-fg", children: g })
3170
+ /* @__PURE__ */ e("span", { className: "font-medium text-fg", children: h })
3165
3171
  ] }),
3166
3172
  /* @__PURE__ */ e(
3167
3173
  "button",
3168
3174
  {
3169
- onClick: () => m(Math.min(g - 1, c + 1)),
3170
- disabled: c >= g - 1,
3175
+ onClick: () => m(Math.min(h - 1, c + 1)),
3176
+ disabled: c >= h - 1,
3171
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",
3172
3178
  children: "Next"
3173
3179
  }
@@ -3240,41 +3246,41 @@ const kr = {
3240
3246
  company: "Company"
3241
3247
  }, bn = /* @__PURE__ */ new Set(["customer", "supplier", "item", "warehouse"]);
3242
3248
  function xn() {
3243
- var B;
3244
- 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({
3245
3251
  queryKey: ["master", t, n],
3246
3252
  queryFn: () => O.getMaster(t, n),
3247
3253
  enabled: !!t && !!n && !i
3248
3254
  });
3249
- re(() => {
3255
+ se(() => {
3250
3256
  if (i) {
3251
- const k = {};
3257
+ const N = {};
3252
3258
  m.forEach((q) => {
3253
- k[q.name] = q.default ?? "";
3254
- }), p(k);
3259
+ N[q.name] = q.default ?? "";
3260
+ }), p(N);
3255
3261
  } else v && p(v);
3256
3262
  }, [i, v, m]);
3257
- const g = me({
3258
- mutationFn: (k) => O.createMaster(t, k),
3259
- onSuccess: (k) => {
3260
- 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 });
3261
3267
  }
3262
- }), y = me({
3263
- mutationFn: (k) => O.updateMaster(t, n, k),
3268
+ }), y = pe({
3269
+ mutationFn: (N) => O.updateMaster(t, n, N),
3264
3270
  onSuccess: () => {
3265
3271
  s.invalidateQueries({ queryKey: ["master", t, n] }), s.invalidateQueries({ queryKey: ["masters", t] });
3266
3272
  }
3267
- }), I = me({
3273
+ }), R = pe({
3268
3274
  mutationFn: () => O.deleteMaster(t, n),
3269
- onSuccess: (k) => {
3270
- 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") {
3271
3277
  a(`/masters/${t}`, {
3272
3278
  replace: !0,
3273
3279
  state: {
3274
3280
  notice: l("masterForm.disabledOnDelete", {
3275
3281
  label: o,
3276
3282
  name: n,
3277
- reason: k.reason ?? "other records"
3283
+ reason: N.reason ?? "other records"
3278
3284
  })
3279
3285
  }
3280
3286
  });
@@ -3282,133 +3288,133 @@ function xn() {
3282
3288
  }
3283
3289
  a(`/masters/${t}`, { replace: !0 });
3284
3290
  }
3285
- }), L = () => {
3286
- if (A.length > 0) return;
3287
- const k = t === "company" && !u.name ? { ...u, name: u.company_name } : u;
3288
- 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);
3289
3295
  }, C = () => {
3290
- window.confirm(l("masterForm.deleteConfirm", { label: o })) && I.mutate();
3291
- }, b = (k, q) => {
3292
- 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 }));
3293
3299
  };
3294
- if (!i && w)
3300
+ if (!i && D)
3295
3301
  return /* @__PURE__ */ e("p", { className: "text-fg-muted", children: l("common.loading") });
3296
- const h = g.isPending || y.isPending, A = m.filter((k) => {
3297
- if (!k.required || k.readOnly || i && k.name === "name" && bn.has(t ?? "")) return !1;
3298
- 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];
3299
3305
  return q == null || String(q).trim() === "";
3300
3306
  });
3301
3307
  return /* @__PURE__ */ r("div", { className: "space-y-6", children: [
3302
3308
  /* @__PURE__ */ e("div", { className: "flex items-center justify-end", children: /* @__PURE__ */ r("div", { className: "flex gap-2", children: [
3303
- /* @__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") }),
3304
3310
  !i && /* @__PURE__ */ e(
3305
- X,
3311
+ ee,
3306
3312
  {
3307
3313
  variant: "danger",
3308
3314
  onClick: C,
3309
- disabled: I.isPending,
3315
+ disabled: R.isPending,
3310
3316
  children: l("common.delete")
3311
3317
  }
3312
3318
  )
3313
3319
  ] }) }),
3314
- (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") }),
3315
- 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(", ") }) }),
3316
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 }) }),
3317
- /* @__PURE__ */ e(V, { children: /* @__PURE__ */ e("div", { className: "grid grid-cols-1 gap-4 sm:grid-cols-2", children: m.map((k) => {
3318
- const x = k.name === "name" && !i || k.readOnly, z = k.required && !(i && k.name === "name" && bn.has(t ?? ""));
3319
- 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)
3320
3326
  return /* @__PURE__ */ e("div", { children: /* @__PURE__ */ e(
3321
3327
  Ke,
3322
3328
  {
3323
- label: d(k),
3324
- options: k.options,
3325
- value: u[k.name] ?? "",
3329
+ label: d(N),
3330
+ options: N.options,
3331
+ value: u[N.name] ?? "",
3326
3332
  required: z,
3327
3333
  disabled: x,
3328
- onChange: (U) => b(k.name, U.target.value)
3334
+ onChange: (U) => b(N.name, U.target.value)
3329
3335
  }
3330
- ) }, k.name);
3331
- if (k.type === "textarea")
3336
+ ) }, N.name);
3337
+ if (N.type === "textarea")
3332
3338
  return /* @__PURE__ */ r("div", { className: "sm:col-span-2", children: [
3333
- /* @__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) }),
3334
3340
  /* @__PURE__ */ e(
3335
3341
  "textarea",
3336
3342
  {
3337
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",
3338
3344
  rows: 3,
3339
- value: u[k.name] ?? "",
3345
+ value: u[N.name] ?? "",
3340
3346
  required: z,
3341
3347
  readOnly: x,
3342
3348
  disabled: x,
3343
- onChange: (U) => b(k.name, U.target.value)
3349
+ onChange: (U) => b(N.name, U.target.value)
3344
3350
  }
3345
3351
  )
3346
- ] }, k.name);
3347
- 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";
3348
3354
  return /* @__PURE__ */ e(
3349
- pe,
3355
+ X,
3350
3356
  {
3351
- label: d(k),
3357
+ label: d(N),
3352
3358
  type: j,
3353
- step: k.type === "currency" ? "0.01" : void 0,
3359
+ step: N.type === "currency" ? "0.01" : void 0,
3354
3360
  required: z,
3355
3361
  readOnly: x,
3356
3362
  disabled: x,
3357
- value: u[k.name] ?? "",
3363
+ value: u[N.name] ?? "",
3358
3364
  onChange: (U) => b(
3359
- k.name,
3365
+ N.name,
3360
3366
  j === "number" ? parseFloat(U.target.value) || 0 : U.target.value
3361
3367
  )
3362
3368
  },
3363
- k.name
3369
+ N.name
3364
3370
  );
3365
3371
  }) }) })
3366
3372
  ] });
3367
3373
  }
3368
3374
  function Cr(t) {
3369
- const { data: n, isLoading: a, error: s, refetch: l } = ie({
3375
+ const { data: n, isLoading: a, error: s, refetch: l } = le({
3370
3376
  queryKey: ["report", "trial-balance", t],
3371
3377
  queryFn: () => O.trialBalance(t)
3372
3378
  });
3373
3379
  return { data: n, isLoading: a, error: s, refetch: l };
3374
3380
  }
3375
3381
  function Dr(t) {
3376
- const { data: n, isLoading: a, error: s, refetch: l } = ie({
3382
+ const { data: n, isLoading: a, error: s, refetch: l } = le({
3377
3383
  queryKey: ["report", "general-ledger", t],
3378
3384
  queryFn: () => O.generalLedger(t)
3379
3385
  });
3380
3386
  return { data: n, isLoading: a, error: s, refetch: l };
3381
3387
  }
3382
3388
  function _r(t) {
3383
- const { data: n, isLoading: a, error: s, refetch: l } = ie({
3389
+ const { data: n, isLoading: a, error: s, refetch: l } = le({
3384
3390
  queryKey: ["report", "stock-balance", t],
3385
3391
  queryFn: () => O.stockBalance(t)
3386
3392
  });
3387
3393
  return { data: n, isLoading: a, error: s, refetch: l };
3388
3394
  }
3389
3395
  function Ar(t) {
3390
- const { data: n, isLoading: a, error: s, refetch: l } = ie({
3396
+ const { data: n, isLoading: a, error: s, refetch: l } = le({
3391
3397
  queryKey: ["report", "profit-and-loss", t],
3392
3398
  queryFn: () => O.profitAndLoss(t)
3393
3399
  });
3394
3400
  return { data: n, isLoading: a, error: s, refetch: l };
3395
3401
  }
3396
3402
  function Tr(t) {
3397
- const { data: n, isLoading: a, error: s, refetch: l } = ie({
3403
+ const { data: n, isLoading: a, error: s, refetch: l } = le({
3398
3404
  queryKey: ["report", "balance-sheet", t],
3399
3405
  queryFn: () => O.balanceSheet(t)
3400
3406
  });
3401
3407
  return { data: n, isLoading: a, error: s, refetch: l };
3402
3408
  }
3403
3409
  function Pr(t) {
3404
- const { data: n, isLoading: a, error: s, refetch: l } = ie({
3410
+ const { data: n, isLoading: a, error: s, refetch: l } = le({
3405
3411
  queryKey: ["report", "ar-aging", t],
3406
3412
  queryFn: () => O.arAging(t)
3407
3413
  });
3408
3414
  return { data: n, isLoading: a, error: s, refetch: l };
3409
3415
  }
3410
3416
  function Rr(t) {
3411
- const { data: n, isLoading: a, error: s, refetch: l } = ie({
3417
+ const { data: n, isLoading: a, error: s, refetch: l } = le({
3412
3418
  queryKey: ["report", "ap-aging", t],
3413
3419
  queryFn: () => O.apAging(t)
3414
3420
  });
@@ -3421,14 +3427,14 @@ function ke({
3421
3427
  linkDoctype: s,
3422
3428
  readOnly: l
3423
3429
  }) {
3424
- 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);
3425
- 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(() => {
3426
3432
  c(n ?? "");
3427
3433
  }, [n]);
3428
- const h = we(() => {
3434
+ const g = we(() => {
3429
3435
  if (C.current) {
3430
3436
  const x = C.current.getBoundingClientRect();
3431
- g({
3437
+ h({
3432
3438
  position: "fixed",
3433
3439
  top: x.bottom + 4,
3434
3440
  left: x.left,
@@ -3436,7 +3442,7 @@ function ke({
3436
3442
  zIndex: 9999
3437
3443
  });
3438
3444
  }
3439
- }, []), A = we(
3445
+ }, []), _ = we(
3440
3446
  (x) => {
3441
3447
  y.current && clearTimeout(y.current), y.current = setTimeout(async () => {
3442
3448
  v(!0);
@@ -3451,10 +3457,10 @@ function ke({
3451
3457
  }, 300);
3452
3458
  },
3453
3459
  [s]
3454
- ), B = (x) => {
3460
+ ), w = (x) => {
3455
3461
  const z = x.target.value;
3456
- c(z), A(z);
3457
- }, k = (x) => {
3462
+ c(z), _(z);
3463
+ }, N = (x) => {
3458
3464
  const z = x.name ?? x.id ?? String(x);
3459
3465
  c(z), a(z), u(!1), m([]);
3460
3466
  }, q = () => {
@@ -3466,17 +3472,17 @@ function ke({
3466
3472
  u(!1), i !== n && a(i);
3467
3473
  }, 150);
3468
3474
  };
3469
- return re(() => {
3475
+ return se(() => {
3470
3476
  const x = (z) => {
3471
3477
  var U, Y;
3472
3478
  const j = z.target;
3473
- (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);
3474
3480
  };
3475
3481
  return document.addEventListener("mousedown", x), () => document.removeEventListener("mousedown", x);
3476
3482
  }, []), l ? /* @__PURE__ */ r("div", { children: [
3477
3483
  t && /* @__PURE__ */ e("span", { className: "mb-1.5 block text-sm font-medium text-fg", children: t }),
3478
3484
  /* @__PURE__ */ e("span", { className: "text-sm text-fg", children: n || "—" })
3479
- ] }) : /* @__PURE__ */ r("div", { ref: I, className: "relative", children: [
3485
+ ] }) : /* @__PURE__ */ r("div", { ref: R, className: "relative", children: [
3480
3486
  t && /* @__PURE__ */ e("label", { className: "mb-1.5 block text-sm font-medium text-fg", children: t }),
3481
3487
  /* @__PURE__ */ e(
3482
3488
  "input",
@@ -3484,9 +3490,9 @@ function ke({
3484
3490
  ref: C,
3485
3491
  type: "text",
3486
3492
  value: i,
3487
- onChange: B,
3493
+ onChange: w,
3488
3494
  onFocus: () => {
3489
- h(), A(i);
3495
+ g(), _(i);
3490
3496
  },
3491
3497
  onBlur: q,
3492
3498
  placeholder: `Search ${s}...`,
@@ -3497,7 +3503,7 @@ function ke({
3497
3503
  }
3498
3504
  ),
3499
3505
  d && o.length > 0 && Ca(
3500
- /* @__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) => {
3501
3507
  const j = x.name ?? x.id ?? String(x);
3502
3508
  return /* @__PURE__ */ e(
3503
3509
  "button",
@@ -3506,7 +3512,7 @@ function ke({
3506
3512
  onMouseDown: () => {
3507
3513
  b.current = !0;
3508
3514
  },
3509
- onClick: () => k(x),
3515
+ onClick: () => N(x),
3510
3516
  className: "block w-full px-3 py-1.5 text-left text-sm text-fg transition-colors hover:bg-surface-subtle",
3511
3517
  children: j
3512
3518
  },
@@ -3518,16 +3524,16 @@ function ke({
3518
3524
  ] });
3519
3525
  }
3520
3526
  function Ir() {
3521
- 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(() => {
3522
3528
  const b = {};
3523
3529
  return n && (b.company = n), a && (b.from_date = a), s && (b.to_date = s), b;
3524
- }, [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 = () => {
3525
3531
  l({
3526
3532
  company: i || null,
3527
3533
  from: o || null,
3528
3534
  to: d || null
3529
- }), I();
3530
- }, C = g ? g.difference === 0 : !1;
3535
+ }), R();
3536
+ }, C = h ? h.difference === 0 : !1;
3531
3537
  return /* @__PURE__ */ r("div", { className: "space-y-4", children: [
3532
3538
  /* @__PURE__ */ r("div", { className: "flex flex-wrap items-end gap-4", children: [
3533
3539
  /* @__PURE__ */ e(
@@ -3541,7 +3547,7 @@ function Ir() {
3541
3547
  }
3542
3548
  ),
3543
3549
  /* @__PURE__ */ e(
3544
- pe,
3550
+ X,
3545
3551
  {
3546
3552
  label: t("fields.From Date", { defaultValue: "From Date" }),
3547
3553
  type: "date",
@@ -3550,7 +3556,7 @@ function Ir() {
3550
3556
  }
3551
3557
  ),
3552
3558
  /* @__PURE__ */ e(
3553
- pe,
3559
+ X,
3554
3560
  {
3555
3561
  label: t("fields.To Date", { defaultValue: "To Date" }),
3556
3562
  type: "date",
@@ -3558,12 +3564,12 @@ function Ir() {
3558
3564
  onChange: (b) => u(b.target.value)
3559
3565
  }
3560
3566
  ),
3561
- /* @__PURE__ */ e(X, { onClick: L, children: t("common.apply") })
3567
+ /* @__PURE__ */ e(ee, { onClick: B, children: t("common.apply") })
3562
3568
  ] }),
3563
- /* @__PURE__ */ e(Dt, { onSelect: (b, h) => {
3564
- 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 });
3565
3571
  } }),
3566
- 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: [
3567
3573
  /* @__PURE__ */ e("div", { className: "overflow-x-auto", children: /* @__PURE__ */ r("table", { className: "min-w-full divide-y divide-line text-sm", children: [
3568
3574
  /* @__PURE__ */ e("thead", { className: "bg-surface-subtle", children: /* @__PURE__ */ r("tr", { children: [
3569
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" }) }),
@@ -3571,17 +3577,17 @@ function Ir() {
3571
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" }) }),
3572
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" }) })
3573
3579
  ] }) }),
3574
- /* @__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: [
3575
3581
  /* @__PURE__ */ e("td", { className: "px-4 py-2 text-fg", children: b.account }),
3576
3582
  /* @__PURE__ */ e("td", { className: "px-4 py-2 text-right tabular-nums text-fg", children: v(b.debit) }),
3577
3583
  /* @__PURE__ */ e("td", { className: "px-4 py-2 text-right tabular-nums text-fg", children: v(b.credit) }),
3578
3584
  /* @__PURE__ */ e("td", { className: "px-4 py-2 text-right font-medium tabular-nums text-fg", children: v(b.balance) })
3579
- ] }, h)) }),
3585
+ ] }, g)) }),
3580
3586
  /* @__PURE__ */ e("tfoot", { className: "border-t border-line bg-surface-subtle font-semibold", children: /* @__PURE__ */ r("tr", { children: [
3581
3587
  /* @__PURE__ */ e("td", { className: "px-4 py-3 text-fg", children: t("common.total") }),
3582
- /* @__PURE__ */ e("td", { className: "px-4 py-3 text-right tabular-nums text-fg", children: v(g.total_debit) }),
3583
- /* @__PURE__ */ e("td", { className: "px-4 py-3 text-right tabular-nums text-fg", children: v(g.total_credit) }),
3584
- /* @__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) })
3585
3591
  ] }) })
3586
3592
  ] }) }),
3587
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: [
@@ -3599,15 +3605,15 @@ function Lr(t) {
3599
3605
  }
3600
3606
  const Br = ["25", "50", "100", "200"];
3601
3607
  function Er() {
3602
- 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(() => {
3603
- const T = {};
3604
- 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;
3605
- }, [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 = () => {
3606
3612
  m({
3607
3613
  account: p || null,
3608
- party: w || null,
3614
+ party: D || null,
3609
3615
  from: y || null,
3610
- to: L || null,
3616
+ to: B || null,
3611
3617
  page: null
3612
3618
  }), q();
3613
3619
  };
@@ -3627,36 +3633,36 @@ function Er() {
3627
3633
  ke,
3628
3634
  {
3629
3635
  label: t("fields.Party", { defaultValue: "Party" }),
3630
- value: w,
3631
- onChange: g,
3636
+ value: D,
3637
+ onChange: h,
3632
3638
  linkDoctype: "customer",
3633
3639
  readOnly: !1
3634
3640
  }
3635
3641
  ),
3636
3642
  /* @__PURE__ */ e(
3637
- pe,
3643
+ X,
3638
3644
  {
3639
3645
  label: t("fields.From Date", { defaultValue: "From Date" }),
3640
3646
  type: "date",
3641
3647
  value: y,
3642
- onChange: (T) => I(T.target.value)
3648
+ onChange: (P) => R(P.target.value)
3643
3649
  }
3644
3650
  ),
3645
3651
  /* @__PURE__ */ e(
3646
- pe,
3652
+ X,
3647
3653
  {
3648
3654
  label: t("fields.To Date", { defaultValue: "To Date" }),
3649
3655
  type: "date",
3650
- value: L,
3651
- onChange: (T) => C(T.target.value)
3656
+ value: B,
3657
+ onChange: (P) => C(P.target.value)
3652
3658
  }
3653
3659
  ),
3654
- /* @__PURE__ */ e(X, { onClick: ce, children: t("common.apply") })
3660
+ /* @__PURE__ */ e(ee, { onClick: de, children: t("common.apply") })
3655
3661
  ] }),
3656
- /* @__PURE__ */ e(Dt, { onSelect: (T, K) => {
3657
- 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 });
3658
3664
  } }),
3659
- 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: [
3660
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: [
3661
3667
  /* @__PURE__ */ e("thead", { className: "bg-gray-50", children: /* @__PURE__ */ r("tr", { children: [
3662
3668
  /* @__PURE__ */ e("th", { className: "px-4 py-3 text-left font-medium text-gray-500", children: t("fields.Date", { defaultValue: "Date" }) }),
@@ -3668,22 +3674,22 @@ function Er() {
3668
3674
  /* @__PURE__ */ e("th", { className: "px-4 py-3 text-left font-medium text-gray-500", children: t("fields.Voucher Type", { defaultValue: "Voucher Type" }) }),
3669
3675
  /* @__PURE__ */ e("th", { className: "px-4 py-3 text-left font-medium text-gray-500", children: t("fields.Voucher No", { defaultValue: "Voucher No" }) })
3670
3676
  ] }) }),
3671
- /* @__PURE__ */ e("tbody", { className: "divide-y divide-gray-100", children: x.map((T, K) => /* @__PURE__ */ r("tr", { className: "hover:bg-gray-50", children: [
3672
- /* @__PURE__ */ e("td", { className: "px-4 py-2 text-gray-500", children: Ct(T.posting_date ?? T.date) }),
3673
- /* @__PURE__ */ e("td", { className: "px-4 py-2 text-gray-900", children: T.account }),
3674
- /* @__PURE__ */ e("td", { className: "px-4 py-2 text-gray-700", children: T.party ?? "-" }),
3675
- /* @__PURE__ */ e("td", { className: "px-4 py-2 text-right", children: h(T.debit) }),
3676
- /* @__PURE__ */ e("td", { className: "px-4 py-2 text-right", children: h(T.credit) }),
3677
- /* @__PURE__ */ e("td", { className: "px-4 py-2 text-right font-medium", children: h(T.balance) }),
3678
- /* @__PURE__ */ e("td", { className: "px-4 py-2 text-gray-700", children: T.voucher_type ?? "-" }),
3679
- /* @__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(
3680
3686
  ye,
3681
3687
  {
3682
- to: `/app/${Lr(T.voucher_type)}/${T.voucher_no}`,
3688
+ to: `/app/${Lr(P.voucher_type)}/${P.voucher_no}`,
3683
3689
  className: "font-medium text-blue-600 hover:text-blue-800",
3684
- children: T.voucher_no
3690
+ children: P.voucher_no
3685
3691
  }
3686
- ) : T.voucher_no ?? "-" })
3692
+ ) : P.voucher_no ?? "-" })
3687
3693
  ] }, K)) })
3688
3694
  ] }) }) }),
3689
3695
  /* @__PURE__ */ r("div", { className: "flex flex-wrap items-center justify-between gap-3 text-sm text-gray-600", children: [
@@ -3707,9 +3713,9 @@ function Er() {
3707
3713
  "select",
3708
3714
  {
3709
3715
  value: i,
3710
- onChange: (T) => u(Number(T.target.value)),
3716
+ onChange: (P) => u(Number(P.target.value)),
3711
3717
  className: "rounded border border-gray-300 bg-white px-2 py-1 text-sm",
3712
- 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))
3713
3719
  }
3714
3720
  )
3715
3721
  ] }),
@@ -3746,14 +3752,14 @@ function Er() {
3746
3752
  ] });
3747
3753
  }
3748
3754
  function Or() {
3749
- 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(() => {
3750
3756
  const y = {};
3751
3757
  return n && (y.item_code = n), a && (y.warehouse = a), y;
3752
- }, [n, a]), { data: p, isLoading: v, refetch: w } = _r(u), g = () => {
3758
+ }, [n, a]), { data: p, isLoading: v, refetch: D } = _r(u), h = () => {
3753
3759
  s({
3754
3760
  item_code: l || null,
3755
3761
  warehouse: c || null
3756
- }), w();
3762
+ }), D();
3757
3763
  };
3758
3764
  return /* @__PURE__ */ r("div", { className: "space-y-4", children: [
3759
3765
  /* @__PURE__ */ r("div", { className: "flex flex-wrap items-end gap-4", children: [
@@ -3777,7 +3783,7 @@ function Or() {
3777
3783
  readOnly: !1
3778
3784
  }
3779
3785
  ),
3780
- /* @__PURE__ */ e(X, { onClick: g, children: t("common.apply") })
3786
+ /* @__PURE__ */ e(ee, { onClick: h, children: t("common.apply") })
3781
3787
  ] }),
3782
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: [
3783
3789
  /* @__PURE__ */ e("thead", { className: "bg-gray-50", children: /* @__PURE__ */ r("tr", { children: [
@@ -3788,37 +3794,37 @@ function Or() {
3788
3794
  /* @__PURE__ */ e("th", { className: "px-4 py-3 text-right font-medium text-gray-500", children: t("fields.Valuation Rate", { defaultValue: "Valuation Rate" }) }),
3789
3795
  /* @__PURE__ */ e("th", { className: "px-4 py-3 text-right font-medium text-gray-500", children: t("fields.Stock Value", { defaultValue: "Stock Value" }) })
3790
3796
  ] }) }),
3791
- /* @__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: [
3792
3798
  /* @__PURE__ */ e("td", { className: "px-4 py-2 font-medium text-gray-900", children: y.item_code }),
3793
3799
  /* @__PURE__ */ e("td", { className: "px-4 py-2 text-gray-700", children: y.item_name }),
3794
3800
  /* @__PURE__ */ e("td", { className: "px-4 py-2 text-gray-700", children: y.warehouse }),
3795
3801
  /* @__PURE__ */ e("td", { className: "px-4 py-2 text-right", children: Mt(y.actual_qty) }),
3796
3802
  /* @__PURE__ */ e("td", { className: "px-4 py-2 text-right", children: d(y.valuation_rate) }),
3797
3803
  /* @__PURE__ */ e("td", { className: "px-4 py-2 text-right font-medium", children: d(y.stock_value) })
3798
- ] }, I)) })
3804
+ ] }, R)) })
3799
3805
  ] }) }) })
3800
3806
  ] });
3801
3807
  }
3802
3808
  function qr() {
3803
- 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(() => {
3804
3810
  const b = {};
3805
3811
  return n && (b.company = n), a && (b.from_date = a), s && (b.to_date = s), b;
3806
- }, [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 = () => {
3807
3813
  l({
3808
3814
  company: i || null,
3809
3815
  from: d || null,
3810
3816
  to: p || null
3811
- }), I();
3812
- }, 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);
3813
3819
  return /* @__PURE__ */ r("div", { className: "space-y-4", children: [
3814
3820
  /* @__PURE__ */ r("div", { className: "flex flex-wrap items-end gap-4", children: [
3815
3821
  /* @__PURE__ */ e(ke, { label: t("fields.Company", { defaultValue: "Company" }), value: i, onChange: c, linkDoctype: "company", readOnly: !1 }),
3816
- /* @__PURE__ */ e(pe, { label: t("fields.From Date", { defaultValue: "From Date" }), type: "date", value: d, onChange: (b) => u(b.target.value) }),
3817
- /* @__PURE__ */ e(pe, { label: t("fields.To Date", { defaultValue: "To Date" }), type: "date", value: p, onChange: (b) => v(b.target.value) }),
3818
- /* @__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") })
3819
3825
  ] }),
3820
- /* @__PURE__ */ e(Dt, { onSelect: (b, h) => {
3821
- 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 });
3822
3828
  } }),
3823
3829
  y ? /* @__PURE__ */ e("p", { className: "text-gray-500", children: t("common.loading") }) : C ? /* @__PURE__ */ r("div", { className: "space-y-4", children: [
3824
3830
  /* @__PURE__ */ r(V, { children: [
@@ -3828,13 +3834,13 @@ function qr() {
3828
3834
  /* @__PURE__ */ e("th", { className: "px-4 py-3 text-left font-medium text-gray-500", children: t("fields.Account", { defaultValue: "Account" }) }),
3829
3835
  /* @__PURE__ */ e("th", { className: "px-4 py-3 text-right font-medium text-gray-500", children: t("fields.Amount", { defaultValue: "Amount" }) })
3830
3836
  ] }) }),
3831
- /* @__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: [
3832
3838
  /* @__PURE__ */ e("td", { className: "px-4 py-2 text-gray-900", children: b.account }),
3833
3839
  /* @__PURE__ */ e("td", { className: "px-4 py-2 text-right", children: m(b.amount) })
3834
- ] }, h)) }),
3840
+ ] }, g)) }),
3835
3841
  /* @__PURE__ */ e("tfoot", { className: "border-t-2 border-gray-300 bg-gray-50 font-semibold", children: /* @__PURE__ */ r("tr", { children: [
3836
3842
  /* @__PURE__ */ e("td", { className: "px-4 py-3 text-gray-900", children: t("reports.totalIncome") }),
3837
- /* @__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) })
3838
3844
  ] }) })
3839
3845
  ] })
3840
3846
  ] }),
@@ -3845,20 +3851,20 @@ function qr() {
3845
3851
  /* @__PURE__ */ e("th", { className: "px-4 py-3 text-left font-medium text-gray-500", children: t("fields.Account", { defaultValue: "Account" }) }),
3846
3852
  /* @__PURE__ */ e("th", { className: "px-4 py-3 text-right font-medium text-gray-500", children: t("fields.Amount", { defaultValue: "Amount" }) })
3847
3853
  ] }) }),
3848
- /* @__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: [
3849
3855
  /* @__PURE__ */ e("td", { className: "px-4 py-2 text-gray-900", children: b.account }),
3850
3856
  /* @__PURE__ */ e("td", { className: "px-4 py-2 text-right", children: m(b.amount) })
3851
- ] }, h)) }),
3857
+ ] }, g)) }),
3852
3858
  /* @__PURE__ */ e("tfoot", { className: "border-t-2 border-gray-300 bg-gray-50 font-semibold", children: /* @__PURE__ */ r("tr", { children: [
3853
3859
  /* @__PURE__ */ e("td", { className: "px-4 py-3 text-gray-900", children: t("reports.totalExpenses") }),
3854
- /* @__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) })
3855
3861
  ] }) })
3856
3862
  ] })
3857
3863
  ] }),
3858
- /* @__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: [
3859
- 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"),
3860
3866
  ": ",
3861
- m(Math.abs(g.net_profit))
3867
+ m(Math.abs(h.net_profit))
3862
3868
  ] }) })
3863
3869
  ] }) : /* @__PURE__ */ e("p", { className: "py-8 text-center text-gray-400", children: t("reports.noData") })
3864
3870
  ] });
@@ -3884,21 +3890,21 @@ function Et({ title: t, rows: n, total: a, totalLabel: s, currency: l }) {
3884
3890
  ] });
3885
3891
  }
3886
3892
  function zr() {
3887
- var L, C, b;
3888
- 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(() => {
3889
- const h = {};
3890
- return n && (h.company = n), a && (h.as_of_date = a), h;
3891
- }, [n, a]), { data: p, isLoading: v, refetch: w } = Tr(u), g = () => {
3892
- s({ company: l || null, as_of_date: c || null }), w();
3893
- }, 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;
3894
3900
  return /* @__PURE__ */ r("div", { className: "space-y-4", children: [
3895
3901
  /* @__PURE__ */ r("div", { className: "flex flex-wrap items-end gap-4", children: [
3896
3902
  /* @__PURE__ */ e(ke, { label: t("fields.Company", { defaultValue: "Company" }), value: l, onChange: i, linkDoctype: "company", readOnly: !1 }),
3897
- /* @__PURE__ */ e(pe, { label: t("fields.As of Date", { defaultValue: "As of Date" }), type: "date", value: c, onChange: (h) => o(h.target.value) }),
3898
- /* @__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") })
3899
3905
  ] }),
3900
- /* @__PURE__ */ e(en, { onSelect: (h) => {
3901
- o(h), s({ as_of_date: h });
3906
+ /* @__PURE__ */ e(en, { onSelect: (g) => {
3907
+ o(g), s({ as_of_date: g });
3902
3908
  } }),
3903
3909
  v ? /* @__PURE__ */ e("p", { className: "text-gray-500", children: t("common.loading") }) : y ? /* @__PURE__ */ r("div", { className: "space-y-4", children: [
3904
3910
  /* @__PURE__ */ e(Et, { title: t("reports.assets"), rows: p.assets || [], total: p.total_assets, totalLabel: t("reports.totalAssets"), currency: m }),
@@ -3917,23 +3923,23 @@ function zr() {
3917
3923
  /* @__PURE__ */ e("span", { className: "font-semibold text-gray-900", children: d(p.total_liabilities_and_equity) })
3918
3924
  ] })
3919
3925
  ] }),
3920
- 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") })
3921
3927
  ] }) })
3922
3928
  ] }) : /* @__PURE__ */ e("p", { className: "py-8 text-center text-gray-400", children: t("reports.noData") })
3923
3929
  ] });
3924
3930
  }
3925
3931
  function Fr() {
3926
- 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(() => {
3927
3933
  const y = {};
3928
3934
  return n && (y.company = n), a && (y.as_of_date = a), y;
3929
- }, [n, a]), { data: p, isLoading: v, refetch: w } = Pr(u), g = () => {
3930
- 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();
3931
3937
  };
3932
3938
  return /* @__PURE__ */ r("div", { className: "space-y-4", children: [
3933
3939
  /* @__PURE__ */ r("div", { className: "flex flex-wrap items-end gap-4", children: [
3934
3940
  /* @__PURE__ */ e(ke, { label: t("fields.Company", { defaultValue: "Company" }), value: l, onChange: i, linkDoctype: "company", readOnly: !1 }),
3935
- /* @__PURE__ */ e(pe, { label: t("fields.As of Date", { defaultValue: "As of Date" }), type: "date", value: c, onChange: (y) => o(y.target.value) }),
3936
- /* @__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") })
3937
3943
  ] }),
3938
3944
  /* @__PURE__ */ e(en, { onSelect: (y) => {
3939
3945
  o(y), s({ as_of_date: y });
@@ -3950,7 +3956,7 @@ function Fr() {
3950
3956
  /* @__PURE__ */ e("th", { className: "px-3 py-3 text-right font-medium text-gray-500", children: "61-90" }),
3951
3957
  /* @__PURE__ */ e("th", { className: "px-3 py-3 text-right font-medium text-gray-500", children: "90+" })
3952
3958
  ] }) }),
3953
- /* @__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: [
3954
3960
  /* @__PURE__ */ e("td", { className: "px-3 py-2", children: /* @__PURE__ */ e(
3955
3961
  ye,
3956
3962
  {
@@ -3967,7 +3973,7 @@ function Fr() {
3967
3973
  /* @__PURE__ */ e("td", { className: "px-3 py-2 text-right", children: y.b31_60 ? d(y.b31_60) : "" }),
3968
3974
  /* @__PURE__ */ e("td", { className: "px-3 py-2 text-right", children: y.b61_90 ? d(y.b61_90) : "" }),
3969
3975
  /* @__PURE__ */ e("td", { className: "px-3 py-2 text-right text-red-600", children: y.b90_plus ? d(y.b90_plus) : "" })
3970
- ] }, I)) }),
3976
+ ] }, R)) }),
3971
3977
  /* @__PURE__ */ e("tfoot", { className: "border-t-2 border-gray-300 bg-gray-50 font-semibold", children: /* @__PURE__ */ r("tr", { children: [
3972
3978
  /* @__PURE__ */ e("td", { className: "px-3 py-3", colSpan: 3, children: t("common.total") }),
3973
3979
  /* @__PURE__ */ e("td", { className: "px-3 py-3 text-right", children: d(p.totals.outstanding) }),
@@ -3981,17 +3987,17 @@ function Fr() {
3981
3987
  ] });
3982
3988
  }
3983
3989
  function Mr() {
3984
- 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(() => {
3985
3991
  const y = {};
3986
3992
  return n && (y.company = n), a && (y.as_of_date = a), y;
3987
- }, [n, a]), { data: p, isLoading: v, refetch: w } = Rr(u), g = () => {
3988
- 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();
3989
3995
  };
3990
3996
  return /* @__PURE__ */ r("div", { className: "space-y-4", children: [
3991
3997
  /* @__PURE__ */ r("div", { className: "flex flex-wrap items-end gap-4", children: [
3992
3998
  /* @__PURE__ */ e(ke, { label: t("fields.Company", { defaultValue: "Company" }), value: l, onChange: i, linkDoctype: "company", readOnly: !1 }),
3993
- /* @__PURE__ */ e(pe, { label: t("fields.As of Date", { defaultValue: "As of Date" }), type: "date", value: c, onChange: (y) => o(y.target.value) }),
3994
- /* @__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") })
3995
4001
  ] }),
3996
4002
  /* @__PURE__ */ e(en, { onSelect: (y) => {
3997
4003
  o(y), s({ as_of_date: y });
@@ -4008,7 +4014,7 @@ function Mr() {
4008
4014
  /* @__PURE__ */ e("th", { className: "px-3 py-3 text-right font-medium text-gray-500", children: "61-90" }),
4009
4015
  /* @__PURE__ */ e("th", { className: "px-3 py-3 text-right font-medium text-gray-500", children: "90+" })
4010
4016
  ] }) }),
4011
- /* @__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: [
4012
4018
  /* @__PURE__ */ e("td", { className: "px-3 py-2", children: /* @__PURE__ */ e(
4013
4019
  ye,
4014
4020
  {
@@ -4025,7 +4031,7 @@ function Mr() {
4025
4031
  /* @__PURE__ */ e("td", { className: "px-3 py-2 text-right", children: y.b31_60 ? d(y.b31_60) : "" }),
4026
4032
  /* @__PURE__ */ e("td", { className: "px-3 py-2 text-right", children: y.b61_90 ? d(y.b61_90) : "" }),
4027
4033
  /* @__PURE__ */ e("td", { className: "px-3 py-2 text-right text-red-600", children: y.b90_plus ? d(y.b90_plus) : "" })
4028
- ] }, I)) }),
4034
+ ] }, R)) }),
4029
4035
  /* @__PURE__ */ e("tfoot", { className: "border-t-2 border-gray-300 bg-gray-50 font-semibold", children: /* @__PURE__ */ r("tr", { children: [
4030
4036
  /* @__PURE__ */ e("td", { className: "px-3 py-3", colSpan: 3, children: t("common.total") }),
4031
4037
  /* @__PURE__ */ e("td", { className: "px-3 py-3 text-right", children: d(p.totals.outstanding) }),
@@ -4133,7 +4139,7 @@ return {
4133
4139
  }
4134
4140
  const Yn = Vr();
4135
4141
  function Ur() {
4136
- 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({
4137
4143
  metric: l,
4138
4144
  groupBy: i,
4139
4145
  fromDate: c || void 0,
@@ -4141,66 +4147,66 @@ function Ur() {
4141
4147
  company: m || void 0
4142
4148
  }), null, 2), [l, i, c, o, m]), U = async (K) => {
4143
4149
  var ge;
4144
- const se = ++z.current, le = () => z.current === se;
4145
- I(""), C(!0);
4150
+ const ie = ++z.current, oe = () => z.current === ie;
4151
+ R(""), C(!0);
4146
4152
  try {
4147
- const Q = JSON.parse(K ?? d), oe = await O.runtimeData({ requests: Q.data_requests || [] });
4148
- if (!le()) return;
4149
- v(oe.datasets), (ge = k.current) == null || ge.terminate();
4150
- const ne = new $r();
4151
- 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;
4152
4158
  const Be = await new Promise((Pe, _e) => {
4153
4159
  const $e = window.setTimeout(() => {
4154
- ne.terminate(), _e(new Error("Report runtime exceeded 4 seconds"));
4160
+ ae.terminate(), _e(new Error("Report runtime exceeded 4 seconds"));
4155
4161
  }, 4e3);
4156
- ne.onmessage = (Re) => {
4162
+ ae.onmessage = (Re) => {
4157
4163
  var he, xe;
4158
- 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"));
4159
- }, ne.postMessage({
4160
- 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,
4161
4167
  params: {},
4162
4168
  transformJs: Q.transform_js || "return {};"
4163
4169
  });
4164
4170
  });
4165
- if (!le()) return;
4166
- g(Be);
4167
- } catch (_) {
4168
- if (!le()) return;
4169
- 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));
4170
4176
  } finally {
4171
- le() && C(!1);
4177
+ oe() && C(!1);
4172
4178
  }
4173
4179
  };
4174
- re(() => {
4180
+ se(() => {
4175
4181
  let K = !1;
4176
- 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) => {
4177
4183
  if (K) return;
4178
- const le = JSON.stringify(se.definition, null, 2);
4179
- return q.current = s, x.current = le, B(se.source_chat_session_id || ""), u(le), U(le);
4180
- }).catch((se) => {
4181
- 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)));
4182
4188
  }).finally(() => {
4183
- K || h(!1);
4189
+ K || g(!1);
4184
4190
  }), () => {
4185
4191
  K = !0;
4186
- }) : (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)), () => {
4187
4193
  K = !0;
4188
4194
  });
4189
4195
  }, [s, j]);
4190
- const Y = !!(!s && j), ce = Ce(() => Wr(w), [w]), T = async () => {
4191
- var oe;
4192
- const K = d.trim() !== x.current.trim(), se = s || "unsaved-runtime-report", le = p.map((ne) => ({
4193
- name: ne.name,
4194
- dataset: ne.dataset,
4195
- row_count: ne.row_count,
4196
- 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)
4197
4203
  })), ge = [
4198
4204
  "This custom analytics report does not work yet. Please repair the existing report draft instead of creating a new one.",
4199
4205
  "",
4200
- `Report ID: ${se}`,
4206
+ `Report ID: ${ie}`,
4201
4207
  "",
4202
4208
  "Current issue summary:",
4203
- y || ce.join(`
4209
+ y || de.join(`
4204
4210
  `) || "No runtime error captured; please review and improve the report definition."
4205
4211
  ];
4206
4212
  K ? ge.push(
@@ -4212,17 +4218,17 @@ function Ur() {
4212
4218
  ) : ge.push(
4213
4219
  "",
4214
4220
  "Load the current saved draft with `get_custom_analytics_report` before making changes."
4215
- ), le.length > 0 && ge.push(
4221
+ ), oe.length > 0 && ge.push(
4216
4222
  "",
4217
4223
  "Fetched dataset preview:",
4218
4224
  "```json",
4219
- JSON.stringify(le, null, 2),
4225
+ JSON.stringify(oe, null, 2),
4220
4226
  "```"
4221
4227
  );
4222
- const _ = ge.join(`
4228
+ const T = ge.join(`
4223
4229
  `);
4224
- let Q = A;
4225
- 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 } });
4226
4232
  };
4227
4233
  return /* @__PURE__ */ r("div", { className: "space-y-4", children: [
4228
4234
  /* @__PURE__ */ e(V, { children: /* @__PURE__ */ r("div", { className: "flex flex-wrap items-center justify-between gap-3", children: [
@@ -4235,11 +4241,11 @@ function Ur() {
4235
4241
  "Loaded draft: ",
4236
4242
  s
4237
4243
  ] }) : Y ? /* @__PURE__ */ e("div", { className: "text-xs text-gray-500", children: "Loaded runtime report from legacy URL filters." }) : null,
4238
- s ? /* @__PURE__ */ e(X, { variant: "secondary", onClick: () => void T(), children: "Fix In Chat" }) : null,
4239
- /* @__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" })
4240
4246
  ] })
4241
4247
  ] }) }),
4242
- 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." }) }),
4243
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: [
4244
4250
  /* @__PURE__ */ r("div", { className: "flex items-baseline justify-between gap-4", children: [
4245
4251
  /* @__PURE__ */ r("div", { children: [
@@ -4310,7 +4316,7 @@ function Gr({ output: t }) {
4310
4316
  /* @__PURE__ */ e(Aa, { type: "monotone", dataKey: i.y, stroke: "#3b82f6", strokeWidth: 2, dot: { r: 3 } })
4311
4317
  ] }) : i.type === "pie" ? /* @__PURE__ */ r(Ta, { children: [
4312
4318
  /* @__PURE__ */ e(It, { formatter: (v) => ct(v, Ot(o, i.y)) }),
4313
- /* @__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)) })
4314
4320
  ] }) : /* @__PURE__ */ r(Ia, { data: m, margin: { top: 10, right: 20, left: 0, bottom: 0 }, children: [
4315
4321
  /* @__PURE__ */ e(an, { strokeDasharray: "3 3", stroke: "#f3f4f6" }),
4316
4322
  /* @__PURE__ */ e(
@@ -4562,57 +4568,65 @@ function Yr(t) {
4562
4568
  }
4563
4569
  const Zr = ["USD", "EUR", "GBP", "CHF", "JPY", "CAD", "AUD", "CNY", "INR"];
4564
4570
  function Xr() {
4565
- const t = We(), { data: n, isLoading: a } = ie({
4571
+ const t = We(), { data: n, isLoading: a } = le({
4566
4572
  queryKey: ["setup-status"],
4567
4573
  queryFn: () => O.setupStatus()
4568
- }), [s, l] = N(""), [i, c] = N("USD"), [o, m] = N("quick"), [d, u] = N(!1), [p, v] = N(null), w = me({
4569
- mutationFn: () => O.createCompany({ name: s, currency: i })
4570
- }), 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({
4571
4585
  mutationFn: () => O.seedDemo()
4572
- }), y = me({
4586
+ }), C = pe({
4573
4587
  mutationFn: () => O.seedHistory()
4574
- }), I = async () => {
4588
+ }), b = async () => {
4575
4589
  if (s.trim())
4576
4590
  try {
4577
- if (await w.mutateAsync(), o === "history") {
4578
- const b = await y.mutateAsync();
4579
- v(b.stats);
4580
- } else o === "quick" && await g.mutateAsync();
4581
- 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);
4582
4596
  } catch {
4583
4597
  }
4584
4598
  };
4585
4599
  if (a)
4586
4600
  return /* @__PURE__ */ e("p", { className: "text-gray-500", children: "Loading..." });
4587
- if (n != null && n.setup_complete && !d)
4601
+ if (n != null && n.setup_complete && !v)
4588
4602
  return /* @__PURE__ */ r("div", { className: "space-y-6", children: [
4589
- /* @__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" }) }),
4590
4604
  /* @__PURE__ */ e(ye, { to: "/", className: "text-blue-600 hover:text-blue-800 text-sm font-medium", children: "Go to Dashboard" })
4591
4605
  ] });
4592
- if (d)
4606
+ if (v)
4593
4607
  return /* @__PURE__ */ e("div", { className: "space-y-6", children: /* @__PURE__ */ e(V, { children: /* @__PURE__ */ r("div", { className: "py-8 text-center", children: [
4594
4608
  /* @__PURE__ */ e("p", { className: "text-lg font-semibold text-green-700", children: "Setup complete!" }),
4595
- /* @__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." }),
4596
- 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: [
4597
4611
  /* @__PURE__ */ e("p", { className: "mb-2 text-sm font-medium text-gray-700", children: "Generated documents:" }),
4598
- /* @__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: [
4599
- /* @__PURE__ */ e("span", { className: "text-gray-600", children: b.replace(/_/g, " ") }),
4600
- /* @__PURE__ */ e("span", { className: "font-mono text-gray-900", children: h.toLocaleString() })
4601
- ] }, 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)) })
4602
4616
  ] }),
4603
- /* @__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" }) }) })
4604
4618
  ] }) }) });
4605
- 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;
4606
4620
  return /* @__PURE__ */ r("div", { className: "mx-auto max-w-lg space-y-6", children: [
4607
4621
  /* @__PURE__ */ e("p", { className: "text-sm text-gray-500", children: "Set up your first company to get started." }),
4608
- 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" }),
4609
4623
  /* @__PURE__ */ e(V, { children: /* @__PURE__ */ r("div", { className: "space-y-4", children: [
4610
4624
  /* @__PURE__ */ e(
4611
- pe,
4625
+ X,
4612
4626
  {
4613
4627
  label: "Company Name",
4614
4628
  value: s,
4615
- onChange: (b) => l(b.target.value),
4629
+ onChange: (w) => l(w.target.value),
4616
4630
  placeholder: "e.g. My Company Ltd",
4617
4631
  required: !0
4618
4632
  }
@@ -4623,9 +4637,34 @@ function Xr() {
4623
4637
  label: "Currency",
4624
4638
  options: Zr,
4625
4639
  value: i,
4626
- onChange: (b) => c(b.target.value)
4640
+ onChange: (w) => c(w.target.value)
4627
4641
  }
4628
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
+ ] }),
4629
4668
  /* @__PURE__ */ r("fieldset", { className: "space-y-2", children: [
4630
4669
  /* @__PURE__ */ e("legend", { className: "mb-1 text-sm font-medium text-gray-700", children: "Seed data" }),
4631
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: [
@@ -4635,8 +4674,8 @@ function Xr() {
4635
4674
  type: "radio",
4636
4675
  name: "seed-mode",
4637
4676
  value: "quick",
4638
- checked: o === "quick",
4639
- onChange: () => m("quick"),
4677
+ checked: u === "quick",
4678
+ onChange: () => p("quick"),
4640
4679
  className: "mt-1"
4641
4680
  }
4642
4681
  ),
@@ -4652,8 +4691,8 @@ function Xr() {
4652
4691
  type: "radio",
4653
4692
  name: "seed-mode",
4654
4693
  value: "history",
4655
- checked: o === "history",
4656
- onChange: () => m("history"),
4694
+ checked: u === "history",
4695
+ onChange: () => p("history"),
4657
4696
  className: "mt-1"
4658
4697
  }
4659
4698
  ),
@@ -4669,8 +4708,8 @@ function Xr() {
4669
4708
  type: "radio",
4670
4709
  name: "seed-mode",
4671
4710
  value: "none",
4672
- checked: o === "none",
4673
- onChange: () => m("none"),
4711
+ checked: u === "none",
4712
+ onChange: () => p("none"),
4674
4713
  className: "mt-1"
4675
4714
  }
4676
4715
  ),
@@ -4681,11 +4720,11 @@ function Xr() {
4681
4720
  ] })
4682
4721
  ] }),
4683
4722
  /* @__PURE__ */ e("div", { className: "pt-2", children: /* @__PURE__ */ e(
4684
- X,
4723
+ ee,
4685
4724
  {
4686
- onClick: I,
4687
- disabled: L || !s.trim(),
4688
- 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"
4689
4728
  }
4690
4729
  ) })
4691
4730
  ] }) })
@@ -5165,152 +5204,152 @@ function wn(t) {
5165
5204
  });
5166
5205
  }
5167
5206
  function Cn() {
5168
- 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), {
5169
- 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,
5170
5209
  connectionVersion: C,
5171
5210
  createSession: b,
5172
- startDemo: h,
5173
- completeDemoTyping: A,
5174
- loadHistory: B,
5175
- loadMoreHistory: k,
5211
+ startDemo: g,
5212
+ completeDemoTyping: _,
5213
+ loadHistory: w,
5214
+ loadMoreHistory: N,
5176
5215
  sendMessage: q,
5177
5216
  getMessages: x,
5178
5217
  hasMoreHistory: z,
5179
5218
  isLoadingOlder: j,
5180
5219
  isThinking: U,
5181
5220
  getDemoStatus: Y,
5182
- getDemoTypingCue: ce
5183
- } = 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(() => {
5184
5223
  _e.current = !0, $e.current !== null && window.clearTimeout($e.current), $e.current = window.setTimeout(() => {
5185
5224
  _e.current = !1, $e.current = null;
5186
5225
  }, 600);
5187
5226
  }, []), pt = we((f = "smooth") => {
5188
- const D = T.current;
5189
- if (!D) return;
5190
- He(), D.scrollTo({ top: D.scrollHeight, behavior: f });
5191
- const ee = () => {
5192
- const ae = T.current;
5193
- 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" })));
5194
5233
  };
5195
- requestAnimationFrame(ee), window.setTimeout(ee, 120);
5234
+ requestAnimationFrame(te), window.setTimeout(te, 120);
5196
5235
  }, [Ae, xe, He]);
5197
5236
  tn(() => {
5198
- const f = T.current, D = Pe.current;
5199
- if (!f || D === null) return;
5200
- const ee = f.scrollHeight - D;
5201
- ee > 0 && (f.scrollTop = f.scrollTop + ee), Pe.current = null;
5202
- }, [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(() => {
5203
5242
  Pe.current === null && (!Be.current && !Ae && !xe || pt(Ae ? "auto" : "smooth"));
5204
- }, [_t, Ae, xe, pt]), re(() => {
5205
- const f = T.current;
5243
+ }, [_t, Ae, xe, pt]), se(() => {
5244
+ const f = P.current;
5206
5245
  if (!f || typeof ResizeObserver > "u") return;
5207
- let D = 0;
5208
- const ee = new ResizeObserver(() => {
5209
- Pe.current === null && (!Be.current && !Ae && !xe || (cancelAnimationFrame(D), D = requestAnimationFrame(() => {
5210
- const te = T.current;
5211
- if (!te) return;
5212
- 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" }));
5213
5252
  })));
5214
- }), ae = f.firstElementChild;
5215
- return ae && ee.observe(ae), ee.observe(f), () => {
5216
- ee.disconnect(), cancelAnimationFrame(D);
5253
+ }), re = f.firstElementChild;
5254
+ return re && te.observe(re), te.observe(f), () => {
5255
+ te.disconnect(), cancelAnimationFrame(A);
5217
5256
  };
5218
5257
  }, [Ae, xe, He]), tn(() => {
5219
- const f = le.current;
5220
- if (!f || (_(f.offsetHeight), typeof ResizeObserver > "u")) return;
5221
- const D = new ResizeObserver(() => _(f.offsetHeight));
5222
- 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();
5223
5262
  }, []);
5224
5263
  const At = we(() => {
5225
5264
  if (!n || Qe || !nt) return;
5226
- const f = T.current;
5227
- 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(() => {
5228
5267
  Pe.current = null;
5229
5268
  });
5230
- }, [n, Qe, nt, k]), S = H(null);
5231
- re(() => {
5232
- 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);
5233
5272
  const f = s.state;
5234
- f != null && f.prefillMessage && S.current !== f ? (S.current = f, o(f.prefillMessage), window.setTimeout(() => {
5235
- var D;
5236
- return (D = se.current) == null ? void 0 : D.focus();
5237
- }, 50)) : f != null && f.prefillMessage || (S.current = null, o(""));
5238
- }, [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(() => {
5239
5278
  if (n || !he) return;
5240
5279
  let f = !1;
5241
- return b().then((D) => {
5242
- f || a(`/chat/${D.id}`, { replace: !0 });
5280
+ return b().then((A) => {
5281
+ f || a(`/chat/${A.id}`, { replace: !0 });
5243
5282
  }).catch(() => {
5244
5283
  }), () => {
5245
5284
  f = !0;
5246
5285
  };
5247
5286
  }, [n, he, a]);
5248
- const G = H(B);
5249
- re(() => {
5250
- G.current = B;
5251
- }, [B]), re(() => {
5287
+ const G = H(w);
5288
+ se(() => {
5289
+ G.current = w;
5290
+ }, [w]), se(() => {
5252
5291
  !n || !he || i || qe === "running" || G.current(n).catch(() => {
5253
5292
  });
5254
- }, [n, he, C, i, qe]), re(() => {
5293
+ }, [n, he, C, i, qe]), se(() => {
5255
5294
  Q.current && !xe && he && setTimeout(() => {
5256
5295
  var f;
5257
- return (f = se.current) == null ? void 0 : f.focus();
5296
+ return (f = ie.current) == null ? void 0 : f.focus();
5258
5297
  }, 50), Q.current = xe;
5259
5298
  }, [xe, he]);
5260
5299
  function W(f) {
5261
5300
  if (_e.current) return;
5262
- const D = f.currentTarget, ee = D.scrollHeight - D.scrollTop - D.clientHeight;
5263
- Be.current = ee < 80;
5301
+ const A = f.currentTarget, te = A.scrollHeight - A.scrollTop - A.clientHeight;
5302
+ Be.current = te < 80;
5264
5303
  }
5265
- re(() => {
5266
- !n || !he || !i || oe.current !== n && (oe.current = n, d(""), h(n).catch((f) => {
5267
- 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"));
5268
5307
  }));
5269
- }, [n, he, i, h]), re(() => {
5308
+ }, [n, he, i, g]), se(() => {
5270
5309
  !n || !i || qe !== "complete" || (o(""), a(`/chat/${n}`, { replace: !0 }));
5271
5310
  }, [n, i, qe, a]);
5272
- const Se = H(A);
5273
- re(() => {
5274
- Se.current = A;
5275
- }, [A]);
5311
+ const Se = H(_);
5312
+ se(() => {
5313
+ Se.current = _;
5314
+ }, [_]);
5276
5315
  const fe = H(null);
5277
- re(() => {
5316
+ se(() => {
5278
5317
  if (!ze || !n || fe.current === ze.seq) return;
5279
5318
  fe.current = ze.seq;
5280
- 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;
5281
5320
  async function rt() {
5282
5321
  o("");
5283
- for (const Tt of D) {
5284
- if (te !== ne.current) return;
5285
- 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);
5286
5325
  }
5287
- te === ne.current && Se.current(f, ae);
5326
+ ne === ae.current && Se.current(f, re);
5288
5327
  }
5289
5328
  rt();
5290
- }, [ze, n]), re(() => {
5291
- qe === "complete" && (ne.current += 1, o(""));
5329
+ }, [ze, n]), se(() => {
5330
+ qe === "complete" && (ae.current += 1, o(""));
5292
5331
  }, [qe]);
5293
5332
  const ve = we((f) => {
5294
5333
  if (!n) return;
5295
- w("");
5296
- const D = Array.from(f);
5297
- p((ee) => {
5298
- const ae = [...ee];
5299
- for (const te of D) {
5300
- if (ae.length >= zt) {
5301
- 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.`);
5302
5341
  break;
5303
5342
  }
5304
- if (!ls.has(te.type)) {
5305
- w(`Unsupported file type: ${te.type || te.name}`);
5343
+ if (!ls.has(ne.type)) {
5344
+ D(`Unsupported file type: ${ne.type || ne.name}`);
5306
5345
  continue;
5307
5346
  }
5308
- if (te.size > is) {
5309
- w(`"${te.name}" is too large (max 10 MB).`);
5347
+ if (ne.size > is) {
5348
+ D(`"${ne.name}" is too large (max 10 MB).`);
5310
5349
  continue;
5311
5350
  }
5312
- 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 };
5313
- 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) => {
5314
5353
  p(
5315
5354
  (ht) => ht.map(
5316
5355
  (lt) => lt.localId === rt ? { ...lt, uploading: !1, uploadedId: it.id } : lt
@@ -5318,42 +5357,42 @@ function Cn() {
5318
5357
  );
5319
5358
  }).catch((it) => {
5320
5359
  const ht = (it == null ? void 0 : it.message) || "Upload failed";
5321
- w(`"${te.name}": ${ht}`), p(
5360
+ D(`"${ne.name}": ${ht}`), p(
5322
5361
  (lt) => lt.map(
5323
5362
  (Rt) => Rt.localId === rt ? { ...Rt, uploading: !1, error: ht } : Rt
5324
5363
  )
5325
5364
  );
5326
5365
  });
5327
5366
  }
5328
- return ae;
5367
+ return re;
5329
5368
  });
5330
5369
  }, [n]), Je = (f) => {
5331
- p((D) => {
5332
- const ee = D.find((ae) => ae.localId === f);
5333
- 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);
5334
5373
  });
5335
5374
  }, F = (f) => {
5336
5375
  f.dataTransfer.types.includes("Files") && (f.preventDefault(), y(!0));
5337
5376
  }, Ye = (f) => {
5338
- const D = f.relatedTarget;
5339
- (!D || !f.currentTarget.contains(D)) && y(!1);
5340
- }, de = (f) => {
5377
+ const A = f.relatedTarget;
5378
+ (!A || !f.currentTarget.contains(A)) && y(!1);
5379
+ }, ue = (f) => {
5341
5380
  f.preventDefault(), y(!1), f.dataTransfer.files && f.dataTransfer.files.length > 0 && ve(f.dataTransfer.files);
5342
- }, P = (f) => {
5343
- const D = [];
5344
- for (const ee of f.clipboardData.items)
5345
- if (ee.kind === "file") {
5346
- const ae = ee.getAsFile();
5347
- 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);
5348
5387
  }
5349
- D.length > 0 && (f.preventDefault(), ve(D));
5350
- }, 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);
5351
5390
  function Te() {
5352
5391
  const f = c.trim();
5353
- if (n && !(!f && $.length === 0) && !R && q(n, f, $.length > 0 ? $ : void 0)) {
5354
- for (const D of u)
5355
- D.previewUrl && URL.revokeObjectURL(D.previewUrl);
5356
- 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("");
5357
5396
  }
5358
5397
  }
5359
5398
  function be(f) {
@@ -5365,13 +5404,13 @@ function Cn() {
5365
5404
  className: "relative -m-4 h-[calc(100%+2rem)] overflow-hidden md:-m-6 md:h-[calc(100%+3rem)]",
5366
5405
  onDragOver: F,
5367
5406
  onDragLeave: Ye,
5368
- onDrop: de,
5407
+ onDrop: ue,
5369
5408
  children: [
5370
- 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") }),
5371
5410
  /* @__PURE__ */ e(
5372
5411
  "div",
5373
5412
  {
5374
- ref: T,
5413
+ ref: P,
5375
5414
  className: "absolute inset-0 overflow-y-auto px-4 py-6",
5376
5415
  onScroll: W,
5377
5416
  children: /* @__PURE__ */ r(
@@ -5402,8 +5441,8 @@ function Cn() {
5402
5441
  "button",
5403
5442
  {
5404
5443
  onClick: () => {
5405
- var D;
5406
- o(f), (D = se.current) == null || D.focus();
5444
+ var A;
5445
+ o(f), (A = ie.current) == null || A.focus();
5407
5446
  },
5408
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",
5409
5448
  children: f
@@ -5411,7 +5450,7 @@ function Cn() {
5411
5450
  f
5412
5451
  )) })
5413
5452
  ] }),
5414
- Re.map((f, D) => /* @__PURE__ */ e(ds, { message: f }, D)),
5453
+ Re.map((f, A) => /* @__PURE__ */ e(ds, { message: f }, A)),
5415
5454
  /* @__PURE__ */ e("div", { ref: K })
5416
5455
  ]
5417
5456
  }
@@ -5421,7 +5460,7 @@ function Cn() {
5421
5460
  /* @__PURE__ */ e(
5422
5461
  "div",
5423
5462
  {
5424
- ref: le,
5463
+ ref: oe,
5425
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",
5426
5465
  children: /* @__PURE__ */ r("div", { className: "mx-auto max-w-3xl", children: [
5427
5466
  u.length > 0 && /* @__PURE__ */ e("div", { className: "mb-2 flex flex-wrap gap-2", children: u.map((f) => /* @__PURE__ */ r(
@@ -5451,7 +5490,7 @@ function Cn() {
5451
5490
  /* @__PURE__ */ e(
5452
5491
  "input",
5453
5492
  {
5454
- ref: I,
5493
+ ref: R,
5455
5494
  type: "file",
5456
5495
  accept: "image/png,image/jpeg,image/gif,image/webp,application/pdf",
5457
5496
  multiple: !0,
@@ -5465,19 +5504,19 @@ function Cn() {
5465
5504
  /* @__PURE__ */ e(
5466
5505
  "textarea",
5467
5506
  {
5468
- ref: se,
5507
+ ref: ie,
5469
5508
  value: c,
5470
5509
  onChange: (f) => o(f.target.value),
5471
5510
  onKeyDown: be,
5472
- onPaste: P,
5511
+ onPaste: I,
5473
5512
  placeholder: t(Ae ? "chat.placeholderDemo" : he ? "chat.placeholderType" : "chat.placeholderConnecting"),
5474
5513
  disabled: !he || !n || xe || Ae,
5475
5514
  rows: 2,
5476
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",
5477
5516
  style: { minHeight: "3rem", maxHeight: "120px" },
5478
5517
  onInput: (f) => {
5479
- const D = f.target;
5480
- 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";
5481
5520
  }
5482
5521
  }
5483
5522
  ),
@@ -5486,7 +5525,7 @@ function Cn() {
5486
5525
  {
5487
5526
  onClick: () => {
5488
5527
  var f;
5489
- return (f = I.current) == null ? void 0 : f.click();
5528
+ return (f = R.current) == null ? void 0 : f.click();
5490
5529
  },
5491
5530
  disabled: !he || !n || xe || Ae || u.length >= zt,
5492
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",
@@ -5498,7 +5537,7 @@ function Cn() {
5498
5537
  "button",
5499
5538
  {
5500
5539
  onClick: Te,
5501
- disabled: !c.trim() && $.length === 0 || !he || !n || xe || Ae || R || M,
5540
+ disabled: !c.trim() && $.length === 0 || !he || !n || xe || Ae || L || M,
5502
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",
5503
5542
  children: /* @__PURE__ */ e(
5504
5543
  "svg",
@@ -5520,7 +5559,7 @@ function Cn() {
5520
5559
  className: `inline-block h-1.5 w-1.5 rounded-full ${he ? "bg-emerald-500" : "bg-rose-500"} ${he ? "" : "animate-pulse"}`
5521
5560
  }
5522
5561
  ),
5523
- /* @__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" })
5524
5563
  ] })
5525
5564
  ] })
5526
5565
  }
@@ -5686,35 +5725,35 @@ function ps(t, n) {
5686
5725
  return s < t.length && a.push(t.slice(s)), a.length > 0 ? a : [t];
5687
5726
  }
5688
5727
  function hs() {
5689
- 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("");
5690
- 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(() => {
5691
5730
  a && a.role !== "public_manager" && t("/", { replace: !0 });
5692
- }, [a, t]), re(() => {
5731
+ }, [a, t]), se(() => {
5693
5732
  O.authSetupStatus().then((q) => {
5694
5733
  u(q.registration_open), q.registration_open && m("register");
5695
5734
  }).catch(() => {
5696
5735
  }).finally(() => v(!1));
5697
5736
  }, []);
5698
- const k = async (q) => {
5699
- if (q.preventDefault(), g(""), o === "register") {
5700
- if (b !== A) {
5701
- g(i("login.passwordsNoMatch"));
5737
+ const N = async (q) => {
5738
+ if (q.preventDefault(), h(""), o === "register") {
5739
+ if (b !== _) {
5740
+ h(i("login.passwordsNoMatch"));
5702
5741
  return;
5703
5742
  }
5704
5743
  if (b.length < 6) {
5705
- g(i("login.passwordTooShort"));
5744
+ h(i("login.passwordTooShort"));
5706
5745
  return;
5707
5746
  }
5708
5747
  try {
5709
- await l(y, L, b, c || void 0), t("/", { replace: !0 });
5748
+ await l(y, B, b, c || void 0), t("/", { replace: !0 });
5710
5749
  } catch (x) {
5711
- g(x instanceof et ? x.message : i("login.registrationFailed"));
5750
+ h(x instanceof et ? x.message : i("login.registrationFailed"));
5712
5751
  }
5713
5752
  } else
5714
5753
  try {
5715
5754
  await s(y, b), t("/", { replace: !0 });
5716
5755
  } catch (x) {
5717
- g(x instanceof et ? x.message : i("login.loginFailed"));
5756
+ h(x instanceof et ? x.message : i("login.loginFailed"));
5718
5757
  }
5719
5758
  };
5720
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: [
@@ -5723,48 +5762,48 @@ function hs() {
5723
5762
  /* @__PURE__ */ e("p", { className: "mt-1 text-sm text-fg-muted", children: i(d ? "login.taglineFirstRun" : o === "register" ? "login.taglineRegister" : "login.taglineSignIn") }),
5724
5763
  (a == null ? void 0 : a.role) === "public_manager" && /* @__PURE__ */ e("p", { className: "mt-2 text-xs text-amber-700", children: i("login.demoBanner") })
5725
5764
  ] }),
5726
- 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 }),
5727
- /* @__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: [
5728
5767
  o === "register" && /* @__PURE__ */ e(
5729
- pe,
5768
+ X,
5730
5769
  {
5731
5770
  label: i("login.fullName"),
5732
- value: L,
5771
+ value: B,
5733
5772
  onChange: (q) => C(q.target.value),
5734
5773
  required: !0
5735
5774
  }
5736
5775
  ),
5737
5776
  /* @__PURE__ */ e(
5738
- pe,
5777
+ X,
5739
5778
  {
5740
5779
  label: i("login.email"),
5741
5780
  type: "email",
5742
5781
  value: y,
5743
- onChange: (q) => I(q.target.value),
5782
+ onChange: (q) => R(q.target.value),
5744
5783
  required: !0
5745
5784
  }
5746
5785
  ),
5747
5786
  /* @__PURE__ */ e(
5748
- pe,
5787
+ X,
5749
5788
  {
5750
5789
  label: i("login.password"),
5751
5790
  type: "password",
5752
5791
  value: b,
5753
- onChange: (q) => h(q.target.value),
5792
+ onChange: (q) => g(q.target.value),
5754
5793
  required: !0
5755
5794
  }
5756
5795
  ),
5757
5796
  o === "register" && /* @__PURE__ */ e(
5758
- pe,
5797
+ X,
5759
5798
  {
5760
5799
  label: i("login.confirmPassword"),
5761
5800
  type: "password",
5762
- value: A,
5763
- onChange: (q) => B(q.target.value),
5801
+ value: _,
5802
+ onChange: (q) => w(q.target.value),
5764
5803
  required: !0
5765
5804
  }
5766
5805
  ),
5767
- /* @__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") })
5768
5807
  ] }) }),
5769
5808
  (a == null ? void 0 : a.role) === "public_manager" && /* @__PURE__ */ e(V, { children: /* @__PURE__ */ r("div", { className: "space-y-3", children: [
5770
5809
  /* @__PURE__ */ r("div", { children: [
@@ -5772,7 +5811,7 @@ function hs() {
5772
5811
  /* @__PURE__ */ e("p", { className: "mt-1 text-sm text-fg-muted", children: i("login.browsingBody") })
5773
5812
  ] }),
5774
5813
  /* @__PURE__ */ e(
5775
- X,
5814
+ ee,
5776
5815
  {
5777
5816
  type: "button",
5778
5817
  className: "w-full",
@@ -5793,8 +5832,8 @@ function hs() {
5793
5832
  ] }) });
5794
5833
  }
5795
5834
  function gs() {
5796
- const t = Oe(), n = H(!1), [a, s] = N("");
5797
- return re(() => {
5835
+ const t = Oe(), n = H(!1), [a, s] = S("");
5836
+ return se(() => {
5798
5837
  n.current || (n.current = !0, O.createChatSession().then((l) => {
5799
5838
  t(`/chat/${l.id}?demo=1`, { replace: !0 });
5800
5839
  }).catch((l) => {
@@ -5825,54 +5864,54 @@ function An() {
5825
5864
  return { type: "sales", party: "", amount: "", due_date: "", remarks: "" };
5826
5865
  }
5827
5866
  function ys() {
5828
- 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({
5829
5868
  mutationFn: () => O.importAccountBalances({
5830
5869
  company: a,
5831
5870
  posting_date: l,
5832
- entries: m.filter((h) => h.account && (h.debit || h.credit)).map((h) => ({
5833
- account: h.account,
5834
- debit: parseFloat(h.debit) || 0,
5835
- credit: parseFloat(h.credit) || 0,
5836
- party_type: h.party_type || void 0,
5837
- 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
5838
5877
  }))
5839
5878
  }),
5840
- onSuccess: (h) => y((A) => ({ ...A, accounts: h }))
5841
- }), L = me({
5879
+ onSuccess: (g) => y((_) => ({ ..._, accounts: g }))
5880
+ }), B = pe({
5842
5881
  mutationFn: () => O.importStockBalances({
5843
5882
  company: a,
5844
5883
  posting_date: l,
5845
5884
  warehouse: c,
5846
- items: u.filter((h) => h.item_code && h.qty).map((h) => ({
5847
- item_code: h.item_code,
5848
- qty: parseFloat(h.qty) || 0,
5849
- 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
5850
5889
  }))
5851
5890
  }),
5852
- onSuccess: (h) => y((A) => ({ ...A, stock: h }))
5853
- }), C = me({
5891
+ onSuccess: (g) => y((_) => ({ ..._, stock: g }))
5892
+ }), C = pe({
5854
5893
  mutationFn: () => O.importOutstandingInvoices({
5855
5894
  company: a,
5856
- invoices: v.filter((h) => h.party && h.amount).map((h) => ({
5857
- type: h.type,
5858
- party: h.party,
5859
- amount: parseFloat(h.amount) || 0,
5860
- due_date: h.due_date || void 0,
5861
- 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,
5862
5901
  posting_date: l
5863
5902
  }))
5864
5903
  }),
5865
- onSuccess: (h) => y((A) => ({ ...A, invoices: h }))
5904
+ onSuccess: (g) => y((_) => ({ ..._, invoices: g }))
5866
5905
  });
5867
- function b(h, A, B, k, q) {
5868
- const x = [...h];
5869
- x[B][k] = q, A(x);
5906
+ function b(g, _, w, N, q) {
5907
+ const x = [...g];
5908
+ x[w][N] = q, _(x);
5870
5909
  }
5871
5910
  return /* @__PURE__ */ r("div", { className: "space-y-6", children: [
5872
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." }),
5873
5912
  /* @__PURE__ */ e(V, { title: "Common Settings", children: /* @__PURE__ */ r("div", { className: "flex flex-wrap items-end gap-4", children: [
5874
5913
  /* @__PURE__ */ e(ke, { label: "Company", value: a, onChange: s, linkDoctype: "company", readOnly: !1 }),
5875
- /* @__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) })
5876
5915
  ] }) }),
5877
5916
  /* @__PURE__ */ r(V, { title: "1. Account Balances", children: [
5878
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." }),
@@ -5884,25 +5923,25 @@ function ys() {
5884
5923
  /* @__PURE__ */ e("th", { className: "px-2 py-2 text-right font-medium text-gray-500", children: "Debit" }),
5885
5924
  /* @__PURE__ */ e("th", { className: "px-2 py-2 text-right font-medium text-gray-500", children: "Credit" })
5886
5925
  ] }) }),
5887
- /* @__PURE__ */ e("tbody", { children: m.map((h, A) => /* @__PURE__ */ r("tr", { children: [
5888
- /* @__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: "" }) }),
5889
- /* @__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: [
5890
5929
  /* @__PURE__ */ e("option", { value: "", children: "—" }),
5891
5930
  /* @__PURE__ */ e("option", { value: "Customer", children: "Customer" }),
5892
5931
  /* @__PURE__ */ e("option", { value: "Supplier", children: "Supplier" })
5893
5932
  ] }) }),
5894
- /* @__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" }) }),
5895
- /* @__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" }) }),
5896
- /* @__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" }) })
5897
- ] }, 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
+ ] }, _)) })
5898
5937
  ] }) }),
5899
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" }) }),
5900
5939
  /* @__PURE__ */ r("div", { className: "mt-3 flex items-center gap-3", children: [
5901
- /* @__PURE__ */ e(X, { onClick: () => I.mutate(), disabled: !a || I.isPending, children: I.isPending ? "Importing..." : "Import Account Balances" }),
5902
- I.error && /* @__PURE__ */ e("span", { className: "text-xs text-red-600", children: I.error.message }),
5903
- 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: [
5904
5943
  "Created ",
5905
- g.accounts.journal_entry
5944
+ h.accounts.journal_entry
5906
5945
  ] })
5907
5946
  ] })
5908
5947
  ] }),
@@ -5915,21 +5954,21 @@ function ys() {
5915
5954
  /* @__PURE__ */ e("th", { className: "px-2 py-2 text-right font-medium text-gray-500", children: "Qty" }),
5916
5955
  /* @__PURE__ */ e("th", { className: "px-2 py-2 text-right font-medium text-gray-500", children: "Rate" })
5917
5956
  ] }) }),
5918
- /* @__PURE__ */ e("tbody", { children: u.map((h, A) => /* @__PURE__ */ r("tr", { children: [
5919
- /* @__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 }) }),
5920
- /* @__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" }) }),
5921
- /* @__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" }) })
5922
- ] }, 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
+ ] }, _)) })
5923
5962
  ] }) }),
5924
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" }) }),
5925
5964
  /* @__PURE__ */ r("div", { className: "mt-3 flex items-center gap-3", children: [
5926
- /* @__PURE__ */ e(X, { onClick: () => L.mutate(), disabled: !a || !c || L.isPending, children: L.isPending ? "Importing..." : "Import Stock Balances" }),
5927
- L.error && /* @__PURE__ */ e("span", { className: "text-xs text-red-600", children: L.error.message }),
5928
- 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: [
5929
5968
  "Created ",
5930
- g.stock.stock_entry,
5969
+ h.stock.stock_entry,
5931
5970
  " (",
5932
- g.stock.items_count,
5971
+ h.stock.items_count,
5933
5972
  " items)"
5934
5973
  ] })
5935
5974
  ] })
@@ -5944,8 +5983,8 @@ function ys() {
5944
5983
  /* @__PURE__ */ e("th", { className: "px-2 py-2 text-left font-medium text-gray-500", children: "Due Date" }),
5945
5984
  /* @__PURE__ */ e("th", { className: "px-2 py-2 text-left font-medium text-gray-500", children: "Ref / Remarks" })
5946
5985
  ] }) }),
5947
- /* @__PURE__ */ e("tbody", { children: v.map((h, A) => /* @__PURE__ */ r("tr", { children: [
5948
- /* @__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: [
5949
5988
  /* @__PURE__ */ e("option", { value: "sales", children: "Sales (AR)" }),
5950
5989
  /* @__PURE__ */ e("option", { value: "purchase", children: "Purchase (AP)" })
5951
5990
  ] }) }),
@@ -5953,24 +5992,24 @@ function ys() {
5953
5992
  ke,
5954
5993
  {
5955
5994
  label: "",
5956
- value: h.party,
5957
- onChange: (B) => b(v, w, A, "party", B),
5958
- 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",
5959
5998
  readOnly: !1
5960
5999
  }
5961
6000
  ) }),
5962
- /* @__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" }) }),
5963
- /* @__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" }) }),
5964
- /* @__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" }) })
5965
- ] }, 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
+ ] }, _)) })
5966
6005
  ] }) }),
5967
- /* @__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" }) }),
5968
6007
  /* @__PURE__ */ r("div", { className: "mt-3 flex items-center gap-3", children: [
5969
- /* @__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" }),
5970
6009
  C.error && /* @__PURE__ */ e("span", { className: "text-xs text-red-600", children: C.error.message }),
5971
- 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: [
5972
6011
  "Created ",
5973
- g.invoices.invoices_created,
6012
+ h.invoices.invoices_created,
5974
6013
  " invoices"
5975
6014
  ] })
5976
6015
  ] })
@@ -5991,22 +6030,22 @@ function ys() {
5991
6030
  ] });
5992
6031
  }
5993
6032
  function fs() {
5994
- const { user: t } = mt(), n = We(), { data: a, isLoading: s } = ie({
6033
+ const { user: t } = mt(), n = We(), { data: a, isLoading: s } = le({
5995
6034
  queryKey: ["auth-users"],
5996
6035
  queryFn: () => O.authListUsers()
5997
- }), { data: l } = ie({
6036
+ }), { data: l } = le({
5998
6037
  queryKey: ["auth-invites"],
5999
6038
  queryFn: () => O.authListInvites()
6000
- }), [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({
6001
6040
  mutationFn: () => O.authInvite(i, o),
6002
- onSuccess: (g) => {
6003
- u(g), c(""), n.invalidateQueries({ queryKey: ["auth-invites"] });
6041
+ onSuccess: (h) => {
6042
+ u(h), c(""), n.invalidateQueries({ queryKey: ["auth-invites"] });
6004
6043
  }
6005
- }), v = me({
6006
- mutationFn: ({ name: g, role: y }) => O.authChangeRole(g, y),
6044
+ }), v = pe({
6045
+ mutationFn: ({ name: h, role: y }) => O.authChangeRole(h, y),
6007
6046
  onSuccess: () => n.invalidateQueries({ queryKey: ["auth-users"] })
6008
- }), w = me({
6009
- mutationFn: (g) => O.authDisableUser(g),
6047
+ }), D = pe({
6048
+ mutationFn: (h) => O.authDisableUser(h),
6010
6049
  onSuccess: () => n.invalidateQueries({ queryKey: ["auth-users"] })
6011
6050
  });
6012
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: [
@@ -6027,12 +6066,12 @@ function fs() {
6027
6066
  /* @__PURE__ */ r(V, { title: "Invite User", children: [
6028
6067
  /* @__PURE__ */ r("div", { className: "flex flex-wrap items-end gap-4", children: [
6029
6068
  /* @__PURE__ */ e(
6030
- pe,
6069
+ X,
6031
6070
  {
6032
6071
  label: "Email",
6033
6072
  type: "email",
6034
6073
  value: i,
6035
- onChange: (g) => c(g.target.value),
6074
+ onChange: (h) => c(h.target.value),
6036
6075
  placeholder: "colleague@company.com"
6037
6076
  }
6038
6077
  ),
@@ -6042,11 +6081,11 @@ function fs() {
6042
6081
  label: "Role",
6043
6082
  options: ["viewer", "manager", "admin"],
6044
6083
  value: o,
6045
- onChange: (g) => m(g.target.value)
6084
+ onChange: (h) => m(h.target.value)
6046
6085
  }
6047
6086
  ),
6048
6087
  /* @__PURE__ */ e(
6049
- X,
6088
+ ee,
6050
6089
  {
6051
6090
  onClick: () => p.mutate(),
6052
6091
  disabled: !i.trim() || p.isPending,
@@ -6067,19 +6106,19 @@ function fs() {
6067
6106
  ] })
6068
6107
  ] })
6069
6108
  ] }),
6070
- 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: [
6071
6110
  /* @__PURE__ */ e("thead", { className: "bg-gray-50", children: /* @__PURE__ */ r("tr", { children: [
6072
6111
  /* @__PURE__ */ e("th", { className: "px-4 py-2 text-left font-medium text-gray-500", children: "Email" }),
6073
6112
  /* @__PURE__ */ e("th", { className: "px-4 py-2 text-left font-medium text-gray-500", children: "Role" }),
6074
6113
  /* @__PURE__ */ e("th", { className: "px-4 py-2 text-left font-medium text-gray-500", children: "Created" })
6075
6114
  ] }) }),
6076
- /* @__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) => {
6077
6116
  var y;
6078
6117
  return /* @__PURE__ */ r("tr", { children: [
6079
- /* @__PURE__ */ e("td", { className: "px-4 py-2", children: g.email }),
6080
- /* @__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 }) }),
6081
- /* @__PURE__ */ e("td", { className: "px-4 py-2 text-gray-500", children: (y = g.creation) == null ? void 0 : y.split("T")[0] })
6082
- ] }, 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);
6083
6122
  }) })
6084
6123
  ] }) }),
6085
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: [
@@ -6090,16 +6129,16 @@ function fs() {
6090
6129
  /* @__PURE__ */ e("th", { className: "px-4 py-2 text-left font-medium text-gray-500", children: "Status" }),
6091
6130
  /* @__PURE__ */ e("th", { className: "px-4 py-2 text-right font-medium text-gray-500", children: "Actions" })
6092
6131
  ] }) }),
6093
- /* @__PURE__ */ e("tbody", { className: "divide-y divide-gray-100", children: (a || []).map((g) => /* @__PURE__ */ r("tr", { className: "hover:bg-gray-50", children: [
6094
- /* @__PURE__ */ e("td", { className: "px-4 py-2 font-medium text-gray-900", children: g.full_name }),
6095
- /* @__PURE__ */ e("td", { className: "px-4 py-2 text-gray-600", children: g.email }),
6096
- /* @__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(
6097
6136
  "select",
6098
6137
  {
6099
- value: g.role,
6100
- onChange: (y) => v.mutate({ name: g.name, role: y.target.value }),
6101
- disabled: g.name === (t == null ? void 0 : t.name),
6102
- 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"}`,
6103
6142
  children: [
6104
6143
  /* @__PURE__ */ e("option", { value: "viewer", children: "viewer" }),
6105
6144
  /* @__PURE__ */ e("option", { value: "manager", children: "manager" }),
@@ -6107,16 +6146,16 @@ function fs() {
6107
6146
  ]
6108
6147
  }
6109
6148
  ) }),
6110
- /* @__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" }) }),
6111
- /* @__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(
6112
6151
  "button",
6113
6152
  {
6114
- onClick: () => w.mutate(g.name),
6153
+ onClick: () => D.mutate(h.name),
6115
6154
  className: "text-xs text-red-500 hover:text-red-700",
6116
6155
  children: "Disable"
6117
6156
  }
6118
6157
  ) : null })
6119
- ] }, g.name)) })
6158
+ ] }, h.name)) })
6120
6159
  ] }) })
6121
6160
  ] });
6122
6161
  }
@@ -6239,13 +6278,13 @@ function Ze(t) {
6239
6278
  return t === 0 ? "$0.00" : t < 0.01 ? `$${t.toFixed(4)}` : `$${t.toFixed(2)}`;
6240
6279
  }
6241
6280
  function Ci() {
6242
- var I, L;
6243
- 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({
6244
6283
  queryKey: ["demo-spend"],
6245
6284
  queryFn: () => O.getDemoSpend(),
6246
6285
  // Refresh once a minute — demo spend changes slowly; no need to poll harder.
6247
6286
  refetchInterval: 6e4
6248
- }), 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";
6249
6288
  return /* @__PURE__ */ r(V, { title: t("settings.demoSpendTitle"), children: [
6250
6289
  /* @__PURE__ */ r("div", { className: "flex flex-wrap items-end justify-between gap-4", children: [
6251
6290
  /* @__PURE__ */ r("div", { className: "max-w-lg text-sm text-gray-600", children: [
@@ -6328,17 +6367,17 @@ function Ci() {
6328
6367
  Ze(u.total_usd),
6329
6368
  /* @__PURE__ */ r("span", { className: "ml-1 text-xs font-normal text-gray-500", children: [
6330
6369
  "(",
6331
- Ze(w),
6370
+ Ze(D),
6332
6371
  "/hr)"
6333
6372
  ] })
6334
6373
  ] })
6335
6374
  ] })
6336
6375
  ] }),
6337
- /* @__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}%` } }) }),
6338
6377
  /* @__PURE__ */ r("div", { className: "mt-1 text-xs text-gray-400", children: [
6339
- g.toFixed(0),
6378
+ h.toFixed(0),
6340
6379
  "% of the hourly cap",
6341
- g >= 100 && " — demo visitors are currently blocked"
6380
+ h >= 100 && " — demo visitors are currently blocked"
6342
6381
  ] })
6343
6382
  ] }),
6344
6383
  /* @__PURE__ */ r("div", { className: "grid grid-cols-2 gap-3 sm:grid-cols-4", children: [
@@ -6399,21 +6438,21 @@ function ft({ label: t, value: n }) {
6399
6438
  ] });
6400
6439
  }
6401
6440
  function Di() {
6402
- 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({
6403
6442
  queryKey: ["settings"],
6404
6443
  queryFn: () => O.getSettings()
6405
- }), c = me({
6444
+ }), c = pe({
6406
6445
  mutationFn: (v) => O.updateSettings(v),
6407
6446
  onSuccess: () => a.invalidateQueries({ queryKey: ["settings"] })
6408
- }), { data: o } = ie({
6447
+ }), { data: o } = le({
6409
6448
  queryKey: ["public-manager"],
6410
6449
  queryFn: () => O.getPublicManagerStatus()
6411
- }), [m, d] = N(!1), u = me({
6450
+ }), [m, d] = S(!1), u = pe({
6412
6451
  mutationFn: () => O.createPublicManager(),
6413
6452
  onSuccess: () => {
6414
6453
  a.invalidateQueries({ queryKey: ["public-manager"] }), d(!1);
6415
6454
  }
6416
- }), p = me({
6455
+ }), p = pe({
6417
6456
  mutationFn: () => O.removePublicManager(),
6418
6457
  onSuccess: () => a.invalidateQueries({ queryKey: ["public-manager"] })
6419
6458
  });