ownledger 2.3.0 → 2.4.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 (79) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +26 -0
  3. package/assets/index.html +10 -10
  4. package/assets/static/{Account-CYrXDU9Z.js → Account-DIDz6cXc.js} +1 -1
  5. package/assets/static/{Accounts-BXleOwUO.js → Accounts-BHqMr96X.js} +1 -1
  6. package/assets/static/{Attention-Ci3luOdE.js → Attention-DW0iYViO.js} +1 -1
  7. package/assets/static/{ByCategory-cLVOyjwd.js → ByCategory-BcC8nC5_.js} +1 -1
  8. package/assets/static/CardBudgets-CaXHjpKv.js +1 -0
  9. package/assets/static/CardDetail-C-EWPz9U.js +1 -0
  10. package/assets/static/{Cards-DnIsAWPD.js → Cards-2bB7IrMZ.js} +1 -1
  11. package/assets/static/{Cards-DNtITMnA.js → Cards-CXuGLYDb.js} +1 -1
  12. package/assets/static/{CardsValue-V1-fYMLf.js → CardsValue-CBP2-s79.js} +1 -1
  13. package/assets/static/{Cashback-B8lqwRnb.js → Cashback-BRHegG4o.js} +1 -1
  14. package/assets/static/{CategoryIcon-D4Cdb_ZP.js → CategoryIcon-DZf6uKtg.js} +1 -1
  15. package/assets/static/{CategoryPicker-54vkuxVh.js → CategoryPicker-CIgSXytj.js} +1 -1
  16. package/assets/static/{ChartWidget-S5F4Ze91.js → ChartWidget-B5oybW6u.js} +1 -1
  17. package/assets/static/{Combobox-BvX68J3o.js → Combobox-CK6B8Keq.js} +1 -1
  18. package/assets/static/{Deposits-Ct5HhCEc.js → Deposits-Ddy3xcdL.js} +1 -1
  19. package/assets/static/{DrillLink-CZyI-y0-.js → DrillLink-CaBCVQQj.js} +1 -1
  20. package/assets/static/{Field-DYmqEAlI.js → Field-rwl1eTQR.js} +1 -1
  21. package/assets/static/{HomeEditor-Dv-h_ql-.js → HomeEditor-Or4bvFoV.js} +1 -1
  22. package/assets/static/{Import-B2uhVnEm.js → Import-CPpOHxfR.js} +1 -1
  23. package/assets/static/{IncomeSpending-DNT2CWH9.js → IncomeSpending-Dw_YhoO_.js} +1 -1
  24. package/assets/static/{KV-CKWaJkRK.js → KV-Cpfsyhnb.js} +1 -1
  25. package/assets/static/{Left-BefXZztB.js → Left-BiuU811i.js} +1 -1
  26. package/assets/static/{Money-BwLucm7P.js → Money-DFHYuv5m.js} +1 -1
  27. package/assets/static/{NetWorth-DeLSapZ2.js → NetWorth-B9uU7Ope.js} +1 -1
  28. package/assets/static/{Pace-D6gilOBZ.js → Pace-BbOf0yAs.js} +1 -1
  29. package/assets/static/{Panel-CSe25x0N.js → Panel-tOE_I4OD.js} +1 -1
  30. package/assets/static/{PinDialog-CHiLIKEs.js → PinDialog-Dj4j0jcD.js} +1 -1
  31. package/assets/static/{Plans-D7rJ1yHU.js → Plans-COJrKjSX.js} +1 -1
  32. package/assets/static/{Recent-Dcqb2yko.js → Recent-BJrdjtMv.js} +1 -1
  33. package/assets/static/{Reports--PDAEnQM.js → Reports-ByrhmAQv.js} +1 -1
  34. package/assets/static/{Settings-Bd0oglWl.js → Settings-BunM2dfp.js} +1 -1
  35. package/assets/static/{Transactions-CQ1yQ1UU.js → Transactions-DVJDPqHI.js} +1 -1
  36. package/assets/static/{TxRow-BGfpKo2m.js → TxRow-CZJ_C-Cp.js} +1 -1
  37. package/assets/static/{Unusual-DGB4ZOA2.js → Unusual-ChtSsnCm.js} +1 -1
  38. package/assets/static/{Upcoming-B0HwBqmG.js → Upcoming-D6ab7_fA.js} +1 -1
  39. package/assets/static/{WhichCard-BefFKS2q.js → WhichCard-BlBXpqMn.js} +1 -1
  40. package/assets/static/{arrow-up-CRgLRKET.js → arrow-up-7r2T_P3U.js} +1 -1
  41. package/assets/static/{bits-D34d9IBm.js → bits-CayEEXaW.js} +1 -1
  42. package/assets/static/{button-BKhMn8jX.js → button-DQvRPLIv.js} +1 -1
  43. package/assets/static/{cards-Ct0jh73r.js → cards-BP4EqCQY.js} +1 -1
  44. package/assets/static/{charts-D-1glV8L.js → charts-DzDF8ihe.js} +1 -1
  45. package/assets/static/chevron-down-wODISwBd.js +1 -0
  46. package/assets/static/chevron-right-CRhYK7Bh.js +1 -0
  47. package/assets/static/{createLucideIcon-XZ28znwT.js → createLucideIcon-DI8vbiOO.js} +1 -1
  48. package/assets/static/{dialog-Bx-cd-2e.js → dialog-B6000kEK.js} +1 -1
  49. package/assets/static/{dist-BFPyD74_.js → dist-Cb1_dp0K.js} +1 -1
  50. package/assets/static/{dist--HKr0kfV.js → dist-CqPSw3yk.js} +1 -1
  51. package/assets/static/{dist-vgyaCpaL.js → dist-DabFVUs-.js} +1 -1
  52. package/assets/static/{dist-CmbuesVk.js → dist-DiXEmDmz.js} +1 -1
  53. package/assets/static/{es2015-DqY4UvQc.js → es2015-ConR4hgR.js} +1 -1
  54. package/assets/static/index-DvdDpUvS.js +14 -0
  55. package/assets/static/{queries-BcMmmb36.js → queries-Dr6hPr4g.js} +1 -1
  56. package/assets/static/{react-dom-5dgiSOdd.js → react-dom-DKhzijWz.js} +1 -1
  57. package/assets/static/{select-B5P2TaPX.js → select-5FcHJXrC.js} +1 -1
  58. package/assets/static/{shared-BgU6fc7z.js → shared-C3-t8uIq.js} +1 -1
  59. package/assets/static/{triangle-exclamation-point-CMy18kC0.js → triangle-exclamation-point-B4sQZqpa.js} +1 -1
  60. package/assets/static/{useMutation-aC3Z1p9y.js → useMutation-Bf1MT3Q_.js} +1 -1
  61. package/dist/engine/actions.js +22 -7
  62. package/dist/engine/dashboard.js +1 -0
  63. package/dist/modules/cards/index.d.ts +2 -1
  64. package/dist/modules/cards/index.js +51 -19
  65. package/dist/modules/cards/statements.d.ts +57 -0
  66. package/dist/modules/cards/statements.js +183 -33
  67. package/dist/modules/cards/terms.d.ts +18 -0
  68. package/dist/modules/cards/terms.js +15 -5
  69. package/dist/node/statement-rows.js +3 -1
  70. package/dist/worker/bestcard.d.ts +58 -0
  71. package/dist/worker/bestcard.js +65 -1
  72. package/dist/worker/mcp.js +38 -7
  73. package/dist/worker/version.d.ts +1 -1
  74. package/dist/worker/version.js +1 -1
  75. package/package.json +1 -1
  76. package/assets/static/CardDetail-BxXfAcMp.js +0 -1
  77. package/assets/static/chevron-down-BWoQwA6m.js +0 -1
  78. package/assets/static/chevron-right-D7Sgw1v1.js +0 -1
  79. package/assets/static/index-DBHFdsYB.js +0 -14
