@fayz-ai/plugin-financial 0.29.2 → 0.29.4

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,13 +1,14 @@
1
- import { renderCardChip, BankPicker, renderAccountAvatar, PaymentModal, InvoiceFormView, InvoiceDetailView, ACCOUNTS_ROUTE } from './chunk-IQHWMVUM.js';
2
- export { FINANCIAL_INVOICE_ZONES } from './chunk-IQHWMVUM.js';
1
+ import { renderCardChip, BankPicker, renderAccountAvatar, PaymentModal, InvoiceFormView, InvoiceDetailView, ACCOUNTS_ROUTE } from './chunk-W7T7RTC4.js';
2
+ export { FINANCIAL_INVOICE_ZONES } from './chunk-W7T7RTC4.js';
3
+ import './chunk-XGBGRXZ3.js';
3
4
  import './chunk-7VKJLBYY.js';
4
5
  import { FINANCIAL_MODULE_DEFAULTS } from './chunk-POYZFEAN.js';
5
6
  import { FinancialContextProvider, useFinancialProvider, formatCurrency, useFinancialConfig, useFinancialStore } from './chunk-CNXAVGSW.js';
6
- import * as React5 from 'react';
7
- import React5__default, { useEffect } from 'react';
8
- import { CircleDollarSign, FileText, Search, X, ChevronsUpDown, ChevronsDownUp, Plus, ChevronRight, FolderOpen, Folder, Pencil, Ban, RotateCcw, Trash2, Wallet, ArrowUpRight, ArrowDownRight, AlertTriangle, EyeOff, Eye, CreditCard } from 'lucide-react';
7
+ import * as React3 from 'react';
8
+ import React3__default, { useEffect } from 'react';
9
+ import { CircleDollarSign, FileText, Wallet, ArrowUpRight, ArrowDownRight, AlertTriangle, EyeOff, Eye, CreditCard } from 'lucide-react';
9
10
  import { registerTranslations, tl, recordRailFields, RECORD_GROUP, activeFacet, lazyComponent, createConnectionStore, connectionSettings, connectionStatus, settingsStatus, connectionRuns, useTranslation, resolveDataProvider, emitDataChanged, registerMessageDefaults, countByTenant, onAppPathChange, resolveCurrency } from '@fayz-ai/core';
10
- import { Button, Badge, Input, ModalTask, Skeleton, SegmentedControl, PageHeaderActions, Checkbox, Select, SelectTrigger, SelectValue, SelectContent, SelectItem, SearchSelect, toast, defineKpiWidget, defineChartWidget, defineCustomWidget, defineTableWidget, Modal, ModalContent, ModalHeader, ModalTitle, ModalDescription, ModalBody, KpiCard, ChartWidget, Card, CardHeader, CardTitle, CardContent, TableWidget, useDashboardNavigate, GoldCard } from '@fayz-ai/ui';
11
+ import { Button, Badge, Input, ModalTask, SegmentedControl, TreeManager, Select, SelectTrigger, SelectValue, SelectContent, SelectItem, SearchSelect, toast, defineKpiWidget, defineChartWidget, defineCustomWidget, defineTableWidget, Modal, ModalContent, ModalHeader, ModalTitle, ModalDescription, ModalBody, KpiCard, ChartWidget, Card, CardHeader, CardTitle, CardContent, TableWidget, useDashboardNavigate, GoldCard } from '@fayz-ai/ui';
11
12
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
12
13
  import { createSafeFinancialProvider, createFinancialStore } from '@fayz-ai/financial/store';
13
14
  export { createSafeFinancialProvider } from '@fayz-ai/financial/store';
@@ -15,7 +16,7 @@ import { FINANCIAL_ZONES } from '@fayz-ai/financial/views/zones';
15
16
  import { draftAllProductsForPriceTable, addAllProductsToPriceTable, fayzConnectorOAuth, defineSettingsTab, RightRailPage, useConnectors, useConnectorsPanelAvailable, SettingsForm, ConnectorMark, StateChip, ConnectorDetail, usePermissionOptional, openConnectorsPanel, createCrudPage, PluginSettingsPanel, useTenantPluginSettings } from '@fayz-ai/admin';
16
17
  import { invoiceOpensForEditing } from '@fayz-ai/financial/domain/invoice';
17
18
  import { T } from '@fayz-ai/financial/data/tables';
18
- import { buildChartTree, rootIds, searchVisibleIds, isGroupNode, descendantIds, accountLabel, suggestNextCode, childIds } from '@fayz-ai/financial/domain/chart-of-accounts';
19
+ import { buildChartTree, isGroupNode, compareCodes, suggestNextCode, accountLabel, descendantIds, childIds } from '@fayz-ai/financial/domain/chart-of-accounts';
19
20
  import { useStore } from 'zustand';
20
21
  import { MIGRATIONS } from '#migrations/main';
21
22
  export { createMockFinancialProvider } from '@fayz-ai/financial/data/mock';
