@adminide-stack/yantra-mobile 12.0.98-alpha.0 → 12.0.99-alpha.0

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.
Files changed (173) hide show
  1. package/lib/bridge/handlers/SurfaceHostBridgeHandler.js +9 -2
  2. package/lib/bridge/handlers/SurfaceHostBridgeHandler.js.map +1 -1
  3. package/lib/compute.js +109 -1
  4. package/lib/compute.js.map +1 -1
  5. package/lib/config/env-config.js +11 -1
  6. package/lib/config/env-config.js.map +1 -1
  7. package/lib/features/agent-chat/NativeAgentChat.js.map +1 -1
  8. package/lib/features/apps/AppsCatalog.js +10 -0
  9. package/lib/features/apps/AppsCatalog.js.map +1 -1
  10. package/lib/features/apps/appArt.js +2 -1
  11. package/lib/features/apps/appArt.js.map +1 -1
  12. package/lib/features/apps/mobileAppCatalog.js +10 -0
  13. package/lib/features/apps/mobileAppCatalog.js.map +1 -1
  14. package/lib/features/apps/nativeAppHandoff.js +2 -1
  15. package/lib/features/apps/nativeAppHandoff.js.map +1 -1
  16. package/lib/features/apps/resolveSurfaceUrl.js +1 -2
  17. package/lib/features/apps/resolveSurfaceUrl.js.map +1 -1
  18. package/lib/features/attachments/useImageAttachments.js +8 -5
  19. package/lib/features/attachments/useImageAttachments.js.map +1 -1
  20. package/lib/features/chat/AssistantMarkdown.js +7 -6
  21. package/lib/features/chat/AssistantMarkdown.js.map +1 -1
  22. package/lib/features/chat/ChatTranscript.js +12 -2
  23. package/lib/features/chat/ChatTranscript.js.map +1 -1
  24. package/lib/features/devices/bleTransport.js +141 -0
  25. package/lib/features/devices/bleTransport.js.map +1 -0
  26. package/lib/features/devices/catalog.js +59 -0
  27. package/lib/features/devices/catalog.js.map +1 -0
  28. package/lib/features/devices/deviceStore.js +292 -0
  29. package/lib/features/devices/deviceStore.js.map +1 -0
  30. package/lib/features/devices/devices.js +68 -0
  31. package/lib/features/devices/devices.js.map +1 -0
  32. package/lib/features/devices/drivers.js +378 -0
  33. package/lib/features/devices/drivers.js.map +1 -0
  34. package/lib/features/devices/gatt/bytes.js +103 -0
  35. package/lib/features/devices/gatt/bytes.js.map +1 -0
  36. package/lib/features/devices/gatt/dateTime.js +23 -0
  37. package/lib/features/devices/gatt/dateTime.js.map +1 -0
  38. package/lib/features/devices/gatt/measurements.js +210 -0
  39. package/lib/features/devices/gatt/measurements.js.map +1 -0
  40. package/lib/features/devices/gatt/userData.js +57 -0
  41. package/lib/features/devices/gatt/userData.js.map +1 -0
  42. package/lib/features/devices/gatt/uuids.js +41 -0
  43. package/lib/features/devices/gatt/uuids.js.map +1 -0
  44. package/lib/features/devices/link.js +8 -0
  45. package/lib/features/devices/link.js.map +1 -0
  46. package/lib/features/devices/readings.js +158 -0
  47. package/lib/features/devices/readings.js.map +1 -0
  48. package/lib/features/devices/session.js +334 -0
  49. package/lib/features/devices/session.js.map +1 -0
  50. package/lib/features/expenses/ExpensesAgentChatPane.js +50 -0
  51. package/lib/features/expenses/ExpensesAgentChatPane.js.map +1 -0
  52. package/lib/features/expenses/ExpensesExperience.js +646 -0
  53. package/lib/features/expenses/ExpensesExperience.js.map +1 -0
  54. package/lib/features/expenses/claimFilters.js +94 -0
  55. package/lib/features/expenses/claimFilters.js.map +1 -0
  56. package/lib/features/expenses/components/AccountsPanel.js +464 -0
  57. package/lib/features/expenses/components/AccountsPanel.js.map +1 -0
  58. package/lib/features/expenses/components/BudgetsPanel.js +320 -0
  59. package/lib/features/expenses/components/BudgetsPanel.js.map +1 -0
  60. package/lib/features/expenses/components/CategoriesSheet.js +181 -0
  61. package/lib/features/expenses/components/CategoriesSheet.js.map +1 -0
  62. package/lib/features/expenses/components/ClaimDetail.js +309 -0
  63. package/lib/features/expenses/components/ClaimDetail.js.map +1 -0
  64. package/lib/features/expenses/components/ClaimForm.js +375 -0
  65. package/lib/features/expenses/components/ClaimForm.js.map +1 -0
  66. package/lib/features/expenses/components/ClaimRow.js +77 -0
  67. package/lib/features/expenses/components/ClaimRow.js.map +1 -0
  68. package/lib/features/expenses/components/ClaimsPanel.js +388 -0
  69. package/lib/features/expenses/components/ClaimsPanel.js.map +1 -0
  70. package/lib/features/expenses/components/DateSheet.js +214 -0
  71. package/lib/features/expenses/components/DateSheet.js.map +1 -0
  72. package/lib/features/expenses/components/ExpensesStates.js +274 -0
  73. package/lib/features/expenses/components/ExpensesStates.js.map +1 -0
  74. package/lib/features/expenses/components/ExpensesTabBar.js +83 -0
  75. package/lib/features/expenses/components/ExpensesTabBar.js.map +1 -0
  76. package/lib/features/expenses/components/FiltersSheet.js +137 -0
  77. package/lib/features/expenses/components/FiltersSheet.js.map +1 -0
  78. package/lib/features/expenses/components/InsightsPanel.js +362 -0
  79. package/lib/features/expenses/components/InsightsPanel.js.map +1 -0
  80. package/lib/features/expenses/components/RecurringPanel.js +370 -0
  81. package/lib/features/expenses/components/RecurringPanel.js.map +1 -0
  82. package/lib/features/expenses/components/Sheets.js +220 -0
  83. package/lib/features/expenses/components/Sheets.js.map +1 -0
  84. package/lib/features/expenses/components/ui.js +496 -0
  85. package/lib/features/expenses/components/ui.js.map +1 -0
  86. package/lib/features/expenses/expensesClient.js +398 -0
  87. package/lib/features/expenses/expensesClient.js.map +1 -0
  88. package/lib/features/expenses/expensesContext.js +30 -0
  89. package/lib/features/expenses/expensesContext.js.map +1 -0
  90. package/lib/features/expenses/expensesEndpoint.js +12 -0
  91. package/lib/features/expenses/expensesEndpoint.js.map +1 -0
  92. package/lib/features/expenses/expensesFormat.js +360 -0
  93. package/lib/features/expenses/expensesFormat.js.map +1 -0
  94. package/lib/features/expenses/expensesOperations.js +136 -0
  95. package/lib/features/expenses/expensesOperations.js.map +1 -0
  96. package/lib/features/expenses/expensesPrompts.js +81 -0
  97. package/lib/features/expenses/expensesPrompts.js.map +1 -0
  98. package/lib/features/expenses/expensesTheme.js +107 -0
  99. package/lib/features/expenses/expensesTheme.js.map +1 -0
  100. package/lib/features/expenses/nativeExpensesRegistry.js +15 -0
  101. package/lib/features/expenses/nativeExpensesRegistry.js.map +1 -0
  102. package/lib/features/expenses/receiptScan.js +242 -0
  103. package/lib/features/expenses/receiptScan.js.map +1 -0
  104. package/lib/features/expenses/useClaimsList.js +159 -0
  105. package/lib/features/expenses/useClaimsList.js.map +1 -0
  106. package/lib/features/expenses/useExpensesResource.js +68 -0
  107. package/lib/features/expenses/useExpensesResource.js.map +1 -0
  108. package/lib/features/health/HealthSyncRunner.js +24 -10
  109. package/lib/features/health/HealthSyncRunner.js.map +1 -1
  110. package/lib/features/health/buildDays.js +52 -5
  111. package/lib/features/health/buildDays.js.map +1 -1
  112. package/lib/features/health/fitnessClient.js +30 -3
  113. package/lib/features/health/fitnessClient.js.map +1 -1
  114. package/lib/features/health/healthConnectMapping.js +65 -2
  115. package/lib/features/health/healthConnectMapping.js.map +1 -1
  116. package/lib/features/health/healthConnectReader.js +23 -5
  117. package/lib/features/health/healthConnectReader.js.map +1 -1
  118. package/lib/features/health/healthConnectWriter.js +49 -0
  119. package/lib/features/health/healthConnectWriter.js.map +1 -0
  120. package/lib/features/health/healthkitMapping.js +58 -2
  121. package/lib/features/health/healthkitMapping.js.map +1 -1
  122. package/lib/features/health/healthkitReader.js +29 -7
  123. package/lib/features/health/healthkitReader.js.map +1 -1
  124. package/lib/features/health/healthkitWriter.js +55 -0
  125. package/lib/features/health/healthkitWriter.js.map +1 -0
  126. package/lib/features/health/model.js +8 -1
  127. package/lib/features/health/model.js.map +1 -1
  128. package/lib/features/health/ownSource.js +6 -0
  129. package/lib/features/health/ownSource.js.map +1 -0
  130. package/lib/features/health/reader.js +21 -0
  131. package/lib/features/health/reader.js.map +1 -1
  132. package/lib/features/health/types.js +15 -3
  133. package/lib/features/health/types.js.map +1 -1
  134. package/lib/features/health/writeMapping.js +218 -0
  135. package/lib/features/health/writeMapping.js.map +1 -0
  136. package/lib/features/links/ChatLinkOpenerProvider.js +56 -0
  137. package/lib/features/links/ChatLinkOpenerProvider.js.map +1 -0
  138. package/lib/features/links/chatLinkOpener.js +8 -0
  139. package/lib/features/links/chatLinkOpener.js.map +1 -0
  140. package/lib/features/links/openInApp.js +25 -0
  141. package/lib/features/links/openInApp.js.map +1 -0
  142. package/lib/features/messaging/ChatComponents.js +25 -6
  143. package/lib/features/messaging/ChatComponents.js.map +1 -1
  144. package/lib/features/messaging/LinkPreviewCard.js +103 -0
  145. package/lib/features/messaging/LinkPreviewCard.js.map +1 -0
  146. package/lib/features/messaging/NativeChatExperience.js +20 -7
  147. package/lib/features/messaging/NativeChatExperience.js.map +1 -1
  148. package/lib/features/messaging/ThreadScreen.js +4 -2
  149. package/lib/features/messaging/ThreadScreen.js.map +1 -1
  150. package/lib/features/messaging/chatLinks.js +64 -0
  151. package/lib/features/messaging/chatLinks.js.map +1 -0
  152. package/lib/features/messaging/linkPreview.js +64 -0
  153. package/lib/features/messaging/linkPreview.js.map +1 -0
  154. package/lib/index.js +1 -1
  155. package/lib/index.js.map +1 -1
  156. package/lib/routes.json +54 -0
  157. package/lib/screens/Account/index.js +39 -14
  158. package/lib/screens/Account/index.js.map +1 -1
  159. package/lib/screens/Chat/index.js +4 -3
  160. package/lib/screens/Chat/index.js.map +1 -1
  161. package/lib/screens/Devices/index.js +1055 -0
  162. package/lib/screens/Devices/index.js.map +1 -0
  163. package/lib/screens/ExpensesNative/index.js +98 -0
  164. package/lib/screens/ExpensesNative/index.js.map +1 -0
  165. package/lib/screens/ExpensesNative/useExpensesHostChat.js +63 -0
  166. package/lib/screens/ExpensesNative/useExpensesHostChat.js.map +1 -0
  167. package/lib/screens/Health/index.js +40 -7
  168. package/lib/screens/Health/index.js.map +1 -1
  169. package/lib/screens/WebBuilder/index.js +20 -0
  170. package/lib/screens/WebBuilder/index.js.map +1 -1
  171. package/lib/utils/hasNativeModule.js +9 -0
  172. package/lib/utils/hasNativeModule.js.map +1 -0
  173. package/package.json +4 -3