@@ -20,7 +20,7 @@ import { dashboardOf } from "./api.js";
20
20
  import { cardList } from "../modules/cards/index.js";
21
21
  import { cashback, closeOnOrAfter, feeWaiver, lineKind, statements } from "../modules/cards/statements.js";
22
22
  import { STATEMENTS_FILE, termsOf, recordFor, withBankAmounts } from "../modules/cards/terms.js";
23
- import { bestCard } from "./bestcard.js";
23
+ import { bestCard, termsFromOpenWallet } from "./bestcard.js";
24
24
  import { openWalletClient } from "./openwallet.js";
25
25
  const out = (v) => ({ content: [{ type: "text", text: typeof v === "string" ? v : JSON.stringify(v) }] });
26
26
  const fail = (msg) => ({ content: [{ type: "text", text: msg }], isError: true });
@@ -28,7 +28,7 @@ const INSTRUCTIONS = `ownledger: the owner's personal finance ledger, kept in th
28
28
  Amounts are whole numbers in the base currency (see about). Answers are computed here; never add up raw rows yourself when a tool computes it.
29
29
  Writes: the add_/edit_/void_/set_/remove_ tools and batch only PREVIEW. Show the owner the preview (what, amounts, accounts), wait for their explicit go, then call apply with the preview_id. Never invent an amount, date, account or category: ask. Call rules once before the first write. For more than ~3 transaction writes at once, use batch: one preview, one go, one commit.
30
30
  Dashboard: when the owner asks to "track", "watch" or "put on my dashboard" something, offer a widget (add_widget), using the categories and accounts from rules.
31
- Cards: for "which card should I use", call best_card; statements, cashback and fee waivers come from cards and card_statement.`;
31
+ Cards: for "which card should I use", call best_card; statements, cashback and fee waivers come from cards and card_statement. "How much more on each card" / "last day to spend": cards gives each group's room and the last safe day (statement date − the card's post margin). To set a card's cashback terms from OpenWallet, call card_terms_from_openwallet, check them with the owner, then set_card_details.`;
32
32
  const OPENWALLET_LINE = `
33
33
  best_card also asks OpenWallet (an outside card catalog the owner turned on) for cards without the owner's own cashback terms: give it the amount and a merchant or kind. It gets those cards' product names, the purchase and their spend this period. Quote OpenWallet's figures with its date and link (source: openwallet); unknown is not 0. If a card is in not_matched, say so and how to fix it.`;
34
34
  function compactTx(t) {
@@ -253,7 +253,7 @@ export function buildServer(env, props, src = sourceFor(env), deps = {}) {
253
253
  ...(months ? { series: netWorthSeries(s.ledger, addMonths(asOf.slice(0, 7) + "-01", -(months - 1)), asOf).map((x) => ({ date: x.date, net: x.net, assets: x.assets, liabilities: x.liabilities })) } : {}),
254
254
  };
255
255
  }));
