@nice2dev/ui-forms 1.0.10 → 1.0.11

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,544 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),x=require("react"),we=require("./index-tVSzr4V7.cjs"),ve=["var(--color-primary, #3b82f6)","var(--color-error, #ef4444)","var(--color-success, #22c55e)","var(--color-warning, #f59e0b)","var(--color-accent, #8b5cf6)","var(--color-accent-pink, #ec4899)","var(--color-info, #06b6d4)","#84cc16"],Se=({series:t,categories:u,width:o=600,height:m=400,title:n,showLegend:f=!0,showGrid:j=!0,axisLabels:S=!0,yAxisLabel:z,xAxisLabel:l,stacked:g,animated:b,zoomable:p,crosshair:$,annotations:w,legendInteractive:i,onDataPointClick:d,exportable:c,className:k,style:_})=>{var ye,ke,je;const N=x.useRef(null),[y,v]=x.useState(new Set),[s,L]=x.useState(null),[r,B]=x.useState(null),[O,X]=x.useState(!1),q=x.useRef(null),U=x.useMemo(()=>t.filter(M=>!y.has(M.name)),[t,y]),re=x.useCallback(M=>{i&&v(ae=>{const ee=new Set(ae);return ee.has(M)?ee.delete(M):ee.add(M),ee})},[i]),J={top:n?40:20,right:20,bottom:l?60:40,left:z?60:50},te=o-J.left-J.right,T=m-J.top-J.bottom,G=((ye=U[0])==null?void 0:ye.data.length)??((ke=t[0])==null?void 0:ke.data.length)??0,oe=(r==null?void 0:r.start)??0,ce=(r==null?void 0:r.end)??G,C=ce-oe,A=x.useMemo(()=>U.map(M=>({...M,data:M.data.slice(oe,ce)})),[U,oe,ce]),V=x.useMemo(()=>u==null?void 0:u.slice(oe,ce),[u,oe,ce]),{minY:Z,maxY:K,yTicks:F}=x.useMemo(()=>{let M;if(g){M=[];for(let E=0;E<C;E++)M.push(A.reduce((ne,se)=>ne+(se.data[E]||0),0))}else M=A.flatMap(E=>E.data);M.length===0&&(M=[0]);const ae=Math.min(0,...M),ee=Math.max(0,...M),a=ee-ae||1,I=Math.pow(10,Math.floor(Math.log10(a)))||1,P=Math.floor(ae/I)*I,h=Math.ceil(ee/I)*I,R=[];for(let E=P;E<=h;E+=I)R.push(Math.round(E*1e6)/1e6);return R.length<2&&R.push(h),{minY:P,maxY:h,yTicks:R}},[A,C,g]),W=M=>T-(M-Z)/(K-Z||1)*T,H=M=>(M+.5)/C*te,Q=C>0?te/C/(g?1.5:Math.max(U.length,1)*1.5):20,D=x.useCallback(M=>{if(!p)return;M.preventDefault();const ae=r??{start:0,end:G},ee=ae.end-ae.start,a=(ae.start+ae.end)/2,I=M.deltaY>0?1.2:.8,P=Math.max(2,Math.min(G,Math.round(ee*I))),h=Math.max(0,Math.round(a-P/2)),R=Math.min(G,h+P);B({start:h,end:R})},[p,r,G]),Y=x.useCallback(M=>{p&&(X(!0),q.current={x:M.clientX,range:r??{start:0,end:G}})},[p,r,G]),ie=x.useCallback(M=>{var ee;const ae=(ee=N.current)==null?void 0:ee.getBoundingClientRect();if(ae&&L({x:M.clientX-ae.left-J.left,y:M.clientY-ae.top-J.top}),O&&q.current&&p){const a=M.clientX-q.current.x,I=te/C,P=-Math.round(a/I),h=q.current.range,R=h.end-h.start;let E=h.start+P;E<0&&(E=0),E+R>G&&(E=G-R),B({start:E,end:E+R})}},[O,p,te,C,G,J.left,J.top]),he=x.useCallback(()=>{X(!1),q.current=null},[]),me=x.useCallback(()=>{L(null),X(!1),q.current=null},[]),fe=x.useCallback(()=>{const M=N.current;if(!M)return;const ae=new XMLSerializer().serializeToString(M),ee=document.createElement("canvas");ee.width=o,ee.height=m+(f?30:0);const a=ee.getContext("2d");if(!a)return;const I=new Image;I.onload=()=>{a.fillStyle="var(--bg-primary, #fff)",a.fillRect(0,0,ee.width,ee.height),a.drawImage(I,0,0);const P=document.createElement("a");P.download="chart.png",P.href=ee.toDataURL("image/png"),P.click()},I.src="data:image/svg+xml;charset=utf-8,"+encodeURIComponent(ae)},[o,m,f]),pe=m+(f?30:0),_e=A.length>0&&A.every(M=>M.type==="radar"),be=x.useMemo(()=>{if(!_e)return 1;const M=A.flatMap(ae=>ae.data);return Math.max(1,...M)},[_e,A]);if(_e){const M=o/2,ae=(m-J.top-J.bottom)/2+J.top,ee=Math.min(te,m-J.top-J.bottom)/2-10,a=(V==null?void 0:V.length)??((je=A[0])==null?void 0:je.data.length)??0,I=R=>R/a*Math.PI*2-Math.PI/2,P=(R,E)=>{const ne=E/be*ee;return[M+Math.cos(I(R))*ne,ae+Math.sin(I(R))*ne]},h=4;return e.jsx("div",{className:`nice-chart nice-chart--radar ${k||""}`,style:_,children:e.jsxs("svg",{ref:N,viewBox:`0 0 ${o} ${pe}`,preserveAspectRatio:"xMidYMid meet",width:"100%",height:"100%",className:"nice-chart__svg",style:{display:"block",maxWidth:"100%",maxHeight:"100%"},children:[n&&e.jsx("text",{x:o/2,y:20,textAnchor:"middle",className:"nice-chart__title",children:n}),j&&Array.from({length:h},(R,E)=>{const ne=(E+1)/h*ee,se=[];for(let le=0;le<a;le++)se.push(`${M+Math.cos(I(le))*ne},${ae+Math.sin(I(le))*ne}`);return e.jsx("polygon",{points:se.join(" "),fill:"none",className:"nice-chart__grid-line"},E)}),Array.from({length:a},(R,E)=>{const[ne,se]=P(E,be);return e.jsx("line",{x1:M,y1:ae,x2:ne,y2:se,className:"nice-chart__grid-line"},E)}),S&&(V==null?void 0:V.map((R,E)=>{const[ne,se]=P(E,be*1.12);return e.jsx("text",{x:ne,y:se,textAnchor:"middle",dominantBaseline:"middle",className:"nice-chart__axis-label",children:R},E)})),A.map((R,E)=>{const ne=R.color||ve[E%ve.length],se=R.data.map((le,ge)=>P(ge,le).join(",")).join(" ");return e.jsxs("g",{className:b?"nice-chart__series nice-chart__series--radar nice-chart__series--anim":"nice-chart__series nice-chart__series--radar",children:[e.jsx("polygon",{points:se,fill:ne,fillOpacity:.2,stroke:ne,strokeWidth:2}),R.data.map((le,ge)=>{const[$e,Ne]=P(ge,le);return e.jsx("circle",{cx:$e,cy:Ne,r:3,fill:ne,children:e.jsx("title",{children:`${R.name}: ${le}`})},ge)})]},R.name)}),f&&e.jsx("g",{transform:`translate(${J.left}, ${m})`,children:t.map((R,E)=>{const ne=E*120,se=y.has(R.name);return e.jsxs("g",{transform:`translate(${ne}, 10)`,style:i?{cursor:"pointer"}:void 0,onClick:()=>re(R.name),opacity:se?.35:1,children:[e.jsx("rect",{width:12,height:12,rx:2,fill:R.color||ve[E%ve.length]}),e.jsx("text",{x:16,y:10,className:"nice-chart__legend-text",children:R.name})]},R.name)})})]})})}return e.jsxs("div",{className:`nice-chart ${k||""}`,style:_,children:[c&&e.jsx("button",{type:"button",className:"nice-chart__export-btn",onClick:fe,title:"Export PNG",children:"📷"}),e.jsxs("svg",{ref:N,viewBox:`0 0 ${o} ${pe}`,preserveAspectRatio:"xMidYMid meet",width:"100%",height:"100%",style:{display:"block",maxWidth:"100%",maxHeight:"100%"},className:"nice-chart__svg",onWheel:D,onMouseDown:Y,onMouseMove:ie,onMouseUp:he,onMouseLeave:me,children:[e.jsxs("g",{transform:`translate(${J.left},${J.top})`,children:[n&&e.jsx("text",{x:te/2,y:-10,textAnchor:"middle",className:"nice-chart__title",children:n}),j&&F.map(M=>e.jsx("line",{x1:0,y1:W(M),x2:te,y2:W(M),className:"nice-chart__grid-line"},`grid-${M}`)),S&&F.map(M=>e.jsx("text",{x:-8,y:W(M)+4,textAnchor:"end",className:"nice-chart__axis-label",children:M},`ylabel-${M}`)),S&&V&&V.map((M,ae)=>e.jsx("text",{x:H(ae),y:T+20,textAnchor:"middle",className:"nice-chart__axis-label",children:M},ae)),z&&e.jsx("text",{x:-J.left+14,y:T/2,textAnchor:"middle",transform:`rotate(-90, -${J.left-14}, ${T/2})`,className:"nice-chart__axis-title",children:z}),l&&e.jsx("text",{x:te/2,y:T+45,textAnchor:"middle",className:"nice-chart__axis-title",children:l}),e.jsx("line",{x1:0,y1:0,x2:0,y2:T,className:"nice-chart__axis"}),e.jsx("line",{x1:0,y1:T,x2:te,y2:T,className:"nice-chart__axis"}),w==null?void 0:w.map((M,ae)=>{if(M.type==="line"){const ee=W(M.value);return e.jsxs("g",{children:[e.jsx("line",{x1:0,y1:ee,x2:te,y2:ee,stroke:M.color||"var(--color-error, #ef4444)",strokeWidth:1.5,strokeDasharray:M.dash||"6,3"}),M.label&&e.jsx("text",{x:te+4,y:ee+4,className:"nice-chart__annotation-label",fill:M.color||"var(--color-error, #ef4444)",children:M.label})]},ae)}return e.jsx("text",{x:H(M.value),y:-4,textAnchor:"middle",className:"nice-chart__annotation-label",fill:M.color||"var(--text-muted, #6b7280)",children:M.label},ae)}),$&&s&&s.x>=0&&s.x<=te&&s.y>=0&&s.y<=T&&e.jsxs(e.Fragment,{children:[e.jsx("line",{x1:s.x,y1:0,x2:s.x,y2:T,stroke:"#9ca3af",strokeWidth:1,strokeDasharray:"4,2"}),e.jsx("line",{x1:0,y1:s.y,x2:te,y2:s.y,stroke:"#9ca3af",strokeWidth:1,strokeDasharray:"4,2"})]}),A.map((M,ae)=>{const ee=M.color||ve[ae%ve.length],a=M.type||"bar";if(a==="bar")return e.jsx("g",{className:b?"nice-chart__series nice-chart__series--bar nice-chart__series--anim":"nice-chart__series nice-chart__series--bar",children:M.data.map((P,h)=>{let R,E;if(g){const se=A.slice(0,ae).reduce((le,ge)=>le+(ge.data[h]||0),0);R=W(se+P),E=W(se)-R}else R=W(Math.max(0,P)),E=Math.abs(W(P)-W(0));const ne=g?H(h)-Q/2:H(h)-A.length*Q/2+ae*Q;return e.jsx("rect",{x:ne,y:R,width:Q*.9,height:Math.max(0,E),fill:ee,rx:2,style:{transformOrigin:`${ne+Q*.9/2}px ${W(0)}px`,...d?{cursor:"pointer"}:{}},onClick:d?()=>d(M.name,oe+h,P):void 0,children:e.jsx("title",{children:`${M.name}: ${P}`})},h)})},M.name);if(a==="scatter")return e.jsx("g",{className:b?"nice-chart__series nice-chart__series--scatter nice-chart__series--anim":"nice-chart__series nice-chart__series--scatter",children:M.data.map((P,h)=>e.jsx("circle",{cx:H(h),cy:W(P),r:5,fill:ee,fillOpacity:.7,stroke:ee,strokeWidth:1.5,style:d?{cursor:"pointer"}:void 0,onClick:d?()=>d(M.name,oe+h,P):void 0,children:e.jsx("title",{children:`${M.name}: ${P}`})},h))},M.name);const I=M.data.map((P,h)=>`${H(h)},${W(P)}`);return e.jsxs("g",{className:b?`nice-chart__series nice-chart__series--${a} nice-chart__series--anim`:`nice-chart__series nice-chart__series--${a}`,children:[a==="area"&&e.jsx("polygon",{points:`${H(0)},${W(0)} ${I.join(" ")} ${H(C-1)},${W(0)}`,fill:ee,opacity:.15}),e.jsx("polyline",{points:I.join(" "),fill:"none",stroke:ee,strokeWidth:2,className:b?"nice-chart__line":void 0}),M.data.map((P,h)=>e.jsx("circle",{cx:H(h),cy:W(P),r:3,fill:ee,style:d?{cursor:"pointer"}:void 0,onClick:d?()=>d(M.name,oe+h,P):void 0,children:e.jsx("title",{children:`${M.name}: ${P}`})},h))]},M.name)})]}),f&&e.jsx("g",{transform:`translate(${J.left}, ${m})`,children:t.map((M,ae)=>{const ee=ae*120,a=y.has(M.name);return e.jsxs("g",{transform:`translate(${ee}, 10)`,style:i?{cursor:"pointer"}:void 0,onClick:()=>re(M.name),opacity:a?.35:1,children:[e.jsx("rect",{width:12,height:12,rx:2,fill:M.color||ve[ae%ve.length]}),e.jsx("text",{x:16,y:10,className:"nice-chart__legend-text",style:a?{textDecoration:"line-through"}:void 0,children:M.name})]},M.name)})})]})]})},Ye=Object.freeze(Object.defineProperty({__proto__:null,NiceChart:Se},Symbol.toStringTag,{value:"Module"}));function He(t){if(!t.length)return{categories:[],numericFields:[],sampleValues:{}};const u=t[0],o=[],m={};let n=null;for(const[f,j]of Object.entries(u))typeof j=="number"?(o.push(f),m[f]=t.map(S=>Number(S[f])||0)):!n&&(typeof j=="string"||j instanceof Date)&&(n=f);return{categories:n?t.map(f=>String(f[n]||"")):t.map((f,j)=>`Item ${j+1}`),numericFields:o,sampleValues:m}}function Xe(t,u){const{categories:o,numericFields:m,sampleValues:n}=He(t);return{series:m.map((f,j)=>({name:f.replace(/([A-Z])/g," $1").replace(/^./,S=>S.toUpperCase()).trim(),data:n[f],type:u==="area"?"area":u==="line"?"line":"bar"})),categories:o}}x.forwardRef(function(t,u){const{rawData:o,enableAI:m=!0,aiModel:n,enableAutoType:f=!0,enableInsights:j=!0,dataDescription:S,onChartSuggestion:z,onInsights:l,showAIToolbar:g=!0,showInsightsOnLoad:b=!1,series:p,categories:$,...w}=t,[i,d]=x.useState("bar"),[c,k]=x.useState(null),[_,N]=x.useState([]),[y,v]=x.useState(b),[s,L]=x.useState(null),{t:r}=we.ue(),B=we.me(),{suggestChartType:O,generateInsights:X,isLoading:q}=we.xd(),U=m&&B.isConfigured,{series:re,categories:J}=o?Xe(o,s||i):{series:p||[],categories:$},te=x.useCallback(async()=>{if(!U||!f)return{type:"bar",reason:"Default",config:{}};const C=o||(p!=null&&p.length?p.flatMap(A=>A.data.map((V,Z)=>({[A.name]:V,index:Z}))):[]);try{const A=await O(C,S),V={type:A.type,reason:A.reason,config:A.config};return k(V),d(V.type),z==null||z(V),V}catch{return{type:"bar",reason:"Default fallback",config:{}}}},[U,f,o,p,S,O,z]),T=x.useCallback(async()=>{if(!U||!j)return[];const C=o||(p!=null&&p.length?p.flatMap(A=>A.data.map((V,Z)=>({[A.name]:V,category:($==null?void 0:$[Z])||Z}))):[]);try{const A=await X(C,s||i);return N(A),l==null||l(A),A}catch{return[]}},[U,j,o,p,$,i,s,X,l]),G=x.useCallback(()=>s||i,[s,i]);x.useEffect(()=>{U&&f&&(o!=null&&o.length||p!=null&&p.length)&&te()},[U,f,o,p]),x.useImperativeHandle(u,()=>({getSuggestion:te,generateInsights:T,getCurrentType:G}));const oe=[{type:"bar",icon:"📊",label:"Bar"},{type:"line",icon:"📈",label:"Line"},{type:"area",icon:"🏔️",label:"Area"},{type:"pie",icon:"🥧",label:"Pie"},{type:"donut",icon:"🍩",label:"Donut"},{type:"scatter",icon:"⭐",label:"Scatter"}],ce=s||i;return e.jsxs("div",{className:"nice-chart-ai","data-testid":t["data-testid"],children:[g&&U&&e.jsxs("div",{className:"nice-chart-ai__toolbar",children:[e.jsxs("div",{className:"nice-chart-ai__toolbar-left",children:[e.jsx("span",{className:"nice-chart-ai__badge",children:"AI"}),c&&e.jsxs("div",{className:"nice-chart-ai__suggestion",children:[e.jsx("span",{className:"nice-chart-ai__suggestion-icon",children:"💡"}),e.jsxs("span",{className:"nice-chart-ai__suggestion-text",children:[r("chartAI.suggestedType","Suggested:")," ",c.type]}),e.jsxs("span",{className:"nice-chart-ai__suggestion-reason",title:c.reason,children:["(",c.reason,")"]})]}),q&&e.jsx("span",{className:"nice-chart-ai__loading",children:r("chartAI.analyzing","Analyzing...")})]}),e.jsx("div",{className:"nice-chart-ai__toolbar-center",children:e.jsx("div",{className:"nice-chart-ai__type-selector",children:oe.filter(C=>["bar","line","area"].includes(C.type)).map(({type:C,icon:A,label:V})=>e.jsx("button",{type:"button",className:`nice-chart-ai__type-btn ${ce===C?"nice-chart-ai__type-btn--active":""}`,onClick:()=>L(C),title:V,children:A},C))})}),e.jsxs("div",{className:"nice-chart-ai__toolbar-right",children:[e.jsxs("button",{type:"button",className:"nice-chart-ai__auto-btn",onClick:()=>te(),disabled:q,title:r("chartAI.autoDetect","Auto-detect best chart type"),children:["🔮 ",r("chartAI.auto","Auto")]}),j&&e.jsxs("button",{type:"button",className:"nice-chart-ai__insights-btn",onClick:()=>{_.length||T(),v(!y)},disabled:q,title:r("chartAI.showInsights","Show data insights"),children:["💡 ",r("chartAI.insights","Insights")]})]})]}),e.jsx("div",{className:"nice-chart-ai__chart-wrapper",children:e.jsx(Se,{series:re,categories:J,...w})}),y&&_.length>0&&e.jsxs("div",{className:"nice-chart-ai__insights",children:[e.jsxs("div",{className:"nice-chart-ai__insights-header",children:[e.jsxs("h4",{children:["💡 ",r("chartAI.dataInsights","Data Insights")]}),e.jsx("button",{type:"button",className:"nice-chart-ai__insights-close",onClick:()=>v(!1),children:"✕"})]}),e.jsx("ul",{className:"nice-chart-ai__insights-list",children:_.map((C,A)=>e.jsxs("li",{className:"nice-chart-ai__insight",children:[e.jsx("span",{className:"nice-chart-ai__insight-icon",children:"•"}),C]},A))}),e.jsx("div",{className:"nice-chart-ai__insights-footer",children:e.jsxs("button",{type:"button",className:"nice-chart-ai__refresh",onClick:()=>T(),disabled:q,children:["🔄 ",r("chartAI.refresh","Refresh")]})})]}),y&&q&&e.jsx("div",{className:"nice-chart-ai__insights nice-chart-ai__insights--loading",children:e.jsxs("div",{className:"nice-chart-ai__loading-content",children:[e.jsx("span",{className:"nice-chart-ai__spinner"}),r("chartAI.generatingInsights","Generating insights...")]})})]})});function Ze(t,u){const o=t?typeof t=="number"?new Date(t):new Date(t):new Date,m=z=>z.toString().padStart(2,"0"),n=m(o.getHours()),f=m(o.getMinutes()),j=m(o.getSeconds()),S=o.getMilliseconds().toString().padStart(3,"0");switch(u){case"HH:mm:ss":return`${n}:${f}:${j}`;case"HH:mm":return`${n}:${f}`;case"mm:ss":return`${f}:${j}`;case"ss.SSS":return`${j}.${S}`;case"ISO":return o.toISOString();default:return`${n}:${f}:${j}`}}function Ie(t){if(t.length===0)return null;const u=Math.min(...t),o=Math.max(...t),m=t.reduce((f,j)=>f+j,0)/t.length,n=t[t.length-1];return{min:u,max:o,avg:m,current:n,count:t.length}}const De=x.forwardRef(({series:t,maxPoints:u=100,slidingWindow:o=!0,refreshRate:m=16,dataSource:n,width:f=600,height:j=400,title:S,showLegend:z=!0,showGrid:l=!0,yAxisLabel:g,xAxisLabel:b,stacked:p,zoomable:$,crosshair:w,annotations:i=[],legendInteractive:d,onDataPointClick:c,exportable:k,showControls:_=!0,showStatus:N=!0,initialPaused:y=!1,onDataReceived:v,onDataDropped:s,timeFormat:L="HH:mm:ss",showStats:r,thresholds:B=[],className:O,style:X},q)=>{const[U,re]=x.useState(()=>{var Y;const D=new Map;for(const ie of t)D.set(ie.name,((Y=ie.initialData)==null?void 0:Y.slice())??[]);return D}),[J,te]=x.useState([]),[T,G]=x.useState(y),[oe,ce]=x.useState(!1),C=x.useRef([]),A=x.useRef(Date.now()),V=x.useRef(null),Z=x.useCallback(()=>{const D=C.current;D.length!==0&&(C.current=[],re(Y=>{const ie=new Map(Y);for(const he of D){const me=ie.get(he.series);if(!me)continue;const fe=[...me,he.value];if(o&&fe.length>u){const pe=fe.length-u;s==null||s(pe,he.series),fe.splice(0,pe)}ie.set(he.series,fe)}return ie}),D.length>0&&te(Y=>{const ie=[...Y];for(const he of D){const me=he.category??Ze(he.timestamp,L);ie.push(me)}return o&&ie.length>u&&ie.splice(0,ie.length-u),ie}))},[o,u,L,s]),K=x.useCallback(()=>{const D=Date.now();D-A.current>=m&&(Z(),A.current=D),V.current=requestAnimationFrame(K)},[m,Z]);x.useEffect(()=>(T||(V.current=requestAnimationFrame(K)),()=>{V.current!==null&&(cancelAnimationFrame(V.current),V.current=null)}),[T,K]);const F=x.useCallback(D=>{if(T)return;const Y="points"in D?D.points:[D];for(const ie of Y)U.has(ie.series)&&(C.current.push(ie),v==null||v(ie))},[T,U,v]);x.useEffect(()=>{if(!n)return;const D=n.subscribe(F);let Y;return n.onStatusChange?Y=n.onStatusChange(ce):ce(!0),n.fetchHistory&&n.fetchHistory(u).then(ie=>{for(const he of ie)C.current.push(he);Z()}),()=>{D(),Y==null||Y()}},[n,F,u,Z]);const W=x.useMemo(()=>t.map(D=>({name:D.name,color:D.color,type:D.type,data:U.get(D.name)??[]})),[t,U]),H=x.useMemo(()=>{const D=[...i];for(const Y of B)D.push({type:"line",value:Y.value,color:Y.color,label:Y.label,dash:Y.style==="dashed"?"5,5":Y.style==="dotted"?"2,2":void 0});return D},[i,B]);x.useImperativeHandle(q,()=>({pause(){G(!0)},resume(){G(!1)},isPaused(){return T},clear(){re(D=>{const Y=new Map(D);for(const ie of Y.keys())Y.set(ie,[]);return Y}),te([]),C.current=[]},addPoint(D){F(D)},addPoints(D){F({points:D})},getData(D){return U.get(D)??[]},getCategories(){return J},exportData(){return{series:W,categories:J}},getStats(D){const Y=U.get(D);return Y?Ie(Y):null}}),[T,U,J,W,F]);const Q=x.useMemo(()=>{if(!r)return null;const D={};for(const[Y,ie]of U)D[Y]=Ie(ie);return D},[r,U]);return e.jsxs("div",{className:O,style:{position:"relative",...X},children:[N&&e.jsxs("div",{style:{position:"absolute",top:8,right:8,display:"flex",alignItems:"center",gap:4,fontSize:12,color:oe?"var(--color-success, #22c55e)":"var(--color-error, #ef4444)",zIndex:10},children:[e.jsx("span",{style:{width:8,height:8,borderRadius:"50%",backgroundColor:oe?"var(--color-success, #22c55e)":"var(--color-error, #ef4444)"}}),oe?"Live":"Disconnected"]}),_&&e.jsx("div",{style:{position:"absolute",top:8,left:8,display:"flex",gap:4,zIndex:10},children:e.jsx("button",{onClick:()=>G(D=>!D),style:{padding:"4px 8px",fontSize:12,border:"1px solid var(--border-color, #ddd)",borderRadius:4,background:T?"var(--warning-bg, #fef3c7)":"var(--bg-primary, #fff)",cursor:"pointer"},title:T?"Resume":"Pause",children:T?"▶":"⏸"})}),r&&Q&&e.jsx("div",{style:{position:"absolute",bottom:50,right:8,background:"rgba(255,255,255,0.9)",border:"1px solid var(--border-color, #ddd)",borderRadius:4,padding:8,fontSize:11,zIndex:10},children:Object.entries(Q).map(([D,Y])=>Y?e.jsxs("div",{style:{marginBottom:4},children:[e.jsx("strong",{children:D}),e.jsxs("div",{children:["Min: ",Y.min.toFixed(2)," | Max: ",Y.max.toFixed(2)]}),e.jsxs("div",{children:["Avg: ",Y.avg.toFixed(2)," | Now: ",Y.current.toFixed(2)]})]},D):null)}),e.jsx(Se,{series:W,categories:J,width:f,height:j,title:S,showLegend:z,showGrid:l,yAxisLabel:g,xAxisLabel:b,stacked:p,zoomable:$,crosshair:w,annotations:H,legendInteractive:d,onDataPointClick:c,exportable:k})]})});De.displayName="NiceLiveChart";const ue=["#3b82f6","#ef4444","#22c55e","#f59e0b","#8b5cf6","#ec4899","#06b6d4","#84cc16"],Ue=({data:t,width:u=400,height:o=400,innerRadius:m=0,title:n,showLegend:f=!0,showLabels:j=!0,className:S,style:z})=>{const l=u/2,g=(o-(f?30:0))/2+(n?10:0),b=Math.min(l,g)-40,p=t.reduce((i,d)=>i+d.value,0);let $=-Math.PI/2;const w=t.map((i,d)=>{const c=i.value/(p||1)*Math.PI*2,k=$;$+=c;const _=$,N=(k+_)/2,y=l+b*Math.cos(k),v=g+b*Math.sin(k),s=l+b*Math.cos(_),L=g+b*Math.sin(_),r=c>Math.PI?1:0,B=i.color||ue[d%ue.length];let O;if(m>0){const re=l+m*Math.cos(k),J=g+m*Math.sin(k),te=l+m*Math.cos(_),T=g+m*Math.sin(_);O=`M${y},${v} A${b},${b} 0 ${r},1 ${s},${L} L${te},${T} A${m},${m} 0 ${r},0 ${re},${J} Z`}else O=`M${l},${g} L${y},${v} A${b},${b} 0 ${r},1 ${s},${L} Z`;const X=l+b*.7*Math.cos(N),q=g+b*.7*Math.sin(N),U=p>0?Math.round(i.value/p*100):0;return{...i,path:O,labelX:X,labelY:q,pct:U,color:B}});return e.jsx("div",{className:`nice-piechart ${S||""}`,style:z,children:e.jsxs("svg",{viewBox:`0 0 ${u} ${o}`,preserveAspectRatio:"xMidYMid meet",width:"100%",height:"100%",style:{display:"block",maxWidth:"100%",maxHeight:"100%"},className:"nice-piechart__svg",children:[n&&e.jsx("text",{x:l,y:20,textAnchor:"middle",className:"nice-chart__title",children:n}),w.map((i,d)=>e.jsxs("g",{children:[e.jsx("path",{d:i.path,fill:i.color,stroke:"var(--bg-primary, #fff)",strokeWidth:2,children:e.jsx("title",{children:`${i.label}: ${i.value} (${i.pct}%)`})}),j&&i.pct>=5&&e.jsxs("text",{x:i.labelX,y:i.labelY,textAnchor:"middle",dominantBaseline:"middle",className:"nice-piechart__label",children:[i.pct,"%"]})]},d)),f&&e.jsx("g",{transform:`translate(10, ${o-25})`,children:t.map((i,d)=>e.jsxs("g",{transform:`translate(${d*100}, 0)`,children:[e.jsx("rect",{width:10,height:10,rx:2,fill:i.color||ue[d%ue.length]}),e.jsx("text",{x:14,y:9,className:"nice-chart__legend-text",children:i.label})]},d))})]})})},Ge=({series:t,categories:u,width:o=400,height:m=400,maxValue:n,title:f,showLegend:j=!0,className:S,style:z})=>{const l=o/2,g=(m-(j?30:0))/2+(f?10:0),b=Math.min(l,g)-60,p=u.length,$=n??Math.max(...t.flatMap(c=>c.data),1),w=Math.PI*2/p,i=5,d=(c,k)=>{const _=c*w-Math.PI/2,N=k/$*b;return{x:l+N*Math.cos(_),y:g+N*Math.sin(_)}};return e.jsx("div",{className:`nice-polarchart ${S||""}`,style:z,children:e.jsxs("svg",{width:o,height:m,className:"nice-polarchart__svg",children:[f&&e.jsx("text",{x:l,y:20,textAnchor:"middle",className:"nice-chart__title",children:f}),Array.from({length:i},(c,k)=>{const _=b*((k+1)/i);return e.jsx("circle",{cx:l,cy:g,r:_,fill:"none",stroke:"var(--border-color, #ddd)",strokeWidth:.5},k)}),u.map((c,k)=>{const _=d(k,$),N=d(k,$*1.22),y=k*w-Math.PI/2,v=Math.cos(y),s=Math.sin(y),L=v>.2?"start":v<-.2?"end":"middle",r=s>.2?"hanging":s<-.2?"auto":"middle";return e.jsxs("g",{children:[e.jsx("line",{x1:l,y1:g,x2:_.x,y2:_.y,stroke:"var(--border-color, #ddd)",strokeWidth:.5}),e.jsx("text",{x:N.x,y:N.y,textAnchor:L,dominantBaseline:r,className:"nice-chart__axis-label nice-chart__axis-label--polar",children:c})]},k)}),t.map((c,k)=>{const _=c.color||ue[k%ue.length],N=c.data.map((y,v)=>{const s=d(v,y);return`${s.x},${s.y}`}).join(" ");return e.jsxs("g",{children:[e.jsx("polygon",{points:N,fill:c.fill!==!1?_:"none",fillOpacity:.15,stroke:_,strokeWidth:2}),c.data.map((y,v)=>{const s=d(v,y);return e.jsx("circle",{cx:s.x,cy:s.y,r:3,fill:_,children:e.jsx("title",{children:`${c.name} - ${u[v]}: ${y}`})},v)})]},c.name)}),j&&e.jsx("g",{transform:`translate(10, ${m-25})`,children:t.map((c,k)=>e.jsxs("g",{transform:`translate(${k*100}, 0)`,children:[e.jsx("rect",{width:10,height:10,rx:2,fill:c.color||ue[k%ue.length]}),e.jsx("text",{x:14,y:9,className:"nice-chart__legend-text",children:c.name})]},k))})]})})},qe=({value:t,min:u=0,max:o=100,width:m=200,height:n=200,startAngle:f=225,endAngle:j=-45,color:S="var(--color-primary, #3b82f6)",trackColor:z,label:l,formatValue:g,ranges:b,className:p,style:$})=>{const w=m/2,i=n/2,d=Math.min(w,i)-20,c=Math.max(0,Math.min(1,(t-u)/(o-u||1))),k=r=>r*Math.PI/180,_=(f-j+360)%360||360,N=r=>({x:w+d*Math.cos(k(r)),y:i-d*Math.sin(k(r))}),y=(r,B)=>{const O=N(r),X=N(B),q=(r-B+360)%360>180?1:0;return`M${O.x},${O.y} A${d},${d} 0 ${q},1 ${X.x},${X.y}`},v=f-c*_,s=N(v);let L=S;if(b){for(const r of b)if(t>=r.start&&t<=r.end){L=r.color;break}}return e.jsx("div",{className:`nice-gauge nice-gauge--circular ${p||""}`,style:$,children:e.jsxs("svg",{width:m,height:n,children:[e.jsx("path",{d:y(f,j),fill:"none",stroke:z||"var(--border-color, #e2e8f0)",strokeWidth:12,strokeLinecap:"round"}),c>0&&e.jsx("path",{d:y(f,v),fill:"none",stroke:L,strokeWidth:12,strokeLinecap:"round"}),e.jsx("line",{x1:w,y1:i,x2:s.x,y2:s.y,stroke:"var(--text-primary, #333)",strokeWidth:2,strokeLinecap:"round"}),e.jsx("circle",{cx:w,cy:i,r:4,fill:"var(--text-primary, #333)"}),e.jsx("text",{x:w,y:i+d*.6,textAnchor:"middle",className:"nice-gauge__value",children:g?g(t):t}),l&&e.jsx("text",{x:w,y:i+d*.95,textAnchor:"middle",className:"nice-gauge__label",children:l})]})})},Te=({value:t,min:u=0,max:o=100,width:m=300,height:n=60,orientation:f="horizontal",color:j="var(--color-primary, #3b82f6)",label:S,formatValue:z,ranges:l,showTicks:g=!0,tickCount:b=5,className:p,style:$})=>{const w=f==="horizontal",i=w?m-40:n-40,d=Math.max(0,Math.min(1,(t-u)/(o-u||1))),c=10;let k=j;if(l){for(const N of l)if(t>=N.start&&t<=N.end){k=N.color;break}}const _=Array.from({length:b},(N,y)=>u+(o-u)*(y/(b-1)));return w?e.jsx("div",{className:`nice-gauge nice-gauge--linear ${p||""}`,style:$,children:e.jsxs("svg",{width:m,height:n,children:[e.jsx("text",{x:20+i*d,y:14,textAnchor:"middle",className:"nice-gauge__value",style:{fontSize:12},children:z?z(t):t}),e.jsx("rect",{x:20,y:n/2-c/2,width:i,height:c,rx:5,fill:"var(--border-color, #e2e8f0)"}),e.jsx("rect",{x:20,y:n/2-c/2,width:i*d,height:c,rx:5,fill:k}),e.jsx("polygon",{points:`${20+i*d},${n/2-c/2-2} ${20+i*d-5},${n/2-c/2-8} ${20+i*d+5},${n/2-c/2-8}`,fill:"var(--text-primary, #333)"}),g&&_.map((N,y)=>{const v=20+(N-u)/(o-u)*i;return e.jsx("text",{x:v,y:n/2+c/2+12,textAnchor:"middle",className:"nice-gauge__tick",children:N},y)}),S&&e.jsx("text",{x:m/2,y:n-2,textAnchor:"middle",className:"nice-gauge__label",children:S})]})}):e.jsx("div",{className:`nice-gauge nice-gauge--linear nice-gauge--vertical ${p||""}`,style:$,children:e.jsxs("svg",{width:m,height:n,children:[e.jsx("rect",{x:m/2-c/2,y:20,width:c,height:i,rx:5,fill:"var(--border-color, #e2e8f0)"}),e.jsx("rect",{x:m/2-c/2,y:20+i*(1-d),width:c,height:i*d,rx:5,fill:k}),e.jsx("text",{x:m/2,y:14,textAnchor:"middle",className:"nice-gauge__value",children:z?z(t):t}),S&&e.jsx("text",{x:m/2,y:n-4,textAnchor:"middle",className:"nice-gauge__label",children:S})]})})},Qe=({items:t,min:u=0,max:o=100,width:m=300,height:n=300,startAngle:f=225,endAngle:j=-45,formatValue:S,title:z,className:l,style:g})=>{const b=m/2,p=n/2,$=Math.min(b,p)-30,w=Math.min(20,$/(t.length+1)),i=4,d=_=>_*Math.PI/180,c=(f-j+360)%360||360,k=(_,N,y)=>{const v=b+_*Math.cos(d(N)),s=p-_*Math.sin(d(N)),L=b+_*Math.cos(d(y)),r=p-_*Math.sin(d(y)),B=(N-y+360)%360;return`M${v},${s} A${_},${_} 0 ${B>180?1:0},1 ${L},${r}`};return e.jsx("div",{className:`nice-bargauge ${l||""}`,style:g,children:e.jsxs("svg",{width:m,height:n,children:[z&&e.jsx("text",{x:b,y:20,textAnchor:"middle",className:"nice-chart__title",children:z}),t.map((_,N)=>{const y=$-N*(w+i),v=Math.max(0,Math.min(1,(_.value-u)/(o-u||1))),s=f-v*c,L=_.color||ue[N%ue.length];return e.jsxs("g",{children:[e.jsx("path",{d:k(y,f,j),fill:"none",stroke:"var(--border-color, #e2e8f0)",strokeWidth:w,strokeLinecap:"round"}),v>0&&e.jsx("path",{d:k(y,f,s),fill:"none",stroke:L,strokeWidth:w,strokeLinecap:"round"})]},N)}),e.jsx("g",{children:t.map((_,N)=>e.jsxs("text",{x:b,y:p-((t.length-1)/2-N)*16,textAnchor:"middle",dominantBaseline:"middle",className:"nice-gauge__value",style:{fontSize:12},children:[_.label?`${_.label}: `:"",S?S(_.value):_.value]},N))})]})})},Je=({data:t,width:u=120,height:o=30,type:m="line",color:n="var(--color-primary, #3b82f6)",showMinMax:f,showLastPoint:j=!0,className:S,style:z})=>{if(t.length===0)return null;const l=2,g=Math.min(...t),b=Math.max(...t),p=b-g||1,$=u-l*2,w=o-l*2,i=y=>l+y/(t.length-1||1)*$,d=y=>l+w-(y-g)/p*w;if(m==="bar"){const y=Math.max(1,$/t.length-1);return e.jsx("svg",{width:u,height:o,className:`nice-sparkline ${S||""}`,style:z,children:t.map((v,s)=>e.jsx("rect",{x:l+s/t.length*$,y:d(v),width:y,height:w-(d(v)-l),fill:n,rx:1},s))})}const c=t.map((y,v)=>`${i(v)},${d(y)}`).join(" "),k=t.indexOf(g),_=t.indexOf(b),N=t.length-1;return e.jsxs("svg",{width:u,height:o,className:`nice-sparkline ${S||""}`,style:z,children:[m==="area"&&e.jsx("polygon",{points:`${i(0)},${l+w} ${c} ${i(N)},${l+w}`,fill:n,opacity:.15}),e.jsx("polyline",{points:c,fill:"none",stroke:n,strokeWidth:1.5}),f&&e.jsx("circle",{cx:i(k),cy:d(g),r:2,fill:"#ef4444"}),f&&e.jsx("circle",{cx:i(_),cy:d(b),r:2,fill:"#22c55e"}),j&&e.jsx("circle",{cx:i(N),cy:d(t[N]),r:2,fill:n})]})},Ke={sm:{width:160,height:22,fontSize:11},md:{width:220,height:32,fontSize:12},lg:{width:320,height:44,fontSize:14}},et=({value:t,target:u,min:o=0,max:m=100,width:n,height:f,color:j="var(--color-primary, #3b82f6)",targetColor:S="var(--color-error, #ef4444)",size:z="md",label:l,labelPlacement:g="top",showValue:b=!1,showTarget:p=!1,formatValue:$=k=>String(k),state:w="normal",errorMessage:i,className:d,style:c})=>{const k=Ke[z],_=n??k.width,N=f??k.height,y=k.fontSize,v=4,s=_-v*2,L=N-v*2,r=Math.max(0,Math.min(1,(t-o)/(m-o||1))),B=u!=null?Math.max(0,Math.min(1,(u-o)/(m-o||1))):null,O=()=>w==="error"?e.jsx("div",{role:"alert",style:{width:_,height:N,display:"flex",alignItems:"center",justifyContent:"center",border:"1px dashed var(--color-error, #ef4444)",borderRadius:4,color:"var(--color-error, #ef4444)",fontSize:y,padding:"0 8px",boxSizing:"border-box"},children:i??"Error"}):w==="loading"?e.jsx("div",{role:"status","aria-label":"Loading",className:"nice-bullet__skeleton",style:{width:_,height:N,borderRadius:4,background:"linear-gradient(90deg, var(--bg-tertiary, #e5e7eb) 25%, var(--bg-secondary, #f3f4f6) 50%, var(--bg-tertiary, #e5e7eb) 75%)",backgroundSize:"200% 100%",animation:"nice-bullet-shimmer 1.4s linear infinite"}}):e.jsxs("svg",{width:_,height:N,role:"img","aria-label":typeof l=="string"?l:void 0,children:[e.jsx("rect",{x:v,y:v,width:s,height:L,rx:3,fill:"var(--border-color, #e2e8f0)"}),e.jsx("rect",{x:v,y:v+L*.2,width:s*r,height:L*.6,rx:2,fill:j}),B!=null&&e.jsx("line",{x1:v+s*B,y1:v+2,x2:v+s*B,y2:v+L-2,stroke:S,strokeWidth:2}),b&&e.jsx("text",{x:v+Math.max(s*r,4),y:N/2,dx:s*r>24?-4:4,textAnchor:s*r>24?"end":"start",dominantBaseline:"middle",fontSize:y,fill:s*r>24?"#fff":"var(--text-primary)",fontWeight:600,children:$(t)}),p&&B!=null&&e.jsxs("text",{x:v+s*B,y:v-1,textAnchor:"middle",fontSize:y-1,fill:S,fontWeight:600,children:["▼",$(u)]})]});if(g==="none"||!l)return e.jsxs("div",{className:`nice-bullet ${d||""}`,style:c,children:[O(),e.jsx("style",{children:ze})]});const X=g==="top"||g==="bottom",q=e.jsx("span",{className:"nice-bullet__label",style:{fontSize:y,fontWeight:600,color:"var(--text-primary)",...X?{marginBottom:g==="top"?4:0,marginTop:g==="bottom"?4:0}:{},...g==="left"?{marginRight:8}:{},...g==="right"?{marginLeft:8}:{}},children:l});return e.jsxs("div",{className:`nice-bullet nice-bullet--${g} ${d||""}`,style:{display:"inline-flex",flexDirection:X?"column":"row",alignItems:X?"flex-start":"center",...c},children:[(g==="top"||g==="left")&&q,O(),(g==="bottom"||g==="right")&&q,e.jsx("style",{children:ze})]})},ze=`
2
+ @keyframes nice-bullet-shimmer {
3
+ 0% { background-position: 200% 0; }
4
+ 100% { background-position: -200% 0; }
5
+ }
6
+ `,tt=({data:t,width:u=400,height:o=300,inverted:m,showLabels:n=!0,showValues:f=!0,title:j,className:S,style:z})=>{const l={top:j?30:10,bottom:10,x:40},g=u-l.x*2,b=o-l.top-l.bottom,p=m?[...t].reverse():t,$=Math.max(...p.map(i=>i.value),1),w=b/p.length;return e.jsx("div",{className:`nice-funnel ${S||""}`,style:z,children:e.jsxs("svg",{width:u,height:o,children:[j&&e.jsx("text",{x:u/2,y:20,textAnchor:"middle",className:"nice-chart__title",children:j}),p.map((i,d)=>{const c=i.value/$*g,k=d<p.length-1?p[d+1].value/$*g:c*.3,_=l.top+d*w,N=_+w,y=u/2,v=`${y-c/2},${_} ${y+c/2},${_} ${y+k/2},${N} ${y-k/2},${N}`,s=i.color||ue[d%ue.length];return e.jsxs("g",{children:[e.jsx("polygon",{points:v,fill:s,stroke:"var(--bg-primary, #fff)",strokeWidth:1,children:e.jsx("title",{children:`${i.label}: ${i.value}`})}),n&&e.jsx("text",{x:y,y:_+w/2-(f?4:0),textAnchor:"middle",dominantBaseline:"middle",className:"nice-funnel__label",children:i.label}),f&&e.jsx("text",{x:y,y:_+w/2+10,textAnchor:"middle",dominantBaseline:"middle",className:"nice-funnel__value",children:i.value})]},d)})]})})},Pe=({nodes:t,links:u,width:o=600,height:m=400,nodeWidth:n=20,nodePadding:f=10,title:j,className:S,style:z})=>{const l={top:j?40:20,bottom:20,left:20,right:20},g=o-l.left-l.right,b=m-l.top-l.bottom,p=new Set(u.map(r=>r.source)),$=new Set(u.map(r=>r.target)),w=t.filter(r=>p.has(r.id)&&!$.has(r.id)),i=t.filter(r=>$.has(r.id)),d=t.filter(r=>p.has(r.id)&&$.has(r.id)),c=[w,...d.length?[d]:[],i].filter(r=>r.length>0),k=c.length,_=new Map;t.forEach(r=>{const B=u.filter(X=>X.source===r.id).reduce((X,q)=>X+q.value,0),O=u.filter(X=>X.target===r.id).reduce((X,q)=>X+q.value,0);_.set(r.id,Math.max(B,O))});const N=c.map(r=>r.reduce((B,O)=>B+(_.get(O.id)||0),0)+(r.length-1)*f),y=Math.max(...N,1),v=new Map;c.forEach((r,B)=>{const O=l.left+B/(k-1||1)*(g-n);let X=0;r.forEach(q=>{const U=(_.get(q.id)||0)/y*b;v.set(q.id,{x:O,y:l.top+X,h:U}),X+=U+f})});const s=new Map,L=new Map;return t.forEach(r=>{s.set(r.id,0),L.set(r.id,0)}),e.jsx("div",{className:`nice-sankey ${S||""}`,style:z,children:e.jsxs("svg",{width:o,height:m,children:[j&&e.jsx("text",{x:o/2,y:20,textAnchor:"middle",className:"nice-chart__title",children:j}),u.map((r,B)=>{var C;const O=v.get(r.source),X=v.get(r.target);if(!O||!X)return null;const q=s.get(r.source)||0,U=L.get(r.target)||0,re=r.value/y*b;s.set(r.source,q+re),L.set(r.target,U+re);const J=O.x+n,te=O.y+q,T=X.x,G=X.y+U,oe=(J+T)/2,ce=((C=t.find(A=>A.id===r.source))==null?void 0:C.color)||ue[B%ue.length];return e.jsx("path",{d:`M${J},${te} C${oe},${te} ${oe},${G} ${T},${G} L${T},${G+re} C${oe},${G+re} ${oe},${te+re} ${J},${te+re} Z`,fill:ce,fillOpacity:.3,stroke:ce,strokeOpacity:.5,strokeWidth:.5,children:e.jsx("title",{children:`${r.source} → ${r.target}: ${r.value}`})},B)}),t.map((r,B)=>{const O=v.get(r.id);if(!O)return null;const X=r.color||ue[B%ue.length];return e.jsxs("g",{children:[e.jsx("rect",{x:O.x,y:O.y,width:n,height:Math.max(O.h,2),fill:X,rx:2}),e.jsx("text",{x:O.x<g/2?O.x+n+4:O.x-4,y:O.y+O.h/2,textAnchor:O.x<g/2?"start":"end",dominantBaseline:"middle",className:"nice-chart__legend-text",children:r.label})]},r.id)})]})})},at=Object.freeze(Object.defineProperty({__proto__:null,NiceSankey:Pe},Symbol.toStringTag,{value:"Module"})),rt=({data:t,min:u,max:o,start:m,end:n,onChange:f,width:j=500,height:S=100,step:z=1,formatValue:l,chartColor:g="var(--color-primary, #3b82f6)",className:b,style:p})=>{const $={top:10,bottom:30,left:10,right:10},w=j-$.left-$.right,i=S-$.top-$.bottom,d=y=>$.left+(y-u)/(o-u||1)*w,c=y=>{const v=Math.max(0,Math.min(1,(y-$.left)/w)),s=u+v*(o-u);return Math.round(s/z)*z},k=(y,v)=>{v.preventDefault();const s=v.target.closest("svg");if(!s)return;const L=B=>{const O=s.getBoundingClientRect(),X=c(B.clientX-O.left);y==="start"?f(Math.min(X,n),n):f(m,Math.max(X,m))},r=()=>{document.removeEventListener("pointermove",L),document.removeEventListener("pointerup",r)};document.addEventListener("pointermove",L),document.addEventListener("pointerup",r)},_=t?Math.min(...t):0,N=(t?Math.max(...t):1)-_||1;return e.jsx("div",{className:`nice-rangeselector ${b||""}`,style:p,children:e.jsxs("svg",{width:j,height:S,children:[t&&t.length>1&&e.jsx("polygon",{points:`${$.left},${$.top+i} ${t.map((y,v)=>`${$.left+v/(t.length-1)*w},${$.top+i-(y-_)/N*i}`).join(" ")} ${$.left+w},${$.top+i}`,fill:g,opacity:.15}),e.jsx("rect",{x:d(m),y:$.top,width:d(n)-d(m),height:i,fill:g,opacity:.1}),e.jsx("rect",{x:$.left,y:$.top,width:d(m)-$.left,height:i,fill:"var(--bg-secondary, #f5f5f5)",opacity:.6}),e.jsx("rect",{x:d(n),y:$.top,width:$.left+w-d(n),height:i,fill:"var(--bg-secondary, #f5f5f5)",opacity:.6}),e.jsx("rect",{x:d(m)-4,y:$.top,width:8,height:i,fill:g,rx:2,cursor:"ew-resize",onPointerDown:y=>k("start",y)}),e.jsx("rect",{x:d(n)-4,y:$.top,width:8,height:i,fill:g,rx:2,cursor:"ew-resize",onPointerDown:y=>k("end",y)}),e.jsx("text",{x:d(m),y:$.top+i+18,textAnchor:"middle",className:"nice-chart__axis-label",children:l?l(m):m}),e.jsx("text",{x:d(n),y:$.top+i+18,textAnchor:"middle",className:"nice-chart__axis-label",children:l?l(n):n})]})})},Re=({regions:t,width:u=600,height:o=400,viewBox:m="0 0 1000 600",colorRange:n=["var(--info-bg, #dbeafe)","var(--color-primary-active, #1d4ed8)"],maxValue:f,onRegionClick:j,selectedRegionId:S,title:z,showTooltip:l=!0,className:g,style:b})=>{const p=f??Math.max(...t.map(w=>w.value??0),1),$=w=>{const i=r=>[parseInt(r.slice(1,3),16),parseInt(r.slice(3,5),16),parseInt(r.slice(5,7),16)],[d,c,k]=i(n[0]),[_,N,y]=i(n[1]),v=Math.round(d+(_-d)*w),s=Math.round(c+(N-c)*w),L=Math.round(k+(y-k)*w);return`rgb(${v},${s},${L})`};return e.jsxs("div",{className:`nice-vectormap ${g||""}`,style:b,children:[z&&e.jsx("div",{className:"nice-vectormap__title",children:z}),e.jsx("svg",{width:u,height:o,viewBox:m,children:t.map(w=>{const i=w.value!=null?Math.max(0,Math.min(1,w.value/p)):0,d=w.value!=null?$(i):"var(--bg-tertiary, #e5e7eb)",c=w.id===S;return e.jsx("path",{d:w.path,fill:d,stroke:c?"var(--color-primary, #3b82f6)":"var(--border-color, #d1d5db)",strokeWidth:c?2:.5,cursor:j?"pointer":void 0,onClick:()=>j==null?void 0:j(w),children:l&&e.jsx("title",{children:`${w.name}${w.value!=null?`: ${w.value}`:""}`})},w.id)})})]})},nt=Object.freeze(Object.defineProperty({__proto__:null,NiceVectorMap:Re},Symbol.toStringTag,{value:"Module"})),it=`
7
+ .nice-forecast-chart {
8
+ display: flex;
9
+ flex-direction: column;
10
+ background: var(--nice-bg-primary, #ffffff);
11
+ border: 1px solid var(--nice-border-color, #e5e7eb);
12
+ border-radius: 0.5rem;
13
+ overflow: hidden;
14
+ }
15
+
16
+ .nice-forecast-chart__header {
17
+ display: flex;
18
+ align-items: center;
19
+ justify-content: space-between;
20
+ padding: 0.75rem 1rem;
21
+ border-bottom: 1px solid var(--nice-border-color, #e5e7eb);
22
+ }
23
+
24
+ .nice-forecast-chart__title {
25
+ font-size: 1rem;
26
+ font-weight: 600;
27
+ color: var(--nice-text-primary);
28
+ margin: 0;
29
+ }
30
+
31
+ .nice-forecast-chart__actions {
32
+ display: flex;
33
+ gap: 0.5rem;
34
+ }
35
+
36
+ .nice-forecast-chart__btn {
37
+ display: inline-flex;
38
+ align-items: center;
39
+ justify-content: center;
40
+ width: 2rem;
41
+ height: 2rem;
42
+ font-size: 1rem;
43
+ border-radius: 0.375rem;
44
+ cursor: pointer;
45
+ transition: all 0.15s ease;
46
+ border: 1px solid var(--nice-border-color, #d1d5db);
47
+ background: var(--nice-bg-primary, #ffffff);
48
+ color: var(--nice-text-secondary);
49
+ }
50
+
51
+ .nice-forecast-chart__btn:hover {
52
+ background: var(--nice-bg-hover, #f3f4f6);
53
+ color: var(--nice-text-primary);
54
+ }
55
+
56
+ .nice-forecast-chart__btn:disabled {
57
+ opacity: 0.5;
58
+ cursor: not-allowed;
59
+ }
60
+
61
+ .nice-forecast-chart__container {
62
+ position: relative;
63
+ width: 100%;
64
+ padding: 1rem;
65
+ }
66
+
67
+ .nice-forecast-chart__svg {
68
+ width: 100%;
69
+ overflow: visible;
70
+ }
71
+
72
+ .nice-forecast-chart__grid-line {
73
+ stroke: var(--nice-border-divider, #f3f4f6);
74
+ stroke-width: 1;
75
+ }
76
+
77
+ .nice-forecast-chart__axis-line {
78
+ stroke: var(--nice-border-color, #e5e7eb);
79
+ stroke-width: 1;
80
+ }
81
+
82
+ .nice-forecast-chart__axis-label {
83
+ font-size: 0.6875rem;
84
+ fill: var(--nice-text-secondary);
85
+ }
86
+
87
+ .nice-forecast-chart__axis-title {
88
+ font-size: 0.75rem;
89
+ font-weight: 500;
90
+ fill: var(--nice-text-primary);
91
+ }
92
+
93
+ .nice-forecast-chart__historical-line {
94
+ fill: none;
95
+ stroke-width: 2;
96
+ stroke-linecap: round;
97
+ stroke-linejoin: round;
98
+ }
99
+
100
+ .nice-forecast-chart__forecast-line {
101
+ fill: none;
102
+ stroke-width: 2;
103
+ stroke-linecap: round;
104
+ stroke-linejoin: round;
105
+ stroke-dasharray: 6, 4;
106
+ }
107
+
108
+ .nice-forecast-chart__confidence-band {
109
+ opacity: 0.2;
110
+ }
111
+
112
+ .nice-forecast-chart__forecast-region {
113
+ fill: var(--nice-bg-secondary, #f9fafb);
114
+ opacity: 0.5;
115
+ }
116
+
117
+ .nice-forecast-chart__point {
118
+ cursor: pointer;
119
+ transition: r 0.15s ease;
120
+ }
121
+
122
+ .nice-forecast-chart__point:hover {
123
+ r: 6;
124
+ }
125
+
126
+ .nice-forecast-chart__annotation-line {
127
+ stroke-dasharray: 4, 2;
128
+ stroke-width: 1;
129
+ }
130
+
131
+ .nice-forecast-chart__annotation-marker {
132
+ cursor: pointer;
133
+ transition: transform 0.15s ease;
134
+ }
135
+
136
+ .nice-forecast-chart__annotation-marker:hover {
137
+ transform: scale(1.2);
138
+ }
139
+
140
+ .nice-forecast-chart__reference-line {
141
+ stroke-width: 1;
142
+ }
143
+
144
+ .nice-forecast-chart__reference-label {
145
+ font-size: 0.625rem;
146
+ fill: var(--nice-text-secondary);
147
+ }
148
+
149
+ .nice-forecast-chart__cash-runway {
150
+ pointer-events: none;
151
+ }
152
+
153
+ .nice-forecast-chart__cash-runway-line {
154
+ stroke: #ef4444;
155
+ stroke-width: 2;
156
+ stroke-dasharray: 8, 4;
157
+ }
158
+
159
+ .nice-forecast-chart__cash-runway-label-bg {
160
+ fill: #ef4444;
161
+ rx: 4;
162
+ }
163
+
164
+ .nice-forecast-chart__cash-runway-label {
165
+ font-size: 0.6875rem;
166
+ font-weight: 600;
167
+ fill: #ffffff;
168
+ }
169
+
170
+ .nice-forecast-chart__cash-runway-date {
171
+ font-size: 0.625rem;
172
+ fill: #ef4444;
173
+ font-weight: 500;
174
+ }
175
+
176
+ .nice-forecast-chart__tooltip {
177
+ position: absolute;
178
+ pointer-events: none;
179
+ z-index: 100;
180
+ padding: 0.75rem;
181
+ background: var(--nice-bg-primary, #ffffff);
182
+ border: 1px solid var(--nice-border-color, #e5e7eb);
183
+ border-radius: 0.5rem;
184
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
185
+ font-size: 0.8125rem;
186
+ max-width: 250px;
187
+ }
188
+
189
+ .nice-forecast-chart__tooltip-date {
190
+ font-weight: 600;
191
+ color: var(--nice-text-primary);
192
+ margin-bottom: 0.5rem;
193
+ padding-bottom: 0.5rem;
194
+ border-bottom: 1px solid var(--nice-border-divider, #f3f4f6);
195
+ }
196
+
197
+ .nice-forecast-chart__tooltip-item {
198
+ display: flex;
199
+ align-items: center;
200
+ gap: 0.5rem;
201
+ margin-bottom: 0.25rem;
202
+ }
203
+
204
+ .nice-forecast-chart__tooltip-color {
205
+ width: 10px;
206
+ height: 10px;
207
+ border-radius: 2px;
208
+ flex-shrink: 0;
209
+ }
210
+
211
+ .nice-forecast-chart__tooltip-label {
212
+ color: var(--nice-text-secondary);
213
+ flex: 1;
214
+ }
215
+
216
+ .nice-forecast-chart__tooltip-value {
217
+ font-weight: 600;
218
+ color: var(--nice-text-primary);
219
+ font-variant-numeric: tabular-nums;
220
+ }
221
+
222
+ .nice-forecast-chart__tooltip-confidence {
223
+ font-size: 0.75rem;
224
+ color: var(--nice-text-tertiary);
225
+ }
226
+
227
+ .nice-forecast-chart__legend {
228
+ display: flex;
229
+ flex-wrap: wrap;
230
+ gap: 1rem;
231
+ padding: 0.75rem 1rem;
232
+ border-top: 1px solid var(--nice-border-color, #e5e7eb);
233
+ }
234
+
235
+ .nice-forecast-chart__legend-item {
236
+ display: flex;
237
+ align-items: center;
238
+ gap: 0.375rem;
239
+ font-size: 0.8125rem;
240
+ color: var(--nice-text-secondary);
241
+ cursor: pointer;
242
+ user-select: none;
243
+ transition: opacity 0.15s ease;
244
+ }
245
+
246
+ .nice-forecast-chart__legend-item:hover {
247
+ color: var(--nice-text-primary);
248
+ }
249
+
250
+ .nice-forecast-chart__legend-item--hidden {
251
+ opacity: 0.4;
252
+ }
253
+
254
+ .nice-forecast-chart__legend-color {
255
+ width: 16px;
256
+ height: 3px;
257
+ border-radius: 1px;
258
+ }
259
+
260
+ .nice-forecast-chart__legend-color--dashed {
261
+ background: repeating-linear-gradient(
262
+ 90deg,
263
+ currentColor,
264
+ currentColor 4px,
265
+ transparent 4px,
266
+ transparent 6px
267
+ );
268
+ }
269
+
270
+ .nice-forecast-chart__empty {
271
+ display: flex;
272
+ align-items: center;
273
+ justify-content: center;
274
+ height: 300px;
275
+ color: var(--nice-text-secondary);
276
+ }
277
+
278
+ /* Dark mode */
279
+ .dark .nice-forecast-chart {
280
+ background: var(--nice-bg-primary-dark, #111827);
281
+ border-color: var(--nice-border-color-dark, #374151);
282
+ }
283
+
284
+ .dark .nice-forecast-chart__tooltip {
285
+ background: var(--nice-bg-secondary-dark, #1f2937);
286
+ border-color: var(--nice-border-color-dark, #374151);
287
+ }
288
+
289
+ .dark .nice-forecast-chart__forecast-region {
290
+ fill: var(--nice-bg-secondary-dark, #1f2937);
291
+ }
292
+ `,Le=["var(--color-primary, #3b82f6)","var(--color-success, #10b981)","var(--color-warning, #f59e0b)","var(--color-error, #ef4444)","var(--color-accent, #8b5cf6)","var(--color-accent-pink, #ec4899)","var(--color-info, #06b6d4)","#f97316"];function xe(t){return t instanceof Date?t:new Date(t)}function Ae(t,u="pl-PL"){return t.toLocaleDateString(u,{year:"numeric",month:"short",day:"numeric"})}function Me(t,u="pl-PL"){return new Intl.NumberFormat(u,{minimumFractionDigits:0,maximumFractionDigits:2}).format(t)}x.forwardRef(function(t,u){var ae,ee;const{scenarios:o,data:m,annotations:n=[],referenceLines:f=[],forecastStartDate:j,cashRunway:S,xAxis:z,yAxis:l,confidenceBands:g=[{level:95,color:"var(--color-primary, #3b82f6)",opacity:.15}],tooltip:b,legend:p={enabled:!0,position:"bottom",interactive:!0},height:$=350,showForecastRegion:w=!0,lineWidth:i=2,showPoints:d=!1,pointRadius:c=4,enableZoom:k=!1,zoomEnabled:_,animationDuration:N=300,showLegend:y,responsive:v=!0,onPointClick:s,onAnnotationClick:L,onScenarioToggle:r,onViewportChange:B,size:O="medium",disabled:X=!1,labels:q={},locale:U="pl-PL",className:re,style:J}=t,te=o&&o.length>0?o:m?[{id:"default",name:"Series",data:m}]:[],T={...p,enabled:y??p.enabled},[G,oe]=x.useState(()=>te.map((a,I)=>({...a,color:a.color??Le[I%Le.length],visible:a.visible!==!1}))),[ce,C]=x.useState(null),[A,V]=x.useState({x:0,y:0}),Z=x.useRef(null),K=x.useRef(null),F={top:20,right:30,bottom:40,left:60},[W,H]=x.useState({width:600,height:typeof $=="number"?$:350});x.useEffect(()=>{if(!v||!Z.current)return;const a=new ResizeObserver(I=>{for(const P of I)H(h=>({width:P.contentRect.width,height:h.height}))});return a.observe(Z.current),()=>a.disconnect()},[v]),x.useEffect(()=>{const a="nice-forecast-chart-styles";if(!document.getElementById(a)){const I=document.createElement("style");I.id=a,I.textContent=it,document.head.appendChild(I)}},[]);const{xScale:Q,yScale:D,allDates:Y,minY:ie,maxY:he}=x.useMemo(()=>{const a=G.filter(de=>de.visible!==!1).flatMap(de=>de.data);if(a.length===0)return{xScale:()=>0,yScale:()=>0,allDates:[],minY:0,maxY:100};const I=a.map(de=>xe(de.date).getTime()),P=Math.min(...I),h=Math.max(...I),R=a.flatMap(de=>[de.value,de.forecast,de.lowerBound,de.upperBound]).filter(de=>de!=null),E=(l==null?void 0:l.min)??Math.min(...R)*.95,ne=(l==null?void 0:l.max)??Math.max(...R)*1.05,se=W.width-F.left-F.right,le=W.height-F.top-F.bottom,ge=de=>{const Ce=typeof de=="number"?de:de.getTime();return F.left+(Ce-P)/(h-P)*se},$e=de=>F.top+le-(de-E)/(ne-E)*le,Ne=[...new Set(I)].sort((de,Ce)=>de-Ce).map(de=>new Date(de));return{xScale:ge,yScale:$e,allDates:Ne,minY:E,maxY:ne}},[G,W,F,l]),me=j?xe(j):null,fe=x.useMemo(()=>{if(!(S!=null&&S.enabled))return null;const a=S.threshold??0,I=S.scenarioId?G.find(h=>h.id===S.scenarioId&&h.visible!==!1):G.find(h=>h.visible!==!1);if(!I)return null;const P=I.data.sort((h,R)=>xe(h.date).getTime()-xe(R.date).getTime());for(let h=1;h<P.length;h++){const R=P[h-1],E=P[h],ne=R.forecast??R.value,se=E.forecast??E.value;if(ne!=null&&se!=null&&ne>a&&se<=a){const le=(ne-a)/(ne-se),ge=xe(R.date).getTime(),$e=xe(E.date).getTime(),Ne=ge+le*($e-ge);return new Date(Ne)}}return null},[S,G]),pe=x.useCallback((a,I)=>{const P=a.filter(h=>h[I]!=null).map(h=>({x:Q(xe(h.date)),y:D(h[I])}));return P.length===0?"":`M ${P.map(h=>`${h.x},${h.y}`).join(" L ")}`},[Q,D]),_e=x.useCallback(a=>{const I=a.filter(R=>R.lowerBound!=null&&R.upperBound!=null);if(I.length===0)return"";const P=I.map(R=>({x:Q(xe(R.date)),y:D(R.upperBound)})),h=I.map(R=>({x:Q(xe(R.date)),y:D(R.lowerBound)})).reverse();return`M ${P.map(R=>`${R.x},${R.y}`).join(" L ")} L ${h.map(R=>`${R.x},${R.y}`).join(" L ")} Z`},[Q,D]),be=x.useCallback(a=>{if(!K.current||(b==null?void 0:b.enabled)===!1)return;const I=K.current.getBoundingClientRect(),P=a.clientX-I.left;a.clientY-I.top;let h=null,R=1/0;for(const E of Y){const ne=Q(E),se=Math.abs(ne-P);se<R&&(R=se,h=E)}if(h&&R<50){const E=G.filter(se=>se.visible!==!1).map(se=>{const le=se.data.find(ge=>xe(ge.date).getTime()===h.getTime());return{scenario:se,value:le==null?void 0:le.value,forecast:le==null?void 0:le.forecast,lowerBound:le==null?void 0:le.lowerBound,upperBound:le==null?void 0:le.upperBound}}),ne=n.filter(se=>Math.abs(xe(se.date).getTime()-h.getTime())<864e5);C({date:h,values:E,annotations:ne}),V({x:a.clientX-I.left+10,y:a.clientY-I.top-10})}else C(null)},[Q,Y,G,n,b]),ye=x.useCallback(a=>{if(!T.interactive)return;oe(P=>P.map(h=>h.id===a?{...h,visible:!h.visible}:h));const I=G.find(P=>P.id===a);I&&(r==null||r(a,!I.visible))},[T.interactive,G,r]);x.useImperativeHandle(u,()=>({getScenarios:()=>G,updateScenario:(a,I)=>{oe(P=>P.map(h=>h.id===a?{...h,data:I}:h))},toggleScenario:ye,setZoomRange:()=>{},resetZoom:()=>{},exportImage:a=>{if(!K.current)return null;const I=K.current,P=new XMLSerializer().serializeToString(I);return`data:image/svg+xml;base64,${btoa(P)}`},getDataAtDate:a=>{const I=G.filter(P=>P.visible!==!1).map(P=>{const h=P.data.find(R=>xe(R.date).getTime()===a.getTime());return{scenario:P,value:h==null?void 0:h.value,forecast:h==null?void 0:h.forecast,lowerBound:h==null?void 0:h.lowerBound,upperBound:h==null?void 0:h.upperBound}});return{date:a,values:I,annotations:n.filter(P=>xe(P.date).getTime()===a.getTime())}}}),[G,n,ye]),W.width-F.left-F.right;const ke=W.height-F.top-F.bottom,je=x.useMemo(()=>{const a=(l==null?void 0:l.tickCount)??5,I=[],P=(he-ie)/(a-1);for(let h=0;h<a;h++)I.push(ie+P*h);return I},[ie,he,l==null?void 0:l.tickCount]),M=x.useMemo(()=>{const a=(z==null?void 0:z.tickCount)??6;if(Y.length===0)return[];const I=Math.max(1,Math.floor(Y.length/(a-1)));return Y.filter((P,h)=>h%I===0||h===Y.length-1)},[Y,z==null?void 0:z.tickCount]);return G.length===0||G.every(a=>a.data.length===0)?e.jsx("div",{className:`nice-forecast-chart ${re??""}`,style:J,children:e.jsx("div",{className:"nice-forecast-chart__empty",children:q.noData??"No data available"})}):e.jsxs("div",{className:`nice-forecast-chart ${re??""}`,style:{...J,height:$},children:[e.jsxs("div",{ref:Z,className:"nice-forecast-chart__container",children:[e.jsxs("svg",{ref:K,className:"nice-forecast-chart__svg",width:W.width,height:W.height,onMouseMove:be,onMouseLeave:()=>C(null),children:[(l==null?void 0:l.showGrid)!==!1&&je.map(a=>e.jsx("line",{className:"nice-forecast-chart__grid-line",x1:F.left,x2:W.width-F.right,y1:D(a),y2:D(a)},a)),w&&me&&e.jsx("rect",{className:"nice-forecast-chart__forecast-region",x:Q(me),y:F.top,width:W.width-F.right-Q(me),height:ke}),f.map(a=>e.jsxs("g",{children:[e.jsx("line",{className:"nice-forecast-chart__reference-line",x1:F.left,x2:W.width-F.right,y1:D(a.value),y2:D(a.value),stroke:a.color??"var(--text-muted, #9ca3af)",strokeDasharray:a.dashArray??"4,2"}),a.label&&e.jsx("text",{className:"nice-forecast-chart__reference-label",x:W.width-F.right-4,y:D(a.value)-4,textAnchor:"end",children:a.label})]},a.id)),fe&&(S==null?void 0:S.enabled)&&e.jsxs("g",{className:"nice-forecast-chart__cash-runway",children:[e.jsx("line",{className:"nice-forecast-chart__cash-runway-line",x1:Q(fe),x2:Q(fe),y1:F.top,y2:W.height-F.bottom,stroke:S.color??"var(--color-error, #ef4444)"}),S.showLabel!==!1&&e.jsxs(e.Fragment,{children:[e.jsx("rect",{className:"nice-forecast-chart__cash-runway-label-bg",x:Q(fe)-60,y:F.top-2,width:120,height:S.showDate!==!1?32:20,fill:S.color??"var(--color-error, #ef4444)",rx:4}),e.jsx("text",{className:"nice-forecast-chart__cash-runway-label",x:Q(fe),y:F.top+12,textAnchor:"middle",fill:"#ffffff",children:S.label??q.cashRunsOut??"💰 Cash runs out"}),S.showDate!==!1&&e.jsx("text",{className:"nice-forecast-chart__cash-runway-label",x:Q(fe),y:F.top+26,textAnchor:"middle",fill:"#ffffff",style:{fontSize:"0.625rem",opacity:.9},children:Ae(fe,U)})]})]}),G.filter(a=>a.visible!==!1&&a.showConfidenceBand).map(a=>e.jsx("path",{className:"nice-forecast-chart__confidence-band",d:_e(a.data),fill:a.color},`band-${a.id}`)),G.filter(a=>a.visible!==!1).map(a=>{const I=me?a.data.filter(h=>xe(h.date)<me):a.data.filter(h=>h.value!=null),P=me?a.data.filter(h=>xe(h.date)>=me):a.data.filter(h=>h.forecast!=null);return e.jsxs("g",{children:[e.jsx("path",{className:"nice-forecast-chart__historical-line",d:pe(I,"value"),stroke:a.color,strokeWidth:i}),e.jsx("path",{className:"nice-forecast-chart__forecast-line",d:pe(P,me?"value":"forecast"),stroke:a.color,strokeWidth:i}),P.length>0&&a.data.some(h=>h.forecast!=null)&&e.jsx("path",{className:"nice-forecast-chart__forecast-line",d:pe(a.data,"forecast"),stroke:a.color,strokeWidth:i}),d&&a.data.map((h,R)=>{const E=h.value??h.forecast;return E==null?null:e.jsx("circle",{className:"nice-forecast-chart__point",cx:Q(xe(h.date)),cy:D(E),r:c,fill:a.color,onClick:()=>s==null?void 0:s(h,a)},R)})]},a.id)}),n.map(a=>{const I=Q(xe(a.date));return e.jsxs("g",{className:"nice-forecast-chart__annotation-marker",onClick:()=>L==null?void 0:L(a),children:[a.showLine!==!1&&e.jsx("line",{className:"nice-forecast-chart__annotation-line",x1:I,x2:I,y1:F.top,y2:W.height-F.bottom,stroke:a.color??"var(--text-muted, #9ca3af)"}),e.jsx("circle",{cx:I,cy:F.top+10,r:8,fill:a.color??"var(--text-muted, #9ca3af)"}),e.jsx("text",{x:I,y:F.top+14,textAnchor:"middle",fill:"white",fontSize:"10",children:a.icon??"!"})]},a.id)}),e.jsx("line",{className:"nice-forecast-chart__axis-line",x1:F.left,x2:F.left,y1:F.top,y2:W.height-F.bottom}),e.jsx("line",{className:"nice-forecast-chart__axis-line",x1:F.left,x2:W.width-F.right,y1:W.height-F.bottom,y2:W.height-F.bottom}),je.map(a=>e.jsx("text",{className:"nice-forecast-chart__axis-label",x:F.left-8,y:D(a)+4,textAnchor:"end",children:l!=null&&l.format?l.format(a):Me(a,U)},a)),M.map(a=>e.jsx("text",{className:"nice-forecast-chart__axis-label",x:Q(a),y:W.height-F.bottom+16,textAnchor:"middle",children:z!=null&&z.format?z.format(a):Ae(a,U)},a.getTime())),(l==null?void 0:l.title)&&e.jsx("text",{className:"nice-forecast-chart__axis-title",x:15,y:W.height/2,textAnchor:"middle",transform:`rotate(-90, 15, ${W.height/2})`,children:l.title})]}),ce&&e.jsxs("div",{className:"nice-forecast-chart__tooltip",style:{left:A.x,top:A.y},children:[e.jsx("div",{className:"nice-forecast-chart__tooltip-date",children:Ae(ce.date,U)}),ce.values.map(a=>{const I=a.value??a.forecast;return I==null?null:e.jsxs("div",{className:"nice-forecast-chart__tooltip-item",children:[e.jsx("span",{className:"nice-forecast-chart__tooltip-color",style:{background:a.scenario.color}}),e.jsx("span",{className:"nice-forecast-chart__tooltip-label",children:a.scenario.name}),e.jsx("span",{className:"nice-forecast-chart__tooltip-value",children:Me(I,U)})]},a.scenario.id)}),ce.values.some(a=>a.lowerBound!=null)&&e.jsxs("div",{className:"nice-forecast-chart__tooltip-confidence",children:[q.confidence??"CI",":"," ",Me(((ae=ce.values[0])==null?void 0:ae.lowerBound)??0,U)," –"," ",Me(((ee=ce.values[0])==null?void 0:ee.upperBound)??0,U)]})]})]}),T.enabled&&e.jsx("div",{className:"nice-forecast-chart__legend",children:G.map(a=>e.jsxs("div",{className:`nice-forecast-chart__legend-item ${a.visible===!1?"nice-forecast-chart__legend-item--hidden":""}`,onClick:()=>ye(a.id),children:[e.jsx("span",{className:`nice-forecast-chart__legend-color ${a.isBase?"":"nice-forecast-chart__legend-color--dashed"}`,style:{background:a.color}}),a.name]},a.id))})]})});const st=["var(--color-primary, #3b82f6)","var(--color-error, #ef4444)","var(--color-success, #22c55e)","var(--color-warning, #f59e0b)","var(--color-accent, #8b5cf6)","var(--color-accent-pink, #ec4899)","var(--color-info, #06b6d4)","#84cc16","#f97316","var(--color-accent, #6366f1)"],Be=x.forwardRef((t,u)=>{var oe,ce;const{levels:o,initialLevelId:m,chartType:n="bar",width:f=600,height:j=400,showBreadcrumbs:S=!0,showBackButton:z=!0,animationDuration:l=300,onLevelChange:g,onItemClick:b,colors:p=st,showValues:$=!0,showLegend:w=!0,className:i,style:d,...c}=t,[k,_]=x.useState(m||((oe=o[0])==null?void 0:oe.id)),[N,y]=x.useState([m||((ce=o[0])==null?void 0:ce.id)]),[v,s]=x.useState(!1),[L,r]=x.useState("in"),B=x.useMemo(()=>o.find(C=>C.id===k),[o,k]),O=x.useCallback(C=>{o.find(A=>A.id===C)&&(r("in"),s(!0),setTimeout(()=>{_(C),y(A=>[...A,C]),g==null||g(C,[...N,C]),s(!1)},l/2))},[o,N,l,g]),X=x.useCallback(()=>{if(N.length<=1)return;r("out"),s(!0);const C=N.slice(0,-1),A=C[C.length-1];setTimeout(()=>{_(A),y(C),g==null||g(A,C),s(!1)},l/2)},[N,l,g]),q=x.useCallback(()=>{var A;const C=(A=o[0])==null?void 0:A.id;C&&(r("out"),s(!0),setTimeout(()=>{_(C),y([C]),g==null||g(C,[C]),s(!1)},l/2))},[o,l,g]);x.useImperativeHandle(u,()=>({drillDown:O,drillUp:X,resetToRoot:q,getCurrentLevel:()=>k,getPath:()=>N}),[O,X,q,k,N]);const U=x.useCallback((C,A)=>{b==null||b(C,k);const V=o.find(Z=>{var K;return Z.parentId===k&&Z.id===((K=C.metadata)==null?void 0:K.childLevelId)});V&&O(V.id)},[k,o,O,b]),re=x.useMemo(()=>(B==null?void 0:B.data.reduce((C,A)=>C+A.value,0))||0,[B]),J=x.useMemo(()=>N.map(C=>{var A;return((A=o.find(V=>V.id===C))==null?void 0:A.label)||C}),[N,o]),te=()=>{if(!B)return null;const C=B.data,A=Math.max(...C.map(Z=>Z.value)),V=Math.min(40,(j-100)/C.length-8);return e.jsx("div",{className:"nice-drilldown-bars",children:C.map((Z,K)=>{const F=Z.value/A*100;return e.jsxs("div",{className:"nice-drilldown-bar-row",onClick:()=>U(Z,K),children:[e.jsx("span",{className:"nice-drilldown-bar-label",children:Z.label||`Item ${K+1}`}),e.jsx("div",{className:"nice-drilldown-bar-track",children:e.jsx("div",{className:"nice-drilldown-bar-fill",style:{width:`${F}%`,backgroundColor:Z.color||p[K%p.length],height:V}})}),$&&e.jsx("span",{className:"nice-drilldown-bar-value",children:Z.value.toLocaleString()})]},K)})})},T=()=>{if(!B)return null;const C=B.data,A=f/2,V=(j-60)/2+30,Z=Math.min(A,V)-40;let K=-90;const F=C.map((W,H)=>{const Q=W.value/re*360,D=K+Q,Y=Q>180?1:0,ie=K*Math.PI/180,he=D*Math.PI/180,me=A+Z*Math.cos(ie),fe=V+Z*Math.sin(ie),pe=A+Z*Math.cos(he),_e=V+Z*Math.sin(he),be=(K+Q/2)*Math.PI/180,ye=A+Z*.7*Math.cos(be),ke=V+Z*.7*Math.sin(be),je=`M ${A} ${V} L ${me} ${fe} A ${Z} ${Z} 0 ${Y} 1 ${pe} ${_e} Z`;return K=D,{path:je,color:W.color||p[H%p.length],label:W.label||`Item ${H+1}`,value:W.value,percentage:(W.value/re*100).toFixed(1),labelX:ye,labelY:ke,item:W,index:H}});return e.jsx("svg",{width:f,height:j-40,className:"nice-drilldown-pie",children:e.jsx("g",{children:F.map((W,H)=>e.jsxs("g",{onClick:()=>U(W.item,W.index),children:[e.jsx("path",{d:W.path,fill:W.color,stroke:"white",strokeWidth:2,className:"nice-drilldown-pie-slice"}),$&&parseFloat(W.percentage)>5&&e.jsxs("text",{x:W.labelX,y:W.labelY,textAnchor:"middle",dominantBaseline:"middle",fill:"white",fontSize:"12",fontWeight:"600",children:[W.percentage,"%"]})]},H))})})},G=()=>{if(!B)return null;const C=B.data,A=Math.max(...C.map(K=>K.value)),V=Math.min(60,(f-100)/C.length-8),Z=j-100;return e.jsx("svg",{width:f,height:j-40,className:"nice-drilldown-columns",children:e.jsxs("g",{transform:"translate(50, 20)",children:[[0,.25,.5,.75,1].map((K,F)=>e.jsxs("g",{children:[e.jsx("line",{x1:0,y1:Z*(1-K),x2:f-80,y2:Z*(1-K),stroke:"#e5e7eb",strokeDasharray:K===0?void 0:"4"}),e.jsx("text",{x:-8,y:Z*(1-K),textAnchor:"end",dominantBaseline:"middle",fontSize:"11",fill:"#6b7280",children:Math.round(A*K).toLocaleString()})]},F)),C.map((K,F)=>{const W=K.value/A*Z,H=F*((f-100)/C.length)+((f-100)/C.length-V)/2;return e.jsxs("g",{onClick:()=>U(K,F),children:[e.jsx("rect",{x:H,y:Z-W,width:V,height:W,fill:K.color||p[F%p.length],rx:4,className:"nice-drilldown-column-bar"}),e.jsx("text",{x:H+V/2,y:Z+16,textAnchor:"middle",fontSize:"11",fill:"#374151",children:(K.label||`${F+1}`).slice(0,10)}),$&&e.jsx("text",{x:H+V/2,y:Z-W-8,textAnchor:"middle",fontSize:"11",fill:"#374151",fontWeight:"500",children:K.value.toLocaleString()})]},F)})]})})};return e.jsxs("div",{className:`nice-drilldown-chart ${v?`animating ${L}`:""} ${i||""}`,style:{width:f,...d},...c,children:[e.jsxs("div",{className:"nice-drilldown-header",children:[z&&N.length>1&&e.jsx("button",{className:"nice-drilldown-back",onClick:X,children:"← Wstecz"}),S&&e.jsx("div",{className:"nice-drilldown-breadcrumbs",children:J.map((C,A)=>e.jsxs(x.Fragment,{children:[A>0&&e.jsx("span",{className:"nice-drilldown-separator",children:"/"}),e.jsx("span",{className:`nice-drilldown-crumb ${A===J.length-1?"active":""}`,onClick:()=>{if(A<J.length-1){const V=N.slice(0,A+1);y(V),_(V[V.length-1])}},children:C})]},A))})]}),e.jsxs("div",{className:"nice-drilldown-content",style:{height:j-40},children:[n==="bar"&&te(),n==="pie"&&T(),n==="column"&&G()]}),w&&B&&e.jsx("div",{className:"nice-drilldown-legend",children:B.data.map((C,A)=>e.jsxs("div",{className:"nice-drilldown-legend-item",children:[e.jsx("span",{className:"nice-drilldown-legend-color",style:{backgroundColor:C.color||p[A%p.length]}}),e.jsx("span",{className:"nice-drilldown-legend-label",children:C.label||`Item ${A+1}`})]},A))}),e.jsx("style",{children:`
293
+ .nice-drilldown-chart {
294
+ font-family: system-ui, -apple-system, sans-serif;
295
+ background: white;
296
+ border-radius: 8px;
297
+ overflow: hidden;
298
+ }
299
+
300
+ .nice-drilldown-header {
301
+ display: flex;
302
+ align-items: center;
303
+ gap: 12px;
304
+ padding: 12px 16px;
305
+ border-bottom: 1px solid var(--border-color, #e5e7eb);
306
+ min-height: 40px;
307
+ }
308
+
309
+ .nice-drilldown-back {
310
+ background: #f3f4f6;
311
+ border: none;
312
+ padding: 6px 12px;
313
+ border-radius: 6px;
314
+ cursor: pointer;
315
+ font-size: 13px;
316
+ color: #374151;
317
+ transition: background 0.2s;
318
+ }
319
+
320
+ .nice-drilldown-back:hover {
321
+ background: #e5e7eb;
322
+ }
323
+
324
+ .nice-drilldown-breadcrumbs {
325
+ display: flex;
326
+ align-items: center;
327
+ gap: 4px;
328
+ font-size: 13px;
329
+ }
330
+
331
+ .nice-drilldown-separator {
332
+ color: #9ca3af;
333
+ }
334
+
335
+ .nice-drilldown-crumb {
336
+ color: #6b7280;
337
+ cursor: pointer;
338
+ }
339
+
340
+ .nice-drilldown-crumb:hover:not(.active) {
341
+ color: #3b82f6;
342
+ }
343
+
344
+ .nice-drilldown-crumb.active {
345
+ color: #111827;
346
+ font-weight: 500;
347
+ cursor: default;
348
+ }
349
+
350
+ .nice-drilldown-content {
351
+ padding: 16px;
352
+ transition: opacity 0.15s, transform 0.15s;
353
+ }
354
+
355
+ .nice-drilldown-chart.animating .nice-drilldown-content {
356
+ opacity: 0;
357
+ }
358
+
359
+ .nice-drilldown-chart.animating.in .nice-drilldown-content {
360
+ transform: translateX(20px);
361
+ }
362
+
363
+ .nice-drilldown-chart.animating.out .nice-drilldown-content {
364
+ transform: translateX(-20px);
365
+ }
366
+
367
+ .nice-drilldown-bars {
368
+ display: flex;
369
+ flex-direction: column;
370
+ gap: 8px;
371
+ }
372
+
373
+ .nice-drilldown-bar-row {
374
+ display: flex;
375
+ align-items: center;
376
+ gap: 12px;
377
+ cursor: pointer;
378
+ padding: 4px 8px;
379
+ margin: -4px -8px;
380
+ border-radius: 6px;
381
+ transition: background 0.2s;
382
+ }
383
+
384
+ .nice-drilldown-bar-row:hover {
385
+ background: #f9fafb;
386
+ }
387
+
388
+ .nice-drilldown-bar-label {
389
+ width: 120px;
390
+ font-size: 13px;
391
+ color: #374151;
392
+ overflow: hidden;
393
+ text-overflow: ellipsis;
394
+ white-space: nowrap;
395
+ }
396
+
397
+ .nice-drilldown-bar-track {
398
+ flex: 1;
399
+ background: #f3f4f6;
400
+ border-radius: 6px;
401
+ overflow: hidden;
402
+ }
403
+
404
+ .nice-drilldown-bar-fill {
405
+ transition: width 0.3s ease;
406
+ border-radius: 6px;
407
+ }
408
+
409
+ .nice-drilldown-bar-value {
410
+ width: 80px;
411
+ text-align: right;
412
+ font-size: 13px;
413
+ font-weight: 500;
414
+ color: #111827;
415
+ }
416
+
417
+ .nice-drilldown-pie-slice {
418
+ cursor: pointer;
419
+ transition: transform 0.2s, opacity 0.2s;
420
+ transform-origin: center;
421
+ }
422
+
423
+ .nice-drilldown-pie-slice:hover {
424
+ opacity: 0.85;
425
+ transform: scale(1.02);
426
+ }
427
+
428
+ .nice-drilldown-column-bar {
429
+ cursor: pointer;
430
+ transition: opacity 0.2s;
431
+ }
432
+
433
+ .nice-drilldown-column-bar:hover {
434
+ opacity: 0.8;
435
+ }
436
+
437
+ .nice-drilldown-legend {
438
+ display: flex;
439
+ flex-wrap: wrap;
440
+ gap: 16px;
441
+ padding: 12px 16px;
442
+ border-top: 1px solid var(--border-color, #e5e7eb);
443
+ }
444
+
445
+ .nice-drilldown-legend-item {
446
+ display: flex;
447
+ align-items: center;
448
+ gap: 6px;
449
+ }
450
+
451
+ .nice-drilldown-legend-color {
452
+ width: 12px;
453
+ height: 12px;
454
+ border-radius: 3px;
455
+ }
456
+
457
+ .nice-drilldown-legend-label {
458
+ font-size: 12px;
459
+ color: #6b7280;
460
+ }
461
+ `})]})});Be.displayName="NiceDrillDownChart";const We=x.forwardRef((t,u)=>{const{initialData:o,data:m,maxPoints:n=60,updateInterval:f=1e3,fetchData:j,width:S=600,height:z=200,chartType:l="line",color:g="var(--color-primary, #3b82f6)",showGrid:b=!0,showTimeAxis:p=!0,showCurrentValue:$=!0,title:w,valueFormatter:i=H=>H.toFixed(2),timeFormatter:d=H=>new Date(H).toLocaleTimeString(),onDataUpdate:c,paused:k,className:_,style:N,...y}=t,[v,s]=x.useState(o??m??[]),[L,r]=x.useState(k||!1),B=x.useRef();x.useEffect(()=>{k!==void 0&&r(k)},[k]),x.useEffect(()=>{if(L||!j)return;const H=async()=>{try{const Q=await j();s(D=>{const Y=[...D,Q].slice(-n);return c==null||c(Y),Y})}catch(Q){console.error("Failed to fetch realtime data:",Q)}};return B.current=setInterval(H,f),()=>{B.current&&clearInterval(B.current)}},[L,j,f,n,c]);const O=x.useCallback(H=>{s(Q=>{const D=[...Q,H].slice(-n);return c==null||c(D),D})},[n,c]),X=x.useCallback(()=>{s([]),c==null||c([])},[c]),q=x.useCallback(()=>r(!0),[]),U=x.useCallback(()=>r(!1),[]);x.useImperativeHandle(u,()=>({addDataPoint:O,clearData:X,pause:q,resume:U,getData:()=>v}),[O,X,v]);const re={top:20,right:60,bottom:p?40:20,left:50},J=S-re.left-re.right,te=z-re.top-re.bottom,T=v.map(H=>H.value),G=T.length?Math.min(...T):0,oe=T.length?Math.max(...T):100,ce=(oe-G||1)*.1,C=G-ce,A=oe+ce-C,V=H=>{const Q=j?n-1:Math.max(1,v.length-1);return re.left+H/Q*J},Z=H=>re.top+te-(H-C)/A*te,K=v.map((H,Q)=>`${V(Q)},${Z(H.value)}`).join(" "),F=v.length>0?`M ${V(0)},${re.top+te} L ${K} L ${V(v.length-1)},${re.top+te} Z`:"",W=v.length>0?v[v.length-1].value:null;return e.jsxs("div",{className:`nice-realtime-chart ${_||""}`,style:{width:S,...N},...y,children:[w&&e.jsxs("div",{className:"nice-realtime-header",children:[e.jsx("span",{className:"nice-realtime-title",children:w}),e.jsxs("div",{className:"nice-realtime-controls",children:[e.jsx("button",{className:`nice-realtime-btn ${L?"paused":""}`,onClick:()=>r(!L),children:L?"▶️":"⏸️"}),$&&W!==null&&e.jsx("span",{className:"nice-realtime-value",children:i(W)})]})]}),e.jsxs("svg",{width:S,height:z,className:"nice-realtime-svg",children:[b&&e.jsx("g",{className:"nice-realtime-grid",children:[0,.25,.5,.75,1].map((H,Q)=>{const D=re.top+te*(1-H),Y=C+A*H;return e.jsxs("g",{children:[e.jsx("line",{x1:re.left,y1:D,x2:S-re.right,y2:D,stroke:"#e5e7eb",strokeDasharray:H===0?void 0:"3"}),e.jsx("text",{x:re.left-8,y:D,textAnchor:"end",dominantBaseline:"middle",fontSize:"10",fill:"#6b7280",children:i(Y)})]},Q)})}),l==="area"&&v.length>0&&e.jsx("path",{d:F,fill:g,fillOpacity:.2}),v.length>1&&e.jsx("polyline",{points:K,fill:"none",stroke:g,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"}),v.length>0&&e.jsx("circle",{cx:V(v.length-1),cy:Z(v[v.length-1].value),r:4,fill:g,className:"nice-realtime-point"}),p&&v.length>0&&e.jsx("g",{className:"nice-realtime-time-axis",children:[0,Math.floor(v.length/2),v.length-1].filter(H=>v[H]).map(H=>e.jsx("text",{x:V(H),y:z-8,textAnchor:"middle",fontSize:"10",fill:"#6b7280",children:d(v[H].timestamp)},H))})]}),e.jsxs("div",{className:`nice-realtime-status ${L?"paused":"live"}`,children:[e.jsx("span",{className:"nice-realtime-status-dot"}),e.jsx("span",{children:L?"Wstrzymano":"Na żywo"})]}),e.jsx("style",{children:`
462
+ .nice-realtime-chart {
463
+ font-family: system-ui, -apple-system, sans-serif;
464
+ background: white;
465
+ border-radius: 8px;
466
+ position: relative;
467
+ }
468
+
469
+ .nice-realtime-header {
470
+ display: flex;
471
+ justify-content: space-between;
472
+ align-items: center;
473
+ padding: 12px 16px;
474
+ border-bottom: 1px solid var(--border-color, #e5e7eb);
475
+ }
476
+
477
+ .nice-realtime-title {
478
+ font-size: 14px;
479
+ font-weight: 600;
480
+ color: #111827;
481
+ }
482
+
483
+ .nice-realtime-controls {
484
+ display: flex;
485
+ align-items: center;
486
+ gap: 12px;
487
+ }
488
+
489
+ .nice-realtime-btn {
490
+ background: none;
491
+ border: none;
492
+ cursor: pointer;
493
+ font-size: 16px;
494
+ padding: 4px;
495
+ }
496
+
497
+ .nice-realtime-value {
498
+ font-size: 18px;
499
+ font-weight: 600;
500
+ color: ${g};
501
+ font-variant-numeric: tabular-nums;
502
+ }
503
+
504
+ .nice-realtime-point {
505
+ animation: realtime-pulse 1s ease-out infinite;
506
+ }
507
+
508
+ @keyframes realtime-pulse {
509
+ 0% { opacity: 1; transform: scale(1); }
510
+ 50% { opacity: 0.5; transform: scale(1.5); }
511
+ 100% { opacity: 1; transform: scale(1); }
512
+ }
513
+
514
+ .nice-realtime-status {
515
+ position: absolute;
516
+ bottom: 8px;
517
+ right: 8px;
518
+ display: flex;
519
+ align-items: center;
520
+ gap: 6px;
521
+ font-size: 11px;
522
+ color: #6b7280;
523
+ }
524
+
525
+ .nice-realtime-status-dot {
526
+ width: 8px;
527
+ height: 8px;
528
+ border-radius: 50%;
529
+ background: #22c55e;
530
+ }
531
+
532
+ .nice-realtime-status.paused .nice-realtime-status-dot {
533
+ background: #f59e0b;
534
+ }
535
+
536
+ .nice-realtime-status.live .nice-realtime-status-dot {
537
+ animation: live-pulse 2s ease-in-out infinite;
538
+ }
539
+
540
+ @keyframes live-pulse {
541
+ 0%, 100% { opacity: 1; }
542
+ 50% { opacity: 0.4; }
543
+ }
544
+ `})]})});We.displayName="NiceRealtimeChart";const Fe=x.forwardRef(({data:t,renderNode:u,selectable:o,selectedKey:m,onSelect:n,direction:f="top-down",collapsible:j=!0,className:S,style:z,id:l},g)=>{const b=we.Os(l),[p,$]=x.useState(new Set),w=x.useCallback(c=>{$(k=>{const _=new Set(k);return _.has(c)?_.delete(c):_.add(c),_})},[]),i=x.useCallback(c=>{o&&(n==null||n(c))},[o,n]),d=x.useCallback(c=>{const k=p.has(c.key),_=c.children&&c.children.length>0;return e.jsxs("li",{className:"nice-org-chart__item",children:[e.jsxs("div",{className:`nice-org-chart__node${m===c.key?" nice-org-chart__node--selected":""}`,onClick:()=>i(c.key),role:o?"button":void 0,children:[u?u(c):e.jsx("span",{children:c.label}),j&&_&&e.jsx("button",{type:"button",className:"nice-org-chart__toggle",onClick:N=>{N.stopPropagation(),w(c.key)},"aria-label":k?"Expand":"Collapse",children:k?"+":"−"})]}),_&&!k&&e.jsx("ul",{className:"nice-org-chart__children",children:c.children.map(N=>d(N))})]},c.key)},[p,m,u,o,j,i,w]);return e.jsx("div",{ref:g,id:b,className:`nice-org-chart nice-org-chart--${f} ${S||""}`,style:z,children:e.jsx("ul",{className:"nice-org-chart__root",children:d(t)})})});Fe.displayName="NiceOrganizationChart";function lt(t,u,o){const m=$=>{const w=$.replace("#","");return[parseInt(w.slice(0,2),16),parseInt(w.slice(2,4),16),parseInt(w.slice(4,6),16)]},[n,f,j]=m(t),[S,z,l]=m(u),g=Math.round(n+(S-n)*o),b=Math.round(f+(z-f)*o),p=Math.round(j+(l-j)*o);return`rgb(${g},${b},${p})`}const Oe=x.forwardRef(({data:t,xLabels:u,yLabels:o,colors:m=["#e0f2fe","var(--color-primary-active, #1d4ed8)"],onCellClick:n,cellSize:f=40,showValues:j=!0,className:S,style:z,id:l},g)=>{const b=we.Os(l),{minVal:p,maxVal:$}=x.useMemo(()=>{let i=1/0,d=-1/0;for(const c of t)for(const k of c)k<i&&(i=k),k>d&&(d=k);return{minVal:i,maxVal:d}},[t]),w=x.useCallback(i=>$===p?.5:(i-p)/($-p),[p,$]);return e.jsx("div",{ref:g,id:b,className:`nice-heatmap ${S||""}`,style:z,children:e.jsxs("table",{className:"nice-heatmap__table",children:[u&&e.jsx("thead",{children:e.jsxs("tr",{children:[o&&e.jsx("th",{}),u.map((i,d)=>e.jsx("th",{className:"nice-heatmap__header",children:i},d))]})}),e.jsx("tbody",{children:t.map((i,d)=>e.jsxs("tr",{children:[o&&e.jsx("th",{className:"nice-heatmap__row-label",children:o[d]}),i.map((c,k)=>e.jsx("td",{className:"nice-heatmap__cell",style:{background:lt(m[0],m[1],w(c)),width:f,height:f,textAlign:"center",color:w(c)>.6?"var(--bg-primary, #fff)":"var(--bg-tertiary, #333)",cursor:n?"pointer":void 0},onClick:()=>n==null?void 0:n(d,k,c),title:String(c),children:j?c:""},k))]},d))})]})})});Oe.displayName="NiceHeatMap";function ot(t,u){const o=t.reduce((l,g)=>l+g.value,0);if(o===0||t.length===0)return[];const m=[];let{x:n,y:f,w:j,h:S}=u;const z=[...t].sort((l,g)=>g.value-l.value);for(const l of z){const g=l.value/o;if(j>=S){const b=j*g;m.push({x:n,y:f,w:b,h:S,node:l}),n+=b,j-=b}else{const b=S*g;m.push({x:n,y:f,w:j,h:b,node:l}),f+=b,S-=b}}return m}const ct=["var(--color-primary, #3b82f6)","var(--color-success, #10b981)","var(--color-warning, #f59e0b)","var(--color-error, #ef4444)","var(--color-accent, #8b5cf6)","var(--color-info, #06b6d4)","var(--color-accent-pink, #ec4899)","#84cc16"],Ve=x.forwardRef(({data:t,width:u=600,height:o=400,onNodeClick:m,colors:n=ct,className:f,style:j,id:S},z)=>{const l=we.Os(S),g=x.useMemo(()=>{const b=t.children??[t];return ot(b,{x:0,y:0,w:u,h:o})},[t,u,o]);return e.jsx("div",{ref:z,id:l,className:`nice-treemap ${f||""}`,style:j,children:e.jsx("svg",{width:u,height:o,className:"nice-treemap__svg",children:g.map((b,p)=>e.jsxs("g",{onClick:()=>m==null?void 0:m(b.node),style:{cursor:m?"pointer":void 0},children:[e.jsx("rect",{x:b.x,y:b.y,width:Math.max(b.w-1,0),height:Math.max(b.h-1,0),fill:b.node.color??n[p%n.length],rx:2}),b.w>40&&b.h>20&&e.jsx("text",{x:b.x+b.w/2,y:b.y+b.h/2,textAnchor:"middle",dominantBaseline:"central",fill:"#fff",fontSize:Math.min(12,b.w/6),className:"nice-treemap__label",children:b.node.label})]},b.node.key))})})});Ve.displayName="NiceTreeMap";const Ee=x.forwardRef(({data:t,type:u="candlestick",showVolume:o=!0,width:m=800,height:n=400,bullColor:f="var(--color-success, #22c55e)",bearColor:j="var(--color-error, #ef4444)",className:S,style:z,id:l},g)=>{const b=we.Os(l),p={top:20,right:20,bottom:o?80:30,left:60},$=m-p.left-p.right,w=o?50:0,i=n-p.top-p.bottom-w,{minP:d,maxP:c,maxVol:k}=x.useMemo(()=>{let s=1/0,L=-1/0,r=0;for(const B of t)B.low<s&&(s=B.low),B.high>L&&(L=B.high),B.volume&&B.volume>r&&(r=B.volume);return{minP:s,maxP:L,maxVol:r}},[t]),_=Math.max(1,$/t.length*.7),N=s=>p.left+(s+.5)*($/t.length),y=s=>p.top+i-(s-d)/(c-d||1)*i,v=s=>n-p.bottom-w+w*(1-s/(k||1));return e.jsx("div",{ref:g,id:b,className:`nice-stock-chart ${S||""}`,style:z,children:e.jsxs("svg",{width:m,height:n,className:"nice-stock-chart__svg",children:[[0,.25,.5,.75,1].map(s=>{const L=d+s*(c-d);return e.jsxs("g",{children:[e.jsx("line",{x1:p.left,x2:m-p.right,y1:y(L),y2:y(L),stroke:"#e5e7eb",strokeDasharray:"2,2"}),e.jsx("text",{x:p.left-4,y:y(L)+4,textAnchor:"end",fontSize:10,fill:"#888",children:L.toFixed(2)})]},s)}),u==="line"?e.jsx("polyline",{points:t.map((s,L)=>`${N(L)},${y(s.close)}`).join(" "),fill:"none",stroke:f,strokeWidth:1.5}):t.map((s,L)=>{const r=s.close>=s.open,B=r?f:j,O=N(L);if(u==="ohlc")return e.jsxs("g",{children:[e.jsx("line",{x1:O,x2:O,y1:y(s.high),y2:y(s.low),stroke:B,strokeWidth:1}),e.jsx("line",{x1:O-_/2,x2:O,y1:y(s.open),y2:y(s.open),stroke:B,strokeWidth:1.5}),e.jsx("line",{x1:O,x2:O+_/2,y1:y(s.close),y2:y(s.close),stroke:B,strokeWidth:1.5})]},L);const X=y(Math.max(s.open,s.close)),q=y(Math.min(s.open,s.close));return e.jsxs("g",{children:[e.jsx("line",{x1:O,x2:O,y1:y(s.high),y2:y(s.low),stroke:B,strokeWidth:1}),e.jsx("rect",{x:O-_/2,y:X,width:_,height:Math.max(q-X,1),fill:r?"transparent":B,stroke:B,strokeWidth:1})]},L)}),o&&t.map((s,L)=>{if(!s.volume)return null;const r=s.close>=s.open;return e.jsx("rect",{x:N(L)-_/2,y:v(s.volume),width:_,height:n-p.bottom-v(s.volume),fill:r?f:j,opacity:.3},`v${L}`)}),t.map((s,L)=>L%Math.max(1,Math.floor(t.length/8))!==0?null:e.jsx("text",{x:N(L),y:n-p.bottom+w+14,textAnchor:"middle",fontSize:9,fill:"#888",children:s.date},`l${L}`))]})})});Ee.displayName="NiceStockChart";exports.A=Ye;exports.B=at;exports.C=ue;exports.D=nt;exports.N=Re;exports.a=rt;exports.b=Fe;exports.c=Ee;exports.d=Ve;exports.e=Oe;exports.f=Pe;exports.g=tt;exports.h=et;exports.i=Je;exports.j=Qe;exports.k=Te;exports.l=qe;exports.m=Ge;exports.n=Ue;exports.o=Se;exports.q=Be;exports.s=De;exports.u=We;