@@ -247,7 +248,7 @@ function RecentTransactions() {
247
248
  const t = useTranslation();
248
249
  const { currency } = useFinancialConfig();
249
250
  const provider = useFinancialProvider();
250
- const [invoices, setInvoices] = React5__default.useState([]);
251
+ const [invoices, setInvoices] = React3__default.useState([]);
251
252
  useEffect(() => {
252
253
  let alive = true;
253
254
  void provider.getInvoices({ ...RECENT_TRANSACTIONS_QUERY, dateRange: recentWindow() }).then((res) => {
@@ -290,7 +291,7 @@ function BalanceHero() {
290
291
  const summary = useFinancialStore((s) => s.summary);
291
292
  const navigate = useDashboardNavigate();
292
293
  useEnsureSummary();
293
- const [hidden, setHidden] = React5__default.useState(false);
294
+ const [hidden, setHidden] = React3__default.useState(false);
294
295
  const money = (v) => hidden ? "\u2022\u2022\u2022\u2022\u2022\u2022" : formatCurrency(v ?? 0, currency);
295
296
  const inflow = summary?.monthlyInflow ?? 0;
296
297
  const outflow = summary?.monthlyOutflow ?? 0;
@@ -369,7 +370,7 @@ function categorizeSpend(notes) {
369
370
  function SpendByCategoryChart() {
370
371
  const t = useTranslation();
371
372
  const provider = useFinancialProvider();
372
- const [rows, setRows] = React5__default.useState([]);
373
+ const [rows, setRows] = React3__default.useState([]);
373
374
  useEffect(() => {
374
375
  let alive = true;
375
376
  void (async () => {
@@ -412,7 +413,7 @@ function UpcomingBills() {
412
413
  const { currency } = useFinancialConfig();
413
414
  const provider = useFinancialProvider();
414
415
  const dueLabel = useDueLabel();
415
- const [bills, setBills] = React5__default.useState([]);
416
+ const [bills, setBills] = React3__default.useState([]);
416
417
  useEffect(() => {
417
418
  let alive = true;
418
419
  void (async () => {
@@ -876,6 +877,8 @@ var en = {
876
877
  "financial.nav.summary": "Summary",
877
878
  "financial.invoice.filterAccount": "Chart account",
878
879
  "financial.invoice.filterAllAccounts": "All accounts",
880
+ "financial.invoice.filterSearchAccount": "Search account\u2026",
881
+ "financial.invoice.filterNoAccountFound": "No account found",
879
882
  "financial.invoice.filterCostCenter": "Cost center",
880
883
  "financial.invoice.filterAllCostCenters": "All cost centers",
881
884
  "financial.invoice.filterPeriod": "Period",
@@ -1899,6 +1902,8 @@ var ptBR = {
1899
1902
  "financial.nav.summary": "Resumo",
1900
1903
  "financial.invoice.filterAccount": "Plano de contas",
1901
1904
  "financial.invoice.filterAllAccounts": "Todos os planos",
1905
+ "financial.invoice.filterSearchAccount": "Buscar conta\u2026",
1906
+ "financial.invoice.filterNoAccountFound": "Nenhuma conta encontrada",
1902
1907
  "financial.invoice.filterCostCenter": "Centro de custo",
1903
1908
  "financial.invoice.filterAllCostCenters": "Todos os centros",
1904
1909
  "financial.invoice.filterPeriod": "Per\xEDodo",
@@ -2698,8 +2703,8 @@ function ReceivePaymentModal({
2698
2703
  onClose,
2699
2704
  onPaid
2700
2705
  }) {
2701
- const provider = React5__default.useMemo(() => createSafeFinancialProvider(), []);
2702
- const store6 = React5__default.useMemo(() => createFinancialStore(provider), [provider]);
2706
+ const provider = React3__default.useMemo(() => createSafeFinancialProvider(), []);
2707
+ const store6 = React3__default.useMemo(() => createFinancialStore(provider), [provider]);
2703
2708
  return /* @__PURE__ */ jsx(FinancialContextProvider, { config: STANDALONE_CONFIG, provider, store: store6, children: /* @__PURE__ */ jsx(
2704
2709
  PaymentModal,
2705
2710
  {
@@ -2733,27 +2738,27 @@ function ClientAccountPanel({
2733
2738
  currency = BRL
2734
2739
  }) {
2735
2740
  const provider = useFinancialProvider();
2736
- const [account, setAccount] = React5__default.useState(null);
2737
- const [busy, setBusy] = React5__default.useState(false);
2738
- const [viewInvoiceId, setViewInvoiceId] = React5__default.useState(null);
2739
- const [comprando, setComprando] = React5__default.useState(false);
2740
- const [buscaServico, setBuscaServico] = React5__default.useState("");
2741
- const [catalogo, setCatalogo] = React5__default.useState([]);
2742
- const [escolhidos, setEscolhidos] = React5__default.useState([]);
2743
- const [comprandoBusy, setComprandoBusy] = React5__default.useState(false);
2744
- const [erroCompra, setErroCompra] = React5__default.useState(null);
2745
- const load = React5__default.useCallback(async () => {
2741
+ const [account, setAccount] = React3__default.useState(null);
2742
+ const [busy, setBusy] = React3__default.useState(false);
2743
+ const [viewInvoiceId, setViewInvoiceId] = React3__default.useState(null);
2744
+ const [comprando, setComprando] = React3__default.useState(false);
2745
+ const [buscaServico, setBuscaServico] = React3__default.useState("");
2746
+ const [catalogo, setCatalogo] = React3__default.useState([]);
2747
+ const [escolhidos, setEscolhidos] = React3__default.useState([]);
2748
+ const [comprandoBusy, setComprandoBusy] = React3__default.useState(false);
2749
+ const [erroCompra, setErroCompra] = React3__default.useState(null);
2750
+ const load = React3__default.useCallback(async () => {
2746
2751
  if (!personId) return;
2747
2752
  setAccount(await provider.getClientAccount(personId));
2748
2753
  }, [personId, provider]);
2749
- React5__default.useEffect(() => {
2754
+ React3__default.useEffect(() => {
2750
2755
  void load();
2751
2756
  }, [load]);
2752
2757
  const viewInvoice = account?.invoices.find((i) => i.id === viewInvoiceId) ?? null;
2753
2758
  const viewEditable = invoiceOpensForEditing(viewInvoice?.status);
2754
2759
  const forThis = account?.invoices.filter((i) => orderId && i.orderId === orderId) ?? [];
2755
2760
  const hasForThis = forThis.length > 0;
2756
- React5__default.useEffect(() => {
2761
+ React3__default.useEffect(() => {
2757
2762
  if (!comprando) return;
2758
2763
  let vivo = true;
2759
2764
  const t = setTimeout(async () => {
@@ -3042,8 +3047,8 @@ function ClientAccountPanel({
3042
3047
  ] });
3043
3048
  }
3044
3049
  function ClientAccountInline(props) {
3045
- const provider = React5__default.useMemo(() => createSafeFinancialProvider(), []);
3046
- const store6 = React5__default.useMemo(() => createFinancialStore(provider), [provider]);
3050
+ const provider = React3__default.useMemo(() => createSafeFinancialProvider(), []);
3051
+ const store6 = React3__default.useMemo(() => createFinancialStore(provider), [provider]);
3047
3052
  return /* @__PURE__ */ jsx(FinancialContextProvider, { config: STANDALONE_CONFIG, provider, store: store6, children: /* @__PURE__ */ jsx(ClientAccountPanel, { ...props }) });
3048
3053
  }
3049
3054
  function ClientAccountModal({
@@ -3128,371 +3133,265 @@ function ChartOfAccountsTree({ entity, mockData, dataProvider, embedded }) {
3128
3133
  const canCreate = can("financial", "create");
3129
3134
  const canEdit = can("financial", "edit");
3130
3135
  const canDelete = can("financial", "delete");
3131
- const provider = React5__default.useMemo(
3136
+ const provider = React3__default.useMemo(
3132
3137
  () => dataProvider ?? resolveDataProvider(entity, mockData ?? []),
3133
3138
  [entity, mockData, dataProvider]
3134
3139
  );
3135
3140
  const table = entity.data?.table;
3136
- const [nodes, setNodes] = React5__default.useState(null);
3137
- const [loadError, setLoadError] = React5__default.useState(null);
3138
- const [expanded, setExpanded] = React5__default.useState(/* @__PURE__ */ new Set());
3139
- const [query, setQuery] = React5__default.useState("");
3140
- const [showInactive, setShowInactive] = React5__default.useState(true);
3141
- const [side, setSide] = React5__default.useState("in");
3142
- const [editing, setEditing] = React5__default.useState(null);
3143
- const [confirmDelete, setConfirmDelete] = React5__default.useState(null);
3144
- const [busy, setBusy] = React5__default.useState(false);
3145
- const initialized = React5__default.useRef(false);
3146
- const reload = React5__default.useCallback(async () => {
3141
+ const [nodes, setNodes] = React3__default.useState(null);
3142
+ const [loadError, setLoadError] = React3__default.useState(null);
3143
+ const [side, setSide] = React3__default.useState("in");
3144
+ const [editing, setEditing] = React3__default.useState(null);
3145
+ const [busy, setBusy] = React3__default.useState(false);
3146
+ const reload = React3__default.useCallback(async () => {
3147
3147
  try {
3148
- const rows = await loadAll(provider);
3149
- setNodes(rows);
3148
+ setNodes(await loadAll(provider));
3150
3149
  setLoadError(null);
3151
- if (!initialized.current) {
3152
- initialized.current = true;
3153
- const tree2 = buildChartTree(rows);
3154
- setExpanded(new Set(rootIds(tree2)));
3155
- }
3156
3150
  } catch (err) {
3157
3151
  setLoadError(errorMessage(err));
3158
3152
  setNodes((prev) => prev ?? []);
3159
3153
  }
3160
3154
  }, [provider]);
3161
- React5__default.useEffect(() => {
3155
+ React3__default.useEffect(() => {
3162
3156
  void reload();
3163
3157
  }, [reload]);
3164
- const shown = React5__default.useMemo(
3165
- () => onSide((nodes ?? []).filter((n) => showInactive || n.isActive), side),
3166
- [nodes, showInactive, side]
3167
- );
3168
- const tree = React5__default.useMemo(() => buildChartTree(shown), [shown]);
3169
- const fullTree = React5__default.useMemo(() => buildChartTree(nodes ?? []), [nodes]);
3170
- const search = React5__default.useMemo(() => searchVisibleIds(tree, query), [tree, query]);
3171
- const groupIds = React5__default.useMemo(
3172
- () => [...tree.byId.values()].filter((n) => isGroupNode(tree, n)).map((n) => n.id),
3173
- [tree]
3174
- );
3175
- function toggle(id) {
3176
- setExpanded((prev) => {
3177
- const next = new Set(prev);
3178
- if (next.has(id)) next.delete(id);
3179
- else next.add(id);
3180
- return next;
3181
- });
3158
+ const shown = React3__default.useMemo(() => nodes === null ? null : onSide(nodes, side), [nodes, side]);
3159
+ const fullTree = React3__default.useMemo(() => buildChartTree(nodes ?? []), [nodes]);
3160
+ async function run(action, success) {
3161
+ setBusy(true);
3162
+ try {
3163
+ await action();
3164
+ if (table) emitDataChanged({ table });
3165
+ toast.success(success);
3166
+ await reload();
3167
+ return true;
3168
+ } catch (err) {
3169
+ toast.error(t("financial.chartTree.error.save"), { description: errorMessage(err) });
3170
+ return false;
3171
+ } finally {
3172
+ setBusy(false);
3173
+ }
3182
3174
  }
3183
- function startCreate(parentId) {
3184
- const parent = parentId ? fullTree.byId.get(parentId) : void 0;
3185
- setConfirmDelete(null);
3186
- setEditing({
3187
- mode: "create",
3188
- parentId,
3189
- draft: {
3190
- code: suggestNextCode(fullTree, parentId),
3191
- name: "",
3192
- nodeType: "leaf",
3193
- accountType: parent?.accountType ?? SIDE_TYPE[side],
3194
- parentId
3175
+ const hasOther = (nodes ?? []).some((n) => sideOf(n.accountType) === "other");
3176
+ const plural = (one, many) => (n) => t(n === 1 ? one : many, { count: n });
3177
+ return /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
3178
+ /* @__PURE__ */ jsx(
3179
+ SegmentedControl,
3180
+ {
3181
+ value: side,
3182
+ onChange: (v) => {
3183
+ setSide(v);
3184
+ setEditing(null);
3185
+ },
3186
+ options: [
3187
+ { value: "in", label: tl("Income (in)", "Receitas (entradas)") },
3188
+ { value: "out", label: tl("Expenses (out)", "Despesas (sa\xEDdas)") },
3189
+ ...hasOther ? [{ value: "other", label: tl("Balance", "Patrimoniais") }] : []
3190
+ ]
3195
3191
  }
3196
- });
3197
- if (parentId) setExpanded((prev) => new Set(prev).add(parentId));
3198
- }
3199
- function startEdit(node) {
3200
- setConfirmDelete(null);
3201
- setEditing({
3202
- mode: "edit",
3203
- id: node.id,
3204
- draft: {
3192
+ ),
3193
+ /* @__PURE__ */ jsx(
3194
+ TreeManager,
3195
+ {
3196
+ nodes: shown,
3197
+ getId: (n) => n.id,
3198
+ getParentId: (n) => n.parentId,
3199
+ getName: (n) => n.name,
3200
+ getCode: (n) => n.code,
3201
+ isActive: (n) => n.isActive,
3202
+ compare: (a, b) => compareCodes(a.code, b.code),
3203
+ isGroup: (n, hasChildren) => n.nodeType === "group" || hasChildren,
3204
+ loadError: loadError ? `${t("financial.chartTree.error.load")} ${loadError}` : null,
3205
+ busy,
3206
+ embedded,
3207
+ canCreate,
3208
+ canEdit,
3209
+ canRemove: canDelete,
3210
+ canAddChild: (n) => n.isActive && isGroupNode(fullTree, n),
3211
+ canDeactivate: (_n, hasChildren) => !hasChildren,
3212
+ onSetActive: (node, isActive) => run(
3213
+ () => provider.update(node.id, { isActive }),
3214
+ t(isActive ? "financial.chartTree.reactivated" : "financial.chartTree.deactivated", { name: node.name })
3215
+ ),
3216
+ onDelete: (node) => run(() => provider.remove(node.id), t("financial.chartTree.deleted", { name: node.name })),
3217
+ editing,
3218
+ onEditingChange: setEditing,
3219
+ renderBadges: (n) => n.accountType && /* @__PURE__ */ jsx(Badge, { variant: NATURE_VARIANT[n.accountType] ?? "default", dot: false, children: t(`financial.chartTree.nature.${n.accountType}`) }),
3220
+ renderEditor: (ctx) => /* @__PURE__ */ jsx(
3221
+ AccountEditor,
3222
+ {
3223
+ ctx,
3224
+ nodes: nodes ?? [],
3225
+ fullTree,
3226
+ side,
3227
+ busy,
3228
+ onSave: (id, payload) => id ? run(() => provider.update(id, payload), t("financial.chartTree.updated", { name: payload.name })) : run(() => provider.create({ ...payload, isActive: true }), t("financial.chartTree.created", { name: payload.name }))
3229
+ }
3230
+ ),
3231
+ labels: {
3232
+ searchPlaceholder: t("financial.chartTree.searchPlaceholder"),
3233
+ clearSearch: t("financial.chartTree.clearSearch"),
3234
+ expandAll: t("financial.chartTree.expandAll"),
3235
+ collapseAll: t("financial.chartTree.collapseAll"),
3236
+ expand: t("financial.chartTree.expand"),
3237
+ collapse: t("financial.chartTree.collapse"),
3238
+ addRoot: t("financial.chartTree.addRoot"),
3239
+ addChild: t("financial.chartTree.addChild"),
3240
+ edit: t("financial.chartTree.edit"),
3241
+ deactivate: t("financial.chartTree.deactivate"),
3242
+ reactivate: t("financial.chartTree.reactivate"),
3243
+ delete: t("financial.chartTree.delete"),
3244
+ confirmDelete: t("financial.chartTree.confirmDelete"),
3245
+ cancel: t("financial.chartTree.cancel"),
3246
+ inactive: t("financial.chartTree.inactive"),
3247
+ empty: t("financial.chartTree.empty"),
3248
+ noMatches: t("financial.chartTree.noMatches"),
3249
+ tree: t("registry.chart-of-accounts"),
3250
+ count: plural("financial.chartTree.countOne", "financial.chartTree.count"),
3251
+ matches: plural("financial.chartTree.matchesOne", "financial.chartTree.matches"),
3252
+ showInactive: (n) => t("financial.chartTree.showInactive", { count: n })
3253
+ }
3254
+ }
3255
+ )
3256
+ ] });
3257
+ }
3258
+ function AccountEditor({ ctx, nodes, fullTree, side, busy, onSave }) {
3259
+ const t = useTranslation();
3260
+ const selfId = ctx.editing.mode === "edit" ? ctx.editing.id : void 0;
3261
+ const [draft, setDraft] = React3__default.useState(() => {
3262
+ const node = ctx.node;
3263
+ if (node) {
3264
+ return {
3205
3265
  code: node.code,
3206
3266
  name: node.name,
3207
3267
  nodeType: node.nodeType === "group" ? "group" : "leaf",
3208
3268
  accountType: node.accountType ?? "",
3209
3269
  parentId: node.parentId ?? null
3210
- }
3211
- });
3212
- }
3213
- function validate(draft, selfId) {
3270
+ };
3271
+ }
3272
+ const parent2 = ctx.parentId ? fullTree.byId.get(ctx.parentId) : void 0;
3273
+ return {
3274
+ code: suggestNextCode(fullTree, ctx.parentId),
3275
+ name: "",
3276
+ nodeType: "leaf",
3277
+ accountType: parent2?.accountType ?? SIDE_TYPE[side],
3278
+ parentId: ctx.parentId
3279
+ };
3280
+ });
3281
+ const update = (patch) => setDraft((prev) => ({ ...prev, ...patch }));
3282
+ const parent = draft.parentId ? fullTree.byId.get(draft.parentId) : void 0;
3283
+ function validate() {
3214
3284
  const code = draft.code.trim();
3215
3285
  if (!code) return t("financial.chartTree.error.codeRequired");
3216
3286
  if (!draft.name.trim()) return t("financial.chartTree.error.nameRequired");
3217
- const clash = (nodes ?? []).find((n) => n.code === code && n.id !== selfId);
3287
+ const clash = nodes.find((n) => n.code === code && n.id !== selfId);
3218
3288
  if (clash) return t("financial.chartTree.error.codeTaken", { code, name: clash.name });
3219
3289
  if (selfId && draft.nodeType === "leaf" && childIds(fullTree, selfId).length > 0) {
3220
3290
  return t("financial.chartTree.error.leafWithChildren");
3221
3291
  }
3222
3292
  return null;
3223
3293
  }
3224
- async function run(action, success) {
3225
- setBusy(true);
3226
- try {
3227
- await action();
3228
- if (table) emitDataChanged({ table });
3229
- toast.success(success);
3230
- await reload();
3231
- return true;
3232
- } catch (err) {
3233
- toast.error(t("financial.chartTree.error.save"), { description: errorMessage(err) });
3234
- return false;
3235
- } finally {
3236
- setBusy(false);
3237
- }
3238
- }
3239
3294
  async function submit() {
3240
- if (!editing) return;
3241
- const { draft } = editing;
3242
- const invalid = validate(draft, editing.mode === "edit" ? editing.id : void 0);
3295
+ const invalid = validate();
3243
3296
  if (invalid) {
3244
3297
  toast.error(invalid);
3245
3298
  return;
3246
3299
  }
3247
- const payload = {
3300
+ const ok = await onSave(selfId ?? null, {
3248
3301
  code: draft.code.trim(),
3249
3302
  name: draft.name.trim(),
3250
3303
  nodeType: draft.nodeType,
3251
3304
  accountType: draft.accountType || null,
3252
3305
  parentId: draft.parentId
3253
- };
3254
- const ok = editing.mode === "create" ? await run(() => provider.create({ ...payload, isActive: true }), t("financial.chartTree.created", { name: payload.name })) : await run(() => provider.update(editing.id, payload), t("financial.chartTree.updated", { name: payload.name }));
3255
- if (ok) setEditing(null);
3256
- }
3257
- async function setActive(node, isActive) {
3258
- await run(
3259
- () => provider.update(node.id, { isActive }),
3260
- t(isActive ? "financial.chartTree.reactivated" : "financial.chartTree.deactivated", { name: node.name })
3261
- );
3262
- }
3263
- async function remove(node) {
3264
- const ok = await run(() => provider.remove(node.id), t("financial.chartTree.deleted", { name: node.name }));
3265
- if (ok) setConfirmDelete(null);
3306
+ });
3307
+ if (ok) ctx.close();
3266
3308
  }
3267
- const parentOptions = React5__default.useCallback((q, selfId) => {
3309
+ const parentOptions = (q) => {
3268
3310
  const blocked = selfId ? descendantIds(fullTree, selfId).add(selfId) : /* @__PURE__ */ new Set();
3269
3311
  const needle = q.trim().toLowerCase();
3270
- return [...fullTree.byId.values()].filter((n) => !blocked.has(n.id) && isGroupNode(fullTree, n)).filter((n) => !needle || accountLabel(n).toLowerCase().includes(needle)).sort((a, b) => a.code.localeCompare(b.code, void 0, { numeric: true })).slice(0, 50).map((n) => ({ id: n.id, label: accountLabel(n) }));
3271
- }, [fullTree]);
3272
- if (nodes === null) {
3273
- return /* @__PURE__ */ jsx("div", { className: "space-y-2", "aria-busy": "true", children: Array.from({ length: 6 }).map((_, i) => /* @__PURE__ */ jsx(Skeleton, { className: "h-9 w-full" }, i)) });
3274
- }
3275
- const roots = rootIds(tree).filter((id) => !search || search.visible.has(id));
3276
- const inactiveCount = (nodes ?? []).filter((n) => !n.isActive).length;
3277
- function renderForm(draft, level, selfId) {
3278
- const update = (patch) => setEditing((prev) => prev ? { ...prev, draft: { ...prev.draft, ...patch } } : prev);
3279
- const parent = draft.parentId ? fullTree.byId.get(draft.parentId) : void 0;
3280
- return (
3281
- // Not a <form>: Enter would "click" the first button inside SearchSelect
3282
- // (its clear action) and wipe the parent instead of saving.
3283
- /* @__PURE__ */ jsxs(
3284
- "div",
3285
- {
3286
- role: "group",
3287
- className: "rounded-md border border-border bg-muted/40 p-3 space-y-3",
3288
- style: { marginLeft: Math.min(level, 8) * 16 },
3289
- onKeyDown: (e) => {
3290
- if (e.key === "Escape") setEditing(null);
3291
- if (e.key === "Enter" && e.target.dataset.submitOnEnter) {
3292
- e.preventDefault();
3293
- void submit();
3294
- }
3295
- },
3296
- children: [
3297
- /* @__PURE__ */ jsxs("div", { className: "grid gap-3 sm:grid-cols-[8rem_1fr]", children: [
3298
- /* @__PURE__ */ jsxs("label", { className: "space-y-1 text-xs font-medium text-muted-foreground", children: [
3299
- t("financial.chartTree.field.code"),
3300
- /* @__PURE__ */ jsx(Input, { "data-submit-on-enter": "1", value: draft.code, onChange: (e) => update({ code: e.target.value }), required: true })
3301
- ] }),
3302
- /* @__PURE__ */ jsxs("label", { className: "space-y-1 text-xs font-medium text-muted-foreground", children: [
3303
- t("financial.chartTree.field.name"),
3304
- /* @__PURE__ */ jsx(Input, { "data-submit-on-enter": "1", autoFocus: true, value: draft.name, onChange: (e) => update({ name: e.target.value }), required: true })
3305
- ] })
3312
+ return [...fullTree.byId.values()].filter((n) => !blocked.has(n.id) && isGroupNode(fullTree, n)).filter((n) => !needle || accountLabel(n).toLowerCase().includes(needle)).sort((a, b) => compareCodes(a.code, b.code)).slice(0, 50).map((n) => ({ id: n.id, label: accountLabel(n) }));
3313
+ };
3314
+ return (
3315
+ // Not a <form>: Enter would "click" the first button inside SearchSelect
3316
+ // (its clear action) and wipe the parent instead of saving.
3317
+ /* @__PURE__ */ jsxs(
3318
+ "div",
3319
+ {
3320
+ role: "group",
3321
+ className: "rounded-md border border-border bg-muted/40 p-3 space-y-3",
3322
+ style: { marginLeft: Math.min(ctx.level, 8) * 16 },
3323
+ onKeyDown: (e) => {
3324
+ if (e.key === "Escape") ctx.close();
3325
+ if (e.key === "Enter" && e.target.dataset.submitOnEnter) {
3326
+ e.preventDefault();
3327
+ void submit();
3328
+ }
3329
+ },
3330
+ children: [
3331
+ /* @__PURE__ */ jsxs("div", { className: "grid gap-3 sm:grid-cols-[8rem_1fr]", children: [
3332
+ /* @__PURE__ */ jsxs("label", { className: "space-y-1 text-xs font-medium text-muted-foreground", children: [
3333
+ t("financial.chartTree.field.code"),
3334
+ /* @__PURE__ */ jsx(Input, { "data-submit-on-enter": "1", value: draft.code, onChange: (e) => update({ code: e.target.value }), required: true })
3306
3335
  ] }),
3307
- /* @__PURE__ */ jsxs("div", { className: "grid gap-3 sm:grid-cols-3", children: [
3308
- /* @__PURE__ */ jsxs("label", { className: "space-y-1 text-xs font-medium text-muted-foreground", children: [
3309
- t("financial.chartTree.field.structure"),
3310
- /* @__PURE__ */ jsxs(Select, { value: draft.nodeType, onValueChange: (v) => update({ nodeType: v }), children: [
3311
- /* @__PURE__ */ jsx(SelectTrigger, { className: "px-2 font-normal text-foreground", children: /* @__PURE__ */ jsx(SelectValue, {}) }),
3312
- /* @__PURE__ */ jsxs(SelectContent, { children: [
3313
- /* @__PURE__ */ jsx(SelectItem, { value: "leaf", children: t("financial.chartTree.leaf") }),
3314
- /* @__PURE__ */ jsx(SelectItem, { value: "group", children: t("financial.chartTree.group") })
3315
- ] })
3336
+ /* @__PURE__ */ jsxs("label", { className: "space-y-1 text-xs font-medium text-muted-foreground", children: [
3337
+ t("financial.chartTree.field.name"),
3338
+ /* @__PURE__ */ jsx(Input, { "data-submit-on-enter": "1", autoFocus: true, value: draft.name, onChange: (e) => update({ name: e.target.value }), required: true })
3339
+ ] })
3340
+ ] }),
3341
+ /* @__PURE__ */ jsxs("div", { className: "grid gap-3 sm:grid-cols-3", children: [
3342
+ /* @__PURE__ */ jsxs("label", { className: "space-y-1 text-xs font-medium text-muted-foreground", children: [
3343
+ t("financial.chartTree.field.structure"),
3344
+ /* @__PURE__ */ jsxs(Select, { value: draft.nodeType, onValueChange: (v) => update({ nodeType: v }), children: [
3345
+ /* @__PURE__ */ jsx(SelectTrigger, { className: "px-2 font-normal text-foreground", children: /* @__PURE__ */ jsx(SelectValue, {}) }),
3346
+ /* @__PURE__ */ jsxs(SelectContent, { children: [
3347
+ /* @__PURE__ */ jsx(SelectItem, { value: "leaf", children: t("financial.chartTree.leaf") }),
3348
+ /* @__PURE__ */ jsx(SelectItem, { value: "group", children: t("financial.chartTree.group") })
3316
3349
  ] })
3317
- ] }),
3318
- /* @__PURE__ */ jsxs("label", { className: "space-y-1 text-xs font-medium text-muted-foreground", children: [
3319
- t("financial.chartTree.field.nature"),
3320
- /* @__PURE__ */ jsxs(
3321
- Select,
3322
- {
3323
- value: draft.accountType || NO_NATURE,
3324
- onValueChange: (v) => update({ accountType: v === NO_NATURE ? "" : v }),
3325
- children: [
3326
- /* @__PURE__ */ jsx(SelectTrigger, { className: "px-2 font-normal text-foreground", children: /* @__PURE__ */ jsx(SelectValue, {}) }),
3327
- /* @__PURE__ */ jsxs(SelectContent, { children: [
3328
- /* @__PURE__ */ jsx(SelectItem, { value: NO_NATURE, children: t("financial.chartTree.nature.none") }),
3329
- NATURES.map((n) => /* @__PURE__ */ jsx(SelectItem, { value: n, children: t(`financial.chartTree.nature.${n}`) }, n))
3330
- ] })
3331
- ]
3332
- }
3333
- )
3334
- ] }),
3335
- /* @__PURE__ */ jsxs("div", { className: "space-y-1 text-xs font-medium text-muted-foreground", children: [
3336
- t("financial.chartTree.field.parent"),
3337
- /* @__PURE__ */ jsx(
3338
- SearchSelect,
3339
- {
3340
- value: draft.parentId ?? void 0,
3341
- displayValue: parent ? accountLabel(parent) : void 0,
3342
- onChange: (id) => update({ parentId: id || null }),
3343
- onSearch: (q) => parentOptions(q, selfId),
3344
- minChars: 0,
3345
- placeholder: t("financial.chartTree.rootLevel"),
3346
- noResultsLabel: t("financial.chartTree.noGroups"),
3347
- searchingLabel: t("financial.chartTree.searching"),
3348
- clearLabel: t("financial.chartTree.rootLevel")
3349
- }
3350
- )
3351
3350
  ] })
3352
3351
  ] }),
3353
- /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap justify-end gap-2", children: [
3354
- /* @__PURE__ */ jsx(Button, { type: "button", variant: "ghost", size: "sm", onClick: () => setEditing(null), disabled: busy, children: t("financial.chartTree.cancel") }),
3355
- /* @__PURE__ */ jsx(Button, { type: "button", size: "sm", disabled: busy, onClick: () => void submit(), children: busy ? t("financial.chartTree.saving") : t("financial.chartTree.save") })
3356
- ] })
3357
- ]
3358
- }
3359
- )
3360
- );
3361
- }
3362
- function renderNode(id, level) {
3363
- const node = tree.byId.get(id);
3364
- const kids = childIds(tree, id).filter((c) => !search || search.visible.has(c));
3365
- const group = isGroupNode(tree, node);
3366
- const open = search ? true : expanded.has(id);
3367
- const isEditingThis = editing?.mode === "edit" && editing.id === id;
3368
- const creatingHere = editing?.mode === "create" && editing.parentId === id;
3369
- const isMatch = search?.matches.has(id);
3370
- const hasAnyChildren = childIds(fullTree, id).length > 0;
3371
- const FolderIcon = open ? FolderOpen : Folder;
3372
- return /* @__PURE__ */ jsxs("li", { role: "treeitem", "aria-level": level + 1, "aria-expanded": group ? open : void 0, children: [
3373
- isEditingThis && editing ? renderForm(editing.draft, level, id) : /* @__PURE__ */ jsxs(
3374
- "div",
3375
- {
3376
- className: "group/row flex min-h-10 items-center gap-2 rounded-md px-2 py-1 hover:bg-muted/60 " + (node.isActive ? "" : "opacity-60"),
3377
- style: { paddingLeft: 8 + Math.min(level, 8) * 16 },
3378
- children: [
3379
- /* @__PURE__ */ jsx(
3380
- Button,
3381
- {
3382
- variant: "bare",
3383
- size: "bare",
3384
- type: "button",
3385
- className: "flex h-6 w-6 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-muted " + (kids.length ? "" : "invisible"),
3386
- onClick: () => toggle(id),
3387
- "aria-label": open ? t("financial.chartTree.collapse") : t("financial.chartTree.expand"),
3388
- disabled: !!search,
3389
- children: /* @__PURE__ */ jsx(ChevronRight, { className: "h-4 w-4 transition-transform " + (open ? "rotate-90" : "") })
3390
- }
3391
- ),
3392
- group ? /* @__PURE__ */ jsx(FolderIcon, { className: "h-4 w-4 shrink-0 text-muted-foreground" }) : /* @__PURE__ */ jsx(FileText, { className: "h-4 w-4 shrink-0 text-muted-foreground" }),
3393
- /* @__PURE__ */ jsx("span", { className: "shrink-0 font-mono text-xs tabular-nums text-muted-foreground", children: node.code }),
3394
- /* @__PURE__ */ jsx("span", { className: "min-w-0 flex-1 truncate text-sm " + (group ? "font-semibold" : "") + (isMatch ? " text-primary" : ""), children: node.name }),
3395
- /* @__PURE__ */ jsxs("span", { className: "hidden shrink-0 items-center gap-1 sm:flex", children: [
3396
- node.accountType && /* @__PURE__ */ jsx(Badge, { variant: NATURE_VARIANT[node.accountType] ?? "default", dot: false, children: t(`financial.chartTree.nature.${node.accountType}`) }),
3397
- !node.isActive && /* @__PURE__ */ jsx(Badge, { variant: "outline", children: t("financial.chartTree.inactive") })
3352
+ /* @__PURE__ */ jsxs("label", { className: "space-y-1 text-xs font-medium text-muted-foreground", children: [
3353
+ t("financial.chartTree.field.nature"),
3354
+ /* @__PURE__ */ jsxs(
3355
+ Select,
3356
+ {
3357
+ value: draft.accountType || NO_NATURE,
3358
+ onValueChange: (v) => update({ accountType: v === NO_NATURE ? "" : v }),
3359
+ children: [
3360
+ /* @__PURE__ */ jsx(SelectTrigger, { className: "px-2 font-normal text-foreground", children: /* @__PURE__ */ jsx(SelectValue, {}) }),
3361
+ /* @__PURE__ */ jsxs(SelectContent, { children: [
3362
+ /* @__PURE__ */ jsx(SelectItem, { value: NO_NATURE, children: t("financial.chartTree.nature.none") }),
3363
+ NATURES.map((n) => /* @__PURE__ */ jsx(SelectItem, { value: n, children: t(`financial.chartTree.nature.${n}`) }, n))
3364
+ ] })
3365
+ ]
3366
+ }
3367
+ )
3398
3368
  ] }),
3399
- confirmDelete === id ? /* @__PURE__ */ jsxs("span", { className: "flex shrink-0 items-center gap-1", children: [
3400
- /* @__PURE__ */ jsx("span", { className: "hidden text-xs text-muted-foreground md:inline", children: t("financial.chartTree.confirmDelete") }),
3401
- /* @__PURE__ */ jsx(Button, { size: "sm", variant: "destructive", disabled: busy, onClick: () => void remove(node), children: t("financial.chartTree.delete") }),
3402
- /* @__PURE__ */ jsx(Button, { size: "sm", variant: "ghost", disabled: busy, onClick: () => setConfirmDelete(null), children: t("financial.chartTree.cancel") })
3403
- ] }) : /* @__PURE__ */ jsxs("span", { className: "flex shrink-0 items-center justify-end gap-0.5 sm:w-32 sm:opacity-0 sm:group-hover/row:opacity-100 sm:focus-within:opacity-100", children: [
3404
- canCreate && group && node.isActive && /* @__PURE__ */ jsx(Button, { size: "icon", variant: "ghost", title: t("financial.chartTree.addChild"), "aria-label": t("financial.chartTree.addChild"), onClick: () => startCreate(id), disabled: busy, children: /* @__PURE__ */ jsx(Plus, { className: "h-4 w-4" }) }),
3405
- canEdit && /* @__PURE__ */ jsx(Button, { size: "icon", variant: "ghost", title: t("financial.chartTree.edit"), "aria-label": t("financial.chartTree.edit"), onClick: () => startEdit(node), disabled: busy, children: /* @__PURE__ */ jsx(Pencil, { className: "h-4 w-4" }) }),
3406
- canEdit && !hasAnyChildren && (node.isActive ? /* @__PURE__ */ jsx(Button, { size: "icon", variant: "ghost", title: t("financial.chartTree.deactivate"), "aria-label": t("financial.chartTree.deactivate"), onClick: () => void setActive(node, false), disabled: busy, children: /* @__PURE__ */ jsx(Ban, { className: "h-4 w-4" }) }) : null),
3407
- canEdit && !node.isActive && /* @__PURE__ */ jsx(Button, { size: "icon", variant: "ghost", title: t("financial.chartTree.reactivate"), "aria-label": t("financial.chartTree.reactivate"), onClick: () => void setActive(node, true), disabled: busy, children: /* @__PURE__ */ jsx(RotateCcw, { className: "h-4 w-4" }) }),
3408
- canDelete && !hasAnyChildren && /* @__PURE__ */ jsx(Button, { size: "icon", variant: "ghost", title: t("financial.chartTree.delete"), "aria-label": t("financial.chartTree.delete"), onClick: () => {
3409
- setEditing(null);
3410
- setConfirmDelete(id);
3411
- }, disabled: busy, children: /* @__PURE__ */ jsx(Trash2, { className: "h-4 w-4" }) })
3369
+ /* @__PURE__ */ jsxs("div", { className: "space-y-1 text-xs font-medium text-muted-foreground", children: [
3370
+ t("financial.chartTree.field.parent"),
3371
+ /* @__PURE__ */ jsx(
3372
+ SearchSelect,
3373
+ {
3374
+ value: draft.parentId ?? void 0,
3375
+ displayValue: parent ? accountLabel(parent) : void 0,
3376
+ onChange: (id) => update({ parentId: id || null }),
3377
+ onSearch: parentOptions,
3378
+ minChars: 0,
3379
+ placeholder: t("financial.chartTree.rootLevel"),
3380
+ noResultsLabel: t("financial.chartTree.noGroups"),
3381
+ searchingLabel: t("financial.chartTree.searching"),
3382
+ clearLabel: t("financial.chartTree.rootLevel")
3383
+ }
3384
+ )
3412
3385
  ] })
3413
- ]
3414
- }
3415
- ),
3416
- open && (kids.length > 0 || creatingHere) && /* @__PURE__ */ jsxs("ul", { role: "group", className: "space-y-0.5", children: [
3417
- creatingHere && editing && /* @__PURE__ */ jsx("li", { children: renderForm(editing.draft, level + 1) }),
3418
- kids.map((c) => renderNode(c, level + 1))
3419
- ] })
3420
- ] }, id);
3421
- }
3422
- const hasOther = (nodes ?? []).some((n) => sideOf(n.accountType) === "other");
3423
- return /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
3424
- /* @__PURE__ */ jsx(
3425
- SegmentedControl,
3426
- {
3427
- value: side,
3428
- onChange: (v) => {
3429
- setSide(v);
3430
- setEditing(null);
3431
- },
3432
- options: [
3433
- { value: "in", label: tl("Income (in)", "Receitas (entradas)") },
3434
- { value: "out", label: tl("Expenses (out)", "Despesas (sa\xEDdas)") },
3435
- ...hasOther ? [{ value: "other", label: tl("Balance", "Patrimoniais") }] : []
3386
+ ] }),
3387
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap justify-end gap-2", children: [
3388
+ /* @__PURE__ */ jsx(Button, { type: "button", variant: "ghost", size: "sm", onClick: ctx.close, disabled: busy, children: t("financial.chartTree.cancel") }),
3389
+ /* @__PURE__ */ jsx(Button, { type: "button", size: "sm", disabled: busy, onClick: () => void submit(), children: busy ? t("financial.chartTree.saving") : t("financial.chartTree.save") })
3390
+ ] })
3436
3391
  ]
3437
3392
  }
3438
- ),
3439
- /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [
3440
- /* @__PURE__ */ jsxs("div", { className: "relative min-w-[12rem] flex-1", children: [
3441
- /* @__PURE__ */ jsx(Search, { className: "pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" }),
3442
- /* @__PURE__ */ jsx(
3443
- Input,
3444
- {
3445
- value: query,
3446
- onChange: (e) => setQuery(e.target.value),
3447
- placeholder: t("financial.chartTree.searchPlaceholder"),
3448
- className: "pl-8 pr-8",
3449
- "aria-label": t("financial.chartTree.searchPlaceholder")
3450
- }
3451
- ),
3452
- query && /* @__PURE__ */ jsx(
3453
- Button,
3454
- {
3455
- variant: "bare",
3456
- size: "bare",
3457
- type: "button",
3458
- className: "absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",
3459
- onClick: () => setQuery(""),
3460
- "aria-label": t("financial.chartTree.clearSearch"),
3461
- children: /* @__PURE__ */ jsx(X, { className: "h-4 w-4" })
3462
- }
3463
- )
3464
- ] }),
3465
- /* @__PURE__ */ jsxs(Button, { variant: "outline", size: "sm", onClick: () => setExpanded(new Set(groupIds)), disabled: !!search, title: t("financial.chartTree.expandAll"), "aria-label": t("financial.chartTree.expandAll"), children: [
3466
- /* @__PURE__ */ jsx(ChevronsUpDown, { className: "h-4 w-4" }),
3467
- /* @__PURE__ */ jsx("span", { className: "hidden sm:inline", children: t("financial.chartTree.expandAll") })
3468
- ] }),
3469
- /* @__PURE__ */ jsxs(Button, { variant: "outline", size: "sm", onClick: () => setExpanded(/* @__PURE__ */ new Set()), disabled: !!search, title: t("financial.chartTree.collapseAll"), "aria-label": t("financial.chartTree.collapseAll"), children: [
3470
- /* @__PURE__ */ jsx(ChevronsDownUp, { className: "h-4 w-4" }),
3471
- /* @__PURE__ */ jsx("span", { className: "hidden sm:inline", children: t("financial.chartTree.collapseAll") })
3472
- ] })
3473
- ] }),
3474
- canCreate && (embedded ? /* @__PURE__ */ jsxs(Button, { size: "sm", onClick: () => startCreate(null), disabled: busy, children: [
3475
- /* @__PURE__ */ jsx(Plus, { className: "h-4 w-4" }),
3476
- t("financial.chartTree.addRoot")
3477
- ] }) : /* @__PURE__ */ jsx(PageHeaderActions, { children: /* @__PURE__ */ jsxs(Button, { size: "sm", onClick: () => startCreate(null), disabled: busy, children: [
3478
- /* @__PURE__ */ jsx(Plus, { className: "h-4 w-4" }),
3479
- t("financial.chartTree.addRoot")
3480
- ] }) })),
3481
- /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center justify-between gap-2 text-xs text-muted-foreground", children: [
3482
- /* @__PURE__ */ jsx("span", { children: search ? t(search.matches.size === 1 ? "financial.chartTree.matchesOne" : "financial.chartTree.matches", { count: search.matches.size }) : t(tree.byId.size === 1 ? "financial.chartTree.countOne" : "financial.chartTree.count", { count: tree.byId.size }) }),
3483
- inactiveCount > 0 && /* @__PURE__ */ jsxs("label", { className: "inline-flex cursor-pointer items-center gap-1.5", children: [
3484
- /* @__PURE__ */ jsx(Checkbox, { checked: showInactive, onChange: setShowInactive }),
3485
- t("financial.chartTree.showInactive", { count: inactiveCount })
3486
- ] })
3487
- ] }),
3488
- loadError && /* @__PURE__ */ jsxs("p", { className: "rounded-md border border-destructive/40 bg-destructive/5 p-3 text-sm text-destructive", children: [
3489
- t("financial.chartTree.error.load"),
3490
- " ",
3491
- loadError
3492
- ] }),
3493
- editing?.mode === "create" && editing.parentId === null && renderForm(editing.draft, 0),
3494
- roots.length === 0 && !(editing?.mode === "create" && editing.parentId === null) ? /* @__PURE__ */ jsx("div", { className: "rounded-md border border-dashed border-border p-8 text-center text-sm text-muted-foreground", children: search ? t("financial.chartTree.noMatches") : t("financial.chartTree.empty") }) : /* @__PURE__ */ jsx("ul", { role: "tree", "aria-label": t("registry.chart-of-accounts"), className: "space-y-0.5", children: roots.map((id) => renderNode(id, 0)) })
3495
- ] });
3393
+ )
3394
+ );
3496
3395
  }
3497
3396
 
3498
3397
  // src/data/registries.ts
@@ -3562,7 +3461,12 @@ var chartOfAccountsEntity = {
3562
3461
  label: tl("Parent", "Conta pai"),
3563
3462
  type: "relation",
3564
3463
  showInTable: false,
3565
- relation: { table: T.chartOfAccounts, labelFields: ["code", "name"], filter: { node_type: "group" } }
3464
+ relation: {
3465
+ table: T.chartOfAccounts,
3466
+ labelFields: ["code", "name"],
3467
+ filter: { node_type: "group" },
3468
+ tree: { parentField: "parent_id", codeField: "code", groupField: "node_type", groupValue: "group" }
3469
+ }
3566
3470
  },
3567
3471
  ...recordRailFields({ tagsTable: "plg_financial_chart_of_accounts", activeLabel: "Ativo", unit: true })
3568
3472
  ],
@@ -3584,7 +3488,7 @@ var chartOfAccountsSeed = [
3584
3488
  { id: "coa-4.2", code: "4.2", name: "Utilities", nodeType: "leaf", accountType: "expense", parentId: "coa-4", isActive: true },
3585
3489
  { id: "coa-4.3", code: "4.3", name: "Payroll", nodeType: "leaf", accountType: "expense", parentId: "coa-4", isActive: true }
3586
3490
  ];
3587
- var ChartOfAccountsRegistryView = (props) => React5__default.createElement(ChartOfAccountsTree, { ...props, entity: chartOfAccountsEntity, mockData: chartOfAccountsSeed });
3491
+ var ChartOfAccountsRegistryView = (props) => React3__default.createElement(ChartOfAccountsTree, { ...props, entity: chartOfAccountsEntity, mockData: chartOfAccountsSeed });
3588
3492
  ChartOfAccountsRegistryView.displayName = "ChartOfAccountsRegistryView";
3589
3493
  var costCenterEntity = {
3590
3494
  name: "Cost Center",
@@ -3682,7 +3586,7 @@ var bankAccountEntity = {
3682
3586
  labelWhen: (v) => v.kind === "card_payable" ? "Banco emissor" : void 0,
3683
3587
  visibleWhen: (v) => hasIssuer(v.kind),
3684
3588
  group: "bank",
3685
- renderInput: ({ value, values, onChange, setValue }) => React5__default.createElement(BankPicker, {
3589
+ renderInput: ({ value, values, onChange, setValue }) => React3__default.createElement(BankPicker, {
3686
3590
  code: values.bankCode ?? "",
3687
3591
  name: value ?? "",
3688
3592
  onChange: (next) => {
@@ -4689,10 +4593,10 @@ function CashSessionControl({ config, provider, store: store6 }) {
4689
4593
  const fetchCashSessions = useStore(store6, (s) => s.fetchCashSessions);
4690
4594
  const open = useStore(store6, (s) => s.cashSessionModalOpen);
4691
4595
  const setOpen = useStore(store6, (s) => s.setCashSessionModalOpen);
4692
- React5__default.useEffect(() => {
4596
+ React3__default.useEffect(() => {
4693
4597
  void fetchCashSessions?.();
4694
4598
  }, [fetchCashSessions]);
4695
- React5__default.useEffect(() => {
4599
+ React3__default.useEffect(() => {
4696
4600
  if (!open) return;
4697
4601
  const close = () => setOpen(false);
4698
4602
  return onAppPathChange(close);
@@ -5262,8 +5166,8 @@ var UPCOMING = [
5262
5166
  function CardMachinesSettings() {
5263
5167
  const { connectors } = useConnectors({ hostPluginId: "financial", includeGrants: false });
5264
5168
  const panelAvailable = useConnectorsPanelAvailable();
5265
- const [selected, setSelected] = React5.useState(null);
5266
- const acquirers = React5.useMemo(
5169
+ const [selected, setSelected] = React3.useState(null);
5170
+ const acquirers = React3.useMemo(
5267
5171
  () => (connectors ?? []).filter((c) => ACQUIRERS.includes(c.slug)).sort((a, b) => ACQUIRERS.indexOf(a.slug) - ACQUIRERS.indexOf(b.slug)),
5268
5172
  [connectors]
5269
5173
  );
@@ -5384,7 +5288,7 @@ function createFinancialSettingsPlugin(options) {
5384
5288
  ...financialRegistries.filter((r) => RECEIVING_REGISTRIES.includes(r.id)),
5385
5289
  ...options?.extraRegistries ?? []
5386
5290
  ];
5387
- const SettingsTab = () => React5__default.createElement(PluginSettingsPanel, {
5291
+ const SettingsTab = () => React3__default.createElement(PluginSettingsPanel, {
5388
5292
  title: "Pagamentos",
5389
5293
  registries,
5390
5294
  hostPluginId: "financial",
@@ -5440,11 +5344,11 @@ function createFinancialPlugin(options) {
5440
5344
  const settingsRegistries = registries.filter((r) => r.id !== "bank-accounts" && r.id !== "commission-rules");
5441
5345
  const AccountsRegistryPage = createCrudPage(financialAccountEntity, { feature: "financial" });
5442
5346
  AccountsRegistryPage.displayName = "FinancialAccountsRegistryPage";
5443
- const PersonStatementBound = (props) => React5__default.createElement(PersonStatementWidget, { person: props.item, provider, config });
5347
+ const PersonStatementBound = (props) => React3__default.createElement(PersonStatementWidget, { person: props.item, provider, config });
5444
5348
  PersonStatementBound.displayName = "FinancialPersonStatement";
5445
- const SupplierFinancialSettingsBound = (props) => React5__default.createElement(SupplierFinancialSettings, { person: props.item, provider });
5349
+ const SupplierFinancialSettingsBound = (props) => React3__default.createElement(SupplierFinancialSettings, { person: props.item, provider });
5446
5350
  SupplierFinancialSettingsBound.displayName = "FinancialSupplierSettings";
5447
- const PageComponent = () => React5__default.createElement(FinancialPage, { config, provider, store: store6, registries });
5351
+ const PageComponent = () => React3__default.createElement(FinancialPage, { config, provider, store: store6, registries });
5448
5352
  const AgentMount = lazyComponent(() => import('./payable-agent-TCKHUAQG.js').then((m) => m.createFinancialAgentMount({ config, provider })));
5449
5353
  return {
5450
5354
  id: "financial",
@@ -5502,7 +5406,7 @@ function createFinancialPlugin(options) {
5502
5406
  // tem — lá é um ícone no cabeçalho, de qualquer tela.
5503
5407
  headerControls: config.modules.cashRegisters ? [{
5504
5408
  id: "financial.cash-session",
5505
- component: (() => React5__default.createElement(CashSessionHeaderControl, { config, provider, store: store6 })),
5409
+ component: (() => React3__default.createElement(CashSessionHeaderControl, { config, provider, store: store6 })),
5506
5410
  order: 90,
5507
5411
  permission: { feature: "financial", action: "read" }
5508
5412
  }] : [],
@@ -5752,9 +5656,9 @@ function createFinancialPlugin(options) {
5752
5656
  { id: "card-brands", label: "Card brands", icon: "CreditCard" }
5753
5657
  ],
5754
5658
  component: (() => {
5755
- const FinancialSettingsTab = () => React5__default.createElement(PluginSettingsPanel, {
5659
+ const FinancialSettingsTab = () => React3__default.createElement(PluginSettingsPanel, {
5756
5660
  title: "Financial Settings",
5757
- generalSettings: React5__default.createElement(FinancialGeneralSettings, { config }),
5661
+ generalSettings: React3__default.createElement(FinancialGeneralSettings, { config }),
5758
5662
  registries: settingsRegistries,
5759
5663
  hostPluginId: "financial",
5760
5664
  routeBase: "/settings/financial"
@@ -5779,7 +5683,7 @@ function createFinancialPlugin(options) {
5779
5683
  icon: "HandCoins",
5780
5684
  group: "Financeiro",
5781
5685
  component: (() => {
5782
- const CommissionRulesTab = () => React5__default.createElement(CommissionRulesView, { provider });
5686
+ const CommissionRulesTab = () => React3__default.createElement(CommissionRulesView, { provider });
5783
5687
  CommissionRulesTab.displayName = "CommissionRulesTab";
5784
5688
  return CommissionRulesTab;
5785
5689
  })(),
@@ -5815,11 +5719,11 @@ function createFinancialPlugin(options) {
5815
5719
  locales: financialLocales
5816
5720
  };
5817
5721
  }
5818
- var FinancialPage = React5__default.lazy(() => import('./FinancialPage-LCKLEAM3.js').then((m) => ({ default: m.FinancialPage })));
5722
+ var FinancialPage = React3__default.lazy(() => import('./FinancialPage-S2EBQVIA.js').then((m) => ({ default: m.FinancialPage })));
5819
5723
  var FinancialGeneralSettings = lazyComponent(() => import('./FinancialGeneralSettings-WXJOCJPZ.js').then((m) => m.FinancialGeneralSettings));
5820
5724
  var CommissionRulesView = lazyComponent(() => import('./CommissionRulesView-2RW4ZCDT.js').then((m) => m.CommissionRulesView));
5821
- var PersonStatementWidget = lazyComponent(() => import('./PersonStatementWidget-ULXXXYZ4.js').then((m) => m.PersonStatementWidget));
5822
- var SupplierFinancialSettings = lazyComponent(() => import('./PersonStatementWidget-ULXXXYZ4.js').then((m) => m.SupplierFinancialSettings));
5725
+ var PersonStatementWidget = lazyComponent(() => import('./PersonStatementWidget-JD6FHD4G.js').then((m) => m.PersonStatementWidget));
5726
+ var SupplierFinancialSettings = lazyComponent(() => import('./PersonStatementWidget-JD6FHD4G.js').then((m) => m.SupplierFinancialSettings));
5823
5727
  var ProductPriceTablesTabView = lazyComponent(() => import('./ProductPriceTablesTab-FKYRGSBI.js').then((m) => m.ProductPriceTablesTab));
5824
5728
  function priceTablesProductTab(options = {}) {
5825
5729
  return {