256
- server.registerTool("cards", { description: "Credit cards: owed, limit, last statement (to pay, due, paid or not), cashback this period, this statement period (spent by category, refunds, cashback booked), product name, annual fee waiver, terms still missing.", inputSchema: z.object({ date: z.string().optional(), include_closed: z.boolean().optional() }), annotations: ro }, wrap(async ({ date, include_closed }) => {
256
+ server.registerTool("cards", { description: "Credit cards: owed, limit, last statement (to pay, due, paid or not), cashback this period (groups with earned / cap / room = more spend still paid for, the last safe day to spend so it lands on this statement), points held, this statement period (spent by category, refunds, cashback booked), product name, annual fee waiver, terms still missing.", inputSchema: z.object({ date: z.string().optional(), include_closed: z.boolean().optional() }), annotations: ro }, wrap(async ({ date, include_closed }) => {
257
257
  const s = await snap();
258
258
  const asOf = date ?? now();
259
259
  const per = new Map(cards(s.ledger, asOf).map((x) => [x.account, x]));
@@ -264,7 +264,17 @@ export function buildServer(env, props, src = sourceFor(env), deps = {}) {
264
264
  limit: c.limit ?? (c.limitAtLeast ? `at least ${c.limitAtLeast} (most ever owed; limit not set)` : null),
265
265
  last_statement: c.last ? { date: c.last.close, amount_due: c.last.amountDue, paid: c.last.paid, to_pay: c.last.toPay, due: c.last.due, status: c.last.status, ...(c.last.bank !== null ? { bank: c.last.bank, diff: c.last.bankDiff } : {}) } : null,
266
266
  this_period: c.current ? { from: c.current.from, purchases: c.current.purchases } : null,
267
- cashback: c.cashback ? { spend: c.cashback.spend, expected: c.cashback.expected, cap_left: c.cashback.capLeft, min_met: c.cashback.minMet, need_for_min: c.cashback.needForMin, ...(c.cashback.incomplete ? { note: "some rates not set" } : {}) } : null,
267
+ cashback: c.cashback
268
+ ? {
269
+ spend: c.cashback.spend, expected: c.cashback.expected, cap_left: c.cashback.capLeft, min_met: c.cashback.minMet, need_for_min: c.cashback.needForMin,
270
+ ...(c.cashback.safeUntil ? { closes_on: c.cashback.closesOn, safe_until: c.cashback.safeUntil, days_left: c.cashback.daysLeft } : {}),
271
+ ...(c.cashback.groups.some((g) => g.cap !== null) ? { groups: c.cashback.groups.map((g) => ({ label: g.label, rate: g.rate, spend: g.spend, earned: g.earned, cap: g.cap, room: g.room, ...(g.inStore ? { in_store: true } : {}) })) } : {}),
272
+ ...(c.cashback.roomSpend != null ? { room_spend: c.cashback.roomSpend, ...(c.cashback.roomEstimate ? { room_estimate: true } : {}) } : {}),
273
+ ...(c.cashback.earnLeft != null ? { earn_left: c.cashback.earnLeft } : {}),
274
+ ...(c.cashback.incomplete ? { note: "some rates not set" } : {}),
275
+ }
276
+ : null,
277
+ ...(c.points ? { points: { balance: c.points.balance, pending: c.points.pending, redeem_min: c.points.redeemMin, can_redeem: c.points.canRedeem, expiring: c.points.lots.filter((x) => x.expires).slice(0, 3), expired: c.points.expired } } : {}),
268
278
  ...(c.bank ? { bank: c.bank } : {}),
269
279
  ...(per.get(c.account)?.product ? { product: per.get(c.account).product } : {}),
270
280
  ...(per.get(c.account) ? { period: (({ from, to, spent, refunds, byCategory, cashback }) => ({ from, to, spent, refunds, by_category: byCategory, cashback_booked: cashback }))(per.get(c.account).period) } : {}),
@@ -297,6 +307,16 @@ export function buildServer(env, props, src = sourceFor(env), deps = {}) {
297
307
  const s = await snap();
298
308
  return bestCard(s.ledger, now(), ow, a);
299
309
  }));
310
+ if (ow) {
311
+ server.registerTool("card_terms_from_openwallet", {
312
+ description: "OpenWallet's cashback rules for one of the owner's credit cards, shaped like set_card_details' cashback, to check with the owner before saving (writes nothing). Sends the card's product name and bank to OpenWallet. Map each rule's intents to the owner's categories, then set_card_details.",
313
+ inputSchema: z.object({ account: z.string() }),
314
+ annotations: { readOnlyHint: true, openWorldHint: true },
315
+ }, wrap(async ({ account }) => {
316
+ const s = await snap();
317
+ return termsFromOpenWallet(s.ledger, now(), ow, account);
318
+ }));
319
+ }
300
320
  server.registerTool("plans_due", { description: "Instalments, loan payments and premiums due in the next N days (and overdue), plus what's left per plan.", inputSchema: z.object({ days: z.number().int().max(366).optional() }), annotations: ro }, wrap(async ({ days }) => {
301
321
  const s = await snap();
302
322
  const asOf = now();
@@ -399,7 +419,7 @@ export function buildServer(env, props, src = sourceFor(env), deps = {}) {
399
419
  server.registerTool("edit_category", { description: "PREVIEW renaming a category, or moving it to a new path (every line using it is remapped).", inputSchema: z.object({ path: z.string(), name: z.string().optional(), new_path: z.string().optional() }), annotations: pv }, wrap(async ({ path, ...set }) => preview((f) => A.editCategory(f, path, set))));
400
420
  /* ---------------------------------------------------------------- cards (preview) */
401
421
  server.registerTool("set_card_details", {
402
- description: "PREVIEW card terms on a credit card account: statement and due days, limit, annual fee and its month, fee waiver target, cashback rules. Only the fields given change; they're kept over codes read from wallet names.",
422
+ description: "PREVIEW card terms on a credit card account: statement and due days, limit, annual fee and its month, fee waiver target, cashback rules (per-rule caps, merchant rules, in-store, points payout, post margin). Only the fields given change; they're kept over codes read from wallet names.",
403
423
  inputSchema: z.object({
404
424
  account: z.string(),
405
425
  statement_day: z.number().int().min(1).max(31).optional(),
@@ -411,7 +431,18 @@ export function buildServer(env, props, src = sourceFor(env), deps = {}) {
411
431
  free_days_max: z.number().int().optional(),
412
432
  cashback: z.object({
413
433
  base: z.number().min(0).max(100).optional(),
414
- rules: z.array(z.object({ categories: z.array(z.string()), rate: z.number().min(0).max(100) })).optional(),
434
+ rules: z.array(z.object({
435
+ categories: z.array(z.string()).optional(),
436
+ merchants: z.array(z.string()).optional().describe("words looked for in the merchant and note, e.g. [shopee, lazada]; wins over categories"),
437
+ rate: z.number().min(0).max(100),
438
+ cap: z.number().int().positive().optional().describe("the most this rule pays per statement"),
439
+ in_store: z.boolean().optional().describe("the bank pays it only for in-store payments"),
440
+ label: z.string().optional(),
441
+ })).optional().describe("replaces the card's rules; each needs categories or merchants"),
442
+ post_margin_days: z.number().int().min(0).max(10).optional().describe("days before the statement date too late to be sure a purchase lands on it (default 3)"),
443
+ payout: z.enum(["auto", "points"]).optional().describe("auto: the bank pays it; points: a balance cashed in by hand"),
444
+ redeem_min: z.number().int().positive().optional().describe("points: cash in only from this balance"),
445
+ expire_months: z.number().int().positive().optional().describe("points: months after their statement that points expire"),
415
446
  cap: z.object({ amount: z.number().int().positive(), per: z.enum(["statement", "month"]) }).optional(),
416
447
  min_spend: z.object({ amount: z.number().int().positive(), per: z.enum(["statement", "month"]) }).optional(),
417
448
  spend_max: z.object({ amount: z.number().int().positive(), per: z.enum(["statement", "month"]) }).optional(),
@@ -494,7 +525,7 @@ export function buildServer(env, props, src = sourceFor(env), deps = {}) {
494
525
  return { file: dashboardPath(props.login), saved: Boolean(dashboardOf(s.files, props.login)), grid_columns: GRID_COLS, widgets: d.widgets };
495
526
  }));
496
527
  server.registerTool("add_widget", {
497
- description: "PREVIEW adding a widget to the owner's dashboard: a chart from a query (type chart), or a built-in widget by type (pace, left, attention, unusual, net_worth, by_category, income_spending, recent, account, upcoming, cards, cashback, which_card, cards_value, deposits). Shows the first numbers so the owner can see it's right.",
528
+ description: "PREVIEW adding a widget to the owner's dashboard: a chart from a query (type chart), or a built-in widget by type (pace, left, attention, unusual, net_worth, by_category, income_spending, recent, account, upcoming, cards, card_budgets (each card's cashback room per group and last safe day), cashback, which_card, cards_value, deposits). Shows the first numbers so the owner can see it's right.",
498
529
  inputSchema: z.object({ type: z.string().default("chart"), title: z.string().max(80).optional(), query: queryShape.optional(), chart: z.enum(["stat", "line", "bar", "hbar", "table"]).optional(), account: z.string().optional(), period: z.string().optional(), w: z.number().int().min(1).max(12).optional(), h: z.number().int().min(1).max(24).optional(), id: z.string().optional() }),
499
530
  annotations: pv,
500
531
  }, wrap(async ({ type, title, query, chart, account, period, w, h, id }) => {
@@ -1 +1 @@
1
- export declare const VERSION = "2.3.0";
1
+ export declare const VERSION = "2.4.0";
@@ -1,2 +1,2 @@
1
1
  // generated by scripts/version.mjs
2
- export const VERSION = "2.3.0";
2
+ export const VERSION = "2.4.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ownledger",
3
- "version": "2.3.0",
3
+ "version": "2.4.0",
4
4
  "description": "Personal finance ledger used through AI chat (MCP). Your data in your own private GitHub repo, served by your own Cloudflare Worker.",
5
5
  "license": "MIT",
6
6
  "author": "phucbm",
@@ -1 +0,0 @@
1
- import{t as e}from"./createLucideIcon-XZ28znwT.js";import{t}from"./chevron-right-D7Sgw1v1.js";import{B as n,I as r,L as i,T as a,d as o,h as s,r as c,w as l,y as u}from"./queries-BcMmmb36.js";import{A as d,G as f,J as p,K as m,W as h,Y as g,a as _,k as v,l as y,q as b,r as x,s as S,t as C}from"./index-DBHFdsYB.js";import{t as w}from"./DrillLink-CZyI-y0-.js";import{t as T}from"./KV-CKWaJkRK.js";import{t as E}from"./Money-BwLucm7P.js";import{t as D}from"./Panel-CSe25x0N.js";import{a as O,i as k,n as A,o as j,r as M}from"./bits-D34d9IBm.js";import{n as N,t as P}from"./TxRow-BGfpKo2m.js";import{a as F,n as I,t as L}from"./charts-D-1glV8L.js";import{n as R,r as z}from"./cards-Ct0jh73r.js";var B={name:`arrow-left`,size:24,node:[[`path`,{d:`m12 19-7-7 7-7`,key:`1l729n`}],[`path`,{d:`M19 12H5`,key:`x3x0zl`}]]};B.node;var V=e(B),H=n(r(),1),U=i();function W({account:e,close:t,onClose:n}){let{t:r,lang:i}=l(),a=v(`(max-width: 767px)`),{data:c,error:u,isLoading:d}=s(e,t),_=N(o().data),y=c?.statement;return(0,U.jsx)(f,{open:t!==null,onOpenChange:e=>!e&&n(),children:(0,U.jsxs)(m,{side:a?`bottom`:`right`,className:a?`max-h-[85svh] overflow-auto rounded-t-xl`:`overflow-auto sm:max-w-md`,children:[(0,U.jsxs)(p,{children:[(0,U.jsx)(g,{children:y?.open?r(`cards.currentPeriod`):r(`cards.statementOf`,{date:t?S(t,i):``})}),(0,U.jsxs)(b,{children:[y?`${S(y.from,i)} – ${S(y.close,i)}`:r(`common.loading`),y?.pdf&&(0,U.jsxs)(U.Fragment,{children:[` · `,(0,U.jsx)(`a`,{href:`/api/m/cards/statement-pdf?account=${encodeURIComponent(e)}&close=${y.close}`,target:`_blank`,rel:`noopener noreferrer`,className:`underline underline-offset-2 hover:text-foreground`,children:r(`cards.statementPdf`)})]})]})]}),(0,U.jsx)(`div`,{className:`flex flex-col gap-3 px-4 pb-4`,children:u?(0,U.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:r(`common.error`,{message:u.message})}):d||!c||!y?(0,U.jsx)(h,{className:`h-40 w-full`}):(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(`dl`,{className:`divide-y rounded-lg border px-3`,children:[(0,U.jsx)(T,{label:r(`cards.opening`),children:(0,U.jsx)(E,{amount:y.opening})}),(0,U.jsx)(T,{label:r(`cards.k.purchase`),children:(0,U.jsx)(E,{amount:y.purchases})}),y.fees>0&&(0,U.jsx)(T,{label:r(`cards.k.fee`),children:(0,U.jsx)(E,{amount:y.fees})}),y.refunds>0&&(0,U.jsx)(T,{label:r(`cards.k.refund`),children:(0,U.jsx)(E,{amount:-y.refunds})}),y.cashback>0&&(0,U.jsx)(T,{label:r(`cards.k.cashback`),children:(0,U.jsx)(E,{amount:-y.cashback})}),y.payments>0&&(0,U.jsx)(T,{label:r(`cards.k.payment`),children:(0,U.jsx)(E,{amount:-y.payments})}),(0,U.jsx)(T,{label:r(`cards.closing`),className:`font-medium`,children:(0,U.jsx)(E,{amount:y.closing})})]}),(0,U.jsx)(`ul`,{children:c.transactions.map(t=>(0,U.jsxs)(`li`,{className:`flex flex-col`,children:[t.kind&&(0,U.jsx)(`span`,{className:`px-2 pt-1 text-[11px] font-medium tracking-wide text-muted-foreground uppercase`,children:r(`cards.k.${t.kind}`)}),(0,U.jsx)(P,{tx:t,names:_,account:e})]},t.id))}),c.transactions.length===0&&(0,U.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:r(`tx.emptyFiltered`)})]})})]})})}function G({value:e,max:t,label:n}){let r=t>0?Math.min(1,e/t):0;return(0,U.jsx)(`div`,{role:`progressbar`,"aria-label":n,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(r*100),className:`h-2 w-full rounded-full bg-muted`,children:(0,U.jsx)(`div`,{className:`h-2 rounded-full bg-[var(--chart-1)]`,style:{width:`${Math.max(r?2:0,r*100)}%`}})})}function K({d:e,asOf:t}){let{t:n,lang:r}=l(),i=e.summary?.current,a=e.terms.statementDay,o=e.account.id;return(0,U.jsx)(D,{title:n(`cards.currentPeriod`),children:i?(0,U.jsxs)(`dl`,{className:`divide-y`,children:[(0,U.jsx)(T,{label:n(`cards.purchasesSoFar`),children:(0,U.jsx)(w,{filter:{account:o,from:i.from,to:t},className:`font-medium`,children:(0,U.jsx)(E,{amount:i.purchases})})}),a&&(0,U.jsxs)(T,{label:n(`cards.closesOn`),children:[S(z(t,a),r),` · `,(0,U.jsx)(`span`,{className:`text-muted-foreground`,children:n(`cards.daysLeft`,{n:R(t,a)})})]}),e.payByToday&&(0,U.jsxs)(T,{label:n(`cards.payByToday`),children:[(0,U.jsx)(`span`,{className:`font-medium`,children:S(e.payByToday,r)}),` · `,(0,U.jsx)(`span`,{className:`text-muted-foreground`,children:n(`cards.daysLeft`,{n:x(t,e.payByToday)})})]})]}):(0,U.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:n(a?`cards.noActivity`:`cards.noStatementDay`)})})}function q({s:e,id:t,asOf:n}){let{t:r,lang:i}=l();return(0,U.jsx)(D,{title:e?r(`cards.statementOf`,{date:S(e.close,i)}):r(`cards.lastStatement`),action:e?(0,U.jsx)(O,{status:e.status}):void 0,children:e?(0,U.jsxs)(`dl`,{className:`divide-y`,children:[(0,U.jsx)(T,{label:r(`cards.amountDue`),children:(0,U.jsx)(w,{filter:{account:t,from:e.from,to:e.close},className:`text-lg font-semibold`,children:(0,U.jsx)(E,{amount:e.amountDue})})}),e.due&&(0,U.jsxs)(T,{label:r(`cards.dueDate`),children:[S(e.due,i),` `,e.toPay>0&&(0,U.jsx)(M,{days:x(n,e.due),className:`ml-1`})]}),(0,U.jsx)(T,{label:r(`cards.paid`),children:(0,U.jsx)(w,{filter:{account:t,from:C(e.close,1),to:n},children:(0,U.jsx)(E,{amount:e.paid})})}),(0,U.jsx)(T,{label:r(`cards.toPay`),className:`font-medium`,children:(0,U.jsx)(E,{amount:e.toPay})}),e.deferred>0&&(0,U.jsx)(T,{label:r(`cards.deferred`),children:(0,U.jsx)(E,{amount:e.deferred})}),e.bank!==null&&(0,U.jsxs)(T,{label:r(`cards.bankAmount`),children:[(0,U.jsx)(E,{amount:e.bank}),e.bankDiff!==null&&e.bankDiff!==0&&(0,U.jsx)(`span`,{className:`block text-xs text-warning`,children:r(`cards.bankDiff`,{amount:`${e.bankDiff>0?`+`:`−`}${y(Math.abs(e.bankDiff),i)}`})})]})]}):(0,U.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:r(`cards.noClosed`)})})}function J({list:e,onOpen:n}){let{t:r,lang:i}=l();return(0,U.jsx)(D,{title:r(`cards.history`),children:e.length===0?(0,U.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:r(`cards.noHistory`)}):(0,U.jsx)(`ul`,{className:`-mx-2 flex flex-col divide-y`,children:e.map(e=>(0,U.jsx)(`li`,{children:(0,U.jsxs)(`button`,{type:`button`,onClick:()=>n(e.close),className:`flex min-h-12 w-full items-center gap-3 rounded-md px-2 py-1.5 text-left outline-none hover:bg-muted/50 focus-visible:ring-3 focus-visible:ring-ring/50`,children:[(0,U.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,U.jsx)(`span`,{className:`truncate text-sm font-medium`,children:e.open?r(`cards.currentPeriod`):S(e.close,i)}),(0,U.jsxs)(`span`,{className:`truncate text-xs text-muted-foreground`,children:[S(e.from,i,{day:`2-digit`,month:`2-digit`}),` – `,S(e.close,i,{day:`2-digit`,month:`2-digit`}),` · `,r(`cards.purchasesShort`),` `,(0,U.jsx)(E,{amount:e.purchases,mode:`short`})]})]}),(0,U.jsxs)(`span`,{className:`flex shrink-0 flex-col items-end`,children:[(0,U.jsx)(E,{amount:e.open?e.closing:e.amountDue,mode:`short`,className:`text-sm font-medium`}),!e.open&&(0,U.jsx)(O,{status:e.status})]}),(0,U.jsx)(t,{className:`size-4 shrink-0 text-muted-foreground`,"aria-hidden":!0})]})},e.close))})})}function Y({d:e}){let{t,lang:n}=l(),r=e.summary?.cashback??null,i=(0,H.useMemo)(()=>[...e.cashback].filter(e=>!e.open).reverse().slice(-12),[e.cashback]).map(e=>({ym:e.close,label:_(e.close.slice(0,7)),expected:e.expected,received:e.received}));return!e.terms.cashback&&!e.cashback.some(e=>e.expected>0||e.received>0)?(0,U.jsxs)(D,{title:t(`cards.cashback`),children:[(0,U.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t(`cards.noCashback`)}),(0,U.jsx)(d,{prompt:t(`ask.cardTerms`,{name:e.account.name,list:t(`cards.missing.cashback_rates`)})})]}):(0,U.jsxs)(D,{title:t(`cards.cashback`),children:[r&&(0,U.jsxs)(`dl`,{className:`divide-y`,children:[(0,U.jsx)(T,{label:t(`cards.spendThisPeriod`),children:(0,U.jsx)(w,{filter:{account:e.account.id,from:r.from,to:r.close},children:(0,U.jsx)(E,{amount:r.spend})})}),(0,U.jsx)(T,{label:t(`cards.expected`),children:r.incomplete?(0,U.jsx)(`span`,{className:`text-warning`,children:t(`cards.rateNotSet`)}):(0,U.jsx)(E,{amount:r.expected,className:`font-medium`})}),r.cap!==null&&r.capLeft!==null&&(0,U.jsxs)(T,{label:t(`cards.capLeftLabel`),children:[(0,U.jsx)(E,{amount:r.capLeft}),` `,(0,U.jsxs)(`span`,{className:`text-muted-foreground`,children:[`/ `,(0,U.jsx)(E,{amount:r.cap,mode:`short`})]})]})]}),r&&r.minSpend!==null&&(0,U.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,U.jsx)(G,{value:r.spend,max:r.minSpend,label:t(`cards.minSpend`)}),(0,U.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r.minMet?t(`cards.minMet`,{amount:y(r.minSpend,n)}):t(`cards.minNeed`,{amount:y(r.needForMin,n),min:y(r.minSpend,n)})})]}),i.length>0&&(0,U.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,U.jsx)(`p`,{className:`text-xs font-medium text-muted-foreground`,children:t(`cards.last12`)}),(0,U.jsx)(`div`,{className:`flex h-40 flex-col`,children:(0,U.jsx)(L,{legend:[{label:t(`cards.earned`),color:F.accent},{label:t(`cards.expected`),color:F.second}],table:{head:[t(`chart.month`),t(`cards.earned`),t(`cards.expected`)],rows:i.map(e=>[e.label,y(e.received,n),y(e.expected,n)])},children:(0,U.jsx)(I,{data:i,xKey:`label`,series:[{key:`received`,label:t(`cards.earned`),color:F.accent},{key:`expected`,label:t(`cards.expected`),color:F.second}]})})})]})]})}function X({d:e,asOf:t}){let{t:n,lang:r}=l(),i=e.feeWaiver;return!i&&!e.terms.annualFee?null:(0,U.jsx)(D,{title:n(`cards.feeWaiver`),children:i?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(G,{value:i.spent,max:i.target,label:n(`cards.feeWaiver`)}),(0,U.jsxs)(`dl`,{className:`divide-y`,children:[(0,U.jsxs)(T,{label:n(`cards.spent`),children:[(0,U.jsx)(w,{filter:{account:e.account.id,from:i.yearFrom,to:t},children:(0,U.jsx)(E,{amount:i.spent})}),` `,(0,U.jsxs)(`span`,{className:`text-muted-foreground`,children:[`/ `,(0,U.jsx)(E,{amount:i.target,mode:`short`})]})]}),(0,U.jsxs)(T,{label:n(`cards.deadline`),children:[S(i.deadline,r),` `,(0,U.jsxs)(`span`,{className:`text-muted-foreground`,children:[`· `,n(`cards.daysLeft`,{n:i.daysLeft})]})]}),!i.met&&(0,U.jsx)(T,{label:n(`cards.perMonth`),children:(0,U.jsx)(E,{amount:i.perMonth})}),e.terms.annualFee?(0,U.jsx)(T,{label:n(`cards.annualFee`),children:(0,U.jsx)(E,{amount:e.terms.annualFee})}):null]}),(0,U.jsx)(`p`,{className:a(`text-sm font-medium`,i.met||i.onTrack?`text-foreground`:`text-critical`),children:i.met?n(`cards.feeMet`):i.onTrack?n(`cards.onTrack`):n(`cards.behind`)})]}):(0,U.jsxs)(`dl`,{children:[(0,U.jsx)(T,{label:n(`cards.annualFee`),children:(0,U.jsx)(E,{amount:e.terms.annualFee})}),(0,U.jsx)(`p`,{className:`py-1 text-sm text-muted-foreground`,children:n(`cards.noWaiver`)})]})})}function Z({d:e}){let{t}=l();return e.instalments.length===0?null:(0,U.jsx)(D,{title:t(`cards.instalments`),children:(0,U.jsx)(`ul`,{className:`flex flex-col gap-3`,children:e.instalments.map(e=>(0,U.jsxs)(`li`,{className:`flex flex-col gap-1`,children:[(0,U.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2 text-sm`,children:[(0,U.jsx)(w,{filter:{plan:e.plan},className:`min-w-0 truncate font-medium`,children:e.name}),(0,U.jsxs)(`span`,{className:`shrink-0 text-xs text-muted-foreground tabular-nums`,children:[e.paidCount,`/`,e.count??`–`]})]}),(0,U.jsx)(G,{value:e.paidCount,max:e.count??0,label:e.name}),(0,U.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[t(`cards.perMonthPay`),` `,(0,U.jsx)(E,{amount:e.perPayment,mode:`short`}),e.leftAmount!==null&&(0,U.jsxs)(U.Fragment,{children:[` · `,t(`cards.left`),` `,(0,U.jsx)(E,{amount:e.leftAmount,mode:`short`})]})]})]},e.plan))})})}function Q({d:e}){let{t,lang:n}=l(),r=e.record;if(!r)return(0,U.jsxs)(D,{title:t(`cards.lifecycle`),children:[(0,U.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t(`cards.noRecord`)}),(0,U.jsx)(d,{prompt:t(`ask.cardRecord`,{name:e.account.name})})]});let i=e=>e?S(e,n):null,a=[[t(`cards.issued`),i(r.issued)],[t(`cards.activated`),i(r.activated)],[t(`cards.lockedOn`),i(r.locked)],[t(`cards.cancelledOn`),i(r.cancelled)],[t(`cards.network`),r.network?r.network.toUpperCase():null],[t(`cards.form`),r.physical?t(`cards.physical.${r.physical}`):null]];return(0,U.jsxs)(D,{title:t(`cards.lifecycle`),action:(0,U.jsx)(A,{status:r.status??`active`}),children:[(0,U.jsxs)(`dl`,{className:`divide-y`,children:[a.filter(([,e])=>e).map(([e,t])=>(0,U.jsx)(T,{label:e,children:t},e)),r.annual_fee?(0,U.jsx)(T,{label:t(`cards.annualFee`),children:(0,U.jsx)(E,{amount:r.annual_fee})}):null,r.close_fee?(0,U.jsx)(T,{label:t(`cards.closeFee`),children:(0,U.jsx)(E,{amount:r.close_fee})}):null,r.keep_for_limit&&(0,U.jsx)(T,{label:t(`cards.keepForLimit`),children:t(`cards.yes`)})]}),r.cancel_plan&&(0,U.jsxs)(`div`,{className:`rounded-md bg-muted/60 p-3 text-sm`,children:[(0,U.jsx)(`p`,{className:`font-medium`,children:t(`cards.cancelPlan`,{by:r.cancel_plan.by??``})}),r.cancel_plan.note&&(0,U.jsx)(`p`,{className:`text-muted-foreground`,children:r.cancel_plan.note})]}),r.note&&(0,U.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:r.note})]})}function $({d:e}){let{t}=l(),n=e.value;return n?(0,U.jsx)(D,{title:t(`cards.netValue`),children:(0,U.jsxs)(`dl`,{className:`divide-y`,children:[(0,U.jsx)(T,{label:t(`cards.value.benefits`),children:(0,U.jsx)(E,{amount:n.benefits})}),(0,U.jsx)(T,{label:t(`cards.cashback`),children:(0,U.jsx)(E,{amount:n.cashback})}),(0,U.jsx)(T,{label:n.feesFrom===`record`?`${t(`cards.value.fees`)} (${t(`cards.value.estimated`)})`:t(`cards.value.fees`),children:(0,U.jsx)(E,{amount:-n.fees})}),n.closeFee>0&&(0,U.jsx)(T,{label:t(`cards.closeFee`),children:(0,U.jsx)(E,{amount:-n.closeFee})}),(0,U.jsx)(T,{label:t(`cards.value.sinceIssued`),className:`font-medium`,children:(0,U.jsx)(E,{amount:n.net,tone:`auto`})}),(0,U.jsx)(T,{label:t(`cards.value.last12`),className:`font-medium`,children:(0,U.jsx)(E,{amount:n.last12.net,tone:`auto`})})]})}):null}function ee({params:e}){let{t}=l(),n=decodeURIComponent(e.account),{data:r,error:i,isLoading:a}=c(n),[o,s]=(0,H.useState)(null),d=(0,U.jsxs)(`a`,{href:`#/cards`,className:`inline-flex min-h-11 items-center gap-1 self-start rounded-md text-sm text-muted-foreground outline-none hover:text-foreground focus-visible:ring-3 focus-visible:ring-ring/50`,children:[(0,U.jsx)(V,{className:`size-4`,"aria-hidden":!0}),t(`cards.back`)]});if(i)return(0,U.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[d,(0,U.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:i instanceof u&&i.status===404?t(`cards.notFound`):t(`common.error`,{message:i.message})})]});if(a||!r)return(0,U.jsxs)(`div`,{className:`flex flex-col gap-3`,"aria-busy":`true`,children:[d,(0,U.jsx)(h,{className:`h-8 w-56`}),(0,U.jsx)(h,{className:`h-40 w-full`})]});let f=r.summary,p=r.record?.status??(r.account.closed?`cancelled`:`active`),m=r.terms.last4,g=[r.terms.bank,m?t(`cards.last4`,{n:m}):null].filter(Boolean).join(` · `);return(0,U.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[d,(0,U.jsxs)(`header`,{className:`flex flex-col gap-2`,children:[(0,U.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,U.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:r.account.name}),(0,U.jsx)(A,{status:p})]}),g&&(0,U.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:g}),f&&(0,U.jsx)(j,{owed:f.owed,limit:f.limit,atLeast:f.limitAtLeast,className:`max-w-md`}),f&&(0,U.jsx)(k,{card:f,className:`max-w-md`})]}),(0,U.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-[minmax(0,1fr)_22rem]`,children:[(0,U.jsx)(`div`,{className:`flex min-w-0 flex-col gap-4`,children:f?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(K,{d:r,asOf:r.asOf}),(0,U.jsx)(q,{s:f.last,id:r.account.id,asOf:r.asOf}),(0,U.jsx)(J,{list:r.statements,onOpen:s})]}):(0,U.jsx)(D,{title:t(`cards.statements`),children:(0,U.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t(`cards.noStatements`)})})}),(0,U.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4`,children:[(0,U.jsx)(Y,{d:r}),(0,U.jsx)(X,{d:r,asOf:r.asOf}),(0,U.jsx)(Z,{d:r}),(0,U.jsx)(Q,{d:r}),(0,U.jsx)($,{d:r})]})]}),(0,U.jsx)(W,{account:r.account.id,close:o,onClose:()=>s(null)})]})}export{ee as default};
@@ -1 +0,0 @@
1
- import{t as e}from"./createLucideIcon-XZ28znwT.js";var t={name:`chevron-down`,size:24,node:[[`path`,{d:`m6 9 6 6 6-6`,key:`qrunsl`}]]};t.node;var n=e(t);export{n as t};
@@ -1 +0,0 @@
1
- import{t as e}from"./createLucideIcon-XZ28znwT.js";var t={name:`chevron-right`,size:24,node:[[`path`,{d:`m9 18 6-6-6-6`,key:`mthhwq`}]]};t.node;var n=e(t);export{n as t};