PageSourceSearch

https://hintermoos.at/assets/CostsCategories-Cld71dli.js

js hintermoos.at collected 2026-10-09 22:02:08 UTC 73,193 bytes, 10 lines download raw bytes

1import{c as ds,u as Et,r as b,j as e,w as be,K as Ce,N as Se,O as Me,B as he,X as Xt,x as je,s as lt,a as us,T as Bt,$ as vt,G as yt,H as bt,J as jt,y as Vt,I as Tt,m as Ht,a2 as Ot,o as ms}from"./index-MoAbC8_9.js";import{S as Be,a as He,b as Oe,c as Ke,d as me}from"./select-ChAxOmxm.js";import{O as gs}from"./OwnersLayout-Cd0M3dw8.js";import{B as it}from"./badge-BHbYeRgi.js";import{A as xs,b as ps,a as hs}from"./alert-B1M6s1_G.js";import{u as qt,c as ye,t as Mt,a as fs,g as Kt,b as Nt,d as vs}from"./useCategorySystem-D4jOQRmA.js";import{T as Ie}from"./trending-up-Cg9WFJWB.js";import{C as It}from"./calendar-CnsXUgOr.js";import{A as ys}from"./arrow-up-down-D7o6PKMM.js";import{C as Qt,S as bs}from"./Header-CnJGZ8vQ.js";import{R as nt,X as Te,Y as Fe,T as _e,C as st,L as rt,B as at}from"./generateCategoricalChart-C2b_mvpD.js";import{L as kt}from"./LineChart-CgmaZj2v.js";import{L as ot}from"./Line-DFydwSLz.js";import{T as Ye}from"./trending-down-EHPUNHPt.js";import{E as es}from"./euro-Cc6O9qjZ.js";import{C as pt}from"./chart-column-Bo5i9GGE.js";import{B as Ft}from"./BarChart-FFUEJ1QK.js";import{M as ht}from"./minus-Dry52jGc.js";import{R as js}from"./receipt-DnGXta2k.js";import{F as Ns}from"./filter-DtRxSZ25.js";import{D as ks}from"./download-DXQgHLv7.js";import{B as Gt}from"./breadcrumb-CmKLwRya.js";import{C as ws}from"./chevron-up-JyGCcpt9.js";import{C as Cs}from"./chevron-down-BDe4YKQW.js";import{U as Ss}from"./users-xui-UtA1.js";import{B as zs}from"./building-crte1H4H.js";import{Z as Ds}from"./zap-D5DuRxrj.js";import{F as Vs}from"./file-text-Bif0RP8Y.js";import{W as Ts}from"./wrench-B4A_f5hE.js";import{D as Fs}from"./droplets-Cp2l0Gq2.js";import{R as _s}from"./route-CzrZqZen.js";import"./index-BdQq_4o_.js";import"./index-D9-GACGG.js";import"./separator-CQ84aZ0V.js";import"./collapsible-BIxz44zB.js";import"./skeleton-ClxqB572.js";import"./switch-BHj3-8MN.js";import"./house-DjS1WMqx.js";import"./user-Cvsz7Lm_.js";import"./upload-BH1HltYO.js";import"./piggy-bank-DP-A2O0m.js";import"./landmark-C0TkBs1l.js";import"./flame-wMx8KIS8.js";import"./eye-DKrvAixa.js";import"./dialog-DrI7Oddz.js";import"./tabs-5EVsfllK.js";import"./textarea-4z16PwID.js";import"./mountain-BHfTfCFy.js";import"./index-Dh4i1-J3.js";/**
2 * @license lucide-react v0.462.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const Zt=ds("ChartLine",[["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"m19 9-5 5-4-4-3 3",key:"2osh9i"}]]),Ut={Mzdy:{cs:{title:"Mzdy",subtitle:"Mzdy a odvody správců domu"},de:{title:"Löhne",subtitle:"Löhne und Abgaben"},en:{title:"Wages",subtitle:"Wages and contributions"}},Voda:{cs:{title:"Voda",subtitle:"Náklady na pitnou vodu"},de:{title:"Wasser",subtitle:"Trinkwasserkosten"},en:{title:"Water",subtitle:"Drinking water costs"}},Cesty:{cs:{title:"Cesty",subtitle:"Zimní údržba a okolí domu"},de:{title:"Wege",subtitle:"Winterdienst und Außenanlagen"},en:{title:"Roads",subtitle:"Winter maintenance and surroundings"}},Bazén:{cs:{title:"Bazén",subtitle:"Provoz a údržba bazénu"},de:{title:"Pool",subtitle:"Poolbetrieb und Wartung"},en:{title:"Pool",subtitle:"Pool operation and maintenance"}},Výtah:{cs:{title:"Výtah",subtitle:"Servis a revize výtahu"},de:{title:"Aufzug",subtitle:"Aufzugservice und Wartung"},en:{title:"Elevator",subtitle:"Elevator service and maintenance"}},"Venkovní prostory":{cs:{title:"Venkovní prostory",subtitle:"Údržba zahrady a okolí"},de:{title:"Außenanlagen",subtitle:"Garten- und Umgebungspflege"},en:{title:"Outdoor Areas",subtitle:"Garden and surroundings maintenance"}},"Správa domu":{cs:{title:"Správa domu",subtitle:"Administrativní náklady"},de:{title:"Verwaltung",subtitle:"Verwaltungskosten"},en:{title:"Management",subtitle:"Administrative costs"}},Pojištění:{cs:{title:"Pojištění",subtitle:"Pojistné smlouvy budovy"},de:{title:"Versicherung",subtitle:"Gebäudeversicherungen"},en:{title:"Insurance",subtitle:"Building insurance policies"}},Poplatky:{cs:{title:"Poplatky",subtitle:"Daně a úřední poplatky"},de:{title:"Gebühren",subtitle:"Steuern und Abgaben"},en:{title:"Fees",subtitle:"Taxes and official fees"}},Energie:{cs:{title:"Energie",subtitle:"Elektřina a telekomunikace"},de:{title:"Energie",subtitle:"Strom und Telekommunikation"},en:{title:"Energy",subtitle:"Electricity and telecommunications"}},Údržba:{cs:{title:"Údržba",subtitle:"Běžné opravy a údržba"},de:{title:"Wartung",subtitle:"Laufende Reparaturen"},en:{title:"Maintenance",subtitle:"Regular repairs and upkeep"}}},Ms=({houseCosts:y,selectedCategory:T,currentYear:P,previousYear:ce,selectedYear:ee,onAreaClick:te,showHeader:t=!0,excludePersonnel:ge=!1})=>{const{language:N}=Et(),de=qt();b.useState("overview");const[K,X]=b.useState("change"),se=b.useMemo(()=>
6[...new Set(y.map(v=>v.year))].sort(),[y]),[le,Ne]=b.useState(null),[f,re]=b.useState(null),M=b.useMemo(()=>{let v=se;return ee!==void 0&&(v=v.filter(S=>S<=ee)),le!==null&&(v=v.filter(S=>S>=le)),f!==null&&(v=v.filter(S=>S<=f)),v},[se,le,f,ee]),ae=le!==null||f!==null,ke=()=>{Ne(null),re(null)},q=v=>new Intl.NumberFormat(N==="de"?"de-DE":"en-GB",{style:"currency",currency:"EUR",maximumFractionDigits:0}).format(v),xe=(v,S)=>{if(v==="Mzdy")return!0;const V=(v||"").toLowerCase(),Q=S.toLowerCase();return V.includes("löhne")||V.includes("lohne")||V.includes("lohn")||V.includes("sozialversicherung")||Q.includes("löhne")||Q.includes("lohne")||Q.includes("lohn")||Q.includes("sozialversicherung")},Ge=["Mzdy","Voda","Cesty"],G=b.useMemo(()=>{const v=T==="Fond_oprav";let S=y.filter(k=>v?k.is_repair_fund:k.category===T);ge&&(S=S.filter(k=>!xe(k.subcategory,k.description))),T==="Provozni_naklady"&&(S=S.filter(k=>!Ge.includes(k.subcategory||"")));const V=M.length>0?M:[...new Set(S.map(k=>k.year))].sort(),Q=V[0]||P,ie=V[V.length-1]||P,pe=V.length>1?V[V.length-2]:Q,B={};return S.forEach(k=>{if(!V.includes(k.year))return;const C=de.getAreaForSubcategory(k.subcategory,k.description);B[C]||(B[C]={current:0,previous:0,yearlyData:{}}),k.year===ie?B[C].current+=Number(k.amount):k.year===pe&&(B[C].previous+=Number(k.amount)),B[C].yearlyData[k.year]=(B[C].yearlyData[k.year]||0)+Number(k.amount)}),Object.entries(B).map(([k,C])=>{var L,Ze;const J=V.map($=>({year:$,value:C.yearlyData[$]||0})),ne=((L=J[0])==null?void 0:L.value)||0,Pe=((Ze=J[J.length-1])==null?void 0:Ze.value)||0,ue=J.length,Ae=ue>1&&ne>0?(Math.pow(Pe/ne,1/(ue-1))-1)*100:0,oe=de.getColorForCategory(k),wt=de.getTranslation(k,N);return{key:k,label:wt,current:C.current,previous:C.previous,change:ye(C.current,C.previous),firstYear:V[0]||P,lastYear:V[V.length-1]||P,firstValue:ne,lastValue:Pe,trendData:J,color:oe,cagr:Ae}}).filter(k=>k.current>0||k.previous>0).sort((k,C)=>C.change.percentage-k.change.percentage)},[y,T,P,ce,N,M,ge]),Ee=b.useMemo(()=>[...G].sort((v,S)=>{switch(K){case"change":return S.change.percentage-v.change.percentage;case"value":return S.lastValue-v.lastValue;case"alpha":return v.label.localeCompare(S.label);default:return 0}}),[G,K]);return e.jsxs(be,{children:[t&&e.jsxs(e.Fragment,{children:[e.jsxs(Ce,{className:"flex flex-row items-start justify-between space-y-0 pb-2",children:[e.jsxs("div",{children:[e.jsxs(Se,{className:"flex items-center gap-2",children:[e.jsx(Ie,{className:"h-5 w-5"}),N==="de"?"Trendanalyse nach Bereichen":N==="cs"?"Trendová analýza podle oblastí":"Trend Analysis by Area"]}),e.jsx(Me,{children:N==="de"?"Welche Bereiche wachsen und welche sinken?":N==="cs"?"Které oblasti rostou a které klesají?":"Which areas are growing and which are declining?"})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-sm text-muted-foreground",children:[e.jsx(It,{className:"h-4 w-4"}),e.jsx("span",{children:N==="de"?"Zeitraum:":N==="cs"?"Období:":"Period:"})]}),e.jsxs(Be,{value:(le==null?void 0:le.toString())||"all",onValueChange:v=>Ne(v==="all"?null:parseInt(v)),children:[e.jsx(He,{className:"w-20 h-8 text-xs",children:e.jsx(Oe,{placeholder:N==="cs"?"Od":N==="de"?"Von":"From"})}),e.jsxs(Ke,{children:[e.jsx(me,{value:"all",children:N==="cs"?"Vše":N==="de"?"Alle":"All"}),se.map(v=>e.jsx(me,{value:v.toString(),children:v},v))]})]}),e.jsx("span",{className:"text-muted-foreground",children:"→"}),e.jsxs(Be,{value:(f==null?void 0:f.toString())||"all",onValueChange:v=>re(v==="all"?null:parseInt(v)),children:[e.jsx(He,{className:"w-20 h-8 text-xs",children:e.jsx(Oe,{placeholder:N==="cs"?"Do":N==="de"?"Bis":"To"})}),e.jsxs(Ke,{children:[e.jsx(me,{value:"all",children:N==="cs"?"Vše":N==="de"?"Alle":"All"}),se.map(v=>e.jsx(me,{value:v.toString(),children:v},v))]})]}),ae&&e.jsx(he,{variant:"ghost",size:"sm",onClick:ke,className:"h-8 px-2 text-muted-foreground hover:text-destructive",children:e.jsx(Xt,{className:"h-4 w-4"})})]})]}),ae&&e.jsx("div",{className:"px-6 pb-2",children:e.jsxs(it,{variant:"secondary",className:"text-xs",children:[e.jsx(It,{className:"h-3 w-3 mr-1"}),le||se[0]," - ",f||se[se.length-1]," ","(",M.length," ",N==="cs"?"let":N==="de"?"Jahre":"years",")"]})})]}),e.jsx(je,{className:t?"":"pt-6",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4 text-xs text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"w-3 h-0.5 bg-destructive rounded"}),e.jsx("span",{children:N==="cs"?"Stoupá":N==="de"?"Steigend":"Rising"})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"w-3 h-0.5 bg-green-600 rounded"}),e.jsx("span",{children:N==="cs"?"Klesá":N==="de"?"Sinkend":"Falling"})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"w-3 h-0.5 bg-muted-foreground rounded"}),e.jsx("span",{children:N==="cs"?"Stabilní":N==="de"?"Stabil":"Stable"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ys,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsxs(Be,{value:K,onValueChange:v=>X(v),children:[e.jsx(He,{className:"h-8 w-[140px] text-xs",children:e.jsx(Oe,{})}),e.jsxs(Ke,{children:[e.jsx(me,{value:"change",children:N==="de"?"Nach Änderung":N==="cs"?"Podle změny":"By change"}),e.jsx(me,{value:"value",children:N==="de"?"Nach Wert":N==="cs"?"Podle hodnoty":"By value"}),e.jsx(me,{value:"alpha",children:N==="de"?"Alphabetisch":N==="cs"?"Abecedně":"Alphabetical"})]})]})]})]}),e.jsx("div",{className:"grid gap-4 grid-cols-1 sm:grid-cols-2 lg:grid-cols-3",children:Ee.map(v=>{var ie,pe,B,k;const S=v.change.percentage>2,V=v.change.percentage<-2,Q=S?"hsl(var(--destructive))":V?"#16a34a":"hsl(var(--muted-foreground))";
6return e.jsxs(be,{className:`cursor-pointer hover:shadow-lg transition-all bg-background ${S?"hover:border-destructive/50":V?"hover:border-green-500/50":"hover:border-primary/50"}`,onClick:()=>te==null?void 0:te(v.key),children:[e.jsx(Ce,{className:"pb-2 px-4 pt-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx(Se,{className:"text-base font-bold",children:((pe=(ie=Ut[v.key])==null?void 0:ie[N])==null?void 0:pe.title)||v.label}),e.jsx(Me,{className:"text-xs text-muted-foreground line-clamp-1",children:((k=(B=Ut[v.key])==null?void 0:B[N])==null?void 0:k.subtitle)||""})]}),e.jsx(Qt,{className:"h-4 w-4 text-muted-foreground ml-2"})]})}),e.jsxs(je,{className:"space-y-3 px-4 pb-4",children:[v.trendData.length>1&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"h-10 w-full",children:e.jsx(nt,{width:"100%",height:"100%",children:e.jsxs(kt,{data:v.trendData,margin:{top:4,right:4,left:4,bottom:4},children:[e.jsx(Te,{dataKey:"year",hide:!0}),e.jsx(Fe,{hide:!0,domain:["dataMin * 0.9","dataMax * 1.1"]}),e.jsx(ot,{type:"monotone",dataKey:"value",stroke:Q,strokeWidth:2,dot:C=>{const{cx:J,cy:ne,payload:Pe}=C;return Pe.year===v.lastYear?e.jsx("circle",{cx:J,cy:ne,r:4,fill:Q,stroke:"white",strokeWidth:2}):e.jsx("circle",{cx:0,cy:0,r:0})},activeDot:!1}),e.jsx(_e,{content:({active:C,payload:J})=>{if(C&&J&&J.length){const ne=J[0].payload;return e.jsxs("div",{className:"bg-popover border rounded-md px-2 py-1 text-xs shadow-md",children:[e.jsxs("span",{className:"font-medium",children:[ne.year,":"]})," ",q(ne.value)]})}return null}})]})})}),e.jsx("div",{className:"flex justify-between text-[10px] text-muted-foreground",children:v.trendData.map(C=>e.jsx("span",{className:C.year===v.lastYear?"text-foreground font-semibold":"",children:C.year},C.year))})]}),e.jsx("div",{className:"pt-2",children:e.jsxs("div",{className:"flex items-end justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xl font-bold",children:q(v.current)}),e.jsxs("div",{className:`flex items-center gap-1 text-sm ${S?"text-destructive":V?"text-green-600":"text-muted-foreground"}`,children:[S&&e.jsx(Ie,{className:"h-3.5 w-3.5"}),V&&e.jsx(Ye,{className:"h-3.5 w-3.5"}),e.jsxs("span",{className:"font-medium tabular-nums",children:[S?"+":"",v.change.percentage.toFixed(1),"%"]})]})]}),e.jsxs("div",{className:"flex flex-col items-end gap-1",children:[e.jsxs(it,{variant:"secondary",className:`text-[10px] font-medium ${S?"bg-destructive/10 text-destructive":V?"bg-green-500/10 text-green-600":"bg-muted text-muted-foreground"}`,children:[S&&e.jsx(Ie,{className:"h-2.5 w-2.5 mr-1"}),V&&e.jsx(Ye,{className:"h-2.5 w-2.5 mr-1"}),S?N==="de"?"Gestiegen":N==="cs"?"Náklady vzrostly":"Increased":V?N==="de"?"Gesunken":N==="cs"?"Náklady klesly":"Decreased":N==="de"?"Stabil":N==="cs"?"Stabilní":"Stable"]}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[N==="cs"?"oproti":"vs"," ",ce,": ",q(v.previous)]})]})]})})]})]},v.key)})})]})})]})},_t={showSourceColumn:!0,autoImportAfterExtraction:!1};function Is(){const[y,T]=b.useState(_t),[P,ce]=b.useState(!0);b.useEffect(()=>{ee()},[]);const ee=async()=>{const{data:te,error:t}=await lt.from("forum_settings").select("value").eq("key","cost_display_settings").single();if(te&&!t){const ge=te.value;T({showSourceColumn:ge.showSourceColumn??_t.showSourceColumn,autoImportAfterExtraction:ge.autoImportAfterExtraction??_t.autoImportAfterExtraction})}ce(!1)};return{settings:y,isLoading:P}}const Es=(y,T=1)=>{if(!y)return y;const P=y.split(" ");return P.length<=T?y:P.slice(0,T).join(" ")+"..."},ft=(y,T)=>{if(!y||T==="de")return y;const P=Nt(y,T);return P!==y?P:Mt(y,T)},Jt=({payload:y,translateFn:T})=>y?e.jsx("div",{className:"flex flex-wrap justify-center gap-x-3 gap-y-1 text-xs mt-2",children:y.map((P,ce)=>{const ee=T(P.value),te=Es(ee,1);return e.jsx(vt,{children:e.jsxs(yt,{children:[e.jsx(bt,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-1.5 cursor-help",children:[e.jsx("div",{className:"w-3 h-3 rounded-sm flex-shrink-0",style:{backgroundColor:P.color}}),e.jsx("span",{className:"text-muted-foreground",children:te})]})}),e.jsx(jt,{side:"top",className:"max-w-xs",children:e.jsx("p",{className:"text-sm",children:ee})})]})},`legend-${ce}`)})}):null,Ps={Mzdy:e.jsx(Ss,{className:"h-5 w-5"}),Facility:e.jsx(zs,{className:"h-5 w-5"}),Energie:e.jsx(Ds,{className:"h-5 w-5"}),Poplatky:e.jsx(Vs,{className:"h-5 w-5"}),Údržba:e.jsx(Ts,{className:"h-5 w-5"}),"Správa & Pojištění":e.jsx(bs,{className:"h-5 w-5"}),Ostatní:e.jsx(es,{className:"h-5 w-5"}),Voda:e.jsx(Fs,{className:"h-5 w-5"}),Cesty:e.jsx(_s,{className:"h-5 w-5"})},As=({houseCosts:y,heatingCosts:T=[],selectedYear:P,onYearChange:ce,onBreadcrumbsChange:ee,resetTrigger:te})=>{const{language:t}=Et(),ge=us(),{settings:N}=Is(),de=qt(),[K,X]=b.useState("overview"),se=(s,i)=>de.getAreaForSubcategory(s,i),le=s=>de.getColorForCategory(s),Ne=(s,i)=>de.getTranslation(s,i),[f,re]=b.useState(null),[M,ae]=b.useState(null),[ke,q]=b.useState(null),[xe,Ge]=b.useState({}),[G,Ee]=b.useState(null),[v,S]=b.useState(!1),[V,Q]=b.useState(new Set);b.useEffect(()=>{te!==void 0&&te>0&&(X("overview"),re(null),ae(null),q(null),Q(new Set))},[te]);const[ie,pe]=b.useState(""),[B,k]=b.useState(""),[C,J]=b.useState(""),[ne,Pe]=b.useState(!1);b.useState(null),b.useState("line");const[ue,Ae]=b.useState("bar"),[oe,wt]=b.useState(!1),[L,Ze]=b.useState(null),[$,Pt]=b.useState(null),we=[...new Set(y.map(s=>s.year))].sort(),D=P==="all"?Math.max(...we):parseInt(P),F=D-1,ts=()=>{oe||(Ze(we[we.length-1]||D),Pt(we[we.length-2]||F)),wt(!oe)},I=s=>new Intl.NumberFormat(t==="de"?"de-DE":"en-GB",{style:"currency",currency:"EUR",maximumFractionDigits:0}).format(s),ss=s=>s?new Date(s).toLocaleDateString(t==="de"?"de-DE":"en-GB",{day:"2-digit",month:"2-digit",year:"numeric"}):"-",At=s=>s.toLowerCase().normalize("NFD").replace(new RegExp("\\p{Diacritic}","gu"),"");b.useEffect(()=>{if(K==="area"&&f&&M){const s=f==="Fond_oprav",i=f==="Mzdy",a=f==="Voda",c=f==="Cesty",p=y.filter(l=>{if(!(l.year===D))return!1;if(i)return l.category==="Mzdy"||l.subcategory==="Mzdy";if(a)return l.category==="Voda"||l.subcategory==="Voda";if(c)return l.category==="Cesty"||l.subcategory==="Cesty";if(s)return l.is_repair_fund;const o=l.category===f,d=se(l.subcategory)===M;return o&&d}).filter(l=>
6!xe[l.id]).map(l=>l.id);p.length>0&&(async()=>{S(!0);const{data:r,error:o}=await lt.from("house_cost_items").select(`
7              *,
8              pdf_document:pdf_documents!source_document_id(file_name)
9            `).in("house_cost_id",p).order("item_date",{ascending:!1});if(!o&&r){const d={};p.forEach(g=>{d[g]=[]}),r.forEach(g=>{d[g.house_cost_id]||(d[g.house_cost_id]=[]),d[g.house_cost_id].push(g)}),Ge(g=>({...g,...d}))}S(!1)})()}},[K,f,M,D,y]);const rs=s=>{Q(i=>{const a=new Set(i);return a.has(s)?a.delete(s):a.add(s),a})},as=()=>{const s=[];if(Re.forEach(r=>{r.items.forEach(o=>{s.push({subcategory:r.label,date:o.item_date||"",invoice:o.invoice_number||"",vendor:o.vendor||"",description:o.description,descriptionEN:Nt(o.description,"en"),descriptionCS:Nt(o.description,"cs"),amount:o.amount})})}),s.length===0){Ot.error(t==="cs"?"Žádná data k exportu":t==="de"?"Keine Daten zum Exportieren":"No data to export");return}const c="\uFEFF"+[["Kategorie","Datum","Rechnung","Lieferant","Beschreibung","EN Preklad","CZ preklad","Betrag"].join(";"),...s.map(r=>[`"${r.subcategory}"`,r.date,`"${r.invoice}"`,`"${r.vendor}"`,`"${r.description.replace(/"/g,'""')}"`,`"${r.descriptionEN.replace(/"/g,'""')}"`,`"${r.descriptionCS.replace(/"/g,'""')}"`,r.amount.toFixed(2).replace(".",",")].join(";"))].join(`
10`),m=new Blob([c],{type:"text/csv;charset=utf-8;"}),p=URL.createObjectURL(m),l=document.createElement("a");l.setAttribute("href",p),l.setAttribute("download",`kosten_${M||"detail"}_${D}.csv`),document.body.appendChild(l),l.click(),document.body.removeChild(l),URL.revokeObjectURL(p),Ot.success(t==="cs"?"CSV exportováno":t==="de"?"CSV exportiert":"CSV exported")};b.useMemo(()=>{const s=new Set;return Object.values(xe).forEach(i=>{i.forEach(a=>{a.vendor&&s.add(a.vendor)})}),Array.from(s).sort()},[xe]);const Le={Mzdy:{cs:{title:"Domovník",subtitle:"Mzdy a odvody domovníků"},de:{title:"Hausmeister",subtitle:"Löhne und Abgaben der Hausbesorger"},en:{title:"Caretaker",subtitle:"Caretaker wages and contributions"}},Provozni_naklady:{cs:{title:"Provozní náklady",subtitle:"Běžné náklady na provoz budovy"},de:{title:"Betriebskosten",subtitle:"Laufende Gebäudebetriebskosten"},en:{title:"Operating Costs",subtitle:"Regular building operating costs"}},Fond_oprav:{cs:{title:"Fond oprav",subtitle:"Rezervy na větší opravy a údržbu"},de:{title:"Reparaturfonds",subtitle:"Rücklagen für größere Reparaturen"},en:{title:"Repair Fund",subtitle:"Reserves for major repairs and maintenance"}},Vytapeni:{cs:{title:"Vytápění a TV",subtitle:"Topení a teplá voda"},de:{title:"Heizung & WW",subtitle:"Heizung und Warmwasser"},en:{title:"Heating & HW",subtitle:"Heating and hot water"}},Voda:{cs:{title:"Voda",subtitle:"Náklady na pitnou vodu"},de:{title:"Wasser",subtitle:"Trinkwasserkosten"},en:{title:"Water",subtitle:"Drinking water costs"}},Cesty:{cs:{title:"Cesty",subtitle:"Zimní údržba a okolí domu"},de:{title:"Wege",subtitle:"Winterdienst und Außenanlagen"},en:{title:"Roads",subtitle:"Winter maintenance and surroundings"}}},ct={Mzdy:{cs:{title:"Mzdy",subtitle:"Mzdy a odvody správců domu"},de:{title:"Löhne",subtitle:"Löhne und Abgaben der Hausbesorger"},en:{title:"Wages",subtitle:"Caretaker wages and contributions"}},Voda:{cs:{title:"Voda",subtitle:"Náklady na pitnou vodu"},de:{title:"Wasser",subtitle:"Trinkwasserkosten"},en:{title:"Water",subtitle:"Drinking water costs"}},Cesty:{cs:{title:"Cesty",subtitle:"Zimní údržba a okolí domu"},de:{title:"Wege",subtitle:"Winterdienst und Außenanlagen"},en:{title:"Roads",subtitle:"Winter maintenance and surroundings"}},"Fond oprav":{cs:{title:"Fond oprav",subtitle:"Investice a větší opravy"},de:{title:"Reparaturfonds",subtitle:"Investitionen und größere Reparaturen"},en:{title:"Repair Fund",subtitle:"Investments and major repairs"}},Bazén:{cs:{title:"Bazén",subtitle:"Provoz a údržba bazénu"},de:{title:"Hallenbad",subtitle:"Hallenbad Betrieb und Wartung"},en:{title:"Pool",subtitle:"Pool operation and maintenance"}},Výtah:{cs:{title:"Výtah",subtitle:"Servis a revize výtahu"},de:{title:"Aufzug",subtitle:"Aufzugservice und Wartung"},en:{title:"Elevator",subtitle:"Elevator service and maintenance"}},"Venkovní prostory":{cs:{title:"Venkovní prostory",subtitle:"Údržba zahrady a okolí"},de:{title:"Außenanlagen",subtitle:"Garten- und Umgebungspflege"},en:{title:"Outdoor Areas",subtitle:"Garden and surroundings maintenance"}},"Správa domu":{cs:{title:"Správa domu",subtitle:"Administrativní náklady"},de:{title:"Verwaltung",subtitle:"Verwaltungskosten"},en:{title:"Management",subtitle:"Administrative costs"}},Pojištění:{cs:{title:"Pojištění",subtitle:"Pojistné smlouvy budovy"},de:{title:"Versicherung",subtitle:"Gebäudeversicherungen"},en:{title:"Insurance",subtitle:"Building insurance policies"}},Poplatky:{cs:{title:"Poplatky",subtitle:"Daně a úřední poplatky"},de:{title:"Gebühren",subtitle:"Steuern und Abgaben"},en:{title:"Fees",subtitle:"Taxes and official fees"}},Energie:{cs:{title:"Energie",subtitle:"Elektřina a telekomunikace"},de:{title:"Energie",subtitle:"Strom und Telekommunikation"},en:{title:"Energy",subtitle:"Electricity and telecommunications"}},Údržba:{cs:{title:"Údržba",subtitle:"Běžné opravy a údržba"},de:{title:"Wartung",subtitle:"Laufende Reparaturen"},en:{title:"Maintenance",subtitle:"Regular repairs and upkeep"}}},Ue=b.useMemo(()=>{var R,A,Z,U,We,mt,De,fe,gt,xt,Ve,ve,Xe,qe,Qe,et,tt;const s=["Fond_oprav","Fond Oprav"],i={Provozni_naklady:{cs:"Provozní náklady",de:"Betriebskosten",en:"Operating Costs"},"Provozní náklady":{cs:"Provozní náklady",de:"Betriebskosten",en:"Operating Costs"},Mzdy:{cs:"Domovník",de:"Hausmeister",en:"Caretaker"},Domovník:{cs:"Domovník",de:"Hausmeister",en:"Caretaker"},Voda:{cs:"Voda",de:"Wasser",en:"Water"},Cesty:{cs:"Cesty",de:"Wege",en:"Roads"},Fond_oprav:{cs:"Fond oprav",de:"Reparaturfonds",en:"Repair Fund"},"Fond Oprav":{cs:"Fond oprav",de:"Reparaturfonds",en:"Repair Fund"},Vytapeni:{cs:"Vytápění a TV",de:"Heizung & WW",en:"Heating & HW"},"Vytápění a TV":{cs:"Vytápění a TV",de:"Heizung & WW",en:"Heating & HW"}},a=[...new Set(y.map(j=>j.year))].sort(),c=[...new Set(T.map(j=>j.year))].sort(),m=[...new Set([...a,...c])].sort(),p=j=>j.category==="Voda"||j.subcategory==="Voda",l=j=>j.category==="Cesty"||j.subcategory==="Cesty",r=j=>j.category==="Mzdy"||j.category==="Domovník"||j.subcategory==="Mzdy"||j.subcategory==="Domovník",o=[],d=y.filter(r);if(d.length>0){const j=d.filter(u=>u.year===D).reduce((u,W)=>u+Number(W.amount),0),E=d.filter(u=>u.year===F).reduce((u,W)=>u+Number(W.amount),0),Y=ye(j,E),n={};d.forEach(u=>{n[u.year]=(n[u.year]||0)+Number(u.amount)});const x=a.map(u=>({year:u,value:n[u]||0})),_=((R=x[0])==null?void 0:R.value)||0,O=((A=x[x.length-1])==null?void 0:A.value)||0,z=_>0?(O-_)/_*100:0;(j>0||E>0)&&o.push({key:"Mzdy",label:((Z=i.Mzdy)==null?void 0:Z[t])||"Caretaker",current:j,previous:E,change:Y,itemCount:d.filter(u=>u.year===D).length,trendData:x,overallTrend:z,trendDirection:z>5?"up":z<-5?"down":"neutral",hasHighIncrease:Y.percentage>20,isHeating:!1,isVoda:!1,isCesty:!1,isPersonal:!0})}const g=y.filter(p);if(g.length>0){const j=g.filter(u=>u.year===D).reduce((u,W)=>u+Number(W.amount),0),E=g.filter(u=>u.year===F).reduce((u,W)=>u+Number(W.amount),0),Y=ye(j,E),n={};g.forEach(u=>{n[u.year]=(n[u.year]||0)+Number(u.amount)});const x=a.map(u=>({year:u,value:n[u]||0})),_=((U=x[0])==null?void 0:U.value)||0,O=((We=x[x.length-1])==null?void 0:We.value)||0,z=_>0?(O-_)/_*100:0;(j>0||E>0)&&o.push({key:"Voda",label:((mt=i.Voda)==null?void 0:mt[t])||"Voda",current:j,previous:E,change:Y,itemCount:g.filter(u=>u.year===D).length,trendData:x,overallTrend:z,trendDirection:z>5?"up":z<-5?"down":"neutral",hasHighIncrease:Y.percentage>20,isHeating:!1,isVoda:!0,isCesty:!1,isPersonal:!1})}const h=y.filter(l);if(h.length>0){const j=h.filter(u=>u.year===D).reduce((u,W)=>u+Number(W.amount),0),E=h.filter(u=>u.year===F).reduce((u,W)=>u+Number(W.amount),0),Y=ye(j,E),n={};h.forEach(u=>{n[u.year]=(n[u.year]||0)+Number(u.amount)});const x=a.map(u=>({year:u,value:n[u]||0})),_=((De=x[0])==null?void 0:De.value)||0,O=((fe=x[x.length-1])==null?void 0:fe.value)||0,z=_>0?(O-_)/_*100:0;(j>0||E>0)&&o.push({key:"Cesty",label:((gt=i.Cesty)==null?void 0:gt[t])||"Cesty",current:j,previous:E,change:Y,itemCount:h.filter(u=>u.year===D).length,trendData:x,overallTrend:z,trendDirection:z>5?"up":z<-5?"down":"neutral",hasHighIncrease:Y.percentage>20,isHeating:!1,isVoda:!1,isCesty:!0,isPersonal:!1})}const w=y.filter(j=>(j.category==="Provozni_naklady"||j.category==="Provozní náklady")&&!r(j)&&!p(j)&&!l(j));if(w.length>0){const j=w.filter(u=>u.year===D).reduce((u,W)=>u+Number(W.amount),0),E=w.filter(u=>u.year===F).reduce((u,W)=>u+Number(W.amount),0),Y=ye(j,E),n={};
10w.forEach(u=>{n[u.year]=(n[u.year]||0)+Number(u.amount)});const x=a.map(u=>({year:u,value:n[u]||0})),_=((xt=x[0])==null?void 0:xt.value)||0,O=((Ve=x[x.length-1])==null?void 0:Ve.value)||0,z=_>0?(O-_)/_*100:0;(j>0||E>0)&&o.push({key:"Provozni_naklady",label:((ve=i.Provozni_naklady)==null?void 0:ve[t])||"Provozní náklady",current:j,previous:E,change:Y,itemCount:w.filter(u=>u.year===D).length,trendData:x,overallTrend:z,trendDirection:z>5?"up":z<-5?"down":"neutral",hasHighIncrease:Y.percentage>20,isHeating:!1,isVoda:!1,isCesty:!1,isPersonal:!1})}if(s.forEach(j=>{var Rt,Wt,Yt;const E=H=>j==="Fond_oprav"||j==="Fond Oprav"?H.is_repair_fund:H.category===j,Y=y.filter(H=>H.year===D&&E(H)),n=y.filter(H=>H.year===F&&E(H)),x=Y.reduce((H,Dt)=>H+Number(Dt.amount),0),_=n.reduce((H,Dt)=>H+Number(Dt.amount),0),O=ye(x,_),z={};y.filter(E).forEach(H=>{z[H.year]=(z[H.year]||0)+Number(H.amount)});const u=a.map(H=>({year:H,value:z[H]||0})),W=((Rt=u[0])==null?void 0:Rt.value)||0,cs=((Wt=u[u.length-1])==null?void 0:Wt.value)||0,zt=W>0?(cs-W)/W*100:0;(x>0||_>0)&&o.push({key:j,label:((Yt=i[j])==null?void 0:Yt[t])||j,current:x,previous:_,change:O,itemCount:Y.length,trendData:u,overallTrend:zt,trendDirection:zt>5?"up":zt<-5?"down":"neutral",hasHighIncrease:O.percentage>20,isHeating:!1,isVoda:!1,isCesty:!1,isPersonal:!1})}),T.length>0){const j=((Xe=T.find(z=>z.year===D))==null?void 0:Xe.total)||0,E=((qe=T.find(z=>z.year===F))==null?void 0:qe.total)||0,Y=ye(j,E),n=m.map(z=>{var u;return{year:z,value:((u=T.find(W=>W.year===z))==null?void 0:u.total)||0}}),x=((Qe=n[0])==null?void 0:Qe.value)||0,_=((et=n[n.length-1])==null?void 0:et.value)||0,O=x>0?(_-x)/x*100:0;(j>0||E>0)&&o.push({key:"Vytapeni",label:((tt=i.Vytapeni)==null?void 0:tt[t])||"Heating",current:j,previous:E,change:Y,itemCount:0,trendData:n,overallTrend:O,trendDirection:O>5?"up":O<-5?"down":"neutral",hasHighIncrease:Y.percentage>20,isHeating:!0,isVoda:!1,isCesty:!1,isPersonal:!1})}return o},[y,T,D,F,t]),Lt=b.useMemo(()=>Ue.filter(s=>s.change.percentage>20),[Ue]),$e=b.useMemo(()=>{var Xe,qe,Qe,et,tt,j,E,Y;if(!oe||!L||!$)return[];const s={Provozni_naklady:{de:"Betriebskosten",en:"Operating Costs",cs:"Provozní náklady"},Mzdy:{de:"Löhne",en:"Wages",cs:"Mzdy"},Voda:{de:"Wasser",en:"Water",cs:"Voda"},Cesty:{de:"Wege",en:"Roads",cs:"Cesty"},Fond_oprav:{de:"Reparaturfonds",en:"Repair Fund",cs:"Fond oprav"},Vytapeni:{de:"Heizung & Warmwasser",en:"Heating & Hot Water",cs:"Vytápění a teplá voda"}},i=n=>n.category==="Voda"||n.subcategory==="Voda",a=n=>n.category==="Cesty"||n.subcategory==="Cesty",c=n=>n.category==="Mzdy"||n.subcategory==="Mzdy",m=[],p=y.filter(n=>n.year===L&&n.category==="Provozni_naklady"&&!c(n)&&!i(n)&&!a(n)),l=y.filter(n=>n.year===$&&n.category==="Provozni_naklady"&&!c(n)&&!i(n)&&!a(n)),r=p.reduce((n,x)=>n+Number(x.amount),0),o=l.reduce((n,x)=>n+Number(x.amount),0);if(r>0||o>0){const n=r-o,x=o>0?(r-o)/o*100:0;m.push({key:"Provozni_naklady",label:((Xe=s.Provozni_naklady)==null?void 0:Xe[t])||"Operating Costs",year1:r,year2:o,difference:n,percentChange:x,direction:n>0?"up":n<0?"down":"neutral"})}const d=y.filter(n=>n.year===L&&c(n)),g=y.filter(n=>n.year===$&&c(n)),h=d.reduce((n,x)=>n+Number(x.amount),0),w=g.reduce((n,x)=>n+Number(x.amount),0);if(h>0||w>0){const n=h-w,x=w>0?(h-w)/w*100:0;m.push({key:"Mzdy",label:((qe=s.Mzdy)==null?void 0:qe[t])||"Wages",year1:h,year2:w,difference:n,percentChange:x,direction:n>0?"up":n<0?"down":"neutral"})}const R=y.filter(n=>n.year===L&&n.is_repair_fund),A=y.filter(n=>n.year===$&&n.is_repair_fund),Z=R.reduce((n,x)=>n+Number(x.amount),0),U=A.reduce((n,x)=>n+Number(x.amount),0);if(Z>0||U>0){const n=Z-U,x=U>0?(Z-U)/U*100:0;m.push({key:"Fond_oprav",label:((Qe=s.Fond_oprav)==null?void 0:Qe[t])||"Repair Fund",year1:Z,year2:U,difference:n,percentChange:x,direction:n>0?"up":n<0?"down":"neutral"})}const We=y.filter(n=>n.year===L&&i(n)),mt=y.filter(n=>n.year===$&&i(n)),De=We.reduce((n,x)=>n+Number(x.amount),0),fe=mt.reduce((n,x)=>n+Number(x.amount),0);if(De>0||fe>0){const n=De-fe,x=fe>0?(De-fe)/fe*100:0;m.splice(1,0,{key:"Voda",label:((et=s.Voda)==null?void 0:et[t])||"Water",year1:De,year2:fe,difference:n,percentChange:x,direction:n>0?"up":n<0?"down":"neutral"})}const gt=y.filter(n=>n.year===L&&a(n)),xt=y.filter(n=>n.year===$&&a(n)),Ve=gt.reduce((n,x)=>n+Number(x.amount),0),ve=xt.reduce((n,x)=>n+Number(x.amount),0);if(Ve>0||ve>0){const n=Ve-ve,x=ve>0?(Ve-ve)/ve*100:0,_=m.findIndex(z=>z.key==="Voda"),O=_>=0?_+1:1;m.splice(O,0,{key:"Cesty",label:((tt=s.Cesty)==null?void 0:tt[t])||"Roads",year1:Ve,year2:ve,difference:n,percentChange:x,direction:n>0?"up":n<0?"down":"neutral"})}if(T.length>0){const n=((j=T.find(z=>z.year===L))==null?void 0:j.total)||0,x=((E=T.find(z=>z.year===$))==null?void 0:E.total)||0,_=n-x,O=x>0?(n-x)/x*100:0;(n>0||x>0)&&m.push({key:"Vytapeni",label:((Y=s.Vytapeni)==null?void 0:Y[t])||"Heating",year1:n,year2:x,difference:_,percentChange:O,direction:_>0?"up":_<0?"down":"neutral"})}return m},[oe,L,$,y,T,t]),dt=b.useMemo(()=>
10{if(!f)return[];const s=f==="Fond_oprav",i=f==="Mzdy",a=f==="Voda",c=f==="Cesty",m=y.filter(r=>i?r.category==="Mzdy"||r.subcategory==="Mzdy":a?r.category==="Voda"||r.subcategory==="Voda":c?r.category==="Cesty"||r.subcategory==="Cesty":f==="Provozni_naklady"?r.category==="Provozni_naklady"&&!["Mzdy","Voda","Cesty"].includes(r.subcategory||""):s?r.is_repair_fund:r.category===f),p=[...new Set(m.map(r=>r.year))].sort(),l={};return m.forEach(r=>{const o=se(r.subcategory,r.description);l[o]||(l[o]={current:0,previous:0,subcategories:new Set,yearlyData:{}}),r.year===D?l[o].current+=Number(r.amount):r.year===F&&(l[o].previous+=Number(r.amount)),l[o].yearlyData[r.year]=(l[o].yearlyData[r.year]||0)+Number(r.amount);const d=r.subcategory||r.description;d&&l[o].subcategories.add(d)}),Object.entries(l).map(([r,o])=>{var R,A;const d=p.map(Z=>({year:Z,value:o.yearlyData[Z]||0})),g=((R=d[0])==null?void 0:R.value)||0,h=((A=d[d.length-1])==null?void 0:A.value)||0,w=g>0?(h-g)/g*100:0;return{key:r,label:Ne(r,t),current:o.current,previous:o.previous,change:ye(o.current,o.previous),subcategoryCount:o.subcategories.size,color:le(r),icon:Ps[r]||e.jsx(es,{className:"h-5 w-5"}),trendData:d,overallTrend:w,trendDirection:w>5?"up":w<-5?"down":"neutral"}}).filter(r=>r.current>0||r.previous>0).sort((r,o)=>o.current-r.current)},[y,f,D,F,t]);b.useMemo(()=>{var i,a;return dt.length===0?[]:(((a=(i=dt[0])==null?void 0:i.trendData)==null?void 0:a.map(c=>c.year))||[]).map(c=>{const m={year:c};return dt.forEach(p=>{const l=p.trendData.find(r=>r.year===c);m[p.key]=(l==null?void 0:l.value)||0}),m})},[dt]);const Re=b.useMemo(()=>{if(!f||!M)return[];const s=f==="Fond_oprav",i=f==="Mzdy",a=f==="Voda",c=f==="Cesty",m=y.filter(r=>{if(i)return(r.category==="Mzdy"||r.subcategory==="Mzdy")&&!0;if(a)return r.category==="Voda"||r.subcategory==="Voda";if(c)return r.category==="Cesty"||r.subcategory==="Cesty";if(f==="Provozni_naklady"&&["Mzdy","Voda","Cesty"].includes(r.category||""))return!1;if(s)return r.is_repair_fund;const o=r.category===f,d=se(r.subcategory,r.description)===M;return o&&d}),p={},l=r=>
10{if(s)return r.description||"Bez kategorie";if(i){const o=r.subcategory||"",d=r.description||"",g=At(o+" "+d);return o==="Lohnabgaben"||g.includes("lohnabgaben")?"Lohnabgaben":g.includes("sozialversicherung")?"Sozialversicherung":o==="Hausbesorger"||g.includes("hausbesorger")?"Hausbesorger":g.includes("lohne")||g.includes("lohn")||g.includes("gehalt")||g.includes("mzdy")||g==="mzdy"||o==="Mzdy"||o==="Löhne"?"Löhne":o||d||"Bez kategorie"}return r.subcategory||r.description||"Bez kategorie"};return m.forEach(r=>{const o=l(r);p[o]||(p[o]={current:0,previous:0,houseCosts:[],allItems:[]}),r.year===D?(p[o].current+=Number(r.amount),p[o].houseCosts.push(r),xe[r.id]&&p[o].allItems.push(...xe[r.id])):r.year===F&&(p[o].previous+=Number(r.amount))}),Object.entries(p).map(([r,o])=>{let d=o.allItems;return ie&&(d=d.filter(g=>{var h;return(h=g.vendor)==null?void 0:h.toLowerCase().includes(ie.toLowerCase())})),B&&(d=d.filter(g=>g.item_date&&g.item_date>=B)),C&&(d=d.filter(g=>g.item_date&&g.item_date<=C)),{key:r,label:Mt(r,t),current:o.current,previous:o.previous,change:ye(o.current,o.previous),houseCosts:o.houseCosts,items:d.sort((g,h)=>!g.item_date&&!h.item_date?0:g.item_date?h.item_date?new Date(h.item_date).getTime()-new Date(g.item_date).getTime():-1:1),totalItems:o.allItems.length}}).filter(r=>s?r.current>0:r.current>0||r.previous>0||r.totalItems>0).filter(r=>!(r.current===0&&r.previous===0&&r.totalItems===0)).sort((r,o)=>o.current-r.current)},[y,f,M,D,F,xe,ie,B,C]),Je=b.useMemo(()=>{if(!f||!M)return[];const s=f==="Fond_oprav",i=f==="Mzdy",a=f==="Voda",c=f==="Cesty",m=y.filter(r=>{if(i)return r.category==="Mzdy"||r.subcategory==="Mzdy";if(a)return r.category==="Voda"||r.subcategory==="Voda";if(c)return r.category==="Cesty"||r.subcategory==="Cesty";if(s)return r.is_repair_fund;const o=r.category===f,d=se(r.subcategory,r.description)===M;return o&&d}),p=[...new Set(m.map(r=>r.year))].sort(),l=[...new Set(m.map(r=>s?r.description||"Ostatní":r.subcategory||r.description||"Ostatní"))];return p.map((r,o)=>{const d={year:r,total:0,prevTotal:0};let g=0;if(l.forEach(h=>{const R=m.filter(A=>A.year!==r?!1:s?A.description===h:A.subcategory===h||!A.subcategory&&A.description===h).reduce((A,Z)=>A+Number(Z.amount),0);if(d[h]=R,g+=R,o>0){const A=p[o-1],Z=m.filter(U=>U.year!==A?!1:s?U.description===h:U.subcategory===h||!U.subcategory&&U.description===h);d[`${h}_prev`]=Z.reduce((U,We)=>U+Number(We.amount),0)}}),d.total=g,o>0){const h=p[o-1],w=m.filter(R=>R.year===h);d.prevTotal=w.reduce((R,A)=>R+Number(A.amount),0)}return d.changePercent=d.prevTotal>0?(d.total-d.prevTotal)/d.prevTotal*100:0,d})},[y,f,M]),Ct=b.useMemo(()=>{if(Je.length===0)return[];const s={};return Je.forEach(i=>{Object.entries(i).forEach(([a,c])=>{a!=="year"&&a!=="total"&&a!=="prevTotal"&&a!=="changePercent"&&!a.endsWith("_prev")&&(s[a]=(s[a]||0)+(Number(c)||0))})}),Object.entries(s).filter(([i,a])=>a>0).map(([i])=>i)},[Je]),ze=b.useMemo(()=>{if(f!=="Mzdy")return[];const s=y.filter(a=>a.category==="Mzdy"||a.subcategory==="Mzdy");return[...new Set(s.map(a=>a.year))].sort().map(a=>{const c=s.filter(l=>l.year===a);let m=0,p=0;return c.forEach(l=>{At(l.subcategory||l.description||"").includes("sozialversicherung")?p+=Number(l.amount):m+=Number(l.amount)}),{year:a,wages:m,socialInsurance:p,total:m+p}})},[y,f]);b.useMemo(()=>{const s=["#16a34a","#71717a","#3b82f6","#f59e0b","#ef4444","#8b5cf6"];return Re.map(a=>a.key).reduce((a,c,m)=>(a[c]=s[m%s.length],a),{})},[Re]);const ut=ie||B||C,ns=()=>{pe(""),k(""),J("")},$t=b.useMemo(()=>{const s=[{level:"overview",label:t==="cs"?"Přehled":t==="de"?"Übersicht":"Overview"}];if(f){const i=Ue.find(m=>m.key===f),a=(i==null?void 0:i.label)||f;["Mzdy","Voda","Cesty","Fond_oprav"].includes(f)||s.push({level:"category",label:a,value:f})}return M&&s.push({level:"area",label:Ne(M,t),value:M}),ke&&s.push({level:"subcategory",label:ke,value:ke}),s},[K,f,M,ke,Ue,t]);b.useEffect(()=>{if(ee){const s=$t.filter(i=>i.level!=="overview").map((i,a,c)=>{var l,r,o,d,g,h,w,R,A;let m,p;if(i.level==="category"&&i.value)m=(r=(l=Le[i.value])==null?void 0:l[t])==null?void 0:r.title,p=(d=(o=Le[i.value])==null?void 0:o[t])==null?void 0:d.subtitle;else if(i.level==="area"&&i.value){if((g=ct[i.value])!=null&&g[t])m=ct[i.value][t].title,p=ct[i.value][t].subtitle;else if(["Mzdy","Voda","Cesty","Fond_oprav"].includes(f)){const Z=f;m=(w=(h=Le[Z])==null?void 0:h[t])==null?void 0:w.title,p=(A=(R=Le[Z])==null?void 0:R[t])==null?void 0:A.subtitle}}return{label:i.label,onClick:a<c.length-1?()=>os(i):void 0,title:m,subtitle:p}});ee(s)}},[$t,ee,t,f,ct]);const os=s=>{switch(s.level){case"overview":X("overview"),re(null),ae(null),q(null),Q(new Set);break;case"category":X("category"),ae(null),q(null),Q(new Set);break;case"area":X("area"),q(null);break}},ls=(s,i)=>{if(s==="Vytapeni"||i){ge("/owners/costs/heating");return}
10if(s==="Voda"){re("Voda"),ae("Voda"),X("area");return}if(s==="Cesty"){re("Cesty"),ae("Cesty"),X("area");return}if(s==="Mzdy"){re("Mzdy"),ae("Mzdy"),X("area");return}if(s==="Fond_oprav"){re("Fond_oprav"),ae("Fond oprav"),X("area");return}re(s),X("category")},is=s=>{ae(s),X("area")},St=({change:s,showTooltip:i=!1,previousValue:a,previousYear:c})=>{const m=s.direction==="up"?Ie:s.direction==="down"?Ye:ht,p=e.jsxs("div",{className:`flex items-center gap-1 ${Kt(s.direction)}`,children:[e.jsx(m,{className:"h-4 w-4"}),e.jsxs("span",{className:"text-sm font-medium",children:[s.percentage>0?"+":"",s.percentage.toFixed(1),"%"]})]});if(i&&c!==void 0){const l=t==="cs"?`Změna oproti roku ${c}${a!==void 0?`: ${I(a)}`:""}`:t==="de"?`Veränderung gegenüber ${c}${a!==void 0?`: ${I(a)}`:""}`:`Change compared to ${c}${a!==void 0?`: ${I(a)}`:""}`;return e.jsx(vt,{children:e.jsxs(yt,{children:[e.jsx(bt,{asChild:!0,children:p}),e.jsx(jt,{children:e.jsx("p",{children:l})})]})})}return p};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[e.jsx("div",{className:"flex items-center gap-4",children:oe?e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:t==="cs"?"Rok 1:":t==="de"?"Jahr 1:":"Year 1:"}),e.jsxs(Be,{value:(L==null?void 0:L.toString())||"",onValueChange:s=>Ze(parseInt(s)),children:[e.jsx(He,{className:"w-24 h-9",children:e.jsx(Oe,{})}),e.jsx(Ke,{children:we.map(s=>e.jsx(me,{value:s.toString(),children:s},s))})]})]}),e.jsx("span",{className:"text-muted-foreground",children:"vs"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:t==="cs"?"Rok 2:":t==="de"?"Jahr 2:":"Year 2:"}),e.jsxs(Be,{value:($==null?void 0:$.toString())||"",onValueChange:s=>Pt(parseInt(s)),children:[e.jsx(He,{className:"w-24 h-9",children:e.jsx(Oe,{})}),e.jsx(Ke,{children:we.map(s=>e.jsx(me,{value:s.toString(),children:s},s))})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:t==="cs"?"Rok:":t==="de"?"Jahr:":"Year:"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:we.map(s=>e.jsx(he,{variant:D===s?"default":"outline",size:"sm",onClick:()=>ce(s.toString()),children:s},s))})]})}),e.jsxs(he,{variant:oe?"default":"outline",size:"sm",onClick:ts,className:"flex items-center gap-2",children:[e.jsx(pt,{className:"h-4 w-4"}),t==="cs"?"Porovnávací režim":t==="de"?"Vergleichsmodus":"Compare Mode"]})]}),oe&&L&&$&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs(be,{children:[e.jsxs(Ce,{children:[e.jsxs(Se,{className:"flex items-center gap-2",children:[e.jsx(pt,{className:"h-5 w-5"}),t==="cs"?`Porovnání: ${L} vs ${$}`:t==="de"?`Vergleich: ${L} vs ${$}`:`Comparison: ${L} vs ${$}`]}),e.jsx(Me,{children:t==="cs"?"Přehled rozdílů nákladů podle kategorií":t==="de"?"Übersicht der Kostenunterschiede nach Kategorien":"Overview of cost differences by category"})]}),e.jsx(je,{children:e.jsx(nt,{width:"100%",height:300,children:e.jsxs(Ft,{data:$e,layout:"vertical",children:[e.jsx(st,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(Te,{type:"number",tickFormatter:s=>`€${(s/1e3).toFixed(0)}k`}),e.jsx(Fe,{type:"category",dataKey:"label",width:140}),e.jsx(_e,{formatter:s=>I(s),contentStyle:{backgroundColor:"hsl(var(--popover))",border:"1px solid hsl(var(--border))",borderRadius:"8px"}}),e.jsx(rt,{}),e.jsx(at,{dataKey:"year2",name:$.toString(),fill:"hsl(var(--muted-foreground))",radius:[0,4,4,0]}),e.jsx(at,{dataKey:"year1",name:L.toString(),fill:"hsl(var(--primary))",radius:[0,4,4,0]})]})})})]}),e.jsx("div",{className:"grid gap-4 md:grid-cols-3",children:$e.map(s=>{const i=s.difference>0,a=s.difference<0;return e.jsxs(be,{className:`${i?"border-destructive/30":a?"border-green-500/30":""}`,children:[e.jsx(Ce,{className:"pb-2",children:e.jsx(Se,{className:"text-lg",children:s.label})}),e.jsxs(je,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"text-center p-3 bg-muted/50 rounded-lg",children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:$}),e.jsx("div",{className:"text-lg font-bold",children:I(s.year2)})]}),e.jsxs("div",{className:"text-center p-3 bg-primary/10 rounded-lg",children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:L}),e.jsx("div",{className:"text-lg font-bold",children:I(s.year1)})]})]}),e.jsxs("div",{className:`flex items-center justify-center gap-2 p-2 rounded-lg ${i?"bg-destructive/10 text-destructive":a?"bg-green-500/10 text-green-600":"bg-muted text-muted-foreground"}`,children:[i&&e.jsx(Ie,{className:"h-4 w-4"}),a&&e.jsx(Ye,{className:"h-4 w-4"}),!i&&!a&&e.jsx(ht,{className:"h-4 w-4"}),e.jsxs("span",{className:"font-medium",children:[i?"+":"",I(s.difference)]}),e.jsxs("span",{className:"text-sm",children:["(",i?"+":"",s.percentChange.toFixed(1),"%)"]})]})]})]},s.key)})}),e.jsx(be,{className:"bg-muted/30",children:e.jsx(je,{className:"pt-6",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[e.jsxs("div",{className:"text-center",children:[e.jsxs("div",{className:"text-sm text-muted-foreground mb-1",children:[t==="cs"?"Celkem":t==="de"?"Gesamt"
10:"Total"," ",$]}),e.jsx("div",{className:"text-2xl font-bold",children:I($e.reduce((s,i)=>s+i.year2,0))})]}),e.jsx("div",{className:"text-center",children:(()=>{const s=$e.reduce((p,l)=>p+l.difference,0),i=$e.reduce((p,l)=>p+l.year2,0),a=i>0?s/i*100:0,c=s>0,m=s<0;return e.jsxs("div",{className:`flex items-center gap-2 ${c?"text-destructive":m?"text-green-600":"text-muted-foreground"}`,children:[c&&e.jsx(Ie,{className:"h-6 w-6"}),m&&e.jsx(Ye,{className:"h-6 w-6"}),!c&&!m&&e.jsx(ht,{className:"h-6 w-6"}),e.jsxs("div",{children:[e.jsxs("div",{className:"text-2xl font-bold",children:[c?"+":"",I(s)]}),e.jsxs("div",{className:"text-sm",children:["(",c?"+":"",a.toFixed(1),"%)"]})]})]})})()}),e.jsxs("div",{className:"text-center",children:[e.jsxs("div",{className:"text-sm text-muted-foreground mb-1",children:[t==="cs"?"Celkem":t==="de"?"Gesamt":"Total"," ",L]}),e.jsx("div",{className:"text-2xl font-bold",children:I($e.reduce((s,i)=>s+i.year1,0))})]})]})})})]}),!oe&&K==="overview"&&Lt.length>0&&e.jsxs(xs,{variant:"destructive",className:"border-destructive/50 bg-destructive/10",children:[e.jsx(Bt,{className:"h-4 w-4"}),e.jsx(ps,{children:t==="cs"?"Pozor: Vysoký nárůst nákladů":t==="de"?"Achtung: Hohe Kostensteigerung":"Warning: High Cost Increase"}),e.jsxs(hs,{children:[Lt.map((s,i)=>e.jsxs("span",{children:[i>0&&", ",e.jsx("strong",{children:s.label})," +",s.change.percentage.toFixed(1),"%"]},s.key))," ",t==="cs"?`(více než 20% oproti ${F})`:t==="de"?`(mehr als 20% im Vergleich zu ${F})`:`(more than 20% compared to ${F})`]})]}),!oe&&K==="overview"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-end gap-4 text-xs text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"w-3 h-0.5 bg-destructive rounded"}),e.jsx("span",{children:t==="cs"?"Stoupá":t==="de"?"Steigend":"Rising"})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"w-3 h-0.5 bg-green-600 rounded"}),e.jsx("span",{children:t==="cs"?"Klesá":t==="de"?"Sinkend":"Falling"})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"w-3 h-0.5 bg-muted-foreground rounded"}),e.jsx("span",{children:t==="cs"?"Stabilní":t==="de"?"Stabil":"Stable"})]})]}),e.jsx("div",{className:"grid gap-4 grid-cols-1 sm:grid-cols-2 lg:grid-cols-3",children:Ue.map(s=>{var i,a,c,m,p,l;return s.trendData.length,(i=s.trendData[0])!=null&&i.value,(a=s.trendData[s.trendData.length-1])!=null&&a.value,e.jsxs(be,{className:`cursor-pointer hover:shadow-lg transition-all bg-background ${s.hasHighIncrease?"border-destructive/50":s.change.direction==="up"?"hover:border-destructive/50":s.change.direction==="down"?"hover:border-green-500/50":"hover:border-primary/50"}`,onClick:()=>ls(s.key,s.isHeating),children:[e.jsx(Ce,{className:"pb-2 px-4 pt-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx(Se,{className:"text-base font-bold",children:((m=(c=Le[s.key])==null?void 0:c[t])==null?void 0:m.title)||s.label}),e.jsx(Me,{className:"text-xs text-muted-foreground line-clamp-1",children:((l=(p=Le[s.key])==null?void 0:p[t])==null?void 0:l.subt
10itle)||""})]}),e.jsxs("div",{className:"flex items-center gap-1 ml-2",children:[s.hasHighIncrease&&e.jsx(Bt,{className:"h-3.5 w-3.5 text-destructive"}),e.jsx(Qt,{className:"h-4 w-4 text-muted-foreground"})]})]})}),e.jsxs(je,{className:"space-y-3 px-4 pb-4",children:[s.trendData.length>1&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"h-10 w-full",children:e.jsx(nt,{width:"100%",height:"100%",children:e.jsxs(kt,{data:s.trendData,margin:{top:4,right:4,left:4,bottom:4},children:[e.jsx(Te,{dataKey:"year",hide:!0}),e.jsx(Fe,{hide:!0,domain:["dataMin * 0.9","dataMax * 1.1"]}),e.jsx(ot,{type:"monotone",dataKey:"value",stroke:s.change.direction==="up"?"hsl(var(--destructive))":s.change.direction==="down"?"#16a34a":"hsl(var(--muted-foreground))",strokeWidth:2,dot:r=>{const{cx:o,cy:d,payload:g}=r;if(g.year===D){const h=s.change.direction==="up"?"hsl(var(--destructive))":s.change.direction==="down"?"#16a34a":"hsl(var(--muted-foreground))";return e.jsx("circle",{cx:o,cy:d,r:4,fill:h,stroke:"white",strokeWidth:2})}return e.jsx("circle",{cx:0,cy:0,r:0})},activeDot:!1}),e.jsx(_e,{content:({active:r,payload:o})=>{if(r&&o&&o.length){const d=o[0].payload;return e.jsxs("div",{className:"bg-popover border rounded-md px-2 py-1 text-xs shadow-md",children:[e.jsxs("span",{className:"font-medium",children:[d.year,":"]})," ",I(d.value)]})}return null}})]})})}),e.jsx("div",{className:"flex justify-between text-[10px] text-muted-foreground",children:s.trendData.map(r=>e.jsx("button",{onClick:o=>{o.stopPropagation(),ce(r.year.toString())},className:`hover:text-primary transition-colors ${r.year===D?"text-foreground font-semibold":""}`,children:r.year},r.year))})]}),e.jsx("div",{className:"pt-2",children:e.jsxs("div",{className:"flex items-end justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xl font-bold",children:I(s.current)}),e.jsx(St,{change:s.change})]}),e.jsxs("div",{className:"flex flex-col items-end gap-1",children:[e.jsx(vt,{children:e.jsxs(yt,{children:[e.jsx(bt,{asChild:!0,children:e.jsxs("div",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-[10px] font-medium cursor-help ${fs(s.change.direction)} ${Kt(s.change.direction)}`,children:[s.change.direction==="up"&&e.jsx(Ie,{className:"h-2.5 w-2.5"}),s.change.direction==="down"&&e.jsx(Ye,{className:"h-2.5 w-2.5"}),s.change.direction==="neutral"&&e.jsx(ht,{className:"h-2.5 w-2.5"}),s.change.direction==="up"?t==="cs"?"Náklady vzrostly":t==="de"?"Gestiegen":"Increased":s.change.direction==="down"?t==="cs"?"Náklady klesly":t==="de"?"Gesunken":"Decreased":t==="cs"?"Stabilní":t==="de"?"Stabil":"Stable"]})}),e.jsx(jt,{children:e.jsx("p",{className:"text-xs",children:s.change.direction==="up"?t==="cs"?`Náklady v této kategorii vzrostly o ${s.change.percentage.toFixed(1)}% oproti roku ${F}`:t==="de"?`Die Kosten in dieser Kategorie sind um ${s.change.percentage.toFixed(1)}% gegenüber ${F} gestiegen`:`Costs in this category increased by ${s.change.percentage.toFixed(1)}% compared to ${F}`:s.change.direction==="down"?t==="cs"?`Náklady v této kategorii klesly o ${Math.abs(s.change.percentage).toFixed(1)}% oproti roku ${F}`:t==="de"?`Die Kosten in dieser Kategorie sind um ${Math.abs(s.change.percentage).toFixed(1)}% gegenüber ${F} gesunken`:`Costs in this category decreased by ${Math.abs(s.change.percentage).toFixed(1)}% compared to ${F}`:t==="cs"?`Náklady v této kategorii zůstaly stabilní oproti roku ${F}`:t==="de"?`Die Kosten in dieser Kategorie blieben gegenüber ${F} stabil`:`Costs in this category remained stable compared to ${F}`})})]})}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:["vs ",F,": ",I(s.previous)]})]})]})})]})]},s.key)})})]}),!oe&&K==="category"&&f&&e.jsx(Ms,{houseCosts:y,selectedCategory:f,currentYear:D,previousYear:F,selectedYear:P==="all"?void 0:parseInt(P),onAreaClick:is,showHeader:!1,excludePersonnel:f==="Provozni_naklady"}),!oe&&K==="area"&&(()=>{const s=f==="Fond_oprav",i=f==="Personal";return e.jsxs("div",{className:"space-y-6",children:[i&&ze.length>0&&e.jsxs(be,{children:[e.jsxs(Ce,{className:"flex flex-row items-center justify-between space-y-0 pb-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(Se,{className:"text-lg font-semibold tracking-tight",children:t==="cs"?"Vývoj nákladů":t==="de"?"Kostenentwicklung":"Cost Development"}),e.jsx(Me,{className:"text-sm text-muted-foreground",children:ue==="bar"?t==="cs"?"Složený sloupcový graf s vývojem v čase • Tooltip: změna v % a celková suma":t==="de"?"Gestapeltes Balkendiagramm mit Zeitverlauf • Tooltip: Änderung in % und Gesamtsumme":"Stacked bar chart with development over time • Tooltip: % change and total sum":t==="cs"?"Liniový graf zobrazující vývoj jednotlivých položek v čase":t==="de"?"Liniendiagramm mit Entwicklung einzelner Posten":"Line chart showing development of individual items over time"})]}),e.jsxs("div",{className:"flex items-center gap-1 border rounded-lg p-1 bg-muted/30",children:[e.jsxs(he,{variant:ue==="line"?"default":"ghost",size:"sm",onClick:()=>Ae("line"),className:"h-8 px-3",children:[e.jsx(Zt,{className:"h-4 w-4 mr-1.5"}),t==="cs"||t==="de"?"Linie":"Line"]}),e.jsxs(he,{variant:ue==="bar"?"default":"ghost",size:"sm",onClick:()=>Ae("bar"),className:"h-8 px-3",children:[e.jsx(pt,{className:"h-4 w-4 mr-1.5"}),t==="cs"?"Sloupcový":t==="de"?"Balken":"Bar"]})]})]}),e.jsx(je,{children:e.jsx(nt,{width:"100%",height:300,children:ue==="bar"?e.jsxs(Ft,{data:ze,children:[e.jsx(st,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(Te,{dataKey:"year"}
10),e.jsx(Fe,{tickFormatter:a=>`€${(a/1e3).toFixed(1)}k`}),e.jsx(_e,{content:({active:a,payload:c,label:m})=>{var p,l;if(a&&c&&c.length){const r=(p=c[0])==null?void 0:p.payload,o=(r==null?void 0:r.total)||0,d=ze.findIndex(w=>w.year===m),g=d>0&&((l=ze[d-1])==null?void 0:l.total)||0,h=g>0?(o-g)/g*100:0;return e.jsxs("div",{className:"bg-popover border rounded-lg px-3 py-2 shadow-lg text-sm",children:[e.jsx("div",{className:"font-semibold border-b pb-1 mb-2",children:m}),c.map((w,R)=>e.jsxs("div",{className:"flex items-center justify-between gap-4 py-0.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-3 h-3 rounded-sm",style:{backgroundColor:w.color}}),e.jsx("span",{className:"text-muted-foreground",children:w.dataKey==="wages"?t==="cs"?"Mzdy":t==="de"?"Löhne":"Wages":t==="cs"?"Sociální pojištění":t==="de"?"Sozialversicherung":"Social Insurance"})]}),e.jsx("span",{className:"font-medium",children:I(w.value)})]},R)),e.jsxs("div",{className:"border-t mt-2 pt-2 space-y-1",children:[e.jsxs("div",{className:"flex justify-between font-semibold",children:[e.jsx("span",{children:t==="cs"?"Celkem":t==="de"?"Gesamt":"Total"}),e.jsx("span",{children:I(o)})]}),g>0&&e.jsxs("div",{className:`flex justify-between text-xs ${h>0?"text-destructive":h<0?"text-green-600":"text-muted-foreground"}`,children:[e.jsx("span",{children:t==="cs"?"Změna":t==="de"?"Änderung":"Change"}),e.jsxs("span",{children:[h>0?"+":"",h.toFixed(1),"%"]})]})]})]})}return null}}),e.jsx(rt,{formatter:a=>a==="wages"?t==="cs"?"Mzdy":t==="de"?"Löhne":"Wages":t==="cs"?"Sociální pojištění":t==="de"?"Sozialversicherung":"Social Insurance"}),e.jsx(at,{dataKey:"wages",name:"wages",stackId:"personnel",fill:"hsl(var(--primary))",radius:[0,0,0,0]}),e.jsx(at,{dataKey:"socialInsurance",name:"socialInsurance",stackId:"personnel",fill:"hsl(var(--muted-foreground))",radius:[4,4,0,0]})]}):e.jsxs(kt,{data:ze,children:[e.jsx(st,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(Te,{dataKey:"year"}),e.jsx(Fe,{tickFormatter:a=>`€${(a/1e3).toFixed(1)}k`}),e.jsx(_e,{content:({active:a,payload:c,label:m})=>{var p,l;if(a&&c&&c.length){const r=(p=c[0])==null?void 0:p.payload,o=(r==null?void 0:r.total)||0,d=ze.findIndex(w=>w.year===m),g=d>0&&((l=ze[d-1])==null?void 0:l.total)||0,h=g>0?(o-g)/g*100:0;return e.jsxs("div",{className:"bg-popover border rounded-lg px-3 py-2 shadow-lg text-sm",children:[e.jsx("div",{className:"font-semibold border-b pb-1 mb-2",children:m}),c.map((w,R)=>e.jsxs("div",{className:"flex items-center justify-between gap-4 py-0.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-3 h-3 rounded-full",style:{backgroundColor:w.color}}),e.jsx("span",{className:"text-muted-foreground",children:w.dataKey==="wages"?t==="cs"?"Mzdy":t==="de"?"Löhne":"Wages":t==="cs"?"Sociální pojištění":t==="de"?"Sozialversicherung":"Social Insurance"})]}),e.jsx("span",{className:"font-medium",children:I(w.value)})]},R)),e.jsxs("div",{className:"border-t mt-2 pt-2 space-y-1",children:[e.jsxs("div",{className:"flex justify-between font-semibold",children:[e.jsx("span",{children:t==="cs"?"Celkem":t==="de"?"Gesamt":"Total"}),e.jsx("span",{children:I(o)})]}),g>0&&e.jsxs("div",{className:`flex justify-between text-xs ${h>0?"text-destructive":h<0?"text-green-600":"text-muted-foreground"}`,children:[e.jsx("span",{children:t==="cs"?"Změna":t==="de"?"Änderung":"Change"}),e.jsxs("span",{children:[h>0?"+":"",h.toFixed(1),"%"]})]})]})]})}return null}}),e.jsx(rt,{formatter:a=>a==="wages"?t==="cs"?"Mzdy":t==="de"?"Löhne":"Wages":t==="cs"?"Sociální pojištění":t==="de"?"Sozialversicherung":"Social Insurance"}),e.jsx(ot,{type:"monotone",dataKey:"wages",name:"wages",stroke:"hsl(var(--primary))",strokeWidth:2,dot:{fill:"hsl(var(--primary))",r:4},activeDot:{r:6}}),e.jsx(ot,{type:"monotone",dataKey:"socialInsurance",name:"socialInsurance",stroke:"hsl(var(--muted-foreground))",strokeWidth:2,dot:{fill:"hsl(var(--muted-foreground))",r:4},activeDot:{r:6}})]})})})]}),!i&&e.jsxs(be,{children:[e.jsxs(Ce,{className:"flex flex-row items-center justify-between space-y-0 pb-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(Se,{className:"text-lg font-semibold tracking-tight",children:t==="cs"?"Vývoj nákladů":t==="de"?"Kostenentwicklung":"Cost Development"}),e.jsx(Me,{className:"text-sm text-muted-foreground",children:ue==="bar"?t==="cs"?"Složený sloupcový graf s vývojem v čase • Tooltip: změna v % a celková suma":t==="de"?"Gestapeltes Balkendiagramm mit Zeitverlauf • Tooltip: Änderung in % und Gesamtsumme":"Stacked bar chart with development over time • Tooltip: % change and total sum":t==="cs"?"Liniový graf zobrazující vývoj jednotlivých položek v čase":t==="de"?"Liniendiagramm mit Entwicklung einzelner Posten":"Line chart showing development of individual items over time"})]}),e.jsxs("div",{className:"flex items-center gap-1 border rounded-lg p-1 bg-muted/30",children:[e.jsxs(he,{variant:ue==="line"?"default":"ghost",size:"sm",onClick:()=>Ae("line"),className:"h-8 px-3",children:[e.jsx(Zt,{className:"h-4 w-4 mr-1.5"}),t==="cs"||t==="de"?"Linie":"Line"]}),e.jsxs(he,{variant:ue==="bar"?"default":"ghost",size:"sm",onClick:()=>Ae("bar"),className:"h-8 px-3",children:[e.jsx(pt,{className:"h-4 w-4 mr-1.5"}),t==="cs"?"Sloupcový":t==="de"?"Balken":"Bar"]})]})]}),e.jsx(je,{children:e.jsx(nt,{width:"100%",height:300,children:ue==="bar"?e.jsxs(Ft,{data:Je,children:[e.jsx(st,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(Te,{dataKey:"year"}
10),e.jsx(Fe,{tickFormatter:a=>`€${(a/1e3).toFixed(1)}k`}),e.jsx(_e,{content:({active:a,payload:c,label:m})=>{var p;if(a&&c&&c.length){const l=(p=c[0])==null?void 0:p.payload,r=(l==null?void 0:l.total)||0,o=(l==null?void 0:l.prevTotal)||0,d=(l==null?void 0:l.changePercent)||0,g=c.filter(h=>Number((h==null?void 0:h.value)||0)!==0);return e.jsxs("div",{className:"bg-popover border rounded-lg px-3 py-2 shadow-lg text-sm",children:[e.jsx("div",{className:"font-semibold border-b pb-1 mb-2",children:m}),g.map((h,w)=>e.jsxs("div",{className:"flex items-center justify-between gap-4 py-0.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-3 h-3 rounded-sm",style:{backgroundColor:h.color}}),e.jsx("span",{className:"text-muted-foreground",children:ft(h.dataKey,t)})]}),e.jsx("span",{className:"font-medium",children:I(h.value)})]},w)),e.jsxs("div",{className:"border-t mt-2 pt-2 space-y-1",children:[e.jsxs("div",{className:"flex justify-between font-semibold",children:[e.jsx("span",{children:t==="cs"?"Celkem":t==="de"?"Gesamt":"Total"}),e.jsx("span",{children:I(r)})]}),o>0&&e.jsxs("div",{className:`flex justify-between text-xs ${d>0?"text-destructive":d<0?"text-green-600":"text-muted-foreground"}`,children:[e.jsx("span",{children:t==="cs"?"Změna":t==="de"?"Änderung":"Change"}),e.jsxs("span",{children:[d>0?"+":"",d.toFixed(1),"%"]})]})]})]})}return null}}),e.jsx(rt,{content:e.jsx(Jt,{translateFn:a=>ft(a,t)})}),Ct.map((a,c)=>{const m=["hsl(var(--primary))","hsl(var(--muted-foreground))","#16a34a","#eab308","#6366f1","#ec4899"];return e.jsx(at,{dataKey:a,name:a,stackId:"subcategories",fill:m[c%m.length],radius:c===Ct.length-1?[4,4,0,0]:[0,0,0,0]},a)})]}):e.jsxs(kt,{data:Je,children:[e.jsx(st,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(Te,{dataKey:"year"}),e.jsx(Fe,{tickFormatter:a=>`€${(a/1e3).toFixed(1)}k`}),e.jsx(_e,{content:({active:a,payload:c,label:m})=>{var p;if(a&&c&&c.length){const l=(p=c[0])==null?void 0:p.payload,r=(l==null?void 0:l.total)||0,o=(l==null?void 0:l.prevTotal)||0,d=(l==null?void 0:l.changePercent)||0,g=c.filter(h=>Number((h==null?void 0:h.value)||0)!==0);return e.jsxs("div",{className:"bg-popover border rounded-lg px-3 py-2 shadow-lg text-sm",children:[e.jsx("div",{className:"font-semibold border-b pb-1 mb-2",children:m}),g.map((h,w)=>e.jsxs("div",{className:"flex items-center justify-between gap-4 py-0.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-3 h-3 rounded-full",style:{backgroundColor:h.color}}),e.jsx("span",{className:"text-muted-foreground",children:ft(h.dataKey,t)})]}),e.jsx("span",{className:"font-medium",children:I(h.value)})]},w)),e.jsxs("div",{className:"border-t mt-2 pt-2 space-y-1",children:[e.jsxs("div",{className:"flex justify-between font-semibold",children:[e.jsx("span",{children:t==="cs"?"Celkem":t==="de"?"Gesamt":"Total"}),e.jsx("span",{children:I(r)})]}),o>0&&e.jsxs("div",{className:`flex justify-between text-xs ${d>0?"text-destructive":d<0?"text-green-600":"text-muted-foreground"}`,children:[e.jsx("span",{children:t==="cs"?"Změna":t==="de"?"Änderung":"Change"}),e.jsxs("span",{children:[d>0?"+":"",d.toFixed(1),"%"]})]})]})]})}return null}}),e.jsx(rt,{content:e.jsx(Jt,{translateFn:a=>ft(a,t)})}),Ct.map((a,c)=>{const m=["hsl(var(--primary))","hsl(var(--muted-foreground))","#16a34a","#eab308","#6366f1","#ec4899"];return e.jsx(ot,{type:"monotone",dataKey:a,name:a,stroke:m[c%m.length],strokeWidth:2,dot:{fill:m[c%m.length],r:4},activeDot:{r:6}},a)})]})})})]}),e.jsxs(be,{children:[e.jsxs(Ce,{className:"flex flex-row items-center justify-between space-y-0 pb-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs(Se,{className:"text-lg font-semibold tracking-tight flex items-center gap-2",children:[e.jsx(js,{className:"h-5 w-5 text-muted-foreground"}),t==="cs"?"Detailní přehled":t==="de"?"Detailübersicht":"Detailed Overview"]}),e.jsx(Me,{className:"text-sm text-muted-foreground",children:s?t==="cs"?`Přehled všech výdajů z fondu oprav • ${D}`:t==="de"?`Übersicht aller Reparaturfonds-Ausgaben • ${D}`:`Overview of all repair fund expenditures • ${D}`:t==="cs"?`Rozbalte kategorie pro zobrazení jednotlivých faktur • ${D}`:t==="de"?`Kategorien erweitern um einzelne Rechnungen zu sehen • ${D}`:`Expand categories to see individual invoices • ${D}`})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(he,{variant:ne?"secondary":"outline",size:"sm",onClick:()=>Pe(!ne),className:"flex items-center gap-2 h-9",children:[e.jsx(Ns,{className:"h-4 w-4"}),t==="cs"?"Filtr":"Filter",ut&&e.jsx(it,{variant:"destructive",className:"ml-1 h-5 w-5 p-0 flex items-center justify-center text-[10px] rounded-full",children:"!"})]}),e.jsxs(he,{variant:"outline",size:"sm",onClick:as,className:"flex items-center gap-2 h-9",children:[e.jsx(ks,{className:"h-4 w-4"}),t==="cs"?"Export CSV":t==="de"?"CSV Export":"Export CSV"]})]})]}),ne&&e.jsxs("div",{className:"px-6 pb-4 border-b",children:[e.jsxs("div",{className:"flex flex-wrap items-end gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-[200px]",children:[e.jsx(Vt,{htmlFor:"vendor-filter",className:"text-xs text-muted-foreground",children:t==="cs"?"Dodavatel":t==="de"?"Lieferant":"Vendor"}),e.jsx(Tt,{id:"vendor-filter",placeholder:t==="cs"?"Hledat dodavatele...":t==="de"?"Lieferant suchen...":"Search vendor...",value:ie,onChange:a=>pe(a.target.value),className:"h-9"})]}),e.jsxs("div",{className:"flex-1 min-w-[150px]",children:[e.jsx(Vt,{htmlFor:"date-from",className:"text-xs text-muted-foreground",children:t==="cs"?"Od data":t==="de"?"Von Datum":"From Date"}),e.jsx(Tt,{id:"date-from",type:"date",value:B,onChange:a=>k(a.target.value),className:"h-9"})]}),e.jsxs("div",{className:"flex-1 min-w-[150px]",children:[e.jsx(Vt,{htmlFor:"date-to",className:"text-xs text-muted-foreground",children:t==="cs"?"Do data":t==="de"?"Bis Datum":"To Date"}),e.jsx(Tt,{id:"date-to",type:"date",value:C,onChange:a=>J(a.target.value),className:"h-9"})]}),ut&&e.jsxs(he,{variant:"ghost",size:"sm",onClick:ns,className:"flex items-center gap-1 text-destructive hover:text-destructive",children:[e.jsx(Xt,{className:"h-4 w-4"}),t==="cs"?"Zrušit filtry":t==="de"?"Filter löschen":"Clear filters"]})]}),ut&&e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:t==="cs"?"Zobrazeny filtrované výsledky. Celkové částky zůstávají nezměněny.":t==="de"?"Zeigt gefilterte Ergebnisse. Gesamtbeträge bleiben unverändert.":"Showing filtered results. Total amounts remain unchanged."})]}),e.jsx(je,{className:ne?"pt-4":"",children:v?e.jsxs("div",{className:"p-8 flex flex-col items-center justify-center gap-3",children:[e.jsx(Ht,{className:"h-8 w-8 animate-spin text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t==="cs"?"Načítám položky...":t==="de"?"Lade Positionen...":"Loading items..."})]}
10):s?e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-2 text-left font-medium text-muted-foreground",children:t==="de"?"Beschreibung":t==="cs"?"Popis":"Description"}),e.jsx("th",{className:"px-4 py-2 text-left font-medium text-muted-foreground",children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Gt,{className:"h-3 w-3"}),t==="de"?"Lieferant":t==="cs"?"Dodavatel":"Vendor"]})}),e.jsx("th",{className:"px-4 py-2 text-center font-medium text-muted-foreground",children:t==="de"?"Änderung":t==="cs"?"Změna":"Change"}),e.jsx("th",{className:"px-4 py-2 text-right font-medium text-muted-foreground",children:t==="de"?"Betrag":t==="cs"?"Částka":"Amount"})]})}),e.jsx("tbody",{children:Re.map((a,c)=>{var m;return e.jsxs("tr",{className:c%2===0?"bg-background":"bg-muted/20",children:[e.jsx("td",{className:"px-4 py-3 font-medium",children:Nt(a.label,t)}),e.jsx("td",{className:"px-4 py-3 text-muted-foreground",children:(m=a.houseCosts[0])!=null&&m.subcategory?Mt(a.houseCosts[0].subcategory,t):"-"}),e.jsx("td",{className:"px-4 py-3 text-center",children:e.jsx(St,{change:a.change,showTooltip:!0,previousValue:a.previous,previousYear:F})}),e.jsx("td",{className:"px-4 py-3 text-right font-bold text-lg",children:I(a.current)})]},a.key)})}),e.jsx("tfoot",{className:"bg-muted/50 font-medium",children:e.jsxs("tr",{children:[e.jsx("td",{colSpan:3,className:"px-4 py-3 text-right font-semibold",children:t==="de"?"Gesamt:":t==="cs"?"Celkem:":"Total:"}),e.jsx("td",{className:"px-4 py-3 text-right text-xl font-bold",children:I(Re.reduce((a,c)=>a+c.current,0))})]})})]})}):e.jsx("div",{className:"space-y-3",children:Re.map(a=>{const c=V.has(a.key),m=a.items.length>0,p=v||a.houseCosts.some(r=>G===r.id),l=ut&&a.items.length!==a.totalItems;return e.jsxs("div",{className:"border rounded-lg overflow-hidden",children:[e.jsxs("button",{onClick:()=>rs(a.key),className:"w-full p-4 flex items-center justify-between hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[c?e.jsx(ws,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(Cs,{className:"h-4 w-4 text-muted-foreground"}),e.jsxs("div",{className:"text-left",children:[e.jsx("h4",{className:"font-medium",children:a.label}),e.jsx("p",{className:"text-sm text-muted-foreground",children:l?`${a.items.length} / ${a.totalItems} ${t==="de"?"Einzelposten (gefiltert)":t==="cs"?"položek (filtrováno)":"line items (filtered)"}`:`${a.items.length} ${t==="de"?"Einzelposten":t==="cs"?"položek":"line items"}`})]})]}),e.jsxs("div",{className:"text-right flex items-center gap-4",children:[e.jsx(St,{change:a.change,showTooltip:!0,previousValue:a.previous,previousYear:F}),e.jsx("div",{className:"text-xl font-bold",children:I(a.current)})]})]}),c&&e.jsx("div",{className:"border-t bg-muted/30",children:p?e.jsx("div",{className:"p-4 flex items-center justify-center",children:e.jsx(Ht,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):m?e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-2 text-left font-medium text-muted-foreground",children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(It,{className:"h-3 w-3"}),t==="de"||t==="cs"?"Datum":"Date"]})}),e.jsx("th",{className:"px-4 py-2 text-left font-medium text-muted-foreground",children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Gt,{className:"h-3 w-3"}),t==="de"?"Lieferant":t==="cs"?"Dodavatel":"Vendor"]})}),e.jsx("th",{className:"px-4 py-2 text-left font-medium text-muted-foreground",children:t==="de"?"Beschreibung":t==="cs"?"Popis":"Description"}),N.showSourceColumn&&e.jsx("th",{className:"px-4 py-2 text-center font-medium text-muted-foreground",children:t==="de"?"Quelle":t==="cs"?"Zdroj":"Source"}),e.jsx("th",{className:"px-4 py-2 text-right font-medium text-muted-foreground",children:t==="de"?"Betrag":t==="cs"?"ČÃ
10¡stka":"Amount"})]})}),e.jsx("tbody",{children:a.items.map((r,o)=>{var d;return e.jsxs("tr",{className:o%2===0?"bg-background":"bg-muted/20",children:[e.jsx("td",{className:"px-4 py-2 whitespace-nowrap",children:r.item_date?ss(r.item_date):e.jsx("span",{className:"text-muted-foreground",children:"-"})}),e.jsx("td",{className:"px-4 py-2",children:r.vendor||e.jsx("span",{className:"text-muted-foreground/50",children:"-"})}),e.jsx("td",{className:"px-4 py-2",children:vs(r.description,t)}),N.showSourceColumn&&e.jsx("td",{className:"px-4 py-2 text-center",children:e.jsx(vt,{children:e.jsxs(yt,{children:[e.jsx(bt,{asChild:!0,children:e.jsx("span",{className:"inline-flex",children:r.source==="pdf_import"?e.jsx(it,{variant:"secondary",className:"bg-blue-100 text-blue-700 dark:bg-blue-950 dark:text-blue-300 hover:bg-blue-100 dark:hover:bg-blue-950 text-[10px] px-1.5 py-0.5",children:"PDF"}):e.jsx(it,{variant:"outline",className:"text-muted-foreground text-[10px] px-1.5 py-0.5",children:t==="de"?"Manuell":t==="cs"?"Manuální":"Manual"})})}),e.jsx(jt,{children:r.source==="pdf_import"?`${t==="cs"?"Importováno z":t==="de"?"Importiert aus":"Imported from"}: ${((d=r.pdf_document)==null?void 0:d.file_name)||"PDF"}`:t==="cs"?"Manuální zadání":t==="de"?"Manuell eingegeben":"Manual entry"})]})})}),e.jsx("td",{className:"px-4 py-2 text-right font-medium",children:I(r.amount)})]},r.id)})}),e.jsx("tfoot",{className:"bg-muted/50 font-medium",children:e.jsxs("tr",{children:[e.jsx("td",{colSpan:N.showSourceColumn?4:3,className:"px-4 py-2 text-right",children:t==="de"?"Summe:":t==="cs"?"Celkem:":"Total:"}),e.jsx("td",{className:"px-4 py-2 text-right",children:I(a.items.reduce((r,o)=>r+Number(o.amount),0))})]})})]})}):e.jsx("div",{className:"p-4 text-center text-muted-foreground",children:t==="de"?"Keine Einzelposten verfügbar":"No detailed items available"})})]},a.key)})})})]})]})})()]})},Mr=()=>{const{user:y}=ms(),{language:T}=Et(),[P,ce]=b.useState([]),[ee,te]=b.useState([]),[t,ge]=b.useState(!0),[N,de]=b.useState("all"),[K,X]=b.useState([]),[se,le]=b.useState(0);b.useEffect(()=>{y&&Ne()},[y]);const Ne=async()=>{ge(!0);const[G,Ee,v]=await Promise.all([lt.from("house_costs").select("*").order("year",{ascending:!0}),lt.from("apartment_heating_costs").select("year, total_gross_eur"),lt.from("reserve_fund_expenditures").select("*").order("year",{ascending:!0})]),S=G.data||[],V=Ee.data||[],ie=(v.data||[]).map(k=>({id:k.id,year:k.year,category:"Fond_oprav",subcategory:k.category||"Instandhaltung",description:k.description,amount:k.amount,is_repair_fund:!0,notes:k.notes})),pe=[...S,...ie];ce(pe);const B=[...new Set(pe.map(k=>k.year))];if(B.length>0&&N==="all"&&de(Math.max(...B).toString()),V){const k={};V.forEach(C=>{C.year&&C.total_gross_eur&&(k[C.year]=(k[C.year]||0)+Number(C.total_gross_eur))}),te(Object.entries(k).map(([C,J])=>({year:parseInt(C),total:J})))}ge(!1)},f=[...new Set(P.map(G=>G.year))].sort(),re={de:{title:"Kostenkategorien",description:"Detaillierte Aufschlüsselung nach Kategorien und Bereichen",allYears:"Alle Jahre",year:"Jahr",costs:"Kosten"},en:{title:"Cost Categories",description:"Detailed breakdown by categories and areas",allYears:"All years",year:"Year",costs:"Costs"},cs:{title:"Kategorie nákladů",description:"Podrobný rozpis podle kategorií a oblastí",allYears:"VÅ¡echny roky",year:"Rok",costs:"Náklady"}},M=re[T]||re.cs,ae=e.jsxs(Be,{value:N,onValueChange:de,children:[e.jsx(He,{className:"w-[140px]",children:e.jsx(Oe,{placeholder:M.year})}),e.jsxs(Ke,{children:[e.jsx(me,{value:"all",children:M.allYears}),f.map(G=>e.jsx(me,{value:G.toString(),children:G},G))]})]}),ke=()=>{X([]),le(G=>G+1)},q=K[K.length-1],xe=(q==null?void 0:q.title)||M.title,Ge=(q==null?void 0:q.subtitle)||M.description;return e.jsx(gs,{title:xe,description:Ge,breadcrumbs:[{label:M.costs,href:"/owners/costs"},{label:M.title,onClick:K.length>0?ke:void 0},...K.map((G,Ee)=>({label:G.label,onClick:Ee<K.length-1?G.onClick:void 0}))],showYearSelector:!0,yearSelector:ae,isLoading:t,onDataRefresh:Ne,children:e.jsx(As,{houseCosts:P,heatingCosts:ee,selectedYear:N,onYearChange:de,onBreadcrumbsChange:X,resetTrigger:se})})};export{Mr as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.