@@ -0,0 +1,646 @@
1
+ import {jsxs,jsx}from'react/jsx-runtime';import {useMemo,useRef,useState,useCallback,useEffect}from'react';import {StyleSheet,Keyboard,AppState,BackHandler,View,Text,Alert}from'react-native';import {GestureHandlerRootView}from'react-native-gesture-handler';import {MaterialCommunityIcons}from'@expo/vector-icons';import {useSafeInsets}from'../canvas/withRemoteSafeArea.js';import {tokenClaims}from'../canvas/sessionIdentity.js';import {createRemoteUploadMedia,createRemoteConnectorExec}from'../canvas/videoEditor/remoteMediaClient.js';import {useAppTheme}from'../../theme/AppThemeProvider.js';import {Tap,DIM}from'../inbox/components/Tap.js';import {EMPTY_FILTERS,toServerFilter}from'./claimFilters.js';import {ExpensesAgentChatPane}from'./ExpensesAgentChatPane.js';import {createExpensesClient,expensesErrorText}from'./expensesClient.js';import {expensesContextHeader}from'./expensesContext.js';import {todayYmd,STATUS_META}from'./expensesFormat.js';import {expensesTheme}from'./expensesTheme.js';import {scanReceipt,pickReceipt,receiptScanErrorText}from'./receiptScan.js';import {useClaimsList}from'./useClaimsList.js';import {useExpensesResource}from'./useExpensesResource.js';import {AccountsPanel,AccountForm}from'./components/AccountsPanel.js';import {BudgetsPanel,BudgetForm}from'./components/BudgetsPanel.js';import {CategoriesSheet}from'./components/CategoriesSheet.js';import {ClaimDetail}from'./components/ClaimDetail.js';import {ClaimForm}from'./components/ClaimForm.js';import {ClaimsPanel}from'./components/ClaimsPanel.js';import {Toast,CenteredState}from'./components/ExpensesStates.js';import {ExpensesTabBar}from'./components/ExpensesTabBar.js';import {FiltersSheet}from'./components/FiltersSheet.js';import {InsightsPanel}from'./components/InsightsPanel.js';import {RecurringPanel,RecurringForm}from'./components/RecurringPanel.js';var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ const TOAST_MS = 2400;
21
+ const SEED_WAIT_MS = 8e3;
22
+ const STATUS_TOAST = {
23
+ SUBMITTED: "Submitted for approval",
24
+ APPROVED: "Expense approved",
25
+ REJECTED: "Expense rejected",
26
+ REIMBURSED: "Marked as paid back"
27
+ };
28
+ function confirm(title, message, action) {
29
+ return new Promise((resolve) => {
30
+ Alert.alert(title, message, [{
31
+ text: "Cancel",
32
+ style: "cancel",
33
+ onPress: () => resolve(false)
34
+ }, {
35
+ text: action,
36
+ style: "destructive",
37
+ onPress: () => resolve(true)
38
+ }]);
39
+ });
40
+ }
41
+ function ExpensesExperience({
42
+ isDark: hostIsDark,
43
+ token,
44
+ indexUrl,
45
+ graphqlUrl,
46
+ sessionError,
47
+ onRetrySession,
48
+ orgName,
49
+ onExit,
50
+ hostChat,
51
+ initialAgentSeed = null,
52
+ onOpenWeb,
53
+ focusKey = 0
54
+ }) {
55
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
56
+ const appTheme = useAppTheme();
57
+ const isDark = hostIsDark != null ? hostIsDark : appTheme.isDark;
58
+ const theme = useMemo(() => expensesTheme(isDark), [isDark]);
59
+ const insets = useSafeInsets();
60
+ const tokenRef = useRef(token != null ? token : null);
61
+ tokenRef.current = token != null ? token : null;
62
+ const hasToken = Boolean(token);
63
+ const sessionOrg = tokenClaims(token).orgName;
64
+ const org = typeof sessionOrg === "string" && sessionOrg.trim() || orgName || "";
65
+ const client = useMemo(() => hasToken && org ? createExpensesClient({
66
+ url: graphqlUrl,
67
+ orgName: org,
68
+ getToken: () => tokenRef.current
69
+ }) : null, [hasToken, org, graphqlUrl]);
70
+ const categoriesRef = useRef([]);
71
+ const scanner = useMemo(() => {
72
+ if (!hasToken || !indexUrl) return null;
73
+ const exec = (connector, action, params, options) => {
74
+ const {
75
+ current
76
+ } = tokenRef;
77
+ if (!current) return Promise.reject(new Error("Network request failed: not signed in yet"));
78
+ return createRemoteConnectorExec(current, indexUrl)(connector, action, params, options);
79
+ };
80
+ const upload = (uri) => {
81
+ const {
82
+ current
83
+ } = tokenRef;
84
+ if (!current) return Promise.reject(new Error("Network request failed: not signed in yet"));
85
+ return createRemoteUploadMedia(current, indexUrl)(uri);
86
+ };
87
+ return {
88
+ pick: (source) => pickReceipt(source),
89
+ scan: (photo, onStage) => scanReceipt(photo, categoriesRef.current, {
90
+ exec,
91
+ upload
92
+ }, onStage)
93
+ };
94
+ }, [hasToken, indexUrl]);
95
+ const [today, setToday] = useState(() => todayYmd());
96
+ const [tab, setTab] = useState("expenses");
97
+ const [visited, setVisited] = useState(() => /* @__PURE__ */ new Set(["expenses"]));
98
+ const [detail, setDetail] = useState(null);
99
+ const selectTab = useCallback((next) => {
100
+ Keyboard.dismiss();
101
+ setDetail(null);
102
+ setTab(next);
103
+ setVisited((prev) => prev.has(next) ? prev : /* @__PURE__ */ new Set([...prev, next]));
104
+ }, []);
105
+ const [filters, setFilters] = useState(EMPTY_FILTERS);
106
+ const serverFilter = useMemo(() => toServerFilter(filters, today), [filters, today]);
107
+ const claims = useClaimsList(client, serverFilter);
108
+ const categories = useExpensesResource(client, "categories", (c) => c.listCategories(true));
109
+ const accounts = useExpensesResource(client, "accounts", (c) => c.listManualAccounts(true));
110
+ const dashboard = useExpensesResource(client, "dashboard", (c) => c.dashboard());
111
+ const counts = useExpensesResource(client, "counts", async (c) => {
112
+ const [drafts, submitted, approving] = await Promise.all([c.listClaims({
113
+ status: "DRAFT",
114
+ limit: 1
115
+ }), c.listClaims({
116
+ status: "SUBMITTED",
117
+ limit: 100
118
+ }), c.listClaims({
119
+ status: "APPROVING",
120
+ limit: 100
121
+ })]);
122
+ const waiting = [...submitted.claims, ...approving.claims];
123
+ return {
124
+ drafts: drafts.totalCount,
125
+ toApprove: submitted.totalCount + approving.totalCount,
126
+ toApproveTotal: waiting.reduce((sum, claim) => sum + claim.amount, 0)
127
+ };
128
+ });
129
+ const budgets = useExpensesResource(client, "budgets", (c) => c.listBudgets(), {
130
+ enabled: visited.has("budgets")
131
+ });
132
+ const recurrings = useExpensesResource(client, "recurrings", (c) => c.listRecurrings(), {
133
+ enabled: visited.has("recurring")
134
+ });
135
+ const recurringSummary = useExpensesResource(client, "recurringSummary", (c) => c.recurringSummary(), {
136
+ enabled: visited.has("recurring")
137
+ });
138
+ const feeds = useExpensesResource(client, "feeds", (c) => c.listCardFeeds(), {
139
+ enabled: visited.has("accounts")
140
+ });
141
+ const categoryList = useMemo(() => {
142
+ var _a2;
143
+ return (_a2 = categories.data) != null ? _a2 : [];
144
+ }, [categories.data]);
145
+ categoriesRef.current = categoryList;
146
+ const activeCategories = useMemo(() => categoryList.filter((c) => c.active !== false), [categoryList]);
147
+ const accountList = useMemo(() => {
148
+ var _a2;
149
+ return (_a2 = accounts.data) != null ? _a2 : [];
150
+ }, [accounts.data]);
151
+ const currency = ((_a = dashboard.data) == null ? void 0 : _a.currency) || "USD";
152
+ const monthSpent = useMemo(() => {
153
+ var _a2, _b2;
154
+ if (!dashboard.data) return null;
155
+ return (_b2 = (_a2 = dashboard.data.monthlySpend.find((m) => m.month === today.slice(0, 7))) == null ? void 0 : _a2.amount) != null ? _b2 : 0;
156
+ }, [dashboard.data, today]);
157
+ const refreshFigures = useCallback(() => {
158
+ void counts.reload({
159
+ quiet: true
160
+ });
161
+ void dashboard.reload({
162
+ quiet: true
163
+ });
164
+ void accounts.reload({
165
+ quiet: true
166
+ });
167
+ if (visited.has("budgets")) void budgets.reload({
168
+ quiet: true
169
+ });
170
+ if (visited.has("recurring")) void recurringSummary.reload({
171
+ quiet: true
172
+ });
173
+ }, [counts, dashboard, accounts, budgets, recurringSummary, visited]);
174
+ const refreshAll = useCallback(() => {
175
+ void claims.reload({
176
+ quiet: true
177
+ });
178
+ void categories.reload({
179
+ quiet: true
180
+ });
181
+ refreshFigures();
182
+ if (visited.has("recurring")) void recurrings.reload({
183
+ quiet: true
184
+ });
185
+ if (visited.has("accounts")) void feeds.reload({
186
+ quiet: true
187
+ });
188
+ }, [claims, categories, refreshFigures, recurrings, feeds, visited]);
189
+ const refreshAllRef = useRef(refreshAll);
190
+ refreshAllRef.current = refreshAll;
191
+ const firstFocus = useRef(true);
192
+ useEffect(() => {
193
+ if (firstFocus.current) {
194
+ firstFocus.current = false;
195
+ return;
196
+ }
197
+ refreshAllRef.current();
198
+ }, [focusKey]);
199
+ useEffect(() => {
200
+ const sub = AppState.addEventListener("change", (next) => {
201
+ if (next !== "active") return;
202
+ setToday(todayYmd());
203
+ refreshAllRef.current();
204
+ });
205
+ return () => sub.remove();
206
+ }, []);
207
+ const [toast, setToast] = useState(null);
208
+ const toastTimer = useRef(null);
209
+ const showToast = useCallback((message) => {
210
+ if (toastTimer.current) clearTimeout(toastTimer.current);
211
+ setToast(message);
212
+ toastTimer.current = setTimeout(() => setToast(null), TOAST_MS);
213
+ }, []);
214
+ useEffect(() => () => {
215
+ if (toastTimer.current) clearTimeout(toastTimer.current);
216
+ }, []);
217
+ const [claimForm, setClaimForm] = useState(null);
218
+ const [filtersOpen, setFiltersOpen] = useState(false);
219
+ const [busyStatus, setBusyStatus] = useState(null);
220
+ const openNewClaim = useCallback(() => setClaimForm({
221
+ claim: null,
222
+ photo: null
223
+ }), []);
224
+ const scanFirst = useCallback(async () => {
225
+ if (!scanner) {
226
+ openNewClaim();
227
+ return;
228
+ }
229
+ try {
230
+ const photo = await scanner.pick("camera");
231
+ if (photo) setClaimForm({
232
+ claim: null,
233
+ photo
234
+ });
235
+ } catch (err) {
236
+ showToast(receiptScanErrorText(err));
237
+ }
238
+ }, [scanner, openNewClaim, showToast]);
239
+ const saveClaim = useCallback(async (input, {
240
+ submit
241
+ }) => {
242
+ var _a2;
243
+ if (!client) throw new Error("Not signed in yet.");
244
+ const editing = (_a2 = claimForm == null ? void 0 : claimForm.claim) != null ? _a2 : null;
245
+ try {
246
+ let saved = editing ? await client.updateClaim(editing.id, input) : await client.createClaim(input);
247
+ if (submit) saved = await client.changeClaimStatus(saved.id, "SUBMITTED");
248
+ claims.patch(saved);
249
+ if (detail && detail.id === saved.id) setDetail(saved);
250
+ setClaimForm(null);
251
+ let done = submit ? "Submitted for approval" : "Saved as a draft";
252
+ if (editing) done = "Changes saved";
253
+ showToast(done);
254
+ void claims.reload({
255
+ quiet: true
256
+ });
257
+ refreshFigures();
258
+ } catch (err) {
259
+ throw new Error(expensesErrorText(err, editing ? "save your changes" : "save this expense"));
260
+ }
261
+ }, [client, claimForm, claims, detail, showToast, refreshFigures]);
262
+ const changeStatus = useCallback(async (claim, status) => {
263
+ var _a2;
264
+ if (!client) return;
265
+ if (status === "REJECTED") {
266
+ const ok = await confirm("Reject this expense?", "It goes back to whoever filed it to fix and resubmit.", "Reject");
267
+ if (!ok) return;
268
+ }
269
+ setBusyStatus(status);
270
+ try {
271
+ const updated = await client.changeClaimStatus(claim.id, status);
272
+ const merged = __spreadValues(__spreadValues({}, claim), updated);
273
+ claims.patch(merged);
274
+ setDetail((current) => current && current.id === claim.id ? merged : current);
275
+ showToast((_a2 = STATUS_TOAST[status]) != null ? _a2 : `Now ${STATUS_META[status].label.toLowerCase()}`);
276
+ refreshFigures();
277
+ } catch (err) {
278
+ showToast(expensesErrorText(err, "update this expense"));
279
+ } finally {
280
+ setBusyStatus(null);
281
+ }
282
+ }, [client, claims, showToast, refreshFigures]);
283
+ const deleteClaim = useCallback(async (claim) => {
284
+ if (!client) return;
285
+ const ok = await confirm("Delete this expense?", `${claim.merchant} will be removed for everyone.`, "Delete");
286
+ if (!ok) return;
287
+ setBusyStatus("DELETE");
288
+ try {
289
+ await client.deleteClaim(claim.id);
290
+ claims.patch({
291
+ id: claim.id,
292
+ removed: true
293
+ });
294
+ setDetail(null);
295
+ showToast("Expense deleted");
296
+ refreshFigures();
297
+ } catch (err) {
298
+ showToast(expensesErrorText(err, "delete this expense"));
299
+ } finally {
300
+ setBusyStatus(null);
301
+ }
302
+ }, [client, claims, showToast, refreshFigures]);
303
+ const [budgetForm, setBudgetForm] = useState(null);
304
+ const [categoriesOpen, setCategoriesOpen] = useState(false);
305
+ const [recurringForm, setRecurringForm] = useState(null);
306
+ const [accountForm, setAccountForm] = useState(null);
307
+ const [syncingId, setSyncingId] = useState(null);
308
+ const syncFeed = useCallback(async (item) => {
309
+ if (!client) return;
310
+ setSyncingId(item.itemId);
311
+ try {
312
+ const result = await client.syncCardFeed(item.itemId);
313
+ showToast(result.createdClaims > 0 ? `${result.createdClaims} new ${result.createdClaims === 1 ? "expense" : "expenses"} from ${item.institutionName || "the bank"}` : "Up to date");
314
+ void feeds.reload({
315
+ quiet: true
316
+ });
317
+ if (result.createdClaims > 0) {
318
+ void claims.reload({
319
+ quiet: true
320
+ });
321
+ refreshFigures();
322
+ }
323
+ } catch (err) {
324
+ showToast(expensesErrorText(err, "sync this bank"));
325
+ } finally {
326
+ setSyncingId(null);
327
+ }
328
+ }, [client, feeds, claims, showToast, refreshFigures]);
329
+ const removeFeed = useCallback(async (item) => {
330
+ if (!client) return;
331
+ const ok = await confirm(`Unlink ${item.institutionName || "this bank"}?`, "New transactions stop arriving. Expenses already filed stay.", "Unlink");
332
+ if (!ok) return;
333
+ try {
334
+ await client.removeCardFeed(item.id);
335
+ feeds.setData((prev) => (prev != null ? prev : []).filter((f) => f.id !== item.id));
336
+ showToast("Bank unlinked");
337
+ } catch (err) {
338
+ showToast(expensesErrorText(err, "unlink this bank"));
339
+ }
340
+ }, [client, feeds, showToast]);
341
+ const [agentOpen, setAgentOpen] = useState(Boolean(initialAgentSeed));
342
+ const [agentSeed, setAgentSeed] = useState(initialAgentSeed ? {
343
+ id: "initial",
344
+ text: initialAgentSeed.text,
345
+ files: initialAgentSeed.files
346
+ } : null);
347
+ const [seedWaitOver, setSeedWaitOver] = useState(false);
348
+ useEffect(() => {
349
+ if (!initialAgentSeed) return void 0;
350
+ const timer = setTimeout(() => setSeedWaitOver(true), SEED_WAIT_MS);
351
+ return () => clearTimeout(timer);
352
+ }, [initialAgentSeed]);
353
+ const seedReady = Boolean(hostChat == null ? void 0 : hostChat.connected) || seedWaitOver;
354
+ const openAgent = useCallback((prompt) => {
355
+ Keyboard.dismiss();
356
+ setAgentSeed(prompt ? {
357
+ id: `${Date.now()}`,
358
+ text: prompt
359
+ } : null);
360
+ setAgentOpen(true);
361
+ }, []);
362
+ const closeAgent = useCallback(() => {
363
+ setAgentOpen(false);
364
+ refreshAllRef.current();
365
+ }, []);
366
+ const contextHeader = useMemo(() => expensesContextHeader({
367
+ view: tab,
368
+ claim: detail,
369
+ statusFilter: filters.status || null,
370
+ today,
371
+ orgName: org
372
+ }), [tab, detail, filters.status, today, org]);
373
+ useEffect(() => {
374
+ const sub = BackHandler.addEventListener("hardwareBackPress", () => {
375
+ if (agentOpen) {
376
+ closeAgent();
377
+ return true;
378
+ }
379
+ if (detail) {
380
+ setDetail(null);
381
+ return true;
382
+ }
383
+ return false;
384
+ });
385
+ return () => sub.remove();
386
+ }, [agentOpen, detail, closeAgent]);
387
+ const overBudget = ((_c = (_b = dashboard.data) == null ? void 0 : _b.overBudgetCount) != null ? _c : 0) > 0;
388
+ let body;
389
+ if (sessionError) {
390
+ body = /* @__PURE__ */ jsx(CenteredState, { icon: "cloud-alert", title: "Expenses couldn't sign you in", body: "Check your connection, then try again.", theme, primary: onRetrySession ? {
391
+ label: "Try again",
392
+ onPress: onRetrySession
393
+ } : void 0, testID: "expenses-session-error" });
394
+ } else if (!graphqlUrl) {
395
+ body = /* @__PURE__ */ jsx(CenteredState, { icon: "cloud-off-outline", title: "Expenses isn't available here", body: "This version of the app doesn't know where Expenses lives. Update the app and try again.", theme, testID: "expenses-unconfigured" });
396
+ } else {
397
+ body = /* @__PURE__ */ jsxs(View, { style: styles.fill, children: [
398
+ /* @__PURE__ */ jsx(View, { style: [styles.fill, tab === "expenses" ? null : styles.hidden], children: /* @__PURE__ */ jsx(ClaimsPanel, { list: claims, filters, onFiltersChange: setFilters, onOpenFilters: () => setFiltersOpen(true), theme, today, monthSpent, currency, counts: counts.data, onOpenClaim: (claim) => {
399
+ Keyboard.dismiss();
400
+ setDetail(claim);
401
+ }, onNewClaim: openNewClaim, onScanReceipt: () => scanFirst() }) }),
402
+ visited.has("insights") ? /* @__PURE__ */ jsx(View, { style: [styles.fill, tab === "insights" ? null : styles.hidden], children: /* @__PURE__ */ jsx(InsightsPanel, { dashboard, counts: counts.data, toApproveTotal: (_e = (_d = counts.data) == null ? void 0 : _d.toApproveTotal) != null ? _e : null, theme, today, onOpenBudgets: () => selectTab("budgets"), onOpenToApprove: () => {
403
+ setFilters(__spreadProps(__spreadValues({}, EMPTY_FILTERS), {
404
+ status: "SUBMITTED"
405
+ }));
406
+ selectTab("expenses");
407
+ }, onAsk: () => openAgent("Summarise my spend this month and flag anything unusual.") }) }) : null,
408
+ visited.has("budgets") ? /* @__PURE__ */ jsx(View, { style: [styles.fill, tab === "budgets" ? null : styles.hidden], children: /* @__PURE__ */ jsx(BudgetsPanel, { budgets, categories: activeCategories, theme, onNew: () => setBudgetForm({
409
+ budget: null
410
+ }), onOpen: (budget) => setBudgetForm({
411
+ budget
412
+ }), onManageCategories: () => setCategoriesOpen(true) }) }) : null,
413
+ visited.has("recurring") ? /* @__PURE__ */ jsx(View, { style: [styles.fill, tab === "recurring" ? null : styles.hidden], children: /* @__PURE__ */ jsx(RecurringPanel, { rules: recurrings, summary: recurringSummary, theme, today, onNew: () => setRecurringForm({
414
+ rule: null
415
+ }), onOpen: (rule) => setRecurringForm({
416
+ rule
417
+ }), onAskFind: () => openAgent("Look through my expenses for repeat charges and set them up as recurring payments.") }) }) : null,
418
+ visited.has("accounts") ? /* @__PURE__ */ jsx(View, { style: [styles.fill, tab === "accounts" ? null : styles.hidden], children: /* @__PURE__ */ jsx(AccountsPanel, { accounts, feeds, theme, syncingId, onNewAccount: () => setAccountForm({
419
+ account: null
420
+ }), onOpenAccount: (account) => setAccountForm({
421
+ account
422
+ }), onSyncFeed: (item) => syncFeed(item), onRemoveFeed: (item) => removeFeed(item), onConnectBank: onOpenWeb ? () => onOpenWeb("accounts") : null }) }) : null,
423
+ detail ? /* @__PURE__ */ jsx(View, { style: [StyleSheet.absoluteFill, {
424
+ backgroundColor: theme.screen
425
+ }], children: /* @__PURE__ */ jsx(ClaimDetail, { claim: detail, theme, today, busyStatus, onAction: (status) => changeStatus(detail, status), onEdit: () => setClaimForm({
426
+ claim: detail,
427
+ photo: null
428
+ }), onDelete: () => deleteClaim(detail), onAsk: () => openAgent(), bottomInset: insets.bottom }, detail.id) }) : null,
429
+ toast ? /* @__PURE__ */ jsx(Toast, { message: toast, theme, bottom: detail ? 96 : 92 }) : null
430
+ ] });
431
+ }
432
+ const showTabs = !sessionError && Boolean(graphqlUrl) && !detail;
433
+ return /* @__PURE__ */ jsxs(GestureHandlerRootView, { style: [styles.fill, {
434
+ backgroundColor: theme.screen
435
+ }], testID: "expenses-panel", children: [
436
+ /* @__PURE__ */ jsxs(View, { style: [styles.topBar, {
437
+ paddingTop: insets.top + 4,
438
+ borderBottomColor: theme.border
439
+ }], children: [
440
+ /* @__PURE__ */ jsx(Tap, { onPress: detail ? () => setDetail(null) : onExit, hitSlop: 8, accessibilityRole: "button", accessibilityLabel: detail ? "Back to expenses" : "Back", style: styles.iconButton, pressedStyle: DIM, testID: "expenses-back", children: /* @__PURE__ */ jsx(MaterialCommunityIcons, { name: "chevron-left", size: 30, color: theme.ink }) }),
441
+ /* @__PURE__ */ jsxs(View, { style: styles.titleBlock, children: [
442
+ /* @__PURE__ */ jsx(Text, { style: [styles.title, {
443
+ color: theme.ink
444
+ }], numberOfLines: 1, children: detail ? "Expense" : "Expenses" }),
445
+ !detail && org ? /* @__PURE__ */ jsx(Text, { style: [styles.subtitle, {
446
+ color: theme.muted
447
+ }], numberOfLines: 1, children: org }) : null
448
+ ] }),
449
+ /* @__PURE__ */ jsxs(Tap, { onPress: () => openAgent(), accessibilityRole: "button", accessibilityLabel: "Ask the Expenses agent", style: [styles.agentChip, {
450
+ backgroundColor: theme.accentSoft
451
+ }], pressedStyle: DIM, testID: "expenses-agent", children: [
452
+ /* @__PURE__ */ jsx(MaterialCommunityIcons, { name: "creation", size: 17, color: theme.accent }),
453
+ /* @__PURE__ */ jsx(Text, { style: [styles.agentLabel, {
454
+ color: theme.accent
455
+ }], children: "Ask" })
456
+ ] })
457
+ ] }),
458
+ body,
459
+ showTabs ? /* @__PURE__ */ jsx(ExpensesTabBar, { tab, theme, bottomInset: insets.bottom, alerts: {
460
+ insights: overBudget
461
+ }, onSelect: selectTab }) : null,
462
+ /* @__PURE__ */ jsx(ClaimForm, { visible: claimForm !== null, claim: (_f = claimForm == null ? void 0 : claimForm.claim) != null ? _f : null, initialPhoto: (_g = claimForm == null ? void 0 : claimForm.photo) != null ? _g : null, categories: categoryList, accounts: accountList, defaultCurrency: currency, theme, scanner, onCancel: () => setClaimForm(null), onSave: saveClaim }),
463
+ /* @__PURE__ */ jsx(FiltersSheet, { visible: filtersOpen, filters, categories: activeCategories, theme, onApply: (next) => {
464
+ setFilters(next);
465
+ setFiltersOpen(false);
466
+ }, onClose: () => setFiltersOpen(false) }),
467
+ /* @__PURE__ */ jsx(BudgetForm, { visible: budgetForm !== null, budget: (_h = budgetForm == null ? void 0 : budgetForm.budget) != null ? _h : null, categories: activeCategories, defaultCurrency: currency, theme, onCancel: () => setBudgetForm(null), onSave: async (input) => {
468
+ if (!client) return;
469
+ const editing = budgetForm == null ? void 0 : budgetForm.budget;
470
+ try {
471
+ if (editing) await client.updateBudget(editing.id, input);
472
+ else await client.createBudget(input);
473
+ } catch (err) {
474
+ throw new Error(expensesErrorText(err, "save this budget"));
475
+ }
476
+ setBudgetForm(null);
477
+ showToast(editing ? "Budget updated" : "Budget created");
478
+ void budgets.reload({
479
+ quiet: true
480
+ });
481
+ void dashboard.reload({
482
+ quiet: true
483
+ });
484
+ }, onDelete: async (budget) => {
485
+ if (!client) return;
486
+ const ok = await confirm("Delete this budget?", `${budget.name} will be removed.`, "Delete");
487
+ if (!ok) return;
488
+ try {
489
+ await client.deleteBudget(budget.id);
490
+ } catch (err) {
491
+ throw new Error(expensesErrorText(err, "delete this budget"));
492
+ }
493
+ setBudgetForm(null);
494
+ budgets.setData((prev) => (prev != null ? prev : []).filter((b) => b.id !== budget.id));
495
+ showToast("Budget deleted");
496
+ void dashboard.reload({
497
+ quiet: true
498
+ });
499
+ } }),
500
+ /* @__PURE__ */ jsx(CategoriesSheet, { visible: categoriesOpen, categories: categoryList, theme, onClose: () => setCategoriesOpen(false), onCreate: async (input) => {
501
+ if (!client) return;
502
+ try {
503
+ const created = await client.createCategory(input);
504
+ categories.setData((prev) => [...prev != null ? prev : [], created]);
505
+ showToast("Category added");
506
+ } catch (err) {
507
+ throw new Error(expensesErrorText(err, "add this category"));
508
+ }
509
+ }, onUpdate: async (category, input) => {
510
+ if (!client) return;
511
+ try {
512
+ const updated = await client.updateCategory(category.id, input);
513
+ categories.setData((prev) => (prev != null ? prev : []).map((c) => c.id === category.id ? updated : c));
514
+ showToast("Category updated");
515
+ } catch (err) {
516
+ throw new Error(expensesErrorText(err, "update this category"));
517
+ }
518
+ }, onDelete: async (category) => {
519
+ if (!client) return false;
520
+ const ok = await confirm(`Delete ${category.name}?`, "Expenses filed under it keep their amounts but lose the category.", "Delete");
521
+ if (!ok) return false;
522
+ try {
523
+ await client.deleteCategory(category.id);
524
+ categories.setData((prev) => (prev != null ? prev : []).filter((c) => c.id !== category.id));
525
+ showToast("Category deleted");
526
+ void claims.reload({
527
+ quiet: true
528
+ });
529
+ return true;
530
+ } catch (err) {
531
+ throw new Error(expensesErrorText(err, "delete this category"));
532
+ }
533
+ } }),
534
+ /* @__PURE__ */ jsx(RecurringForm, { visible: recurringForm !== null, rule: (_i = recurringForm == null ? void 0 : recurringForm.rule) != null ? _i : null, categories: activeCategories, defaultCurrency: currency, theme, onCancel: () => setRecurringForm(null), onSave: async (input) => {
535
+ if (!client) return;
536
+ const editing = recurringForm == null ? void 0 : recurringForm.rule;
537
+ try {
538
+ if (editing) await client.updateRecurring(editing.id, input);
539
+ else await client.createRecurring(input);
540
+ } catch (err) {
541
+ throw new Error(expensesErrorText(err, "save this recurring payment"));
542
+ }
543
+ setRecurringForm(null);
544
+ showToast(editing ? "Recurring payment updated" : "Recurring payment added");
545
+ void recurrings.reload({
546
+ quiet: true
547
+ });
548
+ void recurringSummary.reload({
549
+ quiet: true
550
+ });
551
+ }, onDelete: async (rule) => {
552
+ if (!client) return;
553
+ const ok = await confirm("Delete this recurring payment?", `${rule.name} will stop being tracked.`, "Delete");
554
+ if (!ok) return;
555
+ try {
556
+ await client.deleteRecurring(rule.id);
557
+ } catch (err) {
558
+ throw new Error(expensesErrorText(err, "delete this recurring payment"));
559
+ }
560
+ setRecurringForm(null);
561
+ recurrings.setData((prev) => (prev != null ? prev : []).filter((r) => r.id !== rule.id));
562
+ showToast("Recurring payment deleted");
563
+ void recurringSummary.reload({
564
+ quiet: true
565
+ });
566
+ } }),
567
+ /* @__PURE__ */ jsx(AccountForm, { visible: accountForm !== null, account: (_j = accountForm == null ? void 0 : accountForm.account) != null ? _j : null, theme, onCancel: () => setAccountForm(null), onSave: async (input) => {
568
+ if (!client) return;
569
+ const editing = accountForm == null ? void 0 : accountForm.account;
570
+ try {
571
+ if (editing) await client.updateManualAccount(editing.id, input);
572
+ else await client.createManualAccount(input);
573
+ } catch (err) {
574
+ throw new Error(expensesErrorText(err, "save this account"));
575
+ }
576
+ setAccountForm(null);
577
+ showToast(editing ? "Account updated" : "Account added");
578
+ void accounts.reload({
579
+ quiet: true
580
+ });
581
+ }, onDelete: async (account) => {
582
+ if (!client) return;
583
+ const ok = await confirm(`Delete ${account.institutionName}?`, "Expenses filed against it stay, without the account.", "Delete");
584
+ if (!ok) return;
585
+ try {
586
+ await client.deleteManualAccount(account.id);
587
+ } catch (err) {
588
+ throw new Error(expensesErrorText(err, "delete this account"));
589
+ }
590
+ setAccountForm(null);
591
+ accounts.setData((prev) => (prev != null ? prev : []).filter((a) => a.id !== account.id));
592
+ showToast("Account deleted");
593
+ } }),
594
+ /* @__PURE__ */ jsx(ExpensesAgentChatPane, { visible: agentOpen, onClose: closeAgent, hostChat, contextHeader, view: tab, claimMerchant: detail ? detail.merchant : null, seed: seedReady ? agentSeed : null, theme })
595
+ ] });
596
+ }
597
+ const styles = StyleSheet.create({
598
+ fill: {
599
+ flex: 1
600
+ },
601
+ hidden: {
602
+ display: "none"
603
+ },
604
+ topBar: {
605
+ flexDirection: "row",
606
+ alignItems: "center",
607
+ gap: 6,
608
+ paddingHorizontal: 8,
609
+ paddingBottom: 8,
610
+ borderBottomWidth: StyleSheet.hairlineWidth
611
+ },
612
+ iconButton: {
613
+ width: 36,
614
+ height: 44,
615
+ alignItems: "center",
616
+ justifyContent: "center"
617
+ },
618
+ titleBlock: {
619
+ flex: 1,
620
+ minHeight: 44,
621
+ justifyContent: "center"
622
+ },
623
+ title: {
624
+ fontSize: 22,
625
+ fontWeight: "700",
626
+ letterSpacing: -0.3
627
+ },
628
+ subtitle: {
629
+ fontSize: 13,
630
+ fontWeight: "500",
631
+ marginTop: 1
632
+ },
633
+ agentChip: {
634
+ flexDirection: "row",
635
+ alignItems: "center",
636
+ gap: 5,
637
+ height: 36,
638
+ paddingHorizontal: 14,
639
+ borderRadius: 18,
640
+ marginRight: 6
641
+ },
642
+ agentLabel: {
643
+ fontSize: 15,
644
+ fontWeight: "700"
645
+ }
646
+ });export{ExpensesExperience};//# sourceMappingURL=ExpensesExperience.js.map