import{hG as m,r as a,bf as b,il as I,im as K}from"./index-DxWYYOj0.js";const y="label";function h(t,e){typeof t=="function"?t(e):t&&(t.current=e)}function L(t,e){Object.assign(t.options,e)}function C(t,e){t.labels=e}function E(t,e){let s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:y;const o=[];t.datasets=e.map(n=>{const c=t.datasets.find(i=>i[s]===n[s]);return!c||!n.data||o.includes(c)?{...n}:(o.push(c),Object.assign(c,n),c)})}function v(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:y;const s={labels:[],datasets:[]};return C(s,t.labels),E(s,t.datasets,e),s}function B(t,e){let{height:s=150,width:o=300,redraw:n=!1,datasetIdKey:c,type:i,data:u,options:f,plugins:w=[],fallbackContent:O,updateMode:p,...j}=t;const l=a.useRef(null),r=a.useRef(),d=()=>{l.current&&(r.current=new m(l.current,{type:i,data:v(u,c),options:f&&{...f},plugins:w}),h(e,r.current))},g=()=>{h(e,null),r.current&&(r.current.destroy(),r.current=null)};return a.useEffect(()=>{!n&&r.current&&f&&L(r.current,f)},[n,f]),a.useEffect(()=>{!n&&r.current&&C(r.current.config.data,u.labels)},[n,u.labels]),a.useEffect(()=>{!n&&r.current&&u.datasets&&E(r.current.config.data,u.datasets,c)},[n,u.datasets]),a.useEffect(()=>{r.current&&(n?(g(),setTimeout(d)):r.current.update(p))},[n,f,u.labels,u.datasets,p]),a.useEffect(()=>{r.current&&(g(),setTimeout(d))},[i]),a.useEffect(()=>(d(),()=>g()),[]),b.createElement("canvas",Object.assign({ref:l,role:"img",height:s,width:o},j),O)}const T=a.forwardRef(B);function R(t,e){return m.register(e),a.forwardRef((s,o)=>b.createElement(T,Object.assign({},s,{ref:o,type:t})))}const k=R("line",I),G=R("bar",K);export{G as B,k as L};
