import{c as H,a as g,d as at,f as T,s as tt}from"../chunks/DktbhmWA.js";import"../chunks/CvCfPjaJ.js";import{f as R,p as ut,d as F,e as vt,s as b,g as h,a as ft,c as s,b as w,r,t as pt,n as W,u as Q,o as Ft}from"../chunks/CPWcrcMP.js";import{i as k}from"../chunks/0jvM7PZf.js";import{I as V,h as C,e as St,f as Nt,i as Pt,c as it,m as st,r as lt}from"../chunks/CNDZS43m.js";import{b as dt}from"../chunks/CFyEX9sq.js";import{b as Lt}from"../chunks/CX78IQmC.js";import{l as z,s as I,p as Y}from"../chunks/DBypTyp2.js";import{T as ct,p as Yt}from"../chunks/P-kzdO9z.js";import{X as Ht}from"../chunks/DeZd3Jxh.js";function Rt(d,t){const a=z(t,["children","$$slots","$$events","$$legacy"]);/**
 * @license lucide-svelte v0.511.0 - ISC
 *
 * ISC License
 *
 * Copyright (c) for portions of Lucide are held by Cole Bemis 2013-2022 as part of Feather (MIT). All other copyright (c) for Lucide are held by Lucide Contributors 2022.
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 */const n=[["path",{d:"M12 15V3"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}],["path",{d:"m7 10 5 5 5-5"}]];V(d,I({name:"download"},()=>a,{get iconNode(){return n},children:(i,m)=>{var o=H(),l=R(o);C(l,t,"default",{}),g(i,o)},$$slots:{default:!0}}))}function Vt(d,t){const a=z(t,["children","$$slots","$$events","$$legacy"]);/**
 * @license lucide-svelte v0.511.0 - ISC
 *
 * ISC License
 *
 * Copyright (c) for portions of Lucide are held by Cole Bemis 2013-2022 as part of Feather (MIT). All other copyright (c) for Lucide are held by Lucide Contributors 2022.
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 */const n=[["path",{d:"M10 12.5 8 15l2 2.5"}],["path",{d:"m14 12.5 2 2.5-2 2.5"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4"}],["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7z"}]];V(d,I({name:"file-code"},()=>a,{get iconNode(){return n},children:(i,m)=>{var o=H(),l=R(o);C(l,t,"default",{}),g(i,o)},$$slots:{default:!0}}))}function Ct(d,t){const a=z(t,["children","$$slots","$$events","$$legacy"]);/**
 * @license lucide-svelte v0.511.0 - ISC
 *
 * ISC License
 *
 * Copyright (c) for portions of Lucide are held by Cole Bemis 2013-2022 as part of Feather (MIT). All other copyright (c) for Lucide are held by Lucide Contributors 2022.
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 */const n=[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4"}],["circle",{cx:"10",cy:"12",r:"2"}],["path",{d:"m20 17-1.296-1.296a2.41 2.41 0 0 0-3.408 0L9 22"}]];V(d,I({name:"file-image"},()=>a,{get iconNode(){return n},children:(i,m)=>{var o=H(),l=R(o);C(l,t,"default",{}),g(i,o)},$$slots:{default:!0}}))}function zt(d,t){const a=z(t,["children","$$slots","$$events","$$legacy"]);/**
 * @license lucide-svelte v0.511.0 - ISC
 *
 * ISC License
 *
 * Copyright (c) for portions of Lucide are held by Cole Bemis 2013-2022 as part of Feather (MIT). All other copyright (c) for Lucide are held by Lucide Contributors 2022.
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 */const n=[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4"}],["path",{d:"M8 13h2"}],["path",{d:"M14 13h2"}],["path",{d:"M8 17h2"}],["path",{d:"M14 17h2"}]];V(d,I({name:"file-spreadsheet"},()=>a,{get iconNode(){return n},children:(i,m)=>{var o=H(),l=R(o);C(l,t,"default",{}),g(i,o)},$$slots:{default:!0}}))}function It(d,t){const a=z(t,["children","$$slots","$$events","$$legacy"]);/**
 * @license lucide-svelte v0.511.0 - ISC
 *
 * ISC License
 *
 * Copyright (c) for portions of Lucide are held by Cole Bemis 2013-2022 as part of Feather (MIT). All other copyright (c) for Lucide are held by Lucide Contributors 2022.
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 */const n=[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4"}],["path",{d:"M10 9H8"}],["path",{d:"M16 13H8"}],["path",{d:"M16 17H8"}]];V(d,I({name:"file-text"},()=>a,{get iconNode(){return n},children:(i,m)=>{var o=H(),l=R(o);C(l,t,"default",{}),g(i,o)},$$slots:{default:!0}}))}function Ot(d,t){const a=z(t,["children","$$slots","$$events","$$legacy"]);/**
 * @license lucide-svelte v0.511.0 - ISC
 *
 * ISC License
 *
 * Copyright (c) for portions of Lucide are held by Cole Bemis 2013-2022 as part of Feather (MIT). All other copyright (c) for Lucide are held by Lucide Contributors 2022.
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 */const n=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2"}],["circle",{cx:"9",cy:"9",r:"2"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"}]];V(d,I({name:"image"},()=>a,{get iconNode(){return n},children:(i,m)=>{var o=H(),l=R(o);C(l,t,"default",{}),g(i,o)},$$slots:{default:!0}}))}function Wt(d,t){const a=z(t,["children","$$slots","$$events","$$legacy"]);/**
 * @license lucide-svelte v0.511.0 - ISC
 *
 * ISC License
 *
 * Copyright (c) for portions of Lucide are held by Cole Bemis 2013-2022 as part of Feather (MIT). All other copyright (c) for Lucide are held by Lucide Contributors 2022.
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 */const n=[["path",{d:"M3 7v6h6"}],["path",{d:"M21 17a9 9 0 0 0-9-9 9 9 0 0 0-6 2.3L3 13"}]];V(d,I({name:"undo"},()=>a,{get iconNode(){return n},children:(i,m)=>{var o=H(),l=R(o);C(l,t,"default",{}),g(i,o)},$$slots:{default:!0}}))}const et={Today:"Today",LastDay:"LastDay",ThisWeek:"ThisWeek",LastWeek:"LastWeek",ThisMonth:"ThisMonth",LastMonth:"LastMonth",ThisYear:"ThisYear",LastYear:"LastYear"};function ht(d){const t=new Date;let a,n=new Date(t);switch(d){case"Today":a=new Date(t.getFullYear(),t.getMonth(),t.getDate());break;case"LastDay":a=new Date(t.getFullYear(),t.getMonth(),t.getDate()-1),n=new Date(a.getFullYear(),a.getMonth(),a.getDate(),23,59);break;case"LastWeek":const i=new Date,m=t.getDay()===0?6:t.getDay()-1;i.setDate(t.getDate()-m-7),a=new Date(i.getFullYear(),i.getMonth(),i.getDate()),n=new Date(a),n.setDate(a.getDate()+6),n.setHours(23,59);break;case"LastMonth":a=new Date(t.getFullYear(),t.getMonth()-1,1),n=new Date(t.getFullYear(),t.getMonth(),0,23,59);break;case"LastYear":a=new Date(t.getFullYear()-1,0,1),n=new Date(t.getFullYear()-1,11,31,23,59);break;case"ThisWeek":a=new Date;const o=t.getDay()===0?6:t.getDay()-1;a.setDate(t.getDate()-o),a.setHours(0,0);break;case"ThisMonth":a=new Date(t.getFullYear(),t.getMonth(),1);break;case"ThisYear":a=new Date(t.getFullYear(),0,1);break;default:throw new Error("Invalid TimeRange provided")}return{startTime:a,startTimeUtc:a.toISOString().slice(0,16),endTime:n,endTimeUtc:n.toISOString().slice(0,16)}}var Jt=(d,t,a)=>t(ht(h(a))),Ut=T("<option> </option>"),Xt=T('<div class="flex flex-col gap-2"><div class="text-lg">Time Range</div> <select class="text-lg bg-base-300 p-1"></select></div>');function jt(d,t){ut(t,!0);let a=Y(t,"timeRange",15),n=F(vt(et.Today));var i=Xt(),m=b(s(i),2);m.__change=[Jt,a,n],St(m,21,()=>Object.keys(et),Pt,(o,l)=>{var c=Ut(),O=s(c,!0);r(c);var x={};pt(()=>{tt(O,h(l)),x!==(x=h(l))&&(c.value=(c.__value=h(l))??"")}),g(o,c)}),r(m),r(i),Nt(m,()=>h(n),o=>w(n,o)),g(d,i),ft()}at(["change"]);var Et=T("<li><button><!> PNG</button></li>"),qt=T("<li><button><!> PDF</button></li>"),At=T("<li><button><!> XLSX</button></li>"),Zt=T("<li><button><!> CSV</button></li>"),Bt=T("<li><button><!> JSON</button></li>"),Gt=T('<div class="dropdown dropdown-end" style="z-index: 50"><button class="btn btn-sm btn-secondary tooltip tooltip-bottom" data-tip="Export data"><!></button> <ul class="dropdown-content menu p-2 shadow bg-base-100 rounded-box w-40"><!> <!> <!> <!> <!></ul></div>');function Kt(d,t){let a=Y(t,"saveToPng",3,void 0),n=Y(t,"saveToPdf",3,void 0),i=Y(t,"saveToXlsx",3,void 0),m=Y(t,"saveToCsv",3,void 0),o=Y(t,"saveToJson",3,void 0);var l=Gt(),c=s(l),O=s(c);Rt(O,{}),r(c);var x=b(c,2),J=s(x);{var E=u=>{var v=Et(),f=s(v);f.__click=function(...y){var _;(_=a())==null||_.apply(this,y)};var $=s(f);Ot($,{}),W(),r(f),r(v),g(u,v)};k(J,u=>{a()&&u(E)})}var U=b(J,2);{var q=u=>{var v=qt(),f=s(v);f.__click=function(...y){var _;(_=n())==null||_.apply(this,y)};var $=s(f);Ct($,{}),W(),r(f),r(v),g(u,v)};k(U,u=>{n()&&u(q)})}var X=b(U,2);{var A=u=>{var v=At(),f=s(v);f.__click=function(...y){var _;(_=i())==null||_.apply(this,y)};var $=s(f);zt($,{}),W(),r(f),r(v),g(u,v)};k(X,u=>{i()&&u(A)})}var S=b(X,2);{var Z=u=>{var v=Zt(),f=s(v);f.__click=function(...y){var _;(_=m())==null||_.apply(this,y)};var $=s(f);It($,{}),W(),r(f),r(v),g(u,v)};k(S,u=>{m()&&u(Z)})}var N=b(S,2);{var P=u=>{var v=Bt(),f=s(v);f.__click=function(...y){var _;(_=o())==null||_.apply(this,y)};var $=s(f);Vt($,{}),W(),r(f),r(v),g(u,v)};k(N,u=>{o()&&u(P)})}r(x),r(l),g(d,l)}at(["click"]);var Qt=T('<button class="btn btn-sm btn-secondary tooltip tooltip-bottom" data-tip="Reset Filter"><!></button>'),te=T('<div class="flex gap-2 py-2"><span>Value filter:</span> <input type="number" class="input input-bordered input-sm w-20" placeholder="Min"/> <input type="number" class="input input-bordered input-sm w-20" placeholder="Max"/> <!></div>'),ee=T('<button class="btn btn-sm btn-secondary tooltip tooltip-bottom" data-tip="Reset sorting"><!></button>'),ae=T('<div class="card bg-base-200 p-3 text-base-content"><div class="flex justify-between items-start mb-3"><div class="flex"><!></div> <div class="gap-4"><div class="text-lg"> </div> <!></div> <div class="flex flex-col items-end"><div> </div> <div class="flex flex-row gap-2 mt-2"><!> <!></div></div></div> <div></div></div>');function ne(d,t){ut(t,!0);let a=Y(t,"height",3,"1024px"),n=new it(`${st.getClientId()}/${t.topic}_History`),i=new it(t.topic),m=F(""),o=F(0),l=null,c,O=F(!1);const x=t.topic.replace("/","_");ct.extendModule("download","downloaders",{string(e){let p=e.toString();return"data:application/txt;charset=utf-8,"+encodeURIComponent(p)}});function J(){const e=Intl.NumberFormat().resolvedOptions().locale;return console.log(e),e.startsWith("no")?";":","}function E(){c.download("csv",x+".csv",{delimiter:J()})}function U(){c.download("json",x+".json")}function q(){let e="portrait";c.getColumns().length>4&&(e="landscape"),c.download("pdf",x+".pdf",{orientation:e,title:t.topic})}function X(){c.download("xlsx",x+".xlsx",{sheetName:x})}Q(()=>{if(n.value)try{let e=n.value;if(A(e)){const D=Uint8Array.from(atob(e),M=>M.charCodeAt(0));e=Yt.inflate(D,{to:"string"})}const p=JSON.parse(e);if(!p.length)return;w(o,p.length,!0),p.length>0?c.setData(p):c.clearData()}catch(e){console.error("Failed to parse history data:",e)}}),Q(()=>{if(i.value){let e=JSON.parse(i.value);e.unit&&w(m,e.unit,!0)}});function A(e){try{return btoa(atob(e))===e}catch{return!1}}Ft(async()=>{l&&(c=new ct(l,{layout:"fitColumns",height:a(),movableColumns:!0,index:"T",columns:[{title:"Time",field:"T"},{title:"Value",field:"V",formatter(e){return`${e.getValue()} ${h(m)}`}}],renderVertical:"virtual"}),c.on("dataSorted",()=>{w(O,c.getSorters().length>0)}))});let S=F(vt(ht(et.Today)));Q(()=>{const e=JSON.stringify({format:"object",startTime:h(S).startTimeUtc,endTime:h(S).endTimeUtc,gzip:!0});st.publish(t.topic+"/History",e,!1),console.log("Sent history request:",e)});function Z(){c.clearSort()}let N=F(""),P=F(""),u=F(!1);function v(){if(!c)return;const e=h(N)?parseFloat(h(N)):null,p=h(P)?parseFloat(h(P)):null;w(u,e!==null||p!==null,!0),c.setFilter(D=>{const M=parseFloat(D.V);return!(e!==null&&M<e||p!==null&&M>p)})}function f(){w(N,""),w(P,""),w(u,!1),c.clearFilter(!1)}var $=ae(),y=s($),_=s(y),gt=s(_);jt(gt,{get timeRange(){return h(S)},set timeRange(e){w(S,e,!0)}}),r(_);var B=b(_,2),G=s(B),mt=s(G,!0);r(G);var _t=b(G,2);{var bt=e=>{var p=te(),D=b(s(p),2);lt(D),D.__input=v;var M=b(D,2);lt(M),M.__input=v;var Dt=b(M,2);{var Mt=L=>{var j=Qt();j.__click=f;var kt=s(j);Ht(kt,{}),r(j),g(L,j)};k(Dt,L=>{h(u)&&L(Mt)})}r(p),dt(D,()=>h(N),L=>w(N,L)),dt(M,()=>h(P),L=>w(P,L)),g(e,p)};k(_t,e=>{h(o)&&e(bt)})}r(B);var nt=b(B,2),K=s(nt),$t=s(K);r(K);var ot=b(K,2),rt=s(ot);{var yt=e=>{var p=ee();p.__click=Z;var D=s(p);Wt(D,{}),r(p),g(e,p)};k(rt,e=>{h(O)&&e(yt)})}var Tt=b(rt,2);{var xt=e=>{Kt(e,{saveToCsv:E,saveToJson:U,saveToPdf:q,saveToXlsx:X})};k(Tt,e=>{h(o)&&e(xt)})}r(ot),r(nt),r(y);var wt=b(y,2);Lt(wt,e=>l=e,()=>l),r($),pt(()=>{tt(mt,t.topic),tt($t,`${h(o)??""} Entries`)}),g(d,$),ft()}at(["input","click"]);var oe=T('<section><div class="container mx-auto p-4"><!></div></section>');function he(d){var t=oe(),a=s(t),n=s(a);ne(n,{topic:"HAN2X_70389/actPowPos"}),r(a),r(t),g(d,t)}export{he as component};
