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