@actual-app/web 23.8.0 → 23.8.1

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.
@@ -0,0 +1,2 @@
1
+ (self.webpackChunk_actual_app_web=self.webpackChunk_actual_app_web||[]).push([[162],{91836:function(e,t,n){"use strict";n.d(t,{Z:function(){return s}});n(83017);var o=n(83679),i=n(28993);function s(e){let{width:t,onClose:n,children:s}=e;return(0,i.jsx)(o.u,{position:"bottom-right",width:t,style:{padding:0},onClose:n,children:s})}},98030:function(e,t,n){"use strict";n.d(t,{M:function(){return F},L:function(){return D}});var o=n(83017),i=n(71274),s=n(27876),a=n(3189),r=n(48664),l=n(45249),d=n(26018),c=n(97156),u=n(24917),h=n(80837),p=n(69585),g=n(28091),f=n(28993);var y=e=>(0,f.jsx)("svg",{...e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",style:{color:"inherit",...e.style},children:(0,f.jsx)("path",{fill:"currentColor",d:"M4.5 17.5h6.646a3.5 3.5 0 0 0 6.708 0H19.5a1 1 0 0 0 0-2h-1.646a3.5 3.5 0 0 0-6.708 0H4.5a1 1 0 0 0 0 2Zm10-2.5a1.5 1.5 0 1 1 0 3 1.5 1.5 0 0 1 0-3ZM19.5 6.5h-6.646a3.5 3.5 0 0 0-6.708 0H4.5a1 1 0 0 0 0 2h1.646a3.5 3.5 0 0 0 6.708 0H19.5a1 1 0 1 0 0-2ZM9.5 9a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3Z"})}),m=n(53819),x=n(13743),w=n(18999),v=n(61947),j=n(99884),C=n(10666),b=n(91743),S=n(10945),Z=n(83679),A=n(99446),k=n(58130);let M=["date","account","payee","notes","category","amount","cleared","saved"].map((e=>[e,(0,h.gL)(e)]));function T(e){let{field:t,options:n,value:o}=e;if("date"===t){if(7===o.length)return"month";if(4===o.length)return"year"}else if("amount"===t){if(n&&n.inflow)return"amount-inflow";if(n&&n.outflow)return"amount-outflow"}return t}function O(e,t){switch(e){case"amount":switch(t){case"amount-inflow":return{inflow:!0};case"amount-outflow":return{outflow:!0};default:return null}case"date":switch(t){case"month":return{month:!0};case"year":return{year:!0};default:return null}default:return null}}function I(e){let{op:t,selected:n,style:o,onClick:i}=e;return(0,f.jsx)(x.Z,{type:"bare",style:[{backgroundColor:m.O9.pK,marginBottom:5},o,n&&{color:"white","&,:hover,:active":{backgroundColor:m.O9.b4}}],onClick:i,children:(0,h.w8)(t)})}function B(e,t){switch(t.type){case"set-op":{let n=h.Z9.get(e.field),o=e.value;return"id"!==n&&"string"!==n||"contains"!==t.op&&"is"!==t.op&&"doesNotContain"!==t.op&&"isNot"!==t.op||(o=null),{...e,op:t.op,value:o}}case"set-value":{let{value:n}=(0,h.l1)(t.value,{type:h.Z9.get(e.field)});return{...e,value:n}}default:throw new Error(`Unhandled action type: ${t.type}`)}}function R(e){let{field:t,initialSubfield:n=t,op:i,value:a,dispatch:r,onApply:l}=e,[d,c]=(0,o.useState)(n),u=(0,o.useRef)(),g=(0,o.useRef)(null);(0,o.useEffect)((()=>{g.current!==i&&u.current&&u.current.focus(),g.current=i}),[i]);let y=h.Z9.get(t),w=h.wZ[y].ops.filter((e=>"isbetween"!==e));return"month"!==d&&"year"!==d||(w=["is"]),(0,f.jsx)(Z.u,{position:"bottom-left",style:{padding:15},width:275,onClose:()=>r({type:"close"}),children:(0,f.jsxs)(s.MT,{children:[(0,f.jsx)(b.Z,{style:{marginBottom:10},children:"amount"===t||"date"===t?(0,f.jsx)(v.Z,{options:"amount"===t?[["amount","Amount"],["amount-inflow","Amount (inflow)"],["amount-outflow","Amount (outflow)"]]:"date"===t?[["date","Date"],["month","Month"],["year","Year"]]:null,value:d,onChange:e=>{c(e),"month"!==e&&"year"!==e||r({type:"set-op",op:"is"})},style:{borderWidth:1}}):(0,p.VL)((0,h.gL)(t))}),(0,f.jsx)(b.Z,{style:{color:m.O9.n4,marginBottom:10},children:"saved"===t&&"Existing filters will be cleared"}),(0,f.jsx)(j.Z,{direction:"row",align:"flex-start",spacing:1,style:{flexWrap:"wrap"},children:"boolean"===y?[(0,f.jsx)(I,{op:"true",selected:!0===a,onClick:()=>{r({type:"set-op",op:"is"}),r({type:"set-value",value:!0})}},"true"),(0,f.jsx)(I,{op:"false",selected:!1===a,onClick:()=>{r({type:"set-op",op:"is"}),r({type:"set-value",value:!1})}},"false")]:[(0,f.jsx)(j.Z,{direction:"row",align:"flex-start",spacing:1,style:{flexWrap:"wrap"},children:w.slice(0,3).map((e=>(0,f.jsx)(I,{op:e,selected:e===i,onClick:()=>r({type:"set-op",op:e})},e)))}),(0,f.jsx)(j.Z,{direction:"row",align:"flex-start",spacing:1,style:{flexWrap:"wrap"},children:w.slice(3,w.length).map((e=>(0,f.jsx)(b.Z,{children:(0,f.jsx)(I,{op:e,selected:e===i,onClick:()=>r({type:"set-op",op:e})},e)})))})]}),(0,f.jsxs)("form",{action:"#",children:["boolean"!==y&&(0,f.jsx)(A.Z,{inputRef:u,field:t,subfield:d,type:"id"!==y||"contains"!==i&&"doesNotContain"!==i?y:"string",value:a,multi:"oneOf"===i||"notOneOf"===i,style:{marginTop:10},onChange:e=>r({type:"set-value",value:e})}),(0,f.jsxs)(j.Z,{direction:"row",justify:"flex-end",align:"center",style:{marginTop:15},children:[(0,f.jsx)(b.Z,{style:{flex:1}}),(0,f.jsx)(x.Z,{type:"primary",onClick:e=>{e.preventDefault(),l({field:t,op:i,value:a,options:O(t,d)})},children:"Apply"})]})]})]})})}function D(e){let{onApply:t}=e,n=(0,d.m)(),{dateFormat:s}=(0,i.v9)((e=>({dateFormat:e.prefs.local.dateFormat||"MM/dd/yyyy"}))),[g,m]=(0,o.useReducer)(((e,t)=>{switch(t.type){case"select-field":return{...e,fieldsOpen:!0,condOpen:!1};case"configure":{let{field:n}=(0,h.Z)(t.field),o=h.Z9.get(n),i=h.wZ[o].ops;return{...e,fieldsOpen:!1,condOpen:!0,field:t.field,op:i[0],value:"boolean"===o||null}}case"close":return{fieldsOpen:!1,condOpen:!1,value:null};default:return B(e,t)}}),{fieldsOpen:!1,condOpen:!1,field:null,value:null});return(0,f.jsxs)(b.Z,{children:[(0,f.jsxs)(x.Z,{type:"bare",onClick:()=>m({type:"select-field"}),children:[(0,f.jsx)(y,{style:{width:16,height:16,marginRight:5}})," ","Filter"]}),g.fieldsOpen&&(0,f.jsx)(Z.u,{position:"bottom-left",style:{padding:0},onClose:()=>m({type:"close"}),children:(0,f.jsx)(w.Z,{onMenuSelect:e=>{m({type:"configure",field:e})},items:M.map((e=>{let[t,n]=e;return{name:t,text:(0,p.VL)(n)}}))})}),g.condOpen&&(0,f.jsx)(R,{field:g.field,op:g.op,value:g.value,dispatch:m,onApply:async function(e){if("date"===(e=(0,h.Z2)({...e,type:h.Z9.get(e.field)})).type&&e.options)if(e.options.month){let t=(0,a.Z)(e.value,(0,u.LT)(s),new Date);if(!(0,r.Z)(t))return void alert("Invalid date format");e.value=(0,l.Z)(t,"yyyy-MM")}else if(e.options.year){let t=(0,a.Z)(e.value,"yyyy",new Date);if(!(0,r.Z)(t))return void alert("Invalid date format");e.value=(0,l.Z)(t,"yyyy")}let{error:o}="saved"!==e.field&&await(0,c.lW)("rule-validate",{conditions:[e],actions:[]}),i=n.find((t=>e.value===t.id));if(o&&o.conditionErrors.length>0){let t=(0,p.VL)((0,h.gL)(e.field));alert(t+": "+(0,h.zQ)(o.conditionErrors[0]))}else t(i||e),m({type:"close"})}})]})}function E(e){let{field:t,op:n,value:i,options:s,onSave:a,onClose:r}=e,[l,d]=(0,o.useReducer)(((e,t)=>"close"===t.type?(r(),e):B(e,t)),{field:t,op:n,value:i,options:s});return(0,f.jsx)(R,{field:l.field,initialSubfield:T({field:t,options:s,value:i}),op:l.op,value:l.value,options:l.options,dispatch:d,onApply:e=>{a(e),r()}})}function N(e){let{field:t,customName:n,op:i,value:s,options:a,stage:r,style:l,onChange:d,onDelete:c}=e,[u,p]=(0,o.useState)(!1),y=T({field:t,value:s});return(0,f.jsxs)(b.Z,{style:[{backgroundColor:m.O9.n9,borderRadius:4,flexDirection:"row",alignItems:"center",marginRight:10,marginTop:10},l],children:[(0,f.jsx)(x.Z,{type:"bare",disabled:null!=n,onClick:()=>p(!0),style:{marginRight:-7},children:(0,f.jsx)("div",{style:{paddingBlock:1,paddingLeft:5,paddingRight:2},children:n?(0,f.jsx)(C.Z,{style:{color:m.O9.p4},children:n}):(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(C.Z,{style:{color:m.O9.p4},children:(0,h.gL)(y,a)})," ",(0,f.jsx)(C.Z,{style:{color:m.O9.n3},children:(0,h.w8)(i,null)})," ",(0,f.jsx)(S.B,{value:s,field:y,inline:!0,valueIsRaw:"contains"===i||"doesNotContain"===i})]})})}),(0,f.jsx)(x.Z,{type:"bare",onClick:c,children:(0,f.jsx)(g.Z,{style:{width:8,height:8,margin:5,marginLeft:3}})}),u&&(0,f.jsx)(E,{field:t,customName:n,op:i,value:s,options:a,stage:r,onSave:d,onClose:()=>p(!1)})]})}function F(e){let{filters:t,editingFilter:n,onUpdate:o,onDelete:i,conditionsOp:s,onCondOpChange:a}=e;return(0,f.jsxs)(b.Z,{style:{flexDirection:"row",alignItems:"flex-start",flexWrap:"wrap"},children:[(0,f.jsx)(k.a,{conditionsOp:s,onCondOpChange:a,filters:t}),t.map(((e,t)=>(0,f.jsx)(N,{customName:e.customName,field:e.field,op:e.op,value:e.value,options:e.options,editing:n===e,onChange:t=>o(e,t),onDelete:()=>i(e)},t)))]})}},58130:function(e,t,n){"use strict";n.d(t,{O:function(){return v},a:function(){return w}});var o=n(83017),i=n(97156),s=n(89220),a=n(53819),r=n(13743),l=n(18999),d=n(91836),c=n(99884),u=n(10666),h=n(91743),p=n(36717),g=n(97117),f=n(99446),y=n(98030),m=n(28993);function x(e){let t,n,{filters:g,conditionsOp:y,filterId:x,onClearFilters:w,onReloadSavedFilter:v,filtersList:j}=e,[C,b]=(0,o.useState)(!1),[S,Z]=(0,o.useState)(!1),[A,k]=(0,o.useState)(!1),[M,T]=(0,o.useState)(null),[O,I]=(0,o.useState)(null),B=(0,o.useRef)(),R=x.name,D=x.id;(0,o.useEffect)((()=>{B.current&&B.current.focus()}),[F]);const E=async e=>{switch(I(e),e){case"rename-filter":T(null),Z(!1),k(!1),b(!0);break;case"delete-filter":k(!1),await(0,i.lW)("filter-delete",D),w();break;case"update-filter":T(null),Z(!1),k(!1),n={conditions:g,conditionsOp:y,id:x.id,name:x.name,status:"saved"},t=await(0,i.OK)("filter-update",{state:n,filters:[...j]}),t.error?(T(t.error.message),b(!0)):v(n,"update");break;case"save-filter":T(null),Z(!0),k(!1),b(!0);break;case"reload-filter":k(!1),n={status:"saved"},v(n,"reload");break;case"clear-filter":k(!1),w()}};function N(e){let{onClose:t,filterId:n}=e;return(0,m.jsx)(d.Z,{width:200,onClose:t,children:(0,m.jsx)(l.Z,{onMenuSelect:e=>{E(e)},items:[...n.id?[...null!==n.id&&"saved"===n.status?[{name:"rename-filter",text:"Rename"},{name:"delete-filter",text:"Delete"},l.Z.line,{name:"save-filter",text:"Save new filter",disabled:!0},{name:"clear-filter",text:"Clear all conditions"}]:[{name:"rename-filter",text:"Rename"},{name:"update-filter",text:"Update condtions"},{name:"reload-filter",text:"Revert changes"},{name:"delete-filter",text:"Delete"},l.Z.line,{name:"save-filter",text:"Save new filter"},{name:"clear-filter",text:"Clear all conditions"}]]:[{name:"save-filter",text:"Save new filter"},{name:"clear-filter",text:"Clear all conditions"}]]})})}function F(e){let{onClose:o}=e;return(0,m.jsxs)(d.Z,{width:325,onClose:o,children:["update-filter"!==O&&(0,m.jsx)("form",{children:(0,m.jsxs)(c.Z,{direction:"row",justify:"flex-end",align:"center",style:{padding:10},children:[(0,m.jsxs)(p.Wi,{style:{flex:1},children:[(0,m.jsx)(p.lX,{title:"Filter Name",htmlFor:"name-field",style:{userSelect:"none"}}),(0,m.jsx)(f.Z,{inputRef:B,id:"name-field",field:"string",type:"string",value:R,onChange:e=>R=e})]}),(0,m.jsx)(r.Z,{type:"primary",style:{marginTop:18},onClick:e=>{e.preventDefault(),async function(){S?(n={conditions:g,conditionsOp:y,name:R,status:"saved"},t=await(0,i.OK)("filter-create",{state:n,filters:[...j]}),n={...n,id:t.data}):(n={conditions:x.conditions,conditionsOp:x.conditionsOp,id:x.id,name:R},t=await(0,i.OK)("filter-update",{state:n,filters:[...j]})),t.error?T(t.error.message):(b(!1),v(n))}()},children:S?"Add":"Update"})]})}),M&&(0,m.jsx)(c.Z,{direction:"row",align:"center",style:{padding:10},children:(0,m.jsx)(u.Z,{style:{color:a.O9.r4},children:M})})]})}return(0,m.jsxs)(h.Z,{children:[g.length>0&&(0,m.jsxs)(r.Z,{type:"bare",style:{marginTop:10},onClick:()=>{k(!0)},children:[(0,m.jsxs)(u.Z,{style:{maxWidth:150,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",flexShrink:0},children:[x.id?x.name:"Unsaved filter","\xa0"]}),x.id&&"saved"!==x.status&&(0,m.jsx)(u.Z,{children:"(modified)\xa0"}),(0,m.jsx)(s.Z,{width:8,height:8,style:{marginRight:5}})]}),A&&(0,m.jsx)(N,{onClose:()=>k(!1),filterId:x}),C&&(0,m.jsx)(F,{onClose:()=>b(!1)})]})}function w(e){let{conditionsOp:t,onCondOpChange:n,filters:o}=e;return o.length>1&&(0,m.jsxs)(u.Z,{style:{color:a.O9.n4,marginTop:11,marginRight:5},children:[(0,m.jsx)(g.Wy,{style:{display:"inline-flex"},fields:[["and","all"],["or","any"]],value:t,onChange:(e,t)=>n(t,o)}),"of:"]})}function v(e){let{filters:t,conditionsOp:n,onUpdateFilter:o,onDeleteFilter:i,onClearFilters:s,onReloadSavedFilter:a,filterId:r,filtersList:l,onCondOpChange:d}=e;return(0,m.jsx)(h.Z,{children:(0,m.jsxs)(c.Z,{spacing:2,direction:"row",justify:"flex-start",align:"flex-start",children:[(0,m.jsx)(y.M,{filters:t,conditionsOp:n,onCondOpChange:d,onUpdate:o,onDelete:i}),(0,m.jsx)(h.Z,{style:{flex:1}}),(0,m.jsx)(x,{filters:t,conditionsOp:n,filterId:r,onClearFilters:s,onReloadSavedFilter:a,filtersList:l})]})})}},8821:function(e,t,n){"use strict";n.r(t),n.d(t,{Account:function(){return Zo},Accounts:function(){return Zo},Budget:function(){return St},DiscoverSchedules:function(){return sn},EditSchedule:function(){return Jt},GoCardlessLink:function(){return rn},LinkSchedule:function(){return en},Schedules:function(){return _t}});var o={};n.r(o),n.d(o,{BudgetSummary:function(){return He},BudgetTotalsMonth:function(){return ze},CategoryMonth:function(){return Qe},ExpenseCategoryMonth:function(){return qe},ExpenseGroupMonth:function(){return Xe},GroupMonth:function(){return $e},IncomeCategoryMonth:function(){return Je},IncomeGroupMonth:function(){return Ye},IncomeHeaderMonth:function(){return Ke}});var i={};n.r(i),n.d(i,{BudgetSummary:function(){return ut},BudgetTotalsMonth:function(){return ft},ExpenseCategoryMonth:function(){return xt},ExpenseGroupMonth:function(){return mt},IncomeCategoryMonth:function(){return vt},IncomeGroupMonth:function(){return wt},IncomeHeaderMonth:function(){return yt}});var s=n(83017),a=n(71274),r=n(79274),l=n(62914),d=n(97156),c=n(58155),u=n(24917),h=n(43045),p=n(59831),g=n(53819),f=n(91743),y=n(79291),m=n(22644),x=n(97931),w=n(89220),v=n(61563),j=n(97800),C=n(13743),b=n(18999),S=n(10666),Z=n(86634),A=n(99121),k=n(84214),M=n(28993);var T=e=>(0,M.jsx)("svg",{...e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 19 24",style:{color:"inherit",...e.style},children:(0,M.jsx)("path",{fill:"currentColor",d:"M17 24H2a2 2 0 0 1-2-2V2a2 2 0 0 1 2-2h9a1 1 0 0 1 .707.293l7 7A1 1 0 0 1 19 8v14a2 2 0 0 1-2 2ZM2 21.5a.5.5 0 0 0 .5.5h14a.5.5 0 0 0 .5-.5V9a.5.5 0 0 0-.5-.5h-4a2 2 0 0 1-2-2v-4A.5.5 0 0 0 10 2H2.5a.5.5 0 0 0-.5.5v19Z"})}),O=n(83679);function I(e){let{editable:t,defaultNotes:n,position:o="bottom-left",onClose:i}=e,[a,r]=(0,s.useState)(n),l=(0,s.createRef)();return(0,s.useEffect)((()=>{t&&l.current.focus()}),[l,t]),(0,M.jsx)(O.u,{position:o,onClose:()=>i(a),children:t?(0,M.jsx)("textarea",{ref:l,...(0,Z.iv)({border:"1px solid "+g.O9.Cg,padding:7,minWidth:300,minHeight:120,outline:"none"}),value:a||"",onChange:e=>r(e.target.value)}):(0,M.jsx)(S.Z,{...(0,Z.iv)({display:"block",maxWidth:225,padding:8,whiteSpace:"pre-wrap",overflowWrap:"break-word"}),children:a})})}function B(e){let{id:t,width:n=12,height:o=12,defaultColor:i=g.O9.n8,tooltipPosition:a,style:r}=e,[l,c]=(0,s.useState)(!1),u=(0,O.lL)(),h=(0,k.y)((()=>(0,A.ZP)("notes").filter({id:t}).select("*")),[t]),p=h&&h.length>0?h[0].note:null,y=p&&""!==p;const[m,x]=(0,s.useState)(null),w=u.isOpen||y&&l;return(0,M.jsxs)(f.Z,{style:[{flexShrink:0}],onMouseEnter:()=>{x(setTimeout((()=>{c(!0)}),300))},onMouseLeave:()=>{clearTimeout(m),c(!1)},children:[(0,M.jsx)(C.Z,{type:"bare",className:y||w?"":"hover-visible",style:[{color:i},r,y&&{display:"flex !important"},w&&{color:g.O9.n1}],...u.getOpenEvents(),children:(0,M.jsx)(T,{style:{width:n,height:o}})}),w&&(0,M.jsx)(I,{editable:u.isOpen,defaultNotes:p,position:a,onClose:function(e){(0,d.lW)("notes-save",{id:t,note:e}),u.close()}})]})}var R=n(1317),D=n(7401),E=n(65695),N=n(27807),F=n(99227);function P(e,t,n){return{start:t<e.start?e.start:t,end:n>e.end?e.end:n}}let _=(0,s.createContext)();function W(e){let{startMonth:t,numMonths:n,monthBounds:o,type:i,children:s}=e,a=P(o,t,u.zI(t,n-1)),r=u.Do(a.start,a.end);return(0,M.jsx)(_.Provider,{value:{months:r,type:i},children:s})}function L(e){let{SummaryComponent:t}=e,{months:n}=(0,s.useContext)(_),[o,i]=(0,s.useState)(0),[a,r]=(0,N.q_)((()=>({x:0,config:{mass:3,tension:600,friction:80}}))),l=(0,F.Z)((0,s.useCallback)((e=>{i(e.width)}),[])),d=(0,s.useRef)(n[0]),c=[...n];c.unshift(u.W9(n[0],1)),c.push(u.zI(n[n.length-1],1));let h=o/n.length;return(0,s.useLayoutEffect)((()=>{let e=d.current,t=e>n[0],o=h,i=t?2*-o:0;e!==c[0]&&e!==c[2]&&(i=-o);let s=-o;r.start({from:{x:i},x:s})}),[n[0]]),(0,s.useLayoutEffect)((()=>{d.current=n[0]}),[n[0]]),(0,s.useLayoutEffect)((()=>{r.start({from:{x:-h},to:{x:-h}})}),[h]),(0,M.jsx)("div",{...(0,Z.iv)([{flex:1,overflow:"hidden"},1===n.length&&{marginLeft:-4,marginRight:-4}]),ref:l,children:(0,M.jsx)(N.q.div,{className:"view",style:{flexDirection:"row",width:o,willChange:"transform",transform:a.x.to((e=>`translateX(${e}px)`))},children:c.map((e=>(0,M.jsx)(f.Z,{style:[{flex:`0 0 ${h}px`},{paddingLeft:4,paddingRight:4}],children:(0,M.jsx)(t,{month:e})},e)))})})}const G="0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24)",H=5,U=e=>{let{startMonth:t,numDisplayed:n,monthBounds:o,style:i,onSelect:a}=e;const[r,l]=(0,s.useState)(null),[d,c]=(0,s.useState)(12),h=u.dK(),p=t,y=u.zI(p,n-1),m=u.Do(u.W9(p,d/2-n/2),u.zI(y,d/2-n/2)),x=Math.floor(m.length/2)-Math.floor(n/2),w=x+n-1,[v,j]=(0,s.useState)("small"),C=(0,F.Z)((e=>{j(e.width<=400?"small":"big"),c(Math.min(Math.max(Math.floor(e.width/50),12),24))}));let b=[];return(0,M.jsx)(f.Z,{style:[{flexDirection:"row",alignItems:"center",justifyContent:"space-between"},i],children:(0,M.jsx)(f.Z,{innerRef:C,style:{flexDirection:"row",flex:1,alignItems:"center",justifyContent:"center"},children:m.map(((e,t)=>{const i=u.WU(e,"MMM"),s=t>=x&&t<=w,d=r+n-1,c=null!==r&&(t>=r&&t<=d),p=h===e,y=u.So(e);let m=!1;b.includes(y)||(b.push(y),m=!0);const j=e>=o.start&&e<=o.end;return(0,M.jsxs)(f.Z,{style:[{padding:"3px 3px",width:"big"===v?"35px":"20px",textAlign:"center",userSelect:"none",cursor:"default",borderRadius:2,border:"none"},!j&&{textDecoration:"line-through",color:g.O9.n7},g.W2.smallText,s&&{backgroundColor:g.O9.p6,color:"white"},(c||s)&&{borderRadius:0,cursor:"pointer"},c&&!s&&{backgroundColor:"rgba(100, 100, 100, .15)"},c&&s&&{backgroundColor:g.O9.p7},(t===x||t===r&&!s)&&{borderTopLeftRadius:2,borderBottomLeftRadius:2},(t===w||t===d&&!s)&&{borderTopRightRadius:2,borderBottomRightRadius:2},p&&{fontWeight:"bold"}],onClick:()=>a(e),onMouseEnter:()=>l(t),onMouseLeave:()=>l(null),children:["small"===v?i[0]:i,m&&(0,M.jsx)(f.Z,{style:[{position:"absolute",top:-14,left:0,fontSize:10,fontWeight:"bold",color:j?"#272630":g.O9.n7}],children:y})]},e)}))})})};let z=(0,s.createContext)([]);function K(e){return[{id:"to-be-budgeted",name:"To Be Budgeted",categories:[{id:"to-be-budgeted",name:"To Be Budgeted"}]},...e]}function $(e){return 0===e||"0"===e||""===e?{color:g.O9.pK}:null}function V(e){const t=$(e);return t||(e<0?{color:g.O9.r4}:void 0)}function Q(e){return{color:e<0?g.O9.r4:0===e?g.O9.pK:g.O9.g4}}function X(e,t,n){if("top"===t)return{targetId:n};{let t=e.findIndex((e=>e.id===n));if(-1===t)throw new Error("findSort: item not found: "+n);let o=t+1;return o<e.length-1?{targetId:e[o].id}:{targetId:null}}}function q(){return Math.max(g.W2.scrollbarWidth-2,0)}class Y extends s.Component{constructor(e){var t;super(e),this.onEditMonth=(e,t)=>{this.setState({editing:e?{id:e,cell:t}:null})},this.onEditName=e=>{this.setState({editing:e?{id:e,cell:"name"}:null})},this.onReorderCategory=(e,t,n)=>{let{categoryGroups:o}=this.props;if(!!o.find((e=>e.id===n))){let{targetId:i}=function(e,t,n){if("bottom"===t)return{targetId:n};{let t=e.findIndex((e=>e.id===n));if(-1===t)throw new Error("findSort: item not found: "+n);let o=t-1;return o>=0?{targetId:e[o].id}:{targetId:null}}}(o,t,n),s=o.find((e=>e.id===i));if(s){let{categories:n}=s;this.props.onReorderCategory({id:e,groupId:s.id,targetId:0===n.length||"top"===t?null:n[0].id})}}else{let i;for(let e of o)if(e.categories.find((e=>e.id===n))){i=e;break}this.props.onReorderCategory({id:e,groupId:i.id,...X(i.categories,t,n)})}},this.onReorderGroup=(e,t,n)=>{let{categoryGroups:o}=this.props;this.props.onReorderGroup({id:e,...X(o,t,n)})},this.moveVertically=e=>{let{editing:t}=this.state,{type:n,categoryGroups:o,collapsed:i}=this.props;const s=o.reduce(((e,t)=>i.includes(t.id)?e.concat({id:t.id,isGroup:!0}):e.concat([{id:t.id,isGroup:!0},...t.categories])),[]);if(t){let o=s.findIndex((e=>e.id===t.id))+e;for(;o>=0&&o<s.length;){const i=s[o];if(!i.isGroup){if("report"!==n&&i.is_income)break;return void this.onEditMonth(i.id,t.cell)}o+=e}}},this.onKeyDown=e=>{if(!this.state.editing)return null;"Enter"!==e.key&&"Tab"!==e.key||(e.preventDefault(),this.moveVertically(e.shiftKey?-1:1))},this.onShowActivity=(e,t,n)=>{this.props.onShowActivity(e,t,this.resolveMonth(n))},this.onBudgetAction=(e,t,n)=>{this.props.onBudgetAction(this.resolveMonth(e),t,n)},this.resolveMonth=e=>u.zI(this.props.startMonth,e),this.toggleHiddenCategories=()=>{this.setState((e=>({showHiddenCategories:!e.showHiddenCategories}))),this.props.savePrefs({"budget.showHiddenCategories":!this.state.showHiddenCategories})},this.expandAllCategories=()=>{this.props.setCollapsed([])},this.collapseAllCategories=()=>{let{setCollapsed:e,categoryGroups:t}=this.props;e(t.map((e=>e.id)))},this.budgetCategoriesRef=(0,s.createRef)(),this.state={editing:null,draggingState:null,showHiddenCategories:null!==(t=e.prefs["budget.showHiddenCategories"])&&void 0!==t&&t}}clearEditing(){this.setState({editing:null})}render(){let{type:e,categoryGroups:t,prewarmStartMonth:n,startMonth:o,numMonths:i,monthBounds:s,collapsed:a,setCollapsed:r,newCategoryForGroup:l,dataComponents:d,isAddingGroup:c,onSaveCategory:u,onSaveGroup:h,onDeleteCategory:p,onDeleteGroup:y,onShowNewCategory:m,onHideNewCategory:x,onShowNewGroup:w,onHideNewGroup:v}=this.props,{editing:j,draggingState:C,showHiddenCategories:b}=this.state;return(0,M.jsxs)(f.Z,{"data-testid":"budget-table",style:[{flex:1},g.W2.lightScrollbar&&{"& ::-webkit-scrollbar":{backgroundColor:"transparent"},"& ::-webkit-scrollbar-thumb:vertical":{backgroundColor:"white"}}],children:[(0,M.jsxs)(f.Z,{style:{flexDirection:"row",overflow:"hidden",flexShrink:0,paddingLeft:5,paddingRight:5+q()},children:[(0,M.jsx)(f.Z,{style:{width:200}}),(0,M.jsx)(W,{startMonth:n,numMonths:i,monthBounds:s,type:e,children:(0,M.jsx)(L,{SummaryComponent:d.SummaryComponent})})]}),(0,M.jsxs)(W,{startMonth:o,numMonths:i,monthBounds:s,type:e,children:[(0,M.jsx)(ne,{MonthComponent:d.BudgetTotalsComponent,toggleHiddenCategories:this.toggleHiddenCategories,expandAllCategories:this.expandAllCategories,collapseAllCategories:this.collapseAllCategories}),(0,M.jsx)(O.Hp.Provider,{value:this.budgetCategoriesRef,children:(0,M.jsx)(f.Z,{style:{overflowY:"scroll",overflowAnchor:"none",flex:1,paddingLeft:5,paddingRight:5},innerRef:this.budgetCategoriesRef,children:(0,M.jsx)(f.Z,{style:{opacity:C?.5:1,flexShrink:0},onKeyDown:this.onKeyDown,innerRef:e=>this.budgetDataNode=e,children:(0,M.jsx)(re,{showHiddenCategories:b,categoryGroups:t,newCategoryForGroup:l,isAddingGroup:c,editingCell:j,collapsed:a,setCollapsed:r,dataComponents:d,onEditMonth:this.onEditMonth,onEditName:this.onEditName,onSaveCategory:u,onSaveGroup:h,onDeleteCategory:p,onDeleteGroup:y,onReorderCategory:this.onReorderCategory,onReorderGroup:this.onReorderGroup,onShowNewCategory:m,onHideNewCategory:x,onShowNewGroup:w,onHideNewGroup:v,onBudgetAction:this.onBudgetAction,onShowActivity:this.onShowActivity})})})})]})]})}}function J(e){let{innerRef:t,category:n,dragPreview:o,dragging:i,editing:a,style:r,borderColor:l=g.O9.Cg,isLast:d,onDragChange:c,onEditMonth:u,onEditName:h,onSave:p,onDelete:y,onHideNewCategory:m}=e;const x="new"===n.id,[w,j]=(0,s.useState)(!1),S=(0,M.jsxs)(f.Z,{style:{flexDirection:"row",alignItems:"center",userSelect:"none",WebkitUserSelect:"none",opacity:n.hidden?.33:void 0},children:[(0,M.jsx)("div",{"data-testid":"category-name",style:{textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden",minWidth:0},children:n.name}),(0,M.jsxs)(f.Z,{style:{flexShrink:0,marginLeft:5},children:[(0,M.jsx)(C.Z,{type:"bare",onClick:e=>{e.stopPropagation(),j(!0)},style:{color:"currentColor",padding:3},children:(0,M.jsx)(v.Z,{width:14,height:14,style:{color:"currentColor"}})}),w&&(0,M.jsx)(O.u,{position:"bottom-left",width:200,style:{padding:0},onClose:()=>j(!1),children:(0,M.jsx)(b.Z,{onMenuSelect:e=>{"rename"===e?h(n.id):"delete"===e?y(n.id):"toggleVisibility"===e&&p({...n,hidden:!n.hidden}),j(!1)},items:[{name:"toggleVisibility",text:n.hidden?"Show":"Hide"},{name:"rename",text:"Rename"},{name:"delete",text:"Delete"}]})})]}),(0,M.jsx)(f.Z,{style:{flex:1}}),(0,M.jsx)(B,{id:n.id,style:i&&{color:"currentColor"}})]});return(0,M.jsx)(f.Z,{innerRef:t,style:[{width:200,"& button":{display:"none"}},!i&&!o&&{"&:hover button":{display:"flex",color:g.O9.n1}},i&&{color:g.O9.n8},o&&{backgroundColor:"white",zIndex:1e4,borderRadius:6,overflow:"hidden"},r],onKeyDown:e=>{"Enter"===e.key&&(h(null),e.stopPropagation())},children:(0,M.jsx)(E.F3,{value:n.name,formatter:e=>S,width:"flex",exposed:a||x,borderColor:o?"transparent":l,onUpdate:e=>{x?""===e?m():""!==e&&p({...n,name:e}):e!==n.name&&p({...n,name:e})},onBlur:()=>h(null),style:[{paddingLeft:13},d&&{borderBottomWidth:0}],inputProps:{placeholder:x?"New Category Name":""}})})}function ee(e){let{group:t,editing:n,collapsed:o,dragPreview:i,innerRef:a,style:r,borderColor:l=g.O9.Cg,onEdit:d,onSave:c,onDelete:u,onShowNewCategory:h,onHideNewGroup:p,onToggleCollapse:y}=e;const m="new"===t.id,[x,j]=(0,s.useState)(!1),Z=(0,M.jsxs)(f.Z,{style:{flexDirection:"row",alignItems:"center",userSelect:"none",WebkitUserSelect:"none"},onClick:e=>{y(t.id)},children:[!i&&(0,M.jsx)(w.Z,{width:8,height:8,style:{marginRight:5,marginLeft:5,flexShrink:0,transition:"transform .1s",transform:o?"rotate(-90deg)":""}}),(0,M.jsxs)("div",{style:{textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden",minWidth:0},children:[i&&(0,M.jsx)(S.Z,{style:{fontWeight:500},children:"Group: "}),t.name]}),!i&&(0,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)(f.Z,{style:{marginLeft:5,flexShrink:0},children:[(0,M.jsx)(C.Z,{type:"bare",onClick:e=>{e.stopPropagation(),j(!0)},style:{padding:3},children:(0,M.jsx)(v.Z,{width:14,height:14})}),x&&(0,M.jsx)(O.u,{position:"bottom-left",width:200,style:{padding:0},onClose:()=>j(!1),children:(0,M.jsx)(b.Z,{onMenuSelect:e=>{"rename"===e?d(t.id):"add-category"===e?h(t.id):"delete"===e?u(t.id):"toggleVisibility"===e&&c({...t,hidden:!t.hidden}),j(!1)},items:[{name:"add-category",text:"Add category"},{name:"toggleVisibility",text:t.hidden?"Show":"Hide"},{name:"rename",text:"Rename"},u&&{name:"delete",text:"Delete"}]})})]}),(0,M.jsx)(f.Z,{style:{flex:1}}),(0,M.jsx)(B,{id:t.id})]})]});return(0,M.jsx)(f.Z,{innerRef:a,style:[r,{width:200,backgroundColor:g.O9.S0,"& button":{display:"none"},"&:hover button":{display:"flex",color:g.O9.n1}},i&&{paddingLeft:10,zIndex:1e4,borderRadius:6,overflow:"hidden"}],onKeyDown:e=>{"Enter"===e.key&&(d(null),e.stopPropagation())},children:(0,M.jsx)(E.F3,{value:t.name,formatter:e=>Z,width:"flex",exposed:n,borderColor:g.O9.Cg,onUpdate:e=>{m?""===e?p():""!==e&&c({id:t.id,name:e}):c({id:t.id,name:e})},onBlur:()=>d(null),style:{fontWeight:600},inputProps:{style:{marginLeft:20},placeholder:m?"New Group Name":""}})})}function te(e){let{component:t,editingIndex:n,args:o,style:i}=e,{months:a,type:r}=(0,s.useContext)(_);return a.map(((e,s)=>{let a=n===s;return(0,M.jsx)(D.Z.Provider,{value:u.cv(e,r),children:(0,M.jsx)(f.Z,{style:[{flex:1},{borderLeft:"1px solid "+g.O9.Cg},i],children:(0,M.jsx)(t,{monthIndex:s,editing:a,...o})})},s)}))}const ne=(0,s.memo)((function(e){let{MonthComponent:t,toggleHiddenCategories:n,expandAllCategories:o,collapseAllCategories:i}=e;const[a,r]=(0,s.useState)(!1);return(0,M.jsxs)(f.Z,{"data-testid":"budget-totals",style:{backgroundColor:"white",flexDirection:"row",flexShrink:0,boxShadow:G,marginLeft:5,marginRight:5+q(),borderRadius:"4px 4px 0 0",borderBottom:"1px solid "+g.O9.Cg},children:[(0,M.jsxs)(f.Z,{style:{width:200,color:g.O9.n4,justifyContent:"center",paddingLeft:15,paddingRight:5,display:"flex",flexDirection:"row",alignItems:"center",userSelect:"none",WebkitUserSelect:"none"},children:[(0,M.jsx)(f.Z,{style:{flexGrow:"1"},children:"Category"}),(0,M.jsxs)(C.Z,{type:"bare",onClick:()=>{r(!0)},style:{color:"currentColor",padding:3},children:[(0,M.jsx)(j.Z,{width:15,height:15,style:{color:g.O9.n5}}),a&&(0,M.jsx)(O.u,{position:"bottom-right",width:200,style:{padding:0},onClose:()=>{r(!1)},children:(0,M.jsx)(b.Z,{onMenuSelect:e=>{"toggleVisibility"===e?n():"expandAllCategories"===e?o():"collapseAllCategories"===e&&i(),r(!1)},items:[{name:"toggleVisibility",text:"Toggle hidden"},{name:"expandAllCategories",text:"Expand all"},{name:"collapseAllCategories",text:"Collapse all"}]})})]})]}),(0,M.jsx)(te,{component:t})]})}));function oe(e){let{group:t,collapsed:n,editingCell:o,dragState:i,itemPos:s,MonthComponent:a,onEditName:r,onSave:l,onDelete:d,onDragChange:c,onReorderGroup:u,onReorderCategory:h,onToggleCollapse:p,onShowNewCategory:y}=e,m=i&&i.item===t,{dragRef:x}=(0,R.O1)({type:"group",onDragChange:c,item:t,canDrag:null===o}),{dropRef:w,dropPos:v}=(0,R.Zj)({types:"group",id:t.id,onDrop:u}),{dropRef:j,dropPos:C}=(0,R.Zj)({types:"category",id:t.id,onDrop:h,onLongHover:()=>{n&&p(t.id)}});return(0,M.jsxs)(E.X2,{collapsed:!0,backgroundColor:g.O9.S0,style:{fontWeight:600,opacity:t.hidden?.33:void 0},children:[i&&!i.preview&&"group"===i.type&&(0,M.jsx)(f.Z,{innerRef:w,style:{position:"absolute",left:0,right:0,height:n?E.dN-1:(1+t.categories.length)*(E.dN-1)+1,zIndex:1e4},children:(0,M.jsx)(R.OJ,{pos:v,offset:{top:1}})}),(0,M.jsx)(R.OJ,{pos:C,offset:{top:1}}),(0,M.jsxs)(f.Z,{innerRef:j,style:{flex:1,flexDirection:"row",opacity:m&&!i.preview?.3:1},children:[(0,M.jsx)(ee,{innerRef:x,group:t,editing:o&&"name"===o.cell&&o.id===t.id,dragPreview:m&&i.preview,collapsed:n,onToggleCollapse:p,onEdit:r,onSave:l,onDelete:d,onShowNewCategory:y}),(0,M.jsx)(te,{component:a,args:{group:t}})]})]})}function ie(e){let{cat:t,budgetArray:n,editingCell:o,dragState:i,MonthComponent:s,onEditName:a,onEditMonth:r,onSave:l,onDelete:d,onBudgetAction:c,onShowActivity:u,onDragChange:h,onReorder:p}=e,g=i&&i.item===t;i&&i.item.id===t.cat_group&&(g=!0);let{dragRef:y}=(0,R.O1)({type:"category",onDragChange:h,item:t,canDrag:null===o}),{dropRef:m,dropPos:x}=(0,R.Zj)({types:"category",id:t.id,onDrop:p});return(0,M.jsxs)(E.X2,{innerRef:m,collapsed:!0,style:{backgroundColor:"transparent",opacity:t.hidden?.5:void 0},children:[(0,M.jsx)(R.OJ,{pos:x,offset:{top:1}}),(0,M.jsxs)(f.Z,{style:[{flex:1,flexDirection:"row"}],children:[(0,M.jsx)(J,{innerRef:y,category:t,dragPreview:g&&i.preview,dragging:g&&!i.preview,editing:o&&"name"===o.cell&&o.id===t.id,onEditName:a,onSave:l,onDelete:d,onDragChange:h}),(0,M.jsx)(te,{component:s,editingIndex:o&&o.id===t.id&&o.cell,args:{category:t,onEdit:r,onBudgetAction:c,onShowActivity:u}})]})]})}function se(e){let{group:t,editingCell:n,collapsed:o,MonthComponent:i,onEditName:s,onSave:a,onToggleCollapse:r,onShowNewCategory:l}=e;return(0,M.jsxs)(E.X2,{collapsed:!0,backgroundColor:g.O9.S0,style:{fontWeight:600},children:[(0,M.jsx)(ee,{group:t,collapsed:o,editing:n&&"name"===n.cell&&n.id===t.id,onEdit:s,onSave:a,onToggleCollapse:r,onShowNewCategory:l}),(0,M.jsx)(te,{component:i,args:{group:t}})]})}function ae(e){let{cat:t,isLast:n,editingCell:o,MonthComponent:i,onEditName:s,onEditMonth:a,onSave:r,onDelete:l,onDragChange:d,onBudgetAction:c,onReorder:u,onShowActivity:h}=e,{dragRef:p}=(0,R.O1)({type:"income-category",onDragChange:d,item:t,canDrag:null===o}),{dropRef:g,dropPos:f}=(0,R.Zj)({types:"income-category",id:t.id,onDrop:u});return(0,M.jsxs)(E.X2,{innerRef:g,collapsed:!0,backgroundColor:"transparent",children:[(0,M.jsx)(R.OJ,{pos:f,offset:{top:1}}),(0,M.jsx)(J,{innerRef:p,category:t,isLast:n,editing:o&&"name"===o.cell&&o.id===t.id,onEditName:s,onSave:r,onDelete:l}),(0,M.jsx)(te,{component:i,editingIndex:o&&o.id===t.id&&o.cell,args:{category:t,onEdit:a,isLast:n,onShowActivity:h,onBudgetAction:c}})]})}const re=(0,s.memo)((e=>{let{categoryGroups:t,newCategoryForGroup:n,showHiddenCategories:o,isAddingGroup:i,editingCell:a,collapsed:r,setCollapsed:l,dataComponents:d,onBudgetAction:c,onShowActivity:u,onEditName:h,onEditMonth:p,onSaveCategory:y,onSaveGroup:m,onDeleteCategory:x,onDeleteGroup:w,onReorderCategory:v,onReorderGroup:j,onShowNewCategory:C,onHideNewCategory:b,onShowNewGroup:S,onHideNewGroup:Z}=e,A=(0,s.useMemo)((()=>{let[e,s]=function(e){return[e.filter((e=>!e.is_income)),e.find((e=>e.is_income))]}(t),a=Array.prototype.concat.apply([],e.map((e=>{if(e.hidden&&!o)return[];const t=e.categories.filter((e=>o||!e.hidden));let i=[{type:"expense-group",value:{...e}}];return n===e.id&&i.push({type:"new-category"}),[...i,...(r.includes(e.id)?[]:t).map((e=>({type:"expense-category",value:e})))]})));return i&&a.push({type:"new-group"}),s&&(a=a.concat([{type:"income-separator"},{type:"income-group",value:s},n===s.id&&{type:"new-category"},...(r.includes(s.id)?[]:s.categories.filter((e=>o||!e.hidden))).map((e=>({type:"income-category",value:e})))].filter((e=>e)))),a}),[t,r,n,i,o]),[k,T]=(0,s.useState)(null),[O,I]=(0,s.useState)(null);function B(e){let{state:t}=e;"start-preview"===t?T({type:e.type,item:e.item,preview:!0}):"start"===t?k&&(T({...k,preview:!1}),I(r)):"hover"===t?T({...k,hoveredId:e.id,hoveredPos:e.pos}):"end"===t&&(T(null),l(O||[]))}function D(e){r.includes(e)?l(r.filter((t=>t!==e))):l([...r,e])}return(0,M.jsx)(f.Z,{style:{marginBottom:10,backgroundColor:"white",overflow:"hidden",boxShadow:G,borderRadius:"0 0 4px 4px",flex:1},children:A.map(((e,o)=>{let i;switch(e.type){case"new-group":i=(0,M.jsx)(E.X2,{style:{backgroundColor:g.O9.S0},children:(0,M.jsx)(ee,{group:{id:"new",name:""},editing:!0,onSave:m,onHideNewGroup:Z,onEdit:h})});break;case"new-category":i=(0,M.jsx)(E.X2,{children:(0,M.jsx)(J,{category:{name:"",cat_group:n,is_income:n===t.find((e=>e.is_income)).id,id:"new"},editing:!0,onSave:y,onHideNewCategory:b,onEditName:h})});break;case"expense-group":i=(0,M.jsx)(oe,{group:e.value,editingCell:a,collapsed:r.includes(e.value.id),MonthComponent:d.ExpenseGroupComponent,dragState:k,onEditName:h,onSave:m,onDelete:w,onDragChange:B,onReorderGroup:j,onReorderCategory:v,onToggleCollapse:D,onShowNewCategory:C});break;case"expense-category":i=(0,M.jsx)(ie,{cat:e.value,editingCell:a,MonthComponent:d.ExpenseCategoryComponent,dragState:k,onEditName:h,onEditMonth:p,onSave:y,onDelete:x,onDragChange:B,onReorder:v,onBudgetAction:c,onShowActivity:u});break;case"income-separator":i=(0,M.jsx)(f.Z,{style:{height:70,backgroundColor:"white"},children:(0,M.jsx)(le,{MonthComponent:d.IncomeHeaderComponent,onShowNewGroup:S})});break;case"income-group":i=(0,M.jsx)(se,{group:e.value,editingCell:a,MonthComponent:d.IncomeGroupComponent,collapsed:r.includes(e.value.id),onEditName:h,onSave:m,onToggleCollapse:D,onShowNewCategory:C});break;case"income-category":i=(0,M.jsx)(ae,{cat:e.value,editingCell:a,isLast:o===A.length-1,MonthComponent:d.IncomeCategoryComponent,onEditName:h,onEditMonth:p,onSave:y,onDelete:x,onDragChange:B,onReorder:v,onBudgetAction:c,onShowActivity:u});break;default:throw new Error("Unknown item type: "+e.type)}let s=0===o?"first":o===A.length-1?"last":null;return(0,M.jsx)(R.aB.Provider,{value:s,children:(0,M.jsx)(f.Z,{style:!k&&{":hover":{backgroundColor:"#fcfcfc"}},children:i})},e.value?e.value.id:"income-separator"===e.type?"separator":o)}))})}));function le(e){let{MonthComponent:t,onShowNewGroup:n}=e;return(0,M.jsxs)(f.Z,{style:{flexDirection:"row",flex:1},children:[(0,M.jsx)(f.Z,{style:{width:200,alignItems:"flex-start",justifyContent:"flex-start"},children:(0,M.jsx)(C.Z,{onClick:n,style:{fontSize:12,margin:10},children:"Add Group"})}),(0,M.jsx)(te,{component:t,style:{border:0,justifyContent:"flex-end"}})]})}const de=(0,s.memo)((e=>{let{startMonth:t,onMonthSelect:n,numMonths:o,monthBounds:i,style:s}=e;return(0,M.jsx)(f.Z,{style:{marginLeft:205,flexShrink:0},children:(0,M.jsx)(f.Z,{style:{marginRight:5+q()},children:(0,M.jsx)(U,{startMonth:t,numDisplayed:o,monthBounds:i,style:{paddingTop:5},onSelect:e=>n(function(e){let t=i.start,n=u.W9(i.end,o-1);return e<t?t:e>n?n:e}(e))})})})}));const ce=(0,s.forwardRef)(((e,t)=>{let{width:n,height:o,categoryGroups:i,prewarmStartMonth:r,startMonth:l,maxMonths:d=3,monthBounds:c,onMonthSelect:u,onPreload:p,...g}=e,y=(0,a.v9)((e=>e.prefs.local)),{setDisplayMax:m}=(0,x.s)(),w=(0,h.o)(),v=function(e){let t=e-200;return t<500?1:t<750?2:t<1e3?3:t<1250?4:t<1500?5:6}(n),j=Math.min(v,d),C=200+500*j;return(0,s.useEffect)((()=>{m(v)}),[v]),(0,M.jsx)(z.Provider,{value:i,children:(0,M.jsx)(f.Z,{style:{width:n,height:o,alignItems:"center",opacity:n<=0||o<=0?0:1},children:(0,M.jsxs)(f.Z,{style:{width:"100%",maxWidth:C},children:[(0,M.jsx)(de,{startMonth:r,numMonths:j,monthBounds:c,onMonthSelect:function(e){u(e,j)}}),(0,M.jsx)(Y,{ref:t,categoryGroups:i,prewarmStartMonth:r,startMonth:l,numMonths:j,monthBounds:c,prefs:y,...w,...g})]})})})}));var ue=(0,s.forwardRef)(((e,t)=>(0,M.jsx)(m.Z,{children:n=>{let{width:o,height:i}=n;return(0,M.jsx)(ce,{ref:t,width:o,height:i,...e})}}))),he=n(28321),pe=n(69585);function ge(e,t){throw new Error(t+": "+JSON.stringify(e.str.slice(e.index,10)))}function fe(e){return e.str[e.index]}function ye(e){if(e.index>=e.str.length)return null;let t=fe(e);return e.index++,t}function me(e,t){return fe(e)===t&&(ye(e),!0)}function xe(e){if("("===fe(e)){ye(e);let t=we(e);return")"!==fe(e)&&ge(e,"Unbalanced parentheses"),ye(e),t}return function(e){let t="-"===fe(e);t&&ye(e),/\p{Sc}/u.test(fe(e))&&ye(e);let n="";for(;fe(e)&&fe(e).match(/[0-9,.]/);){let t=","===(0,pe.ff)().separator?".":",";fe(e)===t?ye(e):n+=ye(e)}""===n&&ge(e,"Unexpected character");let o=parseFloat(n.replace((0,pe.ff)().separator,"."));return t?-o:o}(e)}let we=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return t.reduce(((e,t)=>n=>{let o=e(n);for(;me(n,t);)o={op:t,left:o,right:e(n)};return o}),xe)}("^","/","*","-","+");function ve(e){if("number"===typeof e)return e;let{left:t,right:n,op:o}=e;switch(o){case"+":return ve(t)+ve(n);case"-":return ve(t)-ve(n);case"*":return ve(t)*ve(n);case"/":return ve(t)/ve(n);case"^":return Math.pow(ve(t),ve(n));default:throw new Error("Unknown operator: "+o)}}function je(e){let t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;if(""===e)return n;try{t=ve(function(e){let t={str:e.replace(/\s/g,""),index:0};return we(t)}(e))}catch(o){return n}return isNaN(t)?n:t}var Ce=n(91742),be=n(40336),Se=n(17422),Ze=n(62506);function Ae(e){let{carryover:t,balance:n,disabled:o}=e,i=(0,Se.Z)(t),s=(0,Se.Z)(n);return(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(Ce.Z,{binding:n,type:"financial",getStyle:V,style:[{textAlign:"right"},!o&&{cursor:"pointer",":hover":{textDecoration:"underline"}}]}),!0===i&&(0,M.jsx)(f.Z,{style:{alignSelf:"center",marginLeft:2,position:"absolute",right:-4,top:0,bottom:0,justifyContent:"center"},children:(0,M.jsx)(Ze.Z,{width:7,height:7,style:V(s)})})]})}var ke=e=>(0,M.jsxs)("svg",{...e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",style:{color:"inherit",...e.style},children:[(0,M.jsx)("path",{d:"M12 13.584a2.643 2.643 0 0 1-1.875-.775L.584 3.268a1.768 1.768 0 0 1 2.5-2.5l8.739 8.739a.25.25 0 0 0 .354 0L20.916.768a1.768 1.768 0 0 1 2.5 2.5l-9.541 9.541a2.643 2.643 0 0 1-1.875.775Z",fill:"currentColor"}),(0,M.jsx)("path",{d:"M12 23.75a2.643 2.643 0 0 1-1.875-.775L.584 13.434a1.768 1.768 0 0 1 2.5-2.5l8.739 8.739a.25.25 0 0 0 .354 0l8.739-8.739a1.768 1.768 0 0 1 2.5 2.5l-9.541 9.541A2.643 2.643 0 0 1 12 23.75Z",fill:"currentColor"})]});var Me=e=>(0,M.jsxs)("svg",{...e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",style:{color:"inherit",...e.style},children:[(0,M.jsx)("path",{d:"M12 10.416a2.643 2.643 0 0 1 1.875.775l9.541 9.541a1.768 1.768 0 0 1-2.5 2.5l-8.739-8.739a.25.25 0 0 0-.354 0l-8.739 8.739a1.768 1.768 0 0 1-2.5-2.5l9.541-9.541A2.643 2.643 0 0 1 12 10.416Z",fill:"currentColor"}),(0,M.jsx)("path",{d:"M12 .25a2.643 2.643 0 0 1 1.875.775l9.541 9.541a1.768 1.768 0 0 1-2.5 2.5l-8.739-8.739a.25.25 0 0 0-.354 0l-8.739 8.739a1.768 1.768 0 0 1-2.5-2.5l9.541-9.541A2.643 2.643 0 0 1 12 .25Z",fill:"currentColor"})]}),Te=n(78738);function Oe(e){let{style:t,contentStyle:n,children:o,renderContent:i,disabled:a}=e,[r,l]=(0,s.useState)(!1);const d=(0,s.useCallback)((()=>{a||l(!0)}),[a]),c=(0,s.useCallback)((()=>{a||l(!1)}),[a]);return(0,s.useEffect)((()=>{a&&r&&l(!1)}),[a,r]),(0,M.jsxs)(f.Z,{style:t,children:[(0,M.jsx)(f.Z,{onMouseEnter:d,onMouseLeave:c,style:n,children:o}),r&&i()]})}var Ie=n(99884),Be=n(78867);let Re=(0,s.createContext)(null);function De(e){let{summaryCollapsed:t,onBudgetAction:n,onToggleSummaryCollapse:o,children:i}=e,s=u.dK();return(0,M.jsx)(Re.Provider,{value:{currentMonth:s,summaryCollapsed:t,onBudgetAction:n,onToggleSummaryCollapse:o},children:i})}function Ee(e){let{style:t,progress:n,color:o,backgroundColor:i}=e,s=2*Math.PI*4,a=n*s,r=s;return(0,M.jsxs)("svg",{viewBox:"0 0 20 20",style:t,children:[(0,M.jsx)("circle",{r:"10",cx:"10",cy:"10",fill:i}),(0,M.jsx)("circle",{r:4,cx:"10",cy:"10",fill:"none",stroke:o,strokeWidth:8,strokeDasharray:`${a} ${r}`,transform:"rotate(-90) translate(-20)"})," "]})}function Ne(e,t){return 0===t?e>0?1:0:e/t}function Fe(e){let{current:t,target:n}=e,o=(0,Se.Z)(t)||0,i=!1;o<0&&(i=!0,o=-o);let s=Ne(o,(0,Se.Z)(n)||0);return(0,M.jsx)(Ee,{progress:s,color:i?g.O9.r7:g.O9.g5,backgroundColor:i?g.O9.as:g.O9.pK,style:{width:20,height:20}})}function Pe(e){let t,{current:n,target:o}=e,i=(0,Se.Z)(n)||0,s=(0,Se.Z)(o)||0;i=Math.max(-i,0);let a=!1;return i>s?(t=(i-s)/s,a=!0):t=Ne(i,s),(0,M.jsx)(Ee,{progress:t,color:a?g.O9.r7:g.O9.g5,backgroundColor:a?g.O9.as:g.O9.pK,style:{width:20,height:20}})}function _e(e){let{title:t,current:n,target:o,ProgressComponent:i,style:s}=e;return(0,M.jsxs)(f.Z,{style:[{lineHeight:1.5,flexDirection:"row",alignItems:"center",fontSize:14},s],children:[(0,M.jsx)(i,{current:n,target:o}),(0,M.jsxs)(f.Z,{style:{marginLeft:10},children:[(0,M.jsx)(f.Z,{children:(0,M.jsx)(S.Z,{style:{color:g.O9.n4},children:t})}),(0,M.jsxs)(S.Z,{children:[(0,M.jsx)(Ce.Z,{binding:n,type:"financial"}),(0,M.jsxs)(S.Z,{style:{color:g.O9.n6,fontStyle:"italic"},children:[" of ",(0,M.jsx)(Ce.Z,{binding:o,type:"financial",style:g.W2.notFixed})]})]})]})]})}function We(e){let{style:t}=e;return(0,M.jsx)(_e,{title:"Income",current:he.u8.totalIncome,target:he.u8.totalBudgetedIncome,ProgressComponent:Fe,style:t})}function Le(e){let{style:t}=e;return(0,M.jsx)(_e,{title:"Expenses",current:he.u8.totalSpent,target:he.u8.totalBudgetedExpense,ProgressComponent:Pe,style:t})}function Ge(e){let{projected:t,style:n}=e,o=(0,Se.Z)(he.u8.totalBudgetedSaved)||0,i=(0,Se.Z)(he.u8.totalSaved)||0,s=t?o:i,a=s<0;return(0,M.jsxs)(f.Z,{style:[{alignItems:"center",fontSize:14},n],children:[t?(0,M.jsx)(S.Z,{style:{color:g.O9.n4},children:"Projected Savings:"}):(0,M.jsx)(f.Z,{style:{color:g.O9.n4},children:a?"Overspent:":"Saved:"}),(0,M.jsx)(Oe,{renderContent:()=>{if(!t){let e=i-o;return(0,M.jsxs)(O.u,{position:"bottom-center",style:{padding:10,fontSize:14},children:[(0,M.jsx)(Te.Z,{left:"Projected Savings:",right:(0,M.jsx)(S.Z,{style:[Q(o),g.W2.tnum],children:(0,be.Z)(o,"financial-with-sign")})}),(0,M.jsx)(Te.Z,{left:"Difference:",right:(0,M.jsx)(S.Z,{style:[Q(e),g.W2.tnum],children:(0,be.Z)(e,"financial-with-sign")})})]})}return null},children:(0,M.jsx)(f.Z,{...(0,Z.iv)([{fontSize:25,color:t?g.O9.y3:a?g.O9.r4:g.O9.p5}]),children:(0,M.jsx)(Be.ZP,{blurIntensity:7,children:(0,be.Z)(s,"financial")})})})]})}function He(e){let{month:t}=e,{currentMonth:n,summaryCollapsed:o,onBudgetAction:i,onToggleSummaryCollapse:a}=(0,s.useContext)(Re);const r=(0,p.Z)("goalTemplatesEnabled");let[l,d]=(0,s.useState)(!1);function c(){d(!1)}let h=o?ke:Me;return(0,M.jsx)(f.Z,{style:{backgroundColor:"white",boxShadow:G,borderRadius:6,marginLeft:0,marginRight:0,marginTop:5,flex:1,cursor:"default",marginBottom:5,overflow:"hidden","& .hover-visible":{opacity:0,transition:"opacity .25s"},"&:hover .hover-visible":{opacity:1}},children:(0,M.jsxs)(D.Z.Provider,{value:u.cv(t),children:[(0,M.jsxs)(f.Z,{style:[{padding:"0 13px"},o?{margin:"10px 0"}:{marginTop:16}],children:[(0,M.jsx)(f.Z,{style:{position:"absolute",left:10,top:0},children:(0,M.jsx)(C.Z,{type:"bare",className:"hover-visible",onClick:a,children:(0,M.jsx)(h,{width:13,height:13,style:{color:g.O9.n6,margin:1}})})}),(0,M.jsx)("div",{...(0,Z.iv)([{textAlign:"center",marginTop:3,fontSize:18,fontWeight:500,textDecorationSkip:"ink"},n===t&&{textDecoration:"underline"}]),children:u.WU(t,"MMMM")}),(0,M.jsxs)(f.Z,{style:{position:"absolute",right:10,top:0,flexDirection:"row",alignItems:"center"},children:[(0,M.jsx)(f.Z,{children:(0,M.jsx)(B,{id:`budget-${t}`,width:15,height:15,tooltipPosition:"bottom-right",defaultColor:g.O9.n6})}),(0,M.jsxs)(f.Z,{style:{userSelect:"none"},children:[(0,M.jsx)(C.Z,{type:"bare",onClick:function(){d(!0)},children:(0,M.jsx)(j.Z,{width:15,height:15,style:{color:g.O9.n5}})}),l&&(0,M.jsx)(O.u,{position:"bottom-right",width:200,style:{padding:0},onClose:c,children:(0,M.jsx)(b.Z,{onMenuSelect:e=>{c(),i(t,e)},items:[{name:"copy-last",text:"Copy last month\u2019s budget"},{name:"set-zero",text:"Set budgets to zero"},{name:"set-3-avg",text:"Set budgets to 3 month average"},r&&{name:"check-templates",text:"Check templates"},r&&{name:"apply-goal-template",text:"Apply budget template"},r&&{name:"overwrite-goal-template",text:"Overwrite with budget template"}]})})]})]})]}),!o&&(0,M.jsxs)(Ie.Z,{spacing:2,style:{alignSelf:"center",backgroundColor:g.O9.S0,borderRadius:4,padding:"10px 15px",marginTop:13},children:[(0,M.jsx)(We,{}),(0,M.jsx)(Le,{})]}),o?(0,M.jsx)(f.Z,{style:{alignItems:"center",padding:"10px 20px",justifyContent:"space-between",backgroundColor:g.O9.S0,borderTop:"1px solid "+g.O9.pK},children:(0,M.jsx)(Ge,{projected:t>=n})}):(0,M.jsx)(Ge,{projected:t>=n,style:{marginTop:13,marginBottom:20}})]})})}let Ue={flex:1,padding:"0 5px",textAlign:"right"};const ze=(0,s.memo)((function(){return(0,M.jsxs)(f.Z,{style:{flex:1,flexDirection:"row",marginRight:H,paddingTop:10,paddingBottom:10},children:[(0,M.jsxs)(f.Z,{style:Ue,children:[(0,M.jsx)(S.Z,{style:{color:g.O9.n4},children:"Budgeted"}),(0,M.jsx)(Ce.Z,{binding:he.u8.totalBudgetedExpense,type:"financial",style:{color:g.O9.n4,fontWeight:600},formatter:e=>(0,be.Z)(parseFloat(e||"0"),"financial")})]}),(0,M.jsxs)(f.Z,{style:Ue,children:[(0,M.jsx)(S.Z,{style:{color:g.O9.n4},children:"Spent"}),(0,M.jsx)(Ce.Z,{binding:he.u8.totalSpent,type:"financial",style:{color:g.O9.n4,fontWeight:600}})]}),(0,M.jsxs)(f.Z,{style:Ue,children:[(0,M.jsx)(S.Z,{style:{color:g.O9.n4},children:"Balance"}),(0,M.jsx)(Ce.Z,{binding:he.u8.totalLeftover,type:"financial",style:{color:g.O9.n4,fontWeight:600}})]})]})}));function Ke(){return(0,M.jsxs)(f.Z,{style:{flexDirection:"row",marginRight:H,paddingBottom:5},children:[(0,M.jsx)(f.Z,{style:Ue,children:(0,M.jsx)(S.Z,{style:{color:g.O9.n4},children:"Budgeted"})}),(0,M.jsx)(f.Z,{style:Ue,children:(0,M.jsx)(S.Z,{style:{color:g.O9.n4},children:"Received"})})]})}const $e=(0,s.memo)((function(e){let{group:t}=e,n=g.O9.Cg,{id:o}=t;return(0,M.jsxs)(f.Z,{style:{flex:1,flexDirection:"row"},children:[(0,M.jsx)(E.OX,{name:"budgeted",width:"flex",borderColor:n,textAlign:"right",style:[{fontWeight:600},g.W2.tnum],valueProps:{binding:he.u8.groupBudgeted(o),type:"financial"}}),(0,M.jsx)(E.OX,{name:"spent",width:"flex",textAlign:"right",borderColor:n,style:[{fontWeight:600},g.W2.tnum],valueProps:{binding:he.u8.groupSumAmount(o),type:"financial"}}),!t.is_income&&(0,M.jsx)(E.OX,{name:"balance",width:"flex",borderColor:n,textAlign:"right",style:[{fontWeight:600,paddingRight:H},g.W2.tnum],valueProps:{binding:he.u8.groupBalance(o),type:"financial",privacyFilter:{style:{paddingRight:H}}}})]})}));function Ve(e){let{categoryId:t,tooltip:n,monthIndex:o,onBudgetAction:i}=e,s=(0,Se.Z)(he.u8.catCarryover(t));return(0,M.jsx)(O.u,{position:"bottom-right",width:200,style:{padding:0},onClose:n.close,children:(0,M.jsx)(b.Z,{onMenuSelect:e=>{i(o,"carryover",{category:t,flag:!s}),n.close()},items:[{name:"carryover",text:s?"Remove overspending rollover":"Rollover overspending"}]})})}const Qe=(0,s.memo)((function(e){let{monthIndex:t,category:n,editing:o,onEdit:i,onBudgetAction:a,onShowActivity:r}=e,l=g.O9.Cg,d=(0,O.lL)();const[c,u]=(0,s.useState)(!1),[h,y]=(0,s.useState)(!1),m=(0,p.Z)("goalTemplatesEnabled");return(0,M.jsxs)(f.Z,{style:{flex:1,flexDirection:"row","& .hover-visible":{opacity:0,transition:"opacity .25s"},"&:hover .hover-visible":{opacity:1}},children:[(0,M.jsxs)(f.Z,{style:{flex:1,flexDirection:"row",borderTopWidth:1,borderBottomWidth:1,borderColor:l,backgroundColor:"white"},onMouseOverCapture:()=>y(!0),onMouseLeave:()=>{y(!1)},children:[!o&&(h||c)&&(0,M.jsxs)(f.Z,{style:{flexShrink:0,marginRight:0,marginLeft:3,justifyContent:"center"},children:[(0,M.jsx)(C.Z,{type:"bare",onClick:e=>{e.stopPropagation(),u(!0)},style:{padding:3},children:(0,M.jsx)(v.Z,{width:14,height:14,className:"hover-visible",style:c&&{opacity:1}})}),c&&(0,M.jsx)(O.u,{position:"bottom-left",width:200,style:{padding:0},onClose:()=>u(!1),children:(0,M.jsx)(b.Z,{onMenuSelect:e=>{a(t,e,{category:n.id}),u(!1)},items:[{name:"copy-single-last",text:"Copy last month\u2019s budget"},{name:"set-single-3-avg",text:"Set to 3 month average"},{name:"set-single-6-avg",text:"Set to 6 month average"},{name:"set-single-12-avg",text:"Set to yearly average"},m&&{name:"apply-single-category-template",text:"Apply budget template"}]})})]}),(0,M.jsx)(E.OX,{name:"budget",exposed:o,focused:o,width:"flex",borderColor:"white",onExpose:()=>i(n.id,t),style:[o&&{zIndex:100},g.W2.tnum],textAlign:"right",valueStyle:[{cursor:"default",margin:1,padding:"0 4px",borderRadius:4},{":hover":{boxShadow:"inset 0 0 0 1px "+g.O9.n7,backgroundColor:"white"}}],valueProps:{binding:he.u8.catBudgeted(n.id),type:"financial",getValueStyle:$,formatExpr:e=>(0,pe.zA)(e),unformatExpr:e=>(0,pe.l9)(je(e,0))},inputProps:{onBlur:()=>{i(null)}},onSave:e=>{a(t,"budget-amount",{category:n.id,amount:e})}})]}),(0,M.jsx)(E.gN,{name:"spent",width:"flex",borderColor:l,style:{textAlign:"right"},children:(0,M.jsx)("span",{"data-testid":"category-month-spent",onClick:()=>r(n.name,n.id,t),children:(0,M.jsx)(Ce.Z,{binding:he.u8.catSumAmount(n.id),type:"financial",getStyle:$,style:{cursor:"pointer",":hover":{textDecoration:"underline"}}})})}),!n.is_income&&(0,M.jsxs)(E.gN,{name:"balance",width:"flex",borderColor:l,style:{paddingRight:H,textAlign:"right"},children:[(0,M.jsx)("span",{...n.is_income?{}:d.getOpenEvents(),children:(0,M.jsx)(Ae,{disabled:n.is_income,carryover:he.u8.catCarryover(n.id),balance:he.u8.catBalance(n.id)})}),d.isOpen&&(0,M.jsx)(Ve,{categoryId:n.id,tooltip:d,monthIndex:t,onBudgetAction:a})]})]})})),Xe=$e,qe=Qe,Ye=$e,Je=Qe;var et=n(87740),tt=n(74283),nt=n(17904);function ot(e){let{initialAmount:t,initialAmountName:n,showToBeBudgeted:o,tooltipProps:i,onSubmit:a,onClose:r}=e,d=(0,l.M)(),c=(0,s.useContext)(D.Z),u=(0,s.useContext)(z);u=u.filter((e=>!e.is_income)),o&&(u=K(u));let[h,p]=(0,s.useState)(null),[g,y]=(0,s.useState)(null);function m(){let e=je(h,null);e&&g&&(a((0,pe.l9)(e),g),r())}return(0,s.useEffect)((()=>{(async()=>{if(n){const e=await d.get(c,n);p((0,pe.zA)(Math.max(e.value,0)))}else p((0,pe.zA)(Math.max(t,0)))})()}),[]),null===h?null:(0,M.jsxs)(O.u,{position:"bottom-right",width:200,style:{padding:10},...i,onClose:r,children:[(0,M.jsx)(f.Z,{style:{marginBottom:5},children:"Transfer this amount:"}),(0,M.jsx)(f.Z,{children:(0,M.jsx)(tt.Z,{children:(0,M.jsx)(nt.ZP,{value:h,onChange:e=>p(e.target.value),onEnter:m})})}),(0,M.jsx)(f.Z,{style:{margin:"10px 0 5px 0"},children:"To:"}),(0,M.jsx)(et.Z,{categoryGroups:u,value:null,openOnFocus:!0,onUpdate:e=>{},onSelect:e=>y(e),inputProps:{onEnter:m,placeholder:"(none)"}}),(0,M.jsx)(f.Z,{style:{alignItems:"flex-end",marginTop:10},children:(0,M.jsx)(C.Z,{type:"primary",style:{fontSize:12,paddingTop:3,paddingBottom:3},onClick:m,children:"Transfer"})})]})}var it=n(82054),st=n(69367);function at(e){let{onSubmit:t,onClose:n}=e;const o=(0,l.M)(),i=(0,s.useContext)(D.Z),[a,r]=(0,s.useState)(null);function d(){const e=je(a,null);e&&t((0,pe.l9)(e)),n()}return(0,s.useEffect)((()=>{(async()=>{const e=await o.get(i,"to-budget");r((0,pe.zA)(Math.max(e.value,0)))})()}),[]),null===a?null:(0,M.jsxs)(O.u,{position:"bottom-right",width:200,style:{padding:10},onClose:n,children:[(0,M.jsx)(f.Z,{style:{marginBottom:5},children:"Hold this amount:"}),(0,M.jsx)(f.Z,{children:(0,M.jsx)(tt.Z,{children:(0,M.jsx)(nt.ZP,{value:a,onChange:e=>r(e.target.value),onEnter:d})})}),(0,M.jsx)(f.Z,{style:{alignItems:"flex-end",marginTop:10},children:(0,M.jsx)(C.Z,{type:"primary",style:{fontSize:12,paddingTop:3,paddingBottom:3},onClick:d,children:"Hold"})})]})}let rt=(0,s.createContext)(null);function lt(e){let{categoryGroups:t,summaryCollapsed:n,onBudgetAction:o,onToggleSummaryCollapse:i,children:s}=e,a=u.dK();return(0,M.jsx)(rt.Provider,{value:{currentMonth:a,categoryGroups:t,summaryCollapsed:n,onBudgetAction:o,onToggleSummaryCollapse:i},children:s})}function dt(e){let{prevMonthName:t,collapsed:n}=e;return(0,M.jsxs)(f.Z,{style:[{flexDirection:"row",lineHeight:1.5,justifyContent:"center"},!n&&{padding:"5px 0",marginTop:17,backgroundColor:g.O9.S0,borderTopWidth:1,borderBottomWidth:1,borderColor:g.O9.n9},n&&{padding:7},g.W2.smallText],children:[(0,M.jsxs)(f.Z,{style:{textAlign:"right",marginRight:10,minWidth:50},children:[(0,M.jsx)(Oe,{style:{flexShrink:0},renderContent:()=>(0,M.jsxs)(O.u,{width:200,style:{lineHeight:1.5,padding:"6px 10px"},children:[(0,M.jsx)(Te.Z,{left:"Income:",right:(0,M.jsx)(Ce.Z,{binding:he.aK.totalIncome,type:"financial",privacyFilter:!1})}),(0,M.jsx)(Te.Z,{left:"From Last Month:",right:(0,M.jsx)(Ce.Z,{binding:he.aK.fromLastMonth,type:"financial",privacyFilter:!1})})]}),children:(0,M.jsx)(Ce.Z,{binding:he.aK.incomeAvailable,type:"financial",style:{fontWeight:600}})}),(0,M.jsx)(Ce.Z,{binding:he.aK.lastMonthOverspent,type:"financial",formatter:e=>{let t=(0,be.Z)(e,"financial");return e>0?"+"+t:0===e?"-"+t:t},style:[{fontWeight:600},g.W2.tnum]}),(0,M.jsx)(Ce.Z,{binding:he.aK.totalBudgeted,type:"financial",formatter:e=>{let t=(0,be.Z)(e,"financial");return e>0?"+"+t:0===e?"-"+t:t},style:[{fontWeight:600},g.W2.tnum]}),(0,M.jsx)(Ce.Z,{binding:he.aK.forNextMonth,type:"financial",formatter:e=>{let t=parseInt(e)||0,n=(0,be.Z)(Math.abs(t),"financial");return t>=0?"-"+n:"+"+n},style:[{fontWeight:600},g.W2.tnum]})]}),(0,M.jsxs)(f.Z,{children:[(0,M.jsx)(it.Z,{children:"Available Funds"}),(0,M.jsxs)(it.Z,{children:["Overspent in ",t]}),(0,M.jsx)(it.Z,{children:"Budgeted"}),(0,M.jsx)(it.Z,{children:"For Next Month"})]})]})}function ct(e){let{month:t,prevMonthName:n,collapsed:o,onBudgetAction:i}=e,[a,r]=(0,s.useState)(null),l=(0,st.Z)(he.aK.toBudget),d=(0,Se.Z)({name:he.aK.toBudget,value:0}),c=parseInt(d),u=isNaN(c)?0:c,h=u<0;return(0,M.jsxs)(f.Z,{style:{alignItems:"center"},children:[(0,M.jsx)(it.Z,{children:h?"Overbudgeted:":"To Budget:"}),(0,M.jsxs)(f.Z,{children:[(0,M.jsx)(Oe,{disabled:!o||a,renderContent:()=>(0,M.jsx)(O.u,{position:"bottom-center",children:(0,M.jsx)(dt,{collapsed:!0,prevMonthName:n})}),children:(0,M.jsx)(Be.ZP,{blurIntensity:7,children:(0,M.jsx)(it.Z,{onClick:()=>r("actions"),"data-cellname":l,...(0,Z.iv)([g.W2.veryLargeText,{fontWeight:400,userSelect:"none",cursor:"pointer",color:h?g.O9.r4:g.O9.p5,marginBottom:-1,borderBottom:"1px solid transparent",":hover":{borderColor:h?g.O9.r4:g.O9.p5}}]),children:(0,be.Z)(u,"financial")})})}),"actions"===a&&(0,M.jsx)(O.u,{position:"bottom-center",width:200,style:{padding:0},onClose:()=>r(null),children:(0,M.jsx)(b.Z,{onMenuSelect:e=>{"reset-buffer"===e?(i(t,"reset-hold"),r(null)):r(e)},items:[{name:"transfer",text:"Move to a category"},{name:"buffer",text:"Hold for next month"},{name:"reset-buffer",text:"Reset next month\u2019s buffer"}]})}),"buffer"===a&&(0,M.jsx)(at,{onClose:()=>r(null),onSubmit:e=>{i(t,"hold",{amount:e})}}),"transfer"===a&&(0,M.jsx)(ot,{initialAmount:c,onClose:()=>r(null),onSubmit:(e,n)=>{i(t,"transfer-available",{amount:e,category:n})}})]})]})}function ut(e){let{month:t,isGoalTemplatesEnabled:n}=e,{currentMonth:o,summaryCollapsed:i,onBudgetAction:a,onToggleSummaryCollapse:r}=(0,s.useContext)(rt),[l,d]=(0,s.useState)(!1);function c(){d(!1)}let h=u.WU(u.dy(t),"MMM"),p=i?ke:Me;return(0,M.jsx)(f.Z,{"data-testid":"budget-summary",style:{backgroundColor:"white",boxShadow:G,borderRadius:6,marginLeft:0,marginRight:0,marginTop:5,flex:1,cursor:"default",marginBottom:5,overflow:"hidden","& .hover-visible":{opacity:0,transition:"opacity .25s"},"&:hover .hover-visible":{opacity:1}},children:(0,M.jsxs)(D.Z.Provider,{value:u.cv(t),children:[(0,M.jsxs)(f.Z,{style:[{padding:"0 13px"},i?{margin:"10px 0"}:{marginTop:16}],children:[(0,M.jsx)(f.Z,{style:{position:"absolute",left:10,top:0},children:(0,M.jsx)(C.Z,{type:"bare",className:"hover-visible",onClick:r,children:(0,M.jsx)(p,{width:13,height:13,style:{color:g.O9.n6,margin:1}})})}),(0,M.jsx)("div",{...(0,Z.iv)([{textAlign:"center",marginTop:3,fontSize:18,fontWeight:500,textDecorationSkip:"ink"},o===t&&{fontWeight:"bold"}]),children:u.WU(t,"MMMM")}),(0,M.jsxs)(f.Z,{style:{position:"absolute",right:10,top:0,flexDirection:"row",alignItems:"center"},children:[(0,M.jsx)(f.Z,{children:(0,M.jsx)(B,{id:`budget-${t}`,width:15,height:15,tooltipPosition:"bottom-right",defaultColor:g.O9.n6})}),(0,M.jsxs)(f.Z,{style:{userSelect:"none",marginLeft:2},children:[(0,M.jsx)(C.Z,{type:"bare",onClick:function(e){d(!0)},children:(0,M.jsx)(j.Z,{width:15,height:15,style:{color:g.O9.n5}})}),l&&(0,M.jsx)(O.u,{position:"bottom-right",width:200,style:{padding:0},onClose:c,children:(0,M.jsx)(b.Z,{onMenuSelect:e=>{c(),a(t,e)},items:[{name:"copy-last",text:"Copy last month\u2019s budget"},{name:"set-zero",text:"Set budgets to zero"},{name:"set-3-avg",text:"Set budgets to 3 month average"},n&&{name:"check-templates",text:"Check templates"},n&&{name:"apply-goal-template",text:"Apply budget template"},n&&{name:"overwrite-goal-template",text:"Overwrite with budget template"},n&&{name:"cleanup-goal-template",text:"End of month cleanup"}]})})]})]})]}),i?(0,M.jsx)(f.Z,{style:{alignItems:"center",padding:"10px 20px",justifyContent:"space-between",backgroundColor:g.O9.S0,borderTop:"1px solid "+g.O9.pK},children:(0,M.jsx)(ct,{collapsed:i,prevMonthName:h,month:t,onBudgetAction:a})}):(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(dt,{prevMonthName:h}),(0,M.jsx)(f.Z,{style:{margin:"23px 0"},children:(0,M.jsx)(ct,{month:t,onBudgetAction:a})})]})]})})}function ht(e){let{tooltipProps:t,onSubmit:n,onClose:o}=e,i=(0,s.useContext)(z);i=K(i.filter((e=>!e.is_income)));let[a,r]=(0,s.useState)(null);function l(){a&&(n(a),o())}return(0,M.jsxs)(O.u,{position:"bottom-right",width:200,style:{padding:10},...t,onClose:o,children:[(0,M.jsx)(f.Z,{style:{marginBottom:5},children:"Cover from category:"}),(0,M.jsx)(tt.Z,{children:e=>(0,M.jsx)(et.Z,{categoryGroups:i,value:null,openOnFocus:!0,onUpdate:e=>{},onSelect:e=>r(e),inputProps:{inputRef:e,onKeyDown:e=>{"Enter"===e.key&&l()}}})}),(0,M.jsx)(f.Z,{style:{alignItems:"flex-end",marginTop:10},children:(0,M.jsx)(C.Z,{type:"primary",style:{fontSize:12,paddingTop:3},onClick:l,children:"Transfer"})})]})}function pt(e){let{categoryId:t,tooltip:n,monthIndex:o,onBudgetAction:i}=e,a=(0,Se.Z)(he.aK.catCarryover(t)),r=(0,Se.Z)(he.aK.catBalance(t)),[l,d]=(0,s.useState)("menu");return(0,M.jsxs)(M.Fragment,{children:["menu"===l&&(0,M.jsx)(O.u,{position:"bottom-right",width:200,style:{padding:0},onClose:n.close,children:(0,M.jsx)(b.Z,{onMenuSelect:e=>{"carryover"===e?(i(o,"carryover",{category:t,flag:!a}),n.close()):d(e)},items:[{name:"transfer",text:"Transfer to another category"},{name:"carryover",text:a?"Remove overspending rollover":"Rollover overspending"},r<0&&{name:"cover",text:"Cover overspending"}].filter((e=>e))})}),"transfer"===l&&(0,M.jsx)(ot,{initialAmountName:he.aK.catBalance(t),showToBeBudgeted:!0,onClose:n.close,onSubmit:(e,n)=>{i(o,"transfer-category",{amount:e,from:t,to:n})}}),"cover"===l&&(0,M.jsx)(ht,{onClose:n.close,onSubmit:e=>{i(o,"cover",{to:t,from:e})}})]})}let gt={flex:1,padding:"0 5px",textAlign:"right"};const ft=(0,s.memo)((function(){return(0,M.jsxs)(f.Z,{style:{flex:1,flexDirection:"row",marginRight:H,paddingTop:10,paddingBottom:10},children:[(0,M.jsxs)(f.Z,{style:gt,children:[(0,M.jsx)(S.Z,{style:{color:g.O9.n4},children:"Budgeted"}),(0,M.jsx)(Ce.Z,{binding:he.aK.totalBudgeted,type:"financial",style:{color:g.O9.n4,fontWeight:600},formatter:e=>(0,be.Z)(-parseFloat(e||"0"),"financial")})]}),(0,M.jsxs)(f.Z,{style:gt,children:[(0,M.jsx)(S.Z,{style:{color:g.O9.n4},children:"Spent"}),(0,M.jsx)(Ce.Z,{binding:he.aK.totalSpent,type:"financial",style:{color:g.O9.n4,fontWeight:600}})]}),(0,M.jsxs)(f.Z,{style:gt,children:[(0,M.jsx)(S.Z,{style:{color:g.O9.n4},children:"Balance"}),(0,M.jsx)(Ce.Z,{binding:he.aK.totalBalance,type:"financial",style:{color:g.O9.n4,fontWeight:600}})]})]})}));function yt(){return(0,M.jsx)(E.X2,{style:{color:g.O9.n4,alignItems:"center",paddingRight:10},children:(0,M.jsx)(f.Z,{style:{flex:1,textAlign:"right"},children:"Received"})})}const mt=(0,s.memo)((function(e){let{group:t}=e,n=g.O9.Cg,{id:o}=t;return(0,M.jsxs)(f.Z,{style:{flex:1,flexDirection:"row"},children:[(0,M.jsx)(E.OX,{name:"budgeted",width:"flex",borderColor:n,textAlign:"right",style:[{fontWeight:600},g.W2.tnum],valueProps:{binding:he.aK.groupBudgeted(o),type:"financial"}}),(0,M.jsx)(E.OX,{name:"spent",width:"flex",textAlign:"right",borderColor:n,style:[{fontWeight:600},g.W2.tnum],valueProps:{binding:he.aK.groupSumAmount(o),type:"financial"}}),(0,M.jsx)(E.OX,{name:"balance",width:"flex",borderColor:n,textAlign:"right",style:[{fontWeight:600,paddingRight:H},g.W2.tnum],valueProps:{binding:he.aK.groupBalance(o),type:"financial",privacyFilter:{style:{paddingRight:H}}}})]})})),xt=(0,s.memo)((function(e){let{monthIndex:t,category:n,editing:o,onEdit:i,onBudgetAction:a,onShowActivity:r}=e,l=g.O9.Cg,d=(0,O.lL)();const[c,u]=(0,s.useState)(!1),[h,y]=(0,s.useState)(!1),m=(0,p.Z)("goalTemplatesEnabled");return(0,M.jsxs)(f.Z,{style:{flex:1,flexDirection:"row","& .hover-visible":{opacity:0,transition:"opacity .25s"},"&:hover .hover-visible":{opacity:1}},children:[(0,M.jsxs)(f.Z,{style:{flex:1,flexDirection:"row",borderTopWidth:1,borderBottomWidth:1,borderColor:l,backgroundColor:"white"},onMouseOverCapture:()=>y(!0),onMouseLeave:()=>{y(!1)},children:[o||!h&&!c?null:(0,M.jsxs)(f.Z,{style:{flexShrink:1,marginRight:0,marginLeft:3,justifyContent:"center"},children:[(0,M.jsx)(C.Z,{type:"bare",onClick:e=>{e.stopPropagation(),u(!0)},style:{padding:3},children:(0,M.jsx)(v.Z,{width:14,height:14,className:"hover-visible",style:c&&{opacity:1}})}),c&&(0,M.jsx)(O.u,{position:"bottom-left",width:200,style:{padding:0},onClose:()=>u(!1),children:(0,M.jsx)(b.Z,{onMenuSelect:e=>{a(t,e,{category:n.id}),u(!1)},items:[{name:"copy-single-last",text:"Copy last month\u2019s budget"},{name:"set-single-3-avg",text:"Set to 3 month average"},{name:"set-single-6-avg",text:"Set to 6 month average"},{name:"set-single-12-avg",text:"Set to yearly average"},m&&{name:"apply-single-category-template",text:"Apply budget template"}]})})]}),(0,M.jsx)(E.OX,{name:"budget",exposed:o,focused:o,width:"flex",borderColor:"white",onExpose:()=>i(n.id,t),style:[o&&{zIndex:100},g.W2.tnum],textAlign:"right",valueStyle:[{cursor:"default",margin:1,padding:"0 4px",borderRadius:4},{":hover":{boxShadow:"inset 0 0 0 1px "+g.O9.n7,backgroundColor:"white"}}],valueProps:{binding:he.aK.catBudgeted(n.id),type:"financial",getValueStyle:$,formatExpr:e=>(0,pe.zA)(e),unformatExpr:e=>(0,pe.l9)(je(e,0))},inputProps:{onBlur:()=>{i(null)}},onSave:e=>{a(t,"budget-amount",{category:n.id,amount:e})}})]}),(0,M.jsx)(E.gN,{name:"spent",width:"flex",borderColor:l,style:{textAlign:"right"},children:(0,M.jsx)("span",{"data-testid":"category-month-spent",onClick:()=>r(n.name,n.id,t),children:(0,M.jsx)(Ce.Z,{binding:he.aK.catSumAmount(n.id),type:"financial",getStyle:$,style:{cursor:"pointer",":hover":{textDecoration:"underline"}}})})}),(0,M.jsxs)(E.gN,{name:"balance",width:"flex",borderColor:l,style:{paddingRight:H,textAlign:"right"},children:[(0,M.jsx)("span",{...d.getOpenEvents(),children:(0,M.jsx)(Ae,{carryover:he.aK.catCarryover(n.id),balance:he.aK.catBalance(n.id)})}),d.isOpen&&(0,M.jsx)(pt,{categoryId:n.id,tooltip:d,monthIndex:t,onBudgetAction:a})]})]})}));function wt(){return(0,M.jsx)(f.Z,{style:{flex:1},children:(0,M.jsx)(E.OX,{name:"received",width:"flex",borderColor:g.O9.Cg,textAlign:"right",style:[{fontWeight:600,paddingRight:H},g.W2.tnum],valueProps:{binding:he.aK.groupIncomeReceived,type:"financial",privacyFilter:{style:{paddingRight:H}}}})})}function vt(e){let{category:t,isLast:n,monthIndex:o,onShowActivity:i}=e;return(0,M.jsx)(f.Z,{style:{flex:1},children:(0,M.jsx)(E.gN,{name:"received",width:"flex",borderColor:g.O9.Cg,style:[{paddingRight:H,textAlign:"right"},n&&{borderBottomWidth:0}],children:(0,M.jsx)("span",{onClick:()=>i(t.name,t.id,o),children:(0,M.jsx)(Ce.Z,{binding:he.aK.catSumAmount(t.id),type:"financial",style:{cursor:"pointer",":hover":{textDecoration:"underline"}}})})})})}let jt=null;class Ct extends s.PureComponent{constructor(e){var t;super(e),t=this,this.prewarmMonth=async function(e){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;n=n||t.props.budgetType;let o="report"===n?"report-budget-month":"rollover-budget-month",i=await(0,d.lW)(o,{month:e});for(let s of i)t.props.spreadsheet.prewarmCache(s.name,s)},this.onMonthSelect=async(e,t)=>{this.setState({prewarmStartMonth:e}),this.warmingMonth=e;const n=jt||u.dK(),o=this.props.startMonth||n;e<o?await this.prewarmMonth(u.W9(e,1)):e>o&&await this.prewarmMonth(u.zI(e,t)),this.warmingMonth===e&&this.props.savePrefs({"budget.startMonth":e})},this.onShowNewCategory=e=>{this.setState({newCategoryForGroup:e,collapsed:this.state.collapsed.filter((t=>t!==e))})},this.onHideNewCategory=()=>{this.setState({newCategoryForGroup:null})},this.onShowNewGroup=()=>{this.setState({isAddingGroup:!0})},this.onHideNewGroup=()=>{this.setState({isAddingGroup:!1})},this.setCollapsed=e=>{this.setState({collapsed:e})},this.onSaveCategory=async e=>{let{categoryGroups:t}=this.state;if("new"===e.id){let n=await this.props.createCategory(e.name,e.cat_group,e.is_income);this.setState({newCategoryForGroup:null,categoryGroups:(0,c.i8)(t,{...e,is_income:e.is_income?1:0,id:n})})}else{const n={...e,hidden:e.hidden?1:0};this.props.updateCategory(n),this.setState({categoryGroups:(0,c.yr)(t,n)})}},this.onDeleteCategory=async e=>{const t=await(0,d.lW)("must-category-transfer",{id:e});let{categoryGroups:n}=this.state;t?this.props.pushModal("confirm-category-delete",{category:e,onDelete:t=>{e!==t&&(this.props.deleteCategory(e,t),this.setState({categoryGroups:(0,c.uu)(n,e)}))}}):(this.props.deleteCategory(e),this.setState({categoryGroups:(0,c.uu)(n,e)}))},this.onSaveGroup=async e=>{let{categoryGroups:t}=this.state;if("new"===e.id){let n=await this.props.createGroup(e.name);this.setState({isAddingGroup:!1,categoryGroups:(0,c.Rp)(t,{...e,is_income:0,categories:e.categories||[],id:n})})}else{const n={...e,hidden:e.hidden?1:0};this.props.updateGroup(n),this.setState({categoryGroups:(0,c.mD)(t,n)})}},this.onDeleteGroup=async e=>{let{categoryGroups:t}=this.state,n=t.find((t=>t.id===e)),o=!1;for(let i of n.categories)if(await(0,d.lW)("must-category-transfer",{id:i.id})){o=!0;break}o?this.props.pushModal("confirm-category-delete",{group:e,onDelete:n=>{this.props.deleteGroup(e,n),this.setState({categoryGroups:(0,c.iE)(t,e)})}}):(this.props.deleteGroup(e),this.setState({categoryGroups:(0,c.iE)(t,e)}))},this.onBudgetAction=(e,t,n)=>{this.props.applyBudgetAction(e,t,n)},this.onShowActivity=(e,t,n)=>{this.props.navigate("/accounts",{state:{goBack:!0,filterName:`${e} (${u.WU(n,"MMMM yyyy")})`,filter:{category:t,date:{$transform:"$month",$eq:n}}}})},this.onReorderCategory=async e=>{let{categoryGroups:t}=this.state;this.props.moveCategory(e.id,e.groupId,e.targetId),this.setState({categoryGroups:(0,c.Wr)(t,e.id,e.groupId,e.targetId)})},this.onReorderGroup=async e=>{let{categoryGroups:t}=this.state;this.props.moveCategoryGroup(e.id,e.targetId),this.setState({categoryGroups:(0,c.eq)(t,e.id,e.targetId)})},this.onToggleCollapse=()=>{let e=!this.state.summaryCollapsed;this.setState({summaryCollapsed:e}),this.props.savePrefs({"budget.summaryCollapsed":e})},this.onTitlebarEvent=async e=>{switch(e){case"budget/switch-type":{let e="rollover"===this.props.budgetType?"report":"rollover";this.props.spreadsheet.disableObservers(),await(0,d.lW)("budget-set-type",{type:e}),await this.prewarmAllMonths(this.state.bounds,e),this.props.spreadsheet.enableObservers(),this.props.loadPrefs();break}}};const n=jt||u.dK();this.state={initialized:!1,prewarmStartMonth:e.startMonth||n,newCategoryForGroup:null,isAddingGroup:!1,collapsed:e.collapsedPrefs||[],bounds:{start:n,end:n},categoryGroups:null,summaryCollapsed:e.summaryCollapsed}}async loadCategories(){let e=await this.props.getCategories();this.setState({categoryGroups:e.grouped})}async componentDidMount(){let{titlebar:e,budgetType:t}=this.props;this.loadCategories();let{start:n,end:o}=await(0,d.lW)("get-budget-bounds");this.setState({bounds:{start:n,end:o}}),this.prewarmAllMonths({start:n,end:o},t);let i=[(0,d.oL)("sync-event",(e=>{let{type:t,tables:n}=e;"success"===t&&(n.includes("categories")||n.includes("category_mapping")||n.includes("category_groups"))&&this.loadCategories()})),(0,d.oL)("undo-event",(e=>{let{tables:t}=e;this.table&&this.table.clearEditing(),t.includes("categories")&&this.loadCategories()})),e.subscribe(this.onTitlebarEvent)];this.cleanup=()=>{i.forEach((e=>e()))}}componentDidUpdate(e,t){t.collapsed!==this.state.collapsed&&this.props.savePrefs({"budget.collapsed":this.state.collapsed});const n=jt||u.dK(),o=this.props.startMonth||n;t.startMonth!==o&&(jt=o),this.props.accountId!==e.accountId&&(0,d.lW)("get-budget-bounds").then((e=>{let{start:t,end:n}=e,{bounds:o}=this.state;o.start===t&&o.end===n||this.setState({bounds:{start:t,end:n}})}))}componentWillUnmount(){this.cleanup&&this.cleanup()}async prewarmAllMonths(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;const n=jt||u.dK(),o=this.props.startMonth||n;e=P(e,u.W9(o,1),u.zI(o,4));let i=u.Do(e.start,e.end);await Promise.all(i.map((e=>this.prewarmMonth(e,t)))),this.setState({initialized:!0})}onCopy(e){this.props.copyPreviousMonthInto(e,this.props.categories)}render(){let{maxMonths:e,budgetType:t,reportComponents:n,rolloverComponents:o}=this.props,{initialized:i,categoryGroups:s,prewarmStartMonth:a,newCategoryForGroup:r,isAddingGroup:l,collapsed:d,summaryCollapsed:c,bounds:h}=this.state;if(e=e||1,!i||!s)return null;const p=jt||u.dK(),g=this.props.startMonth||p;let y;return y="report"===t?(0,M.jsx)(De,{summaryCollapsed:c,onBudgetAction:this.onBudgetAction,onToggleSummaryCollapse:this.onToggleCollapse,children:(0,M.jsx)(ue,{ref:e=>this.table=e,type:t,categoryGroups:s,prewarmStartMonth:a,startMonth:g,monthBounds:h,maxMonths:e,collapsed:d,setCollapsed:this.setCollapsed,newCategoryForGroup:r,isAddingGroup:l,dataComponents:n,onMonthSelect:this.onMonthSelect,onShowNewCategory:this.onShowNewCategory,onHideNewCategory:this.onHideNewCategory,onShowNewGroup:this.onShowNewGroup,onHideNewGroup:this.onHideNewGroup,onDeleteCategory:this.onDeleteCategory,onDeleteGroup:this.onDeleteGroup,onSaveCategory:this.onSaveCategory,onSaveGroup:this.onSaveGroup,onBudgetAction:this.onBudgetAction,onShowActivity:this.onShowActivity,onReorderCategory:this.onReorderCategory,onReorderGroup:this.onReorderGroup})}):(0,M.jsx)(lt,{categoryGroups:s,summaryCollapsed:c,onBudgetAction:this.onBudgetAction,onToggleSummaryCollapse:this.onToggleCollapse,children:(0,M.jsx)(ue,{ref:e=>this.table=e,type:t,categoryGroups:s,prewarmStartMonth:a,startMonth:g,monthBounds:h,maxMonths:e,collapsed:d,setCollapsed:this.setCollapsed,newCategoryForGroup:r,isAddingGroup:l,dataComponents:o,onMonthSelect:this.onMonthSelect,onShowNewCategory:this.onShowNewCategory,onHideNewCategory:this.onHideNewCategory,onShowNewGroup:this.onShowNewGroup,onHideNewGroup:this.onHideNewGroup,onDeleteCategory:this.onDeleteCategory,onDeleteGroup:this.onDeleteGroup,onSaveCategory:this.onSaveCategory,onSaveGroup:this.onSaveGroup,onBudgetAction:this.onBudgetAction,onShowActivity:this.onShowActivity,onReorderCategory:this.onReorderCategory,onReorderGroup:this.onReorderGroup})}),(0,M.jsx)(f.Z,{style:{flex:1},innerRef:e=>this.page=e,children:y})}}const bt=(0,s.memo)((e=>{const t=(0,p.Z)("goalTemplatesEnabled");return(0,M.jsx)(ut,{...e,isGoalTemplatesEnabled:t})}));function St(e){let t=(0,a.v9)((e=>e.prefs.local["budget.startMonth"])),n=(0,a.v9)((e=>e.prefs.local["budget.collapsed"])),d=(0,a.v9)((e=>e.prefs.local["budget.summaryCollapsed"])),c=(0,a.v9)((e=>e.prefs.local.budgetType||"rollover")),u=(0,a.v9)((e=>e.prefs.global.maxMonths)),p=(0,a.v9)((e=>e.queries.categories.grouped)),m=(0,h.o)(),x=(0,l.M)(),w=(0,s.useContext)(y.CR),v=(0,r.TH)(),j=(0,r.bS)(v.pathname),C=(0,r.s0)(),b=(0,s.useMemo)((()=>({SummaryComponent:He,ExpenseCategoryComponent:qe,ExpenseGroupComponent:Xe,IncomeCategoryComponent:Je,IncomeGroupComponent:Ye,BudgetTotalsComponent:ze,IncomeHeaderComponent:Ke})),[o]),S=(0,s.useMemo)((()=>({SummaryComponent:bt,ExpenseCategoryComponent:xt,ExpenseGroupComponent:mt,IncomeCategoryComponent:vt,IncomeGroupComponent:wt,BudgetTotalsComponent:ft,IncomeHeaderComponent:yt})),[i]);return(0,M.jsx)(f.Z,{style:[g.W2.page,{paddingLeft:8,paddingRight:8,overflow:"hidden"}],children:(0,M.jsx)(Ct,{startMonth:t,collapsedPrefs:n,summaryCollapsed:d,budgetType:c,maxMonths:u,categoryGroups:p,...m,reportComponents:b,rolloverComponents:S,spreadsheet:x,titlebar:w,navigate:C,match:j})})}var Zt=n(33865),At=n(22581),kt=n(38102),Mt=n(17877),Tt=n(15068),Ot=n(69476),It=n(88370);var Bt=e=>(0,M.jsx)("svg",{...e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",style:{color:"inherit",...e.style},children:(0,M.jsx)("path",{fill:"currentColor",d:"M6.847 21.429a3.408 3.408 0 0 1-2.662-1.34l-3.76-4.273a1.714 1.714 0 0 1 2.572-2.263l3.522 4.01a.429.429 0 0 0 .631.014L21.036 3.105a1.715 1.715 0 1 1 2.486 2.362l-14.06 14.8a3.327 3.327 0 0 1-2.615 1.162Z"})}),Rt=n(64652),Dt=n(21912);let Et=43;function Nt(e){let{schedule:t,status:n,onAction:o}=e,[i,a]=(0,s.useState)(!1);return(0,M.jsxs)(f.Z,{children:[(0,M.jsx)(C.Z,{type:"bare",onClick:e=>{e.stopPropagation(),a(!0)},children:(0,M.jsx)(j.Z,{width:15,height:15,style:{transform:"rotateZ(90deg)"}})}),i&&(0,M.jsx)(O.u,{position:"bottom-right",width:150,style:{padding:0},onClose:()=>a(!1),children:(0,M.jsx)(b.Z,{onMenuSelect:e=>{o(e,t.id),a(!1)},items:["due"===n&&{name:"post-transaction",text:"Post transaction"},...t.completed?[{name:"restart",text:"Restart"}]:[{name:"skip",text:"Skip next date"},{name:"complete",text:"Complete"}],{name:"delete",text:"Delete"}]})})]})}function Ft(e){let{amount:t,op:n}=e,o=(0,It.lP)(t),i=(0,pe.zA)(Math.abs(o||0)),s="isapprox"===n||"isbetween"===n;return(0,M.jsxs)(E.bL,{width:100,plain:!0,style:{textAlign:"right",flexDirection:"row",alignItems:"center",padding:"0 5px"},name:"amount",children:[s&&(0,M.jsx)(f.Z,{style:{textAlign:"left",color:g.O9.n7,lineHeight:"1em",marginRight:10},title:(s?"Approximately ":"")+i,children:"~"}),(0,M.jsx)(S.Z,{style:{flex:1,color:o>0?g.O9.g5:null,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},title:(s?"Approximately ":"")+i,children:o>0?`+${i}`:`${i}`})]})}function Pt(e){let{schedules:t,statuses:n,filter:o,minimal:i,allowCompleted:r,style:l,onSelect:d,onAction:c,tableStyle:h}=e,p=(0,a.v9)((e=>e.prefs.local.dateFormat||"MM/dd/yyyy")),[y,m]=(0,s.useState)(!1),x=(0,Ot.n4)(),w=(0,Tt.gM)(),v=(0,s.useMemo)((()=>{if(!o)return t;const e=e=>!!e&&(e.toLowerCase().includes(o.toLowerCase())||o.toLowerCase().includes(e.toLowerCase()));return t.filter((t=>{let o=x.find((e=>t._payee===e.id)),i=w.find((e=>t._account===e.id)),s=(0,It.lP)(t._amount),a=("isapprox"===t._amountOp||"isbetween"===t._amountOp?"~":"")+(s>0?"+":"")+(0,pe.zA)(Math.abs(s||0)),r=t.next_date?u.WU(t.next_date,p):null;return e(t.name)||e(o&&o.name)||e(i&&i.name)||e(a)||e(n.get(t.id))||e(r)}))}),[t,o,n]),j=(0,s.useMemo)((()=>{if(!r)return v.filter((e=>!e.completed));if(y)return v;let e=v.filter((e=>!e.completed));return v.find((e=>e.completed))&&e.push({type:"show-completed"}),e}),[v,y,r]);return(0,M.jsxs)(f.Z,{style:[{flex:1},h],children:[(0,M.jsxs)(E.xD,{height:Et,inset:15,version:"v2",children:[(0,M.jsx)(E.gN,{width:"flex",children:"Name"}),(0,M.jsx)(E.gN,{width:"flex",children:"Payee"}),(0,M.jsx)(E.gN,{width:"flex",children:"Account"}),(0,M.jsx)(E.gN,{width:110,children:"Next date"}),(0,M.jsx)(E.gN,{width:120,children:"Status"}),(0,M.jsx)(E.gN,{width:100,style:{textAlign:"right"},children:"Amount"}),!i&&(0,M.jsx)(E.gN,{width:80,style:{textAlign:"center"},children:"Recurring"}),!i&&(0,M.jsx)(E.gN,{width:40})]}),(0,M.jsx)(E.iA,{rowHeight:Et,backgroundColor:"transparent",version:"v2",style:[{flex:1,backgroundColor:"transparent"},l],items:j,renderItem:function(e){let{item:t}=e;return"show-completed"===t.type?(0,M.jsx)(E.X2,{height:Et,inset:15,backgroundColor:"transparent",style:{cursor:"pointer",backgroundColor:"white",":hover":{backgroundColor:g.O9.Mr}},onClick:()=>m(!0),children:(0,M.jsx)(E.gN,{width:"flex",style:{fontStyle:"italic",textAlign:"center",color:g.O9.n6},children:"Show completed schedules"})}):function(e){let{item:t}=e;return(0,M.jsxs)(E.X2,{height:Et,inset:15,backgroundColor:"transparent",onClick:()=>d(t.id),style:{cursor:"pointer",backgroundColor:"white",":hover":{backgroundColor:g.O9.Mr}},children:[(0,M.jsx)(E.gN,{width:"flex",name:"name",children:(0,M.jsx)(S.Z,{style:null==t.name?{color:g.O9.n8}:null,title:t.name?t.name:"",children:t.name?t.name:"None"})}),(0,M.jsx)(E.gN,{width:"flex",name:"payee",children:(0,M.jsx)(Rt.Z,{type:"payees",id:t._payee})}),(0,M.jsx)(E.gN,{width:"flex",name:"account",children:(0,M.jsx)(Rt.Z,{type:"accounts",id:t._account})}),(0,M.jsx)(E.gN,{width:110,name:"date",children:t.next_date?u.WU(t.next_date,p):null}),(0,M.jsx)(E.gN,{width:120,name:"status",style:{alignItems:"flex-start"},children:(0,M.jsx)(Dt.O,{status:n.get(t.id)})}),(0,M.jsx)(Ft,{amount:t._amount,op:t._amountOp}),!i&&(0,M.jsx)(E.gN,{width:80,style:{textAlign:"center"},children:t._date&&t._date.frequency&&(0,M.jsx)(Bt,{style:{width:13,height:13}})}),!i&&(0,M.jsx)(E.gN,{width:40,name:"actions",children:(0,M.jsx)(Nt,{schedule:t,status:n.get(t.id),onAction:c})})]})}({item:t})},renderEmpty:o?"No matching schedules":"No schedules",allowPopupsEscape:j.length<6})]})}function _t(){let e=(0,At.cu)(),[t,n]=(0,s.useState)(""),o=(0,Zt.gZ)();if(null==o)return null;let{schedules:i,statuses:a}=o;return(0,M.jsxs)(Mt.T3,{title:"Schedules",children:[(0,M.jsx)(f.Z,{style:{alignItems:"flex-end"},children:(0,M.jsx)(kt.Z,{placeholder:"Filter schedules\u2026",value:t,onChange:n})}),(0,M.jsx)(f.Z,{style:{marginTop:15,flexBasis:(Et-1)*(Math.max(i.length,1)+1),overflow:"hidden"},children:(0,M.jsx)(Pt,{schedules:i,filter:t,statuses:a,allowCompleted:!0,onSelect:function(t){e(`/schedule/edit/${t}`)},onAction:async function(e,t){switch(e){case"post-transaction":await(0,d.lW)("schedule/post-transaction",{id:t});break;case"skip":await(0,d.lW)("schedule/skip-next-date",{id:t});break;case"complete":await(0,d.lW)("schedule/update",{schedule:{id:t,completed:!0}});break;case"restart":await(0,d.lW)("schedule/update",{schedule:{id:t,completed:!1},resetNextDate:!0});break;case"delete":await(0,d.lW)("schedule/delete",{id:t})}},style:{backgroundColor:"white"}})}),(0,M.jsxs)(f.Z,{style:{flexDirection:"row",justifyContent:"space-between",margin:"20px 0",flexShrink:0},children:[(0,M.jsx)(C.Z,{onClick:function(){e("/schedule/discover")},children:"Find schedules"}),(0,M.jsx)(C.Z,{type:"primary",onClick:function(){e("/schedule/edit")},children:"Add new schedule"})]})]})}var Wt=n(91669),Lt=n(95058),Gt=n(25432),Ht=n(35946),Ut=n(36717),zt=n(97117),Kt=n(95547),$t=n(73964),Vt=n(39432),Qt=n(41218),Xt=n(99446);function qt(e,t){let n={...e};return t&&Object.keys(t).forEach((o=>{o in e&&(n[o]=t[o])})),n}function Yt(e,t){let n=(0,It.lq)(e._conditions),o=(e,t,n,o)=>e?{...e,value:o}:null!=o?{op:t,field:n,value:o}:null;return null==t.date?{error:"Date is required"}:null==t.amount?{error:"A valid amount is required"}:{conditions:[o(n.payee,"is","payee",t.payee),o(n.account,"is","account",t.account),o(n.date,"isapprox","date",t.date),{op:t.amountOp,field:"amount",value:t.amount}].filter(Boolean)}}function Jt(){let{id:e,initialFields:t}=(0,r.UO)(),n=null==e,o=(0,Ot.n4)({idKey:!0}),i=(0,r.s0)(),l=(0,a.I0)(),c=(0,a.v9)((e=>e.prefs.local.dateFormat||"MM/dd/yyyy")),[h,p]=(0,s.useReducer)(((e,t)=>{switch(t.type){case"set-schedule":{let n=t.schedule,o=(0,It.lq)(n._conditions),i=new Set(Object.values(o)),s=n._conditions.find((e=>!i.has(e)))||n._actions.find((e=>"link-schedule"!==e.op));return{...e,schedule:t.schedule,isCustom:s,fields:{payee:n._payee,account:n._account,amount:n._amount||0,amountOp:n._amountOp||"isapprox",date:n._date,posts_transaction:t.schedule.posts_transaction,name:n.name}}}case"set-field":if(!(t.field in e.fields))throw new Error("Unknown field: "+t.field);let n={[t.field]:t.value};return"amountOp"===t.field&&t.value!==e.fields.amountOp&&("isbetween"===t.value?n.amount="number"===typeof e.fields.amount?{num1:e.fields.amount,num2:e.fields.amount}:{num1:0,num2:0}:"isbetween"===e.fields.amountOp&&(n.amount="number"===typeof e.fields.amount?e.fields.amount:e.fields.amount.num1)),{...e,fields:{...e.fields,...n}};case"set-transactions":return{...e,transactions:t.transactions};case"set-repeats":return{...e,fields:{...e.fields,date:t.repeats?{frequency:"monthly",start:u.PR(),patterns:[]}:u.PR()}};case"set-upcoming-dates":return{...e,upcomingDates:t.dates};case"form-error":return{...e,error:t.error};case"switch-transactions":return{...e,transactionsMode:t.mode};default:throw new Error("Unknown action: "+t.type)}}),{schedule:null,upcomingDates:null,error:null,fields:qt({payee:null,account:null,amount:null,amountOp:null,date:null,posts_transaction:!1,name:null},t),transactions:[],transactionsMode:n?"matched":"linked"});async function y(){let{data:t}=await(0,A.Vn)((0,A.ZP)("schedules").filter({id:e}).select("*"));return t[0]}(0,s.useEffect)((()=>{!async function(){if(n){let e={start:u.PR(),frequency:"monthly",patterns:[]};p({type:"set-schedule",schedule:{posts_transaction:!1,_date:e,_conditions:[{op:"isapprox",field:"date",value:e}],_actions:[]}})}else{let e=await y();e&&null==h.schedule&&p({type:"set-schedule",schedule:e})}}()}),[]),(0,s.useEffect)((()=>{!async function(){let e=h.fields.date;if(null==e)p({type:"set-upcoming-dates",dates:null});else if(e.frequency){let{data:t}=await(0,d.OK)("schedule/get-upcoming-dates",{config:e,count:3});p({type:"set-upcoming-dates",dates:t})}else{let t=u.PR();e===t||u.Ax(e,t)?p({type:"set-upcoming-dates",dates:[e]}):p({type:"set-upcoming-dates",dates:null})}}()}),[h.fields.date]),(0,s.useEffect)((()=>{if(h.schedule&&h.schedule.id&&"linked"===h.transactionsMode){return(0,A.Y1)((0,A.ZP)("transactions").filter({schedule:h.schedule.id}).select("*").options({splits:"none"}),(e=>p({type:"set-transactions",transactions:e}))).unsubscribe}}),[h.schedule,h.transactionsMode]),(0,s.useEffect)((()=>{let e,t=!0;if(h.schedule&&"matched"===h.transactionsMode){let{error:n,conditions:o}=Yt(h.schedule,h.fields);if(n)return void p({type:"form-error",error:n});o=o.map((e=>"description"===e.field?{...e,field:"payee"}:"acct"===e.field?{...e,field:"account"}:e)),(0,d.lW)("make-filters-from-conditions",{conditions:o}).then((n=>{let{filters:o}=n;if(t){let t=(0,A.Y1)((0,A.ZP)("transactions").filter({$and:o}).select("*").options({splits:"none"}),(e=>p({type:"set-transactions",transactions:e})));e=t.unsubscribe}}))}return()=>{t=!1,e&&e()}}),[h.schedule,h.transactionsMode,h.fields]);let m=(0,Lt.ZP)("transactions",h.transactions,[]);async function x(e,t){await(0,d.lW)("transactions-batch-update",{updated:e.map((e=>({id:e,schedule:t||h.schedule.id})))}),m.dispatch({type:"select-none"})}if(null==h.schedule)return null;function w(e){p({type:"switch-transactions",mode:e}),m.dispatch({type:"select-none"})}let v=o?o[h.fields.payee]:null,j=!!h.fields.date&&!!h.fields.date.frequency;return(0,M.jsxs)(Mt.T3,{title:v?`Schedule: ${v.name}`:"Schedule",modalSize:"medium",children:[(0,M.jsx)(Ie.Z,{direction:"row",style:{marginTop:10},children:(0,M.jsxs)(Ut.Wi,{style:{flex:1},children:[(0,M.jsx)(Ut.lX,{title:"Schedule Name",htmlFor:"name-field"}),(0,M.jsx)(Xt.Z,{field:"string",type:"string",value:h.fields.name,multi:!1,onChange:e=>{p({type:"set-field",field:"name",value:e})}})]})}),(0,M.jsxs)(Ie.Z,{direction:"row",style:{marginTop:20},children:[(0,M.jsxs)(Ut.Wi,{style:{flex:1},children:[(0,M.jsx)(Ut.lX,{title:"Payee",id:"payee-label",htmlFor:"payee-field"}),(0,M.jsx)(Ht.Z,{value:h.fields.payee,labelProps:{id:"payee-label"},inputProps:{id:"payee-field",placeholder:"(none)"},onSelect:e=>p({type:"set-field",field:"payee",value:e}),isCreatable:!0})]}),(0,M.jsxs)(Ut.Wi,{style:{flex:1},children:[(0,M.jsx)(Ut.lX,{title:"Account",id:"account-label",htmlFor:"account-field"}),(0,M.jsx)(Gt.Z,{includeClosedAccounts:!1,value:h.fields.account,labelProps:{id:"account-label"},inputProps:{id:"account-field",placeholder:"(none)"},onSelect:e=>p({type:"set-field",field:"account",value:e})})]}),(0,M.jsxs)(Ut.Wi,{style:{flex:1},children:[(0,M.jsxs)(Ie.Z,{direction:"row",align:"center",style:{marginBottom:3},children:[(0,M.jsx)(Ut.lX,{title:"Amount",htmlFor:"amount-field",style:{margin:0,flex:1}}),(0,M.jsx)(zt.Jz,{ops:["isapprox","is","isbetween"],value:h.fields.amountOp,formatOp:e=>{switch(e){case"is":return"is exactly";case"isapprox":return"is approximately";case"isbetween":return"is between";default:throw new Error("Invalid op for select: "+e)}},style:{padding:"0 10px",color:g.O9.n5,fontSize:12},onChange:(e,t)=>p({type:"set-field",field:"amountOp",value:t})})]}),"isbetween"===h.fields.amountOp?(0,M.jsx)(Qt.I,{defaultValue:h.fields.amount,onChange:e=>p({type:"set-field",field:"amount",value:e})}):(0,M.jsx)(Qt._,{id:"amount-field",defaultValue:h.fields.amount,onChange:e=>p({type:"set-field",field:"amount",value:e})})]})]}),(0,M.jsx)(f.Z,{style:{marginTop:20},children:(0,M.jsx)(Ut.lX,{title:"Date"})}),(0,M.jsxs)(Ie.Z,{direction:"row",align:"flex-start",children:[(0,M.jsxs)(f.Z,{style:{flex:1},children:[j?(0,M.jsx)($t.Z,{value:h.fields.date,onChange:e=>p({type:"set-field",field:"date",value:e})}):(0,M.jsx)(Kt.Z,{value:h.fields.date,onSelect:e=>p({type:"set-field",field:"date",value:e}),dateFormat:c}),h.upcomingDates&&(0,M.jsxs)(f.Z,{style:{fontSize:13,marginTop:20},children:[(0,M.jsx)(S.Z,{style:{color:g.O9.n4,fontWeight:600},children:"Upcoming dates"}),(0,M.jsx)(Ie.Z,{direction:"column",spacing:1,style:{marginTop:10,color:g.O9.n4},children:h.upcomingDates.map((e=>(0,M.jsx)(f.Z,{children:u.WU(e,`${c} EEEE`)},e)))})]})]}),(0,M.jsxs)(f.Z,{style:{marginTop:5,flex:1,flexDirection:"row",alignItems:"center",userSelect:"none"},children:[(0,M.jsx)(Ut.XZ,{id:"form_repeats",checked:j,onChange:e=>{p({type:"set-repeats",repeats:e.target.checked})}}),(0,M.jsx)("label",{htmlFor:"form_repeats",style:{userSelect:"none"},children:"Repeats"})]}),(0,M.jsxs)(f.Z,{style:{alignItems:"flex-end",flex:1},children:[(0,M.jsxs)(f.Z,{style:{marginTop:5,flexDirection:"row",alignItems:"center",userSelect:"none",justifyContent:"flex-end"},children:[(0,M.jsx)(Ut.XZ,{id:"form_posts_transaction",checked:h.fields.posts_transaction,onChange:e=>{p({type:"set-field",field:"posts_transaction",value:e.target.checked})}}),(0,M.jsx)("label",{htmlFor:"form_posts_transaction",style:{userSelect:"none"},children:"Automatically add transaction"})]}),(0,M.jsx)(S.Z,{style:{width:350,textAlign:"right",color:g.O9.n4,marginTop:10,fontSize:13,lineHeight:"1.4em"},children:"If checked, the schedule will automatically create transactions for you in the specified account"}),!n&&h.schedule.rule&&(0,M.jsxs)(Ie.Z,{direction:"row",align:"center",style:{marginTop:30},children:[h.isCustom&&(0,M.jsx)(S.Z,{style:{color:g.O9.b5,fontSize:13,textAlign:"right",width:350},children:"This schedule has custom conditions and actions"}),(0,M.jsx)(C.Z,{onClick:()=>async function(e){let t=await(0,d.lW)("rule-get",{id:e||h.schedule.rule});l((0,Wt.Ll)("edit-rule",{rule:t,onSave:async()=>{let e=await y();p({type:"set-schedule",schedule:e})}}))}(),disabled:n,children:"Edit as rule"})]})]})]}),(0,M.jsx)(f.Z,{style:{marginTop:30,flex:1},children:(0,M.jsxs)(Lt.i5,{instance:m,children:[n?(0,M.jsxs)(f.Z,{style:{flexDirection:"row",padding:"5px 0"},children:[(0,M.jsx)(S.Z,{style:{color:g.O9.n4},children:"These transactions match this schedule:"}),(0,M.jsx)(f.Z,{style:{flex:1}}),(0,M.jsx)(S.Z,{style:{color:g.O9.n6},children:"Select transactions to link on save"})]}):(0,M.jsxs)(f.Z,{style:{flexDirection:"row",alignItems:"center"},children:[(0,M.jsx)(C.Z,{type:"bare",style:{color:"linked"===h.transactionsMode?g.O9.b4:g.O9.n7,marginRight:10,fontSize:14},onClick:()=>w("linked"),children:"Linked transactions"})," ",(0,M.jsx)(C.Z,{type:"bare",style:{color:"matched"===h.transactionsMode?g.O9.b4:g.O9.n7,fontSize:14},onClick:()=>w("matched"),children:"Find matching transactions"}),(0,M.jsx)(f.Z,{style:{flex:1}}),(0,M.jsx)(E.Vg,{name:"transactions",items:"linked"===h.transactionsMode?[{name:"unlink",text:"Unlink from schedule"}]:[{name:"link",text:"Link to schedule"}],onSelect:(e,t)=>{switch(e){case"link":x(t);break;case"unlink":!async function(e){await(0,d.lW)("transactions-batch-update",{updated:e.map((e=>({id:e,schedule:null})))}),m.dispatch({type:"select-none"})}(t)}}})]}),(0,M.jsx)(Vt.Z,{renderEmpty:"matched"===h.transactionsMode&&(()=>(0,M.jsx)(f.Z,{style:{padding:20,color:g.O9.n4,textAlign:"center"},children:h.error?(0,M.jsxs)(S.Z,{style:{color:g.O9.r4},children:["Could not search: ",h.error]}):"No transactions found"})),transactions:h.transactions,fields:["date","payee","amount"],style:{border:"1px solid "+g.O9.Cg,borderRadius:4,overflow:"hidden",marginTop:5}})]})}),(0,M.jsxs)(Ie.Z,{direction:"row",justify:"flex-end",align:"center",style:{marginTop:20},children:[h.error&&(0,M.jsx)(S.Z,{style:{color:g.O9.r4},children:h.error}),(0,M.jsx)(C.Z,{style:{marginRight:10},onClick:()=>i(-1),children:"Cancel"}),(0,M.jsx)(C.Z,{type:"primary",onClick:async function(){if(p({type:"form-error",error:null}),h.fields.name){let{data:e}=await(0,A.Vn)((0,A.ZP)("schedules").filter({name:h.fields.name}).select("id"));if(e.length>0&&e[0].id!==h.schedule.id)return void p({type:"form-error",error:"There is already a schedule with this name"})}let{error:e,conditions:t}=Yt(h.schedule,h.fields);if(e)return void p({type:"form-error",error:e});let o=await(0,d.OK)(n?"schedule/create":"schedule/update",{schedule:{id:h.schedule.id,posts_transaction:h.fields.posts_transaction,name:h.fields.name},conditions:t});o.error?p({type:"form-error",error:"An error occurred while saving. Please visit https://actualbudget.org/contact/ for support."}):(n&&await x([...m.items],o.data),i(-1))},children:n?"Add":"Save"})]})]})}function en(){let e=(0,r.TH)(),t=(0,r.s0)(),n=(0,Zt.gZ)((0,s.useCallback)((e=>e.filter({completed:!1})),[])),[o,i]=(0,s.useState)("");if(null==n)return null;let{schedules:a,statuses:l}=n;return(0,M.jsxs)(Mt.T3,{title:"Link Schedule",modalSize:"medium",children:[(0,M.jsxs)(f.Z,{style:{flexDirection:"row",marginBottom:20,alignItems:"center"},children:[(0,M.jsx)(S.Z,{children:"Choose a schedule to link these transactions to:"}),(0,M.jsx)(f.Z,{style:{flex:1}}),(0,M.jsx)(kt.Z,{isInModal:!0,width:300,placeholder:"Filter schedules\u2026",value:o,onChange:i})]}),(0,M.jsx)(Pt,{schedules:a,filter:o,statuses:l,minimal:!0,onSelect:async function(n){let{state:o}=e,i=o.transactionIds;i&&i.length>0&&await(0,d.lW)("transactions-batch-update",{updated:i.map((e=>({id:e,schedule:n})))}),t(-1)},tableStyle:{marginInline:-20}})]})}var tn=n(803);let nn=43;function on(e){let{schedules:t,loading:n}=e,o=(0,Mt.xb)(),i=(0,Lt.D9)(),s=(0,Lt.YP)();return(0,M.jsxs)(f.Z,{style:{flex:1},children:[(0,M.jsxs)(E.xD,{height:nn,inset:15,version:"v2",children:[(0,M.jsx)(E._7,{exposed:!n,focused:!1,selected:i.size>0,onSelect:e=>s({type:"select-all",event:e})}),(0,M.jsx)(E.gN,{width:"flex",children:"Payee"}),(0,M.jsx)(E.gN,{width:"flex",children:"Account"}),(0,M.jsx)(E.gN,{width:"auto",style:{flex:1.5},children:"When"}),(0,M.jsx)(E.gN,{width:100,style:{textAlign:"right"},children:"Amount"})]}),(0,M.jsx)(E.iA,{rowHeight:nn,version:"v2",backgroundColor:"modal"===o.type?"transparent":void 0,style:{flex:1,backgroundColor:"modal"===o.type?"transparent":void 0},items:t,loading:n,isSelected:e=>i.has(e),renderItem:function(e){let{item:t}=e,n=i.has(t.id),o=t._conditions.find((e=>"amount"===e.field)).op,a=(0,It.o7)(t.date);return(0,M.jsxs)(E.X2,{height:nn,inset:15,backgroundColor:"transparent",onClick:e=>{s({type:"select",id:t.id,event:e})},borderColor:n?g.O9.b8:g.O9.Cg,style:{cursor:"pointer",backgroundColor:n?g.O9.hv:"white",":hover":{backgroundColor:n?g.O9.hv:g.O9.Mr}},children:[(0,M.jsx)(E._7,{exposed:!0,focused:!1,selected:n,onSelect:e=>{s({type:"select",id:t.id,event:e})}}),(0,M.jsx)(E.gN,{width:"flex",children:(0,M.jsx)(Rt.Z,{type:"payees",id:t.payee})}),(0,M.jsx)(E.gN,{width:"flex",children:(0,M.jsx)(Rt.Z,{type:"accounts",id:t.account})}),(0,M.jsx)(E.gN,{width:"auto",title:a,style:{flex:1.5},children:a}),(0,M.jsx)(Ft,{amount:t.amount,op:o})]})},renderEmpty:"No schedules found"})]})}function sn(){let e=(0,Mt.xb)(),t=(0,r.s0)(),{data:n,isLoading:o}=function(e,t,n){const[o,i]=(0,s.useState)(null),[a,r]=(0,s.useState)(null);return(0,s.useEffect)((()=>{!async function(){r(!0),i(await(0,d.lW)(e,t,n)),r(!1)}()}),[e,t,n]),{data:o,isLoading:a}}("schedule/discover");n||(n=[]);let[i,a]=(0,s.useState)(!1),l=(0,Lt.ZP)("discover-schedules",n,[]),c=(0,r.TH)();if(!(0,At.G_)(c))return(0,M.jsx)(r.Fg,{to:"/schedules",replace:!0});return(0,M.jsxs)(Mt.T3,{title:"Found schedules",modalSize:{width:850,height:650},children:[(0,M.jsx)(tn.Z,{children:"We found some possible schedules in your current transactions. Select the ones you want to create."}),(0,M.jsx)(tn.Z,{children:"If you expected a schedule here and don\u2019t see it, it might be because the payees of the transactions don\u2019t match. Make sure you rename payees on all transactions for a schedule to be the same payee."}),(0,M.jsx)(Lt.i5,{instance:l,children:(0,M.jsx)(on,{loading:o,schedules:n})}),(0,M.jsx)(Ie.Z,{direction:"row",align:"center",justify:"flex-end",style:{paddingTop:20,paddingBottom:"modal"===e.type?0:20},children:(0,M.jsx)(C.y,{type:"primary",loading:i,disabled:0===l.items.size,onClick:async function(){let e=n.filter((e=>l.items.has(e.id)));a(!0);for(let t of e){let e=await(0,d.lW)("schedule/create",{conditions:t._conditions}),{filters:n}=await(0,d.lW)("make-filters-from-conditions",{conditions:t._conditions});if(n.length>0){let{data:t}=await(0,A.Vn)((0,A.ZP)("transactions").filter({$and:n}).select("id"));await(0,d.lW)("transactions-batch-update",{updated:t.map((t=>({id:t.id,schedule:e})))})}}a(!1),t(-1)},children:"Create schedules"})})]})}var an=n(42131);function rn(){return window.close(),(0,M.jsx)(an.C,{isCurrent:!0,showClose:!1,title:"Account sync",children:()=>(0,M.jsxs)(f.Z,{style:{maxWidth:500},children:[(0,M.jsx)(tn.Z,{children:"Please wait..."}),(0,M.jsx)(tn.Z,{children:"The window should close automatically. If nothing happend you can close this window or tab."})]})})}var ln=n(74881),dn=n(18753),cn=n(17199),un=n(26018),hn=n(28731),pn=n(49963),gn=n(77799),fn=n(48664),yn=n(81785),mn=n(45249),xn=n(5499);var wn=e=>(0,M.jsx)("svg",{...e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 91 51",style:{color:"inherit",...e.style},children:(0,M.jsx)("path",{fill:"currentColor",d:"M30.256 48.614a3.14 3.14 0 0 0-.989-2.153L10.803 29.063h76.915a3.2 3.2 0 0 0 .315 0c1.584-.084 2.95-1.64 2.867-3.266-.082-1.625-1.598-3.028-3.182-2.943H10.803L29.267 5.49c1.284-1.099 1.456-3.057.385-4.373a2.972 2.972 0 0 0-4.48-.187L.971 23.695a3.163 3.163 0 0 0 0 4.56l24.2 22.766a2.98 2.98 0 0 0 2.205.84c1.669-.08 2.958-1.534 2.88-3.247Z"})}),vn=n(17888);var jn=e=>(0,M.jsx)("svg",{...e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",style:{color:"inherit",...e.style},children:(0,M.jsx)("path",{d:"m9 16.172-6.071-6.071-1.414 1.414L10 20l.707-.707 7.778-7.778-1.414-1.414L11 16.172V0H9z",fill:"currentColor"})});var Cn=e=>(0,M.jsx)("svg",{...e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",style:{color:"inherit",...e.style},children:(0,M.jsx)("path",{d:"M9 3.828 2.929 9.899 1.515 8.485 10 0l.707.707 7.778 7.778-1.414 1.414L11 3.828V20H9V3.828z",fill:"currentColor"})}),bn=n(56288),Sn=n(32873);var Zn=e=>(0,M.jsxs)("svg",{...e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",style:{color:"inherit",...e.style},children:[(0,M.jsx)("path",{d:"M12.406 14.905a1 1 0 0 0-.543 1.307 1 1 0 0 1-.217 1.09l-2.828 2.829a2 2 0 0 1-2.828 0L3.868 18.01a2 2 0 0 1 0-2.829L6.7 12.353a1.013 1.013 0 0 1 1.091-.217 1 1 0 0 0 .763-1.849 3.034 3.034 0 0 0-3.268.652l-2.832 2.828a4.006 4.006 0 0 0 0 5.657l2.122 2.121a4 4 0 0 0 5.656 0l2.829-2.828a3.008 3.008 0 0 0 .651-3.27 1 1 0 0 0-1.306-.542Z",fill:"currentColor"}),(0,M.jsx)("path",{d:"M7.757 16.241a1.011 1.011 0 0 0 1.414 0l7.779-7.778a1 1 0 0 0-1.414-1.414l-7.779 7.778a1 1 0 0 0 0 1.414Z",fill:"currentColor"}),(0,M.jsx)("path",{d:"m21.546 4.574-2.121-2.121a4.006 4.006 0 0 0-5.657 0l-2.829 2.828a3.006 3.006 0 0 0-.651 3.269 1 1 0 1 0 1.849-.764 1 1 0 0 1 .217-1.086l2.828-2.828a2 2 0 0 1 2.829 0l2.121 2.121a2 2 0 0 1 0 2.829L17.3 11.645a1.015 1.015 0 0 1-1.091.217 1 1 0 0 0-.765 1.849 3.026 3.026 0 0 0 3.27-.651l2.828-2.828a4.007 4.007 0 0 0 .004-5.658Z",fill:"currentColor"})]});function An(e,t){let{amount:n,date:o}=e;Ln(e.id)&&(n=(e._inverse?-1:1)*(0,It.lP)(n));let i=n<0?-n:null,s=n>0?n:null;return 0===n&&(t?s=0:i=0),(0,fn.Z)((0,yn.Z)(o))||(o=null),{...e,date:o,debit:null!=i?(0,pe.zA)(i):"",credit:null!=s?(0,pe.zA)(s):""}}function kn(e,t){let n=e[t];return n&&n.is_child&&(null==e[t+1]||e[t+1].parent_id!==n.parent_id)}let Mn=(0,s.createContext)(null);function Tn(){let e=(0,s.useContext)(Mn);return(0,s.useMemo)((()=>({...e,expanded:t=>"collapse"===e.state.mode?!e.state.ids.has(t):e.state.ids.has(t)})),[e])}function On(e){let{children:t,initialMode:n="expand"}=e,o=(0,a.v9)((e=>e.app.lastSplitState)),i=(0,a.I0)(),[r,l]=(0,s.useReducer)(((e,t)=>{switch(t.type){case"toggle-split":{let n=new Set([...e.ids]),{id:o}=t;return n.has(o)?n.delete(o):n.add(o),{...e,ids:n}}case"open-split":{let n=new Set([...e.ids]),{id:o}=t;return"collapse"===e.mode?n.delete(o):n.add(o),{...e,ids:n}}case"set-mode":return{...e,mode:t.mode,ids:new Set,transitionId:null};case"switch-mode":return null!=e.transitionId?e:{...e,mode:"expand"===e.mode?"collapse":"expand",transitionId:t.id,ids:new Set};case"finish-switch-mode":return{...e,transitionId:null};default:throw new Error("Unknown action type: "+t.type)}}),o.current||{ids:new Set,mode:n});(0,s.useEffect)((()=>{null!=r.transitionId&&setTimeout((()=>{l({type:"finish-switch-mode"})}),250)}),[r.transitionId]),(0,s.useEffect)((()=>{null==r.transitionId&&i({type:"SET_LAST_SPLIT_STATE",splitState:r})}),[r]);let d=(0,s.useMemo)((()=>({state:r,dispatch:l})),[r,l]);return(0,M.jsx)(Mn.Provider,{value:d,children:t})}function In(e,t,n){return e===n?"asc"===t?"desc":"asc":arguments.length>3&&void 0!==arguments[3]?arguments[3]:"asc"}const Bn=(0,s.memo)((e=>{var t;let{hasSelected:n,showAccount:o,showCategory:i,showBalance:s,showCleared:a,scrollWidth:r,onSort:l,ascDesc:d,field:c}=e,u=(0,Lt.YP)();return(0,M.jsxs)(E.X2,{borderColor:g.O9.n9,backgroundColor:"white",style:{color:g.O9.n4,fontWeight:300,zIndex:200},children:[(0,M.jsx)(E._7,{exposed:!0,focused:!1,selected:n,width:20,onSelect:e=>u({type:"select-all",event:e})}),(0,M.jsx)(Dn,{value:"Date",width:110,alignItems:"flex",marginLeft:-5,id:"date",icon:"date"===c?d:"clickable",onClick:()=>l("date",In(c,d,"date","desc"))}),o&&(0,M.jsx)(Dn,{value:"Account",width:"flex",alignItems:"flex",marginLeft:-5,id:"account",icon:"account"===c?d:"clickable",onClick:()=>l("account",In(c,d,"account","asc"))}),(0,M.jsx)(Dn,{value:"Payee",width:"flex",alignItems:"flex",marginLeft:-5,id:"payee",icon:"payee"===c?d:"clickable",onClick:()=>l("payee",In(c,d,"payee","asc"))}),(0,M.jsx)(Dn,{value:"Notes",width:"flex",alignItems:"flex",marginLeft:-5,id:"notes",icon:"notes"===c?d:"clickable",onClick:()=>l("notes",In(c,d,"notes","asc"))}),i&&(0,M.jsx)(Dn,{value:"Category",width:"flex",alignItems:"flex",marginLeft:-5,id:"category",icon:"category"===c?d:"clickable",onClick:()=>l("category",In(c,d,"category","asc"))}),(0,M.jsx)(Dn,{value:"Payment",width:90,alignItems:"flex-end",marginRight:-5,id:"payment",icon:"payment"===c?d:"clickable",onClick:()=>l("payment",In(c,d,"payment","asc"))}),(0,M.jsx)(Dn,{value:"Deposit",width:85,alignItems:"flex-end",marginRight:-5,id:"deposit",icon:"deposit"===c?d:"clickable",onClick:()=>l("deposit",In(c,d,"deposit","desc"))}),s&&(0,M.jsx)(E.bL,{value:"Balance",width:88,textAlign:"right"}),a&&(0,M.jsx)(E.gN,{width:23,truncate:!1}),(0,M.jsx)(E.bL,{value:"",width:null!==(t=5+r)&&void 0!==t?t:0})]})}));function Rn(e){let{id:t,focused:n,selected:o,status:i,isChild:a,onEdit:r,onUpdate:l}=e,d="cleared"===i||null==i,c=(0,Dt.V)(i),u={color:"cleared"===i?g.O9.g5:"missed"===i?g.O9.r6:"due"===i?g.O9.y5:o?g.O9.b7:g.O9.n7};return(0,M.jsx)(E.bL,{name:"cleared",width:23,focused:n,style:{padding:1},plain:!0,children:(0,M.jsx)(E.Sx,{style:[{padding:3,border:"1px solid transparent",borderRadius:50,":focus":{border:"1px solid "+u.color,boxShadow:`0 1px 2px ${u.color}`},cursor:d?"pointer":"default"},a&&{visibility:"hidden"}],onEdit:()=>r(t,"cleared"),onSelect:function(){d&&l("cleared",!("cleared"===i))},children:(0,s.createElement)(c.Icon,{style:{width:13,height:13,color:u.color,marginTop:"due"===i?-1:0}})})})}function Dn(e){let{value:t,id:n,width:o,alignItems:i,marginLeft:s,marginRight:a,icon:r,onClick:l}=e;return(0,M.jsx)(E.wh,{width:o,name:n,alignItems:i,unexposedContent:(0,M.jsxs)(C.Z,{type:"bare",onClick:l,style:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",color:g.O9.n4,fontWeight:300,marginLeft:s,marginRight:a},children:[(0,M.jsx)(E.rt,{value:t}),"asc"===r&&(0,M.jsx)(jn,{width:10,height:10,style:{marginLeft:5}}),"desc"===r&&(0,M.jsx)(Cn,{width:10,height:10,style:{marginLeft:5}})]})})}function En(e){let{id:t,payeeId:n,accountId:o,focused:i,inherited:a,payees:r,accounts:l,valueStyle:d,transaction:c,payee:u,transferAcct:h,isPreview:p,onEdit:y,onUpdate:m,onCreatePayee:x,onManagePayees:w,onNavigateToTransferAccount:v,onNavigateToSchedule:j}=e,C=(0,s.useRef)(!1);return l=l.filter((e=>e.id!==o)),r=r.filter((e=>e.transfer_acct!==o)),(0,M.jsx)(E.wh,{width:"flex",name:"payee",textAlign:"flex",value:n,valueStyle:[d,a&&{color:g.O9.n8}],exposed:i,onExpose:e=>!p&&y(t,e),onUpdate:async e=>{if(m("payee",e),e&&e.startsWith("new:")&&!C.current){C.current=!0;let t=await x(e.slice(4));m("payee",t),C.current=!1}},unexposedContent:(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(Nn,{transaction:c,transferAccount:h,onNavigateToTransferAccount:v,onNavigateToSchedule:j}),(0,M.jsx)(E.rt,{value:n,formatter:()=>function(e,t,n){let{payee:o}=e;return n?(0,M.jsx)(f.Z,{style:{flexDirection:"row",alignItems:"center"},children:(0,M.jsx)("div",{style:{overflow:"hidden",textOverflow:"ellipsis"},children:n.name})}):t&&!t.transfer_acct?t.name:o&&o.startsWith("new:")?o.slice(4):""}(c,u,h)})]}),children:e=>{let{onBlur:t,onKeyDown:o,onUpdate:i,onSave:s,shouldSaveFromKey:a,inputStyle:d}=e;return(0,M.jsx)(Ht.Z,{payees:r,accounts:l,value:n,shouldSaveFromKey:a,inputProps:{onBlur:t,onKeyDown:o,style:d},showManagePayees:!0,tableBehavior:!0,defaultFocusTransferPayees:c.is_child,focused:!0,onUpdate:i,onSelect:s,onManagePayees:()=>w(n),isCreatable:!0,menuPortalTarget:void 0})}})}function Nn(e){let{transaction:t,transferAccount:n,onNavigateToTransferAccount:o,onNavigateToSchedule:i,children:s}=e,a=t.schedule,r=(0,Zt.oF)(),l=r?r.schedules.find((e=>e.id===a)):null;if(null==l&&null==n)return s;let d={marginLeft:-5,marginRight:2,width:23,height:23,color:"inherit"},c={width:13,height:13},u={width:10,height:10},h=l&&l._date&&!!l._date.frequency;return l?(0,M.jsx)(C.Z,{type:"bare",style:d,onClick:e=>{e.stopPropagation(),i(a)},children:h?(0,M.jsx)(bn.Z,{style:c}):(0,M.jsx)(Sn.Z,{style:c})}):n?(0,M.jsx)(C.Z,{type:"bare",style:d,onClick:e=>{e.stopPropagation(),Wn(t.id)||o(n.id)},children:(t._inverse?-1:1)*t.amount>0?(0,M.jsx)(wn,{style:u}):(0,M.jsx)(vn.Z,{style:u})}):null}const Fn=(0,s.memo)((function(e){let{transaction:t,editing:n,backgroundColor:o="white",showAccount:i,showBalance:a,showCleared:r,showZeroInDeposit:l,style:d,hovered:c,selected:h,highlighted:p,added:y,matched:m,expanded:x,inheritedFields:w,focusedField:j,categoryGroups:C,payees:b,accounts:Z,balance:A,dateFormat:k="MM/dd/yyyy",hideFraction:T,onSave:O,onEdit:I,onHover:B,onDelete:R,onSplit:D,onManagePayees:N,onCreatePayee:F,onToggleSplit:P,onNavigateToTransferAccount:_,onNavigateToSchedule:W}=e,L=(0,Lt.YP)(),[G,H]=(0,s.useState)(l),[U,z]=(0,s.useState)(t),[K,$]=(0,s.useState)((()=>An(t,l))),V=Ln(K.id);function Q(e,n){if(K[e]!==n){let o={...K,[e]:n};if("note"===e&&""===n&&null==K.note)return;if("account"===e&&n&&(0,xn.gI)(Z)[n].offbudget&&(o.category=null),"credit"===e?o.debit="":"debit"===e&&(o.credit=""),"payee"===e&&n&&n.startsWith("new:"))$(o);else{let e=function(e,t){let n,{debit:o,credit:i,date:s,...a}=e;if(""!==o){let e=je(o,null);n=null!=e?-e:null}else n=je(i,null);return n=null!=n?(0,pe.l9)(n):t.amount,null==s&&(s=t.date||(0,u.PR)()),{...a,date:s,amount:n}}(o,t);$(An(e,l)),O(e)}}}t===U&&l===G||($(An(t,l)),z(t),H(l));let X,{id:q,debit:Y,credit:J,payee:ee,imported_payee:te,notes:ne,date:oe,account:ie,category:se,cleared:ae,is_parent:re,_unmatched:le=!1,_inverse:de=!1}=K,ce=b&&ee&&(0,xn.yG)(b)[ee],ue=Z&&ie&&(0,xn.gI)(Z)[ie];X=de?Z&&ie&&(0,xn.gI)(Z)[ie]:ce&&ce.transfer_acct&&(0,xn.gI)(Z)[ce.transfer_acct];let he=K.is_child,ge=h?g.O9.b8:g.O9.Cg,fe=X&&0===X.offbudget,ye=ue&&1===ue.offbudget,me=y?{fontWeight:600}:null,xe=c||"select"===j,we=T?{letterSpacing:-.5}:null;return(0,M.jsxs)(E.X2,{borderColor:ge,backgroundColor:h?g.O9.hv:xe?g.O9.Mr:V?"#fcfcfc":o,highlighted:p,style:[d,V&&{color:g.O9.n5,fontStyle:"italic"},le&&{opacity:.5}],onMouseEnter:()=>B&&B(K.id),children:[he&&(0,M.jsx)(E.gN,{borderColor:"transparent",width:110,style:{width:110,backgroundColor:g.O9.S0,borderBottomWidth:0}}),he&&i&&(0,M.jsx)(E.gN,{borderColor:"transparent",style:{flex:1,backgroundColor:g.O9.S0,opacity:0}}),Wn(K.id)?he?(0,M.jsx)(E.nu,{onDelete:()=>R&&R(K.id),exposed:c||n,style:[he&&{borderLeftWidth:1},{lineHeight:0}]}):(0,M.jsx)(E.bL,{width:20}):(0,M.jsx)(E._7,{exposed:c||h||n,focused:"select"===j,onSelect:e=>{L({type:"select",id:K.id,event:e})},onEdit:()=>I(q,"select"),selected:h,style:[he&&{borderLeftWidth:1}],value:m&&(0,M.jsx)(Zn,{style:{width:13,height:13,color:g.O9.n7}})}),!he&&(0,M.jsx)(E.wh,{name:"date",width:110,textAlign:"flex",exposed:"date"===j,value:oe,valueStyle:me,formatter:e=>e?(0,mn.Z)((0,yn.Z)(e),k):"",onExpose:e=>!V&&I(q,e),onUpdate:e=>{Q("date",e)},children:e=>{let{onBlur:t,onKeyDown:n,onUpdate:o,onSave:i,shouldSaveFromKey:s,inputStyle:a}=e;return(0,M.jsx)(Kt.Z,{value:oe||"",dateFormat:k,inputProps:{onBlur:t,onKeyDown:n,style:a},shouldSaveFromKey:s,tableBehavior:!0,onUpdate:o,onSelect:i})}}),!he&&i&&(0,M.jsx)(E.wh,{name:"account",width:"flex",textAlign:"flex",value:ie,formatter:e=>{let t=e&&(0,xn.gI)(Z)[e];return t?t.name:""},valueStyle:me,exposed:"account"===j,onExpose:e=>!V&&I(q,e),onUpdate:async e=>{e&&Q("account",e)},children:e=>{let{onBlur:t,onKeyDown:n,onUpdate:o,onSave:i,shouldSaveFromKey:s,inputStyle:a}=e;return(0,M.jsx)(Gt.Z,{includeClosedAccounts:!1,value:ie,accounts:Z,shouldSaveFromKey:s,tableBehavior:!0,focused:!0,inputProps:{onBlur:t,onKeyDown:n,style:a},onUpdate:o,onSelect:i,menuPortalTarget:void 0})}}),(0,M.jsx)(En,{id:q,payeeId:ee,accountId:ie,focused:"payee"===j,inherited:w&&w.has("payee"),payees:b,accounts:Z,valueStyle:me,transaction:K,payee:ce,transferAcct:X,importedPayee:te,isPreview:V,onEdit:I,onUpdate:Q,onCreatePayee:F,onManagePayees:N,onNavigateToTransferAccount:_,onNavigateToSchedule:W}),V?(0,M.jsx)(E.bL,{name:"notes",width:"flex"}):(0,M.jsx)(E.F3,{width:"flex",name:"notes",textAlign:"flex",exposed:"notes"===j,focused:"notes"===j,value:ne||"",valueStyle:me,onExpose:e=>!V&&I(q,e),inputProps:{value:ne||"",onUpdate:Q.bind(null,"notes")}}),V?(0,M.jsx)(E.bL,{width:"flex",style:{alignItems:"flex-start"},exposed:!0,children:()=>(0,M.jsx)(f.Z,{style:{color:"missed"===ne?g.O9.r6:"due"===ne?g.O9.y4:h?g.O9.b5:g.O9.n6,backgroundColor:"missed"===ne?g.O9.as:"due"===ne?g.O9.y9:h?g.O9.b8:g.O9.pK,margin:"0 5px",padding:"3px 7px",borderRadius:4},children:(0,pe.VL)(ne)})}):re?(0,M.jsx)(E.bL,{name:"category",width:"flex",focused:"category"===j,style:{padding:0},plain:!0,children:(0,M.jsx)(E.Sx,{style:{alignSelf:"flex-start",color:g.O9.n6,borderRadius:4,transition:"none","&:hover":{backgroundColor:"rgba(100, 100, 100, .15)",color:g.O9.n5}},disabled:Wn(K.id),onEdit:()=>I(q,"category"),onSelect:()=>P(q),children:(0,M.jsxs)(f.Z,{style:{flexDirection:"row",alignItems:"center",alignSelf:"stretch",borderRadius:4,flex:1,padding:4},children:[re&&(0,M.jsx)(v.Z,{style:{width:14,height:14,transition:"transform .08s",transform:x?"rotateZ(0)":"rotateZ(-90deg)"}}),(0,M.jsx)(S.Z,{style:{fontStyle:"italic",userSelect:"none"},children:"Split"})]})})}):fe||ye||V?(0,M.jsx)(E.F3,{name:"category",width:"flex",exposed:"category"===j,focused:"category"===j,onExpose:e=>!V&&I(q,e),value:re?"Split":ye?"Off Budget":fe?"Transfer":"",valueStyle:me,style:{fontStyle:"italic",color:"#c0c0c0",fontWeight:300},inputProps:{readOnly:!0,style:{fontStyle:"italic"}}}):(0,M.jsx)(E.wh,{name:"category",width:"flex",textAlign:"flex",value:se,formatter:e=>{return e?(t=(0,xn.ch)(C)[e],n="name",t?t[n]:""):K.id?"Categorize":"";var t,n},exposed:"category"===j,onExpose:e=>I(q,e),valueStyle:se?me:{fontStyle:"italic",fontWeight:300,color:g.O9.p8},onUpdate:async e=>{"split"===e?D(K.id):Q("category",e)},children:e=>{let{onBlur:t,onKeyDown:n,onUpdate:o,onSave:i,shouldSaveFromKey:s,inputStyle:a}=e;return(0,M.jsx)(et.Z,{categoryGroups:C,value:se,focused:!0,tableBehavior:!0,showSplitOption:!he&&!re,shouldSaveFromKey:s,inputProps:{onBlur:t,onKeyDown:n,style:a},onUpdate:o,onSelect:i,menuPortalTarget:void 0})}}),(0,M.jsx)(E.F3,{type:"input",width:90,name:"debit",exposed:"debit"===j,focused:"debit"===j,value:""===Y&&""===J?"0.00":Y,valueStyle:me,textAlign:"right",title:Y,onExpose:e=>!V&&I(q,e),style:[re&&{fontStyle:"italic"},g.W2.tnum,we],inputProps:{value:""===Y&&""===J?"0.00":Y,onUpdate:Q.bind(null,"debit")},privacyFilter:{activationFilters:[!Wn(K.id)]}}),(0,M.jsx)(E.F3,{type:"input",width:85,name:"credit",exposed:"credit"===j,focused:"credit"===j,value:J,valueStyle:me,textAlign:"right",title:J,onExpose:e=>!V&&I(q,e),style:[re&&{fontStyle:"italic"},g.W2.tnum,we],inputProps:{value:J,onUpdate:Q.bind(null,"credit")},privacyFilter:{activationFilters:[!Wn(K.id)]}}),a&&(0,M.jsx)(E.bL,{name:"balance",value:null==A||he?"":(0,pe.zA)(A),valueStyle:{color:A<0?g.O9.r4:g.O9.g4},style:[g.W2.tnum,we],width:88,textAlign:"right",privacyFilter:!0}),r&&(0,M.jsx)(Rn,{id:q,focused:"cleared"===j,selected:h,isPreview:V,status:V?ne:ae?"cleared":null,isChild:he,onEdit:I,onUpdate:Q}),(0,M.jsx)(E.bL,{width:5})]})}));function Pn(e){let{error:t,isDeposit:n,onAddSplit:o,style:i}=e;return"SplitTransactionError"!==t.type?null:1===t.version?(0,M.jsxs)(f.Z,{style:[{flexDirection:"row",alignItems:"center",padding:"0 5px"},i],"data-testid":"transaction-error",children:[(0,M.jsxs)(S.Z,{children:["Amount left:"," ",(0,M.jsx)(S.Z,{style:{fontWeight:500},children:(0,pe.zA)(n?t.difference:-t.difference)})]}),(0,M.jsx)(f.Z,{style:{flex:1}}),(0,M.jsx)(C.Z,{type:"primary",style:{marginLeft:15,padding:"4px 10px"},onClick:o,children:"Add Split"})]}):void 0}function _n(e,t,n){return[{id:"temp",date:n||(0,u.PR)(),account:e||null,category:t||null,cleared:!1,amount:null}]}function Wn(e){return-1!==e.indexOf("temp")}function Ln(e){return-1!==e.indexOf("preview/")}function Gn(e){let{transactions:t,accounts:n,categoryGroups:o,payees:i,editingTransaction:s,hoveredTransaction:a,focusedField:r,showAccount:l,showCategory:d,showBalance:c,showCleared:u,dateFormat:h,hideFraction:p,onHover:g,onClose:y,onSplit:m,onEdit:x,onDelete:w,onSave:v,onAdd:j,onAddSplit:b,onManagePayees:S,onCreatePayee:Z,onNavigateToTransferAccount:A,onNavigateToSchedule:k}=e;const T=t[0].error,O=t[0].amount>0;return(0,M.jsxs)(f.Z,{style:{borderBottom:"1px solid #ebebeb",paddingBottom:6,backgroundColor:"white"},"data-testid":"new-transaction",onKeyDown:e=>{"Escape"===e.key&&y()},onMouseLeave:()=>g(null),children:[t.map(((e,t)=>(0,M.jsx)(Fn,{editing:s===e.id,hovered:a===e.id,transaction:e,showAccount:l,showCategory:d,showBalance:c,showCleared:u,focusedField:s===e.id&&r,showZeroInDeposit:O,accounts:n,categoryGroups:o,payees:i,dateFormat:h,hideFraction:p,expanded:!0,onHover:g,onEdit:x,onSave:v,onSplit:m,onDelete:w,onAdd:j,onManagePayees:S,onCreatePayee:Z,style:{marginTop:-1},onNavigateToTransferAccount:A,onNavigateToSchedule:k},e.id))),(0,M.jsxs)(f.Z,{style:{flexDirection:"row",alignItems:"center",justifyContent:"flex-end",marginTop:6,marginRight:20},children:[(0,M.jsx)(C.Z,{style:{marginRight:10,padding:"4px 10px"},onClick:()=>y(),"data-testid":"cancel-button",children:"Cancel"}),T?(0,M.jsx)(Pn,{error:T,isDeposit:O,onAddSplit:()=>b(t[0].id)}):(0,M.jsx)(C.Z,{type:"primary",style:{padding:"4px 10px"},onClick:j,"data-testid":"add-button",children:"Add"})]})]})}function Hn(e){let{tableNavigator:t,tableRef:n,dateFormat:o="MM/dd/yyyy",newNavigator:i,renderEmpty:a,onHover:r,onScroll:l,...d}=e;const c=(0,s.createRef)(),u=function(e){const t=(0,s.useRef)();return(0,s.useEffect)((()=>{t.current=e}),[e]),t.current}(d.isAdding);let[h,p]=(0,s.useState)(0);let g=(0,s.useCallback)((e=>{d.onCloseAddTransaction(),d.onNavigateToTransferAccount(e)}),[d.onCloseAddTransaction,d.onNavigateToTransferAccount]),y=(0,s.useCallback)((e=>{d.onCloseAddTransaction(),d.onNavigateToSchedule(e)}),[d.onCloseAddTransaction,d.onNavigateToSchedule]);(0,s.useEffect)((()=>{!u&&d.isAdding&&i.onEdit("temp","date")}),[u,d.isAdding,i]);return(0,M.jsxs)(f.Z,{innerRef:c,style:[{flex:1,cursor:"default"},d.style],children:[(0,M.jsxs)(f.Z,{children:[(0,M.jsx)(Bn,{hasSelected:d.selectedItems.size>0,showAccount:d.showAccount,showCategory:d.showCategory,showBalance:d.showBalances,showCleared:d.showCleared,scrollWidth:h,onSort:d.onSort,ascDesc:d.ascDesc,field:d.sortField}),d.isAdding&&(0,M.jsx)(f.Z,{...i.getNavigatorProps({onKeyDown:e=>d.onCheckNewEnter(e)}),children:(0,M.jsx)(Gn,{transactions:d.newTransactions,editingTransaction:i.editingId,hoveredTransaction:d.hoveredTransaction,focusedField:i.focusedField,accounts:d.accounts,categoryGroups:d.categoryGroups,payees:d.payees||[],showAccount:d.showAccount,showCategory:d.showCategory,showBalance:d.showBalances,showCleared:d.showCleared,dateFormat:o,hideFraction:d.hideFraction,onClose:d.onCloseAddTransaction,onAdd:d.onAddTemporary,onAddSplit:d.onAddSplit,onSplit:d.onSplit,onEdit:i.onEdit,onSave:d.onSave,onDelete:d.onDelete,onHover:r,onManagePayees:d.onManagePayees,onCreatePayee:d.onCreatePayee,onNavigateToTransferAccount:g,onNavigateToSchedule:g})})]}),(0,M.jsxs)(f.Z,{style:[{flex:1,overflow:"hidden"}],"data-testid":"transaction-table",onMouseLeave:()=>r(null),children:[(0,M.jsx)(E.iA,{navigator:t,ref:n,items:d.transactions,renderItem:e=>{var n;let{item:i,index:s,position:a,editing:l}=e;const{transactions:c,selectedItems:u,hoveredTransaction:h,accounts:p,categoryGroups:f,payees:m,showCleared:x,showAccount:w,showCategory:v,showBalances:j,balances:C,hideFraction:b,isNew:S,isMatched:Z,isExpanded:A}=d;let k=i,T=h===k.id,I=u.has(k.id),B=d.transactionMap.get(k.parent_id),R=B&&B.amount>0,D=A&&A((B||k).id),E=D&&B&&B.error||k.error;return(0,M.jsxs)(M.Fragment,{children:[(!D||kn(c,s))&&E&&"SplitTransactionError"===E.type&&(0,M.jsx)(O.u,{position:"bottom-right",width:250,forceTop:a,forceLayout:!0,style:{transform:"translate(-5px, 2px)"},children:(0,M.jsx)(Pn,{error:E,isDeposit:R,onAddSplit:()=>d.onAddSplit(k.id)})}),(0,M.jsx)(Fn,{editing:l,transaction:k,showAccount:w,showCategory:v,showBalance:j,showCleared:x,hovered:T,selected:I,highlighted:!1,added:null===S||void 0===S?void 0:S(k.id),expanded:null===A||void 0===A?void 0:A(k.id),matched:null===Z||void 0===Z?void 0:Z(k.id),showZeroInDeposit:R,balance:null===C||void 0===C||null===(n=C[k.id])||void 0===n?void 0:n.balance,focusedField:l&&t.focusedField,accounts:p,categoryGroups:f,payees:m,inheritedFields:(null===B||void 0===B?void 0:B.payee)===k.payee?new Set(["payee"]):new Set,dateFormat:o,hideFraction:b,onHover:r,onEdit:t.onEdit,onSave:d.onSave,onDelete:d.onDelete,onSplit:d.onSplit,onManagePayees:d.onManagePayees,onCreatePayee:d.onCreatePayee,onToggleSplit:d.onToggleSplit,onNavigateToTransferAccount:g,onNavigateToSchedule:y})]})},renderEmpty:a,loadMore:d.loadMoreTransactions,isSelected:e=>d.selectedItems.has(e),onKeyDown:e=>d.onCheckEnter(e),onScroll:l,saveScrollWidth:function(e,t){let n=e>0&&t>0&&e-t;p(n||0)}}),d.isAdding&&(0,M.jsx)("div",{style:{position:"absolute",top:-20,left:0,right:0,height:20,backgroundColor:"red",boxShadow:"0 0 6px rgba(0, 0, 0, .20)"}},"shadow")]})]})}let Un=(0,s.forwardRef)(((e,t)=>{let[n,o]=(0,s.useState)(null),[i,a]=(0,s.useState)(e.hoveredTransaction),[r,l]=(0,s.useState)(!1),d=Tn(),c=(0,s.useRef)(null),u=(0,s.useRef)(null),h=(p=u,g=t,(0,s.useMemo)((()=>function(e){[p,g].forEach((t=>{"function"===typeof t?t(e):null!=t&&(t.current=e)}))}),[p,g]));var p,g;let f=(0,s.useMemo)((()=>{let t;if(null!=d.state.transitionId){let n=e.transactions.findIndex((e=>e.id===d.state.transitionId));t=e.transactions.filter(((e,t)=>{if(e.parent_id){if(t>=n)return d.expanded(e.parent_id);if(c.current)return c.current.expanded(e.parent_id)}return!0}))}else c.current&&null!=c.current.state.transitionId&&(u.current.anchor(),u.current.setRowAnimation(!1)),c.current=d,t=e.transactions.filter((e=>!e.parent_id||d.expanded(e.parent_id)));return c.current=d,t}),[e.transactions,d]);const y=(0,s.useMemo)((()=>new Map(f.map((e=>[e.id,e])))),[f]);(0,s.useEffect)((()=>{u.current.isAnchored()&&(u.current.unanchor(),u.current.setRowAnimation(!0))}),[c.current]);let m=(0,E.wz)(n,A),x=(0,E.wz)(f,A),w=(0,s.useRef)(!1),v=(0,s.useRef)({newTransactions:n,newNavigator:m,tableNavigator:x}),j=(0,s.useRef)(!1),C=(0,s.useRef)(!1),[b,S]=(0,s.useState)({}),Z=(0,Lt.D9)();function A(t){let n=["select","date","account","payee","notes","category","debit","credit","cleared"];return n=t.is_child?["select","payee","notes","category","debit","credit"]:n.filter((t=>(e.showAccount||"account"!==t)&&(e.showCategory||"category"!==t))),Ln(t.id)&&(n=["select","cleared"]),Wn(t.id)&&(n=n.slice(1)),n}function k(t){j.current?C.current=t:t(e)}(0,s.useLayoutEffect)((()=>{v.current={newTransactions:n,newNavigator:m,tableNavigator:x,transactions:e.transactions}})),r!==e.isAdding&&(!r&&e.isAdding&&o(_n(e.currentAccountId,e.currentCategoryId)),l(e.isAdding)),(0,s.useEffect)((()=>{if(w.current){if(null==n[0].account)e.addNotification({type:"error",message:"Account is a required field"}),m.onEdit("temp","account");else{let t=v.current.newTransactions,n=t.length>0?t[0].date:null;o(_n(e.currentAccountId,e.currentCategoryId,n)),m.onEdit("temp","date"),e.onAdd(t)}w.current=!1}})),(0,s.useEffect)((()=>{j.current&&C.current&&(C.current(e),C.current=null),j.current=!1}),[n,e.transactions]);let T=(0,s.useCallback)((()=>{w.current=!0,S({})}),[e.onAdd,m.onEdit]),O=(0,s.useCallback)((async t=>{if(j.current=!0,Wn(t.id)){e.onApplyRules&&(t=await e.onApplyRules(t));let n=v.current.newTransactions;o((0,hn.Ld)(n,t).data)}else e.onSave(t)}),[e.onSave]),I=(0,s.useCallback)((e=>{a(e)}),[]),B=(0,s.useCallback)((e=>{if(Wn(e)){let t=v.current.newTransactions;if(e===t[0].id)return;o((0,hn.Ks)(t,e).data)}}),[]),R=(0,s.useMemo)((()=>t=>{if(Wn(t)){let{newNavigator:e}=v.current,n=v.current.newTransactions,{data:i,diff:s}=(0,hn.oQ)(n,t);o(i),null===n[0].amount?e.onEdit(n[0].id,"debit"):e.onEdit(s.added[0].id,v.current.newNavigator.focusedField)}else{let n=v.current.transactions.find((e=>e.id===t)),o=e.onSplit(t);d.dispatch({type:"open-split",id:n.id});let{tableNavigator:i}=v.current;null===n.amount?i.onEdit(n.id,"debit"):i.onEdit(o,i.focusedField)}}),[e.onSplit,d.dispatch]),D=(0,s.useCallback)((t=>{if(Wn(t)){let e=v.current.newTransactions,{data:n,diff:i}=(0,hn.CX)(e,t);o(n),m.onEdit(i.added[0].id,v.current.newNavigator.focusedField)}else{let n=e.onAddSplit(t);x.onEdit(n,v.current.tableNavigator.focusedField)}}),[e.onAddSplit]);let N=(0,s.useCallback)((e=>d.dispatch({type:"toggle-split",id:e})),[d.dispatch]);return(0,M.jsx)(Hn,{tableRef:h,...e,transactions:f,transactionMap:y,selectedItems:Z,hoveredTransaction:i,isExpanded:d.expanded,onHover:I,onSave:O,onDelete:B,onSplit:R,onCheckNewEnter:function(e){if("Enter"===e.key)if(e.metaKey)e.stopPropagation(),T();else if(!e.shiftKey){function t(e){let{newTransactions:t}=e.current;return t[t.length-1]}m.editingId===t(v).id&&e.stopPropagation(),k((()=>{let e=t(v),n=e.parent_id||e.is_parent;v.current.newTransactions[0].error&&m.editingId===e.id?D(e.id):m.editingId!==e.id||n&&e.error||T()}))}},onCheckEnter:function(e){if("Enter"===e.key&&!e.shiftKey){let{editingId:t,focusedField:n}=x;k((()=>{var o;let i=v.current.transactions,s=i.findIndex((e=>e.id===t)),a=y.get(null===(o=i[s])||void 0===o?void 0:o.parent_id);kn(i,s)&&a&&a.error&&"select"!==n&&(e.stopPropagation(),D(t))}))}},onAddTemporary:T,onAddSplit:D,onCloseAddTransaction:function(){o(_n(e.currentAccountId,e.currentCategoryId)),e.onCloseAddTransaction()},onToggleSplit:N,newTransactions:n,tableNavigator:x,newNavigator:m})}));async function zn(e){let t=await(0,d.lW)("transactions-batch-update",{...e,learnCategories:!0});return t.length>0?{updates:t}:{}}async function Kn(e,t,n){let o=await zn(e);n((0,hn._n)(t.newTransaction,o),(0,pe.zb)(o,t.data))}function $n(e){let{tableRef:t,transactions:n,allTransactions:o,loadMoreTransactions:i,account:a,accounts:l,category:c,categoryGroups:u,payees:h,balances:p,showBalances:g,showCleared:f,showAccount:y,headerContent:m,animated:x,isAdding:w,isNew:v,isMatched:j,isFiltered:C,dateFormat:b,hideFraction:S,addNotification:Z,renderEmpty:A,onSort:k,sortField:T,ascDesc:O,onChange:I,onRefetch:B,onCloseAddTransaction:R,onCreatePayee:D}=e,E=(0,s.useRef)(),N=(0,r.s0)(),F=(0,At.cu)();(0,s.useLayoutEffect)((()=>{E.current=n}),[n]);let P=(0,s.useCallback)((async e=>{e=(0,hn.V6)(e),await zn({added:e}),B()}),[]),_=(0,s.useCallback)((async e=>{let t=(0,hn.Ld)(E.current,e);if(t.diff.updated.length>0){!!t.diff.updated[0].date?(t.diff.updated[0].sort_order=Date.now(),await zn(t.diff),B()):(I(t.newTransaction,t.data),Kn(t.diff,t,I))}}),[]),W=(0,s.useCallback)((e=>{const t=(0,hn.CX)(E.current,e);return I(t.newTransaction,t.data),Kn(t.diff,t,I),t.diff.added[0].id}),[]),L=(0,s.useCallback)((e=>{const t=(0,hn.oQ)(E.current,e);return I(t.newTransaction,t.data),Kn(t.diff,t,I),t.diff.added[0].id}),[]),G=(0,s.useCallback)((async e=>{let t=await(0,d.lW)("rules-run",{transaction:e}),n=(0,pe.k4)(e,t),o={...e};return n&&Object.keys(n).forEach((e=>{null!=o[e]&&""!==o[e]&&0!==o[e]&&!1!==o[e]||(o[e]=n[e])})),o}),[]),H=(0,s.useCallback)((e=>{N("/payees",{selectedPayee:e})})),U=(0,s.useCallback)((e=>{N(`/accounts/${e}`)})),z=(0,s.useCallback)((e=>{F(`/schedule/edit/${e}`)}));return(0,M.jsx)(Un,{ref:t,transactions:o,loadMoreTransactions:i,accounts:l,categoryGroups:u,payees:h,showBalances:g,balances:p,showCleared:f,showAccount:y,showCategory:!0,animated:x,currentAccountId:a&&a.id,currentCategoryId:c&&c.id,isAdding:w,isNew:v,isMatched:j,isFiltered:C,dateFormat:b,hideFraction:S,addNotification:Z,headerContent:m,renderEmpty:A,onSave:_,onApplyRules:G,onSplit:L,onCloseAddTransaction:R,onAdd:P,onAddSplit:W,onManagePayees:H,onCreatePayee:D,style:{backgroundColor:"white"},onNavigateToTransferAccount:U,onNavigateToSchedule:z,onSort:k,sortField:T,ascDesc:O})}var Vn=n(63529),Qn=n(9314),Xn=n(81576);var qn=e=>(0,M.jsx)("svg",{...e,xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",style:{color:"inherit",...e.style},children:(0,M.jsx)("path",{fill:"currentColor",d:"M19.611 2.571h-3.754a1.286 1.286 0 1 1 0-2.571h6.857A1.286 1.286 0 0 1 24 1.286v6.857a1.286 1.286 0 0 1-2.571 0V4.39L15.48 10.34a1.286 1.286 0 0 1-1.817-1.817l5.948-5.95ZM1.286 14.571a1.286 1.286 0 0 1 1.285 1.286v3.754l5.949-5.946a1.286 1.286 0 0 1 1.817 1.817L4.39 21.429h3.753a1.285 1.285 0 1 1 0 2.571H1.286A1.286 1.286 0 0 1 0 22.714v-6.857a1.286 1.286 0 0 1 1.286-1.286Z"})});var Yn=e=>(0,M.jsx)("svg",{...e,xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",style:{color:"inherit",...e.style},children:(0,M.jsx)("path",{fill:"currentColor",d:"M14.143 1.714A1.286 1.286 0 0 1 15.429 3v3.753L21.806.377a1.286 1.286 0 0 1 1.817 1.817l-6.376 6.377H21a1.286 1.286 0 1 1 0 2.572h-6.857a1.286 1.286 0 0 1-1.286-1.286V3a1.286 1.286 0 0 1 1.286-1.286ZM9.857 22.286A1.285 1.285 0 0 1 8.571 21v-3.753l-6.377 6.376a1.286 1.286 0 0 1-1.817-1.817l6.376-6.377H3a1.286 1.286 0 0 1 0-2.572h6.857a1.286 1.286 0 0 1 1.286 1.286V21a1.286 1.286 0 0 1-1.286 1.286Z"})});var Jn=e=>(0,M.jsxs)("svg",{...e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",style:{color:"inherit",...e.style},children:[(0,M.jsx)("path",{d:"M8.616 1.741A1.455 1.455 0 0 1 10.07.287h3.392a1.455 1.455 0 0 1 1.453 1.454v8.228a.25.25 0 0 0 .25.25h2.9a1.138 1.138 0 0 1 .827 2l-6.1 6.1a1.489 1.489 0 0 1-2.056 0l-6.1-6.1a1.137 1.137 0 0 1 .827-2h2.9a.249.249 0 0 0 .25-.25Z",fill:"currentColor"}),(0,M.jsx)("path",{d:"M0 19.677a4.039 4.039 0 0 0 4.035 4.035h15.93A4.039 4.039 0 0 0 24 19.677V17.8a1.225 1.225 0 0 0-2.449 0v1.874a1.588 1.588 0 0 1-1.586 1.586H4.035a1.588 1.588 0 0 1-1.586-1.586V17.8A1.225 1.225 0 0 0 0 17.8Z",fill:"currentColor"})]});var eo=e=>(0,M.jsx)("svg",{...e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",style:{color:"inherit",...e.style},children:(0,M.jsx)("path",{d:"M15.067 3.986a.5.5 0 0 0-.354-.148.5.5 0 0 0-.354.147L3.437 14.91a.5.5 0 0 0 0 .707l4.948 4.948a.5.5 0 0 0 .707 0L20.009 9.648a.5.5 0 0 0 0-.706ZM2.43 16.8a.5.5 0 0 0-.489-.127.5.5 0 0 0-.351.364L.084 23.314a.5.5 0 0 0 .133.47.507.507 0 0 0 .47.132l6.272-1.5a.5.5 0 0 0 .237-.84ZM23.2 2.924 21.077.8a2.5 2.5 0 0 0-3.532 0l-1.418 1.417a.5.5 0 0 0 0 .707l4.95 4.949a.5.5 0 0 0 .707 0L23.2 6.454a2.5 2.5 0 0 0 0-3.53Z",fill:"currentColor"})}),to=n(55082);function no(e){let{onClick:t}=e;return(0,M.jsx)(C.Z,{type:"bare",onClick:t,"aria-label":"Menu",children:(0,M.jsx)(j.Z,{width:15,height:15,style:{transform:"rotateZ(90deg)"}})})}var oo=n(91836),io=n(98030),so=n(58130),ao=n(52677);function ro(e){let{getTransaction:t,onShow:n,onDuplicate:o,onDelete:i,onEdit:a,onUnlink:r,onCreateRule:l,onScheduleAction:d}=e,c=(0,At.cu)(),u=(0,Lt.D9)(),h=(0,s.useMemo)((()=>{let e=[...u];return{preview:!!e.find((e=>Ln(e))),trans:!!e.find((e=>!Ln(e)))}}),[u]),p=(0,s.useMemo)((()=>[...u].map((e=>t(e))).some((e=>e&&e.is_child))),[u]),g=(0,s.useMemo)((()=>!h.preview&&[...u].every((e=>{let n=t(e);return n&&n.schedule}))),[h.preview,u,t]);return(0,M.jsx)(E.Vg,{name:"transactions",keyHandlers:h.trans&&{f:()=>n([...u]),d:()=>i([...u]),a:()=>a("account",[...u]),p:()=>a("payee",[...u]),n:()=>a("notes",[...u]),c:()=>a("category",[...u]),l:()=>a("cleared",[...u])},items:[...h.trans?[{name:"show",text:"Show",key:"F"},{name:"duplicate",text:"Duplicate",disabled:p},{name:"delete",text:"Delete",key:"D"},...g?[{name:"view-schedule",text:"View schedule",disabled:u.size>1},{name:"unlink-schedule",text:"Unlink schedule"}]:[{name:"link-schedule",text:"Link schedule"},{name:"create-rule",text:"Create rule"}],b.Z.line,{type:b.Z.label,name:"Edit field"},{name:"date",text:"Date"},{name:"account",text:"Account",key:"A"},{name:"payee",text:"Payee",key:"P"},{name:"notes",text:"Notes",key:"N"},{name:"category",text:"Category",key:"C"},{name:"amount",text:"Amount"},{name:"cleared",text:"Cleared",key:"L"}]:[{name:"view-schedule",text:"View schedule"},{name:"post-transaction",text:"Post transaction"},{name:"skip",text:"Skip scheduled date"}]],onSelect:e=>{switch(e){case"show":n([...u]);break;case"duplicate":o([...u]);break;case"delete":i([...u]);break;case"post-transaction":case"skip":d(e,u);break;case"view-schedule":let s,h=[...u][0];if(Ln(h)){s=h.split("/")[1]}else{let e=t(h);s=e&&e.schedule}s&&c(`/schedule/edit/${s}`);break;case"link-schedule":c("/schedule/link",{transactionIds:[...u]});break;case"unlink-schedule":r([...u]);break;case"create-rule":l([...u]);break;default:a(e,[...u])}}})}var lo=e=>(0,M.jsxs)("svg",{...e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",style:{color:"inherit",...e.style},children:[(0,M.jsx)("path",{d:"M13.584 12a2.643 2.643 0 0 1-.775 1.875l-9.541 9.541a1.768 1.768 0 0 1-2.5-2.5l8.739-8.739a.25.25 0 0 0 0-.354L.768 3.084a1.768 1.768 0 0 1 2.5-2.5l9.541 9.541A2.643 2.643 0 0 1 13.584 12Z",fill:"currentColor"}),(0,M.jsx)("path",{d:"M23.75 12a2.643 2.643 0 0 1-.775 1.875l-9.541 9.541a1.768 1.768 0 0 1-2.5-2.5l8.739-8.739a.25.25 0 0 0 0-.354l-8.739-8.739a1.768 1.768 0 0 1 2.5-2.5l9.541 9.541A2.643 2.643 0 0 1 23.75 12Z",fill:"currentColor"})]});function co(e){let{name:t,balance:n,isExactBalance:o=!0}=e;return(0,M.jsxs)(S.Z,{style:{marginLeft:15,backgroundColor:g.O9.n9,borderRadius:4,padding:"4px 6px",color:g.O9.n5},children:[t," ",(0,M.jsx)(Be.ZP,{children:(0,M.jsxs)(S.Z,{style:{fontWeight:600},children:[!o&&"~ ",(0,be.Z)(n,"financial")]})})]})}function uo(e){let{selectedItems:t,account:n}=e,o=`selected-balance-${[...t].join("-")}`,i=(0,Se.Z)({name:o,query:(0,A.ZP)("transactions").filter({id:{$oneof:[...t]},parent_id:{$oneof:[...t]}}).select("id")}),s=new Set((i||[]).map((e=>e.id))),a=[...t].filter((e=>!s.has(e))),r=(0,Se.Z)({name:o+"-sum",query:(0,A.ZP)("transactions").filter({id:{$oneof:a}}).options({splits:"all"}).calculate({$sum:"$amount"})}),l=null,d=(0,Zt.oF)(),c=d?d.schedules:[],u=[...t].filter((e=>Ln(e))).map((e=>e.slice(8))),h=!0;for(let p of c)u.includes(p.id)&&("isbetween"===p._amountOp&&(h=!1),n&&n.id!==p._account?l-=(0,It.lP)(p._amount):l+=(0,It.lP)(p._amount));if(null==r){if(null==l)return null;r=l}else null!=l&&(r+=l);return(0,M.jsx)(co,{name:"Selected balance:",balance:r,isExactBalance:h})}function ho(e){let{balanceQuery:t}=e,n=(0,Se.Z)({name:t.name+"-cleared",query:t.query.filter({cleared:!0})}),o=(0,Se.Z)({name:t.name+"-uncleared",query:t.query.filter({cleared:!1})});return(0,M.jsxs)(f.Z,{style:{flexDirection:"row"},children:[(0,M.jsx)(co,{name:"Cleared total:",balance:n}),(0,M.jsx)(co,{name:"Uncleared total:",balance:o})]})}function po(e){let{balanceQuery:t,showExtraBalances:n,onToggleExtraBalances:o,account:i}=e,s=(0,Lt.D9)();return(0,M.jsxs)(f.Z,{style:{flexDirection:"row",alignItems:"center",marginTop:-5,marginLeft:-5},children:[(0,M.jsxs)(C.Z,{"data-testid":"account-balance",type:"bare",onClick:o,style:{"& svg":{opacity:s.size>0||n?1:0},"&:hover svg":{opacity:1}},children:[(0,M.jsx)(Ce.Z,{binding:{...t,value:0},type:"financial",style:{fontSize:22,fontWeight:400},getStyle:e=>({color:e<0?g.O9.r5:e>0?g.O9.g5:g.O9.n8}),privacyFilter:{blurIntensity:5}}),(0,M.jsx)(lo,{style:{width:10,height:10,marginLeft:10,color:g.O9.n5,transform:n?"rotateZ(180deg)":"rotateZ(0)"}})]}),n&&(0,M.jsx)(ho,{balanceQuery:t}),s.size>0&&(0,M.jsx)(uo,{selectedItems:s,account:i})]})}var go=n(46854);function fo(e){let{balanceQuery:t,targetBalance:n,onDone:o,onCreateTransaction:i}=e,s=(0,Se.Z)({name:t.name+"-cleared",value:0,query:t.query.filter({cleared:!0})}),a=n-s;return(0,M.jsx)(f.Z,{style:{flexDirection:"row",alignSelf:"center",backgroundColor:"white",...g.W2.shadow,borderRadius:4,marginTop:5,marginBottom:15,padding:10},children:(0,M.jsxs)(f.Z,{style:{flexDirection:"row",alignItems:"center"},children:[0===a?(0,M.jsxs)(f.Z,{style:{color:g.O9.g4,flex:1,flexDirection:"row",alignItems:"center",justifyContent:"center"},children:[(0,M.jsx)(go.Z,{style:{width:13,height:13,color:g.O9.g5,marginRight:3}}),"All reconciled!"]}):(0,M.jsx)(f.Z,{style:{color:g.O9.n3},children:(0,M.jsxs)(S.Z,{style:{fontStyle:"italic",textAlign:"center"},children:["Your cleared balance"," ",(0,M.jsx)("strong",{children:(0,be.Z)(s,"financial")})," needs"," ",(0,M.jsx)("strong",{children:(a>0?"+":"")+(0,be.Z)(a,"financial")})," ","to match",(0,M.jsx)("br",{})," your bank\u2019s balance of"," ",(0,M.jsx)(S.Z,{style:{fontWeight:700},children:(0,be.Z)(n,"financial")})]})}),(0,M.jsx)(f.Z,{style:{marginLeft:15},children:(0,M.jsx)(C.Z,{type:"primary",onClick:o,children:"Done Reconciling"})}),0!==a&&(0,M.jsx)(f.Z,{style:{marginLeft:15},children:(0,M.jsx)(C.Z,{onClick:()=>i(a),children:"Create Reconciliation Transaction"})})]})})}function yo(e){let{account:t,onReconcile:n,onClose:o}=e,i=(0,Se.Z)(he.cW(t));return(0,M.jsx)(O.u,{position:"bottom-right",width:275,onClose:o,children:(0,M.jsxs)(f.Z,{style:{padding:"5px 8px"},children:[(0,M.jsx)(S.Z,{children:"Enter the current balance of your bank account that you want to reconcile with:"}),(0,M.jsxs)("form",{onSubmit:function(e){e.preventDefault();let t=e.target.elements[0],s=(0,pe.qT)(t.value);null!=s?(n(null==s?i:s),o()):t.select()},children:[null!=i&&(0,M.jsx)(tt.Z,{children:(0,M.jsx)(nt.ZP,{defaultValue:(0,be.Z)(i,"financial"),style:{margin:"7px 0"}})}),(0,M.jsx)(C.Z,{type:"primary",children:"Reconcile"})]})]})})}function mo(e){let{tableRef:t,editingName:n,isNameEditable:o,workingHard:i,accountName:a,account:r,filterId:l,filtersList:d,accountsSyncing:c,accounts:u,transactions:h,showBalances:p,showExtraBalances:y,showCleared:m,showEmptyMessage:x,balanceQuery:w,reconcileAmount:v,canCalculateBalance:j,isSorted:b,search:S,filters:Z,conditionsOp:A,savePrefs:k,onSearch:T,onAddTransaction:O,onShowTransactions:I,onDoneReconciling:R,onCreateReconciliationTransaction:D,onToggleExtraBalances:E,onSaveName:N,onExposeName:F,onSync:P,onImport:_,onMenuSelect:W,onReconcile:L,onBatchDelete:G,onBatchDuplicate:H,onBatchEdit:U,onBatchUnlink:z,onCreateRule:K,onApplyFilter:$,onUpdateFilter:V,onClearFilters:Q,onReloadSavedFilter:X,onCondOpChange:q,onDeleteFilter:Y,onScheduleAction:J}=e,[ee,te]=(0,s.useState)(!1),ne=(0,s.useRef)(null),oe=Tn(),ie=r&&r.account_id;return r||(ie=!!u.find((e=>!!e.account_id))),(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(ao.U,{keys:{"ctrl+f, cmd+f":()=>{ne.current&&ne.current.focus()}}}),(0,M.jsxs)(f.Z,{style:[g.W2.pageContent,{paddingBottom:10,flexShrink:0}],children:[(0,M.jsx)(f.Z,{style:{marginTop:2,alignItems:"flex-start"},children:(0,M.jsx)(f.Z,{children:n?(0,M.jsx)(tt.Z,{children:(0,M.jsx)(nt.ZP,{defaultValue:a,onEnter:e=>N(e.target.value),onBlur:()=>F(!1),style:{fontSize:25,fontWeight:500,marginTop:-5,marginBottom:-2,marginLeft:-5}})}):o?(0,M.jsxs)(f.Z,{style:{flexDirection:"row",alignItems:"center",gap:3,"& .hover-visible":{opacity:0,transition:"opacity .25s"},"&:hover .hover-visible":{opacity:1}},children:[(0,M.jsx)(f.Z,{style:{fontSize:25,fontWeight:500,marginRight:5,marginBottom:5},"data-testid":"account-name",children:r&&r.closed?"Closed: "+a:a}),r&&(0,M.jsx)(B,{id:`account-${r.id}`}),(0,M.jsx)(C.Z,{type:"bare",className:"hover-visible",onClick:()=>F(!0),children:(0,M.jsx)(eo,{style:{width:11,height:11,color:g.O9.n8}})})]}):(0,M.jsx)(f.Z,{style:{fontSize:25,fontWeight:500,marginBottom:5},"data-testid":"account-name",children:r&&r.closed?"Closed: "+a:a})})}),(0,M.jsx)(po,{balanceQuery:w,showExtraBalances:y,onToggleExtraBalances:E,account:r}),(0,M.jsxs)(Ie.Z,{spacing:2,direction:"row",align:"center",style:{marginTop:12},children:[(r&&!r.closed||ie)&&(0,M.jsx)(C.Z,{type:"bare",onClick:ie?P:_,children:ie?(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(to.Z,{width:13,height:13,animating:r&&c===r.name||"__all"===c,style:{marginRight:4}})," ","Sync"]}):(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(Jn,{width:13,height:13,style:{marginRight:4}})," ","Import"]})}),!x&&(0,M.jsxs)(C.Z,{type:"bare",onClick:O,children:[(0,M.jsx)(Xn.Z,{width:10,height:10,style:{marginRight:3}})," Add New"]}),(0,M.jsx)(f.Z,{style:{flexShrink:0},children:(0,M.jsx)(io.L,{onApply:$})}),(0,M.jsx)(f.Z,{style:{flex:1}}),(0,M.jsx)(kt.Z,{placeholder:"Search",value:S,onChange:T,inputRef:ne}),i?(0,M.jsx)(f.Z,{children:(0,M.jsx)(Qn.Z,{color:g.O9.n1,style:{width:16,height:16}})}):(0,M.jsx)(ro,{getTransaction:e=>h.find((t=>t.id===e)),onShow:I,onDuplicate:H,onDelete:G,onEdit:U,onUnlink:z,onCreateRule:K,onScheduleAction:J}),(0,M.jsx)(C.Z,{type:"bare",disabled:""!==S||Z.length>0,style:{padding:6,marginLeft:10},onClick:function(){t.current&&(oe.dispatch({type:"switch-mode",id:t.current.getScrolledItem()}),k({"expand-splits":!("expand"===oe.state.mode)}))},title:"collapse"===oe.state.mode?"Collapse split transactions":"Expand split transactions",children:"collapse"===oe.state.mode?(0,M.jsx)(Yn,{style:{width:14,height:14}}):(0,M.jsx)(qn,{style:{width:14,height:14}})}),r?(0,M.jsxs)(f.Z,{children:[(0,M.jsx)(no,{onClick:()=>te(!0)}),ee&&(0,M.jsx)(xo,{account:r,canSync:ie,canShowBalances:j(),isSorted:b,showBalances:p,showCleared:m,onMenuSelect:e=>{te(!1),W(e)},onReconcile:L,onClose:()=>te(!1)})]}):(0,M.jsxs)(f.Z,{children:[(0,M.jsx)(no,{onClick:()=>te(!0)}),ee&&(0,M.jsx)(wo,{onMenuSelect:e=>{te(!1),W(e)},onClose:()=>te(!1),isSorted:b})]})]}),Z&&Z.length>0&&(0,M.jsx)(so.O,{filters:Z,conditionsOp:A,onUpdateFilter:V,onDeleteFilter:Y,onClearFilters:Q,onReloadSavedFilter:X,filterId:l,filtersList:d,onCondOpChange:q})]}),null!=v&&(0,M.jsx)(fo,{targetBalance:v,balanceQuery:w,onDone:R,onCreateTransaction:D})]})}function xo(e){let{account:t,canSync:n,showBalances:o,canShowBalances:i,showCleared:a,onClose:r,isSorted:l,onReconcile:d,onMenuSelect:c}=e,[u,h]=(0,s.useState)("default");const p=(0,Vn.Z)();return"reconcile"===u?(0,M.jsx)(yo,{account:t,onClose:r,onReconcile:d}):(0,M.jsx)(oo.Z,{width:200,onClose:r,children:(0,M.jsx)(b.Z,{onMenuSelect:e=>{"reconcile"===e?h("reconcile"):c(e)},items:[l&&{name:"remove-sorting",text:"Remove all sorting"},i&&{name:"toggle-balance",text:(o?"Hide":"Show")+" running balance"},{name:"toggle-cleared",text:(a?"Hide":"Show")+" \u201ccleared\u201d checkboxes"},{name:"export",text:"Export"},{name:"reconcile",text:"Reconcile"},t&&!t.closed&&(n?{name:"unlink",text:"Unlink account"}:"online"===p&&{name:"link",text:"Link account"}),t.closed?{name:"reopen",text:"Reopen account"}:{name:"close",text:"Close account"}].filter((e=>e))})})}function wo(e){let{onClose:t,onMenuSelect:n,isSorted:o}=e;return(0,M.jsx)(oo.Z,{width:200,onClose:t,children:(0,M.jsx)(b.Z,{onMenuSelect:e=>{n(e)},items:[o&&{name:"remove-sorting",text:"Remove all sorting"},{name:"export",text:"Export"}]})})}function vo(e){let{onAdd:t}=e;return(0,M.jsx)(f.Z,{style:{backgroundColor:"white",flex:1,alignItems:"center",borderTopWidth:1,borderColor:g.O9.n9},children:(0,M.jsxs)(f.Z,{style:{width:550,marginTop:75,fontSize:15,alignItems:"center"},children:[(0,M.jsxs)(S.Z,{style:{textAlign:"center",lineHeight:"1.4em"},children:["For Actual to be useful, you need to ",(0,M.jsx)("strong",{children:"add an account"}),". You can link an account to automatically download transactions, or manage it locally yourself."]}),(0,M.jsx)(C.Z,{type:"primary",style:{marginTop:20},onClick:t,children:"Add account"}),(0,M.jsx)(f.Z,{style:{marginTop:20,fontSize:13,color:g.O9.n5},children:"In the future, you can add accounts from the sidebar."})]})})}function jo(e){let{account:t={},transactions:n,balances:o,showBalances:i,filtered:a,children:r}=e;const{id:l}=t;let d=(0,Zt.oF)();n??=[];let c=(0,s.useMemo)((()=>d?d.schedules.filter((e=>!e.completed&&["due","upcoming","missed"].includes(d.statuses.get(e.id)))):[]),[d]),u=(0,s.useMemo)((()=>c.map((e=>({id:`preview/${e.id}`,payee:e._payee,account:e._account,amount:e._amount,date:e.next_date,notes:d.statuses.get(e.id),schedule:e.id,_inverse:l!==e._account})))),[c,l]),h=(0,s.useMemo)((()=>{var e,t,s;return i&&o&&(null===(e=n)||void 0===e?void 0:e.length)>0&&null!==(t=null===(s=o[n[0].id])||void 0===s?void 0:s.balance)&&void 0!==t?t:0}),[i,o,n]),p=(0,s.useMemo)((()=>{if(!i)return null;let e=[...u].reverse().map((e=>{let t=(e._inverse?-1:1)*(0,It.lP)(e.amount);return{balance:h+=t,id:e.id}}));return(0,pe.ZZ)(e)}),[i,u,h]),g=(0,s.useMemo)((()=>!a&&u.length>0?u.concat(n):n),[a,u,n]),f=(0,s.useMemo)((()=>!a&&p&&o?{...p,...o}:o),[a,p,o]);return null==d?r(n,o):r(g,f)}function Co(e){switch(e){case"account":return"account.name";case"payee":return"payee.name";case"category":return"category.name";case"payment":case"deposit":return"amount";default:return e}}class bo extends s.PureComponent{constructor(e){super(e),this.fetchAllIds=async()=>{let{data:e}=await(0,A.Vn)(this.paged.getQuery().select("id"));return e.reduce(((e,t)=>(e.push(t.id),t.subtransactions.forEach((t=>e.push(t.id))),e)),[])},this.refetchTransactions=async()=>{var e;null===(e=this.paged)||void 0===e||e.run()},this.fetchTransactions=()=>{let e=this.makeRootQuery();this.rootQuery=this.currentQuery=e,this.updateQuery(e),this.props.accountId&&this.props.markAccountRead(this.props.accountId)},this.makeRootQuery=()=>{let e=this.props.location.state,t=this.props.accountId;return e&&e.filter?(0,A.ZP)("transactions").options({splits:"grouped"}).filter({"account.offbudget":!1,...e.filter}):he.yf(t)},this.onSearch=e=>{this.paged.unsubscribe(),this.setState({search:e},this.onSearchDone)},this.onSearchDone=(0,ln.debounce)((()=>{""===this.state.search?this.updateQuery(this.currentQuery,this.state.filters.length>0):this.updateQuery(he.jS(this.currentQuery,this.state.search,this.props.dateFormat),!0)}),150),this.onSync=async()=>{const e=this.props.accountId,t=this.props.accounts.find((t=>t.id===e));await this.props.syncAndDownload(t?t.id:null)},this.onImport=async()=>{const e=this.props.accountId;if(this.props.accounts.find((t=>t.id===e))){const t=await window.Actual.openFileDialog({filters:[{name:"Financial Files",extensions:["qif","ofx","qfx","csv","tsv"]}]});t&&this.props.pushModal("import-transactions",{accountId:e,filename:t[0],onImported:e=>{e&&this.fetchTransactions()}})}},this.onExport=async e=>{let t=await(0,d.lW)("transactions-export-query",{query:this.currentQuery.serialize()}),n=`${e&&e.replace(/[()]/g,"").replace(/\s+/g,"-")||"transactions"}.csv`;window.Actual.saveFile(t,n,"Export Transactions")},this.onTransactionsChange=(e,t)=>{this.paged.optimisticUpdate((t=>e._deleted?t.filter((t=>t.id!==e.id)):t.map((t=>t.id===e.id?e:t))),(e=>t)),this.props.updateNewTransactions(e.id)},this.canCalculateBalance=()=>{let e=this.props.accountId;return this.props.accounts.find((t=>t.id===e))&&""===this.state.search&&0===this.state.filters.length&&(0===this.state.sort.length||"date"===this.state.sort.field&&"desc"===this.state.sort.ascDesc)},this.onAddTransaction=()=>{this.setState({isAdding:!0})},this.onExposeName=e=>{this.setState({editingName:e})},this.onSaveName=e=>{if(e.trim().length){const t=this.props.accountId,n=this.props.accounts.find((e=>e.id===t));this.props.updateAccount({...n,name:e}),this.setState({editingName:!1})}},this.onToggleExtraBalances=()=>{let{accountId:e,showExtraBalances:t}=this.props,n="show-extra-balances-"+e||0;this.props.savePrefs({[n]:!t})},this.onMenuSelect=async e=>{const t=this.props.accountId,n=this.props.accounts.find((e=>e.id===t));switch(e){case"link":(0,pn.F)(this.props.pushModal,{upgradingAccountId:t});break;case"unlink":this.props.unlinkAccount(t);break;case"close":this.props.openAccountCloseModal(t);break;case"reopen":this.props.reopenAccount(t);break;case"export":const e=this.getAccountTitle(n,t);this.onExport(e);break;case"toggle-balance":this.state.showBalances?(this.props.savePrefs({["show-balances-"+t]:!1}),this.setState({showBalances:!1,balances:null})):(this.props.savePrefs({["show-balances-"+t]:!0}),this.setState({transactions:[],transactionCount:0,filters:[],search:"",sort:[],showBalances:!0},(()=>{this.fetchTransactions()})));break;case"remove-sorting":this.setState({sort:[]},(()=>{let e=this.state.filters;e.length>0?this.applyFilters([...e]):this.fetchTransactions(),""!==this.state.search&&this.onSearch(this.state.search)}));break;case"toggle-cleared":this.state.showCleared?(this.props.savePrefs({["hide-cleared-"+t]:!0}),this.setState({showCleared:!1})):(this.props.savePrefs({["hide-cleared-"+t]:!1}),this.setState({showCleared:!0}))}},this.isNew=e=>this.props.newTransactions.includes(e),this.isMatched=e=>this.props.matchedTransactions.includes(e),this.onCreatePayee=e=>""!==e.trim()?this.props.createPayee(e):null,this.onReconcile=e=>{this.setState({reconcileAmount:e})},this.onDoneReconciling=()=>{this.setState({reconcileAmount:null})},this.onCreateReconciliationTransaction=async e=>{const t=(0,hn.V6)([{id:"temp",account:this.props.accountId,cleared:!0,amount:e,date:(0,u.PR)(),notes:"Reconciliation balance adjustment"}]);this.setState({transactions:[...this.state.transactions,...t]}),await(0,d.lW)("transactions-batch-update",{added:t}),await this.refetchTransactions()},this.onShowTransactions=async e=>{this.onApplyFilter({customName:"Selected transactions",filter:{id:{$oneof:e}}})},this.onBatchEdit=async(e,t)=>{let n=async(e,n)=>{this.setState({workingHard:!0});let{data:o}=await(0,A.Vn)((0,A.ZP)("transactions").filter({id:{$oneof:t}}).select("*").options({splits:"grouped"})),i=(0,hn.Xt)(o),s={deleted:[],updated:[]};"cleared"===e&&(n=!!i.find((e=>!e.cleared)));const a=new Set(t);i.forEach((t=>{if(!a.has(t.id))return;let{diff:o}=(0,hn.Ld)(i,{...t,[e]:n});i=(0,pe.zb)(o,i),s.deleted=s.deleted?s.deleted.concat(o.deleted):o.deleted,s.updated=s.updated?s.updated.concat(o.updated):o.updated,s.added=s.added?s.added.concat(o.added):o.added})),await(0,d.lW)("transactions-batch-update",s),await this.refetchTransactions(),this.table.current&&this.table.current.edit(i[0].id,"select",!1)};"cleared"===e?n("cleared",null):this.props.pushModal("edit-field",{name:e,onSubmit:n})},this.onBatchDuplicate=async e=>{this.setState({workingHard:!0});let{data:t}=await(0,A.Vn)((0,A.ZP)("transactions").filter({id:{$oneof:e}}).select("*").options({splits:"grouped"})),n={added:t.reduce(((e,t)=>e.concat((0,hn.V6)((0,hn.F6)(t)))),[]).map((e=>{let{sort_order:t,...n}=e;return{...n}}))};await(0,d.lW)("transactions-batch-update",n),await this.refetchTransactions()},this.onBatchDelete=async e=>{this.setState({workingHard:!0});let{data:t}=await(0,A.Vn)((0,A.ZP)("transactions").filter({id:{$oneof:e}}).select("*").options({splits:"grouped"})),n=(0,hn.Xt)(t),o=new Set(e),i={deleted:[],updated:[]};n.forEach((e=>{let t=e.parent_id;if(!o.has(e.id)||t&&o.has(t))return;let{diff:s}=(0,hn.Ks)(n,e.id);n=(0,pe.zb)(s,n),i.deleted=s.deleted?i.deleted.concat(s.deleted):s.deleted,i.updated=s.updated?i.updated.concat(s.updated):s.updated})),await(0,d.lW)("transactions-batch-update",i),await this.refetchTransactions()},this.onBatchUnlink=async e=>{await(0,d.lW)("transactions-batch-update",{updated:e.map((e=>({id:e,schedule:null})))}),await this.refetchTransactions()},this.onCreateRule=async e=>{let{data:t}=await(0,A.Vn)((0,A.ZP)("transactions").filter({id:{$oneof:e}}).select("*").options({splits:"grouped"})),n=(0,hn.Xt)(t),o={stage:null,conditionsOp:"and",conditions:[n[0].imported_payee?{field:"imported_payee",op:"is",value:n[0].imported_payee,type:"string"}:{field:"payee",op:"is",value:n[0].payee,type:"id"}],actions:[{op:"set",field:"category",value:n[0].category,type:"id"}]};this.props.pushModal("edit-rule",{rule:o})},this.onCondOpChange=(e,t)=>{this.setState({conditionsOp:e}),this.setState({filterId:{...this.state.filterId,status:"changed"}}),this.applyFilters([...t]),""!==this.state.search&&this.onSearch(this.state.search)},this.onReloadSavedFilter=(e,t)=>{if("reload"===t){let[e]=this.props.filtersList.filter((e=>e.id===this.state.filterId.id));this.setState({conditionsOp:e.conditionsOp}),this.applyFilters([...e.conditions])}else e.status&&(this.setState({conditionsOp:e.conditionsOp}),this.applyFilters([...e.conditions]));this.setState({filterId:{...this.state.filterId,...e}})},this.onClearFilters=()=>{this.setState({conditionsOp:"and"}),this.setState({filterId:[]}),this.applyFilters([]),""!==this.state.search&&this.onSearch(this.state.search)},this.onUpdateFilter=(e,t)=>{this.applyFilters(this.state.filters.map((n=>n===e?t:n))),this.setState({filterId:{...this.state.filterId,status:this.state.filterId&&"changed"}}),""!==this.state.search&&this.onSearch(this.state.search)},this.onDeleteFilter=e=>{this.applyFilters(this.state.filters.filter((t=>t!==e))),1===this.state.filters.length?(this.setState({filterId:[]}),this.setState({conditionsOp:"and"})):this.setState({filterId:{...this.state.filterId,status:this.state.filterId&&"changed"}}),""!==this.state.search&&this.onSearch(this.state.search)},this.onApplyFilter=async e=>{let t=this.state.filters;e.customName&&(t=t.filter((t=>t.customName!==e.customName))),e.conditions?(this.setState({filterId:{...e,status:"saved"}}),this.setState({conditionsOp:e.conditionsOp}),this.applyFilters([...e.conditions])):(this.setState({filterId:{...this.state.filterId,status:this.state.filterId&&"changed"}}),this.applyFilters([...t,e])),""!==this.state.search&&this.onSearch(this.state.search)},this.onScheduleAction=async(e,t)=>{switch(e){case"post-transaction":for(let e of t){let t=e.split("/");await(0,d.lW)("schedule/post-transaction",{id:t[1]})}this.refetchTransactions();break;case"skip":for(let e of t){let t=e.split("/");await(0,d.lW)("schedule/skip-next-date",{id:t[1]})}}},this.applyFilters=async e=>{if(e.length>0){let t=e.filter((e=>!!e.customName)).map((e=>e.filter)),{filters:n}=await(0,d.lW)("make-filters-from-conditions",{conditions:e.filter((e=>!e.customName))});const o="or"===this.state.conditionsOp?"$or":"$and";this.currentQuery=this.rootQuery.filter({[o]:[...n,...t]}),this.setState({filters:e},(()=>{this.updateQuery(this.currentQuery,!0)}))}else this.setState({transactions:[],transactionCount:0,filters:e},(()=>{this.fetchTransactions()}));0!==this.state.sort.length&&this.applySort()},this.applySort=(e,t,n,o)=>{let i=this.state.filters,s=Co(e||this.state.sort.field),a=t||this.state.sort.ascDesc,r=Co(n||this.state.sort.prevField),l=n?o:this.state.sort.prevAscDesc;e?i.length>0?(this.applyFilters([...i]),this.currentQuery=this.currentQuery.orderBy({[s]:a})):this.currentQuery=this.rootQuery.orderBy({[s]:a}):this.currentQuery=this.currentQuery.orderBy({[s]:a}),r&&(this.currentQuery=this.currentQuery.orderBy({[r]:l})),this.updateQuery(this.currentQuery,this.state.filters.length>0)},this.onSort=(e,t)=>{let n,o;e===this.state.sort.field?(n=this.state.sort.prevField,o=this.state.sort.prevAscDesc,this.setState({sort:{...this.state.sort,ascDesc:t}})):(n=this.state.sort.field,o=this.state.sort.ascDesc,this.setState({sort:{field:e,ascDesc:t,prevField:this.state.sort.field,prevAscDesc:this.state.sort.ascDesc}})),this.applySort(e,t,n,o),""!==this.state.search&&this.onSearch(this.state.search)},this.paged=null,this.table=(0,s.createRef)(),this.animated=!0,this.state={search:"",filters:[],loading:!0,workingHard:!1,reconcileAmount:null,transactions:[],transactionsCount:0,showBalances:e.showBalances,balances:null,showCleared:e.showCleared,editingName:!1,isAdding:!1,latestDate:null,filterId:[],conditionsOp:"and",sort:[]}}async componentDidMount(){let e=e=>{if(e.includes("transactions")||e.includes("category_mapping")||e.includes("payee_mapping"))return this.refetchTransactions()},t=async t=>{let n,{tables:o,messages:i,undoTag:s}=t;if(await e(o),i.every((e=>"transactions"===e.dataset))&&!i.find((e=>"tombstone"===e.column))){let e=i.filter((e=>"transactions"===e.dataset&&!("tombstone"===e.column)));n=1===e.length?e[0].row:null}this.table.current&&(this.table.current.edit(null),n&&this.table.current.scrollTo(n)),this.props.setLastUndoState(null)},n=[(0,d.oL)("undo-event",t)];this.unlisten=()=>{n.forEach((e=>e()))},0===this.props.categoryGroups.length&&await this.props.getCategories(),await this.props.initiallyLoadPayees(),await this.fetchTransactions(),this.props.lastUndoState&&this.props.lastUndoState.current&&t(this.props.lastUndoState.current)}componentDidUpdate(e){this.state.isAdding&&this.props.accountId!==e.accountId&&this.setState({isAdding:!1}),e.modalShowing&&!this.props.modalShowing&&setTimeout((()=>{this.refetchTransactions()}),100),this.props.accountId!==e.accountId&&this.setState({sort:[],search:"",filters:[]})}componentWillUnmount(){this.unlisten&&this.unlisten(),this.paged&&this.paged.unsubscribe()}updateQuery(e,t){this.paged&&this.paged.unsubscribe(),this.paged=(0,A.Fr)(e.select("*"),(async(e,n)=>{const o=null==n;var i;o&&(null===(i=this.table.current)||void 0===i||i.setRowAnimation(!1),t?this.props.splitsExpandedDispatch({type:"set-mode",mode:"collapse"}):this.props.splitsExpandedDispatch({type:"set-mode",mode:this.props.expandSplits?"expand":"collapse"}));this.setState({transactions:e,transactionCount:this.paged.getTotalCount(),transactionsFiltered:t,loading:!1,workingHard:!1,balances:this.state.showBalances?await this.calculateBalances():null},(()=>{var e;o&&(null===(e=this.table.current)||void 0===e||e.scrollToTop());setTimeout((()=>{var e;null===(e=this.table.current)||void 0===e||e.setRowAnimation(!0)}),0)}))}),{pageCount:150,onlySync:!0,mapper:hn.Xt})}componentWillReceiveProps(e){this.props.accountId!==e.accountId&&this.setState({editingName:!1,loading:!0,search:"",showBalances:e.showBalances,balances:null,showCleared:e.showCleared},(()=>{this.fetchTransactions()}))}async calculateBalances(){if(!this.canCalculateBalance())return null;let{data:e}=await(0,A.Vn)(this.paged.getQuery().options({splits:"none"}).select([{balance:{$sumOver:"$amount"}}]));return(0,pe.ZZ)(e)}getAccountTitle(e,t){let{filterName:n}=this.props.location.state||{};return n||(e?e.name:"budgeted"===t?"Budgeted Accounts":"offbudget"===t?"Off Budget Accounts":"uncategorized"===t?"Uncategorized":t?null:"All Accounts")}getBalanceQuery(e,t){return{name:`balance-query-${t}`,query:this.makeRootQuery().calculate({$sum:"$amount"})}}render(){let{accounts:e,categoryGroups:t,payees:n,dateFormat:o,hideFraction:i,addNotification:s,accountsSyncing:a,replaceModal:l,showExtraBalances:d,accountId:c,categoryId:u}=this.props,{transactions:h,loading:p,workingHard:y,filterId:m,reconcileAmount:x,transactionsFiltered:w,editingName:v,showBalances:j,balances:C,showCleared:b}=this.state,S=e.find((e=>e.id===c));const Z=this.getAccountTitle(S,c);if(!Z&&!p)return(0,M.jsx)(r.Fg,{to:"/accounts",replace:!0});let A=t.flatMap((e=>e.categories)).find((e=>e.id===u)),k=!p&&!c&&0===e.length,T=c&&"budgeted"!==c&&"offbudget"!==c&&"uncategorized"!==c,O=this.getBalanceQuery(S,c);return(0,M.jsx)(jo,{account:S,transactions:h,balances:C,showBalances:j,filtered:w,children:(r,u)=>(0,M.jsx)(Lt.mL,{name:"transactions",items:r,fetchAllIds:this.fetchAllIds,registerDispatch:e=>this.dispatchSelected=e,children:(0,M.jsxs)(f.Z,{style:[g.W2.page],children:[(0,M.jsx)(mo,{tableRef:this.table,editingName:v,isNameEditable:T,workingHard:y,account:S,filterId:m,filtersList:this.props.filtersList,location:this.props.location,accountName:Z,accountsSyncing:a,accounts:e,transactions:h,showBalances:j,showExtraBalances:d,showCleared:b,showEmptyMessage:k,balanceQuery:O,canCalculateBalance:this.canCalculateBalance,isSorted:0!==this.state.sort.length,reconcileAmount:x,search:this.state.search,filters:this.state.filters,conditionsOp:this.state.conditionsOp,savePrefs:this.props.savePrefs,onSearch:this.onSearch,onShowTransactions:this.onShowTransactions,onMenuSelect:this.onMenuSelect,onAddTransaction:this.onAddTransaction,onToggleExtraBalances:this.onToggleExtraBalances,onSaveName:this.onSaveName,onExposeName:this.onExposeName,onReconcile:this.onReconcile,onDoneReconciling:this.onDoneReconciling,onCreateReconciliationTransaction:this.onCreateReconciliationTransaction,onSync:this.onSync,onImport:this.onImport,onBatchDelete:this.onBatchDelete,onBatchDuplicate:this.onBatchDuplicate,onBatchEdit:this.onBatchEdit,onBatchUnlink:this.onBatchUnlink,onCreateRule:this.onCreateRule,onUpdateFilter:this.onUpdateFilter,onClearFilters:this.onClearFilters,onReloadSavedFilter:this.onReloadSavedFilter,onCondOpChange:this.onCondOpChange,onDeleteFilter:this.onDeleteFilter,onApplyFilter:this.onApplyFilter,onScheduleAction:this.onScheduleAction}),(0,M.jsx)(f.Z,{style:{flex:1},children:(0,M.jsx)($n,{tableRef:this.table,account:S,transactions:h,allTransactions:r,animated:this.animated,loadMoreTransactions:()=>this.paged&&this.paged.fetchNext(),accounts:e,category:A,categoryGroups:t,payees:n,balances:u,showBalances:!!u,showCleared:b,showAccount:!c||"offbudget"===c||"budgeted"===c||"uncategorized"===c,isAdding:this.state.isAdding,isNew:this.isNew,isMatched:this.isMatched,isFiltered:""!==this.state.search||this.state.filters.length>0,dateFormat:o,hideFraction:i,addNotification:s,renderEmpty:()=>k?(0,M.jsx)(vo,{onAdd:()=>l("add-account")}):p?null:(0,M.jsx)(f.Z,{style:{marginTop:20,textAlign:"center",fontStyle:"italic"},children:"No transactions"}),onSort:this.onSort,sortField:this.state.sort.field,ascDesc:this.state.sort.ascDesc,onChange:this.onTransactionsChange,onRefetch:this.refetchTransactions,onRefetchUpToRow:e=>this.paged.refetchUpToRow(e,{field:"date",order:"desc"}),onCloseAddTransaction:()=>this.setState({isAdding:!1}),onCreatePayee:this.onCreatePayee})})]})})})}}function So(e){let{dispatch:t}=Tn(),n=(0,r.bS)(e.location.pathname);return(0,M.jsx)(bo,{...e,match:n,splitsExpandedDispatch:t})}function Zo(){var e,t;let n=(0,r.UO)(),o=(0,r.TH)(),i=(0,gn.F)(),l=(0,a.v9)((e=>({newTransactions:e.queries.newTransactions,matchedTransactions:e.queries.matchedTransactions,accounts:e.queries.accounts,failedAccounts:e.account.failedAccounts,categoryGroups:e.queries.categories.grouped,dateFormat:e.prefs.local.dateFormat||"MM/dd/yyyy",hideFraction:e.prefs.local.hideFraction||!1,expandSplits:e.prefs.local["expand-splits"],showBalances:n.id&&e.prefs.local["show-balances-"+n.id],showCleared:n.id&&!e.prefs.local["hide-cleared-"+n.id],showExtraBalances:e.prefs.local["show-extra-balances-"+n.id||0],payees:e.queries.payees,modalShowing:e.modals.modalStack.length>0,accountsSyncing:e.account.accountsSyncing,lastUndoState:e.app.lastUndoState}))),d=(0,a.I0)(),c=(0,un.m)(),u=(0,s.useMemo)((()=>(0,dn.DE)(cn,d)),[d]),h=(0,s.useMemo)((()=>{let e=he.PK(n.id,"_account"),t=he.PK(n.id,"_payee.transfer_acct");return(o.state&&o.state.filter||"uncategorized"===n.id)&&(e={id:null},t={id:null}),n=>(n=n.filter({$and:[{"_account.closed":!1}],$or:[e,t]})).orderBy({next_date:"desc"})}),[n.id]);return(0,M.jsx)(Zt.up,{transform:h,children:(0,M.jsx)(On,{initialMode:l.expandSplits?"collapse":"expand",children:(0,M.jsx)(So,{...l,...u,modalShowing:l.modalShowing||!(!i.state||!i.state.parent),accountId:n.id,categoryId:null===i||void 0===i||null===(e=i.state)||void 0===e||null===(t=e.filter)||void 0===t?void 0:t.category,location:o,filtersList:c})})})}},58155:function(e,t,n){"use strict";function o(e,t){return e.map((e=>(e.id===t.cat_group&&(e.categories=[t,...e.categories]),{...e})))}function i(e,t){return e.map((e=>(e.id===t.cat_group&&(e.categories=e.categories.map((e=>e.id===t.id?{...e,...t}:e))),e)))}function s(e,t,n,o){if(t===o)return e;let i=e.reduce(((e,n)=>e||n.categories.find((e=>e.id===t))),null);return i={...i,cat_group:n},e.map((e=>(e.id===n?(e.categories=e.categories.reduce(((e,n)=>(n.id===o?(e.push(i),e.push(n)):n.id!==t&&e.push(n),e)),[]),o||e.categories.push(i)):e.categories=e.categories.filter((e=>e.id!==t)),{...e})))}function a(e,t,n){if(t===n)return e;let o=e.find((e=>e.id===t));return e=e.reduce(((e,i)=>(i.id===n?(e.push(o),e.push(i)):i.id!==t&&e.push(i),e)),[]),n||e.push(o),e}function r(e,t){return e.map((e=>(e.categories=e.categories.filter((e=>e.id!==t)),e)))}function l(e,t){return[...e,t]}function d(e,t){return e.map((e=>e.id===t.id?{...e,...t}:e))}function c(e,t){return e.filter((e=>e.id!==t))}n.d(t,{Rp:function(){return l},Wr:function(){return s},eq:function(){return a},i8:function(){return o},iE:function(){return c},mD:function(){return d},uu:function(){return r},yr:function(){return i}})},28731:function(e,t,n){"use strict";n.d(t,{CX:function(){return y},F6:function(){return p},J4:function(){return s},Ks:function(){return x},Ld:function(){return m},M$:function(){return c},V6:function(){return v},Xt:function(){return u},_n:function(){return g},oQ:function(){return w}});var o=n(5284),i=n(69585);function s(e){return-1!==e.indexOf("preview/")}function a(e){return"number"===typeof e?e:0}function r(e,t){return{type:"SplitTransactionError",version:1,difference:a(t.amount)-e}}function l(e,t){let n="temp"===e.id?"temp":"";return{amount:0,...t,payee:t.payee||e.payee,id:t.id?t.id:n+(0,o.Z)(),account:e.account,date:e.date,cleared:null!=e.cleared?e.cleared:null,starting_balance_flag:null!=e.starting_balance_flag?e.starting_balance_flag:null,is_child:!0,parent_id:e.id,error:null}}function d(e){const t=e.subtransactions.reduce(((e,t)=>e+a(t.amount)),0);return{...e,error:t===a(e.amount)?null:r(t,e)}}function c(e,t){let n=[e[t]],o=t+1;for(;o<e.length&&e[o].is_child;)n.push(e[o]),o++;return n}function u(e){return e.reduce(((e,t)=>{let{subtransactions:n,...o}=t;n=n||[],e.push(o);for(let i=0;i<n.length;i++)e.push(n[i]);return e}),[])}function h(e){return{...e[0],subtransactions:e.slice(1)}}function p(e){return null==e?null:u([e])}function g(e,t){return h((0,i.zb)(t,p(e)))}function f(e,t,n){let o=e.findIndex((e=>e.id===t)),s=e[o],a=[...e];if(-1===o)throw new Error("Tried to edit unknown transaction id: "+t);if(s.is_parent||s.is_child){let t=function(e,t){for(;t>=0;){if(e[t].is_parent)return t;t--}return null}(e,o);if(null==t)return console.log("Cannot find parent index"),{diff:{deleted:[],updated:[]}};let s,r=c(e,t),l=n(h(r)),d=p(l);return null==d?(s={deleted:[{id:r[0].id}],updated:[]},l={id:r[0].id,_deleted:!0},a.splice(t,r.length)):(s=(0,i.Th)(r,d),a.splice(t,r.length,...d)),{data:a,newTransaction:l,diff:s}}{let e=n(s),t=p(e)||[];return e&&(e.subtransactions=e.subtransactions||[]),a.splice(o,1,...t),{data:a,newTransaction:e||{id:s.id,_deleted:!0},diff:(0,i.Th)([s],t)}}}function y(e,t){return f(e,t,(e=>{if(!e.is_parent)return e;let t=(0,i.Z$)(e.subtransactions);return e.subtransactions.push(l(e,{amount:0,sort_order:a(t&&t.sort_order)-1})),e}))}function m(e,t){return f(e,t.id,(e=>{if(e.is_parent){let n=e.id===t.id?t:e,o=e.subtransactions.map((o=>{let i=o;return e.id===t.id?i={...o,payee:o.payee===e.payee?t.payee:o.payee}:o.id===t.id&&(i=t),l(n,i)}));return d({...n,subtransactions:o})}return t}))}function x(e,t){return f(e,t,(e=>{if(e.is_parent){if(e.id===t)return null;if(1===e.subtransactions.length)return{...e,subtransactions:null,is_parent:!1,error:null};{let n=e.subtransactions.filter((e=>e.id!==t));return d({...e,subtransactions:n})}}return null}))}function w(e,t){return f(e,t,(e=>e.is_parent||e.is_child?e:{...e,is_parent:!0,error:0===a(e.amount)?null:r(0,e),subtransactions:[l(e,{amount:0,sort_order:-1})]}))}function v(e){let t=e.find((e=>!e.is_child));t={...t,id:(0,o.Z)()};let n=e.filter((e=>e.is_child));return[t,...n.map((e=>({...e,id:(0,o.Z)(),parent_id:t.id})))]}},74881:function(e){function t(e,t,n){var o,i,s,a,r;function l(){var d=Date.now()-a;d<t&&d>=0?o=setTimeout(l,t-d):(o=null,n||(r=e.apply(s,i),s=i=null))}null==t&&(t=100);var d=function(){s=this,i=arguments,a=Date.now();var d=n&&!o;return o||(o=setTimeout(l,t)),d&&(r=e.apply(s,i),s=i=null),r};return d.clear=function(){o&&(clearTimeout(o),o=null)},d.flush=function(){o&&(r=e.apply(s,i),s=i=null,clearTimeout(o),o=null)},d}t.debounce=t,e.exports=t}}]);
2
+ //# sourceMappingURL=wide-components.e3cfa9ca.chunk.js.map