@nice2dev/ui 1.4.22 → 1.4.23

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.
@@ -1,918 +0,0 @@
1
- "use strict";const e=require("react/jsx-runtime"),le=require("@nice2dev/ui-core"),w=require("react"),ft=require("@nice2dev/i18n"),mt=[],Se=["var(--nice-color-primary, #3b82f6)","var(--nice-color-error, #ef4444)","var(--nice-color-success, #22c55e)","var(--nice-color-warning, #f59e0b)","var(--nice-color-accent, #8b5cf6)","var(--nice-color-accent-pink, #ec4899)","var(--nice-color-info, #06b6d4)","var(--nice-success, #84cc16)"],De=({series:t=mt,categories:n,width:a=600,height:r=400,title:s,showLegend:u=!0,showGrid:c=!0,axisLabels:d=!0,yAxisLabel:j,xAxisLabel:y,stacked:p,animated:g,zoomable:z,crosshair:b,annotations:C,legendInteractive:o,onDataPointClick:l,exportable:h,className:x,style:$,testId:k,"data-testid":f})=>{const{t:M}=le.useNiceTranslation(),v=w.useRef(null),[S,i]=w.useState(new Set),[N,_]=w.useState(null),[E,T]=w.useState(null),[P,D]=w.useState(!1),B=w.useRef(null),Y=w.useMemo(()=>t.filter(L=>!S.has(L.name)),[t,S]),F=w.useCallback(L=>{o&&i(ee=>{const m=new Set(ee);return m.has(L)?m.delete(L):m.add(L),m})},[o]),V={top:s?40:20,right:20,bottom:y?60:40,left:j?60:50},q=a-V.left-V.right,K=r-V.top-V.bottom,R=Y[0]?.data.length??t[0]?.data.length??0,X=E?.start??0,te=E?.end??R,se=te-X,ae=w.useMemo(()=>Y.map(L=>({...L,data:L.data.slice(X,te)})),[Y,X,te]),he=w.useMemo(()=>n?.slice(X,te),[n,X,te]),{minY:W,maxY:A,yTicks:U}=w.useMemo(()=>{let L;if(p){L=[];for(let ce=0;ce<se;ce++)L.push(ae.reduce((de,pe)=>de+(pe.data[ce]||0),0))}else L=ae.flatMap(ce=>ce.data);L.length===0&&(L=[0]);const ee=Math.min(0,...L),m=Math.max(0,...L),H=m-ee||1,J=Math.pow(10,Math.floor(Math.log10(H)))||1,O=Math.floor(ee/J)*J;let Q=Math.ceil(m/J)*J;const re=[];for(let ce=O;ce<=Q;ce+=J)re.push(Math.round(ce*1e6)/1e6);return re.length<2&&(Q=O+J,re.push(Math.round(Q*1e6)/1e6)),{minY:O,maxY:Q,yTicks:re}},[ae,se,p]),I=L=>K-(L-W)/(A-W||1)*K,G=L=>(L+.5)/se*q,fe=L=>(L.type||"bar")==="bar",Z=new Map(ae.filter(fe).map((L,ee)=>[L,ee])),oe=se>0?q/se/(p?1.5:Math.max(Z.size,1)*1.5):20,ue=oe*.9,ye=w.useCallback(L=>{if(!z)return;L.preventDefault();const ee=E??{start:0,end:R},m=ee.end-ee.start,H=(ee.start+ee.end)/2,J=L.deltaY>0?1.2:.8,O=Math.max(2,Math.min(R,Math.round(m*J))),Q=Math.max(0,Math.round(H-O/2)),re=Math.min(R,Q+O);T({start:Q,end:re})},[z,E,R]),$e=w.useCallback(L=>{z&&(D(!0),B.current={x:L.clientX,range:E??{start:0,end:R}})},[z,E,R]),ve=w.useCallback(L=>{const ee=v.current?.getBoundingClientRect();if(ee&&_({x:L.clientX-ee.left-V.left,y:L.clientY-ee.top-V.top}),P&&B.current&&z){const m=L.clientX-B.current.x,H=q/se,J=-Math.round(m/H),O=B.current.range,Q=O.end-O.start;let re=O.start+J;re<0&&(re=0),re+Q>R&&(re=R-Q),T({start:re,end:re+Q})}},[P,z,q,se,R,V.left,V.top]),je=w.useCallback(()=>{D(!1),B.current=null},[]),Me=w.useCallback(()=>{_(null),D(!1),B.current=null},[]),ne=w.useCallback(()=>{const L=v.current;if(!L)return;const ee=new XMLSerializer().serializeToString(L),m=document.createElement("canvas");m.width=a,m.height=r+(u?30:0);const H=m.getContext("2d");if(!H)return;const J=new Image;J.onload=()=>{H.fillStyle=le.resolveCssColor("var(--nice-bg-primary, #fff)",H.canvas),H.fillRect(0,0,m.width,m.height),H.drawImage(J,0,0);const O=document.createElement("a");O.download="chart.png",O.href=m.toDataURL("image/png"),O.click()},J.src="data:image/svg+xml;charset=utf-8,"+encodeURIComponent(ee)},[a,r,u]),ie=r+(u?30:0),me=ae.length>0&&ae.every(L=>L.type==="radar"),we=w.useMemo(()=>{if(!me)return 1;const L=ae.flatMap(ee=>ee.data);return Math.max(1,...L)},[me,ae]);if(me){const L=a/2,ee=(r-V.top-V.bottom)/2+V.top,m=Math.min(q,r-V.top-V.bottom)/2-10,H=he?.length??ae[0]?.data.length??0,J=re=>re/H*Math.PI*2-Math.PI/2,O=(re,ce)=>{const de=ce/we*m;return[L+Math.cos(J(re))*de,ee+Math.sin(J(re))*de]},Q=4;return e.jsx("div",{className:`nice-chart nice-chart--radar ${x||""}`,style:$,"data-testid":f??k,children:e.jsxs("svg",{ref:v,viewBox:`0 0 ${a} ${ie}`,preserveAspectRatio:"xMidYMid meet",width:"100%",height:"100%",className:"nice-chart__svg",style:{display:"block",maxWidth:"100%",maxHeight:"100%"},children:[s&&e.jsx("text",{x:a/2,y:20,textAnchor:"middle",className:"nice-chart__title",children:s}),c&&Array.from({length:Q},(re,ce)=>{const de=(ce+1)/Q*m,pe=[];for(let ge=0;ge<H;ge++)pe.push(`${L+Math.cos(J(ge))*de},${ee+Math.sin(J(ge))*de}`);return e.jsx("polygon",{points:pe.join(" "),fill:"none",className:"nice-chart__grid-line"},ce)}),Array.from({length:H},(re,ce)=>{const[de,pe]=O(ce,we);return e.jsx("line",{x1:L,y1:ee,x2:de,y2:pe,className:"nice-chart__grid-line"},ce)}),d&&he?.map((re,ce)=>{const[de,pe]=O(ce,we*1.12);return e.jsx("text",{x:de,y:pe,textAnchor:"middle",dominantBaseline:"middle",className:"nice-chart__axis-label",children:re},ce)}),ae.map((re,ce)=>{const de=re.color||Se[ce%Se.length],pe=re.data.map((ge,ke)=>O(ke,ge).join(",")).join(" ");return e.jsxs("g",{className:g?"nice-chart__series nice-chart__series--radar nice-chart__series--anim":"nice-chart__series nice-chart__series--radar",children:[e.jsx("polygon",{points:pe,fill:de,fillOpacity:.2,stroke:de,strokeWidth:2}),re.data.map((ge,ke)=>{const[Ce,Ee]=O(ke,ge);return e.jsx("circle",{cx:Ce,cy:Ee,r:3,fill:de,children:e.jsx("title",{children:`${re.name}: ${ge}`})},ke)})]},re.name)}),u&&e.jsx("g",{transform:`translate(${V.left}, ${r})`,children:t.map((re,ce)=>{const de=ce*120,pe=S.has(re.name);return e.jsxs("g",{transform:`translate(${de}, 10)`,style:o?{cursor:"pointer"}:void 0,onClick:()=>F(re.name),opacity:pe?.35:1,children:[e.jsx("rect",{width:12,height:12,rx:2,fill:re.color||Se[ce%Se.length]}),e.jsx("text",{x:16,y:10,className:"nice-chart__legend-text",children:re.name})]},re.name)})})]})})}return e.jsxs("div",{className:`nice-chart ${x||""}`,style:$,"data-testid":f??k,children:[h&&e.jsx("button",{type:"button",className:"nice-chart__export-btn",onClick:ne,title:M("chart.exportPng","Export PNG"),"aria-label":M("chart.exportPng","Export PNG"),children:e.jsx(le.NiceIcon,{name:"camera",size:16})}),e.jsxs("svg",{ref:v,viewBox:`0 0 ${a} ${ie}`,preserveAspectRatio:"xMidYMid meet",width:"100%",height:"100%",style:{display:"block",maxWidth:"100%",maxHeight:"100%"},className:"nice-chart__svg",onWheel:ye,onMouseDown:$e,onMouseMove:ve,onMouseUp:je,onMouseLeave:Me,children:[e.jsxs("g",{transform:`translate(${V.left},${V.top})`,children:[s&&e.jsx("text",{x:q/2,y:-10,textAnchor:"middle",className:"nice-chart__title",children:s}),c&&U.map(L=>e.jsx("line",{x1:0,y1:I(L),x2:q,y2:I(L),className:"nice-chart__grid-line"},`grid-${L}`)),d&&U.map(L=>e.jsx("text",{x:-8,y:I(L)+4,textAnchor:"end",className:"nice-chart__axis-label",children:L},`ylabel-${L}`)),d&&he&&he.map((L,ee)=>e.jsx("text",{x:G(ee),y:K+20,textAnchor:"middle",className:"nice-chart__axis-label",children:L},ee)),j&&e.jsx("text",{x:-V.left+14,y:K/2,textAnchor:"middle",transform:`rotate(-90, -${V.left-14}, ${K/2})`,className:"nice-chart__axis-title",children:j}),y&&e.jsx("text",{x:q/2,y:K+45,textAnchor:"middle",className:"nice-chart__axis-title",children:y}),e.jsx("line",{x1:0,y1:0,x2:0,y2:K,className:"nice-chart__axis"}),e.jsx("line",{x1:0,y1:K,x2:q,y2:K,className:"nice-chart__axis"}),C?.map((L,ee)=>{if(L.type==="line"){const m=I(L.value);return e.jsxs("g",{children:[e.jsx("line",{x1:0,y1:m,x2:q,y2:m,stroke:L.color||"var(--nice-color-error, #ef4444)",strokeWidth:1.5,strokeDasharray:L.dash||"6,3"}),L.label&&e.jsx("text",{x:q+4,y:m+4,className:"nice-chart__annotation-label",fill:L.color||"var(--nice-color-error, #ef4444)",children:L.label})]},ee)}return e.jsx("text",{x:G(L.value),y:-4,textAnchor:"middle",className:"nice-chart__annotation-label",fill:L.color||"var(--nice-text-muted, #6b7280)",children:L.label},ee)}),b&&N&&N.x>=0&&N.x<=q&&N.y>=0&&N.y<=K&&e.jsxs(e.Fragment,{children:[e.jsx("line",{x1:N.x,y1:0,x2:N.x,y2:K,stroke:"var(--nice-text-muted, #9ca3af)",strokeWidth:1,strokeDasharray:"4,2"}),e.jsx("line",{x1:0,y1:N.y,x2:q,y2:N.y,stroke:"var(--nice-text-muted, #9ca3af)",strokeWidth:1,strokeDasharray:"4,2"})]}),ae.map((L,ee)=>{const m=L.color||Se[ee%Se.length],H=L.type||"bar";if(H==="bar")return e.jsx("g",{className:g?"nice-chart__series nice-chart__series--bar nice-chart__series--anim":"nice-chart__series nice-chart__series--bar",children:L.data.map((O,Q)=>{let re,ce;if(p){const ge=ae.slice(0,ee).filter(fe).reduce((ke,Ce)=>ke+(Ce.data[Q]||0),0);re=I(ge+O),ce=I(ge)-re}else re=I(Math.max(0,O)),ce=Math.abs(I(O)-I(0));const de=Z.get(L)??0,pe=p?G(Q)-ue/2:G(Q)-Z.size*oe/2+de*oe+(oe-ue)/2;return e.jsx("rect",{x:pe,y:re,width:ue,height:Math.max(0,ce),fill:m,rx:2,style:{transformOrigin:`${pe+ue/2}px ${I(0)}px`,...l?{cursor:"pointer"}:{}},onClick:l?()=>l(L.name,X+Q,O):void 0,children:e.jsx("title",{children:`${L.name}: ${O}`})},Q)})},L.name);if(H==="scatter")return e.jsx("g",{className:g?"nice-chart__series nice-chart__series--scatter nice-chart__series--anim":"nice-chart__series nice-chart__series--scatter",children:L.data.map((O,Q)=>e.jsx("circle",{cx:G(Q),cy:I(O),r:5,fill:m,fillOpacity:.7,stroke:m,strokeWidth:1.5,style:l?{cursor:"pointer"}:void 0,onClick:l?()=>l(L.name,X+Q,O):void 0,children:e.jsx("title",{children:`${L.name}: ${O}`})},Q))},L.name);const J=L.data.map((O,Q)=>`${G(Q)},${I(O)}`);return e.jsxs("g",{className:g?`nice-chart__series nice-chart__series--${H} nice-chart__series--anim`:`nice-chart__series nice-chart__series--${H}`,children:[H==="area"&&se>0&&e.jsx("polygon",{points:`${G(0)},${I(0)} ${J.join(" ")} ${G(se-1)},${I(0)}`,fill:m,opacity:.15}),e.jsx("polyline",{points:J.join(" "),fill:"none",stroke:m,strokeWidth:2,className:g?"nice-chart__line":void 0}),L.data.map((O,Q)=>e.jsx("circle",{cx:G(Q),cy:I(O),r:3,fill:m,style:l?{cursor:"pointer"}:void 0,onClick:l?()=>l(L.name,X+Q,O):void 0,children:e.jsx("title",{children:`${L.name}: ${O}`})},Q))]},L.name)})]}),u&&e.jsx("g",{transform:`translate(${V.left}, ${r})`,children:t.map((L,ee)=>{const m=ee*120,H=S.has(L.name);return e.jsxs("g",{transform:`translate(${m}, 10)`,style:o?{cursor:"pointer"}:void 0,onClick:()=>F(L.name),opacity:H?.35:1,children:[e.jsx("rect",{width:12,height:12,rx:2,fill:L.color||Se[ee%Se.length]}),e.jsx("text",{x:16,y:10,className:"nice-chart__legend-text",style:H?{textDecoration:"line-through"}:void 0,children:L.name})]},L.name)})})]})]})},pt=Object.freeze(Object.defineProperty({__proto__:null,NiceChart:De},Symbol.toStringTag,{value:"Module"})),xt=({value:t,min:n=0,max:a=100,width:r=200,height:s=200,startAngle:u=225,endAngle:c=-45,color:d="var(--nice-color-primary, #3b82f6)",trackColor:j,label:y,formatValue:p,ranges:g,className:z,style:b,testId:C,"data-testid":o})=>{const l=r/2,h=s/2,x=Math.min(l,h)-20,$=Math.max(0,Math.min(1,(t-n)/(a-n||1))),k=_=>_*Math.PI/180,f=(u-c+360)%360||360,M=_=>({x:l+x*Math.cos(k(_)),y:h-x*Math.sin(k(_))}),v=(_,E)=>{const T=M(_),P=M(E),B=(_-E+360)%360>180?1:0;return`M${T.x},${T.y} A${x},${x} 0 ${B},1 ${P.x},${P.y}`},S=u-$*f,i=M(S);let N=d;if(g){for(const _ of g)if(t>=_.start&&t<=_.end){N=_.color;break}}return e.jsx("div",{className:`nice-gauge nice-gauge--circular ${z||""}`,style:b,"data-testid":o??C,children:e.jsxs("svg",{width:r,height:s,children:[e.jsx("path",{d:v(u,c),fill:"none",stroke:j||"var(--nice-border-color, #e2e8f0)",strokeWidth:12,strokeLinecap:"round"}),$>0&&e.jsx("path",{d:v(u,S),fill:"none",stroke:N,strokeWidth:12,strokeLinecap:"round"}),e.jsx("line",{x1:l,y1:h,x2:i.x,y2:i.y,stroke:"var(--nice-text-primary, #333)",strokeWidth:2,strokeLinecap:"round"}),e.jsx("circle",{cx:l,cy:h,r:4,fill:"var(--nice-text-primary, #333)"}),e.jsx("text",{x:l,y:h+x*.6,textAnchor:"middle",className:"nice-gauge__value",children:p?p(t):t}),y&&e.jsx("text",{x:l,y:h+x*.95,textAnchor:"middle",className:"nice-gauge__label",children:y})]})})},gt=({value:t,min:n=0,max:a=100,width:r=300,height:s=60,orientation:u="horizontal",color:c="var(--nice-color-primary, #3b82f6)",label:d,formatValue:j,ranges:y,showTicks:p=!0,tickCount:g=5,className:z,style:b,testId:C,"data-testid":o})=>{const l=u==="horizontal",h=l?r-40:s-40,x=Math.max(0,Math.min(1,(t-n)/(a-n||1))),$=10;let k=c;if(y){for(const M of y)if(t>=M.start&&t<=M.end){k=M.color;break}}const f=Array.from({length:g},(M,v)=>n+(a-n)*(v/(g-1)));if(l){const M=d?14:0;return e.jsx("div",{className:`nice-gauge nice-gauge--linear ${z||""}`,style:b,"data-testid":o??C,children:e.jsxs("svg",{width:r,height:s+M,children:[e.jsx("text",{x:20+h*x,y:14,textAnchor:"middle",className:"nice-gauge__value",style:{fontSize:12},children:j?j(t):t}),e.jsx("rect",{x:20,y:s/2-$/2,width:h,height:$,rx:5,fill:"var(--nice-border-color, #e2e8f0)"}),e.jsx("rect",{x:20,y:s/2-$/2,width:h*x,height:$,rx:5,fill:k}),e.jsx("polygon",{points:`${20+h*x},${s/2-$/2-2} ${20+h*x-5},${s/2-$/2-8} ${20+h*x+5},${s/2-$/2-8}`,fill:"var(--nice-text-primary, #333)"}),p&&f.map((v,S)=>{const i=20+(v-n)/(a-n)*h;return e.jsx("text",{x:i,y:s/2+$/2+12,textAnchor:"middle",className:"nice-gauge__tick",children:v},S)}),d&&e.jsx("text",{x:r/2,y:s+M-2,textAnchor:"middle",className:"nice-gauge__label",children:d})]})})}return e.jsx("div",{className:`nice-gauge nice-gauge--linear nice-gauge--vertical ${z||""}`,style:b,"data-testid":o??C,children:e.jsxs("svg",{width:r,height:s,children:[e.jsx("rect",{x:r/2-$/2,y:20,width:$,height:h,rx:5,fill:"var(--nice-border-color, #e2e8f0)"}),e.jsx("rect",{x:r/2-$/2,y:20+h*(1-x),width:$,height:h*x,rx:5,fill:k}),e.jsx("text",{x:r/2,y:14,textAnchor:"middle",className:"nice-gauge__value",children:j?j(t):t}),d&&e.jsx("text",{x:r/2,y:s-4,textAnchor:"middle",className:"nice-gauge__label",children:d})]})})},_e=["#3b82f6","#ef4444","#22c55e","#f59e0b","#8b5cf6","#ec4899","#06b6d4","#84cc16"],yt=[],We=20,vt=10,bt=32,_t=({items:t=yt,min:n=0,max:a=100,width:r=300,height:s=300,startAngle:u=225,endAngle:c=-45,formatValue:d,title:j,className:y,style:p,testId:g,"data-testid":z})=>{const b=D=>D*Math.PI/180,C=(u-c+360)%360||360,o=[b(u),b(c)],l=D=>(u-D+720)%360<=C,h=l(90)?1:Math.max(0,...o.map(D=>Math.sin(D))),x=l(270)?1:Math.max(0,...o.map(D=>-Math.sin(D))),$=l(180)?1:Math.max(0,...o.map(D=>-Math.cos(D))),k=l(0)?1:Math.max(0,...o.map(D=>Math.cos(D))),f=j?bt:0,M=vt+We/2,v=r-2*M,S=s-f-2*M,i=Math.max(0,Math.min(v/($+k||1),S/(h+x||1))),N=M+$*i+(v-($+k)*i)/2,_=f+M+h*i+(S-(h+x)*i)/2,E=Math.min(We,i/(t.length+1)),T=4,P=(D,B,Y)=>{const F=N+D*Math.cos(b(B)),V=_-D*Math.sin(b(B)),q=N+D*Math.cos(b(Y)),K=_-D*Math.sin(b(Y)),R=(B-Y+360)%360;return`M${F},${V} A${D},${D} 0 ${R>180?1:0},1 ${q},${K}`};return e.jsx("div",{className:`nice-bargauge ${y||""}`,style:p,"data-testid":z??g,children:e.jsxs("svg",{width:r,height:s,children:[j&&e.jsx("text",{x:r/2,y:20,textAnchor:"middle",className:"nice-chart__title",children:j}),t.map((D,B)=>{const Y=i-B*(E+T),F=Math.max(0,Math.min(1,(D.value-n)/(a-n||1))),V=u-F*C,q=D.color||_e[B%_e.length];return e.jsxs("g",{children:[e.jsx("path",{d:P(Y,u,c),fill:"none",stroke:"var(--nice-border-color, #e2e8f0)",strokeWidth:E,strokeLinecap:"round"}),F>0&&e.jsx("path",{d:P(Y,u,V),fill:"none",stroke:q,strokeWidth:E,strokeLinecap:"round"})]},B)}),e.jsx("g",{children:t.map((D,B)=>e.jsxs("text",{x:N,y:_-((t.length-1)/2-B)*16,textAnchor:"middle",dominantBaseline:"middle",className:"nice-gauge__value",style:{fontSize:12},children:[D.label?`${D.label}: `:"",d?d(D.value):D.value]},B))})]})})},wt={sm:{width:160,height:22,fontSize:11},md:{width:220,height:32,fontSize:12},lg:{width:320,height:44,fontSize:14}},jt=({value:t,target:n,min:a=0,max:r=100,width:s,height:u,color:c="var(--nice-color-primary, #3b82f6)",targetColor:d="var(--nice-color-error, #ef4444)",size:j="md",label:y,labelPlacement:p="top",showValue:g=!1,showTarget:z=!1,formatValue:b=k=>String(k),state:C="normal",errorMessage:o,className:l,style:h,testId:x,"data-testid":$})=>{const{t:k}=le.useNiceTranslation(),f=wt[j],M=s??f.width,v=u??f.height,S=f.fontSize,i=4,N=M-i*2,_=z&&n!=null?S+4:i,E=z&&n!=null?v+(_-i):v,T=E-_-i,P=Math.max(0,Math.min(1,(t-a)/(r-a||1))),D=n!=null?Math.max(0,Math.min(1,(n-a)/(r-a||1))):null,B=()=>C==="error"?e.jsx("div",{role:"alert",style:{width:M,height:E,display:"flex",alignItems:"center",justifyContent:"center",border:"1px dashed var(--nice-color-error, #ef4444)",borderRadius:4,color:"var(--nice-color-error, #ef4444)",fontSize:S,padding:"0 8px",boxSizing:"border-box"},children:o??k("bullet.error","Error")}):C==="loading"?e.jsx("div",{role:"status","aria-label":k("bullet.loading","Loading"),className:"nice-bullet__skeleton",style:{width:M,height:E,borderRadius:4,background:"linear-gradient(90deg, var(--nice-bg-tertiary, #e5e7eb) 25%, var(--nice-bg-secondary, #f3f4f6) 50%, var(--nice-bg-tertiary, #e5e7eb) 75%)",backgroundSize:"200% 100%",animation:"nice-bullet-shimmer 1.4s linear infinite"}}):e.jsxs("svg",{width:M,height:E,role:"img","aria-label":typeof y=="string"?y:void 0,children:[e.jsx("rect",{x:i,y:_,width:N,height:T,rx:3,fill:"var(--nice-border-color, #e2e8f0)"}),e.jsx("rect",{x:i,y:_+T*.2,width:N*P,height:T*.6,rx:2,fill:c}),D!=null&&e.jsx("line",{x1:i+N*D,y1:_+2,x2:i+N*D,y2:_+T-2,stroke:d,strokeWidth:2}),g&&e.jsx("text",{x:i+Math.max(N*P,4),y:_+T/2,dx:N*P>24?-4:4,textAnchor:N*P>24?"end":"start",dominantBaseline:"middle",fontSize:S,fill:N*P>24?"var(--nice-color-white, #ffffff)":"var(--nice-text-primary)",fontWeight:600,children:b(t)}),z&&D!=null&&e.jsx("text",{x:i+N*D,y:_-2,textAnchor:"middle",fontSize:S-1,fill:d,fontWeight:600,children:b(n)})]});if(p==="none"||!y)return e.jsxs("div",{className:`nice-bullet ${l||""}`,style:h,"data-testid":$??x,children:[B(),e.jsx("style",{children:Ye})]});const Y=p==="top"||p==="bottom",F=e.jsx("span",{className:"nice-bullet__label",style:{fontSize:S,fontWeight:600,color:"var(--nice-text-primary)",...Y?{marginBottom:p==="top"?4:0,marginTop:p==="bottom"?4:0}:{},...p==="left"?{marginRight:8}:{},...p==="right"?{marginLeft:8}:{}},children:y});return e.jsxs("div",{className:`nice-bullet nice-bullet--${p} ${l||""}`,style:{display:"inline-flex",flexDirection:Y?"column":"row",alignItems:Y?"flex-start":"center",...h},"data-testid":$??x,children:[(p==="top"||p==="left")&&F,B(),(p==="bottom"||p==="right")&&F,e.jsx("style",{children:Ye})]})},Ye=`
2
- @keyframes nice-bullet-shimmer {
3
- 0% { background-position: 200% 0; }
4
- 100% { background-position: -200% 0; }
5
- }
6
- `,$t=[],Mt=({data:t=$t,width:n=400,height:a=400,innerRadius:r=0,title:s,showLegend:u=!0,showLabels:c=!0,className:d,style:j,testId:y,"data-testid":p})=>{const g=n/2,z=(a-(u?30:0))/2+(s?10:0),b=Math.min(g,z)-40,C=t.reduce((h,x)=>h+x.value,0);let o=-Math.PI/2;const l=t.map((h,x)=>{const $=h.value/(C||1)*Math.PI*2,k=o;o+=$;const f=o,M=(k+f)/2,v=g+b*Math.cos(k),S=z+b*Math.sin(k),i=g+b*Math.cos(f),N=z+b*Math.sin(f),_=$>Math.PI?1:0,E=h.color||_e[x%_e.length],T=$>=Math.PI*2-1e-9;let P;if(T){const q=(K,R)=>`M${g-K},${z} A${K},${K} 0 1,${R} ${g+K},${z} A${K},${K} 0 1,${R} ${g-K},${z} Z`;P=r>0?`${q(b,1)} ${q(r,0)}`:q(b,1)}else if(r>0){const q=g+r*Math.cos(k),K=z+r*Math.sin(k),R=g+r*Math.cos(f),X=z+r*Math.sin(f);P=`M${v},${S} A${b},${b} 0 ${_},1 ${i},${N} L${R},${X} A${r},${r} 0 ${_},0 ${q},${K} Z`}else P=`M${g},${z} L${v},${S} A${b},${b} 0 ${_},1 ${i},${N} Z`;const D=Math.min(Math.max(r,0),b),B=D>0?(D+b)/2:b*.65,Y=T?g:g+B*Math.cos(M),F=T?z:z+B*Math.sin(M),V=C>0?Math.round(h.value/C*100):0;return{...h,path:P,labelX:Y,labelY:F,pct:V,color:E}});return e.jsx("div",{className:`nice-piechart ${d||""}`,style:j,"data-testid":p??y,children:e.jsxs("svg",{viewBox:`0 0 ${n} ${a}`,preserveAspectRatio:"xMidYMid meet",width:"100%",height:"100%",style:{display:"block",maxWidth:"100%",maxHeight:"100%"},className:"nice-piechart__svg",children:[s&&e.jsx("text",{x:g,y:20,textAnchor:"middle",className:"nice-chart__title",children:s}),l.map((h,x)=>e.jsxs("g",{children:[e.jsx("path",{d:h.path,fill:h.color,stroke:"var(--nice-bg-primary, #fff)",strokeWidth:2,children:e.jsx("title",{children:`${h.label}: ${h.value} (${h.pct}%)`})}),c&&h.pct>=5&&e.jsxs("text",{x:h.labelX,y:h.labelY,textAnchor:"middle",dominantBaseline:"middle",className:"nice-piechart__label",children:[h.pct,"%"]})]},x)),u&&e.jsx("g",{transform:`translate(10, ${a-25})`,children:t.map((h,x)=>e.jsxs("g",{transform:`translate(${x*100}, 0)`,children:[e.jsx("rect",{width:10,height:10,rx:2,fill:h.color||_e[x%_e.length]}),e.jsx("text",{x:14,y:9,className:"nice-chart__legend-text",children:h.label})]},x))})]})})},kt=[],Nt=({data:t=kt,width:n=400,height:a=300,inverted:r,showLabels:s=!0,showValues:u=!0,title:c,className:d,style:j,testId:y,"data-testid":p})=>{const g={top:c?30:10,bottom:10,x:40},z=n-g.x*2,b=a-g.top-g.bottom,C=r?[...t].reverse():t,o=Math.max(...C.map(h=>h.value),1),l=b/C.length;return e.jsx("div",{className:`nice-funnel ${d||""}`,style:j,"data-testid":p??y,children:e.jsxs("svg",{width:n,height:a,children:[c&&e.jsx("text",{x:n/2,y:20,textAnchor:"middle",className:"nice-chart__title",children:c}),C.map((h,x)=>{const $=h.value/o*z,k=x<C.length-1?C[x+1].value/o*z:$*.3,f=g.top+x*l,M=f+l,v=n/2,S=`${v-$/2},${f} ${v+$/2},${f} ${v+k/2},${M} ${v-k/2},${M}`,i=h.color||_e[x%_e.length];return e.jsxs("g",{children:[e.jsx("polygon",{points:S,fill:i,stroke:"var(--nice-bg-primary, #fff)",strokeWidth:1,children:e.jsx("title",{children:`${h.label}: ${h.value}`})}),s&&e.jsx("text",{x:v,y:f+l/2-(u?4:0),textAnchor:"middle",dominantBaseline:"middle",className:"nice-funnel__label",children:h.label}),u&&e.jsx("text",{x:v,y:f+l/2+10,textAnchor:"middle",dominantBaseline:"middle",className:"nice-funnel__value",children:h.value})]},x)})]})})},St=[];function Ct(t,n,a){const r=b=>{const C=b.replace("#","");return[parseInt(C.slice(0,2),16),parseInt(C.slice(2,4),16),parseInt(C.slice(4,6),16)]},[s,u,c]=r(t),[d,j,y]=r(n),p=Math.round(s+(d-s)*a),g=Math.round(u+(j-u)*a),z=Math.round(c+(y-c)*a);return`rgb(${p},${g},${z})`}const Tt=Object.assign(w.forwardRef(({data:t=St,xLabels:n,yLabels:a,colors:r=["var(--nice-primary-bg, #e0f2fe)","var(--nice-color-primary-active, #1d4ed8)"],onCellClick:s,cellSize:u=40,showValues:c=!0,className:d,style:j,id:y,testId:p,"data-testid":g},z)=>{const b=le.useControlId(y),{minVal:C,maxVal:o}=w.useMemo(()=>{let h=1/0,x=-1/0;for(const $ of t)for(const k of $)k<h&&(h=k),k>x&&(x=k);return{minVal:h,maxVal:x}},[t]),l=w.useCallback(h=>o===C?.5:(h-C)/(o-C),[C,o]);return e.jsx("div",{ref:z,id:b,className:`nice-heatmap ${d||""}`,style:j,"data-testid":g??p,children:e.jsxs("table",{className:"nice-heatmap__table",children:[n&&e.jsx("thead",{children:e.jsxs("tr",{children:[a&&e.jsx("th",{}),n.map((h,x)=>e.jsx("th",{className:"nice-heatmap__header",children:h},x))]})}),e.jsx("tbody",{children:t.map((h,x)=>e.jsxs("tr",{children:[a&&e.jsx("th",{className:"nice-heatmap__row-label",children:a[x]}),h.map(($,k)=>e.jsx("td",{className:"nice-heatmap__cell",style:{background:Ct(r[0],r[1],l($)),width:u,height:u,textAlign:"center",color:l($)>.6?"var(--nice-color-white, #fff)":"var(--nice-text-primary, #333)",cursor:s?"pointer":void 0},onClick:()=>s?.(x,k,$),title:String($),children:c?$:""},k))]},x))})]})})}),{displayName:"NiceHeatMap"}),At=[],It=[],Ke=({nodes:t=At,links:n=It,width:a=600,height:r=400,nodeWidth:s=20,nodePadding:u=10,title:c,className:d,style:j,testId:y,"data-testid":p})=>{const g={top:c?40:20,bottom:20,left:20,right:20},z=a-g.left-g.right,b=r-g.top-g.bottom,C=new Set(n.map(_=>_.source)),o=new Set(n.map(_=>_.target)),l=t.filter(_=>C.has(_.id)&&!o.has(_.id)),h=t.filter(_=>o.has(_.id)),x=t.filter(_=>C.has(_.id)&&o.has(_.id)),$=[l,...x.length?[x]:[],h].filter(_=>_.length>0),k=$.length,f=new Map;t.forEach(_=>{const E=n.filter(P=>P.source===_.id).reduce((P,D)=>P+D.value,0),T=n.filter(P=>P.target===_.id).reduce((P,D)=>P+D.value,0);f.set(_.id,Math.max(E,T))});const M=$.map(_=>_.reduce((E,T)=>E+(f.get(T.id)||0),0)+(_.length-1)*u),v=Math.max(...M,1),S=new Map;$.forEach((_,E)=>{const T=g.left+E/(k-1||1)*(z-s);let P=0;_.forEach(D=>{const B=(f.get(D.id)||0)/v*b;S.set(D.id,{x:T,y:g.top+P,h:B}),P+=B+u})});const i=new Map,N=new Map;return t.forEach(_=>{i.set(_.id,0),N.set(_.id,0)}),e.jsx("div",{className:`nice-sankey ${d||""}`,style:j,"data-testid":p??y,children:e.jsxs("svg",{width:a,height:r,children:[c&&e.jsx("text",{x:a/2,y:20,textAnchor:"middle",className:"nice-chart__title",children:c}),n.map((_,E)=>{const T=S.get(_.source),P=S.get(_.target);if(!T||!P)return null;const D=i.get(_.source)||0,B=N.get(_.target)||0,Y=_.value/v*b;i.set(_.source,D+Y),N.set(_.target,B+Y);const F=T.x+s,V=T.y+D,q=P.x,K=P.y+B,R=(F+q)/2,te=t.find(se=>se.id===_.source)?.color||_e[E%_e.length];return e.jsx("path",{d:`M${F},${V} C${R},${V} ${R},${K} ${q},${K} L${q},${K+Y} C${R},${K+Y} ${R},${V+Y} ${F},${V+Y} Z`,fill:te,fillOpacity:.3,stroke:te,strokeOpacity:.5,strokeWidth:.5,children:e.jsx("title",{children:`${_.source} → ${_.target}: ${_.value}`})},E)}),t.map((_,E)=>{const T=S.get(_.id);if(!T)return null;const P=_.color||_e[E%_e.length];return e.jsxs("g",{children:[e.jsx("rect",{x:T.x,y:T.y,width:s,height:Math.max(T.h,2),fill:P,rx:2}),e.jsx("text",{x:T.x<z/2?T.x+s+4:T.x-4,y:T.y+T.h/2,textAnchor:T.x<z/2?"start":"end",dominantBaseline:"middle",className:"nice-chart__legend-text",children:_.label})]},_.id)})]})})},zt=Object.freeze(Object.defineProperty({__proto__:null,NiceSankey:Ke},Symbol.toStringTag,{value:"Module"}));function Rt(t,n){const a=t.reduce((y,p)=>y+p.value,0);if(a===0||t.length===0)return[];const r=[];let{x:s,y:u,w:c,h:d}=n;const j=[...t].sort((y,p)=>p.value-y.value);for(const y of j){const p=y.value/a;if(c>=d){const g=c*p;r.push({x:s,y:u,w:g,h:d,node:y}),s+=g,c-=g}else{const g=d*p;r.push({x:s,y:u,w:c,h:g,node:y}),u+=g,d-=g}}return r}const Dt=["var(--nice-color-primary, #3b82f6)","var(--nice-color-success, #10b981)","var(--nice-color-warning, #f59e0b)","var(--nice-color-error, #ef4444)","var(--nice-color-accent, #8b5cf6)","var(--nice-color-info, #06b6d4)","var(--nice-color-accent-pink, #ec4899)","var(--nice-success, #84cc16)"],Je=Object.assign(w.forwardRef(({data:t,width:n=600,height:a=400,onNodeClick:r,colors:s=Dt,className:u,style:c,id:d,testId:j,"data-testid":y},p)=>{const g=le.useControlId(d),z=w.useMemo(()=>{const b=t.children??[t];return Rt(b,{x:0,y:0,w:n,h:a})},[t,n,a]);return e.jsx("div",{ref:p,id:g,className:`nice-treemap ${u||""}`,style:c,"data-testid":y??j,children:e.jsx("svg",{width:n,height:a,className:"nice-treemap__svg",children:z.map((b,C)=>e.jsxs("g",{onClick:()=>r?.(b.node),style:{cursor:r?"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??s[C%s.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:"var(--nice-color-white, #fff)",fontSize:Math.min(12,b.w/6),className:"nice-treemap__label",children:b.node.label})]},b.node.key))})})}),{displayName:"NiceTreeMap"}),Lt=Object.freeze(Object.defineProperty({__proto__:null,NiceTreeMap:Je},Symbol.toStringTag,{value:"Module"})),Et=[],Qe=({regions:t=Et,width:n=600,height:a=400,viewBox:r="0 0 1000 600",colorRange:s=["#dbeafe","#1d4ed8"],maxValue:u,onRegionClick:c,selectedRegionId:d,title:j,showTooltip:y=!0,className:p,style:g,testId:z,"data-testid":b})=>{const C=u??Math.max(...t.map(l=>l.value??0),1),o=l=>{const h=_=>[parseInt(_.slice(1,3),16),parseInt(_.slice(3,5),16),parseInt(_.slice(5,7),16)],[x,$,k]=h(s[0]),[f,M,v]=h(s[1]),S=Math.round(x+(f-x)*l),i=Math.round($+(M-$)*l),N=Math.round(k+(v-k)*l);return`rgb(${S},${i},${N})`};return e.jsxs("div",{className:`nice-vectormap ${p||""}`,style:g,"data-testid":b??z,children:[j&&e.jsx("div",{className:"nice-vectormap__title",children:j}),e.jsx("svg",{width:n,height:a,viewBox:r,children:t.map(l=>{const h=l.value!=null?Math.max(0,Math.min(1,l.value/C)):0,x=l.value!=null?o(h):"var(--nice-bg-tertiary, #e5e7eb)",$=l.id===d;return e.jsx("path",{d:l.path,fill:x,stroke:$?"var(--nice-color-primary, #3b82f6)":"var(--nice-border-color, #d1d5db)",strokeWidth:$?2:.5,cursor:c?"pointer":void 0,onClick:()=>c?.(l),children:y&&e.jsx("title",{children:`${l.name}${l.value!=null?`: ${l.value}`:""}`})},l.id)})})]})},Bt=Object.freeze(Object.defineProperty({__proto__:null,NiceVectorMap:Qe},Symbol.toStringTag,{value:"Module"}));function et(t,n,a={}){const{delimiter:r=",",lineEnding:s=`
7
- `,quoteChar:u='"',alwaysQuote:c=!1,includeHeaders:d=!0,includeRowNumbers:j=!1,locale:y="en-US",dateTimeFormat:p="yyyy-MM-dd HH:mm:ss"}=a,g=n.filter(o=>o.visible!==!1),z=[],b=o=>{if(c||o.includes(r)||o.includes(u)||o.includes(`
8
- `)||o.includes("\r")){const h=o.replace(new RegExp(u,"g"),u+u);return`${u}${h}${u}`}return o},C=(o,l,h)=>{if(o==null)return"";if(l.format)return l.format(o,h);switch(l.dataType){case"date":return Fe(o,l.dateFormat??p);case"number":return Pe(o,l.numberFormat,y);case"currency":return Ue(o,l.currencyCode??"USD",y);case"boolean":return o?"Yes":"No";default:return String(o)}};if(d){const o=[];j&&o.push(b("#"));for(const l of g)o.push(b(l.header));z.push(o.join(r))}return t.forEach((o,l)=>{const h=[];j&&h.push(String(l+1));for(const x of g){const $=o[x.field],k=C($,x,o);h.push(b(k))}z.push(h.join(r))}),z.join(s)}function tt(t,n,a={}){const{fileName:r="export",includeTimestamp:s=!1,includeBOM:u=!0,encoding:c="utf-8"}=a,d=et(t,n,a),j=s?`_${Le()}`:"",y=`${r}${j}.csv`;let p=d;u&&c==="utf-8"&&(p="\uFEFF"+d);const g=new Blob([p],{type:`text/csv;charset=${c}`});Te(g,y)}function Ot(){return{sheets:new Map,activeSheet:""}}function Ft(t,n){const a={name:n,cells:new Map,columns:[],merges:[]};return t.sheets.set(n,a),t.activeSheet||(t.activeSheet=n),a}function Ae(t,n,a,r){const s=ze(n,a);t.cells.set(s,r)}function ze(t,n){let a="",r=n;for(;r>=0;)a=String.fromCharCode(65+r%26)+a,r=Math.floor(r/26)-1;return`${a}${t+1}`}function Pt(t){const n=new TextEncoder,a=Array.from(t.sheets.entries()),r=a.map(([j,y],p)=>{const g=[];let z=0,b=0;y.cells.forEach((o,l)=>{const h=l.match(/([A-Z]+)(\d+)/);if(h){const x=Ut(h[1]),$=parseInt(h[2],10);z=Math.max(z,$),b=Math.max(b,x)}});for(let o=1;o<=z;o++){const l=[];for(let h=0;h<=b;h++){const x=ze(o-1,h),$=y.cells.get(x);if($){const k=$.type==="s"?' t="inlineStr"':$.type==="b"?' t="b"':"";let f;$.type==="s"?f=`<is><t>${Ve(String($.value))}</t></is>`:$.type==="b"?f=`<v>${$.value?1:0}</v>`:f=`<v>${$.value}</v>`,l.push(`<c r="${x}"${k}>${f}</c>`)}}l.length>0&&g.push(`<row r="${o}">${l.join("")}</row>`)}return`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
9
- <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
10
- <dimension ref="${z>0?`A1:${ze(z-1,b)}`:"A1"}"/>
11
- <sheetData>${g.join("")}</sheetData>
12
- </worksheet>`}),s=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
13
- <workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
14
- <sheets>${a.map(([j],y)=>`<sheet name="${Ve(j)}" sheetId="${y+1}" r:id="rId${y+1}"/>`).join("")}</sheets>
15
- </workbook>`,u=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
16
- <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
17
- ${a.map((j,y)=>`<Relationship Id="rId${y+1}" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet${y+1}.xml"/>`).join(`
18
- `)}
19
- </Relationships>`,c=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
20
- <Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
21
- <Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
22
- <Default Extension="xml" ContentType="application/xml"/>
23
- <Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/>
24
- ${a.map((j,y)=>`<Override PartName="/xl/worksheets/sheet${y+1}.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>`).join(`
25
- `)}
26
- </Types>`;return Ht([{path:"[Content_Types].xml",content:n.encode(c)},{path:"_rels/.rels",content:n.encode(`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
27
- <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
28
- <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/>
29
- </Relationships>`)},{path:"xl/workbook.xml",content:n.encode(s)},{path:"xl/_rels/workbook.xml.rels",content:n.encode(u)},...r.map((j,y)=>({path:`xl/worksheets/sheet${y+1}.xml`,content:n.encode(j)}))])}function Ut(t){let n=0;for(let a=0;a<t.length;a++)n=n*26+(t.charCodeAt(a)-64);return n-1}function Ve(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;")}function Ht(t){const n=[],a=[];let r=0;for(const p of t){const g=new TextEncoder().encode(p.path),z=new Uint8Array(30+g.length),b=new DataView(z.buffer);b.setUint32(0,67324752,!0),b.setUint16(4,20,!0),b.setUint16(6,0,!0),b.setUint16(8,0,!0),b.setUint16(10,0,!0),b.setUint16(12,0,!0),b.setUint32(14,Xe(p.content),!0),b.setUint32(18,p.content.length,!0),b.setUint32(22,p.content.length,!0),b.setUint16(26,g.length,!0),b.setUint16(28,0,!0),z.set(g,30),n.push(z),n.push(p.content);const C=new Uint8Array(46+g.length),o=new DataView(C.buffer);o.setUint32(0,33639248,!0),o.setUint16(4,20,!0),o.setUint16(6,20,!0),o.setUint16(8,0,!0),o.setUint16(10,0,!0),o.setUint16(12,0,!0),o.setUint16(14,0,!0),o.setUint32(16,Xe(p.content),!0),o.setUint32(20,p.content.length,!0),o.setUint32(24,p.content.length,!0),o.setUint16(28,g.length,!0),o.setUint16(30,0,!0),o.setUint16(32,0,!0),o.setUint16(34,0,!0),o.setUint16(36,0,!0),o.setUint32(38,0,!0),o.setUint32(42,r,!0),C.set(g,46),a.push(C),r+=z.length+p.content.length}const s=a.reduce((p,g)=>p+g.length,0),u=new Uint8Array(22),c=new DataView(u.buffer);c.setUint32(0,101010256,!0),c.setUint16(4,0,!0),c.setUint16(6,0,!0),c.setUint16(8,t.length,!0),c.setUint16(10,t.length,!0),c.setUint32(12,s,!0),c.setUint32(16,r,!0),c.setUint16(20,0,!0);const d=r+s+u.length,j=new Uint8Array(d);let y=0;for(const p of n)j.set(p,y),y+=p.length;for(const p of a)j.set(p,y),y+=p.length;return j.set(u,y),j.buffer}function Xe(t){let n=4294967295;const a=Wt();for(let r=0;r<t.length;r++)n=n>>>8^a[(n^t[r])&255];return(n^4294967295)>>>0}let Ie=null;function Wt(){if(Ie)return Ie;Ie=new Uint32Array(256);for(let t=0;t<256;t++){let n=t;for(let a=0;a<8;a++)n=n&1?3988292384^n>>>1:n>>>1;Ie[t]=n}return Ie}function nt(t,n,a={}){const{sheetName:r="Sheet1",title:s,subtitle:u,includeHeaders:c=!0,includeRowNumbers:d=!1,freezeHeader:j=!0,autoFilter:y=!0,styles:p={},locale:g="en-US",dateTimeFormat:z="yyyy-MM-dd HH:mm:ss"}=a,b=n.filter(k=>k.visible!==!1),C=Ot(),o=Ft(C,r);let l=0;const h=d?1:0;s&&(Ae(o,l,0,{value:s,type:"s",style:{font:{bold:!0,size:16}}}),l++),u&&(Ae(o,l,0,{value:u,type:"s",style:{font:{italic:!0,size:12}}}),l++);const x=l;c&&(d&&Ae(o,l,0,{value:"#",type:"s",style:{font:{bold:p.headerFontWeight==="bold",color:p.headerColor},fill:{color:p.headerBackground},alignment:{horizontal:"center"}}}),b.forEach((k,f)=>{Ae(o,l,f+h,{value:k.header,type:"s",style:{font:{bold:p.headerFontWeight==="bold",color:p.headerColor},fill:{color:p.headerBackground},alignment:{horizontal:k.align??"left"}}})}),l++),t.forEach((k,f)=>{d&&Ae(o,l,0,{value:f+1,type:"n"}),b.forEach((M,v)=>{const S=k[M.field];let i;if(S==null)i={value:"",type:"s"};else if(M.format)i={value:M.format(S,k),type:"s"};else switch(M.dataType){case"number":case"currency":i={value:Number(S),type:"n",numberFormat:M.numberFormat};break;case"date":{i={value:Yt(S),type:"n",numberFormat:M.dateFormat??"yyyy-mm-dd"};break}case"boolean":i={value:S,type:"b"};break;default:i={value:String(S),type:"s"}}p.alternateRows&&f%2===1&&(i.style={...i.style,fill:{color:p.alternateBackground??"var(--nice-text-primary, #f5f5f5)"}}),Ae(o,l,v+h,i)}),l++});const $=b.map(k=>k.width??100);if(d&&$.unshift(40),o.columns=$.map(k=>({width:k/7})),j&&c&&(o.freezePane={row:x+1,col:0}),y&&c&&t.length>0){const k=ze(x,0),f=ze(l-1,b.length-1+h);o.autoFilter={start:k,end:f}}return Pt(C)}function rt(t,n,a={}){const{fileName:r="export",includeTimestamp:s=!1}=a,u=nt(t,n,a),c=s?`_${Le()}`:"",d=`${r}${c}.xlsx`,j=new Blob([u],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});Te(j,d)}function at(t,n,a={}){const{title:r,subtitle:s,orientation:u="portrait",pageSize:c="A4",margins:d={top:20,right:20,bottom:20,left:20},header:j,footer:y,logo:p,logoWidth:g=100,logoHeight:z,watermark:b,includeHeaders:C=!0,includeRowNumbers:o=!1,styles:l={},locale:h="en-US",dateTimeFormat:x="yyyy-MM-dd HH:mm:ss"}=a,$=n.filter(v=>v.visible!==!1),k=(v,S,i)=>{if(v==null)return"";if(S.format)return S.format(v,i);switch(S.dataType){case"date":return Fe(v,S.dateFormat??x);case"number":return Pe(v,S.numberFormat,h);case"currency":return Ue(v,S.currencyCode??"USD",h);case"boolean":return v?"✓":"✗";default:return String(v)}};let f=`
30
- <!DOCTYPE html>
31
- <html>
32
- <head>
33
- <meta charset="utf-8">
34
- <title>${Ne(r??"Export")}</title>
35
- <style>
36
- @page {
37
- size: ${c} ${u};
38
- margin: ${d.top}mm ${d.right}mm ${d.bottom}mm ${d.left}mm;
39
- }
40
-
41
- body {
42
- font-family: ${l.fontFamily??"Arial, sans-serif"};
43
- font-size: ${l.fontSize??10}pt;
44
- margin: 0;
45
- padding: 0;
46
- }
47
-
48
- .header {
49
- text-align: center;
50
- margin-bottom: var(--nice-space-5, 20px);
51
- }
52
-
53
- .title {
54
- font-size: 18pt;
55
- font-weight: bold;
56
- margin: 0 0 var(--nice-space-1-25, 5px) 0;
57
- }
58
-
59
- .subtitle {
60
- font-size: 12pt;
61
- color: var(--nice-text-secondary, #666);
62
- margin: 0;
63
- }
64
-
65
- .logo {
66
- max-width: ${g}px;
67
- ${z?`max-height: ${z}px;`:""}
68
- margin-bottom: var(--nice-space-2-5, 10px);
69
- }
70
-
71
- table {
72
- width: 100%;
73
- border-collapse: collapse;
74
- page-break-inside: auto;
75
- }
76
-
77
- tr {
78
- page-break-inside: avoid;
79
- page-break-after: auto;
80
- }
81
-
82
- th, td {
83
- border: 1px solid ${l.borderColor??"var(--nice-border, #ddd)"};
84
- padding: var(--nice-space-1-5, 6px) var(--nice-space-2, 8px);
85
- text-align: left;
86
- }
87
-
88
- th {
89
- background-color: ${l.headerBackground??"var(--nice-bg-secondary, #f5f5f5)"};
90
- color: ${l.headerColor??"var(--nice-text, #333)"};
91
- font-weight: ${l.headerFontWeight??"bold"};
92
- }
93
-
94
- tr:nth-child(even) {
95
- background-color: ${l.alternateRows!==!1?l.alternateBackground??"var(--nice-bg-secondary, #fafafa)":"transparent"};
96
- }
97
-
98
- .text-left { text-align: left; }
99
- .text-center { text-align: center; }
100
- .text-right { text-align: right; }
101
-
102
- .watermark {
103
- position: fixed;
104
- top: 50%;
105
- left: 50%;
106
- transform: translate(-50%, -50%) rotate(-45deg);
107
- font-size: 72pt;
108
- color: var(--nice-overlay-10, rgba(0, 0, 0, 0.1));
109
- pointer-events: none;
110
- z-index: -1;
111
- }
112
-
113
- .page-footer {
114
- position: fixed;
115
- bottom: 0;
116
- width: 100%;
117
- text-align: center;
118
- font-size: 9pt;
119
- color: var(--nice-text-secondary, #666);
120
- }
121
-
122
- @media print {
123
- .no-print { display: none; }
124
- }
125
- </style>
126
- </head>
127
- <body>
128
- `;if(b&&(f+=`<div class="watermark">${Ne(b)}</div>`),f+='<div class="header">',p&&(f+=`<img src="${p}" class="logo" alt="Logo">`),r&&(f+=`<h1 class="title">${Ne(r)}</h1>`),s&&(f+=`<p class="subtitle">${Ne(s)}</p>`),f+="</div>",f+="<table>",C){f+="<thead><tr>",o&&(f+='<th class="text-center">#</th>');for(const v of $){const S=v.align??"left";f+=`<th class="text-${S}" style="width: ${v.width??"auto"}px">${Ne(v.header)}</th>`}f+="</tr></thead>"}f+="<tbody>",t.forEach((v,S)=>{f+="<tr>",o&&(f+=`<td class="text-center">${S+1}</td>`);for(const i of $){const N=k(v[i.field],i,v),_=i.align??"left";f+=`<td class="text-${_}">${Ne(N)}</td>`}f+="</tr>"}),f+="</tbody>",f+="</table>",f+="</body></html>";const M=window.open("","_blank");M&&(M.document.write(f),M.document.close(),M.onload=()=>{M.print()})}function st(t,n,a={}){at(t,n,a)}function ot(t,n={}){const{pretty:a=!0,indent:r=2,fields:s,transform:u}=n;let c=t;return u&&(c=t.map((d,j)=>u(d,j))),s?.length&&(c=c.map(d=>{const j={};for(const y of s)y in d&&(j[y]=d[y]);return j})),JSON.stringify(c,null,a?r:void 0)}function ct(t,n={}){const{fileName:a="export",includeTimestamp:r=!1}=n,s=ot(t,n),u=r?`_${Le()}`:"",c=`${a}${u}.json`,d=new Blob([s],{type:"application/json;charset=utf-8"});Te(d,c)}function it(t,n,a={}){const{title:r,includeHeaders:s=!0,includeRowNumbers:u=!1,inlineStyles:c=!0,tableClass:d="nice-export-table",standalone:j=!0,styles:y={},locale:p="en-US",dateTimeFormat:g="yyyy-MM-dd HH:mm:ss"}=a,z=n.filter(o=>o.visible!==!1),b=(o,l,h)=>{if(o==null)return"";if(l.format)return l.format(o,h);switch(l.dataType){case"date":return Fe(o,l.dateFormat??g);case"number":return Pe(o,l.numberFormat,p);case"currency":return Ue(o,l.currencyCode??"USD",p);case"boolean":return o?"Yes":"No";default:return String(o)}};let C="";if(j&&(C+=`<!DOCTYPE html>
129
- <html>
130
- <head>
131
- <meta charset="utf-8">
132
- <title>${Ne(r??"Export")}</title>
133
- <style>
134
- .${d} {
135
- border-collapse: collapse;
136
- width: 100%;
137
- font-family: ${y.fontFamily??"Arial, sans-serif"};
138
- font-size: ${y.fontSize??12}px;
139
- }
140
- .${d} th, .${d} td {
141
- border: 1px solid ${y.borderColor??"var(--nice-border, #ddd)"};
142
- padding: var(--nice-space-2, 8px);
143
- text-align: left;
144
- }
145
- .${d} th {
146
- background-color: ${y.headerBackground??"var(--nice-bg-secondary, #f5f5f5)"};
147
- color: ${y.headerColor??"var(--nice-text, #333)"};
148
- font-weight: ${y.headerFontWeight??"bold"};
149
- }
150
- .${d} tr:nth-child(even) {
151
- background-color: ${y.alternateRows!==!1?y.alternateBackground??"var(--nice-bg-secondary, #fafafa)":"transparent"};
152
- }
153
- </style>
154
- </head>
155
- <body>
156
- `,r&&(C+=`<h1>${Ne(r)}</h1>`)),C+=`<table class="${d}"${!j&&c?' style="border-collapse:collapse;width:100%"':""}>`,s){C+="<thead><tr>",u&&(C+="<th>#</th>");for(const o of z)C+=`<th>${Ne(o.header)}</th>`;C+="</tr></thead>"}return C+="<tbody>",t.forEach((o,l)=>{C+="<tr>",u&&(C+=`<td>${l+1}</td>`);for(const h of z){const x=b(o[h.field],h,o);C+=`<td>${Ne(x)}</td>`}C+="</tr>"}),C+="</tbody></table>",j&&(C+="</body></html>"),C}function lt(t,n,a={}){const{fileName:r="export",includeTimestamp:s=!1}=a,u=it(t,n,{...a,standalone:!0}),c=s?`_${Le()}`:"",d=`${r}${c}.html`,j=new Blob([u],{type:"text/html;charset=utf-8"});Te(j,d)}function Te(t,n){const a=URL.createObjectURL(t),r=document.createElement("a");r.href=a,r.download=n,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(a)}function Le(){return new Date().toISOString().slice(0,19).replace(/[T:]/g,"-")}function Fe(t,n,a){const r=t instanceof Date?t:new Date(t);if(isNaN(r.getTime()))return String(t);const s=u=>String(u).padStart(2,"0");return n.replace("yyyy",String(r.getFullYear())).replace("MM",s(r.getMonth()+1)).replace("dd",s(r.getDate())).replace("HH",s(r.getHours())).replace("mm",s(r.getMinutes())).replace("ss",s(r.getSeconds()))}function Pe(t,n,a){if(n){const r=n.match(/0+$/)?.[0]?.length??0;return t.toLocaleString(a,{minimumFractionDigits:r,maximumFractionDigits:r})}return t.toLocaleString(a)}function Ue(t,n,a){return t.toLocaleString(a,{style:"currency",currency:n})}function Yt(t){const n=t instanceof Date?t:new Date(t),a=new Date(1899,11,30),r=1440*60*1e3;return(n.getTime()-a.getTime())/r}function Ne(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function Vt(t){const{data:n,columns:a,format:r,options:s={}}=t;switch(r){case"csv":tt(n,a,s);break;case"xlsx":rt(n,a,s);break;case"pdf":st(n,a,s);break;case"json":ct(n,s);break;case"html":lt(n,a,s);break;default:throw new Error(`Unsupported export format: ${r}`)}}function Xt(t,n={}){const{maxSample:a=100,exclude:r=[]}=n;if(t.length===0)return[];const s=t.slice(0,a),u=t[0],c=[];for(const d of Object.keys(u)){if(r.includes(d))continue;let j="string";for(const y of s){const p=y[d];if(p!=null){if(typeof p=="number"){j="number";break}if(typeof p=="boolean"){j="boolean";break}if(p instanceof Date){j="date";break}if(typeof p=="string"&&/^\d{4}-\d{2}-\d{2}/.test(p)&&!isNaN(Date.parse(p))){j="date";break}}}c.push({field:d,header:Gt(d),dataType:j})}return c}function Gt(t){return t.replace(/([A-Z])/g," $1").replace(/_/g," ").replace(/^\s+/,"").split(" ").map(n=>n.charAt(0).toUpperCase()+n.slice(1).toLowerCase()).join(" ")}function dt(t,n={}){const a=n.nodeWidth??160,r=n.nodeHeight??56,s=n.siblingGap??24,u=n.levelGap??48,c=n.direction==="LR",d=k=>c?k.height??r:k.width??a,j=k=>c?k.width??a:k.height??r,y=new Set,p=new Map,g=new Map,z=[],b=(k,f)=>{y.add(k.id),z[f]=Math.max(z[f]??0,j(k));const M=(k.children??[]).filter(i=>!y.has(i.id));M.forEach(i=>y.add(i.id)),p.set(k.id,M);const v=M.reduce((i,N,_)=>i+b(N,f+1)+(_>0?s:0),0),S=Math.max(d(k),v);return g.set(k.id,S),S},C=[],o=[];for(const k of t)y.has(k.id)||(C.push(k),o.push(b(k,0)));const l=[];z.forEach((k,f)=>{l[f]=f===0?0:l[f-1]+z[f-1]+u});const h=new Map,x=(k,f,M)=>{const v=g.get(k.id)??d(k),S=p.get(k.id)??[],i=S.reduce((D,B,Y)=>D+(g.get(B.id)??d(B))+(Y>0?s:0),0);let N=f+(v-i)/2;const _=[];for(const D of S)_.push(x(D,N,M+1)),N+=(g.get(D.id)??d(D))+s;const E=_.length?(_[0]+_[_.length-1])/2:f+v/2,T=Math.min(Math.max(E-d(k)/2,f),f+v-d(k)),P=l[M];return h.set(k.id,{x:c?P:T,y:c?T:P,width:k.width??a,height:k.height??r,depth:M}),T+d(k)/2};let $=0;return C.forEach((k,f)=>{x(k,$,0),$+=o[f]+s}),h}const Ge=t=>t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;");function He(t,n={}){const a=n.fontSize??13,r=n.nodeHeight??40,s=n.minNodeWidth??120,u=n.direction==="left-right",c=16,d=x=>({id:x.key,width:Math.max(s,Math.round(x.label.length*a*.6)+32),height:r,children:(x.children??[]).map(d)}),j=dt([d(t)],{direction:u?"LR":"TB",siblingGap:16,levelGap:32});let y=0,p=0;for(const x of j.values())y=Math.max(y,x.x+x.width),p=Math.max(p,x.y+x.height);const g=n.lineColor??"#9ca3af",z=[],b=x=>{const $=j.get(x.key);if($)for(const k of x.children??[]){const f=j.get(k.key);if(f){if(u){const M=$.x+$.width+c,v=$.y+$.height/2+c,S=f.x+c,i=f.y+f.height/2+c,N=(M+S)/2;z.push(`<path d="M${M} ${v}H${N}V${i}H${S}" fill="none" stroke="${g}" stroke-width="1.5"/>`)}else{const M=$.x+$.width/2+c,v=$.y+$.height+c,S=f.x+f.width/2+c,i=f.y+c,N=(v+i)/2;z.push(`<path d="M${M} ${v}V${N}H${S}V${i}" fill="none" stroke="${g}" stroke-width="1.5"/>`)}b(k)}}};b(t);const C=[],o=x=>{const $=j.get(x.key);$&&C.push(`<g><rect x="${$.x+c}" y="${$.y+c}" width="${$.width}" height="${$.height}" rx="6" fill="${n.boxFill??"#ffffff"}" stroke="${n.boxStroke??"#d1d5db"}"/><text x="${$.x+c+$.width/2}" y="${$.y+c+$.height/2}" text-anchor="middle" dominant-baseline="central" font-size="${a}" fill="${n.textColor??"#111827"}">${Ge(x.label)}</text></g>`),(x.children??[]).forEach(o)};o(t);const l=y+c*2,h=p+c*2;return`<svg xmlns="http://www.w3.org/2000/svg" width="${l}" height="${h}" viewBox="0 0 ${l} ${h}" font-family="${Ge(n.fontFamily??"system-ui, sans-serif")}"><rect width="100%" height="100%" fill="${n.background??"#ffffff"}"/>`+z.join("")+C.join("")+"</svg>"}async function ht(t,n={}){const a=He(t,n),r=n.scale??2,s=/width="([\d.]+)" height="([\d.]+)"/.exec(a),u=Number(s?.[1]??0),c=Number(s?.[2]??0),d=URL.createObjectURL(new Blob([a],{type:"image/svg+xml"}));try{const j=new Image;await new Promise((g,z)=>{j.onload=()=>g(),j.onerror=()=>z(new Error("The chart image could not be drawn.")),j.src=d});const y=document.createElement("canvas");y.width=Math.ceil(u*r),y.height=Math.ceil(c*r);const p=y.getContext("2d");if(!p)throw new Error("No 2D canvas.");return p.scale(r,r),p.drawImage(j,0,0),await new Promise((g,z)=>y.toBlob(b=>b?g(b):z(new Error("No PNG.")),"image/png"))}finally{URL.revokeObjectURL(d)}}const Zt=Object.assign(w.forwardRef(({data:t,renderNode:n,selectable:a,selectedKey:r,onSelect:s,direction:u="top-down",collapsible:c=!0,zoomable:d=!1,exportable:j=!1,onExport:y,className:p,style:g,id:z,testId:b,"data-testid":C},o)=>{const{t:l}=le.useNiceTranslation(),h=le.useControlId(z),[x,$]=w.useState(new Set),[k,f]=w.useState(1),M=w.useRef(null),v=w.useRef(null),S=w.useRef(null);le.useRovingFocus(S,{orientation:"horizontal"});const i=B=>f(Y=>Math.min(2,Math.max(.2,Math.round(Y*B*100)/100))),N=()=>{const B=M.current,Y=v.current;if(!B||!Y)return;const F=Y.scrollWidth/k,V=Y.scrollHeight/k;F>0&&V>0&&f(Math.max(.2,Math.min(1,B.clientWidth/F,B.clientHeight/V)))},_=j===!0?["svg","png"]:j===!1?[]:j,E=async B=>{const Y={direction:u};if(B==="svg"){const V=He(t,Y);y?y("svg",V):Te(new Blob([V],{type:"image/svg+xml"}),"organization-chart.svg");return}const F=await ht(t,Y);y?y("png",F):Te(F,"organization-chart.png")},T=w.useCallback(B=>{$(Y=>{const F=new Set(Y);return F.has(B)?F.delete(B):F.add(B),F})},[]),P=w.useCallback(B=>{a&&s?.(B)},[a,s]),D=w.useCallback(B=>{const Y=x.has(B.key),F=B.children&&B.children.length>0;return e.jsxs("li",{className:"nice-org-chart__item",children:[e.jsxs("div",{tabIndex:a?0:void 0,onKeyDown:a?le.clickOnActivationKey:void 0,className:`nice-org-chart__node${r===B.key?" nice-org-chart__node--selected":""}`,onClick:()=>P(B.key),role:a?"button":void 0,children:[n?n(B):e.jsx("span",{children:B.label}),c&&F&&e.jsx("button",{type:"button",className:"nice-org-chart__toggle",onClick:V=>{V.stopPropagation(),T(B.key)},"aria-label":Y?l("organizationChart.expand","Expand"):l("organizationChart.collapse","Collapse"),children:e.jsx(le.NiceIcon,{name:Y?"plus":"minus",size:14})})]}),F&&!Y&&e.jsx("ul",{className:"nice-org-chart__children",children:B.children.map(V=>D(V))})]},B.key)},[x,r,n,a,c,P,T,l]);return e.jsxs("div",{ref:o,id:h,className:`nice-org-chart nice-org-chart--${u}${d||_.length?" nice-org-chart--tools":""} ${p||""}`,style:g,"data-testid":C??b,children:[(d||_.length>0)&&e.jsxs("div",{ref:S,className:"nice-org-chart__tools",role:"toolbar","aria-label":l("organizationChart.tools","Chart tools"),children:[d&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"nice-org-chart__tool",onClick:()=>i(1/1.2),"aria-label":l("organizationChart.zoomOut","Zoom out"),title:l("organizationChart.zoomOut","Zoom out"),children:e.jsx(le.NiceIcon,{name:"zoom-out",size:14})}),e.jsxs("span",{className:"nice-org-chart__zoom","aria-live":"polite",children:[Math.round(k*100),"%"]}),e.jsx("button",{type:"button",className:"nice-org-chart__tool",onClick:()=>i(1.2),"aria-label":l("organizationChart.zoomIn","Zoom in"),title:l("organizationChart.zoomIn","Zoom in"),children:e.jsx(le.NiceIcon,{name:"zoom-in",size:14})}),e.jsx("button",{type:"button",className:"nice-org-chart__tool",onClick:N,"aria-label":l("organizationChart.fit","Fit to view"),title:l("organizationChart.fit","Fit to view"),children:e.jsx(le.NiceIcon,{name:"expand",size:14})})]}),_.map(B=>e.jsxs("button",{type:"button",className:"nice-org-chart__tool",onClick:()=>void E(B),title:l("organizationChart.export","Export as {format}").replace("{format}",B.toUpperCase()),children:[e.jsx(le.NiceIcon,{name:"download",size:14})," ",B.toUpperCase()]},B))]}),e.jsx("div",{ref:M,className:"nice-org-chart__view",children:e.jsx("ul",{ref:v,className:"nice-org-chart__root",style:k!==1?{zoom:k}:void 0,children:D(t)})})]})}),{displayName:"NiceOrganizationChart"}),qt=[],Kt=Object.assign(w.forwardRef(({data:t=qt,type:n="candlestick",showVolume:a=!0,width:r=800,height:s=400,bullColor:u="var(--nice-color-success, #22c55e)",bearColor:c="var(--nice-color-error, #ef4444)",className:d,style:j,id:y,testId:p,"data-testid":g},z)=>{const b=le.useControlId(y),C={top:20,right:20,bottom:a?80:30,left:60},o=r-C.left-C.right,l=a?50:0,h=s-C.top-C.bottom-l,{minP:x,maxP:$,maxVol:k}=w.useMemo(()=>{if(t.length===0)return{minP:0,maxP:1,maxVol:0};let i=1/0,N=-1/0,_=0;for(const E of t)E.low<i&&(i=E.low),E.high>N&&(N=E.high),E.volume&&E.volume>_&&(_=E.volume);return{minP:i,maxP:N,maxVol:_}},[t]),f=Math.max(1,o/t.length*.7),M=i=>C.left+(i+.5)*(o/t.length),v=i=>C.top+h-(i-x)/($-x||1)*h,S=i=>s-C.bottom-l+l*(1-i/(k||1));return e.jsx("div",{ref:z,id:b,className:`nice-stock-chart ${d||""}`,style:j,"data-testid":g??p,children:e.jsxs("svg",{width:r,height:s,className:"nice-stock-chart__svg",children:[[0,.25,.5,.75,1].map(i=>{const N=x+i*($-x);return e.jsxs("g",{children:[e.jsx("line",{x1:C.left,x2:r-C.right,y1:v(N),y2:v(N),stroke:"var(--nice-border, #e5e7eb)",strokeDasharray:"2,2"}),t.length>0&&e.jsx("text",{x:C.left-4,y:v(N)+4,textAnchor:"end",fontSize:10,fill:"var(--nice-text-secondary, #888)",children:N.toFixed(2)})]},i)}),n==="line"?e.jsx("polyline",{points:t.map((i,N)=>`${M(N)},${v(i.close)}`).join(" "),fill:"none",stroke:u,strokeWidth:1.5}):t.map((i,N)=>{const _=i.close>=i.open,E=_?u:c,T=M(N);if(n==="ohlc")return e.jsxs("g",{children:[e.jsx("line",{x1:T,x2:T,y1:v(i.high),y2:v(i.low),stroke:E,strokeWidth:1}),e.jsx("line",{x1:T-f/2,x2:T,y1:v(i.open),y2:v(i.open),stroke:E,strokeWidth:1.5}),e.jsx("line",{x1:T,x2:T+f/2,y1:v(i.close),y2:v(i.close),stroke:E,strokeWidth:1.5})]},N);const P=v(Math.max(i.open,i.close)),D=v(Math.min(i.open,i.close));return e.jsxs("g",{children:[e.jsx("line",{x1:T,x2:T,y1:v(i.high),y2:v(i.low),stroke:E,strokeWidth:1}),e.jsx("rect",{x:T-f/2,y:P,width:f,height:Math.max(D-P,1),fill:_?"transparent":E,stroke:E,strokeWidth:1})]},N)}),a&&t.map((i,N)=>{if(!i.volume)return null;const _=i.close>=i.open;return e.jsx("rect",{x:M(N)-f/2,y:S(i.volume),width:f,height:s-C.bottom-S(i.volume),fill:_?u:c,opacity:.3},`v${N}`)}),t.map((i,N)=>N%Math.max(1,Math.floor(t.length/8))!==0?null:e.jsx("text",{x:M(N),y:s-C.bottom+l+14,textAnchor:"middle",fontSize:9,fill:"var(--nice-text-secondary, #888)",children:i.date},`l${N}`))]})})}),{displayName:"NiceStockChart"}),Jt=[],Qt=({data:t=Jt,width:n=120,height:a=30,type:r="line",color:s="var(--nice-color-primary, #3b82f6)",showMinMax:u,showLastPoint:c=!0,className:d,style:j,testId:y,"data-testid":p})=>{if(t.length===0)return null;const g=2,z=Math.min(...t),b=Math.max(...t),C=b-z||1,o=n-g*2,l=a-g*2,h=v=>g+v/(t.length-1||1)*o,x=v=>g+l-(v-z)/C*l;if(r==="bar"){const v=Math.max(1,o/t.length-1);return e.jsx("svg",{width:n,height:a,className:`nice-sparkline ${d||""}`,style:j,"data-testid":p??y,children:t.map((S,i)=>e.jsx("rect",{x:g+i/t.length*o,y:x(S),width:v,height:l-(x(S)-g),fill:s,rx:1},i))})}const $=t.map((v,S)=>`${h(S)},${x(v)}`).join(" "),k=t.indexOf(z),f=t.indexOf(b),M=t.length-1;return e.jsxs("svg",{width:n,height:a,className:`nice-sparkline ${d||""}`,style:j,"data-testid":p??y,children:[r==="area"&&e.jsx("polygon",{points:`${h(0)},${g+l} ${$} ${h(M)},${g+l}`,fill:s,opacity:.15}),e.jsx("polyline",{points:$,fill:"none",stroke:s,strokeWidth:1.5}),u&&e.jsx("circle",{cx:h(k),cy:x(z),r:2,fill:"var(--nice-danger, #ef4444)"}),u&&e.jsx("circle",{cx:h(f),cy:x(b),r:2,fill:"var(--nice-success, #22c55e)"}),c&&e.jsx("circle",{cx:h(M),cy:x(t[M]),r:2,fill:s})]})},en=[],tn=[],nn=({series:t=en,categories:n=tn,width:a=400,height:r=400,maxValue:s,title:u,showLegend:c=!0,className:d,style:j,testId:y,"data-testid":p})=>{const g=u?44:0,z=r-(c?30:0)-g,b=a/2,C=g+z/2,o=Math.min(b,z/2)-60,l=n.length,h=s??Math.max(...t.flatMap(f=>f.data),1),x=Math.PI*2/l,$=5,k=(f,M)=>{const v=f*x-Math.PI/2,S=M/h*o;return{x:b+S*Math.cos(v),y:C+S*Math.sin(v)}};return e.jsx("div",{className:`nice-polarchart ${d||""}`,style:j,"data-testid":p??y,children:e.jsxs("svg",{width:a,height:r,className:"nice-polarchart__svg",children:[u&&e.jsx("text",{x:b,y:20,textAnchor:"middle",className:"nice-chart__title",children:u}),Array.from({length:$},(f,M)=>{const v=o*((M+1)/$);return e.jsx("circle",{cx:b,cy:C,r:v,fill:"none",stroke:"var(--nice-border-color, #ddd)",strokeWidth:.5},M)}),n.map((f,M)=>{const v=k(M,h),S=k(M,h*1.22),i=M*x-Math.PI/2,N=Math.cos(i),_=Math.sin(i),E=N>.2?"start":N<-.2?"end":"middle",T=_>.2?"hanging":_<-.2?"auto":"middle";return e.jsxs("g",{children:[e.jsx("line",{x1:b,y1:C,x2:v.x,y2:v.y,stroke:"var(--nice-border-color, #ddd)",strokeWidth:.5}),e.jsx("text",{x:S.x,y:S.y,textAnchor:E,dominantBaseline:T,className:"nice-chart__axis-label nice-chart__axis-label--polar",children:f})]},M)}),t.map((f,M)=>{const v=f.color||_e[M%_e.length],S=f.data.map((i,N)=>{const _=k(N,i);return`${_.x},${_.y}`}).join(" ");return e.jsxs("g",{children:[e.jsx("polygon",{points:S,fill:f.fill!==!1?v:"none",fillOpacity:.15,stroke:v,strokeWidth:2}),f.data.map((i,N)=>{const _=k(N,i);return e.jsx("circle",{cx:_.x,cy:_.y,r:3,fill:v,children:e.jsx("title",{children:`${f.name} - ${n[N]}: ${i}`})},N)})]},f.name)}),c&&e.jsx("g",{transform:`translate(10, ${r-25})`,children:t.map((f,M)=>e.jsxs("g",{transform:`translate(${M*100}, 0)`,children:[e.jsx("rect",{width:10,height:10,rx:2,fill:f.color||_e[M%_e.length]}),e.jsx("text",{x:14,y:9,className:"nice-chart__legend-text",children:f.name})]},M))})]})})},rn=({data:t,min:n,max:a,start:r,end:s,onChange:u,width:c=500,height:d=100,step:j=1,formatValue:y,chartColor:p="var(--nice-color-primary, #3b82f6)",className:g,style:z,testId:b,"data-testid":C})=>{const o={top:10,bottom:30,left:10,right:10},l=c-o.left-o.right,h=d-o.top-o.bottom,x=S=>o.left+(S-n)/(a-n||1)*l,$=S=>{const i=Math.max(0,Math.min(1,(S-o.left)/l)),N=n+i*(a-n);return Math.round(N/j)*j},k=(S,i)=>{i.preventDefault();const N=i.target.closest("svg");if(!N)return;const _=T=>{const P=N.getBoundingClientRect(),D=$(T.clientX-P.left);S==="start"?u(Math.min(D,s),s):u(r,Math.max(D,r))},E=()=>{document.removeEventListener("pointermove",_),document.removeEventListener("pointerup",E)};document.addEventListener("pointermove",_),document.addEventListener("pointerup",E)},f=t?Math.min(...t):0,v=(t?Math.max(...t):1)-f||1;return e.jsx("div",{className:`nice-rangeselector ${g||""}`,style:z,"data-testid":C??b,children:e.jsxs("svg",{width:c,height:d,children:[t&&t.length>1&&e.jsx("polygon",{points:`${o.left},${o.top+h} ${t.map((S,i)=>`${o.left+i/(t.length-1)*l},${o.top+h-(S-f)/v*h}`).join(" ")} ${o.left+l},${o.top+h}`,fill:p,opacity:.15}),e.jsx("rect",{x:x(r),y:o.top,width:x(s)-x(r),height:h,fill:p,opacity:.1}),e.jsx("rect",{x:o.left,y:o.top,width:x(r)-o.left,height:h,fill:"var(--nice-bg-secondary, #f5f5f5)",opacity:.6}),e.jsx("rect",{x:x(s),y:o.top,width:o.left+l-x(s),height:h,fill:"var(--nice-bg-secondary, #f5f5f5)",opacity:.6}),e.jsx("rect",{x:x(r)-4,y:o.top,width:8,height:h,fill:p,rx:2,cursor:"ew-resize",onPointerDown:S=>k("start",S)}),e.jsx("rect",{x:x(s)-4,y:o.top,width:8,height:h,fill:p,rx:2,cursor:"ew-resize",onPointerDown:S=>k("end",S)}),e.jsx("text",{x:x(r),y:o.top+h+18,textAnchor:"middle",className:"nice-chart__axis-label",children:y?y(r):r}),e.jsx("text",{x:x(s),y:o.top+h+18,textAnchor:"middle",className:"nice-chart__axis-label",children:y?y(s):s})]})})},an=`
157
- .nice-forecast-chart {
158
- display: flex;
159
- flex-direction: column;
160
- background: var(--nice-bg-primary, #ffffff);
161
- border: 1px solid var(--nice-border-color, #e5e7eb);
162
- border-radius: var(--nice-radius-lg, 0.5rem);
163
- overflow: hidden;
164
- }
165
-
166
- .nice-forecast-chart__header {
167
- display: flex;
168
- align-items: center;
169
- justify-content: space-between;
170
- padding: 0.75rem 1rem;
171
- border-bottom: 1px solid var(--nice-border-color, #e5e7eb);
172
- }
173
-
174
- .nice-forecast-chart__title {
175
- font-size: 1rem;
176
- font-weight: 600;
177
- color: var(--nice-text-primary);
178
- margin: 0;
179
- }
180
-
181
- .nice-forecast-chart__actions {
182
- display: flex;
183
- gap: 0.5rem;
184
- }
185
-
186
- .nice-forecast-chart__btn {
187
- display: inline-flex;
188
- align-items: center;
189
- justify-content: center;
190
- width: 2rem;
191
- height: 2rem;
192
- font-size: 1rem;
193
- border-radius: var(--nice-radius-md, 0.375rem);
194
- cursor: pointer;
195
- transition: all 0.15s ease;
196
- border: 1px solid var(--nice-border-color, #d1d5db);
197
- background: var(--nice-bg-primary, #ffffff);
198
- color: var(--nice-text-secondary);
199
- }
200
-
201
- .nice-forecast-chart__btn:hover {
202
- background: var(--nice-bg-hover, #f3f4f6);
203
- color: var(--nice-text-primary);
204
- }
205
-
206
- .nice-forecast-chart__btn:disabled {
207
- opacity: 0.5;
208
- cursor: not-allowed;
209
- }
210
-
211
- .nice-forecast-chart__container {
212
- position: relative;
213
- width: 100%;
214
- padding: 1rem;
215
- }
216
-
217
- .nice-forecast-chart__svg {
218
- width: 100%;
219
- overflow: visible;
220
- }
221
-
222
- .nice-forecast-chart__grid-line {
223
- stroke: var(--nice-border-divider, #f3f4f6);
224
- stroke-width: 1;
225
- }
226
-
227
- .nice-forecast-chart__axis-line {
228
- stroke: var(--nice-border-color, #e5e7eb);
229
- stroke-width: 1;
230
- }
231
-
232
- .nice-forecast-chart__axis-label {
233
- font-size: 0.6875rem;
234
- fill: var(--nice-text-secondary);
235
- }
236
-
237
- .nice-forecast-chart__axis-title {
238
- font-size: 0.75rem;
239
- font-weight: 500;
240
- fill: var(--nice-text-primary);
241
- }
242
-
243
- .nice-forecast-chart__historical-line {
244
- fill: none;
245
- stroke-width: 2;
246
- stroke-linecap: round;
247
- stroke-linejoin: round;
248
- }
249
-
250
- .nice-forecast-chart__forecast-line {
251
- fill: none;
252
- stroke-width: 2;
253
- stroke-linecap: round;
254
- stroke-linejoin: round;
255
- stroke-dasharray: 6, 4;
256
- }
257
-
258
- .nice-forecast-chart__confidence-band {
259
- opacity: 0.2;
260
- }
261
-
262
- .nice-forecast-chart__forecast-region {
263
- fill: var(--nice-bg-secondary, #f9fafb);
264
- opacity: 0.5;
265
- }
266
-
267
- .nice-forecast-chart__point {
268
- cursor: pointer;
269
- transition: r 0.15s ease;
270
- }
271
-
272
- .nice-forecast-chart__point:hover {
273
- r: 6;
274
- }
275
-
276
- .nice-forecast-chart__annotation-line {
277
- stroke-dasharray: 4, 2;
278
- stroke-width: 1;
279
- }
280
-
281
- .nice-forecast-chart__annotation-marker {
282
- cursor: pointer;
283
- transition: transform 0.15s ease;
284
- }
285
-
286
- .nice-forecast-chart__annotation-marker:hover {
287
- transform: scale(1.2);
288
- }
289
-
290
- .nice-forecast-chart__reference-line {
291
- stroke-width: 1;
292
- }
293
-
294
- .nice-forecast-chart__reference-label {
295
- font-size: 0.625rem;
296
- fill: var(--nice-text-secondary);
297
- }
298
-
299
- .nice-forecast-chart__cash-runway {
300
- pointer-events: none;
301
- }
302
-
303
- .nice-forecast-chart__cash-runway-line {
304
- stroke: var(--nice-danger, #ef4444);
305
- stroke-width: 2;
306
- stroke-dasharray: 8, 4;
307
- }
308
-
309
- .nice-forecast-chart__cash-runway-label-bg {
310
- fill: var(--nice-danger, #ef4444);
311
- rx: 4;
312
- }
313
-
314
- .nice-forecast-chart__cash-runway-label {
315
- font-size: 0.6875rem;
316
- font-weight: 600;
317
- fill: var(--nice-bg, #FFFFFF);
318
- }
319
-
320
- .nice-forecast-chart__cash-runway-date {
321
- font-size: 0.625rem;
322
- fill: var(--nice-danger, #ef4444);
323
- font-weight: 500;
324
- }
325
-
326
- .nice-forecast-chart__tooltip {
327
- position: absolute;
328
- pointer-events: none;
329
- z-index: 100;
330
- padding: 0.75rem;
331
- background: var(--nice-bg-primary, #ffffff);
332
- border: 1px solid var(--nice-border-color, #e5e7eb);
333
- border-radius: var(--nice-radius-lg, 0.5rem);
334
- box-shadow: 0 4px 12px var(--nice-overlay-10, rgba(0, 0, 0, 0.1));
335
- font-size: 0.8125rem;
336
- max-width: 250px;
337
- }
338
-
339
- .nice-forecast-chart__tooltip-date {
340
- font-weight: 600;
341
- color: var(--nice-text-primary);
342
- margin-bottom: 0.5rem;
343
- padding-bottom: 0.5rem;
344
- border-bottom: 1px solid var(--nice-border-divider, #f3f4f6);
345
- }
346
-
347
- .nice-forecast-chart__tooltip-item {
348
- display: flex;
349
- align-items: center;
350
- gap: 0.5rem;
351
- margin-bottom: 0.25rem;
352
- }
353
-
354
- .nice-forecast-chart__tooltip-color {
355
- width: 10px;
356
- height: 10px;
357
- border-radius: var(--nice-radius-sm, 2px);
358
- flex-shrink: 0;
359
- }
360
-
361
- .nice-forecast-chart__tooltip-label {
362
- color: var(--nice-text-secondary);
363
- flex: 1;
364
- }
365
-
366
- .nice-forecast-chart__tooltip-value {
367
- font-weight: 600;
368
- color: var(--nice-text-primary);
369
- font-variant-numeric: tabular-nums;
370
- }
371
-
372
- .nice-forecast-chart__tooltip-confidence {
373
- font-size: 0.75rem;
374
- color: var(--nice-text-tertiary);
375
- }
376
-
377
- .nice-forecast-chart__legend {
378
- display: flex;
379
- flex-wrap: wrap;
380
- gap: 1rem;
381
- padding: 0.75rem 1rem;
382
- border-top: 1px solid var(--nice-border-color, #e5e7eb);
383
- }
384
-
385
- .nice-forecast-chart__legend-item {
386
- display: flex;
387
- align-items: center;
388
- gap: 0.375rem;
389
- font-size: 0.8125rem;
390
- color: var(--nice-text-secondary);
391
- cursor: pointer;
392
- user-select: none;
393
- transition: opacity 0.15s ease;
394
- }
395
-
396
- .nice-forecast-chart__legend-item:hover {
397
- color: var(--nice-text-primary);
398
- }
399
-
400
- .nice-forecast-chart__legend-item--hidden {
401
- opacity: 0.4;
402
- }
403
-
404
- .nice-forecast-chart__legend-color {
405
- width: 16px;
406
- height: 3px;
407
- border-radius: var(--nice-radius-xs, 1px);
408
- }
409
-
410
- .nice-forecast-chart__legend-color--dashed {
411
- background: repeating-linear-gradient(
412
- 90deg,
413
- currentColor,
414
- currentColor 4px,
415
- transparent 4px,
416
- transparent 6px
417
- );
418
- }
419
-
420
- .nice-forecast-chart__empty {
421
- display: flex;
422
- align-items: center;
423
- justify-content: center;
424
- height: 300px;
425
- color: var(--nice-text-secondary);
426
- }
427
-
428
- /* Dark mode */
429
- .dark .nice-forecast-chart {
430
- background: var(--nice-bg-primary-dark, #111827);
431
- border-color: var(--nice-border-color-dark, #374151);
432
- }
433
-
434
- .dark .nice-forecast-chart__tooltip {
435
- background: var(--nice-bg-secondary-dark, #1f2937);
436
- border-color: var(--nice-border-color-dark, #374151);
437
- }
438
-
439
- .dark .nice-forecast-chart__forecast-region {
440
- fill: var(--nice-bg-secondary-dark, #1f2937);
441
- }
442
- `,Ze=["var(--nice-color-primary, #3b82f6)","var(--nice-color-success, #10b981)","var(--nice-color-warning, #f59e0b)","var(--nice-color-error, #ef4444)","var(--nice-color-accent, #8b5cf6)","var(--nice-color-accent-pink, #ec4899)","var(--nice-color-info, #06b6d4)","var(--nice-warning, #f97316)"];function be(t){return t instanceof Date?t:new Date(t)}function Oe(t,n="pl-PL"){return t.toLocaleDateString(n,{year:"numeric",month:"short",day:"numeric"})}function Re(t,n="pl-PL"){return new Intl.NumberFormat(n,{minimumFractionDigits:0,maximumFractionDigits:2}).format(t)}const sn={top:20,right:30,bottom:40,left:60},on=w.forwardRef(function(n,a){const{t:r}=le.useNiceTranslation(),{scenarios:s,data:u,annotations:c=[],referenceLines:d=[],forecastStartDate:j,cashRunway:y,xAxis:p,yAxis:g,confidenceBands:z=[{level:95,color:"var(--nice-color-primary, #3b82f6)",opacity:.15}],tooltip:b,legend:C={enabled:!0,position:"bottom",interactive:!0},height:o=350,showForecastRegion:l=!0,lineWidth:h=2,showPoints:x=!1,pointRadius:$=4,enableZoom:k=!1,zoomEnabled:f,animationDuration:M=300,showLegend:v,responsive:S=!0,onPointClick:i,onAnnotationClick:N,onScenarioToggle:_,onViewportChange:E,size:T="medium",disabled:P=!1,labels:D={},locale:B="pl-PL",className:Y,style:F,testId:V,"data-testid":q}=n,K=s&&s.length>0?s:u?[{id:"default",name:"Series",data:u}]:[],R={...C,enabled:v??C.enabled},[X,te]=w.useState(()=>K.map((m,H)=>({...m,color:m.color??Ze[H%Ze.length],visible:m.visible!==!1}))),[se,ae]=w.useState(null),[he,W]=w.useState({x:0,y:0}),A=w.useRef(null),U=w.useRef(null),I=sn,[G,fe]=w.useState({width:600,height:typeof o=="number"?o:350});w.useEffect(()=>{if(!S||!A.current)return;const m=new ResizeObserver(H=>{for(const J of H)fe(O=>({width:J.contentRect.width,height:O.height}))});return m.observe(A.current),()=>m.disconnect()},[S]),w.useEffect(()=>{const m="nice-forecast-chart-styles";if(!document.getElementById(m)){const H=document.createElement("style");H.id=m,H.textContent=an,document.head.appendChild(H)}},[]);const{xScale:Z,yScale:oe,allDates:ue,minY:ye,maxY:$e}=w.useMemo(()=>{const H=X.filter(xe=>xe.visible!==!1).flatMap(xe=>xe.data);if(H.length===0)return{xScale:()=>0,yScale:()=>0,allDates:[],minY:0,maxY:100};const J=H.map(xe=>be(xe.date).getTime()),O=Math.min(...J),Q=Math.max(...J),re=H.flatMap(xe=>[xe.value,xe.forecast,xe.lowerBound,xe.upperBound]).filter(xe=>xe!=null),ce=g?.min??Math.min(...re)*.95,de=g?.max??Math.max(...re)*1.05,pe=G.width-I.left-I.right,ge=G.height-I.top-I.bottom,ke=xe=>{const Be=typeof xe=="number"?xe:xe.getTime();return I.left+(Be-O)/(Q-O)*pe},Ce=xe=>I.top+ge-(xe-ce)/(de-ce)*ge,Ee=[...new Set(J)].sort((xe,Be)=>xe-Be).map(xe=>new Date(xe));return{xScale:ke,yScale:Ce,allDates:Ee,minY:ce,maxY:de}},[X,G,I,g]),ve=j?be(j):null,je=w.useMemo(()=>{if(!y?.enabled)return null;const m=y.threshold??0,H=y.scenarioId?X.find(O=>O.id===y.scenarioId&&O.visible!==!1):X.find(O=>O.visible!==!1);if(!H)return null;const J=H.data.sort((O,Q)=>be(O.date).getTime()-be(Q.date).getTime());for(let O=1;O<J.length;O++){const Q=J[O-1],re=J[O],ce=Q.forecast??Q.value,de=re.forecast??re.value;if(ce!=null&&de!=null&&ce>m&&de<=m){const pe=(ce-m)/(ce-de),ge=be(Q.date).getTime(),ke=be(re.date).getTime(),Ce=ge+pe*(ke-ge);return new Date(Ce)}}return null},[y,X]),Me=w.useCallback((m,H)=>{const J=m.filter(O=>O[H]!=null).map(O=>({x:Z(be(O.date)),y:oe(O[H])}));return J.length===0?"":`M ${J.map(O=>`${O.x},${O.y}`).join(" L ")}`},[Z,oe]),ne=w.useCallback(m=>{const H=m.filter(Q=>Q.lowerBound!=null&&Q.upperBound!=null);if(H.length===0)return"";const J=H.map(Q=>({x:Z(be(Q.date)),y:oe(Q.upperBound)})),O=H.map(Q=>({x:Z(be(Q.date)),y:oe(Q.lowerBound)})).reverse();return`M ${J.map(Q=>`${Q.x},${Q.y}`).join(" L ")} L ${O.map(Q=>`${Q.x},${Q.y}`).join(" L ")} Z`},[Z,oe]),ie=w.useCallback(m=>{if(!U.current||b?.enabled===!1)return;const H=U.current.getBoundingClientRect(),J=m.clientX-H.left;m.clientY-H.top;let O=null,Q=1/0;for(const re of ue){const ce=Z(re),de=Math.abs(ce-J);de<Q&&(Q=de,O=re)}if(O&&Q<50){const re=X.filter(de=>de.visible!==!1).map(de=>{const pe=de.data.find(ge=>be(ge.date).getTime()===O.getTime());return{scenario:de,value:pe?.value,forecast:pe?.forecast,lowerBound:pe?.lowerBound,upperBound:pe?.upperBound}}),ce=c.filter(de=>Math.abs(be(de.date).getTime()-O.getTime())<864e5);ae({date:O,values:re,annotations:ce}),W({x:m.clientX-H.left+10,y:m.clientY-H.top-10})}else ae(null)},[Z,ue,X,c,b]),me=w.useCallback(m=>{if(!R.interactive)return;te(J=>J.map(O=>O.id===m?{...O,visible:!O.visible}:O));const H=X.find(J=>J.id===m);H&&_?.(m,!H.visible)},[R.interactive,X,_]);w.useImperativeHandle(a,()=>({getScenarios:()=>X,updateScenario:(m,H)=>{te(J=>J.map(O=>O.id===m?{...O,data:H}:O))},toggleScenario:me,setZoomRange:()=>{},resetZoom:()=>{},exportImage:m=>{if(!U.current)return null;const H=U.current,O=new XMLSerializer().serializeToString(H);return`data:image/svg+xml;base64,${btoa(O)}`},getDataAtDate:m=>{const H=X.filter(J=>J.visible!==!1).map(J=>{const O=J.data.find(Q=>be(Q.date).getTime()===m.getTime());return{scenario:J,value:O?.value,forecast:O?.forecast,lowerBound:O?.lowerBound,upperBound:O?.upperBound}});return{date:m,values:H,annotations:c.filter(J=>be(J.date).getTime()===m.getTime())}}}),[X,c,me]),G.width-I.left-I.right;const we=G.height-I.top-I.bottom,L=w.useMemo(()=>{const m=g?.tickCount??5,H=[],J=($e-ye)/(m-1);for(let O=0;O<m;O++)H.push(ye+J*O);return H},[ye,$e,g?.tickCount]),ee=w.useMemo(()=>{const m=p?.tickCount??6;if(ue.length===0)return[];const H=Math.max(1,Math.floor(ue.length/(m-1)));return ue.filter((J,O)=>O%H===0||O===ue.length-1)},[ue,p?.tickCount]);return X.length===0||X.every(m=>m.data.length===0)?e.jsx("div",{className:`nice-forecast-chart ${Y??""}`,style:F,"data-testid":q??V,children:e.jsx("div",{className:"nice-forecast-chart__empty",children:D.noData??r("forecastChart.noDataAvailable","No data available")})}):e.jsxs("div",{className:`nice-forecast-chart ${Y??""}`,style:{...F,height:o},"data-testid":q??V,children:[e.jsxs("div",{ref:A,className:"nice-forecast-chart__container",children:[e.jsxs("svg",{ref:U,className:"nice-forecast-chart__svg",width:G.width,height:G.height,onMouseMove:ie,onMouseLeave:()=>ae(null),children:[g?.showGrid!==!1&&L.map(m=>e.jsx("line",{className:"nice-forecast-chart__grid-line",x1:I.left,x2:G.width-I.right,y1:oe(m),y2:oe(m)},m)),l&&ve&&e.jsx("rect",{className:"nice-forecast-chart__forecast-region",x:Z(ve),y:I.top,width:G.width-I.right-Z(ve),height:we}),d.map(m=>e.jsxs("g",{children:[e.jsx("line",{className:"nice-forecast-chart__reference-line",x1:I.left,x2:G.width-I.right,y1:oe(m.value),y2:oe(m.value),stroke:m.color??"var(--nice-text-muted, #9ca3af)",strokeDasharray:m.dashArray??"4,2"}),m.label&&e.jsx("text",{className:"nice-forecast-chart__reference-label",x:G.width-I.right-4,y:oe(m.value)-4,textAnchor:"end",children:m.label})]},m.id)),je&&y?.enabled&&e.jsxs("g",{className:"nice-forecast-chart__cash-runway",children:[e.jsx("line",{className:"nice-forecast-chart__cash-runway-line",x1:Z(je),x2:Z(je),y1:I.top,y2:G.height-I.bottom,stroke:y.color??"var(--nice-color-error, #ef4444)"}),y.showLabel!==!1&&e.jsxs(e.Fragment,{children:[e.jsx("rect",{className:"nice-forecast-chart__cash-runway-label-bg",x:Z(je)-60,y:I.top-2,width:120,height:y.showDate!==!1?32:20,fill:y.color??"var(--nice-color-error, #ef4444)",rx:4}),e.jsx("text",{className:"nice-forecast-chart__cash-runway-label",x:Z(je),y:I.top+12,textAnchor:"middle",fill:"var(--nice-color-white, #fff)",children:y.label??D.cashRunsOut??r("forecastChart.cashRunsOut","Cash runs out")}),y.showDate!==!1&&e.jsx("text",{className:"nice-forecast-chart__cash-runway-label",x:Z(je),y:I.top+26,textAnchor:"middle",fill:"var(--nice-color-white, #fff)",style:{fontSize:"0.625rem",opacity:.9},children:Oe(je,B)})]})]}),X.filter(m=>m.visible!==!1&&m.showConfidenceBand).map(m=>e.jsx("path",{className:"nice-forecast-chart__confidence-band",d:ne(m.data),fill:m.color},`band-${m.id}`)),X.filter(m=>m.visible!==!1).map(m=>{const H=ve?m.data.filter(O=>be(O.date)<ve):m.data.filter(O=>O.value!=null),J=ve?m.data.filter(O=>be(O.date)>=ve):m.data.filter(O=>O.forecast!=null);return e.jsxs("g",{children:[e.jsx("path",{className:"nice-forecast-chart__historical-line",d:Me(H,"value"),stroke:m.color,strokeWidth:h}),e.jsx("path",{className:"nice-forecast-chart__forecast-line",d:Me(J,ve?"value":"forecast"),stroke:m.color,strokeWidth:h}),J.length>0&&m.data.some(O=>O.forecast!=null)&&e.jsx("path",{className:"nice-forecast-chart__forecast-line",d:Me(m.data,"forecast"),stroke:m.color,strokeWidth:h}),x&&m.data.map((O,Q)=>{const re=O.value??O.forecast;return re==null?null:e.jsx("circle",{className:"nice-forecast-chart__point",cx:Z(be(O.date)),cy:oe(re),r:$,fill:m.color,onClick:()=>i?.(O,m)},Q)})]},m.id)}),c.map(m=>{const H=Z(be(m.date));return e.jsxs("g",{className:"nice-forecast-chart__annotation-marker",onClick:()=>N?.(m),children:[m.showLine!==!1&&e.jsx("line",{className:"nice-forecast-chart__annotation-line",x1:H,x2:H,y1:I.top,y2:G.height-I.bottom,stroke:m.color??"var(--nice-text-muted, #9ca3af)"}),e.jsx("circle",{cx:H,cy:I.top+10,r:8,fill:m.color??"var(--nice-text-muted, #9ca3af)"}),e.jsx("text",{x:H,y:I.top+14,textAnchor:"middle",fill:"white",fontSize:"10",children:m.icon??"!"})]},m.id)}),e.jsx("line",{className:"nice-forecast-chart__axis-line",x1:I.left,x2:I.left,y1:I.top,y2:G.height-I.bottom}),e.jsx("line",{className:"nice-forecast-chart__axis-line",x1:I.left,x2:G.width-I.right,y1:G.height-I.bottom,y2:G.height-I.bottom}),L.map(m=>e.jsx("text",{className:"nice-forecast-chart__axis-label",x:I.left-8,y:oe(m)+4,textAnchor:"end",children:g?.format?g.format(m):Re(m,B)},m)),ee.map(m=>e.jsx("text",{className:"nice-forecast-chart__axis-label",x:Z(m),y:G.height-I.bottom+16,textAnchor:"middle",children:p?.format?p.format(m):Oe(m,B)},m.getTime())),g?.title&&e.jsx("text",{className:"nice-forecast-chart__axis-title",x:15,y:G.height/2,textAnchor:"middle",transform:`rotate(-90, 15, ${G.height/2})`,children:g.title})]}),se&&e.jsxs("div",{className:"nice-forecast-chart__tooltip",style:{left:he.x,top:he.y},children:[e.jsx("div",{className:"nice-forecast-chart__tooltip-date",children:Oe(se.date,B)}),se.values.map(m=>{const H=m.value??m.forecast;return H==null?null:e.jsxs("div",{className:"nice-forecast-chart__tooltip-item",children:[e.jsx("span",{className:"nice-forecast-chart__tooltip-color",style:{background:m.scenario.color}}),e.jsx("span",{className:"nice-forecast-chart__tooltip-label",children:m.scenario.name}),e.jsx("span",{className:"nice-forecast-chart__tooltip-value",children:Re(H,B)})]},m.scenario.id)}),se.values.some(m=>m.lowerBound!=null)&&e.jsxs("div",{className:"nice-forecast-chart__tooltip-confidence",children:[D.confidence??r("forecastChart.ci","CI"),":"," ",Re(se.values[0]?.lowerBound??0,B)," –"," ",Re(se.values[0]?.upperBound??0,B)]})]})]}),R.enabled&&e.jsx("div",{className:"nice-forecast-chart__legend",children:X.map(m=>e.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":m.visible!==!1,onKeyDown:le.clickOnActivationKey,className:`nice-forecast-chart__legend-item ${m.visible===!1?"nice-forecast-chart__legend-item--hidden":""}`,onClick:()=>me(m.id),children:[e.jsx("span",{className:`nice-forecast-chart__legend-color ${m.isBase?"":"nice-forecast-chart__legend-color--dashed"}`,style:{background:m.color}}),m.name]},m.id))})]})}),cn=[];function ln(t,n){const a=t?typeof t=="number"?new Date(t):new Date(t):new Date,r=j=>j.toString().padStart(2,"0"),s=r(a.getHours()),u=r(a.getMinutes()),c=r(a.getSeconds()),d=a.getMilliseconds().toString().padStart(3,"0");switch(n){case"HH:mm:ss":return`${s}:${u}:${c}`;case"HH:mm":return`${s}:${u}`;case"mm:ss":return`${u}:${c}`;case"ss.SSS":return`${c}.${d}`;case"ISO":return a.toISOString();default:return`${s}:${u}:${c}`}}function qe(t){if(t.length===0)return null;const n=Math.min(...t),a=Math.max(...t),r=t.reduce((u,c)=>u+c,0)/t.length,s=t[t.length-1];return{min:n,max:a,avg:r,current:s,count:t.length}}const dn=Object.assign(w.forwardRef(({series:t=cn,maxPoints:n=100,slidingWindow:a=!0,refreshRate:r=16,dataSource:s,width:u=600,height:c=400,title:d,showLegend:j=!0,showGrid:y=!0,yAxisLabel:p,xAxisLabel:g,stacked:z,zoomable:b,crosshair:C,annotations:o=[],legendInteractive:l,onDataPointClick:h,exportable:x,showControls:$=!0,showStatus:k=!0,initialPaused:f=!1,onDataReceived:M,onDataDropped:v,timeFormat:S="HH:mm:ss",showStats:i,thresholds:N=[],className:_,style:E,testId:T,"data-testid":P},D)=>{const[B,Y]=w.useState(()=>{const ne=new Map;for(const ie of t)ne.set(ie.name,ie.initialData?.slice()??[]);return ne}),[F,V]=w.useState([]),{t:q}=le.useNiceTranslation(),[K,R]=w.useState(f),[X,te]=w.useState(!1),se=w.useRef([]),ae=w.useRef(Date.now()),he=w.useRef(null),W=w.useRef(new Map),A=w.useRef(0),U=JSON.stringify(t.map(ne=>ne.name)),I=w.useMemo(()=>new Set(JSON.parse(U)),[U]),G=w.useRef(K),fe=w.useRef(M),Z=w.useRef(v);w.useEffect(()=>{G.current=K,fe.current=M,Z.current=v});const oe=w.useRef(null);oe.current===null&&(oe.current=new Map(t.map(ne=>[ne.name,ne.initialData?.length??0])));const ue=w.useCallback(()=>{const ne=se.current;if(ne.length===0)return;se.current=[];const ie=oe.current??new Map,me=[];for(const L of ne){const ee=ie.get(L.series);ee!==void 0&&(a&&ee+1>n?(me.push([L.series,ee+1-n]),ie.set(L.series,n)):ie.set(L.series,ee+1))}Y(L=>{const ee=new Map(L);for(const m of ne){const H=ee.get(m.series);if(!H)continue;const J=[...H,m.value];a&&J.length>n&&J.splice(0,J.length-n),ee.set(m.series,J)}return ee});for(const[L,ee]of me)Z.current?.(ee,L);const we=[];for(const L of ne){if(!I.has(L.series))continue;const ee=(W.current.get(L.series)??0)+1;W.current.set(L.series,ee),ee>A.current&&(A.current=ee,we.push(L.category??ln(L.timestamp,S)))}we.length>0&&V(L=>{const ee=[...L,...we];return a&&ee.length>n&&ee.splice(0,ee.length-n),ee})},[a,n,S,I]),ye=w.useCallback(()=>{const ne=Date.now();ne-ae.current>=r&&(ue(),ae.current=ne),he.current=requestAnimationFrame(ye)},[r,ue]);w.useEffect(()=>(K||(he.current=requestAnimationFrame(ye)),()=>{he.current!==null&&(cancelAnimationFrame(he.current),he.current=null)}),[K,ye]);const $e=w.useCallback(ne=>{if(G.current)return;const ie="points"in ne?ne.points:[ne];for(const me of ie)I.has(me.series)&&(se.current.push(me),fe.current?.(me))},[I]);w.useEffect(()=>{if(!s)return;const ne=s.subscribe($e);let ie;return s.onStatusChange?ie=s.onStatusChange(te):te(!0),s.fetchHistory&&s.fetchHistory(n).then(me=>{for(const we of me)se.current.push(we);ue()}),()=>{ne(),ie?.()}},[s,$e,n,ue]);const ve=w.useMemo(()=>t.map(ne=>({name:ne.name,color:ne.color,type:ne.type,data:B.get(ne.name)??[]})),[t,B]),je=w.useMemo(()=>{const ne=[...o];for(const ie of N)ne.push({type:"line",value:ie.value,color:ie.color,label:ie.label,dash:ie.style==="dashed"?"5,5":ie.style==="dotted"?"2,2":void 0});return ne},[o,N]);w.useImperativeHandle(D,()=>({pause(){R(!0)},resume(){R(!1)},isPaused(){return K},clear(){Y(ie=>{const me=new Map(ie);for(const we of me.keys())me.set(we,[]);return me}),V([]),W.current=new Map,A.current=0,se.current=[];const ne=oe.current;if(ne)for(const ie of ne.keys())ne.set(ie,0)},addPoint(ne){$e(ne)},addPoints(ne){$e({points:ne})},getData(ne){return B.get(ne)??[]},getCategories(){return F},exportData(){return{series:ve,categories:F}},getStats(ne){const ie=B.get(ne);return ie?qe(ie):null}}),[K,B,F,ve,$e]);const Me=w.useMemo(()=>{if(!i)return null;const ne={};for(const[ie,me]of B)ne[ie]=qe(me);return ne},[i,B]);return e.jsxs("div",{className:_,style:{position:"relative",...E},"data-testid":P??T,children:[k&&e.jsxs("div",{style:{position:"absolute",top:8,right:8,display:"flex",alignItems:"center",gap:4,fontSize:12,color:X?"var(--nice-color-success, #22c55e)":"var(--nice-color-error, #ef4444)",zIndex:10},children:[e.jsx("span",{style:{width:8,height:8,borderRadius:"50%",backgroundColor:X?"var(--nice-color-success, #22c55e)":"var(--nice-color-error, #ef4444)"}}),X?q("charts.live","Live"):q("charts.disconnected","Disconnected")]}),$&&e.jsx("div",{style:{position:"absolute",top:8,left:8,display:"flex",gap:4,zIndex:10},children:e.jsx("button",{onClick:()=>R(ne=>!ne),style:{padding:"4px 8px",fontSize:12,border:"1px solid var(--nice-border-color, #ddd)",borderRadius:4,background:K?"var(--nice-warning-bg, #fef3c7)":"var(--nice-bg-primary, #fff)",color:"var(--nice-text-primary, #0f172a)",cursor:"pointer"},title:K?q("charts.resume","Resume"):q("charts.pause","Pause"),"aria-label":K?q("charts.resume","Resume"):q("charts.pause","Pause"),children:e.jsx(le.NiceIcon,{name:K?"play":"pause",size:14})})}),i&&Me&&e.jsx("div",{style:{position:"absolute",bottom:50,right:8,background:"color-mix(in srgb, var(--nice-bg-elevated, #fff) 92%, transparent)",color:"var(--nice-text-primary, #0f172a)",border:"1px solid var(--nice-border-color, #ddd)",borderRadius:4,padding:8,fontSize:11,zIndex:10},children:Object.entries(Me).map(([ne,ie])=>ie?e.jsxs("div",{style:{marginBottom:4},children:[e.jsx("strong",{children:ne}),e.jsxs("div",{children:[q("charts.stats.min","Min"),": ",ie.min.toFixed(2)," |"," ",q("charts.stats.max","Max"),": ",ie.max.toFixed(2)]}),e.jsxs("div",{children:[q("charts.stats.avg","Avg"),": ",ie.avg.toFixed(2)," |"," ",q("charts.stats.now","Now"),": ",ie.current.toFixed(2)]})]},ne):null)}),e.jsx(De,{series:ve,categories:F,width:u,height:c,title:d,showLegend:j,showGrid:y,yAxisLabel:p,xAxisLabel:g,stacked:z,zoomable:b,crosshair:C,annotations:je,legendInteractive:l,onDataPointClick:h,exportable:x})]})}),{displayName:"NiceLiveChart"});function hn(t){const{hubConnection:n,eventName:a="DataPoint",subscribeMethod:r="SubscribeToMetrics",historyMethod:s="GetMetricHistory",metricName:u}=t;return{subscribe(c){const d=j=>{c(j)};return n.on(a,d),n.state==="Connected"&&n.invoke(r,u).catch(()=>{}),()=>{n.off(a,d)}},async fetchHistory(c){try{return await n.invoke(s,u,c)}catch{return[]}},onStatusChange(c){const d=()=>c(n.state==="Connected");return n.onclose(()=>c(!1)),n.onreconnected(()=>c(!0)),d(),()=>{}}}}function un(t){const{url:n,autoReconnect:a=!0,reconnectDelay:r=3e3,parseMessage:s=p=>JSON.parse(p)}=t;let u=null,c=null,d=null,j=null;const y=()=>{u=new WebSocket(n),u.onopen=()=>{c?.(!0)},u.onclose=()=>{c?.(!1),a&&(j=setTimeout(y,r))},u.onerror=()=>{u?.close()},u.onmessage=p=>{try{const g=s(p.data);g&&d&&d(g)}catch{}}};return{subscribe(p){return d=p,y(),()=>{d=null,j&&clearTimeout(j),u?.close(),u=null}},onStatusChange(p){return c=p,()=>{c=null}}}}function fn(t){const{seriesNames:n,interval:a=1e3,generateValue:r=()=>Math.random()*100}=t;let s=null,u=0;return{subscribe(c){return s=setInterval(()=>{for(const d of n)c({series:d,value:r(d,u),timestamp:Date.now()});u++},a),()=>{s&&clearInterval(s)}},onStatusChange(c){return c(!0),()=>{}}}}const mn=[];function pn(t){if(!t.length)return{categories:[],numericFields:[],sampleValues:{}};const n=t[0],a=[],r={};let s=null;for(const[c,d]of Object.entries(n))typeof d=="number"?(a.push(c),r[c]=t.map(j=>Number(j[c])||0)):!s&&(typeof d=="string"||d instanceof Date)&&(s=c);return{categories:s?t.map(c=>String(c[s]||"")):t.map((c,d)=>`Item ${d+1}`),numericFields:a,sampleValues:r}}function xn(t,n){const{categories:a,numericFields:r,sampleValues:s}=pn(t);return{series:r.map((c,d)=>({name:c.replace(/([A-Z])/g," $1").replace(/^./,j=>j.toUpperCase()).trim(),data:s[c],type:n==="area"?"area":n==="line"?"line":"bar"})),categories:a}}const gn=w.forwardRef(function(n,a){const{rawData:r,enableAI:s=!0,aiModel:u,enableAutoType:c=!0,enableInsights:d=!0,dataDescription:j,onChartSuggestion:y,onInsights:p,showAIToolbar:g=!0,showInsightsOnLoad:z=!1,series:b=mn,categories:C,...o}=n,[l,h]=w.useState("bar"),[x,$]=w.useState(null),[k,f]=w.useState([]),[M,v]=w.useState(z),[S,i]=w.useState(null),{t:N}=ft.useNiceTranslation(),_=le.useNiceAI(),{suggestChartType:E,generateInsights:T,isLoading:P}=le.useChartSuggestion(),D=s&&_.isConfigured,{series:B,categories:Y}=r?xn(r,S||l):{series:b||[],categories:C},F=w.useCallback(async()=>{if(!D||!c)return{type:"bar",reason:"Default",config:{}};const X=r||(b?.length?b.flatMap(te=>te.data.map((se,ae)=>({[te.name]:se,index:ae}))):[]);try{const te=await E(X,j),se={type:te.type,reason:te.reason,config:te.config};return $(se),h(se.type),y?.(se),se}catch{return{type:"bar",reason:"Default fallback",config:{}}}},[D,c,r,b,j,E,y]),V=w.useCallback(async()=>{if(!D||!d)return[];const X=r||(b?.length?b.flatMap(te=>te.data.map((se,ae)=>({[te.name]:se,category:C?.[ae]||ae}))):[]);try{const te=await T(X,S||l);return f(te),p?.(te),te}catch{return[]}},[D,d,r,b,C,l,S,T,p]),q=w.useCallback(()=>S||l,[S,l]);w.useEffect(()=>{D&&c&&(r?.length||b?.length)&&F()},[D,c,r,b]),w.useImperativeHandle(a,()=>({getSuggestion:F,generateInsights:V,getCurrentType:q}));const K=[{type:"bar",icon:"bar-chart",label:N("chartAI.bar","Bar")},{type:"line",icon:"line-chart",label:N("chartAI.line","Line")},{type:"area",icon:"area-chart",label:N("chartAI.area","Area")},{type:"pie",icon:"pie-chart",label:N("chartAI.pie","Pie")},{type:"donut",icon:"donut-chart",label:N("chartAI.donut","Donut")},{type:"scatter",icon:"scatter-chart",label:N("chartAI.scatter","Scatter")}],R=S||l;return e.jsxs("div",{className:"nice-chart-ai","data-testid":n["data-testid"],children:[g&&D&&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:N("chartAI.ai","AI")}),x&&e.jsxs("div",{className:"nice-chart-ai__suggestion",children:[e.jsx("span",{className:"nice-chart-ai__suggestion-icon",children:e.jsx(le.NiceIcon,{name:"lightbulb",size:14})}),e.jsxs("span",{className:"nice-chart-ai__suggestion-text",children:[N("chartAI.suggestedType","Suggested:")," ",x.type]}),e.jsxs("span",{className:"nice-chart-ai__suggestion-reason",title:x.reason,children:["(",x.reason,")"]})]}),P&&e.jsx("span",{className:"nice-chart-ai__loading",children:N("chartAI.analyzing","Analyzing...")})]}),e.jsx("div",{className:"nice-chart-ai__toolbar-center",children:e.jsx("div",{className:"nice-chart-ai__type-selector",children:K.filter(X=>["bar","line","area"].includes(X.type)).map(({type:X,icon:te,label:se})=>e.jsx("button",{type:"button",className:`nice-chart-ai__type-btn ${R===X?"nice-chart-ai__type-btn--active":""}`,onClick:()=>i(X),title:se,children:e.jsx(le.NiceIcon,{name:te,size:16})},X))})}),e.jsxs("div",{className:"nice-chart-ai__toolbar-right",children:[e.jsxs("button",{type:"button",className:"nice-chart-ai__auto-btn",onClick:()=>F(),disabled:P,title:N("chartAI.autoDetect","Auto-detect best chart type"),children:[e.jsx(le.NiceIcon,{name:"zap",size:14})," ",N("chartAI.auto","Auto")]}),d&&e.jsxs("button",{type:"button",className:"nice-chart-ai__insights-btn",onClick:()=>{k.length||V(),v(!M)},disabled:P,title:N("chartAI.showInsights","Show data insights"),children:[e.jsx(le.NiceIcon,{name:"lightbulb",size:14})," ",N("chartAI.insights","Insights")]})]})]}),e.jsx("div",{className:"nice-chart-ai__chart-wrapper",children:e.jsx(De,{series:B,categories:Y,...o})}),M&&k.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:[e.jsx(le.NiceIcon,{name:"lightbulb",size:14})," ",N("chartAI.dataInsights","Data Insights")]}),e.jsx("button",{type:"button",className:"nice-chart-ai__insights-close",onClick:()=>v(!1),"aria-label":N("chartAI.close","Close"),children:e.jsx(le.NiceIcon,{name:"close",size:14})})]}),e.jsx("ul",{className:"nice-chart-ai__insights-list",children:k.map((X,te)=>e.jsxs("li",{className:"nice-chart-ai__insight",children:[e.jsx("span",{className:"nice-chart-ai__insight-icon",children:"•"}),X]},te))}),e.jsx("div",{className:"nice-chart-ai__insights-footer",children:e.jsxs("button",{type:"button",className:"nice-chart-ai__refresh",onClick:()=>V(),disabled:P,children:[e.jsx(le.NiceIcon,{name:"refresh",size:14})," ",N("chartAI.refresh","Refresh")]})})]}),M&&P&&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"}),N("chartAI.generatingInsights","Generating insights...")]})})]})}),yn=[],vn=[],bn=[],ut=["var(--nice-color-primary, #3b82f6)","var(--nice-color-error, #ef4444)","var(--nice-color-success, #22c55e)","var(--nice-color-warning, #f59e0b)","var(--nice-color-accent, #8b5cf6)","var(--nice-color-accent-pink, #ec4899)","var(--nice-color-info, #06b6d4)","var(--nice-color-success, #10b981)","var(--nice-color-warning, #f59e0b)","var(--nice-color-accent, #6366f1)"],_n=Object.assign(w.forwardRef((t,n)=>{const{t:a}=le.useNiceTranslation(),{levels:r=bn,initialLevelId:s,levelId:u,chartType:c="bar",width:d=600,height:j=400,showBreadcrumbs:y=!0,showBackButton:p=!0,animationDuration:g=300,onLevelChange:z,onItemClick:b,colors:C=ut,showValues:o=!0,showLegend:l=!0,className:h,style:x,testId:$,"data-testid":k,...f}=t,M=u!==void 0,[v,S]=w.useState(s||r[0]?.id),[i,N]=w.useState([s||r[0]?.id]),_=w.useCallback(W=>{const A=[];let U=r.find(I=>I.id===W);for(;U&&!A.includes(U.id);){A.unshift(U.id);const I=U.parentId;U=I?r.find(G=>G.id===I):void 0}return A.length>0?A:[W]},[r]),E=u??v,T=w.useMemo(()=>u!==void 0?_(u):i,[u,i,_]),[P,D]=w.useState(!1),[B,Y]=w.useState("in"),F=w.useMemo(()=>r.find(W=>W.id===E),[r,E]),V=w.useCallback(W=>{r.find(U=>U.id===W)&&(Y("in"),D(!0),setTimeout(()=>{M||(S(W),N(U=>[...U,W])),z?.(W,M?_(W):[...T,W]),D(!1)},g/2))},[r,T,g,z,M,_]),q=w.useCallback(()=>{if(T.length<=1)return;Y("out"),D(!0);const W=T.slice(0,-1),A=W[W.length-1];setTimeout(()=>{M||(S(A),N(W)),z?.(A,W),D(!1)},g/2)},[T,g,z,M]),K=w.useCallback(()=>{const W=r[0]?.id;W&&(Y("out"),D(!0),setTimeout(()=>{M||(S(W),N([W])),z?.(W,[W]),D(!1)},g/2))},[r,g,z,M]);w.useImperativeHandle(n,()=>({drillDown:V,drillUp:q,resetToRoot:K,getCurrentLevel:()=>E,getPath:()=>T}),[V,q,K,E,T]);const R=w.useCallback((W,A)=>{b?.(W,E);const U=r.find(I=>I.parentId===E&&I.id===W.metadata?.childLevelId);U&&V(U.id)},[E,r,V,b]),X=w.useMemo(()=>F?.data.reduce((W,A)=>W+A.value,0)||0,[F]),te=w.useMemo(()=>T.map(W=>r.find(A=>A.id===W)?.label||W),[T,r]),se=()=>{if(!F)return null;const W=F.data,A=Math.max(...W.map(I=>I.value)),U=Math.min(40,(j-100)/W.length-8);return e.jsx("div",{className:"nice-drilldown-bars",children:W.map((I,G)=>{const fe=I.value/A*100;return e.jsxs("div",{role:"button",tabIndex:0,onKeyDown:le.clickOnActivationKey,className:"nice-drilldown-bar-row",onClick:()=>R(I,G),children:[e.jsx("span",{className:"nice-drilldown-bar-label",children:I.label||a("charts.item","Item {i}").replace("{i}",String(G+1))}),e.jsx("div",{className:"nice-drilldown-bar-track",children:e.jsx("div",{className:"nice-drilldown-bar-fill",style:{width:`${fe}%`,backgroundColor:I.color||C[G%C.length],height:U}})}),o&&e.jsx("span",{className:"nice-drilldown-bar-value",children:I.value.toLocaleString()})]},G)})})},ae=()=>{if(!F)return null;const W=F.data,A=d/2,U=(j-60)/2+30,I=Math.min(A,U)-40;let G=-90;const fe=W.map((Z,oe)=>{const ue=Z.value/X*360,ye=G+ue,$e=ue>180?1:0,ve=G*Math.PI/180,je=ye*Math.PI/180,Me=A+I*Math.cos(ve),ne=U+I*Math.sin(ve),ie=A+I*Math.cos(je),me=U+I*Math.sin(je),we=(G+ue/2)*Math.PI/180,L=A+I*.7*Math.cos(we),ee=U+I*.7*Math.sin(we),m=`M ${A} ${U} L ${Me} ${ne} A ${I} ${I} 0 ${$e} 1 ${ie} ${me} Z`;return G=ye,{path:m,color:Z.color||C[oe%C.length],label:Z.label||a("charts.item","Item {i}").replace("{i}",String(oe+1)),value:Z.value,percentage:(Z.value/X*100).toFixed(1),labelX:L,labelY:ee,item:Z,index:oe}});return e.jsx("svg",{width:d,height:j-40,className:"nice-drilldown-pie",children:e.jsx("g",{children:fe.map((Z,oe)=>e.jsxs("g",{onClick:()=>R(Z.item,Z.index),children:[e.jsx("path",{d:Z.path,fill:Z.color,stroke:"white",strokeWidth:2,className:"nice-drilldown-pie-slice"}),o&&parseFloat(Z.percentage)>5&&e.jsxs("text",{x:Z.labelX,y:Z.labelY,textAnchor:"middle",dominantBaseline:"middle",fill:"white",fontSize:"12",fontWeight:"600",children:[Z.percentage,"%"]})]},oe))})})},he=()=>{if(!F)return null;const W=F.data,A=Math.max(...W.map(G=>G.value)),U=Math.min(60,(d-100)/W.length-8),I=j-100;return e.jsx("svg",{width:d,height:j-40,className:"nice-drilldown-columns",children:e.jsxs("g",{transform:"translate(50, 20)",children:[[0,.25,.5,.75,1].map((G,fe)=>e.jsxs("g",{children:[e.jsx("line",{x1:0,y1:I*(1-G),x2:d-80,y2:I*(1-G),stroke:"var(--nice-border-color, #e5e7eb)",strokeDasharray:G===0?void 0:"4"}),e.jsx("text",{x:-8,y:I*(1-G),textAnchor:"end",dominantBaseline:"middle",fontSize:"11",fill:"var(--nice-text-secondary, #6b7280)",children:Math.round(A*G).toLocaleString()})]},fe)),W.map((G,fe)=>{const Z=G.value/A*I,oe=fe*((d-100)/W.length)+((d-100)/W.length-U)/2;return e.jsxs("g",{onClick:()=>R(G,fe),children:[e.jsx("rect",{x:oe,y:I-Z,width:U,height:Z,fill:G.color||C[fe%C.length],rx:4,className:"nice-drilldown-column-bar"}),e.jsx("text",{x:oe+U/2,y:I+16,textAnchor:"middle",fontSize:"11",fill:"var(--nice-text-primary, #374151)",children:(G.label||`${fe+1}`).slice(0,10)}),o&&e.jsx("text",{x:oe+U/2,y:I-Z-8,textAnchor:"middle",fontSize:"11",fill:"var(--nice-text-primary, #374151)",fontWeight:"500",children:G.value.toLocaleString()})]},fe)})]})})};return e.jsxs("div",{className:`nice-drilldown-chart ${P?`animating ${B}`:""} ${h||""}`,style:{width:d,...x},"data-testid":k??$,...f,children:[e.jsxs("div",{className:"nice-drilldown-header",children:[p&&T.length>1&&e.jsxs("button",{className:"nice-drilldown-back",onClick:q,children:[e.jsx(le.NiceIcon,{name:"arrow-left",size:14})," ",a("charts.back","Back")]}),y&&e.jsx("div",{className:"nice-drilldown-breadcrumbs",children:te.map((W,A)=>e.jsxs(w.Fragment,{children:[A>0&&e.jsx("span",{className:"nice-drilldown-separator",children:"/"}),e.jsx("span",{role:A<te.length-1?"button":void 0,tabIndex:A<te.length-1?0:void 0,"aria-current":A===te.length-1?"location":void 0,onKeyDown:A<te.length-1?le.clickOnActivationKey:void 0,className:`nice-drilldown-crumb ${A===te.length-1?"active":""}`,onClick:()=>{if(A<te.length-1){const U=T.slice(0,A+1),I=U[U.length-1];M||(N(U),S(I)),z?.(I,U)}},children:W})]},A))})]}),e.jsxs("div",{className:"nice-drilldown-content",style:{height:j-40},children:[c==="bar"&&se(),c==="pie"&&ae(),c==="column"&&he()]}),l&&F&&e.jsx("div",{className:"nice-drilldown-legend",children:F.data.map((W,A)=>e.jsxs("div",{className:"nice-drilldown-legend-item",children:[e.jsx("span",{className:"nice-drilldown-legend-color",style:{backgroundColor:W.color||C[A%C.length]}}),e.jsx("span",{className:"nice-drilldown-legend-label",children:W.label||a("charts.item","Item {i}").replace("{i}",String(A+1))})]},A))}),e.jsx("style",{children:`
443
- .nice-drilldown-chart {
444
- font-family: inherit;
445
- color: var(--nice-text-primary, #111827);
446
- background: var(--nice-bg-elevated, #ffffff);
447
- border-radius: 8px;
448
- overflow: hidden;
449
- }
450
-
451
- .nice-drilldown-header {
452
- display: flex;
453
- align-items: center;
454
- gap: 12px;
455
- padding: 12px 16px;
456
- border-bottom: 1px solid var(--nice-border-color, #e5e7eb);
457
- min-height: 40px;
458
- }
459
-
460
- .nice-drilldown-back {
461
- background: var(--nice-bg-secondary, #f3f4f6);
462
- border: none;
463
- padding: 6px 12px;
464
- border-radius: 6px;
465
- cursor: pointer;
466
- font-size: 13px;
467
- font-family: inherit;
468
- color: var(--nice-text-primary, #374151);
469
- transition: background 0.2s;
470
- }
471
-
472
- .nice-drilldown-back:hover {
473
- background: var(--nice-hover-bg, #e5e7eb);
474
- }
475
-
476
- .nice-drilldown-breadcrumbs {
477
- display: flex;
478
- align-items: center;
479
- gap: 4px;
480
- font-size: 13px;
481
- font-family: inherit;
482
- }
483
-
484
- .nice-drilldown-separator {
485
- color: var(--nice-text-muted, #9ca3af);
486
- }
487
-
488
- .nice-drilldown-crumb {
489
- color: var(--nice-text-secondary, #6b7280);
490
- cursor: pointer;
491
- }
492
-
493
- .nice-drilldown-crumb:hover:not(.active) {
494
- color: var(--nice-color-primary, #3b82f6);
495
- }
496
-
497
- .nice-drilldown-crumb.active {
498
- color: var(--nice-text-primary, #111827);
499
- font-weight: 500;
500
- cursor: default;
501
- }
502
-
503
- .nice-drilldown-content {
504
- padding: 16px;
505
- transition: opacity 0.15s, transform 0.15s;
506
- }
507
-
508
- .nice-drilldown-chart.animating .nice-drilldown-content {
509
- opacity: 0;
510
- }
511
-
512
- .nice-drilldown-chart.animating.in .nice-drilldown-content {
513
- transform: translateX(20px);
514
- }
515
-
516
- .nice-drilldown-chart.animating.out .nice-drilldown-content {
517
- transform: translateX(-20px);
518
- }
519
-
520
- .nice-drilldown-bars {
521
- display: flex;
522
- flex-direction: column;
523
- gap: 8px;
524
- }
525
-
526
- .nice-drilldown-bar-row {
527
- display: flex;
528
- align-items: center;
529
- gap: 12px;
530
- cursor: pointer;
531
- padding: 4px 8px;
532
- margin: -4px -8px;
533
- border-radius: 6px;
534
- transition: background 0.2s;
535
- }
536
-
537
- .nice-drilldown-bar-row:hover {
538
- background: var(--nice-hover-bg, #f9fafb);
539
- }
540
-
541
- .nice-drilldown-bar-label {
542
- width: 120px;
543
- font-size: 13px;
544
- font-family: inherit;
545
- color: var(--nice-text-primary, #374151);
546
- overflow: hidden;
547
- text-overflow: ellipsis;
548
- white-space: nowrap;
549
- }
550
-
551
- .nice-drilldown-bar-track {
552
- flex: 1;
553
- background: var(--nice-bg-tertiary, #f3f4f6);
554
- border-radius: 6px;
555
- overflow: hidden;
556
- }
557
-
558
- .nice-drilldown-bar-fill {
559
- transition: width 0.3s ease;
560
- border-radius: 6px;
561
- }
562
-
563
- .nice-drilldown-bar-value {
564
- width: 80px;
565
- text-align: right;
566
- font-size: 13px;
567
- font-family: inherit;
568
- font-weight: 500;
569
- color: var(--nice-text-primary, #111827);
570
- }
571
-
572
- .nice-drilldown-pie-slice {
573
- cursor: pointer;
574
- transition: transform 0.2s, opacity 0.2s;
575
- transform-origin: center;
576
- }
577
-
578
- .nice-drilldown-pie-slice:hover {
579
- opacity: 0.85;
580
- transform: scale(1.02);
581
- }
582
-
583
- .nice-drilldown-column-bar {
584
- cursor: pointer;
585
- transition: opacity 0.2s;
586
- }
587
-
588
- .nice-drilldown-column-bar:hover {
589
- opacity: 0.8;
590
- }
591
-
592
- .nice-drilldown-legend {
593
- display: flex;
594
- flex-wrap: wrap;
595
- gap: 16px;
596
- padding: 12px 16px;
597
- border-top: 1px solid var(--nice-border-color, #e5e7eb);
598
- }
599
-
600
- .nice-drilldown-legend-item {
601
- display: flex;
602
- align-items: center;
603
- gap: 6px;
604
- }
605
-
606
- .nice-drilldown-legend-color {
607
- width: 12px;
608
- height: 12px;
609
- border-radius: 3px;
610
- }
611
-
612
- .nice-drilldown-legend-label {
613
- font-size: 12px;
614
- font-family: inherit;
615
- color: var(--nice-text-secondary, #6b7280);
616
- }
617
- `})]})}),{displayName:"NiceDrillDownChart"}),wn=["var(--nice-info-bg, #dbeafe)","var(--nice-color-primary-light, #93c5fd)","var(--nice-color-primary, #3b82f6)","var(--nice-color-primary-active, #1d4ed8)","var(--nice-color-primary, #6366f1)"],jn=({type:t="choropleth",regions:n=[],bubbles:a=[],width:r=800,height:s=500,viewBox:u="0 0 800 500",colorScale:c,colorRange:d,minValue:j,maxValue:y,showTooltip:p=!0,showLegend:g=!0,onRegionClick:z,onBubbleClick:b,onRegionHover:C,title:o,mapSvg:l,zoomable:h=!1,className:x,style:$,testId:k,"data-testid":f,...M})=>{const v=c??d??wn,{t:S}=le.useNiceTranslation(),[i,N]=w.useState(null),[_,E]=w.useState(1),[T,P]=w.useState({x:0,y:0}),D=w.useRef(null),B=w.useRef(!1),Y=w.useRef({x:0,y:0}),F=j??Math.min(...n.map(A=>A.value),...a.map(A=>A.value)),V=y??Math.max(...n.map(A=>A.value),...a.map(A=>A.value)),q=w.useCallback(A=>{const U=(A-F)/(V-F),I=Math.min(Math.floor(U*v.length),v.length-1);return v[Math.max(0,I)]},[F,V,v]),K=w.useCallback(A=>{if(!p||!i)return;const U=D.current?.getBoundingClientRect();U&&N(I=>I?{...I,x:A.clientX-U.left,y:A.clientY-U.top}:null)},[p,i]),R=w.useCallback((A,U)=>{const I=D.current?.getBoundingClientRect();I&&p&&N({x:U.clientX-I.left,y:U.clientY-I.top,content:`${A.name}: ${A.value.toLocaleString()}`}),C?.(A)},[p,C]),X=w.useCallback(()=>{N(null),C?.(null)},[C]),te=w.useCallback(A=>{if(!h)return;A.preventDefault();const U=A.deltaY>0?.9:1.1;E(I=>Math.min(Math.max(I*U,.5),4))},[h]),se=w.useCallback(A=>{h&&(B.current=!0,Y.current={x:A.clientX-T.x,y:A.clientY-T.y})},[h,T]),ae=w.useCallback(()=>{B.current=!1},[]),he=w.useCallback(A=>{B.current&&P({x:A.clientX-Y.current.x,y:A.clientY-Y.current.y})},[]),W=w.useMemo(()=>n.length>0?n:[{id:"mazowieckie",name:"Mazowieckie",value:100,path:"M400,200 L450,200 L460,250 L420,280 L380,250 Z"},{id:"slaskie",name:"Śląskie",value:80,path:"M350,280 L400,280 L390,330 L340,320 Z"},{id:"wielkopolskie",name:"Wielkopolskie",value:70,path:"M300,200 L350,200 L360,260 L310,270 L280,230 Z"}],[n]);return e.jsxs("div",{className:`nice-map-chart ${x||""}`,style:{width:r,...$},"data-testid":f??k,...M,children:[o&&e.jsx("div",{className:"nice-map-title",children:o}),e.jsx("svg",{ref:D,width:r,height:s,viewBox:u,className:"nice-map-svg",onWheel:te,onMouseDown:se,onMouseUp:ae,onMouseLeave:ae,onMouseMove:A=>{K(A),he(A)},children:e.jsxs("g",{transform:`translate(${T.x}, ${T.y}) scale(${_})`,children:[l&&e.jsx("g",{dangerouslySetInnerHTML:{__html:l}}),t==="choropleth"&&W.map(A=>e.jsx("path",{d:A.path,fill:A.color||q(A.value),stroke:"var(--nice-bg-primary, #ffffff)",strokeWidth:1,className:"nice-map-region",onClick:()=>z?.(A),onMouseEnter:U=>R(A,U),onMouseLeave:X},A.id)),(t==="bubble"||a.length>0)&&a.map(A=>{const U=Math.sqrt((A.value-F)/(V-F))*30+5;return e.jsx("circle",{cx:A.lng,cy:A.lat,r:U,fill:A.color||"var(--nice-color-primary, #3b82f6)",fillOpacity:.7,stroke:"var(--nice-bg-primary, #ffffff)",strokeWidth:1,className:"nice-map-bubble",onClick:()=>b?.(A),onMouseEnter:I=>{const G=D.current?.getBoundingClientRect();G&&p&&N({x:I.clientX-G.left,y:I.clientY-G.top,content:`${A.label||A.id}: ${A.value.toLocaleString()}`})},onMouseLeave:X,children:A.label&&e.jsxs("title",{children:[A.label,": ",A.value]})},A.id)})]})}),i&&e.jsx("div",{className:"nice-map-tooltip",style:{left:i.x+10,top:i.y-30},children:i.content}),g&&e.jsxs("div",{className:"nice-map-legend",children:[e.jsx("span",{className:"nice-map-legend-title",children:S("charts.value","Value")}),e.jsx("div",{className:"nice-map-legend-scale",children:v.map((A,U)=>e.jsx("div",{className:"nice-map-legend-item",style:{backgroundColor:A}},U))}),e.jsxs("div",{className:"nice-map-legend-labels",children:[e.jsx("span",{children:F.toLocaleString()}),e.jsx("span",{children:V.toLocaleString()})]})]}),e.jsx("style",{children:`
618
- .nice-map-chart {
619
- font-family: system-ui, -apple-system, sans-serif;
620
- background: var(--nice-bg-primary, #ffffff);
621
- border-radius: var(--nice-radius-lg, 8px);
622
- overflow: hidden;
623
- position: relative;
624
- }
625
-
626
- .nice-map-title {
627
- padding: var(--nice-space-3, 12px) var(--nice-space-4, 16px);
628
- font-size: 16px;
629
- font-weight: 600;
630
- color: var(--nice-text-primary, #0f172a);
631
- border-bottom: 1px solid var(--nice-border-color, #e5e7eb);
632
- }
633
-
634
- .nice-map-svg {
635
- display: block;
636
- cursor: grab;
637
- }
638
-
639
- .nice-map-svg:active {
640
- cursor: grabbing;
641
- }
642
-
643
- .nice-map-region {
644
- cursor: pointer;
645
- transition: opacity 0.2s, stroke-width 0.2s;
646
- }
647
-
648
- .nice-map-region:hover {
649
- opacity: 0.8;
650
- stroke-width: 2;
651
- }
652
-
653
- .nice-map-bubble {
654
- cursor: pointer;
655
- transition: transform 0.2s, opacity 0.2s;
656
- }
657
-
658
- .nice-map-bubble:hover {
659
- opacity: 1;
660
- transform: scale(1.1);
661
- }
662
-
663
- .nice-map-tooltip {
664
- position: absolute;
665
- /* audit-allow: token-role — inverted chip like .nice-tooltip: the text colour is the
666
- fill and the label uses --nice-text-inverse, so the pair flips together. */
667
- background: var(--nice-text-primary, #0f172a);
668
- color: var(--nice-text-inverse, #ffffff);
669
- padding: var(--nice-space-1-5, 6px) var(--nice-space-2-5, 10px);
670
- border-radius: var(--nice-radius-sm, 4px);
671
- font-size: 12px;
672
- pointer-events: none;
673
- z-index: 10;
674
- white-space: nowrap;
675
- }
676
-
677
- .nice-map-legend {
678
- position: absolute;
679
- right: 16px;
680
- bottom: 16px;
681
- background: var(--nice-bg-elevated, #ffffff);
682
- padding: var(--nice-space-3, 12px);
683
- border-radius: var(--nice-radius-md, 6px);
684
- box-shadow: 0 2px 8px var(--nice-overlay-10, color-mix(in srgb, var(--nice-text-primary, #000) 10%, transparent));
685
- }
686
-
687
- .nice-map-legend-title {
688
- display: block;
689
- font-size: 11px;
690
- color: var(--nice-text-secondary, #475569);
691
- margin-bottom: var(--nice-space-1-5, 6px);
692
- }
693
-
694
- .nice-map-legend-scale {
695
- display: flex;
696
- height: 12px;
697
- border-radius: var(--nice-radius-sm, 2px);
698
- overflow: hidden;
699
- }
700
-
701
- .nice-map-legend-item {
702
- flex: 1;
703
- min-width: 24px;
704
- }
705
-
706
- .nice-map-legend-labels {
707
- display: flex;
708
- justify-content: space-between;
709
- font-size: 10px;
710
- color: var(--nice-text-secondary, #475569);
711
- margin-top: var(--nice-space-1, 4px);
712
- }
713
- `})]})},$n=({nodes:t=yn,links:n=vn,width:a=800,height:r=500,nodeWidth:s=20,nodePadding:u=10,showValues:c=!0,showTooltip:d=!0,onNodeClick:j,onLinkClick:y,title:p,className:g,style:z,testId:b,"data-testid":C,...o})=>{const[l,h]=w.useState(null),x=w.useRef(null),$=w.useMemo(()=>{const f=new Map;t.forEach(R=>f.set(R.id,R));const M=new Set(n.map(R=>R.target)),v=new Set(n.map(R=>R.source)),S=[],i=new Map,N=t.filter(R=>v.has(R.id)&&!M.has(R.id));N.length>0&&(S.push(N.map(R=>R.id)),N.forEach(R=>i.set(R.id,0)));const _=t.filter(R=>v.has(R.id)&&M.has(R.id));_.length>0&&(S.push(_.map(R=>R.id)),_.forEach(R=>i.set(R.id,1)));const E=t.filter(R=>!v.has(R.id)&&M.has(R.id));E.length>0&&(S.push(E.map(R=>R.id)),E.forEach(R=>i.set(R.id,2))),S.length===0&&(S.push(t.map(R=>R.id)),t.forEach(R=>i.set(R.id,0)));const T=new Map;n.forEach(R=>{T.set(R.source,(T.get(R.source)||0)+R.value),T.set(R.target,(T.get(R.target)||0)+R.value)});const P=40,D=a-P*2,B=r-P*2,Y=S.length>1?D/(S.length-1):D,F=new Map;Math.max(...Array.from(T.values())),S.forEach((R,X)=>{const te=R.reduce((he,W)=>he+(T.get(W)||0),0),se=(B-(R.length-1)*u)/te;let ae=P;R.forEach(he=>{const A=(T.get(he)||0)*se,U=P+X*Y;F.set(he,{x:U,y:ae,height:A}),ae+=A+u})});const V=[],q=new Map,K=new Map;return n.forEach(R=>{const X=F.get(R.source),te=F.get(R.target);if(!X||!te)return;const se=T.get(R.source)||1;T.get(R.target);const ae=R.value/se*X.height,he=X.y+(q.get(R.source)||0),W=te.y+(K.get(R.target)||0);q.set(R.source,(q.get(R.source)||0)+ae),K.set(R.target,(K.get(R.target)||0)+ae);const A=X.x+s,U=te.x,I=(U-A)*.5,G=`
714
- M ${A} ${he}
715
- C ${A+I} ${he},
716
- ${U-I} ${W},
717
- ${U} ${W}
718
- L ${U} ${W+ae}
719
- C ${U-I} ${W+ae},
720
- ${A+I} ${he+ae},
721
- ${A} ${he+ae}
722
- Z
723
- `;V.push({path:G,link:R,sourcePos:X,targetPos:te})}),{nodePositions:F,linkPaths:V,nodeMap:f,nodeValues:T}},[t,n,a,r,s,u]),k=w.useCallback((f,M)=>{const v=x.current?.getBoundingClientRect();v&&d&&h({x:M.clientX-v.left,y:M.clientY-v.top,content:f})},[d]);return e.jsxs("div",{className:`nice-sankey-chart ${g||""}`,style:{width:a,...z},"data-testid":C??b,...o,children:[p&&e.jsx("div",{className:"nice-sankey-title",children:p}),e.jsxs("svg",{ref:x,width:a,height:r,className:"nice-sankey-svg",children:[e.jsx("defs",{children:$.linkPaths.map((f,M)=>e.jsxs("linearGradient",{id:`sankey-gradient-${M}`,x1:"0%",y1:"0%",x2:"100%",y2:"0%",children:[e.jsx("stop",{offset:"0%",stopColor:$.nodeMap.get(f.link.source)?.color||"var(--nice-color-primary, #3b82f6)"}),e.jsx("stop",{offset:"100%",stopColor:$.nodeMap.get(f.link.target)?.color||"var(--nice-color-error, #ef4444)"})]},M))}),e.jsx("g",{className:"nice-sankey-links",children:$.linkPaths.map((f,M)=>e.jsx("path",{d:f.path,fill:f.link.color||`url(#sankey-gradient-${M})`,fillOpacity:.4,className:"nice-sankey-link",onClick:()=>y?.(f.link),onMouseEnter:v=>k(`${$.nodeMap.get(f.link.source)?.name} → ${$.nodeMap.get(f.link.target)?.name}: ${f.link.value.toLocaleString()}`,v),onMouseLeave:()=>h(null)},M))}),e.jsx("g",{className:"nice-sankey-nodes",children:Array.from($.nodePositions.entries()).map(([f,M])=>{const v=$.nodeMap.get(f);return v?e.jsxs("g",{children:[e.jsx("rect",{x:M.x,y:M.y,width:s,height:M.height,fill:v.color||"var(--nice-color-primary, #3b82f6)",rx:2,className:"nice-sankey-node",onClick:()=>j?.(v),onMouseEnter:S=>k(`${v.label??v.name??v.id}: ${$.nodeValues.get(f)?.toLocaleString()||0}`,S),onMouseLeave:()=>h(null)}),e.jsxs("text",{x:M.x+s+6,y:M.y+M.height/2,dominantBaseline:"middle",fontSize:"12",fill:"var(--nice-text-primary, #0f172a)",children:[v.label??v.name??v.id,c&&` (${$.nodeValues.get(f)?.toLocaleString()||0})`]})]},f):null})})]}),l&&e.jsx("div",{className:"nice-sankey-tooltip",style:{left:l.x+10,top:l.y-30},children:l.content}),e.jsx("style",{children:`
724
- .nice-sankey-chart {
725
- font-family: system-ui, -apple-system, sans-serif;
726
- background: var(--nice-bg-primary, #ffffff);
727
- border-radius: var(--nice-radius-lg, 8px);
728
- position: relative;
729
- }
730
-
731
- .nice-sankey-title {
732
- padding: var(--nice-space-3, 12px) var(--nice-space-4, 16px);
733
- font-size: 16px;
734
- font-weight: 600;
735
- color: var(--nice-text-primary, #0f172a);
736
- border-bottom: 1px solid var(--nice-border-color, #e5e7eb);
737
- }
738
-
739
- .nice-sankey-link {
740
- cursor: pointer;
741
- transition: fill-opacity 0.2s;
742
- }
743
-
744
- .nice-sankey-link:hover {
745
- fill-opacity: 0.7;
746
- }
747
-
748
- .nice-sankey-node {
749
- cursor: pointer;
750
- transition: opacity 0.2s;
751
- }
752
-
753
- .nice-sankey-node:hover {
754
- opacity: 0.8;
755
- }
756
-
757
- .nice-sankey-tooltip {
758
- position: absolute;
759
- /* audit-allow: token-role — inverted chip like .nice-tooltip: the text colour is the
760
- fill and the label uses --nice-text-inverse, so the pair flips together. */
761
- background: var(--nice-text-primary, #0f172a);
762
- color: var(--nice-text-inverse, #ffffff);
763
- padding: var(--nice-space-1-5, 6px) var(--nice-space-2-5, 10px);
764
- border-radius: var(--nice-radius-sm, 4px);
765
- font-size: 12px;
766
- pointer-events: none;
767
- z-index: 10;
768
- white-space: nowrap;
769
- }
770
- `})]})},Mn=Object.assign(w.forwardRef((t,n)=>{const{t:a}=le.useNiceTranslation(),{initialData:r,data:s,maxPoints:u=60,updateInterval:c=1e3,fetchData:d,width:j=600,height:y=200,chartType:p="line",color:g="var(--nice-color-primary, #3b82f6)",showGrid:z=!0,showTimeAxis:b=!0,showCurrentValue:C=!0,title:o,valueFormatter:l=Z=>Z.toFixed(2),timeFormatter:h=Z=>new Date(Z).toLocaleTimeString(),onDataUpdate:x,paused:$,className:k,style:f,testId:M,"data-testid":v,...S}=t,[i,N]=w.useState(r??s??[]),[_,E]=w.useState($||!1),T=w.useRef(void 0);w.useEffect(()=>{$!==void 0&&E($)},[$]),w.useEffect(()=>{if(_||!d)return;const Z=async()=>{try{const oe=await d();N(ue=>{const ye=[...ue,oe].slice(-u);return x?.(ye),ye})}catch(oe){console.error("Failed to fetch realtime data:",oe)}};return T.current=setInterval(Z,c),()=>{T.current&&clearInterval(T.current)}},[_,d,c,u,x]);const P=w.useCallback(Z=>{N(oe=>{const ue=[...oe,Z].slice(-u);return x?.(ue),ue})},[u,x]),D=w.useCallback(()=>{N([]),x?.([])},[x]),B=w.useCallback(()=>E(!0),[]),Y=w.useCallback(()=>E(!1),[]);w.useImperativeHandle(n,()=>({addDataPoint:P,clearData:D,pause:B,resume:Y,getData:()=>i}),[P,D,B,Y,i]);const F={top:20,right:60,bottom:b?40:20,left:50},V=j-F.left-F.right,q=y-F.top-F.bottom,K=i.map(Z=>Z.value),R=K.length?Math.min(...K):0,X=K.length?Math.max(...K):100,se=(X-R||1)*.1,ae=R-se,W=X+se-ae,A=Z=>{const oe=d?u-1:Math.max(1,i.length-1);return F.left+Z/oe*V},U=Z=>F.top+q-(Z-ae)/W*q,I=i.map((Z,oe)=>`${A(oe)},${U(Z.value)}`).join(" "),G=i.length>0?`M ${A(0)},${F.top+q} L ${I} L ${A(i.length-1)},${F.top+q} Z`:"",fe=i.length>0?i[i.length-1].value:null;return e.jsxs("div",{className:`nice-realtime-chart ${k||""}`,style:{width:j,...f},"data-testid":v??M,...S,children:[e.jsxs("div",{className:"nice-realtime-header",children:[e.jsx("span",{className:"nice-realtime-title",children:o}),e.jsxs("div",{className:"nice-realtime-controls",children:[e.jsxs("span",{className:`nice-realtime-status ${_?"paused":"live"}`,children:[e.jsx("span",{className:"nice-realtime-status-dot"}),e.jsx("span",{children:_?a("charts.paused","Paused"):a("charts.live","Live")})]}),e.jsx("button",{className:`nice-realtime-btn ${_?"paused":""}`,onClick:()=>E(!_),"aria-label":_?a("charts.resume","Resume"):a("charts.pause","Pause"),children:e.jsx(le.NiceIcon,{name:_?"play":"pause",size:14})}),C&&fe!==null&&e.jsx("span",{className:"nice-realtime-value",children:l(fe)})]})]}),e.jsxs("svg",{width:j,height:y,className:"nice-realtime-svg",children:[z&&e.jsx("g",{className:"nice-realtime-grid",children:[0,.25,.5,.75,1].map((Z,oe)=>{const ue=F.top+q*(1-Z),ye=ae+W*Z;return e.jsxs("g",{children:[e.jsx("line",{x1:F.left,y1:ue,x2:j-F.right,y2:ue,stroke:"var(--nice-border-color, #e5e7eb)",strokeDasharray:Z===0?void 0:"3"}),e.jsx("text",{x:F.left-8,y:ue,textAnchor:"end",dominantBaseline:"middle",fontSize:"10",fill:"var(--nice-text-secondary, #6b7280)",children:Math.round(ye).toLocaleString()})]},oe)})}),p==="area"&&i.length>0&&e.jsx("path",{d:G,fill:g,fillOpacity:.2}),i.length>1&&e.jsx("polyline",{points:I,fill:"none",stroke:g,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"}),i.length>0&&e.jsx("circle",{cx:A(i.length-1),cy:U(i[i.length-1].value),r:3,fill:g,className:"nice-realtime-point"}),b&&i.length>0&&e.jsx("g",{className:"nice-realtime-time-axis",children:Array.from(new Set([0,Math.floor(i.length/2),i.length-1].filter(Z=>i[Z]))).map(Z=>e.jsx("text",{x:A(Z),y:y-8,textAnchor:"middle",fontSize:"10",fill:"var(--nice-text-secondary, #6b7280)",children:h(i[Z].timestamp)},`tx-${Z}`))})]}),e.jsx("style",{children:`
771
- .nice-realtime-chart {
772
- font-family: inherit;
773
- color: var(--nice-text-primary, #111827);
774
- background: var(--nice-bg-elevated, #ffffff);
775
- border-radius: 8px;
776
- position: relative;
777
- }
778
-
779
- .nice-realtime-header {
780
- display: flex;
781
- justify-content: space-between;
782
- align-items: center;
783
- padding: 12px 16px;
784
- border-bottom: 1px solid var(--nice-border-color, #e5e7eb);
785
- }
786
-
787
- .nice-realtime-title {
788
- font-size: 14px;
789
- font-weight: 600;
790
- color: var(--nice-text-primary, #111827);
791
- }
792
-
793
- .nice-realtime-controls {
794
- display: flex;
795
- align-items: center;
796
- gap: 12px;
797
- }
798
-
799
- .nice-realtime-btn {
800
- background: none;
801
- border: none;
802
- cursor: pointer;
803
- font-size: 16px;
804
- padding: 4px;
805
- font-family: inherit;
806
- color: inherit;
807
- }
808
-
809
- .nice-realtime-value {
810
- font-size: 18px;
811
- font-weight: 600;
812
- color: ${g};
813
- font-variant-numeric: tabular-nums;
814
- }
815
-
816
- /* Static current-value dot — no pulsing animation (was distracting) */
817
-
818
- .nice-realtime-status {
819
- display: inline-flex;
820
- align-items: center;
821
- gap: 6px;
822
- font-size: 11px;
823
- font-family: inherit;
824
- color: var(--nice-text-secondary, #6b7280);
825
- background: var(--nice-bg-secondary, #f3f4f6);
826
- padding: 2px 10px;
827
- border-radius: 999px;
828
- }
829
-
830
- .nice-realtime-status-dot {
831
- width: 8px;
832
- height: 8px;
833
- border-radius: 50%;
834
- background: var(--nice-color-success, #22c55e);
835
- }
836
-
837
- .nice-realtime-status.paused .nice-realtime-status-dot {
838
- background: var(--nice-color-warning, #f59e0b);
839
- }
840
-
841
- .nice-realtime-status.live .nice-realtime-status-dot {
842
- animation: live-pulse 2s ease-in-out infinite;
843
- }
844
-
845
- @keyframes live-pulse {
846
- 0%, 100% { opacity: 1; }
847
- 50% { opacity: 0.4; }
848
- }
849
- `})]})}),{displayName:"NiceRealtimeChart"}),kn=({data:t,width:n=600,height:a=400,showLabels:r=!0,showValues:s=!0,onNodeClick:u,drilldownEnabled:c=!0,colors:d=ut,tilePadding:j=2,className:y,style:p,testId:g,"data-testid":z,...b})=>{const{t:C}=le.useNiceTranslation(),o=w.useMemo(()=>Array.isArray(t)?{id:"root",name:"Root",value:t.reduce((E,T)=>E+(T.value||0),0),children:t.map((E,T)=>({id:`${T}`,name:E.label??E.name??`Item ${T+1}`,value:E.value,color:E.color}))}:t,[t]),[l,h]=w.useState(o),[x,$]=w.useState([o.name]),[k,f]=w.useState(null),M=w.useRef(null),v=w.useMemo(()=>{const T=l.children||[];if(T.length===0)return[];const P=T.reduce((R,X)=>R+X.value,0),D=T.map(R=>({node:R,area:R.value/P*n*a}));D.sort((R,X)=>X.area-R.area);const B=[];let Y=0,F=0,V=n,q=a,K=0;for(;K<D.length;){const R=V<q;let X=0,te=[];const se=R?q:V;for(let W=K;W<D.length;W++){const A=[...te,D[W]],U=A.reduce((G,fe)=>G+fe.area,0),I=S(A,U,se);if(te.length===0)te=A,X=U;else{const G=S(te,X,se);if(I<=G)te=A,X=U;else break}}const ae=X/se;let he=0;te.forEach((W,A)=>{const U=W.area/ae;B.push({node:W.node,x:R?Y:Y+he,y:R?F+he:F,w:R?ae:U,h:R?U:ae,color:W.node.color||d[(K+A)%d.length]}),he+=U}),R?(Y+=ae,V-=ae):(F+=ae,q-=ae),K+=te.length}return B},[l,n,a,d]);function S(E,T,P){const D=T/P;let B=0;for(const Y of E){const F=Y.area/D,V=Math.max(D/F,F/D);B=Math.max(B,V)}return B}const i=E=>{u?.(E,[...x,E.name]),c&&E.children&&E.children.length>0&&(h(E),$(T=>[...T,E.name]))},N=()=>{if(x.length<=1)return;let E=o;const T=x.slice(0,-1);for(let P=1;P<T.length;P++){const D=E.children?.find(B=>B.name===T[P]);D&&(E=D)}h(E),$(T)},_=(E,T)=>{const P=M.current?.getBoundingClientRect();P&&f({x:T.clientX-P.left,y:T.clientY-P.top,content:E})};return e.jsxs("div",{className:`nice-treemap-chart ${y||""}`,style:{width:n,...p},"data-testid":z??g,...b,children:[e.jsxs("div",{className:"nice-treemap-nav",children:[x.length>1&&e.jsxs("button",{className:"nice-treemap-back",onClick:N,children:[e.jsx(le.NiceIcon,{name:"arrow-left",size:14})," ",C("charts.back","Back")]}),e.jsx("div",{className:"nice-treemap-breadcrumbs",children:x.map((E,T)=>e.jsxs(w.Fragment,{children:[T>0&&e.jsx("span",{className:"nice-treemap-sep",children:"/"}),e.jsx("span",{className:T===x.length-1?"current":"",children:E})]},T))})]}),e.jsx("svg",{ref:M,width:n,height:a,className:"nice-treemap-svg",children:v.map((E,T)=>{const{node:P,x:D,y:B,w:Y,h:F,color:V}=E,q=Math.min(14,Math.max(10,Math.min(Y,F)/6)),K=Y>40&&F>30;return e.jsxs("g",{onClick:()=>i(P),onMouseEnter:R=>_(`${P.name}: ${P.value.toLocaleString()}`,R),onMouseLeave:()=>f(null),children:[e.jsx("rect",{x:D+j/2,y:B+j/2,width:Math.max(0,Y-j),height:Math.max(0,F-j),fill:V,rx:4,className:"nice-treemap-tile"}),r&&K&&e.jsx("text",{x:D+Y/2,y:B+F/2-(s?6:0),textAnchor:"middle",dominantBaseline:"middle",fontSize:q,fill:"white",fontWeight:"500",style:{pointerEvents:"none"},children:P.name.length>Y/q+2?P.name.slice(0,Math.floor(Y/q))+"...":P.name}),s&&K&&e.jsx("text",{x:D+Y/2,y:B+F/2+10,textAnchor:"middle",dominantBaseline:"middle",fontSize:q-2,fill:"var(--nice-overlay-light-80, rgba(255, 255, 255, 0.8))",style:{pointerEvents:"none"},children:P.value.toLocaleString()})]},T)})}),k&&e.jsx("div",{className:"nice-treemap-tooltip",style:{left:k.x+10,top:k.y-30},children:k.content}),e.jsx("style",{children:`
850
- .nice-treemap-chart {
851
- font-family: system-ui, -apple-system, sans-serif;
852
- background: var(--nice-bg-primary, #ffffff);
853
- border-radius: var(--nice-radius-lg, 8px);
854
- position: relative;
855
- }
856
-
857
- .nice-treemap-nav {
858
- display: flex;
859
- align-items: center;
860
- gap: var(--nice-space-3, 12px);
861
- padding: var(--nice-space-3, 12px) var(--nice-space-4, 16px);
862
- border-bottom: 1px solid var(--nice-border-color, #e5e7eb);
863
- }
864
-
865
- .nice-treemap-back {
866
- background: var(--nice-bg-secondary, #f8fafc);
867
- color: var(--nice-text-primary, #0f172a);
868
- border: none;
869
- padding: var(--nice-space-1-5, 6px) var(--nice-space-3, 12px);
870
- border-radius: var(--nice-radius-md, 6px);
871
- cursor: pointer;
872
- font-size: 13px;
873
- }
874
-
875
- .nice-treemap-back:hover {
876
- background: var(--nice-border-color, #e5e7eb);
877
- }
878
-
879
- .nice-treemap-breadcrumbs {
880
- display: flex;
881
- align-items: center;
882
- gap: var(--nice-space-1, 4px);
883
- font-size: 13px;
884
- color: var(--nice-text-secondary, #475569);
885
- }
886
-
887
- .nice-treemap-breadcrumbs .current {
888
- color: var(--nice-text-primary, #0f172a);
889
- font-weight: 500;
890
- }
891
-
892
- .nice-treemap-sep {
893
- color: var(--nice-text-muted, #94a3b8);
894
- }
895
-
896
- .nice-treemap-tile {
897
- cursor: pointer;
898
- transition: opacity 0.2s, transform 0.1s;
899
- }
900
-
901
- .nice-treemap-tile:hover {
902
- opacity: 0.85;
903
- }
904
-
905
- .nice-treemap-tooltip {
906
- position: absolute;
907
- /* audit-allow: token-role — inverted chip like .nice-tooltip: the text colour is the
908
- fill and the label uses --nice-text-inverse, so the pair flips together. */
909
- background: var(--nice-text-primary, #0f172a);
910
- color: var(--nice-text-inverse, #ffffff);
911
- padding: var(--nice-space-1-5, 6px) var(--nice-space-2-5, 10px);
912
- border-radius: var(--nice-radius-sm, 4px);
913
- font-size: 12px;
914
- pointer-events: none;
915
- z-index: 10;
916
- white-space: nowrap;
917
- }
918
- `})]})};exports.CHART_COLORS=_e;exports.NiceBarGauge=_t;exports.NiceBullet=jt;exports.NiceChart=De;exports.NiceChart$1=pt;exports.NiceChartAI=gn;exports.NiceCircularGauge=xt;exports.NiceDrillDownChart=_n;exports.NiceForecastChart=on;exports.NiceFunnel=Nt;exports.NiceHeatMap=Tt;exports.NiceLinearGauge=gt;exports.NiceLiveChart=dn;exports.NiceMapChart=jn;exports.NiceOrganizationChart=Zt;exports.NicePieChart=Mt;exports.NicePolarChart=nn;exports.NiceRangeSelector=rn;exports.NiceRealtimeChart=Mn;exports.NiceSankey=Ke;exports.NiceSankey$1=zt;exports.NiceSankeyChart=$n;exports.NiceSparkline=Qt;exports.NiceStockChart=Kt;exports.NiceTreeMap=Je;exports.NiceTreeMap$1=Lt;exports.NiceTreeMapChart=kn;exports.NiceVectorMap=Qe;exports.NiceVectorMap$1=Bt;exports.autoDetectColumns=Xt;exports.createMockLiveChartSource=fn;exports.createSignalRLiveChartSource=hn;exports.createWebSocketLiveChartSource=un;exports.downloadBlob=Te;exports.downloadCSV=tt;exports.downloadHTML=lt;exports.downloadJSON=ct;exports.downloadPDF=st;exports.downloadXLSX=rt;exports.exportToCSV=et;exports.exportToHTML=it;exports.exportToJSON=ot;exports.exportToPDF=at;exports.exportToXLSX=nt;exports.niceExport=Vt;exports.orgChartToPng=ht;exports.orgChartToSvg=He;exports.tidyTreeLayout=dt;