(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[368],{4841:function(e,t,n){(window.__NEXT_P=window.__NEXT_P||[]).push(["/stats",function(){return n(8011)}])},6248:function(e,t,n){"use strict";n.d(t,{Z:function(){return i}});var a=n(5893),r=n(7294),c=n(1163),s=n(9415);let o=[{href:"/",label:"首页",icon:"home"},{href:"/stats",label:"统计",icon:"chart"},{href:"/recurring",label:"周期",icon:"repeat"},{href:"/categories",label:"分类",icon:"tags"}];function i(e){let{title:t,subtitle:n,actions:i,headerContent:l,children:u,contentClassName:d="",hideNav:h=!1,compactHeader:p=!1}=e,m=(0,c.useRouter)(),f=(0,r.useMemo)(()=>{let e=o.find(e=>e.href===m.pathname);return(null==e?void 0:e.href)||null},[m.pathname]),g=l||(t?(0,a.jsxs)("div",{className:"app-header__text",children:[(0,a.jsx)("h1",{children:t}),n?(0,a.jsx)("p",{children:n}):null]}):null),y=["app-header",p?"app-header--compact":"",g?"app-header--with-content":"app-header--actions-only",i?"app-header--with-actions":""].filter(Boolean).join(" ");return(0,a.jsxs)("div",{className:"app-shell".concat(h?" app-shell--standalone":""),children:[(0,a.jsx)("header",{className:y,children:(0,a.jsxs)("div",{className:"app-shell__container app-header__inner",children:[g?(0,a.jsx)("div",{className:"app-header__main",children:g}):(0,a.jsx)("div",{className:"app-header__spacer","aria-hidden":"true"}),i?(0,a.jsx)("div",{className:"app-header__actions",children:i}):null]})}),(0,a.jsx)("main",{className:"app-content ".concat(d).trim(),children:(0,a.jsx)("div",{className:"app-shell__container app-content__inner",children:u})}),h?null:(0,a.jsx)("nav",{className:"bottom-nav","aria-label":"主导航",children:(0,a.jsx)("div",{className:"app-shell__container bottom-nav__inner",children:o.map(e=>{let t=f===e.href;return(0,a.jsxs)("button",{type:"button",className:"bottom-nav__item".concat(t?" is-active":""),onClick:()=>m.push(e.href),"aria-current":t?"page":void 0,children:[(0,a.jsx)(s.J,{name:e.icon,size:20}),(0,a.jsx)("span",{children:e.label})]},e.href)})})})]})}},610:function(e,t,n){"use strict";async function a(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=await fetch("".concat("").concat(e),{...t,headers:{"Content-Type":"application/json",...function(){let e=localStorage.getItem("token");return e?{Authorization:"Bearer ".concat(e)}:{}}(),...t.headers}}),a=await n.json();if(!n.ok)throw Error(a.error||"请求失败");return a}async function r(e,t){let n=await a("/api/auth/login",{method:"POST",body:JSON.stringify({username:e,password:t})});return localStorage.setItem("token",n.token),n}async function c(e,t){let n=await a("/api/auth/register",{method:"POST",body:JSON.stringify({username:e,password:t})});return localStorage.setItem("token",n.token),n}function s(){localStorage.removeItem("token")}function o(){return!!localStorage.getItem("token")}async function i(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"all",n="/api/records?month=".concat(e);return"all"!==t&&(n+="&type=".concat(t)),a(n)}async function l(e){return a("/api/stats?month=".concat(e))}async function u(e){return a("/api/records",{method:"POST",body:JSON.stringify(e)})}async function d(e,t){return a("/api/records/".concat(e),{method:"PUT",body:JSON.stringify(t)})}async function h(e){return a("/api/records/".concat(e),{method:"DELETE"})}async function p(e){return a("/api/records/search?q=".concat(encodeURIComponent(e)))}async function m(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"month",t=arguments.length>1?arguments[1]:void 0,n="/api/stats/trend?period=".concat(e);return t&&(n+="&month=".concat(t)),a(n)}async function f(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"all",n="/api/stats/category?type=".concat(t);return e&&(n+="&month=".concat(e)),a(n)}async function g(){return a("/api/recurring")}async function y(e){return a("/api/recurring",{method:"POST",body:JSON.stringify(e)})}async function b(e,t){return a("/api/recurring/".concat(e),{method:"PUT",body:JSON.stringify(t)})}async function x(e){return a("/api/recurring/".concat(e),{method:"DELETE"})}async function j(e){return a("/api/recurring/".concat(e,"/apply"),{method:"POST"})}async function N(){return a("/api/categories")}async function v(e){return a("/api/categories",{method:"POST",body:JSON.stringify(e)})}async function _(e){return a("/api/categories/".concat(e),{method:"DELETE"})}async function k(){return a("/api/export")}async function S(e){return a("/api/import",{method:"POST",body:JSON.stringify(e)})}n.d(t,{Ap:function(){return f},CP:function(){return N},JS:function(){return h},Kp:function(){return p},Q6:function(){return i},TZ:function(){return x},Vn:function(){return g},Vs:function(){return d},Xu:function(){return j},ae:function(){return u},dk:function(){return S},fy:function(){return l},gR:function(){return m},jl:function(){return o},k4:function(){return v},kS:function(){return s},u1:function(){return k},uO:function(){return b},uu:function(){return _},x4:function(){return r},z0:function(){return y},z2:function(){return c}})},8011:function(e,t,n){"use strict";n.r(t),n.d(t,{default:function(){return d}});var a=n(5893),r=n(7294),c=n(1163),s=n(610),o=n(3148),i=n(6248),l=n(9415),u=n(5546);function d(){let e=(0,c.useRouter)(),{showToast:t}=(0,u.p)(),[n,d]=(0,r.useState)("month"),[h,p]=(0,r.useState)(new Date),[m,f]=(0,r.useState)([]),[g,y]=(0,r.useState)([]),[b,x]=(0,r.useState)("expense"),[j,N]=(0,r.useState)(!0),[v,_]=(0,r.useState)(!0),k=(0,r.useRef)(null),S=(0,r.useRef)(null),w=(0,r.useRef)(null),C=(0,r.useRef)(null);(0,r.useEffect)(()=>{if(!(0,s.jl)()){e.push("/login");return}O()},[e,n,h]),(0,r.useEffect)(()=>{(0,s.jl)()&&T()},[e,h,b]);let E=e=>"".concat(e.getFullYear(),"-").concat(String(e.getMonth()+1).padStart(2,"0")),O=async()=>{N(!0);try{let e=await (0,s.gR)(n,E(h));f(e)}catch(e){console.error(e),t(e.message,{tone:"error"})}finally{N(!1)}},T=async()=>{_(!0);try{let e=await (0,s.Ap)(E(h),b);y(e)}catch(e){console.error(e),t(e.message,{tone:"error"})}finally{_(!1)}};(0,r.useEffect)(()=>{if(w.current&&w.current.destroy(),k.current&&m.length>0){let e=k.current.getContext("2d");w.current=new o.kL(e,{type:"line",data:{labels:m.map(e=>e.period),datasets:[{label:"收入",data:m.map(e=>e.income),borderColor:"#10b981",backgroundColor:"rgba(16, 185, 129, 0.1)",fill:!0,tension:.4},{label:"支出",data:m.map(e=>e.expense),borderColor:"#ef4444",backgroundColor:"rgba(239, 68, 68, 0.1)",fill:!0,tension:.4}]},options:{responsive:!0,maintainAspectRatio:!1,plugins:{legend:{position:"top"}},scales:{y:{beginAtZero:!0}}}})}},[m]),(0,r.useEffect)(()=>{if(C.current&&C.current.destroy(),S.current&&g.length>0){let e=S.current.getContext("2d");C.current=new o.kL(e,{type:"doughnut",data:{labels:g.map(e=>e.category),datasets:[{data:g.map(e=>e.total),backgroundColor:["#2563eb","#10b981","#f59e0b","#ef4444","#8b5cf6","#ec4899","#06b6d4","#84cc16","#f97316","#6366f1"].slice(0,g.length)}]},options:{responsive:!0,maintainAspectRatio:!1,plugins:{legend:{position:"bottom"}}}})}},[g]);let J=g.reduce((e,t)=>e+t.total,0),P=(0,a.jsxs)("div",{className:"header-center-container",children:[(0,a.jsx)("div",{className:"header-spacer"}),(0,a.jsxs)("div",{className:"month-switcher-container",children:[(0,a.jsx)("button",{type:"button",className:"icon-button","aria-label":"上个月",onClick:()=>{let e=new Date(h);e.setMonth(e.getMonth()-1),p(e)},children:(0,a.jsx)(l.J,{name:"chevronLeft",size:18})}),(0,a.jsx)("span",{className:"month-switcher__label",children:"".concat(h.getFullYear(),"年").concat(h.getMonth()+1,"月")}),(0,a.jsx)("button",{type:"button",className:"icon-button","aria-label":"下个月",onClick:()=>{let e=new Date(h);e.setMonth(e.getMonth()+1),p(e)},children:(0,a.jsx)(l.J,{name:"chevronRight",size:18})})]}),(0,a.jsx)("div",{className:"header-right-actions",children:(0,a.jsx)("button",{type:"button",className:"icon-button","aria-label":"设置",onClick:()=>e.push("/settings"),children:(0,a.jsx)(l.J,{name:"settings",size:18})})})]});return(0,a.jsxs)(i.Z,{headerContent:P,compactHeader:!0,children:[(0,a.jsxs)("section",{className:"card section-card section-card--stats",children:[(0,a.jsx)("div",{className:"section-heading section-heading--compact",children:(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"eyebrow",children:"趋势"}),(0,a.jsx)("h2",{children:"收支趋势"})]})}),(0,a.jsxs)("div",{className:"period-tabs",children:[(0,a.jsx)("button",{type:"button",className:"week"===n?"active":"",onClick:()=>d("week"),children:"周"}),(0,a.jsx)("button",{type:"button",className:"month"===n?"active":"",onClick:()=>d("month"),children:"月"}),(0,a.jsx)("button",{type:"button",className:"year"===n?"active":"",onClick:()=>d("year"),children:"年"})]}),(0,a.jsx)("div",{className:"chart-container chart-container--large chart-container--stats",children:j?(0,a.jsx)("div",{className:"loading-state",children:"加载中..."}):(0,a.jsx)("canvas",{ref:k})})]}),(0,a.jsxs)("section",{className:"card section-card section-card--stats",children:[(0,a.jsx)("div",{className:"section-heading section-heading--compact",children:(0,a.jsx)("div",{children:(0,a.jsx)("h2",{children:"分类明细"})})}),(0,a.jsxs)("div",{className:"category-type-tabs",children:[(0,a.jsx)("button",{type:"button",className:"expense"===b?"active":"",onClick:()=>x("expense"),children:"支出"}),(0,a.jsx)("button",{type:"button",className:"income"===b?"active":"",onClick:()=>x("income"),children:"收入"})]}),(0,a.jsx)("div",{className:"category-breakdown category-breakdown--stats",children:g.length>0?g.map((e,t)=>{let n=J?(e.total/J*100).toFixed(1):"0.0";return(0,a.jsxs)("div",{className:"stats-category-item",children:[(0,a.jsxs)("div",{className:"stats-category-header",children:[(0,a.jsx)("span",{className:"stats-category-name",children:e.category}),(0,a.jsx)("span",{className:"stats-category-amount",children:e.total.toFixed(2)})]}),(0,a.jsx)("div",{className:"stats-category-bar-wrap",children:(0,a.jsx)("div",{className:"stats-category-bar",style:{width:"".concat(n,"%")}})})]},t)}):(0,a.jsx)("div",{className:"empty-state empty-state--inline",children:"暂无数据"})})]})]})}o.kL.register(...o.zX)}},function(e){e.O(0,[196,925,888,774,179],function(){return e(e.s=4841)}),_N_E=e.O()}]);