import{C as N,r as o,R as w,B as R,L as A,P,j as t,F as B,a as I,b as K,c as O,d as k,e as F,f as T,A as _,p as $,g as D,h as L,i as M}from"./index-Cy6U-KII.js";const v="label";function C(s,e){typeof s=="function"?s(e):s&&(s.current=e)}function S(s,e){const a=s.options;a&&e&&Object.assign(a,e)}function y(s,e){s.labels=e}function E(s,e){let a=arguments.length>2&&arguments[2]!==void 0?arguments[2]:v;const l=[];s.datasets=e.map(n=>{const i=s.datasets.find(f=>f[a]===n[a]);return!i||!n.data||l.includes(i)?{...n}:(l.push(i),Object.assign(i,n),i)})}function G(s){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:v;const a={labels:[],datasets:[]};return y(a,s.labels),E(a,s.datasets,e),a}function U(s,e){const{height:a=150,width:l=300,redraw:n=!1,datasetIdKey:i,type:f,data:c,options:d,plugins:g=[],fallbackContent:x,updateMode:m,...p}=s,u=o.useRef(null),r=o.useRef(null),h=()=>{u.current&&(r.current=new N(u.current,{type:f,data:G(c,i),options:d&&{...d},plugins:g}),C(e,r.current))},j=()=>{C(e,null),r.current&&(r.current.destroy(),r.current=null)};return o.useEffect(()=>{!n&&r.current&&d&&S(r.current,d)},[n,d]),o.useEffect(()=>{!n&&r.current&&y(r.current.config.data,c.labels)},[n,c.labels]),o.useEffect(()=>{!n&&r.current&&c.datasets&&E(r.current.config.data,c.datasets,i)},[n,c.datasets]),o.useEffect(()=>{r.current&&(n?(j(),setTimeout(h)):r.current.update(m))},[n,d,c.labels,c.datasets,m]),o.useEffect(()=>{r.current&&(j(),setTimeout(h))},[f]),o.useEffect(()=>(h(),()=>j()),[]),w.createElement("canvas",{ref:u,role:"img",height:a,width:l,...p},x)}const q=o.forwardRef(U);function b(s,e){return N.register(e),o.forwardRef((a,l)=>w.createElement(q,{...a,ref:l,type:s}))}const H=b("line",A),J=b("bar",R),Q=b("pie",P);N.register(K,O,k,F,T,_,$,D,L,M);const X=({type:s,data:e,options:a={},title:l,verticalLabel:n,horizontalLabel:i,filters:f,legendPosition:c="top",className:d})=>{var p;const g={line:H,bar:J,pie:Q}[s],x={responsive:!0,maintainAspectRatio:!1,plugins:{legend:{display:!1,position:c,...((p=a.plugins)==null?void 0:p.legend)||{}}},...s==="pie"&&{scales:{}}},m=V(x,a);return t.jsxs("div",{className:`flex flex-col rounded-md bg-neutral-50 p-4 ${d}`,children:[t.jsxs("div",{className:"mb-4 flex flex-col justify-between gap-4 sm:flex-row sm:items-center",children:[l&&t.jsx("h3",{className:"text-sm font-medium text-gray-800",children:l}),t.jsxs("div",{className:"flex flex-wrap items-center gap-4",children:[s!=="pie"&&(n||i)&&t.jsxs("div",{className:"mr-4 flex items-center gap-4",children:[n&&t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx(B,{className:"text-primary"}),t.jsx("span",{className:"text-xs font-medium",children:n})]}),i&&t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx(I,{className:"text-primary"}),t.jsx("span",{className:"text-xs font-medium",children:i})]})]}),f&&t.jsx("div",{className:"flex flex-wrap items-center gap-2",children:f})]})]}),t.jsx("div",{className:`relative h-64 ${s==="bar"?"w-150":"w-full"} `,children:t.jsx(g,{data:e,options:m,...s==="pie"&&{data:{...e,datasets:e.datasets.map(u=>({...u}))}}})}),s==="pie"&&(e==null?void 0:e.labels)&&t.jsx("div",{className:"mt-4 grid grid-cols-2 gap-4 sm:grid-cols-3 lg:grid-cols-3",children:e.labels.map((u,r)=>t.jsxs("div",{className:"flex items-center justify-center gap-2",children:[t.jsx("div",{className:"h-3 w-3 rounded-full shadow-sm",style:{backgroundColor:e.datasets[0].backgroundColor[r]}}),t.jsxs("div",{className:"flex flex-col",children:[t.jsx("span",{className:"text-xs font-medium text-gray-800",children:u}),t.jsxs("span",{className:"text-xs text-gray-500",children:[e.datasets[0].data[r],"%"]})]})]},u))})]})},V=(s,e)=>{var a,l;return{...s,...e,plugins:{...s.plugins,...e.plugins,legend:{...(a=s.plugins)==null?void 0:a.legend,...(l=e.plugins)==null?void 0:l.legend}},scales:{...s.scales,...e.scales}}};export{X as default};
//# sourceMappingURL=CustomGraph-DBXxjBsQ.js.map
