From ca2eb5d0521363f39e96f121dde2904fe4bfe71e Mon Sep 17 00:00:00 2001 From: maziggy Date: Wed, 10 Dec 2025 19:13:47 +0100 Subject: [PATCH] Added quick button to disable notification --- .../{index-Y4EG-tDv.js => index-C2iKZTlc.js} | 20 +++++++++---------- static/index.html | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) rename static/assets/{index-Y4EG-tDv.js => index-C2iKZTlc.js} (94%) diff --git a/static/assets/index-Y4EG-tDv.js b/static/assets/index-C2iKZTlc.js similarity index 94% rename from static/assets/index-Y4EG-tDv.js rename to static/assets/index-C2iKZTlc.js index 208a6a740..7bab2e11a 100644 --- a/static/assets/index-Y4EG-tDv.js +++ b/static/assets/index-C2iKZTlc.js @@ -8408,13 +8408,13 @@ void main() { } `};class hW extends rd{constructor(e){super({type:"LineMaterial",uniforms:GR.clone(zs.line.uniforms),vertexShader:zs.line.vertexShader,fragmentShader:zs.line.fragmentShader,clipping:!0}),this.isLineMaterial=!0,this.setValues(e)}get color(){return this.uniforms.diffuse.value}set color(e){this.uniforms.diffuse.value=e}get worldUnits(){return"WORLD_UNITS"in this.defines}set worldUnits(e){e===!0?this.defines.WORLD_UNITS="":delete this.defines.WORLD_UNITS}get linewidth(){return this.uniforms.linewidth.value}set linewidth(e){this.uniforms.linewidth&&(this.uniforms.linewidth.value=e)}get dashed(){return"USE_DASH"in this.defines}set dashed(e){e===!0!==this.dashed&&(this.needsUpdate=!0),e===!0?this.defines.USE_DASH="":delete this.defines.USE_DASH}get dashScale(){return this.uniforms.dashScale.value}set dashScale(e){this.uniforms.dashScale.value=e}get dashSize(){return this.uniforms.dashSize.value}set dashSize(e){this.uniforms.dashSize.value=e}get dashOffset(){return this.uniforms.dashOffset.value}set dashOffset(e){this.uniforms.dashOffset.value=e}get gapSize(){return this.uniforms.gapSize.value}set gapSize(e){this.uniforms.gapSize.value=e}get opacity(){return this.uniforms.opacity.value}set opacity(e){this.uniforms&&(this.uniforms.opacity.value=e)}get resolution(){return this.uniforms.resolution.value}set resolution(e){this.uniforms.resolution.value.copy(e)}get alphaToCoverage(){return"USE_ALPHA_TO_COVERAGE"in this.defines}set alphaToCoverage(e){this.defines&&(e===!0!==this.alphaToCoverage&&(this.needsUpdate=!0),e===!0?(this.defines.USE_ALPHA_TO_COVERAGE="",this.extensions.derivatives=!0):(delete this.defines.USE_ALPHA_TO_COVERAGE,this.extensions.derivatives=!1))}}const TB=new eo,Zy=new De;class fW extends hwe{constructor(){super(),this.isLineSegmentsGeometry=!0,this.type="LineSegmentsGeometry",this.setIndex([0,2,1,2,3,1,2,4,3,4,5,3,4,6,5,6,7,5]),this.setAttribute("position",new Lr([-1,2,0,1,2,0,-1,1,0,1,1,0,-1,0,0,1,0,0,-1,-1,0,1,-1,0],3)),this.setAttribute("uv",new Lr([-1,2,1,2,-1,1,1,1,-1,-1,1,-1,-1,-2,1,-2],2))}applyMatrix4(e){const n=this.attributes.instanceStart,r=this.attributes.instanceEnd;return n!==void 0&&(n.applyMatrix4(e),r.applyMatrix4(e),n.needsUpdate=!0),this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this}setPositions(e){let n;e instanceof Float32Array?n=e:Array.isArray(e)&&(n=new Float32Array(e));const r=new hk(n,6,1);return this.setAttribute("instanceStart",new Iu(r,3,0)),this.setAttribute("instanceEnd",new Iu(r,3,3)),this.computeBoundingBox(),this.computeBoundingSphere(),this}setColors(e){let n;e instanceof Float32Array?n=e:Array.isArray(e)&&(n=new Float32Array(e));const r=new hk(n,6,1);return this.setAttribute("instanceColorStart",new Iu(r,3,0)),this.setAttribute("instanceColorEnd",new Iu(r,3,3)),this}fromWireframeGeometry(e){return this.setPositions(e.attributes.position.array),this}fromEdgesGeometry(e){return this.setPositions(e.attributes.position.array),this}fromMesh(e){return this.fromWireframeGeometry(new swe(e.geometry)),this}fromLineSegments(e){const n=e.geometry;return this.setPositions(n.attributes.position.array),this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new eo);const e=this.attributes.instanceStart,n=this.attributes.instanceEnd;e!==void 0&&n!==void 0&&(this.boundingBox.setFromBufferAttribute(e),TB.setFromBufferAttribute(n),this.boundingBox.union(TB))}computeBoundingSphere(){this.boundingSphere===null&&(this.boundingSphere=new sl),this.boundingBox===null&&this.computeBoundingBox();const e=this.attributes.instanceStart,n=this.attributes.instanceEnd;if(e!==void 0&&n!==void 0){const r=this.boundingSphere.center;this.boundingBox.getCenter(r);let i=0;for(let s=0,a=e.count;sT&&Vi.z>T)continue;if($i.z>T){const L=$i.z-Vi.z,q=($i.z-T)/L;$i.lerp(Vi,q)}else if(Vi.z>T){const L=Vi.z-$i.z,q=(Vi.z-T)/L;Vi.lerp($i,q)}$i.applyMatrix4(x),Vi.applyMatrix4(x),$i.multiplyScalar(1/$i.w),Vi.multiplyScalar(1/Vi.w),$i.x*=y.x/2,$i.y*=y.y/2,Vi.x*=y.x/2,Vi.y*=y.y/2,Gi.start.copy($i),Gi.start.z=0,Gi.end.copy(Vi),Gi.end.z=0;const I=Gi.closestPointToPointParameter(MT,!0);Gi.at(I,kB);const N=G7.lerp($i.z,Vi.z,I),D=N>=-1&&N<=1,F=MT.distanceTo(kB)<.5*nh;if(D&&F){Gi.start.fromBufferAttribute(E,P),Gi.end.fromBufferAttribute(S,P),Gi.start.applyMatrix4(v),Gi.end.applyMatrix4(v);const L=new De,q=new De;Ko.distanceSqToSegment(Gi.start,Gi.end,q,L),m.push({point:q,pointOnLine:L,distance:Ko.origin.distanceTo(q),object:f,face:null,faceIndex:P,uv:null,uv1:null})}}})(this,i,n)))}}class kwe extends PS{constructor(e,n,r,i,s=4473924,a=8947848){s=new $t(s),a=new $t(a);const o=Math.round(e/n);r=Math.round(r/i)*i/2;const l=[],u=[];let d=0;for(let g=-1*(e=o*n/2);g<=e;g+=n){l.push(g,0,-1*r,g,0,r);const m=g===0?s:a;m.toArray(u,d),d+=3,m.toArray(u,d),d+=3,m.toArray(u,d),d+=3,m.toArray(u,d),d+=3}for(let g=-1*r;g<=r;g+=i){l.push(-1*e,0,g,e,0,g);const m=g===0?s:a;m.toArray(u,d),d+=3,m.toArray(u,d),d+=3,m.toArray(u,d),d+=3,m.toArray(u,d),d+=3}const f=new fs;f.setAttribute("position",new Lr(l,3)),f.setAttribute("color",new Lr(u,3)),super(f,new ob({vertexColors:!0,toneMapped:!1}))}}function Pwe(t,e,n,r){const i=(function(a,o,l){a*=.5,o*=.5,l*=.5;const u=new fs,d=[];return d.push(-a,-o,-l,-a,o,-l,-a,o,-l,a,o,-l,a,o,-l,a,-o,-l,a,-o,-l,-a,-o,-l,-a,-o,l,-a,o,l,-a,o,l,a,o,l,a,o,l,a,-o,l,a,-o,l,-a,-o,l,-a,-o,-l,-a,-o,l,-a,o,-l,-a,o,l,a,o,-l,a,o,l,a,-o,-l,a,-o,l),u.setAttribute("position",new Lr(d,3)),u})(t,e,n),s=new PS(i,new owe({color:new $t(r),dashSize:3,gapSize:1}));return s.computeLineDistances(),s}var Ux=function(){var t=0,e=document.createElement("div");function n(d){return e.appendChild(d.dom),d}function r(d){for(var f=0;f=s+1e3&&(o.update(1e3*a/(d-s),100),s=d,a=0,u)){var f=performance.memory;u.update(f.usedJSHeapSize/1048576,f.jsHeapSizeLimit/1048576)}return d},update:function(){i=this.end()},domElement:e,setMode:r}};Ux.Panel=function(t,e,n){var r=1/0,i=0,s=Math.round,a=s(window.devicePixelRatio||1),o=80*a,l=48*a,u=3*a,d=2*a,f=3*a,g=15*a,m=74*a,x=30*a,y=document.createElement("canvas");y.width=o,y.height=l,y.style.cssText="width:80px;height:48px";var v=y.getContext("2d");return v.font="bold "+9*a+"px Helvetica,Arial,sans-serif",v.textBaseline="top",v.fillStyle=n,v.fillRect(0,0,o,l),v.fillStyle=e,v.fillText(t,u,d),v.fillRect(f,g,m,x),v.fillStyle=n,v.globalAlpha=.9,v.fillRect(f,g,m,x),{dom:y,update:function(b,E){r=Math.min(r,b),i=Math.max(i,b),v.fillStyle=n,v.globalAlpha=1,v.fillRect(0,0,o,g),v.fillStyle=e,v.fillText(s(b)+" "+t+" ("+s(r)+"-"+s(i)+")",u,d),v.drawImage(y,f+a,g,m-a,x,f,g,m-a,x),v.fillRect(f+m-a,g,a,x),v.fillStyle=n,v.globalAlpha=.9,v.fillRect(f+m-a,g,a,s((1-b/E)*x))}}};var Rwe=Ux;class RB{constructor(e,n){this.openFolders=[],this.watchedObject=e,this.options=n,this.gui=new _1,this.gui.title("Dev info"),this.setup()}setup(){this.loadOpenFolders(),this.options&&!this.options.renderer||this.setupRedererFolder(),this.options&&!this.options.camera||this.setupCameraFolder(),this.options&&!this.options.parser||this.setupParserFolder(),this.options&&!this.options.buildVolume||this.setupBuildVolumeFolder(),this.options&&!this.options.devHelpers||this.setupDevHelpers()}reset(){this.gui.destroy(),this.gui=new _1,this.gui.title("Dev info"),this.setup()}loadOpenFolders(){this.openFolders=JSON.parse(localStorage.getItem("dev-gui-open")||"{}").open||[]}saveOpenFolders(){this.openFolders=this.gui.foldersRecursive().filter((e=>!e._closed)).map((e=>e._title)),console.log(this.openFolders),localStorage.setItem("dev-gui-open",JSON.stringify({open:this.openFolders}))}setupRedererFolder(){const e=this.gui.addFolder("Render Info");this.openFolders.includes("Render Info")||e.close(),e.onOpenClose((()=>{this.saveOpenFolders()})),e.add(this.watchedObject.renderer.info.render,"triangles").listen(),e.add(this.watchedObject.renderer.info.render,"calls").listen(),e.add(this.watchedObject.renderer.info.render,"lines").listen(),e.add(this.watchedObject.renderer.info.render,"points").listen(),e.add(this.watchedObject.renderer.info.memory,"geometries").listen(),e.add(this.watchedObject.renderer.info.memory,"textures").listen(),e.add(this.watchedObject,"_lastRenderTime").listen()}setupCameraFolder(){const e=this.gui.addFolder("Camera");this.openFolders.includes("Camera")||e.close(),e.onOpenClose((()=>{this.saveOpenFolders()}));const n=e.addFolder("Camera position");n.add(this.watchedObject.camera.position,"x").listen(),n.add(this.watchedObject.camera.position,"y").listen(),n.add(this.watchedObject.camera.position,"z").listen();const r=e.addFolder("Camera rotation");r.add(this.watchedObject.camera.rotation,"x").listen(),r.add(this.watchedObject.camera.rotation,"y").listen(),r.add(this.watchedObject.camera.rotation,"z").listen()}setupParserFolder(){const e=this.gui.addFolder("Parser");this.openFolders.includes("Parser")||e.close(),e.onOpenClose((()=>{this.saveOpenFolders()})),e.add(this.watchedObject.parser,"curZ").listen(),e.add(this.watchedObject.parser,"maxZ").listen(),e.add(this.watchedObject.parser,"tolerance").listen(),e.add(this.watchedObject.parser.layers,"length").name("layers.count").listen(),e.add(this.watchedObject.parser.lines,"length").name("lines.count").listen()}setupBuildVolumeFolder(){const e=this.gui.addFolder("Build Volume");this.openFolders.includes("Build Volume")||e.close(),e.onOpenClose((()=>{this.saveOpenFolders()})),e.add(this.watchedObject.buildVolume,"x").min(0).max(600).listen().onChange((()=>{this.watchedObject.render()})),e.add(this.watchedObject.buildVolume,"y").min(0).max(600).listen().onChange((()=>{this.watchedObject.render()})),e.add(this.watchedObject.buildVolume,"z").min(0).max(600).listen().onChange((()=>{this.watchedObject.render()}))}setupDevHelpers(){const e=this.gui.addFolder("Dev Helpers");this.openFolders.includes("Dev Helpers")||e.close(),e.onOpenClose((()=>{this.saveOpenFolders()})),e.add(this.watchedObject,"_wireframe").listen().onChange((()=>{this.watchedObject.render()})),e.add(this.watchedObject,"render").listen(),e.add(this.watchedObject,"clear").listen()}}class Dwe extends fs{constructor(e=[new De],n=.6,r=.2,i=8){super(),this.type="ExtrusionGeometry",this.parameters={points:e,lineWidth:n,lineHeight:r,radialSegments:i,closed:!1};const s=new De,a=new De,o=new Yt,l=[],u=[],d=[],f=[];function g(m){const[x,y,v]=(function(b){const E=e[b],S=new De,A=new De,T=new De,P=new De;S.copy(E).sub(e[b-1]||E).normalize().add((e[b+1]||E).clone().sub(E).normalize()).normalize();let C=Number.MAX_VALUE;const I=Math.abs(S.x),N=Math.abs(S.y),D=Math.abs(S.z);return I<=C&&(C=I,A.set(1,0,0)),N<=C&&(C=N,A.set(0,1,0)),D<=C&&A.set(0,0,1),P.crossVectors(S,A).normalize(),A.crossVectors(S,P),T.crossVectors(S,A),[E,A,T]})(m);for(let b=0;b<=i;b++){const E=b/i*Math.PI*2,S=Math.sin(E),A=-Math.cos(E);a.x=A*y.x+S*v.x,a.y=A*y.y+S*v.y,a.z=A*y.z+S*v.z,a.normalize(),u.push(a.x,a.y,a.z),s.x=x.x+n*a.x*.5,s.y=x.y+n*a.y*.5,s.z=x.z+r*a.z*.5,l.push(s.x,s.y,s.z)}}(function(){for(let m=0;mthis.animate())),this.controls.update(),this.renderer.render(this.scene,this.camera),(e=this.stats)===null||e===void 0||e.update()}processGCode(e){this.parser.parseGCode(e),this.render()}initScene(){for(;this.scene.children.length>0;)this.scene.remove(this.scene.children[0]);for(;this.disposables.length>0;){const e=this.disposables.pop();e&&e.dispose()}if(this.debug&&this.buildVolume){const e=new pwe(Math.max(this.buildVolume.x/2,this.buildVolume.y/2)+20);this.scene.add(e)}if(this.buildVolume&&this.drawBuildVolume(),this.renderTubes){console.warn("Volumetric rendering is experimental. It may not work as expected or change in the future.");const e=new dwe(13421772,.3*Math.PI),n=new uwe(16777215,Math.PI,void 0,.001);n.position.set(0,500,500),this.scene.add(e),this.scene.add(n)}}createGroup(e){const n=new Ex;return n.name=e,n.quaternion.setFromEuler(new sb(-Math.PI/2,0,0)),this.buildVolume?n.position.set(-this.buildVolume.x/2,0,this.buildVolume.y/2):n.position.set(-100,0,100),n}render(){const e=performance.now();this.group=this.createGroup("allLayers"),this.state=Fx.initial,this.initScene();for(let n=0;n0?e:1)}))}renderFrameLoop(e){return new Promise((n=>{const r=()=>{this.renderLayerIndex>this.layers.length-1?n():(this.renderFrame(e),requestAnimationFrame(r))};r()}))}renderFrame(e){this.group=this.createGroup("layer"+this.renderLayerIndex);for(let n=0;nthis.maxLayerIndex)return;const d=this.layers[e],f={extrusion:[],travel:[],z:this.state.z,height:d.height};for(const g of d.commands)if(g.gcode!="g20"){if(g.gcode.startsWith("t")){this.doRenderExtrusion(f,e),f.extrusion=[];const m=g;this.state.t=m.toolIndex}else if(["g0","g00","g1","g01","g2","g02","g3","g03"].indexOf(g.gcode)>-1){const m=g,x={x:(n=m.params.x)!==null&&n!==void 0?n:this.state.x,y:(r=m.params.y)!==null&&r!==void 0?r:this.state.y,z:(i=m.params.z)!==null&&i!==void 0?i:this.state.z,r:(s=m.params.r)!==null&&s!==void 0?s:this.state.r,e:(a=m.params.e)!==null&&a!==void 0?a:this.state.e,i:(o=m.params.i)!==null&&o!==void 0?o:this.state.i,j:(l=m.params.j)!==null&&l!==void 0?l:this.state.j,t:this.state.t};if(e>=this.minLayerIndex){const y=((u=m.params.e)!==null&&u!==void 0?u:0)>0||this.nonTravelmoves.indexOf(g.gcode)>-1;(x.x!=this.state.x||x.y!=this.state.y||x.z!=this.state.z)&&(y&&this.renderExtrusion||!y&&this.renderTravel)&&(g.gcode=="g2"||g.gcode=="g3"||g.gcode=="g02"||g.gcode=="g03"?this.addArcSegment(f,this.state,x,y,g.gcode=="g2"||g.gcode=="g02"):this.addLineSegment(f,this.state,x,y))}this.state.x=x.x,this.state.y=x.y,this.state.z=x.z,this.beyondFirstMove||(this.beyondFirstMove=!0)}}else this.setInches();this.doRenderExtrusion(f,e)}doRenderExtrusion(e,n){var r,i;if(this.renderExtrusion){let s=this.currentToolColor;if(!this.singleLayerMode&&!this.renderTubes&&!this.disableGradient){const a=.1+.7*n/this.layers.length;s.getHSL(TT),s=new $t().setHSL(TT.h,TT.s,a)}if(n==this.layers.length-1){const a=(r=this._topLayerColor)!==null&&r!==void 0?r:s,o=(i=this._lastSegmentColor)!==null&&i!==void 0?i:a,l=e.extrusion.splice(-3),u=e.extrusion.splice(-3);this.renderTubes?(this.addTubeLine(e.extrusion,a.getHex(),e.height),this.addTubeLine([...u,...l],o.getHex(),e.height)):(this.addLine(e.extrusion,a.getHex()),this.addLine([...u,...l],o.getHex()))}else this.renderTubes?this.addTubeLine(e.extrusion,s.getHex(),e.height):this.addLine(e.extrusion,s.getHex())}this.renderTravel&&this.addLine(e.travel,this._travelColor.getHex())}setInches(){this.beyondFirstMove?console.warn("Switching units after movement is already made is discouraged and is not supported."):this.inches=!0}drawBuildVolume(){if(!this.buildVolume)return;this.scene.add(new kwe(this.buildVolume.x,10,this.buildVolume.y,10));const e=Pwe(this.buildVolume.x,this.buildVolume.z,this.buildVolume.y,8947848);e.position.setY(this.buildVolume.z/2),this.scene.add(e)}clear(){this.resetState(),this.parser=new w1(this.minLayerThreshold)}resetState(){var e;this.startLayer=1,this.endLayer=1/0,this.singleLayerMode=!1,this.beyondFirstMove=!1,this.state=Fx.initial,(e=this.devGui)===null||e===void 0||e.reset(),this._geometries={}}resize(){const[e,n]=[this.canvas.offsetWidth,this.canvas.offsetHeight];this.camera.aspect=e/n,this.camera.updateProjectionMatrix(),this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.setSize(e,n,!1)}addLineSegment(e,n,r,i){(i?e.extrusion:e.travel).push(n.x,n.y,n.z,r.x,r.y,r.z)}addArcSegment(e,n,r,i,s){const a=i?e.extrusion:e.travel,o=n.x,l=n.y,u=n.z,d=r.x,f=r.y,g=r.z;let m=r.r,x=r.i,y=r.j;if(m){const V=d-o,K=f-l,W=Math.sqrt(Math.pow(V/2,2)+Math.pow(K/2,2));m=Math.max(m,W);const ne=Math.pow(V,2)+Math.pow(K,2),Y=Math.pow(m,2)-ne/4;let Z=Math.sqrt(Y/ne);(s&&m<0||!s&&m>0)&&(Z=-Z),x=V/2+K*Z,y=K/2-V*Z}const v=o==d&&l==f,b=o+x,E=l+y,S=Math.sqrt(x*x+y*y),A=Math.atan2(-y,-x),T=Math.atan2(f-E,d-b);let P;v?P=2*Math.PI:(P=s?A-T:T-A,P<0&&(P+=2*Math.PI));let C=S*P/1.8;this.inches&&(C*=25),C<1&&(C=1);let I=P/C;I*=s?-1:1;const N=[];N.push({x:o,y:l,z:u});const D=(u-g)/C;let F=o,L=l,q=u,R=A;for(let V=0;V0)return void this.addThickLine(e,n);const i=new fs;i.setAttribute("position",new Lr(e,3)),this.disposables.push(i);const s=new ob({color:n});this.disposables.push(s);const a=new PS(i,s);(r=this.group)===null||r===void 0||r.add(a)}addTubeLine(e,n,r=.2){let i=[];const s=[];for(let a=0;a{var o;const l=new Dwe(a,this.extrusionWidth,this.lineHeight||r,4);(o=this._geometries)[n]||(o[n]=[]),this._geometries[n].push(l)}))}addThickLine(e,n){var r;if(!e.length||!this.lineWidth)return;const i=new fW;this.disposables.push(i);const s=new hW({color:n,linewidth:this.lineWidth/(1e3*window.devicePixelRatio)});this.disposables.push(s),i.setPositions(e);const a=new Nwe(i,s);(r=this.group)===null||r===void 0||r.add(a)}dispose(){this.disposables.forEach((e=>e.dispose())),this.disposables=[],this.controls.dispose(),this.renderer.dispose(),this.cancelAnimation()}cancelAnimation(){this.animationFrameId!==void 0&&cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0}_enableDropHandler(){console.warn("Drag and drop is deprecated as a library feature. See the demo how to implement your own."),this.canvas.addEventListener("dragover",(e=>{e.stopPropagation(),e.preventDefault(),e.dataTransfer&&(e.dataTransfer.dropEffect="copy"),this.canvas.classList.add("dragging")})),this.canvas.addEventListener("dragleave",(e=>{e.stopPropagation(),e.preventDefault(),this.canvas.classList.remove("dragging")})),this.canvas.addEventListener("drop",(e=>ST(this,void 0,void 0,(function*(){var n,r;e.stopPropagation(),e.preventDefault(),this.canvas.classList.remove("dragging");const i=((r=(n=e.dataTransfer)===null||n===void 0?void 0:n.files)!==null&&r!==void 0?r:[])[0];this.clear(),yield this._readFromStream(i.stream()),this.render()}))))}batchGeometries(){if(this._geometries)for(const e in this._geometries){const n=this.createBatchMesh(parseInt(e));for(;this._geometries[e].length>0;){const r=this._geometries[e].pop();n.addGeometry(r)}}}createBatchMesh(e){var n;const r=this._geometries[e],i=new awe({color:e,wireframe:this._wireframe});this.disposables.push(i);const s=r.reduce(((o,l)=>3*l.attributes.position.count+o),0),a=new rwe(r.length,s,void 0,i);return this.disposables.push(a),(n=this.group)===null||n===void 0||n.add(a),a}_readFromStream(e){var n,r;return ST(this,void 0,void 0,(function*(){const i=e.getReader();let s,a="",o=0;do{console.debug("reading from stream"),s=yield i.read(),o+=(r=(n=s.value)===null||n===void 0?void 0:n.length)!==null&&r!==void 0?r:0;const u=(l=s.value,new TextDecoder("utf-8").decode(l)),d=u.lastIndexOf(` -`),f=u.slice(0,d);this.parser.parseGCode(a+f),a=u.slice(d)}while(!s.done);var l;console.debug("read from stream",o)}))}initGui(){typeof this.devMode=="boolean"&&this.devMode===!0?this.devGui=new RB(this):typeof this.devMode=="object"&&(this.devGui=new RB(this,this.devMode))}initStats(){var e;this.stats&&(typeof this.devMode=="object"&&(this.statsContainer=this.devMode.statsContainer),((e=this.statsContainer)!==null&&e!==void 0?e:document.body).appendChild(this.stats.dom),this.stats.dom.classList.add("stats"),this.initGui())}}Xp.defaultExtrusionColor=new $t("hotpink");const Owe=function(t){return new Xp(t)};function jwe({gcodeUrl:t,buildVolume:e={x:256,y:256,z:256},className:n=""}){const r=M.useRef(null),i=M.useRef(null),[s,a]=M.useState(!0),[o,l]=M.useState(null),[u,d]=M.useState(!1),[f,g]=M.useState(0),[m,x]=M.useState(0);M.useEffect(()=>{if(!r.current)return;const b=r.current,E=Owe({canvas:b,buildVolume:e,backgroundColor:1710618,travelColor:4473924,extrusionColor:44610,topLayerColor:65370,lastSegmentColor:16777215,lineWidth:2,renderTravel:!1,renderExtrusion:!0});i.current=E,a(!0),l(null),d(!1),fetch(t).then(async A=>{if(!A.ok)throw A.status===404&&(await A.json().catch(()=>({}))).detail?.includes("sliced")?(d(!0),new Error("not_sliced")):new Error("Failed to load G-code");return A.text()}).then(A=>{E.processGCode(A);const T=E.layers?.length||0;x(T),g(T),E.render(),a(!1)}).catch(A=>{l(A.message),a(!1)});const S=()=>{if(b.parentElement){const A=b.parentElement.getBoundingClientRect();b.width=A.width,b.height=A.height,E.resize()}};return S(),window.addEventListener("resize",S),()=>{window.removeEventListener("resize",S),E.dispose()}},[t,e]);const y=b=>{if(!i.current)return;const E=Math.max(1,Math.min(b,m));g(E),i.current.render()},v=b=>{y(parseInt(b.target.value,10))};return c.jsxs("div",{className:`relative flex flex-col h-full ${n}`,children:[c.jsxs("div",{className:"flex-1 relative bg-bambu-dark rounded-lg overflow-hidden",children:[c.jsx("canvas",{ref:r,className:"w-full h-full"}),s&&c.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-bambu-dark/80",children:c.jsxs("div",{className:"text-center",children:[c.jsx(At,{className:"w-8 h-8 animate-spin text-bambu-green mx-auto mb-2"}),c.jsx("p",{className:"text-bambu-gray text-sm",children:"Loading G-code..."})]})}),u&&c.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-bambu-dark/80",children:c.jsxs("div",{className:"text-center max-w-sm px-4",children:[c.jsx(yoe,{className:"w-12 h-12 text-bambu-gray mx-auto mb-3"}),c.jsx("p",{className:"text-white font-medium mb-2",children:"G-code not available"}),c.jsx("p",{className:"text-bambu-gray text-sm",children:"This file hasn't been sliced yet. G-code preview is only available after slicing the model in Bambu Studio or Orca Slicer."})]})}),o&&!u&&c.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-bambu-dark/80",children:c.jsx("div",{className:"text-center text-red-400",children:c.jsx("p",{className:"text-sm",children:o})})})]}),!s&&!o&&!u&&m>0&&c.jsx("div",{className:"mt-4 px-2",children:c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx(Oh,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}),c.jsx("button",{onClick:()=>y(f-1),disabled:f<=1,className:"p-1 rounded hover:bg-bambu-dark-tertiary disabled:opacity-30 disabled:cursor-not-allowed",children:c.jsx(Rh,{className:"w-4 h-4"})}),c.jsx("input",{type:"range",min:1,max:m,value:f,onChange:v,className:"flex-1 h-2 bg-bambu-dark-tertiary rounded-lg appearance-none cursor-pointer accent-bambu-green"}),c.jsx("button",{onClick:()=>y(f+1),disabled:f>=m,className:"p-1 rounded hover:bg-bambu-dark-tertiary disabled:opacity-30 disabled:cursor-not-allowed",children:c.jsx(tf,{className:"w-4 h-4"})}),c.jsxs("span",{className:"text-sm text-bambu-gray min-w-[80px] text-right",children:[f," / ",m]})]})})]})}function Lwe({archiveId:t,title:e,onClose:n}){const[r,i]=M.useState(null),[s,a]=M.useState(null),[o,l]=M.useState(!0);M.useEffect(()=>{const d=f=>{f.key==="Escape"&&n()};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[n]),M.useEffect(()=>{Pe.getArchiveCapabilities(t).then(d=>{a(d),d.has_model?i("3d"):d.has_gcode&&i("gcode"),l(!1)}).catch(()=>{a({has_model:!0,has_gcode:!1,build_volume:{x:256,y:256,z:256}}),i("3d"),l(!1)})},[t]);const u=()=>{const d=e||"model",f=`${window.location.origin}${Pe.getArchiveForSlicer(t,d)}`;window.location.href=`bambustudioopen://${encodeURIComponent(f)}`};return c.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-8",onClick:n,children:c.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-4xl h-[80vh] flex flex-col",onClick:d=>d.stopPropagation(),children:[c.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[c.jsx("h2",{className:"text-lg font-semibold text-white truncate flex-1 mr-4",children:e}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs(Ie,{variant:"secondary",size:"sm",onClick:u,children:[c.jsx(ro,{className:"w-4 h-4"}),"Open in Slicer"]}),c.jsx(Ie,{variant:"ghost",size:"sm",onClick:n,children:c.jsx(Gt,{className:"w-5 h-5"})})]})]}),s&&c.jsxs("div",{className:"flex border-b border-bambu-dark-tertiary",children:[c.jsxs("button",{onClick:()=>s.has_model&&i("3d"),disabled:!s.has_model,className:`flex items-center gap-2 px-6 py-3 text-sm font-medium transition-colors ${r==="3d"?"text-bambu-green border-b-2 border-bambu-green":s.has_model?"text-bambu-gray hover:text-white":"text-bambu-gray/30 cursor-not-allowed"}`,children:[c.jsx(rm,{className:"w-4 h-4"}),"3D Model",!s.has_model&&c.jsx("span",{className:"text-xs",children:"(not available)"})]}),c.jsxs("button",{onClick:()=>s.has_gcode&&i("gcode"),disabled:!s.has_gcode,className:`flex items-center gap-2 px-6 py-3 text-sm font-medium transition-colors ${r==="gcode"?"text-bambu-green border-b-2 border-bambu-green":s.has_gcode?"text-bambu-gray hover:text-white":"text-bambu-gray/30 cursor-not-allowed"}`,children:[c.jsx(Kae,{className:"w-4 h-4"}),"G-code Preview",!s.has_gcode&&c.jsx("span",{className:"text-xs",children:"(not sliced)"})]})]}),c.jsx("div",{className:"flex-1 overflow-hidden p-4",children:o?c.jsx("div",{className:"w-full h-full flex items-center justify-center",children:c.jsx(At,{className:"w-8 h-8 animate-spin text-bambu-green"})}):r==="3d"&&s?c.jsx(Pxe,{url:Pe.getArchiveDownload(t),buildVolume:s.build_volume,className:"w-full h-full"}):r==="gcode"&&s?c.jsx(jwe,{gcodeUrl:Pe.getArchiveGcode(t),buildVolume:s.build_volume,className:"w-full h-full"}):c.jsx("div",{className:"w-full h-full flex items-center justify-center text-bambu-gray",children:"No preview available for this file"})})]})})}function Iwe({archiveId:t,archiveName:e,onClose:n,onSuccess:r}){const[i,s]=M.useState(null);M.useEffect(()=>{const d=f=>{f.key==="Escape"&&n()};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[n]);const{data:a,isLoading:o}=yt({queryKey:["printers"],queryFn:Pe.getPrinters}),l=_t({mutationFn:()=>{if(!i)throw new Error("No printer selected");return Pe.reprintArchive(t,i)},onSuccess:()=>{r(),n()}}),u=a?.filter(d=>d.is_active)||[];return c.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-8",children:c.jsx(Nt,{className:"w-full max-w-md",children:c.jsxs(Dt,{children:[c.jsxs("div",{className:"flex items-center justify-between mb-4",children:[c.jsx("h2",{className:"text-lg font-semibold text-white",children:"Re-print"}),c.jsx(Ie,{variant:"ghost",size:"sm",onClick:n,children:c.jsx(Gt,{className:"w-5 h-5"})})]}),c.jsxs("p",{className:"text-sm text-bambu-gray mb-4",children:["Send ",c.jsx("span",{className:"text-white",children:e})," to a printer"]}),o?c.jsx("div",{className:"flex justify-center py-8",children:c.jsx(At,{className:"w-6 h-6 text-bambu-green animate-spin"})}):u.length===0?c.jsx("div",{className:"text-center py-8 text-bambu-gray",children:"No active printers available"}):c.jsx("div",{className:"space-y-2 mb-6",children:u.map(d=>c.jsxs("button",{onClick:()=>s(d.id),className:`w-full flex items-center gap-3 p-3 rounded-lg border transition-colors ${i===d.id?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray"}`,children:[c.jsx("div",{className:`p-2 rounded-lg ${i===d.id?"bg-bambu-green/20":"bg-bambu-dark-tertiary"}`,children:c.jsx(jo,{className:`w-5 h-5 ${i===d.id?"text-bambu-green":"text-bambu-gray"}`})}),c.jsxs("div",{className:"text-left",children:[c.jsx("p",{className:"text-white font-medium",children:d.name}),c.jsxs("p",{className:"text-xs text-bambu-gray",children:[d.model||"Unknown model"," • ",d.ip_address]})]})]},d.id))}),l.isError&&c.jsx("div",{className:"mb-4 p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:l.error.message||"Failed to start print"}),c.jsxs("div",{className:"flex gap-3",children:[c.jsx(Ie,{variant:"secondary",onClick:n,className:"flex-1",children:"Cancel"}),c.jsx(Ie,{onClick:()=>l.mutate(),disabled:!i||l.isPending,className:"flex-1",children:l.isPending?c.jsxs(c.Fragment,{children:[c.jsx(At,{className:"w-4 h-4 animate-spin"}),"Sending..."]}):c.jsxs(c.Fragment,{children:[c.jsx(jo,{className:"w-4 h-4"}),"Print"]})})]})]})})})}function Uwe({onClose:t,initialFiles:e}){const n=Sn(),{showToast:r}=ri(),i=M.useRef(null),[s,a]=M.useState(()=>e?.filter(C=>C.name.endsWith(".3mf")).map(C=>({file:C,status:"pending"}))||[]),[o,l]=M.useState(!1),[u,d]=M.useState(),[f,g]=M.useState(null);M.useEffect(()=>{const C=I=>{I.key==="Escape"&&t()};return window.addEventListener("keydown",C),()=>window.removeEventListener("keydown",C)},[t]);const{data:m}=yt({queryKey:["printers"],queryFn:Pe.getPrinters}),x=_t({mutationFn:C=>Pe.uploadArchivesBulk(C,u),onSuccess:C=>{g(C),n.invalidateQueries({queryKey:["archives"]}),n.invalidateQueries({queryKey:["archiveStats"]}),a(I=>I.map(N=>{const D=C.results.find(L=>L.filename===N.file.name),F=C.errors.find(L=>L.filename===N.file.name);return D?{...N,status:"success",archiveId:D.id}:F?{...N,status:"error",error:F.error}:N})),C.failed===0?r(`${C.uploaded} file${C.uploaded!==1?"s":""} uploaded`):C.uploaded===0?r(`Failed to upload ${C.failed} file${C.failed!==1?"s":""}`,"error"):r(`${C.uploaded} uploaded, ${C.failed} failed`,"warning")},onError:()=>{a(C=>C.map(I=>({...I,status:"error",error:"Upload failed"}))),r("Upload failed","error")}}),y=M.useCallback(C=>{C.preventDefault(),l(!0)},[]),v=M.useCallback(C=>{C.preventDefault(),l(!1)},[]),b=M.useCallback(C=>{C.preventDefault(),l(!1);const I=Array.from(C.dataTransfer.files).filter(N=>N.name.endsWith(".3mf"));I.length>0&&a(N=>[...N,...I.map(D=>({file:D,status:"pending"}))])},[]),E=M.useCallback(C=>{const I=Array.from(C.target.files||[]).filter(N=>N.name.endsWith(".3mf"));I.length>0&&a(N=>[...N,...I.map(D=>({file:D,status:"pending"}))]),i.current&&(i.current.value="")},[]),S=M.useCallback(C=>{a(I=>I.filter((N,D)=>D!==C))},[]),A=()=>{if(s.length===0)return;const C=s.filter(I=>I.status==="pending");C.length!==0&&(a(I=>I.map(N=>N.status==="pending"?{...N,status:"uploading"}:N)),x.mutate(C.map(I=>I.file)))},T=s.filter(C=>C.status==="pending").length,P=x.isPending;return c.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:c.jsx(Nt,{className:"w-full max-w-2xl max-h-[90vh] flex flex-col",children:c.jsxs(Dt,{className:"p-0 flex flex-col h-full",children:[c.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[c.jsx("h2",{className:"text-xl font-semibold text-white",children:"Upload 3MF Files"}),c.jsx("button",{onClick:t,className:"text-bambu-gray hover:text-white transition-colors",children:c.jsx(Gt,{className:"w-5 h-5"})})]}),c.jsx("div",{className:"p-4",children:c.jsxs("div",{className:`border-2 border-dashed rounded-lg p-8 text-center transition-colors ${o?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-gray"}`,onDragOver:y,onDragLeave:v,onDrop:b,children:[c.jsx(ma,{className:"w-12 h-12 mx-auto mb-4 text-bambu-gray"}),c.jsx("p",{className:"text-white mb-2",children:"Drag & drop .3mf files here"}),c.jsx("p",{className:"text-bambu-gray text-sm mb-4",children:"or"}),c.jsx(Ie,{variant:"secondary",onClick:()=>i.current?.click(),disabled:P,children:"Browse Files"}),c.jsx("input",{ref:i,type:"file",accept:".3mf",multiple:!0,className:"hidden",onChange:E})]})}),c.jsxs("div",{className:"px-4 pb-4",children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:"Associate with printer (optional)"}),c.jsxs("select",{className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:u||"",onChange:C=>d(C.target.value?Number(C.target.value):void 0),disabled:P,children:[c.jsx("option",{value:"",children:"No printer"}),m?.map(C=>c.jsx("option",{value:C.id,children:C.name},C.id))]})]}),s.length>0&&c.jsx("div",{className:"px-4 pb-4 max-h-60 overflow-y-auto",children:c.jsx("div",{className:"space-y-2",children:s.map((C,I)=>c.jsxs("div",{className:"flex items-center gap-3 p-3 bg-bambu-dark rounded-lg",children:[c.jsx(kG,{className:"w-5 h-5 text-bambu-gray flex-shrink-0"}),c.jsx("span",{className:"flex-1 text-white text-sm truncate",children:C.file.name}),c.jsxs("span",{className:"text-xs text-bambu-gray",children:[(C.file.size/(1024*1024)).toFixed(1)," MB"]}),C.status==="pending"&&c.jsx("button",{onClick:()=>S(I),className:"text-bambu-gray hover:text-red-400 transition-colors",disabled:P,children:c.jsx(Gt,{className:"w-4 h-4"})}),C.status==="uploading"&&c.jsx(At,{className:"w-4 h-4 text-bambu-green animate-spin"}),C.status==="success"&&c.jsx(ds,{className:"w-4 h-4 text-bambu-green"}),C.status==="error"&&c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"text-xs text-red-400",children:C.error}),c.jsx(Oo,{className:"w-4 h-4 text-red-400"})]})]},`${C.file.name}-${I}`))})}),f&&c.jsx("div",{className:"px-4 pb-4",children:c.jsx("div",{className:"p-3 bg-bambu-dark rounded-lg",children:c.jsxs("p",{className:"text-sm text-white",children:[c.jsx("span",{className:"text-bambu-green",children:f.uploaded})," uploaded",f.failed>0&&c.jsxs(c.Fragment,{children:[", ",c.jsx("span",{className:"text-red-400",children:f.failed})," failed"]})]})})}),c.jsxs("div",{className:"flex gap-3 p-4 border-t border-bambu-dark-tertiary",children:[c.jsx(Ie,{variant:"secondary",onClick:t,className:"flex-1",children:f?"Close":"Cancel"}),!f&&c.jsx(Ie,{onClick:A,disabled:T===0||P,className:"flex-1",children:P?c.jsxs(c.Fragment,{children:[c.jsx(At,{className:"w-4 h-4 animate-spin"}),"Uploading..."]}):c.jsxs(c.Fragment,{children:[c.jsx(ma,{className:"w-4 h-4"}),"Upload ",T>0&&`(${T})`]})})]})]})})})}const Fwe=["Adhesion failure","Spaghetti / Detached","Layer shift","Clogged nozzle","Filament runout","Warping","Stringing","Under-extrusion","Power failure","User cancelled","Other"];function zwe({archive:t,onClose:e,existingTags:n=[]}){M.useEffect(()=>{const U=$=>{$.key==="Escape"&&e()};return window.addEventListener("keydown",U),()=>window.removeEventListener("keydown",U)},[e]);const r=Sn(),[i,s]=M.useState(t.print_name||""),[a,o]=M.useState(t.printer_id),[l,u]=M.useState(t.project_id??null),[d,f]=M.useState(t.notes||""),[g,m]=M.useState(t.tags||""),[x,y]=M.useState(t.failure_reason||""),[v,b]=M.useState(t.photos||[]),[E,S]=M.useState(!1),[A,T]=M.useState(!1),P=M.useRef(null),C=M.useRef(null),I=M.useRef(null),{data:N}=yt({queryKey:["printers"],queryFn:Pe.getPrinters}),{data:D}=yt({queryKey:["projects"],queryFn:()=>Pe.getProjects()}),{data:F}=yt({queryKey:["archives"],queryFn:()=>Pe.getArchives(void 0,1e3,0),enabled:n.length===0}),L=n.length>0?n:[...new Set(F?.flatMap(U=>U.tags?.split(",").map($=>$.trim())||[]).filter(Boolean)||[])].sort(),q=g.split(",").map(U=>U.trim()).filter(Boolean),R=L.filter(U=>!q.includes(U)),V=U=>{if(!q.includes(U)){const $=[...q,U].join(", ");m($)}I.current!==null&&clearTimeout(I.current),P.current?.focus()},K=U=>{const $=q.filter(ee=>ee!==U).join(", ");m($)},W=_t({mutationFn:U=>Pe.updateArchive(t.id,U),onSuccess:()=>{r.invalidateQueries({queryKey:["archives"]}),r.invalidateQueries({queryKey:["projects"]}),e()}}),ne=async U=>{const $=U.target.files?.[0];if($){S(!0);try{const ee=await Pe.uploadArchivePhoto(t.id,$);b(ee.photos),r.invalidateQueries({queryKey:["archives"]})}catch(ee){console.error("Failed to upload photo:",ee)}finally{S(!1),C.current&&(C.current.value="")}}},Y=async U=>{try{const $=await Pe.deleteArchivePhoto(t.id,U);b($.photos||[]),r.invalidateQueries({queryKey:["archives"]})}catch($){console.error("Failed to delete photo:",$)}},Z=U=>{U.preventDefault(),W.mutate({print_name:i||void 0,printer_id:a,project_id:l,notes:d||void 0,tags:g||void 0,failure_reason:t.status==="failed"&&x||void 0})};return c.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:e,children:c.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-md max-h-[90vh] flex flex-col",onClick:U=>U.stopPropagation(),children:[c.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[c.jsx("h2",{className:"text-lg font-semibold text-white",children:"Edit Archive"}),c.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:c.jsx(Gt,{className:"w-5 h-5"})})]}),c.jsxs("form",{onSubmit:Z,className:"p-6 space-y-4 overflow-y-auto flex-1",children:[c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name"}),c.jsx("input",{type:"text",value:i,onChange:U=>s(U.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",placeholder:"Print name"})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Printer"}),c.jsxs("select",{value:a??"",onChange:U=>o(U.target.value?Number(U.target.value):null),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[c.jsx("option",{value:"",children:"No printer"}),N?.map(U=>c.jsx("option",{value:U.id,children:U.name},U.id))]})]}),c.jsxs("div",{children:[c.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[c.jsx(ph,{className:"w-4 h-4 inline mr-1"}),"Project"]}),c.jsxs("select",{value:l??"",onChange:U=>u(U.target.value?Number(U.target.value):null),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[c.jsx("option",{value:"",children:"No project"}),D?.map(U=>c.jsx("option",{value:U.id,children:U.name},U.id))]})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Notes"}),c.jsx("textarea",{value:d,onChange:U=>f(U.target.value),rows:3,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none resize-none",placeholder:"Add notes about this print..."})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Tags"}),q.length>0&&c.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:q.map(U=>c.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 bg-bambu-dark-tertiary rounded text-sm text-white",children:[c.jsx(f0,{className:"w-3 h-3"}),U,c.jsx("button",{type:"button",onClick:()=>K(U),className:"ml-0.5 text-bambu-gray hover:text-white",children:c.jsx(Gt,{className:"w-3 h-3"})})]},U))}),c.jsxs("div",{className:"relative",children:[c.jsx("input",{ref:P,type:"text",value:g,onChange:U=>m(U.target.value),onFocus:()=>{I.current!==null&&clearTimeout(I.current),T(!0)},onBlur:()=>{I.current=window.setTimeout(()=>T(!1),200)},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",placeholder:q.length>0?"Add more tags...":"Add tags..."}),A&&R.length>0&&c.jsxs("div",{className:"absolute top-full left-0 right-0 mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg z-10 max-h-40 overflow-y-auto",children:[c.jsx("div",{className:"p-2 text-xs text-bambu-gray border-b border-bambu-dark-tertiary",children:"Existing tags (click to add)"}),c.jsx("div",{className:"p-2 flex flex-wrap gap-1.5",children:R.map(U=>c.jsx("button",{type:"button",onClick:()=>V(U),className:"px-2 py-0.5 bg-bambu-dark-tertiary hover:bg-bambu-green/20 rounded text-sm text-bambu-gray hover:text-white transition-colors",children:U},U))})]})]})]}),t.status==="failed"&&c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Failure Reason"}),c.jsxs("select",{value:x,onChange:U=>y(U.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[c.jsx("option",{value:"",children:"Select reason..."}),Fwe.map(U=>c.jsx("option",{value:U,children:U},U))]})]}),c.jsxs("div",{children:[c.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[c.jsx(a0,{className:"w-4 h-4 inline mr-1"}),"Photos of Printed Result"]}),c.jsxs("div",{className:"flex flex-wrap gap-2 mb-2",children:[v.map(U=>c.jsxs("div",{className:"relative group",children:[c.jsx("img",{src:Pe.getArchivePhotoUrl(t.id,U),alt:"Print result",className:"w-20 h-20 object-cover rounded-lg border border-bambu-dark-tertiary"}),c.jsx("button",{type:"button",onClick:()=>Y(U),className:"absolute -top-1 -right-1 p-1 bg-red-500 rounded-full opacity-0 group-hover:opacity-100 transition-opacity",children:c.jsx(kn,{className:"w-3 h-3 text-white"})})]},U)),c.jsxs("label",{className:"w-20 h-20 flex items-center justify-center border-2 border-dashed border-bambu-dark-tertiary rounded-lg cursor-pointer hover:border-bambu-green transition-colors",children:[c.jsx("input",{ref:C,type:"file",accept:"image/jpeg,image/png,image/webp",onChange:ne,className:"hidden",disabled:E}),E?c.jsx(At,{className:"w-6 h-6 text-bambu-gray animate-spin"}):c.jsx(fr,{className:"w-6 h-6 text-bambu-gray"})]})]}),c.jsx("p",{className:"text-xs text-bambu-gray",children:"Click + to add photos of your printed result"})]}),c.jsxs("div",{className:"flex gap-3 pt-2",children:[c.jsx(Ie,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:"Cancel"}),c.jsxs(Ie,{type:"submit",disabled:W.isPending,className:"flex-1",children:[c.jsx(To,{className:"w-4 h-4"}),W.isPending?"Saving...":"Save"]})]})]})]})})}function Bwe({x:t,y:e,items:n,onClose:r}){const i=M.useRef(null),[s,a]=M.useState(null),o=M.useRef(null);M.useEffect(()=>{const d=m=>{i.current&&!i.current.contains(m.target)&&r()},f=m=>{m.key==="Escape"&&r()},g=()=>{r()};return document.addEventListener("mousedown",d),document.addEventListener("keydown",f),document.addEventListener("scroll",g,!0),()=>{document.removeEventListener("mousedown",d),document.removeEventListener("keydown",f),document.removeEventListener("scroll",g,!0),o.current&&clearTimeout(o.current)}},[r]),M.useEffect(()=>{if(i.current){const d=i.current.getBoundingClientRect(),f=window.innerWidth,g=window.innerHeight;let m=t,x=e;t+d.width>f&&(m=f-d.width-8),e+d.height>g&&(x=g-d.height-8),i.current.style.left=`${m}px`,i.current.style.top=`${x}px`}},[t,e]);const l=d=>{o.current&&(clearTimeout(o.current),o.current=null),a(d)},u=()=>{o.current=window.setTimeout(()=>{a(null)},150)};return c.jsx("div",{ref:i,className:"fixed z-50 min-w-[180px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1",style:{left:t,top:e},children:n.map((d,f)=>{if(d.divider)return c.jsx("div",{className:"my-1 border-t border-bambu-dark-tertiary"},f);const g=d.submenu&&d.submenu.length>0;return c.jsxs("div",{className:"relative",onMouseEnter:()=>g&&l(f),onMouseLeave:()=>g&&u(),children:[c.jsxs("button",{onClick:()=>{g?a(s===f?null:f):d.disabled||(d.onClick(),r())},disabled:d.disabled,className:`w-full flex items-center gap-2 px-3 py-2 text-sm text-left transition-colors ${d.disabled?"text-bambu-gray cursor-not-allowed":d.danger?"text-red-400 hover:bg-red-400/10":"text-white hover:bg-bambu-dark-tertiary"} ${g&&s===f?"bg-bambu-dark-tertiary":""}`,children:[d.icon&&c.jsx("span",{className:"w-4 h-4 flex-shrink-0 flex items-center justify-center",children:d.icon}),c.jsx("span",{className:"flex-1",children:d.label}),g&&c.jsx(tf,{className:"w-4 h-4 text-bambu-gray"})]}),g&&s===f&&c.jsx("div",{className:"absolute left-full top-0 ml-1 min-w-[160px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 overflow-hidden max-h-[300px] overflow-y-auto z-[60]",onMouseEnter:()=>{o.current&&(clearTimeout(o.current),o.current=null)},onMouseLeave:()=>u(),children:d.submenu.map((m,x)=>c.jsxs("button",{onClick:()=>{m.disabled||(m.onClick(),r())},disabled:m.disabled,className:`w-full flex items-center gap-2 px-3 py-2 text-sm text-left transition-colors ${m.disabled?"text-bambu-gray cursor-not-allowed":m.danger?"text-red-400 hover:bg-red-400/10":"text-white hover:bg-bambu-dark-tertiary"}`,children:[m.icon&&c.jsx("span",{className:"w-4 h-4 flex-shrink-0 flex items-center justify-center",children:m.icon}),m.label]},x))})]},f)})})}function Hwe({selectedIds:t,existingTags:e,onClose:n}){const r=Sn(),{showToast:i}=ri(),[s,a]=M.useState(""),[o,l]=M.useState(new Set),[u,d]=M.useState("add");M.useEffect(()=>{const y=v=>{v.key==="Escape"&&n()};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[n]);const f=_t({mutationFn:async()=>{const y=Array.from(o);let v=0;for(const b of t)try{const E=await Pe.getArchive(b),S=E.tags?E.tags.split(",").map(T=>T.trim()).filter(Boolean):[];let A;u==="add"?A=[...new Set([...S,...y])]:A=S.filter(T=>!o.has(T)),await Pe.updateArchive(b,{tags:A.join(", ")}),v++}catch(E){throw console.error(`Failed to update archive ${b}:`,E),new Error(`Failed on archive ${b}: ${E instanceof Error?E.message:"Unknown error"}`)}return{count:v,mode:u,tags:y}},onSuccess:({count:y,mode:v,tags:b})=>{r.invalidateQueries({queryKey:["archives"]}),i(`${v==="add"?"Added":"Removed"} ${b.length} tag${b.length!==1?"s":""} ${v==="add"?"to":"from"} ${y} archive${y!==1?"s":""}`),n()},onError:y=>{i(y.message||"Failed to update tags","error")}}),g=y=>{l(v=>{const b=new Set(v);return b.has(y)?b.delete(y):b.add(y),b})},m=()=>{s.trim()&&!o.has(s.trim())&&(l(y=>new Set([...y,s.trim()])),a(""))},x=y=>{y.key==="Enter"&&(y.preventDefault(),m())};return c.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:c.jsx(Nt,{className:"w-full max-w-md",children:c.jsxs(Dt,{className:"p-0",children:[c.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(f0,{className:"w-5 h-5 text-bambu-green"}),c.jsx("h2",{className:"text-xl font-semibold text-white",children:u==="add"?"Add Tags":"Remove Tags"})]}),c.jsx("button",{onClick:n,className:"text-bambu-gray hover:text-white transition-colors",children:c.jsx(Gt,{className:"w-5 h-5"})})]}),c.jsxs("div",{className:"p-4 space-y-4",children:[c.jsxs("p",{className:"text-sm text-bambu-gray",children:[u==="add"?"Add":"Remove"," tags for ",t.length," selected archive",t.length!==1?"s":""]}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(Ie,{size:"sm",variant:u==="add"?"primary":"secondary",onClick:()=>d("add"),children:"Add Tags"}),c.jsx(Ie,{size:"sm",variant:u==="remove"?"primary":"secondary",onClick:()=>d("remove"),children:"Remove Tags"})]}),u==="add"&&c.jsxs("div",{className:"flex gap-2",children:[c.jsx("input",{type:"text",placeholder:"Enter new tag...",className:"flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none",value:s,onChange:y=>a(y.target.value),onKeyDown:x}),c.jsx(Ie,{size:"sm",variant:"secondary",onClick:m,disabled:!s.trim(),children:c.jsx(fr,{className:"w-4 h-4"})})]}),e.length>0&&c.jsxs("div",{children:[c.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:"Existing tags:"}),c.jsx("div",{className:"flex flex-wrap gap-2",children:e.map(y=>c.jsx("button",{onClick:()=>g(y),className:`px-2 py-1 rounded text-sm transition-colors ${o.has(y)?"bg-bambu-green text-white":"bg-bambu-dark-tertiary text-bambu-gray-light hover:bg-bambu-dark"}`,children:y},y))})]}),o.size>0&&c.jsxs("div",{children:[c.jsxs("p",{className:"text-xs text-bambu-gray mb-2",children:["Tags to ",u==="add"?"add":"remove",":"]}),c.jsx("div",{className:"flex flex-wrap gap-2",children:Array.from(o).map(y=>c.jsxs("span",{className:`px-2 py-1 rounded text-sm flex items-center gap-1 ${u==="add"?"bg-green-500/20 text-green-400":"bg-red-500/20 text-red-400"}`,children:[y,c.jsx("button",{onClick:()=>g(y),className:"hover:opacity-70",children:c.jsx(Gt,{className:"w-3 h-3"})})]},y))})]})]}),c.jsxs("div",{className:"flex gap-3 p-4 border-t border-bambu-dark-tertiary",children:[c.jsx(Ie,{variant:"secondary",onClick:n,className:"flex-1",children:"Cancel"}),c.jsx(Ie,{onClick:()=>f.mutate(),disabled:o.size===0||f.isPending,className:"flex-1",children:f.isPending?c.jsxs(c.Fragment,{children:[c.jsx(At,{className:"w-4 h-4 animate-spin"}),"Processing..."]}):c.jsxs(c.Fragment,{children:[c.jsx(f0,{className:"w-4 h-4"}),u==="add"?"Add Tags":"Remove Tags"]})})]})]})})})}function $we(t,e){return new Date(t,e+1,0).getDate()}function Vwe(t,e){return new Date(t,e,1).getDay()}const Gwe=["January","February","March","April","May","June","July","August","September","October","November","December"],Wwe=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];function qwe({archives:t,onArchiveClick:e}){const n=new Date,[r,i]=M.useState(n.getMonth()),[s,a]=M.useState(n.getFullYear()),[o,l]=M.useState(null),u=M.useMemo(()=>{const b=new Map;return t.forEach(E=>{const S=new Date(E.completed_at||E.created_at),A=`${S.getFullYear()}-${String(S.getMonth()+1).padStart(2,"0")}-${String(S.getDate()).padStart(2,"0")}`,T=b.get(A)||[];T.push(E),b.set(A,T)}),b},[t]),d=$we(s,r),f=Vwe(s,r),g=()=>{r===0?(i(11),a(s-1)):i(r-1)},m=()=>{r===11?(i(0),a(s+1)):i(r+1)},x=()=>{i(n.getMonth()),a(n.getFullYear())},y=[];for(let b=0;bc.jsx("div",{className:"text-center text-xs text-bambu-gray py-2",children:b},b))}),c.jsx("div",{className:"grid grid-cols-7 gap-1",children:y.map((b,E)=>{if(b===null)return c.jsx("div",{className:"aspect-square"},`empty-${E}`);const S=`${s}-${String(r+1).padStart(2,"0")}-${String(b).padStart(2,"0")}`,A=u.get(S)||[],T=A.length>0,P=b===n.getDate()&&r===n.getMonth()&&s===n.getFullYear(),C=S===o,I=A.filter(D=>D.status==="completed").length,N=A.filter(D=>D.status==="failed").length;return c.jsxs("button",{onClick:()=>l(C?null:S),className:`aspect-square rounded-lg p-1 flex flex-col items-center justify-center transition-colors relative ${C?"bg-bambu-green text-white":P?"bg-bambu-green/20 text-white ring-2 ring-bambu-green":T?"bg-bambu-dark-tertiary hover:bg-bambu-dark-tertiary/70 text-white":"hover:bg-bambu-dark-tertiary/50 text-bambu-gray"}`,children:[c.jsx("span",{className:`text-sm font-medium ${P&&!C?"text-bambu-green":""}`,children:b}),T&&c.jsxs("div",{className:"absolute bottom-1 left-1/2 -translate-x-1/2 flex items-center gap-1",children:[c.jsx("div",{className:`w-2 h-2 rounded-full ${N>0&&I===0?"bg-red-400":N>0?"bg-yellow-400":"bg-green-400"}`}),c.jsx("span",{className:"text-xs font-medium",children:A.length})]})]},b)})}),c.jsx("div",{className:"mt-4 pt-4 border-t border-bambu-dark-tertiary",children:c.jsxs("div",{className:"grid grid-cols-3 gap-4 text-center",children:[c.jsxs("div",{children:[c.jsx("div",{className:"text-2xl font-bold text-white",children:t.filter(b=>{const E=new Date(b.completed_at||b.created_at);return E.getMonth()===r&&E.getFullYear()===s}).length}),c.jsx("div",{className:"text-xs text-bambu-gray",children:"Prints this month"})]}),c.jsxs("div",{children:[c.jsx("div",{className:"text-2xl font-bold text-green-400",children:t.filter(b=>{const E=new Date(b.completed_at||b.created_at);return E.getMonth()===r&&E.getFullYear()===s&&b.status==="completed"}).length}),c.jsx("div",{className:"text-xs text-bambu-gray",children:"Successful"})]}),c.jsxs("div",{children:[c.jsx("div",{className:"text-2xl font-bold text-red-400",children:t.filter(b=>{const E=new Date(b.completed_at||b.created_at);return E.getMonth()===r&&E.getFullYear()===s&&b.status==="failed"}).length}),c.jsx("div",{className:"text-xs text-bambu-gray",children:"Failed"})]})]})})]}),c.jsx("div",{className:"lg:w-80 bg-bambu-dark rounded-xl p-4",children:o?c.jsxs(c.Fragment,{children:[c.jsx("h3",{className:"text-sm font-medium text-bambu-gray mb-3",children:new Date(o+"T12:00:00").toLocaleDateString("en-US",{weekday:"long",month:"long",day:"numeric",year:"numeric"})}),v.length>0?c.jsx("div",{className:"space-y-2 max-h-96 overflow-y-auto",children:v.map(b=>c.jsxs("button",{onClick:()=>e?.(b),className:"w-full flex items-center gap-3 p-2 rounded-lg hover:bg-bambu-dark-tertiary transition-colors text-left",children:[b.thumbnail_path?c.jsx("img",{src:Pe.getArchiveThumbnail(b.id),alt:"",className:"w-12 h-12 rounded object-cover"}):c.jsx("div",{className:"w-12 h-12 rounded bg-bambu-dark-tertiary flex items-center justify-center",children:c.jsx("span",{className:"text-xs text-bambu-gray",children:"3MF"})}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsx("p",{className:"text-sm text-white truncate",children:b.print_name||b.filename}),c.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[c.jsx("span",{className:b.status==="failed"?"text-red-400":"text-green-400",children:b.status==="failed"?"Failed":"Completed"}),b.filament_color&&c.jsx("div",{className:"flex gap-0.5",children:b.filament_color.split(",").map((E,S)=>c.jsx("div",{className:"w-3 h-3 rounded-full border border-white/20",style:{backgroundColor:E}},S))})]})]})]},b.id))}):c.jsx("p",{className:"text-sm text-bambu-gray",children:"No prints on this day"})]}):c.jsx("div",{className:"text-center py-8",children:c.jsx("p",{className:"text-sm text-bambu-gray",children:"Select a day to see prints"})})})]})}function Kwe({archiveId:t,archiveName:e,onClose:n}){const r=Pe.getArchiveQRCodeUrl(t,300);M.useEffect(()=>{const s=a=>{a.key==="Escape"&&n()};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[n]);const i=()=>{const s=document.createElement("a");s.href=r,s.download=`${e}_qrcode.png`,s.click()};return c.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:n,children:c.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-sm",onClick:s=>s.stopPropagation(),children:[c.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[c.jsx("h2",{className:"text-lg font-semibold text-white",children:"QR Code"}),c.jsx("button",{onClick:n,className:"text-bambu-gray hover:text-white transition-colors",children:c.jsx(Gt,{className:"w-5 h-5"})})]}),c.jsxs("div",{className:"p-6 flex flex-col items-center",children:[c.jsx("p",{className:"text-sm text-bambu-gray mb-4 text-center truncate max-w-full",children:e}),c.jsx("div",{className:"bg-white p-4 rounded-lg mb-4",children:c.jsx("img",{src:r,alt:"QR Code",className:"w-64 h-64"})}),c.jsx("p",{className:"text-xs text-bambu-gray mb-4 text-center",children:"Scan to open this archive"}),c.jsxs(Ie,{onClick:i,className:"w-full",children:[c.jsx(ya,{className:"w-4 h-4"}),"Download QR Code"]})]})]})})}function Xwe({archiveId:t,archiveName:e,photos:n,onClose:r,onDelete:i}){const[s,a]=M.useState(0),[o,l]=M.useState(!1);if(M.useEffect(()=>{const m=x=>{x.key==="Escape"&&r(),x.key==="ArrowLeft"&&a(y=>Math.max(0,y-1)),x.key==="ArrowRight"&&a(y=>Math.min(n.length-1,y+1))};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[r,n.length]),M.useEffect(()=>{s>=n.length&&a(Math.max(0,n.length-1))},[n.length,s]),n.length===0)return r(),null;const u=n[s],d=Pe.getArchivePhotoUrl(t,u),f=()=>{const m=document.createElement("a");m.href=d,m.download=`${e}_photo_${s+1}.jpg`,m.click()},g=()=>{i&&l(!0)};return c.jsxs("div",{className:"fixed inset-0 bg-black/90 flex items-center justify-center z-50",onClick:r,children:[c.jsxs("div",{className:"relative w-full h-full flex flex-col",onClick:m=>m.stopPropagation(),children:[c.jsxs("div",{className:"flex items-center justify-between px-6 py-4 bg-black/50",children:[c.jsxs("div",{children:[c.jsx("h2",{className:"text-lg font-semibold text-white",children:e}),c.jsxs("p",{className:"text-sm text-bambu-gray",children:["Photo ",s+1," of ",n.length]})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs(Ie,{variant:"secondary",size:"sm",onClick:f,children:[c.jsx(ya,{className:"w-4 h-4"}),"Download"]}),i&&c.jsx(Ie,{variant:"secondary",size:"sm",onClick:g,className:"text-red-400 hover:text-red-300",children:c.jsx(kn,{className:"w-4 h-4"})}),c.jsx("button",{onClick:r,className:"p-2 text-bambu-gray hover:text-white transition-colors",children:c.jsx(Gt,{className:"w-6 h-6"})})]})]}),c.jsxs("div",{className:"flex-1 min-h-0 flex items-center justify-center p-4 relative overflow-hidden",children:[s>0&&c.jsx("button",{onClick:()=>a(m=>m-1),className:"absolute left-4 z-10 p-3 bg-black/50 hover:bg-black/70 rounded-full transition-colors",children:c.jsx(Rh,{className:"w-8 h-8 text-white"})}),c.jsx("img",{src:d,alt:`Photo ${s+1}`,className:"max-w-full max-h-full object-contain rounded-lg",style:{maxHeight:"calc(100vh - 200px)"}}),sa(m=>m+1),className:"absolute right-4 z-10 p-3 bg-black/50 hover:bg-black/70 rounded-full transition-colors",children:c.jsx(tf,{className:"w-8 h-8 text-white"})})]}),n.length>1&&c.jsx("div",{className:"flex justify-center gap-2 p-4 bg-black/50",children:n.map((m,x)=>c.jsx("button",{onClick:()=>a(x),className:`w-16 h-16 rounded-lg overflow-hidden border-2 transition-colors ${x===s?"border-bambu-green":"border-transparent hover:border-bambu-gray"}`,children:c.jsx("img",{src:Pe.getArchivePhotoUrl(t,m),alt:`Thumbnail ${x+1}`,className:"w-full h-full object-cover"})},m))})]}),o&&c.jsx(Kr,{title:"Delete Photo",message:"Delete this photo? This cannot be undone.",confirmText:"Delete",variant:"danger",onConfirm:()=>{i?.(u),l(!1)},onCancel:()=>l(!1)})]})}function qi(t){this.content=t}qi.prototype={constructor:qi,find:function(t){for(var e=0;e>1}};qi.from=function(t){if(t instanceof qi)return t;var e=[];if(t)for(var n in t)e.push(n,t[n]);return new qi(e)};function pW(t,e,n){for(let r=0;;r++){if(r==t.childCount||r==e.childCount)return t.childCount==e.childCount?null:n;let i=t.child(r),s=e.child(r);if(i==s){n+=i.nodeSize;continue}if(!i.sameMarkup(s))return n;if(i.isText&&i.text!=s.text){for(let a=0;i.text[a]==s.text[a];a++)n++;return n}if(i.content.size||s.content.size){let a=pW(i.content,s.content,n+1);if(a!=null)return a}n+=i.nodeSize}}function mW(t,e,n,r){for(let i=t.childCount,s=e.childCount;;){if(i==0||s==0)return i==s?null:{a:n,b:r};let a=t.child(--i),o=e.child(--s),l=a.nodeSize;if(a==o){n-=l,r-=l;continue}if(!a.sameMarkup(o))return{a:n,b:r};if(a.isText&&a.text!=o.text){let u=0,d=Math.min(a.text.length,o.text.length);for(;ue&&r(l,i+o,s||null,a)!==!1&&l.content.size){let d=o+1;l.nodesBetween(Math.max(0,e-d),Math.min(l.content.size,n-d),r,i+d)}o=u}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,n,r,i){let s="",a=!0;return this.nodesBetween(e,n,(o,l)=>{let u=o.isText?o.text.slice(Math.max(e,l)-l,n-l):o.isLeaf?i?typeof i=="function"?i(o):i:o.type.spec.leafText?o.type.spec.leafText(o):"":"";o.isBlock&&(o.isLeaf&&u||o.isTextblock)&&r&&(a?a=!1:s+=r),s+=u},0),s}append(e){if(!e.size)return this;if(!this.size)return e;let n=this.lastChild,r=e.firstChild,i=this.content.slice(),s=0;for(n.isText&&n.sameMarkup(r)&&(i[i.length-1]=n.withText(n.text+r.text),s=1);se)for(let s=0,a=0;ae&&((an)&&(o.isText?o=o.cut(Math.max(0,e-a),Math.min(o.text.length,n-a)):o=o.cut(Math.max(0,e-a-1),Math.min(o.content.size,n-a-1))),r.push(o),i+=o.nodeSize),a=l}return new pt(r,i)}cutByIndex(e,n){return e==n?pt.empty:e==0&&n==this.content.length?this:new pt(this.content.slice(e,n))}replaceChild(e,n){let r=this.content[e];if(r==n)return this;let i=this.content.slice(),s=this.size+n.nodeSize-r.nodeSize;return i[e]=n,new pt(i,s)}addToStart(e){return new pt([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new pt(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let n=0;nthis.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let n=0,r=0;;n++){let i=this.child(n),s=r+i.nodeSize;if(s>=e)return s==e?e_(n+1,s):e_(n,r);r=s}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,n){if(!n)return pt.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return new pt(n.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return pt.empty;let n,r=0;for(let i=0;ithis.type.rank&&(n||(n=e.slice(0,i)),n.push(this),r=!0),n&&n.push(s)}}return n||(n=e.slice()),r||n.push(this),n}removeFromSet(e){for(let n=0;nr.type.rank-i.type.rank),n}};Zn.none=[];class E1 extends Error{}class Tt{constructor(e,n,r){this.content=e,this.openStart=n,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,n){let r=xW(this.content,e+this.openStart,n);return r&&new Tt(r,this.openStart,this.openEnd)}removeBetween(e,n){return new Tt(gW(this.content,e+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,n){if(!n)return Tt.empty;let r=n.openStart||0,i=n.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new Tt(pt.fromJSON(e,n.content),r,i)}static maxOpen(e,n=!0){let r=0,i=0;for(let s=e.firstChild;s&&!s.isLeaf&&(n||!s.type.spec.isolating);s=s.firstChild)r++;for(let s=e.lastChild;s&&!s.isLeaf&&(n||!s.type.spec.isolating);s=s.lastChild)i++;return new Tt(e,r,i)}}Tt.empty=new Tt(pt.empty,0,0);function gW(t,e,n){let{index:r,offset:i}=t.findIndex(e),s=t.maybeChild(r),{index:a,offset:o}=t.findIndex(n);if(i==e||s.isText){if(o!=n&&!t.child(a).isText)throw new RangeError("Removing non-flat range");return t.cut(0,e).append(t.cut(n))}if(r!=a)throw new RangeError("Removing non-flat range");return t.replaceChild(r,s.copy(gW(s.content,e-i-1,n-i-1)))}function xW(t,e,n,r){let{index:i,offset:s}=t.findIndex(e),a=t.maybeChild(i);if(s==e||a.isText)return r&&!r.canReplace(i,i,n)?null:t.cut(0,e).append(n).append(t.cut(e));let o=xW(a.content,e-s-1,n,a);return o&&t.replaceChild(i,a.copy(o))}function Ywe(t,e,n){if(n.openStart>t.depth)throw new E1("Inserted content deeper than insertion position");if(t.depth-n.openStart!=e.depth-n.openEnd)throw new E1("Inconsistent open depths");return bW(t,e,n,0)}function bW(t,e,n,r){let i=t.index(r),s=t.node(r);if(i==e.index(r)&&r=0&&t.isText&&t.sameMarkup(e[n])?e[n]=t.withText(e[n].text+t.text):e.push(t)}function zx(t,e,n,r){let i=(e||t).node(n),s=0,a=e?e.index(n):i.childCount;t&&(s=t.index(n),t.depth>n?s++:t.textOffset&&(bh(t.nodeAfter,r),s++));for(let o=s;oi&&mk(t,e,i+1),a=r.depth>i&&mk(n,r,i+1),o=[];return zx(null,t,i,o),s&&a&&e.index(i)==n.index(i)?(vW(s,a),bh(vh(s,yW(t,e,n,r,i+1)),o)):(s&&bh(vh(s,M1(t,e,i+1)),o),zx(e,n,i,o),a&&bh(vh(a,M1(n,r,i+1)),o)),zx(r,null,i,o),new pt(o)}function M1(t,e,n){let r=[];if(zx(null,t,n,r),t.depth>n){let i=mk(t,e,n+1);bh(vh(i,M1(t,e,n+1)),r)}return zx(e,null,n,r),new pt(r)}function Zwe(t,e){let n=e.depth-t.openStart,i=e.node(n).copy(t.content);for(let s=n-1;s>=0;s--)i=e.node(s).copy(pt.from(i));return{start:i.resolveNoCache(t.openStart+n),end:i.resolveNoCache(i.content.size-t.openEnd-n)}}class M0{constructor(e,n,r){this.pos=e,this.path=n,this.parentOffset=r,this.depth=n.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,n=this.index(this.depth);if(n==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],i=e.child(n);return r?e.child(n).cut(r):i}get nodeBefore(){let e=this.index(this.depth),n=this.pos-this.path[this.path.length-1];return n?this.parent.child(e).cut(0,n):e==0?null:this.parent.child(e-1)}posAtIndex(e,n){n=this.resolveDepth(n);let r=this.path[n*3],i=n==0?0:this.path[n*3-1]+1;for(let s=0;s0;n--)if(this.start(n)<=e&&this.end(n)>=e)return n;return 0}blockRange(e=this,n){if(e.pos=0;r--)if(e.pos<=this.end(r)&&(!n||n(this.node(r))))return new A1(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&n<=e.content.size))throw new RangeError("Position "+n+" out of range");let r=[],i=0,s=n;for(let a=e;;){let{index:o,offset:l}=a.content.findIndex(s),u=s-l;if(r.push(a,o,i+l),!u||(a=a.child(o),a.isText))break;s=u-1,i+=l+1}return new M0(n,r,s)}static resolveCached(e,n){let r=DB.get(e);if(r)for(let s=0;se&&this.nodesBetween(e,n,s=>(r.isInSet(s.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),_W(this.marks,e)}contentMatchAt(e){let n=this.type.contentMatch.matchFragment(this.content,0,e);if(!n)throw new Error("Called contentMatchAt on a node with invalid content");return n}canReplace(e,n,r=pt.empty,i=0,s=r.childCount){let a=this.contentMatchAt(e).matchFragment(r,i,s),o=a&&a.matchFragment(this.content,n);if(!o||!o.validEnd)return!1;for(let l=i;ln.type.name)}`);this.content.forEach(n=>n.check())}toJSON(){let e={type:this.type.name};for(let n in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(n=>n.toJSON())),e}static fromJSON(e,n){if(!n)throw new RangeError("Invalid input for Node.fromJSON");let r;if(n.marks){if(!Array.isArray(n.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=n.marks.map(e.markFromJSON)}if(n.type=="text"){if(typeof n.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(n.text,r)}let i=pt.fromJSON(e,n.content),s=e.nodeType(n.type).create(n.attrs,i,r);return s.type.checkAttrs(s.attrs),s}};Wu.prototype.text=void 0;class T1 extends Wu{constructor(e,n,r,i){if(super(e,n,null,i),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):_W(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,n){return this.text.slice(e,n)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new T1(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new T1(this.type,this.attrs,e,this.marks)}cut(e=0,n=this.text.length){return e==0&&n==this.text.length?this:this.withText(this.text.slice(e,n))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}}function _W(t,e){for(let n=t.length-1;n>=0;n--)e=t[n].type.name+"("+e+")";return e}class Hh{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,n){let r=new tSe(e,n);if(r.next==null)return Hh.empty;let i=wW(r);r.next&&r.err("Unexpected trailing text");let s=lSe(oSe(i));return cSe(s,r),s}matchType(e){for(let n=0;nu.createAndFill()));for(let u=0;u=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function n(r){e.push(r);for(let i=0;i{let s=i+(r.validEnd?"*":" ")+" ";for(let a=0;a"+e.indexOf(r.next[a].next);return s}).join(` -`)}}Hh.empty=new Hh(!0);class tSe{constructor(e,n){this.string=e,this.nodeTypes=n,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}}function wW(t){let e=[];do e.push(nSe(t));while(t.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function nSe(t){let e=[];do e.push(rSe(t));while(t.next&&t.next!=")"&&t.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function rSe(t){let e=aSe(t);for(;;)if(t.eat("+"))e={type:"plus",expr:e};else if(t.eat("*"))e={type:"star",expr:e};else if(t.eat("?"))e={type:"opt",expr:e};else if(t.eat("{"))e=iSe(t,e);else break;return e}function OB(t){/\D/.test(t.next)&&t.err("Expected number, got '"+t.next+"'");let e=Number(t.next);return t.pos++,e}function iSe(t,e){let n=OB(t),r=n;return t.eat(",")&&(t.next!="}"?r=OB(t):r=-1),t.eat("}")||t.err("Unclosed braced range"),{type:"range",min:n,max:r,expr:e}}function sSe(t,e){let n=t.nodeTypes,r=n[e];if(r)return[r];let i=[];for(let s in n){let a=n[s];a.isInGroup(e)&&i.push(a)}return i.length==0&&t.err("No node type or group '"+e+"' found"),i}function aSe(t){if(t.eat("(")){let e=wW(t);return t.eat(")")||t.err("Missing closing paren"),e}else if(/\W/.test(t.next))t.err("Unexpected token '"+t.next+"'");else{let e=sSe(t,t.next).map(n=>(t.inline==null?t.inline=n.isInline:t.inline!=n.isInline&&t.err("Mixing inline and block content"),{type:"name",value:n}));return t.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function oSe(t){let e=[[]];return i(s(t,0),n()),e;function n(){return e.push([])-1}function r(a,o,l){let u={term:l,to:o};return e[a].push(u),u}function i(a,o){a.forEach(l=>l.to=o)}function s(a,o){if(a.type=="choice")return a.exprs.reduce((l,u)=>l.concat(s(u,o)),[]);if(a.type=="seq")for(let l=0;;l++){let u=s(a.exprs[l],o);if(l==a.exprs.length-1)return u;i(u,o=n())}else if(a.type=="star"){let l=n();return r(o,l),i(s(a.expr,l),l),[r(l)]}else if(a.type=="plus"){let l=n();return i(s(a.expr,o),l),i(s(a.expr,l),l),[r(l)]}else{if(a.type=="opt")return[r(o)].concat(s(a.expr,o));if(a.type=="range"){let l=o;for(let u=0;u{t[a].forEach(({term:o,to:l})=>{if(!o)return;let u;for(let d=0;d{u||i.push([o,u=[]]),u.indexOf(d)==-1&&u.push(d)})})});let s=e[r.join(",")]=new Hh(r.indexOf(t.length-1)>-1);for(let a=0;a-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:MW(this.attrs,e)}create(e=null,n,r){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new Wu(this,this.computeAttrs(e),pt.from(n),Zn.setFrom(r))}createChecked(e=null,n,r){return n=pt.from(n),this.checkContent(n),new Wu(this,this.computeAttrs(e),n,Zn.setFrom(r))}createAndFill(e=null,n,r){if(e=this.computeAttrs(e),n=pt.from(n),n.size){let a=this.contentMatch.fillBefore(n);if(!a)return null;n=a.append(n)}let i=this.contentMatch.matchFragment(n),s=i&&i.fillBefore(pt.empty,!0);return s?new Wu(this,e,n.append(s),Zn.setFrom(r)):null}validContent(e){let n=this.contentMatch.matchFragment(e);if(!n||!n.validEnd)return!1;for(let r=0;r-1}allowsMarks(e){if(this.markSet==null)return!0;for(let n=0;nr[s]=new CW(s,n,a));let i=n.spec.topNode||"doc";if(!r[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let s in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function uSe(t,e,n){let r=n.split("|");return i=>{let s=i===null?"null":typeof i;if(r.indexOf(s)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${t}, got ${s}`)}}class dSe{constructor(e,n,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?uSe(e,n,r.validate):r.validate}get isRequired(){return!this.hasDefault}}class RS{constructor(e,n,r,i){this.name=e,this.rank=n,this.schema=r,this.spec=i,this.attrs=TW(e,i.attrs),this.excluded=null;let s=EW(this.attrs);this.instance=s?new Zn(this,s):null}create(e=null){return!e&&this.instance?this.instance:new Zn(this,MW(this.attrs,e))}static compile(e,n){let r=Object.create(null),i=0;return e.forEach((s,a)=>r[s]=new RS(s,i++,n,a)),r}removeFromSet(e){for(var n=0;n-1}}class NW{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let n=this.spec={};for(let i in e)n[i]=e[i];n.nodes=qi.from(e.nodes),n.marks=qi.from(e.marks||{}),this.nodes=LB.compile(this.spec.nodes,this),this.marks=RS.compile(this.spec.marks,this);let r=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let s=this.nodes[i],a=s.spec.content||"",o=s.spec.marks;if(s.contentMatch=r[a]||(r[a]=Hh.parse(a,this.nodes)),s.inlineContent=s.contentMatch.inlineContent,s.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!s.isInline||!s.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=s}s.markSet=o=="_"?null:o?IB(this,o.split(" ")):o==""||!s.inlineContent?[]:null}for(let i in this.marks){let s=this.marks[i],a=s.spec.excludes;s.excluded=a==null?[s]:a==""?[]:IB(this,a.split(" "))}this.nodeFromJSON=i=>Wu.fromJSON(this,i),this.markFromJSON=i=>Zn.fromJSON(this,i),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,n=null,r,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof LB){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(n,r,i)}text(e,n){let r=this.nodes.text;return new T1(r,r.defaultAttrs,e,Zn.setFrom(n))}mark(e,n){return typeof e=="string"&&(e=this.marks[e]),e.create(n)}nodeType(e){let n=this.nodes[e];if(!n)throw new RangeError("Unknown node type: "+e);return n}}function IB(t,e){let n=[];for(let r=0;r-1)&&n.push(a=l)}if(!a)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return n}function hSe(t){return t.tag!=null}function fSe(t){return t.style!=null}let Bx=class xk{constructor(e,n){this.schema=e,this.rules=n,this.tags=[],this.styles=[];let r=this.matchedStyles=[];n.forEach(i=>{if(hSe(i))this.tags.push(i);else if(fSe(i)){let s=/[^=]*/.exec(i.style)[0];r.indexOf(s)<0&&r.push(s),this.styles.push(i)}}),this.normalizeLists=!this.tags.some(i=>{if(!/^(ul|ol)\b/.test(i.tag)||!i.node)return!1;let s=e.nodes[i.node];return s.contentMatch.matchType(s)})}parse(e,n={}){let r=new FB(this,n,!1);return r.addAll(e,Zn.none,n.from,n.to),r.finish()}parseSlice(e,n={}){let r=new FB(this,n,!0);return r.addAll(e,Zn.none,n.from,n.to),Tt.maxOpen(r.finish())}matchTag(e,n,r){for(let i=r?this.tags.indexOf(r)+1:0;ie.length&&(o.charCodeAt(e.length)!=61||o.slice(e.length+1)!=n))){if(a.getAttrs){let l=a.getAttrs(n);if(l===!1)continue;a.attrs=l||void 0}return a}}}static schemaRules(e){let n=[];function r(i){let s=i.priority==null?50:i.priority,a=0;for(;a{r(a=zB(a)),a.mark||a.ignore||a.clearMark||(a.mark=i)})}for(let i in e.nodes){let s=e.nodes[i].spec.parseDOM;s&&s.forEach(a=>{r(a=zB(a)),a.node||a.ignore||a.mark||(a.node=i)})}return n}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new xk(e,xk.schemaRules(e)))}};const kW={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},pSe={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},PW={ol:!0,ul:!0},A0=1,bk=2,Hx=4;function UB(t,e,n){return e!=null?(e?A0:0)|(e==="full"?bk:0):t&&t.whitespace=="pre"?A0|bk:n&~Hx}class t_{constructor(e,n,r,i,s,a){this.type=e,this.attrs=n,this.marks=r,this.solid=i,this.options=a,this.content=[],this.activeMarks=Zn.none,this.match=s||(a&Hx?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let n=this.type.contentMatch.fillBefore(pt.from(e));if(n)this.match=this.type.contentMatch.matchFragment(n);else{let r=this.type.contentMatch,i;return(i=r.findWrapping(e.type))?(this.match=r,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&A0)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let s=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=s.withText(s.text.slice(0,s.text.length-i[0].length))}}let n=pt.from(this.content);return!e&&this.match&&(n=n.append(this.match.fillBefore(pt.empty,!0))),this.type?this.type.create(this.attrs,n,this.marks):n}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!kW.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class FB{constructor(e,n,r){this.parser=e,this.options=n,this.isOpen=r,this.open=0,this.localPreserveWS=!1;let i=n.topNode,s,a=UB(null,n.preserveWhitespace,0)|(r?Hx:0);i?s=new t_(i.type,i.attrs,Zn.none,!0,n.topMatch||i.type.contentMatch,a):r?s=new t_(null,null,Zn.none,!0,null,a):s=new t_(e.schema.topNodeType,null,Zn.none,!0,null,a),this.nodes=[s],this.find=n.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,n){e.nodeType==3?this.addTextNode(e,n):e.nodeType==1&&this.addElement(e,n)}addTextNode(e,n){let r=e.nodeValue,i=this.top,s=i.options&bk?"full":this.localPreserveWS||(i.options&A0)>0,{schema:a}=this.parser;if(s==="full"||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(s)if(s==="full")r=r.replace(/\r\n?/g,` +`),f=u.slice(0,d);this.parser.parseGCode(a+f),a=u.slice(d)}while(!s.done);var l;console.debug("read from stream",o)}))}initGui(){typeof this.devMode=="boolean"&&this.devMode===!0?this.devGui=new RB(this):typeof this.devMode=="object"&&(this.devGui=new RB(this,this.devMode))}initStats(){var e;this.stats&&(typeof this.devMode=="object"&&(this.statsContainer=this.devMode.statsContainer),((e=this.statsContainer)!==null&&e!==void 0?e:document.body).appendChild(this.stats.dom),this.stats.dom.classList.add("stats"),this.initGui())}}Xp.defaultExtrusionColor=new $t("hotpink");const Owe=function(t){return new Xp(t)};function jwe({gcodeUrl:t,buildVolume:e={x:256,y:256,z:256},className:n=""}){const r=M.useRef(null),i=M.useRef(null),[s,a]=M.useState(!0),[o,l]=M.useState(null),[u,d]=M.useState(!1),[f,g]=M.useState(0),[m,x]=M.useState(0);M.useEffect(()=>{if(!r.current)return;const b=r.current,E=Owe({canvas:b,buildVolume:e,backgroundColor:1710618,travelColor:4473924,extrusionColor:44610,topLayerColor:65370,lastSegmentColor:16777215,lineWidth:2,renderTravel:!1,renderExtrusion:!0});i.current=E,a(!0),l(null),d(!1),fetch(t).then(async A=>{if(!A.ok)throw A.status===404&&(await A.json().catch(()=>({}))).detail?.includes("sliced")?(d(!0),new Error("not_sliced")):new Error("Failed to load G-code");return A.text()}).then(A=>{E.processGCode(A);const T=E.layers?.length||0;x(T),g(T),E.render(),a(!1)}).catch(A=>{l(A.message),a(!1)});const S=()=>{if(b.parentElement){const A=b.parentElement.getBoundingClientRect();b.width=A.width,b.height=A.height,E.resize()}};return S(),window.addEventListener("resize",S),()=>{window.removeEventListener("resize",S),E.dispose()}},[t,e]);const y=b=>{if(!i.current)return;const E=Math.max(1,Math.min(b,m));g(E),i.current.render()},v=b=>{y(parseInt(b.target.value,10))};return c.jsxs("div",{className:`relative flex flex-col h-full ${n}`,children:[c.jsxs("div",{className:"flex-1 relative bg-bambu-dark rounded-lg overflow-hidden",children:[c.jsx("canvas",{ref:r,className:"w-full h-full"}),s&&c.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-bambu-dark/80",children:c.jsxs("div",{className:"text-center",children:[c.jsx(At,{className:"w-8 h-8 animate-spin text-bambu-green mx-auto mb-2"}),c.jsx("p",{className:"text-bambu-gray text-sm",children:"Loading G-code..."})]})}),u&&c.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-bambu-dark/80",children:c.jsxs("div",{className:"text-center max-w-sm px-4",children:[c.jsx(yoe,{className:"w-12 h-12 text-bambu-gray mx-auto mb-3"}),c.jsx("p",{className:"text-white font-medium mb-2",children:"G-code not available"}),c.jsx("p",{className:"text-bambu-gray text-sm",children:"This file hasn't been sliced yet. G-code preview is only available after slicing the model in Bambu Studio or Orca Slicer."})]})}),o&&!u&&c.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-bambu-dark/80",children:c.jsx("div",{className:"text-center text-red-400",children:c.jsx("p",{className:"text-sm",children:o})})})]}),!s&&!o&&!u&&m>0&&c.jsx("div",{className:"mt-4 px-2",children:c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx(Oh,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}),c.jsx("button",{onClick:()=>y(f-1),disabled:f<=1,className:"p-1 rounded hover:bg-bambu-dark-tertiary disabled:opacity-30 disabled:cursor-not-allowed",children:c.jsx(Rh,{className:"w-4 h-4"})}),c.jsx("input",{type:"range",min:1,max:m,value:f,onChange:v,className:"flex-1 h-2 bg-bambu-dark-tertiary rounded-lg appearance-none cursor-pointer accent-bambu-green"}),c.jsx("button",{onClick:()=>y(f+1),disabled:f>=m,className:"p-1 rounded hover:bg-bambu-dark-tertiary disabled:opacity-30 disabled:cursor-not-allowed",children:c.jsx(tf,{className:"w-4 h-4"})}),c.jsxs("span",{className:"text-sm text-bambu-gray min-w-[80px] text-right",children:[f," / ",m]})]})})]})}function Lwe({archiveId:t,title:e,onClose:n}){const[r,i]=M.useState(null),[s,a]=M.useState(null),[o,l]=M.useState(!0);M.useEffect(()=>{const d=f=>{f.key==="Escape"&&n()};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[n]),M.useEffect(()=>{Pe.getArchiveCapabilities(t).then(d=>{a(d),d.has_model?i("3d"):d.has_gcode&&i("gcode"),l(!1)}).catch(()=>{a({has_model:!0,has_gcode:!1,build_volume:{x:256,y:256,z:256}}),i("3d"),l(!1)})},[t]);const u=()=>{const d=e||"model",f=`${window.location.origin}${Pe.getArchiveForSlicer(t,d)}`;window.location.href=`bambustudioopen://${encodeURIComponent(f)}`};return c.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-8",onClick:n,children:c.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-4xl h-[80vh] flex flex-col",onClick:d=>d.stopPropagation(),children:[c.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[c.jsx("h2",{className:"text-lg font-semibold text-white truncate flex-1 mr-4",children:e}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs(Ie,{variant:"secondary",size:"sm",onClick:u,children:[c.jsx(ro,{className:"w-4 h-4"}),"Open in Slicer"]}),c.jsx(Ie,{variant:"ghost",size:"sm",onClick:n,children:c.jsx(Gt,{className:"w-5 h-5"})})]})]}),s&&c.jsxs("div",{className:"flex border-b border-bambu-dark-tertiary",children:[c.jsxs("button",{onClick:()=>s.has_model&&i("3d"),disabled:!s.has_model,className:`flex items-center gap-2 px-6 py-3 text-sm font-medium transition-colors ${r==="3d"?"text-bambu-green border-b-2 border-bambu-green":s.has_model?"text-bambu-gray hover:text-white":"text-bambu-gray/30 cursor-not-allowed"}`,children:[c.jsx(rm,{className:"w-4 h-4"}),"3D Model",!s.has_model&&c.jsx("span",{className:"text-xs",children:"(not available)"})]}),c.jsxs("button",{onClick:()=>s.has_gcode&&i("gcode"),disabled:!s.has_gcode,className:`flex items-center gap-2 px-6 py-3 text-sm font-medium transition-colors ${r==="gcode"?"text-bambu-green border-b-2 border-bambu-green":s.has_gcode?"text-bambu-gray hover:text-white":"text-bambu-gray/30 cursor-not-allowed"}`,children:[c.jsx(Kae,{className:"w-4 h-4"}),"G-code Preview",!s.has_gcode&&c.jsx("span",{className:"text-xs",children:"(not sliced)"})]})]}),c.jsx("div",{className:"flex-1 overflow-hidden p-4",children:o?c.jsx("div",{className:"w-full h-full flex items-center justify-center",children:c.jsx(At,{className:"w-8 h-8 animate-spin text-bambu-green"})}):r==="3d"&&s?c.jsx(Pxe,{url:Pe.getArchiveDownload(t),buildVolume:s.build_volume,className:"w-full h-full"}):r==="gcode"&&s?c.jsx(jwe,{gcodeUrl:Pe.getArchiveGcode(t),buildVolume:s.build_volume,className:"w-full h-full"}):c.jsx("div",{className:"w-full h-full flex items-center justify-center text-bambu-gray",children:"No preview available for this file"})})]})})}function Iwe({archiveId:t,archiveName:e,onClose:n,onSuccess:r}){const[i,s]=M.useState(null);M.useEffect(()=>{const d=f=>{f.key==="Escape"&&n()};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[n]);const{data:a,isLoading:o}=yt({queryKey:["printers"],queryFn:Pe.getPrinters}),l=_t({mutationFn:()=>{if(!i)throw new Error("No printer selected");return Pe.reprintArchive(t,i)},onSuccess:()=>{r(),n()}}),u=a?.filter(d=>d.is_active)||[];return c.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-8",children:c.jsx(Nt,{className:"w-full max-w-md",children:c.jsxs(Dt,{children:[c.jsxs("div",{className:"flex items-center justify-between mb-4",children:[c.jsx("h2",{className:"text-lg font-semibold text-white",children:"Re-print"}),c.jsx(Ie,{variant:"ghost",size:"sm",onClick:n,children:c.jsx(Gt,{className:"w-5 h-5"})})]}),c.jsxs("p",{className:"text-sm text-bambu-gray mb-4",children:["Send ",c.jsx("span",{className:"text-white",children:e})," to a printer"]}),o?c.jsx("div",{className:"flex justify-center py-8",children:c.jsx(At,{className:"w-6 h-6 text-bambu-green animate-spin"})}):u.length===0?c.jsx("div",{className:"text-center py-8 text-bambu-gray",children:"No active printers available"}):c.jsx("div",{className:"space-y-2 mb-6",children:u.map(d=>c.jsxs("button",{onClick:()=>s(d.id),className:`w-full flex items-center gap-3 p-3 rounded-lg border transition-colors ${i===d.id?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray"}`,children:[c.jsx("div",{className:`p-2 rounded-lg ${i===d.id?"bg-bambu-green/20":"bg-bambu-dark-tertiary"}`,children:c.jsx(jo,{className:`w-5 h-5 ${i===d.id?"text-bambu-green":"text-bambu-gray"}`})}),c.jsxs("div",{className:"text-left",children:[c.jsx("p",{className:"text-white font-medium",children:d.name}),c.jsxs("p",{className:"text-xs text-bambu-gray",children:[d.model||"Unknown model"," • ",d.ip_address]})]})]},d.id))}),l.isError&&c.jsx("div",{className:"mb-4 p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:l.error.message||"Failed to start print"}),c.jsxs("div",{className:"flex gap-3",children:[c.jsx(Ie,{variant:"secondary",onClick:n,className:"flex-1",children:"Cancel"}),c.jsx(Ie,{onClick:()=>l.mutate(),disabled:!i||l.isPending,className:"flex-1",children:l.isPending?c.jsxs(c.Fragment,{children:[c.jsx(At,{className:"w-4 h-4 animate-spin"}),"Sending..."]}):c.jsxs(c.Fragment,{children:[c.jsx(jo,{className:"w-4 h-4"}),"Print"]})})]})]})})})}function Uwe({onClose:t,initialFiles:e}){const n=Sn(),{showToast:r}=ri(),i=M.useRef(null),[s,a]=M.useState(()=>e?.filter(C=>C.name.endsWith(".3mf")).map(C=>({file:C,status:"pending"}))||[]),[o,l]=M.useState(!1),[u,d]=M.useState(),[f,g]=M.useState(null);M.useEffect(()=>{const C=I=>{I.key==="Escape"&&t()};return window.addEventListener("keydown",C),()=>window.removeEventListener("keydown",C)},[t]);const{data:m}=yt({queryKey:["printers"],queryFn:Pe.getPrinters}),x=_t({mutationFn:C=>Pe.uploadArchivesBulk(C,u),onSuccess:C=>{g(C),n.invalidateQueries({queryKey:["archives"]}),n.invalidateQueries({queryKey:["archiveStats"]}),a(I=>I.map(N=>{const D=C.results.find(L=>L.filename===N.file.name),F=C.errors.find(L=>L.filename===N.file.name);return D?{...N,status:"success",archiveId:D.id}:F?{...N,status:"error",error:F.error}:N})),C.failed===0?r(`${C.uploaded} file${C.uploaded!==1?"s":""} uploaded`):C.uploaded===0?r(`Failed to upload ${C.failed} file${C.failed!==1?"s":""}`,"error"):r(`${C.uploaded} uploaded, ${C.failed} failed`,"warning")},onError:()=>{a(C=>C.map(I=>({...I,status:"error",error:"Upload failed"}))),r("Upload failed","error")}}),y=M.useCallback(C=>{C.preventDefault(),l(!0)},[]),v=M.useCallback(C=>{C.preventDefault(),l(!1)},[]),b=M.useCallback(C=>{C.preventDefault(),l(!1);const I=Array.from(C.dataTransfer.files).filter(N=>N.name.endsWith(".3mf"));I.length>0&&a(N=>[...N,...I.map(D=>({file:D,status:"pending"}))])},[]),E=M.useCallback(C=>{const I=Array.from(C.target.files||[]).filter(N=>N.name.endsWith(".3mf"));I.length>0&&a(N=>[...N,...I.map(D=>({file:D,status:"pending"}))]),i.current&&(i.current.value="")},[]),S=M.useCallback(C=>{a(I=>I.filter((N,D)=>D!==C))},[]),A=()=>{if(s.length===0)return;const C=s.filter(I=>I.status==="pending");C.length!==0&&(a(I=>I.map(N=>N.status==="pending"?{...N,status:"uploading"}:N)),x.mutate(C.map(I=>I.file)))},T=s.filter(C=>C.status==="pending").length,P=x.isPending;return c.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:c.jsx(Nt,{className:"w-full max-w-2xl max-h-[90vh] flex flex-col",children:c.jsxs(Dt,{className:"p-0 flex flex-col h-full",children:[c.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[c.jsx("h2",{className:"text-xl font-semibold text-white",children:"Upload 3MF Files"}),c.jsx("button",{onClick:t,className:"text-bambu-gray hover:text-white transition-colors",children:c.jsx(Gt,{className:"w-5 h-5"})})]}),c.jsx("div",{className:"p-4",children:c.jsxs("div",{className:`border-2 border-dashed rounded-lg p-8 text-center transition-colors ${o?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-gray"}`,onDragOver:y,onDragLeave:v,onDrop:b,children:[c.jsx(ma,{className:"w-12 h-12 mx-auto mb-4 text-bambu-gray"}),c.jsx("p",{className:"text-white mb-2",children:"Drag & drop .3mf files here"}),c.jsx("p",{className:"text-bambu-gray text-sm mb-4",children:"or"}),c.jsx(Ie,{variant:"secondary",onClick:()=>i.current?.click(),disabled:P,children:"Browse Files"}),c.jsx("input",{ref:i,type:"file",accept:".3mf",multiple:!0,className:"hidden",onChange:E})]})}),c.jsxs("div",{className:"px-4 pb-4",children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:"Associate with printer (optional)"}),c.jsxs("select",{className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:u||"",onChange:C=>d(C.target.value?Number(C.target.value):void 0),disabled:P,children:[c.jsx("option",{value:"",children:"No printer"}),m?.map(C=>c.jsx("option",{value:C.id,children:C.name},C.id))]})]}),s.length>0&&c.jsx("div",{className:"px-4 pb-4 max-h-60 overflow-y-auto",children:c.jsx("div",{className:"space-y-2",children:s.map((C,I)=>c.jsxs("div",{className:"flex items-center gap-3 p-3 bg-bambu-dark rounded-lg",children:[c.jsx(kG,{className:"w-5 h-5 text-bambu-gray flex-shrink-0"}),c.jsx("span",{className:"flex-1 text-white text-sm truncate",children:C.file.name}),c.jsxs("span",{className:"text-xs text-bambu-gray",children:[(C.file.size/(1024*1024)).toFixed(1)," MB"]}),C.status==="pending"&&c.jsx("button",{onClick:()=>S(I),className:"text-bambu-gray hover:text-red-400 transition-colors",disabled:P,children:c.jsx(Gt,{className:"w-4 h-4"})}),C.status==="uploading"&&c.jsx(At,{className:"w-4 h-4 text-bambu-green animate-spin"}),C.status==="success"&&c.jsx(ds,{className:"w-4 h-4 text-bambu-green"}),C.status==="error"&&c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"text-xs text-red-400",children:C.error}),c.jsx(Oo,{className:"w-4 h-4 text-red-400"})]})]},`${C.file.name}-${I}`))})}),f&&c.jsx("div",{className:"px-4 pb-4",children:c.jsx("div",{className:"p-3 bg-bambu-dark rounded-lg",children:c.jsxs("p",{className:"text-sm text-white",children:[c.jsx("span",{className:"text-bambu-green",children:f.uploaded})," uploaded",f.failed>0&&c.jsxs(c.Fragment,{children:[", ",c.jsx("span",{className:"text-red-400",children:f.failed})," failed"]})]})})}),c.jsxs("div",{className:"flex gap-3 p-4 border-t border-bambu-dark-tertiary",children:[c.jsx(Ie,{variant:"secondary",onClick:t,className:"flex-1",children:f?"Close":"Cancel"}),!f&&c.jsx(Ie,{onClick:A,disabled:T===0||P,className:"flex-1",children:P?c.jsxs(c.Fragment,{children:[c.jsx(At,{className:"w-4 h-4 animate-spin"}),"Uploading..."]}):c.jsxs(c.Fragment,{children:[c.jsx(ma,{className:"w-4 h-4"}),"Upload ",T>0&&`(${T})`]})})]})]})})})}const Fwe=["Adhesion failure","Spaghetti / Detached","Layer shift","Clogged nozzle","Filament runout","Warping","Stringing","Under-extrusion","Power failure","User cancelled","Other"];function zwe({archive:t,onClose:e,existingTags:n=[]}){M.useEffect(()=>{const U=$=>{$.key==="Escape"&&e()};return window.addEventListener("keydown",U),()=>window.removeEventListener("keydown",U)},[e]);const r=Sn(),[i,s]=M.useState(t.print_name||""),[a,o]=M.useState(t.printer_id),[l,u]=M.useState(t.project_id??null),[d,f]=M.useState(t.notes||""),[g,m]=M.useState(t.tags||""),[x,y]=M.useState(t.failure_reason||""),[v,b]=M.useState(t.photos||[]),[E,S]=M.useState(!1),[A,T]=M.useState(!1),P=M.useRef(null),C=M.useRef(null),I=M.useRef(null),{data:N}=yt({queryKey:["printers"],queryFn:Pe.getPrinters}),{data:D}=yt({queryKey:["projects"],queryFn:()=>Pe.getProjects()}),{data:F}=yt({queryKey:["archives"],queryFn:()=>Pe.getArchives(void 0,1e3,0),enabled:n.length===0}),L=n.length>0?n:[...new Set(F?.flatMap(U=>U.tags?.split(",").map($=>$.trim())||[]).filter(Boolean)||[])].sort(),q=g.split(",").map(U=>U.trim()).filter(Boolean),R=L.filter(U=>!q.includes(U)),V=U=>{if(!q.includes(U)){const $=[...q,U].join(", ");m($)}I.current!==null&&clearTimeout(I.current),P.current?.focus()},K=U=>{const $=q.filter(ee=>ee!==U).join(", ");m($)},W=_t({mutationFn:U=>Pe.updateArchive(t.id,U),onSuccess:()=>{r.invalidateQueries({queryKey:["archives"]}),r.invalidateQueries({queryKey:["projects"]}),e()}}),ne=async U=>{const $=U.target.files?.[0];if($){S(!0);try{const ee=await Pe.uploadArchivePhoto(t.id,$);b(ee.photos),r.invalidateQueries({queryKey:["archives"]})}catch(ee){console.error("Failed to upload photo:",ee)}finally{S(!1),C.current&&(C.current.value="")}}},Y=async U=>{try{const $=await Pe.deleteArchivePhoto(t.id,U);b($.photos||[]),r.invalidateQueries({queryKey:["archives"]})}catch($){console.error("Failed to delete photo:",$)}},Z=U=>{U.preventDefault(),W.mutate({print_name:i||void 0,printer_id:a,project_id:l,notes:d||void 0,tags:g||void 0,failure_reason:t.status==="failed"&&x||void 0})};return c.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:e,children:c.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-md max-h-[90vh] flex flex-col",onClick:U=>U.stopPropagation(),children:[c.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[c.jsx("h2",{className:"text-lg font-semibold text-white",children:"Edit Archive"}),c.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:c.jsx(Gt,{className:"w-5 h-5"})})]}),c.jsxs("form",{onSubmit:Z,className:"p-6 space-y-4 overflow-y-auto flex-1",children:[c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name"}),c.jsx("input",{type:"text",value:i,onChange:U=>s(U.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",placeholder:"Print name"})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Printer"}),c.jsxs("select",{value:a??"",onChange:U=>o(U.target.value?Number(U.target.value):null),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[c.jsx("option",{value:"",children:"No printer"}),N?.map(U=>c.jsx("option",{value:U.id,children:U.name},U.id))]})]}),c.jsxs("div",{children:[c.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[c.jsx(ph,{className:"w-4 h-4 inline mr-1"}),"Project"]}),c.jsxs("select",{value:l??"",onChange:U=>u(U.target.value?Number(U.target.value):null),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[c.jsx("option",{value:"",children:"No project"}),D?.map(U=>c.jsx("option",{value:U.id,children:U.name},U.id))]})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Notes"}),c.jsx("textarea",{value:d,onChange:U=>f(U.target.value),rows:3,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none resize-none",placeholder:"Add notes about this print..."})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Tags"}),q.length>0&&c.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:q.map(U=>c.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 bg-bambu-dark-tertiary rounded text-sm text-white",children:[c.jsx(f0,{className:"w-3 h-3"}),U,c.jsx("button",{type:"button",onClick:()=>K(U),className:"ml-0.5 text-bambu-gray hover:text-white",children:c.jsx(Gt,{className:"w-3 h-3"})})]},U))}),c.jsxs("div",{className:"relative",children:[c.jsx("input",{ref:P,type:"text",value:g,onChange:U=>m(U.target.value),onFocus:()=>{I.current!==null&&clearTimeout(I.current),T(!0)},onBlur:()=>{I.current=window.setTimeout(()=>T(!1),200)},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",placeholder:q.length>0?"Add more tags...":"Add tags..."}),A&&R.length>0&&c.jsxs("div",{className:"absolute top-full left-0 right-0 mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg z-10 max-h-40 overflow-y-auto",children:[c.jsx("div",{className:"p-2 text-xs text-bambu-gray border-b border-bambu-dark-tertiary",children:"Existing tags (click to add)"}),c.jsx("div",{className:"p-2 flex flex-wrap gap-1.5",children:R.map(U=>c.jsx("button",{type:"button",onClick:()=>V(U),className:"px-2 py-0.5 bg-bambu-dark-tertiary hover:bg-bambu-green/20 rounded text-sm text-bambu-gray hover:text-white transition-colors",children:U},U))})]})]})]}),t.status==="failed"&&c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Failure Reason"}),c.jsxs("select",{value:x,onChange:U=>y(U.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[c.jsx("option",{value:"",children:"Select reason..."}),Fwe.map(U=>c.jsx("option",{value:U,children:U},U))]})]}),c.jsxs("div",{children:[c.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[c.jsx(a0,{className:"w-4 h-4 inline mr-1"}),"Photos of Printed Result"]}),c.jsxs("div",{className:"flex flex-wrap gap-2 mb-2",children:[v.map(U=>c.jsxs("div",{className:"relative group",children:[c.jsx("img",{src:Pe.getArchivePhotoUrl(t.id,U),alt:"Print result",className:"w-20 h-20 object-cover rounded-lg border border-bambu-dark-tertiary"}),c.jsx("button",{type:"button",onClick:()=>Y(U),className:"absolute -top-1 -right-1 p-1 bg-red-500 rounded-full opacity-0 group-hover:opacity-100 transition-opacity",children:c.jsx(kn,{className:"w-3 h-3 text-white"})})]},U)),c.jsxs("label",{className:"w-20 h-20 flex items-center justify-center border-2 border-dashed border-bambu-dark-tertiary rounded-lg cursor-pointer hover:border-bambu-green transition-colors",children:[c.jsx("input",{ref:C,type:"file",accept:"image/jpeg,image/png,image/webp",onChange:ne,className:"hidden",disabled:E}),E?c.jsx(At,{className:"w-6 h-6 text-bambu-gray animate-spin"}):c.jsx(fr,{className:"w-6 h-6 text-bambu-gray"})]})]}),c.jsx("p",{className:"text-xs text-bambu-gray",children:"Click + to add photos of your printed result"})]}),c.jsxs("div",{className:"flex gap-3 pt-2",children:[c.jsx(Ie,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:"Cancel"}),c.jsxs(Ie,{type:"submit",disabled:W.isPending,className:"flex-1",children:[c.jsx(To,{className:"w-4 h-4"}),W.isPending?"Saving...":"Save"]})]})]})]})})}function Bwe({x:t,y:e,items:n,onClose:r}){const i=M.useRef(null),[s,a]=M.useState(null),o=M.useRef(null);M.useEffect(()=>{const d=m=>{i.current&&!i.current.contains(m.target)&&r()},f=m=>{m.key==="Escape"&&r()},g=()=>{r()};return document.addEventListener("mousedown",d),document.addEventListener("keydown",f),document.addEventListener("scroll",g,!0),()=>{document.removeEventListener("mousedown",d),document.removeEventListener("keydown",f),document.removeEventListener("scroll",g,!0),o.current&&clearTimeout(o.current)}},[r]),M.useEffect(()=>{if(i.current){const d=i.current.getBoundingClientRect(),f=window.innerWidth,g=window.innerHeight;let m=t,x=e;t+d.width>f&&(m=f-d.width-8),e+d.height>g&&(x=g-d.height-8),i.current.style.left=`${m}px`,i.current.style.top=`${x}px`}},[t,e]);const l=d=>{o.current&&(clearTimeout(o.current),o.current=null),a(d)},u=()=>{o.current=window.setTimeout(()=>{a(null)},150)};return c.jsx("div",{ref:i,className:"fixed z-50 min-w-[180px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1",style:{left:t,top:e},children:n.map((d,f)=>{if(d.divider)return c.jsx("div",{className:"my-1 border-t border-bambu-dark-tertiary"},f);const g=d.submenu&&d.submenu.length>0;return c.jsxs("div",{className:"relative",onMouseEnter:()=>g&&l(f),onMouseLeave:()=>g&&u(),children:[c.jsxs("button",{onClick:()=>{g?a(s===f?null:f):d.disabled||(d.onClick(),r())},disabled:d.disabled,className:`w-full flex items-center gap-2 px-3 py-2 text-sm text-left transition-colors ${d.disabled?"text-bambu-gray cursor-not-allowed":d.danger?"text-red-400 hover:bg-red-400/10":"text-white hover:bg-bambu-dark-tertiary"} ${g&&s===f?"bg-bambu-dark-tertiary":""}`,children:[d.icon&&c.jsx("span",{className:"w-4 h-4 flex-shrink-0 flex items-center justify-center",children:d.icon}),c.jsx("span",{className:"flex-1",children:d.label}),g&&c.jsx(tf,{className:"w-4 h-4 text-bambu-gray"})]}),g&&s===f&&c.jsx("div",{className:"absolute left-full top-0 ml-1 min-w-[160px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 overflow-hidden max-h-[300px] overflow-y-auto z-[60]",onMouseEnter:()=>{o.current&&(clearTimeout(o.current),o.current=null)},onMouseLeave:()=>u(),children:d.submenu.map((m,x)=>c.jsxs("button",{onClick:()=>{m.disabled||(m.onClick(),r())},disabled:m.disabled,className:`w-full flex items-center gap-2 px-3 py-2 text-sm text-left transition-colors ${m.disabled?"text-bambu-gray cursor-not-allowed":m.danger?"text-red-400 hover:bg-red-400/10":"text-white hover:bg-bambu-dark-tertiary"}`,children:[m.icon&&c.jsx("span",{className:"w-4 h-4 flex-shrink-0 flex items-center justify-center",children:m.icon}),m.label]},x))})]},f)})})}function Hwe({selectedIds:t,existingTags:e,onClose:n}){const r=Sn(),{showToast:i}=ri(),[s,a]=M.useState(""),[o,l]=M.useState(new Set),[u,d]=M.useState("add");M.useEffect(()=>{const y=v=>{v.key==="Escape"&&n()};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[n]);const f=_t({mutationFn:async()=>{const y=Array.from(o);let v=0;for(const b of t)try{const E=await Pe.getArchive(b),S=E.tags?E.tags.split(",").map(T=>T.trim()).filter(Boolean):[];let A;u==="add"?A=[...new Set([...S,...y])]:A=S.filter(T=>!o.has(T)),await Pe.updateArchive(b,{tags:A.join(", ")}),v++}catch(E){throw console.error(`Failed to update archive ${b}:`,E),new Error(`Failed on archive ${b}: ${E instanceof Error?E.message:"Unknown error"}`)}return{count:v,mode:u,tags:y}},onSuccess:({count:y,mode:v,tags:b})=>{r.invalidateQueries({queryKey:["archives"]}),i(`${v==="add"?"Added":"Removed"} ${b.length} tag${b.length!==1?"s":""} ${v==="add"?"to":"from"} ${y} archive${y!==1?"s":""}`),n()},onError:y=>{i(y.message||"Failed to update tags","error")}}),g=y=>{l(v=>{const b=new Set(v);return b.has(y)?b.delete(y):b.add(y),b})},m=()=>{s.trim()&&!o.has(s.trim())&&(l(y=>new Set([...y,s.trim()])),a(""))},x=y=>{y.key==="Enter"&&(y.preventDefault(),m())};return c.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:c.jsx(Nt,{className:"w-full max-w-md",children:c.jsxs(Dt,{className:"p-0",children:[c.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(f0,{className:"w-5 h-5 text-bambu-green"}),c.jsx("h2",{className:"text-xl font-semibold text-white",children:u==="add"?"Add Tags":"Remove Tags"})]}),c.jsx("button",{onClick:n,className:"text-bambu-gray hover:text-white transition-colors",children:c.jsx(Gt,{className:"w-5 h-5"})})]}),c.jsxs("div",{className:"p-4 space-y-4",children:[c.jsxs("p",{className:"text-sm text-bambu-gray",children:[u==="add"?"Add":"Remove"," tags for ",t.length," selected archive",t.length!==1?"s":""]}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(Ie,{size:"sm",variant:u==="add"?"primary":"secondary",onClick:()=>d("add"),children:"Add Tags"}),c.jsx(Ie,{size:"sm",variant:u==="remove"?"primary":"secondary",onClick:()=>d("remove"),children:"Remove Tags"})]}),u==="add"&&c.jsxs("div",{className:"flex gap-2",children:[c.jsx("input",{type:"text",placeholder:"Enter new tag...",className:"flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none",value:s,onChange:y=>a(y.target.value),onKeyDown:x}),c.jsx(Ie,{size:"sm",variant:"secondary",onClick:m,disabled:!s.trim(),children:c.jsx(fr,{className:"w-4 h-4"})})]}),e.length>0&&c.jsxs("div",{children:[c.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:"Existing tags:"}),c.jsx("div",{className:"flex flex-wrap gap-2",children:e.map(y=>c.jsx("button",{onClick:()=>g(y),className:`px-2 py-1 rounded text-sm transition-colors ${o.has(y)?"bg-bambu-green text-white":"bg-bambu-dark-tertiary text-bambu-gray-light hover:bg-bambu-dark"}`,children:y},y))})]}),o.size>0&&c.jsxs("div",{children:[c.jsxs("p",{className:"text-xs text-bambu-gray mb-2",children:["Tags to ",u==="add"?"add":"remove",":"]}),c.jsx("div",{className:"flex flex-wrap gap-2",children:Array.from(o).map(y=>c.jsxs("span",{className:`px-2 py-1 rounded text-sm flex items-center gap-1 ${u==="add"?"bg-green-500/20 text-green-400":"bg-red-500/20 text-red-400"}`,children:[y,c.jsx("button",{onClick:()=>g(y),className:"hover:opacity-70",children:c.jsx(Gt,{className:"w-3 h-3"})})]},y))})]})]}),c.jsxs("div",{className:"flex gap-3 p-4 border-t border-bambu-dark-tertiary",children:[c.jsx(Ie,{variant:"secondary",onClick:n,className:"flex-1",children:"Cancel"}),c.jsx(Ie,{onClick:()=>f.mutate(),disabled:o.size===0||f.isPending,className:"flex-1",children:f.isPending?c.jsxs(c.Fragment,{children:[c.jsx(At,{className:"w-4 h-4 animate-spin"}),"Processing..."]}):c.jsxs(c.Fragment,{children:[c.jsx(f0,{className:"w-4 h-4"}),u==="add"?"Add Tags":"Remove Tags"]})})]})]})})})}function $we(t,e){return new Date(t,e+1,0).getDate()}function Vwe(t,e){return new Date(t,e,1).getDay()}const Gwe=["January","February","March","April","May","June","July","August","September","October","November","December"],Wwe=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];function qwe({archives:t,onArchiveClick:e}){const n=new Date,[r,i]=M.useState(n.getMonth()),[s,a]=M.useState(n.getFullYear()),[o,l]=M.useState(null),u=M.useMemo(()=>{const b=new Map;return t.forEach(E=>{const S=new Date(E.completed_at||E.created_at),A=`${S.getFullYear()}-${String(S.getMonth()+1).padStart(2,"0")}-${String(S.getDate()).padStart(2,"0")}`,T=b.get(A)||[];T.push(E),b.set(A,T)}),b},[t]),d=$we(s,r),f=Vwe(s,r),g=()=>{r===0?(i(11),a(s-1)):i(r-1)},m=()=>{r===11?(i(0),a(s+1)):i(r+1)},x=()=>{i(n.getMonth()),a(n.getFullYear())},y=[];for(let b=0;bc.jsx("div",{className:"text-center text-xs text-bambu-gray py-2",children:b},b))}),c.jsx("div",{className:"grid grid-cols-7 gap-1",children:y.map((b,E)=>{if(b===null)return c.jsx("div",{className:"aspect-square"},`empty-${E}`);const S=`${s}-${String(r+1).padStart(2,"0")}-${String(b).padStart(2,"0")}`,A=u.get(S)||[],T=A.length>0,P=b===n.getDate()&&r===n.getMonth()&&s===n.getFullYear(),C=S===o,I=A.filter(D=>D.status==="completed").length,N=A.filter(D=>D.status==="failed").length;return c.jsxs("button",{onClick:()=>l(C?null:S),className:`aspect-square rounded-lg p-1 flex flex-col items-center justify-center transition-colors relative ${C?"bg-bambu-green text-white":P?"bg-bambu-green/20 text-white ring-2 ring-bambu-green":T?"bg-bambu-dark-tertiary hover:bg-bambu-dark-tertiary/70 text-white":"hover:bg-bambu-dark-tertiary/50 text-bambu-gray"}`,children:[c.jsx("span",{className:`text-sm font-medium ${P&&!C?"text-bambu-green":""}`,children:b}),T&&c.jsxs("div",{className:"absolute bottom-1 left-1/2 -translate-x-1/2 flex items-center gap-1",children:[c.jsx("div",{className:`w-2 h-2 rounded-full ${N>0&&I===0?"bg-red-400":N>0?"bg-yellow-400":"bg-green-400"}`}),c.jsx("span",{className:"text-xs font-medium",children:A.length})]})]},b)})}),c.jsx("div",{className:"mt-4 pt-4 border-t border-bambu-dark-tertiary",children:c.jsxs("div",{className:"grid grid-cols-3 gap-4 text-center",children:[c.jsxs("div",{children:[c.jsx("div",{className:"text-2xl font-bold text-white",children:t.filter(b=>{const E=new Date(b.completed_at||b.created_at);return E.getMonth()===r&&E.getFullYear()===s}).length}),c.jsx("div",{className:"text-xs text-bambu-gray",children:"Prints this month"})]}),c.jsxs("div",{children:[c.jsx("div",{className:"text-2xl font-bold text-green-400",children:t.filter(b=>{const E=new Date(b.completed_at||b.created_at);return E.getMonth()===r&&E.getFullYear()===s&&b.status==="completed"}).length}),c.jsx("div",{className:"text-xs text-bambu-gray",children:"Successful"})]}),c.jsxs("div",{children:[c.jsx("div",{className:"text-2xl font-bold text-red-400",children:t.filter(b=>{const E=new Date(b.completed_at||b.created_at);return E.getMonth()===r&&E.getFullYear()===s&&b.status==="failed"}).length}),c.jsx("div",{className:"text-xs text-bambu-gray",children:"Failed"})]})]})})]}),c.jsx("div",{className:"lg:w-80 bg-bambu-dark rounded-xl p-4",children:o?c.jsxs(c.Fragment,{children:[c.jsx("h3",{className:"text-sm font-medium text-bambu-gray mb-3",children:new Date(o+"T12:00:00").toLocaleDateString("en-US",{weekday:"long",month:"long",day:"numeric",year:"numeric"})}),v.length>0?c.jsx("div",{className:"space-y-2 max-h-96 overflow-y-auto",children:v.map(b=>c.jsxs("button",{onClick:()=>e?.(b),className:"w-full flex items-center gap-3 p-2 rounded-lg hover:bg-bambu-dark-tertiary transition-colors text-left",children:[b.thumbnail_path?c.jsx("img",{src:Pe.getArchiveThumbnail(b.id),alt:"",className:"w-12 h-12 rounded object-cover"}):c.jsx("div",{className:"w-12 h-12 rounded bg-bambu-dark-tertiary flex items-center justify-center",children:c.jsx("span",{className:"text-xs text-bambu-gray",children:"3MF"})}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsx("p",{className:"text-sm text-white truncate",children:b.print_name||b.filename}),c.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[c.jsx("span",{className:b.status==="failed"?"text-red-400":"text-green-400",children:b.status==="failed"?"Failed":"Completed"}),b.filament_color&&c.jsx("div",{className:"flex gap-0.5",children:b.filament_color.split(",").map((E,S)=>c.jsx("div",{className:"w-3 h-3 rounded-full border border-white/20",style:{backgroundColor:E}},S))})]})]})]},b.id))}):c.jsx("p",{className:"text-sm text-bambu-gray",children:"No prints on this day"})]}):c.jsx("div",{className:"text-center py-8",children:c.jsx("p",{className:"text-sm text-bambu-gray",children:"Select a day to see prints"})})})]})}function Kwe({archiveId:t,archiveName:e,onClose:n}){const r=Pe.getArchiveQRCodeUrl(t,300);M.useEffect(()=>{const s=a=>{a.key==="Escape"&&n()};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[n]);const i=()=>{const s=document.createElement("a");s.href=r,s.download=`${e}_qrcode.png`,s.click()};return c.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:n,children:c.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-sm",onClick:s=>s.stopPropagation(),children:[c.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[c.jsx("h2",{className:"text-lg font-semibold text-white",children:"QR Code"}),c.jsx("button",{onClick:n,className:"text-bambu-gray hover:text-white transition-colors",children:c.jsx(Gt,{className:"w-5 h-5"})})]}),c.jsxs("div",{className:"p-6 flex flex-col items-center",children:[c.jsx("p",{className:"text-sm text-bambu-gray mb-4 text-center truncate max-w-full",children:e}),c.jsx("div",{className:"bg-white p-4 rounded-lg mb-4",children:c.jsx("img",{src:r,alt:"QR Code",className:"w-64 h-64"})}),c.jsx("p",{className:"text-xs text-bambu-gray mb-4 text-center",children:"Scan to open this archive"}),c.jsxs(Ie,{onClick:i,className:"w-full",children:[c.jsx(ya,{className:"w-4 h-4"}),"Download QR Code"]})]})]})})}function Xwe({archiveId:t,archiveName:e,photos:n,onClose:r,onDelete:i}){const[s,a]=M.useState(0),[o,l]=M.useState(!1);if(M.useEffect(()=>{const m=x=>{x.key==="Escape"&&r(),x.key==="ArrowLeft"&&a(y=>Math.max(0,y-1)),x.key==="ArrowRight"&&a(y=>Math.min(n.length-1,y+1))};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[r,n.length]),M.useEffect(()=>{s>=n.length&&a(Math.max(0,n.length-1))},[n.length,s]),n.length===0)return r(),null;const u=n[s],d=Pe.getArchivePhotoUrl(t,u),f=()=>{const m=document.createElement("a");m.href=d,m.download=`${e}_photo_${s+1}.jpg`,m.click()},g=()=>{i&&l(!0)};return c.jsxs("div",{className:"fixed inset-0 bg-black/90 flex items-center justify-center z-50",onClick:r,children:[c.jsxs("div",{className:"relative w-full h-full flex flex-col",onClick:m=>m.stopPropagation(),children:[c.jsxs("div",{className:"flex items-center justify-between px-6 py-4 bg-black/50",children:[c.jsxs("div",{children:[c.jsx("h2",{className:"text-lg font-semibold text-white",children:e}),c.jsxs("p",{className:"text-sm text-bambu-gray",children:["Photo ",s+1," of ",n.length]})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs(Ie,{variant:"secondary",size:"sm",onClick:f,children:[c.jsx(ya,{className:"w-4 h-4"}),"Download"]}),i&&c.jsx(Ie,{variant:"secondary",size:"sm",onClick:g,className:"text-red-400 hover:text-red-300",children:c.jsx(kn,{className:"w-4 h-4"})}),c.jsx("button",{onClick:r,className:"p-2 text-bambu-gray hover:text-white transition-colors",children:c.jsx(Gt,{className:"w-6 h-6"})})]})]}),c.jsxs("div",{className:"flex-1 min-h-0 flex items-center justify-center p-4 relative overflow-hidden",children:[s>0&&c.jsx("button",{onClick:()=>a(m=>m-1),className:"absolute left-4 z-10 p-3 bg-black/50 hover:bg-black/70 rounded-full transition-colors",children:c.jsx(Rh,{className:"w-8 h-8 text-white"})}),c.jsx("img",{src:d,alt:`Photo ${s+1}`,className:"max-w-full max-h-full object-contain rounded-lg",style:{maxHeight:"calc(100vh - 200px)"}}),sa(m=>m+1),className:"absolute right-4 z-10 p-3 bg-black/50 hover:bg-black/70 rounded-full transition-colors",children:c.jsx(tf,{className:"w-8 h-8 text-white"})})]}),n.length>1&&c.jsx("div",{className:"flex justify-center gap-2 p-4 bg-black/50",children:n.map((m,x)=>c.jsx("button",{onClick:()=>a(x),className:`w-16 h-16 rounded-lg overflow-hidden border-2 transition-colors ${x===s?"border-bambu-green":"border-transparent hover:border-bambu-gray"}`,children:c.jsx("img",{src:Pe.getArchivePhotoUrl(t,m),alt:`Thumbnail ${x+1}`,className:"w-full h-full object-cover"})},m))})]}),o&&c.jsx(Kr,{title:"Delete Photo",message:"Delete this photo? This cannot be undone.",confirmText:"Delete",variant:"danger",onConfirm:()=>{i?.(u),l(!1)},onCancel:()=>l(!1)})]})}function qi(t){this.content=t}qi.prototype={constructor:qi,find:function(t){for(var e=0;e>1}};qi.from=function(t){if(t instanceof qi)return t;var e=[];if(t)for(var n in t)e.push(n,t[n]);return new qi(e)};function pW(t,e,n){for(let r=0;;r++){if(r==t.childCount||r==e.childCount)return t.childCount==e.childCount?null:n;let i=t.child(r),s=e.child(r);if(i==s){n+=i.nodeSize;continue}if(!i.sameMarkup(s))return n;if(i.isText&&i.text!=s.text){for(let a=0;i.text[a]==s.text[a];a++)n++;return n}if(i.content.size||s.content.size){let a=pW(i.content,s.content,n+1);if(a!=null)return a}n+=i.nodeSize}}function mW(t,e,n,r){for(let i=t.childCount,s=e.childCount;;){if(i==0||s==0)return i==s?null:{a:n,b:r};let a=t.child(--i),o=e.child(--s),l=a.nodeSize;if(a==o){n-=l,r-=l;continue}if(!a.sameMarkup(o))return{a:n,b:r};if(a.isText&&a.text!=o.text){let u=0,d=Math.min(a.text.length,o.text.length);for(;ue&&r(l,i+o,s||null,a)!==!1&&l.content.size){let d=o+1;l.nodesBetween(Math.max(0,e-d),Math.min(l.content.size,n-d),r,i+d)}o=u}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,n,r,i){let s="",a=!0;return this.nodesBetween(e,n,(o,l)=>{let u=o.isText?o.text.slice(Math.max(e,l)-l,n-l):o.isLeaf?i?typeof i=="function"?i(o):i:o.type.spec.leafText?o.type.spec.leafText(o):"":"";o.isBlock&&(o.isLeaf&&u||o.isTextblock)&&r&&(a?a=!1:s+=r),s+=u},0),s}append(e){if(!e.size)return this;if(!this.size)return e;let n=this.lastChild,r=e.firstChild,i=this.content.slice(),s=0;for(n.isText&&n.sameMarkup(r)&&(i[i.length-1]=n.withText(n.text+r.text),s=1);se)for(let s=0,a=0;ae&&((an)&&(o.isText?o=o.cut(Math.max(0,e-a),Math.min(o.text.length,n-a)):o=o.cut(Math.max(0,e-a-1),Math.min(o.content.size,n-a-1))),r.push(o),i+=o.nodeSize),a=l}return new pt(r,i)}cutByIndex(e,n){return e==n?pt.empty:e==0&&n==this.content.length?this:new pt(this.content.slice(e,n))}replaceChild(e,n){let r=this.content[e];if(r==n)return this;let i=this.content.slice(),s=this.size+n.nodeSize-r.nodeSize;return i[e]=n,new pt(i,s)}addToStart(e){return new pt([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new pt(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let n=0;nthis.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let n=0,r=0;;n++){let i=this.child(n),s=r+i.nodeSize;if(s>=e)return s==e?e_(n+1,s):e_(n,r);r=s}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,n){if(!n)return pt.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return new pt(n.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return pt.empty;let n,r=0;for(let i=0;ithis.type.rank&&(n||(n=e.slice(0,i)),n.push(this),r=!0),n&&n.push(s)}}return n||(n=e.slice()),r||n.push(this),n}removeFromSet(e){for(let n=0;nr.type.rank-i.type.rank),n}};Qn.none=[];class E1 extends Error{}class Tt{constructor(e,n,r){this.content=e,this.openStart=n,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,n){let r=xW(this.content,e+this.openStart,n);return r&&new Tt(r,this.openStart,this.openEnd)}removeBetween(e,n){return new Tt(gW(this.content,e+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,n){if(!n)return Tt.empty;let r=n.openStart||0,i=n.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new Tt(pt.fromJSON(e,n.content),r,i)}static maxOpen(e,n=!0){let r=0,i=0;for(let s=e.firstChild;s&&!s.isLeaf&&(n||!s.type.spec.isolating);s=s.firstChild)r++;for(let s=e.lastChild;s&&!s.isLeaf&&(n||!s.type.spec.isolating);s=s.lastChild)i++;return new Tt(e,r,i)}}Tt.empty=new Tt(pt.empty,0,0);function gW(t,e,n){let{index:r,offset:i}=t.findIndex(e),s=t.maybeChild(r),{index:a,offset:o}=t.findIndex(n);if(i==e||s.isText){if(o!=n&&!t.child(a).isText)throw new RangeError("Removing non-flat range");return t.cut(0,e).append(t.cut(n))}if(r!=a)throw new RangeError("Removing non-flat range");return t.replaceChild(r,s.copy(gW(s.content,e-i-1,n-i-1)))}function xW(t,e,n,r){let{index:i,offset:s}=t.findIndex(e),a=t.maybeChild(i);if(s==e||a.isText)return r&&!r.canReplace(i,i,n)?null:t.cut(0,e).append(n).append(t.cut(e));let o=xW(a.content,e-s-1,n,a);return o&&t.replaceChild(i,a.copy(o))}function Ywe(t,e,n){if(n.openStart>t.depth)throw new E1("Inserted content deeper than insertion position");if(t.depth-n.openStart!=e.depth-n.openEnd)throw new E1("Inconsistent open depths");return bW(t,e,n,0)}function bW(t,e,n,r){let i=t.index(r),s=t.node(r);if(i==e.index(r)&&r=0&&t.isText&&t.sameMarkup(e[n])?e[n]=t.withText(e[n].text+t.text):e.push(t)}function zx(t,e,n,r){let i=(e||t).node(n),s=0,a=e?e.index(n):i.childCount;t&&(s=t.index(n),t.depth>n?s++:t.textOffset&&(bh(t.nodeAfter,r),s++));for(let o=s;oi&&mk(t,e,i+1),a=r.depth>i&&mk(n,r,i+1),o=[];return zx(null,t,i,o),s&&a&&e.index(i)==n.index(i)?(vW(s,a),bh(vh(s,yW(t,e,n,r,i+1)),o)):(s&&bh(vh(s,M1(t,e,i+1)),o),zx(e,n,i,o),a&&bh(vh(a,M1(n,r,i+1)),o)),zx(r,null,i,o),new pt(o)}function M1(t,e,n){let r=[];if(zx(null,t,n,r),t.depth>n){let i=mk(t,e,n+1);bh(vh(i,M1(t,e,n+1)),r)}return zx(e,null,n,r),new pt(r)}function Zwe(t,e){let n=e.depth-t.openStart,i=e.node(n).copy(t.content);for(let s=n-1;s>=0;s--)i=e.node(s).copy(pt.from(i));return{start:i.resolveNoCache(t.openStart+n),end:i.resolveNoCache(i.content.size-t.openEnd-n)}}class M0{constructor(e,n,r){this.pos=e,this.path=n,this.parentOffset=r,this.depth=n.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,n=this.index(this.depth);if(n==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],i=e.child(n);return r?e.child(n).cut(r):i}get nodeBefore(){let e=this.index(this.depth),n=this.pos-this.path[this.path.length-1];return n?this.parent.child(e).cut(0,n):e==0?null:this.parent.child(e-1)}posAtIndex(e,n){n=this.resolveDepth(n);let r=this.path[n*3],i=n==0?0:this.path[n*3-1]+1;for(let s=0;s0;n--)if(this.start(n)<=e&&this.end(n)>=e)return n;return 0}blockRange(e=this,n){if(e.pos=0;r--)if(e.pos<=this.end(r)&&(!n||n(this.node(r))))return new A1(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&n<=e.content.size))throw new RangeError("Position "+n+" out of range");let r=[],i=0,s=n;for(let a=e;;){let{index:o,offset:l}=a.content.findIndex(s),u=s-l;if(r.push(a,o,i+l),!u||(a=a.child(o),a.isText))break;s=u-1,i+=l+1}return new M0(n,r,s)}static resolveCached(e,n){let r=DB.get(e);if(r)for(let s=0;se&&this.nodesBetween(e,n,s=>(r.isInSet(s.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),_W(this.marks,e)}contentMatchAt(e){let n=this.type.contentMatch.matchFragment(this.content,0,e);if(!n)throw new Error("Called contentMatchAt on a node with invalid content");return n}canReplace(e,n,r=pt.empty,i=0,s=r.childCount){let a=this.contentMatchAt(e).matchFragment(r,i,s),o=a&&a.matchFragment(this.content,n);if(!o||!o.validEnd)return!1;for(let l=i;ln.type.name)}`);this.content.forEach(n=>n.check())}toJSON(){let e={type:this.type.name};for(let n in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(n=>n.toJSON())),e}static fromJSON(e,n){if(!n)throw new RangeError("Invalid input for Node.fromJSON");let r;if(n.marks){if(!Array.isArray(n.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=n.marks.map(e.markFromJSON)}if(n.type=="text"){if(typeof n.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(n.text,r)}let i=pt.fromJSON(e,n.content),s=e.nodeType(n.type).create(n.attrs,i,r);return s.type.checkAttrs(s.attrs),s}};Wu.prototype.text=void 0;class T1 extends Wu{constructor(e,n,r,i){if(super(e,n,null,i),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):_W(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,n){return this.text.slice(e,n)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new T1(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new T1(this.type,this.attrs,e,this.marks)}cut(e=0,n=this.text.length){return e==0&&n==this.text.length?this:this.withText(this.text.slice(e,n))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}}function _W(t,e){for(let n=t.length-1;n>=0;n--)e=t[n].type.name+"("+e+")";return e}class Hh{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,n){let r=new tSe(e,n);if(r.next==null)return Hh.empty;let i=wW(r);r.next&&r.err("Unexpected trailing text");let s=lSe(oSe(i));return cSe(s,r),s}matchType(e){for(let n=0;nu.createAndFill()));for(let u=0;u=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function n(r){e.push(r);for(let i=0;i{let s=i+(r.validEnd?"*":" ")+" ";for(let a=0;a"+e.indexOf(r.next[a].next);return s}).join(` +`)}}Hh.empty=new Hh(!0);class tSe{constructor(e,n){this.string=e,this.nodeTypes=n,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}}function wW(t){let e=[];do e.push(nSe(t));while(t.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function nSe(t){let e=[];do e.push(rSe(t));while(t.next&&t.next!=")"&&t.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function rSe(t){let e=aSe(t);for(;;)if(t.eat("+"))e={type:"plus",expr:e};else if(t.eat("*"))e={type:"star",expr:e};else if(t.eat("?"))e={type:"opt",expr:e};else if(t.eat("{"))e=iSe(t,e);else break;return e}function OB(t){/\D/.test(t.next)&&t.err("Expected number, got '"+t.next+"'");let e=Number(t.next);return t.pos++,e}function iSe(t,e){let n=OB(t),r=n;return t.eat(",")&&(t.next!="}"?r=OB(t):r=-1),t.eat("}")||t.err("Unclosed braced range"),{type:"range",min:n,max:r,expr:e}}function sSe(t,e){let n=t.nodeTypes,r=n[e];if(r)return[r];let i=[];for(let s in n){let a=n[s];a.isInGroup(e)&&i.push(a)}return i.length==0&&t.err("No node type or group '"+e+"' found"),i}function aSe(t){if(t.eat("(")){let e=wW(t);return t.eat(")")||t.err("Missing closing paren"),e}else if(/\W/.test(t.next))t.err("Unexpected token '"+t.next+"'");else{let e=sSe(t,t.next).map(n=>(t.inline==null?t.inline=n.isInline:t.inline!=n.isInline&&t.err("Mixing inline and block content"),{type:"name",value:n}));return t.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function oSe(t){let e=[[]];return i(s(t,0),n()),e;function n(){return e.push([])-1}function r(a,o,l){let u={term:l,to:o};return e[a].push(u),u}function i(a,o){a.forEach(l=>l.to=o)}function s(a,o){if(a.type=="choice")return a.exprs.reduce((l,u)=>l.concat(s(u,o)),[]);if(a.type=="seq")for(let l=0;;l++){let u=s(a.exprs[l],o);if(l==a.exprs.length-1)return u;i(u,o=n())}else if(a.type=="star"){let l=n();return r(o,l),i(s(a.expr,l),l),[r(l)]}else if(a.type=="plus"){let l=n();return i(s(a.expr,o),l),i(s(a.expr,l),l),[r(l)]}else{if(a.type=="opt")return[r(o)].concat(s(a.expr,o));if(a.type=="range"){let l=o;for(let u=0;u{t[a].forEach(({term:o,to:l})=>{if(!o)return;let u;for(let d=0;d{u||i.push([o,u=[]]),u.indexOf(d)==-1&&u.push(d)})})});let s=e[r.join(",")]=new Hh(r.indexOf(t.length-1)>-1);for(let a=0;a-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:MW(this.attrs,e)}create(e=null,n,r){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new Wu(this,this.computeAttrs(e),pt.from(n),Qn.setFrom(r))}createChecked(e=null,n,r){return n=pt.from(n),this.checkContent(n),new Wu(this,this.computeAttrs(e),n,Qn.setFrom(r))}createAndFill(e=null,n,r){if(e=this.computeAttrs(e),n=pt.from(n),n.size){let a=this.contentMatch.fillBefore(n);if(!a)return null;n=a.append(n)}let i=this.contentMatch.matchFragment(n),s=i&&i.fillBefore(pt.empty,!0);return s?new Wu(this,e,n.append(s),Qn.setFrom(r)):null}validContent(e){let n=this.contentMatch.matchFragment(e);if(!n||!n.validEnd)return!1;for(let r=0;r-1}allowsMarks(e){if(this.markSet==null)return!0;for(let n=0;nr[s]=new CW(s,n,a));let i=n.spec.topNode||"doc";if(!r[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let s in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function uSe(t,e,n){let r=n.split("|");return i=>{let s=i===null?"null":typeof i;if(r.indexOf(s)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${t}, got ${s}`)}}class dSe{constructor(e,n,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?uSe(e,n,r.validate):r.validate}get isRequired(){return!this.hasDefault}}class RS{constructor(e,n,r,i){this.name=e,this.rank=n,this.schema=r,this.spec=i,this.attrs=TW(e,i.attrs),this.excluded=null;let s=EW(this.attrs);this.instance=s?new Qn(this,s):null}create(e=null){return!e&&this.instance?this.instance:new Qn(this,MW(this.attrs,e))}static compile(e,n){let r=Object.create(null),i=0;return e.forEach((s,a)=>r[s]=new RS(s,i++,n,a)),r}removeFromSet(e){for(var n=0;n-1}}class NW{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let n=this.spec={};for(let i in e)n[i]=e[i];n.nodes=qi.from(e.nodes),n.marks=qi.from(e.marks||{}),this.nodes=LB.compile(this.spec.nodes,this),this.marks=RS.compile(this.spec.marks,this);let r=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let s=this.nodes[i],a=s.spec.content||"",o=s.spec.marks;if(s.contentMatch=r[a]||(r[a]=Hh.parse(a,this.nodes)),s.inlineContent=s.contentMatch.inlineContent,s.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!s.isInline||!s.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=s}s.markSet=o=="_"?null:o?IB(this,o.split(" ")):o==""||!s.inlineContent?[]:null}for(let i in this.marks){let s=this.marks[i],a=s.spec.excludes;s.excluded=a==null?[s]:a==""?[]:IB(this,a.split(" "))}this.nodeFromJSON=i=>Wu.fromJSON(this,i),this.markFromJSON=i=>Qn.fromJSON(this,i),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,n=null,r,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof LB){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(n,r,i)}text(e,n){let r=this.nodes.text;return new T1(r,r.defaultAttrs,e,Qn.setFrom(n))}mark(e,n){return typeof e=="string"&&(e=this.marks[e]),e.create(n)}nodeType(e){let n=this.nodes[e];if(!n)throw new RangeError("Unknown node type: "+e);return n}}function IB(t,e){let n=[];for(let r=0;r-1)&&n.push(a=l)}if(!a)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return n}function hSe(t){return t.tag!=null}function fSe(t){return t.style!=null}let Bx=class xk{constructor(e,n){this.schema=e,this.rules=n,this.tags=[],this.styles=[];let r=this.matchedStyles=[];n.forEach(i=>{if(hSe(i))this.tags.push(i);else if(fSe(i)){let s=/[^=]*/.exec(i.style)[0];r.indexOf(s)<0&&r.push(s),this.styles.push(i)}}),this.normalizeLists=!this.tags.some(i=>{if(!/^(ul|ol)\b/.test(i.tag)||!i.node)return!1;let s=e.nodes[i.node];return s.contentMatch.matchType(s)})}parse(e,n={}){let r=new FB(this,n,!1);return r.addAll(e,Qn.none,n.from,n.to),r.finish()}parseSlice(e,n={}){let r=new FB(this,n,!0);return r.addAll(e,Qn.none,n.from,n.to),Tt.maxOpen(r.finish())}matchTag(e,n,r){for(let i=r?this.tags.indexOf(r)+1:0;ie.length&&(o.charCodeAt(e.length)!=61||o.slice(e.length+1)!=n))){if(a.getAttrs){let l=a.getAttrs(n);if(l===!1)continue;a.attrs=l||void 0}return a}}}static schemaRules(e){let n=[];function r(i){let s=i.priority==null?50:i.priority,a=0;for(;a{r(a=zB(a)),a.mark||a.ignore||a.clearMark||(a.mark=i)})}for(let i in e.nodes){let s=e.nodes[i].spec.parseDOM;s&&s.forEach(a=>{r(a=zB(a)),a.node||a.ignore||a.mark||(a.node=i)})}return n}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new xk(e,xk.schemaRules(e)))}};const kW={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},pSe={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},PW={ol:!0,ul:!0},A0=1,bk=2,Hx=4;function UB(t,e,n){return e!=null?(e?A0:0)|(e==="full"?bk:0):t&&t.whitespace=="pre"?A0|bk:n&~Hx}class t_{constructor(e,n,r,i,s,a){this.type=e,this.attrs=n,this.marks=r,this.solid=i,this.options=a,this.content=[],this.activeMarks=Qn.none,this.match=s||(a&Hx?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let n=this.type.contentMatch.fillBefore(pt.from(e));if(n)this.match=this.type.contentMatch.matchFragment(n);else{let r=this.type.contentMatch,i;return(i=r.findWrapping(e.type))?(this.match=r,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&A0)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let s=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=s.withText(s.text.slice(0,s.text.length-i[0].length))}}let n=pt.from(this.content);return!e&&this.match&&(n=n.append(this.match.fillBefore(pt.empty,!0))),this.type?this.type.create(this.attrs,n,this.marks):n}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!kW.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class FB{constructor(e,n,r){this.parser=e,this.options=n,this.isOpen=r,this.open=0,this.localPreserveWS=!1;let i=n.topNode,s,a=UB(null,n.preserveWhitespace,0)|(r?Hx:0);i?s=new t_(i.type,i.attrs,Qn.none,!0,n.topMatch||i.type.contentMatch,a):r?s=new t_(null,null,Qn.none,!0,null,a):s=new t_(e.schema.topNodeType,null,Qn.none,!0,null,a),this.nodes=[s],this.find=n.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,n){e.nodeType==3?this.addTextNode(e,n):e.nodeType==1&&this.addElement(e,n)}addTextNode(e,n){let r=e.nodeValue,i=this.top,s=i.options&bk?"full":this.localPreserveWS||(i.options&A0)>0,{schema:a}=this.parser;if(s==="full"||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(r)){if(s)if(s==="full")r=r.replace(/\r\n?/g,` `);else if(a.linebreakReplacement&&/[\r\n]/.test(r)&&this.top.findWrapping(a.linebreakReplacement.create())){let o=r.split(/\r?\n|\r/);for(let l=0;l!l.clearMark(u)):n=n.concat(this.parser.schema.marks[l.mark].create(l.attrs)),l.consuming===!1)o=l;else break}}return n}addElementByRule(e,n,r,i){let s,a;if(n.node)if(a=this.parser.schema.nodes[n.node],a.isLeaf)this.insertNode(a.create(n.attrs),r,e.nodeName=="BR")||this.leafFallback(e,r);else{let l=this.enter(a,n.attrs||null,r,n.preserveWhitespace);l&&(s=!0,r=l)}else{let l=this.parser.schema.marks[n.mark];r=r.concat(l.create(n.attrs))}let o=this.top;if(a&&a.isLeaf)this.findInside(e);else if(i)this.addElement(e,r,i);else if(n.getContent)this.findInside(e),n.getContent(e,this.parser.schema).forEach(l=>this.insertNode(l,r,!1));else{let l=e;typeof n.contentElement=="string"?l=e.querySelector(n.contentElement):typeof n.contentElement=="function"?l=n.contentElement(e):n.contentElement&&(l=n.contentElement),this.findAround(e,l,!0),this.addAll(l,r),this.findAround(e,l,!1)}s&&this.sync(o)&&this.open--}addAll(e,n,r,i){let s=r||0;for(let a=r?e.childNodes[r]:e.firstChild,o=i==null?null:e.childNodes[i];a!=o;a=a.nextSibling,++s)this.findAtPoint(e,s),this.addDOM(a,n);this.findAtPoint(e,s)}findPlace(e,n,r){let i,s;for(let a=this.open,o=0;a>=0;a--){let l=this.nodes[a],u=l.findWrapping(e);if(u&&(!i||i.length>u.length+o)&&(i=u,s=l,!u.length))break;if(l.solid){if(r)break;o+=2}}if(!i)return null;this.sync(s);for(let a=0;a(a.type?a.type.allowsMarkType(u.type):BB(u.type,e))?(l=u.addToSet(l),!1):!0),this.nodes.push(new t_(e,n,l,i,null,o)),this.open++,r}closeExtra(e=!1){let n=this.nodes.length-1;if(n>this.open){for(;n>this.open;n--)this.nodes[n-1].content.push(this.nodes[n].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(e){for(let n=this.open;n>=0;n--){if(this.nodes[n]==e)return this.open=n,!0;this.localPreserveWS&&(this.nodes[n].options|=A0)}return!1}get currentPos(){this.closeExtra();let e=0;for(let n=this.open;n>=0;n--){let r=this.nodes[n].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;n&&e++}return e}findAtPoint(e,n){if(this.find)for(let r=0;r-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let n=e.split("/"),r=this.options.context,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),s=-(r?r.depth+1:0)+(i?0:1),a=(o,l)=>{for(;o>=0;o--){let u=n[o];if(u==""){if(o==n.length-1||o==0)continue;for(;l>=s;l--)if(a(o-1,l))return!0;return!1}else{let d=l>0||l==0&&i?this.nodes[l].type:r&&l>=s?r.node(l-s).type:null;if(!d||d.name!=u&&!d.isInGroup(u))return!1;l--}}return!0};return a(n.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let n=e.depth;n>=0;n--){let r=e.node(n).contentMatchAt(e.indexAfter(n)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let n in this.parser.schema.nodes){let r=this.parser.schema.nodes[n];if(r.isTextblock&&r.defaultAttrs)return r}}}function mSe(t){for(let e=t.firstChild,n=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&PW.hasOwnProperty(r)&&n?(n.appendChild(e),e=n):r=="li"?n=e:r&&(n=null)}}function gSe(t,e){return(t.matches||t.msMatchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector).call(t,e)}function zB(t){let e={};for(let n in t)e[n]=t[n];return e}function BB(t,e){let n=e.schema.nodes;for(let r in n){let i=n[r];if(!i.allowsMarkType(t))continue;let s=[],a=o=>{s.push(o);for(let l=0;l{if(s.length||a.marks.length){let o=0,l=0;for(;o=0;i--){let s=this.serializeMark(e.marks[i],e.isInline,n);s&&((s.contentDOM||s.dom).appendChild(r),r=s.dom)}return r}serializeMark(e,n,r={}){let i=this.marks[e.type.name];return i&&V_(NT(r),i(e,n),null,e.attrs)}static renderSpec(e,n,r=null,i){return V_(e,n,r,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new sf(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let n=HB(e.nodes);return n.text||(n.text=r=>r.text),n}static marksFromSchema(e){return HB(e.marks)}}function HB(t){let e={};for(let n in t){let r=t[n].spec.toDOM;r&&(e[n]=r)}return e}function NT(t){return t.document||window.document}const $B=new WeakMap;function xSe(t){let e=$B.get(t);return e===void 0&&$B.set(t,e=bSe(t)),e}function bSe(t){let e=null;function n(r){if(r&&typeof r=="object")if(Array.isArray(r))if(typeof r[0]=="string")e||(e=[]),e.push(r);else for(let i=0;i-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let a=i.indexOf(" ");a>0&&(n=i.slice(0,a),i=i.slice(a+1));let o,l=n?t.createElementNS(n,i):t.createElement(i),u=e[1],d=1;if(u&&typeof u=="object"&&u.nodeType==null&&!Array.isArray(u)){d=2;for(let f in u)if(u[f]!=null){let g=f.indexOf(" ");g>0?l.setAttributeNS(f.slice(0,g),f.slice(g+1),u[f]):f=="style"&&l.style?l.style.cssText=u[f]:l.setAttribute(f,u[f])}}for(let f=d;fd)throw new RangeError("Content hole must be the only child of its parent node");return{dom:l,contentDOM:l}}else{let{dom:m,contentDOM:x}=V_(t,g,n,r);if(l.appendChild(m),x){if(o)throw new RangeError("Multiple content holes");o=x}}}return{dom:l,contentDOM:o}}const RW=65535,DW=Math.pow(2,16);function vSe(t,e){return t+e*DW}function VB(t){return t&RW}function ySe(t){return(t-(t&RW))/DW}const OW=1,jW=2,G_=4,LW=8;class vk{constructor(e,n,r){this.pos=e,this.delInfo=n,this.recover=r}get deleted(){return(this.delInfo&LW)>0}get deletedBefore(){return(this.delInfo&(OW|G_))>0}get deletedAfter(){return(this.delInfo&(jW|G_))>0}get deletedAcross(){return(this.delInfo&G_)>0}}class ha{constructor(e,n=!1){if(this.ranges=e,this.inverted=n,!e.length&&ha.empty)return ha.empty}recover(e){let n=0,r=VB(e);if(!this.inverted)for(let i=0;ie)break;let u=this.ranges[o+s],d=this.ranges[o+a],f=l+u;if(e<=f){let g=u?e==l?-1:e==f?1:n:n,m=l+i+(g<0?0:d);if(r)return m;let x=e==(n<0?l:f)?null:vSe(o/3,e-l),y=e==l?jW:e==f?OW:G_;return(n<0?e!=l:e!=f)&&(y|=LW),new vk(m,y,x)}i+=d-u}return r?e+i:new vk(e+i,0,null)}touches(e,n){let r=0,i=VB(n),s=this.inverted?2:1,a=this.inverted?1:2;for(let o=0;oe)break;let u=this.ranges[o+s],d=l+u;if(e<=d&&o==i*3)return!0;r+=this.ranges[o+a]-u}return!1}forEach(e){let n=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,s=0;i=0;n--){let i=e.getMirror(n);this.appendMap(e._maps[n].invert(),i!=null&&i>n?r-i-1:void 0)}}invert(){let e=new T0;return e.appendMappingInverted(this),e}map(e,n=1){if(this.mirror)return this._map(e,n,!0);for(let r=this.from;rs&&l!a.isAtom||!o.type.allowsMarkType(this.mark.type)?a:a.mark(this.mark.addToSet(a.marks)),i),n.openStart,n.openEnd);return Xr.fromReplace(e,this.from,this.to,s)}invert(){return new ko(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new Uu(n.pos,r.pos,this.mark)}merge(e){return e instanceof Uu&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Uu(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new Uu(n.from,n.to,e.markFromJSON(n.mark))}}ps.jsonID("addMark",Uu);class ko extends ps{constructor(e,n,r){super(),this.from=e,this.to=n,this.mark=r}apply(e){let n=e.slice(this.from,this.to),r=new Tt(ZR(n.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),n.openStart,n.openEnd);return Xr.fromReplace(e,this.from,this.to,r)}invert(){return new Uu(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new ko(n.pos,r.pos,this.mark)}merge(e){return e instanceof ko&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new ko(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new ko(n.from,n.to,e.markFromJSON(n.mark))}}ps.jsonID("removeMark",ko);class Fu extends ps{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.nodeAt(this.pos);if(!n)return Xr.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.addToSet(n.marks));return Xr.fromReplace(e,this.pos,this.pos+1,new Tt(pt.from(r),0,n.isLeaf?0:1))}invert(e){let n=e.nodeAt(this.pos);if(n){let r=this.mark.addToSet(n.marks);if(r.length==n.marks.length){for(let i=0;ir.pos?null:new Oi(n.pos,r.pos,i,s,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number"||typeof n.gapFrom!="number"||typeof n.gapTo!="number"||typeof n.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new Oi(n.from,n.to,n.gapFrom,n.gapTo,Tt.fromJSON(e,n.slice),n.insert,!!n.structure)}}ps.jsonID("replaceAround",Oi);function yk(t,e,n){let r=t.resolve(e),i=n-e,s=r.depth;for(;i>0&&s>0&&r.indexAfter(s)==r.node(s).childCount;)s--,i--;if(i>0){let a=r.node(s).maybeChild(r.indexAfter(s));for(;i>0;){if(!a||a.isLeaf)return!0;a=a.firstChild,i--}}return!1}function _Se(t,e,n,r){let i=[],s=[],a,o;t.doc.nodesBetween(e,n,(l,u,d)=>{if(!l.isInline)return;let f=l.marks;if(!r.isInSet(f)&&d.type.allowsMarkType(r.type)){let g=Math.max(u,e),m=Math.min(u+l.nodeSize,n),x=r.addToSet(f);for(let y=0;yt.step(l)),s.forEach(l=>t.step(l))}function wSe(t,e,n,r){let i=[],s=0;t.doc.nodesBetween(e,n,(a,o)=>{if(!a.isInline)return;s++;let l=null;if(r instanceof RS){let u=a.marks,d;for(;d=r.isInSet(u);)(l||(l=[])).push(d),u=d.removeFromSet(u)}else r?r.isInSet(a.marks)&&(l=[r]):l=a.marks;if(l&&l.length){let u=Math.min(o+a.nodeSize,n);for(let d=0;dt.step(new ko(a.from,a.to,a.style)))}function QR(t,e,n,r=n.contentMatch,i=!0){let s=t.doc.nodeAt(e),a=[],o=e+1;for(let l=0;l=0;l--)t.step(a[l])}function SSe(t,e,n){return(e==0||t.canReplace(e,t.childCount))&&(n==t.childCount||t.canReplace(0,n))}function $m(t){let n=t.parent.content.cutByIndex(t.startIndex,t.endIndex);for(let r=t.depth,i=0,s=0;;--r){let a=t.$from.node(r),o=t.$from.index(r)+i,l=t.$to.indexAfter(r)-s;if(rn;x--)y||r.index(x)>0?(y=!0,d=pt.from(r.node(x).copy(d)),f++):l--;let g=pt.empty,m=0;for(let x=s,y=!1;x>n;x--)y||i.after(x+1)=0;a--){if(r.size){let o=n[a].type.contentMatch.matchFragment(r);if(!o||!o.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=pt.from(n[a].type.create(n[a].attrs,r))}let i=e.start,s=e.end;t.step(new Oi(i,s,i,s,new Tt(r,0,0),n.length,!0))}function CSe(t,e,n,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let s=t.steps.length;t.doc.nodesBetween(e,n,(a,o)=>{let l=typeof i=="function"?i(a):i;if(a.isTextblock&&!a.hasMarkup(r,l)&&NSe(t.doc,t.mapping.slice(s).map(o),r)){let u=null;if(r.schema.linebreakReplacement){let m=r.whitespace=="pre",x=!!r.contentMatch.matchType(r.schema.linebreakReplacement);m&&!x?u=!1:!m&&x&&(u=!0)}u===!1&&UW(t,a,o,s),QR(t,t.mapping.slice(s).map(o,1),r,void 0,u===null);let d=t.mapping.slice(s),f=d.map(o,1),g=d.map(o+a.nodeSize,1);return t.step(new Oi(f,g,f+1,g-1,new Tt(pt.from(r.create(l,null,a.marks)),0,0),1,!0)),u===!0&&IW(t,a,o,s),!1}})}function IW(t,e,n,r){e.forEach((i,s)=>{if(i.isText){let a,o=/\r?\n|\r/g;for(;a=o.exec(i.text);){let l=t.mapping.slice(r).map(n+1+s+a.index);t.replaceWith(l,l+1,e.type.schema.linebreakReplacement.create())}}})}function UW(t,e,n,r){e.forEach((i,s)=>{if(i.type==i.type.schema.linebreakReplacement){let a=t.mapping.slice(r).map(n+1+s);t.replaceWith(a,a+1,e.type.schema.text(` -`))}})}function NSe(t,e,n){let r=t.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,n)}function kSe(t,e,n,r,i){let s=t.doc.nodeAt(e);if(!s)throw new RangeError("No node at given position");n||(n=s.type);let a=n.create(r,null,i||s.marks);if(s.isLeaf)return t.replaceWith(e,e+s.nodeSize,a);if(!n.validContent(s.content))throw new RangeError("Invalid content for node type "+n.name);t.step(new Oi(e,e+s.nodeSize,e+1,e+s.nodeSize-1,new Tt(pt.from(a),0,0),1,!0))}function mc(t,e,n=1,r){let i=t.resolve(e),s=i.depth-n,a=r&&r[r.length-1]||i.parent;if(s<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!a.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let u=i.depth-1,d=n-2;u>s;u--,d--){let f=i.node(u),g=i.index(u);if(f.type.spec.isolating)return!1;let m=f.content.cutByIndex(g,f.childCount),x=r&&r[d+1];x&&(m=m.replaceChild(0,x.type.create(x.attrs)));let y=r&&r[d]||f;if(!f.canReplace(g+1,f.childCount)||!y.type.validContent(m))return!1}let o=i.indexAfter(s),l=r&&r[0];return i.node(s).canReplaceWith(o,o,l?l.type:i.node(s+1).type)}function PSe(t,e,n=1,r){let i=t.doc.resolve(e),s=pt.empty,a=pt.empty;for(let o=i.depth,l=i.depth-n,u=n-1;o>l;o--,u--){s=pt.from(i.node(o).copy(s));let d=r&&r[u];a=pt.from(d?d.type.create(d.attrs,a):i.node(o).copy(a))}t.step(new Ri(e,e,new Tt(s.append(a),n,n),!0))}function pd(t,e){let n=t.resolve(e),r=n.index();return FW(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function RSe(t,e){e.content.size||t.type.compatibleContent(e.type);let n=t.contentMatchAt(t.childCount),{linebreakReplacement:r}=t.type.schema;for(let i=0;i0?(s=r.node(i+1),o++,a=r.node(i).maybeChild(o)):(s=r.node(i).maybeChild(o-1),a=r.node(i+1)),s&&!s.isTextblock&&FW(s,a)&&r.node(i).canReplace(o,o+1))return e;if(i==0)break;e=n<0?r.before(i):r.after(i)}}function DSe(t,e,n){let r=null,{linebreakReplacement:i}=t.doc.type.schema,s=t.doc.resolve(e-n),a=s.node().type;if(i&&a.inlineContent){let d=a.whitespace=="pre",f=!!a.contentMatch.matchType(i);d&&!f?r=!1:!d&&f&&(r=!0)}let o=t.steps.length;if(r===!1){let d=t.doc.resolve(e+n);UW(t,d.node(),d.before(),o)}a.inlineContent&&QR(t,e+n-1,a,s.node().contentMatchAt(s.index()),r==null);let l=t.mapping.slice(o),u=l.map(e-n);if(t.step(new Ri(u,l.map(e+n,-1),Tt.empty,!0)),r===!0){let d=t.doc.resolve(u);IW(t,d.node(),d.before(),t.steps.length)}return t}function OSe(t,e,n){let r=t.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),n))return e;if(r.parentOffset==0)for(let i=r.depth-1;i>=0;i--){let s=r.index(i);if(r.node(i).canReplaceWith(s,s,n))return r.before(i+1);if(s>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let s=r.indexAfter(i);if(r.node(i).canReplaceWith(s,s,n))return r.after(i+1);if(s=0;a--){let o=a==r.depth?0:r.pos<=(r.start(a+1)+r.end(a+1))/2?-1:1,l=r.index(a)+(o>0?1:0),u=r.node(a),d=!1;if(s==1)d=u.canReplace(l,l,i);else{let f=u.contentMatchAt(l).findWrapping(i.firstChild.type);d=f&&u.canReplaceWith(l,l,f[0])}if(d)return o==0?r.pos:o<0?r.before(a+1):r.after(a+1)}return null}function OS(t,e,n=e,r=Tt.empty){if(e==n&&!r.size)return null;let i=t.resolve(e),s=t.resolve(n);return BW(i,s,r)?new Ri(e,n,r):new jSe(i,s,r).fit()}function BW(t,e,n){return!n.openStart&&!n.openEnd&&t.start()==e.start()&&t.parent.canReplace(t.index(),e.index(),n.content)}class jSe{constructor(e,n,r){this.$from=e,this.$to=n,this.unplaced=r,this.frontier=[],this.placed=pt.empty;for(let i=0;i<=e.depth;i++){let s=e.node(i);this.frontier.push({type:s.type,match:s.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=pt.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let u=this.findFittable();u?this.placeNodes(u):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),n=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(e<0?this.$to:r.doc.resolve(e));if(!i)return null;let s=this.placed,a=r.depth,o=i.depth;for(;a&&o&&s.childCount==1;)s=s.firstChild.content,a--,o--;let l=new Tt(s,a,o);return e>-1?new Oi(r.pos,e,this.$to.pos,this.$to.end(),l,n):l.size||r.pos!=this.$to.pos?new Ri(r.pos,i.pos,l):null}findFittable(){let e=this.unplaced.openStart;for(let n=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),s.type.spec.isolating&&i<=r){e=r;break}n=s.content}for(let n=1;n<=2;n++)for(let r=n==1?e:this.unplaced.openStart;r>=0;r--){let i,s=null;r?(s=PT(this.unplaced.content,r-1).firstChild,i=s.content):i=this.unplaced.content;let a=i.firstChild;for(let o=this.depth;o>=0;o--){let{type:l,match:u}=this.frontier[o],d,f=null;if(n==1&&(a?u.matchType(a.type)||(f=u.fillBefore(pt.from(a),!1)):s&&l.compatibleContent(s.type)))return{sliceDepth:r,frontierDepth:o,parent:s,inject:f};if(n==2&&a&&(d=u.findWrapping(a.type)))return{sliceDepth:r,frontierDepth:o,parent:s,wrap:d};if(s&&u.matchType(s.type))break}}}openMore(){let{content:e,openStart:n,openEnd:r}=this.unplaced,i=PT(e,n);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new Tt(e,n+1,Math.max(r,i.size+n>=e.size-r?n+1:0)),!0)}dropNode(){let{content:e,openStart:n,openEnd:r}=this.unplaced,i=PT(e,n);if(i.childCount<=1&&n>0){let s=e.size-n<=n+i.size;this.unplaced=new Tt(Mx(e,n-1,1),n-1,s?n-1:r)}else this.unplaced=new Tt(Mx(e,n,1),n,r)}placeNodes({sliceDepth:e,frontierDepth:n,parent:r,inject:i,wrap:s}){for(;this.depth>n;)this.closeFrontierNode();if(s)for(let y=0;y1||l==0||y.content.size)&&(f=v,d.push(HW(y.mark(g.allowedMarks(y.marks)),u==1?l:0,u==o.childCount?m:-1)))}let x=u==o.childCount;x||(m=-1),this.placed=Ax(this.placed,n,pt.from(d)),this.frontier[n].match=f,x&&m<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let y=0,v=o;y1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let n=Math.min(this.depth,e.depth);n>=0;n--){let{match:r,type:i}=this.frontier[n],s=n=0;o--){let{match:l,type:u}=this.frontier[o],d=RT(e,o,u,l,!0);if(!d||d.childCount)continue e}return{depth:n,fit:a,move:s?e.doc.resolve(e.after(n+1)):e}}}}close(e){let n=this.findCloseLevel(e);if(!n)return null;for(;this.depth>n.depth;)this.closeFrontierNode();n.fit.childCount&&(this.placed=Ax(this.placed,n.depth,n.fit)),e=n.move;for(let r=n.depth+1;r<=e.depth;r++){let i=e.node(r),s=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,s)}return e}openFrontierNode(e,n=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=Ax(this.placed,this.depth,pt.from(e.create(n,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let n=this.frontier.pop().match.fillBefore(pt.empty,!0);n.childCount&&(this.placed=Ax(this.placed,this.frontier.length,n))}}function Mx(t,e,n){return e==0?t.cutByIndex(n,t.childCount):t.replaceChild(0,t.firstChild.copy(Mx(t.firstChild.content,e-1,n)))}function Ax(t,e,n){return e==0?t.append(n):t.replaceChild(t.childCount-1,t.lastChild.copy(Ax(t.lastChild.content,e-1,n)))}function PT(t,e){for(let n=0;n1&&(r=r.replaceChild(0,HW(r.firstChild,e-1,r.childCount==1?n-1:0))),e>0&&(r=t.type.contentMatch.fillBefore(r).append(r),n<=0&&(r=r.append(t.type.contentMatch.matchFragment(r).fillBefore(pt.empty,!0)))),t.copy(r)}function RT(t,e,n,r,i){let s=t.node(e),a=i?t.indexAfter(e):t.index(e);if(a==s.childCount&&!n.compatibleContent(s.type))return null;let o=r.fillBefore(s.content,!0,a);return o&&!LSe(n,s.content,a)?o:null}function LSe(t,e,n){for(let r=n;r0;g--,m--){let x=i.node(g).type.spec;if(x.defining||x.definingAsContext||x.isolating)break;a.indexOf(g)>-1?o=g:i.before(g)==m&&a.splice(1,0,-g)}let l=a.indexOf(o),u=[],d=r.openStart;for(let g=r.content,m=0;;m++){let x=g.firstChild;if(u.push(x),m==r.openStart)break;g=x.content}for(let g=d-1;g>=0;g--){let m=u[g],x=ISe(m.type);if(x&&!m.sameMarkup(i.node(Math.abs(o)-1)))d=g;else if(x||!m.type.isTextblock)break}for(let g=r.openStart;g>=0;g--){let m=(g+d+1)%(r.openStart+1),x=u[m];if(x)for(let y=0;y=0&&(t.replace(e,n,r),!(t.steps.length>f));g--){let m=a[g];m<0||(e=i.before(m),n=s.after(m))}}function $W(t,e,n,r,i){if(er){let s=i.contentMatchAt(0),a=s.fillBefore(t).append(t);t=a.append(s.matchFragment(a).fillBefore(pt.empty,!0))}return t}function FSe(t,e,n,r){if(!r.isInline&&e==n&&t.doc.resolve(e).parent.content.size){let i=OSe(t.doc,e,r.type);i!=null&&(e=n=i)}t.replaceRange(e,n,new Tt(pt.from(r),0,0))}function zSe(t,e,n){let r=t.doc.resolve(e),i=t.doc.resolve(n),s=VW(r,i);for(let a=0;a0&&(l||r.node(o-1).canReplace(r.index(o-1),i.indexAfter(o-1))))return t.delete(r.before(o),i.after(o))}for(let a=1;a<=r.depth&&a<=i.depth;a++)if(e-r.start(a)==r.depth-a&&n>r.end(a)&&i.end(a)-n!=i.depth-a&&r.start(a-1)==i.start(a-1)&&r.node(a-1).canReplace(r.index(a-1),i.index(a-1)))return t.delete(r.before(a),n);t.delete(e,n)}function VW(t,e){let n=[],r=Math.min(t.depth,e.depth);for(let i=r;i>=0;i--){let s=t.start(i);if(se.pos+(e.depth-i)||t.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(s==e.start(i)||i==t.depth&&i==e.depth&&t.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==s-1)&&n.push(i)}return n}class Yp extends ps{constructor(e,n,r){super(),this.pos=e,this.attr=n,this.value=r}apply(e){let n=e.nodeAt(this.pos);if(!n)return Xr.fail("No node at attribute step's position");let r=Object.create(null);for(let s in n.attrs)r[s]=n.attrs[s];r[this.attr]=this.value;let i=n.type.create(r,null,n.marks);return Xr.fromReplace(e,this.pos,this.pos+1,new Tt(pt.from(i),0,n.isLeaf?0:1))}getMap(){return ha.empty}invert(e){return new Yp(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new Yp(n.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,n){if(typeof n.pos!="number"||typeof n.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new Yp(n.pos,n.attr,n.value)}}ps.jsonID("attr",Yp);class C0 extends ps{constructor(e,n){super(),this.attr=e,this.value=n}apply(e){let n=Object.create(null);for(let i in e.attrs)n[i]=e.attrs[i];n[this.attr]=this.value;let r=e.type.create(n,e.content,e.marks);return Xr.ok(r)}getMap(){return ha.empty}invert(e){return new C0(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,n){if(typeof n.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new C0(n.attr,n.value)}}ps.jsonID("docAttr",C0);let gm=class extends Error{};gm=function t(e){let n=Error.call(this,e);return n.__proto__=t.prototype,n};gm.prototype=Object.create(Error.prototype);gm.prototype.constructor=gm;gm.prototype.name="TransformError";class GW{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new T0}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let n=this.maybeStep(e);if(n.failed)throw new gm(n.failed);return this}maybeStep(e){let n=e.apply(this.doc);return n.failed||this.addStep(e,n.doc),n}get docChanged(){return this.steps.length>0}addStep(e,n){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=n}replace(e,n=e,r=Tt.empty){let i=OS(this.doc,e,n,r);return i&&this.step(i),this}replaceWith(e,n,r){return this.replace(e,n,new Tt(pt.from(r),0,0))}delete(e,n){return this.replace(e,n,Tt.empty)}insert(e,n){return this.replaceWith(e,e,n)}replaceRange(e,n,r){return USe(this,e,n,r),this}replaceRangeWith(e,n,r){return FSe(this,e,n,r),this}deleteRange(e,n){return zSe(this,e,n),this}lift(e,n){return ESe(this,e,n),this}join(e,n=1){return DSe(this,e,n),this}wrap(e,n){return TSe(this,e,n),this}setBlockType(e,n=e,r,i=null){return CSe(this,e,n,r,i),this}setNodeMarkup(e,n,r=null,i){return kSe(this,e,n,r,i),this}setNodeAttribute(e,n,r){return this.step(new Yp(e,n,r)),this}setDocAttribute(e,n){return this.step(new C0(e,n)),this}addNodeMark(e,n){return this.step(new Fu(e,n)),this}removeNodeMark(e,n){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(n instanceof Zn)n.isInSet(r.marks)&&this.step(new $h(e,n));else{let i=r.marks,s,a=[];for(;s=n.isInSet(i);)a.push(new $h(e,s)),i=s.removeFromSet(i);for(let o=a.length-1;o>=0;o--)this.step(a[o])}return this}split(e,n=1,r){return PSe(this,e,n,r),this}addMark(e,n,r){return _Se(this,e,n,r),this}removeMark(e,n,r){return wSe(this,e,n,r),this}clearIncompatible(e,n,r){return QR(this,e,n,r),this}}const DT=Object.create(null);class ln{constructor(e,n,r){this.$anchor=e,this.$head=n,this.ranges=r||[new BSe(e.min(n),e.max(n))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let n=0;n=0;s--){let a=n<0?Np(e.node(0),e.node(s),e.before(s+1),e.index(s),n,r):Np(e.node(0),e.node(s),e.after(s+1),e.index(s)+1,n,r);if(a)return a}return null}static near(e,n=1){return this.findFrom(e,n)||this.findFrom(e,-n)||new ba(e.node(0))}static atStart(e){return Np(e,e,0,0,1)||new ba(e)}static atEnd(e){return Np(e,e,e.content.size,e.childCount,-1)||new ba(e)}static fromJSON(e,n){if(!n||!n.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=DT[n.type];if(!r)throw new RangeError(`No selection type ${n.type} defined`);return r.fromJSON(e,n)}static jsonID(e,n){if(e in DT)throw new RangeError("Duplicate use of selection JSON ID "+e);return DT[e]=n,n.prototype.jsonID=e,n}getBookmark(){return qt.between(this.$anchor,this.$head).getBookmark()}}ln.prototype.visible=!0;class BSe{constructor(e,n){this.$from=e,this.$to=n}}let WB=!1;function qB(t){!WB&&!t.parent.inlineContent&&(WB=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+t.parent.type.name+")"))}class qt extends ln{constructor(e,n=e){qB(e),qB(n),super(e,n)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,n){let r=e.resolve(n.map(this.head));if(!r.parent.inlineContent)return ln.near(r);let i=e.resolve(n.map(this.anchor));return new qt(i.parent.inlineContent?i:r,r)}replace(e,n=Tt.empty){if(super.replace(e,n),n==Tt.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof qt&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new jS(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,n){if(typeof n.anchor!="number"||typeof n.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new qt(e.resolve(n.anchor),e.resolve(n.head))}static create(e,n,r=n){let i=e.resolve(n);return new this(i,r==n?i:e.resolve(r))}static between(e,n,r){let i=e.pos-n.pos;if((!r||i)&&(r=i>=0?1:-1),!n.parent.inlineContent){let s=ln.findFrom(n,r,!0)||ln.findFrom(n,-r,!0);if(s)n=s.$head;else return ln.near(n,r)}return e.parent.inlineContent||(i==0?e=n:(e=(ln.findFrom(e,-r,!0)||ln.findFrom(e,r,!0)).$anchor,e.pos0?0:1);i>0?a=0;a+=i){let o=e.child(a);if(o.isAtom){if(!s&&Ht.isSelectable(o))return Ht.create(t,n-(i<0?o.nodeSize:0))}else{let l=Np(t,o,n+i,i<0?o.childCount:0,i,s);if(l)return l}n+=o.nodeSize*i}return null}function KB(t,e,n){let r=t.steps.length-1;if(r{a==null&&(a=d)}),t.setSelection(ln.near(t.doc.resolve(a),n))}const XB=1,n_=2,YB=4;class $Se extends GW{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor0}setStoredMarks(e){return this.storedMarks=e,this.updated|=n_,this}ensureMarks(e){return Zn.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&n_)>0}addStep(e,n){super.addStep(e,n),this.updated=this.updated&~n_,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,n=!0){let r=this.selection;return n&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||Zn.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,n,r){let i=this.doc.type.schema;if(n==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(r==null&&(r=n),!e)return this.deleteRange(n,r);let s=this.storedMarks;if(!s){let a=this.doc.resolve(n);s=r==n?a.marks():a.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(n,r,i.text(e,s)),!this.selection.empty&&this.selection.to==n+e.length&&this.setSelection(ln.near(this.selection.$to)),this}}setMeta(e,n){return this.meta[typeof e=="string"?e:e.key]=n,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=YB,this}get scrolledIntoView(){return(this.updated&YB)>0}}function ZB(t,e){return!e||!t?t:t.bind(e)}class Tx{constructor(e,n,r){this.name=e,this.init=ZB(n.init,r),this.apply=ZB(n.apply,r)}}const VSe=[new Tx("doc",{init(t){return t.doc||t.schema.topNodeType.createAndFill()},apply(t){return t.doc}}),new Tx("selection",{init(t,e){return t.selection||ln.atStart(e.doc)},apply(t){return t.selection}}),new Tx("storedMarks",{init(t){return t.storedMarks||null},apply(t,e,n,r){return r.selection.$cursor?t.storedMarks:null}}),new Tx("scrollToSelection",{init(){return 0},apply(t,e){return t.scrolledIntoView?e+1:e}})];class OT{constructor(e,n){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=VSe.slice(),n&&n.forEach(r=>{if(this.pluginsByKey[r.key])throw new RangeError("Adding different instances of a keyed plugin ("+r.key+")");this.plugins.push(r),this.pluginsByKey[r.key]=r,r.spec.state&&this.fields.push(new Tx(r.key,r.spec.state,r))})}}class Ip{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,n=-1){for(let r=0;rr.toJSON())),e&&typeof e=="object")for(let r in e){if(r=="doc"||r=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[r],s=i.spec.state;s&&s.toJSON&&(n[r]=s.toJSON.call(i,this[i.key]))}return n}static fromJSON(e,n,r){if(!n)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new OT(e.schema,e.plugins),s=new Ip(i);return i.fields.forEach(a=>{if(a.name=="doc")s.doc=Wu.fromJSON(e.schema,n.doc);else if(a.name=="selection")s.selection=ln.fromJSON(s.doc,n.selection);else if(a.name=="storedMarks")n.storedMarks&&(s.storedMarks=n.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let o in r){let l=r[o],u=l.spec.state;if(l.key==a.name&&u&&u.fromJSON&&Object.prototype.hasOwnProperty.call(n,o)){s[a.name]=u.fromJSON.call(l,e,n[o],s);return}}s[a.name]=a.init(e,s)}}),s}}function WW(t,e,n){for(let r in t){let i=t[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=WW(i,e,{})),n[r]=i}return n}class _r{constructor(e){this.spec=e,this.props={},e.props&&WW(e.props,this,this.props),this.key=e.key?e.key.key:qW("plugin")}getState(e){return e[this.key]}}const jT=Object.create(null);function qW(t){return t in jT?t+"$"+ ++jT[t]:(jT[t]=0,t+"$")}class gi{constructor(e="key"){this.key=qW(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const tD=(t,e)=>t.selection.empty?!1:(e&&e(t.tr.deleteSelection().scrollIntoView()),!0);function KW(t,e){let{$cursor:n}=t.selection;return!n||(e?!e.endOfTextblock("backward",t):n.parentOffset>0)?null:n}const XW=(t,e,n)=>{let r=KW(t,n);if(!r)return!1;let i=nD(r);if(!i){let a=r.blockRange(),o=a&&$m(a);return o==null?!1:(e&&e(t.tr.lift(a,o).scrollIntoView()),!0)}let s=i.nodeBefore;if(iq(t,i,e,-1))return!0;if(r.parent.content.size==0&&(xm(s,"end")||Ht.isSelectable(s)))for(let a=r.depth;;a--){let o=OS(t.doc,r.before(a),r.after(a),Tt.empty);if(o&&o.slice.size1)break}return s.isAtom&&i.depth==r.depth-1?(e&&e(t.tr.delete(i.pos-s.nodeSize,i.pos).scrollIntoView()),!0):!1},GSe=(t,e,n)=>{let r=KW(t,n);if(!r)return!1;let i=nD(r);return i?YW(t,i,e):!1},WSe=(t,e,n)=>{let r=QW(t,n);if(!r)return!1;let i=rD(r);return i?YW(t,i,e):!1};function YW(t,e,n){let r=e.nodeBefore,i=r,s=e.pos-1;for(;!i.isTextblock;s--){if(i.type.spec.isolating)return!1;let d=i.lastChild;if(!d)return!1;i=d}let a=e.nodeAfter,o=a,l=e.pos+1;for(;!o.isTextblock;l++){if(o.type.spec.isolating)return!1;let d=o.firstChild;if(!d)return!1;o=d}let u=OS(t.doc,s,l,Tt.empty);if(!u||u.from!=s||u instanceof Ri&&u.slice.size>=l-s)return!1;if(n){let d=t.tr.step(u);d.setSelection(qt.create(d.doc,s)),n(d.scrollIntoView())}return!0}function xm(t,e,n=!1){for(let r=t;r;r=e=="start"?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(n&&r.childCount!=1)return!1}return!1}const ZW=(t,e,n)=>{let{$head:r,empty:i}=t.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock("backward",t):r.parentOffset>0)return!1;s=nD(r)}let a=s&&s.nodeBefore;return!a||!Ht.isSelectable(a)?!1:(e&&e(t.tr.setSelection(Ht.create(t.doc,s.pos-a.nodeSize)).scrollIntoView()),!0)};function nD(t){if(!t.parent.type.spec.isolating)for(let e=t.depth-1;e>=0;e--){if(t.index(e)>0)return t.doc.resolve(t.before(e+1));if(t.node(e).type.spec.isolating)break}return null}function QW(t,e){let{$cursor:n}=t.selection;return!n||(e?!e.endOfTextblock("forward",t):n.parentOffset{let r=QW(t,n);if(!r)return!1;let i=rD(r);if(!i)return!1;let s=i.nodeAfter;if(iq(t,i,e,1))return!0;if(r.parent.content.size==0&&(xm(s,"start")||Ht.isSelectable(s))){let a=OS(t.doc,r.before(),r.after(),Tt.empty);if(a&&a.slice.size{let{$head:r,empty:i}=t.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock("forward",t):r.parentOffset=0;e--){let n=t.node(e);if(t.index(e)+1{let n=t.selection,r=n instanceof Ht,i;if(r){if(n.node.isTextblock||!pd(t.doc,n.from))return!1;i=n.from}else if(i=DS(t.doc,n.from,-1),i==null)return!1;if(e){let s=t.tr.join(i);r&&s.setSelection(Ht.create(s.doc,i-t.doc.resolve(i).nodeBefore.nodeSize)),e(s.scrollIntoView())}return!0},KSe=(t,e)=>{let n=t.selection,r;if(n instanceof Ht){if(n.node.isTextblock||!pd(t.doc,n.to))return!1;r=n.to}else if(r=DS(t.doc,n.to,1),r==null)return!1;return e&&e(t.tr.join(r).scrollIntoView()),!0},XSe=(t,e)=>{let{$from:n,$to:r}=t.selection,i=n.blockRange(r),s=i&&$m(i);return s==null?!1:(e&&e(t.tr.lift(i,s).scrollIntoView()),!0)},tq=(t,e)=>{let{$head:n,$anchor:r}=t.selection;return!n.parent.type.spec.code||!n.sameParent(r)?!1:(e&&e(t.tr.insertText(` +`),n)}ignoreFallback(e,n){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),n,!0)}readStyles(e,n){let r=e.style;if(r&&r.length)for(let i=0;i!l.clearMark(u)):n=n.concat(this.parser.schema.marks[l.mark].create(l.attrs)),l.consuming===!1)o=l;else break}}return n}addElementByRule(e,n,r,i){let s,a;if(n.node)if(a=this.parser.schema.nodes[n.node],a.isLeaf)this.insertNode(a.create(n.attrs),r,e.nodeName=="BR")||this.leafFallback(e,r);else{let l=this.enter(a,n.attrs||null,r,n.preserveWhitespace);l&&(s=!0,r=l)}else{let l=this.parser.schema.marks[n.mark];r=r.concat(l.create(n.attrs))}let o=this.top;if(a&&a.isLeaf)this.findInside(e);else if(i)this.addElement(e,r,i);else if(n.getContent)this.findInside(e),n.getContent(e,this.parser.schema).forEach(l=>this.insertNode(l,r,!1));else{let l=e;typeof n.contentElement=="string"?l=e.querySelector(n.contentElement):typeof n.contentElement=="function"?l=n.contentElement(e):n.contentElement&&(l=n.contentElement),this.findAround(e,l,!0),this.addAll(l,r),this.findAround(e,l,!1)}s&&this.sync(o)&&this.open--}addAll(e,n,r,i){let s=r||0;for(let a=r?e.childNodes[r]:e.firstChild,o=i==null?null:e.childNodes[i];a!=o;a=a.nextSibling,++s)this.findAtPoint(e,s),this.addDOM(a,n);this.findAtPoint(e,s)}findPlace(e,n,r){let i,s;for(let a=this.open,o=0;a>=0;a--){let l=this.nodes[a],u=l.findWrapping(e);if(u&&(!i||i.length>u.length+o)&&(i=u,s=l,!u.length))break;if(l.solid){if(r)break;o+=2}}if(!i)return null;this.sync(s);for(let a=0;a(a.type?a.type.allowsMarkType(u.type):BB(u.type,e))?(l=u.addToSet(l),!1):!0),this.nodes.push(new t_(e,n,l,i,null,o)),this.open++,r}closeExtra(e=!1){let n=this.nodes.length-1;if(n>this.open){for(;n>this.open;n--)this.nodes[n-1].content.push(this.nodes[n].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(e){for(let n=this.open;n>=0;n--){if(this.nodes[n]==e)return this.open=n,!0;this.localPreserveWS&&(this.nodes[n].options|=A0)}return!1}get currentPos(){this.closeExtra();let e=0;for(let n=this.open;n>=0;n--){let r=this.nodes[n].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;n&&e++}return e}findAtPoint(e,n){if(this.find)for(let r=0;r-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let n=e.split("/"),r=this.options.context,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),s=-(r?r.depth+1:0)+(i?0:1),a=(o,l)=>{for(;o>=0;o--){let u=n[o];if(u==""){if(o==n.length-1||o==0)continue;for(;l>=s;l--)if(a(o-1,l))return!0;return!1}else{let d=l>0||l==0&&i?this.nodes[l].type:r&&l>=s?r.node(l-s).type:null;if(!d||d.name!=u&&!d.isInGroup(u))return!1;l--}}return!0};return a(n.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let n=e.depth;n>=0;n--){let r=e.node(n).contentMatchAt(e.indexAfter(n)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let n in this.parser.schema.nodes){let r=this.parser.schema.nodes[n];if(r.isTextblock&&r.defaultAttrs)return r}}}function mSe(t){for(let e=t.firstChild,n=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&PW.hasOwnProperty(r)&&n?(n.appendChild(e),e=n):r=="li"?n=e:r&&(n=null)}}function gSe(t,e){return(t.matches||t.msMatchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector).call(t,e)}function zB(t){let e={};for(let n in t)e[n]=t[n];return e}function BB(t,e){let n=e.schema.nodes;for(let r in n){let i=n[r];if(!i.allowsMarkType(t))continue;let s=[],a=o=>{s.push(o);for(let l=0;l{if(s.length||a.marks.length){let o=0,l=0;for(;o=0;i--){let s=this.serializeMark(e.marks[i],e.isInline,n);s&&((s.contentDOM||s.dom).appendChild(r),r=s.dom)}return r}serializeMark(e,n,r={}){let i=this.marks[e.type.name];return i&&V_(NT(r),i(e,n),null,e.attrs)}static renderSpec(e,n,r=null,i){return V_(e,n,r,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new sf(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let n=HB(e.nodes);return n.text||(n.text=r=>r.text),n}static marksFromSchema(e){return HB(e.marks)}}function HB(t){let e={};for(let n in t){let r=t[n].spec.toDOM;r&&(e[n]=r)}return e}function NT(t){return t.document||window.document}const $B=new WeakMap;function xSe(t){let e=$B.get(t);return e===void 0&&$B.set(t,e=bSe(t)),e}function bSe(t){let e=null;function n(r){if(r&&typeof r=="object")if(Array.isArray(r))if(typeof r[0]=="string")e||(e=[]),e.push(r);else for(let i=0;i-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let a=i.indexOf(" ");a>0&&(n=i.slice(0,a),i=i.slice(a+1));let o,l=n?t.createElementNS(n,i):t.createElement(i),u=e[1],d=1;if(u&&typeof u=="object"&&u.nodeType==null&&!Array.isArray(u)){d=2;for(let f in u)if(u[f]!=null){let g=f.indexOf(" ");g>0?l.setAttributeNS(f.slice(0,g),f.slice(g+1),u[f]):f=="style"&&l.style?l.style.cssText=u[f]:l.setAttribute(f,u[f])}}for(let f=d;fd)throw new RangeError("Content hole must be the only child of its parent node");return{dom:l,contentDOM:l}}else{let{dom:m,contentDOM:x}=V_(t,g,n,r);if(l.appendChild(m),x){if(o)throw new RangeError("Multiple content holes");o=x}}}return{dom:l,contentDOM:o}}const RW=65535,DW=Math.pow(2,16);function vSe(t,e){return t+e*DW}function VB(t){return t&RW}function ySe(t){return(t-(t&RW))/DW}const OW=1,jW=2,G_=4,LW=8;class vk{constructor(e,n,r){this.pos=e,this.delInfo=n,this.recover=r}get deleted(){return(this.delInfo&LW)>0}get deletedBefore(){return(this.delInfo&(OW|G_))>0}get deletedAfter(){return(this.delInfo&(jW|G_))>0}get deletedAcross(){return(this.delInfo&G_)>0}}class ha{constructor(e,n=!1){if(this.ranges=e,this.inverted=n,!e.length&&ha.empty)return ha.empty}recover(e){let n=0,r=VB(e);if(!this.inverted)for(let i=0;ie)break;let u=this.ranges[o+s],d=this.ranges[o+a],f=l+u;if(e<=f){let g=u?e==l?-1:e==f?1:n:n,m=l+i+(g<0?0:d);if(r)return m;let x=e==(n<0?l:f)?null:vSe(o/3,e-l),y=e==l?jW:e==f?OW:G_;return(n<0?e!=l:e!=f)&&(y|=LW),new vk(m,y,x)}i+=d-u}return r?e+i:new vk(e+i,0,null)}touches(e,n){let r=0,i=VB(n),s=this.inverted?2:1,a=this.inverted?1:2;for(let o=0;oe)break;let u=this.ranges[o+s],d=l+u;if(e<=d&&o==i*3)return!0;r+=this.ranges[o+a]-u}return!1}forEach(e){let n=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,s=0;i=0;n--){let i=e.getMirror(n);this.appendMap(e._maps[n].invert(),i!=null&&i>n?r-i-1:void 0)}}invert(){let e=new T0;return e.appendMappingInverted(this),e}map(e,n=1){if(this.mirror)return this._map(e,n,!0);for(let r=this.from;rs&&l!a.isAtom||!o.type.allowsMarkType(this.mark.type)?a:a.mark(this.mark.addToSet(a.marks)),i),n.openStart,n.openEnd);return Xr.fromReplace(e,this.from,this.to,s)}invert(){return new ko(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new Uu(n.pos,r.pos,this.mark)}merge(e){return e instanceof Uu&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Uu(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new Uu(n.from,n.to,e.markFromJSON(n.mark))}}ps.jsonID("addMark",Uu);class ko extends ps{constructor(e,n,r){super(),this.from=e,this.to=n,this.mark=r}apply(e){let n=e.slice(this.from,this.to),r=new Tt(ZR(n.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),n.openStart,n.openEnd);return Xr.fromReplace(e,this.from,this.to,r)}invert(){return new Uu(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new ko(n.pos,r.pos,this.mark)}merge(e){return e instanceof ko&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new ko(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new ko(n.from,n.to,e.markFromJSON(n.mark))}}ps.jsonID("removeMark",ko);class Fu extends ps{constructor(e,n){super(),this.pos=e,this.mark=n}apply(e){let n=e.nodeAt(this.pos);if(!n)return Xr.fail("No node at mark step's position");let r=n.type.create(n.attrs,null,this.mark.addToSet(n.marks));return Xr.fromReplace(e,this.pos,this.pos+1,new Tt(pt.from(r),0,n.isLeaf?0:1))}invert(e){let n=e.nodeAt(this.pos);if(n){let r=this.mark.addToSet(n.marks);if(r.length==n.marks.length){for(let i=0;ir.pos?null:new Oi(n.pos,r.pos,i,s,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,n){if(typeof n.from!="number"||typeof n.to!="number"||typeof n.gapFrom!="number"||typeof n.gapTo!="number"||typeof n.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new Oi(n.from,n.to,n.gapFrom,n.gapTo,Tt.fromJSON(e,n.slice),n.insert,!!n.structure)}}ps.jsonID("replaceAround",Oi);function yk(t,e,n){let r=t.resolve(e),i=n-e,s=r.depth;for(;i>0&&s>0&&r.indexAfter(s)==r.node(s).childCount;)s--,i--;if(i>0){let a=r.node(s).maybeChild(r.indexAfter(s));for(;i>0;){if(!a||a.isLeaf)return!0;a=a.firstChild,i--}}return!1}function _Se(t,e,n,r){let i=[],s=[],a,o;t.doc.nodesBetween(e,n,(l,u,d)=>{if(!l.isInline)return;let f=l.marks;if(!r.isInSet(f)&&d.type.allowsMarkType(r.type)){let g=Math.max(u,e),m=Math.min(u+l.nodeSize,n),x=r.addToSet(f);for(let y=0;yt.step(l)),s.forEach(l=>t.step(l))}function wSe(t,e,n,r){let i=[],s=0;t.doc.nodesBetween(e,n,(a,o)=>{if(!a.isInline)return;s++;let l=null;if(r instanceof RS){let u=a.marks,d;for(;d=r.isInSet(u);)(l||(l=[])).push(d),u=d.removeFromSet(u)}else r?r.isInSet(a.marks)&&(l=[r]):l=a.marks;if(l&&l.length){let u=Math.min(o+a.nodeSize,n);for(let d=0;dt.step(new ko(a.from,a.to,a.style)))}function QR(t,e,n,r=n.contentMatch,i=!0){let s=t.doc.nodeAt(e),a=[],o=e+1;for(let l=0;l=0;l--)t.step(a[l])}function SSe(t,e,n){return(e==0||t.canReplace(e,t.childCount))&&(n==t.childCount||t.canReplace(0,n))}function $m(t){let n=t.parent.content.cutByIndex(t.startIndex,t.endIndex);for(let r=t.depth,i=0,s=0;;--r){let a=t.$from.node(r),o=t.$from.index(r)+i,l=t.$to.indexAfter(r)-s;if(rn;x--)y||r.index(x)>0?(y=!0,d=pt.from(r.node(x).copy(d)),f++):l--;let g=pt.empty,m=0;for(let x=s,y=!1;x>n;x--)y||i.after(x+1)=0;a--){if(r.size){let o=n[a].type.contentMatch.matchFragment(r);if(!o||!o.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=pt.from(n[a].type.create(n[a].attrs,r))}let i=e.start,s=e.end;t.step(new Oi(i,s,i,s,new Tt(r,0,0),n.length,!0))}function CSe(t,e,n,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let s=t.steps.length;t.doc.nodesBetween(e,n,(a,o)=>{let l=typeof i=="function"?i(a):i;if(a.isTextblock&&!a.hasMarkup(r,l)&&NSe(t.doc,t.mapping.slice(s).map(o),r)){let u=null;if(r.schema.linebreakReplacement){let m=r.whitespace=="pre",x=!!r.contentMatch.matchType(r.schema.linebreakReplacement);m&&!x?u=!1:!m&&x&&(u=!0)}u===!1&&UW(t,a,o,s),QR(t,t.mapping.slice(s).map(o,1),r,void 0,u===null);let d=t.mapping.slice(s),f=d.map(o,1),g=d.map(o+a.nodeSize,1);return t.step(new Oi(f,g,f+1,g-1,new Tt(pt.from(r.create(l,null,a.marks)),0,0),1,!0)),u===!0&&IW(t,a,o,s),!1}})}function IW(t,e,n,r){e.forEach((i,s)=>{if(i.isText){let a,o=/\r?\n|\r/g;for(;a=o.exec(i.text);){let l=t.mapping.slice(r).map(n+1+s+a.index);t.replaceWith(l,l+1,e.type.schema.linebreakReplacement.create())}}})}function UW(t,e,n,r){e.forEach((i,s)=>{if(i.type==i.type.schema.linebreakReplacement){let a=t.mapping.slice(r).map(n+1+s);t.replaceWith(a,a+1,e.type.schema.text(` +`))}})}function NSe(t,e,n){let r=t.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,n)}function kSe(t,e,n,r,i){let s=t.doc.nodeAt(e);if(!s)throw new RangeError("No node at given position");n||(n=s.type);let a=n.create(r,null,i||s.marks);if(s.isLeaf)return t.replaceWith(e,e+s.nodeSize,a);if(!n.validContent(s.content))throw new RangeError("Invalid content for node type "+n.name);t.step(new Oi(e,e+s.nodeSize,e+1,e+s.nodeSize-1,new Tt(pt.from(a),0,0),1,!0))}function mc(t,e,n=1,r){let i=t.resolve(e),s=i.depth-n,a=r&&r[r.length-1]||i.parent;if(s<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!a.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let u=i.depth-1,d=n-2;u>s;u--,d--){let f=i.node(u),g=i.index(u);if(f.type.spec.isolating)return!1;let m=f.content.cutByIndex(g,f.childCount),x=r&&r[d+1];x&&(m=m.replaceChild(0,x.type.create(x.attrs)));let y=r&&r[d]||f;if(!f.canReplace(g+1,f.childCount)||!y.type.validContent(m))return!1}let o=i.indexAfter(s),l=r&&r[0];return i.node(s).canReplaceWith(o,o,l?l.type:i.node(s+1).type)}function PSe(t,e,n=1,r){let i=t.doc.resolve(e),s=pt.empty,a=pt.empty;for(let o=i.depth,l=i.depth-n,u=n-1;o>l;o--,u--){s=pt.from(i.node(o).copy(s));let d=r&&r[u];a=pt.from(d?d.type.create(d.attrs,a):i.node(o).copy(a))}t.step(new Ri(e,e,new Tt(s.append(a),n,n),!0))}function pd(t,e){let n=t.resolve(e),r=n.index();return FW(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function RSe(t,e){e.content.size||t.type.compatibleContent(e.type);let n=t.contentMatchAt(t.childCount),{linebreakReplacement:r}=t.type.schema;for(let i=0;i0?(s=r.node(i+1),o++,a=r.node(i).maybeChild(o)):(s=r.node(i).maybeChild(o-1),a=r.node(i+1)),s&&!s.isTextblock&&FW(s,a)&&r.node(i).canReplace(o,o+1))return e;if(i==0)break;e=n<0?r.before(i):r.after(i)}}function DSe(t,e,n){let r=null,{linebreakReplacement:i}=t.doc.type.schema,s=t.doc.resolve(e-n),a=s.node().type;if(i&&a.inlineContent){let d=a.whitespace=="pre",f=!!a.contentMatch.matchType(i);d&&!f?r=!1:!d&&f&&(r=!0)}let o=t.steps.length;if(r===!1){let d=t.doc.resolve(e+n);UW(t,d.node(),d.before(),o)}a.inlineContent&&QR(t,e+n-1,a,s.node().contentMatchAt(s.index()),r==null);let l=t.mapping.slice(o),u=l.map(e-n);if(t.step(new Ri(u,l.map(e+n,-1),Tt.empty,!0)),r===!0){let d=t.doc.resolve(u);IW(t,d.node(),d.before(),t.steps.length)}return t}function OSe(t,e,n){let r=t.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),n))return e;if(r.parentOffset==0)for(let i=r.depth-1;i>=0;i--){let s=r.index(i);if(r.node(i).canReplaceWith(s,s,n))return r.before(i+1);if(s>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let s=r.indexAfter(i);if(r.node(i).canReplaceWith(s,s,n))return r.after(i+1);if(s=0;a--){let o=a==r.depth?0:r.pos<=(r.start(a+1)+r.end(a+1))/2?-1:1,l=r.index(a)+(o>0?1:0),u=r.node(a),d=!1;if(s==1)d=u.canReplace(l,l,i);else{let f=u.contentMatchAt(l).findWrapping(i.firstChild.type);d=f&&u.canReplaceWith(l,l,f[0])}if(d)return o==0?r.pos:o<0?r.before(a+1):r.after(a+1)}return null}function OS(t,e,n=e,r=Tt.empty){if(e==n&&!r.size)return null;let i=t.resolve(e),s=t.resolve(n);return BW(i,s,r)?new Ri(e,n,r):new jSe(i,s,r).fit()}function BW(t,e,n){return!n.openStart&&!n.openEnd&&t.start()==e.start()&&t.parent.canReplace(t.index(),e.index(),n.content)}class jSe{constructor(e,n,r){this.$from=e,this.$to=n,this.unplaced=r,this.frontier=[],this.placed=pt.empty;for(let i=0;i<=e.depth;i++){let s=e.node(i);this.frontier.push({type:s.type,match:s.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=pt.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let u=this.findFittable();u?this.placeNodes(u):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),n=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(e<0?this.$to:r.doc.resolve(e));if(!i)return null;let s=this.placed,a=r.depth,o=i.depth;for(;a&&o&&s.childCount==1;)s=s.firstChild.content,a--,o--;let l=new Tt(s,a,o);return e>-1?new Oi(r.pos,e,this.$to.pos,this.$to.end(),l,n):l.size||r.pos!=this.$to.pos?new Ri(r.pos,i.pos,l):null}findFittable(){let e=this.unplaced.openStart;for(let n=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),s.type.spec.isolating&&i<=r){e=r;break}n=s.content}for(let n=1;n<=2;n++)for(let r=n==1?e:this.unplaced.openStart;r>=0;r--){let i,s=null;r?(s=PT(this.unplaced.content,r-1).firstChild,i=s.content):i=this.unplaced.content;let a=i.firstChild;for(let o=this.depth;o>=0;o--){let{type:l,match:u}=this.frontier[o],d,f=null;if(n==1&&(a?u.matchType(a.type)||(f=u.fillBefore(pt.from(a),!1)):s&&l.compatibleContent(s.type)))return{sliceDepth:r,frontierDepth:o,parent:s,inject:f};if(n==2&&a&&(d=u.findWrapping(a.type)))return{sliceDepth:r,frontierDepth:o,parent:s,wrap:d};if(s&&u.matchType(s.type))break}}}openMore(){let{content:e,openStart:n,openEnd:r}=this.unplaced,i=PT(e,n);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new Tt(e,n+1,Math.max(r,i.size+n>=e.size-r?n+1:0)),!0)}dropNode(){let{content:e,openStart:n,openEnd:r}=this.unplaced,i=PT(e,n);if(i.childCount<=1&&n>0){let s=e.size-n<=n+i.size;this.unplaced=new Tt(Mx(e,n-1,1),n-1,s?n-1:r)}else this.unplaced=new Tt(Mx(e,n,1),n,r)}placeNodes({sliceDepth:e,frontierDepth:n,parent:r,inject:i,wrap:s}){for(;this.depth>n;)this.closeFrontierNode();if(s)for(let y=0;y1||l==0||y.content.size)&&(f=v,d.push(HW(y.mark(g.allowedMarks(y.marks)),u==1?l:0,u==o.childCount?m:-1)))}let x=u==o.childCount;x||(m=-1),this.placed=Ax(this.placed,n,pt.from(d)),this.frontier[n].match=f,x&&m<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let y=0,v=o;y1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let n=Math.min(this.depth,e.depth);n>=0;n--){let{match:r,type:i}=this.frontier[n],s=n=0;o--){let{match:l,type:u}=this.frontier[o],d=RT(e,o,u,l,!0);if(!d||d.childCount)continue e}return{depth:n,fit:a,move:s?e.doc.resolve(e.after(n+1)):e}}}}close(e){let n=this.findCloseLevel(e);if(!n)return null;for(;this.depth>n.depth;)this.closeFrontierNode();n.fit.childCount&&(this.placed=Ax(this.placed,n.depth,n.fit)),e=n.move;for(let r=n.depth+1;r<=e.depth;r++){let i=e.node(r),s=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,s)}return e}openFrontierNode(e,n=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=Ax(this.placed,this.depth,pt.from(e.create(n,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let n=this.frontier.pop().match.fillBefore(pt.empty,!0);n.childCount&&(this.placed=Ax(this.placed,this.frontier.length,n))}}function Mx(t,e,n){return e==0?t.cutByIndex(n,t.childCount):t.replaceChild(0,t.firstChild.copy(Mx(t.firstChild.content,e-1,n)))}function Ax(t,e,n){return e==0?t.append(n):t.replaceChild(t.childCount-1,t.lastChild.copy(Ax(t.lastChild.content,e-1,n)))}function PT(t,e){for(let n=0;n1&&(r=r.replaceChild(0,HW(r.firstChild,e-1,r.childCount==1?n-1:0))),e>0&&(r=t.type.contentMatch.fillBefore(r).append(r),n<=0&&(r=r.append(t.type.contentMatch.matchFragment(r).fillBefore(pt.empty,!0)))),t.copy(r)}function RT(t,e,n,r,i){let s=t.node(e),a=i?t.indexAfter(e):t.index(e);if(a==s.childCount&&!n.compatibleContent(s.type))return null;let o=r.fillBefore(s.content,!0,a);return o&&!LSe(n,s.content,a)?o:null}function LSe(t,e,n){for(let r=n;r0;g--,m--){let x=i.node(g).type.spec;if(x.defining||x.definingAsContext||x.isolating)break;a.indexOf(g)>-1?o=g:i.before(g)==m&&a.splice(1,0,-g)}let l=a.indexOf(o),u=[],d=r.openStart;for(let g=r.content,m=0;;m++){let x=g.firstChild;if(u.push(x),m==r.openStart)break;g=x.content}for(let g=d-1;g>=0;g--){let m=u[g],x=ISe(m.type);if(x&&!m.sameMarkup(i.node(Math.abs(o)-1)))d=g;else if(x||!m.type.isTextblock)break}for(let g=r.openStart;g>=0;g--){let m=(g+d+1)%(r.openStart+1),x=u[m];if(x)for(let y=0;y=0&&(t.replace(e,n,r),!(t.steps.length>f));g--){let m=a[g];m<0||(e=i.before(m),n=s.after(m))}}function $W(t,e,n,r,i){if(er){let s=i.contentMatchAt(0),a=s.fillBefore(t).append(t);t=a.append(s.matchFragment(a).fillBefore(pt.empty,!0))}return t}function FSe(t,e,n,r){if(!r.isInline&&e==n&&t.doc.resolve(e).parent.content.size){let i=OSe(t.doc,e,r.type);i!=null&&(e=n=i)}t.replaceRange(e,n,new Tt(pt.from(r),0,0))}function zSe(t,e,n){let r=t.doc.resolve(e),i=t.doc.resolve(n),s=VW(r,i);for(let a=0;a0&&(l||r.node(o-1).canReplace(r.index(o-1),i.indexAfter(o-1))))return t.delete(r.before(o),i.after(o))}for(let a=1;a<=r.depth&&a<=i.depth;a++)if(e-r.start(a)==r.depth-a&&n>r.end(a)&&i.end(a)-n!=i.depth-a&&r.start(a-1)==i.start(a-1)&&r.node(a-1).canReplace(r.index(a-1),i.index(a-1)))return t.delete(r.before(a),n);t.delete(e,n)}function VW(t,e){let n=[],r=Math.min(t.depth,e.depth);for(let i=r;i>=0;i--){let s=t.start(i);if(se.pos+(e.depth-i)||t.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(s==e.start(i)||i==t.depth&&i==e.depth&&t.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==s-1)&&n.push(i)}return n}class Yp extends ps{constructor(e,n,r){super(),this.pos=e,this.attr=n,this.value=r}apply(e){let n=e.nodeAt(this.pos);if(!n)return Xr.fail("No node at attribute step's position");let r=Object.create(null);for(let s in n.attrs)r[s]=n.attrs[s];r[this.attr]=this.value;let i=n.type.create(r,null,n.marks);return Xr.fromReplace(e,this.pos,this.pos+1,new Tt(pt.from(i),0,n.isLeaf?0:1))}getMap(){return ha.empty}invert(e){return new Yp(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let n=e.mapResult(this.pos,1);return n.deletedAfter?null:new Yp(n.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,n){if(typeof n.pos!="number"||typeof n.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new Yp(n.pos,n.attr,n.value)}}ps.jsonID("attr",Yp);class C0 extends ps{constructor(e,n){super(),this.attr=e,this.value=n}apply(e){let n=Object.create(null);for(let i in e.attrs)n[i]=e.attrs[i];n[this.attr]=this.value;let r=e.type.create(n,e.content,e.marks);return Xr.ok(r)}getMap(){return ha.empty}invert(e){return new C0(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,n){if(typeof n.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new C0(n.attr,n.value)}}ps.jsonID("docAttr",C0);let gm=class extends Error{};gm=function t(e){let n=Error.call(this,e);return n.__proto__=t.prototype,n};gm.prototype=Object.create(Error.prototype);gm.prototype.constructor=gm;gm.prototype.name="TransformError";class GW{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new T0}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let n=this.maybeStep(e);if(n.failed)throw new gm(n.failed);return this}maybeStep(e){let n=e.apply(this.doc);return n.failed||this.addStep(e,n.doc),n}get docChanged(){return this.steps.length>0}addStep(e,n){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=n}replace(e,n=e,r=Tt.empty){let i=OS(this.doc,e,n,r);return i&&this.step(i),this}replaceWith(e,n,r){return this.replace(e,n,new Tt(pt.from(r),0,0))}delete(e,n){return this.replace(e,n,Tt.empty)}insert(e,n){return this.replaceWith(e,e,n)}replaceRange(e,n,r){return USe(this,e,n,r),this}replaceRangeWith(e,n,r){return FSe(this,e,n,r),this}deleteRange(e,n){return zSe(this,e,n),this}lift(e,n){return ESe(this,e,n),this}join(e,n=1){return DSe(this,e,n),this}wrap(e,n){return TSe(this,e,n),this}setBlockType(e,n=e,r,i=null){return CSe(this,e,n,r,i),this}setNodeMarkup(e,n,r=null,i){return kSe(this,e,n,r,i),this}setNodeAttribute(e,n,r){return this.step(new Yp(e,n,r)),this}setDocAttribute(e,n){return this.step(new C0(e,n)),this}addNodeMark(e,n){return this.step(new Fu(e,n)),this}removeNodeMark(e,n){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(n instanceof Qn)n.isInSet(r.marks)&&this.step(new $h(e,n));else{let i=r.marks,s,a=[];for(;s=n.isInSet(i);)a.push(new $h(e,s)),i=s.removeFromSet(i);for(let o=a.length-1;o>=0;o--)this.step(a[o])}return this}split(e,n=1,r){return PSe(this,e,n,r),this}addMark(e,n,r){return _Se(this,e,n,r),this}removeMark(e,n,r){return wSe(this,e,n,r),this}clearIncompatible(e,n,r){return QR(this,e,n,r),this}}const DT=Object.create(null);class ln{constructor(e,n,r){this.$anchor=e,this.$head=n,this.ranges=r||[new BSe(e.min(n),e.max(n))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let n=0;n=0;s--){let a=n<0?Np(e.node(0),e.node(s),e.before(s+1),e.index(s),n,r):Np(e.node(0),e.node(s),e.after(s+1),e.index(s)+1,n,r);if(a)return a}return null}static near(e,n=1){return this.findFrom(e,n)||this.findFrom(e,-n)||new ba(e.node(0))}static atStart(e){return Np(e,e,0,0,1)||new ba(e)}static atEnd(e){return Np(e,e,e.content.size,e.childCount,-1)||new ba(e)}static fromJSON(e,n){if(!n||!n.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=DT[n.type];if(!r)throw new RangeError(`No selection type ${n.type} defined`);return r.fromJSON(e,n)}static jsonID(e,n){if(e in DT)throw new RangeError("Duplicate use of selection JSON ID "+e);return DT[e]=n,n.prototype.jsonID=e,n}getBookmark(){return qt.between(this.$anchor,this.$head).getBookmark()}}ln.prototype.visible=!0;class BSe{constructor(e,n){this.$from=e,this.$to=n}}let WB=!1;function qB(t){!WB&&!t.parent.inlineContent&&(WB=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+t.parent.type.name+")"))}class qt extends ln{constructor(e,n=e){qB(e),qB(n),super(e,n)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,n){let r=e.resolve(n.map(this.head));if(!r.parent.inlineContent)return ln.near(r);let i=e.resolve(n.map(this.anchor));return new qt(i.parent.inlineContent?i:r,r)}replace(e,n=Tt.empty){if(super.replace(e,n),n==Tt.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof qt&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new jS(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,n){if(typeof n.anchor!="number"||typeof n.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new qt(e.resolve(n.anchor),e.resolve(n.head))}static create(e,n,r=n){let i=e.resolve(n);return new this(i,r==n?i:e.resolve(r))}static between(e,n,r){let i=e.pos-n.pos;if((!r||i)&&(r=i>=0?1:-1),!n.parent.inlineContent){let s=ln.findFrom(n,r,!0)||ln.findFrom(n,-r,!0);if(s)n=s.$head;else return ln.near(n,r)}return e.parent.inlineContent||(i==0?e=n:(e=(ln.findFrom(e,-r,!0)||ln.findFrom(e,r,!0)).$anchor,e.pos0?0:1);i>0?a=0;a+=i){let o=e.child(a);if(o.isAtom){if(!s&&Ht.isSelectable(o))return Ht.create(t,n-(i<0?o.nodeSize:0))}else{let l=Np(t,o,n+i,i<0?o.childCount:0,i,s);if(l)return l}n+=o.nodeSize*i}return null}function KB(t,e,n){let r=t.steps.length-1;if(r{a==null&&(a=d)}),t.setSelection(ln.near(t.doc.resolve(a),n))}const XB=1,n_=2,YB=4;class $Se extends GW{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor0}setStoredMarks(e){return this.storedMarks=e,this.updated|=n_,this}ensureMarks(e){return Qn.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&n_)>0}addStep(e,n){super.addStep(e,n),this.updated=this.updated&~n_,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,n=!0){let r=this.selection;return n&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||Qn.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,n,r){let i=this.doc.type.schema;if(n==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(r==null&&(r=n),!e)return this.deleteRange(n,r);let s=this.storedMarks;if(!s){let a=this.doc.resolve(n);s=r==n?a.marks():a.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(n,r,i.text(e,s)),!this.selection.empty&&this.selection.to==n+e.length&&this.setSelection(ln.near(this.selection.$to)),this}}setMeta(e,n){return this.meta[typeof e=="string"?e:e.key]=n,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=YB,this}get scrolledIntoView(){return(this.updated&YB)>0}}function ZB(t,e){return!e||!t?t:t.bind(e)}class Tx{constructor(e,n,r){this.name=e,this.init=ZB(n.init,r),this.apply=ZB(n.apply,r)}}const VSe=[new Tx("doc",{init(t){return t.doc||t.schema.topNodeType.createAndFill()},apply(t){return t.doc}}),new Tx("selection",{init(t,e){return t.selection||ln.atStart(e.doc)},apply(t){return t.selection}}),new Tx("storedMarks",{init(t){return t.storedMarks||null},apply(t,e,n,r){return r.selection.$cursor?t.storedMarks:null}}),new Tx("scrollToSelection",{init(){return 0},apply(t,e){return t.scrolledIntoView?e+1:e}})];class OT{constructor(e,n){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=VSe.slice(),n&&n.forEach(r=>{if(this.pluginsByKey[r.key])throw new RangeError("Adding different instances of a keyed plugin ("+r.key+")");this.plugins.push(r),this.pluginsByKey[r.key]=r,r.spec.state&&this.fields.push(new Tx(r.key,r.spec.state,r))})}}class Ip{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,n=-1){for(let r=0;rr.toJSON())),e&&typeof e=="object")for(let r in e){if(r=="doc"||r=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[r],s=i.spec.state;s&&s.toJSON&&(n[r]=s.toJSON.call(i,this[i.key]))}return n}static fromJSON(e,n,r){if(!n)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new OT(e.schema,e.plugins),s=new Ip(i);return i.fields.forEach(a=>{if(a.name=="doc")s.doc=Wu.fromJSON(e.schema,n.doc);else if(a.name=="selection")s.selection=ln.fromJSON(s.doc,n.selection);else if(a.name=="storedMarks")n.storedMarks&&(s.storedMarks=n.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let o in r){let l=r[o],u=l.spec.state;if(l.key==a.name&&u&&u.fromJSON&&Object.prototype.hasOwnProperty.call(n,o)){s[a.name]=u.fromJSON.call(l,e,n[o],s);return}}s[a.name]=a.init(e,s)}}),s}}function WW(t,e,n){for(let r in t){let i=t[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=WW(i,e,{})),n[r]=i}return n}class _r{constructor(e){this.spec=e,this.props={},e.props&&WW(e.props,this,this.props),this.key=e.key?e.key.key:qW("plugin")}getState(e){return e[this.key]}}const jT=Object.create(null);function qW(t){return t in jT?t+"$"+ ++jT[t]:(jT[t]=0,t+"$")}class gi{constructor(e="key"){this.key=qW(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const tD=(t,e)=>t.selection.empty?!1:(e&&e(t.tr.deleteSelection().scrollIntoView()),!0);function KW(t,e){let{$cursor:n}=t.selection;return!n||(e?!e.endOfTextblock("backward",t):n.parentOffset>0)?null:n}const XW=(t,e,n)=>{let r=KW(t,n);if(!r)return!1;let i=nD(r);if(!i){let a=r.blockRange(),o=a&&$m(a);return o==null?!1:(e&&e(t.tr.lift(a,o).scrollIntoView()),!0)}let s=i.nodeBefore;if(iq(t,i,e,-1))return!0;if(r.parent.content.size==0&&(xm(s,"end")||Ht.isSelectable(s)))for(let a=r.depth;;a--){let o=OS(t.doc,r.before(a),r.after(a),Tt.empty);if(o&&o.slice.size1)break}return s.isAtom&&i.depth==r.depth-1?(e&&e(t.tr.delete(i.pos-s.nodeSize,i.pos).scrollIntoView()),!0):!1},GSe=(t,e,n)=>{let r=KW(t,n);if(!r)return!1;let i=nD(r);return i?YW(t,i,e):!1},WSe=(t,e,n)=>{let r=QW(t,n);if(!r)return!1;let i=rD(r);return i?YW(t,i,e):!1};function YW(t,e,n){let r=e.nodeBefore,i=r,s=e.pos-1;for(;!i.isTextblock;s--){if(i.type.spec.isolating)return!1;let d=i.lastChild;if(!d)return!1;i=d}let a=e.nodeAfter,o=a,l=e.pos+1;for(;!o.isTextblock;l++){if(o.type.spec.isolating)return!1;let d=o.firstChild;if(!d)return!1;o=d}let u=OS(t.doc,s,l,Tt.empty);if(!u||u.from!=s||u instanceof Ri&&u.slice.size>=l-s)return!1;if(n){let d=t.tr.step(u);d.setSelection(qt.create(d.doc,s)),n(d.scrollIntoView())}return!0}function xm(t,e,n=!1){for(let r=t;r;r=e=="start"?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(n&&r.childCount!=1)return!1}return!1}const ZW=(t,e,n)=>{let{$head:r,empty:i}=t.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock("backward",t):r.parentOffset>0)return!1;s=nD(r)}let a=s&&s.nodeBefore;return!a||!Ht.isSelectable(a)?!1:(e&&e(t.tr.setSelection(Ht.create(t.doc,s.pos-a.nodeSize)).scrollIntoView()),!0)};function nD(t){if(!t.parent.type.spec.isolating)for(let e=t.depth-1;e>=0;e--){if(t.index(e)>0)return t.doc.resolve(t.before(e+1));if(t.node(e).type.spec.isolating)break}return null}function QW(t,e){let{$cursor:n}=t.selection;return!n||(e?!e.endOfTextblock("forward",t):n.parentOffset{let r=QW(t,n);if(!r)return!1;let i=rD(r);if(!i)return!1;let s=i.nodeAfter;if(iq(t,i,e,1))return!0;if(r.parent.content.size==0&&(xm(s,"start")||Ht.isSelectable(s))){let a=OS(t.doc,r.before(),r.after(),Tt.empty);if(a&&a.slice.size{let{$head:r,empty:i}=t.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock("forward",t):r.parentOffset=0;e--){let n=t.node(e);if(t.index(e)+1{let n=t.selection,r=n instanceof Ht,i;if(r){if(n.node.isTextblock||!pd(t.doc,n.from))return!1;i=n.from}else if(i=DS(t.doc,n.from,-1),i==null)return!1;if(e){let s=t.tr.join(i);r&&s.setSelection(Ht.create(s.doc,i-t.doc.resolve(i).nodeBefore.nodeSize)),e(s.scrollIntoView())}return!0},KSe=(t,e)=>{let n=t.selection,r;if(n instanceof Ht){if(n.node.isTextblock||!pd(t.doc,n.to))return!1;r=n.to}else if(r=DS(t.doc,n.to,1),r==null)return!1;return e&&e(t.tr.join(r).scrollIntoView()),!0},XSe=(t,e)=>{let{$from:n,$to:r}=t.selection,i=n.blockRange(r),s=i&&$m(i);return s==null?!1:(e&&e(t.tr.lift(i,s).scrollIntoView()),!0)},tq=(t,e)=>{let{$head:n,$anchor:r}=t.selection;return!n.parent.type.spec.code||!n.sameParent(r)?!1:(e&&e(t.tr.insertText(` `).scrollIntoView()),!0)};function iD(t){for(let e=0;e{let{$head:n,$anchor:r}=t.selection;if(!n.parent.type.spec.code||!n.sameParent(r))return!1;let i=n.node(-1),s=n.indexAfter(-1),a=iD(i.contentMatchAt(s));if(!a||!i.canReplaceWith(s,s,a))return!1;if(e){let o=n.after(),l=t.tr.replaceWith(o,o,a.createAndFill());l.setSelection(ln.near(l.doc.resolve(o),1)),e(l.scrollIntoView())}return!0},nq=(t,e)=>{let n=t.selection,{$from:r,$to:i}=n;if(n instanceof ba||r.parent.inlineContent||i.parent.inlineContent)return!1;let s=iD(i.parent.contentMatchAt(i.indexAfter()));if(!s||!s.isTextblock)return!1;if(e){let a=(!r.parentOffset&&i.index(){let{$cursor:n}=t.selection;if(!n||n.parent.content.size)return!1;if(n.depth>1&&n.after()!=n.end(-1)){let s=n.before();if(mc(t.doc,s))return e&&e(t.tr.split(s).scrollIntoView()),!0}let r=n.blockRange(),i=r&&$m(r);return i==null?!1:(e&&e(t.tr.lift(r,i).scrollIntoView()),!0)};function ZSe(t){return(e,n)=>{let{$from:r,$to:i}=e.selection;if(e.selection instanceof Ht&&e.selection.node.isBlock)return!r.parentOffset||!mc(e.doc,r.pos)?!1:(n&&n(e.tr.split(r.pos).scrollIntoView()),!0);if(!r.depth)return!1;let s=[],a,o,l=!1,u=!1;for(let m=r.depth;;m--)if(r.node(m).isBlock){l=r.end(m)==r.pos+(r.depth-m),u=r.start(m)==r.pos-(r.depth-m),o=iD(r.node(m-1).contentMatchAt(r.indexAfter(m-1))),s.unshift(l&&o?{type:o}:null),a=m;break}else{if(m==1)return!1;s.unshift(null)}let d=e.tr;(e.selection instanceof qt||e.selection instanceof ba)&&d.deleteSelection();let f=d.mapping.map(r.pos),g=mc(d.doc,f,s.length,s);if(g||(s[0]=o?{type:o}:null,g=mc(d.doc,f,s.length,s)),!g)return!1;if(d.split(f,s.length,s),!l&&u&&r.node(a).type!=o){let m=d.mapping.map(r.before(a)),x=d.doc.resolve(m);o&&r.node(a-1).canReplaceWith(x.index(),x.index()+1,o)&&d.setNodeMarkup(d.mapping.map(r.before(a)),o)}return n&&n(d.scrollIntoView()),!0}}const QSe=ZSe(),JSe=(t,e)=>{let{$from:n,to:r}=t.selection,i,s=n.sharedDepth(r);return s==0?!1:(i=n.before(s),e&&e(t.tr.setSelection(Ht.create(t.doc,i))),!0)};function eEe(t,e,n){let r=e.nodeBefore,i=e.nodeAfter,s=e.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&e.parent.canReplace(s-1,s)?(n&&n(t.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(s,s+1)||!(i.isTextblock||pd(t.doc,e.pos))?!1:(n&&n(t.tr.join(e.pos).scrollIntoView()),!0)}function iq(t,e,n,r){let i=e.nodeBefore,s=e.nodeAfter,a,o,l=i.type.spec.isolating||s.type.spec.isolating;if(!l&&eEe(t,e,n))return!0;let u=!l&&e.parent.canReplace(e.index(),e.index()+1);if(u&&(a=(o=i.contentMatchAt(i.childCount)).findWrapping(s.type))&&o.matchType(a[0]||s.type).validEnd){if(n){let m=e.pos+s.nodeSize,x=pt.empty;for(let b=a.length-1;b>=0;b--)x=pt.from(a[b].create(null,x));x=pt.from(i.copy(x));let y=t.tr.step(new Oi(e.pos-1,m,e.pos,m,new Tt(x,1,0),a.length,!0)),v=y.doc.resolve(m+2*a.length);v.nodeAfter&&v.nodeAfter.type==i.type&&pd(y.doc,v.pos)&&y.join(v.pos),n(y.scrollIntoView())}return!0}let d=s.type.spec.isolating||r>0&&l?null:ln.findFrom(e,1),f=d&&d.$from.blockRange(d.$to),g=f&&$m(f);if(g!=null&&g>=e.depth)return n&&n(t.tr.lift(f,g).scrollIntoView()),!0;if(u&&xm(s,"start",!0)&&xm(i,"end")){let m=i,x=[];for(;x.push(m),!m.isTextblock;)m=m.lastChild;let y=s,v=1;for(;!y.isTextblock;y=y.firstChild)v++;if(m.canReplace(m.childCount,m.childCount,y.content)){if(n){let b=pt.empty;for(let S=x.length-1;S>=0;S--)b=pt.from(x[S].copy(b));let E=t.tr.step(new Oi(e.pos-x.length,e.pos+s.nodeSize,e.pos+v,e.pos+s.nodeSize-v,new Tt(b,x.length,0),0,!0));n(E.scrollIntoView())}return!0}}return!1}function sq(t){return function(e,n){let r=e.selection,i=t<0?r.$from:r.$to,s=i.depth;for(;i.node(s).isInline;){if(!s)return!1;s--}return i.node(s).isTextblock?(n&&n(e.tr.setSelection(qt.create(e.doc,t<0?i.start(s):i.end(s)))),!0):!1}}const tEe=sq(-1),nEe=sq(1);function rEe(t,e=null){return function(n,r){let{$from:i,$to:s}=n.selection,a=i.blockRange(s),o=a&&JR(a,t,e);return o?(r&&r(n.tr.wrap(a,o).scrollIntoView()),!0):!1}}function QB(t,e=null){return function(n,r){let i=!1;for(let s=0;s{if(i)return!1;if(!(!l.isTextblock||l.hasMarkup(t,e)))if(l.type==t)i=!0;else{let d=n.doc.resolve(u),f=d.index();i=d.parent.canReplaceWith(f,f+1,t)}})}if(!i)return!1;if(r){let s=n.tr;for(let a=0;a=2&&e.$from.node(e.depth-1).type.compatibleContent(n)&&e.startIndex==0){if(e.$from.index(e.depth-1)==0)return!1;let l=a.resolve(e.start-2);s=new A1(l,l,e.depth),e.endIndex=0;d--)s=pt.from(n[d].type.create(n[d].attrs,s));t.step(new Oi(e.start-(r?2:0),e.end,e.start,e.end,new Tt(s,0,0),n.length,!0));let a=0;for(let d=0;da.childCount>0&&a.firstChild.type==t);return s?n?r.node(s.depth-1).type==t?lEe(e,n,t,s):cEe(e,n,s):!0:!1}}function lEe(t,e,n,r){let i=t.tr,s=r.end,a=r.$to.end(r.depth);sy;x--)m-=i.child(x).nodeSize,r.delete(m-1,m+1);let s=r.doc.resolve(n.start),a=s.nodeAfter;if(r.mapping.map(n.end)!=n.start+s.nodeAfter.nodeSize)return!1;let o=n.startIndex==0,l=n.endIndex==i.childCount,u=s.node(-1),d=s.index(-1);if(!u.canReplace(d+(o?0:1),d+1,a.content.append(l?pt.empty:pt.from(i))))return!1;let f=s.pos,g=f+a.nodeSize;return r.step(new Oi(f-(o?1:0),g+(l?1:0),f+1,g-1,new Tt((o?pt.empty:pt.from(i.copy(pt.empty))).append(l?pt.empty:pt.from(i.copy(pt.empty))),o?0:1,l?0:1),o?0:1)),e(r.scrollIntoView()),!0}function uEe(t){return function(e,n){let{$from:r,$to:i}=e.selection,s=r.blockRange(i,u=>u.childCount>0&&u.firstChild.type==t);if(!s)return!1;let a=s.startIndex;if(a==0)return!1;let o=s.parent,l=o.child(a-1);if(l.type!=t)return!1;if(n){let u=l.lastChild&&l.lastChild.type==o.type,d=pt.from(u?t.create():null),f=new Tt(pt.from(t.create(null,pt.from(o.type.create(null,d)))),u?3:1,0),g=s.start,m=s.end;n(e.tr.step(new Oi(g-(u?3:1),m,g,m,f,1,!0)).scrollIntoView())}return!0}}const Zi=function(t){for(var e=0;;e++)if(t=t.previousSibling,!t)return e},bm=function(t){let e=t.assignedSlot||t.parentNode;return e&&e.nodeType==11?e.host:e};let _k=null;const Jl=function(t,e,n){let r=_k||(_k=document.createRange());return r.setEnd(t,n??t.nodeValue.length),r.setStart(t,e||0),r},dEe=function(){_k=null},Vh=function(t,e,n,r){return n&&(JB(t,e,n,r,-1)||JB(t,e,n,r,1))},hEe=/^(img|br|input|textarea|hr)$/i;function JB(t,e,n,r,i){for(var s;;){if(t==n&&e==r)return!0;if(e==(i<0?0:Xa(t))){let a=t.parentNode;if(!a||a.nodeType!=1||lb(t)||hEe.test(t.nodeName)||t.contentEditable=="false")return!1;e=Zi(t)+(i<0?0:1),t=a}else if(t.nodeType==1){let a=t.childNodes[e+(i<0?-1:0)];if(a.nodeType==1&&a.contentEditable=="false")if(!((s=a.pmViewDesc)===null||s===void 0)&&s.ignoreForSelection)e+=i;else return!1;else t=a,e=i<0?Xa(t):0}else return!1}}function Xa(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function fEe(t,e){for(;;){if(t.nodeType==3&&e)return t;if(t.nodeType==1&&e>0){if(t.contentEditable=="false")return null;t=t.childNodes[e-1],e=Xa(t)}else if(t.parentNode&&!lb(t))e=Zi(t),t=t.parentNode;else return null}}function pEe(t,e){for(;;){if(t.nodeType==3&&e2),$a=vm||(ul?/Mac/.test(ul.platform):!1),bEe=ul?/Win/.test(ul.platform):!1,lc=/Android \d/.test(md),cb=!!e6&&"webkitFontSmoothing"in e6.documentElement.style,vEe=cb?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function yEe(t){let e=t.defaultView&&t.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:t.documentElement.clientWidth,top:0,bottom:t.documentElement.clientHeight}}function ql(t,e){return typeof t=="number"?t:t[e]}function _Ee(t){let e=t.getBoundingClientRect(),n=e.width/t.offsetWidth||1,r=e.height/t.offsetHeight||1;return{left:e.left,right:e.left+t.clientWidth*n,top:e.top,bottom:e.top+t.clientHeight*r}}function t6(t,e,n){let r=t.someProp("scrollThreshold")||0,i=t.someProp("scrollMargin")||5,s=t.dom.ownerDocument;for(let a=n||t.dom;a;){if(a.nodeType!=1){a=bm(a);continue}let o=a,l=o==s.body,u=l?yEe(s):_Ee(o),d=0,f=0;if(e.topu.bottom-ql(r,"bottom")&&(f=e.bottom-e.top>u.bottom-u.top?e.top+ql(i,"top")-u.top:e.bottom-u.bottom+ql(i,"bottom")),e.leftu.right-ql(r,"right")&&(d=e.right-u.right+ql(i,"right")),d||f)if(l)s.defaultView.scrollBy(d,f);else{let m=o.scrollLeft,x=o.scrollTop;f&&(o.scrollTop+=f),d&&(o.scrollLeft+=d);let y=o.scrollLeft-m,v=o.scrollTop-x;e={left:e.left-y,top:e.top-v,right:e.right-y,bottom:e.bottom-v}}let g=l?"fixed":getComputedStyle(a).position;if(/^(fixed|sticky)$/.test(g))break;a=g=="absolute"?a.offsetParent:bm(a)}}function wEe(t){let e=t.dom.getBoundingClientRect(),n=Math.max(0,e.top),r,i;for(let s=(e.left+e.right)/2,a=n+1;a=n-20){r=o,i=l.top;break}}return{refDOM:r,refTop:i,stack:lq(t.dom)}}function lq(t){let e=[],n=t.ownerDocument;for(let r=t;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),t!=n);r=bm(r));return e}function SEe({refDOM:t,refTop:e,stack:n}){let r=t?t.getBoundingClientRect().top:0;cq(n,r==0?0:r-e)}function cq(t,e){for(let n=0;n=o){a=Math.max(x.bottom,a),o=Math.min(x.top,o);let y=x.left>e.left?x.left-e.left:x.right=(x.left+x.right)/2?1:0));continue}}else x.top>e.top&&!l&&x.left<=e.left&&x.right>=e.left&&(l=d,u={left:Math.max(x.left,Math.min(x.right,e.left)),top:x.top});!n&&(e.left>=x.right&&e.top>=x.top||e.left>=x.left&&e.top>=x.bottom)&&(s=f+1)}}return!n&&l&&(n=l,i=u,r=0),n&&n.nodeType==3?MEe(n,i):!n||r&&n.nodeType==1?{node:t,offset:s}:uq(n,i)}function MEe(t,e){let n=t.nodeValue.length,r=document.createRange();for(let i=0;i=(s.left+s.right)/2?1:0)}}return{node:t,offset:0}}function aD(t,e){return t.left>=e.left-1&&t.left<=e.right+1&&t.top>=e.top-1&&t.top<=e.bottom+1}function AEe(t,e){let n=t.parentNode;return n&&/^li$/i.test(n.nodeName)&&e.left(a.left+a.right)/2?1:-1}return t.docView.posFromDOM(r,i,s)}function CEe(t,e,n,r){let i=-1;for(let s=e,a=!1;s!=t.dom;){let o=t.docView.nearestDesc(s,!0),l;if(!o)return null;if(o.dom.nodeType==1&&(o.node.isBlock&&o.parent||!o.contentDOM)&&((l=o.dom.getBoundingClientRect()).width||l.height)&&(o.node.isBlock&&o.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(o.dom.nodeName)&&(!a&&l.left>r.left||l.top>r.top?i=o.posBefore:(!a&&l.right-1?i:t.docView.posFromDOM(e,n,-1)}function dq(t,e,n){let r=t.childNodes.length;if(r&&n.tope.top&&i++}let u;cb&&i&&r.nodeType==1&&(u=r.childNodes[i-1]).nodeType==1&&u.contentEditable=="false"&&u.getBoundingClientRect().top>=e.top&&i--,r==t.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?o=t.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!="BR")&&(o=CEe(t,r,i,e))}o==null&&(o=TEe(t,a,e));let l=t.docView.nearestDesc(a,!0);return{pos:o,inside:l?l.posAtStart-l.border:-1}}function n6(t){return t.top=0&&i==r.nodeValue.length?(l--,d=1):n<0?l--:u++,ux(_u(Jl(r,l,u),d),d<0)}if(!t.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&i&&(n<0||i==Xa(r))){let l=r.childNodes[i-1];if(l.nodeType==1)return LT(l.getBoundingClientRect(),!1)}if(s==null&&i=0)}if(s==null&&i&&(n<0||i==Xa(r))){let l=r.childNodes[i-1],u=l.nodeType==3?Jl(l,Xa(l)-(a?0:1)):l.nodeType==1&&(l.nodeName!="BR"||!l.nextSibling)?l:null;if(u)return ux(_u(u,1),!1)}if(s==null&&i=0)}function ux(t,e){if(t.width==0)return t;let n=e?t.left:t.right;return{top:t.top,bottom:t.bottom,left:n,right:n}}function LT(t,e){if(t.height==0)return t;let n=e?t.top:t.bottom;return{top:n,bottom:n,left:t.left,right:t.right}}function fq(t,e,n){let r=t.state,i=t.root.activeElement;r!=e&&t.updateState(e),i!=t.dom&&t.focus();try{return n()}finally{r!=e&&t.updateState(r),i!=t.dom&&i&&i.focus()}}function PEe(t,e,n){let r=e.selection,i=n=="up"?r.$from:r.$to;return fq(t,e,()=>{let{node:s}=t.docView.domFromPos(i.pos,n=="up"?-1:1);for(;;){let o=t.docView.nearestDesc(s,!0);if(!o)break;if(o.node.isBlock){s=o.contentDOM||o.dom;break}s=o.dom.parentNode}let a=hq(t,i.pos,1);for(let o=s.firstChild;o;o=o.nextSibling){let l;if(o.nodeType==1)l=o.getClientRects();else if(o.nodeType==3)l=Jl(o,0,o.nodeValue.length).getClientRects();else continue;for(let u=0;ud.top+1&&(n=="up"?a.top-d.top>(d.bottom-a.top)*2:d.bottom-a.bottom>(a.bottom-d.top)*2))return!1}}return!0})}const REe=/[\u0590-\u08ac]/;function DEe(t,e,n){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,s=!i,a=i==r.parent.content.size,o=t.domSelection();return o?!REe.test(r.parent.textContent)||!o.modify?n=="left"||n=="backward"?s:a:fq(t,e,()=>{let{focusNode:l,focusOffset:u,anchorNode:d,anchorOffset:f}=t.domSelectionRange(),g=o.caretBidiLevel;o.modify("move",n,"character");let m=r.depth?t.docView.domAfterPos(r.before()):t.dom,{focusNode:x,focusOffset:y}=t.domSelectionRange(),v=x&&!m.contains(x.nodeType==1?x:x.parentNode)||l==x&&u==y;try{o.collapse(d,f),l&&(l!=d||u!=f)&&o.extend&&o.extend(l,u)}catch{}return g!=null&&(o.caretBidiLevel=g),v}):r.pos==r.start()||r.pos==r.end()}let r6=null,i6=null,s6=!1;function OEe(t,e,n){return r6==e&&i6==n?s6:(r6=e,i6=n,s6=n=="up"||n=="down"?PEe(t,e,n):DEe(t,e,n))}const no=0,a6=1,ah=2,dl=3;class ub{constructor(e,n,r,i){this.parent=e,this.children=n,this.dom=r,this.contentDOM=i,this.dirty=no,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,n,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let n=0;nZi(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(n==0)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!1;break}if(s.previousSibling)break}if(i==null&&n==e.childNodes.length)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!0;break}if(s.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,n=!1){for(let r=!0,i=e;i;i=i.parentNode){let s=this.getDesc(i),a;if(s&&(!n||s.node))if(r&&(a=s.nodeDOM)&&!(a.nodeType==1?a.contains(e.nodeType==1?e:e.parentNode):a==e))r=!1;else return s}}getDesc(e){let n=e.pmViewDesc;for(let r=n;r;r=r.parent)if(r==this)return n}posFromDOM(e,n,r){for(let i=e;i;i=i.parentNode){let s=this.getDesc(i);if(s)return s.localPosFromDOM(e,n,r)}return-1}descAt(e){for(let n=0,r=0;ne||a instanceof mq){i=e-s;break}s=o}if(i)return this.children[r].domFromPos(i-this.children[r].border,n);for(let s;r&&!(s=this.children[r-1]).size&&s instanceof pq&&s.side>=0;r--);if(n<=0){let s,a=!0;for(;s=r?this.children[r-1]:null,!(!s||s.dom.parentNode==this.contentDOM);r--,a=!1);return s&&n&&a&&!s.border&&!s.domAtom?s.domFromPos(s.size,n):{node:this.contentDOM,offset:s?Zi(s.dom)+1:0}}else{let s,a=!0;for(;s=r=d&&n<=u-l.border&&l.node&&l.contentDOM&&this.contentDOM.contains(l.contentDOM))return l.parseRange(e,n,d);e=a;for(let f=o;f>0;f--){let g=this.children[f-1];if(g.size&&g.dom.parentNode==this.contentDOM&&!g.emptyChildAt(1)){i=Zi(g.dom)+1;break}e-=g.size}i==-1&&(i=0)}if(i>-1&&(u>n||o==this.children.length-1)){n=u;for(let d=o+1;dx&&an){let x=o;o=l,l=x}let m=document.createRange();m.setEnd(l.node,l.offset),m.setStart(o.node,o.offset),u.removeAllRanges(),u.addRange(m)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,n){for(let r=0,i=0;i=r:er){let o=r+s.border,l=a-s.border;if(e>=o&&n<=l){this.dirty=e==r||n==a?ah:a6,e==o&&n==l&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=dl:s.markDirty(e-o,n-o);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?ah:dl}r=a}this.dirty=ah}markParentsDirty(){let e=1;for(let n=this.parent;n;n=n.parent,e++){let r=e==1?ah:a6;n.dirty{if(!s)return i;if(s.parent)return s.parent.posBeforeChild(s)})),!n.type.spec.raw){if(a.nodeType!=1){let o=document.createElement("span");o.appendChild(a),a=o}a.contentEditable="false",a.classList.add("ProseMirror-widget")}super(e,[],a,null),this.widget=n,this.widget=n,s=this}matchesWidget(e){return this.dirty==no&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let n=this.widget.spec.stopEvent;return n?n(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get ignoreForSelection(){return!!this.widget.type.spec.relaxedSide}get side(){return this.widget.type.side}}class jEe extends ub{constructor(e,n,r,i){super(e,[],n,null),this.textDOM=r,this.text=i}get size(){return this.text.length}localPosFromDOM(e,n){return e!=this.textDOM?this.posAtStart+(n?this.size:0):this.posAtStart+n}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}}class Gh extends ub{constructor(e,n,r,i,s){super(e,[],r,i),this.mark=n,this.spec=s}static create(e,n,r,i){let s=i.nodeViews[n.type.name],a=s&&s(n,i,r);return(!a||!a.dom)&&(a=sf.renderSpec(document,n.type.spec.toDOM(n,r),null,n.attrs)),new Gh(e,n,a.dom,a.contentDOM||a.dom,a)}parseRule(){return this.dirty&dl||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=dl&&this.mark.eq(e)}markDirty(e,n){if(super.markDirty(e,n),this.dirty!=no){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty0&&(s=Ak(s,0,e,r));for(let o=0;o{if(!l)return a;if(l.parent)return l.parent.posBeforeChild(l)},r,i),d=u&&u.dom,f=u&&u.contentDOM;if(n.isText){if(!d)d=document.createTextNode(n.text);else if(d.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else d||({dom:d,contentDOM:f}=sf.renderSpec(document,n.type.spec.toDOM(n),null,n.attrs));!f&&!n.isText&&d.nodeName!="BR"&&(d.hasAttribute("contenteditable")||(d.contentEditable="false"),n.type.spec.draggable&&(d.draggable=!0));let g=d;return d=bq(d,r,n),u?l=new LEe(e,n,r,i,d,f||null,g,u,s,a+1):n.isText?new IS(e,n,r,i,d,g,s):new Ku(e,n,r,i,d,f||null,g,s,a+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let n=this.children.length-1;n>=0;n--){let r=this.children[n];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>pt.empty)}return e}matchesNode(e,n,r){return this.dirty==no&&e.eq(this.node)&&C1(n,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,n){let r=this.node.inlineContent,i=n,s=e.composing?this.localCompositionInfo(e,n):null,a=s&&s.pos>-1?s:null,o=s&&s.pos<0,l=new UEe(this,a&&a.node,e);BEe(this.node,this.innerDeco,(u,d,f)=>{u.spec.marks?l.syncToMarks(u.spec.marks,r,e):u.type.side>=0&&!f&&l.syncToMarks(d==this.node.childCount?Zn.none:this.node.child(d).marks,r,e),l.placeWidget(u,e,i)},(u,d,f,g)=>{l.syncToMarks(u.marks,r,e);let m;l.findNodeMatch(u,d,f,g)||o&&e.state.selection.from>i&&e.state.selection.to-1&&l.updateNodeAt(u,d,f,m,e)||l.updateNextNode(u,d,f,e,g,i)||l.addNode(u,d,f,e,i),i+=u.nodeSize}),l.syncToMarks([],r,e),this.node.isTextblock&&l.addTextblockHacks(),l.destroyRest(),(l.changed||this.dirty==ah)&&(a&&this.protectLocalComposition(e,a),gq(this.contentDOM,this.children,e),vm&&HEe(this.dom))}localCompositionInfo(e,n){let{from:r,to:i}=e.state.selection;if(!(e.state.selection instanceof qt)||rn+this.node.content.size)return null;let s=e.input.compositionNode;if(!s||!this.dom.contains(s.parentNode))return null;if(this.node.inlineContent){let a=s.nodeValue,o=$Ee(this.node.content,a,r-n,i-n);return o<0?null:{node:s,pos:o,text:a}}else return{node:s,pos:-1,text:""}}protectLocalComposition(e,{node:n,pos:r,text:i}){if(this.getDesc(n))return;let s=n;for(;s.parentNode!=this.contentDOM;s=s.parentNode){for(;s.previousSibling;)s.parentNode.removeChild(s.previousSibling);for(;s.nextSibling;)s.parentNode.removeChild(s.nextSibling);s.pmViewDesc&&(s.pmViewDesc=void 0)}let a=new jEe(this,s,n,i);e.input.compositionNodes.push(a),this.children=Ak(this.children,r,r+i.length,e,a)}update(e,n,r,i){return this.dirty==dl||!e.sameMarkup(this.node)?!1:(this.updateInner(e,n,r,i),!0)}updateInner(e,n,r,i){this.updateOuterDeco(n),this.node=e,this.innerDeco=r,this.contentDOM&&this.updateChildren(i,this.posAtStart),this.dirty=no}updateOuterDeco(e){if(C1(e,this.outerDeco))return;let n=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=xq(this.dom,this.nodeDOM,Mk(this.outerDeco,this.node,n),Mk(e,this.node,n)),this.dom!=r&&(r.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.nodeDOM.draggable=!0))}deselectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.nodeDOM.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}}function o6(t,e,n,r,i){bq(r,e,t);let s=new Ku(void 0,t,e,n,r,r,r,i,0);return s.contentDOM&&s.updateChildren(i,0),s}class IS extends Ku{constructor(e,n,r,i,s,a,o){super(e,n,r,i,s,null,a,o,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,n,r,i){return this.dirty==dl||this.dirty!=no&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(n),(this.dirty!=no||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,i.trackWrites==this.nodeDOM&&(i.trackWrites=null)),this.node=e,this.dirty=no,!0)}inParent(){let e=this.parent.contentDOM;for(let n=this.nodeDOM;n;n=n.parentNode)if(n==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,n,r){return e==this.nodeDOM?this.posAtStart+Math.min(n,this.node.text.length):super.localPosFromDOM(e,n,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,n,r){let i=this.node.cut(e,n),s=document.createTextNode(i.text);return new IS(this.parent,i,this.outerDeco,this.innerDeco,s,s,r)}markDirty(e,n){super.markDirty(e,n),this.dom!=this.nodeDOM&&(e==0||n==this.nodeDOM.nodeValue.length)&&(this.dirty=dl)}get domAtom(){return!1}isText(e){return this.node.text==e}}class mq extends ub{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==no&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}}class LEe extends Ku{constructor(e,n,r,i,s,a,o,l,u,d){super(e,n,r,i,s,a,o,u,d),this.spec=l}update(e,n,r,i){if(this.dirty==dl)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let s=this.spec.update(e,n,r);return s&&this.updateInner(e,n,r,i),s}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,n,r,i)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,n,r,i){this.spec.setSelection?this.spec.setSelection(e,n,r.root):super.setSelection(e,n,r,i)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}}function gq(t,e,n){let r=t.firstChild,i=!1;for(let s=0;s>1,a=Math.min(s,e.length);for(;i-1)o>this.index&&(this.changed=!0,this.destroyBetween(this.index,o)),this.top=this.top.children[this.index];else{let l=Gh.create(this.top,e[s],n,r);this.top.children.splice(this.index,0,l),this.top=l,this.changed=!0}this.index=0,s++}}findNodeMatch(e,n,r,i){let s=-1,a;if(i>=this.preMatch.index&&(a=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&a.matchesNode(e,n,r))s=this.top.children.indexOf(a,this.index);else for(let o=this.index,l=Math.min(this.top.children.length,o+5);o0;){let o;for(;;)if(r){let u=n.children[r-1];if(u instanceof Gh)n=u,r=u.children.length;else{o=u,r--;break}}else{if(n==e)break e;r=n.parent.children.indexOf(n),n=n.parent}let l=o.node;if(l){if(l!=t.child(i-1))break;--i,s.set(o,i),a.push(o)}}return{index:i,matched:s,matches:a.reverse()}}function zEe(t,e){return t.type.side-e.type.side}function BEe(t,e,n,r){let i=e.locals(t),s=0;if(i.length==0){for(let u=0;us;)o.push(i[a++]);let x=s+g.nodeSize;if(g.isText){let v=x;a!v.inline):o.slice();r(g,y,e.forChild(s,g),m),s=x}}function HEe(t){if(t.nodeName=="UL"||t.nodeName=="OL"){let e=t.style.cssText;t.style.cssText=e+"; list-style: square !important",window.getComputedStyle(t).listStyle,t.style.cssText=e}}function $Ee(t,e,n,r){for(let i=0,s=0;i=n){if(s>=r&&l.slice(r-e.length-o,r-o)==e)return r-e.length;let u=o=0&&u+e.length+o>=n)return o+u;if(n==r&&l.length>=r+e.length-o&&l.slice(r-o,r-o+e.length)==e)return r}}return-1}function Ak(t,e,n,r,i){let s=[];for(let a=0,o=0;a=n||d<=e?s.push(l):(un&&s.push(l.slice(n-u,l.size,r)))}return s}function oD(t,e=null){let n=t.domSelectionRange(),r=t.state.doc;if(!n.focusNode)return null;let i=t.docView.nearestDesc(n.focusNode),s=i&&i.size==0,a=t.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(a<0)return null;let o=r.resolve(a),l,u;if(LS(n)){for(l=a;i&&!i.node;)i=i.parent;let f=i.node;if(i&&f.isAtom&&Ht.isSelectable(f)&&i.parent&&!(f.isInline&&mEe(n.focusNode,n.focusOffset,i.dom))){let g=i.posBefore;u=new Ht(a==g?o:r.resolve(g))}}else{if(n instanceof t.dom.ownerDocument.defaultView.Selection&&n.rangeCount>1){let f=a,g=a;for(let m=0;m{(n.anchorNode!=r||n.anchorOffset!=i)&&(e.removeEventListener("selectionchange",t.input.hideSelectionGuard),setTimeout(()=>{(!vq(t)||t.state.selection.visible)&&t.dom.classList.remove("ProseMirror-hideselection")},20))})}function GEe(t){let e=t.domSelection();if(!e)return;let n=t.cursorWrapper.dom,r=n.nodeName=="IMG";r?e.collapse(n.parentNode,Zi(n)+1):e.collapse(n,0),!r&&!t.state.selection.visible&&Ws&&qu<=11&&(n.disabled=!0,n.disabled=!1)}function yq(t,e){if(e instanceof Ht){let n=t.docView.descAt(e.from);n!=t.lastSelectedViewDesc&&(h6(t),n&&n.selectNode(),t.lastSelectedViewDesc=n)}else h6(t)}function h6(t){t.lastSelectedViewDesc&&(t.lastSelectedViewDesc.parent&&t.lastSelectedViewDesc.deselectNode(),t.lastSelectedViewDesc=void 0)}function lD(t,e,n,r){return t.someProp("createSelectionBetween",i=>i(t,e,n))||qt.between(e,n,r)}function f6(t){return t.editable&&!t.hasFocus()?!1:_q(t)}function _q(t){let e=t.domSelectionRange();if(!e.anchorNode)return!1;try{return t.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(t.editable||t.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch{return!1}}function WEe(t){let e=t.docView.domFromPos(t.state.selection.anchor,0),n=t.domSelectionRange();return Vh(e.node,e.offset,n.anchorNode,n.anchorOffset)}function Tk(t,e){let{$anchor:n,$head:r}=t.selection,i=e>0?n.max(r):n.min(r),s=i.parent.inlineContent?i.depth?t.doc.resolve(e>0?i.after():i.before()):null:i;return s&&ln.findFrom(s,e)}function Eu(t,e){return t.dispatch(t.state.tr.setSelection(e).scrollIntoView()),!0}function p6(t,e,n){let r=t.state.selection;if(r instanceof qt)if(n.indexOf("s")>-1){let{$head:i}=r,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!s||s.isText||!s.isLeaf)return!1;let a=t.state.doc.resolve(i.pos+s.nodeSize*(e<0?-1:1));return Eu(t,new qt(r.$anchor,a))}else if(r.empty){if(t.endOfTextblock(e>0?"forward":"backward")){let i=Tk(t.state,e);return i&&i instanceof Ht?Eu(t,i):!1}else if(!($a&&n.indexOf("m")>-1)){let i=r.$head,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,a;if(!s||s.isText)return!1;let o=e<0?i.pos-s.nodeSize:i.pos;return s.isAtom||(a=t.docView.descAt(o))&&!a.contentDOM?Ht.isSelectable(s)?Eu(t,new Ht(e<0?t.state.doc.resolve(i.pos-s.nodeSize):i)):cb?Eu(t,new qt(t.state.doc.resolve(e<0?o:o+s.nodeSize))):!1:!1}}else return!1;else{if(r instanceof Ht&&r.node.isInline)return Eu(t,new qt(e>0?r.$to:r.$from));{let i=Tk(t.state,e);return i?Eu(t,i):!1}}}function N1(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function Vx(t,e){let n=t.pmViewDesc;return n&&n.size==0&&(e<0||t.nextSibling||t.nodeName!="BR")}function wp(t,e){return e<0?qEe(t):KEe(t)}function qEe(t){let e=t.domSelectionRange(),n=e.focusNode,r=e.focusOffset;if(!n)return;let i,s,a=!1;for(to&&n.nodeType==1&&r0){if(n.nodeType!=1)break;{let o=n.childNodes[r-1];if(Vx(o,-1))i=n,s=--r;else if(o.nodeType==3)n=o,r=n.nodeValue.length;else break}}else{if(wq(n))break;{let o=n.previousSibling;for(;o&&Vx(o,-1);)i=n.parentNode,s=Zi(o),o=o.previousSibling;if(o)n=o,r=N1(n);else{if(n=n.parentNode,n==t.dom)break;r=0}}}a?Ck(t,n,r):i&&Ck(t,i,s)}function KEe(t){let e=t.domSelectionRange(),n=e.focusNode,r=e.focusOffset;if(!n)return;let i=N1(n),s,a;for(;;)if(r{t.state==i&&gc(t)},50)}function m6(t,e){let n=t.state.doc.resolve(e);if(!(us||bEe)&&n.parent.inlineContent){let i=t.coordsAtPos(e);if(e>n.start()){let s=t.coordsAtPos(e-1),a=(s.top+s.bottom)/2;if(a>i.top&&a1)return s.lefti.top&&a1)return s.left>i.left?"ltr":"rtl"}}return getComputedStyle(t.dom).direction=="rtl"?"rtl":"ltr"}function g6(t,e,n){let r=t.state.selection;if(r instanceof qt&&!r.empty||n.indexOf("s")>-1||$a&&n.indexOf("m")>-1)return!1;let{$from:i,$to:s}=r;if(!i.parent.inlineContent||t.endOfTextblock(e<0?"up":"down")){let a=Tk(t.state,e);if(a&&a instanceof Ht)return Eu(t,a)}if(!i.parent.inlineContent){let a=e<0?i:s,o=r instanceof ba?ln.near(a,e):ln.findFrom(a,e);return o?Eu(t,o):!1}return!1}function x6(t,e){if(!(t.state.selection instanceof qt))return!0;let{$head:n,$anchor:r,empty:i}=t.state.selection;if(!n.sameParent(r))return!0;if(!i)return!1;if(t.endOfTextblock(e>0?"forward":"backward"))return!0;let s=!n.textOffset&&(e<0?n.nodeBefore:n.nodeAfter);if(s&&!s.isText){let a=t.state.tr;return e<0?a.delete(n.pos-s.nodeSize,n.pos):a.delete(n.pos,n.pos+s.nodeSize),t.dispatch(a),!0}return!1}function b6(t,e,n){t.domObserver.stop(),e.contentEditable=n,t.domObserver.start()}function ZEe(t){if(!Ms||t.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:n}=t.domSelectionRange();if(e&&e.nodeType==1&&n==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let r=e.firstChild;b6(t,r,"true"),setTimeout(()=>b6(t,r,"false"),20)}return!1}function QEe(t){let e="";return t.ctrlKey&&(e+="c"),t.metaKey&&(e+="m"),t.altKey&&(e+="a"),t.shiftKey&&(e+="s"),e}function JEe(t,e){let n=e.keyCode,r=QEe(e);if(n==8||$a&&n==72&&r=="c")return x6(t,-1)||wp(t,-1);if(n==46&&!e.shiftKey||$a&&n==68&&r=="c")return x6(t,1)||wp(t,1);if(n==13||n==27)return!0;if(n==37||$a&&n==66&&r=="c"){let i=n==37?m6(t,t.state.selection.from)=="ltr"?-1:1:-1;return p6(t,i,r)||wp(t,i)}else if(n==39||$a&&n==70&&r=="c"){let i=n==39?m6(t,t.state.selection.from)=="ltr"?1:-1:1;return p6(t,i,r)||wp(t,i)}else{if(n==38||$a&&n==80&&r=="c")return g6(t,-1,r)||wp(t,-1);if(n==40||$a&&n==78&&r=="c")return ZEe(t)||g6(t,1,r)||wp(t,1);if(r==($a?"m":"c")&&(n==66||n==73||n==89||n==90))return!0}return!1}function cD(t,e){t.someProp("transformCopied",m=>{e=m(e,t)});let n=[],{content:r,openStart:i,openEnd:s}=e;for(;i>1&&s>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,s--;let m=r.firstChild;n.push(m.type.name,m.attrs!=m.type.defaultAttrs?m.attrs:null),r=m.content}let a=t.someProp("clipboardSerializer")||sf.fromSchema(t.state.schema),o=Cq(),l=o.createElement("div");l.appendChild(a.serializeFragment(r,{document:o}));let u=l.firstChild,d,f=0;for(;u&&u.nodeType==1&&(d=Tq[u.nodeName.toLowerCase()]);){for(let m=d.length-1;m>=0;m--){let x=o.createElement(d[m]);for(;l.firstChild;)x.appendChild(l.firstChild);l.appendChild(x),f++}u=l.firstChild}u&&u.nodeType==1&&u.setAttribute("data-pm-slice",`${i} ${s}${f?` -${f}`:""} ${JSON.stringify(n)}`);let g=t.someProp("clipboardTextSerializer",m=>m(e,t))||e.content.textBetween(0,e.content.size,` +`),f&&x==m.nodeValue.length)for(let y=m,v;y;y=y.parentNode){if(v=y.nextSibling){v.nodeName=="BR"&&(o=l={node:v.parentNode,offset:Zi(v)+1});break}let b=y.pmViewDesc;if(b&&b.node&&b.node.isBlock)break}}else{let y=m.childNodes[x-1];f=y&&(y.nodeName=="BR"||y.contentEditable=="false")}}if(to&&d.focusNode&&d.focusNode!=l.node&&d.focusNode.nodeType==1){let m=d.focusNode.childNodes[d.focusOffset];m&&m.contentEditable=="false"&&(i=!0)}if(!(i||f&&Ms)&&Vh(o.node,o.offset,d.anchorNode,d.anchorOffset)&&Vh(l.node,l.offset,d.focusNode,d.focusOffset))return;let g=!1;if((u.extend||e==n)&&!(f&&to)){u.collapse(o.node,o.offset);try{e!=n&&u.extend(l.node,l.offset),g=!0}catch{}}if(!g){if(e>n){let x=o;o=l,l=x}let m=document.createRange();m.setEnd(l.node,l.offset),m.setStart(o.node,o.offset),u.removeAllRanges(),u.addRange(m)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,n){for(let r=0,i=0;i=r:er){let o=r+s.border,l=a-s.border;if(e>=o&&n<=l){this.dirty=e==r||n==a?ah:a6,e==o&&n==l&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=dl:s.markDirty(e-o,n-o);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?ah:dl}r=a}this.dirty=ah}markParentsDirty(){let e=1;for(let n=this.parent;n;n=n.parent,e++){let r=e==1?ah:a6;n.dirty{if(!s)return i;if(s.parent)return s.parent.posBeforeChild(s)})),!n.type.spec.raw){if(a.nodeType!=1){let o=document.createElement("span");o.appendChild(a),a=o}a.contentEditable="false",a.classList.add("ProseMirror-widget")}super(e,[],a,null),this.widget=n,this.widget=n,s=this}matchesWidget(e){return this.dirty==no&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let n=this.widget.spec.stopEvent;return n?n(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get ignoreForSelection(){return!!this.widget.type.spec.relaxedSide}get side(){return this.widget.type.side}}class jEe extends ub{constructor(e,n,r,i){super(e,[],n,null),this.textDOM=r,this.text=i}get size(){return this.text.length}localPosFromDOM(e,n){return e!=this.textDOM?this.posAtStart+(n?this.size:0):this.posAtStart+n}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}}class Gh extends ub{constructor(e,n,r,i,s){super(e,[],r,i),this.mark=n,this.spec=s}static create(e,n,r,i){let s=i.nodeViews[n.type.name],a=s&&s(n,i,r);return(!a||!a.dom)&&(a=sf.renderSpec(document,n.type.spec.toDOM(n,r),null,n.attrs)),new Gh(e,n,a.dom,a.contentDOM||a.dom,a)}parseRule(){return this.dirty&dl||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=dl&&this.mark.eq(e)}markDirty(e,n){if(super.markDirty(e,n),this.dirty!=no){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty0&&(s=Ak(s,0,e,r));for(let o=0;o{if(!l)return a;if(l.parent)return l.parent.posBeforeChild(l)},r,i),d=u&&u.dom,f=u&&u.contentDOM;if(n.isText){if(!d)d=document.createTextNode(n.text);else if(d.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else d||({dom:d,contentDOM:f}=sf.renderSpec(document,n.type.spec.toDOM(n),null,n.attrs));!f&&!n.isText&&d.nodeName!="BR"&&(d.hasAttribute("contenteditable")||(d.contentEditable="false"),n.type.spec.draggable&&(d.draggable=!0));let g=d;return d=bq(d,r,n),u?l=new LEe(e,n,r,i,d,f||null,g,u,s,a+1):n.isText?new IS(e,n,r,i,d,g,s):new Ku(e,n,r,i,d,f||null,g,s,a+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let n=this.children.length-1;n>=0;n--){let r=this.children[n];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>pt.empty)}return e}matchesNode(e,n,r){return this.dirty==no&&e.eq(this.node)&&C1(n,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,n){let r=this.node.inlineContent,i=n,s=e.composing?this.localCompositionInfo(e,n):null,a=s&&s.pos>-1?s:null,o=s&&s.pos<0,l=new UEe(this,a&&a.node,e);BEe(this.node,this.innerDeco,(u,d,f)=>{u.spec.marks?l.syncToMarks(u.spec.marks,r,e):u.type.side>=0&&!f&&l.syncToMarks(d==this.node.childCount?Qn.none:this.node.child(d).marks,r,e),l.placeWidget(u,e,i)},(u,d,f,g)=>{l.syncToMarks(u.marks,r,e);let m;l.findNodeMatch(u,d,f,g)||o&&e.state.selection.from>i&&e.state.selection.to-1&&l.updateNodeAt(u,d,f,m,e)||l.updateNextNode(u,d,f,e,g,i)||l.addNode(u,d,f,e,i),i+=u.nodeSize}),l.syncToMarks([],r,e),this.node.isTextblock&&l.addTextblockHacks(),l.destroyRest(),(l.changed||this.dirty==ah)&&(a&&this.protectLocalComposition(e,a),gq(this.contentDOM,this.children,e),vm&&HEe(this.dom))}localCompositionInfo(e,n){let{from:r,to:i}=e.state.selection;if(!(e.state.selection instanceof qt)||rn+this.node.content.size)return null;let s=e.input.compositionNode;if(!s||!this.dom.contains(s.parentNode))return null;if(this.node.inlineContent){let a=s.nodeValue,o=$Ee(this.node.content,a,r-n,i-n);return o<0?null:{node:s,pos:o,text:a}}else return{node:s,pos:-1,text:""}}protectLocalComposition(e,{node:n,pos:r,text:i}){if(this.getDesc(n))return;let s=n;for(;s.parentNode!=this.contentDOM;s=s.parentNode){for(;s.previousSibling;)s.parentNode.removeChild(s.previousSibling);for(;s.nextSibling;)s.parentNode.removeChild(s.nextSibling);s.pmViewDesc&&(s.pmViewDesc=void 0)}let a=new jEe(this,s,n,i);e.input.compositionNodes.push(a),this.children=Ak(this.children,r,r+i.length,e,a)}update(e,n,r,i){return this.dirty==dl||!e.sameMarkup(this.node)?!1:(this.updateInner(e,n,r,i),!0)}updateInner(e,n,r,i){this.updateOuterDeco(n),this.node=e,this.innerDeco=r,this.contentDOM&&this.updateChildren(i,this.posAtStart),this.dirty=no}updateOuterDeco(e){if(C1(e,this.outerDeco))return;let n=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=xq(this.dom,this.nodeDOM,Mk(this.outerDeco,this.node,n),Mk(e,this.node,n)),this.dom!=r&&(r.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.nodeDOM.draggable=!0))}deselectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.nodeDOM.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}}function o6(t,e,n,r,i){bq(r,e,t);let s=new Ku(void 0,t,e,n,r,r,r,i,0);return s.contentDOM&&s.updateChildren(i,0),s}class IS extends Ku{constructor(e,n,r,i,s,a,o){super(e,n,r,i,s,null,a,o,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,n,r,i){return this.dirty==dl||this.dirty!=no&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(n),(this.dirty!=no||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,i.trackWrites==this.nodeDOM&&(i.trackWrites=null)),this.node=e,this.dirty=no,!0)}inParent(){let e=this.parent.contentDOM;for(let n=this.nodeDOM;n;n=n.parentNode)if(n==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,n,r){return e==this.nodeDOM?this.posAtStart+Math.min(n,this.node.text.length):super.localPosFromDOM(e,n,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,n,r){let i=this.node.cut(e,n),s=document.createTextNode(i.text);return new IS(this.parent,i,this.outerDeco,this.innerDeco,s,s,r)}markDirty(e,n){super.markDirty(e,n),this.dom!=this.nodeDOM&&(e==0||n==this.nodeDOM.nodeValue.length)&&(this.dirty=dl)}get domAtom(){return!1}isText(e){return this.node.text==e}}class mq extends ub{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==no&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}}class LEe extends Ku{constructor(e,n,r,i,s,a,o,l,u,d){super(e,n,r,i,s,a,o,u,d),this.spec=l}update(e,n,r,i){if(this.dirty==dl)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let s=this.spec.update(e,n,r);return s&&this.updateInner(e,n,r,i),s}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,n,r,i)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,n,r,i){this.spec.setSelection?this.spec.setSelection(e,n,r.root):super.setSelection(e,n,r,i)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}}function gq(t,e,n){let r=t.firstChild,i=!1;for(let s=0;s>1,a=Math.min(s,e.length);for(;i-1)o>this.index&&(this.changed=!0,this.destroyBetween(this.index,o)),this.top=this.top.children[this.index];else{let l=Gh.create(this.top,e[s],n,r);this.top.children.splice(this.index,0,l),this.top=l,this.changed=!0}this.index=0,s++}}findNodeMatch(e,n,r,i){let s=-1,a;if(i>=this.preMatch.index&&(a=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&a.matchesNode(e,n,r))s=this.top.children.indexOf(a,this.index);else for(let o=this.index,l=Math.min(this.top.children.length,o+5);o0;){let o;for(;;)if(r){let u=n.children[r-1];if(u instanceof Gh)n=u,r=u.children.length;else{o=u,r--;break}}else{if(n==e)break e;r=n.parent.children.indexOf(n),n=n.parent}let l=o.node;if(l){if(l!=t.child(i-1))break;--i,s.set(o,i),a.push(o)}}return{index:i,matched:s,matches:a.reverse()}}function zEe(t,e){return t.type.side-e.type.side}function BEe(t,e,n,r){let i=e.locals(t),s=0;if(i.length==0){for(let u=0;us;)o.push(i[a++]);let x=s+g.nodeSize;if(g.isText){let v=x;a!v.inline):o.slice();r(g,y,e.forChild(s,g),m),s=x}}function HEe(t){if(t.nodeName=="UL"||t.nodeName=="OL"){let e=t.style.cssText;t.style.cssText=e+"; list-style: square !important",window.getComputedStyle(t).listStyle,t.style.cssText=e}}function $Ee(t,e,n,r){for(let i=0,s=0;i=n){if(s>=r&&l.slice(r-e.length-o,r-o)==e)return r-e.length;let u=o=0&&u+e.length+o>=n)return o+u;if(n==r&&l.length>=r+e.length-o&&l.slice(r-o,r-o+e.length)==e)return r}}return-1}function Ak(t,e,n,r,i){let s=[];for(let a=0,o=0;a=n||d<=e?s.push(l):(un&&s.push(l.slice(n-u,l.size,r)))}return s}function oD(t,e=null){let n=t.domSelectionRange(),r=t.state.doc;if(!n.focusNode)return null;let i=t.docView.nearestDesc(n.focusNode),s=i&&i.size==0,a=t.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(a<0)return null;let o=r.resolve(a),l,u;if(LS(n)){for(l=a;i&&!i.node;)i=i.parent;let f=i.node;if(i&&f.isAtom&&Ht.isSelectable(f)&&i.parent&&!(f.isInline&&mEe(n.focusNode,n.focusOffset,i.dom))){let g=i.posBefore;u=new Ht(a==g?o:r.resolve(g))}}else{if(n instanceof t.dom.ownerDocument.defaultView.Selection&&n.rangeCount>1){let f=a,g=a;for(let m=0;m{(n.anchorNode!=r||n.anchorOffset!=i)&&(e.removeEventListener("selectionchange",t.input.hideSelectionGuard),setTimeout(()=>{(!vq(t)||t.state.selection.visible)&&t.dom.classList.remove("ProseMirror-hideselection")},20))})}function GEe(t){let e=t.domSelection();if(!e)return;let n=t.cursorWrapper.dom,r=n.nodeName=="IMG";r?e.collapse(n.parentNode,Zi(n)+1):e.collapse(n,0),!r&&!t.state.selection.visible&&Ws&&qu<=11&&(n.disabled=!0,n.disabled=!1)}function yq(t,e){if(e instanceof Ht){let n=t.docView.descAt(e.from);n!=t.lastSelectedViewDesc&&(h6(t),n&&n.selectNode(),t.lastSelectedViewDesc=n)}else h6(t)}function h6(t){t.lastSelectedViewDesc&&(t.lastSelectedViewDesc.parent&&t.lastSelectedViewDesc.deselectNode(),t.lastSelectedViewDesc=void 0)}function lD(t,e,n,r){return t.someProp("createSelectionBetween",i=>i(t,e,n))||qt.between(e,n,r)}function f6(t){return t.editable&&!t.hasFocus()?!1:_q(t)}function _q(t){let e=t.domSelectionRange();if(!e.anchorNode)return!1;try{return t.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(t.editable||t.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch{return!1}}function WEe(t){let e=t.docView.domFromPos(t.state.selection.anchor,0),n=t.domSelectionRange();return Vh(e.node,e.offset,n.anchorNode,n.anchorOffset)}function Tk(t,e){let{$anchor:n,$head:r}=t.selection,i=e>0?n.max(r):n.min(r),s=i.parent.inlineContent?i.depth?t.doc.resolve(e>0?i.after():i.before()):null:i;return s&&ln.findFrom(s,e)}function Eu(t,e){return t.dispatch(t.state.tr.setSelection(e).scrollIntoView()),!0}function p6(t,e,n){let r=t.state.selection;if(r instanceof qt)if(n.indexOf("s")>-1){let{$head:i}=r,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!s||s.isText||!s.isLeaf)return!1;let a=t.state.doc.resolve(i.pos+s.nodeSize*(e<0?-1:1));return Eu(t,new qt(r.$anchor,a))}else if(r.empty){if(t.endOfTextblock(e>0?"forward":"backward")){let i=Tk(t.state,e);return i&&i instanceof Ht?Eu(t,i):!1}else if(!($a&&n.indexOf("m")>-1)){let i=r.$head,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,a;if(!s||s.isText)return!1;let o=e<0?i.pos-s.nodeSize:i.pos;return s.isAtom||(a=t.docView.descAt(o))&&!a.contentDOM?Ht.isSelectable(s)?Eu(t,new Ht(e<0?t.state.doc.resolve(i.pos-s.nodeSize):i)):cb?Eu(t,new qt(t.state.doc.resolve(e<0?o:o+s.nodeSize))):!1:!1}}else return!1;else{if(r instanceof Ht&&r.node.isInline)return Eu(t,new qt(e>0?r.$to:r.$from));{let i=Tk(t.state,e);return i?Eu(t,i):!1}}}function N1(t){return t.nodeType==3?t.nodeValue.length:t.childNodes.length}function Vx(t,e){let n=t.pmViewDesc;return n&&n.size==0&&(e<0||t.nextSibling||t.nodeName!="BR")}function wp(t,e){return e<0?qEe(t):KEe(t)}function qEe(t){let e=t.domSelectionRange(),n=e.focusNode,r=e.focusOffset;if(!n)return;let i,s,a=!1;for(to&&n.nodeType==1&&r0){if(n.nodeType!=1)break;{let o=n.childNodes[r-1];if(Vx(o,-1))i=n,s=--r;else if(o.nodeType==3)n=o,r=n.nodeValue.length;else break}}else{if(wq(n))break;{let o=n.previousSibling;for(;o&&Vx(o,-1);)i=n.parentNode,s=Zi(o),o=o.previousSibling;if(o)n=o,r=N1(n);else{if(n=n.parentNode,n==t.dom)break;r=0}}}a?Ck(t,n,r):i&&Ck(t,i,s)}function KEe(t){let e=t.domSelectionRange(),n=e.focusNode,r=e.focusOffset;if(!n)return;let i=N1(n),s,a;for(;;)if(r{t.state==i&&gc(t)},50)}function m6(t,e){let n=t.state.doc.resolve(e);if(!(us||bEe)&&n.parent.inlineContent){let i=t.coordsAtPos(e);if(e>n.start()){let s=t.coordsAtPos(e-1),a=(s.top+s.bottom)/2;if(a>i.top&&a1)return s.lefti.top&&a1)return s.left>i.left?"ltr":"rtl"}}return getComputedStyle(t.dom).direction=="rtl"?"rtl":"ltr"}function g6(t,e,n){let r=t.state.selection;if(r instanceof qt&&!r.empty||n.indexOf("s")>-1||$a&&n.indexOf("m")>-1)return!1;let{$from:i,$to:s}=r;if(!i.parent.inlineContent||t.endOfTextblock(e<0?"up":"down")){let a=Tk(t.state,e);if(a&&a instanceof Ht)return Eu(t,a)}if(!i.parent.inlineContent){let a=e<0?i:s,o=r instanceof ba?ln.near(a,e):ln.findFrom(a,e);return o?Eu(t,o):!1}return!1}function x6(t,e){if(!(t.state.selection instanceof qt))return!0;let{$head:n,$anchor:r,empty:i}=t.state.selection;if(!n.sameParent(r))return!0;if(!i)return!1;if(t.endOfTextblock(e>0?"forward":"backward"))return!0;let s=!n.textOffset&&(e<0?n.nodeBefore:n.nodeAfter);if(s&&!s.isText){let a=t.state.tr;return e<0?a.delete(n.pos-s.nodeSize,n.pos):a.delete(n.pos,n.pos+s.nodeSize),t.dispatch(a),!0}return!1}function b6(t,e,n){t.domObserver.stop(),e.contentEditable=n,t.domObserver.start()}function ZEe(t){if(!Ms||t.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:n}=t.domSelectionRange();if(e&&e.nodeType==1&&n==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let r=e.firstChild;b6(t,r,"true"),setTimeout(()=>b6(t,r,"false"),20)}return!1}function QEe(t){let e="";return t.ctrlKey&&(e+="c"),t.metaKey&&(e+="m"),t.altKey&&(e+="a"),t.shiftKey&&(e+="s"),e}function JEe(t,e){let n=e.keyCode,r=QEe(e);if(n==8||$a&&n==72&&r=="c")return x6(t,-1)||wp(t,-1);if(n==46&&!e.shiftKey||$a&&n==68&&r=="c")return x6(t,1)||wp(t,1);if(n==13||n==27)return!0;if(n==37||$a&&n==66&&r=="c"){let i=n==37?m6(t,t.state.selection.from)=="ltr"?-1:1:-1;return p6(t,i,r)||wp(t,i)}else if(n==39||$a&&n==70&&r=="c"){let i=n==39?m6(t,t.state.selection.from)=="ltr"?1:-1:1;return p6(t,i,r)||wp(t,i)}else{if(n==38||$a&&n==80&&r=="c")return g6(t,-1,r)||wp(t,-1);if(n==40||$a&&n==78&&r=="c")return ZEe(t)||g6(t,1,r)||wp(t,1);if(r==($a?"m":"c")&&(n==66||n==73||n==89||n==90))return!0}return!1}function cD(t,e){t.someProp("transformCopied",m=>{e=m(e,t)});let n=[],{content:r,openStart:i,openEnd:s}=e;for(;i>1&&s>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,s--;let m=r.firstChild;n.push(m.type.name,m.attrs!=m.type.defaultAttrs?m.attrs:null),r=m.content}let a=t.someProp("clipboardSerializer")||sf.fromSchema(t.state.schema),o=Cq(),l=o.createElement("div");l.appendChild(a.serializeFragment(r,{document:o}));let u=l.firstChild,d,f=0;for(;u&&u.nodeType==1&&(d=Tq[u.nodeName.toLowerCase()]);){for(let m=d.length-1;m>=0;m--){let x=o.createElement(d[m]);for(;l.firstChild;)x.appendChild(l.firstChild);l.appendChild(x),f++}u=l.firstChild}u&&u.nodeType==1&&u.setAttribute("data-pm-slice",`${i} ${s}${f?` -${f}`:""} ${JSON.stringify(n)}`);let g=t.someProp("clipboardTextSerializer",m=>m(e,t))||e.content.textBetween(0,e.content.size,` `);return{dom:l,text:g,slice:e}}function Sq(t,e,n,r,i){let s=i.parent.type.spec.code,a,o;if(!n&&!e)return null;let l=!!e&&(r||s||!n);if(l){if(t.someProp("transformPastedText",g=>{e=g(e,s||r,t)}),s)return o=new Tt(pt.from(t.state.schema.text(e.replace(/\r\n?/g,` `))),0,0),t.someProp("transformPasted",g=>{o=g(o,t,!0)}),o;let f=t.someProp("clipboardTextParser",g=>g(e,i,r,t));if(f)o=f;else{let g=i.marks(),{schema:m}=t.state,x=sf.fromSchema(m);a=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(y=>{let v=a.appendChild(document.createElement("p"));y&&v.appendChild(x.serializeNode(m.text(y,g)))})}}else t.someProp("transformPastedHTML",f=>{n=f(n,t)}),a=rMe(n),cb&&iMe(a);let u=a&&a.querySelector("[data-pm-slice]"),d=u&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(u.getAttribute("data-pm-slice")||"");if(d&&d[3])for(let f=+d[3];f>0;f--){let g=a.firstChild;for(;g&&g.nodeType!=1;)g=g.nextSibling;if(!g)break;a=g}if(o||(o=(t.someProp("clipboardParser")||t.someProp("domParser")||Bx.fromSchema(t.state.schema)).parseSlice(a,{preserveWhitespace:!!(l||d),context:i,ruleFromNode(g){return g.nodeName=="BR"&&!g.nextSibling&&g.parentNode&&!eMe.test(g.parentNode.nodeName)?{ignore:!0}:null}})),d)o=sMe(v6(o,+d[1],+d[2]),d[4]);else if(o=Tt.maxOpen(tMe(o.content,i),!0),o.openStart||o.openEnd){let f=0,g=0;for(let m=o.content.firstChild;f{o=f(o,t,l)}),o}const eMe=/^(a|abbr|acronym|b|cite|code|del|em|i|ins|kbd|label|output|q|ruby|s|samp|span|strong|sub|sup|time|u|tt|var)$/i;function tMe(t,e){if(t.childCount<2)return t;for(let n=e.depth;n>=0;n--){let i=e.node(n).contentMatchAt(e.index(n)),s,a=[];if(t.forEach(o=>{if(!a)return;let l=i.findWrapping(o.type),u;if(!l)return a=null;if(u=a.length&&s.length&&Mq(l,s,o,a[a.length-1],0))a[a.length-1]=u;else{a.length&&(a[a.length-1]=Aq(a[a.length-1],s.length));let d=Eq(o,l);a.push(d),i=i.matchType(d.type),s=l}}),a)return pt.from(a)}return t}function Eq(t,e,n=0){for(let r=e.length-1;r>=n;r--)t=e[r].create(null,pt.from(t));return t}function Mq(t,e,n,r,i){if(i1&&(s=0),i=n&&(o=e<0?a.contentMatchAt(0).fillBefore(o,s<=i).append(o):o.append(a.contentMatchAt(a.childCount).fillBefore(pt.empty,!0))),t.replaceChild(e<0?0:t.childCount-1,a.copy(o))}function v6(t,e,n){return en})),UT.createHTML(t)):t}function rMe(t){let e=/^(\s*]*>)*/.exec(t);e&&(t=t.slice(e[0].length));let n=Cq().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(t),i;if((i=r&&Tq[r[1].toLowerCase()])&&(t=i.map(s=>"<"+s+">").join("")+t+i.map(s=>"").reverse().join("")),n.innerHTML=nMe(t),i)for(let s=0;s=0;o-=2){let l=n.nodes[r[o]];if(!l||l.hasRequiredAttrs())break;i=pt.from(l.create(r[o+1],i)),s++,a++}return new Tt(i,s,a)}const As={},Ts={},aMe={touchstart:!0,touchmove:!0};class oMe{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:"",button:0},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastChromeDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}}function lMe(t){for(let e in As){let n=As[e];t.dom.addEventListener(e,t.input.eventHandlers[e]=r=>{uMe(t,r)&&!uD(t,r)&&(t.editable||!(r.type in Ts))&&n(t,r)},aMe[e]?{passive:!0}:void 0)}Ms&&t.dom.addEventListener("input",()=>null),kk(t)}function zu(t,e){t.input.lastSelectionOrigin=e,t.input.lastSelectionTime=Date.now()}function cMe(t){t.domObserver.stop();for(let e in t.input.eventHandlers)t.dom.removeEventListener(e,t.input.eventHandlers[e]);clearTimeout(t.input.composingTimeout),clearTimeout(t.input.lastIOSEnterFallbackTimeout)}function kk(t){t.someProp("handleDOMEvents",e=>{for(let n in e)t.input.eventHandlers[n]||t.dom.addEventListener(n,t.input.eventHandlers[n]=r=>uD(t,r))})}function uD(t,e){return t.someProp("handleDOMEvents",n=>{let r=n[e.type];return r?r(t,e)||e.defaultPrevented:!1})}function uMe(t,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let n=e.target;n!=t.dom;n=n.parentNode)if(!n||n.nodeType==11||n.pmViewDesc&&n.pmViewDesc.stopEvent(e))return!1;return!0}function dMe(t,e){!uD(t,e)&&As[e.type]&&(t.editable||!(e.type in Ts))&&As[e.type](t,e)}Ts.keydown=(t,e)=>{let n=e;if(t.input.shiftKey=n.keyCode==16||n.shiftKey,!kq(t,n)&&(t.input.lastKeyCode=n.keyCode,t.input.lastKeyCodeTime=Date.now(),!(lc&&us&&n.keyCode==13)))if(n.keyCode!=229&&t.domObserver.forceFlush(),vm&&n.keyCode==13&&!n.ctrlKey&&!n.altKey&&!n.metaKey){let r=Date.now();t.input.lastIOSEnter=r,t.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{t.input.lastIOSEnter==r&&(t.someProp("handleKeyDown",i=>i(t,rh(13,"Enter"))),t.input.lastIOSEnter=0)},200)}else t.someProp("handleKeyDown",r=>r(t,n))||JEe(t,n)?n.preventDefault():zu(t,"key")};Ts.keyup=(t,e)=>{e.keyCode==16&&(t.input.shiftKey=!1)};Ts.keypress=(t,e)=>{let n=e;if(kq(t,n)||!n.charCode||n.ctrlKey&&!n.altKey||$a&&n.metaKey)return;if(t.someProp("handleKeyPress",i=>i(t,n))){n.preventDefault();return}let r=t.state.selection;if(!(r instanceof qt)||!r.$from.sameParent(r.$to)){let i=String.fromCharCode(n.charCode),s=()=>t.state.tr.insertText(i).scrollIntoView();!/[\r\n]/.test(i)&&!t.someProp("handleTextInput",a=>a(t,r.$from.pos,r.$to.pos,i,s))&&t.dispatch(s()),n.preventDefault()}};function US(t){return{left:t.clientX,top:t.clientY}}function hMe(t,e){let n=e.x-t.clientX,r=e.y-t.clientY;return n*n+r*r<100}function dD(t,e,n,r,i){if(r==-1)return!1;let s=t.state.doc.resolve(r);for(let a=s.depth+1;a>0;a--)if(t.someProp(e,o=>a>s.depth?o(t,n,s.nodeAfter,s.before(a),i,!0):o(t,n,s.node(a),s.before(a),i,!1)))return!0;return!1}function Zp(t,e,n){if(t.focused||t.focus(),t.state.selection.eq(e))return;let r=t.state.tr.setSelection(e);r.setMeta("pointer",!0),t.dispatch(r)}function fMe(t,e){if(e==-1)return!1;let n=t.state.doc.resolve(e),r=n.nodeAfter;return r&&r.isAtom&&Ht.isSelectable(r)?(Zp(t,new Ht(n)),!0):!1}function pMe(t,e){if(e==-1)return!1;let n=t.state.selection,r,i;n instanceof Ht&&(r=n.node);let s=t.state.doc.resolve(e);for(let a=s.depth+1;a>0;a--){let o=a>s.depth?s.nodeAfter:s.node(a);if(Ht.isSelectable(o)){r&&n.$from.depth>0&&a>=n.$from.depth&&s.before(n.$from.depth+1)==n.$from.pos?i=s.before(n.$from.depth):i=s.before(a);break}}return i!=null?(Zp(t,Ht.create(t.state.doc,i)),!0):!1}function mMe(t,e,n,r,i){return dD(t,"handleClickOn",e,n,r)||t.someProp("handleClick",s=>s(t,e,r))||(i?pMe(t,n):fMe(t,n))}function gMe(t,e,n,r){return dD(t,"handleDoubleClickOn",e,n,r)||t.someProp("handleDoubleClick",i=>i(t,e,r))}function xMe(t,e,n,r){return dD(t,"handleTripleClickOn",e,n,r)||t.someProp("handleTripleClick",i=>i(t,e,r))||bMe(t,n,r)}function bMe(t,e,n){if(n.button!=0)return!1;let r=t.state.doc;if(e==-1)return r.inlineContent?(Zp(t,qt.create(r,0,r.content.size)),!0):!1;let i=r.resolve(e);for(let s=i.depth+1;s>0;s--){let a=s>i.depth?i.nodeAfter:i.node(s),o=i.before(s);if(a.inlineContent)Zp(t,qt.create(r,o+1,o+1+a.content.size));else if(Ht.isSelectable(a))Zp(t,Ht.create(r,o));else continue;return!0}}function hD(t){return k1(t)}const Nq=$a?"metaKey":"ctrlKey";As.mousedown=(t,e)=>{let n=e;t.input.shiftKey=n.shiftKey;let r=hD(t),i=Date.now(),s="singleClick";i-t.input.lastClick.time<500&&hMe(n,t.input.lastClick)&&!n[Nq]&&t.input.lastClick.button==n.button&&(t.input.lastClick.type=="singleClick"?s="doubleClick":t.input.lastClick.type=="doubleClick"&&(s="tripleClick")),t.input.lastClick={time:i,x:n.clientX,y:n.clientY,type:s,button:n.button};let a=t.posAtCoords(US(n));a&&(s=="singleClick"?(t.input.mouseDown&&t.input.mouseDown.done(),t.input.mouseDown=new vMe(t,a,n,!!r)):(s=="doubleClick"?gMe:xMe)(t,a.pos,a.inside,n)?n.preventDefault():zu(t,"pointer"))};class vMe{constructor(e,n,r,i){this.view=e,this.pos=n,this.event=r,this.flushed=i,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!r[Nq],this.allowDefault=r.shiftKey;let s,a;if(n.inside>-1)s=e.state.doc.nodeAt(n.inside),a=n.inside;else{let d=e.state.doc.resolve(n.pos);s=d.parent,a=d.depth?d.before():0}const o=i?null:r.target,l=o?e.docView.nearestDesc(o,!0):null;this.target=l&&l.nodeDOM.nodeType==1?l.nodeDOM:null;let{selection:u}=e.state;(r.button==0&&s.type.spec.draggable&&s.type.spec.selectable!==!1||u instanceof Ht&&u.from<=a&&u.to>a)&&(this.mightDrag={node:s,pos:a,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&to&&!this.target.hasAttribute("contentEditable"))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout(()=>{this.view.input.mouseDown==this&&this.target.setAttribute("contentEditable","false")},20),this.view.domObserver.start()),e.root.addEventListener("mouseup",this.up=this.up.bind(this)),e.root.addEventListener("mousemove",this.move=this.move.bind(this)),zu(e,"pointer")}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute("draggable"),this.mightDrag.setUneditable&&this.target.removeAttribute("contentEditable"),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>gc(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let n=this.pos;this.view.state.doc!=this.startDoc&&(n=this.view.posAtCoords(US(e))),this.updateAllowDefault(e),this.allowDefault||!n?zu(this.view,"pointer"):mMe(this.view,n.pos,n.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||Ms&&this.mightDrag&&!this.mightDrag.node.isAtom||us&&!this.view.state.selection.visible&&Math.min(Math.abs(n.pos-this.view.state.selection.from),Math.abs(n.pos-this.view.state.selection.to))<=2)?(Zp(this.view,ln.near(this.view.state.doc.resolve(n.pos))),e.preventDefault()):zu(this.view,"pointer")}move(e){this.updateAllowDefault(e),zu(this.view,"pointer"),e.buttons==0&&this.done()}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}}As.touchstart=t=>{t.input.lastTouch=Date.now(),hD(t),zu(t,"pointer")};As.touchmove=t=>{t.input.lastTouch=Date.now(),zu(t,"pointer")};As.contextmenu=t=>hD(t);function kq(t,e){return t.composing?!0:Ms&&Math.abs(e.timeStamp-t.input.compositionEndedAt)<500?(t.input.compositionEndedAt=-2e8,!0):!1}const yMe=lc?5e3:-1;Ts.compositionstart=Ts.compositionupdate=t=>{if(!t.composing){t.domObserver.flush();let{state:e}=t,n=e.selection.$to;if(e.selection instanceof qt&&(e.storedMarks||!n.textOffset&&n.parentOffset&&n.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)))t.markCursor=t.state.storedMarks||n.marks(),k1(t,!0),t.markCursor=null;else if(k1(t,!e.selection.empty),to&&e.selection.empty&&n.parentOffset&&!n.textOffset&&n.nodeBefore.marks.length){let r=t.domSelectionRange();for(let i=r.focusNode,s=r.focusOffset;i&&i.nodeType==1&&s!=0;){let a=s<0?i.lastChild:i.childNodes[s-1];if(!a)break;if(a.nodeType==3){let o=t.domSelection();o&&o.collapse(a,a.nodeValue.length);break}else i=a,s=-1}}t.input.composing=!0}Pq(t,yMe)};Ts.compositionend=(t,e)=>{t.composing&&(t.input.composing=!1,t.input.compositionEndedAt=e.timeStamp,t.input.compositionPendingChanges=t.domObserver.pendingRecords().length?t.input.compositionID:0,t.input.compositionNode=null,t.input.compositionPendingChanges&&Promise.resolve().then(()=>t.domObserver.flush()),t.input.compositionID++,Pq(t,20))};function Pq(t,e){clearTimeout(t.input.composingTimeout),e>-1&&(t.input.composingTimeout=setTimeout(()=>k1(t),e))}function Rq(t){for(t.composing&&(t.input.composing=!1,t.input.compositionEndedAt=wMe());t.input.compositionNodes.length>0;)t.input.compositionNodes.pop().markParentsDirty()}function _Me(t){let e=t.domSelectionRange();if(!e.focusNode)return null;let n=fEe(e.focusNode,e.focusOffset),r=pEe(e.focusNode,e.focusOffset);if(n&&r&&n!=r){let i=r.pmViewDesc,s=t.domObserver.lastChangedTextNode;if(n==s||r==s)return s;if(!i||!i.isText(r.nodeValue))return r;if(t.input.compositionNode==r){let a=n.pmViewDesc;if(!(!a||!a.isText(n.nodeValue)))return r}}return n||r}function wMe(){let t=document.createEvent("Event");return t.initEvent("event",!0,!0),t.timeStamp}function k1(t,e=!1){if(!(lc&&t.domObserver.flushingSoon>=0)){if(t.domObserver.forceFlush(),Rq(t),e||t.docView&&t.docView.dirty){let n=oD(t),r=t.state.selection;return n&&!n.eq(r)?t.dispatch(t.state.tr.setSelection(n)):(t.markCursor||e)&&!r.$from.node(r.$from.sharedDepth(r.to)).inlineContent?t.dispatch(t.state.tr.deleteSelection()):t.updateState(t.state),!0}return!1}}function SMe(t,e){if(!t.dom.parentNode)return;let n=t.dom.parentNode.appendChild(document.createElement("div"));n.appendChild(e),n.style.cssText="position: fixed; left: -10000px; top: 10px";let r=getSelection(),i=document.createRange();i.selectNodeContents(e),t.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{n.parentNode&&n.parentNode.removeChild(n),t.focus()},50)}const N0=Ws&&qu<15||vm&&vEe<604;As.copy=Ts.cut=(t,e)=>{let n=e,r=t.state.selection,i=n.type=="cut";if(r.empty)return;let s=N0?null:n.clipboardData,a=r.content(),{dom:o,text:l}=cD(t,a);s?(n.preventDefault(),s.clearData(),s.setData("text/html",o.innerHTML),s.setData("text/plain",l)):SMe(t,o),i&&t.dispatch(t.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function EMe(t){return t.openStart==0&&t.openEnd==0&&t.content.childCount==1?t.content.firstChild:null}function MMe(t,e){if(!t.dom.parentNode)return;let n=t.input.shiftKey||t.state.selection.$from.parent.type.spec.code,r=t.dom.parentNode.appendChild(document.createElement(n?"textarea":"div"));n||(r.contentEditable="true"),r.style.cssText="position: fixed; left: -10000px; top: 10px",r.focus();let i=t.input.shiftKey&&t.input.lastKeyCode!=45;setTimeout(()=>{t.focus(),r.parentNode&&r.parentNode.removeChild(r),n?k0(t,r.value,null,i,e):k0(t,r.textContent,r.innerHTML,i,e)},50)}function k0(t,e,n,r,i){let s=Sq(t,e,n,r,t.state.selection.$from);if(t.someProp("handlePaste",l=>l(t,i,s||Tt.empty)))return!0;if(!s)return!1;let a=EMe(s),o=a?t.state.tr.replaceSelectionWith(a,r):t.state.tr.replaceSelection(s);return t.dispatch(o.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function Dq(t){let e=t.getData("text/plain")||t.getData("Text");if(e)return e;let n=t.getData("text/uri-list");return n?n.replace(/\r?\n/g," "):""}Ts.paste=(t,e)=>{let n=e;if(t.composing&&!lc)return;let r=N0?null:n.clipboardData,i=t.input.shiftKey&&t.input.lastKeyCode!=45;r&&k0(t,Dq(r),r.getData("text/html"),i,n)?n.preventDefault():MMe(t,n)};class Oq{constructor(e,n,r){this.slice=e,this.move=n,this.node=r}}const AMe=$a?"altKey":"ctrlKey";function jq(t,e){let n=t.someProp("dragCopies",r=>!r(e));return n??!e[AMe]}As.dragstart=(t,e)=>{let n=e,r=t.input.mouseDown;if(r&&r.done(),!n.dataTransfer)return;let i=t.state.selection,s=i.empty?null:t.posAtCoords(US(n)),a;if(!(s&&s.pos>=i.from&&s.pos<=(i instanceof Ht?i.to-1:i.to))){if(r&&r.mightDrag)a=Ht.create(t.state.doc,r.mightDrag.pos);else if(n.target&&n.target.nodeType==1){let f=t.docView.nearestDesc(n.target,!0);f&&f.node.type.spec.draggable&&f!=t.docView&&(a=Ht.create(t.state.doc,f.posBefore))}}let o=(a||t.state.selection).content(),{dom:l,text:u,slice:d}=cD(t,o);(!n.dataTransfer.files.length||!us||oq>120)&&n.dataTransfer.clearData(),n.dataTransfer.setData(N0?"Text":"text/html",l.innerHTML),n.dataTransfer.effectAllowed="copyMove",N0||n.dataTransfer.setData("text/plain",u),t.dragging=new Oq(d,jq(t,n),a)};As.dragend=t=>{let e=t.dragging;window.setTimeout(()=>{t.dragging==e&&(t.dragging=null)},50)};Ts.dragover=Ts.dragenter=(t,e)=>e.preventDefault();Ts.drop=(t,e)=>{let n=e,r=t.dragging;if(t.dragging=null,!n.dataTransfer)return;let i=t.posAtCoords(US(n));if(!i)return;let s=t.state.doc.resolve(i.pos),a=r&&r.slice;a?t.someProp("transformPasted",x=>{a=x(a,t,!1)}):a=Sq(t,Dq(n.dataTransfer),N0?null:n.dataTransfer.getData("text/html"),!1,s);let o=!!(r&&jq(t,n));if(t.someProp("handleDrop",x=>x(t,n,a||Tt.empty,o))){n.preventDefault();return}if(!a)return;n.preventDefault();let l=a?zW(t.state.doc,s.pos,a):s.pos;l==null&&(l=s.pos);let u=t.state.tr;if(o){let{node:x}=r;x?x.replace(u):u.deleteSelection()}let d=u.mapping.map(l),f=a.openStart==0&&a.openEnd==0&&a.content.childCount==1,g=u.doc;if(f?u.replaceRangeWith(d,d,a.content.firstChild):u.replaceRange(d,d,a),u.doc.eq(g))return;let m=u.doc.resolve(d);if(f&&Ht.isSelectable(a.content.firstChild)&&m.nodeAfter&&m.nodeAfter.sameMarkup(a.content.firstChild))u.setSelection(new Ht(m));else{let x=u.mapping.map(l);u.mapping.maps[u.mapping.maps.length-1].forEach((y,v,b,E)=>x=E),u.setSelection(lD(t,m,u.doc.resolve(x)))}t.focus(),t.dispatch(u.setMeta("uiEvent","drop"))};As.focus=t=>{t.input.lastFocus=Date.now(),t.focused||(t.domObserver.stop(),t.dom.classList.add("ProseMirror-focused"),t.domObserver.start(),t.focused=!0,setTimeout(()=>{t.docView&&t.hasFocus()&&!t.domObserver.currentSelection.eq(t.domSelectionRange())&&gc(t)},20))};As.blur=(t,e)=>{let n=e;t.focused&&(t.domObserver.stop(),t.dom.classList.remove("ProseMirror-focused"),t.domObserver.start(),n.relatedTarget&&t.dom.contains(n.relatedTarget)&&t.domObserver.currentSelection.clear(),t.focused=!1)};As.beforeinput=(t,e)=>{if(us&&lc&&e.inputType=="deleteContentBackward"){t.domObserver.flushSoon();let{domChangeCount:r}=t.input;setTimeout(()=>{if(t.input.domChangeCount!=r||(t.dom.blur(),t.focus(),t.someProp("handleKeyDown",s=>s(t,rh(8,"Backspace")))))return;let{$cursor:i}=t.state.selection;i&&i.pos>0&&t.dispatch(t.state.tr.delete(i.pos-1,i.pos).scrollIntoView())},50)}};for(let t in Ts)As[t]=Ts[t];function P0(t,e){if(t==e)return!0;for(let n in t)if(t[n]!==e[n])return!1;for(let n in e)if(!(n in t))return!1;return!0}class P1{constructor(e,n){this.toDOM=e,this.spec=n||yh,this.side=this.spec.side||0}map(e,n,r,i){let{pos:s,deleted:a}=e.mapResult(n.from+i,this.side<0?-1:1);return a?null:new ws(s-r,s-r,this)}valid(){return!0}eq(e){return this==e||e instanceof P1&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&P0(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class Xu{constructor(e,n){this.attrs=e,this.spec=n||yh}map(e,n,r,i){let s=e.map(n.from+i,this.spec.inclusiveStart?-1:1)-r,a=e.map(n.to+i,this.spec.inclusiveEnd?1:-1)-r;return s>=a?null:new ws(s,a,this)}valid(e,n){return n.from=e&&(!s||s(o.spec))&&r.push(o.copy(o.from+i,o.to+i))}for(let a=0;ae){let o=this.children[a]+1;this.children[a+2].findInner(e-o,n-o,r,i+o,s)}}map(e,n,r){return this==as||e.maps.length==0?this:this.mapInner(e,n,0,0,r||yh)}mapInner(e,n,r,i,s){let a;for(let o=0;o{let u=l+r,d;if(d=Iq(n,o,u)){for(i||(i=this.children.slice());so&&f.to=e){this.children[o]==e&&(r=this.children[o+2]);break}let s=e+1,a=s+n.content.size;for(let o=0;os&&l.type instanceof Xu){let u=Math.max(s,l.from)-s,d=Math.min(a,l.to)-s;ui.map(e,n,yh));return Pu.from(r)}forChild(e,n){if(n.isLeaf)return br.empty;let r=[];for(let i=0;in instanceof br)?e:e.reduce((n,r)=>n.concat(r instanceof br?r:r.members),[]))}}forEachSet(e){for(let n=0;n{let v=y-x-(m-g);for(let b=0;bE+d-f)continue;let S=o[b]+d-f;m>=S?o[b+1]=g<=S?-2:-1:g>=d&&v&&(o[b]+=v,o[b+1]+=v)}f+=v}),d=n.maps[u].map(d,-1)}let l=!1;for(let u=0;u=r.content.size){l=!0;continue}let g=n.map(t[u+1]+s,-1),m=g-i,{index:x,offset:y}=r.content.findIndex(f),v=r.maybeChild(x);if(v&&y==f&&y+v.nodeSize==m){let b=o[u+2].mapInner(n,v,d+1,t[u]+s+1,a);b!=as?(o[u]=f,o[u+1]=m,o[u+2]=b):(o[u+1]=-2,l=!0)}else l=!0}if(l){let u=CMe(o,t,e,n,i,s,a),d=R1(u,r,0,a);e=d.local;for(let f=0;fn&&a.to{let u=Iq(t,o,l+n);if(u){s=!0;let d=R1(u,o,n+l+1,r);d!=as&&i.push(l,l+o.nodeSize,d)}});let a=Lq(s?Uq(t):t,-n).sort(_h);for(let o=0;o0;)e++;t.splice(e,0,n)}function FT(t){let e=[];return t.someProp("decorations",n=>{let r=n(t.state);r&&r!=as&&e.push(r)}),t.cursorWrapper&&e.push(br.create(t.state.doc,[t.cursorWrapper.deco])),Pu.from(e)}const NMe={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},kMe=Ws&&qu<=11;class PMe{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}set(e){this.anchorNode=e.anchorNode,this.anchorOffset=e.anchorOffset,this.focusNode=e.focusNode,this.focusOffset=e.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(e){return e.anchorNode==this.anchorNode&&e.anchorOffset==this.anchorOffset&&e.focusNode==this.focusNode&&e.focusOffset==this.focusOffset}}class RMe{constructor(e,n){this.view=e,this.handleDOMChange=n,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new PMe,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(r=>{for(let i=0;ii.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),kMe&&(this.onCharData=r=>{this.queue.push({target:r.target,type:"characterData",oldValue:r.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,NMe)),this.onCharData&&this.view.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.connectSelection()}stop(){if(this.observer){let e=this.observer.takeRecords();if(e.length){for(let n=0;nthis.flush(),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener("DOMCharacterDataModified",this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}onSelectionChange(){if(f6(this.view)){if(this.suppressingSelectionUpdates)return gc(this.view);if(Ws&&qu<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&Vh(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let n=new Set,r;for(let s=e.focusNode;s;s=bm(s))n.add(s);for(let s=e.anchorNode;s;s=bm(s))if(n.has(s)){r=s;break}let i=r&&this.view.docView.nearestDesc(r);if(i&&i.ignoreMutation({type:"selection",target:r.nodeType==3?r.parentNode:r}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let n=this.pendingRecords();n.length&&(this.queue=[]);let r=e.domSelectionRange(),i=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(r)&&f6(e)&&!this.ignoreSelectionChange(r),s=-1,a=-1,o=!1,l=[];if(e.editable)for(let d=0;df.nodeName=="BR");if(d.length==2){let[f,g]=d;f.parentNode&&f.parentNode.parentNode==g.parentNode?g.remove():f.remove()}else{let{focusNode:f}=this.currentSelection;for(let g of d){let m=g.parentNode;m&&m.nodeName=="LI"&&(!f||jMe(e,f)!=m)&&g.remove()}}}let u=null;s<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1||i)&&(s>-1&&(e.docView.markDirty(s,a),DMe(e)),this.handleDOMChange(s,a,o,l),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||gc(e),this.currentSelection.set(r))}registerMutation(e,n){if(n.indexOf(e.target)>-1)return null;let r=this.view.docView.nearestDesc(e.target);if(e.type=="attributes"&&(r==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!r||r.ignoreMutation(e))return null;if(e.type=="childList"){for(let d=0;di;v--){let b=r.childNodes[v-1],E=b.pmViewDesc;if(b.nodeName=="BR"&&!E){s=v;break}if(!E||E.size)break}let f=t.state.doc,g=t.someProp("domParser")||Bx.fromSchema(t.state.schema),m=f.resolve(a),x=null,y=g.parse(r,{topNode:m.parent,topMatch:m.parent.contentMatchAt(m.index()),topOpen:!0,from:i,to:s,preserveWhitespace:m.parent.type.whitespace=="pre"?"full":!0,findPositions:u,ruleFromNode:IMe,context:m});if(u&&u[0].pos!=null){let v=u[0].pos,b=u[1]&&u[1].pos;b==null&&(b=v),x={anchor:v+a,head:b+a}}return{doc:y,sel:x,from:a,to:o}}function IMe(t){let e=t.pmViewDesc;if(e)return e.parseRule();if(t.nodeName=="BR"&&t.parentNode){if(Ms&&/^(ul|ol)$/i.test(t.parentNode.nodeName)){let n=document.createElement("div");return n.appendChild(document.createElement("li")),{skip:n}}else if(t.parentNode.lastChild==t||Ms&&/^(tr|table)$/i.test(t.parentNode.nodeName))return{ignore:!0}}else if(t.nodeName=="IMG"&&t.getAttribute("mark-placeholder"))return{ignore:!0};return null}const UMe=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|img|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function FMe(t,e,n,r,i){let s=t.input.compositionPendingChanges||(t.composing?t.input.compositionID:0);if(t.input.compositionPendingChanges=0,e<0){let C=t.input.lastSelectionTime>Date.now()-50?t.input.lastSelectionOrigin:null,I=oD(t,C);if(I&&!t.state.selection.eq(I)){if(us&&lc&&t.input.lastKeyCode===13&&Date.now()-100D(t,rh(13,"Enter"))))return;let N=t.state.tr.setSelection(I);C=="pointer"?N.setMeta("pointer",!0):C=="key"&&N.scrollIntoView(),s&&N.setMeta("composition",s),t.dispatch(N)}return}let a=t.state.doc.resolve(e),o=a.sharedDepth(n);e=a.before(o+1),n=t.state.doc.resolve(n).after(o+1);let l=t.state.selection,u=LMe(t,e,n),d=t.state.doc,f=d.slice(u.from,u.to),g,m;t.input.lastKeyCode===8&&Date.now()-100Date.now()-225||lc)&&i.some(C=>C.nodeType==1&&!UMe.test(C.nodeName))&&(!x||x.endA>=x.endB)&&t.someProp("handleKeyDown",C=>C(t,rh(13,"Enter")))){t.input.lastIOSEnter=0;return}if(!x)if(r&&l instanceof qt&&!l.empty&&l.$head.sameParent(l.$anchor)&&!t.composing&&!(u.sel&&u.sel.anchor!=u.sel.head))x={start:l.from,endA:l.to,endB:l.to};else{if(u.sel){let C=M6(t,t.state.doc,u.sel);if(C&&!C.eq(t.state.selection)){let I=t.state.tr.setSelection(C);s&&I.setMeta("composition",s),t.dispatch(I)}}return}t.state.selection.fromt.state.selection.from&&x.start<=t.state.selection.from+2&&t.state.selection.from>=u.from?x.start=t.state.selection.from:x.endA=t.state.selection.to-2&&t.state.selection.to<=u.to&&(x.endB+=t.state.selection.to-x.endA,x.endA=t.state.selection.to)),Ws&&qu<=11&&x.endB==x.start+1&&x.endA==x.start&&x.start>u.from&&u.doc.textBetween(x.start-u.from-1,x.start-u.from+1)=="  "&&(x.start--,x.endA--,x.endB--);let y=u.doc.resolveNoCache(x.start-u.from),v=u.doc.resolveNoCache(x.endB-u.from),b=d.resolve(x.start),E=y.sameParent(v)&&y.parent.inlineContent&&b.end()>=x.endA;if((vm&&t.input.lastIOSEnter>Date.now()-225&&(!E||i.some(C=>C.nodeName=="DIV"||C.nodeName=="P"))||!E&&y.posC(t,rh(13,"Enter")))){t.input.lastIOSEnter=0;return}if(t.state.selection.anchor>x.start&&BMe(d,x.start,x.endA,y,v)&&t.someProp("handleKeyDown",C=>C(t,rh(8,"Backspace")))){lc&&us&&t.domObserver.suppressSelectionUpdates();return}us&&x.endB==x.start&&(t.input.lastChromeDelete=Date.now()),lc&&!E&&y.start()!=v.start()&&v.parentOffset==0&&y.depth==v.depth&&u.sel&&u.sel.anchor==u.sel.head&&u.sel.head==x.endA&&(x.endB-=2,v=u.doc.resolveNoCache(x.endB-u.from),setTimeout(()=>{t.someProp("handleKeyDown",function(C){return C(t,rh(13,"Enter"))})},20));let S=x.start,A=x.endA,T=C=>{let I=C||t.state.tr.replace(S,A,u.doc.slice(x.start-u.from,x.endB-u.from));if(u.sel){let N=M6(t,I.doc,u.sel);N&&!(us&&t.composing&&N.empty&&(x.start!=x.endB||t.input.lastChromeDeletegc(t),20));let C=T(t.state.tr.delete(S,A)),I=d.resolve(x.start).marksAcross(d.resolve(x.endA));I&&C.ensureMarks(I),t.dispatch(C)}else if(x.endA==x.endB&&(P=zMe(y.parent.content.cut(y.parentOffset,v.parentOffset),b.parent.content.cut(b.parentOffset,x.endA-b.start())))){let C=T(t.state.tr);P.type=="add"?C.addMark(S,A,P.mark):C.removeMark(S,A,P.mark),t.dispatch(C)}else if(y.parent.child(y.index()).isText&&y.index()==v.index()-(v.textOffset?0:1)){let C=y.parent.textBetween(y.parentOffset,v.parentOffset),I=()=>T(t.state.tr.insertText(C,S,A));t.someProp("handleTextInput",N=>N(t,S,A,C,I))||t.dispatch(I())}else t.dispatch(T());else t.dispatch(T())}function M6(t,e,n){return Math.max(n.anchor,n.head)>e.content.size?null:lD(t,e.resolve(n.anchor),e.resolve(n.head))}function zMe(t,e){let n=t.firstChild.marks,r=e.firstChild.marks,i=n,s=r,a,o,l;for(let d=0;dd.mark(o.addToSet(d.marks));else if(i.length==0&&s.length==1)o=s[0],a="remove",l=d=>d.mark(o.removeFromSet(d.marks));else return null;let u=[];for(let d=0;dn||zT(a,!0,!1)0&&(e||t.indexAfter(r)==t.node(r).childCount);)r--,i++,e=!1;if(n){let s=t.node(r).maybeChild(t.indexAfter(r));for(;s&&!s.isLeaf;)s=s.firstChild,i++}return i}function HMe(t,e,n,r,i){let s=t.findDiffStart(e,n);if(s==null)return null;let{a,b:o}=t.findDiffEnd(e,n+t.size,n+e.size);if(i=="end"){let l=Math.max(0,s-Math.min(a,o));r-=a+l-s}if(a=a?s-r:0;s-=l,s&&s=o?s-r:0;s-=l,s&&s=56320&&e<=57343&&n>=55296&&n<=56319}class Fq{constructor(e,n){this._root=null,this.focused=!1,this.trackWrites=null,this.mounted=!1,this.markCursor=null,this.cursorWrapper=null,this.lastSelectedViewDesc=void 0,this.input=new oMe,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=n,this.state=n.state,this.directPlugins=n.plugins||[],this.directPlugins.forEach(P6),this.dispatch=this.dispatch.bind(this),this.dom=e&&e.mount||document.createElement("div"),e&&(e.appendChild?e.appendChild(this.dom):typeof e=="function"?e(this.dom):e.mount&&(this.mounted=!0)),this.editable=N6(this),C6(this),this.nodeViews=k6(this),this.docView=o6(this.state.doc,T6(this),FT(this),this.dom,this),this.domObserver=new RMe(this,(r,i,s,a)=>FMe(this,r,i,s,a)),this.domObserver.start(),lMe(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let e=this._props;this._props={};for(let n in e)this._props[n]=e[n];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&kk(this);let n=this._props;this._props=e,e.plugins&&(e.plugins.forEach(P6),this.directPlugins=e.plugins),this.updateStateInner(e.state,n)}setProps(e){let n={};for(let r in this._props)n[r]=this._props[r];n.state=this.state;for(let r in e)n[r]=e[r];this.update(n)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,n){var r;let i=this.state,s=!1,a=!1;e.storedMarks&&this.composing&&(Rq(this),a=!0),this.state=e;let o=i.plugins!=e.plugins||this._props.plugins!=n.plugins;if(o||this._props.plugins!=n.plugins||this._props.nodeViews!=n.nodeViews){let m=k6(this);VMe(m,this.nodeViews)&&(this.nodeViews=m,s=!0)}(o||n.handleDOMEvents!=this._props.handleDOMEvents)&&kk(this),this.editable=N6(this),C6(this);let l=FT(this),u=T6(this),d=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",f=s||!this.docView.matchesNode(e.doc,u,l);(f||!e.selection.eq(i.selection))&&(a=!0);let g=d=="preserve"&&a&&this.dom.style.overflowAnchor==null&&wEe(this);if(a){this.domObserver.stop();let m=f&&(Ws||us)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&$Me(i.selection,e.selection);if(f){let x=us?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=_Me(this)),(s||!this.docView.update(e.doc,u,l,this))&&(this.docView.updateOuterDeco(u),this.docView.destroy(),this.docView=o6(e.doc,u,l,this.dom,this)),x&&!this.trackWrites&&(m=!0)}m||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&WEe(this))?gc(this,m):(yq(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(i),!((r=this.dragging)===null||r===void 0)&&r.node&&!i.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,i),d=="reset"?this.dom.scrollTop=0:d=="to selection"?this.scrollToSelection():g&&SEe(g)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!(!e||!this.dom.contains(e.nodeType==1?e:e.parentNode))){if(!this.someProp("handleScrollToSelection",n=>n(this)))if(this.state.selection instanceof Ht){let n=this.docView.domAfterPos(this.state.selection.from);n.nodeType==1&&t6(this,n.getBoundingClientRect(),e)}else t6(this,this.coordsAtPos(this.state.selection.head,1),e)}}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(!e||e.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let n=0;n0&&this.state.doc.nodeAt(s))==r.node&&(i=s)}this.dragging=new Oq(e.slice,e.move,i<0?void 0:Ht.create(this.state.doc,i))}someProp(e,n){let r=this._props&&this._props[e],i;if(r!=null&&(i=n?n(r):r))return i;for(let a=0;an.ownerDocument.getSelection()),this._root=n}return e||document}updateRoot(){this._root=null}posAtCoords(e){return NEe(this,e)}coordsAtPos(e,n=1){return hq(this,e,n)}domAtPos(e,n=0){return this.docView.domFromPos(e,n)}nodeDOM(e){let n=this.docView.descAt(e);return n?n.nodeDOM:null}posAtDOM(e,n,r=-1){let i=this.docView.posFromDOM(e,n,r);if(i==null)throw new RangeError("DOM position not inside the editor");return i}endOfTextblock(e,n){return OEe(this,n||this.state,e)}pasteHTML(e,n){return k0(this,"",e,!1,n||new ClipboardEvent("paste"))}pasteText(e,n){return k0(this,e,null,!0,n||new ClipboardEvent("paste"))}serializeForClipboard(e){return cD(this,e)}destroy(){this.docView&&(cMe(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],FT(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,dEe())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return dMe(this,e)}domSelectionRange(){let e=this.domSelection();return e?Ms&&this.root.nodeType===11&&gEe(this.dom.ownerDocument)==this.dom&&OMe(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}Fq.prototype.dispatch=function(t){let e=this._props.dispatchTransaction;e?e.call(this,t):this.updateState(this.state.apply(t))};function T6(t){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(t.editable),t.someProp("attributes",n=>{if(typeof n=="function"&&(n=n(t.state)),n)for(let r in n)r=="class"?e.class+=" "+n[r]:r=="style"?e.style=(e.style?e.style+";":"")+n[r]:!e[r]&&r!="contenteditable"&&r!="nodeName"&&(e[r]=String(n[r]))}),e.translate||(e.translate="no"),[ws.node(0,t.state.doc.content.size,e)]}function C6(t){if(t.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),t.cursorWrapper={dom:e,deco:ws.widget(t.state.selection.from,e,{raw:!0,marks:t.markCursor})}}else t.cursorWrapper=null}function N6(t){return!t.someProp("editable",e=>e(t.state)===!1)}function $Me(t,e){let n=Math.min(t.$anchor.sharedDepth(t.head),e.$anchor.sharedDepth(e.head));return t.$anchor.start(n)!=e.$anchor.start(n)}function k6(t){let e=Object.create(null);function n(r){for(let i in r)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=r[i])}return t.someProp("nodeViews",n),t.someProp("markViews",n),e}function VMe(t,e){let n=0,r=0;for(let i in t){if(t[i]!=e[i])return!0;n++}for(let i in e)r++;return n!=r}function P6(t){if(t.spec.state||t.spec.filterTransaction||t.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}var id={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},D1={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},GMe=typeof navigator<"u"&&/Mac/.test(navigator.platform),WMe=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(var Qi=0;Qi<10;Qi++)id[48+Qi]=id[96+Qi]=String(Qi);for(var Qi=1;Qi<=24;Qi++)id[Qi+111]="F"+Qi;for(var Qi=65;Qi<=90;Qi++)id[Qi]=String.fromCharCode(Qi+32),D1[Qi]=String.fromCharCode(Qi);for(var BT in id)D1.hasOwnProperty(BT)||(D1[BT]=id[BT]);function qMe(t){var e=GMe&&t.metaKey&&t.shiftKey&&!t.ctrlKey&&!t.altKey||WMe&&t.shiftKey&&t.key&&t.key.length==1||t.key=="Unidentified",n=!e&&t.key||(t.shiftKey?D1:id)[t.keyCode]||t.key||"Unidentified";return n=="Esc"&&(n="Escape"),n=="Del"&&(n="Delete"),n=="Left"&&(n="ArrowLeft"),n=="Up"&&(n="ArrowUp"),n=="Right"&&(n="ArrowRight"),n=="Down"&&(n="ArrowDown"),n}const KMe=typeof navigator<"u"&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),XMe=typeof navigator<"u"&&/Win/.test(navigator.platform);function YMe(t){let e=t.split(/-(?!$)/),n=e[e.length-1];n=="Space"&&(n=" ");let r,i,s,a;for(let o=0;o{for(var n in e)JMe(t,n,{get:e[n],enumerable:!0})};function FS(t){const{state:e,transaction:n}=t;let{selection:r}=n,{doc:i}=n,{storedMarks:s}=n;return{...e,apply:e.apply.bind(e),applyTransaction:e.applyTransaction.bind(e),plugins:e.plugins,schema:e.schema,reconfigure:e.reconfigure.bind(e),toJSON:e.toJSON.bind(e),get storedMarks(){return s},get selection(){return r},get doc(){return i},get tr(){return r=n.selection,i=n.doc,s=n.storedMarks,n}}}var zS=class{constructor(t){this.editor=t.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=t.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){const{rawCommands:t,editor:e,state:n}=this,{view:r}=e,{tr:i}=n,s=this.buildProps(i);return Object.fromEntries(Object.entries(t).map(([a,o])=>[a,(...u)=>{const d=o(...u)(s);return!i.getMeta("preventDispatch")&&!this.hasCustomState&&r.dispatch(i),d}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(t,e=!0){const{rawCommands:n,editor:r,state:i}=this,{view:s}=r,a=[],o=!!t,l=t||i.tr,u=()=>(!o&&e&&!l.getMeta("preventDispatch")&&!this.hasCustomState&&s.dispatch(l),a.every(f=>f===!0)),d={...Object.fromEntries(Object.entries(n).map(([f,g])=>[f,(...x)=>{const y=this.buildProps(l,e),v=g(...x)(y);return a.push(v),d}])),run:u};return d}createCan(t){const{rawCommands:e,state:n}=this,r=!1,i=t||n.tr,s=this.buildProps(i,r);return{...Object.fromEntries(Object.entries(e).map(([o,l])=>[o,(...u)=>l(...u)({...s,dispatch:void 0})])),chain:()=>this.createChain(i,r)}}buildProps(t,e=!0){const{rawCommands:n,editor:r,state:i}=this,{view:s}=r,a={tr:t,editor:r,view:s,state:FS({state:i,transaction:t}),dispatch:e?()=>{}:void 0,chain:()=>this.createChain(t,e),can:()=>this.createCan(t),get commands(){return Object.fromEntries(Object.entries(n).map(([o,l])=>[o,(...u)=>l(...u)(a)]))}};return a}},Bq={};mD(Bq,{blur:()=>e2e,clearContent:()=>t2e,clearNodes:()=>n2e,command:()=>r2e,createParagraphNear:()=>i2e,cut:()=>s2e,deleteCurrentNode:()=>a2e,deleteNode:()=>o2e,deleteRange:()=>l2e,deleteSelection:()=>c2e,enter:()=>u2e,exitCode:()=>d2e,extendMarkRange:()=>h2e,first:()=>f2e,focus:()=>m2e,forEach:()=>g2e,insertContent:()=>x2e,insertContentAt:()=>y2e,joinBackward:()=>S2e,joinDown:()=>w2e,joinForward:()=>E2e,joinItemBackward:()=>M2e,joinItemForward:()=>A2e,joinTextblockBackward:()=>T2e,joinTextblockForward:()=>C2e,joinUp:()=>_2e,keyboardShortcut:()=>k2e,lift:()=>P2e,liftEmptyBlock:()=>R2e,liftListItem:()=>D2e,newlineInCode:()=>O2e,resetAttributes:()=>j2e,scrollIntoView:()=>L2e,selectAll:()=>I2e,selectNodeBackward:()=>U2e,selectNodeForward:()=>F2e,selectParentNode:()=>z2e,selectTextblockEnd:()=>B2e,selectTextblockStart:()=>H2e,setContent:()=>$2e,setMark:()=>oAe,setMeta:()=>lAe,setNode:()=>cAe,setNodeSelection:()=>uAe,setTextDirection:()=>dAe,setTextSelection:()=>hAe,sinkListItem:()=>fAe,splitBlock:()=>pAe,splitListItem:()=>mAe,toggleList:()=>gAe,toggleMark:()=>xAe,toggleNode:()=>bAe,toggleWrap:()=>vAe,undoInputRule:()=>yAe,unsetAllMarks:()=>_Ae,unsetMark:()=>wAe,unsetTextDirection:()=>SAe,updateAttributes:()=>EAe,wrapIn:()=>MAe,wrapInList:()=>AAe});var e2e=()=>({editor:t,view:e})=>(requestAnimationFrame(()=>{var n;t.isDestroyed||(e.dom.blur(),(n=window?.getSelection())==null||n.removeAllRanges())}),!0),t2e=(t=!0)=>({commands:e})=>e.setContent("",{emitUpdate:t}),n2e=()=>({state:t,tr:e,dispatch:n})=>{const{selection:r}=e,{ranges:i}=r;return n&&i.forEach(({$from:s,$to:a})=>{t.doc.nodesBetween(s.pos,a.pos,(o,l)=>{if(o.type.isText)return;const{doc:u,mapping:d}=e,f=u.resolve(d.map(l)),g=u.resolve(d.map(l+o.nodeSize)),m=f.blockRange(g);if(!m)return;const x=$m(m);if(o.type.isTextblock){const{defaultType:y}=f.parent.contentMatchAt(f.index());e.setNodeMarkup(m.start,y)}(x||x===0)&&e.lift(m,x)})}),!0},r2e=t=>e=>t(e),i2e=()=>({state:t,dispatch:e})=>nq(t,e),s2e=(t,e)=>({editor:n,tr:r})=>{const{state:i}=n,s=i.doc.slice(t.from,t.to);r.deleteRange(t.from,t.to);const a=r.mapping.map(e);return r.insert(a,s.content),r.setSelection(new qt(r.doc.resolve(Math.max(a-1,0)))),!0},a2e=()=>({tr:t,dispatch:e})=>{const{selection:n}=t,r=n.$anchor.node();if(r.content.size>0)return!1;const i=t.selection.$anchor;for(let s=i.depth;s>0;s-=1)if(i.node(s).type===r.type){if(e){const o=i.before(s),l=i.after(s);t.delete(o,l).scrollIntoView()}return!0}return!1};function ni(t,e){if(typeof t=="string"){if(!e.nodes[t])throw Error(`There is no node type named '${t}'. Maybe you forgot to add the extension?`);return e.nodes[t]}return t}var o2e=t=>({tr:e,state:n,dispatch:r})=>{const i=ni(t,n.schema),s=e.selection.$anchor;for(let a=s.depth;a>0;a-=1)if(s.node(a).type===i){if(r){const l=s.before(a),u=s.after(a);e.delete(l,u).scrollIntoView()}return!0}return!1},l2e=t=>({tr:e,dispatch:n})=>{const{from:r,to:i}=t;return n&&e.delete(r,i),!0},c2e=()=>({state:t,dispatch:e})=>tD(t,e),u2e=()=>({commands:t})=>t.keyboardShortcut("Enter"),d2e=()=>({state:t,dispatch:e})=>YSe(t,e);function gD(t){return Object.prototype.toString.call(t)==="[object RegExp]"}function O1(t,e,n={strict:!0}){const r=Object.keys(e);return r.length?r.every(i=>n.strict?e[i]===t[i]:gD(e[i])?e[i].test(t[i]):e[i]===t[i]):!0}function Hq(t,e,n={}){return t.find(r=>r.type===e&&O1(Object.fromEntries(Object.keys(n).map(i=>[i,r.attrs[i]])),n))}function R6(t,e,n={}){return!!Hq(t,e,n)}function xD(t,e,n){var r;if(!t||!e)return;let i=t.parent.childAfter(t.parentOffset);if((!i.node||!i.node.marks.some(d=>d.type===e))&&(i=t.parent.childBefore(t.parentOffset)),!i.node||!i.node.marks.some(d=>d.type===e)||(n=n||((r=i.node.marks[0])==null?void 0:r.attrs),!Hq([...i.node.marks],e,n)))return;let a=i.index,o=t.start()+i.offset,l=a+1,u=o+i.node.nodeSize;for(;a>0&&R6([...t.parent.child(a-1).marks],e,n);)a-=1,o-=t.parent.child(a).nodeSize;for(;l({tr:n,state:r,dispatch:i})=>{const s=Nc(t,r.schema),{doc:a,selection:o}=n,{$from:l,from:u,to:d}=o;if(i){const f=xD(l,s,e);if(f&&f.from<=u&&f.to>=d){const g=qt.create(a,f.from,f.to);n.setSelection(g)}}return!0},f2e=t=>e=>{const n=typeof t=="function"?t(e):t;for(let r=0;r({editor:n,view:r,tr:i,dispatch:s})=>{e={scrollIntoView:!0,...e};const a=()=>{(bD()||p2e())&&r.dom.focus(),requestAnimationFrame(()=>{n.isDestroyed||(r.focus(),e?.scrollIntoView&&n.commands.scrollIntoView())})};if(r.hasFocus()&&t===null||t===!1)return!0;if(s&&t===null&&!$q(n.state.selection))return a(),!0;const o=Vq(i.doc,t)||n.state.selection,l=n.state.selection.eq(o);return s&&(l||i.setSelection(o),l&&i.storedMarks&&i.setStoredMarks(i.storedMarks),a()),!0},g2e=(t,e)=>n=>t.every((r,i)=>e(r,{...n,index:i})),x2e=(t,e)=>({tr:n,commands:r})=>r.insertContentAt({from:n.selection.from,to:n.selection.to},t,e),Gq=t=>{const e=t.childNodes;for(let n=e.length-1;n>=0;n-=1){const r=e[n];r.nodeType===3&&r.nodeValue&&/^(\n\s\s|\n)$/.test(r.nodeValue)?t.removeChild(r):r.nodeType===1&&Gq(r)}return t};function r_(t){if(typeof window>"u")throw new Error("[tiptap error]: there is no window object available, so this function cannot be used");const e=`${t}`,n=new window.DOMParser().parseFromString(e,"text/html").body;return Gq(n)}function R0(t,e,n){if(t instanceof Wu||t instanceof pt)return t;n={slice:!0,parseOptions:{},...n};const r=typeof t=="object"&&t!==null,i=typeof t=="string";if(r)try{if(Array.isArray(t)&&t.length>0)return pt.fromArray(t.map(o=>e.nodeFromJSON(o)));const a=e.nodeFromJSON(t);return n.errorOnInvalidContent&&a.check(),a}catch(s){if(n.errorOnInvalidContent)throw new Error("[tiptap error]: Invalid JSON content",{cause:s});return console.warn("[tiptap warn]: Invalid content.","Passed value:",t,"Error:",s),R0("",e,n)}if(i){if(n.errorOnInvalidContent){let a=!1,o="";const l=new NW({topNode:e.spec.topNode,marks:e.spec.marks,nodes:e.spec.nodes.append({__tiptap__private__unknown__catch__all__node:{content:"inline*",group:"block",parseDOM:[{tag:"*",getAttrs:u=>(a=!0,o=typeof u=="string"?u:u.outerHTML,null)}]}})});if(n.slice?Bx.fromSchema(l).parseSlice(r_(t),n.parseOptions):Bx.fromSchema(l).parse(r_(t),n.parseOptions),n.errorOnInvalidContent&&a)throw new Error("[tiptap error]: Invalid HTML content",{cause:new Error(`Invalid element found: ${o}`)})}const s=Bx.fromSchema(e);return n.slice?s.parseSlice(r_(t),n.parseOptions).content:s.parse(r_(t),n.parseOptions)}return R0("",e,n)}function b2e(t,e,n){const r=t.steps.length-1;if(r{a===0&&(a=d)}),t.setSelection(ln.near(t.doc.resolve(a),n))}var v2e=t=>!("type"in t),y2e=(t,e,n)=>({tr:r,dispatch:i,editor:s})=>{var a;if(i){n={parseOptions:s.options.parseOptions,updateSelection:!0,applyInputRules:!1,applyPasteRules:!1,...n};let o;const l=v=>{s.emit("contentError",{editor:s,error:v,disableCollaboration:()=>{"collaboration"in s.storage&&typeof s.storage.collaboration=="object"&&s.storage.collaboration&&(s.storage.collaboration.isDisabled=!0)}})},u={preserveWhitespace:"full",...n.parseOptions};if(!n.errorOnInvalidContent&&!s.options.enableContentCheck&&s.options.emitContentError)try{R0(e,s.schema,{parseOptions:u,errorOnInvalidContent:!0})}catch(v){l(v)}try{o=R0(e,s.schema,{parseOptions:u,errorOnInvalidContent:(a=n.errorOnInvalidContent)!=null?a:s.options.enableContentCheck})}catch(v){return l(v),!1}let{from:d,to:f}=typeof t=="number"?{from:t,to:t}:{from:t.from,to:t.to},g=!0,m=!0;if((v2e(o)?o:[o]).forEach(v=>{v.check(),g=g?v.isText&&v.marks.length===0:!1,m=m?v.isBlock:!1}),d===f&&m){const{parent:v}=r.doc.resolve(d);v.isTextblock&&!v.type.spec.code&&!v.childCount&&(d-=1,f+=1)}let y;if(g){if(Array.isArray(e))y=e.map(v=>v.text||"").join("");else if(e instanceof pt){let v="";e.forEach(b=>{b.text&&(v+=b.text)}),y=v}else typeof e=="object"&&e&&e.text?y=e.text:y=e;r.insertText(y,d,f)}else{y=o;const v=r.doc.resolve(d),b=v.node(),E=v.parentOffset===0,S=b.isText||b.isTextblock,A=b.content.size>0;E&&S&&A&&(d=Math.max(0,d-1)),r.replaceWith(d,f,y)}n.updateSelection&&b2e(r,r.steps.length-1,-1),n.applyInputRules&&r.setMeta("applyInputRules",{from:d,text:y}),n.applyPasteRules&&r.setMeta("applyPasteRules",{from:d,text:y})}return!0},_2e=()=>({state:t,dispatch:e})=>qSe(t,e),w2e=()=>({state:t,dispatch:e})=>KSe(t,e),S2e=()=>({state:t,dispatch:e})=>XW(t,e),E2e=()=>({state:t,dispatch:e})=>JW(t,e),M2e=()=>({state:t,dispatch:e,tr:n})=>{try{const r=DS(t.doc,t.selection.$from.pos,-1);return r==null?!1:(n.join(r,2),e&&e(n),!0)}catch{return!1}},A2e=()=>({state:t,dispatch:e,tr:n})=>{try{const r=DS(t.doc,t.selection.$from.pos,1);return r==null?!1:(n.join(r,2),e&&e(n),!0)}catch{return!1}},T2e=()=>({state:t,dispatch:e})=>GSe(t,e),C2e=()=>({state:t,dispatch:e})=>WSe(t,e);function Wq(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function N2e(t){const e=t.split(/-(?!$)/);let n=e[e.length-1];n==="Space"&&(n=" ");let r,i,s,a;for(let o=0;o({editor:e,view:n,tr:r,dispatch:i})=>{const s=N2e(t).split(/-(?!$)/),a=s.find(u=>!["Alt","Ctrl","Meta","Shift"].includes(u)),o=new KeyboardEvent("keydown",{key:a==="Space"?" ":a,altKey:s.includes("Alt"),ctrlKey:s.includes("Ctrl"),metaKey:s.includes("Meta"),shiftKey:s.includes("Shift"),bubbles:!0,cancelable:!0}),l=e.captureTransaction(()=>{n.someProp("handleKeyDown",u=>u(n,o))});return l?.steps.forEach(u=>{const d=u.map(r.mapping);d&&i&&r.maybeStep(d)}),!0};function sd(t,e,n={}){const{from:r,to:i,empty:s}=t.selection,a=e?ni(e,t.schema):null,o=[];t.doc.nodesBetween(r,i,(f,g)=>{if(f.isText)return;const m=Math.max(r,g),x=Math.min(i,g+f.nodeSize);o.push({node:f,from:m,to:x})});const l=i-r,u=o.filter(f=>a?a.name===f.node.type.name:!0).filter(f=>O1(f.node.attrs,n,{strict:!1}));return s?!!u.length:u.reduce((f,g)=>f+g.to-g.from,0)>=l}var P2e=(t,e={})=>({state:n,dispatch:r})=>{const i=ni(t,n.schema);return sd(n,i,e)?XSe(n,r):!1},R2e=()=>({state:t,dispatch:e})=>rq(t,e),D2e=t=>({state:e,dispatch:n})=>{const r=ni(t,e.schema);return oEe(r)(e,n)},O2e=()=>({state:t,dispatch:e})=>tq(t,e);function BS(t,e){return e.nodes[t]?"node":e.marks[t]?"mark":null}function D6(t,e){const n=typeof e=="string"?[e]:e;return Object.keys(t).reduce((r,i)=>(n.includes(i)||(r[i]=t[i]),r),{})}var j2e=(t,e)=>({tr:n,state:r,dispatch:i})=>{let s=null,a=null;const o=BS(typeof t=="string"?t:t.name,r.schema);if(!o)return!1;o==="node"&&(s=ni(t,r.schema)),o==="mark"&&(a=Nc(t,r.schema));let l=!1;return n.selection.ranges.forEach(u=>{r.doc.nodesBetween(u.$from.pos,u.$to.pos,(d,f)=>{s&&s===d.type&&(l=!0,i&&n.setNodeMarkup(f,void 0,D6(d.attrs,e))),a&&d.marks.length&&d.marks.forEach(g=>{a===g.type&&(l=!0,i&&n.addMark(f,f+d.nodeSize,a.create(D6(g.attrs,e))))})})}),l},L2e=()=>({tr:t,dispatch:e})=>(e&&t.scrollIntoView(),!0),I2e=()=>({tr:t,dispatch:e})=>{if(e){const n=new ba(t.doc);t.setSelection(n)}return!0},U2e=()=>({state:t,dispatch:e})=>ZW(t,e),F2e=()=>({state:t,dispatch:e})=>eq(t,e),z2e=()=>({state:t,dispatch:e})=>JSe(t,e),B2e=()=>({state:t,dispatch:e})=>nEe(t,e),H2e=()=>({state:t,dispatch:e})=>tEe(t,e);function Pk(t,e,n={},r={}){return R0(t,e,{slice:!1,parseOptions:n,errorOnInvalidContent:r.errorOnInvalidContent})}var $2e=(t,{errorOnInvalidContent:e,emitUpdate:n=!0,parseOptions:r={}}={})=>({editor:i,tr:s,dispatch:a,commands:o})=>{const{doc:l}=s;if(r.preserveWhitespace!=="full"){const u=Pk(t,i.schema,r,{errorOnInvalidContent:e??i.options.enableContentCheck});return a&&s.replaceWith(0,l.content.size,u).setMeta("preventUpdate",!n),!0}return a&&s.setMeta("preventUpdate",!n),o.insertContentAt({from:0,to:l.content.size},t,{parseOptions:r,errorOnInvalidContent:e??i.options.enableContentCheck})};function qq(t,e){const n=Nc(e,t.schema),{from:r,to:i,empty:s}=t.selection,a=[];s?(t.storedMarks&&a.push(...t.storedMarks),a.push(...t.selection.$head.marks())):t.doc.nodesBetween(r,i,l=>{a.push(...l.marks)});const o=a.find(l=>l.type.name===n.name);return o?{...o.attrs}:{}}function Kq(t,e){const n=new GW(t);return e.forEach(r=>{r.steps.forEach(i=>{n.step(i)})}),n}function V2e(t){for(let e=0;e{n(i)&&r.push({node:i,pos:s})}),r}function W2e(t,e){for(let n=t.depth;n>0;n-=1){const r=t.node(n);if(e(r))return{pos:n>0?t.before(n):0,start:t.start(n),depth:n,node:r}}}function HS(t){return e=>W2e(e.$from,t)}function Bt(t,e,n){return t.config[e]===void 0&&t.parent?Bt(t.parent,e,n):typeof t.config[e]=="function"?t.config[e].bind({...n,parent:t.parent?Bt(t.parent,e,n):null}):t.config[e]}function vD(t){return t.map(e=>{const n={name:e.name,options:e.options,storage:e.storage},r=Bt(e,"addExtensions",n);return r?[e,...vD(r())]:e}).flat(10)}function yD(t,e){const n=sf.fromSchema(e).serializeFragment(t),i=document.implementation.createHTMLDocument().createElement("div");return i.appendChild(n),i.innerHTML}function Xq(t){return typeof t=="function"}function Ln(t,e=void 0,...n){return Xq(t)?e?t.bind(e)(...n):t(...n):t}function q2e(t={}){return Object.keys(t).length===0&&t.constructor===Object}function ym(t){const e=t.filter(i=>i.type==="extension"),n=t.filter(i=>i.type==="node"),r=t.filter(i=>i.type==="mark");return{baseExtensions:e,nodeExtensions:n,markExtensions:r}}function Yq(t){const e=[],{nodeExtensions:n,markExtensions:r}=ym(t),i=[...n,...r],s={default:null,validate:void 0,rendered:!0,renderHTML:null,parseHTML:null,keepOnSplit:!0,isRequired:!1};return t.forEach(a=>{const o={name:a.name,options:a.options,storage:a.storage,extensions:i},l=Bt(a,"addGlobalAttributes",o);if(!l)return;l().forEach(d=>{d.types.forEach(f=>{Object.entries(d.attributes).forEach(([g,m])=>{e.push({type:f,name:g,attribute:{...s,...m}})})})})}),i.forEach(a=>{const o={name:a.name,options:a.options,storage:a.storage},l=Bt(a,"addAttributes",o);if(!l)return;const u=l();Object.entries(u).forEach(([d,f])=>{const g={...s,...f};typeof g?.default=="function"&&(g.default=g.default()),g?.isRequired&&g?.default===void 0&&delete g.default,e.push({type:a.name,name:d,attribute:g})})}),e}function Nr(...t){return t.filter(e=>!!e).reduce((e,n)=>{const r={...e};return Object.entries(n).forEach(([i,s])=>{if(!r[i]){r[i]=s;return}if(i==="class"){const o=s?String(s).split(" "):[],l=r[i]?r[i].split(" "):[],u=o.filter(d=>!l.includes(d));r[i]=[...l,...u].join(" ")}else if(i==="style"){const o=s?s.split(";").map(d=>d.trim()).filter(Boolean):[],l=r[i]?r[i].split(";").map(d=>d.trim()).filter(Boolean):[],u=new Map;l.forEach(d=>{const[f,g]=d.split(":").map(m=>m.trim());u.set(f,g)}),o.forEach(d=>{const[f,g]=d.split(":").map(m=>m.trim());u.set(f,g)}),r[i]=Array.from(u.entries()).map(([d,f])=>`${d}: ${f}`).join("; ")}else r[i]=s}),r},{})}function j1(t,e){return e.filter(n=>n.type===t.type.name).filter(n=>n.attribute.rendered).map(n=>n.attribute.renderHTML?n.attribute.renderHTML(t.attrs)||{}:{[n.name]:t.attrs[n.name]}).reduce((n,r)=>Nr(n,r),{})}function K2e(t){return typeof t!="string"?t:t.match(/^[+-]?(?:\d*\.)?\d+$/)?Number(t):t==="true"?!0:t==="false"?!1:t}function O6(t,e){return"style"in t?t:{...t,getAttrs:n=>{const r=t.getAttrs?t.getAttrs(n):t.attrs;if(r===!1)return!1;const i=e.reduce((s,a)=>{const o=a.attribute.parseHTML?a.attribute.parseHTML(n):K2e(n.getAttribute(a.name));return o==null?s:{...s,[a.name]:o}},{});return{...r,...i}}}}function j6(t){return Object.fromEntries(Object.entries(t).filter(([e,n])=>e==="attrs"&&q2e(n)?!1:n!=null))}function L6(t){var e,n;const r={};return!((e=t?.attribute)!=null&&e.isRequired)&&"default"in(t?.attribute||{})&&(r.default=t.attribute.default),((n=t?.attribute)==null?void 0:n.validate)!==void 0&&(r.validate=t.attribute.validate),[t.name,r]}function X2e(t,e){var n;const r=Yq(t),{nodeExtensions:i,markExtensions:s}=ym(t),a=(n=i.find(u=>Bt(u,"topNode")))==null?void 0:n.name,o=Object.fromEntries(i.map(u=>{const d=r.filter(b=>b.type===u.name),f={name:u.name,options:u.options,storage:u.storage,editor:e},g=t.reduce((b,E)=>{const S=Bt(E,"extendNodeSchema",f);return{...b,...S?S(u):{}}},{}),m=j6({...g,content:Ln(Bt(u,"content",f)),marks:Ln(Bt(u,"marks",f)),group:Ln(Bt(u,"group",f)),inline:Ln(Bt(u,"inline",f)),atom:Ln(Bt(u,"atom",f)),selectable:Ln(Bt(u,"selectable",f)),draggable:Ln(Bt(u,"draggable",f)),code:Ln(Bt(u,"code",f)),whitespace:Ln(Bt(u,"whitespace",f)),linebreakReplacement:Ln(Bt(u,"linebreakReplacement",f)),defining:Ln(Bt(u,"defining",f)),isolating:Ln(Bt(u,"isolating",f)),attrs:Object.fromEntries(d.map(L6))}),x=Ln(Bt(u,"parseHTML",f));x&&(m.parseDOM=x.map(b=>O6(b,d)));const y=Bt(u,"renderHTML",f);y&&(m.toDOM=b=>y({node:b,HTMLAttributes:j1(b,d)}));const v=Bt(u,"renderText",f);return v&&(m.toText=v),[u.name,m]})),l=Object.fromEntries(s.map(u=>{const d=r.filter(v=>v.type===u.name),f={name:u.name,options:u.options,storage:u.storage,editor:e},g=t.reduce((v,b)=>{const E=Bt(b,"extendMarkSchema",f);return{...v,...E?E(u):{}}},{}),m=j6({...g,inclusive:Ln(Bt(u,"inclusive",f)),excludes:Ln(Bt(u,"excludes",f)),group:Ln(Bt(u,"group",f)),spanning:Ln(Bt(u,"spanning",f)),code:Ln(Bt(u,"code",f)),attrs:Object.fromEntries(d.map(L6))}),x=Ln(Bt(u,"parseHTML",f));x&&(m.parseDOM=x.map(v=>O6(v,d)));const y=Bt(u,"renderHTML",f);return y&&(m.toDOM=v=>y({mark:v,HTMLAttributes:j1(v,d)})),[u.name,m]}));return new NW({topNode:a,nodes:o,marks:l})}function Y2e(t){const e=t.filter((n,r)=>t.indexOf(n)!==r);return Array.from(new Set(e))}function _D(t){return t.sort((n,r)=>{const i=Bt(n,"priority")||100,s=Bt(r,"priority")||100;return i>s?-1:ir.name));return n.length&&console.warn(`[tiptap warn]: Duplicate extension names found: [${n.map(r=>`'${r}'`).join(", ")}]. This can lead to issues.`),e}function Qq(t,e,n){const{from:r,to:i}=e,{blockSeparator:s=` @@ -8561,10 +8561,10 @@ Accuracy: ${t.time_accuracy.toFixed(0)}%`:t.actual_time_seconds?`Actual: ${hx(t. transition-all duration-200 hover:border-bambu-dark-tertiary/80 ${g?"opacity-50 scale-[1.02] shadow-xl z-50":""} ${x?"border-blue-500/30 bg-gradient-to-r from-blue-500/5 to-transparent":""} - `,children:c.jsxs("div",{className:"flex items-center gap-4 p-4",children:[y?c.jsx("div",{...o,...l,className:"flex items-center justify-center w-10 h-10 md:w-8 md:h-8 rounded-lg bg-bambu-dark cursor-grab active:cursor-grabbing hover:bg-bambu-dark-tertiary transition-colors touch-manipulation",children:c.jsx(c0,{className:"w-6 h-6 md:w-4 md:h-4 text-bambu-gray"})}):e!==void 0?c.jsxs("div",{className:"flex items-center justify-center w-8 h-8 rounded-lg bg-bambu-dark text-bambu-gray text-sm font-medium",children:["#",e]}):c.jsx("div",{className:"w-8"}),c.jsx("div",{className:"w-14 h-14 flex-shrink-0 bg-bambu-dark rounded-lg overflow-hidden",children:t.archive_thumbnail?c.jsx("img",{src:Pe.getArchiveThumbnail(t.archive_id),alt:"",className:"w-full h-full object-cover"}):c.jsx("div",{className:"w-full h-full flex items-center justify-center text-bambu-gray",children:c.jsx(Oh,{className:"w-6 h-6"})})}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[c.jsx("p",{className:"text-white font-medium truncate",children:t.archive_name||`Archive #${t.archive_id}`}),c.jsx(fS,{to:`/archives?highlight=${t.archive_id}`,className:"text-bambu-gray hover:text-bambu-green transition-colors flex-shrink-0",title:"View archive",children:c.jsx(ro,{className:"w-3.5 h-3.5"})})]}),c.jsxs("div",{className:"flex items-center gap-3 text-sm text-bambu-gray",children:[c.jsxs("span",{className:"flex items-center gap-1.5",children:[c.jsx(jo,{className:"w-3.5 h-3.5"}),t.printer_name||`Printer #${t.printer_id}`]}),t.print_time_seconds&&c.jsxs("span",{className:"flex items-center gap-1.5",children:[c.jsx(Ou,{className:"w-3.5 h-3.5"}),EX(t.print_time_seconds)]}),y&&c.jsxs("span",{className:"flex items-center gap-1.5",children:[c.jsx(ti,{className:"w-3.5 h-3.5"}),rke(t.scheduled_time)]})]}),c.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[t.require_previous_success&&c.jsx("span",{className:"text-xs px-2 py-0.5 bg-orange-500/10 text-orange-400 rounded-full border border-orange-500/20",children:"Requires previous success"}),t.auto_off_after&&c.jsxs("span",{className:"text-xs px-2 py-0.5 bg-blue-500/10 text-blue-400 rounded-full border border-blue-500/20 flex items-center gap-1",children:[c.jsx(fd,{className:"w-3 h-3"}),"Auto power off"]})]}),x&&c.jsxs("div",{className:"mt-3",children:[c.jsx("div",{className:"h-2 bg-bambu-dark rounded-full overflow-hidden",children:c.jsx("div",{className:"h-full bg-gradient-to-r from-blue-500 to-blue-400 animate-pulse w-full opacity-50"})}),c.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Printing in progress..."})]}),t.error_message&&c.jsxs("p",{className:"text-xs text-red-400 mt-2 flex items-center gap-1",children:[c.jsx(Oo,{className:"w-3 h-3"}),t.error_message]})]}),c.jsx(ike,{status:t.status}),c.jsxs("div",{className:"flex items-center gap-1",children:[x&&c.jsx(Ie,{variant:"ghost",size:"sm",onClick:s,title:"Stop Print",className:"text-red-400 hover:text-red-300 hover:bg-red-500/10",children:c.jsx($ae,{className:"w-4 h-4"})}),y&&c.jsxs(c.Fragment,{children:[c.jsx(Ie,{variant:"ghost",size:"sm",onClick:n,title:"Edit",children:c.jsx(Zu,{className:"w-4 h-4"})}),c.jsx(Ie,{variant:"ghost",size:"sm",onClick:r,title:"Cancel",className:"text-red-400 hover:text-red-300 hover:bg-red-500/10",children:c.jsx(Gt,{className:"w-4 h-4"})})]}),v&&c.jsxs(c.Fragment,{children:[c.jsx(Ie,{variant:"ghost",size:"sm",onClick:a,title:"Re-queue",className:"text-bambu-green hover:text-bambu-green/80 hover:bg-bambu-green/10",children:c.jsx(qs,{className:"w-4 h-4"})}),c.jsx(Ie,{variant:"ghost",size:"sm",onClick:i,title:"Remove",children:c.jsx(kn,{className:"w-4 h-4"})})]})]})]})})}function ske(){const t=Sn(),{showToast:e}=ri(),[n,r]=M.useState(null),[i,s]=M.useState(""),[a,o]=M.useState(!1),[l,u]=M.useState(null),[d,f]=M.useState(null),[g,m]=M.useState(()=>localStorage.getItem("queue.historySortBy")||"date"),[x,y]=M.useState(()=>{const Y=localStorage.getItem("queue.historySortAsc");return Y!==null?Y==="true":!1}),[v,b]=M.useState(()=>localStorage.getItem("queue.pendingSortBy")||"position"),[E,S]=M.useState(()=>{const Y=localStorage.getItem("queue.pendingSortAsc");return Y!==null?Y==="true":!0});M.useEffect(()=>{localStorage.setItem("queue.historySortBy",g)},[g]),M.useEffect(()=>{localStorage.setItem("queue.historySortAsc",String(x))},[x]),M.useEffect(()=>{localStorage.setItem("queue.pendingSortBy",v)},[v]),M.useEffect(()=>{localStorage.setItem("queue.pendingSortAsc",String(E))},[E]);const A=JK(fw(YS,{activationConstraint:{distance:8}}),fw(XS,{coordinateGetter:wX})),{data:T,isLoading:P}=yt({queryKey:["queue",n,i],queryFn:()=>Pe.getQueue(n||void 0,i||void 0),refetchInterval:5e3}),{data:C}=yt({queryKey:["printers"],queryFn:()=>Pe.getPrinters()}),I=_t({mutationFn:Y=>Pe.cancelQueueItem(Y),onSuccess:()=>{t.invalidateQueries({queryKey:["queue"]}),e("Queue item cancelled")},onError:()=>e("Failed to cancel item","error")}),N=_t({mutationFn:Y=>Pe.removeFromQueue(Y),onSuccess:()=>{t.invalidateQueries({queryKey:["queue"]}),e("Queue item removed")},onError:()=>e("Failed to remove item","error")}),D=_t({mutationFn:Y=>Pe.stopQueueItem(Y),onSuccess:()=>{t.invalidateQueries({queryKey:["queue"]}),e("Print stopped")},onError:()=>e("Failed to stop print","error")}),F=_t({mutationFn:Y=>Pe.reorderQueue(Y),onSuccess:()=>{t.invalidateQueries({queryKey:["queue"]})},onError:()=>e("Failed to reorder queue","error")}),L=_t({mutationFn:Y=>{const Z=new Date;return Z.setFullYear(Z.getFullYear()+1),Pe.addToQueue({printer_id:Y.printer_id,archive_id:Y.archive_id,scheduled_time:Z.toISOString(),require_previous_success:!1,auto_off_after:!1})},onSuccess:Y=>{t.invalidateQueries({queryKey:["queue"]}),e("Added back to queue - please set schedule"),u(Y)},onError:Y=>e(Y.message||"Failed to re-queue item","error")}),q=_t({mutationFn:async()=>{const Y=T?.filter(Z=>["completed","failed","skipped","cancelled"].includes(Z.status))||[];for(const Z of Y)await Pe.removeFromQueue(Z.id);return Y.length},onSuccess:Y=>{t.invalidateQueries({queryKey:["queue"]}),e(`Cleared ${Y} history item${Y!==1?"s":""}`)},onError:()=>e("Failed to clear history","error")}),R=M.useMemo(()=>{const Y=T?.filter(U=>U.status==="pending")||[],Z=U=>{if(!U.scheduled_time)return 0;const $=new Date(U.scheduled_time).getTime(),ee=Date.now()+4320*60*60*1e3;return $>ee?0:$};return[...Y].sort((U,$)=>{let ee;return v==="name"?ee=(U.archive_name||"").localeCompare($.archive_name||""):v==="printer"?ee=(U.printer_name||"").localeCompare($.printer_name||""):v==="time"?ee=Z(U)-Z($):ee=U.position-$.position,E?ee:-ee})},[T,v,E]),V=T?.filter(Y=>Y.status==="printing")||[],K=M.useMemo(()=>[...T?.filter(Z=>["completed","failed","skipped","cancelled"].includes(Z.status))||[]].sort((Z,U)=>{let $;return g==="name"?$=(Z.archive_name||"").localeCompare(U.archive_name||""):g==="printer"?$=(Z.printer_name||"").localeCompare(U.printer_name||""):$=new Date(U.completed_at||U.created_at).getTime()-new Date(Z.completed_at||Z.created_at).getTime(),x?-$:$}),[T,g,x]),W=M.useMemo(()=>R.reduce((Y,Z)=>Y+(Z.print_time_seconds||0),0),[R]),ne=Y=>{const{active:Z,over:U}=Y;if(!U||Z.id===U.id)return;const $=R.findIndex(ae=>ae.id===Z.id),ee=R.findIndex(ae=>ae.id===U.id);if($!==-1&&ee!==-1){const fe=JS(R,$,ee).map((ue,xe)=>({id:ue.id,position:xe+1}));F.mutate(fe)}};return c.jsxs("div",{className:"p-4 md:p-8",children:[c.jsx("div",{className:"flex items-center justify-between mb-8",children:c.jsxs("div",{children:[c.jsxs("h1",{className:"text-2xl font-bold text-white flex items-center gap-3",children:[c.jsx(jG,{className:"w-7 h-7 text-bambu-green"}),"Print Queue"]}),c.jsx("p",{className:"text-bambu-gray mt-1",children:"Schedule and manage your print jobs"})]})}),c.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4 mb-8",children:[c.jsx(Nt,{className:"bg-gradient-to-br from-blue-500/10 to-transparent border-blue-500/20",children:c.jsx(Dt,{className:"p-4",children:c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("div",{className:"w-10 h-10 rounded-lg bg-blue-500/20 flex items-center justify-center",children:c.jsx(bS,{className:"w-5 h-5 text-blue-400"})}),c.jsxs("div",{children:[c.jsx("p",{className:"text-2xl font-bold text-white",children:V.length}),c.jsx("p",{className:"text-sm text-bambu-gray",children:"Printing"})]})]})})}),c.jsx(Nt,{className:"bg-gradient-to-br from-yellow-500/10 to-transparent border-yellow-500/20",children:c.jsx(Dt,{className:"p-4",children:c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("div",{className:"w-10 h-10 rounded-lg bg-yellow-500/20 flex items-center justify-center",children:c.jsx(ti,{className:"w-5 h-5 text-yellow-400"})}),c.jsxs("div",{children:[c.jsx("p",{className:"text-2xl font-bold text-white",children:R.length}),c.jsx("p",{className:"text-sm text-bambu-gray",children:"Queued"})]})]})})}),c.jsx(Nt,{className:"bg-gradient-to-br from-bambu-green/10 to-transparent border-bambu-green/20",children:c.jsx(Dt,{className:"p-4",children:c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("div",{className:"w-10 h-10 rounded-lg bg-bambu-green/20 flex items-center justify-center",children:c.jsx(Ou,{className:"w-5 h-5 text-bambu-green"})}),c.jsxs("div",{children:[c.jsx("p",{className:"text-2xl font-bold text-white",children:EX(W)}),c.jsx("p",{className:"text-sm text-bambu-gray",children:"Total Queue Time"})]})]})})}),c.jsx(Nt,{className:"bg-gradient-to-br from-gray-500/10 to-transparent border-gray-500/20",children:c.jsx(Dt,{className:"p-4",children:c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("div",{className:"w-10 h-10 rounded-lg bg-gray-500/20 flex items-center justify-center",children:c.jsx(ds,{className:"w-5 h-5 text-gray-400"})}),c.jsxs("div",{children:[c.jsx("p",{className:"text-2xl font-bold text-white",children:K.length}),c.jsx("p",{className:"text-sm text-bambu-gray",children:"History"})]})]})})})]}),c.jsxs("div",{className:"flex items-center gap-4 mb-6",children:[c.jsxs("select",{className:"px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:n||"",onChange:Y=>r(Y.target.value?Number(Y.target.value):null),children:[c.jsx("option",{value:"",children:"All Printers"}),C?.map(Y=>c.jsx("option",{value:Y.id,children:Y.name},Y.id))]}),c.jsxs("select",{className:"px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:i,onChange:Y=>s(Y.target.value),children:[c.jsx("option",{value:"",children:"All Status"}),c.jsx("option",{value:"pending",children:"Pending"}),c.jsx("option",{value:"printing",children:"Printing"}),c.jsx("option",{value:"completed",children:"Completed"}),c.jsx("option",{value:"failed",children:"Failed"}),c.jsx("option",{value:"skipped",children:"Skipped"}),c.jsx("option",{value:"cancelled",children:"Cancelled"})]}),c.jsx("div",{className:"flex-1"}),K.length>0&&c.jsxs(Ie,{variant:"secondary",size:"sm",onClick:()=>o(!0),children:[c.jsx(kn,{className:"w-4 h-4"}),"Clear History"]})]}),P?c.jsx("div",{className:"text-center py-12 text-bambu-gray",children:"Loading..."}):T?.length===0?c.jsxs(Nt,{className:"p-12 text-center border-dashed",children:[c.jsx(qr,{className:"w-16 h-16 text-bambu-gray mx-auto mb-4 opacity-50"}),c.jsx("h3",{className:"text-xl font-medium text-white mb-2",children:"No prints scheduled"}),c.jsx("p",{className:"text-bambu-gray max-w-md mx-auto",children:'Schedule a print from the Archives page using the "Schedule" option in the context menu, or drag and drop files to get started.'})]}):c.jsxs("div",{className:"space-y-8",children:[V.length>0&&c.jsxs("div",{children:[c.jsxs("h2",{className:"text-lg font-semibold text-white mb-4 flex items-center gap-2",children:[c.jsx("div",{className:"w-2 h-2 rounded-full bg-blue-400 animate-pulse"}),"Currently Printing"]}),c.jsx("div",{className:"space-y-3",children:V.map(Y=>c.jsx(lC,{item:Y,onEdit:()=>{},onCancel:()=>{},onRemove:()=>{},onStop:()=>f({type:"stop",item:Y}),onRequeue:()=>{}},Y.id))})]}),R.length>0&&c.jsxs("div",{children:[c.jsxs("div",{className:"flex items-center justify-between mb-4",children:[c.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[c.jsx(ti,{className:"w-5 h-5 text-yellow-400"}),"Queued",c.jsxs("span",{className:"text-sm font-normal text-bambu-gray",children:["(",R.length," item",R.length!==1?"s":"",")"]}),c.jsx("span",{className:"text-xs text-bambu-gray ml-2",title:"Position only affects ASAP items. Scheduled items run at their set time.",children:"Drag to reorder (ASAP only)"})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("select",{className:"px-3 py-1.5 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:v,onChange:Y=>b(Y.target.value),children:[c.jsx("option",{value:"position",children:"Sort by Position"}),c.jsx("option",{value:"name",children:"Sort by Name"}),c.jsx("option",{value:"printer",children:"Sort by Printer"}),c.jsx("option",{value:"time",children:"Sort by Schedule"})]}),c.jsx(Ie,{variant:"ghost",size:"sm",onClick:()=>S(!E),title:E?"Ascending":"Descending",className:"px-2",children:E?c.jsx(nm,{className:"w-4 h-4"}):c.jsx(s0,{className:"w-4 h-4"})})]})]}),c.jsx(gX,{sensors:A,collisionDetection:rX,onDragEnd:ne,children:c.jsx(vX,{items:R.map(Y=>Y.id),strategy:G3e,children:c.jsx("div",{className:"space-y-3",children:R.map((Y,Z)=>c.jsx(lC,{item:Y,position:Z+1,onEdit:()=>u(Y),onCancel:()=>f({type:"cancel",item:Y}),onRemove:()=>{},onStop:()=>{},onRequeue:()=>{}},Y.id))})})})]}),K.length>0&&c.jsxs("div",{children:[c.jsxs("div",{className:"flex items-center justify-between mb-4",children:[c.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[c.jsx(ds,{className:"w-5 h-5 text-bambu-gray"}),"History",c.jsxs("span",{className:"text-sm font-normal text-bambu-gray",children:["(",K.length," item",K.length!==1?"s":"",")"]})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("select",{className:"px-3 py-1.5 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:g,onChange:Y=>m(Y.target.value),children:[c.jsx("option",{value:"date",children:"Sort by Date"}),c.jsx("option",{value:"name",children:"Sort by Name"}),c.jsx("option",{value:"printer",children:"Sort by Printer"})]}),c.jsx(Ie,{variant:"ghost",size:"sm",onClick:()=>y(!x),title:x?"Ascending (oldest first)":"Descending (newest first)",className:"px-2",children:x?c.jsx(nm,{className:"w-4 h-4"}):c.jsx(s0,{className:"w-4 h-4"})})]})]}),c.jsx("div",{className:"space-y-3",children:K.slice(0,20).map((Y,Z)=>c.jsx(lC,{item:Y,position:Z+1,onEdit:()=>{},onCancel:()=>{},onRemove:()=>f({type:"remove",item:Y}),onStop:()=>{},onRequeue:()=>L.mutate(Y)},Y.id))})]})]}),l&&c.jsx(nke,{item:l,onClose:()=>u(null)}),d&&c.jsx(Kr,{title:d.type==="cancel"?"Cancel Scheduled Print":d.type==="stop"?"Stop Print":"Remove from History",message:d.type==="cancel"?`Are you sure you want to cancel "${d.item.archive_name||"this print"}"?`:d.type==="stop"?`Are you sure you want to stop the current print "${d.item.archive_name||"this print"}"? This will cancel the print job on the printer.`:`Are you sure you want to remove "${d.item.archive_name||"this item"}" from the queue history?`,confirmText:d.type==="cancel"?"Cancel Print":d.type==="stop"?"Stop Print":"Remove",variant:"danger",onConfirm:()=>{d.type==="cancel"?I.mutate(d.item.id):d.type==="stop"?D.mutate(d.item.id):N.mutate(d.item.id),f(null)},onCancel:()=>f(null)}),a&&c.jsx(Kr,{title:"Clear History",message:`Are you sure you want to remove all ${K.length} item${K.length!==1?"s":""} from the history?`,confirmText:"Clear History",variant:"danger",onConfirm:()=>{q.mutate(),o(!1)},onCancel:()=>o(!1)})]})}function ake({printDates:t,months:e=3}){const{weeks:n,monthLabels:r,printCounts:i}=M.useMemo(()=>{const l={};t.forEach(b=>{const E=b.split("T")[0];l[E]=(l[E]||0)+1});const u=new Date,d=new Date(u);d.setMonth(d.getMonth()-e),d.setDate(d.getDate()-d.getDay());const f=[],g=[];let m=[],x=-1;const y=new Date(d);let v=0;for(;y<=u;)y.getDay()===0&&m.length>0&&(f.push(m),m=[],v++),y.getMonth()!==x&&(g.push({month:y.toLocaleDateString("en-US",{month:"short"}),weekIndex:v}),x=y.getMonth()),m.push(new Date(y)),y.setDate(y.getDate()+1);return m.length>0&&f.push(m),{weeks:f,monthLabels:g,printCounts:l}},[t,e]),s=Math.max(1,...Object.values(i)),a=l=>{if(l===0)return"bg-bambu-dark";const u=l/s;return u<=.25?"bg-bambu-green/30":u<=.5?"bg-bambu-green/50":u<=.75?"bg-bambu-green/75":"bg-bambu-green"},o=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];return c.jsxs("div",{className:"overflow-x-auto",children:[c.jsx("div",{className:"flex mb-1 ml-8",children:r.map(({month:l,weekIndex:u},d)=>c.jsx("div",{className:"text-xs text-bambu-gray",style:{marginLeft:d===0?0:`${(u-(r[d-1]?.weekIndex||0))*14-24}px`},children:l},d))}),c.jsxs("div",{className:"flex gap-0.5",children:[c.jsx("div",{className:"flex flex-col gap-0.5 mr-1",children:o.map((l,u)=>c.jsx("div",{className:"h-3 text-xs text-bambu-gray flex items-center",style:{visibility:u%2===1?"visible":"hidden"},children:l},l))}),n.map((l,u)=>c.jsx("div",{className:"flex flex-col gap-0.5",children:[0,1,2,3,4,5,6].map(d=>{const f=l.find(y=>y.getDay()===d);if(!f)return c.jsx("div",{className:"w-3 h-3"},d);const g=f.toISOString().split("T")[0],m=i[g]||0,x=g===new Date().toISOString().split("T")[0];return c.jsx("div",{className:`w-3 h-3 rounded-sm ${a(m)} ${x?"ring-1 ring-white":""}`,title:`${f.toLocaleDateString()}: ${m} print${m!==1?"s":""}`},d)})},u))]}),c.jsxs("div",{className:"flex items-center gap-2 mt-3 text-xs text-bambu-gray",children:[c.jsx("span",{children:"Less"}),c.jsxs("div",{className:"flex gap-0.5",children:[c.jsx("div",{className:"w-3 h-3 rounded-sm bg-bambu-dark"}),c.jsx("div",{className:"w-3 h-3 rounded-sm bg-bambu-green/30"}),c.jsx("div",{className:"w-3 h-3 rounded-sm bg-bambu-green/50"}),c.jsx("div",{className:"w-3 h-3 rounded-sm bg-bambu-green/75"}),c.jsx("div",{className:"w-3 h-3 rounded-sm bg-bambu-green"})]}),c.jsx("span",{children:"More"})]})]})}function MX(t){var e,n,r="";if(typeof t=="string"||typeof t=="number")r+=t;else if(typeof t=="object")if(Array.isArray(t)){var i=t.length;for(e=0;e{var{children:n,width:r,height:i,viewBox:s,className:a,style:o,title:l,desc:u}=t,d=hke(t,dke),f=s||{width:r,height:i,x:0,y:0},g=Tn("recharts-surface",a);return M.createElement("svg",Qk({},Cs(d),{className:g,width:r,height:i,style:o,viewBox:"".concat(f.x," ").concat(f.y," ").concat(f.width," ").concat(f.height),ref:e}),M.createElement("title",null,l),M.createElement("desc",null,u),n)}),pke=["children","className"];function Jk(){return Jk=Object.assign?Object.assign.bind():function(t){for(var e=1;e{var{children:n,className:r}=t,i=mke(t,pke),s=Tn("recharts-layer",r);return M.createElement("g",Jk({className:s},Cs(i),{ref:e}),n)}),CX=M.createContext(null),xke=()=>M.useContext(CX);function er(t){return function(){return t}}const NX=Math.cos,gw=Math.sin,zo=Math.sqrt,xw=Math.PI,eE=2*xw,eP=Math.PI,tP=2*eP,Xd=1e-6,bke=tP-Xd;function kX(t){this._+=t[0];for(let e=1,n=t.length;e=0))throw new Error(`invalid digits: ${t}`);if(e>15)return kX;const n=10**e;return function(r){this._+=r[0];for(let i=1,s=r.length;iXd)if(!(Math.abs(f*l-u*d)>Xd)||!s)this._append`L${this._x1=e},${this._y1=n}`;else{let m=r-a,x=i-o,y=l*l+u*u,v=m*m+x*x,b=Math.sqrt(y),E=Math.sqrt(g),S=s*Math.tan((eP-Math.acos((y+g-v)/(2*b*E)))/2),A=S/E,T=S/b;Math.abs(A-1)>Xd&&this._append`L${e+A*d},${n+A*f}`,this._append`A${s},${s},0,0,${+(f*m>d*x)},${this._x1=e+T*l},${this._y1=n+T*u}`}}arc(e,n,r,i,s,a){if(e=+e,n=+n,r=+r,a=!!a,r<0)throw new Error(`negative radius: ${r}`);let o=r*Math.cos(i),l=r*Math.sin(i),u=e+o,d=n+l,f=1^a,g=a?i-s:s-i;this._x1===null?this._append`M${u},${d}`:(Math.abs(this._x1-u)>Xd||Math.abs(this._y1-d)>Xd)&&this._append`L${u},${d}`,r&&(g<0&&(g=g%tP+tP),g>bke?this._append`A${r},${r},0,1,${f},${e-o},${n-l}A${r},${r},0,1,${f},${this._x1=u},${this._y1=d}`:g>Xd&&this._append`A${r},${r},0,${+(g>=eP)},${f},${this._x1=e+r*Math.cos(s)},${this._y1=n+r*Math.sin(s)}`)}rect(e,n,r,i){this._append`M${this._x0=this._x1=+e},${this._y0=this._y1=+n}h${r=+r}v${+i}h${-r}Z`}toString(){return this._}}function qD(t){let e=3;return t.digits=function(n){if(!arguments.length)return e;if(n==null)e=null;else{const r=Math.floor(n);if(!(r>=0))throw new RangeError(`invalid digits: ${n}`);e=r}return t},()=>new yke(e)}function KD(t){return typeof t=="object"&&"length"in t?t:Array.from(t)}function PX(t){this._context=t}PX.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;default:this._context.lineTo(t,e);break}}};function tE(t){return new PX(t)}function RX(t){return t[0]}function DX(t){return t[1]}function OX(t,e){var n=er(!0),r=null,i=tE,s=null,a=qD(o);t=typeof t=="function"?t:t===void 0?RX:er(t),e=typeof e=="function"?e:e===void 0?DX:er(e);function o(l){var u,d=(l=KD(l)).length,f,g=!1,m;for(r==null&&(s=i(m=a())),u=0;u<=d;++u)!(u=m;--x)o.point(S[x],A[x]);o.lineEnd(),o.areaEnd()}b&&(S[g]=+t(v,g,f),A[g]=+e(v,g,f),o.point(r?+r(v,g,f):S[g],n?+n(v,g,f):A[g]))}if(E)return o=null,E+""||null}function d(){return OX().defined(i).curve(a).context(s)}return u.x=function(f){return arguments.length?(t=typeof f=="function"?f:er(+f),r=null,u):t},u.x0=function(f){return arguments.length?(t=typeof f=="function"?f:er(+f),u):t},u.x1=function(f){return arguments.length?(r=f==null?null:typeof f=="function"?f:er(+f),u):r},u.y=function(f){return arguments.length?(e=typeof f=="function"?f:er(+f),n=null,u):e},u.y0=function(f){return arguments.length?(e=typeof f=="function"?f:er(+f),u):e},u.y1=function(f){return arguments.length?(n=f==null?null:typeof f=="function"?f:er(+f),u):n},u.lineX0=u.lineY0=function(){return d().x(t).y(e)},u.lineY1=function(){return d().x(t).y(n)},u.lineX1=function(){return d().x(r).y(e)},u.defined=function(f){return arguments.length?(i=typeof f=="function"?f:er(!!f),u):i},u.curve=function(f){return arguments.length?(a=f,s!=null&&(o=a(s)),u):a},u.context=function(f){return arguments.length?(f==null?s=o=null:o=a(s=f),u):s},u}class jX{constructor(e,n){this._context=e,this._x=n}areaStart(){this._line=0}areaEnd(){this._line=NaN}lineStart(){this._point=0}lineEnd(){(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line}point(e,n){switch(e=+e,n=+n,this._point){case 0:{this._point=1,this._line?this._context.lineTo(e,n):this._context.moveTo(e,n);break}case 1:this._point=2;default:{this._x?this._context.bezierCurveTo(this._x0=(this._x0+e)/2,this._y0,this._x0,n,e,n):this._context.bezierCurveTo(this._x0,this._y0=(this._y0+n)/2,e,this._y0,e,n);break}}this._x0=e,this._y0=n}}function _ke(t){return new jX(t,!0)}function wke(t){return new jX(t,!1)}const XD={draw(t,e){const n=zo(e/xw);t.moveTo(n,0),t.arc(0,0,n,0,eE)}},Ske={draw(t,e){const n=zo(e/5)/2;t.moveTo(-3*n,-n),t.lineTo(-n,-n),t.lineTo(-n,-3*n),t.lineTo(n,-3*n),t.lineTo(n,-n),t.lineTo(3*n,-n),t.lineTo(3*n,n),t.lineTo(n,n),t.lineTo(n,3*n),t.lineTo(-n,3*n),t.lineTo(-n,n),t.lineTo(-3*n,n),t.closePath()}},LX=zo(1/3),Eke=LX*2,Mke={draw(t,e){const n=zo(e/Eke),r=n*LX;t.moveTo(0,-n),t.lineTo(r,0),t.lineTo(0,n),t.lineTo(-r,0),t.closePath()}},Ake={draw(t,e){const n=zo(e),r=-n/2;t.rect(r,r,n,n)}},Tke=.8908130915292852,IX=gw(xw/10)/gw(7*xw/10),Cke=gw(eE/10)*IX,Nke=-NX(eE/10)*IX,kke={draw(t,e){const n=zo(e*Tke),r=Cke*n,i=Nke*n;t.moveTo(0,-n),t.lineTo(r,i);for(let s=1;s<5;++s){const a=eE*s/5,o=NX(a),l=gw(a);t.lineTo(l*n,-o*n),t.lineTo(o*r-l*i,l*r+o*i)}t.closePath()}},cC=zo(3),Pke={draw(t,e){const n=-zo(e/(cC*3));t.moveTo(0,n*2),t.lineTo(-cC*n,-n),t.lineTo(cC*n,-n),t.closePath()}},Oa=-.5,ja=zo(3)/2,nP=1/zo(12),Rke=(nP/2+1)*3,Dke={draw(t,e){const n=zo(e/Rke),r=n/2,i=n*nP,s=r,a=n*nP+n,o=-s,l=a;t.moveTo(r,i),t.lineTo(s,a),t.lineTo(o,l),t.lineTo(Oa*r-ja*i,ja*r+Oa*i),t.lineTo(Oa*s-ja*a,ja*s+Oa*a),t.lineTo(Oa*o-ja*l,ja*o+Oa*l),t.lineTo(Oa*r+ja*i,Oa*i-ja*r),t.lineTo(Oa*s+ja*a,Oa*a-ja*s),t.lineTo(Oa*o+ja*l,Oa*l-ja*o),t.closePath()}};function Oke(t,e){let n=null,r=qD(i);t=typeof t=="function"?t:er(t||XD),e=typeof e=="function"?e:er(e===void 0?64:+e);function i(){let s;if(n||(n=s=r()),t.apply(this,arguments).draw(n,+e.apply(this,arguments)),s)return n=null,s+""||null}return i.type=function(s){return arguments.length?(t=typeof s=="function"?s:er(s),i):t},i.size=function(s){return arguments.length?(e=typeof s=="function"?s:er(+s),i):e},i.context=function(s){return arguments.length?(n=s??null,i):n},i}function bw(){}function vw(t,e,n){t._context.bezierCurveTo((2*t._x0+t._x1)/3,(2*t._y0+t._y1)/3,(t._x0+2*t._x1)/3,(t._y0+2*t._y1)/3,(t._x0+4*t._x1+e)/6,(t._y0+4*t._y1+n)/6)}function UX(t){this._context=t}UX.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._point=0},lineEnd:function(){switch(this._point){case 3:vw(this,this._x1,this._y1);case 2:this._context.lineTo(this._x1,this._y1);break}(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;break;case 2:this._point=3,this._context.lineTo((5*this._x0+this._x1)/6,(5*this._y0+this._y1)/6);default:vw(this,t,e);break}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=e}};function jke(t){return new UX(t)}function FX(t){this._context=t}FX.prototype={areaStart:bw,areaEnd:bw,lineStart:function(){this._x0=this._x1=this._x2=this._x3=this._x4=this._y0=this._y1=this._y2=this._y3=this._y4=NaN,this._point=0},lineEnd:function(){switch(this._point){case 1:{this._context.moveTo(this._x2,this._y2),this._context.closePath();break}case 2:{this._context.moveTo((this._x2+2*this._x3)/3,(this._y2+2*this._y3)/3),this._context.lineTo((this._x3+2*this._x2)/3,(this._y3+2*this._y2)/3),this._context.closePath();break}case 3:{this.point(this._x2,this._y2),this.point(this._x3,this._y3),this.point(this._x4,this._y4);break}}},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._x2=t,this._y2=e;break;case 1:this._point=2,this._x3=t,this._y3=e;break;case 2:this._point=3,this._x4=t,this._y4=e,this._context.moveTo((this._x0+4*this._x1+t)/6,(this._y0+4*this._y1+e)/6);break;default:vw(this,t,e);break}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=e}};function Lke(t){return new FX(t)}function zX(t){this._context=t}zX.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._point=0},lineEnd:function(){(this._line||this._line!==0&&this._point===3)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1;break;case 1:this._point=2;break;case 2:this._point=3;var n=(this._x0+4*this._x1+t)/6,r=(this._y0+4*this._y1+e)/6;this._line?this._context.lineTo(n,r):this._context.moveTo(n,r);break;case 3:this._point=4;default:vw(this,t,e);break}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=e}};function Ike(t){return new zX(t)}function BX(t){this._context=t}BX.prototype={areaStart:bw,areaEnd:bw,lineStart:function(){this._point=0},lineEnd:function(){this._point&&this._context.closePath()},point:function(t,e){t=+t,e=+e,this._point?this._context.lineTo(t,e):(this._point=1,this._context.moveTo(t,e))}};function Uke(t){return new BX(t)}function v8(t){return t<0?-1:1}function y8(t,e,n){var r=t._x1-t._x0,i=e-t._x1,s=(t._y1-t._y0)/(r||i<0&&-0),a=(n-t._y1)/(i||r<0&&-0),o=(s*i+a*r)/(r+i);return(v8(s)+v8(a))*Math.min(Math.abs(s),Math.abs(a),.5*Math.abs(o))||0}function _8(t,e){var n=t._x1-t._x0;return n?(3*(t._y1-t._y0)/n-e)/2:e}function uC(t,e,n){var r=t._x0,i=t._y0,s=t._x1,a=t._y1,o=(s-r)/3;t._context.bezierCurveTo(r+o,i+o*e,s-o,a-o*n,s,a)}function yw(t){this._context=t}yw.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=this._t0=NaN,this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x1,this._y1);break;case 3:uC(this,this._t0,_8(this,this._t0));break}(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){var n=NaN;if(t=+t,e=+e,!(t===this._x1&&e===this._y1)){switch(this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;break;case 2:this._point=3,uC(this,_8(this,n=y8(this,t,e)),n);break;default:uC(this,this._t0,n=y8(this,t,e));break}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=e,this._t0=n}}};function HX(t){this._context=new $X(t)}(HX.prototype=Object.create(yw.prototype)).point=function(t,e){yw.prototype.point.call(this,e,t)};function $X(t){this._context=t}$X.prototype={moveTo:function(t,e){this._context.moveTo(e,t)},closePath:function(){this._context.closePath()},lineTo:function(t,e){this._context.lineTo(e,t)},bezierCurveTo:function(t,e,n,r,i,s){this._context.bezierCurveTo(e,t,r,n,s,i)}};function Fke(t){return new yw(t)}function zke(t){return new HX(t)}function VX(t){this._context=t}VX.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x=[],this._y=[]},lineEnd:function(){var t=this._x,e=this._y,n=t.length;if(n)if(this._line?this._context.lineTo(t[0],e[0]):this._context.moveTo(t[0],e[0]),n===2)this._context.lineTo(t[1],e[1]);else for(var r=w8(t),i=w8(e),s=0,a=1;a=0;--e)i[e]=(a[e]-i[e+1])/s[e];for(s[n-1]=(t[n]+i[n-1])/2,e=0;e=0&&(this._t=1-this._t,this._line=1-this._line)},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;default:{if(this._t<=0)this._context.lineTo(this._x,e),this._context.lineTo(t,e);else{var n=this._x*(1-this._t)+t*this._t;this._context.lineTo(n,this._y),this._context.lineTo(n,e)}break}}this._x=t,this._y=e}};function Hke(t){return new nE(t,.5)}function $ke(t){return new nE(t,0)}function Vke(t){return new nE(t,1)}function Em(t,e){if((a=t.length)>1)for(var n=1,r,i,s=t[e[0]],a,o=s.length;n=0;)n[e]=e;return n}function Gke(t,e){return t[e]}function Wke(t){const e=[];return e.key=t,e}function qke(){var t=er([]),e=rP,n=Em,r=Gke;function i(s){var a=Array.from(t.apply(this,arguments),Wke),o,l=a.length,u=-1,d;for(const f of s)for(o=0,++u;o0){for(var n,r,i=0,s=t[0].length,a;i0){for(var n=0,r=t[e[0]],i,s=r.length;n0)||!((s=(i=t[e[0]]).length)>0))){for(var n=0,r=1,i,s,a;rt===0?0:t>0?1:-1,io=t=>typeof t=="number"&&t!=+t,wc=t=>typeof t=="string"&&t.indexOf("%")===t.length-1,Ct=t=>(typeof t=="number"||t instanceof Number)&&!io(t),fl=t=>Ct(t)||typeof t=="string",tPe=0,U0=t=>{var e=++tPe;return"".concat(t||"").concat(e)},hs=function(e,n){var r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:0,i=arguments.length>3&&arguments[3]!==void 0?arguments[3]:!1;if(!Ct(e)&&typeof e!="string")return r;var s;if(wc(e)){if(n==null)return r;var a=e.indexOf("%");s=n*parseFloat(e.slice(0,a))/100}else s=+e;return io(s)&&(s=r),i&&n!=null&&s>n&&(s=n),s},WX=t=>{if(!Array.isArray(t))return!1;for(var e=t.length,n={},r=0;rr&&(typeof e=="function"?e(r):Kh(r,e))===n)}var yr=t=>t===null||typeof t>"u",mb=t=>yr(t)?t:"".concat(t.charAt(0).toUpperCase()).concat(t.slice(1));function nPe(t){return t!=null}function gb(){}var rPe=["type","size","sizeType"];function iP(){return iP=Object.assign?Object.assign.bind():function(t){for(var e=1;e{var e="symbol".concat(mb(t));return KX[e]||XD},dPe=(t,e,n)=>{if(e==="area")return t;switch(n){case"cross":return 5*t*t/9;case"diamond":return .5*t*t/Math.sqrt(3);case"square":return t*t;case"star":{var r=18*cPe;return 1.25*t*t*(Math.tan(r)-Math.tan(r*2)*Math.tan(r)**2)}case"triangle":return Math.sqrt(3)*t*t/4;case"wye":return(21-10*Math.sqrt(3))*t*t/8;default:return Math.PI*t*t/4}},hPe=(t,e)=>{KX["symbol".concat(mb(t))]=e},JD=t=>{var{type:e="circle",size:n=64,sizeType:r="area"}=t,i=oPe(t,rPe),s=P8(P8({},i),{},{type:e,size:n,sizeType:r}),a="circle";typeof e=="string"&&(a=e);var o=()=>{var g=uPe(a),m=Oke().type(g).size(dPe(n,r,a)),x=m();if(x!==null)return x},{className:l,cx:u,cy:d}=s,f=Cs(s);return Ct(u)&&Ct(d)&&Ct(n)?M.createElement("path",iP({},f,{className:Tn("recharts-symbols",l),transform:"translate(".concat(u,", ").concat(d,")"),d:o()})):null};JD.registerSymbol=hPe;var XX=t=>"radius"in t&&"startAngle"in t&&"endAngle"in t,eO=(t,e)=>{if(!t||typeof t=="function"||typeof t=="boolean")return null;var n=t;if(M.isValidElement(t)&&(n=t.props),typeof n!="object"&&typeof n!="function")return null;var r={};return Object.keys(n).forEach(i=>{GD(i)&&(r[i]=(s=>n[i](n,s)))}),r},fPe=(t,e,n)=>r=>(t(e,n,r),null),xb=(t,e,n)=>{if(t===null||typeof t!="object"&&typeof t!="function")return null;var r=null;return Object.keys(t).forEach(i=>{var s=t[i];GD(i)&&typeof s=="function"&&(r||(r={}),r[i]=fPe(s,e,n))}),r};function R8(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function pPe(t){for(var e=1;e(a[o]===void 0&&r[o]!==void 0&&(a[o]=r[o]),a),n);return s}function _w(){return _w=Object.assign?Object.assign.bind():function(t){for(var e=1;elocalStorage.getItem("queue.historySortBy")||"date"),[x,y]=M.useState(()=>{const Y=localStorage.getItem("queue.historySortAsc");return Y!==null?Y==="true":!1}),[v,b]=M.useState(()=>localStorage.getItem("queue.pendingSortBy")||"position"),[E,S]=M.useState(()=>{const Y=localStorage.getItem("queue.pendingSortAsc");return Y!==null?Y==="true":!0});M.useEffect(()=>{localStorage.setItem("queue.historySortBy",g)},[g]),M.useEffect(()=>{localStorage.setItem("queue.historySortAsc",String(x))},[x]),M.useEffect(()=>{localStorage.setItem("queue.pendingSortBy",v)},[v]),M.useEffect(()=>{localStorage.setItem("queue.pendingSortAsc",String(E))},[E]);const A=JK(fw(YS,{activationConstraint:{distance:8}}),fw(XS,{coordinateGetter:wX})),{data:T,isLoading:P}=yt({queryKey:["queue",n,i],queryFn:()=>Pe.getQueue(n||void 0,i||void 0),refetchInterval:5e3}),{data:C}=yt({queryKey:["printers"],queryFn:()=>Pe.getPrinters()}),I=_t({mutationFn:Y=>Pe.cancelQueueItem(Y),onSuccess:()=>{t.invalidateQueries({queryKey:["queue"]}),e("Queue item cancelled")},onError:()=>e("Failed to cancel item","error")}),N=_t({mutationFn:Y=>Pe.removeFromQueue(Y),onSuccess:()=>{t.invalidateQueries({queryKey:["queue"]}),e("Queue item removed")},onError:()=>e("Failed to remove item","error")}),D=_t({mutationFn:Y=>Pe.stopQueueItem(Y),onSuccess:()=>{t.invalidateQueries({queryKey:["queue"]}),e("Print stopped")},onError:()=>e("Failed to stop print","error")}),F=_t({mutationFn:Y=>Pe.reorderQueue(Y),onSuccess:()=>{t.invalidateQueries({queryKey:["queue"]})},onError:()=>e("Failed to reorder queue","error")}),L=_t({mutationFn:Y=>{const Z=new Date;return Z.setFullYear(Z.getFullYear()+1),Pe.addToQueue({printer_id:Y.printer_id,archive_id:Y.archive_id,scheduled_time:Z.toISOString(),require_previous_success:!1,auto_off_after:!1})},onSuccess:Y=>{t.invalidateQueries({queryKey:["queue"]}),e("Added back to queue - please set schedule"),u(Y)},onError:Y=>e(Y.message||"Failed to re-queue item","error")}),q=_t({mutationFn:async()=>{const Y=T?.filter(Z=>["completed","failed","skipped","cancelled"].includes(Z.status))||[];for(const Z of Y)await Pe.removeFromQueue(Z.id);return Y.length},onSuccess:Y=>{t.invalidateQueries({queryKey:["queue"]}),e(`Cleared ${Y} history item${Y!==1?"s":""}`)},onError:()=>e("Failed to clear history","error")}),R=M.useMemo(()=>{const Y=T?.filter(U=>U.status==="pending")||[],Z=U=>{if(!U.scheduled_time)return 0;const $=new Date(U.scheduled_time).getTime(),ee=Date.now()+4320*60*60*1e3;return $>ee?0:$};return[...Y].sort((U,$)=>{let ee;return v==="name"?ee=(U.archive_name||"").localeCompare($.archive_name||""):v==="printer"?ee=(U.printer_name||"").localeCompare($.printer_name||""):v==="time"?ee=Z(U)-Z($):ee=U.position-$.position,E?ee:-ee})},[T,v,E]),V=T?.filter(Y=>Y.status==="printing")||[],K=M.useMemo(()=>[...T?.filter(Z=>["completed","failed","skipped","cancelled"].includes(Z.status))||[]].sort((Z,U)=>{let $;return g==="name"?$=(Z.archive_name||"").localeCompare(U.archive_name||""):g==="printer"?$=(Z.printer_name||"").localeCompare(U.printer_name||""):$=new Date(U.completed_at||U.created_at).getTime()-new Date(Z.completed_at||Z.created_at).getTime(),x?-$:$}),[T,g,x]),W=M.useMemo(()=>R.reduce((Y,Z)=>Y+(Z.print_time_seconds||0),0),[R]),ne=Y=>{const{active:Z,over:U}=Y;if(!U||Z.id===U.id)return;const $=R.findIndex(ae=>ae.id===Z.id),ee=R.findIndex(ae=>ae.id===U.id);if($!==-1&&ee!==-1){const fe=JS(R,$,ee).map((ue,xe)=>({id:ue.id,position:xe+1}));F.mutate(fe)}};return c.jsxs("div",{className:"p-4 md:p-8",children:[c.jsx("div",{className:"flex items-center justify-between mb-8",children:c.jsxs("div",{children:[c.jsxs("h1",{className:"text-2xl font-bold text-white flex items-center gap-3",children:[c.jsx(jG,{className:"w-7 h-7 text-bambu-green"}),"Print Queue"]}),c.jsx("p",{className:"text-bambu-gray mt-1",children:"Schedule and manage your print jobs"})]})}),c.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4 mb-8",children:[c.jsx(Nt,{className:"bg-gradient-to-br from-blue-500/10 to-transparent border-blue-500/20",children:c.jsx(Dt,{className:"p-4",children:c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("div",{className:"w-10 h-10 rounded-lg bg-blue-500/20 flex items-center justify-center",children:c.jsx(bS,{className:"w-5 h-5 text-blue-400"})}),c.jsxs("div",{children:[c.jsx("p",{className:"text-2xl font-bold text-white",children:V.length}),c.jsx("p",{className:"text-sm text-bambu-gray",children:"Printing"})]})]})})}),c.jsx(Nt,{className:"bg-gradient-to-br from-yellow-500/10 to-transparent border-yellow-500/20",children:c.jsx(Dt,{className:"p-4",children:c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("div",{className:"w-10 h-10 rounded-lg bg-yellow-500/20 flex items-center justify-center",children:c.jsx(ti,{className:"w-5 h-5 text-yellow-400"})}),c.jsxs("div",{children:[c.jsx("p",{className:"text-2xl font-bold text-white",children:R.length}),c.jsx("p",{className:"text-sm text-bambu-gray",children:"Queued"})]})]})})}),c.jsx(Nt,{className:"bg-gradient-to-br from-bambu-green/10 to-transparent border-bambu-green/20",children:c.jsx(Dt,{className:"p-4",children:c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("div",{className:"w-10 h-10 rounded-lg bg-bambu-green/20 flex items-center justify-center",children:c.jsx(Ou,{className:"w-5 h-5 text-bambu-green"})}),c.jsxs("div",{children:[c.jsx("p",{className:"text-2xl font-bold text-white",children:EX(W)}),c.jsx("p",{className:"text-sm text-bambu-gray",children:"Total Queue Time"})]})]})})}),c.jsx(Nt,{className:"bg-gradient-to-br from-gray-500/10 to-transparent border-gray-500/20",children:c.jsx(Dt,{className:"p-4",children:c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("div",{className:"w-10 h-10 rounded-lg bg-gray-500/20 flex items-center justify-center",children:c.jsx(ds,{className:"w-5 h-5 text-gray-400"})}),c.jsxs("div",{children:[c.jsx("p",{className:"text-2xl font-bold text-white",children:K.length}),c.jsx("p",{className:"text-sm text-bambu-gray",children:"History"})]})]})})})]}),c.jsxs("div",{className:"flex items-center gap-4 mb-6",children:[c.jsxs("select",{className:"px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:n||"",onChange:Y=>r(Y.target.value?Number(Y.target.value):null),children:[c.jsx("option",{value:"",children:"All Printers"}),C?.map(Y=>c.jsx("option",{value:Y.id,children:Y.name},Y.id))]}),c.jsxs("select",{className:"px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:i,onChange:Y=>s(Y.target.value),children:[c.jsx("option",{value:"",children:"All Status"}),c.jsx("option",{value:"pending",children:"Pending"}),c.jsx("option",{value:"printing",children:"Printing"}),c.jsx("option",{value:"completed",children:"Completed"}),c.jsx("option",{value:"failed",children:"Failed"}),c.jsx("option",{value:"skipped",children:"Skipped"}),c.jsx("option",{value:"cancelled",children:"Cancelled"})]}),c.jsx("div",{className:"flex-1"}),K.length>0&&c.jsxs(Ie,{variant:"secondary",size:"sm",onClick:()=>o(!0),children:[c.jsx(kn,{className:"w-4 h-4"}),"Clear History"]})]}),P?c.jsx("div",{className:"text-center py-12 text-bambu-gray",children:"Loading..."}):T?.length===0?c.jsxs(Nt,{className:"p-12 text-center border-dashed",children:[c.jsx(qr,{className:"w-16 h-16 text-bambu-gray mx-auto mb-4 opacity-50"}),c.jsx("h3",{className:"text-xl font-medium text-white mb-2",children:"No prints scheduled"}),c.jsx("p",{className:"text-bambu-gray max-w-md mx-auto",children:'Schedule a print from the Archives page using the "Schedule" option in the context menu, or drag and drop files to get started.'})]}):c.jsxs("div",{className:"space-y-8",children:[V.length>0&&c.jsxs("div",{children:[c.jsxs("h2",{className:"text-lg font-semibold text-white mb-4 flex items-center gap-2",children:[c.jsx("div",{className:"w-2 h-2 rounded-full bg-blue-400 animate-pulse"}),"Currently Printing"]}),c.jsx("div",{className:"space-y-3",children:V.map(Y=>c.jsx(lC,{item:Y,onEdit:()=>{},onCancel:()=>{},onRemove:()=>{},onStop:()=>f({type:"stop",item:Y}),onRequeue:()=>{}},Y.id))})]}),R.length>0&&c.jsxs("div",{children:[c.jsxs("div",{className:"flex items-center justify-between mb-4",children:[c.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[c.jsx(ti,{className:"w-5 h-5 text-yellow-400"}),"Queued",c.jsxs("span",{className:"text-sm font-normal text-bambu-gray",children:["(",R.length," item",R.length!==1?"s":"",")"]}),c.jsx("span",{className:"text-xs text-bambu-gray ml-2",title:"Position only affects ASAP items. Scheduled items run at their set time.",children:"Drag to reorder (ASAP only)"})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("select",{className:"px-3 py-1.5 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:v,onChange:Y=>b(Y.target.value),children:[c.jsx("option",{value:"position",children:"Sort by Position"}),c.jsx("option",{value:"name",children:"Sort by Name"}),c.jsx("option",{value:"printer",children:"Sort by Printer"}),c.jsx("option",{value:"time",children:"Sort by Schedule"})]}),c.jsx(Ie,{variant:"ghost",size:"sm",onClick:()=>S(!E),title:E?"Ascending":"Descending",className:"px-2",children:E?c.jsx(nm,{className:"w-4 h-4"}):c.jsx(s0,{className:"w-4 h-4"})})]})]}),c.jsx(gX,{sensors:A,collisionDetection:rX,onDragEnd:ne,children:c.jsx(vX,{items:R.map(Y=>Y.id),strategy:G3e,children:c.jsx("div",{className:"space-y-3",children:R.map((Y,Z)=>c.jsx(lC,{item:Y,position:Z+1,onEdit:()=>u(Y),onCancel:()=>f({type:"cancel",item:Y}),onRemove:()=>{},onStop:()=>{},onRequeue:()=>{}},Y.id))})})})]}),K.length>0&&c.jsxs("div",{children:[c.jsxs("div",{className:"flex items-center justify-between mb-4",children:[c.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[c.jsx(ds,{className:"w-5 h-5 text-bambu-gray"}),"History",c.jsxs("span",{className:"text-sm font-normal text-bambu-gray",children:["(",K.length," item",K.length!==1?"s":"",")"]})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("select",{className:"px-3 py-1.5 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:g,onChange:Y=>m(Y.target.value),children:[c.jsx("option",{value:"date",children:"Sort by Date"}),c.jsx("option",{value:"name",children:"Sort by Name"}),c.jsx("option",{value:"printer",children:"Sort by Printer"})]}),c.jsx(Ie,{variant:"ghost",size:"sm",onClick:()=>y(!x),title:x?"Ascending (oldest first)":"Descending (newest first)",className:"px-2",children:x?c.jsx(nm,{className:"w-4 h-4"}):c.jsx(s0,{className:"w-4 h-4"})})]})]}),c.jsx("div",{className:"space-y-3",children:K.slice(0,20).map((Y,Z)=>c.jsx(lC,{item:Y,position:Z+1,onEdit:()=>{},onCancel:()=>{},onRemove:()=>f({type:"remove",item:Y}),onStop:()=>{},onRequeue:()=>L.mutate(Y)},Y.id))})]})]}),l&&c.jsx(nke,{item:l,onClose:()=>u(null)}),d&&c.jsx(Kr,{title:d.type==="cancel"?"Cancel Scheduled Print":d.type==="stop"?"Stop Print":"Remove from History",message:d.type==="cancel"?`Are you sure you want to cancel "${d.item.archive_name||"this print"}"?`:d.type==="stop"?`Are you sure you want to stop the current print "${d.item.archive_name||"this print"}"? This will cancel the print job on the printer.`:`Are you sure you want to remove "${d.item.archive_name||"this item"}" from the queue history?`,confirmText:d.type==="cancel"?"Cancel Print":d.type==="stop"?"Stop Print":"Remove",variant:"danger",onConfirm:()=>{d.type==="cancel"?I.mutate(d.item.id):d.type==="stop"?D.mutate(d.item.id):N.mutate(d.item.id),f(null)},onCancel:()=>f(null)}),a&&c.jsx(Kr,{title:"Clear History",message:`Are you sure you want to remove all ${K.length} item${K.length!==1?"s":""} from the history?`,confirmText:"Clear History",variant:"danger",onConfirm:()=>{q.mutate(),o(!1)},onCancel:()=>o(!1)})]})}function ake({printDates:t,months:e=3}){const{weeks:n,monthLabels:r,printCounts:i}=M.useMemo(()=>{const l={};t.forEach(b=>{const E=b.split("T")[0];l[E]=(l[E]||0)+1});const u=new Date,d=new Date(u);d.setMonth(d.getMonth()-e),d.setDate(d.getDate()-d.getDay());const f=[],g=[];let m=[],x=-1;const y=new Date(d);let v=0;for(;y<=u;)y.getDay()===0&&m.length>0&&(f.push(m),m=[],v++),y.getMonth()!==x&&(g.push({month:y.toLocaleDateString("en-US",{month:"short"}),weekIndex:v}),x=y.getMonth()),m.push(new Date(y)),y.setDate(y.getDate()+1);return m.length>0&&f.push(m),{weeks:f,monthLabels:g,printCounts:l}},[t,e]),s=Math.max(1,...Object.values(i)),a=l=>{if(l===0)return"bg-bambu-dark";const u=l/s;return u<=.25?"bg-bambu-green/30":u<=.5?"bg-bambu-green/50":u<=.75?"bg-bambu-green/75":"bg-bambu-green"},o=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];return c.jsxs("div",{className:"overflow-x-auto",children:[c.jsx("div",{className:"flex mb-1 ml-8",children:r.map(({month:l,weekIndex:u},d)=>c.jsx("div",{className:"text-xs text-bambu-gray",style:{marginLeft:d===0?0:`${(u-(r[d-1]?.weekIndex||0))*14-24}px`},children:l},d))}),c.jsxs("div",{className:"flex gap-0.5",children:[c.jsx("div",{className:"flex flex-col gap-0.5 mr-1",children:o.map((l,u)=>c.jsx("div",{className:"h-3 text-xs text-bambu-gray flex items-center",style:{visibility:u%2===1?"visible":"hidden"},children:l},l))}),n.map((l,u)=>c.jsx("div",{className:"flex flex-col gap-0.5",children:[0,1,2,3,4,5,6].map(d=>{const f=l.find(y=>y.getDay()===d);if(!f)return c.jsx("div",{className:"w-3 h-3"},d);const g=f.toISOString().split("T")[0],m=i[g]||0,x=g===new Date().toISOString().split("T")[0];return c.jsx("div",{className:`w-3 h-3 rounded-sm ${a(m)} ${x?"ring-1 ring-white":""}`,title:`${f.toLocaleDateString()}: ${m} print${m!==1?"s":""}`},d)})},u))]}),c.jsxs("div",{className:"flex items-center gap-2 mt-3 text-xs text-bambu-gray",children:[c.jsx("span",{children:"Less"}),c.jsxs("div",{className:"flex gap-0.5",children:[c.jsx("div",{className:"w-3 h-3 rounded-sm bg-bambu-dark"}),c.jsx("div",{className:"w-3 h-3 rounded-sm bg-bambu-green/30"}),c.jsx("div",{className:"w-3 h-3 rounded-sm bg-bambu-green/50"}),c.jsx("div",{className:"w-3 h-3 rounded-sm bg-bambu-green/75"}),c.jsx("div",{className:"w-3 h-3 rounded-sm bg-bambu-green"})]}),c.jsx("span",{children:"More"})]})]})}function MX(t){var e,n,r="";if(typeof t=="string"||typeof t=="number")r+=t;else if(typeof t=="object")if(Array.isArray(t)){var i=t.length;for(e=0;e{var{children:n,width:r,height:i,viewBox:s,className:a,style:o,title:l,desc:u}=t,d=hke(t,dke),f=s||{width:r,height:i,x:0,y:0},g=Tn("recharts-surface",a);return M.createElement("svg",Qk({},Cs(d),{className:g,width:r,height:i,style:o,viewBox:"".concat(f.x," ").concat(f.y," ").concat(f.width," ").concat(f.height),ref:e}),M.createElement("title",null,l),M.createElement("desc",null,u),n)}),pke=["children","className"];function Jk(){return Jk=Object.assign?Object.assign.bind():function(t){for(var e=1;e{var{children:n,className:r}=t,i=mke(t,pke),s=Tn("recharts-layer",r);return M.createElement("g",Jk({className:s},Cs(i),{ref:e}),n)}),CX=M.createContext(null),xke=()=>M.useContext(CX);function tr(t){return function(){return t}}const NX=Math.cos,gw=Math.sin,zo=Math.sqrt,xw=Math.PI,eE=2*xw,eP=Math.PI,tP=2*eP,Xd=1e-6,bke=tP-Xd;function kX(t){this._+=t[0];for(let e=1,n=t.length;e=0))throw new Error(`invalid digits: ${t}`);if(e>15)return kX;const n=10**e;return function(r){this._+=r[0];for(let i=1,s=r.length;iXd)if(!(Math.abs(f*l-u*d)>Xd)||!s)this._append`L${this._x1=e},${this._y1=n}`;else{let m=r-a,x=i-o,y=l*l+u*u,v=m*m+x*x,b=Math.sqrt(y),E=Math.sqrt(g),S=s*Math.tan((eP-Math.acos((y+g-v)/(2*b*E)))/2),A=S/E,T=S/b;Math.abs(A-1)>Xd&&this._append`L${e+A*d},${n+A*f}`,this._append`A${s},${s},0,0,${+(f*m>d*x)},${this._x1=e+T*l},${this._y1=n+T*u}`}}arc(e,n,r,i,s,a){if(e=+e,n=+n,r=+r,a=!!a,r<0)throw new Error(`negative radius: ${r}`);let o=r*Math.cos(i),l=r*Math.sin(i),u=e+o,d=n+l,f=1^a,g=a?i-s:s-i;this._x1===null?this._append`M${u},${d}`:(Math.abs(this._x1-u)>Xd||Math.abs(this._y1-d)>Xd)&&this._append`L${u},${d}`,r&&(g<0&&(g=g%tP+tP),g>bke?this._append`A${r},${r},0,1,${f},${e-o},${n-l}A${r},${r},0,1,${f},${this._x1=u},${this._y1=d}`:g>Xd&&this._append`A${r},${r},0,${+(g>=eP)},${f},${this._x1=e+r*Math.cos(s)},${this._y1=n+r*Math.sin(s)}`)}rect(e,n,r,i){this._append`M${this._x0=this._x1=+e},${this._y0=this._y1=+n}h${r=+r}v${+i}h${-r}Z`}toString(){return this._}}function qD(t){let e=3;return t.digits=function(n){if(!arguments.length)return e;if(n==null)e=null;else{const r=Math.floor(n);if(!(r>=0))throw new RangeError(`invalid digits: ${n}`);e=r}return t},()=>new yke(e)}function KD(t){return typeof t=="object"&&"length"in t?t:Array.from(t)}function PX(t){this._context=t}PX.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;default:this._context.lineTo(t,e);break}}};function tE(t){return new PX(t)}function RX(t){return t[0]}function DX(t){return t[1]}function OX(t,e){var n=tr(!0),r=null,i=tE,s=null,a=qD(o);t=typeof t=="function"?t:t===void 0?RX:tr(t),e=typeof e=="function"?e:e===void 0?DX:tr(e);function o(l){var u,d=(l=KD(l)).length,f,g=!1,m;for(r==null&&(s=i(m=a())),u=0;u<=d;++u)!(u=m;--x)o.point(S[x],A[x]);o.lineEnd(),o.areaEnd()}b&&(S[g]=+t(v,g,f),A[g]=+e(v,g,f),o.point(r?+r(v,g,f):S[g],n?+n(v,g,f):A[g]))}if(E)return o=null,E+""||null}function d(){return OX().defined(i).curve(a).context(s)}return u.x=function(f){return arguments.length?(t=typeof f=="function"?f:tr(+f),r=null,u):t},u.x0=function(f){return arguments.length?(t=typeof f=="function"?f:tr(+f),u):t},u.x1=function(f){return arguments.length?(r=f==null?null:typeof f=="function"?f:tr(+f),u):r},u.y=function(f){return arguments.length?(e=typeof f=="function"?f:tr(+f),n=null,u):e},u.y0=function(f){return arguments.length?(e=typeof f=="function"?f:tr(+f),u):e},u.y1=function(f){return arguments.length?(n=f==null?null:typeof f=="function"?f:tr(+f),u):n},u.lineX0=u.lineY0=function(){return d().x(t).y(e)},u.lineY1=function(){return d().x(t).y(n)},u.lineX1=function(){return d().x(r).y(e)},u.defined=function(f){return arguments.length?(i=typeof f=="function"?f:tr(!!f),u):i},u.curve=function(f){return arguments.length?(a=f,s!=null&&(o=a(s)),u):a},u.context=function(f){return arguments.length?(f==null?s=o=null:o=a(s=f),u):s},u}class jX{constructor(e,n){this._context=e,this._x=n}areaStart(){this._line=0}areaEnd(){this._line=NaN}lineStart(){this._point=0}lineEnd(){(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line}point(e,n){switch(e=+e,n=+n,this._point){case 0:{this._point=1,this._line?this._context.lineTo(e,n):this._context.moveTo(e,n);break}case 1:this._point=2;default:{this._x?this._context.bezierCurveTo(this._x0=(this._x0+e)/2,this._y0,this._x0,n,e,n):this._context.bezierCurveTo(this._x0,this._y0=(this._y0+n)/2,e,this._y0,e,n);break}}this._x0=e,this._y0=n}}function _ke(t){return new jX(t,!0)}function wke(t){return new jX(t,!1)}const XD={draw(t,e){const n=zo(e/xw);t.moveTo(n,0),t.arc(0,0,n,0,eE)}},Ske={draw(t,e){const n=zo(e/5)/2;t.moveTo(-3*n,-n),t.lineTo(-n,-n),t.lineTo(-n,-3*n),t.lineTo(n,-3*n),t.lineTo(n,-n),t.lineTo(3*n,-n),t.lineTo(3*n,n),t.lineTo(n,n),t.lineTo(n,3*n),t.lineTo(-n,3*n),t.lineTo(-n,n),t.lineTo(-3*n,n),t.closePath()}},LX=zo(1/3),Eke=LX*2,Mke={draw(t,e){const n=zo(e/Eke),r=n*LX;t.moveTo(0,-n),t.lineTo(r,0),t.lineTo(0,n),t.lineTo(-r,0),t.closePath()}},Ake={draw(t,e){const n=zo(e),r=-n/2;t.rect(r,r,n,n)}},Tke=.8908130915292852,IX=gw(xw/10)/gw(7*xw/10),Cke=gw(eE/10)*IX,Nke=-NX(eE/10)*IX,kke={draw(t,e){const n=zo(e*Tke),r=Cke*n,i=Nke*n;t.moveTo(0,-n),t.lineTo(r,i);for(let s=1;s<5;++s){const a=eE*s/5,o=NX(a),l=gw(a);t.lineTo(l*n,-o*n),t.lineTo(o*r-l*i,l*r+o*i)}t.closePath()}},cC=zo(3),Pke={draw(t,e){const n=-zo(e/(cC*3));t.moveTo(0,n*2),t.lineTo(-cC*n,-n),t.lineTo(cC*n,-n),t.closePath()}},Oa=-.5,ja=zo(3)/2,nP=1/zo(12),Rke=(nP/2+1)*3,Dke={draw(t,e){const n=zo(e/Rke),r=n/2,i=n*nP,s=r,a=n*nP+n,o=-s,l=a;t.moveTo(r,i),t.lineTo(s,a),t.lineTo(o,l),t.lineTo(Oa*r-ja*i,ja*r+Oa*i),t.lineTo(Oa*s-ja*a,ja*s+Oa*a),t.lineTo(Oa*o-ja*l,ja*o+Oa*l),t.lineTo(Oa*r+ja*i,Oa*i-ja*r),t.lineTo(Oa*s+ja*a,Oa*a-ja*s),t.lineTo(Oa*o+ja*l,Oa*l-ja*o),t.closePath()}};function Oke(t,e){let n=null,r=qD(i);t=typeof t=="function"?t:tr(t||XD),e=typeof e=="function"?e:tr(e===void 0?64:+e);function i(){let s;if(n||(n=s=r()),t.apply(this,arguments).draw(n,+e.apply(this,arguments)),s)return n=null,s+""||null}return i.type=function(s){return arguments.length?(t=typeof s=="function"?s:tr(s),i):t},i.size=function(s){return arguments.length?(e=typeof s=="function"?s:tr(+s),i):e},i.context=function(s){return arguments.length?(n=s??null,i):n},i}function bw(){}function vw(t,e,n){t._context.bezierCurveTo((2*t._x0+t._x1)/3,(2*t._y0+t._y1)/3,(t._x0+2*t._x1)/3,(t._y0+2*t._y1)/3,(t._x0+4*t._x1+e)/6,(t._y0+4*t._y1+n)/6)}function UX(t){this._context=t}UX.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._point=0},lineEnd:function(){switch(this._point){case 3:vw(this,this._x1,this._y1);case 2:this._context.lineTo(this._x1,this._y1);break}(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;break;case 2:this._point=3,this._context.lineTo((5*this._x0+this._x1)/6,(5*this._y0+this._y1)/6);default:vw(this,t,e);break}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=e}};function jke(t){return new UX(t)}function FX(t){this._context=t}FX.prototype={areaStart:bw,areaEnd:bw,lineStart:function(){this._x0=this._x1=this._x2=this._x3=this._x4=this._y0=this._y1=this._y2=this._y3=this._y4=NaN,this._point=0},lineEnd:function(){switch(this._point){case 1:{this._context.moveTo(this._x2,this._y2),this._context.closePath();break}case 2:{this._context.moveTo((this._x2+2*this._x3)/3,(this._y2+2*this._y3)/3),this._context.lineTo((this._x3+2*this._x2)/3,(this._y3+2*this._y2)/3),this._context.closePath();break}case 3:{this.point(this._x2,this._y2),this.point(this._x3,this._y3),this.point(this._x4,this._y4);break}}},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._x2=t,this._y2=e;break;case 1:this._point=2,this._x3=t,this._y3=e;break;case 2:this._point=3,this._x4=t,this._y4=e,this._context.moveTo((this._x0+4*this._x1+t)/6,(this._y0+4*this._y1+e)/6);break;default:vw(this,t,e);break}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=e}};function Lke(t){return new FX(t)}function zX(t){this._context=t}zX.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._point=0},lineEnd:function(){(this._line||this._line!==0&&this._point===3)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1;break;case 1:this._point=2;break;case 2:this._point=3;var n=(this._x0+4*this._x1+t)/6,r=(this._y0+4*this._y1+e)/6;this._line?this._context.lineTo(n,r):this._context.moveTo(n,r);break;case 3:this._point=4;default:vw(this,t,e);break}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=e}};function Ike(t){return new zX(t)}function BX(t){this._context=t}BX.prototype={areaStart:bw,areaEnd:bw,lineStart:function(){this._point=0},lineEnd:function(){this._point&&this._context.closePath()},point:function(t,e){t=+t,e=+e,this._point?this._context.lineTo(t,e):(this._point=1,this._context.moveTo(t,e))}};function Uke(t){return new BX(t)}function v8(t){return t<0?-1:1}function y8(t,e,n){var r=t._x1-t._x0,i=e-t._x1,s=(t._y1-t._y0)/(r||i<0&&-0),a=(n-t._y1)/(i||r<0&&-0),o=(s*i+a*r)/(r+i);return(v8(s)+v8(a))*Math.min(Math.abs(s),Math.abs(a),.5*Math.abs(o))||0}function _8(t,e){var n=t._x1-t._x0;return n?(3*(t._y1-t._y0)/n-e)/2:e}function uC(t,e,n){var r=t._x0,i=t._y0,s=t._x1,a=t._y1,o=(s-r)/3;t._context.bezierCurveTo(r+o,i+o*e,s-o,a-o*n,s,a)}function yw(t){this._context=t}yw.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=this._t0=NaN,this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x1,this._y1);break;case 3:uC(this,this._t0,_8(this,this._t0));break}(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){var n=NaN;if(t=+t,e=+e,!(t===this._x1&&e===this._y1)){switch(this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;break;case 2:this._point=3,uC(this,_8(this,n=y8(this,t,e)),n);break;default:uC(this,this._t0,n=y8(this,t,e));break}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=e,this._t0=n}}};function HX(t){this._context=new $X(t)}(HX.prototype=Object.create(yw.prototype)).point=function(t,e){yw.prototype.point.call(this,e,t)};function $X(t){this._context=t}$X.prototype={moveTo:function(t,e){this._context.moveTo(e,t)},closePath:function(){this._context.closePath()},lineTo:function(t,e){this._context.lineTo(e,t)},bezierCurveTo:function(t,e,n,r,i,s){this._context.bezierCurveTo(e,t,r,n,s,i)}};function Fke(t){return new yw(t)}function zke(t){return new HX(t)}function VX(t){this._context=t}VX.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x=[],this._y=[]},lineEnd:function(){var t=this._x,e=this._y,n=t.length;if(n)if(this._line?this._context.lineTo(t[0],e[0]):this._context.moveTo(t[0],e[0]),n===2)this._context.lineTo(t[1],e[1]);else for(var r=w8(t),i=w8(e),s=0,a=1;a=0;--e)i[e]=(a[e]-i[e+1])/s[e];for(s[n-1]=(t[n]+i[n-1])/2,e=0;e=0&&(this._t=1-this._t,this._line=1-this._line)},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;default:{if(this._t<=0)this._context.lineTo(this._x,e),this._context.lineTo(t,e);else{var n=this._x*(1-this._t)+t*this._t;this._context.lineTo(n,this._y),this._context.lineTo(n,e)}break}}this._x=t,this._y=e}};function Hke(t){return new nE(t,.5)}function $ke(t){return new nE(t,0)}function Vke(t){return new nE(t,1)}function Em(t,e){if((a=t.length)>1)for(var n=1,r,i,s=t[e[0]],a,o=s.length;n=0;)n[e]=e;return n}function Gke(t,e){return t[e]}function Wke(t){const e=[];return e.key=t,e}function qke(){var t=tr([]),e=rP,n=Em,r=Gke;function i(s){var a=Array.from(t.apply(this,arguments),Wke),o,l=a.length,u=-1,d;for(const f of s)for(o=0,++u;o0){for(var n,r,i=0,s=t[0].length,a;i0){for(var n=0,r=t[e[0]],i,s=r.length;n0)||!((s=(i=t[e[0]]).length)>0))){for(var n=0,r=1,i,s,a;rt===0?0:t>0?1:-1,io=t=>typeof t=="number"&&t!=+t,wc=t=>typeof t=="string"&&t.indexOf("%")===t.length-1,Ct=t=>(typeof t=="number"||t instanceof Number)&&!io(t),fl=t=>Ct(t)||typeof t=="string",tPe=0,U0=t=>{var e=++tPe;return"".concat(t||"").concat(e)},hs=function(e,n){var r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:0,i=arguments.length>3&&arguments[3]!==void 0?arguments[3]:!1;if(!Ct(e)&&typeof e!="string")return r;var s;if(wc(e)){if(n==null)return r;var a=e.indexOf("%");s=n*parseFloat(e.slice(0,a))/100}else s=+e;return io(s)&&(s=r),i&&n!=null&&s>n&&(s=n),s},WX=t=>{if(!Array.isArray(t))return!1;for(var e=t.length,n={},r=0;rr&&(typeof e=="function"?e(r):Kh(r,e))===n)}var yr=t=>t===null||typeof t>"u",mb=t=>yr(t)?t:"".concat(t.charAt(0).toUpperCase()).concat(t.slice(1));function nPe(t){return t!=null}function gb(){}var rPe=["type","size","sizeType"];function iP(){return iP=Object.assign?Object.assign.bind():function(t){for(var e=1;e{var e="symbol".concat(mb(t));return KX[e]||XD},dPe=(t,e,n)=>{if(e==="area")return t;switch(n){case"cross":return 5*t*t/9;case"diamond":return .5*t*t/Math.sqrt(3);case"square":return t*t;case"star":{var r=18*cPe;return 1.25*t*t*(Math.tan(r)-Math.tan(r*2)*Math.tan(r)**2)}case"triangle":return Math.sqrt(3)*t*t/4;case"wye":return(21-10*Math.sqrt(3))*t*t/8;default:return Math.PI*t*t/4}},hPe=(t,e)=>{KX["symbol".concat(mb(t))]=e},JD=t=>{var{type:e="circle",size:n=64,sizeType:r="area"}=t,i=oPe(t,rPe),s=P8(P8({},i),{},{type:e,size:n,sizeType:r}),a="circle";typeof e=="string"&&(a=e);var o=()=>{var g=uPe(a),m=Oke().type(g).size(dPe(n,r,a)),x=m();if(x!==null)return x},{className:l,cx:u,cy:d}=s,f=Cs(s);return Ct(u)&&Ct(d)&&Ct(n)?M.createElement("path",iP({},f,{className:Tn("recharts-symbols",l),transform:"translate(".concat(u,", ").concat(d,")"),d:o()})):null};JD.registerSymbol=hPe;var XX=t=>"radius"in t&&"startAngle"in t&&"endAngle"in t,eO=(t,e)=>{if(!t||typeof t=="function"||typeof t=="boolean")return null;var n=t;if(M.isValidElement(t)&&(n=t.props),typeof n!="object"&&typeof n!="function")return null;var r={};return Object.keys(n).forEach(i=>{GD(i)&&(r[i]=(s=>n[i](n,s)))}),r},fPe=(t,e,n)=>r=>(t(e,n,r),null),xb=(t,e,n)=>{if(t===null||typeof t!="object"&&typeof t!="function")return null;var r=null;return Object.keys(t).forEach(i=>{var s=t[i];GD(i)&&typeof s=="function"&&(r||(r={}),r[i]=fPe(s,e,n))}),r};function R8(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function pPe(t){for(var e=1;e(a[o]===void 0&&r[o]!==void 0&&(a[o]=r[o]),a),n);return s}function _w(){return _w=Object.assign?Object.assign.bind():function(t){for(var e=1;e{var g=d.formatter||i,m=Tn({"recharts-legend-item":!0,["legend-item-".concat(f)]:!0,inactive:d.inactive});if(d.type==="none")return null;var x=d.inactive?s:d.color,y=g?g(d.value,d,f):d.value;return M.createElement("li",_w({className:m,style:l,key:"legend-item-".concat(f)},xb(t,d,f)),M.createElement(WD,{width:n,height:n,viewBox:o,style:u,"aria-label":"".concat(y," legend icon")},M.createElement(SPe,{data:d,iconType:a,inactiveColor:s})),M.createElement("span",{className:"recharts-legend-item-text",style:{color:x}},y))})}var MPe=t=>{var e=ii(t,wPe),{payload:n,layout:r,align:i}=e;if(!n||!n.length)return null;var s={padding:0,margin:0,textAlign:r==="horizontal"?i:"left"};return M.createElement("ul",{className:"recharts-default-legend",style:s},M.createElement(EPe,_w({},e,{payload:n})))},bC={},vC={},O8;function APe(){return O8||(O8=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});function e(n,r){const i=new Map;for(let s=0;s=0}t.isLength=e})(SC)),SC}var I8;function tO(){return I8||(I8=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});const e=TPe();function n(r){return r!=null&&typeof r!="function"&&e.isLength(r.length)}t.isArrayLike=n})(wC)),wC}var EC={},U8;function CPe(){return U8||(U8=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});function e(n){return typeof n=="object"&&n!==null}t.isObjectLike=e})(EC)),EC}var F8;function NPe(){return F8||(F8=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});const e=tO(),n=CPe();function r(i){return n.isObjectLike(i)&&e.isArrayLike(i)}t.isArrayLikeObject=r})(_C)),_C}var MC={},AC={},z8;function kPe(){return z8||(z8=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});const e=QD();function n(r){return function(i){return e.get(i,r)}}t.property=n})(AC)),AC}var TC={},CC={},NC={},kC={},B8;function ZX(){return B8||(B8=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});function e(n){return n!==null&&(typeof n=="object"||typeof n=="function")}t.isObject=e})(kC)),kC}var PC={},H8;function QX(){return H8||(H8=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});function e(n){return n==null||typeof n!="object"&&typeof n!="function"}t.isPrimitive=e})(PC)),PC}var RC={},$8;function JX(){return $8||($8=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});function e(n,r){return n===r||Number.isNaN(n)&&Number.isNaN(r)}t.eq=e})(RC)),RC}var V8;function PPe(){return V8||(V8=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});const e=ZX(),n=QX(),r=JX();function i(d,f,g){return typeof g!="function"?i(d,f,()=>{}):s(d,f,function m(x,y,v,b,E,S){const A=g(x,y,v,b,E,S);return A!==void 0?!!A:s(x,y,m,S)},new Map)}function s(d,f,g,m){if(f===d)return!0;switch(typeof f){case"object":return a(d,f,g,m);case"function":return Object.keys(f).length>0?s(d,{...f},g,m):r.eq(d,f);default:return e.isObject(d)?typeof f=="string"?f==="":!0:r.eq(d,f)}}function a(d,f,g,m){if(f==null)return!0;if(Array.isArray(f))return l(d,f,g,m);if(f instanceof Map)return o(d,f,g,m);if(f instanceof Set)return u(d,f,g,m);const x=Object.keys(f);if(d==null)return x.length===0;if(x.length===0)return!0;if(m?.has(f))return m.get(f)===d;m?.set(f,d);try{for(let y=0;y{})}t.isMatch=n})(CC)),CC}var DC={},OC={},jC={},W8;function RPe(){return W8||(W8=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});function e(n){return Object.getOwnPropertySymbols(n).filter(r=>Object.prototype.propertyIsEnumerable.call(n,r))}t.getSymbols=e})(jC)),jC}var LC={},q8;function tY(){return q8||(q8=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});function e(n){return n==null?n===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(n)}t.getTag=e})(LC)),LC}var IC={},K8;function nY(){return K8||(K8=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});const e="[object RegExp]",n="[object String]",r="[object Number]",i="[object Boolean]",s="[object Arguments]",a="[object Symbol]",o="[object Date]",l="[object Map]",u="[object Set]",d="[object Array]",f="[object Function]",g="[object ArrayBuffer]",m="[object Object]",x="[object Error]",y="[object DataView]",v="[object Uint8Array]",b="[object Uint8ClampedArray]",E="[object Uint16Array]",S="[object Uint32Array]",A="[object BigUint64Array]",T="[object Int8Array]",P="[object Int16Array]",C="[object Int32Array]",I="[object BigInt64Array]",N="[object Float32Array]",D="[object Float64Array]";t.argumentsTag=s,t.arrayBufferTag=g,t.arrayTag=d,t.bigInt64ArrayTag=I,t.bigUint64ArrayTag=A,t.booleanTag=i,t.dataViewTag=y,t.dateTag=o,t.errorTag=x,t.float32ArrayTag=N,t.float64ArrayTag=D,t.functionTag=f,t.int16ArrayTag=P,t.int32ArrayTag=C,t.int8ArrayTag=T,t.mapTag=l,t.numberTag=r,t.objectTag=m,t.regexpTag=e,t.setTag=u,t.stringTag=n,t.symbolTag=a,t.uint16ArrayTag=E,t.uint32ArrayTag=S,t.uint8ArrayTag=v,t.uint8ClampedArrayTag=b})(IC)),IC}var UC={},X8;function DPe(){return X8||(X8=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});function e(n){return ArrayBuffer.isView(n)&&!(n instanceof DataView)}t.isTypedArray=e})(UC)),UC}var Y8;function rY(){return Y8||(Y8=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});const e=RPe(),n=tY(),r=nY(),i=QX(),s=DPe();function a(d,f){return o(d,void 0,d,new Map,f)}function o(d,f,g,m=new Map,x=void 0){const y=x?.(d,f,g,m);if(y!==void 0)return y;if(i.isPrimitive(d))return d;if(m.has(d))return m.get(d);if(Array.isArray(d)){const v=new Array(d.length);m.set(d,v);for(let b=0;be.isMatch(s,i)}t.matches=r})(TC)),TC}var FC={},zC={},BC={},J8;function LPe(){return J8||(J8=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});const e=rY(),n=nY();function r(i,s){return e.cloneDeepWith(i,(a,o,l,u)=>{const d=s?.(a,o,l,u);if(d!==void 0)return d;if(typeof i=="object")switch(Object.prototype.toString.call(i)){case n.numberTag:case n.stringTag:case n.booleanTag:{const f=new i.constructor(i?.valueOf());return e.copyProperties(f,i),f}case n.argumentsTag:{const f={};return e.copyProperties(f,i),f.length=i.length,f[Symbol.iterator]=i[Symbol.iterator],f}default:return}})}t.cloneDeepWith=r})(BC)),BC}var eH;function IPe(){return eH||(eH=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});const e=LPe();function n(r){return e.cloneDeepWith(r)}t.cloneDeep=n})(zC)),zC}var HC={},$C={},tH;function iY(){return tH||(tH=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});const e=/^(?:0|[1-9]\d*)$/;function n(r,i=Number.MAX_SAFE_INTEGER){switch(typeof r){case"number":return Number.isInteger(r)&&r>=0&&rt,rr=()=>{var t=M.useContext(nO);return t?t.store.dispatch:GPe},Y_=()=>{},WPe=()=>Y_,qPe=(t,e)=>t===e;function kt(t){var e=M.useContext(nO);return vK.useSyncExternalStoreWithSelector(e?e.subscription.addNestedSub:WPe,e?e.store.getState:Y_,e?e.store.getState:Y_,e?t:Y_,qPe)}function KPe(t,e=`expected a function, instead received ${typeof t}`){if(typeof t!="function")throw new TypeError(e)}function XPe(t,e=`expected an object, instead received ${typeof t}`){if(typeof t!="object")throw new TypeError(e)}function YPe(t,e="expected all items to be functions, instead received the following types: "){if(!t.every(n=>typeof n=="function")){const n=t.map(r=>typeof r=="function"?`function ${r.name||"unnamed"}()`:typeof r).join(", ");throw new TypeError(`${e}[${n}]`)}}var cH=t=>Array.isArray(t)?t:[t];function ZPe(t){const e=Array.isArray(t[0])?t[0]:t;return YPe(e,"createSelector expects all input-selectors to be functions, but received the following types: "),e}function QPe(t,e){const n=[],{length:r}=t;for(let i=0;i{n=p_(),a.resetResultsCount()},a.resultsCount=()=>s,a.resetResultsCount=()=>{s=0},a}function nRe(t,...e){const n=typeof t=="function"?{memoize:t,memoizeOptions:e}:t,r=(...i)=>{let s=0,a=0,o,l={},u=i.pop();typeof u=="object"&&(l=u,u=i.pop()),KPe(u,`createSelector expects an output function after the inputs, but received: [${typeof u}]`);const d={...n,...l},{memoize:f,memoizeOptions:g=[],argsMemoize:m=aY,argsMemoizeOptions:x=[]}=d,y=cH(g),v=cH(x),b=ZPe(i),E=f(function(){return s++,u.apply(null,arguments)},...y),S=m(function(){a++;const T=QPe(b,arguments);return o=E.apply(null,T),o},...v);return Object.assign(S,{resultFunc:u,memoizedResultFunc:E,dependencies:b,dependencyRecomputations:()=>a,resetDependencyRecomputations:()=>{a=0},lastResult:()=>o,recomputations:()=>s,resetRecomputations:()=>{s=0},memoize:f,argsMemoize:m})};return Object.assign(r,{withTypes:()=>r}),r}var Ke=nRe(aY),rRe=Object.assign((t,e=Ke)=>{XPe(t,`createStructuredSelector expects first argument to be an object where each property is a selector, instead received a ${typeof t}`);const n=Object.keys(t),r=n.map(s=>t[s]);return e(r,(...s)=>s.reduce((a,o,l)=>(a[n[l]]=o,a),{}))},{withTypes:()=>rRe}),WC={},qC={},KC={},dH;function iRe(){return dH||(dH=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});function e(r){return typeof r=="symbol"?1:r===null?2:r===void 0?3:r!==r?4:0}const n=(r,i,s)=>{if(r!==i){const a=e(r),o=e(i);if(a===o&&a===0){if(ri)return s==="desc"?-1:1}return s==="desc"?o-a:a-o}return 0};t.compareValues=n})(KC)),KC}var XC={},YC={},hH;function oY(){return hH||(hH=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});function e(n){return typeof n=="symbol"||n instanceof Symbol}t.isSymbol=e})(YC)),YC}var fH;function sRe(){return fH||(fH=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});const e=oY(),n=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,r=/^\w*$/;function i(s,a){return Array.isArray(s)?!1:typeof s=="number"||typeof s=="boolean"||s==null||e.isSymbol(s)?!0:typeof s=="string"&&(r.test(s)||!n.test(s))||a!=null&&Object.hasOwn(a,s)}t.isKey=i})(XC)),XC}var pH;function aRe(){return pH||(pH=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});const e=iRe(),n=sRe(),r=ZD();function i(s,a,o,l){if(s==null)return[];o=l?void 0:o,Array.isArray(s)||(s=Object.values(s)),Array.isArray(a)||(a=a==null?[null]:[a]),a.length===0&&(a=[null]),Array.isArray(o)||(o=o==null?[]:[o]),o=o.map(m=>String(m));const u=(m,x)=>{let y=m;for(let v=0;vx==null||m==null?x:typeof m=="object"&&"key"in m?Object.hasOwn(x,m.key)?x[m.key]:u(x,m.path):typeof m=="function"?m(x):Array.isArray(m)?u(x,m):typeof x=="object"?x[m]:x,f=a.map(m=>(Array.isArray(m)&&m.length===1&&(m=m[0]),m==null||typeof m=="function"||Array.isArray(m)||n.isKey(m)?m:{key:m,path:r.toPath(m)}));return s.map(m=>({original:m,criteria:f.map(x=>d(x,m))})).slice().sort((m,x)=>{for(let y=0;ym.original)}t.orderBy=i})(qC)),qC}var ZC={},mH;function oRe(){return mH||(mH=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});function e(n,r=1){const i=[],s=Math.floor(r),a=(o,l)=>{for(let u=0;u1&&r.isIterateeCall(s,a[0],a[1])?a=[]:o>2&&r.isIterateeCall(a[0],a[1],a[2])&&(a=[a[0]]),e.orderBy(s,n.flatten(a),["asc"])}t.sortBy=i})(WC)),WC}var JC,bH;function cRe(){return bH||(bH=1,JC=lRe().sortBy),JC}var uRe=cRe();const rE=oo(uRe);var cY=t=>t.legend.settings,dRe=t=>t.legend.size,hRe=t=>t.legend.payload,fRe=Ke([hRe,cY],(t,e)=>{var{itemSorter:n}=e,r=t.flat(1);return n?rE(r,n):r});function pRe(){return kt(fRe)}var m_=1;function uY(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],[e,n]=M.useState({height:0,left:0,top:0,width:0}),r=M.useCallback(i=>{if(i!=null){var s=i.getBoundingClientRect(),a={height:s.height,left:s.left,top:s.top,width:s.width};(Math.abs(a.height-e.height)>m_||Math.abs(a.left-e.left)>m_||Math.abs(a.top-e.top)>m_||Math.abs(a.width-e.width)>m_)&&n({height:a.height,left:a.left,top:a.top,width:a.width})}},[e.width,e.height,e.top,e.left,...t]);return[e,r]}function Wi(t){return`Minified Redux error #${t}; visit https://redux.js.org/Errors?code=${t} for the full message or use the non-minified dev environment for full errors. `}var mRe=typeof Symbol=="function"&&Symbol.observable||"@@observable",vH=mRe,eN=()=>Math.random().toString(36).substring(7).split("").join("."),gRe={INIT:`@@redux/INIT${eN()}`,REPLACE:`@@redux/REPLACE${eN()}`,PROBE_UNKNOWN_ACTION:()=>`@@redux/PROBE_UNKNOWN_ACTION${eN()}`},ww=gRe;function rO(t){if(typeof t!="object"||t===null)return!1;let e=t;for(;Object.getPrototypeOf(e)!==null;)e=Object.getPrototypeOf(e);return Object.getPrototypeOf(t)===e||Object.getPrototypeOf(t)===null}function dY(t,e,n){if(typeof t!="function")throw new Error(Wi(2));if(typeof e=="function"&&typeof n=="function"||typeof n=="function"&&typeof arguments[3]=="function")throw new Error(Wi(0));if(typeof e=="function"&&typeof n>"u"&&(n=e,e=void 0),typeof n<"u"){if(typeof n!="function")throw new Error(Wi(1));return n(dY)(t,e)}let r=t,i=e,s=new Map,a=s,o=0,l=!1;function u(){a===s&&(a=new Map,s.forEach((v,b)=>{a.set(b,v)}))}function d(){if(l)throw new Error(Wi(3));return i}function f(v){if(typeof v!="function")throw new Error(Wi(4));if(l)throw new Error(Wi(5));let b=!0;u();const E=o++;return a.set(E,v),function(){if(b){if(l)throw new Error(Wi(6));b=!1,u(),a.delete(E),s=null}}}function g(v){if(!rO(v))throw new Error(Wi(7));if(typeof v.type>"u")throw new Error(Wi(8));if(typeof v.type!="string")throw new Error(Wi(17));if(l)throw new Error(Wi(9));try{l=!0,i=r(i,v)}finally{l=!1}return(s=a).forEach(E=>{E()}),v}function m(v){if(typeof v!="function")throw new Error(Wi(10));r=v,g({type:ww.REPLACE})}function x(){const v=f;return{subscribe(b){if(typeof b!="object"||b===null)throw new Error(Wi(11));function E(){const A=b;A.next&&A.next(d())}return E(),{unsubscribe:v(E)}},[vH](){return this}}}return g({type:ww.INIT}),{dispatch:g,subscribe:f,getState:d,replaceReducer:m,[vH]:x}}function xRe(t){Object.keys(t).forEach(e=>{const n=t[e];if(typeof n(void 0,{type:ww.INIT})>"u")throw new Error(Wi(12));if(typeof n(void 0,{type:ww.PROBE_UNKNOWN_ACTION()})>"u")throw new Error(Wi(13))})}function hY(t){const e=Object.keys(t),n={};for(let s=0;s"u")throw o&&o.type,new Error(Wi(14));u[f]=x,l=l||x!==m}return l=l||r.length!==Object.keys(a).length,l?u:a}}function Sw(...t){return t.length===0?e=>e:t.length===1?t[0]:t.reduce((e,n)=>(...r)=>e(n(...r)))}function bRe(...t){return e=>(n,r)=>{const i=e(n,r);let s=()=>{throw new Error(Wi(15))};const a={getState:i.getState,dispatch:(l,...u)=>s(l,...u)},o=t.map(l=>l(a));return s=Sw(...o)(i.dispatch),{...i,dispatch:s}}}function fY(t){return rO(t)&&"type"in t&&typeof t.type=="string"}var pY=Symbol.for("immer-nothing"),yH=Symbol.for("immer-draftable"),Ns=Symbol.for("immer-state");function Eo(t,...e){throw new Error(`[Immer] minified error nr: ${t}. Full error at: https://bit.ly/3cXEKWf`)}var pa=Object,Mm=pa.getPrototypeOf,Ew="constructor",iE="prototype",sP="configurable",Mw="enumerable",Z_="writable",F0="value",Sc=t=>!!t&&!!t[Ns];function Io(t){return t?mY(t)||sE(t)||!!t[yH]||!!t[Ew]?.[yH]||aE(t)||oE(t):!1}var vRe=pa[iE][Ew].toString(),_H=new WeakMap;function mY(t){if(!t||!iO(t))return!1;const e=Mm(t);if(e===null||e===pa[iE])return!0;const n=pa.hasOwnProperty.call(e,Ew)&&e[Ew];if(n===Object)return!0;if(!Dp(n))return!1;let r=_H.get(n);return r===void 0&&(r=Function.toString.call(n),_H.set(n,r)),r===vRe}function bb(t,e,n=!0){vb(t)===0?(n?Reflect.ownKeys(t):pa.keys(t)).forEach(i=>{e(i,t[i],t)}):t.forEach((r,i)=>e(i,r,t))}function vb(t){const e=t[Ns];return e?e.type_:sE(t)?1:aE(t)?2:oE(t)?3:0}var wH=(t,e,n=vb(t))=>n===2?t.has(e):pa[iE].hasOwnProperty.call(t,e),aP=(t,e,n=vb(t))=>n===2?t.get(e):t[e],Aw=(t,e,n,r=vb(t))=>{r===2?t.set(e,n):r===3?t.add(n):t[e]=n};function yRe(t,e){return t===e?t!==0||1/t===1/e:t!==t&&e!==e}var sE=Array.isArray,aE=t=>t instanceof Map,oE=t=>t instanceof Set,iO=t=>typeof t=="object",Dp=t=>typeof t=="function",tN=t=>typeof t=="boolean",ec=t=>t.copy_||t.base_,sO=t=>t.modified_?t.copy_:t.base_;function oP(t,e){if(aE(t))return new Map(t);if(oE(t))return new Set(t);if(sE(t))return Array[iE].slice.call(t);const n=mY(t);if(e===!0||e==="class_only"&&!n){const r=pa.getOwnPropertyDescriptors(t);delete r[Ns];let i=Reflect.ownKeys(r);for(let s=0;s1&&pa.defineProperties(t,{set:g_,add:g_,clear:g_,delete:g_}),pa.freeze(t),e&&bb(t,(n,r)=>{aO(r,!0)},!1)),t}function _Re(){Eo(2)}var g_={[F0]:_Re};function lE(t){return t===null||!iO(t)?!0:pa.isFrozen(t)}var Tw="MapSet",lP="Patches",gY={};function Am(t){const e=gY[t];return e||Eo(0,t),e}var wRe=t=>!!gY[t],z0,xY=()=>z0,SRe=(t,e)=>({drafts_:[],parent_:t,immer_:e,canAutoFreeze_:!0,unfinalizedDrafts_:0,handledSet_:new Set,processedForPatches_:new Set,mapSetPlugin_:wRe(Tw)?Am(Tw):void 0});function SH(t,e){e&&(t.patchPlugin_=Am(lP),t.patches_=[],t.inversePatches_=[],t.patchListener_=e)}function cP(t){uP(t),t.drafts_.forEach(ERe),t.drafts_=null}function uP(t){t===z0&&(z0=t.parent_)}var EH=t=>z0=SRe(z0,t);function ERe(t){const e=t[Ns];e.type_===0||e.type_===1?e.revoke_():e.revoked_=!0}function MH(t,e){e.unfinalizedDrafts_=e.drafts_.length;const n=e.drafts_[0];if(t!==void 0&&t!==n){n[Ns].modified_&&(cP(e),Eo(4)),Io(t)&&(t=AH(e,t));const{patchPlugin_:i}=e;i&&i.generateReplacementPatches_(n[Ns].base_,t,e)}else t=AH(e,n);return MRe(e,t,!0),cP(e),e.patches_&&e.patchListener_(e.patches_,e.inversePatches_),t!==pY?t:void 0}function AH(t,e){if(lE(e))return e;const n=e[Ns];if(!n)return oO(e,t.handledSet_,t);if(!cE(n,t))return e;if(!n.modified_)return n.base_;if(!n.finalized_){const{callbacks_:r}=n;if(r)for(;r.length>0;)r.pop()(t);yY(n,t)}return n.copy_}function MRe(t,e,n=!1){!t.parent_&&t.immer_.autoFreeze_&&t.canAutoFreeze_&&aO(e,n)}function bY(t){t.finalized_=!0,t.scope_.unfinalizedDrafts_--}var cE=(t,e)=>t.scope_===e,ARe=[];function vY(t,e,n,r){const i=ec(t),s=t.type_;if(r!==void 0&&aP(i,r,s)===e){Aw(i,r,n,s);return}if(!t.draftLocations_){const o=t.draftLocations_=new Map;bb(i,(l,u)=>{if(Sc(u)){const d=o.get(u)||[];d.push(l),o.set(u,d)}})}const a=t.draftLocations_.get(e)??ARe;for(const o of a)Aw(i,o,n,s)}function TRe(t,e,n){t.callbacks_.push(function(i){const s=e;if(!s||!cE(s,i))return;i.mapSetPlugin_?.fixSetContents(s);const a=sO(s);vY(t,s.draft_??s,a,n),yY(s,i)})}function yY(t,e){if(t.modified_&&!t.finalized_&&(t.type_===3||(t.assigned_?.size??0)>0)){const{patchPlugin_:r}=e;if(r){const i=r.getPath(t);i&&r.generatePatches_(t,i,e)}bY(t)}}function CRe(t,e,n){const{scope_:r}=t;if(Sc(n)){const i=n[Ns];cE(i,r)&&i.callbacks_.push(function(){Q_(t);const a=sO(i);vY(t,n,a,e)})}else Io(n)&&t.callbacks_.push(function(){const s=ec(t);aP(s,e,t.type_)===n&&r.drafts_.length>1&&(t.assigned_.get(e)??!1)===!0&&t.copy_&&oO(aP(t.copy_,e,t.type_),r.handledSet_,r)})}function oO(t,e,n){return!n.immer_.autoFreeze_&&n.unfinalizedDrafts_<1||Sc(t)||e.has(t)||!Io(t)||lE(t)||(e.add(t),bb(t,(r,i)=>{if(Sc(i)){const s=i[Ns];if(cE(s,n)){const a=sO(s);Aw(t,r,a,t.type_),bY(s)}}else Io(i)&&oO(i,e,n)})),t}function NRe(t,e){const n=sE(t),r={type_:n?1:0,scope_:e?e.scope_:xY(),modified_:!1,finalized_:!1,assigned_:void 0,parent_:e,base_:t,draft_:null,copy_:null,revoke_:null,isManual_:!1,callbacks_:void 0};let i=r,s=lO;n&&(i=[r],s=B0);const{revoke:a,proxy:o}=Proxy.revocable(i,s);return r.draft_=o,r.revoke_=a,[o,r]}var lO={get(t,e){if(e===Ns)return t;const n=ec(t);if(!wH(n,e,t.type_))return kRe(t,n,e);const r=n[e];if(t.finalized_||!Io(r))return r;if(r===nN(t.base_,e)){Q_(t);const i=t.type_===1?+e:e,s=hP(t.scope_,r,t,i);return t.copy_[i]=s}return r},has(t,e){return e in ec(t)},ownKeys(t){return Reflect.ownKeys(ec(t))},set(t,e,n){const r=_Y(ec(t),e);if(r?.set)return r.set.call(t.draft_,n),!0;if(!t.modified_){const i=nN(ec(t),e),s=i?.[Ns];if(s&&s.base_===n)return t.copy_[e]=n,t.assigned_.set(e,!1),!0;if(yRe(n,i)&&(n!==void 0||wH(t.base_,e,t.type_)))return!0;Q_(t),dP(t)}return t.copy_[e]===n&&(n!==void 0||e in t.copy_)||Number.isNaN(n)&&Number.isNaN(t.copy_[e])||(t.copy_[e]=n,t.assigned_.set(e,!0),CRe(t,e,n)),!0},deleteProperty(t,e){return Q_(t),nN(t.base_,e)!==void 0||e in t.base_?(t.assigned_.set(e,!1),dP(t)):t.assigned_.delete(e),t.copy_&&delete t.copy_[e],!0},getOwnPropertyDescriptor(t,e){const n=ec(t),r=Reflect.getOwnPropertyDescriptor(n,e);return r&&{[Z_]:!0,[sP]:t.type_!==1||e!=="length",[Mw]:r[Mw],[F0]:n[e]}},defineProperty(){Eo(11)},getPrototypeOf(t){return Mm(t.base_)},setPrototypeOf(){Eo(12)}},B0={};bb(lO,(t,e)=>{B0[t]=function(){const n=arguments;return n[0]=n[0][0],e.apply(this,n)}});B0.deleteProperty=function(t,e){return B0.set.call(this,t,e,void 0)};B0.set=function(t,e,n){return lO.set.call(this,t[0],e,n,t[0])};function nN(t,e){const n=t[Ns];return(n?ec(n):t)[e]}function kRe(t,e,n){const r=_Y(e,n);return r?F0 in r?r[F0]:r.get?.call(t.draft_):void 0}function _Y(t,e){if(!(e in t))return;let n=Mm(t);for(;n;){const r=Object.getOwnPropertyDescriptor(n,e);if(r)return r;n=Mm(n)}}function dP(t){t.modified_||(t.modified_=!0,t.parent_&&dP(t.parent_))}function Q_(t){t.copy_||(t.assigned_=new Map,t.copy_=oP(t.base_,t.scope_.immer_.useStrictShallowCopy_))}var PRe=class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.useStrictIteration_=!1,this.produce=(n,r,i)=>{if(Dp(n)&&!Dp(r)){const a=r;r=n;const o=this;return function(u=a,...d){return o.produce(u,f=>r.call(this,f,...d))}}Dp(r)||Eo(6),i!==void 0&&!Dp(i)&&Eo(7);let s;if(Io(n)){const a=EH(this),o=hP(a,n,void 0);let l=!0;try{s=r(o),l=!1}finally{l?cP(a):uP(a)}return SH(a,i),MH(s,a)}else if(!n||!iO(n)){if(s=r(n),s===void 0&&(s=n),s===pY&&(s=void 0),this.autoFreeze_&&aO(s,!0),i){const a=[],o=[];Am(lP).generateReplacementPatches_(n,s,{patches_:a,inversePatches_:o}),i(a,o)}return s}else Eo(1,n)},this.produceWithPatches=(n,r)=>{if(Dp(n))return(o,...l)=>this.produceWithPatches(o,u=>n(u,...l));let i,s;return[this.produce(n,r,(o,l)=>{i=o,s=l}),i,s]},tN(e?.autoFreeze)&&this.setAutoFreeze(e.autoFreeze),tN(e?.useStrictShallowCopy)&&this.setUseStrictShallowCopy(e.useStrictShallowCopy),tN(e?.useStrictIteration)&&this.setUseStrictIteration(e.useStrictIteration)}createDraft(e){Io(e)||Eo(8),Sc(e)&&(e=Ro(e));const n=EH(this),r=hP(n,e,void 0);return r[Ns].isManual_=!0,uP(n),r}finishDraft(e,n){const r=e&&e[Ns];(!r||!r.isManual_)&&Eo(9);const{scope_:i}=r;return SH(i,n),MH(void 0,i)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}setUseStrictIteration(e){this.useStrictIteration_=e}shouldUseStrictIteration(){return this.useStrictIteration_}applyPatches(e,n){let r;for(r=n.length-1;r>=0;r--){const s=n[r];if(s.path.length===0&&s.op==="replace"){e=s.value;break}}r>-1&&(n=n.slice(r+1));const i=Am(lP).applyPatches_;return Sc(e)?i(e,n):this.produce(e,s=>i(s,n))}};function hP(t,e,n,r){const[i,s]=aE(e)?Am(Tw).proxyMap_(e,n):oE(e)?Am(Tw).proxySet_(e,n):NRe(e,n);return(n?.scope_??xY()).drafts_.push(i),s.callbacks_=n?.callbacks_??[],s.key_=r,n&&r!==void 0?TRe(n,s,r):s.callbacks_.push(function(l){l.mapSetPlugin_?.fixSetContents(s);const{patchPlugin_:u}=l;s.modified_&&u&&u.generatePatches_(s,[],l)}),i}function Ro(t){return Sc(t)||Eo(10,t),wY(t)}function wY(t){if(!Io(t)||lE(t))return t;const e=t[Ns];let n,r=!0;if(e){if(!e.modified_)return e.base_;e.finalized_=!0,n=oP(t,e.scope_.immer_.useStrictShallowCopy_),r=e.scope_.immer_.shouldUseStrictIteration()}else n=oP(t,!0);return bb(n,(i,s)=>{Aw(n,i,wY(s))},r),e&&(e.finalized_=!1),n}var RRe=new PRe,SY=RRe.produce;function EY(t){return({dispatch:n,getState:r})=>i=>s=>typeof s=="function"?s(n,r,t):i(s)}var DRe=EY(),ORe=EY,jRe=typeof window<"u"&&window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__?window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__:function(){if(arguments.length!==0)return typeof arguments[0]=="object"?Sw:Sw.apply(null,arguments)};function so(t,e){function n(...r){if(e){let i=e(...r);if(!i)throw new Error(va(0));return{type:t,payload:i.payload,..."meta"in i&&{meta:i.meta},..."error"in i&&{error:i.error}}}return{type:t,payload:r[0]}}return n.toString=()=>`${t}`,n.type=t,n.match=r=>fY(r)&&r.type===t,n}var MY=class Nx extends Array{constructor(...e){super(...e),Object.setPrototypeOf(this,Nx.prototype)}static get[Symbol.species](){return Nx}concat(...e){return super.concat.apply(this,e)}prepend(...e){return e.length===1&&Array.isArray(e[0])?new Nx(...e[0].concat(this)):new Nx(...e.concat(this))}};function TH(t){return Io(t)?SY(t,()=>{}):t}function x_(t,e,n){return t.has(e)?t.get(e):t.set(e,n(e)).get(e)}function LRe(t){return typeof t=="boolean"}var IRe=()=>function(e){const{thunk:n=!0,immutableCheck:r=!0,serializableCheck:i=!0,actionCreatorCheck:s=!0}=e??{};let a=new MY;return n&&(LRe(n)?a.push(DRe):a.push(ORe(n.extraArgument))),a},AY="RTK_autoBatch",hr=()=>t=>({payload:t,meta:{[AY]:!0}}),CH=t=>e=>{setTimeout(e,t)},TY=(t={type:"raf"})=>e=>(...n)=>{const r=e(...n);let i=!0,s=!1,a=!1;const o=new Set,l=t.type==="tick"?queueMicrotask:t.type==="raf"?typeof window<"u"&&window.requestAnimationFrame?window.requestAnimationFrame:CH(10):t.type==="callback"?t.queueNotification:CH(t.timeout),u=()=>{a=!1,s&&(s=!1,o.forEach(d=>d()))};return Object.assign({},r,{subscribe(d){const f=()=>i&&d(),g=r.subscribe(f);return o.add(d),()=>{g(),o.delete(d)}},dispatch(d){try{return i=!d?.meta?.[AY],s=!i,s&&(a||(a=!0,l(u))),r.dispatch(d)}finally{i=!0}}})},URe=t=>function(n){const{autoBatch:r=!0}=n??{};let i=new MY(t);return r&&i.push(TY(typeof r=="object"?r:void 0)),i};function FRe(t){const e=IRe(),{reducer:n=void 0,middleware:r,devTools:i=!0,preloadedState:s=void 0,enhancers:a=void 0}=t||{};let o;if(typeof n=="function")o=n;else if(rO(n))o=hY(n);else throw new Error(va(1));let l;typeof r=="function"?l=r(e):l=e();let u=Sw;i&&(u=jRe({trace:!1,...typeof i=="object"&&i}));const d=bRe(...l),f=URe(d);let g=typeof a=="function"?a(f):f();const m=u(...g);return dY(o,s,m)}function CY(t){const e={},n=[];let r;const i={addCase(s,a){const o=typeof s=="string"?s:s.type;if(!o)throw new Error(va(28));if(o in e)throw new Error(va(29));return e[o]=a,i},addAsyncThunk(s,a){return a.pending&&(e[s.pending.type]=a.pending),a.rejected&&(e[s.rejected.type]=a.rejected),a.fulfilled&&(e[s.fulfilled.type]=a.fulfilled),a.settled&&n.push({matcher:s.settled,reducer:a.settled}),i},addMatcher(s,a){return n.push({matcher:s,reducer:a}),i},addDefaultCase(s){return r=s,i}};return t(i),[e,n,r]}function zRe(t){return typeof t=="function"}function BRe(t,e){let[n,r,i]=CY(e),s;if(zRe(t))s=()=>TH(t());else{const o=TH(t);s=()=>o}function a(o=s(),l){let u=[n[l.type],...r.filter(({matcher:d})=>d(l)).map(({reducer:d})=>d)];return u.filter(d=>!!d).length===0&&(u=[i]),u.reduce((d,f)=>{if(f)if(Sc(d)){const m=f(d,l);return m===void 0?d:m}else{if(Io(d))return SY(d,g=>f(g,l));{const g=f(d,l);if(g===void 0){if(d===null)return d;throw Error("A case reducer on a non-draftable value must not return undefined")}return g}}return d},o)}return a.getInitialState=s,a}var HRe="ModuleSymbhasOwnPr-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW",$Re=(t=21)=>{let e="",n=t;for(;n--;)e+=HRe[Math.random()*64|0];return e},VRe=Symbol.for("rtk-slice-createasyncthunk");function GRe(t,e){return`${t}/${e}`}function WRe({creators:t}={}){const e=t?.asyncThunk?.[VRe];return function(r){const{name:i,reducerPath:s=i}=r;if(!i)throw new Error(va(11));const a=(typeof r.reducers=="function"?r.reducers(KRe()):r.reducers)||{},o=Object.keys(a),l={sliceCaseReducersByName:{},sliceCaseReducersByType:{},actionCreators:{},sliceMatchers:[]},u={addCase(S,A){const T=typeof S=="string"?S:S.type;if(!T)throw new Error(va(12));if(T in l.sliceCaseReducersByType)throw new Error(va(13));return l.sliceCaseReducersByType[T]=A,u},addMatcher(S,A){return l.sliceMatchers.push({matcher:S,reducer:A}),u},exposeAction(S,A){return l.actionCreators[S]=A,u},exposeCaseReducer(S,A){return l.sliceCaseReducersByName[S]=A,u}};o.forEach(S=>{const A=a[S],T={reducerName:S,type:GRe(i,S),createNotation:typeof r.reducers=="function"};YRe(A)?QRe(T,A,u,e):XRe(T,A,u)});function d(){const[S={},A=[],T=void 0]=typeof r.extraReducers=="function"?CY(r.extraReducers):[r.extraReducers],P={...S,...l.sliceCaseReducersByType};return BRe(r.initialState,C=>{for(let I in P)C.addCase(I,P[I]);for(let I of l.sliceMatchers)C.addMatcher(I.matcher,I.reducer);for(let I of A)C.addMatcher(I.matcher,I.reducer);T&&C.addDefaultCase(T)})}const f=S=>S,g=new Map,m=new WeakMap;let x;function y(S,A){return x||(x=d()),x(S,A)}function v(){return x||(x=d()),x.getInitialState()}function b(S,A=!1){function T(C){let I=C[S];return typeof I>"u"&&A&&(I=x_(m,T,v)),I}function P(C=f){const I=x_(g,A,()=>new WeakMap);return x_(I,C,()=>{const N={};for(const[D,F]of Object.entries(r.selectors??{}))N[D]=qRe(F,C,()=>x_(m,C,v),A);return N})}return{reducerPath:S,getSelectors:P,get selectors(){return P(T)},selectSlice:T}}const E={name:i,reducer:y,actions:l.actionCreators,caseReducers:l.sliceCaseReducersByName,getInitialState:v,...b(s),injectInto(S,{reducerPath:A,...T}={}){const P=A??s;return S.inject({reducerPath:P,reducer:y},T),{...E,...b(P,!0)}}};return E}}function qRe(t,e,n,r){function i(s,...a){let o=e(s);return typeof o>"u"&&r&&(o=n()),t(o,...a)}return i.unwrapped=t,i}var Zs=WRe();function KRe(){function t(e,n){return{_reducerDefinitionType:"asyncThunk",payloadCreator:e,...n}}return t.withTypes=()=>t,{reducer(e){return Object.assign({[e.name](...n){return e(...n)}}[e.name],{_reducerDefinitionType:"reducer"})},preparedReducer(e,n){return{_reducerDefinitionType:"reducerWithPrepare",prepare:e,reducer:n}},asyncThunk:t}}function XRe({type:t,reducerName:e,createNotation:n},r,i){let s,a;if("reducer"in r){if(n&&!ZRe(r))throw new Error(va(17));s=r.reducer,a=r.prepare}else s=r;i.addCase(t,s).exposeCaseReducer(e,s).exposeAction(e,a?so(t,a):so(t))}function YRe(t){return t._reducerDefinitionType==="asyncThunk"}function ZRe(t){return t._reducerDefinitionType==="reducerWithPrepare"}function QRe({type:t,reducerName:e},n,r,i){if(!i)throw new Error(va(18));const{payloadCreator:s,fulfilled:a,pending:o,rejected:l,settled:u,options:d}=n,f=i(t,s,d);r.exposeAction(e,f),a&&r.addCase(f.fulfilled,a),o&&r.addCase(f.pending,o),l&&r.addCase(f.rejected,l),u&&r.addMatcher(f.settled,u),r.exposeCaseReducer(e,{fulfilled:a||b_,pending:o||b_,rejected:l||b_,settled:u||b_})}function b_(){}var JRe="task",NY="listener",kY="completed",cO="cancelled",eDe=`task-${cO}`,tDe=`task-${kY}`,fP=`${NY}-${cO}`,nDe=`${NY}-${kY}`,uE=class{constructor(t){this.code=t,this.message=`${JRe} ${cO} (reason: ${t})`}name="TaskAbortError";message},uO=(t,e)=>{if(typeof t!="function")throw new TypeError(va(32))},Cw=()=>{},PY=(t,e=Cw)=>(t.catch(e),t),RY=(t,e)=>(t.addEventListener("abort",e,{once:!0}),()=>t.removeEventListener("abort",e)),Sh=(t,e)=>{const n=t.signal;n.aborted||("reason"in n||Object.defineProperty(n,"reason",{enumerable:!0,value:e,configurable:!0,writable:!0}),t.abort(e))},Eh=t=>{if(t.aborted){const{reason:e}=t;throw new uE(e)}};function DY(t,e){let n=Cw;return new Promise((r,i)=>{const s=()=>i(new uE(t.reason));if(t.aborted){s();return}n=RY(t,s),e.finally(()=>n()).then(r,i)}).finally(()=>{n=Cw})}var rDe=async(t,e)=>{try{return await Promise.resolve(),{status:"ok",value:await t()}}catch(n){return{status:n instanceof uE?"cancelled":"rejected",error:n}}finally{e?.()}},Nw=t=>e=>PY(DY(t,e).then(n=>(Eh(t),n))),OY=t=>{const e=Nw(t);return n=>e(new Promise(r=>setTimeout(r,n)))},{assign:Jp}=Object,NH={},dE="listenerMiddleware",iDe=(t,e)=>{const n=r=>RY(t,()=>Sh(r,t.reason));return(r,i)=>{uO(r);const s=new AbortController;n(s);const a=rDe(async()=>{Eh(t),Eh(s.signal);const o=await r({pause:Nw(s.signal),delay:OY(s.signal),signal:s.signal});return Eh(s.signal),o},()=>Sh(s,tDe));return i?.autoJoin&&e.push(a.catch(Cw)),{result:Nw(t)(a),cancel(){Sh(s,eDe)}}}},sDe=(t,e)=>{const n=async(r,i)=>{Eh(e);let s=()=>{};const o=[new Promise((l,u)=>{let d=t({predicate:r,effect:(f,g)=>{g.unsubscribe(),l([f,g.getState(),g.getOriginalState()])}});s=()=>{d(),u()}})];i!=null&&o.push(new Promise(l=>setTimeout(l,i,null)));try{const l=await DY(e,Promise.race(o));return Eh(e),l}finally{s()}};return(r,i)=>PY(n(r,i))},jY=t=>{let{type:e,actionCreator:n,matcher:r,predicate:i,effect:s}=t;if(e)i=so(e).match;else if(n)e=n.type,i=n.match;else if(r)i=r;else if(!i)throw new Error(va(21));return uO(s),{predicate:i,type:e,effect:s}},LY=Jp(t=>{const{type:e,predicate:n,effect:r}=jY(t);return{id:$Re(),effect:r,type:e,predicate:n,pending:new Set,unsubscribe:()=>{throw new Error(va(22))}}},{withTypes:()=>LY}),kH=(t,e)=>{const{type:n,effect:r,predicate:i}=jY(e);return Array.from(t.values()).find(s=>(typeof n=="string"?s.type===n:s.predicate===i)&&s.effect===r)},pP=t=>{t.pending.forEach(e=>{Sh(e,fP)})},aDe=(t,e)=>()=>{for(const n of e.keys())pP(n);t.clear()},PH=(t,e,n)=>{try{t(e,n)}catch(r){setTimeout(()=>{throw r},0)}},IY=Jp(so(`${dE}/add`),{withTypes:()=>IY}),oDe=so(`${dE}/removeAll`),UY=Jp(so(`${dE}/remove`),{withTypes:()=>UY}),lDe=(...t)=>{console.error(`${dE}/error`,...t)},yb=(t={})=>{const e=new Map,n=new Map,r=m=>{const x=n.get(m)??0;n.set(m,x+1)},i=m=>{const x=n.get(m)??1;x===1?n.delete(m):n.set(m,x-1)},{extra:s,onError:a=lDe}=t;uO(a);const o=m=>(m.unsubscribe=()=>e.delete(m.id),e.set(m.id,m),x=>{m.unsubscribe(),x?.cancelActive&&pP(m)}),l=m=>{const x=kH(e,m)??LY(m);return o(x)};Jp(l,{withTypes:()=>l});const u=m=>{const x=kH(e,m);return x&&(x.unsubscribe(),m.cancelActive&&pP(x)),!!x};Jp(u,{withTypes:()=>u});const d=async(m,x,y,v)=>{const b=new AbortController,E=sDe(l,b.signal),S=[];try{m.pending.add(b),r(m),await Promise.resolve(m.effect(x,Jp({},y,{getOriginalState:v,condition:(A,T)=>E(A,T).then(Boolean),take:E,delay:OY(b.signal),pause:Nw(b.signal),extra:s,signal:b.signal,fork:iDe(b.signal,S),unsubscribe:m.unsubscribe,subscribe:()=>{e.set(m.id,m)},cancelActiveListeners:()=>{m.pending.forEach((A,T,P)=>{A!==b&&(Sh(A,fP),P.delete(A))})},cancel:()=>{Sh(b,fP),m.pending.delete(b)},throwIfCancelled:()=>{Eh(b.signal)}})))}catch(A){A instanceof uE||PH(a,A,{raisedBy:"effect"})}finally{await Promise.all(S),Sh(b,nDe),i(m),m.pending.delete(b)}},f=aDe(e,n);return{middleware:m=>x=>y=>{if(!fY(y))return x(y);if(IY.match(y))return l(y.payload);if(oDe.match(y)){f();return}if(UY.match(y))return u(y.payload);let v=m.getState();const b=()=>{if(v===NH)throw new Error(va(23));return v};let E;try{if(E=x(y),e.size>0){const S=m.getState(),A=Array.from(e.values());for(const T of A){let P=!1;try{P=T.predicate(y,S,v)}catch(C){P=!1,PH(a,C,{raisedBy:"predicate"})}P&&d(T,y,m,b)}}}finally{v=NH}return E},startListening:l,stopListening:u,clearListeners:f}};function va(t){return`Minified Redux Toolkit error #${t}; visit https://redux-toolkit.js.org/Errors?code=${t} for the full message or use the non-minified dev environment for full errors. `}var cDe={layoutType:"horizontal",width:0,height:0,margin:{top:5,right:5,bottom:5,left:5},scale:1},FY=Zs({name:"chartLayout",initialState:cDe,reducers:{setLayout(t,e){t.layoutType=e.payload},setChartSize(t,e){t.width=e.payload.width,t.height=e.payload.height},setMargin(t,e){var n,r,i,s;t.margin.top=(n=e.payload.top)!==null&&n!==void 0?n:0,t.margin.right=(r=e.payload.right)!==null&&r!==void 0?r:0,t.margin.bottom=(i=e.payload.bottom)!==null&&i!==void 0?i:0,t.margin.left=(s=e.payload.left)!==null&&s!==void 0?s:0},setScale(t,e){t.scale=e.payload}}}),{setMargin:uDe,setLayout:dDe,setChartSize:hDe,setScale:fDe}=FY.actions,pDe=FY.reducer;function zY(t,e,n){return Array.isArray(t)&&t&&e+n!==0?t.slice(e,n+1):t}function RH(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function Up(t){for(var e=1;e{if(e&&n){var{width:r,height:i}=n,{align:s,verticalAlign:a,layout:o}=e;if((o==="vertical"||o==="horizontal"&&a==="middle")&&s!=="center"&&Ct(t[s]))return Up(Up({},t),{},{[s]:t[s]+(r||0)});if((o==="horizontal"||o==="vertical"&&s==="center")&&a!=="middle"&&Ct(t[a]))return Up(Up({},t),{},{[a]:t[a]+(i||0)})}return t},kc=(t,e)=>t==="horizontal"&&e==="xAxis"||t==="vertical"&&e==="yAxis"||t==="centric"&&e==="angleAxis"||t==="radial"&&e==="radiusAxis",BY=(t,e,n,r)=>{if(r)return t.map(o=>o.coordinate);var i,s,a=t.map(o=>(o.coordinate===e&&(i=!0),o.coordinate===n&&(s=!0),o.coordinate));return i||a.push(e),s||a.push(n),a},HY=(t,e,n)=>{if(!t)return null;var{duplicateDomain:r,type:i,range:s,scale:a,realScaleType:o,isCategorical:l,categoricalDomain:u,tickCount:d,ticks:f,niceTicks:g,axisType:m}=t;if(!a)return null;var x=o==="scaleBand"&&a.bandwidth?a.bandwidth()/2:2,y=i==="category"&&a.bandwidth?a.bandwidth()/x:0;if(y=m==="angleAxis"&&s&&s.length>=2?Di(s[0]-s[1])*2*y:y,f||g){var v=(f||g||[]).map((b,E)=>{var S=r?r.indexOf(b):b;return{coordinate:a(S)+y,value:b,offset:y,index:E}});return v.filter(b=>!io(b.coordinate))}return l&&u?u.map((b,E)=>({coordinate:a(b)+y,value:b,index:E,offset:y})):a.ticks&&d!=null?a.ticks(d).map((b,E)=>({coordinate:a(b)+y,value:b,offset:y,index:E})):a.domain().map((b,E)=>({coordinate:a(b)+y,value:r?r[b]:b,index:E,offset:y}))},DH=1e-4,vDe=t=>{var e=t.domain();if(!(!e||e.length<=2)){var n=e.length,r=t.range(),i=Math.min(r[0],r[1])-DH,s=Math.max(r[0],r[1])+DH,a=t(e[0]),o=t(e[n-1]);(as||os)&&t.domain([e[0],e[n-1]])}},yDe=(t,e)=>{if(!e||e.length!==2||!Ct(e[0])||!Ct(e[1]))return t;var n=Math.min(e[0],e[1]),r=Math.max(e[0],e[1]),i=[t[0],t[1]];return(!Ct(t[0])||t[0]r)&&(i[1]=r),i[0]>r&&(i[0]=r),i[1]{var e=t.length;if(!(e<=0))for(var n=0,r=t[0].length;n=0?(t[a][n][0]=i,t[a][n][1]=i+o,i=t[a][n][1]):(t[a][n][0]=s,t[a][n][1]=s+o,s=t[a][n][1])}},wDe=t=>{var e=t.length;if(!(e<=0))for(var n=0,r=t[0].length;n=0?(t[s][n][0]=i,t[s][n][1]=i+a,i=t[s][n][1]):(t[s][n][0]=0,t[s][n][1]=0)}},SDe={sign:_De,expand:Kke,none:Em,silhouette:Xke,wiggle:Yke,positive:wDe},EDe=(t,e,n)=>{var r=SDe[n],i=qke().keys(e).value((s,a)=>Number(Qn(s,a,0))).order(rP).offset(r);return i(t)};function $Y(t){return t==null?void 0:String(t)}function OH(t){var{axis:e,ticks:n,bandSize:r,entry:i,index:s,dataKey:a}=t;if(e.type==="category"){if(!e.allowDuplicatedCategory&&e.dataKey&&!yr(i[e.dataKey])){var o=qX(n,"value",i[e.dataKey]);if(o)return o.coordinate+r/2}return n[s]?n[s].coordinate+r/2:null}var l=Qn(i,yr(a)?e.dataKey:a);return yr(l)?null:e.scale(l)}var jH=t=>{var{axis:e,ticks:n,offset:r,bandSize:i,entry:s,index:a}=t;if(e.type==="category")return n[a]?n[a].coordinate+r:null;var o=Qn(s,e.dataKey,e.scale.domain()[a]);return yr(o)?null:e.scale(o)-i/2+r},MDe=t=>{var{numericAxis:e}=t,n=e.scale.domain();if(e.type==="number"){var r=Math.min(n[0],n[1]),i=Math.max(n[0],n[1]);return r<=0&&i>=0?0:i<0?i:r}return n[0]},ADe=t=>{var e=t.flat(2).filter(Ct);return[Math.min(...e),Math.max(...e)]},TDe=t=>[t[0]===1/0?0:t[0],t[1]===-1/0?0:t[1]],CDe=(t,e,n)=>{if(t!=null)return TDe(Object.keys(t).reduce((r,i)=>{var s=t[i],{stackedData:a}=s,o=a.reduce((l,u)=>{var d=zY(u,e,n),f=ADe(d);return[Math.min(l[0],f[0]),Math.max(l[1],f[1])]},[1/0,-1/0]);return[Math.min(o[0],r[0]),Math.max(o[1],r[1])]},[1/0,-1/0]))},LH=/^dataMin[\s]*-[\s]*([0-9]+([.]{1}[0-9]+){0,1})$/,IH=/^dataMax[\s]*\+[\s]*([0-9]+([.]{1}[0-9]+){0,1})$/,Tm=(t,e,n)=>{if(t&&t.scale&&t.scale.bandwidth){var r=t.scale.bandwidth();if(!n||r>0)return r}if(t&&e&&e.length>=2){for(var i=rE(e,d=>d.coordinate),s=1/0,a=1,o=i.length;a{if(e==="horizontal")return t.chartX;if(e==="vertical")return t.chartY},kDe=(t,e)=>e==="centric"?t.angle:t.radius,Pc=t=>t.layout.width,Rc=t=>t.layout.height,PDe=t=>t.layout.scale,VY=t=>t.layout.margin,hE=Ke(t=>t.cartesianAxis.xAxis,t=>Object.values(t)),fE=Ke(t=>t.cartesianAxis.yAxis,t=>Object.values(t)),GY="data-recharts-item-index",WY="data-recharts-item-data-key",_b=60;function FH(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function v_(t){for(var e=1;et.brush.height;function LDe(t){var e=fE(t);return e.reduce((n,r)=>{if(r.orientation==="left"&&!r.mirror&&!r.hide){var i=typeof r.width=="number"?r.width:_b;return n+i}return n},0)}function IDe(t){var e=fE(t);return e.reduce((n,r)=>{if(r.orientation==="right"&&!r.mirror&&!r.hide){var i=typeof r.width=="number"?r.width:_b;return n+i}return n},0)}function UDe(t){var e=hE(t);return e.reduce((n,r)=>r.orientation==="top"&&!r.mirror&&!r.hide?n+r.height:n,0)}function FDe(t){var e=hE(t);return e.reduce((n,r)=>r.orientation==="bottom"&&!r.mirror&&!r.hide?n+r.height:n,0)}var xi=Ke([Pc,Rc,VY,jDe,LDe,IDe,UDe,FDe,cY,dRe],(t,e,n,r,i,s,a,o,l,u)=>{var d={left:(n.left||0)+i,right:(n.right||0)+s},f={top:(n.top||0)+a,bottom:(n.bottom||0)+o},g=v_(v_({},f),d),m=g.bottom;g.bottom+=r,g=bDe(g,l,u);var x=t-g.left-g.right,y=e-g.top-g.bottom;return v_(v_({brushBottom:m},g),{},{width:Math.max(x,0),height:Math.max(y,0)})}),zDe=Ke(xi,t=>({x:t.left,y:t.top,width:t.width,height:t.height})),dO=Ke(Pc,Rc,(t,e)=>({x:0,y:0,width:t,height:e})),BDe=M.createContext(null),ms=()=>M.useContext(BDe)!=null,pE=t=>t.brush,mE=Ke([pE,xi,VY],(t,e,n)=>({height:t.height,x:Ct(t.x)?t.x:e.left,y:Ct(t.y)?t.y:e.top+e.height+e.brushBottom-(n?.bottom||0),width:Ct(t.width)?t.width:e.width})),rN={},iN={},sN={},zH;function HDe(){return zH||(zH=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});function e(n,r,{signal:i,edges:s}={}){let a,o=null;const l=s!=null&&s.includes("leading"),u=s==null||s.includes("trailing"),d=()=>{o!==null&&(n.apply(a,o),a=void 0,o=null)},f=()=>{u&&d(),y()};let g=null;const m=()=>{g!=null&&clearTimeout(g),g=setTimeout(()=>{g=null,f()},r)},x=()=>{g!==null&&(clearTimeout(g),g=null)},y=()=>{x(),a=void 0,o=null},v=()=>{d()},b=function(...E){if(i?.aborted)return;a=this,o=E;const S=g==null;m(),l&&S&&d()};return b.schedule=m,b.cancel=y,b.flush=v,i?.addEventListener("abort",y,{once:!0}),b}t.debounce=e})(sN)),sN}var BH;function $De(){return BH||(BH=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});const e=HDe();function n(r,i=0,s={}){typeof s!="object"&&(s={});const{leading:a=!1,trailing:o=!0,maxWait:l}=s,u=Array(2);a&&(u[0]="leading"),o&&(u[1]="trailing");let d,f=null;const g=e.debounce(function(...y){d=r.apply(this,y),f=null},i,{edges:u}),m=function(...y){return l!=null&&(f===null&&(f=Date.now()),Date.now()-f>=l)?(d=r.apply(this,y),f=Date.now(),g.cancel(),g.schedule(),d):(g.apply(this,y),d)},x=()=>(g.flush(),d);return m.cancel=g.cancel,m.flush=x,m}t.debounce=n})(iN)),iN}var HH;function VDe(){return HH||(HH=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});const e=$De();function n(r,i=0,s={}){const{leading:a=!0,trailing:o=!0}=s;return e.debounce(r,i,{leading:a,maxWait:i,trailing:o})}t.throttle=n})(rN)),rN}var aN,$H;function GDe(){return $H||($H=1,aN=VDe().throttle),aN}var WDe=GDe();const qDe=oo(WDe);var kw=function(e,n){for(var r=arguments.length,i=new Array(r>2?r-2:0),s=2;si[a++]))}},qY=(t,e,n)=>{var{width:r="100%",height:i="100%",aspect:s,maxHeight:a}=n,o=wc(r)?t:Number(r),l=wc(i)?e:Number(i);return s&&s>0&&(o?l=o/s:l&&(o=l*s),a&&l!=null&&l>a&&(l=a)),{calculatedWidth:o,calculatedHeight:l}},KDe={width:0,height:0,overflow:"visible"},XDe={width:0,overflowX:"visible"},YDe={height:0,overflowY:"visible"},ZDe={},QDe=t=>{var{width:e,height:n}=t,r=wc(e),i=wc(n);return r&&i?KDe:r?XDe:i?YDe:ZDe};function JDe(t){var{width:e,height:n,aspect:r}=t,i=e,s=n;return i===void 0&&s===void 0?(i="100%",s="100%"):i===void 0?i=r&&r>0?void 0:"100%":s===void 0&&(s=r&&r>0?void 0:"100%"),{width:i,height:s}}function ur(t){return Number.isFinite(t)}function pl(t){return typeof t=="number"&&t>0&&Number.isFinite(t)}function mP(){return mP=Object.assign?Object.assign.bind():function(t){for(var e=1;e({width:n,height:r}),[n,r]);return rOe(i)?M.createElement(KY.Provider,{value:i},e):null}var hO=()=>M.useContext(KY),iOe=M.forwardRef((t,e)=>{var{aspect:n,initialDimension:r={width:-1,height:-1},width:i,height:s,minWidth:a=0,minHeight:o,maxHeight:l,children:u,debounce:d=0,id:f,className:g,onResize:m,style:x={}}=t,y=M.useRef(null),v=M.useRef();v.current=m,M.useImperativeHandle(e,()=>y.current);var[b,E]=M.useState({containerWidth:r.width,containerHeight:r.height}),S=M.useCallback((I,N)=>{E(D=>{var F=Math.round(I),L=Math.round(N);return D.containerWidth===F&&D.containerHeight===L?D:{containerWidth:F,containerHeight:L}})},[]);M.useEffect(()=>{if(y.current==null||typeof ResizeObserver>"u")return gb;var I=L=>{var q,{width:R,height:V}=L[0].contentRect;S(R,V),(q=v.current)===null||q===void 0||q.call(v,R,V)};d>0&&(I=qDe(I,d,{trailing:!0,leading:!1}));var N=new ResizeObserver(I),{width:D,height:F}=y.current.getBoundingClientRect();return S(D,F),N.observe(y.current),()=>{N.disconnect()}},[S,d]);var{containerWidth:A,containerHeight:T}=b;kw(!n||n>0,"The aspect(%s) must be greater than zero.",n);var{calculatedWidth:P,calculatedHeight:C}=qY(A,T,{width:i,height:s,aspect:n,maxHeight:l});return kw(P!=null&&P>0||C!=null&&C>0,`The width(%s) and height(%s) of chart should be greater than 0, + A`).concat(s,",").concat(s,",0,1,1,").concat(a,",").concat(i),className:"recharts-legend-icon"});if(l==="rect")return M.createElement("path",{stroke:"none",fill:o,d:"M0,".concat(Fa/8,"h").concat(Fa,"v").concat(Fa*3/4,"h").concat(-Fa,"z"),className:"recharts-legend-icon"});if(M.isValidElement(e.legendIcon)){var d=bPe({},e);return delete d.legendIcon,M.cloneElement(e.legendIcon,d)}return M.createElement(JD,{fill:o,cx:i,cy:i,size:Fa,sizeType:"diameter",type:l})}function EPe(t){var{payload:e,iconSize:n,layout:r,formatter:i,inactiveColor:s,iconType:a}=t,o={x:0,y:0,width:Fa,height:Fa},l={display:r==="horizontal"?"inline-block":"block",marginRight:10},u={display:"inline-block",verticalAlign:"middle",marginRight:4};return e.map((d,f)=>{var g=d.formatter||i,m=Tn({"recharts-legend-item":!0,["legend-item-".concat(f)]:!0,inactive:d.inactive});if(d.type==="none")return null;var x=d.inactive?s:d.color,y=g?g(d.value,d,f):d.value;return M.createElement("li",_w({className:m,style:l,key:"legend-item-".concat(f)},xb(t,d,f)),M.createElement(WD,{width:n,height:n,viewBox:o,style:u,"aria-label":"".concat(y," legend icon")},M.createElement(SPe,{data:d,iconType:a,inactiveColor:s})),M.createElement("span",{className:"recharts-legend-item-text",style:{color:x}},y))})}var MPe=t=>{var e=ii(t,wPe),{payload:n,layout:r,align:i}=e;if(!n||!n.length)return null;var s={padding:0,margin:0,textAlign:r==="horizontal"?i:"left"};return M.createElement("ul",{className:"recharts-default-legend",style:s},M.createElement(EPe,_w({},e,{payload:n})))},bC={},vC={},O8;function APe(){return O8||(O8=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});function e(n,r){const i=new Map;for(let s=0;s=0}t.isLength=e})(SC)),SC}var I8;function tO(){return I8||(I8=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});const e=TPe();function n(r){return r!=null&&typeof r!="function"&&e.isLength(r.length)}t.isArrayLike=n})(wC)),wC}var EC={},U8;function CPe(){return U8||(U8=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});function e(n){return typeof n=="object"&&n!==null}t.isObjectLike=e})(EC)),EC}var F8;function NPe(){return F8||(F8=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});const e=tO(),n=CPe();function r(i){return n.isObjectLike(i)&&e.isArrayLike(i)}t.isArrayLikeObject=r})(_C)),_C}var MC={},AC={},z8;function kPe(){return z8||(z8=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});const e=QD();function n(r){return function(i){return e.get(i,r)}}t.property=n})(AC)),AC}var TC={},CC={},NC={},kC={},B8;function ZX(){return B8||(B8=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});function e(n){return n!==null&&(typeof n=="object"||typeof n=="function")}t.isObject=e})(kC)),kC}var PC={},H8;function QX(){return H8||(H8=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});function e(n){return n==null||typeof n!="object"&&typeof n!="function"}t.isPrimitive=e})(PC)),PC}var RC={},$8;function JX(){return $8||($8=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});function e(n,r){return n===r||Number.isNaN(n)&&Number.isNaN(r)}t.eq=e})(RC)),RC}var V8;function PPe(){return V8||(V8=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});const e=ZX(),n=QX(),r=JX();function i(d,f,g){return typeof g!="function"?i(d,f,()=>{}):s(d,f,function m(x,y,v,b,E,S){const A=g(x,y,v,b,E,S);return A!==void 0?!!A:s(x,y,m,S)},new Map)}function s(d,f,g,m){if(f===d)return!0;switch(typeof f){case"object":return a(d,f,g,m);case"function":return Object.keys(f).length>0?s(d,{...f},g,m):r.eq(d,f);default:return e.isObject(d)?typeof f=="string"?f==="":!0:r.eq(d,f)}}function a(d,f,g,m){if(f==null)return!0;if(Array.isArray(f))return l(d,f,g,m);if(f instanceof Map)return o(d,f,g,m);if(f instanceof Set)return u(d,f,g,m);const x=Object.keys(f);if(d==null)return x.length===0;if(x.length===0)return!0;if(m?.has(f))return m.get(f)===d;m?.set(f,d);try{for(let y=0;y{})}t.isMatch=n})(CC)),CC}var DC={},OC={},jC={},W8;function RPe(){return W8||(W8=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});function e(n){return Object.getOwnPropertySymbols(n).filter(r=>Object.prototype.propertyIsEnumerable.call(n,r))}t.getSymbols=e})(jC)),jC}var LC={},q8;function tY(){return q8||(q8=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});function e(n){return n==null?n===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(n)}t.getTag=e})(LC)),LC}var IC={},K8;function nY(){return K8||(K8=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});const e="[object RegExp]",n="[object String]",r="[object Number]",i="[object Boolean]",s="[object Arguments]",a="[object Symbol]",o="[object Date]",l="[object Map]",u="[object Set]",d="[object Array]",f="[object Function]",g="[object ArrayBuffer]",m="[object Object]",x="[object Error]",y="[object DataView]",v="[object Uint8Array]",b="[object Uint8ClampedArray]",E="[object Uint16Array]",S="[object Uint32Array]",A="[object BigUint64Array]",T="[object Int8Array]",P="[object Int16Array]",C="[object Int32Array]",I="[object BigInt64Array]",N="[object Float32Array]",D="[object Float64Array]";t.argumentsTag=s,t.arrayBufferTag=g,t.arrayTag=d,t.bigInt64ArrayTag=I,t.bigUint64ArrayTag=A,t.booleanTag=i,t.dataViewTag=y,t.dateTag=o,t.errorTag=x,t.float32ArrayTag=N,t.float64ArrayTag=D,t.functionTag=f,t.int16ArrayTag=P,t.int32ArrayTag=C,t.int8ArrayTag=T,t.mapTag=l,t.numberTag=r,t.objectTag=m,t.regexpTag=e,t.setTag=u,t.stringTag=n,t.symbolTag=a,t.uint16ArrayTag=E,t.uint32ArrayTag=S,t.uint8ArrayTag=v,t.uint8ClampedArrayTag=b})(IC)),IC}var UC={},X8;function DPe(){return X8||(X8=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});function e(n){return ArrayBuffer.isView(n)&&!(n instanceof DataView)}t.isTypedArray=e})(UC)),UC}var Y8;function rY(){return Y8||(Y8=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});const e=RPe(),n=tY(),r=nY(),i=QX(),s=DPe();function a(d,f){return o(d,void 0,d,new Map,f)}function o(d,f,g,m=new Map,x=void 0){const y=x?.(d,f,g,m);if(y!==void 0)return y;if(i.isPrimitive(d))return d;if(m.has(d))return m.get(d);if(Array.isArray(d)){const v=new Array(d.length);m.set(d,v);for(let b=0;be.isMatch(s,i)}t.matches=r})(TC)),TC}var FC={},zC={},BC={},J8;function LPe(){return J8||(J8=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});const e=rY(),n=nY();function r(i,s){return e.cloneDeepWith(i,(a,o,l,u)=>{const d=s?.(a,o,l,u);if(d!==void 0)return d;if(typeof i=="object")switch(Object.prototype.toString.call(i)){case n.numberTag:case n.stringTag:case n.booleanTag:{const f=new i.constructor(i?.valueOf());return e.copyProperties(f,i),f}case n.argumentsTag:{const f={};return e.copyProperties(f,i),f.length=i.length,f[Symbol.iterator]=i[Symbol.iterator],f}default:return}})}t.cloneDeepWith=r})(BC)),BC}var eH;function IPe(){return eH||(eH=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});const e=LPe();function n(r){return e.cloneDeepWith(r)}t.cloneDeep=n})(zC)),zC}var HC={},$C={},tH;function iY(){return tH||(tH=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});const e=/^(?:0|[1-9]\d*)$/;function n(r,i=Number.MAX_SAFE_INTEGER){switch(typeof r){case"number":return Number.isInteger(r)&&r>=0&&rt,rr=()=>{var t=M.useContext(nO);return t?t.store.dispatch:GPe},Y_=()=>{},WPe=()=>Y_,qPe=(t,e)=>t===e;function kt(t){var e=M.useContext(nO);return vK.useSyncExternalStoreWithSelector(e?e.subscription.addNestedSub:WPe,e?e.store.getState:Y_,e?e.store.getState:Y_,e?t:Y_,qPe)}function KPe(t,e=`expected a function, instead received ${typeof t}`){if(typeof t!="function")throw new TypeError(e)}function XPe(t,e=`expected an object, instead received ${typeof t}`){if(typeof t!="object")throw new TypeError(e)}function YPe(t,e="expected all items to be functions, instead received the following types: "){if(!t.every(n=>typeof n=="function")){const n=t.map(r=>typeof r=="function"?`function ${r.name||"unnamed"}()`:typeof r).join(", ");throw new TypeError(`${e}[${n}]`)}}var cH=t=>Array.isArray(t)?t:[t];function ZPe(t){const e=Array.isArray(t[0])?t[0]:t;return YPe(e,"createSelector expects all input-selectors to be functions, but received the following types: "),e}function QPe(t,e){const n=[],{length:r}=t;for(let i=0;i{n=p_(),a.resetResultsCount()},a.resultsCount=()=>s,a.resetResultsCount=()=>{s=0},a}function nRe(t,...e){const n=typeof t=="function"?{memoize:t,memoizeOptions:e}:t,r=(...i)=>{let s=0,a=0,o,l={},u=i.pop();typeof u=="object"&&(l=u,u=i.pop()),KPe(u,`createSelector expects an output function after the inputs, but received: [${typeof u}]`);const d={...n,...l},{memoize:f,memoizeOptions:g=[],argsMemoize:m=aY,argsMemoizeOptions:x=[]}=d,y=cH(g),v=cH(x),b=ZPe(i),E=f(function(){return s++,u.apply(null,arguments)},...y),S=m(function(){a++;const T=QPe(b,arguments);return o=E.apply(null,T),o},...v);return Object.assign(S,{resultFunc:u,memoizedResultFunc:E,dependencies:b,dependencyRecomputations:()=>a,resetDependencyRecomputations:()=>{a=0},lastResult:()=>o,recomputations:()=>s,resetRecomputations:()=>{s=0},memoize:f,argsMemoize:m})};return Object.assign(r,{withTypes:()=>r}),r}var Ke=nRe(aY),rRe=Object.assign((t,e=Ke)=>{XPe(t,`createStructuredSelector expects first argument to be an object where each property is a selector, instead received a ${typeof t}`);const n=Object.keys(t),r=n.map(s=>t[s]);return e(r,(...s)=>s.reduce((a,o,l)=>(a[n[l]]=o,a),{}))},{withTypes:()=>rRe}),WC={},qC={},KC={},dH;function iRe(){return dH||(dH=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});function e(r){return typeof r=="symbol"?1:r===null?2:r===void 0?3:r!==r?4:0}const n=(r,i,s)=>{if(r!==i){const a=e(r),o=e(i);if(a===o&&a===0){if(ri)return s==="desc"?-1:1}return s==="desc"?o-a:a-o}return 0};t.compareValues=n})(KC)),KC}var XC={},YC={},hH;function oY(){return hH||(hH=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});function e(n){return typeof n=="symbol"||n instanceof Symbol}t.isSymbol=e})(YC)),YC}var fH;function sRe(){return fH||(fH=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});const e=oY(),n=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,r=/^\w*$/;function i(s,a){return Array.isArray(s)?!1:typeof s=="number"||typeof s=="boolean"||s==null||e.isSymbol(s)?!0:typeof s=="string"&&(r.test(s)||!n.test(s))||a!=null&&Object.hasOwn(a,s)}t.isKey=i})(XC)),XC}var pH;function aRe(){return pH||(pH=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});const e=iRe(),n=sRe(),r=ZD();function i(s,a,o,l){if(s==null)return[];o=l?void 0:o,Array.isArray(s)||(s=Object.values(s)),Array.isArray(a)||(a=a==null?[null]:[a]),a.length===0&&(a=[null]),Array.isArray(o)||(o=o==null?[]:[o]),o=o.map(m=>String(m));const u=(m,x)=>{let y=m;for(let v=0;vx==null||m==null?x:typeof m=="object"&&"key"in m?Object.hasOwn(x,m.key)?x[m.key]:u(x,m.path):typeof m=="function"?m(x):Array.isArray(m)?u(x,m):typeof x=="object"?x[m]:x,f=a.map(m=>(Array.isArray(m)&&m.length===1&&(m=m[0]),m==null||typeof m=="function"||Array.isArray(m)||n.isKey(m)?m:{key:m,path:r.toPath(m)}));return s.map(m=>({original:m,criteria:f.map(x=>d(x,m))})).slice().sort((m,x)=>{for(let y=0;ym.original)}t.orderBy=i})(qC)),qC}var ZC={},mH;function oRe(){return mH||(mH=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});function e(n,r=1){const i=[],s=Math.floor(r),a=(o,l)=>{for(let u=0;u1&&r.isIterateeCall(s,a[0],a[1])?a=[]:o>2&&r.isIterateeCall(a[0],a[1],a[2])&&(a=[a[0]]),e.orderBy(s,n.flatten(a),["asc"])}t.sortBy=i})(WC)),WC}var JC,bH;function cRe(){return bH||(bH=1,JC=lRe().sortBy),JC}var uRe=cRe();const rE=oo(uRe);var cY=t=>t.legend.settings,dRe=t=>t.legend.size,hRe=t=>t.legend.payload,fRe=Ke([hRe,cY],(t,e)=>{var{itemSorter:n}=e,r=t.flat(1);return n?rE(r,n):r});function pRe(){return kt(fRe)}var m_=1;function uY(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],[e,n]=M.useState({height:0,left:0,top:0,width:0}),r=M.useCallback(i=>{if(i!=null){var s=i.getBoundingClientRect(),a={height:s.height,left:s.left,top:s.top,width:s.width};(Math.abs(a.height-e.height)>m_||Math.abs(a.left-e.left)>m_||Math.abs(a.top-e.top)>m_||Math.abs(a.width-e.width)>m_)&&n({height:a.height,left:a.left,top:a.top,width:a.width})}},[e.width,e.height,e.top,e.left,...t]);return[e,r]}function Wi(t){return`Minified Redux error #${t}; visit https://redux.js.org/Errors?code=${t} for the full message or use the non-minified dev environment for full errors. `}var mRe=typeof Symbol=="function"&&Symbol.observable||"@@observable",vH=mRe,eN=()=>Math.random().toString(36).substring(7).split("").join("."),gRe={INIT:`@@redux/INIT${eN()}`,REPLACE:`@@redux/REPLACE${eN()}`,PROBE_UNKNOWN_ACTION:()=>`@@redux/PROBE_UNKNOWN_ACTION${eN()}`},ww=gRe;function rO(t){if(typeof t!="object"||t===null)return!1;let e=t;for(;Object.getPrototypeOf(e)!==null;)e=Object.getPrototypeOf(e);return Object.getPrototypeOf(t)===e||Object.getPrototypeOf(t)===null}function dY(t,e,n){if(typeof t!="function")throw new Error(Wi(2));if(typeof e=="function"&&typeof n=="function"||typeof n=="function"&&typeof arguments[3]=="function")throw new Error(Wi(0));if(typeof e=="function"&&typeof n>"u"&&(n=e,e=void 0),typeof n<"u"){if(typeof n!="function")throw new Error(Wi(1));return n(dY)(t,e)}let r=t,i=e,s=new Map,a=s,o=0,l=!1;function u(){a===s&&(a=new Map,s.forEach((v,b)=>{a.set(b,v)}))}function d(){if(l)throw new Error(Wi(3));return i}function f(v){if(typeof v!="function")throw new Error(Wi(4));if(l)throw new Error(Wi(5));let b=!0;u();const E=o++;return a.set(E,v),function(){if(b){if(l)throw new Error(Wi(6));b=!1,u(),a.delete(E),s=null}}}function g(v){if(!rO(v))throw new Error(Wi(7));if(typeof v.type>"u")throw new Error(Wi(8));if(typeof v.type!="string")throw new Error(Wi(17));if(l)throw new Error(Wi(9));try{l=!0,i=r(i,v)}finally{l=!1}return(s=a).forEach(E=>{E()}),v}function m(v){if(typeof v!="function")throw new Error(Wi(10));r=v,g({type:ww.REPLACE})}function x(){const v=f;return{subscribe(b){if(typeof b!="object"||b===null)throw new Error(Wi(11));function E(){const A=b;A.next&&A.next(d())}return E(),{unsubscribe:v(E)}},[vH](){return this}}}return g({type:ww.INIT}),{dispatch:g,subscribe:f,getState:d,replaceReducer:m,[vH]:x}}function xRe(t){Object.keys(t).forEach(e=>{const n=t[e];if(typeof n(void 0,{type:ww.INIT})>"u")throw new Error(Wi(12));if(typeof n(void 0,{type:ww.PROBE_UNKNOWN_ACTION()})>"u")throw new Error(Wi(13))})}function hY(t){const e=Object.keys(t),n={};for(let s=0;s"u")throw o&&o.type,new Error(Wi(14));u[f]=x,l=l||x!==m}return l=l||r.length!==Object.keys(a).length,l?u:a}}function Sw(...t){return t.length===0?e=>e:t.length===1?t[0]:t.reduce((e,n)=>(...r)=>e(n(...r)))}function bRe(...t){return e=>(n,r)=>{const i=e(n,r);let s=()=>{throw new Error(Wi(15))};const a={getState:i.getState,dispatch:(l,...u)=>s(l,...u)},o=t.map(l=>l(a));return s=Sw(...o)(i.dispatch),{...i,dispatch:s}}}function fY(t){return rO(t)&&"type"in t&&typeof t.type=="string"}var pY=Symbol.for("immer-nothing"),yH=Symbol.for("immer-draftable"),Ns=Symbol.for("immer-state");function Eo(t,...e){throw new Error(`[Immer] minified error nr: ${t}. Full error at: https://bit.ly/3cXEKWf`)}var pa=Object,Mm=pa.getPrototypeOf,Ew="constructor",iE="prototype",sP="configurable",Mw="enumerable",Z_="writable",F0="value",Sc=t=>!!t&&!!t[Ns];function Io(t){return t?mY(t)||sE(t)||!!t[yH]||!!t[Ew]?.[yH]||aE(t)||oE(t):!1}var vRe=pa[iE][Ew].toString(),_H=new WeakMap;function mY(t){if(!t||!iO(t))return!1;const e=Mm(t);if(e===null||e===pa[iE])return!0;const n=pa.hasOwnProperty.call(e,Ew)&&e[Ew];if(n===Object)return!0;if(!Dp(n))return!1;let r=_H.get(n);return r===void 0&&(r=Function.toString.call(n),_H.set(n,r)),r===vRe}function bb(t,e,n=!0){vb(t)===0?(n?Reflect.ownKeys(t):pa.keys(t)).forEach(i=>{e(i,t[i],t)}):t.forEach((r,i)=>e(i,r,t))}function vb(t){const e=t[Ns];return e?e.type_:sE(t)?1:aE(t)?2:oE(t)?3:0}var wH=(t,e,n=vb(t))=>n===2?t.has(e):pa[iE].hasOwnProperty.call(t,e),aP=(t,e,n=vb(t))=>n===2?t.get(e):t[e],Aw=(t,e,n,r=vb(t))=>{r===2?t.set(e,n):r===3?t.add(n):t[e]=n};function yRe(t,e){return t===e?t!==0||1/t===1/e:t!==t&&e!==e}var sE=Array.isArray,aE=t=>t instanceof Map,oE=t=>t instanceof Set,iO=t=>typeof t=="object",Dp=t=>typeof t=="function",tN=t=>typeof t=="boolean",ec=t=>t.copy_||t.base_,sO=t=>t.modified_?t.copy_:t.base_;function oP(t,e){if(aE(t))return new Map(t);if(oE(t))return new Set(t);if(sE(t))return Array[iE].slice.call(t);const n=mY(t);if(e===!0||e==="class_only"&&!n){const r=pa.getOwnPropertyDescriptors(t);delete r[Ns];let i=Reflect.ownKeys(r);for(let s=0;s1&&pa.defineProperties(t,{set:g_,add:g_,clear:g_,delete:g_}),pa.freeze(t),e&&bb(t,(n,r)=>{aO(r,!0)},!1)),t}function _Re(){Eo(2)}var g_={[F0]:_Re};function lE(t){return t===null||!iO(t)?!0:pa.isFrozen(t)}var Tw="MapSet",lP="Patches",gY={};function Am(t){const e=gY[t];return e||Eo(0,t),e}var wRe=t=>!!gY[t],z0,xY=()=>z0,SRe=(t,e)=>({drafts_:[],parent_:t,immer_:e,canAutoFreeze_:!0,unfinalizedDrafts_:0,handledSet_:new Set,processedForPatches_:new Set,mapSetPlugin_:wRe(Tw)?Am(Tw):void 0});function SH(t,e){e&&(t.patchPlugin_=Am(lP),t.patches_=[],t.inversePatches_=[],t.patchListener_=e)}function cP(t){uP(t),t.drafts_.forEach(ERe),t.drafts_=null}function uP(t){t===z0&&(z0=t.parent_)}var EH=t=>z0=SRe(z0,t);function ERe(t){const e=t[Ns];e.type_===0||e.type_===1?e.revoke_():e.revoked_=!0}function MH(t,e){e.unfinalizedDrafts_=e.drafts_.length;const n=e.drafts_[0];if(t!==void 0&&t!==n){n[Ns].modified_&&(cP(e),Eo(4)),Io(t)&&(t=AH(e,t));const{patchPlugin_:i}=e;i&&i.generateReplacementPatches_(n[Ns].base_,t,e)}else t=AH(e,n);return MRe(e,t,!0),cP(e),e.patches_&&e.patchListener_(e.patches_,e.inversePatches_),t!==pY?t:void 0}function AH(t,e){if(lE(e))return e;const n=e[Ns];if(!n)return oO(e,t.handledSet_,t);if(!cE(n,t))return e;if(!n.modified_)return n.base_;if(!n.finalized_){const{callbacks_:r}=n;if(r)for(;r.length>0;)r.pop()(t);yY(n,t)}return n.copy_}function MRe(t,e,n=!1){!t.parent_&&t.immer_.autoFreeze_&&t.canAutoFreeze_&&aO(e,n)}function bY(t){t.finalized_=!0,t.scope_.unfinalizedDrafts_--}var cE=(t,e)=>t.scope_===e,ARe=[];function vY(t,e,n,r){const i=ec(t),s=t.type_;if(r!==void 0&&aP(i,r,s)===e){Aw(i,r,n,s);return}if(!t.draftLocations_){const o=t.draftLocations_=new Map;bb(i,(l,u)=>{if(Sc(u)){const d=o.get(u)||[];d.push(l),o.set(u,d)}})}const a=t.draftLocations_.get(e)??ARe;for(const o of a)Aw(i,o,n,s)}function TRe(t,e,n){t.callbacks_.push(function(i){const s=e;if(!s||!cE(s,i))return;i.mapSetPlugin_?.fixSetContents(s);const a=sO(s);vY(t,s.draft_??s,a,n),yY(s,i)})}function yY(t,e){if(t.modified_&&!t.finalized_&&(t.type_===3||(t.assigned_?.size??0)>0)){const{patchPlugin_:r}=e;if(r){const i=r.getPath(t);i&&r.generatePatches_(t,i,e)}bY(t)}}function CRe(t,e,n){const{scope_:r}=t;if(Sc(n)){const i=n[Ns];cE(i,r)&&i.callbacks_.push(function(){Q_(t);const a=sO(i);vY(t,n,a,e)})}else Io(n)&&t.callbacks_.push(function(){const s=ec(t);aP(s,e,t.type_)===n&&r.drafts_.length>1&&(t.assigned_.get(e)??!1)===!0&&t.copy_&&oO(aP(t.copy_,e,t.type_),r.handledSet_,r)})}function oO(t,e,n){return!n.immer_.autoFreeze_&&n.unfinalizedDrafts_<1||Sc(t)||e.has(t)||!Io(t)||lE(t)||(e.add(t),bb(t,(r,i)=>{if(Sc(i)){const s=i[Ns];if(cE(s,n)){const a=sO(s);Aw(t,r,a,t.type_),bY(s)}}else Io(i)&&oO(i,e,n)})),t}function NRe(t,e){const n=sE(t),r={type_:n?1:0,scope_:e?e.scope_:xY(),modified_:!1,finalized_:!1,assigned_:void 0,parent_:e,base_:t,draft_:null,copy_:null,revoke_:null,isManual_:!1,callbacks_:void 0};let i=r,s=lO;n&&(i=[r],s=B0);const{revoke:a,proxy:o}=Proxy.revocable(i,s);return r.draft_=o,r.revoke_=a,[o,r]}var lO={get(t,e){if(e===Ns)return t;const n=ec(t);if(!wH(n,e,t.type_))return kRe(t,n,e);const r=n[e];if(t.finalized_||!Io(r))return r;if(r===nN(t.base_,e)){Q_(t);const i=t.type_===1?+e:e,s=hP(t.scope_,r,t,i);return t.copy_[i]=s}return r},has(t,e){return e in ec(t)},ownKeys(t){return Reflect.ownKeys(ec(t))},set(t,e,n){const r=_Y(ec(t),e);if(r?.set)return r.set.call(t.draft_,n),!0;if(!t.modified_){const i=nN(ec(t),e),s=i?.[Ns];if(s&&s.base_===n)return t.copy_[e]=n,t.assigned_.set(e,!1),!0;if(yRe(n,i)&&(n!==void 0||wH(t.base_,e,t.type_)))return!0;Q_(t),dP(t)}return t.copy_[e]===n&&(n!==void 0||e in t.copy_)||Number.isNaN(n)&&Number.isNaN(t.copy_[e])||(t.copy_[e]=n,t.assigned_.set(e,!0),CRe(t,e,n)),!0},deleteProperty(t,e){return Q_(t),nN(t.base_,e)!==void 0||e in t.base_?(t.assigned_.set(e,!1),dP(t)):t.assigned_.delete(e),t.copy_&&delete t.copy_[e],!0},getOwnPropertyDescriptor(t,e){const n=ec(t),r=Reflect.getOwnPropertyDescriptor(n,e);return r&&{[Z_]:!0,[sP]:t.type_!==1||e!=="length",[Mw]:r[Mw],[F0]:n[e]}},defineProperty(){Eo(11)},getPrototypeOf(t){return Mm(t.base_)},setPrototypeOf(){Eo(12)}},B0={};bb(lO,(t,e)=>{B0[t]=function(){const n=arguments;return n[0]=n[0][0],e.apply(this,n)}});B0.deleteProperty=function(t,e){return B0.set.call(this,t,e,void 0)};B0.set=function(t,e,n){return lO.set.call(this,t[0],e,n,t[0])};function nN(t,e){const n=t[Ns];return(n?ec(n):t)[e]}function kRe(t,e,n){const r=_Y(e,n);return r?F0 in r?r[F0]:r.get?.call(t.draft_):void 0}function _Y(t,e){if(!(e in t))return;let n=Mm(t);for(;n;){const r=Object.getOwnPropertyDescriptor(n,e);if(r)return r;n=Mm(n)}}function dP(t){t.modified_||(t.modified_=!0,t.parent_&&dP(t.parent_))}function Q_(t){t.copy_||(t.assigned_=new Map,t.copy_=oP(t.base_,t.scope_.immer_.useStrictShallowCopy_))}var PRe=class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.useStrictIteration_=!1,this.produce=(n,r,i)=>{if(Dp(n)&&!Dp(r)){const a=r;r=n;const o=this;return function(u=a,...d){return o.produce(u,f=>r.call(this,f,...d))}}Dp(r)||Eo(6),i!==void 0&&!Dp(i)&&Eo(7);let s;if(Io(n)){const a=EH(this),o=hP(a,n,void 0);let l=!0;try{s=r(o),l=!1}finally{l?cP(a):uP(a)}return SH(a,i),MH(s,a)}else if(!n||!iO(n)){if(s=r(n),s===void 0&&(s=n),s===pY&&(s=void 0),this.autoFreeze_&&aO(s,!0),i){const a=[],o=[];Am(lP).generateReplacementPatches_(n,s,{patches_:a,inversePatches_:o}),i(a,o)}return s}else Eo(1,n)},this.produceWithPatches=(n,r)=>{if(Dp(n))return(o,...l)=>this.produceWithPatches(o,u=>n(u,...l));let i,s;return[this.produce(n,r,(o,l)=>{i=o,s=l}),i,s]},tN(e?.autoFreeze)&&this.setAutoFreeze(e.autoFreeze),tN(e?.useStrictShallowCopy)&&this.setUseStrictShallowCopy(e.useStrictShallowCopy),tN(e?.useStrictIteration)&&this.setUseStrictIteration(e.useStrictIteration)}createDraft(e){Io(e)||Eo(8),Sc(e)&&(e=Ro(e));const n=EH(this),r=hP(n,e,void 0);return r[Ns].isManual_=!0,uP(n),r}finishDraft(e,n){const r=e&&e[Ns];(!r||!r.isManual_)&&Eo(9);const{scope_:i}=r;return SH(i,n),MH(void 0,i)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}setUseStrictIteration(e){this.useStrictIteration_=e}shouldUseStrictIteration(){return this.useStrictIteration_}applyPatches(e,n){let r;for(r=n.length-1;r>=0;r--){const s=n[r];if(s.path.length===0&&s.op==="replace"){e=s.value;break}}r>-1&&(n=n.slice(r+1));const i=Am(lP).applyPatches_;return Sc(e)?i(e,n):this.produce(e,s=>i(s,n))}};function hP(t,e,n,r){const[i,s]=aE(e)?Am(Tw).proxyMap_(e,n):oE(e)?Am(Tw).proxySet_(e,n):NRe(e,n);return(n?.scope_??xY()).drafts_.push(i),s.callbacks_=n?.callbacks_??[],s.key_=r,n&&r!==void 0?TRe(n,s,r):s.callbacks_.push(function(l){l.mapSetPlugin_?.fixSetContents(s);const{patchPlugin_:u}=l;s.modified_&&u&&u.generatePatches_(s,[],l)}),i}function Ro(t){return Sc(t)||Eo(10,t),wY(t)}function wY(t){if(!Io(t)||lE(t))return t;const e=t[Ns];let n,r=!0;if(e){if(!e.modified_)return e.base_;e.finalized_=!0,n=oP(t,e.scope_.immer_.useStrictShallowCopy_),r=e.scope_.immer_.shouldUseStrictIteration()}else n=oP(t,!0);return bb(n,(i,s)=>{Aw(n,i,wY(s))},r),e&&(e.finalized_=!1),n}var RRe=new PRe,SY=RRe.produce;function EY(t){return({dispatch:n,getState:r})=>i=>s=>typeof s=="function"?s(n,r,t):i(s)}var DRe=EY(),ORe=EY,jRe=typeof window<"u"&&window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__?window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__:function(){if(arguments.length!==0)return typeof arguments[0]=="object"?Sw:Sw.apply(null,arguments)};function so(t,e){function n(...r){if(e){let i=e(...r);if(!i)throw new Error(va(0));return{type:t,payload:i.payload,..."meta"in i&&{meta:i.meta},..."error"in i&&{error:i.error}}}return{type:t,payload:r[0]}}return n.toString=()=>`${t}`,n.type=t,n.match=r=>fY(r)&&r.type===t,n}var MY=class Nx extends Array{constructor(...e){super(...e),Object.setPrototypeOf(this,Nx.prototype)}static get[Symbol.species](){return Nx}concat(...e){return super.concat.apply(this,e)}prepend(...e){return e.length===1&&Array.isArray(e[0])?new Nx(...e[0].concat(this)):new Nx(...e.concat(this))}};function TH(t){return Io(t)?SY(t,()=>{}):t}function x_(t,e,n){return t.has(e)?t.get(e):t.set(e,n(e)).get(e)}function LRe(t){return typeof t=="boolean"}var IRe=()=>function(e){const{thunk:n=!0,immutableCheck:r=!0,serializableCheck:i=!0,actionCreatorCheck:s=!0}=e??{};let a=new MY;return n&&(LRe(n)?a.push(DRe):a.push(ORe(n.extraArgument))),a},AY="RTK_autoBatch",hr=()=>t=>({payload:t,meta:{[AY]:!0}}),CH=t=>e=>{setTimeout(e,t)},TY=(t={type:"raf"})=>e=>(...n)=>{const r=e(...n);let i=!0,s=!1,a=!1;const o=new Set,l=t.type==="tick"?queueMicrotask:t.type==="raf"?typeof window<"u"&&window.requestAnimationFrame?window.requestAnimationFrame:CH(10):t.type==="callback"?t.queueNotification:CH(t.timeout),u=()=>{a=!1,s&&(s=!1,o.forEach(d=>d()))};return Object.assign({},r,{subscribe(d){const f=()=>i&&d(),g=r.subscribe(f);return o.add(d),()=>{g(),o.delete(d)}},dispatch(d){try{return i=!d?.meta?.[AY],s=!i,s&&(a||(a=!0,l(u))),r.dispatch(d)}finally{i=!0}}})},URe=t=>function(n){const{autoBatch:r=!0}=n??{};let i=new MY(t);return r&&i.push(TY(typeof r=="object"?r:void 0)),i};function FRe(t){const e=IRe(),{reducer:n=void 0,middleware:r,devTools:i=!0,preloadedState:s=void 0,enhancers:a=void 0}=t||{};let o;if(typeof n=="function")o=n;else if(rO(n))o=hY(n);else throw new Error(va(1));let l;typeof r=="function"?l=r(e):l=e();let u=Sw;i&&(u=jRe({trace:!1,...typeof i=="object"&&i}));const d=bRe(...l),f=URe(d);let g=typeof a=="function"?a(f):f();const m=u(...g);return dY(o,s,m)}function CY(t){const e={},n=[];let r;const i={addCase(s,a){const o=typeof s=="string"?s:s.type;if(!o)throw new Error(va(28));if(o in e)throw new Error(va(29));return e[o]=a,i},addAsyncThunk(s,a){return a.pending&&(e[s.pending.type]=a.pending),a.rejected&&(e[s.rejected.type]=a.rejected),a.fulfilled&&(e[s.fulfilled.type]=a.fulfilled),a.settled&&n.push({matcher:s.settled,reducer:a.settled}),i},addMatcher(s,a){return n.push({matcher:s,reducer:a}),i},addDefaultCase(s){return r=s,i}};return t(i),[e,n,r]}function zRe(t){return typeof t=="function"}function BRe(t,e){let[n,r,i]=CY(e),s;if(zRe(t))s=()=>TH(t());else{const o=TH(t);s=()=>o}function a(o=s(),l){let u=[n[l.type],...r.filter(({matcher:d})=>d(l)).map(({reducer:d})=>d)];return u.filter(d=>!!d).length===0&&(u=[i]),u.reduce((d,f)=>{if(f)if(Sc(d)){const m=f(d,l);return m===void 0?d:m}else{if(Io(d))return SY(d,g=>f(g,l));{const g=f(d,l);if(g===void 0){if(d===null)return d;throw Error("A case reducer on a non-draftable value must not return undefined")}return g}}return d},o)}return a.getInitialState=s,a}var HRe="ModuleSymbhasOwnPr-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW",$Re=(t=21)=>{let e="",n=t;for(;n--;)e+=HRe[Math.random()*64|0];return e},VRe=Symbol.for("rtk-slice-createasyncthunk");function GRe(t,e){return`${t}/${e}`}function WRe({creators:t}={}){const e=t?.asyncThunk?.[VRe];return function(r){const{name:i,reducerPath:s=i}=r;if(!i)throw new Error(va(11));const a=(typeof r.reducers=="function"?r.reducers(KRe()):r.reducers)||{},o=Object.keys(a),l={sliceCaseReducersByName:{},sliceCaseReducersByType:{},actionCreators:{},sliceMatchers:[]},u={addCase(S,A){const T=typeof S=="string"?S:S.type;if(!T)throw new Error(va(12));if(T in l.sliceCaseReducersByType)throw new Error(va(13));return l.sliceCaseReducersByType[T]=A,u},addMatcher(S,A){return l.sliceMatchers.push({matcher:S,reducer:A}),u},exposeAction(S,A){return l.actionCreators[S]=A,u},exposeCaseReducer(S,A){return l.sliceCaseReducersByName[S]=A,u}};o.forEach(S=>{const A=a[S],T={reducerName:S,type:GRe(i,S),createNotation:typeof r.reducers=="function"};YRe(A)?QRe(T,A,u,e):XRe(T,A,u)});function d(){const[S={},A=[],T=void 0]=typeof r.extraReducers=="function"?CY(r.extraReducers):[r.extraReducers],P={...S,...l.sliceCaseReducersByType};return BRe(r.initialState,C=>{for(let I in P)C.addCase(I,P[I]);for(let I of l.sliceMatchers)C.addMatcher(I.matcher,I.reducer);for(let I of A)C.addMatcher(I.matcher,I.reducer);T&&C.addDefaultCase(T)})}const f=S=>S,g=new Map,m=new WeakMap;let x;function y(S,A){return x||(x=d()),x(S,A)}function v(){return x||(x=d()),x.getInitialState()}function b(S,A=!1){function T(C){let I=C[S];return typeof I>"u"&&A&&(I=x_(m,T,v)),I}function P(C=f){const I=x_(g,A,()=>new WeakMap);return x_(I,C,()=>{const N={};for(const[D,F]of Object.entries(r.selectors??{}))N[D]=qRe(F,C,()=>x_(m,C,v),A);return N})}return{reducerPath:S,getSelectors:P,get selectors(){return P(T)},selectSlice:T}}const E={name:i,reducer:y,actions:l.actionCreators,caseReducers:l.sliceCaseReducersByName,getInitialState:v,...b(s),injectInto(S,{reducerPath:A,...T}={}){const P=A??s;return S.inject({reducerPath:P,reducer:y},T),{...E,...b(P,!0)}}};return E}}function qRe(t,e,n,r){function i(s,...a){let o=e(s);return typeof o>"u"&&r&&(o=n()),t(o,...a)}return i.unwrapped=t,i}var Zs=WRe();function KRe(){function t(e,n){return{_reducerDefinitionType:"asyncThunk",payloadCreator:e,...n}}return t.withTypes=()=>t,{reducer(e){return Object.assign({[e.name](...n){return e(...n)}}[e.name],{_reducerDefinitionType:"reducer"})},preparedReducer(e,n){return{_reducerDefinitionType:"reducerWithPrepare",prepare:e,reducer:n}},asyncThunk:t}}function XRe({type:t,reducerName:e,createNotation:n},r,i){let s,a;if("reducer"in r){if(n&&!ZRe(r))throw new Error(va(17));s=r.reducer,a=r.prepare}else s=r;i.addCase(t,s).exposeCaseReducer(e,s).exposeAction(e,a?so(t,a):so(t))}function YRe(t){return t._reducerDefinitionType==="asyncThunk"}function ZRe(t){return t._reducerDefinitionType==="reducerWithPrepare"}function QRe({type:t,reducerName:e},n,r,i){if(!i)throw new Error(va(18));const{payloadCreator:s,fulfilled:a,pending:o,rejected:l,settled:u,options:d}=n,f=i(t,s,d);r.exposeAction(e,f),a&&r.addCase(f.fulfilled,a),o&&r.addCase(f.pending,o),l&&r.addCase(f.rejected,l),u&&r.addMatcher(f.settled,u),r.exposeCaseReducer(e,{fulfilled:a||b_,pending:o||b_,rejected:l||b_,settled:u||b_})}function b_(){}var JRe="task",NY="listener",kY="completed",cO="cancelled",eDe=`task-${cO}`,tDe=`task-${kY}`,fP=`${NY}-${cO}`,nDe=`${NY}-${kY}`,uE=class{constructor(t){this.code=t,this.message=`${JRe} ${cO} (reason: ${t})`}name="TaskAbortError";message},uO=(t,e)=>{if(typeof t!="function")throw new TypeError(va(32))},Cw=()=>{},PY=(t,e=Cw)=>(t.catch(e),t),RY=(t,e)=>(t.addEventListener("abort",e,{once:!0}),()=>t.removeEventListener("abort",e)),Sh=(t,e)=>{const n=t.signal;n.aborted||("reason"in n||Object.defineProperty(n,"reason",{enumerable:!0,value:e,configurable:!0,writable:!0}),t.abort(e))},Eh=t=>{if(t.aborted){const{reason:e}=t;throw new uE(e)}};function DY(t,e){let n=Cw;return new Promise((r,i)=>{const s=()=>i(new uE(t.reason));if(t.aborted){s();return}n=RY(t,s),e.finally(()=>n()).then(r,i)}).finally(()=>{n=Cw})}var rDe=async(t,e)=>{try{return await Promise.resolve(),{status:"ok",value:await t()}}catch(n){return{status:n instanceof uE?"cancelled":"rejected",error:n}}finally{e?.()}},Nw=t=>e=>PY(DY(t,e).then(n=>(Eh(t),n))),OY=t=>{const e=Nw(t);return n=>e(new Promise(r=>setTimeout(r,n)))},{assign:Jp}=Object,NH={},dE="listenerMiddleware",iDe=(t,e)=>{const n=r=>RY(t,()=>Sh(r,t.reason));return(r,i)=>{uO(r);const s=new AbortController;n(s);const a=rDe(async()=>{Eh(t),Eh(s.signal);const o=await r({pause:Nw(s.signal),delay:OY(s.signal),signal:s.signal});return Eh(s.signal),o},()=>Sh(s,tDe));return i?.autoJoin&&e.push(a.catch(Cw)),{result:Nw(t)(a),cancel(){Sh(s,eDe)}}}},sDe=(t,e)=>{const n=async(r,i)=>{Eh(e);let s=()=>{};const o=[new Promise((l,u)=>{let d=t({predicate:r,effect:(f,g)=>{g.unsubscribe(),l([f,g.getState(),g.getOriginalState()])}});s=()=>{d(),u()}})];i!=null&&o.push(new Promise(l=>setTimeout(l,i,null)));try{const l=await DY(e,Promise.race(o));return Eh(e),l}finally{s()}};return(r,i)=>PY(n(r,i))},jY=t=>{let{type:e,actionCreator:n,matcher:r,predicate:i,effect:s}=t;if(e)i=so(e).match;else if(n)e=n.type,i=n.match;else if(r)i=r;else if(!i)throw new Error(va(21));return uO(s),{predicate:i,type:e,effect:s}},LY=Jp(t=>{const{type:e,predicate:n,effect:r}=jY(t);return{id:$Re(),effect:r,type:e,predicate:n,pending:new Set,unsubscribe:()=>{throw new Error(va(22))}}},{withTypes:()=>LY}),kH=(t,e)=>{const{type:n,effect:r,predicate:i}=jY(e);return Array.from(t.values()).find(s=>(typeof n=="string"?s.type===n:s.predicate===i)&&s.effect===r)},pP=t=>{t.pending.forEach(e=>{Sh(e,fP)})},aDe=(t,e)=>()=>{for(const n of e.keys())pP(n);t.clear()},PH=(t,e,n)=>{try{t(e,n)}catch(r){setTimeout(()=>{throw r},0)}},IY=Jp(so(`${dE}/add`),{withTypes:()=>IY}),oDe=so(`${dE}/removeAll`),UY=Jp(so(`${dE}/remove`),{withTypes:()=>UY}),lDe=(...t)=>{console.error(`${dE}/error`,...t)},yb=(t={})=>{const e=new Map,n=new Map,r=m=>{const x=n.get(m)??0;n.set(m,x+1)},i=m=>{const x=n.get(m)??1;x===1?n.delete(m):n.set(m,x-1)},{extra:s,onError:a=lDe}=t;uO(a);const o=m=>(m.unsubscribe=()=>e.delete(m.id),e.set(m.id,m),x=>{m.unsubscribe(),x?.cancelActive&&pP(m)}),l=m=>{const x=kH(e,m)??LY(m);return o(x)};Jp(l,{withTypes:()=>l});const u=m=>{const x=kH(e,m);return x&&(x.unsubscribe(),m.cancelActive&&pP(x)),!!x};Jp(u,{withTypes:()=>u});const d=async(m,x,y,v)=>{const b=new AbortController,E=sDe(l,b.signal),S=[];try{m.pending.add(b),r(m),await Promise.resolve(m.effect(x,Jp({},y,{getOriginalState:v,condition:(A,T)=>E(A,T).then(Boolean),take:E,delay:OY(b.signal),pause:Nw(b.signal),extra:s,signal:b.signal,fork:iDe(b.signal,S),unsubscribe:m.unsubscribe,subscribe:()=>{e.set(m.id,m)},cancelActiveListeners:()=>{m.pending.forEach((A,T,P)=>{A!==b&&(Sh(A,fP),P.delete(A))})},cancel:()=>{Sh(b,fP),m.pending.delete(b)},throwIfCancelled:()=>{Eh(b.signal)}})))}catch(A){A instanceof uE||PH(a,A,{raisedBy:"effect"})}finally{await Promise.all(S),Sh(b,nDe),i(m),m.pending.delete(b)}},f=aDe(e,n);return{middleware:m=>x=>y=>{if(!fY(y))return x(y);if(IY.match(y))return l(y.payload);if(oDe.match(y)){f();return}if(UY.match(y))return u(y.payload);let v=m.getState();const b=()=>{if(v===NH)throw new Error(va(23));return v};let E;try{if(E=x(y),e.size>0){const S=m.getState(),A=Array.from(e.values());for(const T of A){let P=!1;try{P=T.predicate(y,S,v)}catch(C){P=!1,PH(a,C,{raisedBy:"predicate"})}P&&d(T,y,m,b)}}}finally{v=NH}return E},startListening:l,stopListening:u,clearListeners:f}};function va(t){return`Minified Redux Toolkit error #${t}; visit https://redux-toolkit.js.org/Errors?code=${t} for the full message or use the non-minified dev environment for full errors. `}var cDe={layoutType:"horizontal",width:0,height:0,margin:{top:5,right:5,bottom:5,left:5},scale:1},FY=Zs({name:"chartLayout",initialState:cDe,reducers:{setLayout(t,e){t.layoutType=e.payload},setChartSize(t,e){t.width=e.payload.width,t.height=e.payload.height},setMargin(t,e){var n,r,i,s;t.margin.top=(n=e.payload.top)!==null&&n!==void 0?n:0,t.margin.right=(r=e.payload.right)!==null&&r!==void 0?r:0,t.margin.bottom=(i=e.payload.bottom)!==null&&i!==void 0?i:0,t.margin.left=(s=e.payload.left)!==null&&s!==void 0?s:0},setScale(t,e){t.scale=e.payload}}}),{setMargin:uDe,setLayout:dDe,setChartSize:hDe,setScale:fDe}=FY.actions,pDe=FY.reducer;function zY(t,e,n){return Array.isArray(t)&&t&&e+n!==0?t.slice(e,n+1):t}function RH(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function Up(t){for(var e=1;e{if(e&&n){var{width:r,height:i}=n,{align:s,verticalAlign:a,layout:o}=e;if((o==="vertical"||o==="horizontal"&&a==="middle")&&s!=="center"&&Ct(t[s]))return Up(Up({},t),{},{[s]:t[s]+(r||0)});if((o==="horizontal"||o==="vertical"&&s==="center")&&a!=="middle"&&Ct(t[a]))return Up(Up({},t),{},{[a]:t[a]+(i||0)})}return t},kc=(t,e)=>t==="horizontal"&&e==="xAxis"||t==="vertical"&&e==="yAxis"||t==="centric"&&e==="angleAxis"||t==="radial"&&e==="radiusAxis",BY=(t,e,n,r)=>{if(r)return t.map(o=>o.coordinate);var i,s,a=t.map(o=>(o.coordinate===e&&(i=!0),o.coordinate===n&&(s=!0),o.coordinate));return i||a.push(e),s||a.push(n),a},HY=(t,e,n)=>{if(!t)return null;var{duplicateDomain:r,type:i,range:s,scale:a,realScaleType:o,isCategorical:l,categoricalDomain:u,tickCount:d,ticks:f,niceTicks:g,axisType:m}=t;if(!a)return null;var x=o==="scaleBand"&&a.bandwidth?a.bandwidth()/2:2,y=i==="category"&&a.bandwidth?a.bandwidth()/x:0;if(y=m==="angleAxis"&&s&&s.length>=2?Di(s[0]-s[1])*2*y:y,f||g){var v=(f||g||[]).map((b,E)=>{var S=r?r.indexOf(b):b;return{coordinate:a(S)+y,value:b,offset:y,index:E}});return v.filter(b=>!io(b.coordinate))}return l&&u?u.map((b,E)=>({coordinate:a(b)+y,value:b,index:E,offset:y})):a.ticks&&d!=null?a.ticks(d).map((b,E)=>({coordinate:a(b)+y,value:b,offset:y,index:E})):a.domain().map((b,E)=>({coordinate:a(b)+y,value:r?r[b]:b,index:E,offset:y}))},DH=1e-4,vDe=t=>{var e=t.domain();if(!(!e||e.length<=2)){var n=e.length,r=t.range(),i=Math.min(r[0],r[1])-DH,s=Math.max(r[0],r[1])+DH,a=t(e[0]),o=t(e[n-1]);(as||os)&&t.domain([e[0],e[n-1]])}},yDe=(t,e)=>{if(!e||e.length!==2||!Ct(e[0])||!Ct(e[1]))return t;var n=Math.min(e[0],e[1]),r=Math.max(e[0],e[1]),i=[t[0],t[1]];return(!Ct(t[0])||t[0]r)&&(i[1]=r),i[0]>r&&(i[0]=r),i[1]{var e=t.length;if(!(e<=0))for(var n=0,r=t[0].length;n=0?(t[a][n][0]=i,t[a][n][1]=i+o,i=t[a][n][1]):(t[a][n][0]=s,t[a][n][1]=s+o,s=t[a][n][1])}},wDe=t=>{var e=t.length;if(!(e<=0))for(var n=0,r=t[0].length;n=0?(t[s][n][0]=i,t[s][n][1]=i+a,i=t[s][n][1]):(t[s][n][0]=0,t[s][n][1]=0)}},SDe={sign:_De,expand:Kke,none:Em,silhouette:Xke,wiggle:Yke,positive:wDe},EDe=(t,e,n)=>{var r=SDe[n],i=qke().keys(e).value((s,a)=>Number(Jn(s,a,0))).order(rP).offset(r);return i(t)};function $Y(t){return t==null?void 0:String(t)}function OH(t){var{axis:e,ticks:n,bandSize:r,entry:i,index:s,dataKey:a}=t;if(e.type==="category"){if(!e.allowDuplicatedCategory&&e.dataKey&&!yr(i[e.dataKey])){var o=qX(n,"value",i[e.dataKey]);if(o)return o.coordinate+r/2}return n[s]?n[s].coordinate+r/2:null}var l=Jn(i,yr(a)?e.dataKey:a);return yr(l)?null:e.scale(l)}var jH=t=>{var{axis:e,ticks:n,offset:r,bandSize:i,entry:s,index:a}=t;if(e.type==="category")return n[a]?n[a].coordinate+r:null;var o=Jn(s,e.dataKey,e.scale.domain()[a]);return yr(o)?null:e.scale(o)-i/2+r},MDe=t=>{var{numericAxis:e}=t,n=e.scale.domain();if(e.type==="number"){var r=Math.min(n[0],n[1]),i=Math.max(n[0],n[1]);return r<=0&&i>=0?0:i<0?i:r}return n[0]},ADe=t=>{var e=t.flat(2).filter(Ct);return[Math.min(...e),Math.max(...e)]},TDe=t=>[t[0]===1/0?0:t[0],t[1]===-1/0?0:t[1]],CDe=(t,e,n)=>{if(t!=null)return TDe(Object.keys(t).reduce((r,i)=>{var s=t[i],{stackedData:a}=s,o=a.reduce((l,u)=>{var d=zY(u,e,n),f=ADe(d);return[Math.min(l[0],f[0]),Math.max(l[1],f[1])]},[1/0,-1/0]);return[Math.min(o[0],r[0]),Math.max(o[1],r[1])]},[1/0,-1/0]))},LH=/^dataMin[\s]*-[\s]*([0-9]+([.]{1}[0-9]+){0,1})$/,IH=/^dataMax[\s]*\+[\s]*([0-9]+([.]{1}[0-9]+){0,1})$/,Tm=(t,e,n)=>{if(t&&t.scale&&t.scale.bandwidth){var r=t.scale.bandwidth();if(!n||r>0)return r}if(t&&e&&e.length>=2){for(var i=rE(e,d=>d.coordinate),s=1/0,a=1,o=i.length;a{if(e==="horizontal")return t.chartX;if(e==="vertical")return t.chartY},kDe=(t,e)=>e==="centric"?t.angle:t.radius,Pc=t=>t.layout.width,Rc=t=>t.layout.height,PDe=t=>t.layout.scale,VY=t=>t.layout.margin,hE=Ke(t=>t.cartesianAxis.xAxis,t=>Object.values(t)),fE=Ke(t=>t.cartesianAxis.yAxis,t=>Object.values(t)),GY="data-recharts-item-index",WY="data-recharts-item-data-key",_b=60;function FH(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function v_(t){for(var e=1;et.brush.height;function LDe(t){var e=fE(t);return e.reduce((n,r)=>{if(r.orientation==="left"&&!r.mirror&&!r.hide){var i=typeof r.width=="number"?r.width:_b;return n+i}return n},0)}function IDe(t){var e=fE(t);return e.reduce((n,r)=>{if(r.orientation==="right"&&!r.mirror&&!r.hide){var i=typeof r.width=="number"?r.width:_b;return n+i}return n},0)}function UDe(t){var e=hE(t);return e.reduce((n,r)=>r.orientation==="top"&&!r.mirror&&!r.hide?n+r.height:n,0)}function FDe(t){var e=hE(t);return e.reduce((n,r)=>r.orientation==="bottom"&&!r.mirror&&!r.hide?n+r.height:n,0)}var xi=Ke([Pc,Rc,VY,jDe,LDe,IDe,UDe,FDe,cY,dRe],(t,e,n,r,i,s,a,o,l,u)=>{var d={left:(n.left||0)+i,right:(n.right||0)+s},f={top:(n.top||0)+a,bottom:(n.bottom||0)+o},g=v_(v_({},f),d),m=g.bottom;g.bottom+=r,g=bDe(g,l,u);var x=t-g.left-g.right,y=e-g.top-g.bottom;return v_(v_({brushBottom:m},g),{},{width:Math.max(x,0),height:Math.max(y,0)})}),zDe=Ke(xi,t=>({x:t.left,y:t.top,width:t.width,height:t.height})),dO=Ke(Pc,Rc,(t,e)=>({x:0,y:0,width:t,height:e})),BDe=M.createContext(null),ms=()=>M.useContext(BDe)!=null,pE=t=>t.brush,mE=Ke([pE,xi,VY],(t,e,n)=>({height:t.height,x:Ct(t.x)?t.x:e.left,y:Ct(t.y)?t.y:e.top+e.height+e.brushBottom-(n?.bottom||0),width:Ct(t.width)?t.width:e.width})),rN={},iN={},sN={},zH;function HDe(){return zH||(zH=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});function e(n,r,{signal:i,edges:s}={}){let a,o=null;const l=s!=null&&s.includes("leading"),u=s==null||s.includes("trailing"),d=()=>{o!==null&&(n.apply(a,o),a=void 0,o=null)},f=()=>{u&&d(),y()};let g=null;const m=()=>{g!=null&&clearTimeout(g),g=setTimeout(()=>{g=null,f()},r)},x=()=>{g!==null&&(clearTimeout(g),g=null)},y=()=>{x(),a=void 0,o=null},v=()=>{d()},b=function(...E){if(i?.aborted)return;a=this,o=E;const S=g==null;m(),l&&S&&d()};return b.schedule=m,b.cancel=y,b.flush=v,i?.addEventListener("abort",y,{once:!0}),b}t.debounce=e})(sN)),sN}var BH;function $De(){return BH||(BH=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});const e=HDe();function n(r,i=0,s={}){typeof s!="object"&&(s={});const{leading:a=!1,trailing:o=!0,maxWait:l}=s,u=Array(2);a&&(u[0]="leading"),o&&(u[1]="trailing");let d,f=null;const g=e.debounce(function(...y){d=r.apply(this,y),f=null},i,{edges:u}),m=function(...y){return l!=null&&(f===null&&(f=Date.now()),Date.now()-f>=l)?(d=r.apply(this,y),f=Date.now(),g.cancel(),g.schedule(),d):(g.apply(this,y),d)},x=()=>(g.flush(),d);return m.cancel=g.cancel,m.flush=x,m}t.debounce=n})(iN)),iN}var HH;function VDe(){return HH||(HH=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});const e=$De();function n(r,i=0,s={}){const{leading:a=!0,trailing:o=!0}=s;return e.debounce(r,i,{leading:a,maxWait:i,trailing:o})}t.throttle=n})(rN)),rN}var aN,$H;function GDe(){return $H||($H=1,aN=VDe().throttle),aN}var WDe=GDe();const qDe=oo(WDe);var kw=function(e,n){for(var r=arguments.length,i=new Array(r>2?r-2:0),s=2;si[a++]))}},qY=(t,e,n)=>{var{width:r="100%",height:i="100%",aspect:s,maxHeight:a}=n,o=wc(r)?t:Number(r),l=wc(i)?e:Number(i);return s&&s>0&&(o?l=o/s:l&&(o=l*s),a&&l!=null&&l>a&&(l=a)),{calculatedWidth:o,calculatedHeight:l}},KDe={width:0,height:0,overflow:"visible"},XDe={width:0,overflowX:"visible"},YDe={height:0,overflowY:"visible"},ZDe={},QDe=t=>{var{width:e,height:n}=t,r=wc(e),i=wc(n);return r&&i?KDe:r?XDe:i?YDe:ZDe};function JDe(t){var{width:e,height:n,aspect:r}=t,i=e,s=n;return i===void 0&&s===void 0?(i="100%",s="100%"):i===void 0?i=r&&r>0?void 0:"100%":s===void 0&&(s=r&&r>0?void 0:"100%"),{width:i,height:s}}function ur(t){return Number.isFinite(t)}function pl(t){return typeof t=="number"&&t>0&&Number.isFinite(t)}function mP(){return mP=Object.assign?Object.assign.bind():function(t){for(var e=1;e({width:n,height:r}),[n,r]);return rOe(i)?M.createElement(KY.Provider,{value:i},e):null}var hO=()=>M.useContext(KY),iOe=M.forwardRef((t,e)=>{var{aspect:n,initialDimension:r={width:-1,height:-1},width:i,height:s,minWidth:a=0,minHeight:o,maxHeight:l,children:u,debounce:d=0,id:f,className:g,onResize:m,style:x={}}=t,y=M.useRef(null),v=M.useRef();v.current=m,M.useImperativeHandle(e,()=>y.current);var[b,E]=M.useState({containerWidth:r.width,containerHeight:r.height}),S=M.useCallback((I,N)=>{E(D=>{var F=Math.round(I),L=Math.round(N);return D.containerWidth===F&&D.containerHeight===L?D:{containerWidth:F,containerHeight:L}})},[]);M.useEffect(()=>{if(y.current==null||typeof ResizeObserver>"u")return gb;var I=L=>{var q,{width:R,height:V}=L[0].contentRect;S(R,V),(q=v.current)===null||q===void 0||q.call(v,R,V)};d>0&&(I=qDe(I,d,{trailing:!0,leading:!1}));var N=new ResizeObserver(I),{width:D,height:F}=y.current.getBoundingClientRect();return S(D,F),N.observe(y.current),()=>{N.disconnect()}},[S,d]);var{containerWidth:A,containerHeight:T}=b;kw(!n||n>0,"The aspect(%s) must be greater than zero.",n);var{calculatedWidth:P,calculatedHeight:C}=qY(A,T,{width:i,height:s,aspect:n,maxHeight:l});return kw(P!=null&&P>0||C!=null&&C>0,`The width(%s) and height(%s) of chart should be greater than 0, please check the style of container, or the props width(%s) and height(%s), or add a minWidth(%s) or minHeight(%s) or use aspect(%s) to control the height and width.`,P,C,i,s,a,o,n),M.createElement("div",{id:f?"".concat(f):void 0,className:Tn("recharts-responsive-container",g),style:GH(GH({},x),{},{width:i,height:s,minWidth:a,minHeight:o,maxHeight:l}),ref:y},M.createElement("div",{style:QDe({width:i,height:s})},M.createElement(XY,{width:P,height:C},u)))}),oN=M.forwardRef((t,e)=>{var n=hO();if(pl(n.width)&&pl(n.height))return t.children;var{width:r,height:i}=JDe({width:t.width,height:t.height,aspect:t.aspect}),{calculatedWidth:s,calculatedHeight:a}=qY(void 0,void 0,{width:r,height:i,aspect:t.aspect,maxHeight:t.maxHeight});return Ct(s)&&Ct(a)?M.createElement(XY,{width:s,height:a},t.children):M.createElement(iOe,mP({},t,{width:r,height:i,ref:e}))});function YY(t){if(t)return{x:t.x,y:t.y,upperWidth:"upperWidth"in t?t.upperWidth:t.width,lowerWidth:"lowerWidth"in t?t.lowerWidth:t.width,width:t.width,height:t.height}}var gE=()=>{var t,e=ms(),n=kt(zDe),r=kt(mE),i=(t=kt(pE))===null||t===void 0?void 0:t.padding;return!e||!r||!i?n:{width:r.width-i.left-i.right,height:r.height-i.top-i.bottom,x:i.left,y:i.top}},sOe={top:0,bottom:0,left:0,right:0,width:0,height:0,brushBottom:0},ZY=()=>{var t;return(t=kt(xi))!==null&&t!==void 0?t:sOe},fO=()=>kt(Pc),pO=()=>kt(Rc),aOe=()=>kt(t=>t.layout.margin),wn=t=>t.layout.layoutType,Km=()=>kt(wn),oOe=()=>{var t=Km();if(t==="horizontal"||t==="vertical")return t},lOe=()=>{var t=Km();return t!==void 0},xE=t=>{var e=rr(),n=ms(),{width:r,height:i}=t,s=hO(),a=r,o=i;return s&&(a=s.width>0?s.width:r,o=s.height>0?s.height:i),M.useEffect(()=>{!n&&pl(a)&&pl(o)&&e(hDe({width:a,height:o}))},[e,n,a,o]),null},QY=Symbol.for("immer-nothing"),WH=Symbol.for("immer-draftable"),wa=Symbol.for("immer-state");function Mo(t,...e){throw new Error(`[Immer] minified error nr: ${t}. Full error at: https://bit.ly/3cXEKWf`)}var H0=Object.getPrototypeOf;function Cm(t){return!!t&&!!t[wa]}function Xh(t){return t?JY(t)||Array.isArray(t)||!!t[WH]||!!t.constructor?.[WH]||wb(t)||vE(t):!1}var cOe=Object.prototype.constructor.toString(),qH=new WeakMap;function JY(t){if(!t||typeof t!="object")return!1;const e=Object.getPrototypeOf(t);if(e===null||e===Object.prototype)return!0;const n=Object.hasOwnProperty.call(e,"constructor")&&e.constructor;if(n===Object)return!0;if(typeof n!="function")return!1;let r=qH.get(n);return r===void 0&&(r=Function.toString.call(n),qH.set(n,r)),r===cOe}function Pw(t,e,n=!0){bE(t)===0?(n?Reflect.ownKeys(t):Object.keys(t)).forEach(i=>{e(i,t[i],t)}):t.forEach((r,i)=>e(i,r,t))}function bE(t){const e=t[wa];return e?e.type_:Array.isArray(t)?1:wb(t)?2:vE(t)?3:0}function gP(t,e){return bE(t)===2?t.has(e):Object.prototype.hasOwnProperty.call(t,e)}function eZ(t,e,n){const r=bE(t);r===2?t.set(e,n):r===3?t.add(n):t[e]=n}function uOe(t,e){return t===e?t!==0||1/t===1/e:t!==t&&e!==e}function wb(t){return t instanceof Map}function vE(t){return t instanceof Set}function Yd(t){return t.copy_||t.base_}function xP(t,e){if(wb(t))return new Map(t);if(vE(t))return new Set(t);if(Array.isArray(t))return Array.prototype.slice.call(t);const n=JY(t);if(e===!0||e==="class_only"&&!n){const r=Object.getOwnPropertyDescriptors(t);delete r[wa];let i=Reflect.ownKeys(r);for(let s=0;s1&&Object.defineProperties(t,{set:y_,add:y_,clear:y_,delete:y_}),Object.freeze(t),e&&Object.values(t).forEach(n=>mO(n,!0))),t}function dOe(){Mo(2)}var y_={value:dOe};function yE(t){return t===null||typeof t!="object"?!0:Object.isFrozen(t)}var hOe={};function Yh(t){const e=hOe[t];return e||Mo(0,t),e}var $0;function tZ(){return $0}function fOe(t,e){return{drafts_:[],parent_:t,immer_:e,canAutoFreeze_:!0,unfinalizedDrafts_:0}}function KH(t,e){e&&(Yh("Patches"),t.patches_=[],t.inversePatches_=[],t.patchListener_=e)}function bP(t){vP(t),t.drafts_.forEach(pOe),t.drafts_=null}function vP(t){t===$0&&($0=t.parent_)}function XH(t){return $0=fOe($0,t)}function pOe(t){const e=t[wa];e.type_===0||e.type_===1?e.revoke_():e.revoked_=!0}function YH(t,e){e.unfinalizedDrafts_=e.drafts_.length;const n=e.drafts_[0];return t!==void 0&&t!==n?(n[wa].modified_&&(bP(e),Mo(4)),Xh(t)&&(t=Rw(e,t),e.parent_||Dw(e,t)),e.patches_&&Yh("Patches").generateReplacementPatches_(n[wa].base_,t,e.patches_,e.inversePatches_)):t=Rw(e,n,[]),bP(e),e.patches_&&e.patchListener_(e.patches_,e.inversePatches_),t!==QY?t:void 0}function Rw(t,e,n){if(yE(e))return e;const r=t.immer_.shouldUseStrictIteration(),i=e[wa];if(!i)return Pw(e,(s,a)=>ZH(t,i,e,s,a,n),r),e;if(i.scope_!==t)return e;if(!i.modified_)return Dw(t,i.base_,!0),i.base_;if(!i.finalized_){i.finalized_=!0,i.scope_.unfinalizedDrafts_--;const s=i.copy_;let a=s,o=!1;i.type_===3&&(a=new Set(s),s.clear(),o=!0),Pw(a,(l,u)=>ZH(t,i,s,l,u,n,o),r),Dw(t,s,!1),n&&t.patches_&&Yh("Patches").generatePatches_(i,n,t.patches_,t.inversePatches_)}return i.copy_}function ZH(t,e,n,r,i,s,a){if(i==null||typeof i!="object"&&!a)return;const o=yE(i);if(!(o&&!a)){if(Cm(i)){const l=s&&e&&e.type_!==3&&!gP(e.assigned_,r)?s.concat(r):void 0,u=Rw(t,i,l);if(eZ(n,r,u),Cm(u))t.canAutoFreeze_=!1;else return}else a&&n.add(i);if(Xh(i)&&!o){if(!t.immer_.autoFreeze_&&t.unfinalizedDrafts_<1||e&&e.base_&&e.base_[r]===i&&o)return;Rw(t,i),(!e||!e.scope_.parent_)&&typeof r!="symbol"&&(wb(n)?n.has(r):Object.prototype.propertyIsEnumerable.call(n,r))&&Dw(t,i)}}}function Dw(t,e,n=!1){!t.parent_&&t.immer_.autoFreeze_&&t.canAutoFreeze_&&mO(e,n)}function mOe(t,e){const n=Array.isArray(t),r={type_:n?1:0,scope_:e?e.scope_:tZ(),modified_:!1,finalized_:!1,assigned_:{},parent_:e,base_:t,draft_:null,copy_:null,revoke_:null,isManual_:!1};let i=r,s=gO;n&&(i=[r],s=V0);const{revoke:a,proxy:o}=Proxy.revocable(i,s);return r.draft_=o,r.revoke_=a,o}var gO={get(t,e){if(e===wa)return t;const n=Yd(t);if(!gP(n,e))return gOe(t,n,e);const r=n[e];return t.finalized_||!Xh(r)?r:r===lN(t.base_,e)?(cN(t),t.copy_[e]=_P(r,t)):r},has(t,e){return e in Yd(t)},ownKeys(t){return Reflect.ownKeys(Yd(t))},set(t,e,n){const r=nZ(Yd(t),e);if(r?.set)return r.set.call(t.draft_,n),!0;if(!t.modified_){const i=lN(Yd(t),e),s=i?.[wa];if(s&&s.base_===n)return t.copy_[e]=n,t.assigned_[e]=!1,!0;if(uOe(n,i)&&(n!==void 0||gP(t.base_,e)))return!0;cN(t),yP(t)}return t.copy_[e]===n&&(n!==void 0||e in t.copy_)||Number.isNaN(n)&&Number.isNaN(t.copy_[e])||(t.copy_[e]=n,t.assigned_[e]=!0),!0},deleteProperty(t,e){return lN(t.base_,e)!==void 0||e in t.base_?(t.assigned_[e]=!1,cN(t),yP(t)):delete t.assigned_[e],t.copy_&&delete t.copy_[e],!0},getOwnPropertyDescriptor(t,e){const n=Yd(t),r=Reflect.getOwnPropertyDescriptor(n,e);return r&&{writable:!0,configurable:t.type_!==1||e!=="length",enumerable:r.enumerable,value:n[e]}},defineProperty(){Mo(11)},getPrototypeOf(t){return H0(t.base_)},setPrototypeOf(){Mo(12)}},V0={};Pw(gO,(t,e)=>{V0[t]=function(){return arguments[0]=arguments[0][0],e.apply(this,arguments)}});V0.deleteProperty=function(t,e){return V0.set.call(this,t,e,void 0)};V0.set=function(t,e,n){return gO.set.call(this,t[0],e,n,t[0])};function lN(t,e){const n=t[wa];return(n?Yd(n):t)[e]}function gOe(t,e,n){const r=nZ(e,n);return r?"value"in r?r.value:r.get?.call(t.draft_):void 0}function nZ(t,e){if(!(e in t))return;let n=H0(t);for(;n;){const r=Object.getOwnPropertyDescriptor(n,e);if(r)return r;n=H0(n)}}function yP(t){t.modified_||(t.modified_=!0,t.parent_&&yP(t.parent_))}function cN(t){t.copy_||(t.copy_=xP(t.base_,t.scope_.immer_.useStrictShallowCopy_))}var xOe=class{constructor(t){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.useStrictIteration_=!0,this.produce=(e,n,r)=>{if(typeof e=="function"&&typeof n!="function"){const s=n;n=e;const a=this;return function(l=s,...u){return a.produce(l,d=>n.call(this,d,...u))}}typeof n!="function"&&Mo(6),r!==void 0&&typeof r!="function"&&Mo(7);let i;if(Xh(e)){const s=XH(this),a=_P(e,void 0);let o=!0;try{i=n(a),o=!1}finally{o?bP(s):vP(s)}return KH(s,r),YH(i,s)}else if(!e||typeof e!="object"){if(i=n(e),i===void 0&&(i=e),i===QY&&(i=void 0),this.autoFreeze_&&mO(i,!0),r){const s=[],a=[];Yh("Patches").generateReplacementPatches_(e,i,s,a),r(s,a)}return i}else Mo(1,e)},this.produceWithPatches=(e,n)=>{if(typeof e=="function")return(a,...o)=>this.produceWithPatches(a,l=>e(l,...o));let r,i;return[this.produce(e,n,(a,o)=>{r=a,i=o}),r,i]},typeof t?.autoFreeze=="boolean"&&this.setAutoFreeze(t.autoFreeze),typeof t?.useStrictShallowCopy=="boolean"&&this.setUseStrictShallowCopy(t.useStrictShallowCopy),typeof t?.useStrictIteration=="boolean"&&this.setUseStrictIteration(t.useStrictIteration)}createDraft(t){Xh(t)||Mo(8),Cm(t)&&(t=bOe(t));const e=XH(this),n=_P(t,void 0);return n[wa].isManual_=!0,vP(e),n}finishDraft(t,e){const n=t&&t[wa];(!n||!n.isManual_)&&Mo(9);const{scope_:r}=n;return KH(r,e),YH(void 0,r)}setAutoFreeze(t){this.autoFreeze_=t}setUseStrictShallowCopy(t){this.useStrictShallowCopy_=t}setUseStrictIteration(t){this.useStrictIteration_=t}shouldUseStrictIteration(){return this.useStrictIteration_}applyPatches(t,e){let n;for(n=e.length-1;n>=0;n--){const i=e[n];if(i.path.length===0&&i.op==="replace"){t=i.value;break}}n>-1&&(e=e.slice(n+1));const r=Yh("Patches").applyPatches_;return Cm(t)?r(t,e):this.produce(t,i=>r(i,e))}};function _P(t,e){const n=wb(t)?Yh("MapSet").proxyMap_(t,e):vE(t)?Yh("MapSet").proxySet_(t,e):mOe(t,e);return(e?e.scope_:tZ()).drafts_.push(n),n}function bOe(t){return Cm(t)||Mo(10,t),rZ(t)}function rZ(t){if(!Xh(t)||yE(t))return t;const e=t[wa];let n,r=!0;if(e){if(!e.modified_)return e.base_;e.finalized_=!0,n=xP(t,e.scope_.immer_.useStrictShallowCopy_),r=e.scope_.immer_.shouldUseStrictIteration()}else n=xP(t,!0);return Pw(n,(i,s)=>{eZ(n,i,rZ(s))},r),e&&(e.finalized_=!1),n}var vOe=new xOe;vOe.produce;var yOe={settings:{layout:"horizontal",align:"center",verticalAlign:"middle",itemSorter:"value"},size:{width:0,height:0},payload:[]},iZ=Zs({name:"legend",initialState:yOe,reducers:{setLegendSize(t,e){t.size.width=e.payload.width,t.size.height=e.payload.height},setLegendSettings(t,e){t.settings.align=e.payload.align,t.settings.layout=e.payload.layout,t.settings.verticalAlign=e.payload.verticalAlign,t.settings.itemSorter=e.payload.itemSorter},addLegendPayload:{reducer(t,e){t.payload.push(e.payload)},prepare:hr()},replaceLegendPayload:{reducer(t,e){var{prev:n,next:r}=e.payload,i=Ro(t).payload.indexOf(n);i>-1&&(t.payload[i]=r)},prepare:hr()},removeLegendPayload:{reducer(t,e){var n=Ro(t).payload.indexOf(e.payload);n>-1&&t.payload.splice(n,1)},prepare:hr()}}}),{setLegendSize:QH,setLegendSettings:_Oe,addLegendPayload:sZ,replaceLegendPayload:aZ,removeLegendPayload:oZ}=iZ.actions,wOe=iZ.reducer,SOe=["contextPayload"];function wP(){return wP=Object.assign?Object.assign.bind():function(t){for(var e=1;e{e(_Oe(t))},[e,t]),null}function DOe(t){var e=rr();return M.useEffect(()=>(e(QH(t)),()=>{e(QH({width:0,height:0}))}),[e,t]),null}function OOe(t,e,n,r){return t==="vertical"&&Ct(e)?{height:e}:t==="horizontal"?{width:n||r}:null}var jOe={align:"center",iconSize:14,itemSorter:"value",layout:"horizontal",verticalAlign:"bottom"};function lZ(t){var e=ii(t,jOe),n=pRe(),r=xke(),i=aOe(),{width:s,height:a,wrapperStyle:o,portal:l}=e,[u,d]=uY([n]),f=fO(),g=pO();if(f==null||g==null)return null;var m=f-(i?.left||0)-(i?.right||0),x=OOe(e.layout,a,s,m),y=l?o:Nm(Nm({position:"absolute",width:x?.width||s||"auto",height:x?.height||a||"auto"},POe(o,e,i,f,g,u)),o),v=l??r;if(v==null||n==null)return null;var b=M.createElement("div",{className:"recharts-legend-wrapper",style:y,ref:d},M.createElement(ROe,{layout:e.layout,align:e.align,verticalAlign:e.verticalAlign,itemSorter:e.itemSorter}),!l&&M.createElement(DOe,{width:u.width,height:u.height}),M.createElement(kOe,wP({},e,x,{margin:i,chartWidth:f,chartHeight:g,contextPayload:n})));return ic.createPortal(b,v)}lZ.displayName="Legend";function SP(){return SP=Object.assign?Object.assign.bind():function(t){for(var e=1;e{var{separator:e=" : ",contentStyle:n={},itemStyle:r={},labelStyle:i={},payload:s,formatter:a,itemSorter:o,wrapperClassName:l,labelClassName:u,label:d,labelFormatter:f,accessibilityLayer:g=!1}=t,m=()=>{if(s&&s.length){var T={padding:0,margin:0},P=(o?rE(s,o):s).map((C,I)=>{if(C.type==="none")return null;var N=C.formatter||a||FOe,{value:D,name:F}=C,L=D,q=F;if(N){var R=N(D,F,C,I,s);if(Array.isArray(R))[L,q]=R;else if(R!=null)L=R;else return null}var V=uN({display:"block",paddingTop:4,paddingBottom:4,color:C.color||"#000"},r);return M.createElement("li",{className:"recharts-tooltip-item",key:"tooltip-item-".concat(I),style:V},fl(q)?M.createElement("span",{className:"recharts-tooltip-item-name"},q):null,fl(q)?M.createElement("span",{className:"recharts-tooltip-item-separator"},e):null,M.createElement("span",{className:"recharts-tooltip-item-value"},L),M.createElement("span",{className:"recharts-tooltip-item-unit"},C.unit||""))});return M.createElement("ul",{className:"recharts-tooltip-item-list",style:T},P)}return null},x=uN({margin:0,padding:10,backgroundColor:"#fff",border:"1px solid #ccc",whiteSpace:"nowrap"},n),y=uN({margin:0},i),v=!yr(d),b=v?d:"",E=Tn("recharts-default-tooltip",l),S=Tn("recharts-tooltip-label",u);v&&f&&s!==void 0&&s!==null&&(b=f(d,s));var A=g?{role:"status","aria-live":"assertive"}:{};return M.createElement("div",SP({className:E,style:x},A),M.createElement("p",{className:S,style:y},M.isValidElement(b)?b:"".concat(b)),m())},fx="recharts-tooltip-wrapper",BOe={visibility:"hidden"};function HOe(t){var{coordinate:e,translateX:n,translateY:r}=t;return Tn(fx,{["".concat(fx,"-right")]:Ct(n)&&e&&Ct(e.x)&&n>=e.x,["".concat(fx,"-left")]:Ct(n)&&e&&Ct(e.x)&&n=e.y,["".concat(fx,"-top")]:Ct(r)&&e&&Ct(e.y)&&r0?i:0),f=n[r]+i;if(e[r])return a[r]?d:f;var g=l[r];if(g==null)return 0;if(a[r]){var m=d,x=g;return mv?Math.max(d,g):Math.max(f,g)}function $Oe(t){var{translateX:e,translateY:n,useTranslate3d:r}=t;return{transform:r?"translate3d(".concat(e,"px, ").concat(n,"px, 0)"):"translate(".concat(e,"px, ").concat(n,"px)")}}function VOe(t){var{allowEscapeViewBox:e,coordinate:n,offsetTopLeft:r,position:i,reverseDirection:s,tooltipBox:a,useTranslate3d:o,viewBox:l}=t,u,d,f;return a.height>0&&a.width>0&&n?(d=t$({allowEscapeViewBox:e,coordinate:n,key:"x",offsetTopLeft:r,position:i,reverseDirection:s,tooltipDimension:a.width,viewBox:l,viewBoxDimension:l.width}),f=t$({allowEscapeViewBox:e,coordinate:n,key:"y",offsetTopLeft:r,position:i,reverseDirection:s,tooltipDimension:a.height,viewBox:l,viewBoxDimension:l.height}),u=$Oe({translateX:d,translateY:f,useTranslate3d:o})):u=BOe,{cssProperties:u,cssClasses:HOe({translateX:d,translateY:f,coordinate:n})}}function n$(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function __(t){for(var e=1;e{if(e.key==="Escape"){var n,r,i,s;this.setState({dismissed:!0,dismissedAtCoordinate:{x:(n=(r=this.props.coordinate)===null||r===void 0?void 0:r.x)!==null&&n!==void 0?n:0,y:(i=(s=this.props.coordinate)===null||s===void 0?void 0:s.y)!==null&&i!==void 0?i:0}})}})}componentDidMount(){document.addEventListener("keydown",this.handleKeyDown)}componentWillUnmount(){document.removeEventListener("keydown",this.handleKeyDown)}componentDidUpdate(){var e,n;this.state.dismissed&&(((e=this.props.coordinate)===null||e===void 0?void 0:e.x)!==this.state.dismissedAtCoordinate.x||((n=this.props.coordinate)===null||n===void 0?void 0:n.y)!==this.state.dismissedAtCoordinate.y)&&(this.state.dismissed=!1)}render(){var{active:e,allowEscapeViewBox:n,animationDuration:r,animationEasing:i,children:s,coordinate:a,hasPayload:o,isAnimationActive:l,offset:u,position:d,reverseDirection:f,useTranslate3d:g,viewBox:m,wrapperStyle:x,lastBoundingBox:y,innerRef:v,hasPortalFromProps:b}=this.props,{cssClasses:E,cssProperties:S}=VOe({allowEscapeViewBox:n,coordinate:a,offsetTopLeft:u,position:d,reverseDirection:f,tooltipBox:{height:y.height,width:y.width},useTranslate3d:g,viewBox:m}),A=b?{}:__(__({transition:l&&e?"transform ".concat(r,"ms ").concat(i):void 0},S),{},{pointerEvents:"none",visibility:!this.state.dismissed&&e&&o?"visible":"hidden",position:"absolute",top:0,left:0}),T=__(__({},A),{},{visibility:!this.state.dismissed&&e&&o?"visible":"hidden"},x);return M.createElement("div",{xmlns:"http://www.w3.org/1999/xhtml",tabIndex:-1,className:E,style:T,ref:v},s)}}var cZ=()=>{var t;return(t=kt(e=>e.rootProps.accessibilityLayer))!==null&&t!==void 0?t:!0};function MP(){return MP=Object.assign?Object.assign.bind():function(t){for(var e=1;eur(t.x)&&ur(t.y),a$=t=>t.base!=null&&Ow(t.base)&&Ow(t),px=t=>t.x,mx=t=>t.y,ZOe=(t,e)=>{if(typeof t=="function")return t;var n="curve".concat(mb(t));return(n==="curveMonotone"||n==="curveBump")&&e?s$["".concat(n).concat(e==="vertical"?"Y":"X")]:s$[n]||tE},QOe=t=>{var{type:e="linear",points:n=[],baseLine:r,layout:i,connectNulls:s=!1}=t,a=ZOe(e,i),o=s?n.filter(Ow):n,l;if(Array.isArray(r)){var u=n.map((m,x)=>i$(i$({},m),{},{base:r[x]}));i==="vertical"?l=f_().y(mx).x1(px).x0(m=>m.base.x):l=f_().x(px).y1(mx).y0(m=>m.base.y);var d=l.defined(a$).curve(a),f=s?u.filter(a$):u;return d(f)}i==="vertical"&&Ct(r)?l=f_().y(mx).x1(px).x0(r):Ct(r)?l=f_().x(px).y1(mx).y0(r):l=OX().x(px).y(mx);var g=l.defined(Ow).curve(a);return g(o)},em=t=>{var{className:e,points:n,path:r,pathRef:i}=t;if((!n||!n.length)&&!r)return null;var s=n&&n.length?QOe(t):r;return M.createElement("path",MP({},Ks(t),eO(t),{className:Tn("recharts-curve",e),d:s===null?void 0:s,ref:i}))},JOe=["x","y","top","left","width","height","className"];function AP(){return AP=Object.assign?Object.assign.bind():function(t){for(var e=1;e"M".concat(t,",").concat(i,"v").concat(r,"M").concat(s,",").concat(e,"h").concat(n),oje=t=>{var{x:e=0,y:n=0,top:r=0,left:i=0,width:s=0,height:a=0,className:o}=t,l=ije(t,JOe),u=eje({x:e,y:n,top:r,left:i,width:s,height:a},l);return!Ct(e)||!Ct(n)||!Ct(s)||!Ct(a)||!Ct(r)||!Ct(i)?null:M.createElement("path",AP({},Cs(u),{className:Tn("recharts-cross",o),d:aje(e,n,s,a,r,i)}))};function lje(t,e,n,r){var i=r/2;return{stroke:"none",fill:"#ccc",x:t==="horizontal"?e.x-i:n.left+.5,y:t==="horizontal"?n.top+.5:e.y-i,width:t==="horizontal"?r:n.width-1,height:t==="horizontal"?n.height-1:r}}function l$(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function c$(t){for(var e=1;et.replace(/([A-Z])/g,e=>"-".concat(e.toLowerCase())),uZ=(t,e,n)=>t.map(r=>"".concat(hje(r)," ").concat(e,"ms ").concat(n)).join(","),fje=(t,e)=>[Object.keys(t),Object.keys(e)].reduce((n,r)=>n.filter(i=>r.includes(i))),G0=(t,e)=>Object.keys(e).reduce((n,r)=>c$(c$({},n),{},{[r]:t(r,e[r])}),{});function u$(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function ci(t){for(var e=1;et+(e-t)*n,TP=t=>{var{from:e,to:n}=t;return e!==n},dZ=(t,e,n)=>{var r=G0((i,s)=>{if(TP(s)){var[a,o]=t(s.from,s.to,s.velocity);return ci(ci({},s),{},{from:a,velocity:o})}return s},e);return n<1?G0((i,s)=>TP(s)?ci(ci({},s),{},{velocity:jw(s.velocity,r[i].velocity,n),from:jw(s.from,r[i].from,n)}):s,e):dZ(t,r,n-1)};function xje(t,e,n,r,i,s){var a,o=r.reduce((g,m)=>ci(ci({},g),{},{[m]:{from:t[m],velocity:0,to:e[m]}}),{}),l=()=>G0((g,m)=>m.from,o),u=()=>!Object.values(o).filter(TP).length,d=null,f=g=>{a||(a=g);var m=g-a,x=m/n.dt;o=dZ(n,o,x),i(ci(ci(ci({},t),e),l())),a=g,u()||(d=s.setTimeout(f))};return()=>(d=s.setTimeout(f),()=>{var g;(g=d)===null||g===void 0||g()})}function bje(t,e,n,r,i,s,a){var o=null,l=i.reduce((f,g)=>ci(ci({},f),{},{[g]:[t[g],e[g]]}),{}),u,d=f=>{u||(u=f);var g=(f-u)/r,m=G0((y,v)=>jw(...v,n(g)),l);if(s(ci(ci(ci({},t),e),m)),g<1)o=a.setTimeout(d);else{var x=G0((y,v)=>jw(...v,n(1)),l);s(ci(ci(ci({},t),e),x))}};return()=>(o=a.setTimeout(d),()=>{var f;(f=o)===null||f===void 0||f()})}const vje=(t,e,n,r,i,s)=>{var a=fje(t,e);return n==null?()=>(i(ci(ci({},t),e)),()=>{}):n.isStepper===!0?xje(t,e,n,a,i,s):bje(t,e,n,r,a,i,s)};var Lw=1e-4,hZ=(t,e)=>[0,3*t,3*e-6*t,3*t-3*e+1],fZ=(t,e)=>t.map((n,r)=>n*e**r).reduce((n,r)=>n+r),d$=(t,e)=>n=>{var r=hZ(t,e);return fZ(r,n)},yje=(t,e)=>n=>{var r=hZ(t,e),i=[...r.map((s,a)=>s*a).slice(1),0];return fZ(i,n)},_je=function(){for(var e=arguments.length,n=new Array(e),r=0;rparseFloat(o));return[a[0],a[1],a[2],a[3]]}}}return n.length===4?n:[0,0,1,1]},wje=(t,e,n,r)=>{var i=d$(t,n),s=d$(e,r),a=yje(t,n),o=u=>u>1?1:u<0?0:u,l=u=>{for(var d=u>1?1:u,f=d,g=0;g<8;++g){var m=i(f)-d,x=a(f);if(Math.abs(m-d)0&&arguments[0]!==void 0?arguments[0]:{},{stiff:n=100,damping:r=8,dt:i=17}=e,s=(a,o,l)=>{var u=-(a-o)*n,d=l*r,f=l+(u-d)*i/1e3,g=l*i/1e3+a;return Math.abs(g-o){if(typeof t=="string")switch(t){case"ease":case"ease-in-out":case"ease-out":case"ease-in":case"linear":return h$(t);case"spring":return Sje();default:if(t.split("(")[0]==="cubic-bezier")return h$(t)}return typeof t=="function"?t:null};function Mje(t){var e,n=()=>null,r=!1,i=null,s=a=>{if(!r){if(Array.isArray(a)){if(!a.length)return;var o=a,[l,...u]=o;if(typeof l=="number"){i=t.setTimeout(s.bind(null,u),l);return}s(l),i=t.setTimeout(s.bind(null,u));return}typeof a=="string"&&(e=a,n(e)),typeof a=="object"&&(e=a,n(e)),typeof a=="function"&&a()}};return{stop:()=>{r=!0},start:a=>{r=!1,i&&(i(),i=null),s(a)},subscribe:a=>(n=a,()=>{n=()=>null}),getTimeoutController:()=>t}}class Aje{setTimeout(e){var n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,r=performance.now(),i=null,s=a=>{a-r>=n?e(a):typeof requestAnimationFrame=="function"&&(i=requestAnimationFrame(s))};return i=requestAnimationFrame(s),()=>{i!=null&&cancelAnimationFrame(i)}}}function Tje(){return Mje(new Aje)}var Cje=M.createContext(Tje);function Nje(t,e){var n=M.useContext(Cje);return M.useMemo(()=>e??n(t),[t,e,n])}var kje=()=>!(typeof window<"u"&&window.document&&window.document.createElement&&window.setTimeout),Xm={devToolsEnabled:!1,isSsr:kje()},Pje={begin:0,duration:1e3,easing:"ease",isActive:!0,canBegin:!0,onAnimationEnd:()=>{},onAnimationStart:()=>{}},f$={t:0},dN={t:1};function Sb(t){var e=ii(t,Pje),{isActive:n,canBegin:r,duration:i,easing:s,begin:a,onAnimationEnd:o,onAnimationStart:l,children:u}=e,d=n==="auto"?!Xm.isSsr:n,f=Nje(e.animationId,e.animationManager),[g,m]=M.useState(d?f$:dN),x=M.useRef(null);return M.useEffect(()=>{d||m(dN)},[d]),M.useEffect(()=>{if(!d||!r)return gb;var y=vje(f$,dN,Eje(s),i,m,f.getTimeoutController()),v=()=>{x.current=y()};return f.start([l,a,v,i,o]),()=>{f.stop(),x.current&&x.current(),o()}},[d,r,i,s,a,l,o,f]),u(g.t)}function Eb(t){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"animation-",n=M.useRef(U0(e)),r=M.useRef(t);return r.current!==t&&(n.current=U0(e),r.current=t),n.current}var Rje=["radius"],Dje=["radius"];function p$(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function m$(t){for(var e=1;e{var s=Math.min(Math.abs(n)/2,Math.abs(r)/2),a=r>=0?1:-1,o=n>=0?1:-1,l=r>=0&&n>=0||r<0&&n<0?1:0,u;if(s>0&&i instanceof Array){for(var d=[0,0,0,0],f=0,g=4;fs?s:i[f];u="M".concat(t,",").concat(e+a*d[0]),d[0]>0&&(u+="A ".concat(d[0],",").concat(d[0],",0,0,").concat(l,",").concat(t+o*d[0],",").concat(e)),u+="L ".concat(t+n-o*d[1],",").concat(e),d[1]>0&&(u+="A ".concat(d[1],",").concat(d[1],",0,0,").concat(l,`, @@ -8594,9 +8594,9 @@ Accuracy: ${t.time_accuracy.toFixed(0)}%`:t.actual_time_seconds?`Actual: ${hx(t. `);if(r>0){var{circleTangency:S,lineTangency:A,theta:T}=w_({cx:e,cy:n,radius:r,angle:l,sign:d,isExternal:!0,cornerRadius:s,cornerIsExternal:o}),{circleTangency:P,lineTangency:C,theta:I}=w_({cx:e,cy:n,radius:r,angle:u,sign:-d,isExternal:!0,cornerRadius:s,cornerIsExternal:o}),N=o?Math.abs(l-u):Math.abs(l-u)-T-I;if(N<0&&s===0)return"".concat(E,"L").concat(e,",").concat(n,"Z");E+="L".concat(C.x,",").concat(C.y,` A`).concat(s,",").concat(s,",0,0,").concat(+(d<0),",").concat(P.x,",").concat(P.y,` A`).concat(r,",").concat(r,",0,").concat(+(N>180),",").concat(+(d>0),",").concat(S.x,",").concat(S.y,` - A`).concat(s,",").concat(s,",0,0,").concat(+(d<0),",").concat(A.x,",").concat(A.y,"Z")}else E+="L".concat(e,",").concat(n,"Z");return E},Xje={cx:0,cy:0,innerRadius:0,outerRadius:0,startAngle:0,endAngle:0,cornerRadius:0,forceCornerRadius:!1,cornerIsExternal:!1},bZ=t=>{var e=ii(t,Xje),{cx:n,cy:r,innerRadius:i,outerRadius:s,cornerRadius:a,forceCornerRadius:o,cornerIsExternal:l,startAngle:u,endAngle:d,className:f}=e;if(s0&&Math.abs(u-d)<360?y=Kje({cx:n,cy:r,innerRadius:i,outerRadius:s,cornerRadius:Math.min(x,m/2),forceCornerRadius:o,cornerIsExternal:l,startAngle:u,endAngle:d}):y=xZ({cx:n,cy:r,innerRadius:i,outerRadius:s,startAngle:u,endAngle:d}),M.createElement("path",CP({},Cs(e),{className:g,d:y}))};function Yje(t,e,n){if(t==="horizontal")return[{x:e.x,y:n.top},{x:e.x,y:n.top+n.height}];if(t==="vertical")return[{x:n.left,y:e.y},{x:n.left+n.width,y:e.y}];if(XX(e)){if(t==="centric"){var{cx:r,cy:i,innerRadius:s,outerRadius:a,angle:o}=e,l=Yr(r,i,s,o),u=Yr(r,i,a,o);return[{x:l.x,y:l.y},{x:u.x,y:u.y}]}return gZ(e)}}var hN={},fN={},pN={},_$;function Zje(){return _$||(_$=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});const e=oY();function n(r){return e.isSymbol(r)?NaN:Number(r)}t.toNumber=n})(pN)),pN}var w$;function Qje(){return w$||(w$=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});const e=Zje();function n(r){return r?(r=e.toNumber(r),r===1/0||r===-1/0?(r<0?-1:1)*Number.MAX_VALUE:r===r?r:0):r===0?r:0}t.toFinite=n})(fN)),fN}var S$;function Jje(){return S$||(S$=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});const e=lY(),n=Qje();function r(i,s,a){a&&typeof a!="number"&&e.isIterateeCall(i,s,a)&&(s=a=void 0),i=n.toFinite(i),s===void 0?(s=i,i=0):s=n.toFinite(s),a=a===void 0?ie?1:t>=e?0:NaN}function nLe(t,e){return t==null||e==null?NaN:et?1:e>=t?0:NaN}function xO(t){let e,n,r;t.length!==2?(e=Yu,n=(o,l)=>Yu(t(o),l),r=(o,l)=>t(o)-l):(e=t===Yu||t===nLe?t:rLe,n=t,r=t);function i(o,l,u=0,d=o.length){if(u>>1;n(o[f],l)<0?u=f+1:d=f}while(u>>1;n(o[f],l)<=0?u=f+1:d=f}while(uu&&r(o[f-1],l)>-r(o[f],l)?f-1:f}return{left:i,center:a,right:s}}function rLe(){return 0}function yZ(t){return t===null?NaN:+t}function*iLe(t,e){for(let n of t)n!=null&&(n=+n)>=n&&(yield n)}const sLe=xO(Yu),Mb=sLe.right;xO(yZ).center;class M$ extends Map{constructor(e,n=lLe){if(super(),Object.defineProperties(this,{_intern:{value:new Map},_key:{value:n}}),e!=null)for(const[r,i]of e)this.set(r,i)}get(e){return super.get(A$(this,e))}has(e){return super.has(A$(this,e))}set(e,n){return super.set(aLe(this,e),n)}delete(e){return super.delete(oLe(this,e))}}function A$({_intern:t,_key:e},n){const r=e(n);return t.has(r)?t.get(r):n}function aLe({_intern:t,_key:e},n){const r=e(n);return t.has(r)?t.get(r):(t.set(r,n),n)}function oLe({_intern:t,_key:e},n){const r=e(n);return t.has(r)&&(n=t.get(r),t.delete(r)),n}function lLe(t){return t!==null&&typeof t=="object"?t.valueOf():t}function cLe(t=Yu){if(t===Yu)return _Z;if(typeof t!="function")throw new TypeError("compare is not a function");return(e,n)=>{const r=t(e,n);return r||r===0?r:(t(n,n)===0)-(t(e,e)===0)}}function _Z(t,e){return(t==null||!(t>=t))-(e==null||!(e>=e))||(te?1:0)}const uLe=Math.sqrt(50),dLe=Math.sqrt(10),hLe=Math.sqrt(2);function Fw(t,e,n){const r=(e-t)/Math.max(0,n),i=Math.floor(Math.log10(r)),s=r/Math.pow(10,i),a=s>=uLe?10:s>=dLe?5:s>=hLe?2:1;let o,l,u;return i<0?(u=Math.pow(10,-i)/a,o=Math.round(t*u),l=Math.round(e*u),o/ue&&--l,u=-u):(u=Math.pow(10,i)*a,o=Math.round(t/u),l=Math.round(e/u),o*ue&&--l),l0))return[];if(t===e)return[t];const r=e=i))return[];const o=s-i+1,l=new Array(o);if(r)if(a<0)for(let u=0;u=r)&&(n=r);return n}function C$(t,e){let n;for(const r of t)r!=null&&(n>r||n===void 0&&r>=r)&&(n=r);return n}function wZ(t,e,n=0,r=1/0,i){if(e=Math.floor(e),n=Math.floor(Math.max(0,n)),r=Math.floor(Math.min(t.length-1,r)),!(n<=e&&e<=r))return t;for(i=i===void 0?_Z:cLe(i);r>n;){if(r-n>600){const l=r-n+1,u=e-n+1,d=Math.log(l),f=.5*Math.exp(2*d/3),g=.5*Math.sqrt(d*f*(l-f)/l)*(u-l/2<0?-1:1),m=Math.max(n,Math.floor(e-u*f/l+g)),x=Math.min(r,Math.floor(e+(l-u)*f/l+g));wZ(t,e,m,x,i)}const s=t[e];let a=n,o=r;for(gx(t,n,e),i(t[r],s)>0&&gx(t,n,r);a0;)--o}i(t[n],s)===0?gx(t,n,o):(++o,gx(t,o,r)),o<=e&&(n=o+1),e<=o&&(r=o-1)}return t}function gx(t,e,n){const r=t[e];t[e]=t[n],t[n]=r}function fLe(t,e,n){if(t=Float64Array.from(iLe(t)),!(!(r=t.length)||isNaN(e=+e))){if(e<=0||r<2)return C$(t);if(e>=1)return T$(t);var r,i=(r-1)*e,s=Math.floor(i),a=T$(wZ(t,s).subarray(0,s+1)),o=C$(t.subarray(s+1));return a+(o-a)*(i-s)}}function pLe(t,e,n=yZ){if(!(!(r=t.length)||isNaN(e=+e))){if(e<=0||r<2)return+n(t[0],0,t);if(e>=1)return+n(t[r-1],r-1,t);var r,i=(r-1)*e,s=Math.floor(i),a=+n(t[s],s,t),o=+n(t[s+1],s+1,t);return a+(o-a)*(i-s)}}function mLe(t,e,n){t=+t,e=+e,n=(i=arguments.length)<2?(e=t,t=0,1):i<3?1:+n;for(var r=-1,i=Math.max(0,Math.ceil((e-t)/n))|0,s=new Array(i);++r>8&15|e>>4&240,e>>4&15|e&240,(e&15)<<4|e&15,1):n===8?S_(e>>24&255,e>>16&255,e>>8&255,(e&255)/255):n===4?S_(e>>12&15|e>>8&240,e>>8&15|e>>4&240,e>>4&15|e&240,((e&15)<<4|e&15)/255):null):(e=bLe.exec(t))?new Hs(e[1],e[2],e[3],1):(e=vLe.exec(t))?new Hs(e[1]*255/100,e[2]*255/100,e[3]*255/100,1):(e=yLe.exec(t))?S_(e[1],e[2],e[3],e[4]):(e=_Le.exec(t))?S_(e[1]*255/100,e[2]*255/100,e[3]*255/100,e[4]):(e=wLe.exec(t))?j$(e[1],e[2]/100,e[3]/100,1):(e=SLe.exec(t))?j$(e[1],e[2]/100,e[3]/100,e[4]):N$.hasOwnProperty(t)?R$(N$[t]):t==="transparent"?new Hs(NaN,NaN,NaN,0):null}function R$(t){return new Hs(t>>16&255,t>>8&255,t&255,1)}function S_(t,e,n,r){return r<=0&&(t=e=n=NaN),new Hs(t,e,n,r)}function ALe(t){return t instanceof Ab||(t=K0(t)),t?(t=t.rgb(),new Hs(t.r,t.g,t.b,t.opacity)):new Hs}function DP(t,e,n,r){return arguments.length===1?ALe(t):new Hs(t,e,n,r??1)}function Hs(t,e,n,r){this.r=+t,this.g=+e,this.b=+n,this.opacity=+r}yO(Hs,DP,EZ(Ab,{brighter(t){return t=t==null?zw:Math.pow(zw,t),new Hs(this.r*t,this.g*t,this.b*t,this.opacity)},darker(t){return t=t==null?W0:Math.pow(W0,t),new Hs(this.r*t,this.g*t,this.b*t,this.opacity)},rgb(){return this},clamp(){return new Hs(Mh(this.r),Mh(this.g),Mh(this.b),Bw(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:D$,formatHex:D$,formatHex8:TLe,formatRgb:O$,toString:O$}));function D$(){return`#${uh(this.r)}${uh(this.g)}${uh(this.b)}`}function TLe(){return`#${uh(this.r)}${uh(this.g)}${uh(this.b)}${uh((isNaN(this.opacity)?1:this.opacity)*255)}`}function O$(){const t=Bw(this.opacity);return`${t===1?"rgb(":"rgba("}${Mh(this.r)}, ${Mh(this.g)}, ${Mh(this.b)}${t===1?")":`, ${t})`}`}function Bw(t){return isNaN(t)?1:Math.max(0,Math.min(1,t))}function Mh(t){return Math.max(0,Math.min(255,Math.round(t)||0))}function uh(t){return t=Mh(t),(t<16?"0":"")+t.toString(16)}function j$(t,e,n,r){return r<=0?t=e=n=NaN:n<=0||n>=1?t=e=NaN:e<=0&&(t=NaN),new Ao(t,e,n,r)}function MZ(t){if(t instanceof Ao)return new Ao(t.h,t.s,t.l,t.opacity);if(t instanceof Ab||(t=K0(t)),!t)return new Ao;if(t instanceof Ao)return t;t=t.rgb();var e=t.r/255,n=t.g/255,r=t.b/255,i=Math.min(e,n,r),s=Math.max(e,n,r),a=NaN,o=s-i,l=(s+i)/2;return o?(e===s?a=(n-r)/o+(n0&&l<1?0:a,new Ao(a,o,l,t.opacity)}function CLe(t,e,n,r){return arguments.length===1?MZ(t):new Ao(t,e,n,r??1)}function Ao(t,e,n,r){this.h=+t,this.s=+e,this.l=+n,this.opacity=+r}yO(Ao,CLe,EZ(Ab,{brighter(t){return t=t==null?zw:Math.pow(zw,t),new Ao(this.h,this.s,this.l*t,this.opacity)},darker(t){return t=t==null?W0:Math.pow(W0,t),new Ao(this.h,this.s,this.l*t,this.opacity)},rgb(){var t=this.h%360+(this.h<0)*360,e=isNaN(t)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*e,i=2*n-r;return new Hs(gN(t>=240?t-240:t+120,i,r),gN(t,i,r),gN(t<120?t+240:t-120,i,r),this.opacity)},clamp(){return new Ao(L$(this.h),E_(this.s),E_(this.l),Bw(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const t=Bw(this.opacity);return`${t===1?"hsl(":"hsla("}${L$(this.h)}, ${E_(this.s)*100}%, ${E_(this.l)*100}%${t===1?")":`, ${t})`}`}}));function L$(t){return t=(t||0)%360,t<0?t+360:t}function E_(t){return Math.max(0,Math.min(1,t||0))}function gN(t,e,n){return(t<60?e+(n-e)*t/60:t<180?n:t<240?e+(n-e)*(240-t)/60:e)*255}const _O=t=>()=>t;function NLe(t,e){return function(n){return t+n*e}}function kLe(t,e,n){return t=Math.pow(t,n),e=Math.pow(e,n)-t,n=1/n,function(r){return Math.pow(t+r*e,n)}}function PLe(t){return(t=+t)==1?AZ:function(e,n){return n-e?kLe(e,n,t):_O(isNaN(e)?n:e)}}function AZ(t,e){var n=e-t;return n?NLe(t,n):_O(isNaN(t)?e:t)}const I$=(function t(e){var n=PLe(e);function r(i,s){var a=n((i=DP(i)).r,(s=DP(s)).r),o=n(i.g,s.g),l=n(i.b,s.b),u=AZ(i.opacity,s.opacity);return function(d){return i.r=a(d),i.g=o(d),i.b=l(d),i.opacity=u(d),i+""}}return r.gamma=t,r})(1);function RLe(t,e){e||(e=[]);var n=t?Math.min(e.length,t.length):0,r=e.slice(),i;return function(s){for(i=0;in&&(s=e.slice(n,s),o[a]?o[a]+=s:o[++a]=s),(r=r[0])===(i=i[0])?o[a]?o[a]+=i:o[++a]=i:(o[++a]=null,l.push({i:a,x:Hw(r,i)})),n=xN.lastIndex;return ne&&(n=t,t=e,e=n),function(r){return Math.max(t,Math.min(e,r))}}function $Le(t,e,n){var r=t[0],i=t[1],s=e[0],a=e[1];return i2?VLe:$Le,l=u=null,f}function f(g){return g==null||isNaN(g=+g)?s:(l||(l=o(t.map(r),e,n)))(r(a(g)))}return f.invert=function(g){return a(i((u||(u=o(e,t.map(r),Hw)))(g)))},f.domain=function(g){return arguments.length?(t=Array.from(g,$w),d()):t.slice()},f.range=function(g){return arguments.length?(e=Array.from(g),d()):e.slice()},f.rangeRound=function(g){return e=Array.from(g),n=wO,d()},f.clamp=function(g){return arguments.length?(a=g?!0:Ss,d()):a!==Ss},f.interpolate=function(g){return arguments.length?(n=g,d()):n},f.unknown=function(g){return arguments.length?(s=g,f):s},function(g,m){return r=g,i=m,d()}}function SO(){return _E()(Ss,Ss)}function GLe(t){return Math.abs(t=Math.round(t))>=1e21?t.toLocaleString("en").replace(/,/g,""):t.toString(10)}function Vw(t,e){if((n=(t=e?t.toExponential(e-1):t.toExponential()).indexOf("e"))<0)return null;var n,r=t.slice(0,n);return[r.length>1?r[0]+r.slice(2):r,+t.slice(n+1)]}function km(t){return t=Vw(Math.abs(t)),t?t[1]:NaN}function WLe(t,e){return function(n,r){for(var i=n.length,s=[],a=0,o=t[0],l=0;i>0&&o>0&&(l+o+1>r&&(o=Math.max(1,r-l)),s.push(n.substring(i-=o,i+o)),!((l+=o+1)>r));)o=t[a=(a+1)%t.length];return s.reverse().join(e)}}function qLe(t){return function(e){return e.replace(/[0-9]/g,function(n){return t[+n]})}}var KLe=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function X0(t){if(!(e=KLe.exec(t)))throw new Error("invalid format: "+t);var e;return new EO({fill:e[1],align:e[2],sign:e[3],symbol:e[4],zero:e[5],width:e[6],comma:e[7],precision:e[8]&&e[8].slice(1),trim:e[9],type:e[10]})}X0.prototype=EO.prototype;function EO(t){this.fill=t.fill===void 0?" ":t.fill+"",this.align=t.align===void 0?">":t.align+"",this.sign=t.sign===void 0?"-":t.sign+"",this.symbol=t.symbol===void 0?"":t.symbol+"",this.zero=!!t.zero,this.width=t.width===void 0?void 0:+t.width,this.comma=!!t.comma,this.precision=t.precision===void 0?void 0:+t.precision,this.trim=!!t.trim,this.type=t.type===void 0?"":t.type+""}EO.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(this.width===void 0?"":Math.max(1,this.width|0))+(this.comma?",":"")+(this.precision===void 0?"":"."+Math.max(0,this.precision|0))+(this.trim?"~":"")+this.type};function XLe(t){e:for(var e=t.length,n=1,r=-1,i;n0&&(r=0);break}return r>0?t.slice(0,r)+t.slice(i+1):t}var TZ;function YLe(t,e){var n=Vw(t,e);if(!n)return t+"";var r=n[0],i=n[1],s=i-(TZ=Math.max(-8,Math.min(8,Math.floor(i/3)))*3)+1,a=r.length;return s===a?r:s>a?r+new Array(s-a+1).join("0"):s>0?r.slice(0,s)+"."+r.slice(s):"0."+new Array(1-s).join("0")+Vw(t,Math.max(0,e+s-1))[0]}function F$(t,e){var n=Vw(t,e);if(!n)return t+"";var r=n[0],i=n[1];return i<0?"0."+new Array(-i).join("0")+r:r.length>i+1?r.slice(0,i+1)+"."+r.slice(i+1):r+new Array(i-r.length+2).join("0")}const z$={"%":(t,e)=>(t*100).toFixed(e),b:t=>Math.round(t).toString(2),c:t=>t+"",d:GLe,e:(t,e)=>t.toExponential(e),f:(t,e)=>t.toFixed(e),g:(t,e)=>t.toPrecision(e),o:t=>Math.round(t).toString(8),p:(t,e)=>F$(t*100,e),r:F$,s:YLe,X:t=>Math.round(t).toString(16).toUpperCase(),x:t=>Math.round(t).toString(16)};function B$(t){return t}var H$=Array.prototype.map,$$=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function ZLe(t){var e=t.grouping===void 0||t.thousands===void 0?B$:WLe(H$.call(t.grouping,Number),t.thousands+""),n=t.currency===void 0?"":t.currency[0]+"",r=t.currency===void 0?"":t.currency[1]+"",i=t.decimal===void 0?".":t.decimal+"",s=t.numerals===void 0?B$:qLe(H$.call(t.numerals,String)),a=t.percent===void 0?"%":t.percent+"",o=t.minus===void 0?"−":t.minus+"",l=t.nan===void 0?"NaN":t.nan+"";function u(f){f=X0(f);var g=f.fill,m=f.align,x=f.sign,y=f.symbol,v=f.zero,b=f.width,E=f.comma,S=f.precision,A=f.trim,T=f.type;T==="n"?(E=!0,T="g"):z$[T]||(S===void 0&&(S=12),A=!0,T="g"),(v||g==="0"&&m==="=")&&(v=!0,g="0",m="=");var P=y==="$"?n:y==="#"&&/[boxX]/.test(T)?"0"+T.toLowerCase():"",C=y==="$"?r:/[%p]/.test(T)?a:"",I=z$[T],N=/[defgprs%]/.test(T);S=S===void 0?6:/[gprs]/.test(T)?Math.max(1,Math.min(21,S)):Math.max(0,Math.min(20,S));function D(F){var L=P,q=C,R,V,K;if(T==="c")q=I(F)+q,F="";else{F=+F;var W=F<0||1/F<0;if(F=isNaN(F)?l:I(Math.abs(F),S),A&&(F=XLe(F)),W&&+F==0&&x!=="+"&&(W=!1),L=(W?x==="("?x:o:x==="-"||x==="("?"":x)+L,q=(T==="s"?$$[8+TZ/3]:"")+q+(W&&x==="("?")":""),N){for(R=-1,V=F.length;++RK||K>57){q=(K===46?i+F.slice(R+1):F.slice(R))+q,F=F.slice(0,R);break}}}E&&!v&&(F=e(F,1/0));var ne=L.length+F.length+q.length,Y=ne>1)+L+F+q+Y.slice(ne);break;default:F=Y+L+F+q;break}return s(F)}return D.toString=function(){return f+""},D}function d(f,g){var m=u((f=X0(f),f.type="f",f)),x=Math.max(-8,Math.min(8,Math.floor(km(g)/3)))*3,y=Math.pow(10,-x),v=$$[8+x/3];return function(b){return m(y*b)+v}}return{format:u,formatPrefix:d}}var M_,MO,CZ;QLe({thousands:",",grouping:[3],currency:["$",""]});function QLe(t){return M_=ZLe(t),MO=M_.format,CZ=M_.formatPrefix,M_}function JLe(t){return Math.max(0,-km(Math.abs(t)))}function eIe(t,e){return Math.max(0,Math.max(-8,Math.min(8,Math.floor(km(e)/3)))*3-km(Math.abs(t)))}function tIe(t,e){return t=Math.abs(t),e=Math.abs(e)-t,Math.max(0,km(e)-km(t))+1}function NZ(t,e,n,r){var i=PP(t,e,n),s;switch(r=X0(r??",f"),r.type){case"s":{var a=Math.max(Math.abs(t),Math.abs(e));return r.precision==null&&!isNaN(s=eIe(i,a))&&(r.precision=s),CZ(r,a)}case"":case"e":case"g":case"p":case"r":{r.precision==null&&!isNaN(s=tIe(i,Math.max(Math.abs(t),Math.abs(e))))&&(r.precision=s-(r.type==="e"));break}case"f":case"%":{r.precision==null&&!isNaN(s=JLe(i))&&(r.precision=s-(r.type==="%")*2);break}}return MO(r)}function xd(t){var e=t.domain;return t.ticks=function(n){var r=e();return NP(r[0],r[r.length-1],n??10)},t.tickFormat=function(n,r){var i=e();return NZ(i[0],i[i.length-1],n??10,r)},t.nice=function(n){n==null&&(n=10);var r=e(),i=0,s=r.length-1,a=r[i],o=r[s],l,u,d=10;for(o0;){if(u=kP(a,o,n),u===l)return r[i]=a,r[s]=o,e(r);if(u>0)a=Math.floor(a/u)*u,o=Math.ceil(o/u)*u;else if(u<0)a=Math.ceil(a*u)/u,o=Math.floor(o*u)/u;else break;l=u}return t},t}function kZ(){var t=SO();return t.copy=function(){return Tb(t,kZ())},lo.apply(t,arguments),xd(t)}function PZ(t){var e;function n(r){return r==null||isNaN(r=+r)?e:r}return n.invert=n,n.domain=n.range=function(r){return arguments.length?(t=Array.from(r,$w),n):t.slice()},n.unknown=function(r){return arguments.length?(e=r,n):e},n.copy=function(){return PZ(t).unknown(e)},t=arguments.length?Array.from(t,$w):[0,1],xd(n)}function RZ(t,e){t=t.slice();var n=0,r=t.length-1,i=t[n],s=t[r],a;return sMath.pow(t,e)}function aIe(t){return t===Math.E?Math.log:t===10&&Math.log10||t===2&&Math.log2||(t=Math.log(t),e=>Math.log(e)/t)}function W$(t){return(e,n)=>-t(-e,n)}function AO(t){const e=t(V$,G$),n=e.domain;let r=10,i,s;function a(){return i=aIe(r),s=sIe(r),n()[0]<0?(i=W$(i),s=W$(s),t(nIe,rIe)):t(V$,G$),e}return e.base=function(o){return arguments.length?(r=+o,a()):r},e.domain=function(o){return arguments.length?(n(o),a()):n()},e.ticks=o=>{const l=n();let u=l[0],d=l[l.length-1];const f=d0){for(;g<=m;++g)for(x=1;xd)break;b.push(y)}}else for(;g<=m;++g)for(x=r-1;x>=1;--x)if(y=g>0?x/s(-g):x*s(g),!(yd)break;b.push(y)}b.length*2{if(o==null&&(o=10),l==null&&(l=r===10?"s":","),typeof l!="function"&&(!(r%1)&&(l=X0(l)).precision==null&&(l.trim=!0),l=MO(l)),o===1/0)return l;const u=Math.max(1,r*o/e.ticks().length);return d=>{let f=d/s(Math.round(i(d)));return f*rn(RZ(n(),{floor:o=>s(Math.floor(i(o))),ceil:o=>s(Math.ceil(i(o)))})),e}function DZ(){const t=AO(_E()).domain([1,10]);return t.copy=()=>Tb(t,DZ()).base(t.base()),lo.apply(t,arguments),t}function q$(t){return function(e){return Math.sign(e)*Math.log1p(Math.abs(e/t))}}function K$(t){return function(e){return Math.sign(e)*Math.expm1(Math.abs(e))*t}}function TO(t){var e=1,n=t(q$(e),K$(e));return n.constant=function(r){return arguments.length?t(q$(e=+r),K$(e)):e},xd(n)}function OZ(){var t=TO(_E());return t.copy=function(){return Tb(t,OZ()).constant(t.constant())},lo.apply(t,arguments)}function X$(t){return function(e){return e<0?-Math.pow(-e,t):Math.pow(e,t)}}function oIe(t){return t<0?-Math.sqrt(-t):Math.sqrt(t)}function lIe(t){return t<0?-t*t:t*t}function CO(t){var e=t(Ss,Ss),n=1;function r(){return n===1?t(Ss,Ss):n===.5?t(oIe,lIe):t(X$(n),X$(1/n))}return e.exponent=function(i){return arguments.length?(n=+i,r()):n},xd(e)}function NO(){var t=CO(_E());return t.copy=function(){return Tb(t,NO()).exponent(t.exponent())},lo.apply(t,arguments),t}function cIe(){return NO.apply(null,arguments).exponent(.5)}function Y$(t){return Math.sign(t)*t*t}function uIe(t){return Math.sign(t)*Math.sqrt(Math.abs(t))}function jZ(){var t=SO(),e=[0,1],n=!1,r;function i(s){var a=uIe(t(s));return isNaN(a)?r:n?Math.round(a):a}return i.invert=function(s){return t.invert(Y$(s))},i.domain=function(s){return arguments.length?(t.domain(s),i):t.domain()},i.range=function(s){return arguments.length?(t.range((e=Array.from(s,$w)).map(Y$)),i):e.slice()},i.rangeRound=function(s){return i.range(s).round(!0)},i.round=function(s){return arguments.length?(n=!!s,i):n},i.clamp=function(s){return arguments.length?(t.clamp(s),i):t.clamp()},i.unknown=function(s){return arguments.length?(r=s,i):r},i.copy=function(){return jZ(t.domain(),e).round(n).clamp(t.clamp()).unknown(r)},lo.apply(i,arguments),xd(i)}function LZ(){var t=[],e=[],n=[],r;function i(){var a=0,o=Math.max(1,e.length);for(n=new Array(o-1);++a0?n[o-1]:t[0],o=n?[r[n-1],e]:[r[u-1],r[u]]},a.unknown=function(l){return arguments.length&&(s=l),a},a.thresholds=function(){return r.slice()},a.copy=function(){return IZ().domain([t,e]).range(i).unknown(s)},lo.apply(xd(a),arguments)}function UZ(){var t=[.5],e=[0,1],n,r=1;function i(s){return s!=null&&s<=s?e[Mb(t,s,0,r)]:n}return i.domain=function(s){return arguments.length?(t=Array.from(s),r=Math.min(t.length,e.length-1),i):t.slice()},i.range=function(s){return arguments.length?(e=Array.from(s),r=Math.min(t.length,e.length-1),i):e.slice()},i.invertExtent=function(s){var a=e.indexOf(s);return[t[a-1],t[a]]},i.unknown=function(s){return arguments.length?(n=s,i):n},i.copy=function(){return UZ().domain(t).range(e).unknown(n)},lo.apply(i,arguments)}const bN=new Date,vN=new Date;function bi(t,e,n,r){function i(s){return t(s=arguments.length===0?new Date:new Date(+s)),s}return i.floor=s=>(t(s=new Date(+s)),s),i.ceil=s=>(t(s=new Date(s-1)),e(s,1),t(s),s),i.round=s=>{const a=i(s),o=i.ceil(s);return s-a(e(s=new Date(+s),a==null?1:Math.floor(a)),s),i.range=(s,a,o)=>{const l=[];if(s=i.ceil(s),o=o==null?1:Math.floor(o),!(s0))return l;let u;do l.push(u=new Date(+s)),e(s,o),t(s);while(ubi(a=>{if(a>=a)for(;t(a),!s(a);)a.setTime(a-1)},(a,o)=>{if(a>=a)if(o<0)for(;++o<=0;)for(;e(a,-1),!s(a););else for(;--o>=0;)for(;e(a,1),!s(a););}),n&&(i.count=(s,a)=>(bN.setTime(+s),vN.setTime(+a),t(bN),t(vN),Math.floor(n(bN,vN))),i.every=s=>(s=Math.floor(s),!isFinite(s)||!(s>0)?null:s>1?i.filter(r?a=>r(a)%s===0:a=>i.count(0,a)%s===0):i)),i}const Gw=bi(()=>{},(t,e)=>{t.setTime(+t+e)},(t,e)=>e-t);Gw.every=t=>(t=Math.floor(t),!isFinite(t)||!(t>0)?null:t>1?bi(e=>{e.setTime(Math.floor(e/t)*t)},(e,n)=>{e.setTime(+e+n*t)},(e,n)=>(n-e)/t):Gw);Gw.range;const cc=1e3,Qa=cc*60,uc=Qa*60,Ec=uc*24,kO=Ec*7,Z$=Ec*30,yN=Ec*365,dh=bi(t=>{t.setTime(t-t.getMilliseconds())},(t,e)=>{t.setTime(+t+e*cc)},(t,e)=>(e-t)/cc,t=>t.getUTCSeconds());dh.range;const PO=bi(t=>{t.setTime(t-t.getMilliseconds()-t.getSeconds()*cc)},(t,e)=>{t.setTime(+t+e*Qa)},(t,e)=>(e-t)/Qa,t=>t.getMinutes());PO.range;const RO=bi(t=>{t.setUTCSeconds(0,0)},(t,e)=>{t.setTime(+t+e*Qa)},(t,e)=>(e-t)/Qa,t=>t.getUTCMinutes());RO.range;const DO=bi(t=>{t.setTime(t-t.getMilliseconds()-t.getSeconds()*cc-t.getMinutes()*Qa)},(t,e)=>{t.setTime(+t+e*uc)},(t,e)=>(e-t)/uc,t=>t.getHours());DO.range;const OO=bi(t=>{t.setUTCMinutes(0,0,0)},(t,e)=>{t.setTime(+t+e*uc)},(t,e)=>(e-t)/uc,t=>t.getUTCHours());OO.range;const Cb=bi(t=>t.setHours(0,0,0,0),(t,e)=>t.setDate(t.getDate()+e),(t,e)=>(e-t-(e.getTimezoneOffset()-t.getTimezoneOffset())*Qa)/Ec,t=>t.getDate()-1);Cb.range;const wE=bi(t=>{t.setUTCHours(0,0,0,0)},(t,e)=>{t.setUTCDate(t.getUTCDate()+e)},(t,e)=>(e-t)/Ec,t=>t.getUTCDate()-1);wE.range;const FZ=bi(t=>{t.setUTCHours(0,0,0,0)},(t,e)=>{t.setUTCDate(t.getUTCDate()+e)},(t,e)=>(e-t)/Ec,t=>Math.floor(t/Ec));FZ.range;function af(t){return bi(e=>{e.setDate(e.getDate()-(e.getDay()+7-t)%7),e.setHours(0,0,0,0)},(e,n)=>{e.setDate(e.getDate()+n*7)},(e,n)=>(n-e-(n.getTimezoneOffset()-e.getTimezoneOffset())*Qa)/kO)}const SE=af(0),Ww=af(1),dIe=af(2),hIe=af(3),Pm=af(4),fIe=af(5),pIe=af(6);SE.range;Ww.range;dIe.range;hIe.range;Pm.range;fIe.range;pIe.range;function of(t){return bi(e=>{e.setUTCDate(e.getUTCDate()-(e.getUTCDay()+7-t)%7),e.setUTCHours(0,0,0,0)},(e,n)=>{e.setUTCDate(e.getUTCDate()+n*7)},(e,n)=>(n-e)/kO)}const EE=of(0),qw=of(1),mIe=of(2),gIe=of(3),Rm=of(4),xIe=of(5),bIe=of(6);EE.range;qw.range;mIe.range;gIe.range;Rm.range;xIe.range;bIe.range;const jO=bi(t=>{t.setDate(1),t.setHours(0,0,0,0)},(t,e)=>{t.setMonth(t.getMonth()+e)},(t,e)=>e.getMonth()-t.getMonth()+(e.getFullYear()-t.getFullYear())*12,t=>t.getMonth());jO.range;const LO=bi(t=>{t.setUTCDate(1),t.setUTCHours(0,0,0,0)},(t,e)=>{t.setUTCMonth(t.getUTCMonth()+e)},(t,e)=>e.getUTCMonth()-t.getUTCMonth()+(e.getUTCFullYear()-t.getUTCFullYear())*12,t=>t.getUTCMonth());LO.range;const Mc=bi(t=>{t.setMonth(0,1),t.setHours(0,0,0,0)},(t,e)=>{t.setFullYear(t.getFullYear()+e)},(t,e)=>e.getFullYear()-t.getFullYear(),t=>t.getFullYear());Mc.every=t=>!isFinite(t=Math.floor(t))||!(t>0)?null:bi(e=>{e.setFullYear(Math.floor(e.getFullYear()/t)*t),e.setMonth(0,1),e.setHours(0,0,0,0)},(e,n)=>{e.setFullYear(e.getFullYear()+n*t)});Mc.range;const Ac=bi(t=>{t.setUTCMonth(0,1),t.setUTCHours(0,0,0,0)},(t,e)=>{t.setUTCFullYear(t.getUTCFullYear()+e)},(t,e)=>e.getUTCFullYear()-t.getUTCFullYear(),t=>t.getUTCFullYear());Ac.every=t=>!isFinite(t=Math.floor(t))||!(t>0)?null:bi(e=>{e.setUTCFullYear(Math.floor(e.getUTCFullYear()/t)*t),e.setUTCMonth(0,1),e.setUTCHours(0,0,0,0)},(e,n)=>{e.setUTCFullYear(e.getUTCFullYear()+n*t)});Ac.range;function zZ(t,e,n,r,i,s){const a=[[dh,1,cc],[dh,5,5*cc],[dh,15,15*cc],[dh,30,30*cc],[s,1,Qa],[s,5,5*Qa],[s,15,15*Qa],[s,30,30*Qa],[i,1,uc],[i,3,3*uc],[i,6,6*uc],[i,12,12*uc],[r,1,Ec],[r,2,2*Ec],[n,1,kO],[e,1,Z$],[e,3,3*Z$],[t,1,yN]];function o(u,d,f){const g=dv).right(a,g);if(m===a.length)return t.every(PP(u/yN,d/yN,f));if(m===0)return Gw.every(Math.max(PP(u,d,f),1));const[x,y]=a[g/a[m-1][2]53)return null;"w"in de||(de.w=1),"Z"in de?(H=wN(xx(de.y,0,1)),z=H.getUTCDay(),H=z>4||z===0?qw.ceil(H):qw(H),H=wE.offset(H,(de.V-1)*7),de.y=H.getUTCFullYear(),de.m=H.getUTCMonth(),de.d=H.getUTCDate()+(de.w+6)%7):(H=_N(xx(de.y,0,1)),z=H.getDay(),H=z>4||z===0?Ww.ceil(H):Ww(H),H=Cb.offset(H,(de.V-1)*7),de.y=H.getFullYear(),de.m=H.getMonth(),de.d=H.getDate()+(de.w+6)%7)}else("W"in de||"U"in de)&&("w"in de||(de.w="u"in de?de.u%7:"W"in de?1:0),z="Z"in de?wN(xx(de.y,0,1)).getUTCDay():_N(xx(de.y,0,1)).getDay(),de.m=0,de.d="W"in de?(de.w+6)%7+de.W*7-(z+5)%7:de.w+de.U*7-(z+6)%7);return"Z"in de?(de.H+=de.Z/100|0,de.M+=de.Z%100,wN(de)):_N(de)}}function I(se,ve,je,de){for(var ut=0,H=ve.length,z=je.length,re,G;ut=z)return-1;if(re=ve.charCodeAt(ut++),re===37){if(re=ve.charAt(ut++),G=T[re in Q$?ve.charAt(ut++):re],!G||(de=G(se,je,de))<0)return-1}else if(re!=je.charCodeAt(de++))return-1}return de}function N(se,ve,je){var de=u.exec(ve.slice(je));return de?(se.p=d.get(de[0].toLowerCase()),je+de[0].length):-1}function D(se,ve,je){var de=m.exec(ve.slice(je));return de?(se.w=x.get(de[0].toLowerCase()),je+de[0].length):-1}function F(se,ve,je){var de=f.exec(ve.slice(je));return de?(se.w=g.get(de[0].toLowerCase()),je+de[0].length):-1}function L(se,ve,je){var de=b.exec(ve.slice(je));return de?(se.m=E.get(de[0].toLowerCase()),je+de[0].length):-1}function q(se,ve,je){var de=y.exec(ve.slice(je));return de?(se.m=v.get(de[0].toLowerCase()),je+de[0].length):-1}function R(se,ve,je){return I(se,e,ve,je)}function V(se,ve,je){return I(se,n,ve,je)}function K(se,ve,je){return I(se,r,ve,je)}function W(se){return a[se.getDay()]}function ne(se){return s[se.getDay()]}function Y(se){return l[se.getMonth()]}function Z(se){return o[se.getMonth()]}function U(se){return i[+(se.getHours()>=12)]}function $(se){return 1+~~(se.getMonth()/3)}function ee(se){return a[se.getUTCDay()]}function ae(se){return s[se.getUTCDay()]}function fe(se){return l[se.getUTCMonth()]}function ue(se){return o[se.getUTCMonth()]}function xe(se){return i[+(se.getUTCHours()>=12)]}function Me(se){return 1+~~(se.getUTCMonth()/3)}return{format:function(se){var ve=P(se+="",S);return ve.toString=function(){return se},ve},parse:function(se){var ve=C(se+="",!1);return ve.toString=function(){return se},ve},utcFormat:function(se){var ve=P(se+="",A);return ve.toString=function(){return se},ve},utcParse:function(se){var ve=C(se+="",!0);return ve.toString=function(){return se},ve}}}var Q$={"-":"",_:" ",0:"0"},Li=/^\s*\d+/,EIe=/^%/,MIe=/[\\^$*+?|[\]().{}]/g;function Cn(t,e,n){var r=t<0?"-":"",i=(r?-t:t)+"",s=i.length;return r+(s[e.toLowerCase(),n]))}function TIe(t,e,n){var r=Li.exec(e.slice(n,n+1));return r?(t.w=+r[0],n+r[0].length):-1}function CIe(t,e,n){var r=Li.exec(e.slice(n,n+1));return r?(t.u=+r[0],n+r[0].length):-1}function NIe(t,e,n){var r=Li.exec(e.slice(n,n+2));return r?(t.U=+r[0],n+r[0].length):-1}function kIe(t,e,n){var r=Li.exec(e.slice(n,n+2));return r?(t.V=+r[0],n+r[0].length):-1}function PIe(t,e,n){var r=Li.exec(e.slice(n,n+2));return r?(t.W=+r[0],n+r[0].length):-1}function J$(t,e,n){var r=Li.exec(e.slice(n,n+4));return r?(t.y=+r[0],n+r[0].length):-1}function eV(t,e,n){var r=Li.exec(e.slice(n,n+2));return r?(t.y=+r[0]+(+r[0]>68?1900:2e3),n+r[0].length):-1}function RIe(t,e,n){var r=/^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(e.slice(n,n+6));return r?(t.Z=r[1]?0:-(r[2]+(r[3]||"00")),n+r[0].length):-1}function DIe(t,e,n){var r=Li.exec(e.slice(n,n+1));return r?(t.q=r[0]*3-3,n+r[0].length):-1}function OIe(t,e,n){var r=Li.exec(e.slice(n,n+2));return r?(t.m=r[0]-1,n+r[0].length):-1}function tV(t,e,n){var r=Li.exec(e.slice(n,n+2));return r?(t.d=+r[0],n+r[0].length):-1}function jIe(t,e,n){var r=Li.exec(e.slice(n,n+3));return r?(t.m=0,t.d=+r[0],n+r[0].length):-1}function nV(t,e,n){var r=Li.exec(e.slice(n,n+2));return r?(t.H=+r[0],n+r[0].length):-1}function LIe(t,e,n){var r=Li.exec(e.slice(n,n+2));return r?(t.M=+r[0],n+r[0].length):-1}function IIe(t,e,n){var r=Li.exec(e.slice(n,n+2));return r?(t.S=+r[0],n+r[0].length):-1}function UIe(t,e,n){var r=Li.exec(e.slice(n,n+3));return r?(t.L=+r[0],n+r[0].length):-1}function FIe(t,e,n){var r=Li.exec(e.slice(n,n+6));return r?(t.L=Math.floor(r[0]/1e3),n+r[0].length):-1}function zIe(t,e,n){var r=EIe.exec(e.slice(n,n+1));return r?n+r[0].length:-1}function BIe(t,e,n){var r=Li.exec(e.slice(n));return r?(t.Q=+r[0],n+r[0].length):-1}function HIe(t,e,n){var r=Li.exec(e.slice(n));return r?(t.s=+r[0],n+r[0].length):-1}function rV(t,e){return Cn(t.getDate(),e,2)}function $Ie(t,e){return Cn(t.getHours(),e,2)}function VIe(t,e){return Cn(t.getHours()%12||12,e,2)}function GIe(t,e){return Cn(1+Cb.count(Mc(t),t),e,3)}function BZ(t,e){return Cn(t.getMilliseconds(),e,3)}function WIe(t,e){return BZ(t,e)+"000"}function qIe(t,e){return Cn(t.getMonth()+1,e,2)}function KIe(t,e){return Cn(t.getMinutes(),e,2)}function XIe(t,e){return Cn(t.getSeconds(),e,2)}function YIe(t){var e=t.getDay();return e===0?7:e}function ZIe(t,e){return Cn(SE.count(Mc(t)-1,t),e,2)}function HZ(t){var e=t.getDay();return e>=4||e===0?Pm(t):Pm.ceil(t)}function QIe(t,e){return t=HZ(t),Cn(Pm.count(Mc(t),t)+(Mc(t).getDay()===4),e,2)}function JIe(t){return t.getDay()}function e4e(t,e){return Cn(Ww.count(Mc(t)-1,t),e,2)}function t4e(t,e){return Cn(t.getFullYear()%100,e,2)}function n4e(t,e){return t=HZ(t),Cn(t.getFullYear()%100,e,2)}function r4e(t,e){return Cn(t.getFullYear()%1e4,e,4)}function i4e(t,e){var n=t.getDay();return t=n>=4||n===0?Pm(t):Pm.ceil(t),Cn(t.getFullYear()%1e4,e,4)}function s4e(t){var e=t.getTimezoneOffset();return(e>0?"-":(e*=-1,"+"))+Cn(e/60|0,"0",2)+Cn(e%60,"0",2)}function iV(t,e){return Cn(t.getUTCDate(),e,2)}function a4e(t,e){return Cn(t.getUTCHours(),e,2)}function o4e(t,e){return Cn(t.getUTCHours()%12||12,e,2)}function l4e(t,e){return Cn(1+wE.count(Ac(t),t),e,3)}function $Z(t,e){return Cn(t.getUTCMilliseconds(),e,3)}function c4e(t,e){return $Z(t,e)+"000"}function u4e(t,e){return Cn(t.getUTCMonth()+1,e,2)}function d4e(t,e){return Cn(t.getUTCMinutes(),e,2)}function h4e(t,e){return Cn(t.getUTCSeconds(),e,2)}function f4e(t){var e=t.getUTCDay();return e===0?7:e}function p4e(t,e){return Cn(EE.count(Ac(t)-1,t),e,2)}function VZ(t){var e=t.getUTCDay();return e>=4||e===0?Rm(t):Rm.ceil(t)}function m4e(t,e){return t=VZ(t),Cn(Rm.count(Ac(t),t)+(Ac(t).getUTCDay()===4),e,2)}function g4e(t){return t.getUTCDay()}function x4e(t,e){return Cn(qw.count(Ac(t)-1,t),e,2)}function b4e(t,e){return Cn(t.getUTCFullYear()%100,e,2)}function v4e(t,e){return t=VZ(t),Cn(t.getUTCFullYear()%100,e,2)}function y4e(t,e){return Cn(t.getUTCFullYear()%1e4,e,4)}function _4e(t,e){var n=t.getUTCDay();return t=n>=4||n===0?Rm(t):Rm.ceil(t),Cn(t.getUTCFullYear()%1e4,e,4)}function w4e(){return"+0000"}function sV(){return"%"}function aV(t){return+t}function oV(t){return Math.floor(+t/1e3)}var Sp,GZ,WZ;S4e({dateTime:"%x, %X",date:"%-m/%-d/%Y",time:"%-I:%M:%S %p",periods:["AM","PM"],days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]});function S4e(t){return Sp=SIe(t),GZ=Sp.format,Sp.parse,WZ=Sp.utcFormat,Sp.utcParse,Sp}function E4e(t){return new Date(t)}function M4e(t){return t instanceof Date?+t:+new Date(+t)}function IO(t,e,n,r,i,s,a,o,l,u){var d=SO(),f=d.invert,g=d.domain,m=u(".%L"),x=u(":%S"),y=u("%I:%M"),v=u("%I %p"),b=u("%a %d"),E=u("%b %d"),S=u("%B"),A=u("%Y");function T(P){return(l(P)e(i/(t.length-1)))},n.quantiles=function(r){return Array.from({length:r+1},(i,s)=>fLe(t,s/r))},n.copy=function(){return YZ(e).domain(t)},Dc.apply(n,arguments)}function AE(){var t=0,e=.5,n=1,r=1,i,s,a,o,l,u=Ss,d,f=!1,g;function m(y){return isNaN(y=+y)?g:(y=.5+((y=+d(y))-s)*(r*yt.chartData,zO=Ke([vd],t=>{var e=t.chartData!=null?t.chartData.length-1:0;return{chartData:t.chartData,computedData:t.computedData,dataEndIndex:e,dataStartIndex:0}}),TE=(t,e,n,r)=>r?zO(t):vd(t);function ad(t){if(Array.isArray(t)&&t.length===2){var[e,n]=t;if(ur(e)&&ur(n))return!0}return!1}function lV(t,e,n){return n?t:[Math.min(t[0],e[0]),Math.max(t[1],e[1])]}function eQ(t,e){if(e&&typeof t!="function"&&Array.isArray(t)&&t.length===2){var[n,r]=t,i,s;if(ur(n))i=n;else if(typeof n=="function")return;if(ur(r))s=r;else if(typeof r=="function")return;var a=[i,s];if(ad(a))return a}}function k4e(t,e,n){if(!(!n&&e==null)){if(typeof t=="function"&&e!=null)try{var r=t(e,n);if(ad(r))return lV(r,e,n)}catch{}if(Array.isArray(t)&&t.length===2){var[i,s]=t,a,o;if(i==="auto")e!=null&&(a=Math.min(...e));else if(Ct(i))a=i;else if(typeof i=="function")try{e!=null&&(a=i(e?.[0]))}catch{}else if(typeof i=="string"&&LH.test(i)){var l=LH.exec(i);if(l==null||e==null)a=void 0;else{var u=+l[1];a=e[0]-u}}else a=e?.[0];if(s==="auto")e!=null&&(o=Math.max(...e));else if(Ct(s))o=s;else if(typeof s=="function")try{e!=null&&(o=s(e?.[1]))}catch{}else if(typeof s=="string"&&IH.test(s)){var d=IH.exec(s);if(d==null||e==null)o=void 0;else{var f=+d[1];o=e[1]+f}}else o=e?.[1];var g=[a,o];if(ad(g))return e==null?g:lV(g,e,n)}}}var Zm=1e9,P4e={precision:20,rounding:4,toExpNeg:-7,toExpPos:21,LN10:"2.302585092994045684017991454684364207601101488628772976033327900967572609677352480235997205089598298341967784042286"},HO,mr=!0,ao="[DecimalError] ",Ah=ao+"Invalid argument: ",BO=ao+"Exponent out of range: ",Qm=Math.floor,Zd=Math.pow,R4e=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,fa,ki=1e7,lr=7,tQ=9007199254740991,Kw=Qm(tQ/lr),Pt={};Pt.absoluteValue=Pt.abs=function(){var t=new this.constructor(this);return t.s&&(t.s=1),t};Pt.comparedTo=Pt.cmp=function(t){var e,n,r,i,s=this;if(t=new s.constructor(t),s.s!==t.s)return s.s||-t.s;if(s.e!==t.e)return s.e>t.e^s.s<0?1:-1;for(r=s.d.length,i=t.d.length,e=0,n=rt.d[e]^s.s<0?1:-1;return r===i?0:r>i^s.s<0?1:-1};Pt.decimalPlaces=Pt.dp=function(){var t=this,e=t.d.length-1,n=(e-t.e)*lr;if(e=t.d[e],e)for(;e%10==0;e/=10)n--;return n<0?0:n};Pt.dividedBy=Pt.div=function(t){return xc(this,new this.constructor(t))};Pt.dividedToIntegerBy=Pt.idiv=function(t){var e=this,n=e.constructor;return Jn(xc(e,new n(t),0,1),n.precision)};Pt.equals=Pt.eq=function(t){return!this.cmp(t)};Pt.exponent=function(){return ei(this)};Pt.greaterThan=Pt.gt=function(t){return this.cmp(t)>0};Pt.greaterThanOrEqualTo=Pt.gte=function(t){return this.cmp(t)>=0};Pt.isInteger=Pt.isint=function(){return this.e>this.d.length-2};Pt.isNegative=Pt.isneg=function(){return this.s<0};Pt.isPositive=Pt.ispos=function(){return this.s>0};Pt.isZero=function(){return this.s===0};Pt.lessThan=Pt.lt=function(t){return this.cmp(t)<0};Pt.lessThanOrEqualTo=Pt.lte=function(t){return this.cmp(t)<1};Pt.logarithm=Pt.log=function(t){var e,n=this,r=n.constructor,i=r.precision,s=i+5;if(t===void 0)t=new r(10);else if(t=new r(t),t.s<1||t.eq(fa))throw Error(ao+"NaN");if(n.s<1)throw Error(ao+(n.s?"NaN":"-Infinity"));return n.eq(fa)?new r(0):(mr=!1,e=xc(Y0(n,s),Y0(t,s),s),mr=!0,Jn(e,i))};Pt.minus=Pt.sub=function(t){var e=this;return t=new e.constructor(t),e.s==t.s?iQ(e,t):nQ(e,(t.s=-t.s,t))};Pt.modulo=Pt.mod=function(t){var e,n=this,r=n.constructor,i=r.precision;if(t=new r(t),!t.s)throw Error(ao+"NaN");return n.s?(mr=!1,e=xc(n,t,0,1).times(t),mr=!0,n.minus(e)):Jn(new r(n),i)};Pt.naturalExponential=Pt.exp=function(){return rQ(this)};Pt.naturalLogarithm=Pt.ln=function(){return Y0(this)};Pt.negated=Pt.neg=function(){var t=new this.constructor(this);return t.s=-t.s||0,t};Pt.plus=Pt.add=function(t){var e=this;return t=new e.constructor(t),e.s==t.s?nQ(e,t):iQ(e,(t.s=-t.s,t))};Pt.precision=Pt.sd=function(t){var e,n,r,i=this;if(t!==void 0&&t!==!!t&&t!==1&&t!==0)throw Error(Ah+t);if(e=ei(i)+1,r=i.d.length-1,n=r*lr+1,r=i.d[r],r){for(;r%10==0;r/=10)n--;for(r=i.d[0];r>=10;r/=10)n++}return t&&e>n?e:n};Pt.squareRoot=Pt.sqrt=function(){var t,e,n,r,i,s,a,o=this,l=o.constructor;if(o.s<1){if(!o.s)return new l(0);throw Error(ao+"NaN")}for(t=ei(o),mr=!1,i=Math.sqrt(+o),i==0||i==1/0?(e=il(o.d),(e.length+t)%2==0&&(e+="0"),i=Math.sqrt(e),t=Qm((t+1)/2)-(t<0||t%2),i==1/0?e="5e"+t:(e=i.toExponential(),e=e.slice(0,e.indexOf("e")+1)+t),r=new l(e)):r=new l(i.toString()),n=l.precision,i=a=n+3;;)if(s=r,r=s.plus(xc(o,s,a+2)).times(.5),il(s.d).slice(0,a)===(e=il(r.d)).slice(0,a)){if(e=e.slice(a-3,a+1),i==a&&e=="4999"){if(Jn(s,n+1,0),s.times(s).eq(o)){r=s;break}}else if(e!="9999")break;a+=4}return mr=!0,Jn(r,n)};Pt.times=Pt.mul=function(t){var e,n,r,i,s,a,o,l,u,d=this,f=d.constructor,g=d.d,m=(t=new f(t)).d;if(!d.s||!t.s)return new f(0);for(t.s*=d.s,n=d.e+t.e,l=g.length,u=m.length,l=0;){for(e=0,i=l+r;i>r;)o=s[i]+m[r]*g[i-r-1]+e,s[i--]=o%ki|0,e=o/ki|0;s[i]=(s[i]+e)%ki|0}for(;!s[--a];)s.pop();return e?++n:s.shift(),t.d=s,t.e=n,mr?Jn(t,f.precision):t};Pt.toDecimalPlaces=Pt.todp=function(t,e){var n=this,r=n.constructor;return n=new r(n),t===void 0?n:(ml(t,0,Zm),e===void 0?e=r.rounding:ml(e,0,8),Jn(n,t+ei(n)+1,e))};Pt.toExponential=function(t,e){var n,r=this,i=r.constructor;return t===void 0?n=Zh(r,!0):(ml(t,0,Zm),e===void 0?e=i.rounding:ml(e,0,8),r=Jn(new i(r),t+1,e),n=Zh(r,!0,t+1)),n};Pt.toFixed=function(t,e){var n,r,i=this,s=i.constructor;return t===void 0?Zh(i):(ml(t,0,Zm),e===void 0?e=s.rounding:ml(e,0,8),r=Jn(new s(i),t+ei(i)+1,e),n=Zh(r.abs(),!1,t+ei(r)+1),i.isneg()&&!i.isZero()?"-"+n:n)};Pt.toInteger=Pt.toint=function(){var t=this,e=t.constructor;return Jn(new e(t),ei(t)+1,e.rounding)};Pt.toNumber=function(){return+this};Pt.toPower=Pt.pow=function(t){var e,n,r,i,s,a,o=this,l=o.constructor,u=12,d=+(t=new l(t));if(!t.s)return new l(fa);if(o=new l(o),!o.s){if(t.s<1)throw Error(ao+"Infinity");return o}if(o.eq(fa))return o;if(r=l.precision,t.eq(fa))return Jn(o,r);if(e=t.e,n=t.d.length-1,a=e>=n,s=o.s,a){if((n=d<0?-d:d)<=tQ){for(i=new l(fa),e=Math.ceil(r/lr+4),mr=!1;n%2&&(i=i.times(o),uV(i.d,e)),n=Qm(n/2),n!==0;)o=o.times(o),uV(o.d,e);return mr=!0,t.s<0?new l(fa).div(i):Jn(i,r)}}else if(s<0)throw Error(ao+"NaN");return s=s<0&&t.d[Math.max(e,n)]&1?-1:1,o.s=1,mr=!1,i=t.times(Y0(o,r+u)),mr=!0,i=rQ(i),i.s=s,i};Pt.toPrecision=function(t,e){var n,r,i=this,s=i.constructor;return t===void 0?(n=ei(i),r=Zh(i,n<=s.toExpNeg||n>=s.toExpPos)):(ml(t,1,Zm),e===void 0?e=s.rounding:ml(e,0,8),i=Jn(new s(i),t,e),n=ei(i),r=Zh(i,t<=n||n<=s.toExpNeg,t)),r};Pt.toSignificantDigits=Pt.tosd=function(t,e){var n=this,r=n.constructor;return t===void 0?(t=r.precision,e=r.rounding):(ml(t,1,Zm),e===void 0?e=r.rounding:ml(e,0,8)),Jn(new r(n),t,e)};Pt.toString=Pt.valueOf=Pt.val=Pt.toJSON=Pt[Symbol.for("nodejs.util.inspect.custom")]=function(){var t=this,e=ei(t),n=t.constructor;return Zh(t,e<=n.toExpNeg||e>=n.toExpPos)};function nQ(t,e){var n,r,i,s,a,o,l,u,d=t.constructor,f=d.precision;if(!t.s||!e.s)return e.s||(e=new d(t)),mr?Jn(e,f):e;if(l=t.d,u=e.d,a=t.e,i=e.e,l=l.slice(),s=a-i,s){for(s<0?(r=l,s=-s,o=u.length):(r=u,i=a,o=l.length),a=Math.ceil(f/lr),o=a>o?a+1:o+1,s>o&&(s=o,r.length=1),r.reverse();s--;)r.push(0);r.reverse()}for(o=l.length,s=u.length,o-s<0&&(s=o,r=u,u=l,l=r),n=0;s;)n=(l[--s]=l[s]+u[s]+n)/ki|0,l[s]%=ki;for(n&&(l.unshift(n),++i),o=l.length;l[--o]==0;)l.pop();return e.d=l,e.e=i,mr?Jn(e,f):e}function ml(t,e,n){if(t!==~~t||tn)throw Error(Ah+t)}function il(t){var e,n,r,i=t.length-1,s="",a=t[0];if(i>0){for(s+=a,e=1;ea?1:-1;else for(o=l=0;oi[o]?1:-1;break}return l}function n(r,i,s){for(var a=0;s--;)r[s]-=a,a=r[s]1;)r.shift()}return function(r,i,s,a){var o,l,u,d,f,g,m,x,y,v,b,E,S,A,T,P,C,I,N=r.constructor,D=r.s==i.s?1:-1,F=r.d,L=i.d;if(!r.s)return new N(r);if(!i.s)throw Error(ao+"Division by zero");for(l=r.e-i.e,C=L.length,T=F.length,m=new N(D),x=m.d=[],u=0;L[u]==(F[u]||0);)++u;if(L[u]>(F[u]||0)&&--l,s==null?E=s=N.precision:a?E=s+(ei(r)-ei(i))+1:E=s,E<0)return new N(0);if(E=E/lr+2|0,u=0,C==1)for(d=0,L=L[0],E++;(u1&&(L=t(L,d),F=t(F,d),C=L.length,T=F.length),A=C,y=F.slice(0,C),v=y.length;v=ki/2&&++P;do d=0,o=e(L,y,C,v),o<0?(b=y[0],C!=v&&(b=b*ki+(y[1]||0)),d=b/P|0,d>1?(d>=ki&&(d=ki-1),f=t(L,d),g=f.length,v=y.length,o=e(f,y,g,v),o==1&&(d--,n(f,C16)throw Error(BO+ei(t));if(!t.s)return new d(fa);for(mr=!1,o=f,a=new d(.03125);t.abs().gte(.1);)t=t.times(a),u+=5;for(r=Math.log(Zd(2,u))/Math.LN10*2+5|0,o+=r,n=i=s=new d(fa),d.precision=o;;){if(i=Jn(i.times(t),o),n=n.times(++l),a=s.plus(xc(i,n,o)),il(a.d).slice(0,o)===il(s.d).slice(0,o)){for(;u--;)s=Jn(s.times(s),o);return d.precision=f,e==null?(mr=!0,Jn(s,f)):s}s=a}}function ei(t){for(var e=t.e*lr,n=t.d[0];n>=10;n/=10)e++;return e}function SN(t,e,n){if(e>t.LN10.sd())throw mr=!0,n&&(t.precision=n),Error(ao+"LN10 precision limit exceeded");return Jn(new t(t.LN10),e)}function Cu(t){for(var e="";t--;)e+="0";return e}function Y0(t,e){var n,r,i,s,a,o,l,u,d,f=1,g=10,m=t,x=m.d,y=m.constructor,v=y.precision;if(m.s<1)throw Error(ao+(m.s?"NaN":"-Infinity"));if(m.eq(fa))return new y(0);if(e==null?(mr=!1,u=v):u=e,m.eq(10))return e==null&&(mr=!0),SN(y,u);if(u+=g,y.precision=u,n=il(x),r=n.charAt(0),s=ei(m),Math.abs(s)<15e14){for(;r<7&&r!=1||r==1&&n.charAt(1)>3;)m=m.times(t),n=il(m.d),r=n.charAt(0),f++;s=ei(m),r>1?(m=new y("0."+n),s++):m=new y(r+"."+n.slice(1))}else return l=SN(y,u+2,v).times(s+""),m=Y0(new y(r+"."+n.slice(1)),u-g).plus(l),y.precision=v,e==null?(mr=!0,Jn(m,v)):m;for(o=a=m=xc(m.minus(fa),m.plus(fa),u),d=Jn(m.times(m),u),i=3;;){if(a=Jn(a.times(d),u),l=o.plus(xc(a,new y(i),u)),il(l.d).slice(0,u)===il(o.d).slice(0,u))return o=o.times(2),s!==0&&(o=o.plus(SN(y,u+2,v).times(s+""))),o=xc(o,new y(f),u),y.precision=v,e==null?(mr=!0,Jn(o,v)):o;o=l,i+=2}}function cV(t,e){var n,r,i;for((n=e.indexOf("."))>-1&&(e=e.replace(".","")),(r=e.search(/e/i))>0?(n<0&&(n=r),n+=+e.slice(r+1),e=e.substring(0,r)):n<0&&(n=e.length),r=0;e.charCodeAt(r)===48;)++r;for(i=e.length;e.charCodeAt(i-1)===48;)--i;if(e=e.slice(r,i),e){if(i-=r,n=n-r-1,t.e=Qm(n/lr),t.d=[],r=(n+1)%lr,n<0&&(r+=lr),rKw||t.e<-Kw))throw Error(BO+n)}else t.s=0,t.e=0,t.d=[0];return t}function Jn(t,e,n){var r,i,s,a,o,l,u,d,f=t.d;for(a=1,s=f[0];s>=10;s/=10)a++;if(r=e-a,r<0)r+=lr,i=e,u=f[d=0];else{if(d=Math.ceil((r+1)/lr),s=f.length,d>=s)return t;for(u=s=f[d],a=1;s>=10;s/=10)a++;r%=lr,i=r-lr+a}if(n!==void 0&&(s=Zd(10,a-i-1),o=u/s%10|0,l=e<0||f[d+1]!==void 0||u%s,l=n<4?(o||l)&&(n==0||n==(t.s<0?3:2)):o>5||o==5&&(n==4||l||n==6&&(r>0?i>0?u/Zd(10,a-i):0:f[d-1])%10&1||n==(t.s<0?8:7))),e<1||!f[0])return l?(s=ei(t),f.length=1,e=e-s-1,f[0]=Zd(10,(lr-e%lr)%lr),t.e=Qm(-e/lr)||0):(f.length=1,f[0]=t.e=t.s=0),t;if(r==0?(f.length=d,s=1,d--):(f.length=d+1,s=Zd(10,lr-r),f[d]=i>0?(u/Zd(10,a-i)%Zd(10,i)|0)*s:0),l)for(;;)if(d==0){(f[0]+=s)==ki&&(f[0]=1,++t.e);break}else{if(f[d]+=s,f[d]!=ki)break;f[d--]=0,s=1}for(r=f.length;f[--r]===0;)f.pop();if(mr&&(t.e>Kw||t.e<-Kw))throw Error(BO+ei(t));return t}function iQ(t,e){var n,r,i,s,a,o,l,u,d,f,g=t.constructor,m=g.precision;if(!t.s||!e.s)return e.s?e.s=-e.s:e=new g(t),mr?Jn(e,m):e;if(l=t.d,f=e.d,r=e.e,u=t.e,l=l.slice(),a=u-r,a){for(d=a<0,d?(n=l,a=-a,o=f.length):(n=f,r=u,o=l.length),i=Math.max(Math.ceil(m/lr),o)+2,a>i&&(a=i,n.length=1),n.reverse(),i=a;i--;)n.push(0);n.reverse()}else{for(i=l.length,o=f.length,d=i0;--i)l[o++]=0;for(i=f.length;i>a;){if(l[--i]0?s=s.charAt(0)+"."+s.slice(1)+Cu(r):a>1&&(s=s.charAt(0)+"."+s.slice(1)),s=s+(i<0?"e":"e+")+i):i<0?(s="0."+Cu(-i-1)+s,n&&(r=n-a)>0&&(s+=Cu(r))):i>=a?(s+=Cu(i+1-a),n&&(r=n-i-1)>0&&(s=s+"."+Cu(r))):((r=i+1)0&&(i+1===a&&(s+="."),s+=Cu(r))),t.s<0?"-"+s:s}function uV(t,e){if(t.length>e)return t.length=e,!0}function sQ(t){var e,n,r;function i(s){var a=this;if(!(a instanceof i))return new i(s);if(a.constructor=i,s instanceof i){a.s=s.s,a.e=s.e,a.d=(s=s.d)?s.slice():s;return}if(typeof s=="number"){if(s*0!==0)throw Error(Ah+s);if(s>0)a.s=1;else if(s<0)s=-s,a.s=-1;else{a.s=0,a.e=0,a.d=[0];return}if(s===~~s&&s<1e7){a.e=0,a.d=[s];return}return cV(a,s.toString())}else if(typeof s!="string")throw Error(Ah+s);if(s.charCodeAt(0)===45?(s=s.slice(1),a.s=-1):a.s=1,R4e.test(s))cV(a,s);else throw Error(Ah+s)}if(i.prototype=Pt,i.ROUND_UP=0,i.ROUND_DOWN=1,i.ROUND_CEIL=2,i.ROUND_FLOOR=3,i.ROUND_HALF_UP=4,i.ROUND_HALF_DOWN=5,i.ROUND_HALF_EVEN=6,i.ROUND_HALF_CEIL=7,i.ROUND_HALF_FLOOR=8,i.clone=sQ,i.config=i.set=D4e,t===void 0&&(t={}),t)for(r=["precision","rounding","toExpNeg","toExpPos","LN10"],e=0;e=i[e+1]&&r<=i[e+2])this[n]=r;else throw Error(Ah+n+": "+r);if((r=t[n="LN10"])!==void 0)if(r==Math.LN10)this[n]=new this(r);else throw Error(Ah+n+": "+r);return this}var HO=sQ(P4e);fa=new HO(1);const In=HO;var O4e=t=>t,aQ={},oQ=t=>t===aQ,dV=t=>function e(){return arguments.length===0||arguments.length===1&&oQ(arguments.length<=0?void 0:arguments[0])?e:t(...arguments)},lQ=(t,e)=>t===1?e:dV(function(){for(var n=arguments.length,r=new Array(n),i=0;ia!==aQ).length;return s>=t?e(...r):lQ(t-s,dV(function(){for(var a=arguments.length,o=new Array(a),l=0;loQ(d)?o.shift():d);return e(...u,...o)}))}),j4e=t=>lQ(t.length,t),LP=(t,e)=>{for(var n=[],r=t;rArray.isArray(e)?e.map(t):Object.keys(e).map(n=>e[n]).map(t)),I4e=function(){for(var e=arguments.length,n=new Array(e),r=0;rl(o),s(...arguments))}},IP=t=>Array.isArray(t)?t.reverse():t.split("").reverse().join("");function cQ(t){var e;return t===0?e=1:e=Math.floor(new In(t).abs().log(10).toNumber())+1,e}function uQ(t,e,n){for(var r=new In(t),i=0,s=[];r.lt(e)&&i<1e5;)s.push(r.toNumber()),r=r.add(n),i++;return s}var dQ=t=>{var[e,n]=t,[r,i]=[e,n];return e>n&&([r,i]=[n,e]),[r,i]},hQ=(t,e,n)=>{if(t.lte(0))return new In(0);var r=cQ(t.toNumber()),i=new In(10).pow(r),s=t.div(i),a=r!==1?.05:.1,o=new In(Math.ceil(s.div(a).toNumber())).add(n).mul(a),l=o.mul(i);return e?new In(l.toNumber()):new In(Math.ceil(l.toNumber()))},U4e=(t,e,n)=>{var r=new In(1),i=new In(t);if(!i.isint()&&n){var s=Math.abs(t);s<1?(r=new In(10).pow(cQ(t)-1),i=new In(Math.floor(i.div(r).toNumber())).mul(r)):s>1&&(i=new In(Math.floor(t)))}else t===0?i=new In(Math.floor((e-1)/2)):n||(i=new In(Math.floor(t)));var a=Math.floor((e-1)/2),o=I4e(L4e(l=>i.add(new In(l-a).mul(r)).toNumber()),LP);return o(0,e)},fQ=function(e,n,r,i){var s=arguments.length>4&&arguments[4]!==void 0?arguments[4]:0;if(!Number.isFinite((n-e)/(r-1)))return{step:new In(0),tickMin:new In(0),tickMax:new In(0)};var a=hQ(new In(n).sub(e).div(r-1),i,s),o;e<=0&&n>=0?o=new In(0):(o=new In(e).add(n).div(2),o=o.sub(new In(o).mod(a)));var l=Math.ceil(o.sub(e).div(a).toNumber()),u=Math.ceil(new In(n).sub(o).div(a).toNumber()),d=l+u+1;return d>r?fQ(e,n,r,i,s+1):(d0?u+(r-d):u,l=n>0?l:l+(r-d)),{step:a,tickMin:o.sub(new In(l).mul(a)),tickMax:o.add(new In(u).mul(a))})},F4e=function(e){var[n,r]=e,i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:6,s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!0,a=Math.max(i,2),[o,l]=dQ([n,r]);if(o===-1/0||l===1/0){var u=l===1/0?[o,...LP(0,i-1).map(()=>1/0)]:[...LP(0,i-1).map(()=>-1/0),l];return n>r?IP(u):u}if(o===l)return U4e(o,i,s);var{step:d,tickMin:f,tickMax:g}=fQ(o,l,a,s,0),m=uQ(f,g.add(new In(.1).mul(d)),d);return n>r?IP(m):m},z4e=function(e,n){var[r,i]=e,s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!0,[a,o]=dQ([r,i]);if(a===-1/0||o===1/0)return[r,i];if(a===o)return[a];var l=Math.max(n,2),u=hQ(new In(o).sub(a).div(l-1),s,0),d=[...uQ(new In(a),new In(o),u),o];return s===!1&&(d=d.map(f=>Math.round(f))),r>i?IP(d):d},pQ=t=>t.rootProps.maxBarSize,B4e=t=>t.rootProps.barGap,mQ=t=>t.rootProps.barCategoryGap,H4e=t=>t.rootProps.barSize,Nb=t=>t.rootProps.stackOffset,gQ=t=>t.rootProps.reverseStackOrder,$O=t=>t.options.chartName,VO=t=>t.rootProps.syncId,xQ=t=>t.rootProps.syncMethod,GO=t=>t.options.eventEmitter,$4e=t=>t.rootProps.baseValue,Zr={grid:-100,barBackground:-50,area:100,cursorRectangle:200,bar:300,line:400,axis:500,scatter:600,activeBar:1e3,cursorLine:1100,activeDot:1200,label:2e3},nc={allowDuplicatedCategory:!0,angleAxisId:0,reversed:!1,scale:"auto",tick:!0,type:"category"},ua={allowDataOverflow:!1,allowDuplicatedCategory:!0,radiusAxisId:0,scale:"auto",tick:!0,tickCount:5,type:"number"},CE=(t,e)=>{if(!(!t||!e))return t!=null&&t.reversed?[e[1],e[0]]:e},V4e={allowDataOverflow:!1,allowDecimals:!1,allowDuplicatedCategory:!1,dataKey:void 0,domain:void 0,id:nc.angleAxisId,includeHidden:!1,name:void 0,reversed:nc.reversed,scale:nc.scale,tick:nc.tick,tickCount:void 0,ticks:void 0,type:nc.type,unit:void 0},G4e={allowDataOverflow:ua.allowDataOverflow,allowDecimals:!1,allowDuplicatedCategory:ua.allowDuplicatedCategory,dataKey:void 0,domain:void 0,id:ua.radiusAxisId,includeHidden:!1,name:void 0,reversed:!1,scale:ua.scale,tick:ua.tick,tickCount:ua.tickCount,ticks:void 0,type:ua.type,unit:void 0},W4e={allowDataOverflow:!1,allowDecimals:!1,allowDuplicatedCategory:nc.allowDuplicatedCategory,dataKey:void 0,domain:void 0,id:nc.angleAxisId,includeHidden:!1,name:void 0,reversed:!1,scale:nc.scale,tick:nc.tick,tickCount:void 0,ticks:void 0,type:"number",unit:void 0},q4e={allowDataOverflow:ua.allowDataOverflow,allowDecimals:!1,allowDuplicatedCategory:ua.allowDuplicatedCategory,dataKey:void 0,domain:void 0,id:ua.radiusAxisId,includeHidden:!1,name:void 0,reversed:!1,scale:ua.scale,tick:ua.tick,tickCount:ua.tickCount,ticks:void 0,type:"category",unit:void 0},WO=(t,e)=>t.polarAxis.angleAxis[e]!=null?t.polarAxis.angleAxis[e]:t.layout.layoutType==="radial"?W4e:V4e,qO=(t,e)=>t.polarAxis.radiusAxis[e]!=null?t.polarAxis.radiusAxis[e]:t.layout.layoutType==="radial"?q4e:G4e,NE=t=>t.polarOptions,KO=Ke([Pc,Rc,xi],mZ),bQ=Ke([NE,KO],(t,e)=>{if(t!=null)return hs(t.innerRadius,e,0)}),vQ=Ke([NE,KO],(t,e)=>{if(t!=null)return hs(t.outerRadius,e,e*.8)}),K4e=t=>{if(t==null)return[0,0];var{startAngle:e,endAngle:n}=t;return[e,n]},yQ=Ke([NE],K4e);Ke([WO,yQ],CE);var _Q=Ke([KO,bQ,vQ],(t,e,n)=>{if(!(t==null||e==null||n==null))return[e,n]});Ke([qO,_Q],CE);var wQ=Ke([wn,NE,bQ,vQ,Pc,Rc],(t,e,n,r,i,s)=>{if(!(t!=="centric"&&t!=="radial"||e==null||n==null||r==null)){var{cx:a,cy:o,startAngle:l,endAngle:u}=e;return{cx:hs(a,i,i/2),cy:hs(o,s,s/2),innerRadius:n,outerRadius:r,startAngle:l,endAngle:u,clockWise:!1}}}),gr=(t,e)=>e,kb=(t,e,n)=>n;function kE(t){return t?.id}function SQ(t,e,n){var{chartData:r=[]}=e,{allowDuplicatedCategory:i,dataKey:s}=n,a=new Map;return t.forEach(o=>{var l,u=(l=o.data)!==null&&l!==void 0?l:r;if(!(u==null||u.length===0)){var d=kE(o);u.forEach((f,g)=>{var m=s==null||i?g:String(Qn(f,s,null)),x=Qn(f,o.dataKey,0),y;a.has(m)?y=a.get(m):y={},Object.assign(y,{[d]:x}),a.set(m,y)})}}),Array.from(a.values())}function PE(t){return t.stackId!=null&&t.dataKey!=null}var RE=(t,e)=>t===e?!0:t==null||e==null?!1:t[0]===e[0]&&t[1]===e[1];function DE(t,e){return Array.isArray(t)&&Array.isArray(e)&&t.length===0&&e.length===0?!0:t===e}function X4e(t,e){if(t.length===e.length){for(var n=0;n{var e=wn(t);return e==="horizontal"?"xAxis":e==="vertical"?"yAxis":e==="centric"?"angleAxis":"radiusAxis"},Jm=t=>t.tooltip.settings.axisId;function hV(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function Xw(t){for(var e=1;et.cartesianAxis.xAxis[e],Oc=(t,e)=>{var n=EQ(t,e);return n??Ci},Ni={allowDataOverflow:!1,allowDecimals:!0,allowDuplicatedCategory:!0,angle:0,dataKey:void 0,domain:UP,hide:!0,id:0,includeHidden:!1,interval:"preserveEnd",minTickGap:5,mirror:!1,name:void 0,orientation:"left",padding:{top:0,bottom:0},reversed:!1,scale:"auto",tick:!0,tickCount:5,tickFormatter:void 0,ticks:void 0,type:"number",unit:void 0,width:_b},MQ=(t,e)=>t.cartesianAxis.yAxis[e],jc=(t,e)=>{var n=MQ(t,e);return n??Ni},J4e={domain:[0,"auto"],includeHidden:!1,reversed:!1,allowDataOverflow:!1,allowDuplicatedCategory:!1,dataKey:void 0,id:0,name:"",range:[64,64],scale:"auto",type:"number",unit:""},XO=(t,e)=>{var n=t.cartesianAxis.zAxis[e];return n??J4e},wr=(t,e,n)=>{switch(e){case"xAxis":return Oc(t,n);case"yAxis":return jc(t,n);case"zAxis":return XO(t,n);case"angleAxis":return WO(t,n);case"radiusAxis":return qO(t,n);default:throw new Error("Unexpected axis type: ".concat(e))}},eUe=(t,e,n)=>{switch(e){case"xAxis":return Oc(t,n);case"yAxis":return jc(t,n);default:throw new Error("Unexpected axis type: ".concat(e))}},Pb=(t,e,n)=>{switch(e){case"xAxis":return Oc(t,n);case"yAxis":return jc(t,n);case"angleAxis":return WO(t,n);case"radiusAxis":return qO(t,n);default:throw new Error("Unexpected axis type: ".concat(e))}},AQ=t=>t.graphicalItems.cartesianItems.some(e=>e.type==="bar")||t.graphicalItems.polarItems.some(e=>e.type==="radialBar");function YO(t,e){return n=>{switch(t){case"xAxis":return"xAxisId"in n&&n.xAxisId===e;case"yAxis":return"yAxisId"in n&&n.yAxisId===e;case"zAxis":return"zAxisId"in n&&n.zAxisId===e;case"angleAxis":return"angleAxisId"in n&&n.angleAxisId===e;case"radiusAxis":return"radiusAxisId"in n&&n.radiusAxisId===e;default:return!1}}}var OE=t=>t.graphicalItems.cartesianItems,tUe=Ke([gr,kb],YO),ZO=(t,e,n)=>t.filter(n).filter(r=>e?.includeHidden===!0?!0:!r.hide),Rb=Ke([OE,wr,tUe],ZO,{memoizeOptions:{resultEqualityCheck:DE}}),TQ=Ke([Rb],t=>t.filter(e=>e.type==="area"||e.type==="bar").filter(PE)),CQ=t=>t.filter(e=>!("stackId"in e)||e.stackId===void 0),nUe=Ke([Rb],CQ),QO=t=>t.map(e=>e.data).filter(Boolean).flat(1),rUe=Ke([Rb],QO,{memoizeOptions:{resultEqualityCheck:DE}}),JO=(t,e)=>{var{chartData:n=[],dataStartIndex:r,dataEndIndex:i}=e;return t.length>0?t:n.slice(r,i+1)},ej=Ke([rUe,TE],JO),tj=(t,e,n)=>e?.dataKey!=null?t.map(r=>({value:Qn(r,e.dataKey)})):n.length>0?n.map(r=>r.dataKey).flatMap(r=>t.map(i=>({value:Qn(i,r)}))):t.map(r=>({value:r})),jE=Ke([ej,wr,Rb],tj);function NQ(t,e){switch(t){case"xAxis":return e.direction==="x";case"yAxis":return e.direction==="y";default:return!1}}function J_(t){if(fl(t)||t instanceof Date){var e=Number(t);if(ur(e))return e}}function fV(t){if(Array.isArray(t)){var e=[J_(t[0]),J_(t[1])];return ad(e)?e:void 0}var n=J_(t);if(n!=null)return[n,n]}function Tc(t){return t.map(J_).filter(nPe)}function iUe(t,e,n){return!n||typeof e!="number"||io(e)?[]:n.length?Tc(n.flatMap(r=>{var i=Qn(t,r.dataKey),s,a;if(Array.isArray(i)?[s,a]=i:s=a=i,!(!ur(s)||!ur(a)))return[e-s,e+a]})):[]}var yi=t=>{var e=vi(t),n=Jm(t);return Pb(t,e,n)},Db=Ke([yi],t=>t?.dataKey),sUe=Ke([TQ,TE,yi],SQ),kQ=(t,e,n,r)=>{var i={},s=e.reduce((a,o)=>(o.stackId==null||(a[o.stackId]==null&&(a[o.stackId]=[]),a[o.stackId].push(o)),a),i);return Object.fromEntries(Object.entries(s).map(a=>{var[o,l]=a,u=r?[...l].reverse():l,d=u.map(kE);return[o,{stackedData:EDe(t,d,n),graphicalItems:u}]}))},Z0=Ke([sUe,TQ,Nb,gQ],kQ),PQ=(t,e,n,r)=>{var{dataStartIndex:i,dataEndIndex:s}=e;if(r==null&&n!=="zAxis"){var a=CDe(t,i,s);if(!(a!=null&&a[0]===0&&a[1]===0))return a}},aUe=Ke([wr],t=>t.allowDataOverflow),nj=t=>{var e;if(t==null||!("domain"in t))return UP;if(t.domain!=null)return t.domain;if(t.ticks!=null){if(t.type==="number"){var n=Tc(t.ticks);return[Math.min(...n),Math.max(...n)]}if(t.type==="category")return t.ticks.map(String)}return(e=t?.domain)!==null&&e!==void 0?e:UP},rj=Ke([wr],nj),ij=Ke([rj,aUe],eQ),oUe=Ke([Z0,vd,gr,ij],PQ,{memoizeOptions:{resultEqualityCheck:RE}}),LE=t=>t.errorBars,lUe=(t,e,n)=>t.flatMap(r=>e[r.id]).filter(Boolean).filter(r=>NQ(n,r)),Yw=function(){for(var e=arguments.length,n=new Array(e),r=0;r{var s,a;if(n.length>0&&t.forEach(o=>{n.forEach(l=>{var u,d,f=(u=r[l.id])===null||u===void 0?void 0:u.filter(b=>NQ(i,b)),g=Qn(o,(d=e.dataKey)!==null&&d!==void 0?d:l.dataKey),m=iUe(o,g,f);if(m.length>=2){var x=Math.min(...m),y=Math.max(...m);(s==null||xa)&&(a=y)}var v=fV(g);v!=null&&(s=s==null?v[0]:Math.min(s,v[0]),a=a==null?v[1]:Math.max(a,v[1]))})}),e?.dataKey!=null&&t.forEach(o=>{var l=fV(Qn(o,e.dataKey));l!=null&&(s=s==null?l[0]:Math.min(s,l[0]),a=a==null?l[1]:Math.max(a,l[1]))}),ur(s)&&ur(a))return[s,a]},cUe=Ke([ej,wr,nUe,LE,gr],sj,{memoizeOptions:{resultEqualityCheck:RE}});function uUe(t){var{value:e}=t;if(fl(e)||e instanceof Date)return e}var dUe=(t,e,n)=>{var r=t.map(uUe).filter(i=>i!=null);return n&&(e.dataKey==null||e.allowDuplicatedCategory&&WX(r))?vZ(0,t.length):e.allowDuplicatedCategory?r:Array.from(new Set(r))},RQ=t=>t.referenceElements.dots,eg=(t,e,n)=>t.filter(r=>r.ifOverflow==="extendDomain").filter(r=>e==="xAxis"?r.xAxisId===n:r.yAxisId===n),hUe=Ke([RQ,gr,kb],eg),DQ=t=>t.referenceElements.areas,fUe=Ke([DQ,gr,kb],eg),OQ=t=>t.referenceElements.lines,pUe=Ke([OQ,gr,kb],eg),jQ=(t,e)=>{var n=Tc(t.map(r=>e==="xAxis"?r.x:r.y));if(n.length!==0)return[Math.min(...n),Math.max(...n)]},mUe=Ke(hUe,gr,jQ),LQ=(t,e)=>{var n=Tc(t.flatMap(r=>[e==="xAxis"?r.x1:r.y1,e==="xAxis"?r.x2:r.y2]));if(n.length!==0)return[Math.min(...n),Math.max(...n)]},gUe=Ke([fUe,gr],LQ);function xUe(t){var e;if(t.x!=null)return Tc([t.x]);var n=(e=t.segment)===null||e===void 0?void 0:e.map(r=>r.x);return n==null||n.length===0?[]:Tc(n)}function bUe(t){var e;if(t.y!=null)return Tc([t.y]);var n=(e=t.segment)===null||e===void 0?void 0:e.map(r=>r.y);return n==null||n.length===0?[]:Tc(n)}var IQ=(t,e)=>{var n=t.flatMap(r=>e==="xAxis"?xUe(r):bUe(r));if(n.length!==0)return[Math.min(...n),Math.max(...n)]},vUe=Ke([pUe,gr],IQ),yUe=Ke(mUe,vUe,gUe,(t,e,n)=>Yw(t,n,e)),aj=(t,e,n,r,i,s,a,o)=>{if(n!=null)return n;var l=a==="vertical"&&o==="xAxis"||a==="horizontal"&&o==="yAxis",u=l?Yw(r,s,i):Yw(s,i);return k4e(e,u,t.allowDataOverflow)},_Ue=Ke([wr,rj,ij,oUe,cUe,yUe,wn,gr],aj,{memoizeOptions:{resultEqualityCheck:RE}}),wUe=[0,1],oj=(t,e,n,r,i,s,a)=>{if(!((t==null||n==null||n.length===0)&&a===void 0)){var{dataKey:o,type:l}=t,u=kc(e,s);if(u&&o==null){var d;return vZ(0,(d=n?.length)!==null&&d!==void 0?d:0)}return l==="category"?dUe(r,t,u):i==="expand"?wUe:a}},lj=Ke([wr,wn,ej,jE,Nb,gr,_Ue],oj),UQ=(t,e,n,r,i)=>{if(t!=null){var{scale:s,type:a}=t;if(s==="auto")return e==="radial"&&i==="radiusAxis"?"band":e==="radial"&&i==="angleAxis"?"linear":a==="category"&&r&&(r.indexOf("LineChart")>=0||r.indexOf("AreaChart")>=0||r.indexOf("ComposedChart")>=0&&!n)?"point":a==="category"?"band":"linear";if(typeof s=="string"){var o="scale".concat(mb(s));return o in kx?o:"point"}}},tg=Ke([wr,wn,AQ,$O,gr],UQ);function SUe(t){if(t!=null){if(t in kx)return kx[t]();var e="scale".concat(mb(t));if(e in kx)return kx[e]()}}function cj(t,e,n,r){if(!(n==null||r==null)){if(typeof t.scale=="function")return t.scale.copy().domain(n).range(r);var i=SUe(e);if(i!=null){var s=i.domain(n).range(r);return vDe(s),s}}}var uj=(t,e,n)=>{var r=nj(e);if(!(n!=="auto"&&n!=="linear")){if(e!=null&&e.tickCount&&Array.isArray(r)&&(r[0]==="auto"||r[1]==="auto")&&ad(t))return F4e(t,e.tickCount,e.allowDecimals);if(e!=null&&e.tickCount&&e.type==="number"&&ad(t))return z4e(t,e.tickCount,e.allowDecimals)}},dj=Ke([lj,Pb,tg],uj),hj=(t,e,n,r)=>{if(r!=="angleAxis"&&t?.type==="number"&&ad(e)&&Array.isArray(n)&&n.length>0){var i=e[0],s=n[0],a=e[1],o=n[n.length-1];return[Math.min(i,s),Math.max(a,o)]}return e},EUe=Ke([wr,lj,dj,gr],hj),MUe=Ke(jE,wr,(t,e)=>{if(!(!e||e.type!=="number")){var n=1/0,r=Array.from(Tc(t.map(o=>o.value))).sort((o,l)=>o-l);if(r.length<2)return 1/0;var i=r[r.length-1]-r[0];if(i===0)return 1/0;for(var s=0;sr,(t,e,n,r,i)=>{if(!ur(t))return 0;var s=e==="vertical"?r.height:r.width;if(i==="gap")return t*s/2;if(i==="no-gap"){var a=hs(n,t*s),o=t*s/2;return o-a-(o-a)/s*a}return 0}),AUe=(t,e)=>{var n=Oc(t,e);return n==null||typeof n.padding!="string"?0:FQ(t,"xAxis",e,n.padding)},TUe=(t,e)=>{var n=jc(t,e);return n==null||typeof n.padding!="string"?0:FQ(t,"yAxis",e,n.padding)},CUe=Ke(Oc,AUe,(t,e)=>{var n,r;if(t==null)return{left:0,right:0};var{padding:i}=t;return typeof i=="string"?{left:e,right:e}:{left:((n=i.left)!==null&&n!==void 0?n:0)+e,right:((r=i.right)!==null&&r!==void 0?r:0)+e}}),NUe=Ke(jc,TUe,(t,e)=>{var n,r;if(t==null)return{top:0,bottom:0};var{padding:i}=t;return typeof i=="string"?{top:e,bottom:e}:{top:((n=i.top)!==null&&n!==void 0?n:0)+e,bottom:((r=i.bottom)!==null&&r!==void 0?r:0)+e}}),kUe=Ke([xi,CUe,mE,pE,(t,e,n)=>n],(t,e,n,r,i)=>{var{padding:s}=r;return i?[s.left,n.width-s.right]:[t.left+e.left,t.left+t.width-e.right]}),PUe=Ke([xi,wn,NUe,mE,pE,(t,e,n)=>n],(t,e,n,r,i,s)=>{var{padding:a}=i;return s?[r.height-a.bottom,a.top]:e==="horizontal"?[t.top+t.height-n.bottom,t.top+n.top]:[t.top+n.top,t.top+t.height-n.bottom]}),Ob=(t,e,n,r)=>{var i;switch(e){case"xAxis":return kUe(t,n,r);case"yAxis":return PUe(t,n,r);case"zAxis":return(i=XO(t,n))===null||i===void 0?void 0:i.range;case"angleAxis":return yQ(t);case"radiusAxis":return _Q(t,n);default:return}},zQ=Ke([wr,Ob],CE),ng=Ke([wr,tg,EUe,zQ],cj);Ke([Rb,LE,gr],lUe);function BQ(t,e){return t.ide.id?1:0}var IE=(t,e)=>e,UE=(t,e,n)=>n,RUe=Ke(hE,IE,UE,(t,e,n)=>t.filter(r=>r.orientation===e).filter(r=>r.mirror===n).sort(BQ)),DUe=Ke(fE,IE,UE,(t,e,n)=>t.filter(r=>r.orientation===e).filter(r=>r.mirror===n).sort(BQ)),HQ=(t,e)=>({width:t.width,height:e.height}),OUe=(t,e)=>{var n=typeof e.width=="number"?e.width:_b;return{width:n,height:t.height}},$Q=Ke(xi,Oc,HQ),jUe=(t,e,n)=>{switch(e){case"top":return t.top;case"bottom":return n-t.bottom;default:return 0}},LUe=(t,e,n)=>{switch(e){case"left":return t.left;case"right":return n-t.right;default:return 0}},IUe=Ke(Rc,xi,RUe,IE,UE,(t,e,n,r,i)=>{var s={},a;return n.forEach(o=>{var l=HQ(e,o);a==null&&(a=jUe(e,r,t));var u=r==="top"&&!i||r==="bottom"&&i;s[o.id]=a-Number(u)*l.height,a+=(u?-1:1)*l.height}),s}),UUe=Ke(Pc,xi,DUe,IE,UE,(t,e,n,r,i)=>{var s={},a;return n.forEach(o=>{var l=OUe(e,o);a==null&&(a=LUe(e,r,t));var u=r==="left"&&!i||r==="right"&&i;s[o.id]=a-Number(u)*l.width,a+=(u?-1:1)*l.width}),s}),FUe=(t,e)=>{var n=Oc(t,e);if(n!=null)return IUe(t,n.orientation,n.mirror)},zUe=Ke([xi,Oc,FUe,(t,e)=>e],(t,e,n,r)=>{if(e!=null){var i=n?.[r];return i==null?{x:t.left,y:0}:{x:t.left,y:i}}}),BUe=(t,e)=>{var n=jc(t,e);if(n!=null)return UUe(t,n.orientation,n.mirror)},HUe=Ke([xi,jc,BUe,(t,e)=>e],(t,e,n,r)=>{if(e!=null){var i=n?.[r];return i==null?{x:0,y:t.top}:{x:i,y:t.top}}}),VQ=Ke(xi,jc,(t,e)=>{var n=typeof e.width=="number"?e.width:_b;return{width:n,height:t.height}}),pV=(t,e,n)=>{switch(e){case"xAxis":return $Q(t,n).width;case"yAxis":return VQ(t,n).height;default:return}},GQ=(t,e,n,r)=>{if(n!=null){var{allowDuplicatedCategory:i,type:s,dataKey:a}=n,o=kc(t,r),l=e.map(u=>u.value);if(a&&o&&s==="category"&&i&&WX(l))return l}},fj=Ke([wn,jE,wr,gr],GQ),WQ=(t,e,n,r)=>{if(!(n==null||n.dataKey==null)){var{type:i,scale:s}=n,a=kc(t,r);if(a&&(i==="number"||s!=="auto"))return e.map(o=>o.value)}},pj=Ke([wn,jE,Pb,gr],WQ),mV=Ke([wn,eUe,tg,ng,fj,pj,Ob,dj,gr],(t,e,n,r,i,s,a,o,l)=>{if(e!=null){var u=kc(t,l);return{angle:e.angle,interval:e.interval,minTickGap:e.minTickGap,orientation:e.orientation,tick:e.tick,tickCount:e.tickCount,tickFormatter:e.tickFormatter,ticks:e.ticks,type:e.type,unit:e.unit,axisType:l,categoricalDomain:s,duplicateDomain:i,isCategorical:u,niceTicks:o,range:a,realScaleType:n,scale:r}}}),$Ue=(t,e,n,r,i,s,a,o,l)=>{if(!(e==null||r==null)){var u=kc(t,l),{type:d,ticks:f,tickCount:g}=e,m=n==="scaleBand"&&typeof r.bandwidth=="function"?r.bandwidth()/2:2,x=d==="category"&&r.bandwidth?r.bandwidth()/m:0;x=l==="angleAxis"&&s!=null&&s.length>=2?Di(s[0]-s[1])*2*x:x;var y=f||i;if(y){var v=y.map((b,E)=>{var S=a?a.indexOf(b):b;return{index:E,coordinate:r(S)+x,value:b,offset:x}});return v.filter(b=>ur(b.coordinate))}return u&&o?o.map((b,E)=>({coordinate:r(b)+x,value:b,index:E,offset:x})).filter(b=>ur(b.coordinate)):r.ticks?r.ticks(g).map(b=>({coordinate:r(b)+x,value:b,offset:x})):r.domain().map((b,E)=>({coordinate:r(b)+x,value:a?a[b]:b,index:E,offset:x}))}},qQ=Ke([wn,Pb,tg,ng,dj,Ob,fj,pj,gr],$Ue),VUe=(t,e,n,r,i,s,a)=>{if(!(e==null||n==null||r==null||r[0]===r[1])){var o=kc(t,a),{tickCount:l}=e,u=0;return u=a==="angleAxis"&&r?.length>=2?Di(r[0]-r[1])*2*u:u,o&&s?s.map((d,f)=>({coordinate:n(d)+u,value:d,index:f,offset:u})):n.ticks?n.ticks(l).map(d=>({coordinate:n(d)+u,value:d,offset:u})):n.domain().map((d,f)=>({coordinate:n(d)+u,value:i?i[d]:d,index:f,offset:u}))}},od=Ke([wn,Pb,ng,Ob,fj,pj,gr],VUe),ld=Ke(wr,ng,(t,e)=>{if(!(t==null||e==null))return Xw(Xw({},t),{},{scale:e})}),GUe=Ke([wr,tg,lj,zQ],cj);Ke((t,e,n)=>XO(t,n),GUe,(t,e)=>{if(!(t==null||e==null))return Xw(Xw({},t),{},{scale:e})});var WUe=Ke([wn,hE,fE],(t,e,n)=>{switch(t){case"horizontal":return e.some(r=>r.reversed)?"right-to-left":"left-to-right";case"vertical":return n.some(r=>r.reversed)?"bottom-to-top":"top-to-bottom";case"centric":case"radial":return"left-to-right";default:return}}),KQ=t=>t.options.defaultTooltipEventType,XQ=t=>t.options.validateTooltipEventTypes;function YQ(t,e,n){if(t==null)return e;var r=t?"axis":"item";return n==null?e:n.includes(r)?r:e}function mj(t,e){var n=KQ(t),r=XQ(t);return YQ(e,n,r)}function qUe(t){return kt(e=>mj(e,t))}var ZQ=(t,e)=>{var n,r=Number(e);if(!(io(r)||e==null))return r>=0?t==null||(n=t[r])===null||n===void 0?void 0:n.value:void 0},KUe=t=>t.tooltip.settings,Du={active:!1,index:null,dataKey:void 0,graphicalItemId:void 0,coordinate:void 0},XUe={itemInteraction:{click:Du,hover:Du},axisInteraction:{click:Du,hover:Du},keyboardInteraction:Du,syncInteraction:{active:!1,index:null,dataKey:void 0,label:void 0,coordinate:void 0,sourceViewBox:void 0,graphicalItemId:void 0},tooltipItemPayloads:[],settings:{shared:void 0,trigger:"hover",axisId:0,active:!1,defaultIndex:void 0}},QQ=Zs({name:"tooltip",initialState:XUe,reducers:{addTooltipEntrySettings:{reducer(t,e){t.tooltipItemPayloads.push(e.payload)},prepare:hr()},replaceTooltipEntrySettings:{reducer(t,e){var{prev:n,next:r}=e.payload,i=Ro(t).tooltipItemPayloads.indexOf(n);i>-1&&(t.tooltipItemPayloads[i]=r)},prepare:hr()},removeTooltipEntrySettings:{reducer(t,e){var n=Ro(t).tooltipItemPayloads.indexOf(e.payload);n>-1&&t.tooltipItemPayloads.splice(n,1)},prepare:hr()},setTooltipSettingsState(t,e){t.settings=e.payload},setActiveMouseOverItemIndex(t,e){t.syncInteraction.active=!1,t.keyboardInteraction.active=!1,t.itemInteraction.hover.active=!0,t.itemInteraction.hover.index=e.payload.activeIndex,t.itemInteraction.hover.dataKey=e.payload.activeDataKey,t.itemInteraction.hover.graphicalItemId=e.payload.activeGraphicalItemId,t.itemInteraction.hover.coordinate=e.payload.activeCoordinate},mouseLeaveChart(t){t.itemInteraction.hover.active=!1,t.axisInteraction.hover.active=!1},mouseLeaveItem(t){t.itemInteraction.hover.active=!1},setActiveClickItemIndex(t,e){t.syncInteraction.active=!1,t.itemInteraction.click.active=!0,t.keyboardInteraction.active=!1,t.itemInteraction.click.index=e.payload.activeIndex,t.itemInteraction.click.dataKey=e.payload.activeDataKey,t.itemInteraction.click.graphicalItemId=e.payload.activeGraphicalItemId,t.itemInteraction.click.coordinate=e.payload.activeCoordinate},setMouseOverAxisIndex(t,e){t.syncInteraction.active=!1,t.axisInteraction.hover.active=!0,t.keyboardInteraction.active=!1,t.axisInteraction.hover.index=e.payload.activeIndex,t.axisInteraction.hover.dataKey=e.payload.activeDataKey,t.axisInteraction.hover.coordinate=e.payload.activeCoordinate},setMouseClickAxisIndex(t,e){t.syncInteraction.active=!1,t.keyboardInteraction.active=!1,t.axisInteraction.click.active=!0,t.axisInteraction.click.index=e.payload.activeIndex,t.axisInteraction.click.dataKey=e.payload.activeDataKey,t.axisInteraction.click.coordinate=e.payload.activeCoordinate},setSyncInteraction(t,e){t.syncInteraction=e.payload},setKeyboardInteraction(t,e){t.keyboardInteraction.active=e.payload.active,t.keyboardInteraction.index=e.payload.activeIndex,t.keyboardInteraction.coordinate=e.payload.activeCoordinate,t.keyboardInteraction.dataKey=e.payload.activeDataKey}}}),{addTooltipEntrySettings:YUe,replaceTooltipEntrySettings:ZUe,removeTooltipEntrySettings:QUe,setTooltipSettingsState:JUe,setActiveMouseOverItemIndex:JQ,mouseLeaveItem:e5e,mouseLeaveChart:eJ,setActiveClickItemIndex:t5e,setMouseOverAxisIndex:tJ,setMouseClickAxisIndex:n5e,setSyncInteraction:FP,setKeyboardInteraction:zP}=QQ.actions,r5e=QQ.reducer;function gV(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function A_(t){for(var e=1;e{if(e==null)return Du;var i=o5e(t,e,n);if(i==null)return Du;if(i.active)return i;if(t.keyboardInteraction.active)return t.keyboardInteraction;if(t.syncInteraction.active&&t.syncInteraction.index!=null)return t.syncInteraction;var s=t.settings.active===!0;if(l5e(i)){if(s)return A_(A_({},i),{},{active:!0})}else if(r!=null)return{active:!0,coordinate:void 0,dataKey:void 0,index:r,graphicalItemId:void 0};return A_(A_({},Du),{},{coordinate:i.coordinate})};function c5e(t){if(typeof t=="number")return Number.isFinite(t)?t:void 0;if(t instanceof Date){var e=t.valueOf();return Number.isFinite(e)?e:void 0}var n=Number(t);return Number.isFinite(n)?n:void 0}function u5e(t,e){var n=c5e(t),r=e[0],i=e[1];if(n===void 0)return!1;var s=Math.min(r,i),a=Math.max(r,i);return n>=s&&n<=a}function d5e(t,e,n){if(n==null||e==null)return!0;var r=Qn(t,e);return r==null||!ad(n)?!0:u5e(r,n)}var gj=(t,e,n,r)=>{var i=t?.index;if(i==null)return null;var s=Number(i);if(!ur(s))return i;var a=0,o=1/0;e.length>0&&(o=e.length-1);var l=Math.max(a,Math.min(s,o)),u=e[l];return u==null||d5e(u,n,r)?String(l):null},rJ=(t,e,n,r,i,s,a,o)=>{if(!(s==null||o==null)){var l=a[0],u=l==null?void 0:o(l.positions,s);if(u!=null)return u;var d=i?.[Number(s)];if(d)switch(n){case"horizontal":return{x:d.coordinate,y:(r.top+e)/2};default:return{x:(r.left+t)/2,y:d.coordinate}}}},iJ=(t,e,n,r)=>{if(e==="axis")return t.tooltipItemPayloads;if(t.tooltipItemPayloads.length===0)return[];var i;return n==="hover"?i=t.itemInteraction.hover.dataKey:i=t.itemInteraction.click.dataKey,i==null&&r!=null?[t.tooltipItemPayloads[0]]:t.tooltipItemPayloads.filter(s=>{var a;return((a=s.settings)===null||a===void 0?void 0:a.dataKey)===i})},jb=t=>t.options.tooltipPayloadSearcher,rg=t=>t.tooltip;function xV(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function bV(t){for(var e=1;e{if(!(e==null||s==null)){var{chartData:o,computedData:l,dataStartIndex:u,dataEndIndex:d}=n,f=[];return t.reduce((g,m)=>{var x,{dataDefinedOnItem:y,settings:v}=m,b=m5e(y,o),E=Array.isArray(b)?zY(b,u,d):b,S=(x=v?.dataKey)!==null&&x!==void 0?x:r,A=v?.nameKey,T;if(r&&Array.isArray(E)&&!Array.isArray(E[0])&&a==="axis"?T=qX(E,r,i):T=s(E,e,l,A),Array.isArray(T))T.forEach(C=>{var I=bV(bV({},v),{},{name:C.name,unit:C.unit,color:void 0,fill:void 0});g.push(UH({tooltipEntrySettings:I,dataKey:C.dataKey,payload:C.payload,value:Qn(C.payload,C.dataKey),name:C.name}))});else{var P;g.push(UH({tooltipEntrySettings:v,dataKey:S,payload:T,value:Qn(T,S),name:(P=Qn(T,A))!==null&&P!==void 0?P:v?.name}))}return g},f)}},xj=Ke([yi,wn,AQ,$O,vi],UQ),g5e=Ke([t=>t.graphicalItems.cartesianItems,t=>t.graphicalItems.polarItems],(t,e)=>[...t,...e]),x5e=Ke([vi,Jm],YO),Lb=Ke([g5e,yi,x5e],ZO,{memoizeOptions:{resultEqualityCheck:DE}}),b5e=Ke([Lb],t=>t.filter(PE)),v5e=Ke([Lb],QO,{memoizeOptions:{resultEqualityCheck:DE}}),ig=Ke([v5e,vd],JO),y5e=Ke([b5e,vd,yi],SQ),bj=Ke([ig,yi,Lb],tj),aJ=Ke([yi],nj),_5e=Ke([yi],t=>t.allowDataOverflow),oJ=Ke([aJ,_5e],eQ),w5e=Ke([Lb],t=>t.filter(PE)),S5e=Ke([y5e,w5e,Nb,gQ],kQ),E5e=Ke([S5e,vd,vi,oJ],PQ),M5e=Ke([Lb],CQ),A5e=Ke([ig,yi,M5e,LE,vi],sj,{memoizeOptions:{resultEqualityCheck:RE}}),T5e=Ke([RQ,vi,Jm],eg),C5e=Ke([T5e,vi],jQ),N5e=Ke([DQ,vi,Jm],eg),k5e=Ke([N5e,vi],LQ),P5e=Ke([OQ,vi,Jm],eg),R5e=Ke([P5e,vi],IQ),D5e=Ke([C5e,R5e,k5e],Yw),O5e=Ke([yi,aJ,oJ,E5e,A5e,D5e,wn,vi],aj),Ib=Ke([yi,wn,ig,bj,Nb,vi,O5e],oj),j5e=Ke([Ib,yi,xj],uj),L5e=Ke([yi,Ib,j5e,vi],hj),lJ=t=>{var e=vi(t),n=Jm(t),r=!1;return Ob(t,e,n,r)},cJ=Ke([yi,lJ],CE),uJ=Ke([yi,xj,L5e,cJ],cj),I5e=Ke([wn,bj,yi,vi],GQ),U5e=Ke([wn,bj,yi,vi],WQ),F5e=(t,e,n,r,i,s,a,o)=>{if(e){var{type:l}=e,u=kc(t,o);if(r){var d=n==="scaleBand"&&r.bandwidth?r.bandwidth()/2:2,f=l==="category"&&r.bandwidth?r.bandwidth()/d:0;return f=o==="angleAxis"&&i!=null&&i?.length>=2?Di(i[0]-i[1])*2*f:f,u&&a?a.map((g,m)=>({coordinate:r(g)+f,value:g,index:m,offset:f})):r.domain().map((g,m)=>({coordinate:r(g)+f,value:s?s[g]:g,index:m,offset:f}))}}},Lc=Ke([wn,yi,xj,uJ,lJ,I5e,U5e,vi],F5e),vj=Ke([KQ,XQ,KUe],(t,e,n)=>YQ(n.shared,t,e)),dJ=t=>t.tooltip.settings.trigger,yj=t=>t.tooltip.settings.defaultIndex,Ub=Ke([rg,vj,dJ,yj],nJ),cd=Ke([Ub,ig,Db,Ib],gj),hJ=Ke([Lc,cd],ZQ),_j=Ke([Ub],t=>{if(t)return t.dataKey}),z5e=Ke([Ub],t=>{if(t)return t.graphicalItemId}),fJ=Ke([rg,vj,dJ,yj],iJ),B5e=Ke([Pc,Rc,wn,xi,Lc,yj,fJ,jb],rJ),H5e=Ke([Ub,B5e],(t,e)=>t!=null&&t.coordinate?t.coordinate:e),$5e=Ke([Ub],t=>t.active),V5e=Ke([fJ,cd,vd,Db,hJ,jb,vj],sJ),G5e=Ke([V5e],t=>{if(t!=null){var e=t.map(n=>n.payload).filter(n=>n!=null);return Array.from(new Set(e))}});function vV(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function yV(t){for(var e=1;ekt(yi),Y5e=()=>{var t=X5e(),e=kt(Lc),n=kt(uJ);return Tm(!t||!n?void 0:yV(yV({},t),{},{scale:n}),e)};function _V(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function Ep(t){for(var e=1;e{var i=e.find(s=>s&&s.index===n);if(i){if(t==="horizontal")return{x:i.coordinate,y:r.chartY};if(t==="vertical")return{x:r.chartX,y:i.coordinate}}return{x:0,y:0}},tFe=(t,e,n,r)=>{var i=e.find(u=>u&&u.index===n);if(i){if(t==="centric"){var s=i.coordinate,{radius:a}=r;return Ep(Ep(Ep({},r),Yr(r.cx,r.cy,a,s)),{},{angle:s,radius:a})}var o=i.coordinate,{angle:l}=r;return Ep(Ep(Ep({},r),Yr(r.cx,r.cy,o,l)),{},{angle:l,radius:o})}return{angle:0,clockWise:!1,cx:0,cy:0,endAngle:0,innerRadius:0,outerRadius:0,radius:0,startAngle:0,x:0,y:0}};function nFe(t,e){var{chartX:n,chartY:r}=t;return n>=e.left&&n<=e.left+e.width&&r>=e.top&&r<=e.top+e.height}var pJ=(t,e,n,r,i)=>{var s,a=-1,o=(s=e?.length)!==null&&s!==void 0?s:0;if(o<=1||t==null)return 0;if(r==="angleAxis"&&i!=null&&Math.abs(Math.abs(i[1]-i[0])-360)<=1e-6)for(var l=0;l0?n[l-1].coordinate:n[o-1].coordinate,d=n[l].coordinate,f=l>=o-1?n[0].coordinate:n[l+1].coordinate,g=void 0;if(Di(d-u)!==Di(f-d)){var m=[];if(Di(f-d)===Di(i[1]-i[0])){g=f;var x=d+i[1]-i[0];m[0]=Math.min(x,(x+u)/2),m[1]=Math.max(x,(x+u)/2)}else{g=u;var y=f+i[1]-i[0];m[0]=Math.min(d,(y+d)/2),m[1]=Math.max(d,(y+d)/2)}var v=[Math.min(d,(g+d)/2),Math.max(d,(g+d)/2)];if(t>v[0]&&t<=v[1]||t>=m[0]&&t<=m[1]){({index:a}=n[l]);break}}else{var b=Math.min(u,f),E=Math.max(u,f);if(t>(b+d)/2&&t<=(E+d)/2){({index:a}=n[l]);break}}}else if(e){for(var S=0;S0&&S(e[S].coordinate+e[S-1].coordinate)/2&&t<=(e[S].coordinate+e[S+1].coordinate)/2||S===o-1&&t>(e[S].coordinate+e[S-1].coordinate)/2){({index:a}=e[S]);break}}return a},mJ=()=>kt($O),wj=(t,e)=>e,gJ=(t,e,n)=>n,Sj=(t,e,n,r)=>r,rFe=Ke(Lc,t=>rE(t,e=>e.coordinate)),Ej=Ke([rg,wj,gJ,Sj],nJ),Mj=Ke([Ej,ig,Db,Ib],gj),iFe=(t,e,n)=>{if(e!=null){var r=rg(t);return e==="axis"?n==="hover"?r.axisInteraction.hover.dataKey:r.axisInteraction.click.dataKey:n==="hover"?r.itemInteraction.hover.dataKey:r.itemInteraction.click.dataKey}},xJ=Ke([rg,wj,gJ,Sj],iJ),Zw=Ke([Pc,Rc,wn,xi,Lc,Sj,xJ,jb],rJ),sFe=Ke([Ej,Zw],(t,e)=>{var n;return(n=t.coordinate)!==null&&n!==void 0?n:e}),bJ=Ke([Lc,Mj],ZQ),aFe=Ke([xJ,Mj,vd,Db,bJ,jb,wj],sJ),oFe=Ke([Ej,Mj],(t,e)=>({isActive:t.active&&e!=null,activeIndex:e})),lFe=(t,e,n,r,i,s,a)=>{if(!(!t||!n||!r||!i)&&nFe(t,a)){var o=NDe(t,e),l=pJ(o,s,i,n,r),u=eFe(e,i,l,t);return{activeIndex:String(l),activeCoordinate:u}}},cFe=(t,e,n,r,i,s,a)=>{if(!(!t||!r||!i||!s||!n)){var o=Wje(t,n);if(o){var l=kDe(o,e),u=pJ(l,a,s,r,i),d=tFe(e,s,u,o);return{activeIndex:String(u),activeCoordinate:d}}}},uFe=(t,e,n,r,i,s,a,o)=>{if(!(!t||!e||!r||!i||!s))return e==="horizontal"||e==="vertical"?lFe(t,e,r,i,s,a,o):cFe(t,e,n,r,i,s,a)},dFe=Ke(t=>t.zIndex.zIndexMap,(t,e)=>e,(t,e,n)=>n,(t,e,n)=>{if(e!=null){var r=t[e];if(r!=null)return n?r.panoramaElementId:r.elementId}}),hFe=Ke(t=>t.zIndex.zIndexMap,t=>{var e=Object.keys(t).map(r=>parseInt(r,10)).concat(Object.values(Zr)),n=Array.from(new Set(e));return n.sort((r,i)=>r-i)},{memoizeOptions:{resultEqualityCheck:X4e}});function wV(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function SV(t){for(var e=1;eSV(SV({},t),{},{[e]:{elementId:void 0,panoramaElementId:void 0,consumers:0}}),gFe)},bFe=new Set(Object.values(Zr));function vFe(t){return bFe.has(t)}var vJ=Zs({name:"zIndex",initialState:xFe,reducers:{registerZIndexPortal:{reducer:(t,e)=>{var{zIndex:n}=e.payload;t.zIndexMap[n]?t.zIndexMap[n].consumers+=1:t.zIndexMap[n]={consumers:1,elementId:void 0,panoramaElementId:void 0}},prepare:hr()},unregisterZIndexPortal:{reducer:(t,e)=>{var{zIndex:n}=e.payload;t.zIndexMap[n]&&(t.zIndexMap[n].consumers-=1,t.zIndexMap[n].consumers<=0&&!vFe(n)&&delete t.zIndexMap[n])},prepare:hr()},registerZIndexPortalId:{reducer:(t,e)=>{var{zIndex:n,elementId:r,isPanorama:i}=e.payload;t.zIndexMap[n]?i?t.zIndexMap[n].panoramaElementId=r:t.zIndexMap[n].elementId=r:t.zIndexMap[n]={consumers:0,elementId:i?void 0:r,panoramaElementId:i?r:void 0}},prepare:hr()},unregisterZIndexPortalId:{reducer:(t,e)=>{var{zIndex:n}=e.payload;t.zIndexMap[n]&&(e.payload.isPanorama?t.zIndexMap[n].panoramaElementId=void 0:t.zIndexMap[n].elementId=void 0)},prepare:hr()}}}),{registerZIndexPortal:yFe,unregisterZIndexPortal:_Fe,registerZIndexPortalId:wFe,unregisterZIndexPortalId:SFe}=vJ.actions,EFe=vJ.reducer;function Qs(t){var{zIndex:e,children:n}=t,r=lOe(),i=r&&e!==void 0&&e!==0,s=ms(),a=rr();M.useLayoutEffect(()=>i?(a(yFe({zIndex:e})),()=>{a(_Fe({zIndex:e}))}):gb,[a,e,i]);var o=kt(u=>dFe(u,e,s));if(!i)return n;if(!o)return null;var l=document.getElementById(o);return l?ic.createPortal(n,l):null}function BP(){return BP=Object.assign?Object.assign.bind():function(t){for(var e=1;eM.useContext(yJ),EN={exports:{}},MV;function RFe(){return MV||(MV=1,(function(t){var e=Object.prototype.hasOwnProperty,n="~";function r(){}Object.create&&(r.prototype=Object.create(null),new r().__proto__||(n=!1));function i(l,u,d){this.fn=l,this.context=u,this.once=d||!1}function s(l,u,d,f,g){if(typeof d!="function")throw new TypeError("The listener must be a function");var m=new i(d,f||l,g),x=n?n+u:u;return l._events[x]?l._events[x].fn?l._events[x]=[l._events[x],m]:l._events[x].push(m):(l._events[x]=m,l._eventsCount++),l}function a(l,u){--l._eventsCount===0?l._events=new r:delete l._events[u]}function o(){this._events=new r,this._eventsCount=0}o.prototype.eventNames=function(){var u=[],d,f;if(this._eventsCount===0)return u;for(f in d=this._events)e.call(d,f)&&u.push(n?f.slice(1):f);return Object.getOwnPropertySymbols?u.concat(Object.getOwnPropertySymbols(d)):u},o.prototype.listeners=function(u){var d=n?n+u:u,f=this._events[d];if(!f)return[];if(f.fn)return[f.fn];for(var g=0,m=f.length,x=new Array(m);g{t.eventEmitter==null&&(t.eventEmitter=Symbol("rechartsEventEmitter"))}}}),LFe=_J.reducer,{createEventEmitter:IFe}=_J.actions;function UFe(t){return t.tooltip.syncInteraction}var FFe={chartData:void 0,computedData:void 0,dataStartIndex:0,dataEndIndex:0},wJ=Zs({name:"chartData",initialState:FFe,reducers:{setChartData(t,e){if(t.chartData=e.payload,e.payload==null){t.dataStartIndex=0,t.dataEndIndex=0;return}e.payload.length>0&&t.dataEndIndex!==e.payload.length-1&&(t.dataEndIndex=e.payload.length-1)},setComputedData(t,e){t.computedData=e.payload},setDataStartEndIndexes(t,e){var{startIndex:n,endIndex:r}=e.payload;n!=null&&(t.dataStartIndex=n),r!=null&&(t.dataEndIndex=r)}}}),{setChartData:TV,setDataStartEndIndexes:zFe,setComputedData:b7e}=wJ.actions,BFe=wJ.reducer,HFe=["x","y"];function CV(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function Mp(t){for(var e=1;el.rootProps.className);M.useEffect(()=>{if(t==null)return gb;var l=(u,d,f)=>{if(e!==f&&t===u){if(r==="index"){var g;if(a&&d!==null&&d!==void 0&&(g=d.payload)!==null&&g!==void 0&&g.coordinate&&d.payload.sourceViewBox){var m=d.payload.coordinate,{x,y}=m,v=WFe(m,HFe),{x:b,y:E,width:S,height:A}=d.payload.sourceViewBox,T=Mp(Mp({},v),{},{x:a.x+(S?(x-b)/S:0)*a.width,y:a.y+(A?(y-E)/A:0)*a.height});n(Mp(Mp({},d),{},{payload:Mp(Mp({},d.payload),{},{coordinate:T})}))}else n(d);return}if(i!=null){var P;if(typeof r=="function"){var C={activeTooltipIndex:d.payload.index==null?void 0:Number(d.payload.index),isTooltipActive:d.payload.active,activeIndex:d.payload.index==null?void 0:Number(d.payload.index),activeLabel:d.payload.label,activeDataKey:d.payload.dataKey,activeCoordinate:d.payload.coordinate},I=r(i,C);P=i[I]}else r==="value"&&(P=i.find(K=>String(K.value)===d.payload.label));var{coordinate:N}=d.payload;if(P==null||d.payload.active===!1||N==null||a==null){n(FP({active:!1,coordinate:void 0,dataKey:void 0,index:null,label:void 0,sourceViewBox:void 0,graphicalItemId:void 0}));return}var{x:D,y:F}=N,L=Math.min(D,a.x+a.width),q=Math.min(F,a.y+a.height),R={x:s==="horizontal"?P.coordinate:L,y:s==="horizontal"?q:P.coordinate},V=FP({active:d.payload.active,coordinate:R,dataKey:d.payload.dataKey,index:String(P.index),label:d.payload.label,sourceViewBox:d.payload.sourceViewBox,graphicalItemId:d.payload.graphicalItemId});n(V)}}};return Q0.on(HP,l),()=>{Q0.off(HP,l)}},[o,n,e,t,r,i,s,a])}function XFe(){var t=kt(VO),e=kt(GO),n=rr();M.useEffect(()=>{if(t==null)return gb;var r=(i,s,a)=>{e!==a&&t===i&&n(zFe(s))};return Q0.on(AV,r),()=>{Q0.off(AV,r)}},[n,e,t])}function YFe(){var t=rr();M.useEffect(()=>{t(IFe())},[t]),KFe(),XFe()}function ZFe(t,e,n,r,i,s){var a=kt(m=>iFe(m,t,e)),o=kt(GO),l=kt(VO),u=kt(xQ),d=kt(UFe),f=d?.active,g=gE();M.useEffect(()=>{if(!f&&l!=null&&o!=null){var m=FP({active:s,coordinate:n,dataKey:a,index:i,label:typeof r=="number"?String(r):r,sourceViewBox:g,graphicalItemId:void 0});Q0.emit(HP,l,m,o)}},[f,n,a,i,r,o,l,u,s,g])}function NV(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function kV(t){for(var e=1;e{C(JUe({shared:E,trigger:S,axisId:P,active:i,defaultIndex:I}))},[C,E,S,P,i,I]);var N=gE(),D=cZ(),F=qUe(E),{activeIndex:L,isActive:q}=(e=kt(xe=>oFe(xe,F,S,I)))!==null&&e!==void 0?e:{},R=kt(xe=>aFe(xe,F,S,I)),V=kt(xe=>bJ(xe,F,S,I)),K=kt(xe=>sFe(xe,F,S,I)),W=R,ne=PFe(),Y=(n=i??q)!==null&&n!==void 0?n:!1,[Z,U]=uY([W,Y]),$=F==="axis"?V:void 0;ZFe(F,S,K,$,L,Y);var ee=T??ne;if(ee==null||N==null||F==null)return null;var ae=W??PV;Y||(ae=PV),u&&ae.length&&(ae=sY(ae.filter(xe=>xe.value!=null&&(xe.hide!==!0||r.includeHidden)),g,tze));var fe=ae.length>0,ue=M.createElement(qOe,{allowEscapeViewBox:s,animationDuration:a,animationEasing:o,isAnimationActive:d,active:Y,coordinate:K,hasPayload:fe,offset:f,position:m,reverseDirection:x,useTranslate3d:y,viewBox:N,wrapperStyle:v,lastBoundingBox:Z,innerRef:U,hasPortalFromProps:!!T},nze(l,kV(kV({},r),{},{payload:ae,label:$,active:Y,activeIndex:L,coordinate:K,accessibilityLayer:D})));return M.createElement(M.Fragment,null,ic.createPortal(ue,ee),Y&&M.createElement(kFe,{cursor:b,tooltipEventType:F,coordinate:K,payload:ae,index:L}))}var Fb=t=>null;Fb.displayName="Cell";function ize(t,e,n){return(e=sze(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function sze(t){var e=aze(t,"string");return typeof e=="symbol"?e:e+""}function aze(t,e){if(typeof t!="object"||!t)return t;var n=t[Symbol.toPrimitive];if(n!==void 0){var r=n.call(t,e);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(t)}class oze{constructor(e){ize(this,"cache",new Map),this.maxSize=e}get(e){var n=this.cache.get(e);return n!==void 0&&(this.cache.delete(e),this.cache.set(e,n)),n}set(e,n){if(this.cache.has(e))this.cache.delete(e);else if(this.cache.size>=this.maxSize){var r=this.cache.keys().next().value;r!=null&&this.cache.delete(r)}this.cache.set(e,n)}clear(){this.cache.clear()}size(){return this.cache.size}}function RV(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function lze(t){for(var e=1;e{try{var n=document.getElementById(OV);n||(n=document.createElement("span"),n.setAttribute("id",OV),n.setAttribute("aria-hidden","true"),document.body.appendChild(n)),Object.assign(n.style,fze,e),n.textContent="".concat(t);var r=n.getBoundingClientRect();return{width:r.width,height:r.height}}catch{return{width:0,height:0}}},e0=function(e){var n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(e==null||Xm.isSsr)return{width:0,height:0};if(!SJ.enableCache)return jV(e,n);var r=pze(e,n),i=DV.get(r);if(i)return i;var s=jV(e,n);return DV.set(r,s),s},LV=/(-?\d+(?:\.\d+)?[a-zA-Z%]*)([*/])(-?\d+(?:\.\d+)?[a-zA-Z%]*)/,IV=/(-?\d+(?:\.\d+)?[a-zA-Z%]*)([+-])(-?\d+(?:\.\d+)?[a-zA-Z%]*)/,mze=/^px|cm|vh|vw|em|rem|%|mm|in|pt|pc|ex|ch|vmin|vmax|Q$/,gze=/(-?\d+(?:\.\d+)?)([a-zA-Z%]+)?/,EJ={cm:96/2.54,mm:96/25.4,pt:96/72,pc:96/6,in:96,Q:96/(2.54*40),px:1},xze=Object.keys(EJ),Fp="NaN";function bze(t,e){return t*EJ[e]}class Fs{static parse(e){var n,[,r,i]=(n=gze.exec(e))!==null&&n!==void 0?n:[];return new Fs(parseFloat(r),i??"")}constructor(e,n){this.num=e,this.unit=n,this.num=e,this.unit=n,io(e)&&(this.unit=""),n!==""&&!mze.test(n)&&(this.num=NaN,this.unit=""),xze.includes(n)&&(this.num=bze(e,n),this.unit="px")}add(e){return this.unit!==e.unit?new Fs(NaN,""):new Fs(this.num+e.num,this.unit)}subtract(e){return this.unit!==e.unit?new Fs(NaN,""):new Fs(this.num-e.num,this.unit)}multiply(e){return this.unit!==""&&e.unit!==""&&this.unit!==e.unit?new Fs(NaN,""):new Fs(this.num*e.num,this.unit||e.unit)}divide(e){return this.unit!==""&&e.unit!==""&&this.unit!==e.unit?new Fs(NaN,""):new Fs(this.num/e.num,this.unit||e.unit)}toString(){return"".concat(this.num).concat(this.unit)}isNaN(){return io(this.num)}}function MJ(t){if(t.includes(Fp))return Fp;for(var e=t;e.includes("*")||e.includes("/");){var n,[,r,i,s]=(n=LV.exec(e))!==null&&n!==void 0?n:[],a=Fs.parse(r??""),o=Fs.parse(s??""),l=i==="*"?a.multiply(o):a.divide(o);if(l.isNaN())return Fp;e=e.replace(LV,l.toString())}for(;e.includes("+")||/.-\d+(?:\.\d+)?/.test(e);){var u,[,d,f,g]=(u=IV.exec(e))!==null&&u!==void 0?u:[],m=Fs.parse(d??""),x=Fs.parse(g??""),y=f==="+"?m.add(x):m.subtract(x);if(y.isNaN())return Fp;e=e.replace(IV,y.toString())}return e}var UV=/\(([^()]*)\)/;function vze(t){for(var e=t,n;(n=UV.exec(e))!=null;){var[,r]=n;e=e.replace(UV,MJ(r))}return e}function yze(t){var e=t.replace(/\s+/g,"");return e=vze(e),e=MJ(e),e}function _ze(t){try{return yze(t)}catch{return Fp}}function AN(t){var e=_ze(t.slice(5,-1));return e===Fp?"":e}var wze=["x","y","lineHeight","capHeight","fill","scaleToFit","textAnchor","verticalAnchor"],Sze=["dx","dy","angle","className","breakAll"];function $P(){return $P=Object.assign?Object.assign.bind():function(t){for(var e=1;e{var{children:e,breakAll:n,style:r}=t;try{var i=[];yr(e)||(n?i=e.toString().split(""):i=e.toString().split(AJ));var s=i.map(o=>({word:o,width:e0(o,r).width})),a=n?0:e0(" ",r).width;return{wordsWithComputedWidth:s,spaceWidth:a}}catch{return null}};function Mze(t){return t==="start"||t==="middle"||t==="end"||t==="inherit"}var CJ=(t,e,n,r)=>t.reduce((i,s)=>{var{word:a,width:o}=s,l=i[i.length-1];if(l&&o!=null&&(e==null||r||l.width+o+nt.reduce((e,n)=>e.width>n.width?e:n),Aze="…",zV=(t,e,n,r,i,s,a,o)=>{var l=t.slice(0,e),u=TJ({breakAll:n,style:r,children:l+Aze});if(!u)return[!1,[]];var d=CJ(u.wordsWithComputedWidth,s,a,o),f=d.length>i||NJ(d).width>Number(s);return[f,d]},Tze=(t,e,n,r,i)=>{var{maxLines:s,children:a,style:o,breakAll:l}=t,u=Ct(s),d=String(a),f=CJ(e,r,n,i);if(!u||i)return f;var g=f.length>s||NJ(f).width>Number(r);if(!g)return f;for(var m=0,x=d.length-1,y=0,v;m<=x&&y<=d.length-1;){var b=Math.floor((m+x)/2),E=b-1,[S,A]=zV(d,E,l,o,s,r,n,i),[T]=zV(d,b,l,o,s,r,n,i);if(!S&&!T&&(m=b+1),S&&T&&(x=b-1),!S&&T){v=A;break}y++}return v||f},BV=t=>{var e=yr(t)?[]:t.toString().split(AJ);return[{words:e,width:void 0}]},Cze=t=>{var{width:e,scaleToFit:n,children:r,style:i,breakAll:s,maxLines:a}=t;if((e||n)&&!Xm.isSsr){var o,l,u=TJ({breakAll:s,children:r,style:i});if(u){var{wordsWithComputedWidth:d,spaceWidth:f}=u;o=d,l=f}else return BV(r);return Tze({breakAll:s,children:r,maxLines:a,style:i},o,l,e,!!n)}return BV(r)},kJ="#808080",Nze={angle:0,breakAll:!1,capHeight:"0.71em",fill:kJ,lineHeight:"1em",scaleToFit:!1,textAnchor:"start",verticalAnchor:"end",x:0,y:0},FE=M.forwardRef((t,e)=>{var n=ii(t,Nze),{x:r,y:i,lineHeight:s,capHeight:a,fill:o,scaleToFit:l,textAnchor:u,verticalAnchor:d}=n,f=FV(n,wze),g=M.useMemo(()=>Cze({breakAll:f.breakAll,children:f.children,maxLines:f.maxLines,scaleToFit:l,style:f.style,width:f.width}),[f.breakAll,f.children,f.maxLines,l,f.style,f.width]),{dx:m,dy:x,angle:y,className:v,breakAll:b}=f,E=FV(f,Sze);if(!fl(r)||!fl(i)||g.length===0)return null;var S=Number(r)+(Ct(m)?m:0),A=Number(i)+(Ct(x)?x:0);if(!ur(S)||!ur(A))return null;var T;switch(d){case"start":T=AN("calc(".concat(a,")"));break;case"middle":T=AN("calc(".concat((g.length-1)/2," * -").concat(s," + (").concat(a," / 2))"));break;default:T=AN("calc(".concat(g.length-1," * -").concat(s,")"));break}var P=[];if(l){var C=g[0].width,{width:I}=f;P.push("scale(".concat(Ct(I)&&Ct(C)?I/C:1,")"))}return y&&P.push("rotate(".concat(y,", ").concat(S,", ").concat(A,")")),P.length&&(E.transform=P.join(" ")),M.createElement("text",$P({},Cs(E),{ref:e,x:S,y:A,className:Tn("recharts-text",v),textAnchor:u,fill:o.includes("url")?kJ:o}),g.map((N,D)=>{var F=N.words.join(b?"":" ");return M.createElement("tspan",{x:S,dy:D===0?T:s,key:"".concat(F,"-").concat(D)},F)}))});FE.displayName="Text";var kze=["labelRef"];function Pze(t,e){if(t==null)return{};var n,r,i=Rze(t,e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(t);for(r=0;r{var{x:e,y:n,upperWidth:r,lowerWidth:i,width:s,height:a,children:o}=t,l=M.useMemo(()=>({x:e,y:n,upperWidth:r,lowerWidth:i,width:s,height:a}),[e,n,r,i,s,a]);return M.createElement(PJ.Provider,{value:l},o)},RJ=()=>{var t=M.useContext(PJ),e=gE();return t||YY(e)},Ize=M.createContext(null),Uze=()=>{var t=M.useContext(Ize),e=kt(wQ);return t||e},Fze=t=>{var{value:e,formatter:n}=t,r=yr(t.children)?e:t.children;return typeof n=="function"?n(r):r},Tj=t=>t!=null&&typeof t=="function",zze=(t,e)=>{var n=Di(e-t),r=Math.min(Math.abs(e-t),360);return n*r},Bze=(t,e,n,r,i)=>{var{offset:s,className:a}=t,{cx:o,cy:l,innerRadius:u,outerRadius:d,startAngle:f,endAngle:g,clockWise:m}=i,x=(u+d)/2,y=zze(f,g),v=y>=0?1:-1,b,E;switch(e){case"insideStart":b=f+v*s,E=m;break;case"insideEnd":b=g-v*s,E=!m;break;case"end":b=g+v*s,E=m;break;default:throw new Error("Unsupported position ".concat(e))}E=y<=0?E:!E;var S=Yr(o,l,x,b),A=Yr(o,l,x,b+(E?1:-1)*359),T="M".concat(S.x,",").concat(S.y,` + A`).concat(s,",").concat(s,",0,0,").concat(+(d<0),",").concat(A.x,",").concat(A.y,"Z")}else E+="L".concat(e,",").concat(n,"Z");return E},Xje={cx:0,cy:0,innerRadius:0,outerRadius:0,startAngle:0,endAngle:0,cornerRadius:0,forceCornerRadius:!1,cornerIsExternal:!1},bZ=t=>{var e=ii(t,Xje),{cx:n,cy:r,innerRadius:i,outerRadius:s,cornerRadius:a,forceCornerRadius:o,cornerIsExternal:l,startAngle:u,endAngle:d,className:f}=e;if(s0&&Math.abs(u-d)<360?y=Kje({cx:n,cy:r,innerRadius:i,outerRadius:s,cornerRadius:Math.min(x,m/2),forceCornerRadius:o,cornerIsExternal:l,startAngle:u,endAngle:d}):y=xZ({cx:n,cy:r,innerRadius:i,outerRadius:s,startAngle:u,endAngle:d}),M.createElement("path",CP({},Cs(e),{className:g,d:y}))};function Yje(t,e,n){if(t==="horizontal")return[{x:e.x,y:n.top},{x:e.x,y:n.top+n.height}];if(t==="vertical")return[{x:n.left,y:e.y},{x:n.left+n.width,y:e.y}];if(XX(e)){if(t==="centric"){var{cx:r,cy:i,innerRadius:s,outerRadius:a,angle:o}=e,l=Yr(r,i,s,o),u=Yr(r,i,a,o);return[{x:l.x,y:l.y},{x:u.x,y:u.y}]}return gZ(e)}}var hN={},fN={},pN={},_$;function Zje(){return _$||(_$=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});const e=oY();function n(r){return e.isSymbol(r)?NaN:Number(r)}t.toNumber=n})(pN)),pN}var w$;function Qje(){return w$||(w$=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});const e=Zje();function n(r){return r?(r=e.toNumber(r),r===1/0||r===-1/0?(r<0?-1:1)*Number.MAX_VALUE:r===r?r:0):r===0?r:0}t.toFinite=n})(fN)),fN}var S$;function Jje(){return S$||(S$=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});const e=lY(),n=Qje();function r(i,s,a){a&&typeof a!="number"&&e.isIterateeCall(i,s,a)&&(s=a=void 0),i=n.toFinite(i),s===void 0?(s=i,i=0):s=n.toFinite(s),a=a===void 0?ie?1:t>=e?0:NaN}function nLe(t,e){return t==null||e==null?NaN:et?1:e>=t?0:NaN}function xO(t){let e,n,r;t.length!==2?(e=Yu,n=(o,l)=>Yu(t(o),l),r=(o,l)=>t(o)-l):(e=t===Yu||t===nLe?t:rLe,n=t,r=t);function i(o,l,u=0,d=o.length){if(u>>1;n(o[f],l)<0?u=f+1:d=f}while(u>>1;n(o[f],l)<=0?u=f+1:d=f}while(uu&&r(o[f-1],l)>-r(o[f],l)?f-1:f}return{left:i,center:a,right:s}}function rLe(){return 0}function yZ(t){return t===null?NaN:+t}function*iLe(t,e){for(let n of t)n!=null&&(n=+n)>=n&&(yield n)}const sLe=xO(Yu),Mb=sLe.right;xO(yZ).center;class M$ extends Map{constructor(e,n=lLe){if(super(),Object.defineProperties(this,{_intern:{value:new Map},_key:{value:n}}),e!=null)for(const[r,i]of e)this.set(r,i)}get(e){return super.get(A$(this,e))}has(e){return super.has(A$(this,e))}set(e,n){return super.set(aLe(this,e),n)}delete(e){return super.delete(oLe(this,e))}}function A$({_intern:t,_key:e},n){const r=e(n);return t.has(r)?t.get(r):n}function aLe({_intern:t,_key:e},n){const r=e(n);return t.has(r)?t.get(r):(t.set(r,n),n)}function oLe({_intern:t,_key:e},n){const r=e(n);return t.has(r)&&(n=t.get(r),t.delete(r)),n}function lLe(t){return t!==null&&typeof t=="object"?t.valueOf():t}function cLe(t=Yu){if(t===Yu)return _Z;if(typeof t!="function")throw new TypeError("compare is not a function");return(e,n)=>{const r=t(e,n);return r||r===0?r:(t(n,n)===0)-(t(e,e)===0)}}function _Z(t,e){return(t==null||!(t>=t))-(e==null||!(e>=e))||(te?1:0)}const uLe=Math.sqrt(50),dLe=Math.sqrt(10),hLe=Math.sqrt(2);function Fw(t,e,n){const r=(e-t)/Math.max(0,n),i=Math.floor(Math.log10(r)),s=r/Math.pow(10,i),a=s>=uLe?10:s>=dLe?5:s>=hLe?2:1;let o,l,u;return i<0?(u=Math.pow(10,-i)/a,o=Math.round(t*u),l=Math.round(e*u),o/ue&&--l,u=-u):(u=Math.pow(10,i)*a,o=Math.round(t/u),l=Math.round(e/u),o*ue&&--l),l0))return[];if(t===e)return[t];const r=e=i))return[];const o=s-i+1,l=new Array(o);if(r)if(a<0)for(let u=0;u=r)&&(n=r);return n}function C$(t,e){let n;for(const r of t)r!=null&&(n>r||n===void 0&&r>=r)&&(n=r);return n}function wZ(t,e,n=0,r=1/0,i){if(e=Math.floor(e),n=Math.floor(Math.max(0,n)),r=Math.floor(Math.min(t.length-1,r)),!(n<=e&&e<=r))return t;for(i=i===void 0?_Z:cLe(i);r>n;){if(r-n>600){const l=r-n+1,u=e-n+1,d=Math.log(l),f=.5*Math.exp(2*d/3),g=.5*Math.sqrt(d*f*(l-f)/l)*(u-l/2<0?-1:1),m=Math.max(n,Math.floor(e-u*f/l+g)),x=Math.min(r,Math.floor(e+(l-u)*f/l+g));wZ(t,e,m,x,i)}const s=t[e];let a=n,o=r;for(gx(t,n,e),i(t[r],s)>0&&gx(t,n,r);a0;)--o}i(t[n],s)===0?gx(t,n,o):(++o,gx(t,o,r)),o<=e&&(n=o+1),e<=o&&(r=o-1)}return t}function gx(t,e,n){const r=t[e];t[e]=t[n],t[n]=r}function fLe(t,e,n){if(t=Float64Array.from(iLe(t)),!(!(r=t.length)||isNaN(e=+e))){if(e<=0||r<2)return C$(t);if(e>=1)return T$(t);var r,i=(r-1)*e,s=Math.floor(i),a=T$(wZ(t,s).subarray(0,s+1)),o=C$(t.subarray(s+1));return a+(o-a)*(i-s)}}function pLe(t,e,n=yZ){if(!(!(r=t.length)||isNaN(e=+e))){if(e<=0||r<2)return+n(t[0],0,t);if(e>=1)return+n(t[r-1],r-1,t);var r,i=(r-1)*e,s=Math.floor(i),a=+n(t[s],s,t),o=+n(t[s+1],s+1,t);return a+(o-a)*(i-s)}}function mLe(t,e,n){t=+t,e=+e,n=(i=arguments.length)<2?(e=t,t=0,1):i<3?1:+n;for(var r=-1,i=Math.max(0,Math.ceil((e-t)/n))|0,s=new Array(i);++r>8&15|e>>4&240,e>>4&15|e&240,(e&15)<<4|e&15,1):n===8?S_(e>>24&255,e>>16&255,e>>8&255,(e&255)/255):n===4?S_(e>>12&15|e>>8&240,e>>8&15|e>>4&240,e>>4&15|e&240,((e&15)<<4|e&15)/255):null):(e=bLe.exec(t))?new Hs(e[1],e[2],e[3],1):(e=vLe.exec(t))?new Hs(e[1]*255/100,e[2]*255/100,e[3]*255/100,1):(e=yLe.exec(t))?S_(e[1],e[2],e[3],e[4]):(e=_Le.exec(t))?S_(e[1]*255/100,e[2]*255/100,e[3]*255/100,e[4]):(e=wLe.exec(t))?j$(e[1],e[2]/100,e[3]/100,1):(e=SLe.exec(t))?j$(e[1],e[2]/100,e[3]/100,e[4]):N$.hasOwnProperty(t)?R$(N$[t]):t==="transparent"?new Hs(NaN,NaN,NaN,0):null}function R$(t){return new Hs(t>>16&255,t>>8&255,t&255,1)}function S_(t,e,n,r){return r<=0&&(t=e=n=NaN),new Hs(t,e,n,r)}function ALe(t){return t instanceof Ab||(t=K0(t)),t?(t=t.rgb(),new Hs(t.r,t.g,t.b,t.opacity)):new Hs}function DP(t,e,n,r){return arguments.length===1?ALe(t):new Hs(t,e,n,r??1)}function Hs(t,e,n,r){this.r=+t,this.g=+e,this.b=+n,this.opacity=+r}yO(Hs,DP,EZ(Ab,{brighter(t){return t=t==null?zw:Math.pow(zw,t),new Hs(this.r*t,this.g*t,this.b*t,this.opacity)},darker(t){return t=t==null?W0:Math.pow(W0,t),new Hs(this.r*t,this.g*t,this.b*t,this.opacity)},rgb(){return this},clamp(){return new Hs(Mh(this.r),Mh(this.g),Mh(this.b),Bw(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:D$,formatHex:D$,formatHex8:TLe,formatRgb:O$,toString:O$}));function D$(){return`#${uh(this.r)}${uh(this.g)}${uh(this.b)}`}function TLe(){return`#${uh(this.r)}${uh(this.g)}${uh(this.b)}${uh((isNaN(this.opacity)?1:this.opacity)*255)}`}function O$(){const t=Bw(this.opacity);return`${t===1?"rgb(":"rgba("}${Mh(this.r)}, ${Mh(this.g)}, ${Mh(this.b)}${t===1?")":`, ${t})`}`}function Bw(t){return isNaN(t)?1:Math.max(0,Math.min(1,t))}function Mh(t){return Math.max(0,Math.min(255,Math.round(t)||0))}function uh(t){return t=Mh(t),(t<16?"0":"")+t.toString(16)}function j$(t,e,n,r){return r<=0?t=e=n=NaN:n<=0||n>=1?t=e=NaN:e<=0&&(t=NaN),new Ao(t,e,n,r)}function MZ(t){if(t instanceof Ao)return new Ao(t.h,t.s,t.l,t.opacity);if(t instanceof Ab||(t=K0(t)),!t)return new Ao;if(t instanceof Ao)return t;t=t.rgb();var e=t.r/255,n=t.g/255,r=t.b/255,i=Math.min(e,n,r),s=Math.max(e,n,r),a=NaN,o=s-i,l=(s+i)/2;return o?(e===s?a=(n-r)/o+(n0&&l<1?0:a,new Ao(a,o,l,t.opacity)}function CLe(t,e,n,r){return arguments.length===1?MZ(t):new Ao(t,e,n,r??1)}function Ao(t,e,n,r){this.h=+t,this.s=+e,this.l=+n,this.opacity=+r}yO(Ao,CLe,EZ(Ab,{brighter(t){return t=t==null?zw:Math.pow(zw,t),new Ao(this.h,this.s,this.l*t,this.opacity)},darker(t){return t=t==null?W0:Math.pow(W0,t),new Ao(this.h,this.s,this.l*t,this.opacity)},rgb(){var t=this.h%360+(this.h<0)*360,e=isNaN(t)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*e,i=2*n-r;return new Hs(gN(t>=240?t-240:t+120,i,r),gN(t,i,r),gN(t<120?t+240:t-120,i,r),this.opacity)},clamp(){return new Ao(L$(this.h),E_(this.s),E_(this.l),Bw(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const t=Bw(this.opacity);return`${t===1?"hsl(":"hsla("}${L$(this.h)}, ${E_(this.s)*100}%, ${E_(this.l)*100}%${t===1?")":`, ${t})`}`}}));function L$(t){return t=(t||0)%360,t<0?t+360:t}function E_(t){return Math.max(0,Math.min(1,t||0))}function gN(t,e,n){return(t<60?e+(n-e)*t/60:t<180?n:t<240?e+(n-e)*(240-t)/60:e)*255}const _O=t=>()=>t;function NLe(t,e){return function(n){return t+n*e}}function kLe(t,e,n){return t=Math.pow(t,n),e=Math.pow(e,n)-t,n=1/n,function(r){return Math.pow(t+r*e,n)}}function PLe(t){return(t=+t)==1?AZ:function(e,n){return n-e?kLe(e,n,t):_O(isNaN(e)?n:e)}}function AZ(t,e){var n=e-t;return n?NLe(t,n):_O(isNaN(t)?e:t)}const I$=(function t(e){var n=PLe(e);function r(i,s){var a=n((i=DP(i)).r,(s=DP(s)).r),o=n(i.g,s.g),l=n(i.b,s.b),u=AZ(i.opacity,s.opacity);return function(d){return i.r=a(d),i.g=o(d),i.b=l(d),i.opacity=u(d),i+""}}return r.gamma=t,r})(1);function RLe(t,e){e||(e=[]);var n=t?Math.min(e.length,t.length):0,r=e.slice(),i;return function(s){for(i=0;in&&(s=e.slice(n,s),o[a]?o[a]+=s:o[++a]=s),(r=r[0])===(i=i[0])?o[a]?o[a]+=i:o[++a]=i:(o[++a]=null,l.push({i:a,x:Hw(r,i)})),n=xN.lastIndex;return ne&&(n=t,t=e,e=n),function(r){return Math.max(t,Math.min(e,r))}}function $Le(t,e,n){var r=t[0],i=t[1],s=e[0],a=e[1];return i2?VLe:$Le,l=u=null,f}function f(g){return g==null||isNaN(g=+g)?s:(l||(l=o(t.map(r),e,n)))(r(a(g)))}return f.invert=function(g){return a(i((u||(u=o(e,t.map(r),Hw)))(g)))},f.domain=function(g){return arguments.length?(t=Array.from(g,$w),d()):t.slice()},f.range=function(g){return arguments.length?(e=Array.from(g),d()):e.slice()},f.rangeRound=function(g){return e=Array.from(g),n=wO,d()},f.clamp=function(g){return arguments.length?(a=g?!0:Ss,d()):a!==Ss},f.interpolate=function(g){return arguments.length?(n=g,d()):n},f.unknown=function(g){return arguments.length?(s=g,f):s},function(g,m){return r=g,i=m,d()}}function SO(){return _E()(Ss,Ss)}function GLe(t){return Math.abs(t=Math.round(t))>=1e21?t.toLocaleString("en").replace(/,/g,""):t.toString(10)}function Vw(t,e){if((n=(t=e?t.toExponential(e-1):t.toExponential()).indexOf("e"))<0)return null;var n,r=t.slice(0,n);return[r.length>1?r[0]+r.slice(2):r,+t.slice(n+1)]}function km(t){return t=Vw(Math.abs(t)),t?t[1]:NaN}function WLe(t,e){return function(n,r){for(var i=n.length,s=[],a=0,o=t[0],l=0;i>0&&o>0&&(l+o+1>r&&(o=Math.max(1,r-l)),s.push(n.substring(i-=o,i+o)),!((l+=o+1)>r));)o=t[a=(a+1)%t.length];return s.reverse().join(e)}}function qLe(t){return function(e){return e.replace(/[0-9]/g,function(n){return t[+n]})}}var KLe=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function X0(t){if(!(e=KLe.exec(t)))throw new Error("invalid format: "+t);var e;return new EO({fill:e[1],align:e[2],sign:e[3],symbol:e[4],zero:e[5],width:e[6],comma:e[7],precision:e[8]&&e[8].slice(1),trim:e[9],type:e[10]})}X0.prototype=EO.prototype;function EO(t){this.fill=t.fill===void 0?" ":t.fill+"",this.align=t.align===void 0?">":t.align+"",this.sign=t.sign===void 0?"-":t.sign+"",this.symbol=t.symbol===void 0?"":t.symbol+"",this.zero=!!t.zero,this.width=t.width===void 0?void 0:+t.width,this.comma=!!t.comma,this.precision=t.precision===void 0?void 0:+t.precision,this.trim=!!t.trim,this.type=t.type===void 0?"":t.type+""}EO.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(this.width===void 0?"":Math.max(1,this.width|0))+(this.comma?",":"")+(this.precision===void 0?"":"."+Math.max(0,this.precision|0))+(this.trim?"~":"")+this.type};function XLe(t){e:for(var e=t.length,n=1,r=-1,i;n0&&(r=0);break}return r>0?t.slice(0,r)+t.slice(i+1):t}var TZ;function YLe(t,e){var n=Vw(t,e);if(!n)return t+"";var r=n[0],i=n[1],s=i-(TZ=Math.max(-8,Math.min(8,Math.floor(i/3)))*3)+1,a=r.length;return s===a?r:s>a?r+new Array(s-a+1).join("0"):s>0?r.slice(0,s)+"."+r.slice(s):"0."+new Array(1-s).join("0")+Vw(t,Math.max(0,e+s-1))[0]}function F$(t,e){var n=Vw(t,e);if(!n)return t+"";var r=n[0],i=n[1];return i<0?"0."+new Array(-i).join("0")+r:r.length>i+1?r.slice(0,i+1)+"."+r.slice(i+1):r+new Array(i-r.length+2).join("0")}const z$={"%":(t,e)=>(t*100).toFixed(e),b:t=>Math.round(t).toString(2),c:t=>t+"",d:GLe,e:(t,e)=>t.toExponential(e),f:(t,e)=>t.toFixed(e),g:(t,e)=>t.toPrecision(e),o:t=>Math.round(t).toString(8),p:(t,e)=>F$(t*100,e),r:F$,s:YLe,X:t=>Math.round(t).toString(16).toUpperCase(),x:t=>Math.round(t).toString(16)};function B$(t){return t}var H$=Array.prototype.map,$$=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function ZLe(t){var e=t.grouping===void 0||t.thousands===void 0?B$:WLe(H$.call(t.grouping,Number),t.thousands+""),n=t.currency===void 0?"":t.currency[0]+"",r=t.currency===void 0?"":t.currency[1]+"",i=t.decimal===void 0?".":t.decimal+"",s=t.numerals===void 0?B$:qLe(H$.call(t.numerals,String)),a=t.percent===void 0?"%":t.percent+"",o=t.minus===void 0?"−":t.minus+"",l=t.nan===void 0?"NaN":t.nan+"";function u(f){f=X0(f);var g=f.fill,m=f.align,x=f.sign,y=f.symbol,v=f.zero,b=f.width,E=f.comma,S=f.precision,A=f.trim,T=f.type;T==="n"?(E=!0,T="g"):z$[T]||(S===void 0&&(S=12),A=!0,T="g"),(v||g==="0"&&m==="=")&&(v=!0,g="0",m="=");var P=y==="$"?n:y==="#"&&/[boxX]/.test(T)?"0"+T.toLowerCase():"",C=y==="$"?r:/[%p]/.test(T)?a:"",I=z$[T],N=/[defgprs%]/.test(T);S=S===void 0?6:/[gprs]/.test(T)?Math.max(1,Math.min(21,S)):Math.max(0,Math.min(20,S));function D(F){var L=P,q=C,R,V,K;if(T==="c")q=I(F)+q,F="";else{F=+F;var W=F<0||1/F<0;if(F=isNaN(F)?l:I(Math.abs(F),S),A&&(F=XLe(F)),W&&+F==0&&x!=="+"&&(W=!1),L=(W?x==="("?x:o:x==="-"||x==="("?"":x)+L,q=(T==="s"?$$[8+TZ/3]:"")+q+(W&&x==="("?")":""),N){for(R=-1,V=F.length;++RK||K>57){q=(K===46?i+F.slice(R+1):F.slice(R))+q,F=F.slice(0,R);break}}}E&&!v&&(F=e(F,1/0));var ne=L.length+F.length+q.length,Y=ne>1)+L+F+q+Y.slice(ne);break;default:F=Y+L+F+q;break}return s(F)}return D.toString=function(){return f+""},D}function d(f,g){var m=u((f=X0(f),f.type="f",f)),x=Math.max(-8,Math.min(8,Math.floor(km(g)/3)))*3,y=Math.pow(10,-x),v=$$[8+x/3];return function(b){return m(y*b)+v}}return{format:u,formatPrefix:d}}var M_,MO,CZ;QLe({thousands:",",grouping:[3],currency:["$",""]});function QLe(t){return M_=ZLe(t),MO=M_.format,CZ=M_.formatPrefix,M_}function JLe(t){return Math.max(0,-km(Math.abs(t)))}function eIe(t,e){return Math.max(0,Math.max(-8,Math.min(8,Math.floor(km(e)/3)))*3-km(Math.abs(t)))}function tIe(t,e){return t=Math.abs(t),e=Math.abs(e)-t,Math.max(0,km(e)-km(t))+1}function NZ(t,e,n,r){var i=PP(t,e,n),s;switch(r=X0(r??",f"),r.type){case"s":{var a=Math.max(Math.abs(t),Math.abs(e));return r.precision==null&&!isNaN(s=eIe(i,a))&&(r.precision=s),CZ(r,a)}case"":case"e":case"g":case"p":case"r":{r.precision==null&&!isNaN(s=tIe(i,Math.max(Math.abs(t),Math.abs(e))))&&(r.precision=s-(r.type==="e"));break}case"f":case"%":{r.precision==null&&!isNaN(s=JLe(i))&&(r.precision=s-(r.type==="%")*2);break}}return MO(r)}function xd(t){var e=t.domain;return t.ticks=function(n){var r=e();return NP(r[0],r[r.length-1],n??10)},t.tickFormat=function(n,r){var i=e();return NZ(i[0],i[i.length-1],n??10,r)},t.nice=function(n){n==null&&(n=10);var r=e(),i=0,s=r.length-1,a=r[i],o=r[s],l,u,d=10;for(o0;){if(u=kP(a,o,n),u===l)return r[i]=a,r[s]=o,e(r);if(u>0)a=Math.floor(a/u)*u,o=Math.ceil(o/u)*u;else if(u<0)a=Math.ceil(a*u)/u,o=Math.floor(o*u)/u;else break;l=u}return t},t}function kZ(){var t=SO();return t.copy=function(){return Tb(t,kZ())},lo.apply(t,arguments),xd(t)}function PZ(t){var e;function n(r){return r==null||isNaN(r=+r)?e:r}return n.invert=n,n.domain=n.range=function(r){return arguments.length?(t=Array.from(r,$w),n):t.slice()},n.unknown=function(r){return arguments.length?(e=r,n):e},n.copy=function(){return PZ(t).unknown(e)},t=arguments.length?Array.from(t,$w):[0,1],xd(n)}function RZ(t,e){t=t.slice();var n=0,r=t.length-1,i=t[n],s=t[r],a;return sMath.pow(t,e)}function aIe(t){return t===Math.E?Math.log:t===10&&Math.log10||t===2&&Math.log2||(t=Math.log(t),e=>Math.log(e)/t)}function W$(t){return(e,n)=>-t(-e,n)}function AO(t){const e=t(V$,G$),n=e.domain;let r=10,i,s;function a(){return i=aIe(r),s=sIe(r),n()[0]<0?(i=W$(i),s=W$(s),t(nIe,rIe)):t(V$,G$),e}return e.base=function(o){return arguments.length?(r=+o,a()):r},e.domain=function(o){return arguments.length?(n(o),a()):n()},e.ticks=o=>{const l=n();let u=l[0],d=l[l.length-1];const f=d0){for(;g<=m;++g)for(x=1;xd)break;b.push(y)}}else for(;g<=m;++g)for(x=r-1;x>=1;--x)if(y=g>0?x/s(-g):x*s(g),!(yd)break;b.push(y)}b.length*2{if(o==null&&(o=10),l==null&&(l=r===10?"s":","),typeof l!="function"&&(!(r%1)&&(l=X0(l)).precision==null&&(l.trim=!0),l=MO(l)),o===1/0)return l;const u=Math.max(1,r*o/e.ticks().length);return d=>{let f=d/s(Math.round(i(d)));return f*rn(RZ(n(),{floor:o=>s(Math.floor(i(o))),ceil:o=>s(Math.ceil(i(o)))})),e}function DZ(){const t=AO(_E()).domain([1,10]);return t.copy=()=>Tb(t,DZ()).base(t.base()),lo.apply(t,arguments),t}function q$(t){return function(e){return Math.sign(e)*Math.log1p(Math.abs(e/t))}}function K$(t){return function(e){return Math.sign(e)*Math.expm1(Math.abs(e))*t}}function TO(t){var e=1,n=t(q$(e),K$(e));return n.constant=function(r){return arguments.length?t(q$(e=+r),K$(e)):e},xd(n)}function OZ(){var t=TO(_E());return t.copy=function(){return Tb(t,OZ()).constant(t.constant())},lo.apply(t,arguments)}function X$(t){return function(e){return e<0?-Math.pow(-e,t):Math.pow(e,t)}}function oIe(t){return t<0?-Math.sqrt(-t):Math.sqrt(t)}function lIe(t){return t<0?-t*t:t*t}function CO(t){var e=t(Ss,Ss),n=1;function r(){return n===1?t(Ss,Ss):n===.5?t(oIe,lIe):t(X$(n),X$(1/n))}return e.exponent=function(i){return arguments.length?(n=+i,r()):n},xd(e)}function NO(){var t=CO(_E());return t.copy=function(){return Tb(t,NO()).exponent(t.exponent())},lo.apply(t,arguments),t}function cIe(){return NO.apply(null,arguments).exponent(.5)}function Y$(t){return Math.sign(t)*t*t}function uIe(t){return Math.sign(t)*Math.sqrt(Math.abs(t))}function jZ(){var t=SO(),e=[0,1],n=!1,r;function i(s){var a=uIe(t(s));return isNaN(a)?r:n?Math.round(a):a}return i.invert=function(s){return t.invert(Y$(s))},i.domain=function(s){return arguments.length?(t.domain(s),i):t.domain()},i.range=function(s){return arguments.length?(t.range((e=Array.from(s,$w)).map(Y$)),i):e.slice()},i.rangeRound=function(s){return i.range(s).round(!0)},i.round=function(s){return arguments.length?(n=!!s,i):n},i.clamp=function(s){return arguments.length?(t.clamp(s),i):t.clamp()},i.unknown=function(s){return arguments.length?(r=s,i):r},i.copy=function(){return jZ(t.domain(),e).round(n).clamp(t.clamp()).unknown(r)},lo.apply(i,arguments),xd(i)}function LZ(){var t=[],e=[],n=[],r;function i(){var a=0,o=Math.max(1,e.length);for(n=new Array(o-1);++a0?n[o-1]:t[0],o=n?[r[n-1],e]:[r[u-1],r[u]]},a.unknown=function(l){return arguments.length&&(s=l),a},a.thresholds=function(){return r.slice()},a.copy=function(){return IZ().domain([t,e]).range(i).unknown(s)},lo.apply(xd(a),arguments)}function UZ(){var t=[.5],e=[0,1],n,r=1;function i(s){return s!=null&&s<=s?e[Mb(t,s,0,r)]:n}return i.domain=function(s){return arguments.length?(t=Array.from(s),r=Math.min(t.length,e.length-1),i):t.slice()},i.range=function(s){return arguments.length?(e=Array.from(s),r=Math.min(t.length,e.length-1),i):e.slice()},i.invertExtent=function(s){var a=e.indexOf(s);return[t[a-1],t[a]]},i.unknown=function(s){return arguments.length?(n=s,i):n},i.copy=function(){return UZ().domain(t).range(e).unknown(n)},lo.apply(i,arguments)}const bN=new Date,vN=new Date;function bi(t,e,n,r){function i(s){return t(s=arguments.length===0?new Date:new Date(+s)),s}return i.floor=s=>(t(s=new Date(+s)),s),i.ceil=s=>(t(s=new Date(s-1)),e(s,1),t(s),s),i.round=s=>{const a=i(s),o=i.ceil(s);return s-a(e(s=new Date(+s),a==null?1:Math.floor(a)),s),i.range=(s,a,o)=>{const l=[];if(s=i.ceil(s),o=o==null?1:Math.floor(o),!(s0))return l;let u;do l.push(u=new Date(+s)),e(s,o),t(s);while(ubi(a=>{if(a>=a)for(;t(a),!s(a);)a.setTime(a-1)},(a,o)=>{if(a>=a)if(o<0)for(;++o<=0;)for(;e(a,-1),!s(a););else for(;--o>=0;)for(;e(a,1),!s(a););}),n&&(i.count=(s,a)=>(bN.setTime(+s),vN.setTime(+a),t(bN),t(vN),Math.floor(n(bN,vN))),i.every=s=>(s=Math.floor(s),!isFinite(s)||!(s>0)?null:s>1?i.filter(r?a=>r(a)%s===0:a=>i.count(0,a)%s===0):i)),i}const Gw=bi(()=>{},(t,e)=>{t.setTime(+t+e)},(t,e)=>e-t);Gw.every=t=>(t=Math.floor(t),!isFinite(t)||!(t>0)?null:t>1?bi(e=>{e.setTime(Math.floor(e/t)*t)},(e,n)=>{e.setTime(+e+n*t)},(e,n)=>(n-e)/t):Gw);Gw.range;const cc=1e3,Qa=cc*60,uc=Qa*60,Ec=uc*24,kO=Ec*7,Z$=Ec*30,yN=Ec*365,dh=bi(t=>{t.setTime(t-t.getMilliseconds())},(t,e)=>{t.setTime(+t+e*cc)},(t,e)=>(e-t)/cc,t=>t.getUTCSeconds());dh.range;const PO=bi(t=>{t.setTime(t-t.getMilliseconds()-t.getSeconds()*cc)},(t,e)=>{t.setTime(+t+e*Qa)},(t,e)=>(e-t)/Qa,t=>t.getMinutes());PO.range;const RO=bi(t=>{t.setUTCSeconds(0,0)},(t,e)=>{t.setTime(+t+e*Qa)},(t,e)=>(e-t)/Qa,t=>t.getUTCMinutes());RO.range;const DO=bi(t=>{t.setTime(t-t.getMilliseconds()-t.getSeconds()*cc-t.getMinutes()*Qa)},(t,e)=>{t.setTime(+t+e*uc)},(t,e)=>(e-t)/uc,t=>t.getHours());DO.range;const OO=bi(t=>{t.setUTCMinutes(0,0,0)},(t,e)=>{t.setTime(+t+e*uc)},(t,e)=>(e-t)/uc,t=>t.getUTCHours());OO.range;const Cb=bi(t=>t.setHours(0,0,0,0),(t,e)=>t.setDate(t.getDate()+e),(t,e)=>(e-t-(e.getTimezoneOffset()-t.getTimezoneOffset())*Qa)/Ec,t=>t.getDate()-1);Cb.range;const wE=bi(t=>{t.setUTCHours(0,0,0,0)},(t,e)=>{t.setUTCDate(t.getUTCDate()+e)},(t,e)=>(e-t)/Ec,t=>t.getUTCDate()-1);wE.range;const FZ=bi(t=>{t.setUTCHours(0,0,0,0)},(t,e)=>{t.setUTCDate(t.getUTCDate()+e)},(t,e)=>(e-t)/Ec,t=>Math.floor(t/Ec));FZ.range;function af(t){return bi(e=>{e.setDate(e.getDate()-(e.getDay()+7-t)%7),e.setHours(0,0,0,0)},(e,n)=>{e.setDate(e.getDate()+n*7)},(e,n)=>(n-e-(n.getTimezoneOffset()-e.getTimezoneOffset())*Qa)/kO)}const SE=af(0),Ww=af(1),dIe=af(2),hIe=af(3),Pm=af(4),fIe=af(5),pIe=af(6);SE.range;Ww.range;dIe.range;hIe.range;Pm.range;fIe.range;pIe.range;function of(t){return bi(e=>{e.setUTCDate(e.getUTCDate()-(e.getUTCDay()+7-t)%7),e.setUTCHours(0,0,0,0)},(e,n)=>{e.setUTCDate(e.getUTCDate()+n*7)},(e,n)=>(n-e)/kO)}const EE=of(0),qw=of(1),mIe=of(2),gIe=of(3),Rm=of(4),xIe=of(5),bIe=of(6);EE.range;qw.range;mIe.range;gIe.range;Rm.range;xIe.range;bIe.range;const jO=bi(t=>{t.setDate(1),t.setHours(0,0,0,0)},(t,e)=>{t.setMonth(t.getMonth()+e)},(t,e)=>e.getMonth()-t.getMonth()+(e.getFullYear()-t.getFullYear())*12,t=>t.getMonth());jO.range;const LO=bi(t=>{t.setUTCDate(1),t.setUTCHours(0,0,0,0)},(t,e)=>{t.setUTCMonth(t.getUTCMonth()+e)},(t,e)=>e.getUTCMonth()-t.getUTCMonth()+(e.getUTCFullYear()-t.getUTCFullYear())*12,t=>t.getUTCMonth());LO.range;const Mc=bi(t=>{t.setMonth(0,1),t.setHours(0,0,0,0)},(t,e)=>{t.setFullYear(t.getFullYear()+e)},(t,e)=>e.getFullYear()-t.getFullYear(),t=>t.getFullYear());Mc.every=t=>!isFinite(t=Math.floor(t))||!(t>0)?null:bi(e=>{e.setFullYear(Math.floor(e.getFullYear()/t)*t),e.setMonth(0,1),e.setHours(0,0,0,0)},(e,n)=>{e.setFullYear(e.getFullYear()+n*t)});Mc.range;const Ac=bi(t=>{t.setUTCMonth(0,1),t.setUTCHours(0,0,0,0)},(t,e)=>{t.setUTCFullYear(t.getUTCFullYear()+e)},(t,e)=>e.getUTCFullYear()-t.getUTCFullYear(),t=>t.getUTCFullYear());Ac.every=t=>!isFinite(t=Math.floor(t))||!(t>0)?null:bi(e=>{e.setUTCFullYear(Math.floor(e.getUTCFullYear()/t)*t),e.setUTCMonth(0,1),e.setUTCHours(0,0,0,0)},(e,n)=>{e.setUTCFullYear(e.getUTCFullYear()+n*t)});Ac.range;function zZ(t,e,n,r,i,s){const a=[[dh,1,cc],[dh,5,5*cc],[dh,15,15*cc],[dh,30,30*cc],[s,1,Qa],[s,5,5*Qa],[s,15,15*Qa],[s,30,30*Qa],[i,1,uc],[i,3,3*uc],[i,6,6*uc],[i,12,12*uc],[r,1,Ec],[r,2,2*Ec],[n,1,kO],[e,1,Z$],[e,3,3*Z$],[t,1,yN]];function o(u,d,f){const g=dv).right(a,g);if(m===a.length)return t.every(PP(u/yN,d/yN,f));if(m===0)return Gw.every(Math.max(PP(u,d,f),1));const[x,y]=a[g/a[m-1][2]53)return null;"w"in de||(de.w=1),"Z"in de?(H=wN(xx(de.y,0,1)),z=H.getUTCDay(),H=z>4||z===0?qw.ceil(H):qw(H),H=wE.offset(H,(de.V-1)*7),de.y=H.getUTCFullYear(),de.m=H.getUTCMonth(),de.d=H.getUTCDate()+(de.w+6)%7):(H=_N(xx(de.y,0,1)),z=H.getDay(),H=z>4||z===0?Ww.ceil(H):Ww(H),H=Cb.offset(H,(de.V-1)*7),de.y=H.getFullYear(),de.m=H.getMonth(),de.d=H.getDate()+(de.w+6)%7)}else("W"in de||"U"in de)&&("w"in de||(de.w="u"in de?de.u%7:"W"in de?1:0),z="Z"in de?wN(xx(de.y,0,1)).getUTCDay():_N(xx(de.y,0,1)).getDay(),de.m=0,de.d="W"in de?(de.w+6)%7+de.W*7-(z+5)%7:de.w+de.U*7-(z+6)%7);return"Z"in de?(de.H+=de.Z/100|0,de.M+=de.Z%100,wN(de)):_N(de)}}function I(se,ve,je,de){for(var ut=0,H=ve.length,z=je.length,re,G;ut=z)return-1;if(re=ve.charCodeAt(ut++),re===37){if(re=ve.charAt(ut++),G=T[re in Q$?ve.charAt(ut++):re],!G||(de=G(se,je,de))<0)return-1}else if(re!=je.charCodeAt(de++))return-1}return de}function N(se,ve,je){var de=u.exec(ve.slice(je));return de?(se.p=d.get(de[0].toLowerCase()),je+de[0].length):-1}function D(se,ve,je){var de=m.exec(ve.slice(je));return de?(se.w=x.get(de[0].toLowerCase()),je+de[0].length):-1}function F(se,ve,je){var de=f.exec(ve.slice(je));return de?(se.w=g.get(de[0].toLowerCase()),je+de[0].length):-1}function L(se,ve,je){var de=b.exec(ve.slice(je));return de?(se.m=E.get(de[0].toLowerCase()),je+de[0].length):-1}function q(se,ve,je){var de=y.exec(ve.slice(je));return de?(se.m=v.get(de[0].toLowerCase()),je+de[0].length):-1}function R(se,ve,je){return I(se,e,ve,je)}function V(se,ve,je){return I(se,n,ve,je)}function K(se,ve,je){return I(se,r,ve,je)}function W(se){return a[se.getDay()]}function ne(se){return s[se.getDay()]}function Y(se){return l[se.getMonth()]}function Z(se){return o[se.getMonth()]}function U(se){return i[+(se.getHours()>=12)]}function $(se){return 1+~~(se.getMonth()/3)}function ee(se){return a[se.getUTCDay()]}function ae(se){return s[se.getUTCDay()]}function fe(se){return l[se.getUTCMonth()]}function ue(se){return o[se.getUTCMonth()]}function xe(se){return i[+(se.getUTCHours()>=12)]}function Me(se){return 1+~~(se.getUTCMonth()/3)}return{format:function(se){var ve=P(se+="",S);return ve.toString=function(){return se},ve},parse:function(se){var ve=C(se+="",!1);return ve.toString=function(){return se},ve},utcFormat:function(se){var ve=P(se+="",A);return ve.toString=function(){return se},ve},utcParse:function(se){var ve=C(se+="",!0);return ve.toString=function(){return se},ve}}}var Q$={"-":"",_:" ",0:"0"},Li=/^\s*\d+/,EIe=/^%/,MIe=/[\\^$*+?|[\]().{}]/g;function Cn(t,e,n){var r=t<0?"-":"",i=(r?-t:t)+"",s=i.length;return r+(s[e.toLowerCase(),n]))}function TIe(t,e,n){var r=Li.exec(e.slice(n,n+1));return r?(t.w=+r[0],n+r[0].length):-1}function CIe(t,e,n){var r=Li.exec(e.slice(n,n+1));return r?(t.u=+r[0],n+r[0].length):-1}function NIe(t,e,n){var r=Li.exec(e.slice(n,n+2));return r?(t.U=+r[0],n+r[0].length):-1}function kIe(t,e,n){var r=Li.exec(e.slice(n,n+2));return r?(t.V=+r[0],n+r[0].length):-1}function PIe(t,e,n){var r=Li.exec(e.slice(n,n+2));return r?(t.W=+r[0],n+r[0].length):-1}function J$(t,e,n){var r=Li.exec(e.slice(n,n+4));return r?(t.y=+r[0],n+r[0].length):-1}function eV(t,e,n){var r=Li.exec(e.slice(n,n+2));return r?(t.y=+r[0]+(+r[0]>68?1900:2e3),n+r[0].length):-1}function RIe(t,e,n){var r=/^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(e.slice(n,n+6));return r?(t.Z=r[1]?0:-(r[2]+(r[3]||"00")),n+r[0].length):-1}function DIe(t,e,n){var r=Li.exec(e.slice(n,n+1));return r?(t.q=r[0]*3-3,n+r[0].length):-1}function OIe(t,e,n){var r=Li.exec(e.slice(n,n+2));return r?(t.m=r[0]-1,n+r[0].length):-1}function tV(t,e,n){var r=Li.exec(e.slice(n,n+2));return r?(t.d=+r[0],n+r[0].length):-1}function jIe(t,e,n){var r=Li.exec(e.slice(n,n+3));return r?(t.m=0,t.d=+r[0],n+r[0].length):-1}function nV(t,e,n){var r=Li.exec(e.slice(n,n+2));return r?(t.H=+r[0],n+r[0].length):-1}function LIe(t,e,n){var r=Li.exec(e.slice(n,n+2));return r?(t.M=+r[0],n+r[0].length):-1}function IIe(t,e,n){var r=Li.exec(e.slice(n,n+2));return r?(t.S=+r[0],n+r[0].length):-1}function UIe(t,e,n){var r=Li.exec(e.slice(n,n+3));return r?(t.L=+r[0],n+r[0].length):-1}function FIe(t,e,n){var r=Li.exec(e.slice(n,n+6));return r?(t.L=Math.floor(r[0]/1e3),n+r[0].length):-1}function zIe(t,e,n){var r=EIe.exec(e.slice(n,n+1));return r?n+r[0].length:-1}function BIe(t,e,n){var r=Li.exec(e.slice(n));return r?(t.Q=+r[0],n+r[0].length):-1}function HIe(t,e,n){var r=Li.exec(e.slice(n));return r?(t.s=+r[0],n+r[0].length):-1}function rV(t,e){return Cn(t.getDate(),e,2)}function $Ie(t,e){return Cn(t.getHours(),e,2)}function VIe(t,e){return Cn(t.getHours()%12||12,e,2)}function GIe(t,e){return Cn(1+Cb.count(Mc(t),t),e,3)}function BZ(t,e){return Cn(t.getMilliseconds(),e,3)}function WIe(t,e){return BZ(t,e)+"000"}function qIe(t,e){return Cn(t.getMonth()+1,e,2)}function KIe(t,e){return Cn(t.getMinutes(),e,2)}function XIe(t,e){return Cn(t.getSeconds(),e,2)}function YIe(t){var e=t.getDay();return e===0?7:e}function ZIe(t,e){return Cn(SE.count(Mc(t)-1,t),e,2)}function HZ(t){var e=t.getDay();return e>=4||e===0?Pm(t):Pm.ceil(t)}function QIe(t,e){return t=HZ(t),Cn(Pm.count(Mc(t),t)+(Mc(t).getDay()===4),e,2)}function JIe(t){return t.getDay()}function e4e(t,e){return Cn(Ww.count(Mc(t)-1,t),e,2)}function t4e(t,e){return Cn(t.getFullYear()%100,e,2)}function n4e(t,e){return t=HZ(t),Cn(t.getFullYear()%100,e,2)}function r4e(t,e){return Cn(t.getFullYear()%1e4,e,4)}function i4e(t,e){var n=t.getDay();return t=n>=4||n===0?Pm(t):Pm.ceil(t),Cn(t.getFullYear()%1e4,e,4)}function s4e(t){var e=t.getTimezoneOffset();return(e>0?"-":(e*=-1,"+"))+Cn(e/60|0,"0",2)+Cn(e%60,"0",2)}function iV(t,e){return Cn(t.getUTCDate(),e,2)}function a4e(t,e){return Cn(t.getUTCHours(),e,2)}function o4e(t,e){return Cn(t.getUTCHours()%12||12,e,2)}function l4e(t,e){return Cn(1+wE.count(Ac(t),t),e,3)}function $Z(t,e){return Cn(t.getUTCMilliseconds(),e,3)}function c4e(t,e){return $Z(t,e)+"000"}function u4e(t,e){return Cn(t.getUTCMonth()+1,e,2)}function d4e(t,e){return Cn(t.getUTCMinutes(),e,2)}function h4e(t,e){return Cn(t.getUTCSeconds(),e,2)}function f4e(t){var e=t.getUTCDay();return e===0?7:e}function p4e(t,e){return Cn(EE.count(Ac(t)-1,t),e,2)}function VZ(t){var e=t.getUTCDay();return e>=4||e===0?Rm(t):Rm.ceil(t)}function m4e(t,e){return t=VZ(t),Cn(Rm.count(Ac(t),t)+(Ac(t).getUTCDay()===4),e,2)}function g4e(t){return t.getUTCDay()}function x4e(t,e){return Cn(qw.count(Ac(t)-1,t),e,2)}function b4e(t,e){return Cn(t.getUTCFullYear()%100,e,2)}function v4e(t,e){return t=VZ(t),Cn(t.getUTCFullYear()%100,e,2)}function y4e(t,e){return Cn(t.getUTCFullYear()%1e4,e,4)}function _4e(t,e){var n=t.getUTCDay();return t=n>=4||n===0?Rm(t):Rm.ceil(t),Cn(t.getUTCFullYear()%1e4,e,4)}function w4e(){return"+0000"}function sV(){return"%"}function aV(t){return+t}function oV(t){return Math.floor(+t/1e3)}var Sp,GZ,WZ;S4e({dateTime:"%x, %X",date:"%-m/%-d/%Y",time:"%-I:%M:%S %p",periods:["AM","PM"],days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]});function S4e(t){return Sp=SIe(t),GZ=Sp.format,Sp.parse,WZ=Sp.utcFormat,Sp.utcParse,Sp}function E4e(t){return new Date(t)}function M4e(t){return t instanceof Date?+t:+new Date(+t)}function IO(t,e,n,r,i,s,a,o,l,u){var d=SO(),f=d.invert,g=d.domain,m=u(".%L"),x=u(":%S"),y=u("%I:%M"),v=u("%I %p"),b=u("%a %d"),E=u("%b %d"),S=u("%B"),A=u("%Y");function T(P){return(l(P)e(i/(t.length-1)))},n.quantiles=function(r){return Array.from({length:r+1},(i,s)=>fLe(t,s/r))},n.copy=function(){return YZ(e).domain(t)},Dc.apply(n,arguments)}function AE(){var t=0,e=.5,n=1,r=1,i,s,a,o,l,u=Ss,d,f=!1,g;function m(y){return isNaN(y=+y)?g:(y=.5+((y=+d(y))-s)*(r*yt.chartData,zO=Ke([vd],t=>{var e=t.chartData!=null?t.chartData.length-1:0;return{chartData:t.chartData,computedData:t.computedData,dataEndIndex:e,dataStartIndex:0}}),TE=(t,e,n,r)=>r?zO(t):vd(t);function ad(t){if(Array.isArray(t)&&t.length===2){var[e,n]=t;if(ur(e)&&ur(n))return!0}return!1}function lV(t,e,n){return n?t:[Math.min(t[0],e[0]),Math.max(t[1],e[1])]}function eQ(t,e){if(e&&typeof t!="function"&&Array.isArray(t)&&t.length===2){var[n,r]=t,i,s;if(ur(n))i=n;else if(typeof n=="function")return;if(ur(r))s=r;else if(typeof r=="function")return;var a=[i,s];if(ad(a))return a}}function k4e(t,e,n){if(!(!n&&e==null)){if(typeof t=="function"&&e!=null)try{var r=t(e,n);if(ad(r))return lV(r,e,n)}catch{}if(Array.isArray(t)&&t.length===2){var[i,s]=t,a,o;if(i==="auto")e!=null&&(a=Math.min(...e));else if(Ct(i))a=i;else if(typeof i=="function")try{e!=null&&(a=i(e?.[0]))}catch{}else if(typeof i=="string"&&LH.test(i)){var l=LH.exec(i);if(l==null||e==null)a=void 0;else{var u=+l[1];a=e[0]-u}}else a=e?.[0];if(s==="auto")e!=null&&(o=Math.max(...e));else if(Ct(s))o=s;else if(typeof s=="function")try{e!=null&&(o=s(e?.[1]))}catch{}else if(typeof s=="string"&&IH.test(s)){var d=IH.exec(s);if(d==null||e==null)o=void 0;else{var f=+d[1];o=e[1]+f}}else o=e?.[1];var g=[a,o];if(ad(g))return e==null?g:lV(g,e,n)}}}var Zm=1e9,P4e={precision:20,rounding:4,toExpNeg:-7,toExpPos:21,LN10:"2.302585092994045684017991454684364207601101488628772976033327900967572609677352480235997205089598298341967784042286"},HO,mr=!0,ao="[DecimalError] ",Ah=ao+"Invalid argument: ",BO=ao+"Exponent out of range: ",Qm=Math.floor,Zd=Math.pow,R4e=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,fa,ki=1e7,lr=7,tQ=9007199254740991,Kw=Qm(tQ/lr),Pt={};Pt.absoluteValue=Pt.abs=function(){var t=new this.constructor(this);return t.s&&(t.s=1),t};Pt.comparedTo=Pt.cmp=function(t){var e,n,r,i,s=this;if(t=new s.constructor(t),s.s!==t.s)return s.s||-t.s;if(s.e!==t.e)return s.e>t.e^s.s<0?1:-1;for(r=s.d.length,i=t.d.length,e=0,n=rt.d[e]^s.s<0?1:-1;return r===i?0:r>i^s.s<0?1:-1};Pt.decimalPlaces=Pt.dp=function(){var t=this,e=t.d.length-1,n=(e-t.e)*lr;if(e=t.d[e],e)for(;e%10==0;e/=10)n--;return n<0?0:n};Pt.dividedBy=Pt.div=function(t){return xc(this,new this.constructor(t))};Pt.dividedToIntegerBy=Pt.idiv=function(t){var e=this,n=e.constructor;return er(xc(e,new n(t),0,1),n.precision)};Pt.equals=Pt.eq=function(t){return!this.cmp(t)};Pt.exponent=function(){return ei(this)};Pt.greaterThan=Pt.gt=function(t){return this.cmp(t)>0};Pt.greaterThanOrEqualTo=Pt.gte=function(t){return this.cmp(t)>=0};Pt.isInteger=Pt.isint=function(){return this.e>this.d.length-2};Pt.isNegative=Pt.isneg=function(){return this.s<0};Pt.isPositive=Pt.ispos=function(){return this.s>0};Pt.isZero=function(){return this.s===0};Pt.lessThan=Pt.lt=function(t){return this.cmp(t)<0};Pt.lessThanOrEqualTo=Pt.lte=function(t){return this.cmp(t)<1};Pt.logarithm=Pt.log=function(t){var e,n=this,r=n.constructor,i=r.precision,s=i+5;if(t===void 0)t=new r(10);else if(t=new r(t),t.s<1||t.eq(fa))throw Error(ao+"NaN");if(n.s<1)throw Error(ao+(n.s?"NaN":"-Infinity"));return n.eq(fa)?new r(0):(mr=!1,e=xc(Y0(n,s),Y0(t,s),s),mr=!0,er(e,i))};Pt.minus=Pt.sub=function(t){var e=this;return t=new e.constructor(t),e.s==t.s?iQ(e,t):nQ(e,(t.s=-t.s,t))};Pt.modulo=Pt.mod=function(t){var e,n=this,r=n.constructor,i=r.precision;if(t=new r(t),!t.s)throw Error(ao+"NaN");return n.s?(mr=!1,e=xc(n,t,0,1).times(t),mr=!0,n.minus(e)):er(new r(n),i)};Pt.naturalExponential=Pt.exp=function(){return rQ(this)};Pt.naturalLogarithm=Pt.ln=function(){return Y0(this)};Pt.negated=Pt.neg=function(){var t=new this.constructor(this);return t.s=-t.s||0,t};Pt.plus=Pt.add=function(t){var e=this;return t=new e.constructor(t),e.s==t.s?nQ(e,t):iQ(e,(t.s=-t.s,t))};Pt.precision=Pt.sd=function(t){var e,n,r,i=this;if(t!==void 0&&t!==!!t&&t!==1&&t!==0)throw Error(Ah+t);if(e=ei(i)+1,r=i.d.length-1,n=r*lr+1,r=i.d[r],r){for(;r%10==0;r/=10)n--;for(r=i.d[0];r>=10;r/=10)n++}return t&&e>n?e:n};Pt.squareRoot=Pt.sqrt=function(){var t,e,n,r,i,s,a,o=this,l=o.constructor;if(o.s<1){if(!o.s)return new l(0);throw Error(ao+"NaN")}for(t=ei(o),mr=!1,i=Math.sqrt(+o),i==0||i==1/0?(e=il(o.d),(e.length+t)%2==0&&(e+="0"),i=Math.sqrt(e),t=Qm((t+1)/2)-(t<0||t%2),i==1/0?e="5e"+t:(e=i.toExponential(),e=e.slice(0,e.indexOf("e")+1)+t),r=new l(e)):r=new l(i.toString()),n=l.precision,i=a=n+3;;)if(s=r,r=s.plus(xc(o,s,a+2)).times(.5),il(s.d).slice(0,a)===(e=il(r.d)).slice(0,a)){if(e=e.slice(a-3,a+1),i==a&&e=="4999"){if(er(s,n+1,0),s.times(s).eq(o)){r=s;break}}else if(e!="9999")break;a+=4}return mr=!0,er(r,n)};Pt.times=Pt.mul=function(t){var e,n,r,i,s,a,o,l,u,d=this,f=d.constructor,g=d.d,m=(t=new f(t)).d;if(!d.s||!t.s)return new f(0);for(t.s*=d.s,n=d.e+t.e,l=g.length,u=m.length,l=0;){for(e=0,i=l+r;i>r;)o=s[i]+m[r]*g[i-r-1]+e,s[i--]=o%ki|0,e=o/ki|0;s[i]=(s[i]+e)%ki|0}for(;!s[--a];)s.pop();return e?++n:s.shift(),t.d=s,t.e=n,mr?er(t,f.precision):t};Pt.toDecimalPlaces=Pt.todp=function(t,e){var n=this,r=n.constructor;return n=new r(n),t===void 0?n:(ml(t,0,Zm),e===void 0?e=r.rounding:ml(e,0,8),er(n,t+ei(n)+1,e))};Pt.toExponential=function(t,e){var n,r=this,i=r.constructor;return t===void 0?n=Zh(r,!0):(ml(t,0,Zm),e===void 0?e=i.rounding:ml(e,0,8),r=er(new i(r),t+1,e),n=Zh(r,!0,t+1)),n};Pt.toFixed=function(t,e){var n,r,i=this,s=i.constructor;return t===void 0?Zh(i):(ml(t,0,Zm),e===void 0?e=s.rounding:ml(e,0,8),r=er(new s(i),t+ei(i)+1,e),n=Zh(r.abs(),!1,t+ei(r)+1),i.isneg()&&!i.isZero()?"-"+n:n)};Pt.toInteger=Pt.toint=function(){var t=this,e=t.constructor;return er(new e(t),ei(t)+1,e.rounding)};Pt.toNumber=function(){return+this};Pt.toPower=Pt.pow=function(t){var e,n,r,i,s,a,o=this,l=o.constructor,u=12,d=+(t=new l(t));if(!t.s)return new l(fa);if(o=new l(o),!o.s){if(t.s<1)throw Error(ao+"Infinity");return o}if(o.eq(fa))return o;if(r=l.precision,t.eq(fa))return er(o,r);if(e=t.e,n=t.d.length-1,a=e>=n,s=o.s,a){if((n=d<0?-d:d)<=tQ){for(i=new l(fa),e=Math.ceil(r/lr+4),mr=!1;n%2&&(i=i.times(o),uV(i.d,e)),n=Qm(n/2),n!==0;)o=o.times(o),uV(o.d,e);return mr=!0,t.s<0?new l(fa).div(i):er(i,r)}}else if(s<0)throw Error(ao+"NaN");return s=s<0&&t.d[Math.max(e,n)]&1?-1:1,o.s=1,mr=!1,i=t.times(Y0(o,r+u)),mr=!0,i=rQ(i),i.s=s,i};Pt.toPrecision=function(t,e){var n,r,i=this,s=i.constructor;return t===void 0?(n=ei(i),r=Zh(i,n<=s.toExpNeg||n>=s.toExpPos)):(ml(t,1,Zm),e===void 0?e=s.rounding:ml(e,0,8),i=er(new s(i),t,e),n=ei(i),r=Zh(i,t<=n||n<=s.toExpNeg,t)),r};Pt.toSignificantDigits=Pt.tosd=function(t,e){var n=this,r=n.constructor;return t===void 0?(t=r.precision,e=r.rounding):(ml(t,1,Zm),e===void 0?e=r.rounding:ml(e,0,8)),er(new r(n),t,e)};Pt.toString=Pt.valueOf=Pt.val=Pt.toJSON=Pt[Symbol.for("nodejs.util.inspect.custom")]=function(){var t=this,e=ei(t),n=t.constructor;return Zh(t,e<=n.toExpNeg||e>=n.toExpPos)};function nQ(t,e){var n,r,i,s,a,o,l,u,d=t.constructor,f=d.precision;if(!t.s||!e.s)return e.s||(e=new d(t)),mr?er(e,f):e;if(l=t.d,u=e.d,a=t.e,i=e.e,l=l.slice(),s=a-i,s){for(s<0?(r=l,s=-s,o=u.length):(r=u,i=a,o=l.length),a=Math.ceil(f/lr),o=a>o?a+1:o+1,s>o&&(s=o,r.length=1),r.reverse();s--;)r.push(0);r.reverse()}for(o=l.length,s=u.length,o-s<0&&(s=o,r=u,u=l,l=r),n=0;s;)n=(l[--s]=l[s]+u[s]+n)/ki|0,l[s]%=ki;for(n&&(l.unshift(n),++i),o=l.length;l[--o]==0;)l.pop();return e.d=l,e.e=i,mr?er(e,f):e}function ml(t,e,n){if(t!==~~t||tn)throw Error(Ah+t)}function il(t){var e,n,r,i=t.length-1,s="",a=t[0];if(i>0){for(s+=a,e=1;ea?1:-1;else for(o=l=0;oi[o]?1:-1;break}return l}function n(r,i,s){for(var a=0;s--;)r[s]-=a,a=r[s]1;)r.shift()}return function(r,i,s,a){var o,l,u,d,f,g,m,x,y,v,b,E,S,A,T,P,C,I,N=r.constructor,D=r.s==i.s?1:-1,F=r.d,L=i.d;if(!r.s)return new N(r);if(!i.s)throw Error(ao+"Division by zero");for(l=r.e-i.e,C=L.length,T=F.length,m=new N(D),x=m.d=[],u=0;L[u]==(F[u]||0);)++u;if(L[u]>(F[u]||0)&&--l,s==null?E=s=N.precision:a?E=s+(ei(r)-ei(i))+1:E=s,E<0)return new N(0);if(E=E/lr+2|0,u=0,C==1)for(d=0,L=L[0],E++;(u1&&(L=t(L,d),F=t(F,d),C=L.length,T=F.length),A=C,y=F.slice(0,C),v=y.length;v=ki/2&&++P;do d=0,o=e(L,y,C,v),o<0?(b=y[0],C!=v&&(b=b*ki+(y[1]||0)),d=b/P|0,d>1?(d>=ki&&(d=ki-1),f=t(L,d),g=f.length,v=y.length,o=e(f,y,g,v),o==1&&(d--,n(f,C16)throw Error(BO+ei(t));if(!t.s)return new d(fa);for(mr=!1,o=f,a=new d(.03125);t.abs().gte(.1);)t=t.times(a),u+=5;for(r=Math.log(Zd(2,u))/Math.LN10*2+5|0,o+=r,n=i=s=new d(fa),d.precision=o;;){if(i=er(i.times(t),o),n=n.times(++l),a=s.plus(xc(i,n,o)),il(a.d).slice(0,o)===il(s.d).slice(0,o)){for(;u--;)s=er(s.times(s),o);return d.precision=f,e==null?(mr=!0,er(s,f)):s}s=a}}function ei(t){for(var e=t.e*lr,n=t.d[0];n>=10;n/=10)e++;return e}function SN(t,e,n){if(e>t.LN10.sd())throw mr=!0,n&&(t.precision=n),Error(ao+"LN10 precision limit exceeded");return er(new t(t.LN10),e)}function Cu(t){for(var e="";t--;)e+="0";return e}function Y0(t,e){var n,r,i,s,a,o,l,u,d,f=1,g=10,m=t,x=m.d,y=m.constructor,v=y.precision;if(m.s<1)throw Error(ao+(m.s?"NaN":"-Infinity"));if(m.eq(fa))return new y(0);if(e==null?(mr=!1,u=v):u=e,m.eq(10))return e==null&&(mr=!0),SN(y,u);if(u+=g,y.precision=u,n=il(x),r=n.charAt(0),s=ei(m),Math.abs(s)<15e14){for(;r<7&&r!=1||r==1&&n.charAt(1)>3;)m=m.times(t),n=il(m.d),r=n.charAt(0),f++;s=ei(m),r>1?(m=new y("0."+n),s++):m=new y(r+"."+n.slice(1))}else return l=SN(y,u+2,v).times(s+""),m=Y0(new y(r+"."+n.slice(1)),u-g).plus(l),y.precision=v,e==null?(mr=!0,er(m,v)):m;for(o=a=m=xc(m.minus(fa),m.plus(fa),u),d=er(m.times(m),u),i=3;;){if(a=er(a.times(d),u),l=o.plus(xc(a,new y(i),u)),il(l.d).slice(0,u)===il(o.d).slice(0,u))return o=o.times(2),s!==0&&(o=o.plus(SN(y,u+2,v).times(s+""))),o=xc(o,new y(f),u),y.precision=v,e==null?(mr=!0,er(o,v)):o;o=l,i+=2}}function cV(t,e){var n,r,i;for((n=e.indexOf("."))>-1&&(e=e.replace(".","")),(r=e.search(/e/i))>0?(n<0&&(n=r),n+=+e.slice(r+1),e=e.substring(0,r)):n<0&&(n=e.length),r=0;e.charCodeAt(r)===48;)++r;for(i=e.length;e.charCodeAt(i-1)===48;)--i;if(e=e.slice(r,i),e){if(i-=r,n=n-r-1,t.e=Qm(n/lr),t.d=[],r=(n+1)%lr,n<0&&(r+=lr),rKw||t.e<-Kw))throw Error(BO+n)}else t.s=0,t.e=0,t.d=[0];return t}function er(t,e,n){var r,i,s,a,o,l,u,d,f=t.d;for(a=1,s=f[0];s>=10;s/=10)a++;if(r=e-a,r<0)r+=lr,i=e,u=f[d=0];else{if(d=Math.ceil((r+1)/lr),s=f.length,d>=s)return t;for(u=s=f[d],a=1;s>=10;s/=10)a++;r%=lr,i=r-lr+a}if(n!==void 0&&(s=Zd(10,a-i-1),o=u/s%10|0,l=e<0||f[d+1]!==void 0||u%s,l=n<4?(o||l)&&(n==0||n==(t.s<0?3:2)):o>5||o==5&&(n==4||l||n==6&&(r>0?i>0?u/Zd(10,a-i):0:f[d-1])%10&1||n==(t.s<0?8:7))),e<1||!f[0])return l?(s=ei(t),f.length=1,e=e-s-1,f[0]=Zd(10,(lr-e%lr)%lr),t.e=Qm(-e/lr)||0):(f.length=1,f[0]=t.e=t.s=0),t;if(r==0?(f.length=d,s=1,d--):(f.length=d+1,s=Zd(10,lr-r),f[d]=i>0?(u/Zd(10,a-i)%Zd(10,i)|0)*s:0),l)for(;;)if(d==0){(f[0]+=s)==ki&&(f[0]=1,++t.e);break}else{if(f[d]+=s,f[d]!=ki)break;f[d--]=0,s=1}for(r=f.length;f[--r]===0;)f.pop();if(mr&&(t.e>Kw||t.e<-Kw))throw Error(BO+ei(t));return t}function iQ(t,e){var n,r,i,s,a,o,l,u,d,f,g=t.constructor,m=g.precision;if(!t.s||!e.s)return e.s?e.s=-e.s:e=new g(t),mr?er(e,m):e;if(l=t.d,f=e.d,r=e.e,u=t.e,l=l.slice(),a=u-r,a){for(d=a<0,d?(n=l,a=-a,o=f.length):(n=f,r=u,o=l.length),i=Math.max(Math.ceil(m/lr),o)+2,a>i&&(a=i,n.length=1),n.reverse(),i=a;i--;)n.push(0);n.reverse()}else{for(i=l.length,o=f.length,d=i0;--i)l[o++]=0;for(i=f.length;i>a;){if(l[--i]0?s=s.charAt(0)+"."+s.slice(1)+Cu(r):a>1&&(s=s.charAt(0)+"."+s.slice(1)),s=s+(i<0?"e":"e+")+i):i<0?(s="0."+Cu(-i-1)+s,n&&(r=n-a)>0&&(s+=Cu(r))):i>=a?(s+=Cu(i+1-a),n&&(r=n-i-1)>0&&(s=s+"."+Cu(r))):((r=i+1)0&&(i+1===a&&(s+="."),s+=Cu(r))),t.s<0?"-"+s:s}function uV(t,e){if(t.length>e)return t.length=e,!0}function sQ(t){var e,n,r;function i(s){var a=this;if(!(a instanceof i))return new i(s);if(a.constructor=i,s instanceof i){a.s=s.s,a.e=s.e,a.d=(s=s.d)?s.slice():s;return}if(typeof s=="number"){if(s*0!==0)throw Error(Ah+s);if(s>0)a.s=1;else if(s<0)s=-s,a.s=-1;else{a.s=0,a.e=0,a.d=[0];return}if(s===~~s&&s<1e7){a.e=0,a.d=[s];return}return cV(a,s.toString())}else if(typeof s!="string")throw Error(Ah+s);if(s.charCodeAt(0)===45?(s=s.slice(1),a.s=-1):a.s=1,R4e.test(s))cV(a,s);else throw Error(Ah+s)}if(i.prototype=Pt,i.ROUND_UP=0,i.ROUND_DOWN=1,i.ROUND_CEIL=2,i.ROUND_FLOOR=3,i.ROUND_HALF_UP=4,i.ROUND_HALF_DOWN=5,i.ROUND_HALF_EVEN=6,i.ROUND_HALF_CEIL=7,i.ROUND_HALF_FLOOR=8,i.clone=sQ,i.config=i.set=D4e,t===void 0&&(t={}),t)for(r=["precision","rounding","toExpNeg","toExpPos","LN10"],e=0;e=i[e+1]&&r<=i[e+2])this[n]=r;else throw Error(Ah+n+": "+r);if((r=t[n="LN10"])!==void 0)if(r==Math.LN10)this[n]=new this(r);else throw Error(Ah+n+": "+r);return this}var HO=sQ(P4e);fa=new HO(1);const In=HO;var O4e=t=>t,aQ={},oQ=t=>t===aQ,dV=t=>function e(){return arguments.length===0||arguments.length===1&&oQ(arguments.length<=0?void 0:arguments[0])?e:t(...arguments)},lQ=(t,e)=>t===1?e:dV(function(){for(var n=arguments.length,r=new Array(n),i=0;ia!==aQ).length;return s>=t?e(...r):lQ(t-s,dV(function(){for(var a=arguments.length,o=new Array(a),l=0;loQ(d)?o.shift():d);return e(...u,...o)}))}),j4e=t=>lQ(t.length,t),LP=(t,e)=>{for(var n=[],r=t;rArray.isArray(e)?e.map(t):Object.keys(e).map(n=>e[n]).map(t)),I4e=function(){for(var e=arguments.length,n=new Array(e),r=0;rl(o),s(...arguments))}},IP=t=>Array.isArray(t)?t.reverse():t.split("").reverse().join("");function cQ(t){var e;return t===0?e=1:e=Math.floor(new In(t).abs().log(10).toNumber())+1,e}function uQ(t,e,n){for(var r=new In(t),i=0,s=[];r.lt(e)&&i<1e5;)s.push(r.toNumber()),r=r.add(n),i++;return s}var dQ=t=>{var[e,n]=t,[r,i]=[e,n];return e>n&&([r,i]=[n,e]),[r,i]},hQ=(t,e,n)=>{if(t.lte(0))return new In(0);var r=cQ(t.toNumber()),i=new In(10).pow(r),s=t.div(i),a=r!==1?.05:.1,o=new In(Math.ceil(s.div(a).toNumber())).add(n).mul(a),l=o.mul(i);return e?new In(l.toNumber()):new In(Math.ceil(l.toNumber()))},U4e=(t,e,n)=>{var r=new In(1),i=new In(t);if(!i.isint()&&n){var s=Math.abs(t);s<1?(r=new In(10).pow(cQ(t)-1),i=new In(Math.floor(i.div(r).toNumber())).mul(r)):s>1&&(i=new In(Math.floor(t)))}else t===0?i=new In(Math.floor((e-1)/2)):n||(i=new In(Math.floor(t)));var a=Math.floor((e-1)/2),o=I4e(L4e(l=>i.add(new In(l-a).mul(r)).toNumber()),LP);return o(0,e)},fQ=function(e,n,r,i){var s=arguments.length>4&&arguments[4]!==void 0?arguments[4]:0;if(!Number.isFinite((n-e)/(r-1)))return{step:new In(0),tickMin:new In(0),tickMax:new In(0)};var a=hQ(new In(n).sub(e).div(r-1),i,s),o;e<=0&&n>=0?o=new In(0):(o=new In(e).add(n).div(2),o=o.sub(new In(o).mod(a)));var l=Math.ceil(o.sub(e).div(a).toNumber()),u=Math.ceil(new In(n).sub(o).div(a).toNumber()),d=l+u+1;return d>r?fQ(e,n,r,i,s+1):(d0?u+(r-d):u,l=n>0?l:l+(r-d)),{step:a,tickMin:o.sub(new In(l).mul(a)),tickMax:o.add(new In(u).mul(a))})},F4e=function(e){var[n,r]=e,i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:6,s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!0,a=Math.max(i,2),[o,l]=dQ([n,r]);if(o===-1/0||l===1/0){var u=l===1/0?[o,...LP(0,i-1).map(()=>1/0)]:[...LP(0,i-1).map(()=>-1/0),l];return n>r?IP(u):u}if(o===l)return U4e(o,i,s);var{step:d,tickMin:f,tickMax:g}=fQ(o,l,a,s,0),m=uQ(f,g.add(new In(.1).mul(d)),d);return n>r?IP(m):m},z4e=function(e,n){var[r,i]=e,s=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!0,[a,o]=dQ([r,i]);if(a===-1/0||o===1/0)return[r,i];if(a===o)return[a];var l=Math.max(n,2),u=hQ(new In(o).sub(a).div(l-1),s,0),d=[...uQ(new In(a),new In(o),u),o];return s===!1&&(d=d.map(f=>Math.round(f))),r>i?IP(d):d},pQ=t=>t.rootProps.maxBarSize,B4e=t=>t.rootProps.barGap,mQ=t=>t.rootProps.barCategoryGap,H4e=t=>t.rootProps.barSize,Nb=t=>t.rootProps.stackOffset,gQ=t=>t.rootProps.reverseStackOrder,$O=t=>t.options.chartName,VO=t=>t.rootProps.syncId,xQ=t=>t.rootProps.syncMethod,GO=t=>t.options.eventEmitter,$4e=t=>t.rootProps.baseValue,Zr={grid:-100,barBackground:-50,area:100,cursorRectangle:200,bar:300,line:400,axis:500,scatter:600,activeBar:1e3,cursorLine:1100,activeDot:1200,label:2e3},nc={allowDuplicatedCategory:!0,angleAxisId:0,reversed:!1,scale:"auto",tick:!0,type:"category"},ua={allowDataOverflow:!1,allowDuplicatedCategory:!0,radiusAxisId:0,scale:"auto",tick:!0,tickCount:5,type:"number"},CE=(t,e)=>{if(!(!t||!e))return t!=null&&t.reversed?[e[1],e[0]]:e},V4e={allowDataOverflow:!1,allowDecimals:!1,allowDuplicatedCategory:!1,dataKey:void 0,domain:void 0,id:nc.angleAxisId,includeHidden:!1,name:void 0,reversed:nc.reversed,scale:nc.scale,tick:nc.tick,tickCount:void 0,ticks:void 0,type:nc.type,unit:void 0},G4e={allowDataOverflow:ua.allowDataOverflow,allowDecimals:!1,allowDuplicatedCategory:ua.allowDuplicatedCategory,dataKey:void 0,domain:void 0,id:ua.radiusAxisId,includeHidden:!1,name:void 0,reversed:!1,scale:ua.scale,tick:ua.tick,tickCount:ua.tickCount,ticks:void 0,type:ua.type,unit:void 0},W4e={allowDataOverflow:!1,allowDecimals:!1,allowDuplicatedCategory:nc.allowDuplicatedCategory,dataKey:void 0,domain:void 0,id:nc.angleAxisId,includeHidden:!1,name:void 0,reversed:!1,scale:nc.scale,tick:nc.tick,tickCount:void 0,ticks:void 0,type:"number",unit:void 0},q4e={allowDataOverflow:ua.allowDataOverflow,allowDecimals:!1,allowDuplicatedCategory:ua.allowDuplicatedCategory,dataKey:void 0,domain:void 0,id:ua.radiusAxisId,includeHidden:!1,name:void 0,reversed:!1,scale:ua.scale,tick:ua.tick,tickCount:ua.tickCount,ticks:void 0,type:"category",unit:void 0},WO=(t,e)=>t.polarAxis.angleAxis[e]!=null?t.polarAxis.angleAxis[e]:t.layout.layoutType==="radial"?W4e:V4e,qO=(t,e)=>t.polarAxis.radiusAxis[e]!=null?t.polarAxis.radiusAxis[e]:t.layout.layoutType==="radial"?q4e:G4e,NE=t=>t.polarOptions,KO=Ke([Pc,Rc,xi],mZ),bQ=Ke([NE,KO],(t,e)=>{if(t!=null)return hs(t.innerRadius,e,0)}),vQ=Ke([NE,KO],(t,e)=>{if(t!=null)return hs(t.outerRadius,e,e*.8)}),K4e=t=>{if(t==null)return[0,0];var{startAngle:e,endAngle:n}=t;return[e,n]},yQ=Ke([NE],K4e);Ke([WO,yQ],CE);var _Q=Ke([KO,bQ,vQ],(t,e,n)=>{if(!(t==null||e==null||n==null))return[e,n]});Ke([qO,_Q],CE);var wQ=Ke([wn,NE,bQ,vQ,Pc,Rc],(t,e,n,r,i,s)=>{if(!(t!=="centric"&&t!=="radial"||e==null||n==null||r==null)){var{cx:a,cy:o,startAngle:l,endAngle:u}=e;return{cx:hs(a,i,i/2),cy:hs(o,s,s/2),innerRadius:n,outerRadius:r,startAngle:l,endAngle:u,clockWise:!1}}}),gr=(t,e)=>e,kb=(t,e,n)=>n;function kE(t){return t?.id}function SQ(t,e,n){var{chartData:r=[]}=e,{allowDuplicatedCategory:i,dataKey:s}=n,a=new Map;return t.forEach(o=>{var l,u=(l=o.data)!==null&&l!==void 0?l:r;if(!(u==null||u.length===0)){var d=kE(o);u.forEach((f,g)=>{var m=s==null||i?g:String(Jn(f,s,null)),x=Jn(f,o.dataKey,0),y;a.has(m)?y=a.get(m):y={},Object.assign(y,{[d]:x}),a.set(m,y)})}}),Array.from(a.values())}function PE(t){return t.stackId!=null&&t.dataKey!=null}var RE=(t,e)=>t===e?!0:t==null||e==null?!1:t[0]===e[0]&&t[1]===e[1];function DE(t,e){return Array.isArray(t)&&Array.isArray(e)&&t.length===0&&e.length===0?!0:t===e}function X4e(t,e){if(t.length===e.length){for(var n=0;n{var e=wn(t);return e==="horizontal"?"xAxis":e==="vertical"?"yAxis":e==="centric"?"angleAxis":"radiusAxis"},Jm=t=>t.tooltip.settings.axisId;function hV(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function Xw(t){for(var e=1;et.cartesianAxis.xAxis[e],Oc=(t,e)=>{var n=EQ(t,e);return n??Ci},Ni={allowDataOverflow:!1,allowDecimals:!0,allowDuplicatedCategory:!0,angle:0,dataKey:void 0,domain:UP,hide:!0,id:0,includeHidden:!1,interval:"preserveEnd",minTickGap:5,mirror:!1,name:void 0,orientation:"left",padding:{top:0,bottom:0},reversed:!1,scale:"auto",tick:!0,tickCount:5,tickFormatter:void 0,ticks:void 0,type:"number",unit:void 0,width:_b},MQ=(t,e)=>t.cartesianAxis.yAxis[e],jc=(t,e)=>{var n=MQ(t,e);return n??Ni},J4e={domain:[0,"auto"],includeHidden:!1,reversed:!1,allowDataOverflow:!1,allowDuplicatedCategory:!1,dataKey:void 0,id:0,name:"",range:[64,64],scale:"auto",type:"number",unit:""},XO=(t,e)=>{var n=t.cartesianAxis.zAxis[e];return n??J4e},wr=(t,e,n)=>{switch(e){case"xAxis":return Oc(t,n);case"yAxis":return jc(t,n);case"zAxis":return XO(t,n);case"angleAxis":return WO(t,n);case"radiusAxis":return qO(t,n);default:throw new Error("Unexpected axis type: ".concat(e))}},eUe=(t,e,n)=>{switch(e){case"xAxis":return Oc(t,n);case"yAxis":return jc(t,n);default:throw new Error("Unexpected axis type: ".concat(e))}},Pb=(t,e,n)=>{switch(e){case"xAxis":return Oc(t,n);case"yAxis":return jc(t,n);case"angleAxis":return WO(t,n);case"radiusAxis":return qO(t,n);default:throw new Error("Unexpected axis type: ".concat(e))}},AQ=t=>t.graphicalItems.cartesianItems.some(e=>e.type==="bar")||t.graphicalItems.polarItems.some(e=>e.type==="radialBar");function YO(t,e){return n=>{switch(t){case"xAxis":return"xAxisId"in n&&n.xAxisId===e;case"yAxis":return"yAxisId"in n&&n.yAxisId===e;case"zAxis":return"zAxisId"in n&&n.zAxisId===e;case"angleAxis":return"angleAxisId"in n&&n.angleAxisId===e;case"radiusAxis":return"radiusAxisId"in n&&n.radiusAxisId===e;default:return!1}}}var OE=t=>t.graphicalItems.cartesianItems,tUe=Ke([gr,kb],YO),ZO=(t,e,n)=>t.filter(n).filter(r=>e?.includeHidden===!0?!0:!r.hide),Rb=Ke([OE,wr,tUe],ZO,{memoizeOptions:{resultEqualityCheck:DE}}),TQ=Ke([Rb],t=>t.filter(e=>e.type==="area"||e.type==="bar").filter(PE)),CQ=t=>t.filter(e=>!("stackId"in e)||e.stackId===void 0),nUe=Ke([Rb],CQ),QO=t=>t.map(e=>e.data).filter(Boolean).flat(1),rUe=Ke([Rb],QO,{memoizeOptions:{resultEqualityCheck:DE}}),JO=(t,e)=>{var{chartData:n=[],dataStartIndex:r,dataEndIndex:i}=e;return t.length>0?t:n.slice(r,i+1)},ej=Ke([rUe,TE],JO),tj=(t,e,n)=>e?.dataKey!=null?t.map(r=>({value:Jn(r,e.dataKey)})):n.length>0?n.map(r=>r.dataKey).flatMap(r=>t.map(i=>({value:Jn(i,r)}))):t.map(r=>({value:r})),jE=Ke([ej,wr,Rb],tj);function NQ(t,e){switch(t){case"xAxis":return e.direction==="x";case"yAxis":return e.direction==="y";default:return!1}}function J_(t){if(fl(t)||t instanceof Date){var e=Number(t);if(ur(e))return e}}function fV(t){if(Array.isArray(t)){var e=[J_(t[0]),J_(t[1])];return ad(e)?e:void 0}var n=J_(t);if(n!=null)return[n,n]}function Tc(t){return t.map(J_).filter(nPe)}function iUe(t,e,n){return!n||typeof e!="number"||io(e)?[]:n.length?Tc(n.flatMap(r=>{var i=Jn(t,r.dataKey),s,a;if(Array.isArray(i)?[s,a]=i:s=a=i,!(!ur(s)||!ur(a)))return[e-s,e+a]})):[]}var yi=t=>{var e=vi(t),n=Jm(t);return Pb(t,e,n)},Db=Ke([yi],t=>t?.dataKey),sUe=Ke([TQ,TE,yi],SQ),kQ=(t,e,n,r)=>{var i={},s=e.reduce((a,o)=>(o.stackId==null||(a[o.stackId]==null&&(a[o.stackId]=[]),a[o.stackId].push(o)),a),i);return Object.fromEntries(Object.entries(s).map(a=>{var[o,l]=a,u=r?[...l].reverse():l,d=u.map(kE);return[o,{stackedData:EDe(t,d,n),graphicalItems:u}]}))},Z0=Ke([sUe,TQ,Nb,gQ],kQ),PQ=(t,e,n,r)=>{var{dataStartIndex:i,dataEndIndex:s}=e;if(r==null&&n!=="zAxis"){var a=CDe(t,i,s);if(!(a!=null&&a[0]===0&&a[1]===0))return a}},aUe=Ke([wr],t=>t.allowDataOverflow),nj=t=>{var e;if(t==null||!("domain"in t))return UP;if(t.domain!=null)return t.domain;if(t.ticks!=null){if(t.type==="number"){var n=Tc(t.ticks);return[Math.min(...n),Math.max(...n)]}if(t.type==="category")return t.ticks.map(String)}return(e=t?.domain)!==null&&e!==void 0?e:UP},rj=Ke([wr],nj),ij=Ke([rj,aUe],eQ),oUe=Ke([Z0,vd,gr,ij],PQ,{memoizeOptions:{resultEqualityCheck:RE}}),LE=t=>t.errorBars,lUe=(t,e,n)=>t.flatMap(r=>e[r.id]).filter(Boolean).filter(r=>NQ(n,r)),Yw=function(){for(var e=arguments.length,n=new Array(e),r=0;r{var s,a;if(n.length>0&&t.forEach(o=>{n.forEach(l=>{var u,d,f=(u=r[l.id])===null||u===void 0?void 0:u.filter(b=>NQ(i,b)),g=Jn(o,(d=e.dataKey)!==null&&d!==void 0?d:l.dataKey),m=iUe(o,g,f);if(m.length>=2){var x=Math.min(...m),y=Math.max(...m);(s==null||xa)&&(a=y)}var v=fV(g);v!=null&&(s=s==null?v[0]:Math.min(s,v[0]),a=a==null?v[1]:Math.max(a,v[1]))})}),e?.dataKey!=null&&t.forEach(o=>{var l=fV(Jn(o,e.dataKey));l!=null&&(s=s==null?l[0]:Math.min(s,l[0]),a=a==null?l[1]:Math.max(a,l[1]))}),ur(s)&&ur(a))return[s,a]},cUe=Ke([ej,wr,nUe,LE,gr],sj,{memoizeOptions:{resultEqualityCheck:RE}});function uUe(t){var{value:e}=t;if(fl(e)||e instanceof Date)return e}var dUe=(t,e,n)=>{var r=t.map(uUe).filter(i=>i!=null);return n&&(e.dataKey==null||e.allowDuplicatedCategory&&WX(r))?vZ(0,t.length):e.allowDuplicatedCategory?r:Array.from(new Set(r))},RQ=t=>t.referenceElements.dots,eg=(t,e,n)=>t.filter(r=>r.ifOverflow==="extendDomain").filter(r=>e==="xAxis"?r.xAxisId===n:r.yAxisId===n),hUe=Ke([RQ,gr,kb],eg),DQ=t=>t.referenceElements.areas,fUe=Ke([DQ,gr,kb],eg),OQ=t=>t.referenceElements.lines,pUe=Ke([OQ,gr,kb],eg),jQ=(t,e)=>{var n=Tc(t.map(r=>e==="xAxis"?r.x:r.y));if(n.length!==0)return[Math.min(...n),Math.max(...n)]},mUe=Ke(hUe,gr,jQ),LQ=(t,e)=>{var n=Tc(t.flatMap(r=>[e==="xAxis"?r.x1:r.y1,e==="xAxis"?r.x2:r.y2]));if(n.length!==0)return[Math.min(...n),Math.max(...n)]},gUe=Ke([fUe,gr],LQ);function xUe(t){var e;if(t.x!=null)return Tc([t.x]);var n=(e=t.segment)===null||e===void 0?void 0:e.map(r=>r.x);return n==null||n.length===0?[]:Tc(n)}function bUe(t){var e;if(t.y!=null)return Tc([t.y]);var n=(e=t.segment)===null||e===void 0?void 0:e.map(r=>r.y);return n==null||n.length===0?[]:Tc(n)}var IQ=(t,e)=>{var n=t.flatMap(r=>e==="xAxis"?xUe(r):bUe(r));if(n.length!==0)return[Math.min(...n),Math.max(...n)]},vUe=Ke([pUe,gr],IQ),yUe=Ke(mUe,vUe,gUe,(t,e,n)=>Yw(t,n,e)),aj=(t,e,n,r,i,s,a,o)=>{if(n!=null)return n;var l=a==="vertical"&&o==="xAxis"||a==="horizontal"&&o==="yAxis",u=l?Yw(r,s,i):Yw(s,i);return k4e(e,u,t.allowDataOverflow)},_Ue=Ke([wr,rj,ij,oUe,cUe,yUe,wn,gr],aj,{memoizeOptions:{resultEqualityCheck:RE}}),wUe=[0,1],oj=(t,e,n,r,i,s,a)=>{if(!((t==null||n==null||n.length===0)&&a===void 0)){var{dataKey:o,type:l}=t,u=kc(e,s);if(u&&o==null){var d;return vZ(0,(d=n?.length)!==null&&d!==void 0?d:0)}return l==="category"?dUe(r,t,u):i==="expand"?wUe:a}},lj=Ke([wr,wn,ej,jE,Nb,gr,_Ue],oj),UQ=(t,e,n,r,i)=>{if(t!=null){var{scale:s,type:a}=t;if(s==="auto")return e==="radial"&&i==="radiusAxis"?"band":e==="radial"&&i==="angleAxis"?"linear":a==="category"&&r&&(r.indexOf("LineChart")>=0||r.indexOf("AreaChart")>=0||r.indexOf("ComposedChart")>=0&&!n)?"point":a==="category"?"band":"linear";if(typeof s=="string"){var o="scale".concat(mb(s));return o in kx?o:"point"}}},tg=Ke([wr,wn,AQ,$O,gr],UQ);function SUe(t){if(t!=null){if(t in kx)return kx[t]();var e="scale".concat(mb(t));if(e in kx)return kx[e]()}}function cj(t,e,n,r){if(!(n==null||r==null)){if(typeof t.scale=="function")return t.scale.copy().domain(n).range(r);var i=SUe(e);if(i!=null){var s=i.domain(n).range(r);return vDe(s),s}}}var uj=(t,e,n)=>{var r=nj(e);if(!(n!=="auto"&&n!=="linear")){if(e!=null&&e.tickCount&&Array.isArray(r)&&(r[0]==="auto"||r[1]==="auto")&&ad(t))return F4e(t,e.tickCount,e.allowDecimals);if(e!=null&&e.tickCount&&e.type==="number"&&ad(t))return z4e(t,e.tickCount,e.allowDecimals)}},dj=Ke([lj,Pb,tg],uj),hj=(t,e,n,r)=>{if(r!=="angleAxis"&&t?.type==="number"&&ad(e)&&Array.isArray(n)&&n.length>0){var i=e[0],s=n[0],a=e[1],o=n[n.length-1];return[Math.min(i,s),Math.max(a,o)]}return e},EUe=Ke([wr,lj,dj,gr],hj),MUe=Ke(jE,wr,(t,e)=>{if(!(!e||e.type!=="number")){var n=1/0,r=Array.from(Tc(t.map(o=>o.value))).sort((o,l)=>o-l);if(r.length<2)return 1/0;var i=r[r.length-1]-r[0];if(i===0)return 1/0;for(var s=0;sr,(t,e,n,r,i)=>{if(!ur(t))return 0;var s=e==="vertical"?r.height:r.width;if(i==="gap")return t*s/2;if(i==="no-gap"){var a=hs(n,t*s),o=t*s/2;return o-a-(o-a)/s*a}return 0}),AUe=(t,e)=>{var n=Oc(t,e);return n==null||typeof n.padding!="string"?0:FQ(t,"xAxis",e,n.padding)},TUe=(t,e)=>{var n=jc(t,e);return n==null||typeof n.padding!="string"?0:FQ(t,"yAxis",e,n.padding)},CUe=Ke(Oc,AUe,(t,e)=>{var n,r;if(t==null)return{left:0,right:0};var{padding:i}=t;return typeof i=="string"?{left:e,right:e}:{left:((n=i.left)!==null&&n!==void 0?n:0)+e,right:((r=i.right)!==null&&r!==void 0?r:0)+e}}),NUe=Ke(jc,TUe,(t,e)=>{var n,r;if(t==null)return{top:0,bottom:0};var{padding:i}=t;return typeof i=="string"?{top:e,bottom:e}:{top:((n=i.top)!==null&&n!==void 0?n:0)+e,bottom:((r=i.bottom)!==null&&r!==void 0?r:0)+e}}),kUe=Ke([xi,CUe,mE,pE,(t,e,n)=>n],(t,e,n,r,i)=>{var{padding:s}=r;return i?[s.left,n.width-s.right]:[t.left+e.left,t.left+t.width-e.right]}),PUe=Ke([xi,wn,NUe,mE,pE,(t,e,n)=>n],(t,e,n,r,i,s)=>{var{padding:a}=i;return s?[r.height-a.bottom,a.top]:e==="horizontal"?[t.top+t.height-n.bottom,t.top+n.top]:[t.top+n.top,t.top+t.height-n.bottom]}),Ob=(t,e,n,r)=>{var i;switch(e){case"xAxis":return kUe(t,n,r);case"yAxis":return PUe(t,n,r);case"zAxis":return(i=XO(t,n))===null||i===void 0?void 0:i.range;case"angleAxis":return yQ(t);case"radiusAxis":return _Q(t,n);default:return}},zQ=Ke([wr,Ob],CE),ng=Ke([wr,tg,EUe,zQ],cj);Ke([Rb,LE,gr],lUe);function BQ(t,e){return t.ide.id?1:0}var IE=(t,e)=>e,UE=(t,e,n)=>n,RUe=Ke(hE,IE,UE,(t,e,n)=>t.filter(r=>r.orientation===e).filter(r=>r.mirror===n).sort(BQ)),DUe=Ke(fE,IE,UE,(t,e,n)=>t.filter(r=>r.orientation===e).filter(r=>r.mirror===n).sort(BQ)),HQ=(t,e)=>({width:t.width,height:e.height}),OUe=(t,e)=>{var n=typeof e.width=="number"?e.width:_b;return{width:n,height:t.height}},$Q=Ke(xi,Oc,HQ),jUe=(t,e,n)=>{switch(e){case"top":return t.top;case"bottom":return n-t.bottom;default:return 0}},LUe=(t,e,n)=>{switch(e){case"left":return t.left;case"right":return n-t.right;default:return 0}},IUe=Ke(Rc,xi,RUe,IE,UE,(t,e,n,r,i)=>{var s={},a;return n.forEach(o=>{var l=HQ(e,o);a==null&&(a=jUe(e,r,t));var u=r==="top"&&!i||r==="bottom"&&i;s[o.id]=a-Number(u)*l.height,a+=(u?-1:1)*l.height}),s}),UUe=Ke(Pc,xi,DUe,IE,UE,(t,e,n,r,i)=>{var s={},a;return n.forEach(o=>{var l=OUe(e,o);a==null&&(a=LUe(e,r,t));var u=r==="left"&&!i||r==="right"&&i;s[o.id]=a-Number(u)*l.width,a+=(u?-1:1)*l.width}),s}),FUe=(t,e)=>{var n=Oc(t,e);if(n!=null)return IUe(t,n.orientation,n.mirror)},zUe=Ke([xi,Oc,FUe,(t,e)=>e],(t,e,n,r)=>{if(e!=null){var i=n?.[r];return i==null?{x:t.left,y:0}:{x:t.left,y:i}}}),BUe=(t,e)=>{var n=jc(t,e);if(n!=null)return UUe(t,n.orientation,n.mirror)},HUe=Ke([xi,jc,BUe,(t,e)=>e],(t,e,n,r)=>{if(e!=null){var i=n?.[r];return i==null?{x:0,y:t.top}:{x:i,y:t.top}}}),VQ=Ke(xi,jc,(t,e)=>{var n=typeof e.width=="number"?e.width:_b;return{width:n,height:t.height}}),pV=(t,e,n)=>{switch(e){case"xAxis":return $Q(t,n).width;case"yAxis":return VQ(t,n).height;default:return}},GQ=(t,e,n,r)=>{if(n!=null){var{allowDuplicatedCategory:i,type:s,dataKey:a}=n,o=kc(t,r),l=e.map(u=>u.value);if(a&&o&&s==="category"&&i&&WX(l))return l}},fj=Ke([wn,jE,wr,gr],GQ),WQ=(t,e,n,r)=>{if(!(n==null||n.dataKey==null)){var{type:i,scale:s}=n,a=kc(t,r);if(a&&(i==="number"||s!=="auto"))return e.map(o=>o.value)}},pj=Ke([wn,jE,Pb,gr],WQ),mV=Ke([wn,eUe,tg,ng,fj,pj,Ob,dj,gr],(t,e,n,r,i,s,a,o,l)=>{if(e!=null){var u=kc(t,l);return{angle:e.angle,interval:e.interval,minTickGap:e.minTickGap,orientation:e.orientation,tick:e.tick,tickCount:e.tickCount,tickFormatter:e.tickFormatter,ticks:e.ticks,type:e.type,unit:e.unit,axisType:l,categoricalDomain:s,duplicateDomain:i,isCategorical:u,niceTicks:o,range:a,realScaleType:n,scale:r}}}),$Ue=(t,e,n,r,i,s,a,o,l)=>{if(!(e==null||r==null)){var u=kc(t,l),{type:d,ticks:f,tickCount:g}=e,m=n==="scaleBand"&&typeof r.bandwidth=="function"?r.bandwidth()/2:2,x=d==="category"&&r.bandwidth?r.bandwidth()/m:0;x=l==="angleAxis"&&s!=null&&s.length>=2?Di(s[0]-s[1])*2*x:x;var y=f||i;if(y){var v=y.map((b,E)=>{var S=a?a.indexOf(b):b;return{index:E,coordinate:r(S)+x,value:b,offset:x}});return v.filter(b=>ur(b.coordinate))}return u&&o?o.map((b,E)=>({coordinate:r(b)+x,value:b,index:E,offset:x})).filter(b=>ur(b.coordinate)):r.ticks?r.ticks(g).map(b=>({coordinate:r(b)+x,value:b,offset:x})):r.domain().map((b,E)=>({coordinate:r(b)+x,value:a?a[b]:b,index:E,offset:x}))}},qQ=Ke([wn,Pb,tg,ng,dj,Ob,fj,pj,gr],$Ue),VUe=(t,e,n,r,i,s,a)=>{if(!(e==null||n==null||r==null||r[0]===r[1])){var o=kc(t,a),{tickCount:l}=e,u=0;return u=a==="angleAxis"&&r?.length>=2?Di(r[0]-r[1])*2*u:u,o&&s?s.map((d,f)=>({coordinate:n(d)+u,value:d,index:f,offset:u})):n.ticks?n.ticks(l).map(d=>({coordinate:n(d)+u,value:d,offset:u})):n.domain().map((d,f)=>({coordinate:n(d)+u,value:i?i[d]:d,index:f,offset:u}))}},od=Ke([wn,Pb,ng,Ob,fj,pj,gr],VUe),ld=Ke(wr,ng,(t,e)=>{if(!(t==null||e==null))return Xw(Xw({},t),{},{scale:e})}),GUe=Ke([wr,tg,lj,zQ],cj);Ke((t,e,n)=>XO(t,n),GUe,(t,e)=>{if(!(t==null||e==null))return Xw(Xw({},t),{},{scale:e})});var WUe=Ke([wn,hE,fE],(t,e,n)=>{switch(t){case"horizontal":return e.some(r=>r.reversed)?"right-to-left":"left-to-right";case"vertical":return n.some(r=>r.reversed)?"bottom-to-top":"top-to-bottom";case"centric":case"radial":return"left-to-right";default:return}}),KQ=t=>t.options.defaultTooltipEventType,XQ=t=>t.options.validateTooltipEventTypes;function YQ(t,e,n){if(t==null)return e;var r=t?"axis":"item";return n==null?e:n.includes(r)?r:e}function mj(t,e){var n=KQ(t),r=XQ(t);return YQ(e,n,r)}function qUe(t){return kt(e=>mj(e,t))}var ZQ=(t,e)=>{var n,r=Number(e);if(!(io(r)||e==null))return r>=0?t==null||(n=t[r])===null||n===void 0?void 0:n.value:void 0},KUe=t=>t.tooltip.settings,Du={active:!1,index:null,dataKey:void 0,graphicalItemId:void 0,coordinate:void 0},XUe={itemInteraction:{click:Du,hover:Du},axisInteraction:{click:Du,hover:Du},keyboardInteraction:Du,syncInteraction:{active:!1,index:null,dataKey:void 0,label:void 0,coordinate:void 0,sourceViewBox:void 0,graphicalItemId:void 0},tooltipItemPayloads:[],settings:{shared:void 0,trigger:"hover",axisId:0,active:!1,defaultIndex:void 0}},QQ=Zs({name:"tooltip",initialState:XUe,reducers:{addTooltipEntrySettings:{reducer(t,e){t.tooltipItemPayloads.push(e.payload)},prepare:hr()},replaceTooltipEntrySettings:{reducer(t,e){var{prev:n,next:r}=e.payload,i=Ro(t).tooltipItemPayloads.indexOf(n);i>-1&&(t.tooltipItemPayloads[i]=r)},prepare:hr()},removeTooltipEntrySettings:{reducer(t,e){var n=Ro(t).tooltipItemPayloads.indexOf(e.payload);n>-1&&t.tooltipItemPayloads.splice(n,1)},prepare:hr()},setTooltipSettingsState(t,e){t.settings=e.payload},setActiveMouseOverItemIndex(t,e){t.syncInteraction.active=!1,t.keyboardInteraction.active=!1,t.itemInteraction.hover.active=!0,t.itemInteraction.hover.index=e.payload.activeIndex,t.itemInteraction.hover.dataKey=e.payload.activeDataKey,t.itemInteraction.hover.graphicalItemId=e.payload.activeGraphicalItemId,t.itemInteraction.hover.coordinate=e.payload.activeCoordinate},mouseLeaveChart(t){t.itemInteraction.hover.active=!1,t.axisInteraction.hover.active=!1},mouseLeaveItem(t){t.itemInteraction.hover.active=!1},setActiveClickItemIndex(t,e){t.syncInteraction.active=!1,t.itemInteraction.click.active=!0,t.keyboardInteraction.active=!1,t.itemInteraction.click.index=e.payload.activeIndex,t.itemInteraction.click.dataKey=e.payload.activeDataKey,t.itemInteraction.click.graphicalItemId=e.payload.activeGraphicalItemId,t.itemInteraction.click.coordinate=e.payload.activeCoordinate},setMouseOverAxisIndex(t,e){t.syncInteraction.active=!1,t.axisInteraction.hover.active=!0,t.keyboardInteraction.active=!1,t.axisInteraction.hover.index=e.payload.activeIndex,t.axisInteraction.hover.dataKey=e.payload.activeDataKey,t.axisInteraction.hover.coordinate=e.payload.activeCoordinate},setMouseClickAxisIndex(t,e){t.syncInteraction.active=!1,t.keyboardInteraction.active=!1,t.axisInteraction.click.active=!0,t.axisInteraction.click.index=e.payload.activeIndex,t.axisInteraction.click.dataKey=e.payload.activeDataKey,t.axisInteraction.click.coordinate=e.payload.activeCoordinate},setSyncInteraction(t,e){t.syncInteraction=e.payload},setKeyboardInteraction(t,e){t.keyboardInteraction.active=e.payload.active,t.keyboardInteraction.index=e.payload.activeIndex,t.keyboardInteraction.coordinate=e.payload.activeCoordinate,t.keyboardInteraction.dataKey=e.payload.activeDataKey}}}),{addTooltipEntrySettings:YUe,replaceTooltipEntrySettings:ZUe,removeTooltipEntrySettings:QUe,setTooltipSettingsState:JUe,setActiveMouseOverItemIndex:JQ,mouseLeaveItem:e5e,mouseLeaveChart:eJ,setActiveClickItemIndex:t5e,setMouseOverAxisIndex:tJ,setMouseClickAxisIndex:n5e,setSyncInteraction:FP,setKeyboardInteraction:zP}=QQ.actions,r5e=QQ.reducer;function gV(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function A_(t){for(var e=1;e{if(e==null)return Du;var i=o5e(t,e,n);if(i==null)return Du;if(i.active)return i;if(t.keyboardInteraction.active)return t.keyboardInteraction;if(t.syncInteraction.active&&t.syncInteraction.index!=null)return t.syncInteraction;var s=t.settings.active===!0;if(l5e(i)){if(s)return A_(A_({},i),{},{active:!0})}else if(r!=null)return{active:!0,coordinate:void 0,dataKey:void 0,index:r,graphicalItemId:void 0};return A_(A_({},Du),{},{coordinate:i.coordinate})};function c5e(t){if(typeof t=="number")return Number.isFinite(t)?t:void 0;if(t instanceof Date){var e=t.valueOf();return Number.isFinite(e)?e:void 0}var n=Number(t);return Number.isFinite(n)?n:void 0}function u5e(t,e){var n=c5e(t),r=e[0],i=e[1];if(n===void 0)return!1;var s=Math.min(r,i),a=Math.max(r,i);return n>=s&&n<=a}function d5e(t,e,n){if(n==null||e==null)return!0;var r=Jn(t,e);return r==null||!ad(n)?!0:u5e(r,n)}var gj=(t,e,n,r)=>{var i=t?.index;if(i==null)return null;var s=Number(i);if(!ur(s))return i;var a=0,o=1/0;e.length>0&&(o=e.length-1);var l=Math.max(a,Math.min(s,o)),u=e[l];return u==null||d5e(u,n,r)?String(l):null},rJ=(t,e,n,r,i,s,a,o)=>{if(!(s==null||o==null)){var l=a[0],u=l==null?void 0:o(l.positions,s);if(u!=null)return u;var d=i?.[Number(s)];if(d)switch(n){case"horizontal":return{x:d.coordinate,y:(r.top+e)/2};default:return{x:(r.left+t)/2,y:d.coordinate}}}},iJ=(t,e,n,r)=>{if(e==="axis")return t.tooltipItemPayloads;if(t.tooltipItemPayloads.length===0)return[];var i;return n==="hover"?i=t.itemInteraction.hover.dataKey:i=t.itemInteraction.click.dataKey,i==null&&r!=null?[t.tooltipItemPayloads[0]]:t.tooltipItemPayloads.filter(s=>{var a;return((a=s.settings)===null||a===void 0?void 0:a.dataKey)===i})},jb=t=>t.options.tooltipPayloadSearcher,rg=t=>t.tooltip;function xV(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function bV(t){for(var e=1;e{if(!(e==null||s==null)){var{chartData:o,computedData:l,dataStartIndex:u,dataEndIndex:d}=n,f=[];return t.reduce((g,m)=>{var x,{dataDefinedOnItem:y,settings:v}=m,b=m5e(y,o),E=Array.isArray(b)?zY(b,u,d):b,S=(x=v?.dataKey)!==null&&x!==void 0?x:r,A=v?.nameKey,T;if(r&&Array.isArray(E)&&!Array.isArray(E[0])&&a==="axis"?T=qX(E,r,i):T=s(E,e,l,A),Array.isArray(T))T.forEach(C=>{var I=bV(bV({},v),{},{name:C.name,unit:C.unit,color:void 0,fill:void 0});g.push(UH({tooltipEntrySettings:I,dataKey:C.dataKey,payload:C.payload,value:Jn(C.payload,C.dataKey),name:C.name}))});else{var P;g.push(UH({tooltipEntrySettings:v,dataKey:S,payload:T,value:Jn(T,S),name:(P=Jn(T,A))!==null&&P!==void 0?P:v?.name}))}return g},f)}},xj=Ke([yi,wn,AQ,$O,vi],UQ),g5e=Ke([t=>t.graphicalItems.cartesianItems,t=>t.graphicalItems.polarItems],(t,e)=>[...t,...e]),x5e=Ke([vi,Jm],YO),Lb=Ke([g5e,yi,x5e],ZO,{memoizeOptions:{resultEqualityCheck:DE}}),b5e=Ke([Lb],t=>t.filter(PE)),v5e=Ke([Lb],QO,{memoizeOptions:{resultEqualityCheck:DE}}),ig=Ke([v5e,vd],JO),y5e=Ke([b5e,vd,yi],SQ),bj=Ke([ig,yi,Lb],tj),aJ=Ke([yi],nj),_5e=Ke([yi],t=>t.allowDataOverflow),oJ=Ke([aJ,_5e],eQ),w5e=Ke([Lb],t=>t.filter(PE)),S5e=Ke([y5e,w5e,Nb,gQ],kQ),E5e=Ke([S5e,vd,vi,oJ],PQ),M5e=Ke([Lb],CQ),A5e=Ke([ig,yi,M5e,LE,vi],sj,{memoizeOptions:{resultEqualityCheck:RE}}),T5e=Ke([RQ,vi,Jm],eg),C5e=Ke([T5e,vi],jQ),N5e=Ke([DQ,vi,Jm],eg),k5e=Ke([N5e,vi],LQ),P5e=Ke([OQ,vi,Jm],eg),R5e=Ke([P5e,vi],IQ),D5e=Ke([C5e,R5e,k5e],Yw),O5e=Ke([yi,aJ,oJ,E5e,A5e,D5e,wn,vi],aj),Ib=Ke([yi,wn,ig,bj,Nb,vi,O5e],oj),j5e=Ke([Ib,yi,xj],uj),L5e=Ke([yi,Ib,j5e,vi],hj),lJ=t=>{var e=vi(t),n=Jm(t),r=!1;return Ob(t,e,n,r)},cJ=Ke([yi,lJ],CE),uJ=Ke([yi,xj,L5e,cJ],cj),I5e=Ke([wn,bj,yi,vi],GQ),U5e=Ke([wn,bj,yi,vi],WQ),F5e=(t,e,n,r,i,s,a,o)=>{if(e){var{type:l}=e,u=kc(t,o);if(r){var d=n==="scaleBand"&&r.bandwidth?r.bandwidth()/2:2,f=l==="category"&&r.bandwidth?r.bandwidth()/d:0;return f=o==="angleAxis"&&i!=null&&i?.length>=2?Di(i[0]-i[1])*2*f:f,u&&a?a.map((g,m)=>({coordinate:r(g)+f,value:g,index:m,offset:f})):r.domain().map((g,m)=>({coordinate:r(g)+f,value:s?s[g]:g,index:m,offset:f}))}}},Lc=Ke([wn,yi,xj,uJ,lJ,I5e,U5e,vi],F5e),vj=Ke([KQ,XQ,KUe],(t,e,n)=>YQ(n.shared,t,e)),dJ=t=>t.tooltip.settings.trigger,yj=t=>t.tooltip.settings.defaultIndex,Ub=Ke([rg,vj,dJ,yj],nJ),cd=Ke([Ub,ig,Db,Ib],gj),hJ=Ke([Lc,cd],ZQ),_j=Ke([Ub],t=>{if(t)return t.dataKey}),z5e=Ke([Ub],t=>{if(t)return t.graphicalItemId}),fJ=Ke([rg,vj,dJ,yj],iJ),B5e=Ke([Pc,Rc,wn,xi,Lc,yj,fJ,jb],rJ),H5e=Ke([Ub,B5e],(t,e)=>t!=null&&t.coordinate?t.coordinate:e),$5e=Ke([Ub],t=>t.active),V5e=Ke([fJ,cd,vd,Db,hJ,jb,vj],sJ),G5e=Ke([V5e],t=>{if(t!=null){var e=t.map(n=>n.payload).filter(n=>n!=null);return Array.from(new Set(e))}});function vV(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function yV(t){for(var e=1;ekt(yi),Y5e=()=>{var t=X5e(),e=kt(Lc),n=kt(uJ);return Tm(!t||!n?void 0:yV(yV({},t),{},{scale:n}),e)};function _V(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function Ep(t){for(var e=1;e{var i=e.find(s=>s&&s.index===n);if(i){if(t==="horizontal")return{x:i.coordinate,y:r.chartY};if(t==="vertical")return{x:r.chartX,y:i.coordinate}}return{x:0,y:0}},tFe=(t,e,n,r)=>{var i=e.find(u=>u&&u.index===n);if(i){if(t==="centric"){var s=i.coordinate,{radius:a}=r;return Ep(Ep(Ep({},r),Yr(r.cx,r.cy,a,s)),{},{angle:s,radius:a})}var o=i.coordinate,{angle:l}=r;return Ep(Ep(Ep({},r),Yr(r.cx,r.cy,o,l)),{},{angle:l,radius:o})}return{angle:0,clockWise:!1,cx:0,cy:0,endAngle:0,innerRadius:0,outerRadius:0,radius:0,startAngle:0,x:0,y:0}};function nFe(t,e){var{chartX:n,chartY:r}=t;return n>=e.left&&n<=e.left+e.width&&r>=e.top&&r<=e.top+e.height}var pJ=(t,e,n,r,i)=>{var s,a=-1,o=(s=e?.length)!==null&&s!==void 0?s:0;if(o<=1||t==null)return 0;if(r==="angleAxis"&&i!=null&&Math.abs(Math.abs(i[1]-i[0])-360)<=1e-6)for(var l=0;l0?n[l-1].coordinate:n[o-1].coordinate,d=n[l].coordinate,f=l>=o-1?n[0].coordinate:n[l+1].coordinate,g=void 0;if(Di(d-u)!==Di(f-d)){var m=[];if(Di(f-d)===Di(i[1]-i[0])){g=f;var x=d+i[1]-i[0];m[0]=Math.min(x,(x+u)/2),m[1]=Math.max(x,(x+u)/2)}else{g=u;var y=f+i[1]-i[0];m[0]=Math.min(d,(y+d)/2),m[1]=Math.max(d,(y+d)/2)}var v=[Math.min(d,(g+d)/2),Math.max(d,(g+d)/2)];if(t>v[0]&&t<=v[1]||t>=m[0]&&t<=m[1]){({index:a}=n[l]);break}}else{var b=Math.min(u,f),E=Math.max(u,f);if(t>(b+d)/2&&t<=(E+d)/2){({index:a}=n[l]);break}}}else if(e){for(var S=0;S0&&S(e[S].coordinate+e[S-1].coordinate)/2&&t<=(e[S].coordinate+e[S+1].coordinate)/2||S===o-1&&t>(e[S].coordinate+e[S-1].coordinate)/2){({index:a}=e[S]);break}}return a},mJ=()=>kt($O),wj=(t,e)=>e,gJ=(t,e,n)=>n,Sj=(t,e,n,r)=>r,rFe=Ke(Lc,t=>rE(t,e=>e.coordinate)),Ej=Ke([rg,wj,gJ,Sj],nJ),Mj=Ke([Ej,ig,Db,Ib],gj),iFe=(t,e,n)=>{if(e!=null){var r=rg(t);return e==="axis"?n==="hover"?r.axisInteraction.hover.dataKey:r.axisInteraction.click.dataKey:n==="hover"?r.itemInteraction.hover.dataKey:r.itemInteraction.click.dataKey}},xJ=Ke([rg,wj,gJ,Sj],iJ),Zw=Ke([Pc,Rc,wn,xi,Lc,Sj,xJ,jb],rJ),sFe=Ke([Ej,Zw],(t,e)=>{var n;return(n=t.coordinate)!==null&&n!==void 0?n:e}),bJ=Ke([Lc,Mj],ZQ),aFe=Ke([xJ,Mj,vd,Db,bJ,jb,wj],sJ),oFe=Ke([Ej,Mj],(t,e)=>({isActive:t.active&&e!=null,activeIndex:e})),lFe=(t,e,n,r,i,s,a)=>{if(!(!t||!n||!r||!i)&&nFe(t,a)){var o=NDe(t,e),l=pJ(o,s,i,n,r),u=eFe(e,i,l,t);return{activeIndex:String(l),activeCoordinate:u}}},cFe=(t,e,n,r,i,s,a)=>{if(!(!t||!r||!i||!s||!n)){var o=Wje(t,n);if(o){var l=kDe(o,e),u=pJ(l,a,s,r,i),d=tFe(e,s,u,o);return{activeIndex:String(u),activeCoordinate:d}}}},uFe=(t,e,n,r,i,s,a,o)=>{if(!(!t||!e||!r||!i||!s))return e==="horizontal"||e==="vertical"?lFe(t,e,r,i,s,a,o):cFe(t,e,n,r,i,s,a)},dFe=Ke(t=>t.zIndex.zIndexMap,(t,e)=>e,(t,e,n)=>n,(t,e,n)=>{if(e!=null){var r=t[e];if(r!=null)return n?r.panoramaElementId:r.elementId}}),hFe=Ke(t=>t.zIndex.zIndexMap,t=>{var e=Object.keys(t).map(r=>parseInt(r,10)).concat(Object.values(Zr)),n=Array.from(new Set(e));return n.sort((r,i)=>r-i)},{memoizeOptions:{resultEqualityCheck:X4e}});function wV(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function SV(t){for(var e=1;eSV(SV({},t),{},{[e]:{elementId:void 0,panoramaElementId:void 0,consumers:0}}),gFe)},bFe=new Set(Object.values(Zr));function vFe(t){return bFe.has(t)}var vJ=Zs({name:"zIndex",initialState:xFe,reducers:{registerZIndexPortal:{reducer:(t,e)=>{var{zIndex:n}=e.payload;t.zIndexMap[n]?t.zIndexMap[n].consumers+=1:t.zIndexMap[n]={consumers:1,elementId:void 0,panoramaElementId:void 0}},prepare:hr()},unregisterZIndexPortal:{reducer:(t,e)=>{var{zIndex:n}=e.payload;t.zIndexMap[n]&&(t.zIndexMap[n].consumers-=1,t.zIndexMap[n].consumers<=0&&!vFe(n)&&delete t.zIndexMap[n])},prepare:hr()},registerZIndexPortalId:{reducer:(t,e)=>{var{zIndex:n,elementId:r,isPanorama:i}=e.payload;t.zIndexMap[n]?i?t.zIndexMap[n].panoramaElementId=r:t.zIndexMap[n].elementId=r:t.zIndexMap[n]={consumers:0,elementId:i?void 0:r,panoramaElementId:i?r:void 0}},prepare:hr()},unregisterZIndexPortalId:{reducer:(t,e)=>{var{zIndex:n}=e.payload;t.zIndexMap[n]&&(e.payload.isPanorama?t.zIndexMap[n].panoramaElementId=void 0:t.zIndexMap[n].elementId=void 0)},prepare:hr()}}}),{registerZIndexPortal:yFe,unregisterZIndexPortal:_Fe,registerZIndexPortalId:wFe,unregisterZIndexPortalId:SFe}=vJ.actions,EFe=vJ.reducer;function Qs(t){var{zIndex:e,children:n}=t,r=lOe(),i=r&&e!==void 0&&e!==0,s=ms(),a=rr();M.useLayoutEffect(()=>i?(a(yFe({zIndex:e})),()=>{a(_Fe({zIndex:e}))}):gb,[a,e,i]);var o=kt(u=>dFe(u,e,s));if(!i)return n;if(!o)return null;var l=document.getElementById(o);return l?ic.createPortal(n,l):null}function BP(){return BP=Object.assign?Object.assign.bind():function(t){for(var e=1;eM.useContext(yJ),EN={exports:{}},MV;function RFe(){return MV||(MV=1,(function(t){var e=Object.prototype.hasOwnProperty,n="~";function r(){}Object.create&&(r.prototype=Object.create(null),new r().__proto__||(n=!1));function i(l,u,d){this.fn=l,this.context=u,this.once=d||!1}function s(l,u,d,f,g){if(typeof d!="function")throw new TypeError("The listener must be a function");var m=new i(d,f||l,g),x=n?n+u:u;return l._events[x]?l._events[x].fn?l._events[x]=[l._events[x],m]:l._events[x].push(m):(l._events[x]=m,l._eventsCount++),l}function a(l,u){--l._eventsCount===0?l._events=new r:delete l._events[u]}function o(){this._events=new r,this._eventsCount=0}o.prototype.eventNames=function(){var u=[],d,f;if(this._eventsCount===0)return u;for(f in d=this._events)e.call(d,f)&&u.push(n?f.slice(1):f);return Object.getOwnPropertySymbols?u.concat(Object.getOwnPropertySymbols(d)):u},o.prototype.listeners=function(u){var d=n?n+u:u,f=this._events[d];if(!f)return[];if(f.fn)return[f.fn];for(var g=0,m=f.length,x=new Array(m);g{t.eventEmitter==null&&(t.eventEmitter=Symbol("rechartsEventEmitter"))}}}),LFe=_J.reducer,{createEventEmitter:IFe}=_J.actions;function UFe(t){return t.tooltip.syncInteraction}var FFe={chartData:void 0,computedData:void 0,dataStartIndex:0,dataEndIndex:0},wJ=Zs({name:"chartData",initialState:FFe,reducers:{setChartData(t,e){if(t.chartData=e.payload,e.payload==null){t.dataStartIndex=0,t.dataEndIndex=0;return}e.payload.length>0&&t.dataEndIndex!==e.payload.length-1&&(t.dataEndIndex=e.payload.length-1)},setComputedData(t,e){t.computedData=e.payload},setDataStartEndIndexes(t,e){var{startIndex:n,endIndex:r}=e.payload;n!=null&&(t.dataStartIndex=n),r!=null&&(t.dataEndIndex=r)}}}),{setChartData:TV,setDataStartEndIndexes:zFe,setComputedData:b7e}=wJ.actions,BFe=wJ.reducer,HFe=["x","y"];function CV(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function Mp(t){for(var e=1;el.rootProps.className);M.useEffect(()=>{if(t==null)return gb;var l=(u,d,f)=>{if(e!==f&&t===u){if(r==="index"){var g;if(a&&d!==null&&d!==void 0&&(g=d.payload)!==null&&g!==void 0&&g.coordinate&&d.payload.sourceViewBox){var m=d.payload.coordinate,{x,y}=m,v=WFe(m,HFe),{x:b,y:E,width:S,height:A}=d.payload.sourceViewBox,T=Mp(Mp({},v),{},{x:a.x+(S?(x-b)/S:0)*a.width,y:a.y+(A?(y-E)/A:0)*a.height});n(Mp(Mp({},d),{},{payload:Mp(Mp({},d.payload),{},{coordinate:T})}))}else n(d);return}if(i!=null){var P;if(typeof r=="function"){var C={activeTooltipIndex:d.payload.index==null?void 0:Number(d.payload.index),isTooltipActive:d.payload.active,activeIndex:d.payload.index==null?void 0:Number(d.payload.index),activeLabel:d.payload.label,activeDataKey:d.payload.dataKey,activeCoordinate:d.payload.coordinate},I=r(i,C);P=i[I]}else r==="value"&&(P=i.find(K=>String(K.value)===d.payload.label));var{coordinate:N}=d.payload;if(P==null||d.payload.active===!1||N==null||a==null){n(FP({active:!1,coordinate:void 0,dataKey:void 0,index:null,label:void 0,sourceViewBox:void 0,graphicalItemId:void 0}));return}var{x:D,y:F}=N,L=Math.min(D,a.x+a.width),q=Math.min(F,a.y+a.height),R={x:s==="horizontal"?P.coordinate:L,y:s==="horizontal"?q:P.coordinate},V=FP({active:d.payload.active,coordinate:R,dataKey:d.payload.dataKey,index:String(P.index),label:d.payload.label,sourceViewBox:d.payload.sourceViewBox,graphicalItemId:d.payload.graphicalItemId});n(V)}}};return Q0.on(HP,l),()=>{Q0.off(HP,l)}},[o,n,e,t,r,i,s,a])}function XFe(){var t=kt(VO),e=kt(GO),n=rr();M.useEffect(()=>{if(t==null)return gb;var r=(i,s,a)=>{e!==a&&t===i&&n(zFe(s))};return Q0.on(AV,r),()=>{Q0.off(AV,r)}},[n,e,t])}function YFe(){var t=rr();M.useEffect(()=>{t(IFe())},[t]),KFe(),XFe()}function ZFe(t,e,n,r,i,s){var a=kt(m=>iFe(m,t,e)),o=kt(GO),l=kt(VO),u=kt(xQ),d=kt(UFe),f=d?.active,g=gE();M.useEffect(()=>{if(!f&&l!=null&&o!=null){var m=FP({active:s,coordinate:n,dataKey:a,index:i,label:typeof r=="number"?String(r):r,sourceViewBox:g,graphicalItemId:void 0});Q0.emit(HP,l,m,o)}},[f,n,a,i,r,o,l,u,s,g])}function NV(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function kV(t){for(var e=1;e{C(JUe({shared:E,trigger:S,axisId:P,active:i,defaultIndex:I}))},[C,E,S,P,i,I]);var N=gE(),D=cZ(),F=qUe(E),{activeIndex:L,isActive:q}=(e=kt(xe=>oFe(xe,F,S,I)))!==null&&e!==void 0?e:{},R=kt(xe=>aFe(xe,F,S,I)),V=kt(xe=>bJ(xe,F,S,I)),K=kt(xe=>sFe(xe,F,S,I)),W=R,ne=PFe(),Y=(n=i??q)!==null&&n!==void 0?n:!1,[Z,U]=uY([W,Y]),$=F==="axis"?V:void 0;ZFe(F,S,K,$,L,Y);var ee=T??ne;if(ee==null||N==null||F==null)return null;var ae=W??PV;Y||(ae=PV),u&&ae.length&&(ae=sY(ae.filter(xe=>xe.value!=null&&(xe.hide!==!0||r.includeHidden)),g,tze));var fe=ae.length>0,ue=M.createElement(qOe,{allowEscapeViewBox:s,animationDuration:a,animationEasing:o,isAnimationActive:d,active:Y,coordinate:K,hasPayload:fe,offset:f,position:m,reverseDirection:x,useTranslate3d:y,viewBox:N,wrapperStyle:v,lastBoundingBox:Z,innerRef:U,hasPortalFromProps:!!T},nze(l,kV(kV({},r),{},{payload:ae,label:$,active:Y,activeIndex:L,coordinate:K,accessibilityLayer:D})));return M.createElement(M.Fragment,null,ic.createPortal(ue,ee),Y&&M.createElement(kFe,{cursor:b,tooltipEventType:F,coordinate:K,payload:ae,index:L}))}var Fb=t=>null;Fb.displayName="Cell";function ize(t,e,n){return(e=sze(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function sze(t){var e=aze(t,"string");return typeof e=="symbol"?e:e+""}function aze(t,e){if(typeof t!="object"||!t)return t;var n=t[Symbol.toPrimitive];if(n!==void 0){var r=n.call(t,e);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(t)}class oze{constructor(e){ize(this,"cache",new Map),this.maxSize=e}get(e){var n=this.cache.get(e);return n!==void 0&&(this.cache.delete(e),this.cache.set(e,n)),n}set(e,n){if(this.cache.has(e))this.cache.delete(e);else if(this.cache.size>=this.maxSize){var r=this.cache.keys().next().value;r!=null&&this.cache.delete(r)}this.cache.set(e,n)}clear(){this.cache.clear()}size(){return this.cache.size}}function RV(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function lze(t){for(var e=1;e{try{var n=document.getElementById(OV);n||(n=document.createElement("span"),n.setAttribute("id",OV),n.setAttribute("aria-hidden","true"),document.body.appendChild(n)),Object.assign(n.style,fze,e),n.textContent="".concat(t);var r=n.getBoundingClientRect();return{width:r.width,height:r.height}}catch{return{width:0,height:0}}},e0=function(e){var n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(e==null||Xm.isSsr)return{width:0,height:0};if(!SJ.enableCache)return jV(e,n);var r=pze(e,n),i=DV.get(r);if(i)return i;var s=jV(e,n);return DV.set(r,s),s},LV=/(-?\d+(?:\.\d+)?[a-zA-Z%]*)([*/])(-?\d+(?:\.\d+)?[a-zA-Z%]*)/,IV=/(-?\d+(?:\.\d+)?[a-zA-Z%]*)([+-])(-?\d+(?:\.\d+)?[a-zA-Z%]*)/,mze=/^px|cm|vh|vw|em|rem|%|mm|in|pt|pc|ex|ch|vmin|vmax|Q$/,gze=/(-?\d+(?:\.\d+)?)([a-zA-Z%]+)?/,EJ={cm:96/2.54,mm:96/25.4,pt:96/72,pc:96/6,in:96,Q:96/(2.54*40),px:1},xze=Object.keys(EJ),Fp="NaN";function bze(t,e){return t*EJ[e]}class Fs{static parse(e){var n,[,r,i]=(n=gze.exec(e))!==null&&n!==void 0?n:[];return new Fs(parseFloat(r),i??"")}constructor(e,n){this.num=e,this.unit=n,this.num=e,this.unit=n,io(e)&&(this.unit=""),n!==""&&!mze.test(n)&&(this.num=NaN,this.unit=""),xze.includes(n)&&(this.num=bze(e,n),this.unit="px")}add(e){return this.unit!==e.unit?new Fs(NaN,""):new Fs(this.num+e.num,this.unit)}subtract(e){return this.unit!==e.unit?new Fs(NaN,""):new Fs(this.num-e.num,this.unit)}multiply(e){return this.unit!==""&&e.unit!==""&&this.unit!==e.unit?new Fs(NaN,""):new Fs(this.num*e.num,this.unit||e.unit)}divide(e){return this.unit!==""&&e.unit!==""&&this.unit!==e.unit?new Fs(NaN,""):new Fs(this.num/e.num,this.unit||e.unit)}toString(){return"".concat(this.num).concat(this.unit)}isNaN(){return io(this.num)}}function MJ(t){if(t.includes(Fp))return Fp;for(var e=t;e.includes("*")||e.includes("/");){var n,[,r,i,s]=(n=LV.exec(e))!==null&&n!==void 0?n:[],a=Fs.parse(r??""),o=Fs.parse(s??""),l=i==="*"?a.multiply(o):a.divide(o);if(l.isNaN())return Fp;e=e.replace(LV,l.toString())}for(;e.includes("+")||/.-\d+(?:\.\d+)?/.test(e);){var u,[,d,f,g]=(u=IV.exec(e))!==null&&u!==void 0?u:[],m=Fs.parse(d??""),x=Fs.parse(g??""),y=f==="+"?m.add(x):m.subtract(x);if(y.isNaN())return Fp;e=e.replace(IV,y.toString())}return e}var UV=/\(([^()]*)\)/;function vze(t){for(var e=t,n;(n=UV.exec(e))!=null;){var[,r]=n;e=e.replace(UV,MJ(r))}return e}function yze(t){var e=t.replace(/\s+/g,"");return e=vze(e),e=MJ(e),e}function _ze(t){try{return yze(t)}catch{return Fp}}function AN(t){var e=_ze(t.slice(5,-1));return e===Fp?"":e}var wze=["x","y","lineHeight","capHeight","fill","scaleToFit","textAnchor","verticalAnchor"],Sze=["dx","dy","angle","className","breakAll"];function $P(){return $P=Object.assign?Object.assign.bind():function(t){for(var e=1;e{var{children:e,breakAll:n,style:r}=t;try{var i=[];yr(e)||(n?i=e.toString().split(""):i=e.toString().split(AJ));var s=i.map(o=>({word:o,width:e0(o,r).width})),a=n?0:e0(" ",r).width;return{wordsWithComputedWidth:s,spaceWidth:a}}catch{return null}};function Mze(t){return t==="start"||t==="middle"||t==="end"||t==="inherit"}var CJ=(t,e,n,r)=>t.reduce((i,s)=>{var{word:a,width:o}=s,l=i[i.length-1];if(l&&o!=null&&(e==null||r||l.width+o+nt.reduce((e,n)=>e.width>n.width?e:n),Aze="…",zV=(t,e,n,r,i,s,a,o)=>{var l=t.slice(0,e),u=TJ({breakAll:n,style:r,children:l+Aze});if(!u)return[!1,[]];var d=CJ(u.wordsWithComputedWidth,s,a,o),f=d.length>i||NJ(d).width>Number(s);return[f,d]},Tze=(t,e,n,r,i)=>{var{maxLines:s,children:a,style:o,breakAll:l}=t,u=Ct(s),d=String(a),f=CJ(e,r,n,i);if(!u||i)return f;var g=f.length>s||NJ(f).width>Number(r);if(!g)return f;for(var m=0,x=d.length-1,y=0,v;m<=x&&y<=d.length-1;){var b=Math.floor((m+x)/2),E=b-1,[S,A]=zV(d,E,l,o,s,r,n,i),[T]=zV(d,b,l,o,s,r,n,i);if(!S&&!T&&(m=b+1),S&&T&&(x=b-1),!S&&T){v=A;break}y++}return v||f},BV=t=>{var e=yr(t)?[]:t.toString().split(AJ);return[{words:e,width:void 0}]},Cze=t=>{var{width:e,scaleToFit:n,children:r,style:i,breakAll:s,maxLines:a}=t;if((e||n)&&!Xm.isSsr){var o,l,u=TJ({breakAll:s,children:r,style:i});if(u){var{wordsWithComputedWidth:d,spaceWidth:f}=u;o=d,l=f}else return BV(r);return Tze({breakAll:s,children:r,maxLines:a,style:i},o,l,e,!!n)}return BV(r)},kJ="#808080",Nze={angle:0,breakAll:!1,capHeight:"0.71em",fill:kJ,lineHeight:"1em",scaleToFit:!1,textAnchor:"start",verticalAnchor:"end",x:0,y:0},FE=M.forwardRef((t,e)=>{var n=ii(t,Nze),{x:r,y:i,lineHeight:s,capHeight:a,fill:o,scaleToFit:l,textAnchor:u,verticalAnchor:d}=n,f=FV(n,wze),g=M.useMemo(()=>Cze({breakAll:f.breakAll,children:f.children,maxLines:f.maxLines,scaleToFit:l,style:f.style,width:f.width}),[f.breakAll,f.children,f.maxLines,l,f.style,f.width]),{dx:m,dy:x,angle:y,className:v,breakAll:b}=f,E=FV(f,Sze);if(!fl(r)||!fl(i)||g.length===0)return null;var S=Number(r)+(Ct(m)?m:0),A=Number(i)+(Ct(x)?x:0);if(!ur(S)||!ur(A))return null;var T;switch(d){case"start":T=AN("calc(".concat(a,")"));break;case"middle":T=AN("calc(".concat((g.length-1)/2," * -").concat(s," + (").concat(a," / 2))"));break;default:T=AN("calc(".concat(g.length-1," * -").concat(s,")"));break}var P=[];if(l){var C=g[0].width,{width:I}=f;P.push("scale(".concat(Ct(I)&&Ct(C)?I/C:1,")"))}return y&&P.push("rotate(".concat(y,", ").concat(S,", ").concat(A,")")),P.length&&(E.transform=P.join(" ")),M.createElement("text",$P({},Cs(E),{ref:e,x:S,y:A,className:Tn("recharts-text",v),textAnchor:u,fill:o.includes("url")?kJ:o}),g.map((N,D)=>{var F=N.words.join(b?"":" ");return M.createElement("tspan",{x:S,dy:D===0?T:s,key:"".concat(F,"-").concat(D)},F)}))});FE.displayName="Text";var kze=["labelRef"];function Pze(t,e){if(t==null)return{};var n,r,i=Rze(t,e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(t);for(r=0;r{var{x:e,y:n,upperWidth:r,lowerWidth:i,width:s,height:a,children:o}=t,l=M.useMemo(()=>({x:e,y:n,upperWidth:r,lowerWidth:i,width:s,height:a}),[e,n,r,i,s,a]);return M.createElement(PJ.Provider,{value:l},o)},RJ=()=>{var t=M.useContext(PJ),e=gE();return t||YY(e)},Ize=M.createContext(null),Uze=()=>{var t=M.useContext(Ize),e=kt(wQ);return t||e},Fze=t=>{var{value:e,formatter:n}=t,r=yr(t.children)?e:t.children;return typeof n=="function"?n(r):r},Tj=t=>t!=null&&typeof t=="function",zze=(t,e)=>{var n=Di(e-t),r=Math.min(Math.abs(e-t),360);return n*r},Bze=(t,e,n,r,i)=>{var{offset:s,className:a}=t,{cx:o,cy:l,innerRadius:u,outerRadius:d,startAngle:f,endAngle:g,clockWise:m}=i,x=(u+d)/2,y=zze(f,g),v=y>=0?1:-1,b,E;switch(e){case"insideStart":b=f+v*s,E=m;break;case"insideEnd":b=g-v*s,E=!m;break;case"end":b=g+v*s,E=m;break;default:throw new Error("Unsupported position ".concat(e))}E=y<=0?E:!E;var S=Yr(o,l,x,b),A=Yr(o,l,x,b+(E?1:-1)*359),T="M".concat(S.x,",").concat(S.y,` A`).concat(x,",").concat(x,",0,1,").concat(E?0:1,`, - `).concat(A.x,",").concat(A.y),P=yr(t.id)?U0("recharts-radial-line-"):t.id;return M.createElement("text",rc({},r,{dominantBaseline:"central",className:Tn("recharts-radial-bar-label",a)}),M.createElement("defs",null,M.createElement("path",{id:P,d:T})),M.createElement("textPath",{xlinkHref:"#".concat(P)},n))},Hze=(t,e,n)=>{var{cx:r,cy:i,innerRadius:s,outerRadius:a,startAngle:o,endAngle:l}=t,u=(o+l)/2;if(n==="outside"){var{x:d,y:f}=Yr(r,i,a+e,u);return{x:d,y:f,textAnchor:d>=r?"start":"end",verticalAnchor:"middle"}}if(n==="center")return{x:r,y:i,textAnchor:"middle",verticalAnchor:"middle"};if(n==="centerTop")return{x:r,y:i,textAnchor:"middle",verticalAnchor:"start"};if(n==="centerBottom")return{x:r,y:i,textAnchor:"middle",verticalAnchor:"end"};var g=(s+a)/2,{x:m,y:x}=Yr(r,i,g,u);return{x:m,y:x,textAnchor:"middle",verticalAnchor:"middle"}},VP=t=>"cx"in t&&Ct(t.cx),$ze=(t,e)=>{var{parentViewBox:n,offset:r,position:i}=t,s;n!=null&&!VP(n)&&(s=n);var{x:a,y:o,upperWidth:l,lowerWidth:u,height:d}=e,f=a,g=a+(l-u)/2,m=(f+g)/2,x=(l+u)/2,y=f+l/2,v=d>=0?1:-1,b=v*r,E=v>0?"end":"start",S=v>0?"start":"end",A=l>=0?1:-1,T=A*r,P=A>0?"end":"start",C=A>0?"start":"end";if(i==="top"){var I={x:f+l/2,y:o-b,textAnchor:"middle",verticalAnchor:E};return Or(Or({},I),s?{height:Math.max(o-s.y,0),width:l}:{})}if(i==="bottom"){var N={x:g+u/2,y:o+d+b,textAnchor:"middle",verticalAnchor:S};return Or(Or({},N),s?{height:Math.max(s.y+s.height-(o+d),0),width:u}:{})}if(i==="left"){var D={x:m-T,y:o+d/2,textAnchor:P,verticalAnchor:"middle"};return Or(Or({},D),s?{width:Math.max(D.x-s.x,0),height:d}:{})}if(i==="right"){var F={x:m+x+T,y:o+d/2,textAnchor:C,verticalAnchor:"middle"};return Or(Or({},F),s?{width:Math.max(s.x+s.width-F.x,0),height:d}:{})}var L=s?{width:x,height:d}:{};return i==="insideLeft"?Or({x:m+T,y:o+d/2,textAnchor:C,verticalAnchor:"middle"},L):i==="insideRight"?Or({x:m+x-T,y:o+d/2,textAnchor:P,verticalAnchor:"middle"},L):i==="insideTop"?Or({x:f+l/2,y:o+b,textAnchor:"middle",verticalAnchor:S},L):i==="insideBottom"?Or({x:g+u/2,y:o+d-b,textAnchor:"middle",verticalAnchor:E},L):i==="insideTopLeft"?Or({x:f+T,y:o+b,textAnchor:C,verticalAnchor:S},L):i==="insideTopRight"?Or({x:f+l-T,y:o+b,textAnchor:P,verticalAnchor:S},L):i==="insideBottomLeft"?Or({x:g+T,y:o+d-b,textAnchor:C,verticalAnchor:E},L):i==="insideBottomRight"?Or({x:g+u-T,y:o+d-b,textAnchor:P,verticalAnchor:E},L):i&&typeof i=="object"&&(Ct(i.x)||wc(i.x))&&(Ct(i.y)||wc(i.y))?Or({x:a+hs(i.x,x),y:o+hs(i.y,d),textAnchor:"end",verticalAnchor:"end"},L):Or({x:y,y:o+d/2,textAnchor:"middle",verticalAnchor:"middle"},L)},Vze={angle:0,offset:5,zIndex:Zr.label,position:"middle",textBreakAll:!1};function Nu(t){var e=ii(t,Vze),{viewBox:n,position:r,value:i,children:s,content:a,className:o="",textBreakAll:l,labelRef:u}=e,d=Uze(),f=RJ(),g=r==="center"?f:d??f,m,x,y;if(n==null?m=g:VP(n)?m=n:m=YY(n),!m||yr(i)&&yr(s)&&!M.isValidElement(a)&&typeof a!="function")return null;var v=Or(Or({},e),{},{viewBox:m});if(M.isValidElement(a)){var{labelRef:b}=v,E=Pze(v,kze);return M.cloneElement(a,E)}if(typeof a=="function"){if(x=M.createElement(a,v),M.isValidElement(x))return x}else x=Fze(e);var S=Cs(e);if(VP(m)){if(r==="insideStart"||r==="insideEnd"||r==="end")return Bze(e,r,x,S,m);y=Hze(m,e.offset,e.position)}else y=$ze(e,m);return M.createElement(Qs,{zIndex:e.zIndex},M.createElement(FE,rc({ref:u,className:Tn("recharts-label",o)},S,y,{textAnchor:Mze(S.textAnchor)?S.textAnchor:y.textAnchor,breakAll:l}),x))}Nu.displayName="Label";var Gze=(t,e,n)=>{if(!t)return null;var r={viewBox:e,labelRef:n};return t===!0?M.createElement(Nu,rc({key:"label-implicit"},r)):fl(t)?M.createElement(Nu,rc({key:"label-implicit",value:t},r)):M.isValidElement(t)?t.type===Nu?M.cloneElement(t,Or({key:"label-implicit"},r)):M.createElement(Nu,rc({key:"label-implicit",content:t},r)):Tj(t)?M.createElement(Nu,rc({key:"label-implicit",content:t},r)):t&&typeof t=="object"?M.createElement(Nu,rc({},t,{key:"label-implicit"},r)):null};function Wze(t){var{label:e,labelRef:n}=t,r=RJ();return Gze(e,r,n)||null}var TN={},CN={},$V;function qze(){return $V||($V=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});function e(n){return n[n.length-1]}t.last=e})(CN)),CN}var NN={},VV;function Kze(){return VV||(VV=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});function e(n){return Array.isArray(n)?n:Array.from(n)}t.toArray=e})(NN)),NN}var GV;function Xze(){return GV||(GV=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});const e=qze(),n=Kze(),r=tO();function i(s){if(r.isArrayLike(s))return e.last(n.toArray(s))}t.last=i})(TN)),TN}var kN,WV;function Yze(){return WV||(WV=1,kN=Xze().last),kN}var Zze=Yze();const Qze=oo(Zze);var Jze=["valueAccessor"],eBe=["dataKey","clockWise","id","textBreakAll","zIndex"];function Qw(){return Qw=Object.assign?Object.assign.bind():function(t){for(var e=1;eArray.isArray(t.value)?Qze(t.value):t.value,DJ=M.createContext(void 0),OJ=DJ.Provider,jJ=M.createContext(void 0),rBe=jJ.Provider;function iBe(){return M.useContext(DJ)}function sBe(){return M.useContext(jJ)}function e1(t){var{valueAccessor:e=nBe}=t,n=qV(t,Jze),{dataKey:r,clockWise:i,id:s,textBreakAll:a,zIndex:o}=n,l=qV(n,eBe),u=iBe(),d=sBe(),f=u||d;return!f||!f.length?null:M.createElement(Qs,{zIndex:o??Zr.label},M.createElement(Ir,{className:"recharts-label-list"},f.map((g,m)=>{var x,y=yr(r)?e(g,m):Qn(g&&g.payload,r),v=yr(s)?{}:{id:"".concat(s,"-").concat(m)};return M.createElement(Nu,Qw({key:"label-".concat(m)},Cs(g),l,v,{fill:(x=n.fill)!==null&&x!==void 0?x:g.fill,parentViewBox:g.parentViewBox,value:y,textBreakAll:a,viewBox:g.viewBox,index:m,zIndex:0}))})))}e1.displayName="LabelList";function Cj(t){var{label:e}=t;return e?e===!0?M.createElement(e1,{key:"labelList-implicit"}):M.isValidElement(e)||Tj(e)?M.createElement(e1,{key:"labelList-implicit",content:e}):typeof e=="object"?M.createElement(e1,Qw({key:"labelList-implicit"},e,{type:String(e.type)})):null:null}function GP(){return GP=Object.assign?Object.assign.bind():function(t){for(var e=1;e{var{cx:e,cy:n,r,className:i}=t,s=Tn("recharts-dot",i);return Ct(e)&&Ct(n)&&Ct(r)?M.createElement("circle",GP({},Ks(t),eO(t),{className:s,cx:e,cy:n,r})):null},IJ=t=>t.graphicalItems.polarItems,aBe=Ke([gr,kb],YO),zE=Ke([IJ,wr,aBe],ZO),oBe=Ke([zE],QO),BE=Ke([oBe,zO],JO),lBe=Ke([BE,wr,zE],tj);Ke([BE,wr,zE],(t,e,n)=>n.length>0?t.flatMap(r=>n.flatMap(i=>{var s,a=Qn(r,(s=e.dataKey)!==null&&s!==void 0?s:i.dataKey);return{value:a,errorDomain:[]}})).filter(Boolean):e?.dataKey!=null?t.map(r=>({value:Qn(r,e.dataKey),errorDomain:[]})):t.map(r=>({value:r,errorDomain:[]})));var KV=()=>{},cBe=Ke([BE,wr,zE,LE,gr],sj),uBe=Ke([wr,rj,ij,KV,cBe,KV,wn,gr],aj),UJ=Ke([wr,wn,BE,lBe,Nb,gr,uBe],oj),dBe=Ke([UJ,wr,tg],uj);Ke([wr,UJ,dBe,gr],hj);var hBe={radiusAxis:{},angleAxis:{}},FJ=Zs({name:"polarAxis",initialState:hBe,reducers:{addRadiusAxis(t,e){t.radiusAxis[e.payload.id]=e.payload},removeRadiusAxis(t,e){delete t.radiusAxis[e.payload.id]},addAngleAxis(t,e){t.angleAxis[e.payload.id]=e.payload},removeAngleAxis(t,e){delete t.angleAxis[e.payload.id]}}}),{addRadiusAxis:v7e,removeRadiusAxis:y7e,addAngleAxis:_7e,removeAngleAxis:w7e}=FJ.actions,fBe=FJ.reducer;function XV(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function YV(t){for(var e=1;ee,Nj=Ke([IJ,xBe],(t,e)=>t.filter(n=>n.type==="pie").find(n=>n.id===e)),bBe=[],kj=(t,e,n)=>n?.length===0?bBe:n,zJ=Ke([zO,Nj,kj],(t,e,n)=>{var{chartData:r}=t;if(e!=null){var i;if(e?.data!=null&&e.data.length>0?i=e.data:i=r,(!i||!i.length)&&n!=null&&(i=n.map(s=>YV(YV({},e.presentationProps),s.props))),i!=null)return i}}),vBe=Ke([zJ,Nj,kj],(t,e,n)=>{if(!(t==null||e==null))return t.map((r,i)=>{var s,a=Qn(r,e.nameKey,e.name),o;return n!=null&&(s=n[i])!==null&&s!==void 0&&(s=s.props)!==null&&s!==void 0&&s.fill?o=n[i].props.fill:typeof r=="object"&&r!=null&&"fill"in r?o=r.fill:o=e.fill,{value:qm(a,e.dataKey),color:o,payload:r,type:e.legendType}})}),yBe=Ke([zJ,Nj,kj,xi],(t,e,n,r)=>{if(!(e==null||t==null))return _6e({offset:r,pieSettings:e,displayedData:t,cells:n})}),PN={exports:{}},Bn={};var ZV;function _Be(){if(ZV)return Bn;ZV=1;var t=Symbol.for("react.transitional.element"),e=Symbol.for("react.portal"),n=Symbol.for("react.fragment"),r=Symbol.for("react.strict_mode"),i=Symbol.for("react.profiler"),s=Symbol.for("react.consumer"),a=Symbol.for("react.context"),o=Symbol.for("react.forward_ref"),l=Symbol.for("react.suspense"),u=Symbol.for("react.suspense_list"),d=Symbol.for("react.memo"),f=Symbol.for("react.lazy"),g=Symbol.for("react.view_transition"),m=Symbol.for("react.client.reference");function x(y){if(typeof y=="object"&&y!==null){var v=y.$$typeof;switch(v){case t:switch(y=y.type,y){case n:case i:case r:case l:case u:case g:return y;default:switch(y=y&&y.$$typeof,y){case a:case o:case f:case d:return y;case s:return y;default:return v}}case e:return v}}}return Bn.ContextConsumer=s,Bn.ContextProvider=a,Bn.Element=t,Bn.ForwardRef=o,Bn.Fragment=n,Bn.Lazy=f,Bn.Memo=d,Bn.Portal=e,Bn.Profiler=i,Bn.StrictMode=r,Bn.Suspense=l,Bn.SuspenseList=u,Bn.isContextConsumer=function(y){return x(y)===s},Bn.isContextProvider=function(y){return x(y)===a},Bn.isElement=function(y){return typeof y=="object"&&y!==null&&y.$$typeof===t},Bn.isForwardRef=function(y){return x(y)===o},Bn.isFragment=function(y){return x(y)===n},Bn.isLazy=function(y){return x(y)===f},Bn.isMemo=function(y){return x(y)===d},Bn.isPortal=function(y){return x(y)===e},Bn.isProfiler=function(y){return x(y)===i},Bn.isStrictMode=function(y){return x(y)===r},Bn.isSuspense=function(y){return x(y)===l},Bn.isSuspenseList=function(y){return x(y)===u},Bn.isValidElementType=function(y){return typeof y=="string"||typeof y=="function"||y===n||y===i||y===r||y===l||y===u||typeof y=="object"&&y!==null&&(y.$$typeof===f||y.$$typeof===d||y.$$typeof===a||y.$$typeof===s||y.$$typeof===o||y.$$typeof===m||y.getModuleId!==void 0)},Bn.typeOf=x,Bn}var QV;function wBe(){return QV||(QV=1,PN.exports=_Be()),PN.exports}var SBe=wBe(),JV=t=>typeof t=="string"?t:t?t.displayName||t.name||"Component":"",e9=null,RN=null,BJ=t=>{if(t===e9&&Array.isArray(RN))return RN;var e=[];return M.Children.forEach(t,n=>{yr(n)||(SBe.isFragment(n)?e=e.concat(BJ(n.props.children)):e.push(n))}),RN=e,e9=t,e};function Pj(t,e){var n=[],r=[];return Array.isArray(e)?r=e.map(i=>JV(i)):r=[JV(e)],BJ(t).forEach(i=>{var s=Kh(i,"type.displayName")||Kh(i,"type.name");s&&r.indexOf(s)!==-1&&n.push(i)}),n}var HJ=t=>t&&typeof t=="object"&&"clipDot"in t?!!t.clipDot:!0,DN={},t9;function EBe(){return t9||(t9=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});function e(n){if(typeof n!="object"||n==null)return!1;if(Object.getPrototypeOf(n)===null)return!0;if(Object.prototype.toString.call(n)!=="[object Object]"){const i=n[Symbol.toStringTag];return i==null||!Object.getOwnPropertyDescriptor(n,Symbol.toStringTag)?.writable?!1:n.toString()===`[object ${i}]`}let r=n;for(;Object.getPrototypeOf(r)!==null;)r=Object.getPrototypeOf(r);return Object.getPrototypeOf(n)===r}t.isPlainObject=e})(DN)),DN}var ON,n9;function MBe(){return n9||(n9=1,ON=EBe().isPlainObject),ON}var ABe=MBe();const TBe=oo(ABe);function r9(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function i9(t){for(var e=1;e{var s=n-r,a;return a="M ".concat(t,",").concat(e),a+="L ".concat(t+n,",").concat(e),a+="L ".concat(t+n-s/2,",").concat(e+i),a+="L ".concat(t+n-s/2-r,",").concat(e+i),a+="L ".concat(t,",").concat(e," Z"),a},PBe={x:0,y:0,upperWidth:0,lowerWidth:0,height:0,isUpdateAnimationActive:!1,animationBegin:0,animationDuration:1500,animationEasing:"ease"},RBe=t=>{var e=ii(t,PBe),{x:n,y:r,upperWidth:i,lowerWidth:s,height:a,className:o}=e,{animationEasing:l,animationDuration:u,animationBegin:d,isUpdateAnimationActive:f}=e,g=M.useRef(null),[m,x]=M.useState(-1),y=M.useRef(i),v=M.useRef(s),b=M.useRef(a),E=M.useRef(n),S=M.useRef(r),A=Eb(t,"trapezoid-");if(M.useEffect(()=>{if(g.current&&g.current.getTotalLength)try{var R=g.current.getTotalLength();R&&x(R)}catch{}},[]),n!==+n||r!==+r||i!==+i||s!==+s||a!==+a||i===0&&s===0||a===0)return null;var T=Tn("recharts-trapezoid",o);if(!f)return M.createElement("g",null,M.createElement("path",Jw({},Cs(e),{className:T,d:s9(n,r,i,s,a)})));var P=y.current,C=v.current,I=b.current,N=E.current,D=S.current,F="0px ".concat(m===-1?1:m,"px"),L="".concat(m,"px 0px"),q=uZ(["strokeDasharray"],u,l);return M.createElement(Sb,{animationId:A,key:A,canBegin:m>0,duration:u,easing:l,isActive:f,begin:d},R=>{var V=cr(P,i,R),K=cr(C,s,R),W=cr(I,a,R),ne=cr(N,n,R),Y=cr(D,r,R);g.current&&(y.current=V,v.current=K,b.current=W,E.current=ne,S.current=Y);var Z=R>0?{transition:q,strokeDasharray:L}:{strokeDasharray:F};return M.createElement("path",Jw({},Cs(e),{className:T,d:s9(ne,Y,V,K,W),ref:g,style:i9(i9({},Z),e.style)}))})},DBe=["option","shapeType","propTransformer","activeClassName"];function OBe(t,e){if(t==null)return{};var n,r,i=jBe(t,e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(t);for(r=0;r{var r=rr();return(i,s)=>a=>{t?.(i,s,a),r(JQ({activeIndex:String(s),activeDataKey:e,activeCoordinate:i.tooltipPosition,activeGraphicalItemId:n}))}},Dj=t=>{var e=rr();return(n,r)=>i=>{t?.(n,r,i),e(e5e())}},Oj=(t,e,n)=>{var r=rr();return(i,s)=>a=>{t?.(i,s,a),r(t5e({activeIndex:String(s),activeDataKey:e,activeCoordinate:i.tooltipPosition,activeGraphicalItemId:n}))}};function jj(t){var{tooltipEntrySettings:e}=t,n=rr(),r=ms(),i=M.useRef(null);return M.useLayoutEffect(()=>{r||(i.current===null?n(YUe(e)):i.current!==e&&n(ZUe({prev:i.current,next:e})),i.current=e)},[e,n,r]),M.useLayoutEffect(()=>()=>{i.current&&(n(QUe(i.current)),i.current=null)},[n]),null}function VJ(t){var{legendPayload:e}=t,n=rr(),r=ms(),i=M.useRef(null);return M.useLayoutEffect(()=>{r||(i.current===null?n(sZ(e)):i.current!==e&&n(aZ({prev:i.current,next:e})),i.current=e)},[n,r,e]),M.useLayoutEffect(()=>()=>{i.current&&(n(oZ(i.current)),i.current=null)},[n]),null}function HBe(t){var{legendPayload:e}=t,n=rr(),r=kt(wn),i=M.useRef(null);return M.useLayoutEffect(()=>{r!=="centric"&&r!=="radial"||(i.current===null?n(sZ(e)):i.current!==e&&n(aZ({prev:i.current,next:e})),i.current=e)},[n,r,e]),M.useLayoutEffect(()=>()=>{i.current&&(n(oZ(i.current)),i.current=null)},[n]),null}var jN,$Be=()=>{var[t]=M.useState(()=>U0("uid-"));return t},VBe=(jN=$ne.useId)!==null&&jN!==void 0?jN:$Be;function GJ(t,e){var n=VBe();return e||(t?"".concat(t,"-").concat(n):n)}var GBe=M.createContext(void 0),Lj=t=>{var{id:e,type:n,children:r}=t,i=GJ("recharts-".concat(n),e);return M.createElement(GBe.Provider,{value:i},r(i))},WBe={cartesianItems:[],polarItems:[]},WJ=Zs({name:"graphicalItems",initialState:WBe,reducers:{addCartesianGraphicalItem:{reducer(t,e){t.cartesianItems.push(e.payload)},prepare:hr()},replaceCartesianGraphicalItem:{reducer(t,e){var{prev:n,next:r}=e.payload,i=Ro(t).cartesianItems.indexOf(n);i>-1&&(t.cartesianItems[i]=r)},prepare:hr()},removeCartesianGraphicalItem:{reducer(t,e){var n=Ro(t).cartesianItems.indexOf(e.payload);n>-1&&t.cartesianItems.splice(n,1)},prepare:hr()},addPolarGraphicalItem:{reducer(t,e){t.polarItems.push(e.payload)},prepare:hr()},removePolarGraphicalItem:{reducer(t,e){var n=Ro(t).polarItems.indexOf(e.payload);n>-1&&t.polarItems.splice(n,1)},prepare:hr()}}}),{addCartesianGraphicalItem:qBe,replaceCartesianGraphicalItem:KBe,removeCartesianGraphicalItem:XBe,addPolarGraphicalItem:YBe,removePolarGraphicalItem:ZBe}=WJ.actions,QBe=WJ.reducer,JBe=t=>{var e=rr(),n=M.useRef(null);return M.useLayoutEffect(()=>{n.current===null?e(qBe(t)):n.current!==t&&e(KBe({prev:n.current,next:t})),n.current=t},[e,t]),M.useLayoutEffect(()=>()=>{n.current&&(e(XBe(n.current)),n.current=null)},[e]),null},qJ=M.memo(JBe);function e6e(t){var e=rr();return M.useLayoutEffect(()=>(e(YBe(t)),()=>{e(ZBe(t))}),[e,t]),null}var t6e=["key"],n6e=["onMouseEnter","onClick","onMouseLeave"],r6e=["id"],i6e=["id"];function l9(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function Tr(t){for(var e=1;ePj(t.children,Fb),[t.children]),n=kt(r=>vBe(r,t.id,e));return n==null?null:M.createElement(HBe,{legendPayload:n})}var u6e=M.memo(t=>{var{dataKey:e,nameKey:n,sectors:r,stroke:i,strokeWidth:s,fill:a,name:o,hide:l,tooltipType:u}=t,d={dataDefinedOnItem:r.map(f=>f.tooltipPayload),positions:r.map(f=>f.tooltipPosition),settings:{stroke:i,strokeWidth:s,fill:a,dataKey:e,nameKey:n,name:qm(o,e),hide:l,type:u,color:a,unit:""}};return M.createElement(jj,{tooltipEntrySettings:d})}),d6e=(t,e)=>t>e?"start":ths(typeof e=="function"?e(t):e,n,n*.8),f6e=(t,e,n)=>{var{top:r,left:i,width:s,height:a}=e,o=mZ(s,a),l=i+hs(t.cx,s,s/2),u=r+hs(t.cy,a,a/2),d=hs(t.innerRadius,o,0),f=h6e(n,t.outerRadius,o),g=t.maxRadius||Math.sqrt(s*s+a*a)/2;return{cx:l,cy:u,innerRadius:d,outerRadius:f,maxRadius:g}},p6e=(t,e)=>{var n=Di(e-t),r=Math.min(Math.abs(e-t),360);return n*r};function m6e(t){return t&&typeof t=="object"&&"className"in t&&typeof t.className=="string"?t.className:""}var g6e=(t,e)=>{if(M.isValidElement(t))return M.cloneElement(t,e);if(typeof t=="function")return t(e);var n=Tn("recharts-pie-label-line",typeof t!="boolean"?t.className:""),{key:r}=e,i=HE(e,t6e);return M.createElement(em,ud({},i,{type:"linear",className:n}))},x6e=(t,e,n)=>{if(M.isValidElement(t))return M.cloneElement(t,e);var r=n;if(typeof t=="function"&&(r=t(e),M.isValidElement(r)))return r;var i=Tn("recharts-pie-label-text",m6e(t));return M.createElement(FE,ud({},e,{alignmentBaseline:"middle",className:i}),r)};function b6e(t){var{sectors:e,props:n,showLabels:r}=t,{label:i,labelLine:s,dataKey:a}=n;if(!r||!i||!e)return null;var o=Ks(n),l=qh(i),u=qh(s),d=typeof i=="object"&&"offsetRadius"in i&&typeof i.offsetRadius=="number"&&i.offsetRadius||20,f=e.map((g,m)=>{var x=(g.startAngle+g.endAngle)/2,y=Yr(g.cx,g.cy,g.outerRadius+d,x),v=Tr(Tr(Tr(Tr({},o),g),{},{stroke:"none"},l),{},{index:m,textAnchor:d6e(y.x,g.cx)},y),b=Tr(Tr(Tr(Tr({},o),g),{},{fill:"none",stroke:g.fill},u),{},{index:m,points:[Yr(g.cx,g.cy,g.outerRadius,x),y],key:"line"});return M.createElement(Qs,{zIndex:Zr.label,key:"label-".concat(g.startAngle,"-").concat(g.endAngle,"-").concat(g.midAngle,"-").concat(m)},M.createElement(Ir,null,s&&g6e(s,b),x6e(i,v,Qn(g,a))))});return M.createElement(Ir,{className:"recharts-pie-labels"},f)}function v6e(t){var{sectors:e,props:n,showLabels:r}=t,{label:i}=n;return typeof i=="object"&&i!=null&&"position"in i?M.createElement(Cj,{label:i}):M.createElement(b6e,{sectors:e,props:n,showLabels:r})}function y6e(t){var{sectors:e,activeShape:n,inactiveShape:r,allOtherPieProps:i,shape:s,id:a}=t,o=kt(cd),l=kt(_j),u=kt(z5e),{onMouseEnter:d,onClick:f,onMouseLeave:g}=i,m=HE(i,n6e),x=Rj(d,i.dataKey,a),y=Dj(g),v=Oj(f,i.dataKey,a);return e==null||e.length===0?null:M.createElement(M.Fragment,null,e.map((b,E)=>{if(b?.startAngle===0&&b?.endAngle===0&&e.length!==1)return null;var S=u==null||u===a,A=String(E)===o&&(l==null||i.dataKey===l)&&S,T=o?r:null,P=n&&A?n:T,C=Tr(Tr({},b),{},{stroke:b.stroke,tabIndex:-1,[GY]:E,[WY]:i.dataKey});return M.createElement(Ir,ud({key:"sector-".concat(b?.startAngle,"-").concat(b?.endAngle,"-").concat(b.midAngle,"-").concat(E),tabIndex:-1,className:"recharts-pie-sector"},xb(m,b,E),{onMouseEnter:x(b,E),onMouseLeave:y(b,E),onClick:v(b,E)}),M.createElement($J,ud({option:s??P,index:E,shapeType:"sector",isActive:A},C)))}))}function _6e(t){var e,{pieSettings:n,displayedData:r,cells:i,offset:s}=t,{cornerRadius:a,startAngle:o,endAngle:l,dataKey:u,nameKey:d,tooltipType:f}=n,g=Math.abs(n.minAngle),m=p6e(o,l),x=Math.abs(m),y=r.length<=1?0:(e=n.paddingAngle)!==null&&e!==void 0?e:0,v=r.filter(P=>Qn(P,u,0)!==0).length,b=(x>=360?v:v-1)*y,E=x-v*g-b,S=r.reduce((P,C)=>{var I=Qn(C,u,0);return P+(Ct(I)?I:0)},0),A;if(S>0){var T;A=r.map((P,C)=>{var I=Qn(P,u,0),N=Qn(P,d,C),D=f6e(n,s,P),F=(Ct(I)?I:0)/S,L,q=Tr(Tr({},P),i&&i[C]&&i[C].props);C?L=T.endAngle+Di(m)*y*(I!==0?1:0):L=o;var R=L+Di(m)*((I!==0?g:0)+F*E),V=(L+R)/2,K=(D.innerRadius+D.outerRadius)/2,W=[{name:N,value:I,payload:q,dataKey:u,type:f}],ne=Yr(D.cx,D.cy,K,V);return T=Tr(Tr(Tr(Tr({},n.presentationProps),{},{percent:F,cornerRadius:typeof a=="string"?parseFloat(a):a,name:N,tooltipPayload:W,midAngle:V,middleRadius:K,tooltipPosition:ne},q),D),{},{value:I,dataKey:u,startAngle:L,endAngle:R,payload:q,paddingAngle:Di(m)*y}),T})}return A}function w6e(t){var{showLabels:e,sectors:n,children:r}=t,i=M.useMemo(()=>!e||!n?[]:n.map(s=>({value:s.value,payload:s.payload,clockWise:!1,parentViewBox:void 0,viewBox:{cx:s.cx,cy:s.cy,innerRadius:s.innerRadius,outerRadius:s.outerRadius,startAngle:s.startAngle,endAngle:s.endAngle,clockWise:!1},fill:s.fill})),[n,e]);return M.createElement(rBe,{value:e?i:void 0},r)}function S6e(t){var{props:e,previousSectorsRef:n,id:r}=t,{sectors:i,isAnimationActive:s,animationBegin:a,animationDuration:o,animationEasing:l,activeShape:u,inactiveShape:d,onAnimationStart:f,onAnimationEnd:g}=e,m=Eb(e,"recharts-pie-"),x=n.current,[y,v]=M.useState(!1),b=M.useCallback(()=>{typeof g=="function"&&g(),v(!1)},[g]),E=M.useCallback(()=>{typeof f=="function"&&f(),v(!0)},[f]);return M.createElement(w6e,{showLabels:!y,sectors:i},M.createElement(Sb,{animationId:m,begin:a,duration:o,isActive:s,easing:l,onAnimationStart:E,onAnimationEnd:b,key:m},S=>{var A=[],T=i&&i[0],P=T?.startAngle;return i?.forEach((C,I)=>{var N=x&&x[I],D=I>0?Kh(C,"paddingAngle",0):0;if(N){var F=cr(N.endAngle-N.startAngle,C.endAngle-C.startAngle,S),L=Tr(Tr({},C),{},{startAngle:P+D,endAngle:P+F+D});A.push(L),P=L.endAngle}else{var{endAngle:q,startAngle:R}=C,V=cr(0,q-R,S),K=Tr(Tr({},C),{},{startAngle:P+D,endAngle:P+V+D});A.push(K),P=K.endAngle}}),n.current=A,M.createElement(Ir,null,M.createElement(y6e,{sectors:A,activeShape:u,inactiveShape:d,allOtherPieProps:e,shape:e.shape,id:r}))}),M.createElement(v6e,{showLabels:!y,sectors:i,props:e}),e.children)}var E6e={animationBegin:400,animationDuration:1500,animationEasing:"ease",cx:"50%",cy:"50%",dataKey:"value",endAngle:360,fill:"#808080",hide:!1,innerRadius:0,isAnimationActive:"auto",label:!1,labelLine:!0,legendType:"rect",minAngle:0,nameKey:"name",outerRadius:"80%",paddingAngle:0,rootTabIndex:0,startAngle:0,stroke:"#fff",zIndex:Zr.area};function M6e(t){var{id:e}=t,n=HE(t,r6e),{hide:r,className:i,rootTabIndex:s}=t,a=M.useMemo(()=>Pj(t.children,Fb),[t.children]),o=kt(d=>yBe(d,e,a)),l=M.useRef(null),u=Tn("recharts-pie",i);return r||o==null?(l.current=null,M.createElement(Ir,{tabIndex:s,className:u})):M.createElement(Qs,{zIndex:t.zIndex},M.createElement(u6e,{dataKey:t.dataKey,nameKey:t.nameKey,sectors:o,stroke:t.stroke,strokeWidth:t.strokeWidth,fill:t.fill,name:t.name,hide:t.hide,tooltipType:t.tooltipType}),M.createElement(Ir,{tabIndex:s,className:u},M.createElement(S6e,{props:Tr(Tr({},n),{},{sectors:o}),previousSectorsRef:l,id:e})))}function KJ(t){var e=ii(t,E6e),{id:n}=e,r=HE(e,i6e),i=Ks(r);return M.createElement(Lj,{id:n,type:"pie"},s=>M.createElement(M.Fragment,null,M.createElement(e6e,{type:"pie",id:s,data:r.data,dataKey:r.dataKey,hide:r.hide,angleAxisId:0,radiusAxisId:0,name:r.name,nameKey:r.nameKey,tooltipType:r.tooltipType,legendType:r.legendType,fill:r.fill,cx:r.cx,cy:r.cy,startAngle:r.startAngle,endAngle:r.endAngle,paddingAngle:r.paddingAngle,minAngle:r.minAngle,innerRadius:r.innerRadius,outerRadius:r.outerRadius,cornerRadius:r.cornerRadius,presentationProps:i,maxRadius:e.maxRadius}),M.createElement(c6e,ud({},r,{id:s})),M.createElement(M6e,ud({},r,{id:s}))))}KJ.displayName="Pie";var A6e=["points"];function c9(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function LN(t){for(var e=1;e{var v,b,E=LN(LN(LN({r:3},a),f),{},{index:y,cx:(v=x.x)!==null&&v!==void 0?v:void 0,cy:(b=x.y)!==null&&b!==void 0?b:void 0,dataKey:s,value:x.value,payload:x.payload,points:e});return M.createElement(R6e,{key:"dot-".concat(y),option:n,dotProps:E,className:i})}),m={};return o&&l!=null&&(m.clipPath="url(#clipPath-".concat(d?"":"dots-").concat(l,")")),M.createElement(Qs,{zIndex:u},M.createElement(Ir,tS({className:r},m),g))}function u9(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function d9(t){for(var e=1;e({top:t.top,bottom:t.bottom,left:t.left,right:t.right})),K6e=Ke([q6e,Pc,Rc],(t,e,n)=>{if(!(!t||e==null||n==null))return{x:t.left,y:t.top,width:Math.max(0,e-t.left-t.right),height:Math.max(0,n-t.top-t.bottom)}}),Ij=()=>kt(K6e),X6e=()=>kt(G5e);function h9(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function IN(t){for(var e=1;e{var{point:e,childIndex:n,mainColor:r,activeDot:i,dataKey:s,clipPath:a}=t;if(i===!1||e.x==null||e.y==null)return null;var o={index:n,dataKey:s,cx:e.x,cy:e.y,r:4,fill:r??"none",strokeWidth:2,stroke:"#fff",payload:e.payload,value:e.value},l=IN(IN(IN({},o),qh(i)),eO(i)),u;return M.isValidElement(i)?u=M.cloneElement(i,l):typeof i=="function"?u=i(l):u=M.createElement(LJ,l),M.createElement(Ir,{className:"recharts-active-dot",clipPath:a},u)};function f9(t){var{points:e,mainColor:n,activeDot:r,itemDataKey:i,clipPath:s,zIndex:a=Zr.activeDot}=t,o=kt(cd),l=X6e();if(e==null||l==null)return null;var u=e.find(d=>l.includes(d.payload));return yr(u)?null:M.createElement(Qs,{zIndex:a},M.createElement(J6e,{point:u,childIndex:Number(o),mainColor:n,dataKey:i,activeDot:r,clipPath:s}))}var e8e="Invariant failed";function t8e(t,e){throw new Error(e8e)}var n8e=["x","y"];function WP(){return WP=Object.assign?Object.assign.bind():function(t){for(var e=1;e1&&arguments[1]!==void 0?arguments[1]:0;return(r,i)=>{if(Ct(e))return e;var s=Ct(r)||yr(r);return s?e(r,i):(s||t8e(),n)}},u8e={},YJ=Zs({name:"errorBars",initialState:u8e,reducers:{addErrorBar:(t,e)=>{var{itemId:n,errorBar:r}=e.payload;t[n]||(t[n]=[]),t[n].push(r)},replaceErrorBar:(t,e)=>{var{itemId:n,prev:r,next:i}=e.payload;t[n]&&(t[n]=t[n].map(s=>s.dataKey===r.dataKey&&s.direction===r.direction?i:s))},removeErrorBar:(t,e)=>{var{itemId:n,errorBar:r}=e.payload;t[n]&&(t[n]=t[n].filter(i=>i.dataKey!==r.dataKey||i.direction!==r.direction))}}}),{addErrorBar:A7e,replaceErrorBar:T7e,removeErrorBar:C7e}=YJ.actions,d8e=YJ.reducer,h8e=["children"];function f8e(t,e){if(t==null)return{};var n,r,i=p8e(t,e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(t);for(r=0;r({x:0,y:0,value:0}),errorBarOffset:0},g8e=M.createContext(m8e);function x8e(t){var{children:e}=t,n=f8e(t,h8e);return M.createElement(g8e.Provider,{value:n},e)}function Uj(t,e){var n,r,i=kt(u=>Oc(u,t)),s=kt(u=>jc(u,e)),a=(n=i?.allowDataOverflow)!==null&&n!==void 0?n:Ci.allowDataOverflow,o=(r=s?.allowDataOverflow)!==null&&r!==void 0?r:Ni.allowDataOverflow,l=a||o;return{needClip:l,needClipX:a,needClipY:o}}function ZJ(t){var{xAxisId:e,yAxisId:n,clipPathId:r}=t,i=Ij(),{needClipX:s,needClipY:a,needClip:o}=Uj(e,n);if(!o||!i)return null;var{x:l,y:u,width:d,height:f}=i;return M.createElement("clipPath",{id:"clipPath-".concat(r)},M.createElement("rect",{x:s?l:l-d/2,y:a?u:u-f/2,width:s?d:d*2,height:a?f:f*2}))}function b8e(t,e){return t&&typeof t=="object"&&"zIndex"in t&&typeof t.zIndex=="number"&&ur(t.zIndex)?t.zIndex:e}var UN={exports:{}},FN={};var m9;function v8e(){if(m9)return FN;m9=1;var t=Dm();function e(l,u){return l===u&&(l!==0||1/l===1/u)||l!==l&&u!==u}var n=typeof Object.is=="function"?Object.is:e,r=t.useSyncExternalStore,i=t.useRef,s=t.useEffect,a=t.useMemo,o=t.useDebugValue;return FN.useSyncExternalStoreWithSelector=function(l,u,d,f,g){var m=i(null);if(m.current===null){var x={hasValue:!1,value:null};m.current=x}else x=m.current;m=a(function(){function v(T){if(!b){if(b=!0,E=T,T=f(T),g!==void 0&&x.hasValue){var P=x.value;if(g(P,T))return S=P}return S=T}if(P=S,n(E,T))return P;var C=f(T);return g!==void 0&&g(P,C)?(E=T,P):(E=T,S=C)}var b=!1,E,S,A=d===void 0?null:d;return[function(){return v(u())},A===null?void 0:function(){return v(A())}]},[u,d,f,g]);var y=r(l,m[0],m[1]);return s(function(){x.hasValue=!0,x.value=y},[y]),o(y),y},FN}var g9;function y8e(){return g9||(g9=1,UN.exports=v8e()),UN.exports}y8e();function _8e(t){t()}function w8e(){let t=null,e=null;return{clear(){t=null,e=null},notify(){_8e(()=>{let n=t;for(;n;)n.callback(),n=n.next})},get(){const n=[];let r=t;for(;r;)n.push(r),r=r.next;return n},subscribe(n){let r=!0;const i=e={callback:n,next:null,prev:e};return i.prev?i.prev.next=i:t=i,function(){!r||t===null||(r=!1,i.next?i.next.prev=i.prev:e=i.prev,i.prev?i.prev.next=i.next:t=i.next)}}}}var x9={notify(){},get:()=>[]};function S8e(t,e){let n,r=x9,i=0,s=!1;function a(y){d();const v=r.subscribe(y);let b=!1;return()=>{b||(b=!0,v(),f())}}function o(){r.notify()}function l(){x.onStateChange&&x.onStateChange()}function u(){return s}function d(){i++,n||(n=t.subscribe(l),r=w8e())}function f(){i--,n&&i===0&&(n(),n=void 0,r.clear(),r=x9)}function g(){s||(s=!0,d())}function m(){s&&(s=!1,f())}const x={addNestedSub:a,notifyNestedSubs:o,handleChangeWrapper:l,isSubscribed:u,trySubscribe:g,tryUnsubscribe:m,getListeners:()=>r};return x}var E8e=()=>typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",M8e=E8e(),A8e=()=>typeof navigator<"u"&&navigator.product==="ReactNative",T8e=A8e(),C8e=()=>M8e||T8e?M.useLayoutEffect:M.useEffect,N8e=C8e();function b9(t,e){return t===e?t!==0||e!==0||1/t===1/e:t!==t&&e!==e}function k8e(t,e){if(b9(t,e))return!0;if(typeof t!="object"||t===null||typeof e!="object"||e===null)return!1;const n=Object.keys(t),r=Object.keys(e);if(n.length!==r.length)return!1;for(let i=0;i{const l=S8e(i);return{store:i,subscription:l,getServerState:r?()=>r:void 0}},[i,r]),a=M.useMemo(()=>i.getState(),[i]);N8e(()=>{const{subscription:l}=s;return l.onStateChange=l.notifyNestedSubs,l.trySubscribe(),a!==i.getState()&&l.notifyNestedSubs(),()=>{l.tryUnsubscribe(),l.onStateChange=void 0}},[s,a]);const o=n||O8e;return M.createElement(o.Provider,{value:s},e)}var L8e=j8e,I8e=new Set(["axisLine","tickLine","activeBar","activeDot","activeLabel","activeShape","allowEscapeViewBox","background","cursor","dot","label","line","margin","padding","position","shape","style","tick","wrapperStyle"]);function U8e(t,e){return t==null&&e==null?!0:typeof t=="number"&&typeof e=="number"?t===e||t!==t&&e!==e:t===e}function $E(t,e){var n=new Set([...Object.keys(t),...Object.keys(e)]);for(var r of n)if(I8e.has(r)){if(t[r]==null&&e[r]==null)continue;if(!k8e(t[r],e[r]))return!1}else if(!U8e(t[r],e[r]))return!1;return!0}var F8e=["onMouseEnter","onMouseLeave","onClick"],z8e=["value","background","tooltipPosition"],B8e=["id"],H8e=["onMouseEnter","onClick","onMouseLeave"];function Cc(){return Cc=Object.assign?Object.assign.bind():function(t){for(var e=1;e{var{dataKey:e,name:n,fill:r,legendType:i,hide:s}=t;return[{inactive:s,dataKey:e,type:i,color:r,value:qm(n,e),payload:t}]},K8e=M.memo(t=>{var{dataKey:e,stroke:n,strokeWidth:r,fill:i,name:s,hide:a,unit:o,tooltipType:l}=t,u={dataDefinedOnItem:void 0,positions:void 0,settings:{stroke:n,strokeWidth:r,fill:i,dataKey:e,nameKey:void 0,name:qm(s,e),hide:a,type:l,color:i,unit:o}};return M.createElement(jj,{tooltipEntrySettings:u})});function X8e(t){var e=kt(cd),{data:n,dataKey:r,background:i,allOtherBarProps:s}=t,{onMouseEnter:a,onMouseLeave:o,onClick:l}=s,u=rS(s,F8e),d=Rj(a,r),f=Dj(o),g=Oj(l,r);if(!i||n==null)return null;var m=qh(i);return M.createElement(Qs,{zIndex:b8e(i,Zr.barBackground)},n.map((x,y)=>{var{value:v,background:b,tooltipPosition:E}=x,S=rS(x,z8e);if(!b)return null;var A=d(x,y),T=f(x,y),P=g(x,y),C=_s(_s(_s(_s(_s({option:i,isActive:String(y)===e},S),{},{fill:"#eee"},b),m),xb(u,x,y)),{},{onMouseEnter:A,onMouseLeave:T,onClick:P,dataKey:r,index:y,className:"recharts-bar-background-rectangle"});return M.createElement(nS,Cc({key:"background-bar-".concat(y)},C))}))}function Y8e(t){var{showLabels:e,children:n,rects:r}=t,i=r?.map(s=>{var a={x:s.x,y:s.y,width:s.width,lowerWidth:s.width,upperWidth:s.width,height:s.height};return _s(_s({},a),{},{value:s.value,payload:s.payload,parentViewBox:s.parentViewBox,viewBox:a,fill:s.fill})});return M.createElement(OJ,{value:e?i:void 0},n)}function Z8e(t){var{shape:e,activeBar:n,baseProps:r,entry:i,index:s,dataKey:a}=t,o=kt(cd),l=kt(_j),u=n&&String(s)===o&&(l==null||a===l),d=u?n:e;return u?M.createElement(Qs,{zIndex:Zr.activeBar},M.createElement(nS,Cc({},r,{name:String(r.name)},i,{isActive:u,option:d,index:s,dataKey:a}))):M.createElement(nS,Cc({},r,{name:String(r.name)},i,{isActive:u,option:d,index:s,dataKey:a}))}function Q8e(t){var{shape:e,baseProps:n,entry:r,index:i,dataKey:s}=t;return M.createElement(nS,Cc({},n,{name:String(n.name)},r,{isActive:!1,option:e,index:i,dataKey:s}))}function J8e(t){var e,{data:n,props:r}=t,i=(e=Ks(r))!==null&&e!==void 0?e:{},{id:s}=i,a=rS(i,B8e),{shape:o,dataKey:l,activeBar:u}=r,{onMouseEnter:d,onClick:f,onMouseLeave:g}=r,m=rS(r,H8e),x=Rj(d,l),y=Dj(g),v=Oj(f,l);return n?M.createElement(M.Fragment,null,n.map((b,E)=>M.createElement(Ir,Cc({key:"rectangle-".concat(b?.x,"-").concat(b?.y,"-").concat(b?.value,"-").concat(E),className:"recharts-bar-rectangle"},xb(m,b,E),{onMouseEnter:x(b,E),onMouseLeave:y(b,E),onClick:v(b,E)}),u?M.createElement(Z8e,{shape:o,activeBar:u,baseProps:a,entry:b,index:E,dataKey:l}):M.createElement(Q8e,{shape:o,baseProps:a,entry:b,index:E,dataKey:l})))):null}function eHe(t){var{props:e,previousRectanglesRef:n}=t,{data:r,layout:i,isAnimationActive:s,animationBegin:a,animationDuration:o,animationEasing:l,onAnimationEnd:u,onAnimationStart:d}=e,f=n.current,g=Eb(e,"recharts-bar-"),[m,x]=M.useState(!1),y=!m,v=M.useCallback(()=>{typeof u=="function"&&u(),x(!1)},[u]),b=M.useCallback(()=>{typeof d=="function"&&d(),x(!0)},[d]);return M.createElement(Y8e,{showLabels:y,rects:r},M.createElement(Sb,{animationId:g,begin:a,duration:o,isActive:s,easing:l,onAnimationEnd:v,onAnimationStart:b,key:g},E=>{var S=E===1?r:r?.map((A,T)=>{var P=f&&f[T];if(P)return _s(_s({},A),{},{x:cr(P.x,A.x,E),y:cr(P.y,A.y,E),width:cr(P.width,A.width,E),height:cr(P.height,A.height,E)});if(i==="horizontal"){var C=cr(0,A.height,E),I=cr(A.stackedBarStart,A.y,E);return _s(_s({},A),{},{y:I,height:C})}var N=cr(0,A.width,E),D=cr(A.stackedBarStart,A.x,E);return _s(_s({},A),{},{width:N,x:D})});return E>0&&(n.current=S??null),S==null?null:M.createElement(Ir,null,M.createElement(J8e,{props:e,data:S}))}),M.createElement(Cj,{label:e.label}),e.children)}function tHe(t){var e=M.useRef(null);return M.createElement(eHe,{previousRectanglesRef:e,props:t})}var QJ=0,nHe=(t,e)=>{var n=Array.isArray(t.value)?t.value[1]:t.value;return{x:t.x,y:t.y,value:n,errorVal:Qn(t,e)}};class rHe extends M.PureComponent{render(){var{hide:e,data:n,dataKey:r,className:i,xAxisId:s,yAxisId:a,needClip:o,background:l,id:u}=this.props;if(e||n==null)return null;var d=Tn("recharts-bar",i),f=u;return M.createElement(Ir,{className:d,id:u},o&&M.createElement("defs",null,M.createElement(ZJ,{clipPathId:f,xAxisId:s,yAxisId:a})),M.createElement(Ir,{className:"recharts-bar-rectangles",clipPath:o?"url(#clipPath-".concat(f,")"):void 0},M.createElement(X8e,{data:n,dataKey:r,background:l,allOtherBarProps:this.props}),M.createElement(tHe,this.props)))}}var iHe={activeBar:!1,animationBegin:0,animationDuration:400,animationEasing:"ease",background:!1,hide:!1,isAnimationActive:"auto",label:!1,legendType:"rect",minPointSize:QJ,xAxisId:0,yAxisId:0,zIndex:Zr.bar};function sHe(t){var{xAxisId:e,yAxisId:n,hide:r,legendType:i,minPointSize:s,activeBar:a,animationBegin:o,animationDuration:l,animationEasing:u,isAnimationActive:d}=t,{needClip:f}=Uj(e,n),g=Km(),m=ms(),x=Pj(t.children,Fb),y=kt(E=>DHe(E,e,n,m,t.id,x));if(g!=="vertical"&&g!=="horizontal")return null;var v,b=y?.[0];return b==null||b.height==null||b.width==null?v=0:v=g==="vertical"?b.height/2:b.width/2,M.createElement(x8e,{xAxisId:e,yAxisId:n,data:y,dataPointFormatter:nHe,errorBarOffset:v},M.createElement(rHe,Cc({},t,{layout:g,needClip:f,data:y,xAxisId:e,yAxisId:n,hide:r,legendType:i,minPointSize:s,activeBar:a,animationBegin:o,animationDuration:l,animationEasing:u,isAnimationActive:d})))}function aHe(t){var{layout:e,barSettings:{dataKey:n,minPointSize:r},pos:i,bandSize:s,xAxis:a,yAxis:o,xAxisTicks:l,yAxisTicks:u,stackedData:d,displayedData:f,offset:g,cells:m,parentViewBox:x,dataStartIndex:y}=t,v=e==="horizontal"?o:a,b=d?v.scale.domain():null,E=MDe({numericAxis:v}),S=v.scale(E);return f.map((A,T)=>{var P,C,I,N,D,F;d?P=yDe(d[T+y],b):(P=Qn(A,n),Array.isArray(P)||(P=[E,P]));var L=c8e(r,QJ)(P[1],T);if(e==="horizontal"){var q,[R,V]=[o.scale(P[0]),o.scale(P[1])];C=jH({axis:a,ticks:l,bandSize:s,offset:i.offset,entry:A,index:T}),I=(q=V??R)!==null&&q!==void 0?q:void 0,N=i.size;var K=R-V;if(D=io(K)?0:K,F={x:C,y:g.top,width:N,height:g.height},Math.abs(L)>0&&Math.abs(D)0&&Math.abs(N)M.createElement(M.Fragment,null,M.createElement(VJ,{legendPayload:q8e(e)}),M.createElement(K8e,{dataKey:e.dataKey,stroke:e.stroke,strokeWidth:e.strokeWidth,fill:e.fill,name:e.name,hide:e.hide,unit:e.unit,tooltipType:e.tooltipType}),M.createElement(qJ,{type:"bar",id:r,data:void 0,xAxisId:e.xAxisId,yAxisId:e.yAxisId,zAxisId:0,dataKey:e.dataKey,stackId:$Y(e.stackId),hide:e.hide,barSize:e.barSize,minPointSize:e.minPointSize,maxBarSize:e.maxBarSize,isPanorama:n}),M.createElement(Qs,{zIndex:e.zIndex},M.createElement(sHe,Cc({},e,{id:r})))))}var JJ=M.memo(oHe,$E);JJ.displayName="Bar";function y9(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function C_(t){for(var e=1;ee,hHe=(t,e,n)=>n,fHe=(t,e,n,r)=>r,pHe=(t,e,n,r,i)=>i,zb=Ke([OE,pHe],(t,e)=>t.filter(n=>n.type==="bar").find(n=>n.id===e)),mHe=Ke([zb],t=>t?.maxBarSize),gHe=(t,e,n,r,i,s)=>s,_9=(t,e,n)=>{var r=n??t;if(!yr(r))return hs(r,e,0)},xHe=Ke([wn,OE,dHe,hHe,fHe],(t,e,n,r,i)=>e.filter(s=>t==="horizontal"?s.xAxisId===n:s.yAxisId===r).filter(s=>s.isPanorama===i).filter(s=>s.hide===!1).filter(s=>s.type==="bar")),bHe=(t,e,n,r)=>{var i=wn(t);return i==="horizontal"?Z0(t,"yAxis",n,r):Z0(t,"xAxis",e,r)},vHe=(t,e,n)=>{var r=wn(t);return r==="horizontal"?pV(t,"xAxis",e):pV(t,"yAxis",n)},yHe=(t,e,n)=>{var r={},i=t.filter(PE),s=t.filter(u=>u.stackId==null),a=i.reduce((u,d)=>(u[d.stackId]||(u[d.stackId]=[]),u[d.stackId].push(d),u),r),o=Object.entries(a).map(u=>{var[d,f]=u,g=f.map(x=>x.dataKey),m=_9(e,n,f[0].barSize);return{stackId:d,dataKeys:g,barSize:m}}),l=s.map(u=>{var d=[u.dataKey].filter(g=>g!=null),f=_9(e,n,u.barSize);return{stackId:void 0,dataKeys:d,barSize:f}});return[...o,...l]},_He=Ke([xHe,H4e,vHe],yHe),wHe=(t,e,n,r,i)=>{var s,a,o=zb(t,e,n,r,i);if(o!=null){var l=wn(t),u=pQ(t),{maxBarSize:d}=o,f=yr(d)?u:d,g,m;return l==="horizontal"?(g=ld(t,"xAxis",e,r),m=od(t,"xAxis",e,r)):(g=ld(t,"yAxis",n,r),m=od(t,"yAxis",n,r)),(s=(a=Tm(g,m,!0))!==null&&a!==void 0?a:f)!==null&&s!==void 0?s:0}},eee=(t,e,n,r)=>{var i=wn(t),s,a;return i==="horizontal"?(s=ld(t,"xAxis",e,r),a=od(t,"xAxis",e,r)):(s=ld(t,"yAxis",n,r),a=od(t,"yAxis",n,r)),Tm(s,a)};function SHe(t,e,n,r,i){var s=r.length;if(!(s<1)){var a=hs(t,n,0,!0),o,l=[];if(ur(r[0].barSize)){var u=!1,d=n/s,f=r.reduce((b,E)=>b+(E.barSize||0),0);f+=(s-1)*a,f>=n&&(f-=(s-1)*a,a=0),f>=n&&d>0&&(u=!0,d*=.9,f=s*d);var g=(n-f)/2>>0,m={offset:g-a,size:0};o=r.reduce((b,E)=>{var S,A={stackId:E.stackId,dataKeys:E.dataKeys,position:{offset:m.offset+m.size+a,size:u?d:(S=E.barSize)!==null&&S!==void 0?S:0}},T=[...b,A];return m=T[T.length-1].position,T},l)}else{var x=hs(e,n,0,!0);n-2*x-(s-1)*a<=0&&(a=0);var y=(n-2*x-(s-1)*a)/s;y>1&&(y>>=0);var v=ur(i)?Math.min(y,i):y;o=r.reduce((b,E,S)=>[...b,{stackId:E.stackId,dataKeys:E.dataKeys,position:{offset:x+(y+a)*S+(y-v)/2,size:v}}],l)}return o}}var EHe=(t,e,n,r,i,s,a)=>{var o=yr(a)?e:a,l=SHe(n,r,i!==s?i:s,t,o);return i!==s&&l!=null&&(l=l.map(u=>C_(C_({},u),{},{position:C_(C_({},u.position),{},{offset:u.position.offset-i/2})}))),l},MHe=Ke([_He,pQ,B4e,mQ,wHe,eee,mHe],EHe),AHe=(t,e,n,r)=>ld(t,"xAxis",e,r),THe=(t,e,n,r)=>ld(t,"yAxis",n,r),CHe=(t,e,n,r)=>od(t,"xAxis",e,r),NHe=(t,e,n,r)=>od(t,"yAxis",n,r),kHe=Ke([MHe,zb],(t,e)=>{if(!(t==null||e==null)){var n=t.find(r=>r.stackId===e.stackId&&e.dataKey!=null&&r.dataKeys.includes(e.dataKey));if(n!=null)return n.position}}),PHe=(t,e)=>{var n=kE(e);if(!(!t||n==null||e==null)){var{stackId:r}=e;if(r!=null){var i=t[r];if(i){var{stackedData:s}=i;if(s)return s.find(a=>a.key===n)}}}},RHe=Ke([bHe,zb],PHe),DHe=Ke([xi,dO,AHe,THe,CHe,NHe,kHe,wn,TE,eee,RHe,zb,gHe],(t,e,n,r,i,s,a,o,l,u,d,f,g)=>{var{chartData:m,dataStartIndex:x,dataEndIndex:y}=l;if(!(f==null||a==null||e==null||o!=="horizontal"&&o!=="vertical"||n==null||r==null||i==null||s==null||u==null)){var{data:v}=f,b;if(v!=null&&v.length>0?b=v:b=m?.slice(x,y+1),b!=null)return aHe({layout:o,barSettings:f,pos:a,parentViewBox:e,bandSize:u,xAxis:n,yAxis:r,xAxisTicks:i,yAxisTicks:s,stackedData:d,displayedData:b,offset:t,cells:g,dataStartIndex:x})}}),tee=t=>{var{chartData:e}=t,n=rr(),r=ms();return M.useEffect(()=>r?()=>{}:(n(TV(e)),()=>{n(TV(void 0))}),[e,n,r]),null},w9={x:0,y:0,width:0,height:0,padding:{top:0,right:0,bottom:0,left:0}},nee=Zs({name:"brush",initialState:w9,reducers:{setBrushSettings(t,e){return e.payload==null?w9:e.payload}}}),{setBrushSettings:N7e}=nee.actions,OHe=nee.reducer;function jHe(t,e,n){return(e=LHe(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function LHe(t){var e=IHe(t,"string");return typeof e=="symbol"?e:e+""}function IHe(t,e){if(typeof t!="object"||!t)return t;var n=t[Symbol.toPrimitive];if(n!==void 0){var r=n.call(t,e);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(t)}class Fj{static create(e){return new Fj(e)}constructor(e){this.scale=e}get domain(){return this.scale.domain}get range(){return this.scale.range}get rangeMin(){return this.range()[0]}get rangeMax(){return this.range()[1]}get bandwidth(){return this.scale.bandwidth}apply(e){var{bandAware:n,position:r}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(e!==void 0){if(r)switch(r){case"start":return this.scale(e);case"middle":{var i=this.bandwidth?this.bandwidth()/2:0;return this.scale(e)+i}case"end":{var s=this.bandwidth?this.bandwidth():0;return this.scale(e)+s}default:return this.scale(e)}if(n){var a=this.bandwidth?this.bandwidth()/2:0;return this.scale(e)+a}return this.scale(e)}}isInRange(e){var n=this.range(),r=n[0],i=n[n.length-1];return r<=i?e>=r&&e<=i:e>=i&&e<=r}}jHe(Fj,"EPS",1e-4);function UHe(t){return(t%180+180)%180}var FHe=function(e){var{width:n,height:r}=e,i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,s=UHe(i),a=s*Math.PI/180,o=Math.atan(r/n),l=a>o&&a{t.dots.push(e.payload)},removeDot:(t,e)=>{var n=Ro(t).dots.findIndex(r=>r===e.payload);n!==-1&&t.dots.splice(n,1)},addArea:(t,e)=>{t.areas.push(e.payload)},removeArea:(t,e)=>{var n=Ro(t).areas.findIndex(r=>r===e.payload);n!==-1&&t.areas.splice(n,1)},addLine:(t,e)=>{t.lines.push(e.payload)},removeLine:(t,e)=>{var n=Ro(t).lines.findIndex(r=>r===e.payload);n!==-1&&t.lines.splice(n,1)}}}),{addDot:k7e,removeDot:P7e,addArea:R7e,removeArea:D7e,addLine:O7e,removeLine:j7e}=ree.actions,BHe=ree.reducer,HHe=M.createContext(void 0),$He=t=>{var{children:e}=t,[n]=M.useState("".concat(U0("recharts"),"-clip")),r=Ij();if(r==null)return null;var{x:i,y:s,width:a,height:o}=r;return M.createElement(HHe.Provider,{value:n},M.createElement("defs",null,M.createElement("clipPath",{id:n},M.createElement("rect",{x:i,y:s,height:o,width:a}))),e)};function iee(t,e){if(e<1)return[];if(e===1)return t;for(var n=[],r=0;rt*i)return!1;var s=n();return t*(e-t*s/2-r)>=0&&t*(e+t*s/2-i)<=0}function WHe(t,e){return iee(t,e+1)}function qHe(t,e,n,r,i){for(var s=(r||[]).slice(),{start:a,end:o}=e,l=0,u=1,d=a,f=function(){var x=r?.[l];if(x===void 0)return{v:iee(r,u)};var y=l,v,b=()=>(v===void 0&&(v=n(x,y)),v),E=x.coordinate,S=l===0||iS(t,E,b,d,o);S||(l=0,d=a,u+=1),S&&(d=E+t*(b()/2+i),l+=u)},g;u<=s.length;)if(g=f(),g)return g.v;return[]}function S9(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function ls(t){for(var e=1;e(x===void 0&&(x=n(m,g)),x);if(g===a-1){var v=t*(m.coordinate+t*y()/2-l);s[g]=m=ls(ls({},m),{},{tickCoord:v>0?m.coordinate-v*t:m.coordinate})}else s[g]=m=ls(ls({},m),{},{tickCoord:m.coordinate});if(m.tickCoord!=null){var b=iS(t,m.tickCoord,y,o,l);b&&(l=m.tickCoord-t*(y()/2+i),s[g]=ls(ls({},m),{},{isShow:!0}))}},d=a-1;d>=0;d--)u(d);return s}function QHe(t,e,n,r,i,s){var a=(r||[]).slice(),o=a.length,{start:l,end:u}=e;if(s){var d=r[o-1],f=n(d,o-1),g=t*(d.coordinate+t*f/2-u);if(a[o-1]=d=ls(ls({},d),{},{tickCoord:g>0?d.coordinate-g*t:d.coordinate}),d.tickCoord!=null){var m=iS(t,d.tickCoord,()=>f,l,u);m&&(u=d.tickCoord-t*(f/2+i),a[o-1]=ls(ls({},d),{},{isShow:!0}))}}for(var x=s?o-1:o,y=function(E){var S=a[E],A,T=()=>(A===void 0&&(A=n(S,E)),A);if(E===0){var P=t*(S.coordinate-t*T()/2-l);a[E]=S=ls(ls({},S),{},{tickCoord:P<0?S.coordinate-P*t:S.coordinate})}else a[E]=S=ls(ls({},S),{},{tickCoord:S.coordinate});if(S.tickCoord!=null){var C=iS(t,S.tickCoord,T,l,u);C&&(l=S.tickCoord+t*(T()/2+i),a[E]=ls(ls({},S),{},{isShow:!0}))}},v=0;v{var T=typeof u=="function"?u(S.value,A):S.value;return x==="width"?VHe(e0(T,{fontSize:e,letterSpacing:n}),y,f):e0(T,{fontSize:e,letterSpacing:n})[x]},b=i.length>=2?Di(i[1].coordinate-i[0].coordinate):1,E=GHe(s,b,x);return l==="equidistantPreserveStart"?qHe(b,E,v,i,a):(l==="preserveStart"||l==="preserveStartEnd"?m=QHe(b,E,v,i,a,l==="preserveStartEnd"):m=ZHe(b,E,v,i,a),m.filter(S=>S.isShow))}var JHe=t=>{var{ticks:e,label:n,labelGapWithTick:r=5,tickSize:i=0,tickMargin:s=0}=t,a=0;if(e){Array.from(e).forEach(d=>{if(d){var f=d.getBoundingClientRect();f.width>a&&(a=f.width)}});var o=n?n.getBoundingClientRect().width:0,l=i+s,u=a+l+o+(n?r:0);return Math.round(u)}return 0},e$e=["axisLine","width","height","className","hide","ticks","axisType"];function t$e(t,e){if(t==null)return{};var n,r,i=n$e(t,e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(t);for(r=0;r{var{ticks:n=[],tick:r,tickLine:i,stroke:s,tickFormatter:a,unit:o,padding:l,tickTextProps:u,orientation:d,mirror:f,x:g,y:m,width:x,height:y,tickSize:v,tickMargin:b,fontSize:E,letterSpacing:S,getTicksConfig:A,events:T,axisType:P}=t,C=zj(Gr(Gr({},A),{},{ticks:n}),E,S),I=l$e(d,f),N=c$e(d,f),D=Ks(A),F=qh(r),L={};typeof i=="object"&&(L=i);var q=Gr(Gr({},D),{},{fill:"none"},L),R=C.map(W=>Gr({entry:W},o$e(W,g,m,x,y,d,v,f,b))),V=R.map(W=>{var{entry:ne,line:Y}=W;return M.createElement(Ir,{className:"recharts-cartesian-axis-tick",key:"tick-".concat(ne.value,"-").concat(ne.coordinate,"-").concat(ne.tickCoord)},i&&M.createElement("line",Qh({},q,Y,{className:Tn("recharts-cartesian-axis-tick-line",Kh(i,"className"))})))}),K=R.map((W,ne)=>{var{entry:Y,tick:Z}=W,U=Gr(Gr(Gr(Gr({textAnchor:I,verticalAnchor:N},D),{},{stroke:"none",fill:s},F),Z),{},{index:ne,payload:Y,visibleTicksCount:C.length,tickFormatter:a,padding:l},u);return M.createElement(Ir,Qh({className:"recharts-cartesian-axis-tick-label",key:"tick-label-".concat(Y.value,"-").concat(Y.coordinate,"-").concat(Y.tickCoord)},xb(T,Y,ne)),r&&M.createElement(u$e,{option:r,tickProps:U,value:"".concat(typeof a=="function"?a(Y.value,ne):Y.value).concat(o||"")}))});return M.createElement("g",{className:"recharts-cartesian-axis-ticks recharts-".concat(P,"-ticks")},K.length>0&&M.createElement(Qs,{zIndex:Zr.label},M.createElement("g",{className:"recharts-cartesian-axis-tick-labels recharts-".concat(P,"-tick-labels"),ref:e},K)),V.length>0&&M.createElement("g",{className:"recharts-cartesian-axis-tick-lines recharts-".concat(P,"-tick-lines")},V))}),h$e=M.forwardRef((t,e)=>{var{axisLine:n,width:r,height:i,className:s,hide:a,ticks:o,axisType:l}=t,u=t$e(t,e$e),[d,f]=M.useState(""),[g,m]=M.useState(""),x=M.useRef(null);M.useImperativeHandle(e,()=>({getCalculatedWidth:()=>{var v;return JHe({ticks:x.current,label:(v=t.labelRef)===null||v===void 0?void 0:v.current,labelGapWithTick:5,tickSize:t.tickSize,tickMargin:t.tickMargin})}}));var y=M.useCallback(v=>{if(v){var b=v.getElementsByClassName("recharts-cartesian-axis-tick-value");x.current=b;var E=b[0];if(E){var S=window.getComputedStyle(E),A=S.fontSize,T=S.letterSpacing;(A!==d||T!==g)&&(f(A),m(T))}}},[d,g]);return a||r!=null&&r<=0||i!=null&&i<=0?null:M.createElement(Qs,{zIndex:t.zIndex},M.createElement(Ir,{className:Tn("recharts-cartesian-axis",s)},M.createElement(a$e,{x:t.x,y:t.y,width:r,height:i,orientation:t.orientation,mirror:t.mirror,axisLine:n,otherSvgProps:Ks(t)}),M.createElement(d$e,{ref:y,axisType:l,events:u,fontSize:d,getTicksConfig:t,height:t.height,letterSpacing:g,mirror:t.mirror,orientation:t.orientation,padding:t.padding,stroke:t.stroke,tick:t.tick,tickFormatter:t.tickFormatter,tickLine:t.tickLine,tickMargin:t.tickMargin,tickSize:t.tickSize,tickTextProps:t.tickTextProps,ticks:o,unit:t.unit,width:t.width,x:t.x,y:t.y}),M.createElement(Lze,{x:t.x,y:t.y,width:t.width,height:t.height,lowerWidth:t.width,upperWidth:t.width},M.createElement(Wze,{label:t.label,labelRef:t.labelRef}),t.children)))}),Bj=M.forwardRef((t,e)=>{var n=ii(t,bc);return M.createElement(h$e,Qh({},n,{ref:e}))});Bj.displayName="CartesianAxis";var f$e=["x1","y1","x2","y2","key"],p$e=["offset"],m$e=["xAxisId","yAxisId"],g$e=["xAxisId","yAxisId"];function M9(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function cs(t){for(var e=1;e{var{fill:e}=t;if(!e||e==="none")return null;var{fillOpacity:n,x:r,y:i,width:s,height:a,ry:o}=t;return M.createElement("rect",{x:r,y:i,ry:o,width:s,height:a,stroke:"none",fill:e,fillOpacity:n,className:"recharts-cartesian-grid-bg"})};function see(t){var{option:e,lineItemProps:n}=t,r;if(M.isValidElement(e))r=M.cloneElement(e,n);else if(typeof e=="function")r=e(n);else{var i,{x1:s,y1:a,x2:o,y2:l,key:u}=n,d=sS(n,f$e),f=(i=Ks(d))!==null&&i!==void 0?i:{},{offset:g}=f,m=sS(f,p$e);r=M.createElement("line",hh({},m,{x1:s,y1:a,x2:o,y2:l,fill:"none",key:u}))}return r}function w$e(t){var{x:e,width:n,horizontal:r=!0,horizontalPoints:i}=t;if(!r||!i||!i.length)return null;var{xAxisId:s,yAxisId:a}=t,o=sS(t,m$e),l=i.map((u,d)=>{var f=cs(cs({},o),{},{x1:e,y1:u,x2:e+n,y2:u,key:"line-".concat(d),index:d});return M.createElement(see,{key:"line-".concat(d),option:r,lineItemProps:f})});return M.createElement("g",{className:"recharts-cartesian-grid-horizontal"},l)}function S$e(t){var{y:e,height:n,vertical:r=!0,verticalPoints:i}=t;if(!r||!i||!i.length)return null;var{xAxisId:s,yAxisId:a}=t,o=sS(t,g$e),l=i.map((u,d)=>{var f=cs(cs({},o),{},{x1:u,y1:e,x2:u,y2:e+n,key:"line-".concat(d),index:d});return M.createElement(see,{option:r,lineItemProps:f,key:"line-".concat(d)})});return M.createElement("g",{className:"recharts-cartesian-grid-vertical"},l)}function E$e(t){var{horizontalFill:e,fillOpacity:n,x:r,y:i,width:s,height:a,horizontalPoints:o,horizontal:l=!0}=t;if(!l||!e||!e.length||o==null)return null;var u=o.map(f=>Math.round(f+i-i)).sort((f,g)=>f-g);i!==u[0]&&u.unshift(0);var d=u.map((f,g)=>{var m=!u[g+1],x=m?i+a-f:u[g+1]-f;if(x<=0)return null;var y=g%e.length;return M.createElement("rect",{key:"react-".concat(g),y:f,x:r,height:x,width:s,stroke:"none",fill:e[y],fillOpacity:n,className:"recharts-cartesian-grid-bg"})});return M.createElement("g",{className:"recharts-cartesian-gridstripes-horizontal"},d)}function M$e(t){var{vertical:e=!0,verticalFill:n,fillOpacity:r,x:i,y:s,width:a,height:o,verticalPoints:l}=t;if(!e||!n||!n.length)return null;var u=l.map(f=>Math.round(f+i-i)).sort((f,g)=>f-g);i!==u[0]&&u.unshift(0);var d=u.map((f,g)=>{var m=!u[g+1],x=m?i+a-f:u[g+1]-f;if(x<=0)return null;var y=g%n.length;return M.createElement("rect",{key:"react-".concat(g),x:f,y:s,width:x,height:o,stroke:"none",fill:n[y],fillOpacity:r,className:"recharts-cartesian-grid-bg"})});return M.createElement("g",{className:"recharts-cartesian-gridstripes-vertical"},d)}var A$e=(t,e)=>{var{xAxis:n,width:r,height:i,offset:s}=t;return BY(zj(cs(cs(cs({},bc),n),{},{ticks:HY(n),viewBox:{x:0,y:0,width:r,height:i}})),s.left,s.left+s.width,e)},T$e=(t,e)=>{var{yAxis:n,width:r,height:i,offset:s}=t;return BY(zj(cs(cs(cs({},bc),n),{},{ticks:HY(n),viewBox:{x:0,y:0,width:r,height:i}})),s.top,s.top+s.height,e)},C$e={horizontal:!0,vertical:!0,horizontalPoints:[],verticalPoints:[],stroke:"#ccc",fill:"none",verticalFill:[],horizontalFill:[],xAxisId:0,yAxisId:0,syncWithTicks:!1,zIndex:Zr.grid};function qP(t){var e=fO(),n=pO(),r=ZY(),i=cs(cs({},ii(t,C$e)),{},{x:Ct(t.x)?t.x:r.left,y:Ct(t.y)?t.y:r.top,width:Ct(t.width)?t.width:r.width,height:Ct(t.height)?t.height:r.height}),{xAxisId:s,yAxisId:a,x:o,y:l,width:u,height:d,syncWithTicks:f,horizontalValues:g,verticalValues:m}=i,x=ms(),y=kt(N=>mV(N,"xAxis",s,x)),v=kt(N=>mV(N,"yAxis",a,x));if(!pl(u)||!pl(d)||!Ct(o)||!Ct(l))return null;var b=i.verticalCoordinatesGenerator||A$e,E=i.horizontalCoordinatesGenerator||T$e,{horizontalPoints:S,verticalPoints:A}=i;if((!S||!S.length)&&typeof E=="function"){var T=g&&g.length,P=E({yAxis:v?cs(cs({},v),{},{ticks:T?g:v.ticks}):void 0,width:e??u,height:n??d,offset:r},T?!0:f);kw(Array.isArray(P),"horizontalCoordinatesGenerator should return Array but instead it returned [".concat(typeof P,"]")),Array.isArray(P)&&(S=P)}if((!A||!A.length)&&typeof b=="function"){var C=m&&m.length,I=b({xAxis:y?cs(cs({},y),{},{ticks:C?m:y.ticks}):void 0,width:e??u,height:n??d,offset:r},C?!0:f);kw(Array.isArray(I),"verticalCoordinatesGenerator should return Array but instead it returned [".concat(typeof I,"]")),Array.isArray(I)&&(A=I)}return M.createElement(Qs,{zIndex:i.zIndex},M.createElement("g",{className:"recharts-cartesian-grid"},M.createElement(_$e,{fill:i.fill,fillOpacity:i.fillOpacity,x:i.x,y:i.y,width:i.width,height:i.height,ry:i.ry}),M.createElement(E$e,hh({},i,{horizontalPoints:S})),M.createElement(M$e,hh({},i,{verticalPoints:A})),M.createElement(w$e,hh({},i,{offset:r,horizontalPoints:S,xAxis:y,yAxis:v})),M.createElement(S$e,hh({},i,{offset:r,verticalPoints:A,xAxis:y,yAxis:v}))))}qP.displayName="CartesianGrid";function N$e(t){var e=qh(t),n=3,r=2;if(e!=null){var{r:i,strokeWidth:s}=e,a=Number(i),o=Number(s);return(Number.isNaN(a)||a<0)&&(a=n),(Number.isNaN(o)||o<0)&&(o=r),{r:a,strokeWidth:o}}return{r:n,strokeWidth:r}}var aee=(t,e,n,r)=>ld(t,"xAxis",e,r),oee=(t,e,n,r)=>od(t,"xAxis",e,r),lee=(t,e,n,r)=>ld(t,"yAxis",n,r),cee=(t,e,n,r)=>od(t,"yAxis",n,r),k$e=Ke([wn,aee,lee,oee,cee],(t,e,n,r,i)=>kc(t,"xAxis")?Tm(e,r,!1):Tm(n,i,!1)),P$e=(t,e,n,r,i)=>i,uee=Ke([OE,P$e],(t,e)=>t.filter(n=>n.type==="area").find(n=>n.id===e)),R$e=(t,e,n,r,i)=>{var s,a=uee(t,e,n,r,i);if(a!=null){var o=wn(t),l=kc(o,"xAxis"),u;if(l?u=Z0(t,"yAxis",n,r):u=Z0(t,"xAxis",e,r),u!=null){var{stackId:d}=a,f=kE(a);if(!(d==null||f==null)){var g=(s=u[d])===null||s===void 0?void 0:s.stackedData;return g?.find(m=>m.key===f)}}}},D$e=Ke([wn,aee,lee,oee,cee,R$e,TE,k$e,uee,$4e],(t,e,n,r,i,s,a,o,l,u)=>{var{chartData:d,dataStartIndex:f,dataEndIndex:g}=a;if(!(l==null||t!=="horizontal"&&t!=="vertical"||e==null||n==null||r==null||i==null||r.length===0||i.length===0||o==null)){var{data:m}=l,x;if(m&&m.length>0?x=m:x=d?.slice(f,g+1),x!=null)return Q$e({layout:t,xAxis:e,yAxis:n,xAxisTicks:r,yAxisTicks:i,dataStartIndex:f,areaSettings:l,stackedData:s,displayedData:x,chartBaseValue:u,bandSize:o})}}),O$e=["id"],j$e=["activeDot","animationBegin","animationDuration","animationEasing","connectNulls","dot","fill","fillOpacity","hide","isAnimationActive","legendType","stroke","xAxisId","yAxisId"];function Th(){return Th=Object.assign?Object.assign.bind():function(t){for(var e=1;e{var{dataKey:e,name:n,stroke:r,fill:i,legendType:s,hide:a}=t;return[{inactive:a,dataKey:e,type:s,color:aS(r,i),value:qm(n,e),payload:t}]},B$e=M.memo(t=>{var{dataKey:e,data:n,stroke:r,strokeWidth:i,fill:s,name:a,hide:o,unit:l,tooltipType:u}=t,d={dataDefinedOnItem:n,positions:void 0,settings:{stroke:r,strokeWidth:i,fill:s,dataKey:e,nameKey:void 0,name:qm(a,e),hide:o,type:u,color:aS(r,s),unit:l}};return M.createElement(jj,{tooltipEntrySettings:d})});function H$e(t){var{clipPathId:e,points:n,props:r}=t,{needClip:i,dot:s,dataKey:a}=r,o=Ks(r);return M.createElement(O6e,{points:n,dot:s,className:"recharts-area-dots",dotClassName:"recharts-area-dot",dataKey:a,baseProps:o,needClip:i,clipPathId:e})}function $$e(t){var{showLabels:e,children:n,points:r}=t,i=r.map(s=>{var a,o,l={x:(a=s.x)!==null&&a!==void 0?a:0,y:(o=s.y)!==null&&o!==void 0?o:0,width:0,lowerWidth:0,upperWidth:0,height:0};return zp(zp({},l),{},{value:s.value,payload:s.payload,parentViewBox:void 0,viewBox:l,fill:void 0})});return M.createElement(OJ,{value:e?i:void 0},n)}function T9(t){var{points:e,baseLine:n,needClip:r,clipPathId:i,props:s}=t,{layout:a,type:o,stroke:l,connectNulls:u,isRange:d}=s,{id:f}=s,g=dee(s,O$e),m=Ks(g),x=Cs(g);return M.createElement(M.Fragment,null,e?.length>1&&M.createElement(Ir,{clipPath:r?"url(#clipPath-".concat(i,")"):void 0},M.createElement(em,Th({},x,{id:f,points:e,connectNulls:u,type:o,baseLine:n,layout:a,stroke:"none",className:"recharts-area-area"})),l!=="none"&&M.createElement(em,Th({},m,{className:"recharts-area-curve",layout:a,type:o,connectNulls:u,fill:"none",points:e})),l!=="none"&&d&&M.createElement(em,Th({},m,{className:"recharts-area-curve",layout:a,type:o,connectNulls:u,fill:"none",points:n}))),M.createElement(H$e,{points:e,props:g,clipPathId:i}))}function V$e(t){var{alpha:e,baseLine:n,points:r,strokeWidth:i}=t,s=r[0].y,a=r[r.length-1].y;if(!ur(s)||!ur(a))return null;var o=e*Math.abs(s-a),l=Math.max(...r.map(u=>u.x||0));return Ct(n)?l=Math.max(n,l):n&&Array.isArray(n)&&n.length&&(l=Math.max(...n.map(u=>u.x||0),l)),Ct(l)?M.createElement("rect",{x:0,y:su.y||0));return Ct(n)?l=Math.max(n,l):n&&Array.isArray(n)&&n.length&&(l=Math.max(...n.map(u=>u.y||0),l)),Ct(l)?M.createElement("rect",{x:s({points:a,baseLine:o}),[a,o]),y=Eb(x,"recharts-area-"),v=oOe(),[b,E]=M.useState(!1),S=!b,A=M.useCallback(()=>{typeof m=="function"&&m(),E(!1)},[m]),T=M.useCallback(()=>{typeof g=="function"&&g(),E(!0)},[g]);if(v==null)return null;var P=i.current,C=s.current;return M.createElement($$e,{showLabels:S,points:a},r.children,M.createElement(Sb,{animationId:y,begin:u,duration:d,isActive:l,easing:f,onAnimationEnd:A,onAnimationStart:T,key:y},I=>{if(P){var N=P.length/a.length,D=I===1?a:a.map((L,q)=>{var R=Math.floor(q*N);if(P[R]){var V=P[R];return zp(zp({},L),{},{x:cr(V.x,L.x,I),y:cr(V.y,L.y,I)})}return L}),F;return Ct(o)?F=cr(C,o,I):yr(o)||io(o)?F=cr(C,0,I):F=o.map((L,q)=>{var R=Math.floor(q*N);if(Array.isArray(C)&&C[R]){var V=C[R];return zp(zp({},L),{},{x:cr(V.x,L.x,I),y:cr(V.y,L.y,I)})}return L}),I>0&&(i.current=D,s.current=F),M.createElement(T9,{points:D,baseLine:F,needClip:e,clipPathId:n,props:r})}return I>0&&(i.current=a,s.current=o),M.createElement(Ir,null,l&&M.createElement("defs",null,M.createElement("clipPath",{id:"animationClipPath-".concat(n)},M.createElement(W$e,{alpha:I,points:a,baseLine:o,layout:v,strokeWidth:r.strokeWidth}))),M.createElement(Ir,{clipPath:"url(#animationClipPath-".concat(n,")")},M.createElement(T9,{points:a,baseLine:o,needClip:e,clipPathId:n,props:r})))}),M.createElement(Cj,{label:r.label}))}function K$e(t){var{needClip:e,clipPathId:n,props:r}=t,i=M.useRef(null),s=M.useRef();return M.createElement(q$e,{needClip:e,clipPathId:n,props:r,previousPointsRef:i,previousBaselineRef:s})}class X$e extends M.PureComponent{render(){var{hide:e,dot:n,points:r,className:i,top:s,left:a,needClip:o,xAxisId:l,yAxisId:u,width:d,height:f,id:g,baseLine:m,zIndex:x}=this.props;if(e)return null;var y=Tn("recharts-area",i),v=g,{r:b,strokeWidth:E}=N$e(n),S=HJ(n),A=b*2+E,T=o?"url(#clipPath-".concat(S?"":"dots-").concat(v,")"):void 0;return M.createElement(Qs,{zIndex:x},M.createElement(Ir,{className:y},o&&M.createElement("defs",null,M.createElement(ZJ,{clipPathId:v,xAxisId:l,yAxisId:u}),!S&&M.createElement("clipPath",{id:"clipPath-dots-".concat(v)},M.createElement("rect",{x:a-A/2,y:s-A/2,width:d+A,height:f+A}))),M.createElement(K$e,{needClip:o,clipPathId:v,props:this.props})),M.createElement(f9,{points:r,mainColor:aS(this.props.stroke,this.props.fill),itemDataKey:this.props.dataKey,activeDot:this.props.activeDot,clipPath:T}),this.props.isRange&&Array.isArray(m)&&M.createElement(f9,{points:m,mainColor:aS(this.props.stroke,this.props.fill),itemDataKey:this.props.dataKey,activeDot:this.props.activeDot,clipPath:T}))}}var hee={activeDot:!0,animationBegin:0,animationDuration:1500,animationEasing:"ease",connectNulls:!1,dot:!1,fill:"#3182bd",fillOpacity:.6,hide:!1,isAnimationActive:"auto",legendType:"line",stroke:"#3182bd",strokeWidth:1,type:"linear",label:!1,xAxisId:0,yAxisId:0,zIndex:Zr.area};function Y$e(t){var e,n=ii(t,hee),{activeDot:r,animationBegin:i,animationDuration:s,animationEasing:a,connectNulls:o,dot:l,fill:u,fillOpacity:d,hide:f,isAnimationActive:g,legendType:m,stroke:x,xAxisId:y,yAxisId:v}=n,b=dee(n,j$e),E=Km(),S=mJ(),{needClip:A}=Uj(y,v),T=ms(),{points:P,isRange:C,baseLine:I}=(e=kt(R=>D$e(R,y,v,T,t.id)))!==null&&e!==void 0?e:{},N=Ij();if(E!=="horizontal"&&E!=="vertical"||N==null||S!=="AreaChart"&&S!=="ComposedChart")return null;var{height:D,width:F,x:L,y:q}=N;return!P||!P.length?null:M.createElement(X$e,Th({},b,{activeDot:r,animationBegin:i,animationDuration:s,animationEasing:a,baseLine:I,connectNulls:o,dot:l,fill:u,fillOpacity:d,height:D,hide:f,layout:E,isAnimationActive:g==="auto"?!Xm.isSsr:g,isRange:C,legendType:m,needClip:A,points:P,stroke:x,width:F,left:L,top:q,xAxisId:y,yAxisId:v}))}var Z$e=(t,e,n,r,i)=>{var s=n??e;if(Ct(s))return s;var a=t==="horizontal"?i:r,o=a.scale.domain();if(a.type==="number"){var l=Math.max(o[0],o[1]),u=Math.min(o[0],o[1]);return s==="dataMin"?u:s==="dataMax"||l<0?l:Math.max(Math.min(o[0],o[1]),0)}return s==="dataMin"?o[0]:s==="dataMax"?o[1]:o[0]};function Q$e(t){var{areaSettings:{connectNulls:e,baseValue:n,dataKey:r},stackedData:i,layout:s,chartBaseValue:a,xAxis:o,yAxis:l,displayedData:u,dataStartIndex:d,xAxisTicks:f,yAxisTicks:g,bandSize:m}=t,x=i&&i.length,y=Z$e(s,a,n,o,l),v=s==="horizontal",b=!1,E=u.map((A,T)=>{var P;x?P=i[d+T]:(P=Qn(A,r),Array.isArray(P)?b=!0:P=[y,P]);var C=P[1]==null||x&&!e&&Qn(A,r)==null;return v?{x:OH({axis:o,ticks:f,bandSize:m,entry:A,index:T}),y:C?null:l.scale(P[1]),value:P,payload:A}:{x:C?null:o.scale(P[1]),y:OH({axis:l,ticks:g,bandSize:m,entry:A,index:T}),value:P,payload:A}}),S;return x||b?S=E.map(A=>{var T=Array.isArray(A.value)?A.value[0]:null;return v?{x:A.x,y:T!=null&&A.y!=null?l.scale(T):null,payload:A.payload}:{x:T!=null?o.scale(T):null,y:A.y,payload:A.payload}}):S=v?l.scale(y):o.scale(y),{points:E,baseLine:S,isRange:b}}function J$e(t){var e=ii(t,hee),n=ms();return M.createElement(Lj,{id:e.id,type:"area"},r=>M.createElement(M.Fragment,null,M.createElement(VJ,{legendPayload:z$e(e)}),M.createElement(B$e,{dataKey:e.dataKey,data:e.data,stroke:e.stroke,strokeWidth:e.strokeWidth,fill:e.fill,name:e.name,hide:e.hide,unit:e.unit,tooltipType:e.tooltipType}),M.createElement(qJ,{type:"area",id:r,data:e.data,dataKey:e.dataKey,xAxisId:e.xAxisId,yAxisId:e.yAxisId,zAxisId:0,stackId:$Y(e.stackId),hide:e.hide,barSize:void 0,baseValue:e.baseValue,isPanorama:n,connectNulls:e.connectNulls}),M.createElement(Y$e,Th({},e,{id:r}))))}var fee=M.memo(J$e,$E);fee.displayName="Area";var eVe=["domain","range"],tVe=["domain","range"];function C9(t,e){if(t==null)return{};var n,r,i=nVe(t,e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(t);for(r=0;r{n.current===null?e(F6e(t)):n.current!==t&&e(z6e({prev:n.current,next:t})),n.current=t},[t,e]),M.useLayoutEffect(()=>()=>{n.current&&(e(B6e(n.current)),n.current=null)},[e]),null}var oVe=t=>{var{xAxisId:e,className:n}=t,r=kt(dO),i=ms(),s="xAxis",a=kt(v=>ng(v,s,e,i)),o=kt(v=>qQ(v,s,e,i)),l=kt(v=>$Q(v,e)),u=kt(v=>zUe(v,e)),d=kt(v=>EQ(v,e));if(l==null||u==null||d==null)return null;var{dangerouslySetInnerHTML:f,ticks:g}=t,m=k9(t,rVe),{id:x}=d,y=k9(d,iVe);return M.createElement(Bj,KP({},m,y,{scale:a,x:u.x,y:u.y,width:l.width,height:l.height,className:Tn("recharts-".concat(s," ").concat(s),n),viewBox:r,ticks:o,axisType:s}))},lVe={allowDataOverflow:Ci.allowDataOverflow,allowDecimals:Ci.allowDecimals,allowDuplicatedCategory:Ci.allowDuplicatedCategory,angle:Ci.angle,axisLine:bc.axisLine,height:Ci.height,hide:!1,includeHidden:Ci.includeHidden,interval:Ci.interval,minTickGap:Ci.minTickGap,mirror:Ci.mirror,orientation:Ci.orientation,padding:Ci.padding,reversed:Ci.reversed,scale:Ci.scale,tick:Ci.tick,tickCount:Ci.tickCount,tickLine:bc.tickLine,tickSize:bc.tickSize,type:Ci.type,xAxisId:0},cVe=t=>{var e=ii(t,lVe);return M.createElement(M.Fragment,null,M.createElement(aVe,{allowDataOverflow:e.allowDataOverflow,allowDecimals:e.allowDecimals,allowDuplicatedCategory:e.allowDuplicatedCategory,angle:e.angle,dataKey:e.dataKey,domain:e.domain,height:e.height,hide:e.hide,id:e.xAxisId,includeHidden:e.includeHidden,interval:e.interval,minTickGap:e.minTickGap,mirror:e.mirror,name:e.name,orientation:e.orientation,padding:e.padding,reversed:e.reversed,scale:e.scale,tick:e.tick,tickCount:e.tickCount,tickFormatter:e.tickFormatter,ticks:e.ticks,type:e.type,unit:e.unit}),M.createElement(oVe,e))},XP=M.memo(cVe,pee);XP.displayName="XAxis";var uVe=["dangerouslySetInnerHTML","ticks"],dVe=["id"];function YP(){return YP=Object.assign?Object.assign.bind():function(t){for(var e=1;e{n.current===null?e(H6e(t)):n.current!==t&&e($6e({prev:n.current,next:t})),n.current=t},[t,e]),M.useLayoutEffect(()=>()=>{n.current&&(e(V6e(n.current)),n.current=null)},[e]),null}var pVe=t=>{var{yAxisId:e,className:n,width:r,label:i}=t,s=M.useRef(null),a=M.useRef(null),o=kt(dO),l=ms(),u=rr(),d="yAxis",f=kt(T=>ng(T,d,e,l)),g=kt(T=>VQ(T,e)),m=kt(T=>HUe(T,e)),x=kt(T=>qQ(T,d,e,l)),y=kt(T=>MQ(T,e));if(M.useLayoutEffect(()=>{if(!(r!=="auto"||!g||Tj(i)||M.isValidElement(i)||y==null)){var T=s.current;if(T){var P=T.getCalculatedWidth();Math.round(g.width)!==Math.round(P)&&u(G6e({id:e,width:P}))}}},[x,g,u,i,e,r,y]),g==null||m==null||y==null)return null;var{dangerouslySetInnerHTML:v,ticks:b}=t,E=P9(t,uVe),{id:S}=y,A=P9(y,dVe);return M.createElement(Bj,YP({},E,A,{ref:s,labelRef:a,scale:f,x:m.x,y:m.y,tickTextProps:r==="auto"?{width:void 0}:{width:r},width:g.width,height:g.height,className:Tn("recharts-".concat(d," ").concat(d),n),viewBox:o,ticks:x,axisType:d}))},mVe={allowDataOverflow:Ni.allowDataOverflow,allowDecimals:Ni.allowDecimals,allowDuplicatedCategory:Ni.allowDuplicatedCategory,angle:Ni.angle,axisLine:bc.axisLine,hide:!1,includeHidden:Ni.includeHidden,interval:Ni.interval,minTickGap:Ni.minTickGap,mirror:Ni.mirror,orientation:Ni.orientation,padding:Ni.padding,reversed:Ni.reversed,scale:Ni.scale,tick:Ni.tick,tickCount:Ni.tickCount,tickLine:bc.tickLine,tickSize:bc.tickSize,type:Ni.type,width:Ni.width,yAxisId:0},gVe=t=>{var e=ii(t,mVe);return M.createElement(M.Fragment,null,M.createElement(fVe,{interval:e.interval,id:e.yAxisId,scale:e.scale,type:e.type,domain:e.domain,allowDataOverflow:e.allowDataOverflow,dataKey:e.dataKey,allowDuplicatedCategory:e.allowDuplicatedCategory,allowDecimals:e.allowDecimals,tickCount:e.tickCount,padding:e.padding,includeHidden:e.includeHidden,reversed:e.reversed,ticks:e.ticks,width:e.width,orientation:e.orientation,mirror:e.mirror,hide:e.hide,unit:e.unit,name:e.name,angle:e.angle,minTickGap:e.minTickGap,tick:e.tick,tickFormatter:e.tickFormatter}),M.createElement(pVe,e))},ZP=M.memo(gVe,pee);ZP.displayName="YAxis";var xVe=(t,e)=>e,Hj=Ke([xVe,wn,wQ,vi,cJ,Lc,rFe,xi],uFe),$j=t=>{var e=t.currentTarget.getBoundingClientRect(),n=e.width/t.currentTarget.offsetWidth,r=e.height/t.currentTarget.offsetHeight;return{chartX:Math.round((t.clientX-e.left)/n),chartY:Math.round((t.clientY-e.top)/r)}},mee=so("mouseClick"),gee=yb();gee.startListening({actionCreator:mee,effect:(t,e)=>{var n=t.payload,r=Hj(e.getState(),$j(n));r?.activeIndex!=null&&e.dispatch(n5e({activeIndex:r.activeIndex,activeDataKey:void 0,activeCoordinate:r.activeCoordinate}))}});var QP=so("mouseMove"),xee=yb(),N_=null;xee.startListening({actionCreator:QP,effect:(t,e)=>{var n=t.payload;N_!==null&&cancelAnimationFrame(N_);var r=$j(n);N_=requestAnimationFrame(()=>{var i=e.getState(),s=mj(i,i.tooltip.settings.shared);if(s==="axis"){var a=Hj(i,r);a?.activeIndex!=null?e.dispatch(tJ({activeIndex:a.activeIndex,activeDataKey:void 0,activeCoordinate:a.activeCoordinate})):e.dispatch(eJ())}N_=null})}});var R9={accessibilityLayer:!0,barCategoryGap:"10%",barGap:4,barSize:void 0,className:void 0,maxBarSize:void 0,stackOffset:"none",syncId:void 0,syncMethod:"index",baseValue:void 0,reverseStackOrder:!1},bee=Zs({name:"rootProps",initialState:R9,reducers:{updateOptions:(t,e)=>{var n;t.accessibilityLayer=e.payload.accessibilityLayer,t.barCategoryGap=e.payload.barCategoryGap,t.barGap=(n=e.payload.barGap)!==null&&n!==void 0?n:R9.barGap,t.barSize=e.payload.barSize,t.maxBarSize=e.payload.maxBarSize,t.stackOffset=e.payload.stackOffset,t.syncId=e.payload.syncId,t.syncMethod=e.payload.syncMethod,t.className=e.payload.className,t.baseValue=e.payload.baseValue,t.reverseStackOrder=e.payload.reverseStackOrder}}}),bVe=bee.reducer,{updateOptions:vVe}=bee.actions,vee=Zs({name:"polarOptions",initialState:null,reducers:{updatePolarOptions:(t,e)=>e.payload}}),{updatePolarOptions:yVe}=vee.actions,_Ve=vee.reducer,yee=so("keyDown"),_ee=so("focus"),Vj=yb();Vj.startListening({actionCreator:yee,effect:(t,e)=>{var n=e.getState(),r=n.rootProps.accessibilityLayer!==!1;if(r){var{keyboardInteraction:i}=n.tooltip,s=t.payload;if(!(s!=="ArrowRight"&&s!=="ArrowLeft"&&s!=="Enter")){var a=gj(i,ig(n),Db(n),Ib(n)),o=a==null?-1:Number(a);if(!(!Number.isFinite(o)||o<0)){var l=Lc(n);if(s==="Enter"){var u=Zw(n,"axis","hover",String(i.index));e.dispatch(zP({active:!i.active,activeIndex:i.index,activeDataKey:i.dataKey,activeCoordinate:u}));return}var d=WUe(n),f=d==="left-to-right"?1:-1,g=s==="ArrowRight"?1:-1,m=o+g*f;if(!(l==null||m>=l.length||m<0)){var x=Zw(n,"axis","hover",String(m));e.dispatch(zP({active:!0,activeIndex:m.toString(),activeDataKey:void 0,activeCoordinate:x}))}}}}}});Vj.startListening({actionCreator:_ee,effect:(t,e)=>{var n=e.getState(),r=n.rootProps.accessibilityLayer!==!1;if(r){var{keyboardInteraction:i}=n.tooltip;if(!i.active&&i.index==null){var s="0",a=Zw(n,"axis","hover",String(s));e.dispatch(zP({activeDataKey:void 0,active:!0,activeIndex:s,activeCoordinate:a}))}}}});var Ia=so("externalEvent"),wee=yb(),zN=new Map;wee.startListening({actionCreator:Ia,effect:(t,e)=>{var{handler:n,reactEvent:r}=t.payload;if(n!=null){r.persist();var i=r.type,s=zN.get(i);s!==void 0&&cancelAnimationFrame(s);var a=requestAnimationFrame(()=>{try{var o=e.getState(),l={activeCoordinate:H5e(o),activeDataKey:_j(o),activeIndex:cd(o),activeLabel:hJ(o),activeTooltipIndex:cd(o),isTooltipActive:$5e(o)};n(l,r)}finally{zN.delete(i)}});zN.set(i,a)}}});var wVe=Ke([rg],t=>t.tooltipItemPayloads),SVe=Ke([wVe,jb,(t,e,n)=>e,(t,e,n)=>n],(t,e,n,r)=>{var i=t.find(o=>o.settings.dataKey===r);if(i!=null){var{positions:s}=i;if(s!=null){var a=e(s,n);return a}}}),See=so("touchMove"),Eee=yb();Eee.startListening({actionCreator:See,effect:(t,e)=>{var n=t.payload;if(!(n.touches==null||n.touches.length===0)){var r=e.getState(),i=mj(r,r.tooltip.settings.shared);if(i==="axis"){var s=Hj(r,$j({clientX:n.touches[0].clientX,clientY:n.touches[0].clientY,currentTarget:n.currentTarget}));s?.activeIndex!=null&&e.dispatch(tJ({activeIndex:s.activeIndex,activeDataKey:void 0,activeCoordinate:s.activeCoordinate}))}else if(i==="item"){var a,o=n.touches[0];if(document.elementFromPoint==null)return;var l=document.elementFromPoint(o.clientX,o.clientY);if(!l||!l.getAttribute)return;var u=l.getAttribute(GY),d=(a=l.getAttribute(WY))!==null&&a!==void 0?a:void 0,f=SVe(e.getState(),u,d);e.dispatch(JQ({activeDataKey:d,activeIndex:u,activeCoordinate:f}))}}}});var EVe=hY({brush:OHe,cartesianAxis:W6e,chartData:BFe,errorBars:d8e,graphicalItems:QBe,layout:pDe,legend:wOe,options:LFe,polarAxis:fBe,polarOptions:_Ve,referenceElements:BHe,rootProps:bVe,tooltip:r5e,zIndex:EFe}),MVe=function(e){return FRe({reducer:EVe,preloadedState:e,middleware:n=>{var r;return n({serializableCheck:!1,immutableCheck:!["commonjs","es6","production"].includes((r="es6")!==null&&r!==void 0?r:"")}).concat([gee.middleware,xee.middleware,Vj.middleware,wee.middleware,Eee.middleware])},enhancers:n=>{var r=n;return typeof n=="function"&&(r=n()),r.concat(TY({type:"raf"}))},devTools:Xm.devToolsEnabled})};function Mee(t){var{preloadedState:e,children:n,reduxStoreName:r}=t,i=ms(),s=M.useRef(null);if(i)return n;s.current==null&&(s.current=MVe(e));var a=nO;return M.createElement(L8e,{context:a,store:s.current},n)}function AVe(t){var{layout:e,margin:n}=t,r=rr(),i=ms();return M.useEffect(()=>{i||(r(dDe(e)),r(uDe(n)))},[r,i,e,n]),null}var Aee=M.memo(AVe,$E);function Tee(t){var e=rr();return M.useEffect(()=>{e(vVe(t))},[e,t]),null}function D9(t){var{zIndex:e,isPanorama:n}=t,r=n?"recharts-zindex-panorama-":"recharts-zindex-",i=GJ("".concat(r).concat(e)),s=rr();return M.useLayoutEffect(()=>(s(wFe({zIndex:e,elementId:i,isPanorama:n})),()=>{s(SFe({zIndex:e,isPanorama:n}))}),[s,e,i,n]),M.createElement("g",{tabIndex:-1,id:i})}function O9(t){var{children:e,isPanorama:n}=t,r=kt(hFe);if(!r||r.length===0)return e;var i=r.filter(a=>a<0),s=r.filter(a=>a>0);return M.createElement(M.Fragment,null,i.map(a=>M.createElement(D9,{key:a,zIndex:a,isPanorama:n})),e,s.map(a=>M.createElement(D9,{key:a,zIndex:a,isPanorama:n})))}var TVe=["children"];function CVe(t,e){if(t==null)return{};var n,r,i=NVe(t,e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(t);for(r=0;r{var n=fO(),r=pO(),i=cZ();if(!pl(n)||!pl(r))return null;var{children:s,otherAttributes:a,title:o,desc:l}=t,u,d;return a!=null&&(typeof a.tabIndex=="number"?u=a.tabIndex:u=i?0:void 0,typeof a.role=="string"?d=a.role:d=i?"application":void 0),M.createElement(WD,oS({},a,{title:o,desc:l,role:d,tabIndex:u,width:n,height:r,style:kVe,ref:e}),s)}),RVe=t=>{var{children:e}=t,n=kt(mE);if(!n)return null;var{width:r,height:i,y:s,x:a}=n;return M.createElement(WD,{width:r,height:i,x:a,y:s},e)},j9=M.forwardRef((t,e)=>{var{children:n}=t,r=CVe(t,TVe),i=ms();return i?M.createElement(RVe,null,M.createElement(O9,{isPanorama:!0},n)):M.createElement(PVe,oS({ref:e},r),M.createElement(O9,{isPanorama:!1},n))});function DVe(){var t=rr(),[e,n]=M.useState(null),r=kt(PDe);return M.useEffect(()=>{if(e!=null){var i=e.getBoundingClientRect(),s=i.width/e.offsetWidth;ur(s)&&s!==r&&t(fDe(s))}},[e,t,r]),n}function L9(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function OVe(t){for(var e=1;e(YFe(),null);function lS(t){if(typeof t=="number")return t;if(typeof t=="string"){var e=parseFloat(t);if(!Number.isNaN(e))return e}return 0}var FVe=M.forwardRef((t,e)=>{var n,r,i=M.useRef(null),[s,a]=M.useState({containerWidth:lS((n=t.style)===null||n===void 0?void 0:n.width),containerHeight:lS((r=t.style)===null||r===void 0?void 0:r.height)}),o=M.useCallback((u,d)=>{a(f=>{var g=Math.round(u),m=Math.round(d);return f.containerWidth===g&&f.containerHeight===m?f:{containerWidth:g,containerHeight:m}})},[]),l=M.useCallback(u=>{if(typeof e=="function"&&e(u),u!=null&&typeof ResizeObserver<"u"){var{width:d,height:f}=u.getBoundingClientRect();o(d,f);var g=x=>{var{width:y,height:v}=x[0].contentRect;o(y,v)},m=new ResizeObserver(g);m.observe(u),i.current=m}},[e,o]);return M.useEffect(()=>()=>{var u=i.current;u?.disconnect()},[o]),M.createElement(M.Fragment,null,M.createElement(xE,{width:s.containerWidth,height:s.containerHeight}),M.createElement("div",Jh({ref:l},t)))}),zVe=M.forwardRef((t,e)=>{var{width:n,height:r}=t,[i,s]=M.useState({containerWidth:lS(n),containerHeight:lS(r)}),a=M.useCallback((l,u)=>{s(d=>{var f=Math.round(l),g=Math.round(u);return d.containerWidth===f&&d.containerHeight===g?d:{containerWidth:f,containerHeight:g}})},[]),o=M.useCallback(l=>{if(typeof e=="function"&&e(l),l!=null){var{width:u,height:d}=l.getBoundingClientRect();a(u,d)}},[e,a]);return M.createElement(M.Fragment,null,M.createElement(xE,{width:i.containerWidth,height:i.containerHeight}),M.createElement("div",Jh({ref:o},t)))}),BVe=M.forwardRef((t,e)=>{var{width:n,height:r}=t;return M.createElement(M.Fragment,null,M.createElement(xE,{width:n,height:r}),M.createElement("div",Jh({ref:e},t)))}),HVe=M.forwardRef((t,e)=>{var{width:n,height:r}=t;return wc(n)||wc(r)?M.createElement(zVe,Jh({},t,{ref:e})):M.createElement(BVe,Jh({},t,{ref:e}))});function $Ve(t){return t===!0?FVe:HVe}var VVe=M.forwardRef((t,e)=>{var{children:n,className:r,height:i,onClick:s,onContextMenu:a,onDoubleClick:o,onMouseDown:l,onMouseEnter:u,onMouseLeave:d,onMouseMove:f,onMouseUp:g,onTouchEnd:m,onTouchMove:x,onTouchStart:y,style:v,width:b,responsive:E,dispatchTouchEvents:S=!0}=t,A=M.useRef(null),T=rr(),[P,C]=M.useState(null),[I,N]=M.useState(null),D=DVe(),F=hO(),L=F?.width>0?F.width:b,q=F?.height>0?F.height:i,R=M.useCallback(se=>{D(se),typeof e=="function"&&e(se),C(se),N(se),se!=null&&(A.current=se)},[D,e,C,N]),V=M.useCallback(se=>{T(mee(se)),T(Ia({handler:s,reactEvent:se}))},[T,s]),K=M.useCallback(se=>{T(QP(se)),T(Ia({handler:u,reactEvent:se}))},[T,u]),W=M.useCallback(se=>{T(eJ()),T(Ia({handler:d,reactEvent:se}))},[T,d]),ne=M.useCallback(se=>{T(QP(se)),T(Ia({handler:f,reactEvent:se}))},[T,f]),Y=M.useCallback(()=>{T(_ee())},[T]),Z=M.useCallback(se=>{T(yee(se.key))},[T]),U=M.useCallback(se=>{T(Ia({handler:a,reactEvent:se}))},[T,a]),$=M.useCallback(se=>{T(Ia({handler:o,reactEvent:se}))},[T,o]),ee=M.useCallback(se=>{T(Ia({handler:l,reactEvent:se}))},[T,l]),ae=M.useCallback(se=>{T(Ia({handler:g,reactEvent:se}))},[T,g]),fe=M.useCallback(se=>{T(Ia({handler:y,reactEvent:se}))},[T,y]),ue=M.useCallback(se=>{S&&T(See(se)),T(Ia({handler:x,reactEvent:se}))},[T,S,x]),xe=M.useCallback(se=>{T(Ia({handler:m,reactEvent:se}))},[T,m]),Me=$Ve(E);return M.createElement(yJ.Provider,{value:P},M.createElement(CX.Provider,{value:I},M.createElement(Me,{width:L??v?.width,height:q??v?.height,className:Tn("recharts-wrapper",r),style:OVe({position:"relative",cursor:"default",width:L,height:q},v),onClick:V,onContextMenu:U,onDoubleClick:$,onFocus:Y,onKeyDown:Z,onMouseDown:ee,onMouseEnter:K,onMouseLeave:W,onMouseMove:ne,onMouseUp:ae,onTouchEnd:xe,onTouchMove:ue,onTouchStart:fe,ref:R},M.createElement(UVe,null),n)))}),GVe=["width","height","responsive","children","className","style","compact","title","desc"];function WVe(t,e){if(t==null)return{};var n,r,i=qVe(t,e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(t);for(r=0;r{var{width:n,height:r,responsive:i,children:s,className:a,style:o,compact:l,title:u,desc:d}=t,f=WVe(t,GVe),g=Ks(f);return l?M.createElement(M.Fragment,null,M.createElement(xE,{width:n,height:r}),M.createElement(j9,{otherAttributes:g,title:u,desc:d},s)):M.createElement(VVe,{className:a,style:o,width:n,height:r,responsive:i??!1,onClick:t.onClick,onMouseLeave:t.onMouseLeave,onMouseEnter:t.onMouseEnter,onMouseMove:t.onMouseMove,onMouseDown:t.onMouseDown,onMouseUp:t.onMouseUp,onContextMenu:t.onContextMenu,onDoubleClick:t.onDoubleClick,onTouchStart:t.onTouchStart,onTouchMove:t.onTouchMove,onTouchEnd:t.onTouchEnd},M.createElement(j9,{otherAttributes:g,title:u,desc:d,ref:e},M.createElement($He,null,s)))});function JP(){return JP=Object.assign?Object.assign.bind():function(t){for(var e=1;eM.createElement(Nee,{chartName:"BarChart",defaultTooltipEventType:"axis",validateTooltipEventTypes:YVe,tooltipPayloadSearcher:Aj,categoricalChartProps:t,ref:e}));function QVe(t){var e=rr();return M.useEffect(()=>{e(yVe(t))},[e,t]),null}var JVe=["layout"];function eR(){return eR=Object.assign?Object.assign.bind():function(t){for(var e=1;e{var n=ii(t,l9e);return M.createElement(r9e,{chartName:"PieChart",defaultTooltipEventType:"item",validateTooltipEventTypes:o9e,tooltipPayloadSearcher:Aj,categoricalChartProps:n,ref:e})}),u9e=["axis"],d9e=M.forwardRef((t,e)=>M.createElement(Nee,{chartName:"AreaChart",defaultTooltipEventType:"axis",validateTooltipEventTypes:u9e,tooltipPayloadSearcher:Aj,categoricalChartProps:t,ref:e}));const k_=["#00ae42","#3b82f6","#f59e0b","#ef4444","#8b5cf6","#ec4899","#14b8a6","#f97316"];function h9e(t){const e=new Date;switch(t){case"7d":return new Date(e.getTime()-10080*60*1e3);case"30d":return new Date(e.getTime()-720*60*60*1e3);case"90d":return new Date(e.getTime()-2160*60*60*1e3);case"365d":return new Date(e.getTime()-365*24*60*60*1e3);case"all":return new Date(0)}}function f9e({archives:t,currency:e="$"}){const[n,r]=M.useState("30d"),i=M.useMemo(()=>{const g=h9e(n);return t.filter(m=>new Date(m.completed_at||m.created_at)>=g)},[t,n]),s=M.useMemo(()=>{const g=new Map;return i.forEach(m=>{const y=new Date(m.completed_at||m.created_at).toISOString().split("T")[0],v=g.get(y)||{date:y,filament:0,cost:0,prints:0};v.filament+=m.filament_used_grams||0,v.cost+=m.cost||0,v.prints+=1,g.set(y,v)}),Array.from(g.values()).sort((m,x)=>m.date.localeCompare(x.date)).map(m=>({...m,dateLabel:new Date(m.date).toLocaleDateString("en-US",{month:"short",day:"numeric"})}))},[i]),a=M.useMemo(()=>{if(n==="7d"||n==="30d")return s;const g=new Map;return i.forEach(m=>{const x=new Date(m.completed_at||m.created_at),y=new Date(x);y.setDate(x.getDate()-x.getDay());const v=y.toISOString().split("T")[0],b=g.get(v)||{week:v,filament:0,cost:0,prints:0};b.filament+=m.filament_used_grams||0,b.cost+=m.cost||0,b.prints+=1,g.set(v,b)}),Array.from(g.values()).sort((m,x)=>m.week.localeCompare(x.week)).map(m=>({date:m.week,dateLabel:`Week of ${new Date(m.week).toLocaleDateString("en-US",{month:"short",day:"numeric"})}`,...m}))},[i,s,n]),o=M.useMemo(()=>{const g=new Map;return i.forEach(m=>{const y=(m.filament_type||"Unknown").split(", ");y.forEach(v=>{const b=(m.filament_used_grams||0)/y.length;g.set(v,(g.get(v)||0)+b)})}),Array.from(g.entries()).map(([m,x])=>({name:m,value:Math.round(x)})).sort((m,x)=>x.value-m.value)},[i]),l=M.useMemo(()=>{const g=new Date,m=[];for(let x=5;x>=0;x--){const y=new Date(g.getFullYear(),g.getMonth()-x,1),v=new Date(g.getFullYear(),g.getMonth()-x+1,0),b=y.toLocaleDateString("en-US",{month:"short",year:"2-digit"}),E=t.filter(S=>{const A=new Date(S.completed_at||S.created_at);return A>=y&&A<=v});m.push({month:b,filament:Math.round(E.reduce((S,A)=>S+(A.filament_used_grams||0),0)),cost:E.reduce((S,A)=>S+(A.cost||0),0),prints:E.length})}return m},[t]),u=n==="7d"||n==="30d"?s:a,d=i.reduce((g,m)=>g+(m.filament_used_grams||0),0),f=i.reduce((g,m)=>g+(m.cost||0),0);return c.jsxs("div",{className:"space-y-6",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("h3",{className:"text-lg font-semibold text-white",children:"Filament Usage Trends"}),c.jsx("div",{className:"flex gap-1 bg-bambu-dark rounded-lg p-1",children:["7d","30d","90d","365d","all"].map(g=>c.jsx("button",{onClick:()=>r(g),className:`px-3 py-1 text-sm rounded-md transition-colors ${n===g?"bg-bambu-green text-white":"text-bambu-gray hover:text-white"}`,children:g==="all"?"All":g.replace("d","D")},g))})]}),c.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[c.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[c.jsx("p",{className:"text-sm text-bambu-gray",children:"Period Filament"}),c.jsxs("p",{className:"text-2xl font-bold text-white",children:[(d/1e3).toFixed(2),"kg"]}),c.jsxs("p",{className:"text-xs text-bambu-gray",children:[d.toFixed(0),"g total"]})]}),c.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[c.jsx("p",{className:"text-sm text-bambu-gray",children:"Period Cost"}),c.jsxs("p",{className:"text-2xl font-bold text-white",children:[e,f.toFixed(2)]}),c.jsxs("p",{className:"text-xs text-bambu-gray",children:[i.length," prints"]})]}),c.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[c.jsx("p",{className:"text-sm text-bambu-gray",children:"Avg per Print"}),c.jsxs("p",{className:"text-2xl font-bold text-white",children:[i.length>0?(d/i.length).toFixed(0):0,"g"]}),c.jsxs("p",{className:"text-xs text-bambu-gray",children:[e,i.length>0?(f/i.length).toFixed(2):"0.00"," avg"]})]})]}),u.length>0?c.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[c.jsx("h4",{className:"text-sm font-medium text-bambu-gray mb-4",children:"Usage Over Time"}),c.jsx(oN,{width:"100%",height:250,children:c.jsxs(d9e,{data:u,children:[c.jsx("defs",{children:c.jsxs("linearGradient",{id:"colorFilament",x1:"0",y1:"0",x2:"0",y2:"1",children:[c.jsx("stop",{offset:"5%",stopColor:"#00ae42",stopOpacity:.3}),c.jsx("stop",{offset:"95%",stopColor:"#00ae42",stopOpacity:0})]})}),c.jsx(qP,{strokeDasharray:"3 3",stroke:"#3d3d3d"}),c.jsx(XP,{dataKey:"dateLabel",stroke:"#9ca3af",tick:{fontSize:12},interval:"preserveStartEnd"}),c.jsx(ZP,{stroke:"#9ca3af",tick:{fontSize:12},tickFormatter:g=>`${g}g`}),c.jsx(MN,{contentStyle:{backgroundColor:"#2d2d2d",border:"1px solid #3d3d3d",borderRadius:"8px"},labelStyle:{color:"#fff"},formatter:g=>[`${g.toFixed(0)}g`,"Filament"]}),c.jsx(fee,{type:"monotone",dataKey:"filament",stroke:"#00ae42",strokeWidth:2,fillOpacity:1,fill:"url(#colorFilament)"})]})})]}):c.jsx("div",{className:"bg-bambu-dark rounded-lg p-8 text-center text-bambu-gray",children:"No data for selected time range"}),c.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[c.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[c.jsx("h4",{className:"text-sm font-medium text-bambu-gray mb-4",children:"By Filament Type"}),o.length>0?c.jsxs("div",{className:"flex items-center gap-4",children:[c.jsx(oN,{width:160,height:160,children:c.jsxs(c9e,{children:[c.jsx(KJ,{data:o,cx:"50%",cy:"50%",innerRadius:40,outerRadius:70,paddingAngle:2,dataKey:"value",children:o.map((g,m)=>c.jsx(Fb,{fill:k_[m%k_.length]},`cell-${m}`))}),c.jsx(MN,{contentStyle:{backgroundColor:"#2d2d2d",border:"1px solid #3d3d3d",borderRadius:"8px"},formatter:g=>[`${g}g`,"Usage"]})]})}),c.jsx("div",{className:"flex-1 space-y-2 overflow-hidden",children:o.map((g,m)=>{const x=o.reduce((v,b)=>v+b.value,0),y=x>0?(g.value/x*100).toFixed(0):0;return c.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[c.jsx("div",{className:"w-3 h-3 rounded-sm flex-shrink-0",style:{backgroundColor:k_[m%k_.length]}}),c.jsx("span",{className:"text-white truncate flex-1",children:g.name}),c.jsxs("span",{className:"text-bambu-gray flex-shrink-0",children:[y,"%"]})]},g.name)})})]}):c.jsx("div",{className:"h-[160px] flex items-center justify-center text-bambu-gray",children:"No filament data"})]}),c.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[c.jsx("h4",{className:"text-sm font-medium text-bambu-gray mb-4",children:"Monthly Comparison"}),c.jsx(oN,{width:"100%",height:200,children:c.jsxs(ZVe,{data:l,children:[c.jsx(qP,{strokeDasharray:"3 3",stroke:"#3d3d3d"}),c.jsx(XP,{dataKey:"month",stroke:"#9ca3af",tick:{fontSize:12}}),c.jsx(ZP,{stroke:"#9ca3af",tick:{fontSize:12},tickFormatter:g=>`${g}g`}),c.jsx(MN,{contentStyle:{backgroundColor:"#2d2d2d",border:"1px solid #3d3d3d",borderRadius:"8px"},formatter:(g,m)=>[m==="filament"?`${g}g`:m==="cost"?`${e}${g.toFixed(2)}`:g,m==="filament"?"Filament":m==="cost"?"Cost":"Prints"]}),c.jsx(lZ,{}),c.jsx(JJ,{dataKey:"filament",name:"Filament (g)",fill:"#00ae42",radius:[4,4,0,0]})]})})]})]})]})}function p9e({id:t,title:e,children:n,isHidden:r,size:i,onToggleVisibility:s,onToggleSize:a}){const{attributes:o,listeners:l,setNodeRef:u,transform:d,transition:f,isDragging:g}=_X({id:t}),m={transform:Sm.Transform.toString(d),transition:f,opacity:g?.5:1};return r?null:c.jsxs("div",{ref:u,style:{...m,gridColumn:`span ${i}`},className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary overflow-hidden ${g?"ring-2 ring-bambu-green shadow-lg":""}`,children:[c.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark/30",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("button",{...o,...l,className:"cursor-grab active:cursor-grabbing p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",title:"Drag to reorder",children:c.jsx(c0,{className:"w-6 h-6 md:w-4 md:h-4 text-bambu-gray"})}),c.jsx("h3",{className:"text-sm font-medium text-white",children:e})]}),c.jsxs("div",{className:"flex items-center gap-1",children:[c.jsx("button",{onClick:a,className:"p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",title:`Size: ${i===1?"1/4":i===2?"1/2":"Full"} - Click to cycle`,children:i===4?c.jsx(Ele,{className:"w-4 h-4 text-bambu-gray hover:text-white"}):c.jsx(ble,{className:"w-4 h-4 text-bambu-gray hover:text-white"})}),c.jsx("button",{onClick:s,className:"p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",title:"Hide widget",children:c.jsx(mR,{className:"w-4 h-4 text-bambu-gray hover:text-white"})})]})]}),c.jsx("div",{className:"p-4",children:n})]})}function m9e({widgets:t,storageKey:e,columns:n=4,hideControls:r=!1,onResetLayout:i}){const s=()=>{const E={};return t.forEach(S=>{E[S.id]=S.defaultSize||4}),E},[a,o]=M.useState(()=>{const E=localStorage.getItem(e);if(E)try{const S=JSON.parse(E);return S.sizes||(S.sizes=s()),S}catch{}return{order:t.map(S=>S.id),hidden:t.filter(S=>S.defaultVisible===!1).map(S=>S.id),sizes:s()}}),[l,u]=M.useState(!1);M.useEffect(()=>{localStorage.setItem(e,JSON.stringify(a))},[a,e]),M.useEffect(()=>{const S=t.map(A=>A.id).filter(A=>!a.order.includes(A));S.length>0&&o(A=>({...A,order:[...A.order,...S]}))},[t,a.order]);const d=JK(fw(YS,{activationConstraint:{distance:8}}),fw(XS,{coordinateGetter:wX})),f=E=>{const{active:S,over:A}=E;A&&S.id!==A.id&&o(T=>{const P=T.order.indexOf(S.id),C=T.order.indexOf(A.id);return{...T,order:JS(T.order,P,C)}})},g=E=>{o(S=>({...S,hidden:S.hidden.includes(E)?S.hidden.filter(A=>A!==E):[...S.hidden,E]}))},m=E=>{o(S=>{const A=S.sizes[E]||4,T=A===1?2:A===2?4:1;return{...S,sizes:{...S.sizes,[E]:T}}})},x=()=>{const E={order:t.map(S=>S.id),hidden:t.filter(S=>S.defaultVisible===!1).map(S=>S.id),sizes:s()};o(E),i?.()},y=a.order.map(E=>t.find(S=>S.id===E)).filter(Boolean),v=y.filter(E=>!a.hidden.includes(E.id)),b=y.filter(E=>a.hidden.includes(E.id));return c.jsxs("div",{className:"space-y-4",children:[!r&&c.jsxs("div",{className:"flex items-center justify-end gap-2",children:[b.length>0&&c.jsxs(Ie,{variant:"secondary",size:"sm",onClick:()=>u(!l),children:[c.jsx(o0,{className:"w-4 h-4"}),b.length," Hidden"]}),c.jsxs(Ie,{variant:"secondary",size:"sm",onClick:x,children:[c.jsx(Im,{className:"w-4 h-4"}),"Reset Layout"]})]}),l&&b.length>0&&c.jsxs("div",{className:"p-4 bg-bambu-dark rounded-xl border border-bambu-dark-tertiary",children:[c.jsx("p",{className:"text-sm text-bambu-gray mb-3",children:"Hidden widgets (click to show):"}),c.jsx("div",{className:"flex flex-wrap gap-2",children:b.map(E=>c.jsxs("button",{onClick:()=>g(E.id),className:"px-3 py-1.5 bg-bambu-dark-tertiary hover:bg-bambu-green/20 rounded-lg text-sm text-white transition-colors flex items-center gap-2",children:[c.jsx(o0,{className:"w-3 h-3"}),E.title]},E.id))})]}),c.jsx(gX,{sensors:d,collisionDetection:rX,onDragEnd:f,children:c.jsx(vX,{items:v.map(E=>E.id),strategy:VD,children:c.jsx("div",{className:"grid gap-6",style:{gridTemplateColumns:`repeat(${n}, minmax(0, 1fr))`},children:v.map(E=>c.jsx(p9e,{id:E.id,title:E.title,isHidden:a.hidden.includes(E.id),size:a.sizes[E.id]||2,onToggleVisibility:()=>g(E.id),onToggleSize:()=>m(E.id),children:E.component},E.id))})})}),v.length===0&&c.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[c.jsx("p",{children:"All widgets are hidden."}),c.jsx(Ie,{className:"mt-4",onClick:x,children:"Reset Layout"})]})]})}function g9e({stats:t,currency:e}){return c.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-4",children:[c.jsxs("div",{className:"flex items-start gap-3",children:[c.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-bambu-green",children:c.jsx(u0,{className:"w-5 h-5"})}),c.jsxs("div",{children:[c.jsx("p",{className:"text-xs text-bambu-gray",children:"Total Prints"}),c.jsx("p",{className:"text-xl font-bold text-white",children:t?.total_prints||0})]})]}),c.jsxs("div",{className:"flex items-start gap-3",children:[c.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-blue-400",children:c.jsx(ti,{className:"w-5 h-5"})}),c.jsxs("div",{children:[c.jsx("p",{className:"text-xs text-bambu-gray",children:"Print Time"}),c.jsxs("p",{className:"text-xl font-bold text-white",children:[t?.total_print_time_hours.toFixed(1)||0,"h"]})]})]}),c.jsxs("div",{className:"flex items-start gap-3",children:[c.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-orange-400",children:c.jsx(u0,{className:"w-5 h-5"})}),c.jsxs("div",{children:[c.jsx("p",{className:"text-xs text-bambu-gray",children:"Filament Used"}),c.jsxs("p",{className:"text-xl font-bold text-white",children:[((t?.total_filament_grams||0)/1e3).toFixed(2),"kg"]})]})]}),c.jsxs("div",{className:"flex items-start gap-3",children:[c.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-green-400",children:c.jsx(a3,{className:"w-5 h-5"})}),c.jsxs("div",{children:[c.jsx("p",{className:"text-xs text-bambu-gray",children:"Filament Cost"}),c.jsxs("p",{className:"text-xl font-bold text-white",children:[e," ",t?.total_cost.toFixed(2)||"0.00"]})]})]}),c.jsxs("div",{className:"flex items-start gap-3",children:[c.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-yellow-400",children:c.jsx(am,{className:"w-5 h-5"})}),c.jsxs("div",{children:[c.jsx("p",{className:"text-xs text-bambu-gray",children:"Energy Used"}),c.jsxs("p",{className:"text-xl font-bold text-white",children:[t?.total_energy_kwh.toFixed(2)||"0.00"," kWh"]})]})]}),c.jsxs("div",{className:"flex items-start gap-3",children:[c.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-yellow-500",children:c.jsx(a3,{className:"w-5 h-5"})}),c.jsxs("div",{children:[c.jsx("p",{className:"text-xs text-bambu-gray",children:"Energy Cost"}),c.jsxs("p",{className:"text-xl font-bold text-white",children:[e," ",t?.total_energy_cost.toFixed(2)||"0.00"]})]})]})]})}function x9e({stats:t}){const e=t?.total_prints?Math.round(t.successful_prints/t.total_prints*100):0;return c.jsxs("div",{className:"flex items-center gap-6",children:[c.jsxs("div",{className:"relative w-28 h-28",children:[c.jsxs("svg",{className:"w-full h-full -rotate-90",children:[c.jsx("circle",{cx:"56",cy:"56",r:"48",fill:"none",stroke:"#3d3d3d",strokeWidth:"10"}),c.jsx("circle",{cx:"56",cy:"56",r:"48",fill:"none",stroke:"#00ae42",strokeWidth:"10",strokeLinecap:"round",strokeDasharray:`${e*3.02} 302`})]}),c.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:c.jsxs("span",{className:"text-xl font-bold text-white",children:[e,"%"]})})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(ds,{className:"w-4 h-4 text-bambu-green"}),c.jsx("span",{className:"text-sm text-bambu-gray",children:"Successful:"}),c.jsx("span",{className:"text-sm text-white font-medium",children:t?.successful_prints||0})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(hd,{className:"w-4 h-4 text-red-400"}),c.jsx("span",{className:"text-sm text-bambu-gray",children:"Failed:"}),c.jsx("span",{className:"text-sm text-white font-medium",children:t?.failed_prints||0})]})]})]})}function b9e({stats:t,printerMap:e}){const n=t?.average_time_accuracy;if(n==null)return c.jsx("div",{className:"flex items-center justify-center h-full",children:c.jsx("p",{className:"text-bambu-gray text-center py-4",children:"No time accuracy data yet"})});const i=(Math.min(150,Math.max(50,n))-50)/100*100,a=(l=>l>=95&&l<=105?"#00ae42":l>105?"#3b82f6":"#f97316")(n),o=n-100;return c.jsxs("div",{className:"flex items-center gap-6",children:[c.jsxs("div",{className:"relative w-28 h-28",children:[c.jsxs("svg",{className:"w-full h-full -rotate-90",children:[c.jsx("circle",{cx:"56",cy:"56",r:"48",fill:"none",stroke:"#3d3d3d",strokeWidth:"10"}),c.jsx("circle",{cx:"56",cy:"56",r:"48",fill:"none",stroke:a,strokeWidth:"10",strokeLinecap:"round",strokeDasharray:`${i*3.02} 302`})]}),c.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[c.jsxs("span",{className:"text-xl font-bold text-white",children:[n.toFixed(0),"%"]}),c.jsxs("span",{className:`text-xs ${o>=0?"text-blue-400":"text-orange-400"}`,children:[o>=0?"+":"",o.toFixed(0),"%"]})]})]}),c.jsxs("div",{className:"space-y-2 flex-1",children:[c.jsxs("div",{className:"flex items-center gap-2 text-xs text-bambu-gray",children:[c.jsx(IG,{className:"w-3 h-3"}),c.jsx("span",{children:"100% = perfect estimate"})]}),t?.time_accuracy_by_printer&&Object.keys(t.time_accuracy_by_printer).length>0&&c.jsx("div",{className:"space-y-1 mt-2",children:Object.entries(t.time_accuracy_by_printer).slice(0,3).map(([l,u])=>c.jsxs("div",{className:"flex items-center justify-between text-xs",children:[c.jsx("span",{className:"text-bambu-gray truncate max-w-[100px]",children:e.get(l)||`Printer ${l}`}),c.jsxs("span",{className:`font-medium ${u>=95&&u<=105?"text-bambu-green":u>105?"text-blue-400":"text-orange-400"}`,children:[u.toFixed(0),"%"]})]},l))})]})]})}function v9e({stats:t}){if(!t?.prints_by_filament_type||Object.keys(t.prints_by_filament_type).length===0)return c.jsx("p",{className:"text-bambu-gray text-center py-4",children:"No filament data available"});const e=Object.entries(t.prints_by_filament_type).sort(([,n],[,r])=>r-n);return c.jsx("div",{className:"space-y-3",children:e.map(([n,r])=>{const i=Math.round(r/(t.total_prints||1)*100);return c.jsxs("div",{children:[c.jsxs("div",{className:"flex justify-between text-sm mb-1",children:[c.jsx("span",{className:"text-white",children:n}),c.jsxs("span",{className:"text-bambu-gray",children:[r," prints"]})]}),c.jsx("div",{className:"h-2 bg-bambu-dark rounded-full",children:c.jsx("div",{className:"h-full bg-bambu-green rounded-full transition-all",style:{width:`${i}%`}})})]},n)})})}function y9e({printDates:t}){return c.jsx(ake,{printDates:t,months:4})}function _9e({stats:t,printerMap:e}){return!t?.prints_by_printer||Object.keys(t.prints_by_printer).length===0?c.jsx("p",{className:"text-bambu-gray text-center py-4",children:"No printer data available"}):c.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:Object.entries(t.prints_by_printer).map(([n,r])=>c.jsxs("div",{className:"flex items-center gap-3 p-3 bg-bambu-dark rounded-lg",children:[c.jsx("div",{className:"p-2 bg-bambu-dark-tertiary rounded-lg",children:c.jsx(jo,{className:"w-4 h-4 text-bambu-green"})}),c.jsxs("div",{children:[c.jsx("p",{className:"text-white font-medium text-sm",children:e.get(n)||`Printer ${n}`}),c.jsxs("p",{className:"text-xs text-bambu-gray",children:[r," prints"]})]})]},n))})}function w9e({archives:t,currency:e}){return!t||t.length===0?c.jsx("p",{className:"text-bambu-gray text-center py-4",children:"No print data available"}):c.jsx(f9e,{archives:t,currency:e})}function S9e(){const{data:t,isLoading:e}=yt({queryKey:["failureAnalysis"],queryFn:()=>Pe.getFailureAnalysis({days:30})});if(e)return c.jsx("div",{className:"flex justify-center py-4",children:c.jsx(At,{className:"w-6 h-6 text-bambu-green animate-spin"})});if(!t||t.total_prints===0)return c.jsx("p",{className:"text-bambu-gray text-center py-4",children:"No print data in the last 30 days"});const n=Object.entries(t.failures_by_reason).sort(([,r],[,i])=>i-r).slice(0,5);return c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center gap-4",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(Qr,{className:`w-5 h-5 ${t.failure_rate>20?"text-red-400":t.failure_rate>10?"text-yellow-400":"text-bambu-green"}`}),c.jsxs("span",{className:"text-2xl font-bold text-white",children:[t.failure_rate.toFixed(1),"%"]}),c.jsx("span",{className:"text-sm text-bambu-gray",children:"failure rate"})]}),c.jsxs("div",{className:"text-sm text-bambu-gray",children:[t.failed_prints," / ",t.total_prints," prints failed"]})]}),n.length>0&&c.jsxs("div",{className:"space-y-2",children:[c.jsx("p",{className:"text-xs text-bambu-gray font-medium",children:"Top Failure Reasons"}),n.map(([r,i])=>c.jsxs("div",{className:"flex items-center justify-between text-sm",children:[c.jsx("span",{className:"text-white truncate max-w-[200px]",children:r||"Unknown"}),c.jsx("span",{className:"text-bambu-gray",children:i})]},r))]}),t.trend&&t.trend.length>=2&&c.jsx("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:c.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[c.jsx(jce,{className:`w-4 h-4 ${t.trend[t.trend.length-1].failure_ratePe.getArchives(void 0,1e3,0)}),{data:f}=yt({queryKey:["settings"],queryFn:Pe.getSettings}),g=async E=>{i(!1),n(!0);try{const{blob:S,filename:A}=await Pe.exportStats({format:E,days:90}),T=URL.createObjectURL(S),P=document.createElement("a");P.href=T,P.download=A,P.click(),URL.revokeObjectURL(T),t("Export downloaded")}catch{t("Export failed","error")}finally{n(!1)}},m=f?.currency||"$",x=new Map(u?.map(E=>[String(E.id),E.name])||[]),y=d?.map(E=>E.created_at)||[];if(l)return c.jsx("div",{className:"p-4 md:p-8",children:c.jsx("div",{className:"text-center py-12 text-bambu-gray",children:"Loading statistics..."})});const v=[{id:"quick-stats",title:"Quick Stats",component:c.jsx(g9e,{stats:o,currency:m}),defaultSize:2},{id:"success-rate",title:"Success Rate",component:c.jsx(x9e,{stats:o}),defaultSize:1},{id:"time-accuracy",title:"Time Accuracy",component:c.jsx(b9e,{stats:o,printerMap:x}),defaultSize:1},{id:"filament-types",title:"Filament Types",component:c.jsx(v9e,{stats:o}),defaultSize:1},{id:"failure-analysis",title:"Failure Analysis (30 days)",component:c.jsx(S9e,{}),defaultSize:1},{id:"print-activity",title:"Print Activity",component:c.jsx(y9e,{printDates:y}),defaultSize:2},{id:"prints-by-printer",title:"Prints by Printer",component:c.jsx(_9e,{stats:o,printerMap:x}),defaultSize:2},{id:"filament-trends",title:"Filament Usage Trends",component:c.jsx(w9e,{archives:d||[],currency:m}),defaultSize:4}],b=()=>{localStorage.removeItem("bambusy-dashboard-layout"),a(E=>E+1),t("Layout reset")};return c.jsxs("div",{className:"p-4 md:p-8",children:[c.jsxs("div",{className:"flex items-center justify-between mb-6",children:[c.jsxs("div",{children:[c.jsx("h1",{className:"text-2xl font-bold text-white",children:"Dashboard"}),c.jsx("p",{className:"text-bambu-gray",children:"Drag widgets to rearrange. Click the eye icon to hide."})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs(Ie,{variant:"secondary",onClick:b,children:[c.jsx(Im,{className:"w-4 h-4"}),"Reset Layout"]}),c.jsxs("div",{className:"relative",children:[c.jsxs(Ie,{variant:"secondary",onClick:()=>i(!r),disabled:e,children:[e?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(o1,{className:"w-4 h-4"}),"Export Stats"]}),r&&c.jsxs("div",{className:"absolute right-0 top-full mt-1 w-48 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20",children:[c.jsxs("button",{className:"w-full px-4 py-2 text-left text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center gap-2 rounded-t-lg",onClick:()=>g("csv"),children:[c.jsx(Ya,{className:"w-4 h-4"}),"Export as CSV"]}),c.jsxs("button",{className:"w-full px-4 py-2 text-left text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center gap-2 rounded-b-lg",onClick:()=>g("xlsx"),children:[c.jsx(o1,{className:"w-4 h-4"}),"Export as Excel"]})]})]})]})]}),c.jsx(m9e,{widgets:v,storageKey:"bambusy-dashboard-layout",hideControls:!0},s)]})}function M9e({plug:t,onEdit:e}){const n=Sn(),[r,i]=M.useState(!1),[s,a]=M.useState(!1),[o,l]=M.useState(!1),[u,d]=M.useState(!1),{data:f,isLoading:g,refetch:m}=yt({queryKey:["smart-plug-status",t.id],queryFn:()=>Pe.getSmartPlugStatus(t.id),refetchInterval:3e4}),{data:x}=yt({queryKey:["printers"],queryFn:Pe.getPrinters}),y=x?.find(P=>P.id===t.printer_id),v=_t({mutationFn:P=>Pe.controlSmartPlug(t.id,P),onSuccess:()=>{m()}}),b=_t({mutationFn:P=>Pe.updateSmartPlug(t.id,P),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),t.printer_id&&n.invalidateQueries({queryKey:["smartPlugByPrinter",t.printer_id]})}}),E=_t({mutationFn:()=>Pe.deleteSmartPlug(t.id),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]})}}),S=f?.state==="ON",A=f?.reachable??!1,T=v.isPending;return c.jsxs(c.Fragment,{children:[c.jsx(Nt,{className:"relative",children:c.jsxs(Dt,{className:"p-4",children:[c.jsxs("div",{className:"flex items-start justify-between mb-3",children:[c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("div",{className:`p-2 rounded-lg ${A?S?"bg-bambu-green/20":"bg-bambu-dark":"bg-red-500/20"}`,children:c.jsx(Ox,{className:`w-5 h-5 ${A?S?"text-bambu-green":"text-bambu-gray":"text-red-400"}`})}),c.jsxs("div",{children:[c.jsx("h3",{className:"font-medium text-white",children:t.name}),c.jsx("p",{className:"text-sm text-bambu-gray",children:t.ip_address})]})]}),c.jsx("div",{className:"flex items-center gap-2",children:g?c.jsx(At,{className:"w-4 h-4 text-bambu-gray animate-spin"}):A?c.jsxs("div",{className:"flex items-center gap-1 text-sm",children:[c.jsx(BG,{className:"w-4 h-4 text-bambu-green"}),c.jsx("span",{className:S?"text-bambu-green":"text-bambu-gray",children:f?.state||"Unknown"})]}):c.jsxs("div",{className:"flex items-center gap-1 text-sm text-red-400",children:[c.jsx(SR,{className:"w-4 h-4"}),c.jsx("span",{children:"Offline"})]})})]}),y&&c.jsxs("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:[c.jsx("span",{className:"text-xs text-bambu-gray",children:"Linked to: "}),c.jsx("span",{className:"text-sm text-white",children:y.name})]}),(t.power_alert_enabled||t.schedule_enabled)&&c.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-3",children:[t.power_alert_enabled&&c.jsxs("span",{className:"flex items-center gap-1 px-2 py-0.5 bg-yellow-500/20 text-yellow-400 text-xs rounded-full",children:[c.jsx(fh,{className:"w-3 h-3"}),"Alerts"]}),t.schedule_enabled&&c.jsxs("span",{className:"flex items-center gap-1 px-2 py-0.5 bg-blue-500/20 text-blue-400 text-xs rounded-full",children:[c.jsx(qr,{className:"w-3 h-3"}),t.schedule_on_time&&t.schedule_off_time?`${t.schedule_on_time} - ${t.schedule_off_time}`:t.schedule_on_time?`On ${t.schedule_on_time}`:`Off ${t.schedule_off_time}`]})]}),c.jsxs("div",{className:"flex gap-2 mb-3",children:[c.jsxs(Ie,{size:"sm",variant:S?"primary":"secondary",disabled:!A||T,onClick:()=>a(!0),className:"flex-1",children:[T?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(fd,{className:"w-4 h-4"}),"On"]}),c.jsxs(Ie,{size:"sm",variant:S?"secondary":"primary",disabled:!A||T,onClick:()=>l(!0),className:"flex-1",children:[T?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(yR,{className:"w-4 h-4"}),"Off"]})]}),c.jsxs("button",{onClick:()=>d(!u),className:"w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors",children:[c.jsxs("span",{className:"flex items-center gap-2",children:[c.jsx(vS,{className:"w-4 h-4"}),"Automation Settings"]}),c.jsx("span",{children:u?"-":"+"})]}),u&&c.jsxs("div",{className:"pt-3 border-t border-bambu-dark-tertiary space-y-4",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-sm text-white",children:"Enabled"}),c.jsx("p",{className:"text-xs text-bambu-gray",children:"Enable automation for this plug"})]}),c.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[c.jsx("input",{type:"checkbox",checked:t.enabled,onChange:P=>b.mutate({enabled:P.target.checked}),className:"sr-only peer"}),c.jsx("div",{className:"w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-sm text-white",children:"Auto On"}),c.jsx("p",{className:"text-xs text-bambu-gray",children:"Turn on when print starts"})]}),c.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[c.jsx("input",{type:"checkbox",checked:t.auto_on,onChange:P=>b.mutate({auto_on:P.target.checked}),className:"sr-only peer"}),c.jsx("div",{className:"w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-sm text-white",children:"Auto Off"}),c.jsx("p",{className:"text-xs text-bambu-gray",children:"Turn off when print completes (one-shot)"})]}),c.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[c.jsx("input",{type:"checkbox",checked:t.auto_off,onChange:P=>b.mutate({auto_off:P.target.checked}),className:"sr-only peer"}),c.jsx("div",{className:"w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),t.auto_off&&c.jsxs("div",{className:"space-y-3 pl-4 border-l-2 border-bambu-dark-tertiary",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-sm text-white mb-2",children:"Turn Off Delay Mode"}),c.jsxs("div",{className:"flex gap-2",children:[c.jsxs("button",{onClick:()=>b.mutate({off_delay_mode:"time"}),className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-sm transition-colors ${t.off_delay_mode==="time"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:[c.jsx(ti,{className:"w-4 h-4"}),"Time"]}),c.jsxs("button",{onClick:()=>b.mutate({off_delay_mode:"temperature"}),className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-sm transition-colors ${t.off_delay_mode==="temperature"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:[c.jsx($p,{className:"w-4 h-4"}),"Temp"]})]})]}),t.off_delay_mode==="time"?c.jsxs("div",{children:[c.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Delay (minutes)"}),c.jsx("input",{type:"number",min:"1",max:"60",value:t.off_delay_minutes,onChange:P=>b.mutate({off_delay_minutes:parseInt(P.target.value)||5}),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none"})]}):c.jsxs("div",{children:[c.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Temperature threshold (C)"}),c.jsx("input",{type:"number",min:"30",max:"100",value:t.off_temp_threshold,onChange:P=>b.mutate({off_temp_threshold:parseInt(P.target.value)||70}),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none"}),c.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Turns off when nozzle cools below this temperature"})]})]}),c.jsxs("div",{className:"flex gap-2 pt-2",children:[c.jsxs(Ie,{size:"sm",variant:"secondary",onClick:()=>e(t),className:"flex-1",children:[c.jsx(vR,{className:"w-4 h-4"}),"Edit"]}),c.jsx(Ie,{size:"sm",variant:"secondary",onClick:()=>i(!0),className:"text-red-400 hover:text-red-300",children:c.jsx(kn,{className:"w-4 h-4"})})]})]})]})}),r&&c.jsx(Kr,{title:"Delete Smart Plug",message:`Are you sure you want to delete "${t.name}"? This cannot be undone.`,confirmText:"Delete",variant:"danger",onConfirm:()=>{E.mutate(),i(!1)},onCancel:()=>i(!1)}),s&&c.jsx(Kr,{title:"Turn On Smart Plug",message:`Are you sure you want to turn on "${t.name}"?`,confirmText:"Turn On",variant:"default",onConfirm:()=>{v.mutate("on"),a(!1)},onCancel:()=>a(!1)}),o&&c.jsx(Kr,{title:"Turn Off Smart Plug",message:`Are you sure you want to turn off "${t.name}"? This will cut power to the connected device.`,confirmText:"Turn Off",variant:"danger",onConfirm:()=>{v.mutate("off"),l(!1)},onCancel:()=>l(!1)})]})}function A9e({plug:t,onClose:e}){const n=Sn(),r=!!t,[i,s]=M.useState(t?.name||""),[a,o]=M.useState(t?.ip_address||""),[l,u]=M.useState(t?.username||""),[d,f]=M.useState(t?.password||""),[g,m]=M.useState(t?.printer_id||null),[x,y]=M.useState(null),[v,b]=M.useState(null),[E,S]=M.useState(t?.power_alert_enabled||!1),[A,T]=M.useState(t?.power_alert_high?.toString()||""),[P,C]=M.useState(t?.power_alert_low?.toString()||""),[I,N]=M.useState(t?.schedule_enabled||!1),[D,F]=M.useState(t?.schedule_on_time||""),[L,q]=M.useState(t?.schedule_off_time||""),{data:R}=yt({queryKey:["printers"],queryFn:Pe.getPrinters}),{data:V}=yt({queryKey:["smart-plugs"],queryFn:Pe.getSmartPlugs});M.useEffect(()=>{const $=ee=>{ee.key==="Escape"&&e()};return window.addEventListener("keydown",$),()=>window.removeEventListener("keydown",$)},[e]);const K=_t({mutationFn:()=>Pe.testSmartPlugConnection(a,l||null,d||null),onSuccess:$=>{y($),b(null),!i&&$.device_name&&s($.device_name)},onError:$=>{y(null),b($.message)}}),W=_t({mutationFn:$=>Pe.createSmartPlug($),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),e()},onError:$=>{b($.message)}}),ne=_t({mutationFn:$=>Pe.updateSmartPlug(t.id,$),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),e()},onError:$=>{b($.message)}}),Y=R?.filter($=>!V?.some(ae=>ae.printer_id===$.id&&ae.id!==t?.id)),Z=$=>{if($.preventDefault(),b(null),!i.trim()){b("Name is required");return}if(!a.trim()){b("IP address is required");return}const ee={name:i.trim(),ip_address:a.trim(),username:l.trim()||null,password:d.trim()||null,printer_id:g,power_alert_enabled:E,power_alert_high:A?parseFloat(A):null,power_alert_low:P?parseFloat(P):null,schedule_enabled:I,schedule_on_time:D||null,schedule_off_time:L||null};r?ne.mutate(ee):W.mutate(ee)},U=W.isPending||ne.isPending;return c.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:e,children:c.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-md",onClick:$=>$.stopPropagation(),children:[c.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[c.jsx("h2",{className:"text-lg font-semibold text-white",children:r?"Edit Smart Plug":"Add Smart Plug"}),c.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:c.jsx(Gt,{className:"w-5 h-5"})})]}),c.jsxs("form",{onSubmit:Z,className:"p-6 space-y-4",children:[v&&c.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:v}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"IP Address *"}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx("input",{type:"text",value:a,onChange:$=>{o($.target.value),y(null)},placeholder:"192.168.1.100",className:"flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),c.jsxs(Ie,{type:"button",variant:"secondary",onClick:()=>K.mutate(),disabled:!a.trim()||K.isPending,children:[K.isPending?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(BG,{className:"w-4 h-4"}),"Test"]})]})]}),x&&c.jsx("div",{className:`p-3 rounded-lg flex items-center gap-2 ${x.success?"bg-bambu-green/20 border border-bambu-green/50 text-bambu-green":"bg-red-500/20 border border-red-500/50 text-red-400"}`,children:x.success?c.jsxs(c.Fragment,{children:[c.jsx(ds,{className:"w-5 h-5"}),c.jsxs("div",{children:[c.jsx("p",{className:"font-medium",children:"Connected!"}),c.jsxs("p",{className:"text-sm opacity-80",children:[x.device_name&&`Device: ${x.device_name} - `,"State: ",x.state]})]})]}):c.jsxs(c.Fragment,{children:[c.jsx(SR,{className:"w-5 h-5"}),c.jsx("span",{children:"Connection failed"})]})}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name *"}),c.jsx("input",{type:"text",value:i,onChange:$=>s($.target.value),placeholder:"Living Room Plug",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),c.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Username"}),c.jsx("input",{type:"text",value:l,onChange:$=>u($.target.value),placeholder:"admin",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Password"}),c.jsx("input",{type:"password",value:d,onChange:$=>f($.target.value),placeholder:"********",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]})]}),c.jsx("p",{className:"text-xs text-bambu-gray -mt-2",children:"Leave empty if your Tasmota device doesn't require authentication"}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Link to Printer"}),c.jsxs("select",{value:g??"",onChange:$=>m($.target.value?Number($.target.value):null),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[c.jsx("option",{value:"",children:"No printer (manual control only)"}),Y?.map($=>c.jsx("option",{value:$.id,children:$.name},$.id))]}),c.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Linking enables automatic on/off when prints start/complete"})]}),c.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:[c.jsxs("div",{className:"flex items-center justify-between mb-3",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(fh,{className:"w-4 h-4 text-bambu-green"}),c.jsx("span",{className:"text-white font-medium",children:"Power Alerts"})]}),c.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[c.jsx("input",{type:"checkbox",checked:E,onChange:$=>S($.target.checked),className:"sr-only peer"}),c.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),E&&c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Alert if above (W)"}),c.jsx("input",{type:"number",value:A,onChange:$=>T($.target.value),placeholder:"e.g. 200",min:"0",max:"5000",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Alert if below (W)"}),c.jsx("input",{type:"number",value:P,onChange:$=>C($.target.value),placeholder:"e.g. 10",min:"0",max:"5000",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]})]}),c.jsx("p",{className:"text-xs text-bambu-gray",children:"Get notified when power consumption crosses these thresholds. Leave empty to disable that direction."})]})]}),c.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:[c.jsxs("div",{className:"flex items-center justify-between mb-3",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(ti,{className:"w-4 h-4 text-bambu-green"}),c.jsx("span",{className:"text-white font-medium",children:"Daily Schedule"})]}),c.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[c.jsx("input",{type:"checkbox",checked:I,onChange:$=>N($.target.checked),className:"sr-only peer"}),c.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),I&&c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Turn On at"}),c.jsx("input",{type:"time",value:D,onChange:$=>F($.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Turn Off at"}),c.jsx("input",{type:"time",value:L,onChange:$=>q($.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]})]}),c.jsx("p",{className:"text-xs text-bambu-gray",children:"Automatically turn the plug on/off at these times daily. Leave empty to skip that action."})]})]}),c.jsxs("div",{className:"flex gap-3 pt-2",children:[c.jsx(Ie,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:"Cancel"}),c.jsxs(Ie,{type:"submit",disabled:U,className:"flex-1",children:[U?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(To,{className:"w-4 h-4"}),r?"Save":"Add"]})]})]})]})})}function tr({checked:t,onChange:e,disabled:n}){const r=i=>{i.preventDefault(),i.stopPropagation(),n||e(!t)};return c.jsx("button",{type:"button",role:"switch","aria-checked":t,disabled:n,onClick:r,className:`relative inline-flex w-11 h-7 md:w-9 md:h-5 rounded-full transition-colors flex-shrink-0 focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${n?"bg-bambu-dark-tertiary/50 cursor-not-allowed opacity-50":t?"bg-bambu-green cursor-pointer":"bg-bambu-dark-tertiary cursor-pointer hover:bg-bambu-dark-tertiary/80"}`,children:c.jsx("span",{className:`pointer-events-none absolute top-[3px] md:top-[2px] left-[3px] md:left-[2px] w-5 h-5 md:w-4 md:h-4 bg-white rounded-full shadow transition-transform duration-200 ease-in-out ${t?"translate-x-4":"translate-x-0"}`})})}const T9e={callmebot:"CallMeBot/WhatsApp",ntfy:"ntfy",pushover:"Pushover",telegram:"Telegram",email:"Email",discord:"Discord",webhook:"Webhook"};function C9e({provider:t,onEdit:e}){const n=Sn(),[r,i]=M.useState(!1),[s,a]=M.useState(!1),[o,l]=M.useState(null),{data:u}=yt({queryKey:["printers"],queryFn:Pe.getPrinters}),d=u?.find(y=>y.id===t.printer_id),f=_t({mutationFn:y=>Pe.updateNotificationProvider(t.id,y),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-providers"]})}}),g=_t({mutationFn:()=>Pe.deleteNotificationProvider(t.id),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-providers"]})}}),m=_t({mutationFn:()=>Pe.testNotificationProvider(t.id),onSuccess:y=>{l(y),n.invalidateQueries({queryKey:["notification-providers"]})},onError:y=>{l({success:!1,message:y.message})}}),x=y=>y||"";return c.jsxs(c.Fragment,{children:[c.jsx(Nt,{className:"relative",children:c.jsxs(Dt,{className:"p-4",children:[c.jsxs("div",{className:"flex items-start justify-between mb-3",children:[c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("div",{className:`p-2 rounded-lg ${t.enabled?"bg-bambu-green/20":"bg-bambu-dark"}`,children:c.jsx(fh,{className:`w-5 h-5 ${t.enabled?"text-bambu-green":"text-bambu-gray"}`})}),c.jsxs("div",{children:[c.jsx("h3",{className:"font-medium text-white",children:t.name}),c.jsx("p",{className:"text-sm text-bambu-gray",children:T9e[t.provider_type]||t.provider_type})]})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[t.last_success&&c.jsxs("span",{className:"text-xs text-bambu-green",children:["Last sent: ",new Date(t.last_success).toLocaleDateString()]}),t.last_error&&t.last_error_at&&(!t.last_success||new Date(t.last_error_at)>new Date(t.last_success))&&c.jsx("span",{className:"text-xs text-red-400",title:t.last_error,children:"Error"})]})]}),d&&c.jsxs("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:[c.jsx("span",{className:"text-xs text-bambu-gray",children:"Printer: "}),c.jsx("span",{className:"text-sm text-white",children:d.name})]}),!d&&!t.printer_id&&c.jsx("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:c.jsx("span",{className:"text-xs text-bambu-gray",children:"All printers"})}),c.jsxs("div",{className:"mb-3 flex flex-wrap gap-1",children:[t.on_print_start&&c.jsx("span",{className:"px-2 py-0.5 bg-blue-500/20 text-blue-400 text-xs rounded",children:"Start"}),t.on_print_complete&&c.jsx("span",{className:"px-2 py-0.5 bg-bambu-green/20 text-bambu-green text-xs rounded",children:"Complete"}),t.on_print_failed&&c.jsx("span",{className:"px-2 py-0.5 bg-red-500/20 text-red-400 text-xs rounded",children:"Failed"}),t.on_print_stopped&&c.jsx("span",{className:"px-2 py-0.5 bg-orange-500/20 text-orange-400 text-xs rounded",children:"Stopped"}),t.on_print_progress&&c.jsx("span",{className:"px-2 py-0.5 bg-yellow-500/20 text-yellow-400 text-xs rounded",children:"Progress"}),t.on_printer_offline&&c.jsx("span",{className:"px-2 py-0.5 bg-gray-500/20 text-gray-400 text-xs rounded",children:"Offline"}),t.on_printer_error&&c.jsx("span",{className:"px-2 py-0.5 bg-rose-500/20 text-rose-400 text-xs rounded",children:"Error"}),t.on_filament_low&&c.jsx("span",{className:"px-2 py-0.5 bg-cyan-500/20 text-cyan-400 text-xs rounded",children:"Low Filament"}),t.on_maintenance_due&&c.jsx("span",{className:"px-2 py-0.5 bg-purple-500/20 text-purple-400 text-xs rounded",children:"Maintenance"}),t.quiet_hours_enabled&&c.jsxs("span",{className:"px-2 py-0.5 bg-indigo-500/20 text-indigo-400 text-xs rounded flex items-center gap-1",children:[c.jsx(l1,{className:"w-3 h-3"}),"Quiet"]}),t.daily_digest_enabled&&c.jsxs("span",{className:"px-2 py-0.5 bg-emerald-500/20 text-emerald-400 text-xs rounded flex items-center gap-1",children:[c.jsx(qr,{className:"w-3 h-3"}),"Digest ",t.daily_digest_time]})]}),c.jsx("div",{className:"mb-3",children:c.jsxs(Ie,{size:"sm",variant:"secondary",disabled:m.isPending,onClick:()=>{l(null),m.mutate()},className:"w-full",children:[m.isPending?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(_R,{className:"w-4 h-4"}),"Send Test Notification"]})}),o&&c.jsxs("div",{className:`mb-3 p-2 rounded-lg flex items-center gap-2 text-sm ${o.success?"bg-bambu-green/20 text-bambu-green":"bg-red-500/20 text-red-400"}`,children:[o.success?c.jsx(ds,{className:"w-4 h-4"}):c.jsx(hd,{className:"w-4 h-4"}),c.jsx("span",{children:o.message})]}),c.jsxs("button",{onClick:()=>a(!s),className:"w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors border-t border-bambu-dark-tertiary",children:[c.jsxs("span",{className:"flex items-center gap-2",children:[c.jsx(vS,{className:"w-4 h-4"}),"Event Settings"]}),s?c.jsx(mS,{className:"w-4 h-4"}):c.jsx(ef,{className:"w-4 h-4"})]}),s&&c.jsxs("div",{className:"pt-3 border-t border-bambu-dark-tertiary space-y-4",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-sm text-white",children:"Enabled"}),c.jsx("p",{className:"text-xs text-bambu-gray",children:"Send notifications from this provider"})]}),c.jsx(tr,{checked:t.enabled,onChange:y=>f.mutate({enabled:y})})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:"Print Events"}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("p",{className:"text-sm text-white",children:"Print Started"}),c.jsx(tr,{checked:t.on_print_start,onChange:y=>f.mutate({on_print_start:y})})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("p",{className:"text-sm text-white",children:"Print Completed"}),c.jsx(tr,{checked:t.on_print_complete,onChange:y=>f.mutate({on_print_complete:y})})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("p",{className:"text-sm text-white",children:"Print Failed"}),c.jsx(tr,{checked:t.on_print_failed,onChange:y=>f.mutate({on_print_failed:y})})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("p",{className:"text-sm text-white",children:"Print Stopped"}),c.jsx(tr,{checked:t.on_print_stopped,onChange:y=>f.mutate({on_print_stopped:y})})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-sm text-white",children:"Progress Milestones"}),c.jsx("p",{className:"text-xs text-bambu-gray",children:"Notify at 25%, 50%, 75%"})]}),c.jsx(tr,{checked:t.on_print_progress,onChange:y=>f.mutate({on_print_progress:y})})]})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:"Printer Status"}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("p",{className:"text-sm text-white",children:"Printer Offline"}),c.jsx(tr,{checked:t.on_printer_offline,onChange:y=>f.mutate({on_printer_offline:y})})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("p",{className:"text-sm text-white",children:"Printer Error"}),c.jsx(tr,{checked:t.on_printer_error,onChange:y=>f.mutate({on_printer_error:y})})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("p",{className:"text-sm text-white",children:"Low Filament"}),c.jsx(tr,{checked:t.on_filament_low,onChange:y=>f.mutate({on_filament_low:y})})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-sm text-white",children:"Maintenance Due"}),c.jsx("p",{className:"text-xs text-bambu-gray",children:"Notify when maintenance is needed"})]}),c.jsx(tr,{checked:t.on_maintenance_due??!1,onChange:y=>f.mutate({on_maintenance_due:y})})]})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(l1,{className:"w-4 h-4 text-purple-400"}),c.jsx("p",{className:"text-sm text-white",children:"Quiet Hours"})]}),c.jsx(tr,{checked:t.quiet_hours_enabled,onChange:y=>f.mutate({quiet_hours_enabled:y})})]}),t.quiet_hours_enabled&&c.jsxs("div",{className:"pl-4 border-l-2 border-bambu-dark-tertiary space-y-2",children:[c.jsx("p",{className:"text-xs text-bambu-gray",children:"No notifications during these hours"}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(ti,{className:"w-4 h-4 text-bambu-gray"}),c.jsxs("span",{className:"text-sm text-white",children:[x(t.quiet_hours_start)||"22:00"," - ",x(t.quiet_hours_end)||"07:00"]})]}),c.jsx("p",{className:"text-xs text-bambu-gray",children:"Edit provider to change quiet hours"})]})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(qr,{className:"w-4 h-4 text-emerald-400"}),c.jsx("p",{className:"text-sm text-white",children:"Daily Digest"})]}),c.jsx(tr,{checked:t.daily_digest_enabled,onChange:y=>f.mutate({daily_digest_enabled:y})})]}),t.daily_digest_enabled&&c.jsxs("div",{className:"pl-4 border-l-2 border-bambu-dark-tertiary space-y-2",children:[c.jsx("p",{className:"text-xs text-bambu-gray",children:"Batch notifications into a single daily summary"}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(ti,{className:"w-4 h-4 text-bambu-gray"}),c.jsxs("span",{className:"text-sm text-white",children:["Send at ",x(t.daily_digest_time)||"08:00"]})]}),c.jsx("p",{className:"text-xs text-bambu-gray",children:"Edit provider to change digest time"})]})]}),c.jsxs("div",{className:"flex gap-2 pt-2",children:[c.jsxs(Ie,{size:"sm",variant:"secondary",onClick:()=>e(t),className:"flex-1",children:[c.jsx(vR,{className:"w-4 h-4"}),"Edit"]}),c.jsx(Ie,{size:"sm",variant:"secondary",onClick:()=>i(!0),className:"text-red-400 hover:text-red-300",children:c.jsx(kn,{className:"w-4 h-4"})})]})]})]})}),r&&c.jsx(Kr,{title:"Delete Notification Provider",message:`Are you sure you want to delete "${t.name}"? This cannot be undone.`,confirmText:"Delete",variant:"danger",onConfirm:()=>{g.mutate(),i(!1)},onCancel:()=>i(!1)})]})}const F9=[{value:"discord",label:"Discord",description:"Send to Discord channel via webhook"},{value:"telegram",label:"Telegram",description:"Notifications via Telegram bot"},{value:"ntfy",label:"ntfy",description:"Free, self-hostable push notifications"},{value:"pushover",label:"Pushover",description:"Simple, reliable push notifications"},{value:"email",label:"Email",description:"SMTP email notifications"},{value:"callmebot",label:"CallMeBot/WhatsApp",description:"Free WhatsApp notifications via CallMeBot"},{value:"webhook",label:"Webhook",description:"Generic HTTP POST to any URL"}];function N9e({provider:t,onClose:e}){const n=Sn(),r=!!t,[i,s]=M.useState(t?.name||""),[a,o]=M.useState(t?.provider_type||"discord"),[l,u]=M.useState(t?.printer_id||null),[d,f]=M.useState(t?.quiet_hours_enabled||!1),[g,m]=M.useState(t?.quiet_hours_start||"22:00"),[x,y]=M.useState(t?.quiet_hours_end||"07:00"),[v,b]=M.useState(t?.daily_digest_enabled||!1),[E,S]=M.useState(t?.daily_digest_time||"08:00"),[A,T]=M.useState(t?.on_print_start??!1),[P,C]=M.useState(t?.on_print_complete??!0),[I,N]=M.useState(t?.on_print_failed??!0),[D,F]=M.useState(t?.on_print_stopped??!0),[L,q]=M.useState(t?.on_print_progress??!1),[R,V]=M.useState(t?.on_printer_offline??!1),[K,W]=M.useState(t?.on_printer_error??!1),[ne,Y]=M.useState(t?.on_filament_low??!1),[Z,U]=M.useState(t?.on_maintenance_due??!1),[$,ee]=M.useState(t?.config?Object.fromEntries(Object.entries(t.config).map(([G,J])=>[G,String(J)])):{}),[ae,fe]=M.useState(null),[ue,xe]=M.useState(null),{data:Me}=yt({queryKey:["printers"],queryFn:Pe.getPrinters});M.useEffect(()=>{const G=J=>{J.key==="Escape"&&e()};return window.addEventListener("keydown",G),()=>window.removeEventListener("keydown",G)},[e]);const se=_t({mutationFn:()=>Pe.testNotificationConfig({provider_type:a,config:$}),onSuccess:G=>{fe(G),xe(null)},onError:G=>{fe({success:!1,message:G.message})}}),ve=_t({mutationFn:G=>Pe.createNotificationProvider(G),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-providers"]}),e()},onError:G=>{xe(G.message)}}),je=_t({mutationFn:G=>Pe.updateNotificationProvider(t.id,G),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-providers"]}),e()},onError:G=>{xe(G.message)}}),de=G=>{if(G.preventDefault(),xe(null),!i.trim()){xe("Name is required");return}const J=z(a);for(const ke of J)if(!$[ke.key]?.trim()){xe(`${ke.label} is required`);return}const le={name:i.trim(),provider_type:a,config:$,printer_id:l,quiet_hours_enabled:d,quiet_hours_start:d?g:null,quiet_hours_end:d?x:null,daily_digest_enabled:v,daily_digest_time:v?E:null,on_print_start:A,on_print_complete:P,on_print_failed:I,on_print_stopped:D,on_print_progress:L,on_printer_offline:R,on_printer_error:K,on_filament_low:ne,on_maintenance_due:Z};r?je.mutate(le):ve.mutate(le)},ut=ve.isPending||je.isPending,H=G=>{switch(G){case"callmebot":return[{key:"phone",label:"Phone Number",placeholder:"+1234567890",type:"text",required:!0},{key:"apikey",label:"API Key",placeholder:"Your CallMeBot API key",type:"text",required:!0}];case"ntfy":return[{key:"server",label:"Server URL",placeholder:"https://ntfy.sh",type:"text",required:!1},{key:"topic",label:"Topic",placeholder:"my-bambuddy",type:"text",required:!0},{key:"auth_token",label:"Auth Token",placeholder:"Optional authentication",type:"password",required:!1}];case"pushover":return[{key:"user_key",label:"User Key",placeholder:"Your Pushover user key",type:"text",required:!0},{key:"app_token",label:"App Token",placeholder:"Your Pushover app token",type:"text",required:!0},{key:"priority",label:"Priority",placeholder:"0 (normal)",type:"number",required:!1}];case"telegram":return[{key:"bot_token",label:"Bot Token",placeholder:"Bot token from @BotFather",type:"password",required:!0},{key:"chat_id",label:"Chat ID",placeholder:"Your chat or group ID",type:"text",required:!0}];case"email":return[{key:"smtp_server",label:"SMTP Server",placeholder:"smtp.gmail.com",type:"text",required:!0},{key:"smtp_port",label:"SMTP Port",placeholder:"587",type:"number",required:!1},{key:"security",label:"Security",type:"select",required:!1,options:[{value:"starttls",label:"STARTTLS (Port 587)"},{value:"ssl",label:"SSL/TLS (Port 465)"},{value:"none",label:"None (Port 25)"}]},{key:"auth_enabled",label:"Authentication",type:"select",required:!1,options:[{value:"true",label:"Enabled"},{value:"false",label:"Disabled"}]},{key:"username",label:"Username",placeholder:"your@email.com",type:"text",required:!1},{key:"password",label:"Password",placeholder:"App password",type:"password",required:!1},{key:"from_email",label:"From Email",placeholder:"your@email.com",type:"text",required:!0},{key:"to_email",label:"To Email",placeholder:"recipient@email.com",type:"text",required:!0}];case"discord":return[{key:"webhook_url",label:"Webhook URL",placeholder:"https://discord.com/api/webhooks/...",type:"text",required:!0}];case"webhook":return[{key:"webhook_url",label:"Webhook URL",placeholder:"https://example.com/webhook",type:"text",required:!0},{key:"auth_header",label:"Authorization",placeholder:"Bearer token (optional)",type:"password",required:!1},{key:"field_title",label:"Title Field Name",placeholder:"title",type:"text",required:!1},{key:"field_message",label:"Message Field Name",placeholder:"message",type:"text",required:!1}];default:return[]}},z=G=>H(G).filter(J=>J.required),re=H(a);return c.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4 overflow-y-auto",onClick:e,children:c.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg my-8",onClick:G=>G.stopPropagation(),children:[c.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[c.jsx("h2",{className:"text-lg font-semibold text-white",children:r?"Edit Notification Provider":"Add Notification Provider"}),c.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:c.jsx(Gt,{className:"w-5 h-5"})})]}),c.jsxs("form",{onSubmit:de,className:"p-6 space-y-4",children:[ue&&c.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:ue}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name *"}),c.jsx("input",{type:"text",value:i,onChange:G=>s(G.target.value),placeholder:"My Notifications",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Provider Type *"}),c.jsx("select",{value:a,onChange:G=>{o(G.target.value),ee({}),fe(null)},disabled:r,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none disabled:opacity-50",children:F9.map(G=>c.jsx("option",{value:G.value,children:G.label},G.value))}),c.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:F9.find(G=>G.value===a)?.description})]}),c.jsxs("div",{className:"space-y-3",children:[c.jsx("p",{className:"text-sm text-bambu-gray",children:"Configuration"}),re.map(G=>c.jsxs("div",{children:[c.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[G.label," ",G.required&&"*"]}),G.type==="select"&&G.options?c.jsx("select",{value:$[G.key]||G.options[0]?.value||"",onChange:J=>{ee({...$,[G.key]:J.target.value}),fe(null)},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:G.options.map(J=>c.jsx("option",{value:J.value,children:J.label},J.value))}):c.jsx("input",{type:G.type,value:$[G.key]||"",onChange:J=>{ee({...$,[G.key]:J.target.value}),fe(null)},placeholder:G.placeholder,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]},G.key))]}),c.jsx("div",{className:"flex gap-2",children:c.jsxs(Ie,{type:"button",variant:"secondary",onClick:()=>{fe(null),se.mutate()},disabled:se.isPending||!$[z(a)[0]?.key],className:"flex-1",children:[se.isPending?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(_R,{className:"w-4 h-4"}),"Test Configuration"]})}),ae&&c.jsx("div",{className:`p-3 rounded-lg flex items-center gap-2 ${ae.success?"bg-bambu-green/20 border border-bambu-green/50 text-bambu-green":"bg-red-500/20 border border-red-500/50 text-red-400"}`,children:ae.success?c.jsxs(c.Fragment,{children:[c.jsx(ds,{className:"w-5 h-5"}),c.jsx("span",{children:ae.message})]}):c.jsxs(c.Fragment,{children:[c.jsx(hd,{className:"w-5 h-5"}),c.jsx("span",{children:ae.message})]})}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Printer Filter"}),c.jsxs("select",{value:l??"",onChange:G=>u(G.target.value?Number(G.target.value):null),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[c.jsx("option",{value:"",children:"All printers"}),Me?.map(G=>c.jsx("option",{value:G.id,children:G.name},G.id))]}),c.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Only send notifications for events from this printer"})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("label",{className:"text-sm text-white",children:"Quiet Hours (Do Not Disturb)"}),c.jsx(tr,{checked:d,onChange:f})]}),d&&c.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[c.jsxs("div",{children:[c.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Start"}),c.jsx("input",{type:"time",value:g,onChange:G=>m(G.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"End"}),c.jsx("input",{type:"time",value:x,onChange:G=>y(G.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]})]})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("label",{className:"text-sm text-white",children:"Daily Digest"}),c.jsx("p",{className:"text-xs text-bambu-gray",children:"Batch notifications into a single daily summary"})]}),c.jsx(tr,{checked:v,onChange:b})]}),v&&c.jsxs("div",{children:[c.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Send digest at"}),c.jsx("input",{type:"time",value:E,onChange:G=>S(G.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),c.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Events will be collected and sent as a single summary at this time"})]})]}),c.jsxs("div",{className:"space-y-3",children:[c.jsx("p",{className:"text-sm text-bambu-gray",children:"Notification Events"}),c.jsxs("div",{className:"space-y-2 p-3 bg-bambu-dark rounded-lg",children:[c.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide mb-2",children:"Print Events"}),c.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm text-white",children:"Start"}),c.jsx(tr,{checked:A,onChange:T})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm text-white",children:"Complete"}),c.jsx(tr,{checked:P,onChange:C})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm text-white",children:"Failed"}),c.jsx(tr,{checked:I,onChange:N})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm text-white",children:"Stopped"}),c.jsx(tr,{checked:D,onChange:F})]}),c.jsxs("div",{className:"flex items-center justify-between col-span-2",children:[c.jsxs("div",{children:[c.jsx("span",{className:"text-sm text-white",children:"Progress"}),c.jsx("span",{className:"text-xs text-bambu-gray ml-1",children:"(25%, 50%, 75%)"})]}),c.jsx(tr,{checked:L,onChange:q})]})]})]}),c.jsxs("div",{className:"space-y-2 p-3 bg-bambu-dark rounded-lg",children:[c.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide mb-2",children:"Printer Status"}),c.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm text-white",children:"Offline"}),c.jsx(tr,{checked:R,onChange:V})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm text-white",children:"Error"}),c.jsx(tr,{checked:K,onChange:W})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm text-white",children:"Low Filament"}),c.jsx(tr,{checked:ne,onChange:Y})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm text-white",children:"Maintenance"}),c.jsx(tr,{checked:Z,onChange:U})]})]})]})]}),c.jsxs("div",{className:"flex gap-3 pt-2",children:[c.jsx(Ie,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:"Cancel"}),c.jsxs(Ie,{type:"submit",disabled:ut,className:"flex-1",children:[ut?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(To,{className:"w-4 h-4"}),r?"Save":"Add"]})]})]})]})})}function k9e({template:t,onClose:e}){const n=Sn(),r=M.useRef(null),[i,s]=M.useState(t.title_template),[a,o]=M.useState(t.body_template),[l,u]=M.useState(null),[d,f]=M.useState(!0),{data:g}=yt({queryKey:["template-variables"],queryFn:Pe.getTemplateVariables}),m=g?.find(T=>T.event_type===t.event_type),{data:x,isLoading:y}=yt({queryKey:["template-preview",t.event_type,i,a],queryFn:()=>Pe.previewTemplate({event_type:t.event_type,title_template:i,body_template:a}),enabled:d&&i.length>0&&a.length>0});M.useEffect(()=>{const T=P=>{P.key==="Escape"&&e()};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)},[e]);const v=_t({mutationFn:T=>Pe.updateNotificationTemplate(t.id,T),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-templates"]}),e()},onError:T=>{u(T.message)}}),b=_t({mutationFn:()=>Pe.resetNotificationTemplate(t.id),onSuccess:T=>{s(T.title_template),o(T.body_template),n.invalidateQueries({queryKey:["notification-templates"]})},onError:T=>{u(T.message)}}),E=T=>{if(T.preventDefault(),u(null),!i.trim()){u("Title is required");return}if(!a.trim()){u("Body is required");return}v.mutate({title_template:i,body_template:a})},S=T=>{const P=r.current;if(!P)return;const C=P.selectionStart,I=P.selectionEnd,N=a,D=N.substring(0,C),F=N.substring(I),L=D+`{${T}}`+F;o(L),setTimeout(()=>{P.focus();const q=C+T.length+2;P.setSelectionRange(q,q)},0)},A=i!==t.title_template||a!==t.body_template;return c.jsx("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4",children:c.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-2xl max-h-[90vh] flex flex-col",children:[c.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0",children:[c.jsxs("h2",{className:"text-lg font-semibold text-white",children:["Edit Template: ",t.name]}),c.jsx("button",{onClick:e,className:"p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",children:c.jsx(Gt,{className:"w-5 h-5 text-bambu-gray"})})]}),c.jsxs("form",{onSubmit:E,className:"flex-1 overflow-y-auto p-4 space-y-4",children:[l&&c.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded text-red-400 text-sm",children:l}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:"Title"}),c.jsx("input",{type:"text",value:i,onChange:T=>s(T.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white focus:outline-none focus:ring-1 focus:ring-bambu-green",placeholder:"Notification title..."})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:"Body"}),c.jsx("textarea",{ref:r,value:a,onChange:T=>o(T.target.value),rows:4,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white focus:outline-none focus:ring-1 focus:ring-bambu-green font-mono text-sm resize-none",placeholder:"Notification body..."})]}),m&&c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-2",children:"Available Variables"}),c.jsx("div",{className:"flex flex-wrap gap-2",children:m.variables.map(T=>c.jsxs("button",{type:"button",onClick:()=>S(T),className:"inline-flex items-center gap-1 px-2 py-1 bg-bambu-dark hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-xs text-bambu-gray hover:text-white transition-colors",children:[c.jsx(fr,{className:"w-3 h-3"}),T]},T))}),c.jsx("p",{className:"text-xs text-bambu-gray/60 mt-1",children:"Click to insert at cursor position in body"})]}),c.jsxs("div",{children:[c.jsxs("div",{className:"flex items-center justify-between mb-2",children:[c.jsxs("label",{className:"text-sm font-medium text-bambu-gray flex items-center gap-2",children:[c.jsx(o0,{className:"w-4 h-4"}),"Live Preview"]}),c.jsx("button",{type:"button",onClick:()=>f(!d),className:"text-xs text-bambu-green hover:text-bambu-green-light",children:d?"Hide":"Show"})]}),d&&c.jsx("div",{className:"bg-bambu-dark border border-bambu-dark-tertiary rounded p-3 space-y-2",children:y?c.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-sm",children:[c.jsx(At,{className:"w-4 h-4 animate-spin"}),"Loading preview..."]}):x?c.jsxs(c.Fragment,{children:[c.jsxs("div",{children:[c.jsx("span",{className:"text-xs text-bambu-gray",children:"Title:"}),c.jsx("div",{className:"text-white font-medium",children:x.title})]}),c.jsxs("div",{children:[c.jsx("span",{className:"text-xs text-bambu-gray",children:"Body:"}),c.jsx("div",{className:"text-white whitespace-pre-wrap text-sm",children:x.body})]})]}):c.jsx("div",{className:"text-bambu-gray text-sm",children:"Enter template content to see preview"})})]})]}),c.jsxs("div",{className:"flex items-center justify-between p-4 border-t border-bambu-dark-tertiary shrink-0",children:[c.jsxs(Ie,{type:"button",variant:"ghost",onClick:()=>b.mutate(),disabled:b.isPending,className:"text-orange-400 hover:text-orange-300",children:[b.isPending?c.jsx(At,{className:"w-4 h-4 animate-spin mr-2"}):c.jsx(Im,{className:"w-4 h-4 mr-2"}),"Reset to Default"]}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(Ie,{type:"button",variant:"secondary",onClick:e,children:"Cancel"}),c.jsxs(Ie,{onClick:E,disabled:v.isPending||!A,children:[v.isPending?c.jsx(At,{className:"w-4 h-4 animate-spin mr-2"}):c.jsx(To,{className:"w-4 h-4 mr-2"}),"Save"]})]})]})]})})}const P9e={print_start:"Print Started",print_complete:"Print Complete",print_failed:"Print Failed",print_stopped:"Print Stopped",print_progress:"Progress",printer_offline:"Printer Offline",printer_error:"Printer Error",filament_low:"Low Filament",maintenance_due:"Maintenance Due",test:"Test"},R9e={print_start:"text-blue-400",print_complete:"text-bambu-green",print_failed:"text-red-400",print_stopped:"text-orange-400",print_progress:"text-yellow-400",printer_offline:"text-gray-400",printer_error:"text-rose-400",filament_low:"text-cyan-400",maintenance_due:"text-purple-400",test:"text-bambu-gray"};function D9e({onClose:t}){const e=Sn(),{showToast:n}=ri(),[r,i]=M.useState(7),[s,a]=M.useState(null),[o,l]=M.useState(!1),{data:u,isLoading:d,refetch:f,isRefetching:g}=yt({queryKey:["notification-logs",r,o],queryFn:()=>Pe.getNotificationLogs({days:r,limit:100,success:o?!1:void 0})}),{data:m}=yt({queryKey:["notification-log-stats",r],queryFn:()=>Pe.getNotificationLogStats(r)}),x=_t({mutationFn:()=>Pe.clearNotificationLogs(30),onSuccess:v=>{n(v.message,"success"),e.invalidateQueries({queryKey:["notification-logs"]}),e.invalidateQueries({queryKey:["notification-log-stats"]})},onError:v=>{n(`Failed to clear logs: ${v.message}`,"error")}}),y=v=>{const b=new Date(v),S=new Date().getTime()-b.getTime();return S<6e4?"Just now":S<36e5?`${Math.floor(S/6e4)}m ago`:S<864e5?`${Math.floor(S/36e5)}h ago`:b.toLocaleDateString()+" "+b.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})};return c.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:c.jsxs("div",{className:"bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg w-full max-w-3xl max-h-[85vh] flex flex-col",children:[c.jsxs("div",{className:"p-4 border-b border-bambu-dark-tertiary flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx(o3,{className:"w-5 h-5 text-bambu-green"}),c.jsx("h2",{className:"text-lg font-semibold text-white",children:"Notification Log"})]}),c.jsx("button",{onClick:t,className:"text-bambu-gray hover:text-white transition-colors",children:"×"})]}),m&&c.jsx("div",{className:"px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark/50",children:c.jsxs("div",{className:"flex items-center gap-6 text-sm",children:[c.jsxs("span",{className:"text-bambu-gray",children:["Last ",r," days: ",c.jsx("span",{className:"text-white font-medium",children:m.total})," notifications"]}),c.jsxs("span",{className:"flex items-center gap-1 text-bambu-green",children:[c.jsx(ds,{className:"w-4 h-4"}),m.success_count," sent"]}),m.failure_count>0&&c.jsxs("span",{className:"flex items-center gap-1 text-red-400",children:[c.jsx(hd,{className:"w-4 h-4"}),m.failure_count," failed"]})]})}),c.jsxs("div",{className:"px-4 py-3 border-b border-bambu-dark-tertiary flex items-center gap-4",children:[c.jsxs("select",{value:r,onChange:v=>i(Number(v.target.value)),className:"px-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:ring-1 focus:ring-bambu-green",children:[c.jsx("option",{value:1,children:"Last 24 hours"}),c.jsx("option",{value:7,children:"Last 7 days"}),c.jsx("option",{value:30,children:"Last 30 days"}),c.jsx("option",{value:90,children:"Last 90 days"})]}),c.jsxs("label",{className:"flex items-center gap-2 text-sm text-bambu-gray cursor-pointer",children:[c.jsx("input",{type:"checkbox",checked:o,onChange:v=>l(v.target.checked),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),"Show failed only"]}),c.jsx("div",{className:"flex-1"}),c.jsxs(Ie,{size:"sm",variant:"secondary",onClick:()=>f(),disabled:g,children:[g?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(qs,{className:"w-4 h-4"}),"Refresh"]}),c.jsxs(Ie,{size:"sm",variant:"secondary",onClick:()=>x.mutate(),disabled:x.isPending,className:"text-red-400 hover:text-red-300",children:[x.isPending?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(kn,{className:"w-4 h-4"}),"Clear Old"]})]}),c.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:d?c.jsx("div",{className:"flex justify-center py-12",children:c.jsx(At,{className:"w-6 h-6 text-bambu-green animate-spin"})}):u&&u.length>0?c.jsx("div",{className:"space-y-2",children:u.map(v=>c.jsx(O9e,{log:v,isExpanded:s===v.id,onToggle:()=>a(s===v.id?null:v.id),formatDate:y},v.id))}):c.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[c.jsx(o3,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),c.jsx("p",{className:"text-sm",children:o?"No failed notifications":"No notifications logged"})]})})]})})}function O9e({log:t,isExpanded:e,onToggle:n,formatDate:r}){return c.jsxs("div",{className:`border rounded-lg overflow-hidden transition-colors ${t.success?"border-bambu-dark-tertiary bg-bambu-dark/30":"border-red-500/30 bg-red-500/5"}`,children:[c.jsxs("button",{className:"w-full px-3 py-2 flex items-center gap-3 text-left hover:bg-bambu-dark/50 transition-colors",onClick:n,children:[t.success?c.jsx(ds,{className:"w-4 h-4 text-bambu-green shrink-0"}):c.jsx(hd,{className:"w-4 h-4 text-red-400 shrink-0"}),c.jsx("span",{className:`text-xs font-medium ${R9e[t.event_type]||"text-bambu-gray"}`,children:P9e[t.event_type]||t.event_type}),c.jsx("span",{className:"text-sm text-white truncate flex-1",children:t.provider_name||"Unknown Provider"}),t.printer_name&&c.jsx("span",{className:"text-xs text-bambu-gray",children:t.printer_name}),c.jsx("span",{className:"text-xs text-bambu-gray shrink-0",children:r(t.created_at)}),e?c.jsx(mS,{className:"w-4 h-4 text-bambu-gray shrink-0"}):c.jsx(ef,{className:"w-4 h-4 text-bambu-gray shrink-0"})]}),e&&c.jsxs("div",{className:"px-3 py-2 border-t border-bambu-dark-tertiary bg-bambu-dark/20 space-y-2",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-xs text-bambu-gray mb-1",children:"Title"}),c.jsx("p",{className:"text-sm text-white",children:t.title})]}),c.jsxs("div",{children:[c.jsx("p",{className:"text-xs text-bambu-gray mb-1",children:"Message"}),c.jsx("p",{className:"text-sm text-white whitespace-pre-wrap",children:t.message})]}),!t.success&&t.error_message&&c.jsxs("div",{children:[c.jsx("p",{className:"text-xs text-red-400 mb-1",children:"Error"}),c.jsx("p",{className:"text-sm text-red-300",children:t.error_message})]}),c.jsxs("div",{className:"flex gap-4 text-xs text-bambu-gray pt-1",children:[c.jsxs("span",{children:["Provider: ",t.provider_type]}),c.jsxs("span",{children:["Time: ",new Date(t.created_at).toLocaleString()]})]})]})]})}const P_=[{id:"settings",labelKey:"backup.categories.settings",defaultLabel:"App Settings",icon:c.jsx(wR,{className:"w-4 h-4"}),default:!0,description:"Language, theme, update preferences"},{id:"notifications",labelKey:"backup.categories.notifications",defaultLabel:"Notification Providers",icon:c.jsx(fh,{className:"w-4 h-4"}),default:!0,description:"ntfy, Pushover, Discord, etc."},{id:"templates",labelKey:"backup.categories.templates",defaultLabel:"Notification Templates",icon:c.jsx(Ya,{className:"w-4 h-4"}),default:!0,description:"Custom message templates"},{id:"smart_plugs",labelKey:"backup.categories.smartPlugs",defaultLabel:"Smart Plugs",icon:c.jsx(Ox,{className:"w-4 h-4"}),default:!0,description:"Tasmota plug configurations"},{id:"printers",labelKey:"backup.categories.printers",defaultLabel:"Printers",icon:c.jsx(jo,{className:"w-4 h-4"}),default:!1,description:"Printer info (access codes excluded)"},{id:"filaments",labelKey:"backup.categories.filaments",defaultLabel:"Filament Inventory",icon:c.jsx(Dle,{className:"w-4 h-4"}),default:!1,description:"Filament types and costs"},{id:"maintenance",labelKey:"backup.categories.maintenance",defaultLabel:"Maintenance Types",icon:c.jsx(Ju,{className:"w-4 h-4"}),default:!1,description:"Custom maintenance schedules"},{id:"archives",labelKey:"backup.categories.archives",defaultLabel:"Print Archives",icon:c.jsx(pS,{className:"w-4 h-4"}),default:!1,description:"All print data + files (3MF, thumbnails, photos)"}];function j9e({onClose:t,onExport:e}){const{t:n}=uS(),[r,i]=M.useState(()=>{const x={};return P_.forEach(y=>{x[y.id]=y.default}),x}),[s,a]=M.useState(!1),[o,l]=M.useState(!1);M.useEffect(()=>{const x=y=>{y.key==="Escape"&&t()};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[t]);const u=x=>{i(y=>({...y,[x]:!y[x]}))},d=()=>{const x={};P_.forEach(y=>{x[y.id]=!0}),i(x)},f=()=>{const x={};P_.forEach(y=>{x[y.id]=!1}),i(x)},g=Object.values(r).filter(Boolean).length,m=async()=>{l(!0);try{await e({...r,access_codes:s&&r.printers})}finally{l(!1)}};return c.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onClick:o?void 0:t,children:c.jsx(Nt,{className:"w-full max-w-lg",onClick:x=>x.stopPropagation(),children:c.jsxs(Dt,{className:"p-0",children:[c.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("div",{className:"p-2 rounded-full bg-bambu-green/20 text-bambu-green",children:c.jsx(ya,{className:"w-5 h-5"})}),c.jsxs("div",{children:[c.jsx("h3",{className:"text-lg font-semibold text-white",children:n("backup.exportTitle",{defaultValue:"Export Backup"})}),c.jsx("p",{className:"text-sm text-bambu-gray",children:n("backup.selectCategories",{defaultValue:"Select data to include"})})]})]}),c.jsx("button",{onClick:t,className:"p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors",children:c.jsx(Gt,{className:"w-5 h-5"})})]}),c.jsxs("div",{className:"flex gap-2 px-4 pt-4",children:[c.jsx("button",{onClick:d,disabled:o,className:"text-sm text-bambu-green hover:text-bambu-green/80 disabled:opacity-50 disabled:cursor-not-allowed",children:n("common.selectAll",{defaultValue:"Select All"})}),c.jsx("span",{className:"text-bambu-gray",children:"|"}),c.jsx("button",{onClick:f,disabled:o,className:"text-sm text-bambu-gray hover:text-white disabled:opacity-50 disabled:cursor-not-allowed",children:n("common.selectNone",{defaultValue:"Select None"})})]}),c.jsx("div",{className:`p-4 space-y-2 max-h-[400px] overflow-y-auto ${o?"opacity-50 pointer-events-none":""}`,children:P_.map(x=>c.jsxs("label",{className:`flex items-center gap-3 p-3 rounded-lg cursor-pointer transition-colors ${r[x.id]?"bg-bambu-green/10 border border-bambu-green/30":"bg-bambu-dark hover:bg-bambu-dark-tertiary border border-transparent"}`,children:[c.jsx("input",{type:"checkbox",checked:r[x.id],onChange:()=>u(x.id),disabled:o,className:"w-4 h-4 rounded border-bambu-gray bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0"}),c.jsx("div",{className:`${r[x.id]?"text-bambu-green":"text-bambu-gray"}`,children:x.icon}),c.jsxs("div",{className:"flex-1",children:[c.jsx("div",{className:"text-white text-sm font-medium",children:n(x.labelKey,{defaultValue:x.defaultLabel})}),c.jsx("div",{className:"text-xs text-bambu-gray",children:x.description})]})]},x.id))}),r.archives&&c.jsx("div",{className:"mx-4 mb-2 p-3 rounded-lg bg-yellow-500/10 border border-yellow-500/30",children:c.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[c.jsx(pS,{className:"w-4 h-4 text-yellow-500 mt-0.5 flex-shrink-0"}),c.jsxs("div",{className:"text-yellow-200 dark:text-yellow-200 text-yellow-700",children:[c.jsx("span",{className:"font-medium",children:"ZIP file will be created."}),c.jsx("span",{className:"text-yellow-600 dark:text-yellow-200/70",children:" Includes all 3MF files, thumbnails, timelapses, and photos. This may take a while and result in a large file."})]})]})}),r.printers&&c.jsxs("div",{className:"mx-4 mb-2 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-start gap-2",children:[c.jsx(Op,{className:"w-4 h-4 text-orange-500 dark:text-orange-400 mt-0.5 flex-shrink-0"}),c.jsxs("div",{children:[c.jsx("p",{className:"text-sm font-medium text-white",children:"Include Access Codes"}),c.jsx("p",{className:"text-xs text-bambu-gray",children:"For transferring to another machine"})]})]}),c.jsx(tr,{checked:s,onChange:a})]}),s&&c.jsx("div",{className:"mt-2 p-2 rounded bg-orange-500/10 border border-orange-500/30",children:c.jsxs("div",{className:"flex items-start gap-2 text-xs",children:[c.jsx(Qr,{className:"w-3 h-3 text-orange-500 dark:text-orange-400 mt-0.5 flex-shrink-0"}),c.jsx("span",{className:"text-orange-700 dark:text-orange-200",children:"Access codes will be included in plain text. Keep this backup file secure!"})]})})]}),c.jsxs("div",{className:"flex items-center justify-between p-4 border-t border-bambu-dark-tertiary",children:[c.jsx("span",{className:"text-sm text-bambu-gray",children:n("backup.selectedCount",{count:g,defaultValue:`${g} categories selected`})}),c.jsxs("div",{className:"flex gap-3",children:[c.jsx(Ie,{variant:"secondary",onClick:t,disabled:o,children:n("common.cancel",{defaultValue:"Cancel"})}),c.jsx(Ie,{onClick:m,disabled:g===0||o,className:"bg-bambu-green hover:bg-bambu-green-dark disabled:opacity-50 disabled:cursor-not-allowed min-w-[100px]",children:o?c.jsxs(c.Fragment,{children:[c.jsx(At,{className:"w-4 h-4 mr-2 animate-spin"}),n("backup.exporting",{defaultValue:"Exporting..."})]}):c.jsxs(c.Fragment,{children:[c.jsx(ya,{className:"w-4 h-4 mr-2"}),n("backup.export",{defaultValue:"Export"})]})})]})]})]})})})}const z9={settings:"Settings",notification_providers:"Notification Providers",notification_templates:"Notification Templates",smart_plugs:"Smart Plugs",printers:"Printers",filaments:"Filaments",maintenance_types:"Maintenance Types",archives:"Archives"};function L9e({onClose:t,onRestore:e,onSuccess:n}){const[r,i]=M.useState("options"),[s,a]=M.useState(!1),[o,l]=M.useState(null),[u,d]=M.useState(null),[f,g]=M.useState(new Set),m=M.useRef(null);M.useEffect(()=>{const S=A=>{A.key==="Escape"&&r!=="restoring"&&t()};return window.addEventListener("keydown",S),()=>window.removeEventListener("keydown",S)},[t,r]);const x=S=>{const A=S.target.files?.[0];A&&l(A)},y=async()=>{if(o){i("restoring");try{const S=await e(o,s);d(S),i("result"),S.success&&n()}catch{d({success:!1,message:"Failed to restore backup. Please check the file format."}),i("result")}}},v=S=>{g(A=>{const T=new Set(A);return T.has(S)?T.delete(S):T.add(S),T})},b=u?.restored?Object.values(u.restored).reduce((S,A)=>S+A,0)+(u.files_restored||0):0,E=u?.total_skipped||0;return c.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onMouseDown:S=>{S.target===S.currentTarget&&r!=="restoring"&&t()},children:c.jsx(Nt,{className:"w-full max-w-lg",children:c.jsxs(Dt,{className:"p-0",children:[c.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("div",{className:`p-2 rounded-full ${r==="result"&&u?.success?"bg-bambu-green/20 text-bambu-green":r==="result"&&!u?.success?"bg-red-500/20 text-red-500":"bg-blue-500/20 text-blue-500"}`,children:r==="result"&&u?.success?c.jsx(ds,{className:"w-5 h-5"}):r==="result"&&!u?.success?c.jsx(Qr,{className:"w-5 h-5"}):c.jsx(ma,{className:"w-5 h-5"})}),c.jsxs("div",{children:[c.jsxs("h3",{className:"text-lg font-semibold text-white",children:[r==="options"&&"Restore Backup",r==="restoring"&&"Restoring...",r==="result"&&(u?.success?"Restore Complete":"Restore Failed")]}),c.jsxs("p",{className:"text-sm text-bambu-gray",children:[r==="options"&&"Import settings from a backup file",r==="restoring"&&"Please wait while your data is being restored",r==="result"&&u?.message]})]})]}),r!=="restoring"&&c.jsx("button",{onClick:t,className:"p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors",children:c.jsx(Gt,{className:"w-5 h-5"})})]}),r==="options"&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"p-4 space-y-4",children:[c.jsxs("div",{children:[c.jsx("input",{ref:m,type:"file",accept:".json,.zip",className:"hidden",onChange:x}),c.jsx("button",{type:"button",onClick:()=>m.current?.click(),className:`w-full p-4 border-2 border-dashed rounded-lg transition-colors ${o?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:o?c.jsxs("div",{className:"flex items-center justify-center gap-2 text-bambu-green",children:[c.jsx(ds,{className:"w-5 h-5"}),c.jsx("span",{className:"font-medium",children:o.name})]}):c.jsxs("div",{className:"flex flex-col items-center gap-2 text-bambu-gray",children:[c.jsx(ma,{className:"w-8 h-8"}),c.jsx("span",{children:"Click to select backup file (.json or .zip)"})]})})]}),c.jsx("div",{className:"p-3 rounded-lg bg-blue-500/10 border border-blue-500/30",children:c.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[c.jsx(Qr,{className:"w-4 h-4 text-blue-500 dark:text-blue-400 mt-0.5 flex-shrink-0"}),c.jsxs("div",{className:"text-blue-700 dark:text-blue-200",children:[c.jsx("p",{className:"font-medium mb-1",children:"How duplicate handling works:"}),c.jsxs("ul",{className:"text-blue-600 dark:text-blue-200/80 space-y-1 text-xs",children:[c.jsxs("li",{children:[c.jsx("strong",{children:"Printers"})," - matched by serial number"]}),c.jsxs("li",{children:[c.jsx("strong",{children:"Smart Plugs"})," - matched by IP address"]}),c.jsxs("li",{children:[c.jsx("strong",{children:"Notification Providers"})," - matched by name"]}),c.jsxs("li",{children:[c.jsx("strong",{children:"Filaments"})," - matched by name + type + brand"]}),c.jsxs("li",{children:[c.jsx("strong",{children:"Archives"})," - matched by content hash (always skipped)"]}),c.jsxs("li",{children:[c.jsx("strong",{children:"Settings & Templates"})," - always overwritten"]})]})]})]})}),c.jsx("div",{className:"p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary",children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsxs("p",{className:"text-white font-medium flex items-center gap-2",children:[s?c.jsx(qs,{className:"w-4 h-4 text-orange-400"}):c.jsx(c1,{className:"w-4 h-4 text-bambu-gray"}),s?"Replace existing data":"Keep existing data"]}),c.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:s?"Overwrite items that already exist with backup data":"Only restore items that don't already exist"})]}),c.jsx(tr,{checked:s,onChange:a})]})}),s&&c.jsx("div",{className:"p-3 rounded-lg bg-orange-500/10 border border-orange-500/30",children:c.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[c.jsx(Qr,{className:"w-4 h-4 text-orange-500 dark:text-orange-400 mt-0.5 flex-shrink-0"}),c.jsxs("div",{className:"text-orange-700 dark:text-orange-200",children:[c.jsx("span",{className:"font-medium",children:"Caution:"})," Overwriting will replace your current configurations with data from the backup. Printer access codes are never overwritten for security."]})]})})]}),c.jsxs("div",{className:"flex items-center justify-end gap-3 p-4 border-t border-bambu-dark-tertiary",children:[c.jsx(Ie,{type:"button",variant:"secondary",onClick:t,children:"Cancel"}),c.jsxs(Ie,{type:"button",onClick:y,disabled:!o,className:"bg-bambu-green hover:bg-bambu-green-dark disabled:opacity-50",children:[c.jsx(ma,{className:"w-4 h-4 mr-2"}),"Restore"]})]})]}),r==="restoring"&&c.jsxs("div",{className:"p-8 flex flex-col items-center gap-4",children:[c.jsx(At,{className:"w-12 h-12 text-bambu-green animate-spin"}),c.jsx("p",{className:"text-bambu-gray",children:"Processing backup file..."})]}),r==="result"&&u&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"p-4 space-y-4 max-h-[400px] overflow-y-auto",children:[c.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[c.jsxs("div",{className:"p-3 rounded-lg bg-bambu-green/10 border border-bambu-green/30",children:[c.jsx("div",{className:"text-2xl font-bold text-bambu-green",children:b}),c.jsx("div",{className:"text-sm text-bambu-gray",children:"Items Restored"})]}),c.jsxs("div",{className:"p-3 rounded-lg bg-yellow-500/10 border border-yellow-500/30",children:[c.jsx("div",{className:"text-2xl font-bold text-yellow-500",children:E}),c.jsx("div",{className:"text-sm text-bambu-gray",children:"Items Skipped"})]})]}),u.restored&&Object.entries(u.restored).some(([,S])=>S>0)&&c.jsxs("div",{className:"space-y-2",children:[c.jsxs("h4",{className:"text-sm font-medium text-bambu-gray flex items-center gap-2",children:[c.jsx(ds,{className:"w-4 h-4 text-bambu-green"}),"Restored"]}),c.jsxs("div",{className:"space-y-1",children:[Object.entries(u.restored).filter(([,S])=>S>0).map(([S,A])=>c.jsxs("div",{className:"flex items-center justify-between text-sm p-2 rounded bg-bambu-dark",children:[c.jsx("span",{className:"text-white",children:z9[S]||S}),c.jsx("span",{className:"text-bambu-green font-medium",children:A})]},S)),(u.files_restored||0)>0&&c.jsxs("div",{className:"flex items-center justify-between text-sm p-2 rounded bg-bambu-dark",children:[c.jsx("span",{className:"text-white",children:"Files (3MF, thumbnails, etc.)"}),c.jsx("span",{className:"text-bambu-green font-medium",children:u.files_restored})]})]})]}),u.skipped&&Object.entries(u.skipped).some(([,S])=>S>0)&&c.jsxs("div",{className:"space-y-2",children:[c.jsxs("h4",{className:"text-sm font-medium text-bambu-gray flex items-center gap-2",children:[c.jsx(c1,{className:"w-4 h-4 text-yellow-500"}),"Skipped (already exist)"]}),c.jsx("div",{className:"space-y-1",children:Object.entries(u.skipped).filter(([,S])=>S>0).map(([S,A])=>{const T=u.skipped_details?.[S]||[],P=f.has(S);return c.jsxs("div",{children:[c.jsxs("button",{onClick:()=>T.length>0&&v(S),className:`w-full flex items-center justify-between text-sm p-2 rounded bg-bambu-dark ${T.length>0?"hover:bg-bambu-dark-tertiary cursor-pointer":""}`,children:[c.jsxs("span",{className:"text-white flex items-center gap-2",children:[z9[S]||S,T.length>0&&(P?c.jsx(mS,{className:"w-3 h-3"}):c.jsx(ef,{className:"w-3 h-3"}))]}),c.jsx("span",{className:"text-yellow-500 font-medium",children:A})]}),P&&T.length>0&&c.jsxs("div",{className:"mt-1 ml-4 p-2 rounded bg-bambu-dark-tertiary text-xs text-bambu-gray space-y-1",children:[T.slice(0,10).map((C,I)=>c.jsx("div",{children:C},I)),T.length>10&&c.jsxs("div",{className:"text-bambu-gray/60",children:["...and ",T.length-10," more"]})]})]},S)})})]}),b===0&&E===0&&c.jsx("div",{className:"p-4 text-center text-bambu-gray",children:"No data was found to restore in the backup file."})]}),c.jsx("div",{className:"flex items-center justify-end gap-3 p-4 border-t border-bambu-dark-tertiary",children:c.jsx(Ie,{onClick:t,children:"Close"})})]})]})})})}async function I9e(){const t=await fetch("/api/v1/settings/spoolman");if(!t.ok)throw new Error("Failed to load Spoolman settings");return t.json()}async function U9e(t){const e=await fetch("/api/v1/settings/spoolman",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!e.ok)throw new Error("Failed to save Spoolman settings");return e.json()}function F9e(){const t=Sn(),[e,n]=M.useState(!1),[r,i]=M.useState(""),[s,a]=M.useState("auto"),[o,l]=M.useState(!1),[u,d]=M.useState("all"),[f,g]=M.useState(!1),{data:m,isLoading:x}=yt({queryKey:["spoolman-settings"],queryFn:I9e}),{data:y,isLoading:v,refetch:b}=yt({queryKey:["spoolman-status"],queryFn:Pe.getSpoolmanStatus,refetchInterval:3e4}),{data:E}=yt({queryKey:["printers"],queryFn:Pe.getPrinters});M.useEffect(()=>{m&&(n(m.spoolman_enabled==="true"),i(m.spoolman_url||""),a(m.spoolman_sync_mode||"auto"),g(!0))},[m]),M.useEffect(()=>{if(!f||!m)return;if(m.spoolman_enabled==="true"!==e||(m.spoolman_url||"")!==r||(m.spoolman_sync_mode||"auto")!==s){const q=setTimeout(()=>{S.mutate()},500);return()=>clearTimeout(q)}},[e,r,s,f]);const S=_t({mutationFn:()=>U9e({spoolman_enabled:e?"true":"false",spoolman_url:r,spoolman_sync_mode:s}),onSuccess:()=>{t.invalidateQueries({queryKey:["spoolman-settings"]}),t.invalidateQueries({queryKey:["spoolman-status"]}),l(!0),setTimeout(()=>l(!1),2e3)}}),A=_t({mutationFn:Pe.connectSpoolman,onSuccess:()=>{b()}}),T=_t({mutationFn:Pe.disconnectSpoolman,onSuccess:()=>{b()}}),P=_t({mutationFn:Pe.syncAllPrintersAms,onSuccess:L=>{L.success}}),C=_t({mutationFn:L=>Pe.syncPrinterAms(L),onSuccess:L=>{L.success}}),I=()=>{u==="all"?P.mutate():C.mutate(u)},N=P.isPending||C.isPending,D=u==="all"?P.data:C.data,F=u==="all"?P.isSuccess:C.isSuccess;return x?c.jsxs(Nt,{children:[c.jsx(za,{children:c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(s3,{className:"w-5 h-5 text-bambu-green"}),c.jsx("h2",{className:"text-lg font-semibold text-white",children:"Spoolman Integration"})]})}),c.jsx(Dt,{children:c.jsx("div",{className:"flex justify-center py-8",children:c.jsx(At,{className:"w-6 h-6 text-bambu-green animate-spin"})})})]}):c.jsxs(Nt,{children:[c.jsx(za,{children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(s3,{className:"w-5 h-5 text-bambu-green"}),c.jsx("h2",{className:"text-lg font-semibold text-white",children:"Spoolman Integration"})]}),S.isPending&&c.jsx(At,{className:"w-4 h-4 text-bambu-green animate-spin"}),o&&c.jsx(Ph,{className:"w-4 h-4 text-bambu-green"})]})}),c.jsxs(Dt,{className:"space-y-4",children:[c.jsx("p",{className:"text-sm text-bambu-gray",children:"Connect to Spoolman for filament inventory tracking. AMS data will sync automatically."}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-white",children:"Enable Spoolman"}),c.jsx("p",{className:"text-sm text-bambu-gray",children:"Sync filament data with Spoolman server"})]}),c.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[c.jsx("input",{type:"checkbox",checked:e,onChange:L=>n(L.target.checked),className:"sr-only peer"}),c.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Spoolman URL"}),c.jsx("input",{type:"text",placeholder:"http://192.168.1.100:7912",value:r,onChange:L=>i(L.target.value),disabled:!e,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray/50 focus:border-bambu-green focus:outline-none disabled:opacity-50"}),c.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"URL of your Spoolman server (e.g., http://localhost:7912)"})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Sync Mode"}),c.jsxs("select",{value:s,onChange:L=>a(L.target.value),disabled:!e,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none disabled:opacity-50",children:[c.jsx("option",{value:"auto",children:"Automatic"}),c.jsx("option",{value:"manual",children:"Manual Only"})]}),c.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:s==="auto"?"AMS data syncs automatically when changes are detected":"Only sync when manually triggered"})]}),e&&c.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[c.jsxs("div",{className:"flex items-center justify-between mb-3",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"text-sm text-bambu-gray",children:"Status:"}),v?c.jsx(At,{className:"w-4 h-4 text-bambu-gray animate-spin"}):y?.connected?c.jsxs("span",{className:"flex items-center gap-1 text-sm text-green-500",children:[c.jsx(Ph,{className:"w-4 h-4"}),"Connected"]}):c.jsxs("span",{className:"flex items-center gap-1 text-sm text-red-500",children:[c.jsx(Gt,{className:"w-4 h-4"}),"Disconnected"]})]}),c.jsx("div",{className:"flex gap-2",children:y?.connected?c.jsxs(Ie,{variant:"secondary",size:"sm",onClick:()=>T.mutate(),disabled:T.isPending,children:[T.isPending?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(nle,{className:"w-4 h-4"}),"Disconnect"]}):c.jsxs(Ie,{size:"sm",onClick:()=>A.mutate(),disabled:A.isPending||!r,children:[A.isPending?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(c3,{className:"w-4 h-4"}),"Connect"]})})]}),A.isError&&c.jsx("div",{className:"mb-3 p-2 bg-red-500/20 border border-red-500/50 rounded text-sm text-red-400",children:A.error.message}),y?.connected&&c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-sm text-white",children:"Sync AMS Data"}),c.jsx("p",{className:"text-xs text-bambu-gray",children:"Manually sync printer AMS data to Spoolman"})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("div",{className:"relative flex-1",children:[c.jsxs("select",{value:u,onChange:L=>d(L.target.value==="all"?"all":Number(L.target.value)),className:"w-full px-3 py-2 pr-8 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:[c.jsx("option",{value:"all",children:"All Printers"}),E?.map(L=>c.jsx("option",{value:L.id,children:L.name},L.id))]}),c.jsx(ef,{className:"absolute right-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),c.jsxs(Ie,{variant:"secondary",size:"sm",onClick:I,disabled:N,children:[N?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(qs,{className:"w-4 h-4"}),"Sync"]})]})]}),F&&D&&c.jsx("div",{className:`mt-2 p-2 rounded text-sm ${D.success?"bg-green-500/20 border border-green-500/50 text-green-400":"bg-yellow-500/20 border border-yellow-500/50 text-yellow-400"}`,children:D.success?`Synced ${D.synced_count} trays successfully`:`Synced ${D.synced_count} trays with ${D.errors.length} errors`})]})]})]})}function z9e({link:t,onClose:e}){const n=Sn(),{theme:r}=yS(),i=!!t,s=M.useRef(null),[a,o]=M.useState(t?.name||""),[l,u]=M.useState(t?.url||""),[d,f]=M.useState(t?.icon||"link"),[g,m]=M.useState(!!t?.custom_icon),[x,y]=M.useState(t?.custom_icon?Pe.getExternalLinkIconUrl(t.id):null),[v,b]=M.useState(null),[E,S]=M.useState(null);M.useEffect(()=>{const F=L=>{L.key==="Escape"&&e()};return window.addEventListener("keydown",F),()=>window.removeEventListener("keydown",F)},[e]);const A=_t({mutationFn:async F=>{const L=await Pe.createExternalLink(F);return v?await Pe.uploadExternalLinkIcon(L.id,v):L},onSuccess:()=>{n.invalidateQueries({queryKey:["external-links"]}),e()},onError:F=>{S(F.message)}}),T=_t({mutationFn:async F=>{let L=await Pe.updateExternalLink(t.id,F);return v?L=await Pe.uploadExternalLinkIcon(t.id,v):!g&&t?.custom_icon&&(L=await Pe.deleteExternalLinkIcon(t.id)),L},onSuccess:()=>{n.invalidateQueries({queryKey:["external-links"]}),e()},onError:F=>{S(F.message)}}),P=F=>{const L=F.target.files?.[0];if(L){if(!["image/png","image/jpeg","image/gif","image/svg+xml","image/webp","image/x-icon"].includes(L.type)){S("Please select a valid image file (PNG, JPG, GIF, SVG, WebP, or ICO)");return}if(L.size>1024*1024){S("Image file must be less than 1MB");return}b(L),m(!0);const R=new FileReader;R.onload=V=>{y(V.target?.result)},R.readAsDataURL(L)}},C=()=>{b(null),y(null),m(!1),s.current&&(s.current.value="")},I=F=>{if(F.preventDefault(),S(null),!a.trim()){S("Name is required");return}if(!l.trim()){S("URL is required");return}if(!l.startsWith("http://")&&!l.startsWith("https://")){S("URL must start with http:// or https://");return}const L={name:a.trim(),url:l.trim(),icon:d};i?T.mutate(L):A.mutate(L)},N=A.isPending||T.isPending,D=_S(d);return c.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:e,children:c.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-md",onClick:F=>F.stopPropagation(),children:[c.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("div",{className:"p-2 rounded-full bg-bambu-green/20 text-bambu-green",children:g&&x?c.jsx("img",{src:x,alt:"",className:`w-5 h-5 rounded ${r==="dark"?"invert opacity-[0.65]":"opacity-60"}`}):c.jsx(D,{className:"w-5 h-5"})}),c.jsx("h2",{className:"text-lg font-semibold text-white",children:i?"Edit Link":"Add External Link"})]}),c.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:c.jsx(Gt,{className:"w-5 h-5"})})]}),c.jsxs("form",{onSubmit:I,className:"p-6 space-y-4",children:[E&&c.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:E}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name *"}),c.jsx("input",{type:"text",value:a,onChange:F=>o(F.target.value),placeholder:"My Link",maxLength:50,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"URL *"}),c.jsx("input",{type:"text",value:l,onChange:F=>u(F.target.value),placeholder:"https://example.com",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),c.jsxs("div",{className:"space-y-3",children:[c.jsx("label",{className:"block text-sm text-bambu-gray",children:"Icon"}),c.jsxs("div",{className:"p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary",children:[c.jsxs("div",{className:"flex items-center justify-between mb-2",children:[c.jsx("span",{className:"text-sm text-white",children:"Custom Icon"}),c.jsx("input",{ref:s,type:"file",accept:"image/png,image/jpeg,image/gif,image/svg+xml,image/webp,image/x-icon",className:"hidden",onChange:P}),g&&x?c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("img",{src:x,alt:"Custom icon",className:`w-8 h-8 rounded border border-bambu-dark-tertiary ${r==="dark"?"invert opacity-[0.65]":"opacity-60"}`}),c.jsx("button",{type:"button",onClick:C,className:"p-1 text-red-400 hover:text-red-300 transition-colors",title:"Remove custom icon",children:c.jsx(kn,{className:"w-4 h-4"})})]}):c.jsxs(Ie,{type:"button",variant:"secondary",size:"sm",onClick:()=>s.current?.click(),children:[c.jsx(ma,{className:"w-4 h-4"}),"Upload"]})]}),c.jsx("p",{className:"text-xs text-bambu-gray",children:"PNG, JPG, GIF, SVG, WebP, or ICO. Max 1MB."})]}),!g&&c.jsxs("div",{children:[c.jsx("span",{className:"text-sm text-bambu-gray block mb-2",children:"Or choose a preset icon"}),c.jsx(oue,{value:d,onChange:f})]})]}),c.jsxs("div",{className:"flex gap-3 pt-2",children:[c.jsx(Ie,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:"Cancel"}),c.jsxs(Ie,{type:"submit",disabled:N,className:"flex-1",children:[N?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(To,{className:"w-4 h-4"}),i?"Save":"Add"]})]})]})]})})}function B9e(){const t=Sn(),[e,n]=M.useState(!1),[r,i]=M.useState(null),[s,a]=M.useState(null),[o,l]=M.useState(null),{data:u,isLoading:d}=yt({queryKey:["external-links"],queryFn:Pe.getExternalLinks}),f=_t({mutationFn:E=>Pe.deleteExternalLink(E),onSuccess:()=>{t.invalidateQueries({queryKey:["external-links"]})}}),g=_t({mutationFn:E=>Pe.reorderExternalLinks(E),onSuccess:()=>{t.invalidateQueries({queryKey:["external-links"]})}}),m=(E,S)=>{l(S),E.dataTransfer.effectAllowed="move"},x=E=>{E.preventDefault(),E.dataTransfer.dropEffect="move"},y=(E,S)=>{if(E.preventDefault(),o===null||o===S||!u)return;const A=u.map(I=>I.id),T=A.indexOf(o),P=A.indexOf(S);if(T===-1||P===-1)return;const C=[...A];C.splice(T,1),C.splice(P,0,o),g.mutate(C),l(null)},v=E=>{a(E)},b=()=>{s&&(f.mutate(s.id),a(null))};return c.jsxs(c.Fragment,{children:[c.jsxs(Nt,{children:[c.jsx(za,{children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(c3,{className:"w-5 h-5 text-bambu-green"}),c.jsx("h2",{className:"text-lg font-semibold text-white",children:"Sidebar Links"})]}),c.jsxs(Ie,{size:"sm",onClick:()=>n(!0),children:[c.jsx(fr,{className:"w-4 h-4"}),"Add Link"]})]})}),c.jsxs(Dt,{children:[c.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:"Add external links to the sidebar navigation. Drag to reorder."}),d?c.jsx("div",{className:"flex justify-center py-8",children:c.jsx(At,{className:"w-6 h-6 text-bambu-green animate-spin"})}):u&&u.length>0?c.jsx("div",{className:"space-y-2",children:u.map(E=>{const S=_S(E.icon);return c.jsxs("div",{draggable:!0,onDragStart:A=>m(A,E.id),onDragOver:x,onDrop:A=>y(A,E.id),className:`flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary transition-colors ${o===E.id?"opacity-50":""}`,children:[c.jsx(c0,{className:"w-6 h-6 md:w-4 md:h-4 text-bambu-gray cursor-grab flex-shrink-0"}),c.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark-tertiary text-bambu-gray",children:c.jsx(S,{className:"w-4 h-4"})}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"text-white font-medium truncate",children:E.name}),c.jsx(ro,{className:"w-3 h-3 text-bambu-gray flex-shrink-0"})]}),c.jsx("span",{className:"text-sm text-bambu-gray truncate block",children:E.url})]}),c.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[c.jsx("button",{onClick:()=>i(E),className:"p-2 rounded-lg hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors",title:"Edit",children:c.jsx(Zu,{className:"w-4 h-4"})}),c.jsx("button",{onClick:()=>v(E),disabled:f.isPending,className:"p-2 rounded-lg hover:bg-red-500/20 text-bambu-gray hover:text-red-400 transition-colors disabled:opacity-50",title:"Delete",children:c.jsx(kn,{className:"w-4 h-4"})})]})]},E.id)})}):c.jsxs("div",{className:"text-center py-8 text-bambu-gray",children:[c.jsx(c3,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),c.jsx("p",{children:"No external links configured"}),c.jsx("p",{className:"text-sm",children:'Click "Add Link" to add one'})]})]})]}),(e||r)&&c.jsx(z9e,{link:r,onClose:()=>{n(!1),i(null)}}),s&&c.jsx(Kr,{title:"Delete Link",message:`Are you sure you want to delete "${s.name}"? This action cannot be undone.`,confirmText:"Delete",cancelText:"Cancel",variant:"danger",onConfirm:b,onCancel:()=>a(null)})]})}function H9e(){const t=Sn(),{t:e,i18n:n}=uS(),{showToast:r}=ri(),[i,s]=M.useState(null),[a,o]=M.useState(!1),[l,u]=M.useState(null),[d,f]=M.useState(!1),[g,m]=M.useState(null),[x,y]=M.useState(null),[v,b]=M.useState(!1),[E,S]=M.useState(GG()),[A,T]=M.useState("general"),[P,C]=M.useState(!1),[I,N]=M.useState(""),[D,F]=M.useState({can_queue:!0,can_control_printer:!1,can_read_status:!0}),[L,q]=M.useState(null),[R,V]=M.useState(null),[K,W]=M.useState(!1),[ne,Y]=M.useState(!1),[Z,U]=M.useState(null),[$,ee]=M.useState(!1),[ae,fe]=M.useState(!1),ue=Q=>{S(Q),uue(Q)},xe=()=>{localStorage.removeItem("sidebarOrder"),window.location.reload()},{data:Me,isLoading:se}=yt({queryKey:["settings"],queryFn:Pe.getSettings}),{data:ve,isLoading:je}=yt({queryKey:["smart-plugs"],queryFn:Pe.getSmartPlugs}),{data:de,isLoading:ut}=yt({queryKey:["smart-plugs-energy",ve?.map(Q=>Q.id)],queryFn:async()=>{if(!ve||ve.length===0)return null;const Q=await Promise.all(ve.filter(He=>He.enabled).map(async He=>{try{const ht=await Pe.getSmartPlugStatus(He.id);return{plug:He,status:ht}}catch{return{plug:He,status:null}}}));let Fe=0,pe=0,Ue=0,Ce=0,ye=0;for(const{status:He}of Q)He?.reachable&&He.energy&&(ye++,He.energy.power!=null&&(Fe+=He.energy.power),He.energy.today!=null&&(pe+=He.energy.today),He.energy.yesterday!=null&&(Ue+=He.energy.yesterday),He.energy.total!=null&&(Ce+=He.energy.total));return{totalPower:Fe,totalToday:pe,totalYesterday:Ue,totalLifetime:Ce,reachableCount:ye,totalPlugs:ve.filter(He=>He.enabled).length}},enabled:A==="plugs"&&!!ve&&ve.length>0,refetchInterval:A==="plugs"?1e4:!1}),{data:H,isLoading:z}=yt({queryKey:["notification-providers"],queryFn:Pe.getNotificationProviders}),{data:re,isLoading:G}=yt({queryKey:["api-keys"],queryFn:Pe.getAPIKeys,enabled:A==="apikeys"}),J=_t({mutationFn:Q=>Pe.createAPIKey(Q),onSuccess:Q=>{q(Q.key||null),C(!1),N(""),t.invalidateQueries({queryKey:["api-keys"]}),r("API key created")},onError:Q=>{r(`Failed to create API key: ${Q.message}`,"error")}}),le=_t({mutationFn:Q=>Pe.deleteAPIKey(Q),onSuccess:()=>{t.invalidateQueries({queryKey:["api-keys"]}),r("API key deleted")},onError:Q=>{r(`Failed to delete API key: ${Q.message}`,"error")}}),{data:ke}=yt({queryKey:["printers"],queryFn:Pe.getPrinters}),{data:Ne,isLoading:we}=yt({queryKey:["notification-templates"],queryFn:Pe.getNotificationTemplates}),{data:B}=yt({queryKey:["ffmpeg-status"],queryFn:Pe.checkFfmpeg}),{data:j}=yt({queryKey:["version"],queryFn:Pe.getVersion}),{data:te,refetch:be,isRefetching:_e}=yt({queryKey:["updateCheck"],queryFn:Pe.checkForUpdates,staleTime:300*1e3}),{data:ge,refetch:me}=yt({queryKey:["updateStatus"],queryFn:Pe.getUpdateStatus,refetchInterval:Q=>{const Fe=Q.state.data;return Fe?.status==="downloading"||Fe?.status==="installing"?1e3:!1}}),Ae=_t({mutationFn:Pe.applyUpdate,onSuccess:()=>{me()}}),[ze,st]=M.useState(null),Ve=_t({mutationFn:Pe.testAllNotificationProviders,onSuccess:Q=>{st(Q),t.invalidateQueries({queryKey:["notification-providers"]}),Q.failed===0?r(`All ${Q.tested} providers tested successfully!`,"success"):r(`${Q.success}/${Q.tested} providers succeeded`,Q.failed>0?"error":"success")},onError:Q=>{r(`Failed to test providers: ${Q.message}`,"error")}}),ce=_t({mutationFn:async Q=>{if(!ve)return{success:0,failed:0};const Fe=ve.filter(Ue=>Ue.enabled),pe=await Promise.all(Fe.map(async Ue=>{try{return await Pe.controlSmartPlug(Ue.id,Q),{success:!0}}catch{return{success:!1}}}));return{success:pe.filter(Ue=>Ue.success).length,failed:pe.filter(Ue=>!Ue.success).length}},onSuccess:(Q,Fe)=>{t.invalidateQueries({queryKey:["smart-plugs"]}),t.invalidateQueries({queryKey:["smart-plugs-energy"]}),Q.failed===0?r(`All ${Q.success} plugs turned ${Fe}`,"success"):r(`${Q.success} plugs turned ${Fe}, ${Q.failed} failed`,"error")},onError:Q=>{r(`Failed: ${Q.message}`,"error")}}),Ye=M.useRef(null),$e=M.useRef(!0);M.useEffect(()=>{Me&&!i&&(s(Me),setTimeout(()=>{$e.current=!1},100))},[Me,i]);const Ze=_t({mutationFn:Pe.updateSettings,onSuccess:Q=>{t.setQueryData(["settings"],Q),t.invalidateQueries({queryKey:["archiveStats"]}),r("Settings saved","success")},onError:Q=>{r(`Failed to save: ${Q.message}`,"error")}});M.useEffect(()=>{if(!($e.current||!i||!Me||!(Me.auto_archive!==i.auto_archive||Me.save_thumbnails!==i.save_thumbnails||Me.capture_finish_photo!==i.capture_finish_photo||Me.default_filament_cost!==i.default_filament_cost||Me.currency!==i.currency||Me.energy_cost_per_kwh!==i.energy_cost_per_kwh||Me.energy_tracking_mode!==i.energy_tracking_mode||Me.check_updates!==i.check_updates||Me.notification_language!==i.notification_language||Me.ams_humidity_good!==i.ams_humidity_good||Me.ams_humidity_fair!==i.ams_humidity_fair||Me.ams_temp_good!==i.ams_temp_good||Me.ams_temp_fair!==i.ams_temp_fair||Me.date_format!==i.date_format||Me.time_format!==i.time_format||Me.default_printer_id!==i.default_printer_id)))return Ye.current&&clearTimeout(Ye.current),Ye.current=setTimeout(()=>{Ze.mutate(i)},500),()=>{Ye.current&&clearTimeout(Ye.current)}},[i,Me,Ze]);const at=M.useCallback((Q,Fe)=>{s(pe=>pe?{...pe,[Q]:Fe}:null)},[]);return se||!i?c.jsx("div",{className:"p-4 md:p-8 flex justify-center",children:c.jsx(At,{className:"w-8 h-8 text-bambu-green animate-spin"})}):c.jsxs("div",{className:"p-4 md:p-8",children:[c.jsxs("div",{className:"mb-8",children:[c.jsx("h1",{className:"text-2xl font-bold text-white",children:"Settings"}),c.jsx("p",{className:"text-bambu-gray",children:"Configure Bambuddy"})]}),c.jsxs("div",{className:"flex gap-1 mb-6 border-b border-bambu-dark-tertiary",children:[c.jsx("button",{onClick:()=>T("general"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px ${A==="general"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:"General"}),c.jsxs("button",{onClick:()=>T("plugs"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${A==="plugs"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[c.jsx(Ox,{className:"w-4 h-4"}),"Smart Plugs",ve&&ve.length>0&&c.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:ve.length})]}),c.jsxs("button",{onClick:()=>T("notifications"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${A==="notifications"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[c.jsx(fh,{className:"w-4 h-4"}),"Notifications",H&&H.length>0&&c.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:H.length})]}),c.jsxs("button",{onClick:()=>T("apikeys"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${A==="apikeys"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[c.jsx(Op,{className:"w-4 h-4"}),"API Keys",re&&re.length>0&&c.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:re.length})]})]}),A==="general"&&c.jsxs("div",{className:"flex flex-col lg:flex-row gap-6 lg:gap-8",children:[c.jsxs("div",{className:"space-y-6 flex-1 lg:max-w-xl",children:[c.jsxs(Nt,{children:[c.jsx(za,{children:c.jsx("h2",{className:"text-lg font-semibold text-white",children:e("settings.general")})}),c.jsxs(Dt,{className:"space-y-4",children:[c.jsxs("div",{children:[c.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[c.jsx(l0,{className:"w-4 h-4 inline mr-1"}),e("settings.language")]}),c.jsx("select",{value:n.language,onChange:Q=>n.changeLanguage(Q.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:r5.map(Q=>c.jsxs("option",{value:Q.code,children:[Q.nativeName," (",Q.name,")"]},Q.code))}),c.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:e("settings.languageDescription")})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("settings.defaultView")}),c.jsx("select",{value:E,onChange:Q=>ue(Q.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:p0.map(Q=>c.jsx("option",{value:Q.to,children:e(Q.labelKey)},Q.id))}),c.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:e("settings.defaultViewDescription")})]}),c.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Date Format"}),c.jsxs("select",{value:i.date_format||"system",onChange:Q=>at("date_format",Q.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[c.jsx("option",{value:"system",children:"System Default"}),c.jsx("option",{value:"us",children:"US (MM/DD/YYYY)"}),c.jsx("option",{value:"eu",children:"EU (DD/MM/YYYY)"}),c.jsx("option",{value:"iso",children:"ISO (YYYY-MM-DD)"})]})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Time Format"}),c.jsxs("select",{value:i.time_format||"system",onChange:Q=>at("time_format",Q.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[c.jsx("option",{value:"system",children:"System Default"}),c.jsx("option",{value:"12h",children:"12-hour (3:30 PM)"}),c.jsx("option",{value:"24h",children:"24-hour (15:30)"})]})]})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Default Printer"}),c.jsxs("select",{value:i.default_printer_id??"",onChange:Q=>at("default_printer_id",Q.target.value?Number(Q.target.value):null),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[c.jsx("option",{value:"",children:"No default (ask each time)"}),ke?.map(Q=>c.jsx("option",{value:Q.id,children:Q.name},Q.id))]}),c.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Pre-select this printer for uploads, reprints, and other operations."})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-white",children:"Sidebar order"}),c.jsx("p",{className:"text-sm text-bambu-gray",children:"Drag items in the sidebar to reorder. Reset to default order here."})]}),c.jsxs(Ie,{variant:"secondary",size:"sm",onClick:xe,children:[c.jsx(Im,{className:"w-4 h-4"}),"Reset"]})]})]})]}),c.jsxs(Nt,{children:[c.jsx(za,{children:c.jsx("h2",{className:"text-lg font-semibold text-white",children:"Archive Settings"})}),c.jsxs(Dt,{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-white",children:"Auto-archive prints"}),c.jsx("p",{className:"text-sm text-bambu-gray",children:"Automatically save 3MF files when prints complete"})]}),c.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[c.jsx("input",{type:"checkbox",checked:i.auto_archive,onChange:Q=>at("auto_archive",Q.target.checked),className:"sr-only peer"}),c.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-white",children:"Save thumbnails"}),c.jsx("p",{className:"text-sm text-bambu-gray",children:"Extract and save preview images from 3MF files"})]}),c.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[c.jsx("input",{type:"checkbox",checked:i.save_thumbnails,onChange:Q=>at("save_thumbnails",Q.target.checked),className:"sr-only peer"}),c.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-white",children:"Capture finish photo"}),c.jsx("p",{className:"text-sm text-bambu-gray",children:"Take a photo from printer camera when print completes"})]}),c.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[c.jsx("input",{type:"checkbox",checked:i.capture_finish_photo,onChange:Q=>at("capture_finish_photo",Q.target.checked),className:"sr-only peer"}),c.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),i.capture_finish_photo&&B&&!B.installed&&c.jsxs("div",{className:"flex items-start gap-2 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[c.jsx(Qr,{className:"w-5 h-5 text-yellow-500 flex-shrink-0 mt-0.5"}),c.jsxs("div",{className:"text-sm",children:[c.jsx("p",{className:"text-yellow-500 font-medium",children:"ffmpeg not installed"}),c.jsxs("p",{className:"text-bambu-gray mt-1",children:["Camera capture requires ffmpeg. Install it via"," ",c.jsx("code",{className:"bg-bambu-dark-tertiary px-1 rounded",children:"brew install ffmpeg"})," (macOS) or"," ",c.jsx("code",{className:"bg-bambu-dark-tertiary px-1 rounded",children:"apt install ffmpeg"})," (Linux)."]})]})]})]})]}),c.jsxs(Nt,{children:[c.jsx(za,{children:c.jsx("h2",{className:"text-lg font-semibold text-white",children:"Cost Tracking"})}),c.jsxs(Dt,{className:"space-y-4",children:[c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Default filament cost (per kg)"}),c.jsx("input",{type:"number",step:"0.01",min:"0",value:i.default_filament_cost,onChange:Q=>at("default_filament_cost",parseFloat(Q.target.value)||0),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Currency"}),c.jsxs("select",{value:i.currency,onChange:Q=>at("currency",Q.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[c.jsx("option",{value:"USD",children:"USD ($)"}),c.jsx("option",{value:"EUR",children:"EUR (€)"}),c.jsx("option",{value:"GBP",children:"GBP (£)"}),c.jsx("option",{value:"CHF",children:"CHF (Fr.)"}),c.jsx("option",{value:"JPY",children:"JPY (¥)"}),c.jsx("option",{value:"CNY",children:"CNY (¥)"}),c.jsx("option",{value:"CAD",children:"CAD ($)"}),c.jsx("option",{value:"AUD",children:"AUD ($)"})]})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Electricity cost per kWh"}),c.jsx("input",{type:"number",step:"0.01",min:"0",value:i.energy_cost_per_kwh,onChange:Q=>at("energy_cost_per_kwh",parseFloat(Q.target.value)||0),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Energy display mode"}),c.jsxs("select",{value:i.energy_tracking_mode||"total",onChange:Q=>at("energy_tracking_mode",Q.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[c.jsx("option",{value:"print",children:"Prints Only"}),c.jsx("option",{value:"total",children:"Total Consumption"})]}),c.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i.energy_tracking_mode==="print"?"Dashboard shows sum of energy used during prints":"Dashboard shows lifetime energy from smart plugs"})]})]})]})]}),c.jsxs("div",{className:"space-y-6 flex-1 lg:max-w-md",children:[c.jsxs(Nt,{children:[c.jsx(za,{children:c.jsx("h2",{className:"text-lg font-semibold text-white",children:"AMS Display Thresholds"})}),c.jsxs(Dt,{className:"space-y-4",children:[c.jsx("p",{className:"text-sm text-bambu-gray",children:"Configure color thresholds for AMS humidity and temperature indicators."}),c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{className:"flex items-center gap-2 text-white",children:[c.jsx(loe,{className:"w-4 h-4 text-blue-400"}),c.jsx("span",{className:"font-medium",children:"Humidity"})]}),c.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Good (green) ≤"}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("input",{type:"number",min:"0",max:"100",value:i.ams_humidity_good??40,onChange:Q=>at("ams_humidity_good",parseInt(Q.target.value)||40),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),c.jsx("span",{className:"text-bambu-gray",children:"%"})]})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Fair (orange) ≤"}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("input",{type:"number",min:"0",max:"100",value:i.ams_humidity_fair??60,onChange:Q=>at("ams_humidity_fair",parseInt(Q.target.value)||60),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),c.jsx("span",{className:"text-bambu-gray",children:"%"})]})]})]}),c.jsx("p",{className:"text-xs text-bambu-gray",children:"Above fair threshold shows as red (bad)"})]}),c.jsxs("div",{className:"space-y-3 pt-2 border-t border-bambu-dark-tertiary",children:[c.jsxs("div",{className:"flex items-center gap-2 text-white",children:[c.jsx($p,{className:"w-4 h-4 text-orange-400"}),c.jsx("span",{className:"font-medium",children:"Temperature"})]}),c.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Good (blue) ≤"}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("input",{type:"number",step:"0.5",min:"0",max:"60",value:i.ams_temp_good??28,onChange:Q=>at("ams_temp_good",parseFloat(Q.target.value)||28),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),c.jsx("span",{className:"text-bambu-gray",children:"°C"})]})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Fair (orange) ≤"}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("input",{type:"number",step:"0.5",min:"0",max:"60",value:i.ams_temp_fair??35,onChange:Q=>at("ams_temp_fair",parseFloat(Q.target.value)||35),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),c.jsx("span",{className:"text-bambu-gray",children:"°C"})]})]})]}),c.jsx("p",{className:"text-xs text-bambu-gray",children:"Above fair threshold shows as red (hot)"})]})]})]}),c.jsx(F9e,{}),c.jsx(B9e,{})]}),c.jsxs("div",{className:"space-y-6 flex-1 lg:max-w-sm",children:[c.jsxs(Nt,{children:[c.jsx(za,{children:c.jsx("h2",{className:"text-lg font-semibold text-white",children:"Updates"})}),c.jsxs(Dt,{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-white",children:"Check for updates"}),c.jsx("p",{className:"text-sm text-bambu-gray",children:"Automatically check for new versions on startup"})]}),c.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[c.jsx("input",{type:"checkbox",checked:i.check_updates,onChange:Q=>at("check_updates",Q.target.checked),className:"sr-only peer"}),c.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),c.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:[c.jsxs("div",{className:"flex items-center justify-between mb-2",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-white",children:"Current version"}),c.jsxs("p",{className:"text-sm text-bambu-gray",children:["v",j?.version||"..."]})]}),c.jsxs(Ie,{variant:"secondary",size:"sm",onClick:()=>be(),disabled:_e,children:[_e?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(qs,{className:"w-4 h-4"}),"Check now"]})]}),te?.update_available?c.jsxs("div",{className:"mt-4 p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg",children:[c.jsxs("div",{className:"flex items-start justify-between",children:[c.jsxs("div",{children:[c.jsxs("p",{className:"text-bambu-green font-medium",children:["Update available: v",te.latest_version]}),te.release_name&&te.release_name!==te.latest_version&&c.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:te.release_name}),te.release_notes&&c.jsx("p",{className:"text-sm text-bambu-gray mt-2 whitespace-pre-line line-clamp-3",children:te.release_notes})]}),te.release_url&&c.jsx("a",{href:te.release_url,target:"_blank",rel:"noopener noreferrer",className:"text-bambu-gray hover:text-white transition-colors",title:"View release on GitHub",children:c.jsx(ro,{className:"w-4 h-4"})})]}),ge?.status==="downloading"||ge?.status==="installing"?c.jsxs("div",{className:"mt-3",children:[c.jsxs("div",{className:"flex items-center gap-2 text-sm text-bambu-gray",children:[c.jsx(At,{className:"w-4 h-4 animate-spin"}),c.jsx("span",{children:ge.message})]}),c.jsx("div",{className:"mt-2 w-full bg-bambu-dark-tertiary rounded-full h-2",children:c.jsx("div",{className:"bg-bambu-green h-2 rounded-full transition-all duration-300",style:{width:`${ge.progress}%`}})})]}):ge?.status==="complete"?c.jsx("div",{className:"mt-3 p-2 bg-bambu-green/20 rounded text-sm text-bambu-green",children:ge.message}):ge?.status==="error"?c.jsx("div",{className:"mt-3 p-2 bg-red-500/20 rounded text-sm text-red-400",children:ge.error||ge.message}):c.jsxs(Ie,{className:"mt-3",onClick:()=>Ae.mutate(),disabled:Ae.isPending,children:[Ae.isPending?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(ya,{className:"w-4 h-4"}),"Install Update"]})]}):te?.error?c.jsxs("div",{className:"mt-2 p-2 bg-red-500/10 border border-red-500/30 rounded text-sm text-red-400",children:["Failed to check for updates: ",te.error]}):te&&!te.update_available?c.jsx("p",{className:"mt-2 text-sm text-bambu-gray",children:"You're running the latest version"}):null]})]})]}),c.jsxs(Nt,{children:[c.jsx(za,{children:c.jsx("h2",{className:"text-lg font-semibold text-white",children:"Data Management"})}),c.jsxs(Dt,{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-white",children:"Backup Data"}),c.jsx("p",{className:"text-sm text-bambu-gray",children:"Export settings, providers, printers, and more"})]}),c.jsxs(Ie,{variant:"secondary",size:"sm",onClick:()=>ee(!0),children:[c.jsx(ya,{className:"w-4 h-4"}),"Export"]})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-white",children:"Restore Backup"}),c.jsx("p",{className:"text-sm text-bambu-gray",children:"Import settings from a backup file with duplicate handling options"})]}),c.jsxs(Ie,{variant:"secondary",size:"sm",onClick:()=>fe(!0),children:[c.jsx(ma,{className:"w-4 h-4"}),"Restore"]})]}),c.jsx("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-white",children:"Clear Notification Logs"}),c.jsx("p",{className:"text-sm text-bambu-gray",children:"Delete notification logs older than 30 days"})]}),c.jsxs(Ie,{variant:"secondary",size:"sm",onClick:()=>W(!0),children:[c.jsx(kn,{className:"w-4 h-4"}),"Clear"]})]})}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-white",children:"Reset UI Preferences"}),c.jsx("p",{className:"text-sm text-bambu-gray",children:"Reset sidebar order, theme, view modes, and layout preferences. Printers, archives, and settings are not affected."})]}),c.jsxs(Ie,{variant:"secondary",size:"sm",onClick:()=>Y(!0),children:[c.jsx(kn,{className:"w-4 h-4"}),"Reset"]})]})]})]})]})]}),A==="plugs"&&c.jsxs("div",{className:"max-w-4xl",children:[c.jsxs("div",{className:"flex items-start justify-between mb-6",children:[c.jsxs("div",{children:[c.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[c.jsx(Ox,{className:"w-5 h-5 text-bambu-green"}),"Smart Plugs"]}),c.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:"Connect Tasmota-based smart plugs to automate power control and track energy usage for your printers."})]}),c.jsxs("div",{className:"flex items-center gap-2 pt-1 shrink-0",children:[ve&&ve.filter(Q=>Q.enabled).length>1&&c.jsxs(c.Fragment,{children:[c.jsxs(Ie,{variant:"secondary",size:"sm",className:"whitespace-nowrap",onClick:()=>U("on"),disabled:ce.isPending,title:"Turn all plugs on",children:[ce.isPending?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(fd,{className:"w-4 h-4 text-bambu-green"}),"All On"]}),c.jsxs(Ie,{variant:"secondary",size:"sm",className:"whitespace-nowrap",onClick:()=>U("off"),disabled:ce.isPending,title:"Turn all plugs off",children:[ce.isPending?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(yR,{className:"w-4 h-4 text-red-400"}),"All Off"]})]}),c.jsxs(Ie,{className:"whitespace-nowrap",onClick:()=>{u(null),o(!0)},children:[c.jsx(fr,{className:"w-4 h-4"}),"Add Smart Plug"]})]})]}),ve&&ve.length>0&&c.jsxs(Nt,{className:"mb-6",children:[c.jsx(za,{children:c.jsxs("h3",{className:"text-base font-semibold text-white flex items-center gap-2",children:[c.jsx(am,{className:"w-4 h-4 text-yellow-400"}),"Energy Summary",ut&&c.jsx(At,{className:"w-4 h-4 animate-spin text-bambu-gray ml-2"})]})}),c.jsx(Dt,{children:de?c.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[c.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[c.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[c.jsx(am,{className:"w-3 h-3"}),"Current Power"]}),c.jsxs("div",{className:"text-xl font-bold text-white",children:[de.totalPower.toFixed(1),c.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"W"})]}),c.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:[de.reachableCount,"/",de.totalPlugs," plugs online"]})]}),c.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[c.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[c.jsx(qr,{className:"w-3 h-3"}),"Today"]}),c.jsxs("div",{className:"text-xl font-bold text-white",children:[de.totalToday.toFixed(2),c.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"kWh"})]}),i&&i.energy_cost_per_kwh>0&&c.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:["~",(de.totalToday*i.energy_cost_per_kwh).toFixed(2)," ",i.currency]})]}),c.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[c.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[c.jsx(Ice,{className:"w-3 h-3"}),"Yesterday"]}),c.jsxs("div",{className:"text-xl font-bold text-white",children:[de.totalYesterday.toFixed(2),c.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"kWh"})]}),i&&i.energy_cost_per_kwh>0&&c.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:["~",(de.totalYesterday*i.energy_cost_per_kwh).toFixed(2)," ",i.currency]})]}),c.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[c.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[c.jsx(a3,{className:"w-3 h-3"}),"Total"]}),c.jsxs("div",{className:"text-xl font-bold text-white",children:[de.totalLifetime.toFixed(1),c.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"kWh"})]}),i&&i.energy_cost_per_kwh>0&&c.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:["~",(de.totalLifetime*i.energy_cost_per_kwh).toFixed(2)," ",i.currency]})]})]}):ut?null:c.jsx("p",{className:"text-sm text-bambu-gray",children:"Enable plugs to see energy summary"})})]}),je?c.jsx("div",{className:"flex justify-center py-12",children:c.jsx(At,{className:"w-8 h-8 text-bambu-green animate-spin"})}):ve&&ve.length>0?c.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:ve.map(Q=>c.jsx(M9e,{plug:Q,onEdit:Fe=>{u(Fe),o(!0)}},Q.id))}):c.jsx(Nt,{children:c.jsx(Dt,{className:"py-12",children:c.jsxs("div",{className:"text-center text-bambu-gray",children:[c.jsx(Ox,{className:"w-16 h-16 mx-auto mb-4 opacity-30"}),c.jsx("p",{className:"text-lg font-medium text-white mb-2",children:"No smart plugs configured"}),c.jsx("p",{className:"text-sm mb-4",children:"Add a Tasmota-based smart plug to track energy usage and automate power control."}),c.jsxs(Ie,{onClick:()=>{u(null),o(!0)},children:[c.jsx(fr,{className:"w-4 h-4"}),"Add Your First Smart Plug"]})]})})})]}),A==="notifications"&&c.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-8",children:[c.jsxs("div",{children:[c.jsxs("div",{className:"flex items-center justify-between mb-4",children:[c.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[c.jsx(fh,{className:"w-5 h-5 text-bambu-green"}),"Providers"]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs(Ie,{size:"sm",variant:"secondary",onClick:()=>b(!0),children:[c.jsx(o3,{className:"w-4 h-4"}),"Log"]}),H&&H.length>0&&c.jsxs(Ie,{size:"sm",variant:"secondary",onClick:()=>{st(null),Ve.mutate()},disabled:Ve.isPending,children:[Ve.isPending?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(_R,{className:"w-4 h-4"}),"Test All"]}),c.jsxs(Ie,{size:"sm",onClick:()=>{m(null),f(!0)},children:[c.jsx(fr,{className:"w-4 h-4"}),"Add"]})]})]}),c.jsx(Nt,{className:"mb-4",children:c.jsx(Dt,{className:"py-3",children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-white text-sm font-medium",children:e("settings.notificationLanguage")}),c.jsx("p",{className:"text-xs text-bambu-gray",children:e("settings.notificationLanguageDescription")})]}),c.jsx("select",{value:i.notification_language||"en",onChange:Q=>at("notification_language",Q.target.value),className:"px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:ring-1 focus:ring-bambu-green",children:r5.map(Q=>c.jsx("option",{value:Q.code,children:Q.nativeName},Q.code))})]})})}),ze&&c.jsx(Nt,{className:"mb-4",children:c.jsxs(Dt,{className:"py-3",children:[c.jsxs("div",{className:"flex items-center justify-between mb-2",children:[c.jsx("span",{className:"text-sm font-medium text-white",children:"Test Results"}),c.jsx("button",{onClick:()=>st(null),className:"text-bambu-gray hover:text-white text-xs",children:"Dismiss"})]}),c.jsxs("div",{className:"flex items-center gap-4 text-sm mb-2",children:[c.jsxs("span",{className:"flex items-center gap-1 text-bambu-green",children:[c.jsx(ds,{className:"w-4 h-4"}),ze.success," passed"]}),ze.failed>0&&c.jsxs("span",{className:"flex items-center gap-1 text-red-400",children:[c.jsx(hd,{className:"w-4 h-4"}),ze.failed," failed"]})]}),ze.results.filter(Q=>!Q.success).length>0&&c.jsx("div",{className:"space-y-1 mt-2 pt-2 border-t border-bambu-dark-tertiary",children:ze.results.filter(Q=>!Q.success).map(Q=>c.jsxs("div",{className:"text-xs text-red-400",children:[c.jsxs("span",{className:"font-medium",children:[Q.provider_name,":"]})," ",Q.message]},Q.provider_id))})]})}),z?c.jsx("div",{className:"flex justify-center py-12",children:c.jsx(At,{className:"w-6 h-6 text-bambu-green animate-spin"})}):H&&H.length>0?c.jsx("div",{className:"space-y-3",children:H.map(Q=>c.jsx(C9e,{provider:Q,onEdit:Fe=>{m(Fe),f(!0)}},Q.id))}):c.jsx(Nt,{children:c.jsx(Dt,{className:"py-8",children:c.jsxs("div",{className:"text-center text-bambu-gray",children:[c.jsx(fh,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),c.jsx("p",{className:"text-sm font-medium text-white mb-2",children:"No providers configured"}),c.jsx("p",{className:"text-xs mb-3",children:"Add a provider to receive alerts."}),c.jsxs(Ie,{size:"sm",onClick:()=>{m(null),f(!0)},children:[c.jsx(fr,{className:"w-4 h-4"}),"Add Provider"]})]})})})]}),c.jsxs("div",{children:[c.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2 mb-4",children:[c.jsx(Ya,{className:"w-5 h-5 text-bambu-green"}),"Message Templates"]}),c.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:"Customize notification messages for each event."}),we?c.jsx("div",{className:"flex justify-center py-8",children:c.jsx(At,{className:"w-6 h-6 text-bambu-green animate-spin"})}):Ne&&Ne.length>0?c.jsx("div",{className:"space-y-2",children:Ne.map(Q=>c.jsx(Nt,{className:"cursor-pointer hover:border-bambu-green/50 transition-colors",onClick:()=>y(Q),children:c.jsx(Dt,{className:"py-2.5 px-3",children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsx("p",{className:"text-white font-medium text-sm truncate",children:Q.name}),c.jsx("p",{className:"text-bambu-gray text-xs truncate mt-0.5",children:Q.title_template})]}),c.jsx("button",{className:"p-1.5 hover:bg-bambu-dark-tertiary rounded transition-colors shrink-0 ml-2",onClick:Fe=>{Fe.stopPropagation(),y(Q)},children:c.jsx(vR,{className:"w-4 h-4 text-bambu-gray"})})]})})},Q.id))}):c.jsx(Nt,{children:c.jsx(Dt,{className:"py-8",children:c.jsxs("div",{className:"text-center text-bambu-gray",children:[c.jsx(Ya,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),c.jsx("p",{className:"text-sm",children:"No templates available. Restart the backend to seed default templates."})]})})})]})]}),A==="apikeys"&&c.jsxs("div",{className:"max-w-3xl",children:[c.jsxs("div",{className:"flex items-start justify-between gap-4 mb-6",children:[c.jsxs("div",{className:"flex-1",children:[c.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[c.jsx(Op,{className:"w-5 h-5 text-bambu-green"}),"API Keys"]}),c.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:"Create API keys for external integrations and webhooks. Use these keys to control your printers from automation tools like Home Assistant."})]}),c.jsxs(Ie,{size:"sm",onClick:()=>C(!0),className:"flex-shrink-0",children:[c.jsx(fr,{className:"w-4 h-4"}),"Create Key"]})]}),L&&c.jsx(Nt,{className:"mb-6 border-bambu-green",children:c.jsx(Dt,{className:"py-4",children:c.jsxs("div",{className:"flex items-start gap-3",children:[c.jsx(ds,{className:"w-5 h-5 text-bambu-green flex-shrink-0 mt-0.5"}),c.jsxs("div",{className:"flex-1",children:[c.jsx("p",{className:"text-white font-medium mb-1",children:"API Key Created Successfully"}),c.jsx("p",{className:"text-sm text-bambu-gray mb-2",children:"Copy this key now - it won't be shown again!"}),c.jsxs("div",{className:"flex items-center gap-2 bg-bambu-dark rounded-lg p-2",children:[c.jsx("code",{className:"flex-1 text-sm text-bambu-green font-mono break-all",children:L}),c.jsx(Ie,{variant:"secondary",size:"sm",onClick:async()=>{try{if(navigator.clipboard&&navigator.clipboard.writeText)await navigator.clipboard.writeText(L);else{const Q=document.createElement("textarea");Q.value=L,Q.style.position="fixed",Q.style.left="-999999px",document.body.appendChild(Q),Q.select(),document.execCommand("copy"),document.body.removeChild(Q)}r("Key copied to clipboard")}catch{r("Failed to copy key","error")}},children:c.jsx(Dh,{className:"w-4 h-4"})})]}),c.jsx(Ie,{variant:"secondary",size:"sm",className:"mt-3",onClick:()=>q(null),children:"Dismiss"})]})]})})}),P&&c.jsxs(Nt,{className:"mb-6",children:[c.jsx(za,{children:c.jsx("h3",{className:"text-base font-semibold text-white",children:"Create New API Key"})}),c.jsxs(Dt,{className:"space-y-4",children:[c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Key Name"}),c.jsx("input",{type:"text",value:I,onChange:Q=>N(Q.target.value),placeholder:"e.g., Home Assistant, OctoPrint",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:"Permissions"}),c.jsxs("div",{className:"space-y-2",children:[c.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[c.jsx("input",{type:"checkbox",checked:D.can_read_status,onChange:Q=>F(Fe=>({...Fe,can_read_status:Q.target.checked})),className:"w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green"}),c.jsxs("div",{children:[c.jsx("span",{className:"text-white",children:"Read Status"}),c.jsx("p",{className:"text-xs text-bambu-gray",children:"View printer status and queue"})]})]}),c.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[c.jsx("input",{type:"checkbox",checked:D.can_queue,onChange:Q=>F(Fe=>({...Fe,can_queue:Q.target.checked})),className:"w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green"}),c.jsxs("div",{children:[c.jsx("span",{className:"text-white",children:"Manage Queue"}),c.jsx("p",{className:"text-xs text-bambu-gray",children:"Add and remove items from print queue"})]})]}),c.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[c.jsx("input",{type:"checkbox",checked:D.can_control_printer,onChange:Q=>F(Fe=>({...Fe,can_control_printer:Q.target.checked})),className:"w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green"}),c.jsxs("div",{children:[c.jsx("span",{className:"text-white",children:"Control Printer"}),c.jsx("p",{className:"text-xs text-bambu-gray",children:"Pause, resume, and stop prints"})]})]})]})]}),c.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[c.jsxs(Ie,{onClick:()=>J.mutate({name:I||"Unnamed Key",...D}),disabled:J.isPending,children:[J.isPending?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(fr,{className:"w-4 h-4"}),"Create Key"]}),c.jsx(Ie,{variant:"secondary",onClick:()=>C(!1),children:"Cancel"})]})]})]}),G?c.jsx("div",{className:"flex justify-center py-12",children:c.jsx(At,{className:"w-8 h-8 text-bambu-green animate-spin"})}):re&&re.length>0?c.jsx("div",{className:"space-y-3",children:re.map(Q=>c.jsx(Nt,{children:c.jsx(Dt,{className:"py-3",children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx(Op,{className:`w-5 h-5 ${Q.enabled?"text-bambu-green":"text-bambu-gray"}`}),c.jsxs("div",{children:[c.jsx("p",{className:"text-white font-medium",children:Q.name}),c.jsxs("p",{className:"text-xs text-bambu-gray",children:[Q.key_prefix,"••••••••",Q.last_used&&` · Last used: ${new Date(Q.last_used).toLocaleDateString()}`]})]})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("div",{className:"flex gap-1 text-xs",children:[Q.can_read_status&&c.jsx("span",{className:"px-1.5 py-0.5 bg-blue-500/20 text-blue-400 rounded",children:"Read"}),Q.can_queue&&c.jsx("span",{className:"px-1.5 py-0.5 bg-green-500/20 text-green-400 rounded",children:"Queue"}),Q.can_control_printer&&c.jsx("span",{className:"px-1.5 py-0.5 bg-orange-500/20 text-orange-400 rounded",children:"Control"})]}),c.jsx(Ie,{variant:"secondary",size:"sm",onClick:()=>V(Q.id),children:c.jsx(kn,{className:"w-4 h-4 text-red-400"})})]})]})})},Q.id))}):c.jsx(Nt,{children:c.jsx(Dt,{className:"py-12",children:c.jsxs("div",{className:"text-center text-bambu-gray",children:[c.jsx(Op,{className:"w-16 h-16 mx-auto mb-4 opacity-30"}),c.jsx("p",{className:"text-lg font-medium text-white mb-2",children:"No API keys"}),c.jsx("p",{className:"text-sm mb-4",children:"Create an API key to integrate with external services."}),c.jsxs(Ie,{onClick:()=>C(!0),children:[c.jsx(fr,{className:"w-4 h-4"}),"Create Your First Key"]})]})})}),c.jsxs(Nt,{className:"mt-6",children:[c.jsx(za,{children:c.jsx("h3",{className:"text-base font-semibold text-white",children:"Webhook Endpoints"})}),c.jsxs(Dt,{className:"space-y-3 text-sm",children:[c.jsxs("p",{className:"text-bambu-gray",children:["Use your API key in the ",c.jsx("code",{className:"text-bambu-green",children:"X-API-Key"})," header."]}),c.jsxs("div",{className:"space-y-2 font-mono text-xs",children:[c.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[c.jsx("span",{className:"text-blue-400",children:"GET"})," ",c.jsx("span",{className:"text-white",children:"/api/v1/webhook/status"}),c.jsx("span",{className:"text-bambu-gray",children:" - Get all printer status"})]}),c.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[c.jsx("span",{className:"text-blue-400",children:"GET"})," ",c.jsx("span",{className:"text-white",children:"/api/v1/webhook/status/:id"}),c.jsx("span",{className:"text-bambu-gray",children:" - Get specific printer status"})]}),c.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[c.jsx("span",{className:"text-green-400",children:"POST"})," ",c.jsx("span",{className:"text-white",children:"/api/v1/webhook/queue"}),c.jsx("span",{className:"text-bambu-gray",children:" - Add to print queue"})]}),c.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[c.jsx("span",{className:"text-orange-400",children:"POST"})," ",c.jsx("span",{className:"text-white",children:"/api/v1/webhook/printer/:id/pause"}),c.jsx("span",{className:"text-bambu-gray",children:" - Pause print"})]}),c.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[c.jsx("span",{className:"text-orange-400",children:"POST"})," ",c.jsx("span",{className:"text-white",children:"/api/v1/webhook/printer/:id/resume"}),c.jsx("span",{className:"text-bambu-gray",children:" - Resume print"})]}),c.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[c.jsx("span",{className:"text-red-400",children:"POST"})," ",c.jsx("span",{className:"text-white",children:"/api/v1/webhook/printer/:id/stop"}),c.jsx("span",{className:"text-bambu-gray",children:" - Stop print"})]})]})]})]})]}),R!==null&&c.jsx(Kr,{title:"Delete API Key",message:"Are you sure you want to delete this API key? Any integrations using this key will stop working.",confirmText:"Delete Key",variant:"danger",onConfirm:()=>{le.mutate(R),V(null)},onCancel:()=>V(null)}),a&&c.jsx(A9e,{plug:l,onClose:()=>{o(!1),u(null)}}),d&&c.jsx(N9e,{provider:g,onClose:()=>{f(!1),m(null)}}),x&&c.jsx(k9e,{template:x,onClose:()=>y(null)}),v&&c.jsx(D9e,{onClose:()=>b(!1)}),K&&c.jsx(Kr,{title:"Clear Notification Logs",message:"This will permanently delete all notification logs older than 30 days. This action cannot be undone.",confirmText:"Clear Logs",variant:"warning",onConfirm:async()=>{W(!1);try{const Q=await Pe.clearNotificationLogs(30);r(Q.message,"success")}catch{r("Failed to clear logs","error")}},onCancel:()=>W(!1)}),ne&&c.jsx(Kr,{title:"Reset UI Preferences",message:"This will reset all UI preferences to defaults: sidebar order, theme, dashboard layout, view modes, and sorting preferences. Your printers, archives, and server settings will NOT be affected. The page will reload after clearing.",confirmText:"Reset Preferences",variant:"default",onConfirm:()=>{Y(!1),localStorage.clear(),r("UI preferences reset. Refreshing...","success"),setTimeout(()=>window.location.reload(),1e3)},onCancel:()=>Y(!1)}),Z&&c.jsx(Kr,{title:`Turn All Plugs ${Z==="on"?"On":"Off"}`,message:`This will turn ${Z==="on"?"ON":"OFF"} all ${ve?.filter(Q=>Q.enabled).length||0} enabled smart plugs. ${Z==="off"?"Any running printers may be affected!":""}`,confirmText:`Turn All ${Z==="on"?"On":"Off"}`,variant:Z==="off"?"danger":"warning",onConfirm:()=>{const Q=Z;U(null),ce.mutate(Q)},onCancel:()=>U(null)}),$&&c.jsx(j9e,{onClose:()=>ee(!1),onExport:async Q=>{ee(!1);try{const{blob:Fe,filename:pe}=await Pe.exportBackup(Q),Ue=URL.createObjectURL(Fe),Ce=document.createElement("a");Ce.href=Ue,Ce.download=pe,Ce.click(),URL.revokeObjectURL(Ue),r("Backup downloaded","success")}catch{r("Failed to create backup","error")}}}),ae&&c.jsx(L9e,{onClose:()=>fe(!1),onRestore:async(Q,Fe)=>await Pe.importBackup(Q,Fe),onSuccess:()=>{t.invalidateQueries()}})]})}const Pee=t=>{const e=parseFloat(t);return(Math.trunc(e*1e3)/1e3).toFixed(3)},$9e=t=>t.startsWith("HH")?"HF":"S",V9e=t=>{const e=t.match(/^([A-Z]{2}\d{2})/);return e?e[1]:"HH00"},tR=t=>{const e=["High Flow_","High Flow ","Standard_","Standard ","HF_","HF ","S_","S "];for(const r of e)if(t.startsWith(r))return t.slice(r.length);const n=t.indexOf("_");return n>0?t.slice(n+1):t};function BN({profile:t,onEdit:e,onCopy:n,selectionMode:r,isSelected:i,onToggleSelect:s,note:a}){const o=$9e(t.nozzle_id),l=t.nozzle_diameter,u=()=>{r&&s?s():e()};return c.jsxs("div",{className:"flex items-center gap-2",children:[r&&c.jsx("button",{onClick:s,className:"text-bambu-gray hover:text-white transition-colors p-1",children:i?c.jsx(jh,{className:"w-4 h-4 text-bambu-green"}):c.jsx(im,{className:"w-4 h-4"})}),c.jsxs("button",{onClick:u,className:`flex-1 text-left px-3 py-2 bg-bambu-dark rounded hover:bg-bambu-dark-tertiary transition-colors ${i?"ring-1 ring-bambu-green":""}`,children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"text-bambu-green font-mono text-sm font-bold whitespace-nowrap",children:Pee(t.k_value)}),c.jsx("span",{className:"text-white text-sm truncate flex-1",title:t.name,children:t.name||"Unnamed"}),a&&c.jsx("span",{title:"Has note",children:c.jsx(LG,{className:"w-3 h-3 text-yellow-500"})}),c.jsxs("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:[o," ",l]})]}),a&&c.jsxs("div",{className:"text-xs mt-0.5 truncate text-yellow-500/70",title:a,children:["Note: ",a.length>50?a.substring(0,50)+"...":a]})]}),!r&&n&&c.jsx("button",{onClick:d=>{d.stopPropagation(),n()},className:"text-bambu-gray hover:text-white transition-colors p-1",title:"Copy profile",children:c.jsx(Dh,{className:"w-4 h-4"})})]})}function HN({profile:t,printerId:e,nozzleDiameter:n,existingProfiles:r=[],isDualNozzle:i=!1,initialNote:s="",initialNoteKey:a=null,onClose:o,onSave:l,onSaveNote:u}){const{showToast:d}=ri(),[f,g]=M.useState(t?.name||""),[m,x]=M.useState(t?.k_value?Pee(t.k_value):"0.020"),[y,v]=M.useState(t?.filament_id||""),[b,E]=M.useState(t?.nozzle_id?V9e(t.nozzle_id):"HH00"),[S,A]=M.useState(t?.nozzle_diameter||n),[T,P]=M.useState(t?[t.extruder_id]:i?[0,1]:[0]),[C,I]=M.useState(!1),[N,D]=M.useState({current:0,total:0}),[F,L]=M.useState(s),q=pr.useMemo(()=>{const Z=new Map;for(const U of r)if(U.filament_id&&!Z.has(U.filament_id)){const $=tR(U.name||"");Z.set(U.filament_id,{id:U.filament_id,name:$||U.filament_id})}return Array.from(Z.values()).sort((U,$)=>U.name.localeCompare($.name))},[r]),R=_t({mutationFn:Z=>(console.log("[KProfile] Calling API..."),Pe.setKProfile(e,Z)),onSuccess:Z=>{if(console.log("[KProfile] Save success:",Z),d("K-profile saved"),u&&F!==s){let U;F===""&&a?U=a:t&&t.slot_id>0?U=t.setting_id||`slot_${t.slot_id}_${t.filament_id}_${t.extruder_id}`:U=`name_${f}_${y}`,u(U,F)}I(!0),setTimeout(()=>{I(!1),l()},2500)},onError:Z=>{console.error("[KProfile] Save error:",Z),d(Z.message,"error"),I(!1)}}),V=_t({mutationFn:Z=>(console.log("[KProfile] Deleting profile..."),Pe.deleteKProfile(e,Z)),onSuccess:Z=>{console.log("[KProfile] Delete success:",Z),d("K-profile deleted"),I(!0),setTimeout(()=>{I(!1),o()},4e3)},onError:Z=>{console.error("[KProfile] Delete error:",Z),d(Z.message,"error"),I(!1)}}),[K,W]=M.useState(!1),ne=()=>{t&&V.mutate({slot_id:t.slot_id,extruder_id:t.extruder_id,nozzle_id:t.nozzle_id,nozzle_diameter:t.nozzle_diameter,filament_id:t.filament_id,setting_id:t.setting_id})},Y=async Z=>{if(Z.preventDefault(),i&&!t&&T.length===0){d("Please select at least one extruder","error");return}const U=parseFloat(m).toFixed(6),$=`${b}-${S}`;if(t||T.length===1){const ae={name:f,k_value:U,filament_id:y,nozzle_id:$,nozzle_diameter:S,extruder_id:t?t.extruder_id:T[0],setting_id:t?.setting_id,slot_id:t?.slot_id??0};console.log("[KProfile] Saving profile:",ae),R.mutate(ae);return}I(!0),D({current:1,total:T.length});const ee=T.map(ae=>({name:f,k_value:U,filament_id:y,nozzle_id:$,nozzle_diameter:S,extruder_id:ae,setting_id:void 0,slot_id:0}));console.log(`[KProfile] Saving ${ee.length} profiles in batch:`,ee);try{if(await Pe.setKProfilesBatch(e,ee),d(`K-profile saved to ${T.length} extruders`),u&&F){const ae=`name_${f}_${y}`;u(ae,F)}}catch(ae){console.error("[KProfile] Failed to save batch:",ae),d("Failed to save K-profiles","error"),I(!1),D({current:0,total:0});return}D({current:T.length,total:T.length}),setTimeout(()=>{I(!1),D({current:0,total:0}),l()},3e3)};return c.jsxs("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:[c.jsxs(Nt,{className:"w-full max-w-md relative",children:[C&&c.jsxs("div",{className:"absolute inset-0 bg-bambu-dark-secondary/90 flex flex-col items-center justify-center z-10 rounded-lg",children:[c.jsx(At,{className:"w-8 h-8 text-bambu-green animate-spin mb-3"}),c.jsx("p",{className:"text-white font-medium",children:N.total>1?`Saving to extruder ${N.current}/${N.total}...`:"Syncing with printer..."}),c.jsx("p",{className:"text-bambu-gray text-sm mt-1",children:"Please wait"})]}),c.jsxs(Dt,{className:"p-0",children:[c.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[c.jsx("h2",{className:"text-xl font-semibold text-white",children:t?"Edit K-Profile":"Add K-Profile"}),c.jsx("button",{onClick:o,className:"text-bambu-gray hover:text-white transition-colors",disabled:C,children:c.jsx(Gt,{className:"w-5 h-5"})})]}),c.jsxs("form",{onSubmit:Y,className:"p-4 space-y-4",children:[c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Profile Name"}),c.jsx("input",{type:"text",value:f,onChange:Z=>g(Z.target.value),disabled:!!t,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${t?"opacity-60 cursor-not-allowed":""}`,placeholder:"My PLA Profile",required:!t})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"K-Value"}),c.jsx("input",{type:"text",inputMode:"decimal",value:m,onChange:Z=>{const U=Z.target.value;(U===""||/^\d*\.?\d*$/.test(U))&&x(U)},onBlur:Z=>{const U=parseFloat(Z.target.value);isNaN(U)||x((Math.trunc(U*1e3)/1e3).toFixed(3))},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none font-mono",placeholder:"0.020",required:!0}),c.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Typical range: 0.01 - 0.06 for PLA, 0.02 - 0.10 for PETG"})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Filament"}),c.jsxs("select",{value:y,onChange:Z=>{const U=Z.target.value;if(v(U),!t&&U&&!f){const $=q.find(ee=>ee.id===U);$&&g(`${b==="HH00"?"HF":"S"} ${$.name}`)}},disabled:!!t,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${t?"opacity-60 cursor-not-allowed":""}`,required:!t,children:[c.jsx("option",{value:"",children:"Select filament..."}),t?.filament_id&&c.jsx("option",{value:t.filament_id,children:q.find(Z=>Z.id===t.filament_id)?.name||t.filament_id},t.filament_id),!t&&q.map(Z=>c.jsx("option",{value:Z.id,children:Z.name},Z.id))]}),!t&&q.length===0&&c.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"No filaments found. Create a K-profile in Bambu Studio first."})]}),c.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Flow Type"}),c.jsxs("select",{value:b,onChange:Z=>{const U=Z.target.value;if(E(U),!t&&y&&!f){const $=q.find(ee=>ee.id===y);$&&g(`${U==="HS00"?"HF":"S"} ${$.name}`)}},disabled:!!t,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${t?"opacity-60 cursor-not-allowed":""}`,children:[c.jsx("option",{value:"HH00",children:"High Flow"}),c.jsx("option",{value:"HS00",children:"Standard"})]})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Nozzle Size"}),c.jsxs("select",{value:S,onChange:Z=>A(Z.target.value),disabled:!!t,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${t?"opacity-60 cursor-not-allowed":""}`,children:[c.jsx("option",{value:"0.2",children:"0.2mm"}),c.jsx("option",{value:"0.4",children:"0.4mm"}),c.jsx("option",{value:"0.6",children:"0.6mm"}),c.jsx("option",{value:"0.8",children:"0.8mm"})]})]})]}),i&&c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:t?"Extruder":"Extruders"}),t?c.jsx("div",{className:"px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white opacity-60",children:t.extruder_id===1?"Left":"Right"}):c.jsxs("div",{className:"flex gap-4",children:[c.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[c.jsx("input",{type:"checkbox",checked:T.includes(1),onChange:Z=>{Z.target.checked?P([...T,1]):P(T.filter(U=>U!==1))},className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0 accent-bambu-green"}),c.jsx("span",{className:"text-white",children:"Left"})]}),c.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[c.jsx("input",{type:"checkbox",checked:T.includes(0),onChange:Z=>{Z.target.checked?P([...T,0]):P(T.filter(U=>U!==0))},className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0 accent-bambu-green"}),c.jsx("span",{className:"text-white",children:"Right"})]})]})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Notes (stored locally)"}),c.jsx("textarea",{value:F,onChange:Z=>L(Z.target.value),placeholder:"Add notes about this profile...",rows:2,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none resize-none"}),c.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Notes are saved in Bambuddy, not on the printer"})]}),c.jsxs("div",{className:"flex gap-2 pt-4",children:[t&&c.jsx(Ie,{type:"button",variant:"secondary",onClick:()=>W(!0),disabled:V.isPending||C,className:"text-red-500 hover:bg-red-500/10",children:V.isPending?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(kn,{className:"w-4 h-4"})}),c.jsx(Ie,{type:"button",variant:"secondary",onClick:o,disabled:C,className:"flex-1",children:"Cancel"}),c.jsxs(Ie,{type:"submit",disabled:R.isPending||C,className:"flex-1",children:[R.isPending?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(xR,{className:"w-4 h-4"}),"Save"]})]})]})]})]}),K&&c.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-[60]",children:c.jsx(Nt,{className:"w-full max-w-sm",children:c.jsxs(Dt,{className:"p-6",children:[c.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[c.jsx("div",{className:"w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center",children:c.jsx(kn,{className:"w-5 h-5 text-red-500"})}),c.jsxs("div",{children:[c.jsx("h3",{className:"text-lg font-semibold text-white",children:"Delete Profile"}),c.jsx("p",{className:"text-sm text-bambu-gray",children:"This cannot be undone"})]})]}),c.jsxs("p",{className:"text-bambu-gray mb-6",children:["Are you sure you want to delete ",c.jsxs("span",{className:"text-white font-medium",children:['"',t?.name,'"']})," from the printer?"]}),c.jsxs("div",{className:"flex gap-3",children:[c.jsx(Ie,{variant:"secondary",onClick:()=>W(!1),className:"flex-1",children:"Cancel"}),c.jsxs(Ie,{onClick:()=>{W(!1),ne()},disabled:V.isPending,className:"flex-1 bg-red-500 hover:bg-red-600 text-white",children:[V.isPending?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(kn,{className:"w-4 h-4"}),"Delete"]})]})]})})})]})}const R_={NOZZLE_DIAMETER:"bambusy_kprofiles_nozzle",SORT_OPTION:"bambusy_kprofiles_sort"};function G9e(){const{showToast:t}=ri(),[e,n]=M.useState(null),[r,i]=M.useState(()=>localStorage.getItem(R_.NOZZLE_DIAMETER)||"0.4"),[s,a]=M.useState(null),[o,l]=M.useState(!1),[u,d]=M.useState(null),[f,g]=M.useState(""),[m,x]=M.useState("all"),[y,v]=M.useState("all"),[b,E]=M.useState(()=>localStorage.getItem(R_.SORT_OPTION)||"name"),[S,A]=M.useState(!1),[T,P]=M.useState(new Set),[C,I]=M.useState(!1),[N,D]=M.useState(!1),F=G=>`${G.slot_id}_${G.extruder_id}`;M.useEffect(()=>{localStorage.setItem(R_.NOZZLE_DIAMETER,r)},[r]),M.useEffect(()=>{localStorage.setItem(R_.SORT_OPTION,b)},[b]);const{data:L,isLoading:q}=yt({queryKey:["printers"],queryFn:Pe.getPrinters}),{data:R,isLoading:V,isFetching:K,error:W,refetch:ne}=yt({queryKey:["kprofiles",e,r],queryFn:async()=>{console.log("[KProfiles] Fetching profiles for printer",e,"nozzle",r);const G=await Pe.getKProfiles(e,r);return console.log("[KProfiles] Received profiles:",G?.profiles?.length||0,"profiles"),G},enabled:!!e,retry:!1,staleTime:0,gcTime:0,refetchOnMount:"always"}),{data:Y}=yt({queryKey:["kprofiles",e,"0.4"],queryFn:()=>Pe.getKProfiles(e,"0.4"),enabled:!!e,staleTime:6e4}),{data:Z,refetch:U}=yt({queryKey:["kprofile-notes",e],queryFn:()=>Pe.getKProfileNotes(e),enabled:!!e,staleTime:3e4}),$=W?.message?.includes("not connected");M.useEffect(()=>{if(!e&&L&&L.length>0){const G=L.find(J=>J.is_active);G&&n(G.id)}},[e,L]),M.useEffect(()=>{if(e){const G=setTimeout(()=>{ne()},150);return()=>clearTimeout(G)}},[e,r]);const ee=L?.filter(G=>G.is_active)||[],ae=pr.useMemo(()=>R?.profiles?R.profiles.filter(J=>{const le=f.toLowerCase(),ke=!le||J.name.toLowerCase().includes(le)||J.filament_id.toLowerCase().includes(le),Ne=m==="all"||m==="left"&&J.extruder_id===1||m==="right"&&J.extruder_id===0,we=y==="all"||y==="hf"&&J.nozzle_id.startsWith("HH")||y==="s"&&J.nozzle_id.startsWith("HS");return ke&&Ne&&we}).sort((J,le)=>{switch(b){case"k_value":return parseFloat(J.k_value)-parseFloat(le.k_value);case"filament":return tR(J.name).localeCompare(tR(le.name));case"name":default:return J.name.localeCompare(le.name)}}):[],[R?.profiles,f,m,y,b]),fe=L?.find(G=>G.id===e),ue=fe?.nozzle_count===2;M.useEffect(()=>{const G=J=>{J.target instanceof HTMLInputElement||J.target instanceof HTMLTextAreaElement||J.target instanceof HTMLSelectElement||s||o||u||(J.key==="r"||J.key==="R"?(J.preventDefault(),ne()):J.key==="n"||J.key==="N"?(J.preventDefault(),l(!0)):J.key==="Escape"&&S&&(J.preventDefault(),A(!1),P(new Set)))};return window.addEventListener("keydown",G),()=>window.removeEventListener("keydown",G)},[s,o,u,S,ne]);const xe=M.useCallback(()=>{if(!R?.profiles||R.profiles.length===0){t("No profiles to export","error");return}const G={version:1,exported_at:new Date().toISOString(),printer:fe?.name||"Unknown",nozzle_diameter:r,profiles:R.profiles.map(Ne=>({name:Ne.name,k_value:Ne.k_value,filament_id:Ne.filament_id,nozzle_id:Ne.nozzle_id,nozzle_diameter:Ne.nozzle_diameter,extruder_id:Ne.extruder_id}))},J=new Blob([JSON.stringify(G,null,2)],{type:"application/json"}),le=URL.createObjectURL(J),ke=document.createElement("a");ke.href=le,ke.download=`kprofiles_${fe?.name||"printer"}_${r}mm_${new Date().toISOString().split("T")[0]}.json`,document.body.appendChild(ke),ke.click(),document.body.removeChild(ke),URL.revokeObjectURL(le),t(`Exported ${R.profiles.length} profiles`)},[R?.profiles,fe,r,t]),Me=M.useCallback(()=>{const G=document.createElement("input");G.type="file",G.accept=".json",G.onchange=async J=>{const le=J.target.files?.[0];if(le)try{const ke=await le.text(),Ne=JSON.parse(ke);if(!Ne.profiles||!Array.isArray(Ne.profiles)){t("Invalid file format","error");return}let we=0;for(const B of Ne.profiles)if(!(!B.name||!B.k_value||!B.filament_id))try{await Pe.setKProfile(e,{name:B.name,k_value:parseFloat(B.k_value).toFixed(6),filament_id:B.filament_id,nozzle_id:B.nozzle_id||`HH00-${r}`,nozzle_diameter:B.nozzle_diameter||r,extruder_id:B.extruder_id??0,slot_id:0}),we++,await new Promise(j=>setTimeout(j,500))}catch(j){console.error("Failed to import profile:",B.name,j)}t(`Imported ${we} of ${Ne.profiles.length} profiles`),ne()}catch(ke){console.error("Import error:",ke),t("Failed to parse import file","error")}},G.click()},[e,r,t,ne]),se=M.useCallback(G=>{P(J=>{const le=new Set(J);return le.has(G)?le.delete(G):le.add(G),le})},[]),ve=M.useCallback(()=>{P(new Set(ae.map(G=>F(G))))},[ae,F]),je=M.useCallback(()=>{T.size!==0&&I(!0)},[T.size]),de=M.useCallback(async()=>{const G=ae.filter(le=>T.has(F(le)));D(!0);let J=0;for(const le of G)try{await Pe.deleteKProfile(e,{slot_id:le.slot_id,extruder_id:le.extruder_id,nozzle_id:le.nozzle_id,nozzle_diameter:le.nozzle_diameter,filament_id:le.filament_id,setting_id:le.setting_id}),J++,await new Promise(ke=>setTimeout(ke,300))}catch(ke){console.error("Failed to delete profile:",le.name,ke)}t(`Deleted ${J} profiles`),D(!1),I(!1),A(!1),P(new Set),ne()},[e,T,ae,t,ne,F]),ut=M.useCallback(G=>{const J=[];return G.setting_id&&J.push(G.setting_id),J.push(`slot_${G.slot_id}_${G.filament_id}_${G.extruder_id}`),J.push(`name_${G.name}_${G.filament_id}`),J},[]),H=M.useCallback(async(G,J)=>{if(e)try{await Pe.setKProfileNote(e,G,J),U()}catch(le){console.error("Failed to save note:",le),t("Failed to save note","error")}},[e,U,t]),z=M.useCallback(G=>{if(!Z?.notes)return{note:"",key:null};const J=ut(G);for(const le of J)if(Z.notes[le])return{note:Z.notes[le],key:le};return{note:"",key:null}},[Z,ut]),re=M.useCallback(G=>z(G).note,[z]);return q?c.jsx("div",{className:"flex justify-center py-12",children:c.jsx(At,{className:"w-8 h-8 text-bambu-green animate-spin"})}):!L||L.length===0?c.jsx(Nt,{children:c.jsxs(Dt,{className:"py-12 text-center",children:[c.jsx(Oo,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),c.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"No Printers Configured"}),c.jsx("p",{className:"text-bambu-gray",children:"Add a printer in Settings to manage K-profiles"})]})}):ee.length===0?c.jsx(Nt,{children:c.jsxs(Dt,{className:"py-12 text-center",children:[c.jsx(jo,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),c.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"No Active Printers"}),c.jsx("p",{className:"text-bambu-gray",children:"Enable a printer connection to view its K-profiles"})]})}):c.jsxs(c.Fragment,{children:[K&&!V&&c.jsxs("div",{className:"fixed inset-0 bg-black/50 flex flex-col items-center justify-center z-40",children:[c.jsx(At,{className:"w-10 h-10 text-bambu-green animate-spin mb-3"}),c.jsx("p",{className:"text-white font-medium",children:"Loading K-Profiles..."})]}),c.jsxs("div",{className:"flex flex-wrap gap-4 mb-6",children:[c.jsxs("div",{className:"flex-1 min-w-48",children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Printer"}),c.jsx("select",{value:e||"",onChange:G=>n(parseInt(G.target.value)),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:ee.map(G=>c.jsx("option",{value:G.id,children:G.name},G.id))})]}),c.jsxs("div",{className:"w-32",children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Nozzle"}),c.jsxs("select",{value:r,onChange:G=>i(G.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[c.jsx("option",{value:"0.2",children:"0.2mm"}),c.jsx("option",{value:"0.4",children:"0.4mm"}),c.jsx("option",{value:"0.6",children:"0.6mm"}),c.jsx("option",{value:"0.8",children:"0.8mm"})]})]}),c.jsxs("div",{className:"flex items-end gap-2",children:[c.jsxs(Ie,{variant:"secondary",onClick:()=>ne(),disabled:K,children:[c.jsx(qs,{className:`w-4 h-4 ${K?"animate-spin":""}`}),"Refresh"]}),c.jsxs(Ie,{onClick:()=>l(!0),children:[c.jsx(fr,{className:"w-4 h-4"}),"Add Profile"]})]})]}),c.jsxs("div",{className:"flex flex-wrap gap-4 mb-4",children:[c.jsxs("div",{className:"flex-1 min-w-48 relative",children:[c.jsx(Qu,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),c.jsx("input",{type:"text",value:f,onChange:G=>g(G.target.value),placeholder:"Search by name or filament...",className:"w-full pl-10 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]}),ue&&c.jsx("div",{className:"w-36",children:c.jsxs("select",{value:m,onChange:G=>x(G.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[c.jsx("option",{value:"all",children:"All Extruders"}),c.jsx("option",{value:"left",children:"Left Only"}),c.jsx("option",{value:"right",children:"Right Only"})]})}),c.jsx("div",{className:"w-32",children:c.jsxs("select",{value:y,onChange:G=>v(G.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[c.jsx("option",{value:"all",children:"All Flow"}),c.jsx("option",{value:"hf",children:"HF Only"}),c.jsx("option",{value:"s",children:"S Only"})]})}),c.jsx("div",{className:"w-32",children:c.jsxs("select",{value:b,onChange:G=>E(G.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[c.jsx("option",{value:"name",children:"Sort: Name"}),c.jsx("option",{value:"k_value",children:"Sort: K-Value"}),c.jsx("option",{value:"filament",children:"Sort: Filament"})]})})]}),c.jsxs("div",{className:"flex flex-wrap gap-2 mb-6",children:[c.jsxs(Ie,{variant:"secondary",onClick:xe,disabled:!R?.profiles?.length,title:"Export profiles to JSON",children:[c.jsx(ya,{className:"w-4 h-4"}),"Export"]}),c.jsxs(Ie,{variant:"secondary",onClick:Me,title:"Import profiles from JSON",children:[c.jsx(ma,{className:"w-4 h-4"}),"Import"]}),c.jsx("div",{className:"flex-1"}),S?c.jsxs(c.Fragment,{children:[c.jsxs(Ie,{variant:"secondary",onClick:ve,title:"Select all visible profiles",children:[c.jsx(jh,{className:"w-4 h-4"}),"Select All"]}),c.jsxs(Ie,{variant:"secondary",onClick:je,disabled:T.size===0,className:"text-red-500 hover:bg-red-500/10",title:`Delete ${T.size} selected profiles`,children:[c.jsx(kn,{className:"w-4 h-4"}),"Delete (",T.size,")"]}),c.jsxs(Ie,{variant:"secondary",onClick:()=>{A(!1),P(new Set)},children:[c.jsx(Gt,{className:"w-4 h-4"}),"Cancel"]})]}):c.jsxs(Ie,{variant:"secondary",onClick:()=>A(!0),disabled:!ae.length,title:"Enter selection mode for bulk delete",children:[c.jsx(jh,{className:"w-4 h-4"}),"Select"]})]}),V?c.jsx("div",{className:"flex justify-center py-12",children:c.jsx(At,{className:"w-8 h-8 text-bambu-green animate-spin"})}):$?c.jsx(Nt,{children:c.jsxs(Dt,{className:"py-12 text-center",children:[c.jsx(SR,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),c.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"Printer Offline"}),c.jsx("p",{className:"text-bambu-gray mb-4",children:"The selected printer is not connected. Power it on to view K-profiles."}),c.jsxs(Ie,{variant:"secondary",onClick:()=>ne(),children:[c.jsx(qs,{className:"w-4 h-4"}),"Retry"]})]})}):ae.length>0?ue?c.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[c.jsxs("div",{children:[c.jsx("h3",{className:"text-sm font-medium text-bambu-gray mb-2 px-1",children:"Left Extruder"}),c.jsx("div",{className:"space-y-1",children:ae.filter(G=>G.extruder_id===1).map(G=>c.jsx(BN,{profile:G,onEdit:()=>a(G),onCopy:()=>d(G),selectionMode:S,isSelected:T.has(F(G)),onToggleSelect:()=>se(F(G)),note:re(G)},F(G)))})]}),c.jsxs("div",{children:[c.jsx("h3",{className:"text-sm font-medium text-bambu-gray mb-2 px-1",children:"Right Extruder"}),c.jsx("div",{className:"space-y-1",children:ae.filter(G=>G.extruder_id===0).map(G=>c.jsx(BN,{profile:G,onEdit:()=>a(G),onCopy:()=>d(G),selectionMode:S,isSelected:T.has(F(G)),onToggleSelect:()=>se(F(G)),note:re(G)},F(G)))})]})]}):c.jsx("div",{className:"space-y-1",children:ae.map(G=>c.jsx(BN,{profile:G,onEdit:()=>a(G),onCopy:()=>d(G),selectionMode:S,isSelected:T.has(F(G)),onToggleSelect:()=>se(F(G)),note:re(G)},F(G)))}):f||m!=="all"||y!=="all"?c.jsx(Nt,{children:c.jsxs(Dt,{className:"py-12 text-center",children:[c.jsx(Qu,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),c.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"No Matching Profiles"}),c.jsx("p",{className:"text-bambu-gray",children:"No profiles match your search criteria"})]})}):c.jsx(Nt,{children:c.jsxs(Dt,{className:"py-12 text-center",children:[c.jsx(xR,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),c.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"No K-Profiles"}),c.jsxs("p",{className:"text-bambu-gray mb-4",children:["No pressure advance profiles found for ",r,"mm nozzle"]}),c.jsxs(Ie,{onClick:()=>l(!0),children:[c.jsx(fr,{className:"w-4 h-4"}),"Create First Profile"]})]})}),s&&e&&(()=>{const{note:G,key:J}=z(s);return c.jsx(HN,{profile:s,printerId:e,nozzleDiameter:r,existingProfiles:Y?.profiles||R?.profiles,isDualNozzle:ue,initialNote:G,initialNoteKey:J,onSaveNote:H,onClose:()=>{console.log("[KProfiles] Edit modal onClose - refetching profiles..."),a(null),ne()},onSave:()=>{a(null),ne()}})})(),o&&e&&c.jsx(HN,{printerId:e,nozzleDiameter:r,existingProfiles:Y?.profiles||R?.profiles,isDualNozzle:ue,onSaveNote:H,onClose:()=>{l(!1),ne()},onSave:()=>{l(!1),ne()}}),u&&e&&c.jsx(HN,{printerId:e,nozzleDiameter:r,existingProfiles:Y?.profiles||R?.profiles,isDualNozzle:ue,onSaveNote:H,profile:{...u,slot_id:0,name:`${u.name} (Copy)`},onClose:()=>{d(null),ne()},onSave:()=>{d(null),ne()}}),C&&c.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:c.jsx(Nt,{className:"w-full max-w-sm",children:c.jsxs(Dt,{className:"p-6",children:[c.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[c.jsx("div",{className:"w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center",children:c.jsx(kn,{className:"w-5 h-5 text-red-500"})}),c.jsxs("div",{children:[c.jsx("h3",{className:"text-lg font-semibold text-white",children:"Delete Profiles"}),c.jsx("p",{className:"text-sm text-bambu-gray",children:"This cannot be undone"})]})]}),c.jsxs("p",{className:"text-bambu-gray mb-6",children:["Are you sure you want to delete ",c.jsx("span",{className:"text-white font-medium",children:T.size})," selected profiles from the printer?"]}),c.jsxs("div",{className:"flex gap-3",children:[c.jsx(Ie,{variant:"secondary",onClick:()=>I(!1),disabled:N,className:"flex-1",children:"Cancel"}),c.jsxs(Ie,{onClick:de,disabled:N,className:"flex-1 bg-red-500 hover:bg-red-600 text-white",children:[N?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(kn,{className:"w-4 h-4"}),"Delete"]})]})]})})})]})}function Gj(t,e){const n=`${t} ${e||""}`,r=n.match(/@?\s*(?:BBL\s+)?(?:Bambu\s+Lab\s+)?([XPAH][1-9][A-Z]?(?:\s*(?:Carbon|mini))?|H2D)/i),i=r?r[1].trim():null,s=n.match(/(\d+\.?\d*)\s*(?:mm\s*)?nozzle|nozzle\s*(\d+\.?\d*)/i),a=s?(s[1]||s[2])+"mm":null,o=n.match(/(\d+\.?\d*)mm\s*(?:Standard|Fine|Extra Fine|Draft|Quality)?/i),l=o?o[1]+"mm":null,u=n.match(/\b(PLA|PETG|ABS|ASA|TPU|PC|PA|PVA|HIPS|PP|PET(?:-?CF)?|PA(?:-?CF)?|PLA(?:-?CF)?)\b/i),d=u?u[1].toUpperCase():null;return{printer:i,nozzle:a,layerHeight:l,filamentType:d}}function J0(t){return/^(P[FPM]US|PF\d|PP\d)/.test(t)}function W9e(t){const e=new Date(t),r=new Date().getTime()-e.getTime(),i=Math.floor(r/6e4),s=Math.floor(r/36e5),a=Math.floor(r/864e5);return i<1?"Just now":i<60?`${i}m ago`:s<24?`${s}h ago`:a<7?`${a}d ago`:e.toLocaleDateString()}function q9e({onSuccess:t}){const{showToast:e}=ri(),[n,r]=M.useState("email"),[i,s]=M.useState(""),[a,o]=M.useState(""),[l,u]=M.useState(""),[d,f]=M.useState(""),[g,m]=M.useState("global"),x=_t({mutationFn:()=>Pe.cloudLogin(i,a,g),onSuccess:S=>{S.success?(e("Logged in successfully"),t()):S.needs_verification?(e("Verification code sent to your email"),r("code")):e(S.message,"error")},onError:S=>e(S.message,"error")}),y=_t({mutationFn:()=>Pe.cloudVerify(i,l),onSuccess:S=>{S.success?(e("Logged in successfully"),t()):e(S.message,"error")},onError:S=>e(S.message,"error")}),v=_t({mutationFn:()=>Pe.cloudSetToken(d),onSuccess:()=>{e("Token set successfully"),t()},onError:S=>e(S.message,"error")}),b=S=>{S.preventDefault(),n==="email"?x.mutate():n==="code"?y.mutate():n==="token"&&v.mutate()},E=x.isPending||y.isPending||v.isPending;return c.jsx(Nt,{className:"max-w-md mx-auto",children:c.jsxs(Dt,{children:[c.jsxs("div",{className:"text-center mb-6",children:[c.jsx("div",{className:"inline-flex items-center justify-center w-12 h-12 rounded-xl bg-bambu-green/20 mb-3",children:c.jsx(gS,{className:"w-6 h-6 text-bambu-green"})}),c.jsx("h2",{className:"text-xl font-semibold text-white",children:"Connect to Bambu Cloud"}),c.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:"Sync your slicer presets across devices"})]}),c.jsxs("form",{onSubmit:b,className:"space-y-4",children:[n==="email"&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Email"}),c.jsx("input",{type:"email",value:i,onChange:S=>s(S.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none",placeholder:"your@email.com",required:!0})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Password"}),c.jsx("input",{type:"password",value:a,onChange:S=>o(S.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none",placeholder:"••••••••",required:!0})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Region"}),c.jsxs("select",{value:g,onChange:S=>m(S.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[c.jsx("option",{value:"global",children:"Global"}),c.jsx("option",{value:"china",children:"China"})]})]})]}),n==="code"&&c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Verification Code"}),c.jsxs("p",{className:"text-xs text-bambu-gray mb-2",children:["Check your email (",i,") for a 6-digit code"]}),c.jsx("input",{type:"text",value:l,onChange:S=>u(S.target.value.replace(/\D/g,"").slice(0,6)),className:"w-full px-3 py-3 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-center text-2xl tracking-widest font-mono focus:border-bambu-green focus:outline-none",placeholder:"000000",maxLength:6,required:!0})]}),n==="token"&&c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Access Token"}),c.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:"Paste your Bambu Lab access token (from Bambu Studio)"}),c.jsx("textarea",{value:d,onChange:S=>f(S.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-xs font-mono placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none resize-none",placeholder:"eyJ...",rows:4,required:!0})]}),c.jsxs("div",{className:"flex gap-2",children:[n==="code"&&c.jsx(Ie,{type:"button",variant:"secondary",onClick:()=>r("email"),className:"flex-1",children:"Back"}),c.jsxs(Ie,{type:"submit",disabled:E,className:"flex-1",children:[E?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(E5,{className:"w-4 h-4"}),n==="email"?"Login":n==="code"?"Verify":"Set Token"]})]}),n==="email"&&c.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:c.jsxs("button",{type:"button",onClick:()=>r("token"),className:"text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors",children:[c.jsx(Op,{className:"w-4 h-4"}),"Use access token instead"]})}),n==="token"&&c.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:c.jsxs("button",{type:"button",onClick:()=>r("email"),className:"text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors",children:[c.jsx(E5,{className:"w-4 h-4"}),"Login with email instead"]})})]})]})})}function Ap({label:t,value:e,options:n,onChange:r}){const[i,s]=M.useState(!1),a=n.find(o=>o.value===e);return c.jsxs("div",{className:"relative",children:[c.jsxs("button",{onClick:()=>s(!i),className:"flex items-center gap-2 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-white hover:border-bambu-gray-dark transition-colors",children:[c.jsxs("span",{className:"text-bambu-gray",children:[t,":"]}),c.jsx("span",{children:a?.label||"All"}),c.jsx(ef,{className:`w-4 h-4 text-bambu-gray transition-transform ${i?"rotate-180":""}`})]}),i&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>s(!1)}),c.jsx("div",{className:"absolute top-full left-0 mt-1 min-w-[160px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20 py-1 max-h-60 overflow-y-auto",children:n.map(o=>c.jsxs("button",{onClick:()=>{r(o.value),s(!1)},className:`w-full px-3 py-2 text-left text-sm flex items-center justify-between hover:bg-bambu-dark-tertiary transition-colors ${e===o.value?"text-bambu-green":"text-white"}`,children:[c.jsx("span",{children:o.label}),o.count!==void 0&&c.jsx("span",{className:"text-bambu-gray text-xs",children:o.count})]},o.value))})]})]})}function K9e(){const[t,e]=M.useState(!1);M.useEffect(()=>{const r=()=>{e(window.scrollY>300)};return window.addEventListener("scroll",r),()=>window.removeEventListener("scroll",r)},[]);const n=()=>{window.scrollTo({top:0,behavior:"smooth"})};return t?c.jsx("button",{onClick:n,className:"fixed bottom-6 right-6 p-3 bg-bambu-green hover:bg-bambu-green-light text-white rounded-full shadow-lg shadow-bambu-green/25 transition-all z-40","aria-label":"Scroll to top",children:c.jsx(nm,{className:"w-5 h-5"})}):null}function $N({setting:t,onClick:e,onDuplicate:n,compareMode:r,isCompareSelected:i,compareIndex:s,compareDisabled:a}){const o=Gj(t.name),l=J0(t.setting_id);return c.jsxs("div",{className:"flex items-center gap-2 group",children:[c.jsx("button",{onClick:e,disabled:a,className:`flex-1 text-left px-3 py-2 rounded transition-colors ${i?"bg-blue-500/20 border border-blue-500/50":a?"bg-bambu-dark/50 opacity-40 cursor-not-allowed":"bg-bambu-dark hover:bg-bambu-dark-tertiary"} ${r&&!a?"cursor-pointer":""}`,children:c.jsxs("div",{className:"flex items-center gap-2",children:[i&&s!==void 0&&c.jsx("span",{className:"flex-shrink-0 w-5 h-5 rounded-full bg-blue-500 text-white text-xs flex items-center justify-center font-medium",children:s+1}),!i&&l&&c.jsx("span",{className:"flex-shrink-0 w-1.5 h-1.5 rounded-full bg-bambu-green",title:"My preset (editable)"}),c.jsx("span",{className:"text-white text-sm truncate flex-1",title:t.name,children:t.name}),o.filamentType&&t.type==="filament"&&c.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:o.filamentType}),o.layerHeight&&t.type==="process"&&c.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:o.layerHeight}),o.printer&&c.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:o.printer})]})}),c.jsx("button",{onClick:u=>{u.stopPropagation(),n()},className:"opacity-0 group-hover:opacity-100 text-bambu-gray hover:text-white transition-all p-1",title:"Duplicate",children:c.jsx(Dh,{className:"w-4 h-4"})})]})}function nR(t,e=0){const n=" ".repeat(e);if(t===null)return"null";if(t===void 0)return"undefined";if(typeof t=="string"){if(t.includes("\\n")||t.includes(` + `).concat(A.x,",").concat(A.y),P=yr(t.id)?U0("recharts-radial-line-"):t.id;return M.createElement("text",rc({},r,{dominantBaseline:"central",className:Tn("recharts-radial-bar-label",a)}),M.createElement("defs",null,M.createElement("path",{id:P,d:T})),M.createElement("textPath",{xlinkHref:"#".concat(P)},n))},Hze=(t,e,n)=>{var{cx:r,cy:i,innerRadius:s,outerRadius:a,startAngle:o,endAngle:l}=t,u=(o+l)/2;if(n==="outside"){var{x:d,y:f}=Yr(r,i,a+e,u);return{x:d,y:f,textAnchor:d>=r?"start":"end",verticalAnchor:"middle"}}if(n==="center")return{x:r,y:i,textAnchor:"middle",verticalAnchor:"middle"};if(n==="centerTop")return{x:r,y:i,textAnchor:"middle",verticalAnchor:"start"};if(n==="centerBottom")return{x:r,y:i,textAnchor:"middle",verticalAnchor:"end"};var g=(s+a)/2,{x:m,y:x}=Yr(r,i,g,u);return{x:m,y:x,textAnchor:"middle",verticalAnchor:"middle"}},VP=t=>"cx"in t&&Ct(t.cx),$ze=(t,e)=>{var{parentViewBox:n,offset:r,position:i}=t,s;n!=null&&!VP(n)&&(s=n);var{x:a,y:o,upperWidth:l,lowerWidth:u,height:d}=e,f=a,g=a+(l-u)/2,m=(f+g)/2,x=(l+u)/2,y=f+l/2,v=d>=0?1:-1,b=v*r,E=v>0?"end":"start",S=v>0?"start":"end",A=l>=0?1:-1,T=A*r,P=A>0?"end":"start",C=A>0?"start":"end";if(i==="top"){var I={x:f+l/2,y:o-b,textAnchor:"middle",verticalAnchor:E};return Or(Or({},I),s?{height:Math.max(o-s.y,0),width:l}:{})}if(i==="bottom"){var N={x:g+u/2,y:o+d+b,textAnchor:"middle",verticalAnchor:S};return Or(Or({},N),s?{height:Math.max(s.y+s.height-(o+d),0),width:u}:{})}if(i==="left"){var D={x:m-T,y:o+d/2,textAnchor:P,verticalAnchor:"middle"};return Or(Or({},D),s?{width:Math.max(D.x-s.x,0),height:d}:{})}if(i==="right"){var F={x:m+x+T,y:o+d/2,textAnchor:C,verticalAnchor:"middle"};return Or(Or({},F),s?{width:Math.max(s.x+s.width-F.x,0),height:d}:{})}var L=s?{width:x,height:d}:{};return i==="insideLeft"?Or({x:m+T,y:o+d/2,textAnchor:C,verticalAnchor:"middle"},L):i==="insideRight"?Or({x:m+x-T,y:o+d/2,textAnchor:P,verticalAnchor:"middle"},L):i==="insideTop"?Or({x:f+l/2,y:o+b,textAnchor:"middle",verticalAnchor:S},L):i==="insideBottom"?Or({x:g+u/2,y:o+d-b,textAnchor:"middle",verticalAnchor:E},L):i==="insideTopLeft"?Or({x:f+T,y:o+b,textAnchor:C,verticalAnchor:S},L):i==="insideTopRight"?Or({x:f+l-T,y:o+b,textAnchor:P,verticalAnchor:S},L):i==="insideBottomLeft"?Or({x:g+T,y:o+d-b,textAnchor:C,verticalAnchor:E},L):i==="insideBottomRight"?Or({x:g+u-T,y:o+d-b,textAnchor:P,verticalAnchor:E},L):i&&typeof i=="object"&&(Ct(i.x)||wc(i.x))&&(Ct(i.y)||wc(i.y))?Or({x:a+hs(i.x,x),y:o+hs(i.y,d),textAnchor:"end",verticalAnchor:"end"},L):Or({x:y,y:o+d/2,textAnchor:"middle",verticalAnchor:"middle"},L)},Vze={angle:0,offset:5,zIndex:Zr.label,position:"middle",textBreakAll:!1};function Nu(t){var e=ii(t,Vze),{viewBox:n,position:r,value:i,children:s,content:a,className:o="",textBreakAll:l,labelRef:u}=e,d=Uze(),f=RJ(),g=r==="center"?f:d??f,m,x,y;if(n==null?m=g:VP(n)?m=n:m=YY(n),!m||yr(i)&&yr(s)&&!M.isValidElement(a)&&typeof a!="function")return null;var v=Or(Or({},e),{},{viewBox:m});if(M.isValidElement(a)){var{labelRef:b}=v,E=Pze(v,kze);return M.cloneElement(a,E)}if(typeof a=="function"){if(x=M.createElement(a,v),M.isValidElement(x))return x}else x=Fze(e);var S=Cs(e);if(VP(m)){if(r==="insideStart"||r==="insideEnd"||r==="end")return Bze(e,r,x,S,m);y=Hze(m,e.offset,e.position)}else y=$ze(e,m);return M.createElement(Qs,{zIndex:e.zIndex},M.createElement(FE,rc({ref:u,className:Tn("recharts-label",o)},S,y,{textAnchor:Mze(S.textAnchor)?S.textAnchor:y.textAnchor,breakAll:l}),x))}Nu.displayName="Label";var Gze=(t,e,n)=>{if(!t)return null;var r={viewBox:e,labelRef:n};return t===!0?M.createElement(Nu,rc({key:"label-implicit"},r)):fl(t)?M.createElement(Nu,rc({key:"label-implicit",value:t},r)):M.isValidElement(t)?t.type===Nu?M.cloneElement(t,Or({key:"label-implicit"},r)):M.createElement(Nu,rc({key:"label-implicit",content:t},r)):Tj(t)?M.createElement(Nu,rc({key:"label-implicit",content:t},r)):t&&typeof t=="object"?M.createElement(Nu,rc({},t,{key:"label-implicit"},r)):null};function Wze(t){var{label:e,labelRef:n}=t,r=RJ();return Gze(e,r,n)||null}var TN={},CN={},$V;function qze(){return $V||($V=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});function e(n){return n[n.length-1]}t.last=e})(CN)),CN}var NN={},VV;function Kze(){return VV||(VV=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});function e(n){return Array.isArray(n)?n:Array.from(n)}t.toArray=e})(NN)),NN}var GV;function Xze(){return GV||(GV=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});const e=qze(),n=Kze(),r=tO();function i(s){if(r.isArrayLike(s))return e.last(n.toArray(s))}t.last=i})(TN)),TN}var kN,WV;function Yze(){return WV||(WV=1,kN=Xze().last),kN}var Zze=Yze();const Qze=oo(Zze);var Jze=["valueAccessor"],eBe=["dataKey","clockWise","id","textBreakAll","zIndex"];function Qw(){return Qw=Object.assign?Object.assign.bind():function(t){for(var e=1;eArray.isArray(t.value)?Qze(t.value):t.value,DJ=M.createContext(void 0),OJ=DJ.Provider,jJ=M.createContext(void 0),rBe=jJ.Provider;function iBe(){return M.useContext(DJ)}function sBe(){return M.useContext(jJ)}function e1(t){var{valueAccessor:e=nBe}=t,n=qV(t,Jze),{dataKey:r,clockWise:i,id:s,textBreakAll:a,zIndex:o}=n,l=qV(n,eBe),u=iBe(),d=sBe(),f=u||d;return!f||!f.length?null:M.createElement(Qs,{zIndex:o??Zr.label},M.createElement(Ir,{className:"recharts-label-list"},f.map((g,m)=>{var x,y=yr(r)?e(g,m):Jn(g&&g.payload,r),v=yr(s)?{}:{id:"".concat(s,"-").concat(m)};return M.createElement(Nu,Qw({key:"label-".concat(m)},Cs(g),l,v,{fill:(x=n.fill)!==null&&x!==void 0?x:g.fill,parentViewBox:g.parentViewBox,value:y,textBreakAll:a,viewBox:g.viewBox,index:m,zIndex:0}))})))}e1.displayName="LabelList";function Cj(t){var{label:e}=t;return e?e===!0?M.createElement(e1,{key:"labelList-implicit"}):M.isValidElement(e)||Tj(e)?M.createElement(e1,{key:"labelList-implicit",content:e}):typeof e=="object"?M.createElement(e1,Qw({key:"labelList-implicit"},e,{type:String(e.type)})):null:null}function GP(){return GP=Object.assign?Object.assign.bind():function(t){for(var e=1;e{var{cx:e,cy:n,r,className:i}=t,s=Tn("recharts-dot",i);return Ct(e)&&Ct(n)&&Ct(r)?M.createElement("circle",GP({},Ks(t),eO(t),{className:s,cx:e,cy:n,r})):null},IJ=t=>t.graphicalItems.polarItems,aBe=Ke([gr,kb],YO),zE=Ke([IJ,wr,aBe],ZO),oBe=Ke([zE],QO),BE=Ke([oBe,zO],JO),lBe=Ke([BE,wr,zE],tj);Ke([BE,wr,zE],(t,e,n)=>n.length>0?t.flatMap(r=>n.flatMap(i=>{var s,a=Jn(r,(s=e.dataKey)!==null&&s!==void 0?s:i.dataKey);return{value:a,errorDomain:[]}})).filter(Boolean):e?.dataKey!=null?t.map(r=>({value:Jn(r,e.dataKey),errorDomain:[]})):t.map(r=>({value:r,errorDomain:[]})));var KV=()=>{},cBe=Ke([BE,wr,zE,LE,gr],sj),uBe=Ke([wr,rj,ij,KV,cBe,KV,wn,gr],aj),UJ=Ke([wr,wn,BE,lBe,Nb,gr,uBe],oj),dBe=Ke([UJ,wr,tg],uj);Ke([wr,UJ,dBe,gr],hj);var hBe={radiusAxis:{},angleAxis:{}},FJ=Zs({name:"polarAxis",initialState:hBe,reducers:{addRadiusAxis(t,e){t.radiusAxis[e.payload.id]=e.payload},removeRadiusAxis(t,e){delete t.radiusAxis[e.payload.id]},addAngleAxis(t,e){t.angleAxis[e.payload.id]=e.payload},removeAngleAxis(t,e){delete t.angleAxis[e.payload.id]}}}),{addRadiusAxis:v7e,removeRadiusAxis:y7e,addAngleAxis:_7e,removeAngleAxis:w7e}=FJ.actions,fBe=FJ.reducer;function XV(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function YV(t){for(var e=1;ee,Nj=Ke([IJ,xBe],(t,e)=>t.filter(n=>n.type==="pie").find(n=>n.id===e)),bBe=[],kj=(t,e,n)=>n?.length===0?bBe:n,zJ=Ke([zO,Nj,kj],(t,e,n)=>{var{chartData:r}=t;if(e!=null){var i;if(e?.data!=null&&e.data.length>0?i=e.data:i=r,(!i||!i.length)&&n!=null&&(i=n.map(s=>YV(YV({},e.presentationProps),s.props))),i!=null)return i}}),vBe=Ke([zJ,Nj,kj],(t,e,n)=>{if(!(t==null||e==null))return t.map((r,i)=>{var s,a=Jn(r,e.nameKey,e.name),o;return n!=null&&(s=n[i])!==null&&s!==void 0&&(s=s.props)!==null&&s!==void 0&&s.fill?o=n[i].props.fill:typeof r=="object"&&r!=null&&"fill"in r?o=r.fill:o=e.fill,{value:qm(a,e.dataKey),color:o,payload:r,type:e.legendType}})}),yBe=Ke([zJ,Nj,kj,xi],(t,e,n,r)=>{if(!(e==null||t==null))return _6e({offset:r,pieSettings:e,displayedData:t,cells:n})}),PN={exports:{}},Bn={};var ZV;function _Be(){if(ZV)return Bn;ZV=1;var t=Symbol.for("react.transitional.element"),e=Symbol.for("react.portal"),n=Symbol.for("react.fragment"),r=Symbol.for("react.strict_mode"),i=Symbol.for("react.profiler"),s=Symbol.for("react.consumer"),a=Symbol.for("react.context"),o=Symbol.for("react.forward_ref"),l=Symbol.for("react.suspense"),u=Symbol.for("react.suspense_list"),d=Symbol.for("react.memo"),f=Symbol.for("react.lazy"),g=Symbol.for("react.view_transition"),m=Symbol.for("react.client.reference");function x(y){if(typeof y=="object"&&y!==null){var v=y.$$typeof;switch(v){case t:switch(y=y.type,y){case n:case i:case r:case l:case u:case g:return y;default:switch(y=y&&y.$$typeof,y){case a:case o:case f:case d:return y;case s:return y;default:return v}}case e:return v}}}return Bn.ContextConsumer=s,Bn.ContextProvider=a,Bn.Element=t,Bn.ForwardRef=o,Bn.Fragment=n,Bn.Lazy=f,Bn.Memo=d,Bn.Portal=e,Bn.Profiler=i,Bn.StrictMode=r,Bn.Suspense=l,Bn.SuspenseList=u,Bn.isContextConsumer=function(y){return x(y)===s},Bn.isContextProvider=function(y){return x(y)===a},Bn.isElement=function(y){return typeof y=="object"&&y!==null&&y.$$typeof===t},Bn.isForwardRef=function(y){return x(y)===o},Bn.isFragment=function(y){return x(y)===n},Bn.isLazy=function(y){return x(y)===f},Bn.isMemo=function(y){return x(y)===d},Bn.isPortal=function(y){return x(y)===e},Bn.isProfiler=function(y){return x(y)===i},Bn.isStrictMode=function(y){return x(y)===r},Bn.isSuspense=function(y){return x(y)===l},Bn.isSuspenseList=function(y){return x(y)===u},Bn.isValidElementType=function(y){return typeof y=="string"||typeof y=="function"||y===n||y===i||y===r||y===l||y===u||typeof y=="object"&&y!==null&&(y.$$typeof===f||y.$$typeof===d||y.$$typeof===a||y.$$typeof===s||y.$$typeof===o||y.$$typeof===m||y.getModuleId!==void 0)},Bn.typeOf=x,Bn}var QV;function wBe(){return QV||(QV=1,PN.exports=_Be()),PN.exports}var SBe=wBe(),JV=t=>typeof t=="string"?t:t?t.displayName||t.name||"Component":"",e9=null,RN=null,BJ=t=>{if(t===e9&&Array.isArray(RN))return RN;var e=[];return M.Children.forEach(t,n=>{yr(n)||(SBe.isFragment(n)?e=e.concat(BJ(n.props.children)):e.push(n))}),RN=e,e9=t,e};function Pj(t,e){var n=[],r=[];return Array.isArray(e)?r=e.map(i=>JV(i)):r=[JV(e)],BJ(t).forEach(i=>{var s=Kh(i,"type.displayName")||Kh(i,"type.name");s&&r.indexOf(s)!==-1&&n.push(i)}),n}var HJ=t=>t&&typeof t=="object"&&"clipDot"in t?!!t.clipDot:!0,DN={},t9;function EBe(){return t9||(t9=1,(function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});function e(n){if(typeof n!="object"||n==null)return!1;if(Object.getPrototypeOf(n)===null)return!0;if(Object.prototype.toString.call(n)!=="[object Object]"){const i=n[Symbol.toStringTag];return i==null||!Object.getOwnPropertyDescriptor(n,Symbol.toStringTag)?.writable?!1:n.toString()===`[object ${i}]`}let r=n;for(;Object.getPrototypeOf(r)!==null;)r=Object.getPrototypeOf(r);return Object.getPrototypeOf(n)===r}t.isPlainObject=e})(DN)),DN}var ON,n9;function MBe(){return n9||(n9=1,ON=EBe().isPlainObject),ON}var ABe=MBe();const TBe=oo(ABe);function r9(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function i9(t){for(var e=1;e{var s=n-r,a;return a="M ".concat(t,",").concat(e),a+="L ".concat(t+n,",").concat(e),a+="L ".concat(t+n-s/2,",").concat(e+i),a+="L ".concat(t+n-s/2-r,",").concat(e+i),a+="L ".concat(t,",").concat(e," Z"),a},PBe={x:0,y:0,upperWidth:0,lowerWidth:0,height:0,isUpdateAnimationActive:!1,animationBegin:0,animationDuration:1500,animationEasing:"ease"},RBe=t=>{var e=ii(t,PBe),{x:n,y:r,upperWidth:i,lowerWidth:s,height:a,className:o}=e,{animationEasing:l,animationDuration:u,animationBegin:d,isUpdateAnimationActive:f}=e,g=M.useRef(null),[m,x]=M.useState(-1),y=M.useRef(i),v=M.useRef(s),b=M.useRef(a),E=M.useRef(n),S=M.useRef(r),A=Eb(t,"trapezoid-");if(M.useEffect(()=>{if(g.current&&g.current.getTotalLength)try{var R=g.current.getTotalLength();R&&x(R)}catch{}},[]),n!==+n||r!==+r||i!==+i||s!==+s||a!==+a||i===0&&s===0||a===0)return null;var T=Tn("recharts-trapezoid",o);if(!f)return M.createElement("g",null,M.createElement("path",Jw({},Cs(e),{className:T,d:s9(n,r,i,s,a)})));var P=y.current,C=v.current,I=b.current,N=E.current,D=S.current,F="0px ".concat(m===-1?1:m,"px"),L="".concat(m,"px 0px"),q=uZ(["strokeDasharray"],u,l);return M.createElement(Sb,{animationId:A,key:A,canBegin:m>0,duration:u,easing:l,isActive:f,begin:d},R=>{var V=cr(P,i,R),K=cr(C,s,R),W=cr(I,a,R),ne=cr(N,n,R),Y=cr(D,r,R);g.current&&(y.current=V,v.current=K,b.current=W,E.current=ne,S.current=Y);var Z=R>0?{transition:q,strokeDasharray:L}:{strokeDasharray:F};return M.createElement("path",Jw({},Cs(e),{className:T,d:s9(ne,Y,V,K,W),ref:g,style:i9(i9({},Z),e.style)}))})},DBe=["option","shapeType","propTransformer","activeClassName"];function OBe(t,e){if(t==null)return{};var n,r,i=jBe(t,e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(t);for(r=0;r{var r=rr();return(i,s)=>a=>{t?.(i,s,a),r(JQ({activeIndex:String(s),activeDataKey:e,activeCoordinate:i.tooltipPosition,activeGraphicalItemId:n}))}},Dj=t=>{var e=rr();return(n,r)=>i=>{t?.(n,r,i),e(e5e())}},Oj=(t,e,n)=>{var r=rr();return(i,s)=>a=>{t?.(i,s,a),r(t5e({activeIndex:String(s),activeDataKey:e,activeCoordinate:i.tooltipPosition,activeGraphicalItemId:n}))}};function jj(t){var{tooltipEntrySettings:e}=t,n=rr(),r=ms(),i=M.useRef(null);return M.useLayoutEffect(()=>{r||(i.current===null?n(YUe(e)):i.current!==e&&n(ZUe({prev:i.current,next:e})),i.current=e)},[e,n,r]),M.useLayoutEffect(()=>()=>{i.current&&(n(QUe(i.current)),i.current=null)},[n]),null}function VJ(t){var{legendPayload:e}=t,n=rr(),r=ms(),i=M.useRef(null);return M.useLayoutEffect(()=>{r||(i.current===null?n(sZ(e)):i.current!==e&&n(aZ({prev:i.current,next:e})),i.current=e)},[n,r,e]),M.useLayoutEffect(()=>()=>{i.current&&(n(oZ(i.current)),i.current=null)},[n]),null}function HBe(t){var{legendPayload:e}=t,n=rr(),r=kt(wn),i=M.useRef(null);return M.useLayoutEffect(()=>{r!=="centric"&&r!=="radial"||(i.current===null?n(sZ(e)):i.current!==e&&n(aZ({prev:i.current,next:e})),i.current=e)},[n,r,e]),M.useLayoutEffect(()=>()=>{i.current&&(n(oZ(i.current)),i.current=null)},[n]),null}var jN,$Be=()=>{var[t]=M.useState(()=>U0("uid-"));return t},VBe=(jN=$ne.useId)!==null&&jN!==void 0?jN:$Be;function GJ(t,e){var n=VBe();return e||(t?"".concat(t,"-").concat(n):n)}var GBe=M.createContext(void 0),Lj=t=>{var{id:e,type:n,children:r}=t,i=GJ("recharts-".concat(n),e);return M.createElement(GBe.Provider,{value:i},r(i))},WBe={cartesianItems:[],polarItems:[]},WJ=Zs({name:"graphicalItems",initialState:WBe,reducers:{addCartesianGraphicalItem:{reducer(t,e){t.cartesianItems.push(e.payload)},prepare:hr()},replaceCartesianGraphicalItem:{reducer(t,e){var{prev:n,next:r}=e.payload,i=Ro(t).cartesianItems.indexOf(n);i>-1&&(t.cartesianItems[i]=r)},prepare:hr()},removeCartesianGraphicalItem:{reducer(t,e){var n=Ro(t).cartesianItems.indexOf(e.payload);n>-1&&t.cartesianItems.splice(n,1)},prepare:hr()},addPolarGraphicalItem:{reducer(t,e){t.polarItems.push(e.payload)},prepare:hr()},removePolarGraphicalItem:{reducer(t,e){var n=Ro(t).polarItems.indexOf(e.payload);n>-1&&t.polarItems.splice(n,1)},prepare:hr()}}}),{addCartesianGraphicalItem:qBe,replaceCartesianGraphicalItem:KBe,removeCartesianGraphicalItem:XBe,addPolarGraphicalItem:YBe,removePolarGraphicalItem:ZBe}=WJ.actions,QBe=WJ.reducer,JBe=t=>{var e=rr(),n=M.useRef(null);return M.useLayoutEffect(()=>{n.current===null?e(qBe(t)):n.current!==t&&e(KBe({prev:n.current,next:t})),n.current=t},[e,t]),M.useLayoutEffect(()=>()=>{n.current&&(e(XBe(n.current)),n.current=null)},[e]),null},qJ=M.memo(JBe);function e6e(t){var e=rr();return M.useLayoutEffect(()=>(e(YBe(t)),()=>{e(ZBe(t))}),[e,t]),null}var t6e=["key"],n6e=["onMouseEnter","onClick","onMouseLeave"],r6e=["id"],i6e=["id"];function l9(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function Tr(t){for(var e=1;ePj(t.children,Fb),[t.children]),n=kt(r=>vBe(r,t.id,e));return n==null?null:M.createElement(HBe,{legendPayload:n})}var u6e=M.memo(t=>{var{dataKey:e,nameKey:n,sectors:r,stroke:i,strokeWidth:s,fill:a,name:o,hide:l,tooltipType:u}=t,d={dataDefinedOnItem:r.map(f=>f.tooltipPayload),positions:r.map(f=>f.tooltipPosition),settings:{stroke:i,strokeWidth:s,fill:a,dataKey:e,nameKey:n,name:qm(o,e),hide:l,type:u,color:a,unit:""}};return M.createElement(jj,{tooltipEntrySettings:d})}),d6e=(t,e)=>t>e?"start":ths(typeof e=="function"?e(t):e,n,n*.8),f6e=(t,e,n)=>{var{top:r,left:i,width:s,height:a}=e,o=mZ(s,a),l=i+hs(t.cx,s,s/2),u=r+hs(t.cy,a,a/2),d=hs(t.innerRadius,o,0),f=h6e(n,t.outerRadius,o),g=t.maxRadius||Math.sqrt(s*s+a*a)/2;return{cx:l,cy:u,innerRadius:d,outerRadius:f,maxRadius:g}},p6e=(t,e)=>{var n=Di(e-t),r=Math.min(Math.abs(e-t),360);return n*r};function m6e(t){return t&&typeof t=="object"&&"className"in t&&typeof t.className=="string"?t.className:""}var g6e=(t,e)=>{if(M.isValidElement(t))return M.cloneElement(t,e);if(typeof t=="function")return t(e);var n=Tn("recharts-pie-label-line",typeof t!="boolean"?t.className:""),{key:r}=e,i=HE(e,t6e);return M.createElement(em,ud({},i,{type:"linear",className:n}))},x6e=(t,e,n)=>{if(M.isValidElement(t))return M.cloneElement(t,e);var r=n;if(typeof t=="function"&&(r=t(e),M.isValidElement(r)))return r;var i=Tn("recharts-pie-label-text",m6e(t));return M.createElement(FE,ud({},e,{alignmentBaseline:"middle",className:i}),r)};function b6e(t){var{sectors:e,props:n,showLabels:r}=t,{label:i,labelLine:s,dataKey:a}=n;if(!r||!i||!e)return null;var o=Ks(n),l=qh(i),u=qh(s),d=typeof i=="object"&&"offsetRadius"in i&&typeof i.offsetRadius=="number"&&i.offsetRadius||20,f=e.map((g,m)=>{var x=(g.startAngle+g.endAngle)/2,y=Yr(g.cx,g.cy,g.outerRadius+d,x),v=Tr(Tr(Tr(Tr({},o),g),{},{stroke:"none"},l),{},{index:m,textAnchor:d6e(y.x,g.cx)},y),b=Tr(Tr(Tr(Tr({},o),g),{},{fill:"none",stroke:g.fill},u),{},{index:m,points:[Yr(g.cx,g.cy,g.outerRadius,x),y],key:"line"});return M.createElement(Qs,{zIndex:Zr.label,key:"label-".concat(g.startAngle,"-").concat(g.endAngle,"-").concat(g.midAngle,"-").concat(m)},M.createElement(Ir,null,s&&g6e(s,b),x6e(i,v,Jn(g,a))))});return M.createElement(Ir,{className:"recharts-pie-labels"},f)}function v6e(t){var{sectors:e,props:n,showLabels:r}=t,{label:i}=n;return typeof i=="object"&&i!=null&&"position"in i?M.createElement(Cj,{label:i}):M.createElement(b6e,{sectors:e,props:n,showLabels:r})}function y6e(t){var{sectors:e,activeShape:n,inactiveShape:r,allOtherPieProps:i,shape:s,id:a}=t,o=kt(cd),l=kt(_j),u=kt(z5e),{onMouseEnter:d,onClick:f,onMouseLeave:g}=i,m=HE(i,n6e),x=Rj(d,i.dataKey,a),y=Dj(g),v=Oj(f,i.dataKey,a);return e==null||e.length===0?null:M.createElement(M.Fragment,null,e.map((b,E)=>{if(b?.startAngle===0&&b?.endAngle===0&&e.length!==1)return null;var S=u==null||u===a,A=String(E)===o&&(l==null||i.dataKey===l)&&S,T=o?r:null,P=n&&A?n:T,C=Tr(Tr({},b),{},{stroke:b.stroke,tabIndex:-1,[GY]:E,[WY]:i.dataKey});return M.createElement(Ir,ud({key:"sector-".concat(b?.startAngle,"-").concat(b?.endAngle,"-").concat(b.midAngle,"-").concat(E),tabIndex:-1,className:"recharts-pie-sector"},xb(m,b,E),{onMouseEnter:x(b,E),onMouseLeave:y(b,E),onClick:v(b,E)}),M.createElement($J,ud({option:s??P,index:E,shapeType:"sector",isActive:A},C)))}))}function _6e(t){var e,{pieSettings:n,displayedData:r,cells:i,offset:s}=t,{cornerRadius:a,startAngle:o,endAngle:l,dataKey:u,nameKey:d,tooltipType:f}=n,g=Math.abs(n.minAngle),m=p6e(o,l),x=Math.abs(m),y=r.length<=1?0:(e=n.paddingAngle)!==null&&e!==void 0?e:0,v=r.filter(P=>Jn(P,u,0)!==0).length,b=(x>=360?v:v-1)*y,E=x-v*g-b,S=r.reduce((P,C)=>{var I=Jn(C,u,0);return P+(Ct(I)?I:0)},0),A;if(S>0){var T;A=r.map((P,C)=>{var I=Jn(P,u,0),N=Jn(P,d,C),D=f6e(n,s,P),F=(Ct(I)?I:0)/S,L,q=Tr(Tr({},P),i&&i[C]&&i[C].props);C?L=T.endAngle+Di(m)*y*(I!==0?1:0):L=o;var R=L+Di(m)*((I!==0?g:0)+F*E),V=(L+R)/2,K=(D.innerRadius+D.outerRadius)/2,W=[{name:N,value:I,payload:q,dataKey:u,type:f}],ne=Yr(D.cx,D.cy,K,V);return T=Tr(Tr(Tr(Tr({},n.presentationProps),{},{percent:F,cornerRadius:typeof a=="string"?parseFloat(a):a,name:N,tooltipPayload:W,midAngle:V,middleRadius:K,tooltipPosition:ne},q),D),{},{value:I,dataKey:u,startAngle:L,endAngle:R,payload:q,paddingAngle:Di(m)*y}),T})}return A}function w6e(t){var{showLabels:e,sectors:n,children:r}=t,i=M.useMemo(()=>!e||!n?[]:n.map(s=>({value:s.value,payload:s.payload,clockWise:!1,parentViewBox:void 0,viewBox:{cx:s.cx,cy:s.cy,innerRadius:s.innerRadius,outerRadius:s.outerRadius,startAngle:s.startAngle,endAngle:s.endAngle,clockWise:!1},fill:s.fill})),[n,e]);return M.createElement(rBe,{value:e?i:void 0},r)}function S6e(t){var{props:e,previousSectorsRef:n,id:r}=t,{sectors:i,isAnimationActive:s,animationBegin:a,animationDuration:o,animationEasing:l,activeShape:u,inactiveShape:d,onAnimationStart:f,onAnimationEnd:g}=e,m=Eb(e,"recharts-pie-"),x=n.current,[y,v]=M.useState(!1),b=M.useCallback(()=>{typeof g=="function"&&g(),v(!1)},[g]),E=M.useCallback(()=>{typeof f=="function"&&f(),v(!0)},[f]);return M.createElement(w6e,{showLabels:!y,sectors:i},M.createElement(Sb,{animationId:m,begin:a,duration:o,isActive:s,easing:l,onAnimationStart:E,onAnimationEnd:b,key:m},S=>{var A=[],T=i&&i[0],P=T?.startAngle;return i?.forEach((C,I)=>{var N=x&&x[I],D=I>0?Kh(C,"paddingAngle",0):0;if(N){var F=cr(N.endAngle-N.startAngle,C.endAngle-C.startAngle,S),L=Tr(Tr({},C),{},{startAngle:P+D,endAngle:P+F+D});A.push(L),P=L.endAngle}else{var{endAngle:q,startAngle:R}=C,V=cr(0,q-R,S),K=Tr(Tr({},C),{},{startAngle:P+D,endAngle:P+V+D});A.push(K),P=K.endAngle}}),n.current=A,M.createElement(Ir,null,M.createElement(y6e,{sectors:A,activeShape:u,inactiveShape:d,allOtherPieProps:e,shape:e.shape,id:r}))}),M.createElement(v6e,{showLabels:!y,sectors:i,props:e}),e.children)}var E6e={animationBegin:400,animationDuration:1500,animationEasing:"ease",cx:"50%",cy:"50%",dataKey:"value",endAngle:360,fill:"#808080",hide:!1,innerRadius:0,isAnimationActive:"auto",label:!1,labelLine:!0,legendType:"rect",minAngle:0,nameKey:"name",outerRadius:"80%",paddingAngle:0,rootTabIndex:0,startAngle:0,stroke:"#fff",zIndex:Zr.area};function M6e(t){var{id:e}=t,n=HE(t,r6e),{hide:r,className:i,rootTabIndex:s}=t,a=M.useMemo(()=>Pj(t.children,Fb),[t.children]),o=kt(d=>yBe(d,e,a)),l=M.useRef(null),u=Tn("recharts-pie",i);return r||o==null?(l.current=null,M.createElement(Ir,{tabIndex:s,className:u})):M.createElement(Qs,{zIndex:t.zIndex},M.createElement(u6e,{dataKey:t.dataKey,nameKey:t.nameKey,sectors:o,stroke:t.stroke,strokeWidth:t.strokeWidth,fill:t.fill,name:t.name,hide:t.hide,tooltipType:t.tooltipType}),M.createElement(Ir,{tabIndex:s,className:u},M.createElement(S6e,{props:Tr(Tr({},n),{},{sectors:o}),previousSectorsRef:l,id:e})))}function KJ(t){var e=ii(t,E6e),{id:n}=e,r=HE(e,i6e),i=Ks(r);return M.createElement(Lj,{id:n,type:"pie"},s=>M.createElement(M.Fragment,null,M.createElement(e6e,{type:"pie",id:s,data:r.data,dataKey:r.dataKey,hide:r.hide,angleAxisId:0,radiusAxisId:0,name:r.name,nameKey:r.nameKey,tooltipType:r.tooltipType,legendType:r.legendType,fill:r.fill,cx:r.cx,cy:r.cy,startAngle:r.startAngle,endAngle:r.endAngle,paddingAngle:r.paddingAngle,minAngle:r.minAngle,innerRadius:r.innerRadius,outerRadius:r.outerRadius,cornerRadius:r.cornerRadius,presentationProps:i,maxRadius:e.maxRadius}),M.createElement(c6e,ud({},r,{id:s})),M.createElement(M6e,ud({},r,{id:s}))))}KJ.displayName="Pie";var A6e=["points"];function c9(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function LN(t){for(var e=1;e{var v,b,E=LN(LN(LN({r:3},a),f),{},{index:y,cx:(v=x.x)!==null&&v!==void 0?v:void 0,cy:(b=x.y)!==null&&b!==void 0?b:void 0,dataKey:s,value:x.value,payload:x.payload,points:e});return M.createElement(R6e,{key:"dot-".concat(y),option:n,dotProps:E,className:i})}),m={};return o&&l!=null&&(m.clipPath="url(#clipPath-".concat(d?"":"dots-").concat(l,")")),M.createElement(Qs,{zIndex:u},M.createElement(Ir,tS({className:r},m),g))}function u9(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function d9(t){for(var e=1;e({top:t.top,bottom:t.bottom,left:t.left,right:t.right})),K6e=Ke([q6e,Pc,Rc],(t,e,n)=>{if(!(!t||e==null||n==null))return{x:t.left,y:t.top,width:Math.max(0,e-t.left-t.right),height:Math.max(0,n-t.top-t.bottom)}}),Ij=()=>kt(K6e),X6e=()=>kt(G5e);function h9(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function IN(t){for(var e=1;e{var{point:e,childIndex:n,mainColor:r,activeDot:i,dataKey:s,clipPath:a}=t;if(i===!1||e.x==null||e.y==null)return null;var o={index:n,dataKey:s,cx:e.x,cy:e.y,r:4,fill:r??"none",strokeWidth:2,stroke:"#fff",payload:e.payload,value:e.value},l=IN(IN(IN({},o),qh(i)),eO(i)),u;return M.isValidElement(i)?u=M.cloneElement(i,l):typeof i=="function"?u=i(l):u=M.createElement(LJ,l),M.createElement(Ir,{className:"recharts-active-dot",clipPath:a},u)};function f9(t){var{points:e,mainColor:n,activeDot:r,itemDataKey:i,clipPath:s,zIndex:a=Zr.activeDot}=t,o=kt(cd),l=X6e();if(e==null||l==null)return null;var u=e.find(d=>l.includes(d.payload));return yr(u)?null:M.createElement(Qs,{zIndex:a},M.createElement(J6e,{point:u,childIndex:Number(o),mainColor:n,dataKey:i,activeDot:r,clipPath:s}))}var e8e="Invariant failed";function t8e(t,e){throw new Error(e8e)}var n8e=["x","y"];function WP(){return WP=Object.assign?Object.assign.bind():function(t){for(var e=1;e1&&arguments[1]!==void 0?arguments[1]:0;return(r,i)=>{if(Ct(e))return e;var s=Ct(r)||yr(r);return s?e(r,i):(s||t8e(),n)}},u8e={},YJ=Zs({name:"errorBars",initialState:u8e,reducers:{addErrorBar:(t,e)=>{var{itemId:n,errorBar:r}=e.payload;t[n]||(t[n]=[]),t[n].push(r)},replaceErrorBar:(t,e)=>{var{itemId:n,prev:r,next:i}=e.payload;t[n]&&(t[n]=t[n].map(s=>s.dataKey===r.dataKey&&s.direction===r.direction?i:s))},removeErrorBar:(t,e)=>{var{itemId:n,errorBar:r}=e.payload;t[n]&&(t[n]=t[n].filter(i=>i.dataKey!==r.dataKey||i.direction!==r.direction))}}}),{addErrorBar:A7e,replaceErrorBar:T7e,removeErrorBar:C7e}=YJ.actions,d8e=YJ.reducer,h8e=["children"];function f8e(t,e){if(t==null)return{};var n,r,i=p8e(t,e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(t);for(r=0;r({x:0,y:0,value:0}),errorBarOffset:0},g8e=M.createContext(m8e);function x8e(t){var{children:e}=t,n=f8e(t,h8e);return M.createElement(g8e.Provider,{value:n},e)}function Uj(t,e){var n,r,i=kt(u=>Oc(u,t)),s=kt(u=>jc(u,e)),a=(n=i?.allowDataOverflow)!==null&&n!==void 0?n:Ci.allowDataOverflow,o=(r=s?.allowDataOverflow)!==null&&r!==void 0?r:Ni.allowDataOverflow,l=a||o;return{needClip:l,needClipX:a,needClipY:o}}function ZJ(t){var{xAxisId:e,yAxisId:n,clipPathId:r}=t,i=Ij(),{needClipX:s,needClipY:a,needClip:o}=Uj(e,n);if(!o||!i)return null;var{x:l,y:u,width:d,height:f}=i;return M.createElement("clipPath",{id:"clipPath-".concat(r)},M.createElement("rect",{x:s?l:l-d/2,y:a?u:u-f/2,width:s?d:d*2,height:a?f:f*2}))}function b8e(t,e){return t&&typeof t=="object"&&"zIndex"in t&&typeof t.zIndex=="number"&&ur(t.zIndex)?t.zIndex:e}var UN={exports:{}},FN={};var m9;function v8e(){if(m9)return FN;m9=1;var t=Dm();function e(l,u){return l===u&&(l!==0||1/l===1/u)||l!==l&&u!==u}var n=typeof Object.is=="function"?Object.is:e,r=t.useSyncExternalStore,i=t.useRef,s=t.useEffect,a=t.useMemo,o=t.useDebugValue;return FN.useSyncExternalStoreWithSelector=function(l,u,d,f,g){var m=i(null);if(m.current===null){var x={hasValue:!1,value:null};m.current=x}else x=m.current;m=a(function(){function v(T){if(!b){if(b=!0,E=T,T=f(T),g!==void 0&&x.hasValue){var P=x.value;if(g(P,T))return S=P}return S=T}if(P=S,n(E,T))return P;var C=f(T);return g!==void 0&&g(P,C)?(E=T,P):(E=T,S=C)}var b=!1,E,S,A=d===void 0?null:d;return[function(){return v(u())},A===null?void 0:function(){return v(A())}]},[u,d,f,g]);var y=r(l,m[0],m[1]);return s(function(){x.hasValue=!0,x.value=y},[y]),o(y),y},FN}var g9;function y8e(){return g9||(g9=1,UN.exports=v8e()),UN.exports}y8e();function _8e(t){t()}function w8e(){let t=null,e=null;return{clear(){t=null,e=null},notify(){_8e(()=>{let n=t;for(;n;)n.callback(),n=n.next})},get(){const n=[];let r=t;for(;r;)n.push(r),r=r.next;return n},subscribe(n){let r=!0;const i=e={callback:n,next:null,prev:e};return i.prev?i.prev.next=i:t=i,function(){!r||t===null||(r=!1,i.next?i.next.prev=i.prev:e=i.prev,i.prev?i.prev.next=i.next:t=i.next)}}}}var x9={notify(){},get:()=>[]};function S8e(t,e){let n,r=x9,i=0,s=!1;function a(y){d();const v=r.subscribe(y);let b=!1;return()=>{b||(b=!0,v(),f())}}function o(){r.notify()}function l(){x.onStateChange&&x.onStateChange()}function u(){return s}function d(){i++,n||(n=t.subscribe(l),r=w8e())}function f(){i--,n&&i===0&&(n(),n=void 0,r.clear(),r=x9)}function g(){s||(s=!0,d())}function m(){s&&(s=!1,f())}const x={addNestedSub:a,notifyNestedSubs:o,handleChangeWrapper:l,isSubscribed:u,trySubscribe:g,tryUnsubscribe:m,getListeners:()=>r};return x}var E8e=()=>typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",M8e=E8e(),A8e=()=>typeof navigator<"u"&&navigator.product==="ReactNative",T8e=A8e(),C8e=()=>M8e||T8e?M.useLayoutEffect:M.useEffect,N8e=C8e();function b9(t,e){return t===e?t!==0||e!==0||1/t===1/e:t!==t&&e!==e}function k8e(t,e){if(b9(t,e))return!0;if(typeof t!="object"||t===null||typeof e!="object"||e===null)return!1;const n=Object.keys(t),r=Object.keys(e);if(n.length!==r.length)return!1;for(let i=0;i{const l=S8e(i);return{store:i,subscription:l,getServerState:r?()=>r:void 0}},[i,r]),a=M.useMemo(()=>i.getState(),[i]);N8e(()=>{const{subscription:l}=s;return l.onStateChange=l.notifyNestedSubs,l.trySubscribe(),a!==i.getState()&&l.notifyNestedSubs(),()=>{l.tryUnsubscribe(),l.onStateChange=void 0}},[s,a]);const o=n||O8e;return M.createElement(o.Provider,{value:s},e)}var L8e=j8e,I8e=new Set(["axisLine","tickLine","activeBar","activeDot","activeLabel","activeShape","allowEscapeViewBox","background","cursor","dot","label","line","margin","padding","position","shape","style","tick","wrapperStyle"]);function U8e(t,e){return t==null&&e==null?!0:typeof t=="number"&&typeof e=="number"?t===e||t!==t&&e!==e:t===e}function $E(t,e){var n=new Set([...Object.keys(t),...Object.keys(e)]);for(var r of n)if(I8e.has(r)){if(t[r]==null&&e[r]==null)continue;if(!k8e(t[r],e[r]))return!1}else if(!U8e(t[r],e[r]))return!1;return!0}var F8e=["onMouseEnter","onMouseLeave","onClick"],z8e=["value","background","tooltipPosition"],B8e=["id"],H8e=["onMouseEnter","onClick","onMouseLeave"];function Cc(){return Cc=Object.assign?Object.assign.bind():function(t){for(var e=1;e{var{dataKey:e,name:n,fill:r,legendType:i,hide:s}=t;return[{inactive:s,dataKey:e,type:i,color:r,value:qm(n,e),payload:t}]},K8e=M.memo(t=>{var{dataKey:e,stroke:n,strokeWidth:r,fill:i,name:s,hide:a,unit:o,tooltipType:l}=t,u={dataDefinedOnItem:void 0,positions:void 0,settings:{stroke:n,strokeWidth:r,fill:i,dataKey:e,nameKey:void 0,name:qm(s,e),hide:a,type:l,color:i,unit:o}};return M.createElement(jj,{tooltipEntrySettings:u})});function X8e(t){var e=kt(cd),{data:n,dataKey:r,background:i,allOtherBarProps:s}=t,{onMouseEnter:a,onMouseLeave:o,onClick:l}=s,u=rS(s,F8e),d=Rj(a,r),f=Dj(o),g=Oj(l,r);if(!i||n==null)return null;var m=qh(i);return M.createElement(Qs,{zIndex:b8e(i,Zr.barBackground)},n.map((x,y)=>{var{value:v,background:b,tooltipPosition:E}=x,S=rS(x,z8e);if(!b)return null;var A=d(x,y),T=f(x,y),P=g(x,y),C=_s(_s(_s(_s(_s({option:i,isActive:String(y)===e},S),{},{fill:"#eee"},b),m),xb(u,x,y)),{},{onMouseEnter:A,onMouseLeave:T,onClick:P,dataKey:r,index:y,className:"recharts-bar-background-rectangle"});return M.createElement(nS,Cc({key:"background-bar-".concat(y)},C))}))}function Y8e(t){var{showLabels:e,children:n,rects:r}=t,i=r?.map(s=>{var a={x:s.x,y:s.y,width:s.width,lowerWidth:s.width,upperWidth:s.width,height:s.height};return _s(_s({},a),{},{value:s.value,payload:s.payload,parentViewBox:s.parentViewBox,viewBox:a,fill:s.fill})});return M.createElement(OJ,{value:e?i:void 0},n)}function Z8e(t){var{shape:e,activeBar:n,baseProps:r,entry:i,index:s,dataKey:a}=t,o=kt(cd),l=kt(_j),u=n&&String(s)===o&&(l==null||a===l),d=u?n:e;return u?M.createElement(Qs,{zIndex:Zr.activeBar},M.createElement(nS,Cc({},r,{name:String(r.name)},i,{isActive:u,option:d,index:s,dataKey:a}))):M.createElement(nS,Cc({},r,{name:String(r.name)},i,{isActive:u,option:d,index:s,dataKey:a}))}function Q8e(t){var{shape:e,baseProps:n,entry:r,index:i,dataKey:s}=t;return M.createElement(nS,Cc({},n,{name:String(n.name)},r,{isActive:!1,option:e,index:i,dataKey:s}))}function J8e(t){var e,{data:n,props:r}=t,i=(e=Ks(r))!==null&&e!==void 0?e:{},{id:s}=i,a=rS(i,B8e),{shape:o,dataKey:l,activeBar:u}=r,{onMouseEnter:d,onClick:f,onMouseLeave:g}=r,m=rS(r,H8e),x=Rj(d,l),y=Dj(g),v=Oj(f,l);return n?M.createElement(M.Fragment,null,n.map((b,E)=>M.createElement(Ir,Cc({key:"rectangle-".concat(b?.x,"-").concat(b?.y,"-").concat(b?.value,"-").concat(E),className:"recharts-bar-rectangle"},xb(m,b,E),{onMouseEnter:x(b,E),onMouseLeave:y(b,E),onClick:v(b,E)}),u?M.createElement(Z8e,{shape:o,activeBar:u,baseProps:a,entry:b,index:E,dataKey:l}):M.createElement(Q8e,{shape:o,baseProps:a,entry:b,index:E,dataKey:l})))):null}function eHe(t){var{props:e,previousRectanglesRef:n}=t,{data:r,layout:i,isAnimationActive:s,animationBegin:a,animationDuration:o,animationEasing:l,onAnimationEnd:u,onAnimationStart:d}=e,f=n.current,g=Eb(e,"recharts-bar-"),[m,x]=M.useState(!1),y=!m,v=M.useCallback(()=>{typeof u=="function"&&u(),x(!1)},[u]),b=M.useCallback(()=>{typeof d=="function"&&d(),x(!0)},[d]);return M.createElement(Y8e,{showLabels:y,rects:r},M.createElement(Sb,{animationId:g,begin:a,duration:o,isActive:s,easing:l,onAnimationEnd:v,onAnimationStart:b,key:g},E=>{var S=E===1?r:r?.map((A,T)=>{var P=f&&f[T];if(P)return _s(_s({},A),{},{x:cr(P.x,A.x,E),y:cr(P.y,A.y,E),width:cr(P.width,A.width,E),height:cr(P.height,A.height,E)});if(i==="horizontal"){var C=cr(0,A.height,E),I=cr(A.stackedBarStart,A.y,E);return _s(_s({},A),{},{y:I,height:C})}var N=cr(0,A.width,E),D=cr(A.stackedBarStart,A.x,E);return _s(_s({},A),{},{width:N,x:D})});return E>0&&(n.current=S??null),S==null?null:M.createElement(Ir,null,M.createElement(J8e,{props:e,data:S}))}),M.createElement(Cj,{label:e.label}),e.children)}function tHe(t){var e=M.useRef(null);return M.createElement(eHe,{previousRectanglesRef:e,props:t})}var QJ=0,nHe=(t,e)=>{var n=Array.isArray(t.value)?t.value[1]:t.value;return{x:t.x,y:t.y,value:n,errorVal:Jn(t,e)}};class rHe extends M.PureComponent{render(){var{hide:e,data:n,dataKey:r,className:i,xAxisId:s,yAxisId:a,needClip:o,background:l,id:u}=this.props;if(e||n==null)return null;var d=Tn("recharts-bar",i),f=u;return M.createElement(Ir,{className:d,id:u},o&&M.createElement("defs",null,M.createElement(ZJ,{clipPathId:f,xAxisId:s,yAxisId:a})),M.createElement(Ir,{className:"recharts-bar-rectangles",clipPath:o?"url(#clipPath-".concat(f,")"):void 0},M.createElement(X8e,{data:n,dataKey:r,background:l,allOtherBarProps:this.props}),M.createElement(tHe,this.props)))}}var iHe={activeBar:!1,animationBegin:0,animationDuration:400,animationEasing:"ease",background:!1,hide:!1,isAnimationActive:"auto",label:!1,legendType:"rect",minPointSize:QJ,xAxisId:0,yAxisId:0,zIndex:Zr.bar};function sHe(t){var{xAxisId:e,yAxisId:n,hide:r,legendType:i,minPointSize:s,activeBar:a,animationBegin:o,animationDuration:l,animationEasing:u,isAnimationActive:d}=t,{needClip:f}=Uj(e,n),g=Km(),m=ms(),x=Pj(t.children,Fb),y=kt(E=>DHe(E,e,n,m,t.id,x));if(g!=="vertical"&&g!=="horizontal")return null;var v,b=y?.[0];return b==null||b.height==null||b.width==null?v=0:v=g==="vertical"?b.height/2:b.width/2,M.createElement(x8e,{xAxisId:e,yAxisId:n,data:y,dataPointFormatter:nHe,errorBarOffset:v},M.createElement(rHe,Cc({},t,{layout:g,needClip:f,data:y,xAxisId:e,yAxisId:n,hide:r,legendType:i,minPointSize:s,activeBar:a,animationBegin:o,animationDuration:l,animationEasing:u,isAnimationActive:d})))}function aHe(t){var{layout:e,barSettings:{dataKey:n,minPointSize:r},pos:i,bandSize:s,xAxis:a,yAxis:o,xAxisTicks:l,yAxisTicks:u,stackedData:d,displayedData:f,offset:g,cells:m,parentViewBox:x,dataStartIndex:y}=t,v=e==="horizontal"?o:a,b=d?v.scale.domain():null,E=MDe({numericAxis:v}),S=v.scale(E);return f.map((A,T)=>{var P,C,I,N,D,F;d?P=yDe(d[T+y],b):(P=Jn(A,n),Array.isArray(P)||(P=[E,P]));var L=c8e(r,QJ)(P[1],T);if(e==="horizontal"){var q,[R,V]=[o.scale(P[0]),o.scale(P[1])];C=jH({axis:a,ticks:l,bandSize:s,offset:i.offset,entry:A,index:T}),I=(q=V??R)!==null&&q!==void 0?q:void 0,N=i.size;var K=R-V;if(D=io(K)?0:K,F={x:C,y:g.top,width:N,height:g.height},Math.abs(L)>0&&Math.abs(D)0&&Math.abs(N)M.createElement(M.Fragment,null,M.createElement(VJ,{legendPayload:q8e(e)}),M.createElement(K8e,{dataKey:e.dataKey,stroke:e.stroke,strokeWidth:e.strokeWidth,fill:e.fill,name:e.name,hide:e.hide,unit:e.unit,tooltipType:e.tooltipType}),M.createElement(qJ,{type:"bar",id:r,data:void 0,xAxisId:e.xAxisId,yAxisId:e.yAxisId,zAxisId:0,dataKey:e.dataKey,stackId:$Y(e.stackId),hide:e.hide,barSize:e.barSize,minPointSize:e.minPointSize,maxBarSize:e.maxBarSize,isPanorama:n}),M.createElement(Qs,{zIndex:e.zIndex},M.createElement(sHe,Cc({},e,{id:r})))))}var JJ=M.memo(oHe,$E);JJ.displayName="Bar";function y9(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function C_(t){for(var e=1;ee,hHe=(t,e,n)=>n,fHe=(t,e,n,r)=>r,pHe=(t,e,n,r,i)=>i,zb=Ke([OE,pHe],(t,e)=>t.filter(n=>n.type==="bar").find(n=>n.id===e)),mHe=Ke([zb],t=>t?.maxBarSize),gHe=(t,e,n,r,i,s)=>s,_9=(t,e,n)=>{var r=n??t;if(!yr(r))return hs(r,e,0)},xHe=Ke([wn,OE,dHe,hHe,fHe],(t,e,n,r,i)=>e.filter(s=>t==="horizontal"?s.xAxisId===n:s.yAxisId===r).filter(s=>s.isPanorama===i).filter(s=>s.hide===!1).filter(s=>s.type==="bar")),bHe=(t,e,n,r)=>{var i=wn(t);return i==="horizontal"?Z0(t,"yAxis",n,r):Z0(t,"xAxis",e,r)},vHe=(t,e,n)=>{var r=wn(t);return r==="horizontal"?pV(t,"xAxis",e):pV(t,"yAxis",n)},yHe=(t,e,n)=>{var r={},i=t.filter(PE),s=t.filter(u=>u.stackId==null),a=i.reduce((u,d)=>(u[d.stackId]||(u[d.stackId]=[]),u[d.stackId].push(d),u),r),o=Object.entries(a).map(u=>{var[d,f]=u,g=f.map(x=>x.dataKey),m=_9(e,n,f[0].barSize);return{stackId:d,dataKeys:g,barSize:m}}),l=s.map(u=>{var d=[u.dataKey].filter(g=>g!=null),f=_9(e,n,u.barSize);return{stackId:void 0,dataKeys:d,barSize:f}});return[...o,...l]},_He=Ke([xHe,H4e,vHe],yHe),wHe=(t,e,n,r,i)=>{var s,a,o=zb(t,e,n,r,i);if(o!=null){var l=wn(t),u=pQ(t),{maxBarSize:d}=o,f=yr(d)?u:d,g,m;return l==="horizontal"?(g=ld(t,"xAxis",e,r),m=od(t,"xAxis",e,r)):(g=ld(t,"yAxis",n,r),m=od(t,"yAxis",n,r)),(s=(a=Tm(g,m,!0))!==null&&a!==void 0?a:f)!==null&&s!==void 0?s:0}},eee=(t,e,n,r)=>{var i=wn(t),s,a;return i==="horizontal"?(s=ld(t,"xAxis",e,r),a=od(t,"xAxis",e,r)):(s=ld(t,"yAxis",n,r),a=od(t,"yAxis",n,r)),Tm(s,a)};function SHe(t,e,n,r,i){var s=r.length;if(!(s<1)){var a=hs(t,n,0,!0),o,l=[];if(ur(r[0].barSize)){var u=!1,d=n/s,f=r.reduce((b,E)=>b+(E.barSize||0),0);f+=(s-1)*a,f>=n&&(f-=(s-1)*a,a=0),f>=n&&d>0&&(u=!0,d*=.9,f=s*d);var g=(n-f)/2>>0,m={offset:g-a,size:0};o=r.reduce((b,E)=>{var S,A={stackId:E.stackId,dataKeys:E.dataKeys,position:{offset:m.offset+m.size+a,size:u?d:(S=E.barSize)!==null&&S!==void 0?S:0}},T=[...b,A];return m=T[T.length-1].position,T},l)}else{var x=hs(e,n,0,!0);n-2*x-(s-1)*a<=0&&(a=0);var y=(n-2*x-(s-1)*a)/s;y>1&&(y>>=0);var v=ur(i)?Math.min(y,i):y;o=r.reduce((b,E,S)=>[...b,{stackId:E.stackId,dataKeys:E.dataKeys,position:{offset:x+(y+a)*S+(y-v)/2,size:v}}],l)}return o}}var EHe=(t,e,n,r,i,s,a)=>{var o=yr(a)?e:a,l=SHe(n,r,i!==s?i:s,t,o);return i!==s&&l!=null&&(l=l.map(u=>C_(C_({},u),{},{position:C_(C_({},u.position),{},{offset:u.position.offset-i/2})}))),l},MHe=Ke([_He,pQ,B4e,mQ,wHe,eee,mHe],EHe),AHe=(t,e,n,r)=>ld(t,"xAxis",e,r),THe=(t,e,n,r)=>ld(t,"yAxis",n,r),CHe=(t,e,n,r)=>od(t,"xAxis",e,r),NHe=(t,e,n,r)=>od(t,"yAxis",n,r),kHe=Ke([MHe,zb],(t,e)=>{if(!(t==null||e==null)){var n=t.find(r=>r.stackId===e.stackId&&e.dataKey!=null&&r.dataKeys.includes(e.dataKey));if(n!=null)return n.position}}),PHe=(t,e)=>{var n=kE(e);if(!(!t||n==null||e==null)){var{stackId:r}=e;if(r!=null){var i=t[r];if(i){var{stackedData:s}=i;if(s)return s.find(a=>a.key===n)}}}},RHe=Ke([bHe,zb],PHe),DHe=Ke([xi,dO,AHe,THe,CHe,NHe,kHe,wn,TE,eee,RHe,zb,gHe],(t,e,n,r,i,s,a,o,l,u,d,f,g)=>{var{chartData:m,dataStartIndex:x,dataEndIndex:y}=l;if(!(f==null||a==null||e==null||o!=="horizontal"&&o!=="vertical"||n==null||r==null||i==null||s==null||u==null)){var{data:v}=f,b;if(v!=null&&v.length>0?b=v:b=m?.slice(x,y+1),b!=null)return aHe({layout:o,barSettings:f,pos:a,parentViewBox:e,bandSize:u,xAxis:n,yAxis:r,xAxisTicks:i,yAxisTicks:s,stackedData:d,displayedData:b,offset:t,cells:g,dataStartIndex:x})}}),tee=t=>{var{chartData:e}=t,n=rr(),r=ms();return M.useEffect(()=>r?()=>{}:(n(TV(e)),()=>{n(TV(void 0))}),[e,n,r]),null},w9={x:0,y:0,width:0,height:0,padding:{top:0,right:0,bottom:0,left:0}},nee=Zs({name:"brush",initialState:w9,reducers:{setBrushSettings(t,e){return e.payload==null?w9:e.payload}}}),{setBrushSettings:N7e}=nee.actions,OHe=nee.reducer;function jHe(t,e,n){return(e=LHe(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function LHe(t){var e=IHe(t,"string");return typeof e=="symbol"?e:e+""}function IHe(t,e){if(typeof t!="object"||!t)return t;var n=t[Symbol.toPrimitive];if(n!==void 0){var r=n.call(t,e);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(t)}class Fj{static create(e){return new Fj(e)}constructor(e){this.scale=e}get domain(){return this.scale.domain}get range(){return this.scale.range}get rangeMin(){return this.range()[0]}get rangeMax(){return this.range()[1]}get bandwidth(){return this.scale.bandwidth}apply(e){var{bandAware:n,position:r}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(e!==void 0){if(r)switch(r){case"start":return this.scale(e);case"middle":{var i=this.bandwidth?this.bandwidth()/2:0;return this.scale(e)+i}case"end":{var s=this.bandwidth?this.bandwidth():0;return this.scale(e)+s}default:return this.scale(e)}if(n){var a=this.bandwidth?this.bandwidth()/2:0;return this.scale(e)+a}return this.scale(e)}}isInRange(e){var n=this.range(),r=n[0],i=n[n.length-1];return r<=i?e>=r&&e<=i:e>=i&&e<=r}}jHe(Fj,"EPS",1e-4);function UHe(t){return(t%180+180)%180}var FHe=function(e){var{width:n,height:r}=e,i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,s=UHe(i),a=s*Math.PI/180,o=Math.atan(r/n),l=a>o&&a{t.dots.push(e.payload)},removeDot:(t,e)=>{var n=Ro(t).dots.findIndex(r=>r===e.payload);n!==-1&&t.dots.splice(n,1)},addArea:(t,e)=>{t.areas.push(e.payload)},removeArea:(t,e)=>{var n=Ro(t).areas.findIndex(r=>r===e.payload);n!==-1&&t.areas.splice(n,1)},addLine:(t,e)=>{t.lines.push(e.payload)},removeLine:(t,e)=>{var n=Ro(t).lines.findIndex(r=>r===e.payload);n!==-1&&t.lines.splice(n,1)}}}),{addDot:k7e,removeDot:P7e,addArea:R7e,removeArea:D7e,addLine:O7e,removeLine:j7e}=ree.actions,BHe=ree.reducer,HHe=M.createContext(void 0),$He=t=>{var{children:e}=t,[n]=M.useState("".concat(U0("recharts"),"-clip")),r=Ij();if(r==null)return null;var{x:i,y:s,width:a,height:o}=r;return M.createElement(HHe.Provider,{value:n},M.createElement("defs",null,M.createElement("clipPath",{id:n},M.createElement("rect",{x:i,y:s,height:o,width:a}))),e)};function iee(t,e){if(e<1)return[];if(e===1)return t;for(var n=[],r=0;rt*i)return!1;var s=n();return t*(e-t*s/2-r)>=0&&t*(e+t*s/2-i)<=0}function WHe(t,e){return iee(t,e+1)}function qHe(t,e,n,r,i){for(var s=(r||[]).slice(),{start:a,end:o}=e,l=0,u=1,d=a,f=function(){var x=r?.[l];if(x===void 0)return{v:iee(r,u)};var y=l,v,b=()=>(v===void 0&&(v=n(x,y)),v),E=x.coordinate,S=l===0||iS(t,E,b,d,o);S||(l=0,d=a,u+=1),S&&(d=E+t*(b()/2+i),l+=u)},g;u<=s.length;)if(g=f(),g)return g.v;return[]}function S9(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function ls(t){for(var e=1;e(x===void 0&&(x=n(m,g)),x);if(g===a-1){var v=t*(m.coordinate+t*y()/2-l);s[g]=m=ls(ls({},m),{},{tickCoord:v>0?m.coordinate-v*t:m.coordinate})}else s[g]=m=ls(ls({},m),{},{tickCoord:m.coordinate});if(m.tickCoord!=null){var b=iS(t,m.tickCoord,y,o,l);b&&(l=m.tickCoord-t*(y()/2+i),s[g]=ls(ls({},m),{},{isShow:!0}))}},d=a-1;d>=0;d--)u(d);return s}function QHe(t,e,n,r,i,s){var a=(r||[]).slice(),o=a.length,{start:l,end:u}=e;if(s){var d=r[o-1],f=n(d,o-1),g=t*(d.coordinate+t*f/2-u);if(a[o-1]=d=ls(ls({},d),{},{tickCoord:g>0?d.coordinate-g*t:d.coordinate}),d.tickCoord!=null){var m=iS(t,d.tickCoord,()=>f,l,u);m&&(u=d.tickCoord-t*(f/2+i),a[o-1]=ls(ls({},d),{},{isShow:!0}))}}for(var x=s?o-1:o,y=function(E){var S=a[E],A,T=()=>(A===void 0&&(A=n(S,E)),A);if(E===0){var P=t*(S.coordinate-t*T()/2-l);a[E]=S=ls(ls({},S),{},{tickCoord:P<0?S.coordinate-P*t:S.coordinate})}else a[E]=S=ls(ls({},S),{},{tickCoord:S.coordinate});if(S.tickCoord!=null){var C=iS(t,S.tickCoord,T,l,u);C&&(l=S.tickCoord+t*(T()/2+i),a[E]=ls(ls({},S),{},{isShow:!0}))}},v=0;v{var T=typeof u=="function"?u(S.value,A):S.value;return x==="width"?VHe(e0(T,{fontSize:e,letterSpacing:n}),y,f):e0(T,{fontSize:e,letterSpacing:n})[x]},b=i.length>=2?Di(i[1].coordinate-i[0].coordinate):1,E=GHe(s,b,x);return l==="equidistantPreserveStart"?qHe(b,E,v,i,a):(l==="preserveStart"||l==="preserveStartEnd"?m=QHe(b,E,v,i,a,l==="preserveStartEnd"):m=ZHe(b,E,v,i,a),m.filter(S=>S.isShow))}var JHe=t=>{var{ticks:e,label:n,labelGapWithTick:r=5,tickSize:i=0,tickMargin:s=0}=t,a=0;if(e){Array.from(e).forEach(d=>{if(d){var f=d.getBoundingClientRect();f.width>a&&(a=f.width)}});var o=n?n.getBoundingClientRect().width:0,l=i+s,u=a+l+o+(n?r:0);return Math.round(u)}return 0},e$e=["axisLine","width","height","className","hide","ticks","axisType"];function t$e(t,e){if(t==null)return{};var n,r,i=n$e(t,e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(t);for(r=0;r{var{ticks:n=[],tick:r,tickLine:i,stroke:s,tickFormatter:a,unit:o,padding:l,tickTextProps:u,orientation:d,mirror:f,x:g,y:m,width:x,height:y,tickSize:v,tickMargin:b,fontSize:E,letterSpacing:S,getTicksConfig:A,events:T,axisType:P}=t,C=zj(Gr(Gr({},A),{},{ticks:n}),E,S),I=l$e(d,f),N=c$e(d,f),D=Ks(A),F=qh(r),L={};typeof i=="object"&&(L=i);var q=Gr(Gr({},D),{},{fill:"none"},L),R=C.map(W=>Gr({entry:W},o$e(W,g,m,x,y,d,v,f,b))),V=R.map(W=>{var{entry:ne,line:Y}=W;return M.createElement(Ir,{className:"recharts-cartesian-axis-tick",key:"tick-".concat(ne.value,"-").concat(ne.coordinate,"-").concat(ne.tickCoord)},i&&M.createElement("line",Qh({},q,Y,{className:Tn("recharts-cartesian-axis-tick-line",Kh(i,"className"))})))}),K=R.map((W,ne)=>{var{entry:Y,tick:Z}=W,U=Gr(Gr(Gr(Gr({textAnchor:I,verticalAnchor:N},D),{},{stroke:"none",fill:s},F),Z),{},{index:ne,payload:Y,visibleTicksCount:C.length,tickFormatter:a,padding:l},u);return M.createElement(Ir,Qh({className:"recharts-cartesian-axis-tick-label",key:"tick-label-".concat(Y.value,"-").concat(Y.coordinate,"-").concat(Y.tickCoord)},xb(T,Y,ne)),r&&M.createElement(u$e,{option:r,tickProps:U,value:"".concat(typeof a=="function"?a(Y.value,ne):Y.value).concat(o||"")}))});return M.createElement("g",{className:"recharts-cartesian-axis-ticks recharts-".concat(P,"-ticks")},K.length>0&&M.createElement(Qs,{zIndex:Zr.label},M.createElement("g",{className:"recharts-cartesian-axis-tick-labels recharts-".concat(P,"-tick-labels"),ref:e},K)),V.length>0&&M.createElement("g",{className:"recharts-cartesian-axis-tick-lines recharts-".concat(P,"-tick-lines")},V))}),h$e=M.forwardRef((t,e)=>{var{axisLine:n,width:r,height:i,className:s,hide:a,ticks:o,axisType:l}=t,u=t$e(t,e$e),[d,f]=M.useState(""),[g,m]=M.useState(""),x=M.useRef(null);M.useImperativeHandle(e,()=>({getCalculatedWidth:()=>{var v;return JHe({ticks:x.current,label:(v=t.labelRef)===null||v===void 0?void 0:v.current,labelGapWithTick:5,tickSize:t.tickSize,tickMargin:t.tickMargin})}}));var y=M.useCallback(v=>{if(v){var b=v.getElementsByClassName("recharts-cartesian-axis-tick-value");x.current=b;var E=b[0];if(E){var S=window.getComputedStyle(E),A=S.fontSize,T=S.letterSpacing;(A!==d||T!==g)&&(f(A),m(T))}}},[d,g]);return a||r!=null&&r<=0||i!=null&&i<=0?null:M.createElement(Qs,{zIndex:t.zIndex},M.createElement(Ir,{className:Tn("recharts-cartesian-axis",s)},M.createElement(a$e,{x:t.x,y:t.y,width:r,height:i,orientation:t.orientation,mirror:t.mirror,axisLine:n,otherSvgProps:Ks(t)}),M.createElement(d$e,{ref:y,axisType:l,events:u,fontSize:d,getTicksConfig:t,height:t.height,letterSpacing:g,mirror:t.mirror,orientation:t.orientation,padding:t.padding,stroke:t.stroke,tick:t.tick,tickFormatter:t.tickFormatter,tickLine:t.tickLine,tickMargin:t.tickMargin,tickSize:t.tickSize,tickTextProps:t.tickTextProps,ticks:o,unit:t.unit,width:t.width,x:t.x,y:t.y}),M.createElement(Lze,{x:t.x,y:t.y,width:t.width,height:t.height,lowerWidth:t.width,upperWidth:t.width},M.createElement(Wze,{label:t.label,labelRef:t.labelRef}),t.children)))}),Bj=M.forwardRef((t,e)=>{var n=ii(t,bc);return M.createElement(h$e,Qh({},n,{ref:e}))});Bj.displayName="CartesianAxis";var f$e=["x1","y1","x2","y2","key"],p$e=["offset"],m$e=["xAxisId","yAxisId"],g$e=["xAxisId","yAxisId"];function M9(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function cs(t){for(var e=1;e{var{fill:e}=t;if(!e||e==="none")return null;var{fillOpacity:n,x:r,y:i,width:s,height:a,ry:o}=t;return M.createElement("rect",{x:r,y:i,ry:o,width:s,height:a,stroke:"none",fill:e,fillOpacity:n,className:"recharts-cartesian-grid-bg"})};function see(t){var{option:e,lineItemProps:n}=t,r;if(M.isValidElement(e))r=M.cloneElement(e,n);else if(typeof e=="function")r=e(n);else{var i,{x1:s,y1:a,x2:o,y2:l,key:u}=n,d=sS(n,f$e),f=(i=Ks(d))!==null&&i!==void 0?i:{},{offset:g}=f,m=sS(f,p$e);r=M.createElement("line",hh({},m,{x1:s,y1:a,x2:o,y2:l,fill:"none",key:u}))}return r}function w$e(t){var{x:e,width:n,horizontal:r=!0,horizontalPoints:i}=t;if(!r||!i||!i.length)return null;var{xAxisId:s,yAxisId:a}=t,o=sS(t,m$e),l=i.map((u,d)=>{var f=cs(cs({},o),{},{x1:e,y1:u,x2:e+n,y2:u,key:"line-".concat(d),index:d});return M.createElement(see,{key:"line-".concat(d),option:r,lineItemProps:f})});return M.createElement("g",{className:"recharts-cartesian-grid-horizontal"},l)}function S$e(t){var{y:e,height:n,vertical:r=!0,verticalPoints:i}=t;if(!r||!i||!i.length)return null;var{xAxisId:s,yAxisId:a}=t,o=sS(t,g$e),l=i.map((u,d)=>{var f=cs(cs({},o),{},{x1:u,y1:e,x2:u,y2:e+n,key:"line-".concat(d),index:d});return M.createElement(see,{option:r,lineItemProps:f,key:"line-".concat(d)})});return M.createElement("g",{className:"recharts-cartesian-grid-vertical"},l)}function E$e(t){var{horizontalFill:e,fillOpacity:n,x:r,y:i,width:s,height:a,horizontalPoints:o,horizontal:l=!0}=t;if(!l||!e||!e.length||o==null)return null;var u=o.map(f=>Math.round(f+i-i)).sort((f,g)=>f-g);i!==u[0]&&u.unshift(0);var d=u.map((f,g)=>{var m=!u[g+1],x=m?i+a-f:u[g+1]-f;if(x<=0)return null;var y=g%e.length;return M.createElement("rect",{key:"react-".concat(g),y:f,x:r,height:x,width:s,stroke:"none",fill:e[y],fillOpacity:n,className:"recharts-cartesian-grid-bg"})});return M.createElement("g",{className:"recharts-cartesian-gridstripes-horizontal"},d)}function M$e(t){var{vertical:e=!0,verticalFill:n,fillOpacity:r,x:i,y:s,width:a,height:o,verticalPoints:l}=t;if(!e||!n||!n.length)return null;var u=l.map(f=>Math.round(f+i-i)).sort((f,g)=>f-g);i!==u[0]&&u.unshift(0);var d=u.map((f,g)=>{var m=!u[g+1],x=m?i+a-f:u[g+1]-f;if(x<=0)return null;var y=g%n.length;return M.createElement("rect",{key:"react-".concat(g),x:f,y:s,width:x,height:o,stroke:"none",fill:n[y],fillOpacity:r,className:"recharts-cartesian-grid-bg"})});return M.createElement("g",{className:"recharts-cartesian-gridstripes-vertical"},d)}var A$e=(t,e)=>{var{xAxis:n,width:r,height:i,offset:s}=t;return BY(zj(cs(cs(cs({},bc),n),{},{ticks:HY(n),viewBox:{x:0,y:0,width:r,height:i}})),s.left,s.left+s.width,e)},T$e=(t,e)=>{var{yAxis:n,width:r,height:i,offset:s}=t;return BY(zj(cs(cs(cs({},bc),n),{},{ticks:HY(n),viewBox:{x:0,y:0,width:r,height:i}})),s.top,s.top+s.height,e)},C$e={horizontal:!0,vertical:!0,horizontalPoints:[],verticalPoints:[],stroke:"#ccc",fill:"none",verticalFill:[],horizontalFill:[],xAxisId:0,yAxisId:0,syncWithTicks:!1,zIndex:Zr.grid};function qP(t){var e=fO(),n=pO(),r=ZY(),i=cs(cs({},ii(t,C$e)),{},{x:Ct(t.x)?t.x:r.left,y:Ct(t.y)?t.y:r.top,width:Ct(t.width)?t.width:r.width,height:Ct(t.height)?t.height:r.height}),{xAxisId:s,yAxisId:a,x:o,y:l,width:u,height:d,syncWithTicks:f,horizontalValues:g,verticalValues:m}=i,x=ms(),y=kt(N=>mV(N,"xAxis",s,x)),v=kt(N=>mV(N,"yAxis",a,x));if(!pl(u)||!pl(d)||!Ct(o)||!Ct(l))return null;var b=i.verticalCoordinatesGenerator||A$e,E=i.horizontalCoordinatesGenerator||T$e,{horizontalPoints:S,verticalPoints:A}=i;if((!S||!S.length)&&typeof E=="function"){var T=g&&g.length,P=E({yAxis:v?cs(cs({},v),{},{ticks:T?g:v.ticks}):void 0,width:e??u,height:n??d,offset:r},T?!0:f);kw(Array.isArray(P),"horizontalCoordinatesGenerator should return Array but instead it returned [".concat(typeof P,"]")),Array.isArray(P)&&(S=P)}if((!A||!A.length)&&typeof b=="function"){var C=m&&m.length,I=b({xAxis:y?cs(cs({},y),{},{ticks:C?m:y.ticks}):void 0,width:e??u,height:n??d,offset:r},C?!0:f);kw(Array.isArray(I),"verticalCoordinatesGenerator should return Array but instead it returned [".concat(typeof I,"]")),Array.isArray(I)&&(A=I)}return M.createElement(Qs,{zIndex:i.zIndex},M.createElement("g",{className:"recharts-cartesian-grid"},M.createElement(_$e,{fill:i.fill,fillOpacity:i.fillOpacity,x:i.x,y:i.y,width:i.width,height:i.height,ry:i.ry}),M.createElement(E$e,hh({},i,{horizontalPoints:S})),M.createElement(M$e,hh({},i,{verticalPoints:A})),M.createElement(w$e,hh({},i,{offset:r,horizontalPoints:S,xAxis:y,yAxis:v})),M.createElement(S$e,hh({},i,{offset:r,verticalPoints:A,xAxis:y,yAxis:v}))))}qP.displayName="CartesianGrid";function N$e(t){var e=qh(t),n=3,r=2;if(e!=null){var{r:i,strokeWidth:s}=e,a=Number(i),o=Number(s);return(Number.isNaN(a)||a<0)&&(a=n),(Number.isNaN(o)||o<0)&&(o=r),{r:a,strokeWidth:o}}return{r:n,strokeWidth:r}}var aee=(t,e,n,r)=>ld(t,"xAxis",e,r),oee=(t,e,n,r)=>od(t,"xAxis",e,r),lee=(t,e,n,r)=>ld(t,"yAxis",n,r),cee=(t,e,n,r)=>od(t,"yAxis",n,r),k$e=Ke([wn,aee,lee,oee,cee],(t,e,n,r,i)=>kc(t,"xAxis")?Tm(e,r,!1):Tm(n,i,!1)),P$e=(t,e,n,r,i)=>i,uee=Ke([OE,P$e],(t,e)=>t.filter(n=>n.type==="area").find(n=>n.id===e)),R$e=(t,e,n,r,i)=>{var s,a=uee(t,e,n,r,i);if(a!=null){var o=wn(t),l=kc(o,"xAxis"),u;if(l?u=Z0(t,"yAxis",n,r):u=Z0(t,"xAxis",e,r),u!=null){var{stackId:d}=a,f=kE(a);if(!(d==null||f==null)){var g=(s=u[d])===null||s===void 0?void 0:s.stackedData;return g?.find(m=>m.key===f)}}}},D$e=Ke([wn,aee,lee,oee,cee,R$e,TE,k$e,uee,$4e],(t,e,n,r,i,s,a,o,l,u)=>{var{chartData:d,dataStartIndex:f,dataEndIndex:g}=a;if(!(l==null||t!=="horizontal"&&t!=="vertical"||e==null||n==null||r==null||i==null||r.length===0||i.length===0||o==null)){var{data:m}=l,x;if(m&&m.length>0?x=m:x=d?.slice(f,g+1),x!=null)return Q$e({layout:t,xAxis:e,yAxis:n,xAxisTicks:r,yAxisTicks:i,dataStartIndex:f,areaSettings:l,stackedData:s,displayedData:x,chartBaseValue:u,bandSize:o})}}),O$e=["id"],j$e=["activeDot","animationBegin","animationDuration","animationEasing","connectNulls","dot","fill","fillOpacity","hide","isAnimationActive","legendType","stroke","xAxisId","yAxisId"];function Th(){return Th=Object.assign?Object.assign.bind():function(t){for(var e=1;e{var{dataKey:e,name:n,stroke:r,fill:i,legendType:s,hide:a}=t;return[{inactive:a,dataKey:e,type:s,color:aS(r,i),value:qm(n,e),payload:t}]},B$e=M.memo(t=>{var{dataKey:e,data:n,stroke:r,strokeWidth:i,fill:s,name:a,hide:o,unit:l,tooltipType:u}=t,d={dataDefinedOnItem:n,positions:void 0,settings:{stroke:r,strokeWidth:i,fill:s,dataKey:e,nameKey:void 0,name:qm(a,e),hide:o,type:u,color:aS(r,s),unit:l}};return M.createElement(jj,{tooltipEntrySettings:d})});function H$e(t){var{clipPathId:e,points:n,props:r}=t,{needClip:i,dot:s,dataKey:a}=r,o=Ks(r);return M.createElement(O6e,{points:n,dot:s,className:"recharts-area-dots",dotClassName:"recharts-area-dot",dataKey:a,baseProps:o,needClip:i,clipPathId:e})}function $$e(t){var{showLabels:e,children:n,points:r}=t,i=r.map(s=>{var a,o,l={x:(a=s.x)!==null&&a!==void 0?a:0,y:(o=s.y)!==null&&o!==void 0?o:0,width:0,lowerWidth:0,upperWidth:0,height:0};return zp(zp({},l),{},{value:s.value,payload:s.payload,parentViewBox:void 0,viewBox:l,fill:void 0})});return M.createElement(OJ,{value:e?i:void 0},n)}function T9(t){var{points:e,baseLine:n,needClip:r,clipPathId:i,props:s}=t,{layout:a,type:o,stroke:l,connectNulls:u,isRange:d}=s,{id:f}=s,g=dee(s,O$e),m=Ks(g),x=Cs(g);return M.createElement(M.Fragment,null,e?.length>1&&M.createElement(Ir,{clipPath:r?"url(#clipPath-".concat(i,")"):void 0},M.createElement(em,Th({},x,{id:f,points:e,connectNulls:u,type:o,baseLine:n,layout:a,stroke:"none",className:"recharts-area-area"})),l!=="none"&&M.createElement(em,Th({},m,{className:"recharts-area-curve",layout:a,type:o,connectNulls:u,fill:"none",points:e})),l!=="none"&&d&&M.createElement(em,Th({},m,{className:"recharts-area-curve",layout:a,type:o,connectNulls:u,fill:"none",points:n}))),M.createElement(H$e,{points:e,props:g,clipPathId:i}))}function V$e(t){var{alpha:e,baseLine:n,points:r,strokeWidth:i}=t,s=r[0].y,a=r[r.length-1].y;if(!ur(s)||!ur(a))return null;var o=e*Math.abs(s-a),l=Math.max(...r.map(u=>u.x||0));return Ct(n)?l=Math.max(n,l):n&&Array.isArray(n)&&n.length&&(l=Math.max(...n.map(u=>u.x||0),l)),Ct(l)?M.createElement("rect",{x:0,y:su.y||0));return Ct(n)?l=Math.max(n,l):n&&Array.isArray(n)&&n.length&&(l=Math.max(...n.map(u=>u.y||0),l)),Ct(l)?M.createElement("rect",{x:s({points:a,baseLine:o}),[a,o]),y=Eb(x,"recharts-area-"),v=oOe(),[b,E]=M.useState(!1),S=!b,A=M.useCallback(()=>{typeof m=="function"&&m(),E(!1)},[m]),T=M.useCallback(()=>{typeof g=="function"&&g(),E(!0)},[g]);if(v==null)return null;var P=i.current,C=s.current;return M.createElement($$e,{showLabels:S,points:a},r.children,M.createElement(Sb,{animationId:y,begin:u,duration:d,isActive:l,easing:f,onAnimationEnd:A,onAnimationStart:T,key:y},I=>{if(P){var N=P.length/a.length,D=I===1?a:a.map((L,q)=>{var R=Math.floor(q*N);if(P[R]){var V=P[R];return zp(zp({},L),{},{x:cr(V.x,L.x,I),y:cr(V.y,L.y,I)})}return L}),F;return Ct(o)?F=cr(C,o,I):yr(o)||io(o)?F=cr(C,0,I):F=o.map((L,q)=>{var R=Math.floor(q*N);if(Array.isArray(C)&&C[R]){var V=C[R];return zp(zp({},L),{},{x:cr(V.x,L.x,I),y:cr(V.y,L.y,I)})}return L}),I>0&&(i.current=D,s.current=F),M.createElement(T9,{points:D,baseLine:F,needClip:e,clipPathId:n,props:r})}return I>0&&(i.current=a,s.current=o),M.createElement(Ir,null,l&&M.createElement("defs",null,M.createElement("clipPath",{id:"animationClipPath-".concat(n)},M.createElement(W$e,{alpha:I,points:a,baseLine:o,layout:v,strokeWidth:r.strokeWidth}))),M.createElement(Ir,{clipPath:"url(#animationClipPath-".concat(n,")")},M.createElement(T9,{points:a,baseLine:o,needClip:e,clipPathId:n,props:r})))}),M.createElement(Cj,{label:r.label}))}function K$e(t){var{needClip:e,clipPathId:n,props:r}=t,i=M.useRef(null),s=M.useRef();return M.createElement(q$e,{needClip:e,clipPathId:n,props:r,previousPointsRef:i,previousBaselineRef:s})}class X$e extends M.PureComponent{render(){var{hide:e,dot:n,points:r,className:i,top:s,left:a,needClip:o,xAxisId:l,yAxisId:u,width:d,height:f,id:g,baseLine:m,zIndex:x}=this.props;if(e)return null;var y=Tn("recharts-area",i),v=g,{r:b,strokeWidth:E}=N$e(n),S=HJ(n),A=b*2+E,T=o?"url(#clipPath-".concat(S?"":"dots-").concat(v,")"):void 0;return M.createElement(Qs,{zIndex:x},M.createElement(Ir,{className:y},o&&M.createElement("defs",null,M.createElement(ZJ,{clipPathId:v,xAxisId:l,yAxisId:u}),!S&&M.createElement("clipPath",{id:"clipPath-dots-".concat(v)},M.createElement("rect",{x:a-A/2,y:s-A/2,width:d+A,height:f+A}))),M.createElement(K$e,{needClip:o,clipPathId:v,props:this.props})),M.createElement(f9,{points:r,mainColor:aS(this.props.stroke,this.props.fill),itemDataKey:this.props.dataKey,activeDot:this.props.activeDot,clipPath:T}),this.props.isRange&&Array.isArray(m)&&M.createElement(f9,{points:m,mainColor:aS(this.props.stroke,this.props.fill),itemDataKey:this.props.dataKey,activeDot:this.props.activeDot,clipPath:T}))}}var hee={activeDot:!0,animationBegin:0,animationDuration:1500,animationEasing:"ease",connectNulls:!1,dot:!1,fill:"#3182bd",fillOpacity:.6,hide:!1,isAnimationActive:"auto",legendType:"line",stroke:"#3182bd",strokeWidth:1,type:"linear",label:!1,xAxisId:0,yAxisId:0,zIndex:Zr.area};function Y$e(t){var e,n=ii(t,hee),{activeDot:r,animationBegin:i,animationDuration:s,animationEasing:a,connectNulls:o,dot:l,fill:u,fillOpacity:d,hide:f,isAnimationActive:g,legendType:m,stroke:x,xAxisId:y,yAxisId:v}=n,b=dee(n,j$e),E=Km(),S=mJ(),{needClip:A}=Uj(y,v),T=ms(),{points:P,isRange:C,baseLine:I}=(e=kt(R=>D$e(R,y,v,T,t.id)))!==null&&e!==void 0?e:{},N=Ij();if(E!=="horizontal"&&E!=="vertical"||N==null||S!=="AreaChart"&&S!=="ComposedChart")return null;var{height:D,width:F,x:L,y:q}=N;return!P||!P.length?null:M.createElement(X$e,Th({},b,{activeDot:r,animationBegin:i,animationDuration:s,animationEasing:a,baseLine:I,connectNulls:o,dot:l,fill:u,fillOpacity:d,height:D,hide:f,layout:E,isAnimationActive:g==="auto"?!Xm.isSsr:g,isRange:C,legendType:m,needClip:A,points:P,stroke:x,width:F,left:L,top:q,xAxisId:y,yAxisId:v}))}var Z$e=(t,e,n,r,i)=>{var s=n??e;if(Ct(s))return s;var a=t==="horizontal"?i:r,o=a.scale.domain();if(a.type==="number"){var l=Math.max(o[0],o[1]),u=Math.min(o[0],o[1]);return s==="dataMin"?u:s==="dataMax"||l<0?l:Math.max(Math.min(o[0],o[1]),0)}return s==="dataMin"?o[0]:s==="dataMax"?o[1]:o[0]};function Q$e(t){var{areaSettings:{connectNulls:e,baseValue:n,dataKey:r},stackedData:i,layout:s,chartBaseValue:a,xAxis:o,yAxis:l,displayedData:u,dataStartIndex:d,xAxisTicks:f,yAxisTicks:g,bandSize:m}=t,x=i&&i.length,y=Z$e(s,a,n,o,l),v=s==="horizontal",b=!1,E=u.map((A,T)=>{var P;x?P=i[d+T]:(P=Jn(A,r),Array.isArray(P)?b=!0:P=[y,P]);var C=P[1]==null||x&&!e&&Jn(A,r)==null;return v?{x:OH({axis:o,ticks:f,bandSize:m,entry:A,index:T}),y:C?null:l.scale(P[1]),value:P,payload:A}:{x:C?null:o.scale(P[1]),y:OH({axis:l,ticks:g,bandSize:m,entry:A,index:T}),value:P,payload:A}}),S;return x||b?S=E.map(A=>{var T=Array.isArray(A.value)?A.value[0]:null;return v?{x:A.x,y:T!=null&&A.y!=null?l.scale(T):null,payload:A.payload}:{x:T!=null?o.scale(T):null,y:A.y,payload:A.payload}}):S=v?l.scale(y):o.scale(y),{points:E,baseLine:S,isRange:b}}function J$e(t){var e=ii(t,hee),n=ms();return M.createElement(Lj,{id:e.id,type:"area"},r=>M.createElement(M.Fragment,null,M.createElement(VJ,{legendPayload:z$e(e)}),M.createElement(B$e,{dataKey:e.dataKey,data:e.data,stroke:e.stroke,strokeWidth:e.strokeWidth,fill:e.fill,name:e.name,hide:e.hide,unit:e.unit,tooltipType:e.tooltipType}),M.createElement(qJ,{type:"area",id:r,data:e.data,dataKey:e.dataKey,xAxisId:e.xAxisId,yAxisId:e.yAxisId,zAxisId:0,stackId:$Y(e.stackId),hide:e.hide,barSize:void 0,baseValue:e.baseValue,isPanorama:n,connectNulls:e.connectNulls}),M.createElement(Y$e,Th({},e,{id:r}))))}var fee=M.memo(J$e,$E);fee.displayName="Area";var eVe=["domain","range"],tVe=["domain","range"];function C9(t,e){if(t==null)return{};var n,r,i=nVe(t,e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(t);for(r=0;r{n.current===null?e(F6e(t)):n.current!==t&&e(z6e({prev:n.current,next:t})),n.current=t},[t,e]),M.useLayoutEffect(()=>()=>{n.current&&(e(B6e(n.current)),n.current=null)},[e]),null}var oVe=t=>{var{xAxisId:e,className:n}=t,r=kt(dO),i=ms(),s="xAxis",a=kt(v=>ng(v,s,e,i)),o=kt(v=>qQ(v,s,e,i)),l=kt(v=>$Q(v,e)),u=kt(v=>zUe(v,e)),d=kt(v=>EQ(v,e));if(l==null||u==null||d==null)return null;var{dangerouslySetInnerHTML:f,ticks:g}=t,m=k9(t,rVe),{id:x}=d,y=k9(d,iVe);return M.createElement(Bj,KP({},m,y,{scale:a,x:u.x,y:u.y,width:l.width,height:l.height,className:Tn("recharts-".concat(s," ").concat(s),n),viewBox:r,ticks:o,axisType:s}))},lVe={allowDataOverflow:Ci.allowDataOverflow,allowDecimals:Ci.allowDecimals,allowDuplicatedCategory:Ci.allowDuplicatedCategory,angle:Ci.angle,axisLine:bc.axisLine,height:Ci.height,hide:!1,includeHidden:Ci.includeHidden,interval:Ci.interval,minTickGap:Ci.minTickGap,mirror:Ci.mirror,orientation:Ci.orientation,padding:Ci.padding,reversed:Ci.reversed,scale:Ci.scale,tick:Ci.tick,tickCount:Ci.tickCount,tickLine:bc.tickLine,tickSize:bc.tickSize,type:Ci.type,xAxisId:0},cVe=t=>{var e=ii(t,lVe);return M.createElement(M.Fragment,null,M.createElement(aVe,{allowDataOverflow:e.allowDataOverflow,allowDecimals:e.allowDecimals,allowDuplicatedCategory:e.allowDuplicatedCategory,angle:e.angle,dataKey:e.dataKey,domain:e.domain,height:e.height,hide:e.hide,id:e.xAxisId,includeHidden:e.includeHidden,interval:e.interval,minTickGap:e.minTickGap,mirror:e.mirror,name:e.name,orientation:e.orientation,padding:e.padding,reversed:e.reversed,scale:e.scale,tick:e.tick,tickCount:e.tickCount,tickFormatter:e.tickFormatter,ticks:e.ticks,type:e.type,unit:e.unit}),M.createElement(oVe,e))},XP=M.memo(cVe,pee);XP.displayName="XAxis";var uVe=["dangerouslySetInnerHTML","ticks"],dVe=["id"];function YP(){return YP=Object.assign?Object.assign.bind():function(t){for(var e=1;e{n.current===null?e(H6e(t)):n.current!==t&&e($6e({prev:n.current,next:t})),n.current=t},[t,e]),M.useLayoutEffect(()=>()=>{n.current&&(e(V6e(n.current)),n.current=null)},[e]),null}var pVe=t=>{var{yAxisId:e,className:n,width:r,label:i}=t,s=M.useRef(null),a=M.useRef(null),o=kt(dO),l=ms(),u=rr(),d="yAxis",f=kt(T=>ng(T,d,e,l)),g=kt(T=>VQ(T,e)),m=kt(T=>HUe(T,e)),x=kt(T=>qQ(T,d,e,l)),y=kt(T=>MQ(T,e));if(M.useLayoutEffect(()=>{if(!(r!=="auto"||!g||Tj(i)||M.isValidElement(i)||y==null)){var T=s.current;if(T){var P=T.getCalculatedWidth();Math.round(g.width)!==Math.round(P)&&u(G6e({id:e,width:P}))}}},[x,g,u,i,e,r,y]),g==null||m==null||y==null)return null;var{dangerouslySetInnerHTML:v,ticks:b}=t,E=P9(t,uVe),{id:S}=y,A=P9(y,dVe);return M.createElement(Bj,YP({},E,A,{ref:s,labelRef:a,scale:f,x:m.x,y:m.y,tickTextProps:r==="auto"?{width:void 0}:{width:r},width:g.width,height:g.height,className:Tn("recharts-".concat(d," ").concat(d),n),viewBox:o,ticks:x,axisType:d}))},mVe={allowDataOverflow:Ni.allowDataOverflow,allowDecimals:Ni.allowDecimals,allowDuplicatedCategory:Ni.allowDuplicatedCategory,angle:Ni.angle,axisLine:bc.axisLine,hide:!1,includeHidden:Ni.includeHidden,interval:Ni.interval,minTickGap:Ni.minTickGap,mirror:Ni.mirror,orientation:Ni.orientation,padding:Ni.padding,reversed:Ni.reversed,scale:Ni.scale,tick:Ni.tick,tickCount:Ni.tickCount,tickLine:bc.tickLine,tickSize:bc.tickSize,type:Ni.type,width:Ni.width,yAxisId:0},gVe=t=>{var e=ii(t,mVe);return M.createElement(M.Fragment,null,M.createElement(fVe,{interval:e.interval,id:e.yAxisId,scale:e.scale,type:e.type,domain:e.domain,allowDataOverflow:e.allowDataOverflow,dataKey:e.dataKey,allowDuplicatedCategory:e.allowDuplicatedCategory,allowDecimals:e.allowDecimals,tickCount:e.tickCount,padding:e.padding,includeHidden:e.includeHidden,reversed:e.reversed,ticks:e.ticks,width:e.width,orientation:e.orientation,mirror:e.mirror,hide:e.hide,unit:e.unit,name:e.name,angle:e.angle,minTickGap:e.minTickGap,tick:e.tick,tickFormatter:e.tickFormatter}),M.createElement(pVe,e))},ZP=M.memo(gVe,pee);ZP.displayName="YAxis";var xVe=(t,e)=>e,Hj=Ke([xVe,wn,wQ,vi,cJ,Lc,rFe,xi],uFe),$j=t=>{var e=t.currentTarget.getBoundingClientRect(),n=e.width/t.currentTarget.offsetWidth,r=e.height/t.currentTarget.offsetHeight;return{chartX:Math.round((t.clientX-e.left)/n),chartY:Math.round((t.clientY-e.top)/r)}},mee=so("mouseClick"),gee=yb();gee.startListening({actionCreator:mee,effect:(t,e)=>{var n=t.payload,r=Hj(e.getState(),$j(n));r?.activeIndex!=null&&e.dispatch(n5e({activeIndex:r.activeIndex,activeDataKey:void 0,activeCoordinate:r.activeCoordinate}))}});var QP=so("mouseMove"),xee=yb(),N_=null;xee.startListening({actionCreator:QP,effect:(t,e)=>{var n=t.payload;N_!==null&&cancelAnimationFrame(N_);var r=$j(n);N_=requestAnimationFrame(()=>{var i=e.getState(),s=mj(i,i.tooltip.settings.shared);if(s==="axis"){var a=Hj(i,r);a?.activeIndex!=null?e.dispatch(tJ({activeIndex:a.activeIndex,activeDataKey:void 0,activeCoordinate:a.activeCoordinate})):e.dispatch(eJ())}N_=null})}});var R9={accessibilityLayer:!0,barCategoryGap:"10%",barGap:4,barSize:void 0,className:void 0,maxBarSize:void 0,stackOffset:"none",syncId:void 0,syncMethod:"index",baseValue:void 0,reverseStackOrder:!1},bee=Zs({name:"rootProps",initialState:R9,reducers:{updateOptions:(t,e)=>{var n;t.accessibilityLayer=e.payload.accessibilityLayer,t.barCategoryGap=e.payload.barCategoryGap,t.barGap=(n=e.payload.barGap)!==null&&n!==void 0?n:R9.barGap,t.barSize=e.payload.barSize,t.maxBarSize=e.payload.maxBarSize,t.stackOffset=e.payload.stackOffset,t.syncId=e.payload.syncId,t.syncMethod=e.payload.syncMethod,t.className=e.payload.className,t.baseValue=e.payload.baseValue,t.reverseStackOrder=e.payload.reverseStackOrder}}}),bVe=bee.reducer,{updateOptions:vVe}=bee.actions,vee=Zs({name:"polarOptions",initialState:null,reducers:{updatePolarOptions:(t,e)=>e.payload}}),{updatePolarOptions:yVe}=vee.actions,_Ve=vee.reducer,yee=so("keyDown"),_ee=so("focus"),Vj=yb();Vj.startListening({actionCreator:yee,effect:(t,e)=>{var n=e.getState(),r=n.rootProps.accessibilityLayer!==!1;if(r){var{keyboardInteraction:i}=n.tooltip,s=t.payload;if(!(s!=="ArrowRight"&&s!=="ArrowLeft"&&s!=="Enter")){var a=gj(i,ig(n),Db(n),Ib(n)),o=a==null?-1:Number(a);if(!(!Number.isFinite(o)||o<0)){var l=Lc(n);if(s==="Enter"){var u=Zw(n,"axis","hover",String(i.index));e.dispatch(zP({active:!i.active,activeIndex:i.index,activeDataKey:i.dataKey,activeCoordinate:u}));return}var d=WUe(n),f=d==="left-to-right"?1:-1,g=s==="ArrowRight"?1:-1,m=o+g*f;if(!(l==null||m>=l.length||m<0)){var x=Zw(n,"axis","hover",String(m));e.dispatch(zP({active:!0,activeIndex:m.toString(),activeDataKey:void 0,activeCoordinate:x}))}}}}}});Vj.startListening({actionCreator:_ee,effect:(t,e)=>{var n=e.getState(),r=n.rootProps.accessibilityLayer!==!1;if(r){var{keyboardInteraction:i}=n.tooltip;if(!i.active&&i.index==null){var s="0",a=Zw(n,"axis","hover",String(s));e.dispatch(zP({activeDataKey:void 0,active:!0,activeIndex:s,activeCoordinate:a}))}}}});var Ia=so("externalEvent"),wee=yb(),zN=new Map;wee.startListening({actionCreator:Ia,effect:(t,e)=>{var{handler:n,reactEvent:r}=t.payload;if(n!=null){r.persist();var i=r.type,s=zN.get(i);s!==void 0&&cancelAnimationFrame(s);var a=requestAnimationFrame(()=>{try{var o=e.getState(),l={activeCoordinate:H5e(o),activeDataKey:_j(o),activeIndex:cd(o),activeLabel:hJ(o),activeTooltipIndex:cd(o),isTooltipActive:$5e(o)};n(l,r)}finally{zN.delete(i)}});zN.set(i,a)}}});var wVe=Ke([rg],t=>t.tooltipItemPayloads),SVe=Ke([wVe,jb,(t,e,n)=>e,(t,e,n)=>n],(t,e,n,r)=>{var i=t.find(o=>o.settings.dataKey===r);if(i!=null){var{positions:s}=i;if(s!=null){var a=e(s,n);return a}}}),See=so("touchMove"),Eee=yb();Eee.startListening({actionCreator:See,effect:(t,e)=>{var n=t.payload;if(!(n.touches==null||n.touches.length===0)){var r=e.getState(),i=mj(r,r.tooltip.settings.shared);if(i==="axis"){var s=Hj(r,$j({clientX:n.touches[0].clientX,clientY:n.touches[0].clientY,currentTarget:n.currentTarget}));s?.activeIndex!=null&&e.dispatch(tJ({activeIndex:s.activeIndex,activeDataKey:void 0,activeCoordinate:s.activeCoordinate}))}else if(i==="item"){var a,o=n.touches[0];if(document.elementFromPoint==null)return;var l=document.elementFromPoint(o.clientX,o.clientY);if(!l||!l.getAttribute)return;var u=l.getAttribute(GY),d=(a=l.getAttribute(WY))!==null&&a!==void 0?a:void 0,f=SVe(e.getState(),u,d);e.dispatch(JQ({activeDataKey:d,activeIndex:u,activeCoordinate:f}))}}}});var EVe=hY({brush:OHe,cartesianAxis:W6e,chartData:BFe,errorBars:d8e,graphicalItems:QBe,layout:pDe,legend:wOe,options:LFe,polarAxis:fBe,polarOptions:_Ve,referenceElements:BHe,rootProps:bVe,tooltip:r5e,zIndex:EFe}),MVe=function(e){return FRe({reducer:EVe,preloadedState:e,middleware:n=>{var r;return n({serializableCheck:!1,immutableCheck:!["commonjs","es6","production"].includes((r="es6")!==null&&r!==void 0?r:"")}).concat([gee.middleware,xee.middleware,Vj.middleware,wee.middleware,Eee.middleware])},enhancers:n=>{var r=n;return typeof n=="function"&&(r=n()),r.concat(TY({type:"raf"}))},devTools:Xm.devToolsEnabled})};function Mee(t){var{preloadedState:e,children:n,reduxStoreName:r}=t,i=ms(),s=M.useRef(null);if(i)return n;s.current==null&&(s.current=MVe(e));var a=nO;return M.createElement(L8e,{context:a,store:s.current},n)}function AVe(t){var{layout:e,margin:n}=t,r=rr(),i=ms();return M.useEffect(()=>{i||(r(dDe(e)),r(uDe(n)))},[r,i,e,n]),null}var Aee=M.memo(AVe,$E);function Tee(t){var e=rr();return M.useEffect(()=>{e(vVe(t))},[e,t]),null}function D9(t){var{zIndex:e,isPanorama:n}=t,r=n?"recharts-zindex-panorama-":"recharts-zindex-",i=GJ("".concat(r).concat(e)),s=rr();return M.useLayoutEffect(()=>(s(wFe({zIndex:e,elementId:i,isPanorama:n})),()=>{s(SFe({zIndex:e,isPanorama:n}))}),[s,e,i,n]),M.createElement("g",{tabIndex:-1,id:i})}function O9(t){var{children:e,isPanorama:n}=t,r=kt(hFe);if(!r||r.length===0)return e;var i=r.filter(a=>a<0),s=r.filter(a=>a>0);return M.createElement(M.Fragment,null,i.map(a=>M.createElement(D9,{key:a,zIndex:a,isPanorama:n})),e,s.map(a=>M.createElement(D9,{key:a,zIndex:a,isPanorama:n})))}var TVe=["children"];function CVe(t,e){if(t==null)return{};var n,r,i=NVe(t,e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(t);for(r=0;r{var n=fO(),r=pO(),i=cZ();if(!pl(n)||!pl(r))return null;var{children:s,otherAttributes:a,title:o,desc:l}=t,u,d;return a!=null&&(typeof a.tabIndex=="number"?u=a.tabIndex:u=i?0:void 0,typeof a.role=="string"?d=a.role:d=i?"application":void 0),M.createElement(WD,oS({},a,{title:o,desc:l,role:d,tabIndex:u,width:n,height:r,style:kVe,ref:e}),s)}),RVe=t=>{var{children:e}=t,n=kt(mE);if(!n)return null;var{width:r,height:i,y:s,x:a}=n;return M.createElement(WD,{width:r,height:i,x:a,y:s},e)},j9=M.forwardRef((t,e)=>{var{children:n}=t,r=CVe(t,TVe),i=ms();return i?M.createElement(RVe,null,M.createElement(O9,{isPanorama:!0},n)):M.createElement(PVe,oS({ref:e},r),M.createElement(O9,{isPanorama:!1},n))});function DVe(){var t=rr(),[e,n]=M.useState(null),r=kt(PDe);return M.useEffect(()=>{if(e!=null){var i=e.getBoundingClientRect(),s=i.width/e.offsetWidth;ur(s)&&s!==r&&t(fDe(s))}},[e,t,r]),n}function L9(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function OVe(t){for(var e=1;e(YFe(),null);function lS(t){if(typeof t=="number")return t;if(typeof t=="string"){var e=parseFloat(t);if(!Number.isNaN(e))return e}return 0}var FVe=M.forwardRef((t,e)=>{var n,r,i=M.useRef(null),[s,a]=M.useState({containerWidth:lS((n=t.style)===null||n===void 0?void 0:n.width),containerHeight:lS((r=t.style)===null||r===void 0?void 0:r.height)}),o=M.useCallback((u,d)=>{a(f=>{var g=Math.round(u),m=Math.round(d);return f.containerWidth===g&&f.containerHeight===m?f:{containerWidth:g,containerHeight:m}})},[]),l=M.useCallback(u=>{if(typeof e=="function"&&e(u),u!=null&&typeof ResizeObserver<"u"){var{width:d,height:f}=u.getBoundingClientRect();o(d,f);var g=x=>{var{width:y,height:v}=x[0].contentRect;o(y,v)},m=new ResizeObserver(g);m.observe(u),i.current=m}},[e,o]);return M.useEffect(()=>()=>{var u=i.current;u?.disconnect()},[o]),M.createElement(M.Fragment,null,M.createElement(xE,{width:s.containerWidth,height:s.containerHeight}),M.createElement("div",Jh({ref:l},t)))}),zVe=M.forwardRef((t,e)=>{var{width:n,height:r}=t,[i,s]=M.useState({containerWidth:lS(n),containerHeight:lS(r)}),a=M.useCallback((l,u)=>{s(d=>{var f=Math.round(l),g=Math.round(u);return d.containerWidth===f&&d.containerHeight===g?d:{containerWidth:f,containerHeight:g}})},[]),o=M.useCallback(l=>{if(typeof e=="function"&&e(l),l!=null){var{width:u,height:d}=l.getBoundingClientRect();a(u,d)}},[e,a]);return M.createElement(M.Fragment,null,M.createElement(xE,{width:i.containerWidth,height:i.containerHeight}),M.createElement("div",Jh({ref:o},t)))}),BVe=M.forwardRef((t,e)=>{var{width:n,height:r}=t;return M.createElement(M.Fragment,null,M.createElement(xE,{width:n,height:r}),M.createElement("div",Jh({ref:e},t)))}),HVe=M.forwardRef((t,e)=>{var{width:n,height:r}=t;return wc(n)||wc(r)?M.createElement(zVe,Jh({},t,{ref:e})):M.createElement(BVe,Jh({},t,{ref:e}))});function $Ve(t){return t===!0?FVe:HVe}var VVe=M.forwardRef((t,e)=>{var{children:n,className:r,height:i,onClick:s,onContextMenu:a,onDoubleClick:o,onMouseDown:l,onMouseEnter:u,onMouseLeave:d,onMouseMove:f,onMouseUp:g,onTouchEnd:m,onTouchMove:x,onTouchStart:y,style:v,width:b,responsive:E,dispatchTouchEvents:S=!0}=t,A=M.useRef(null),T=rr(),[P,C]=M.useState(null),[I,N]=M.useState(null),D=DVe(),F=hO(),L=F?.width>0?F.width:b,q=F?.height>0?F.height:i,R=M.useCallback(se=>{D(se),typeof e=="function"&&e(se),C(se),N(se),se!=null&&(A.current=se)},[D,e,C,N]),V=M.useCallback(se=>{T(mee(se)),T(Ia({handler:s,reactEvent:se}))},[T,s]),K=M.useCallback(se=>{T(QP(se)),T(Ia({handler:u,reactEvent:se}))},[T,u]),W=M.useCallback(se=>{T(eJ()),T(Ia({handler:d,reactEvent:se}))},[T,d]),ne=M.useCallback(se=>{T(QP(se)),T(Ia({handler:f,reactEvent:se}))},[T,f]),Y=M.useCallback(()=>{T(_ee())},[T]),Z=M.useCallback(se=>{T(yee(se.key))},[T]),U=M.useCallback(se=>{T(Ia({handler:a,reactEvent:se}))},[T,a]),$=M.useCallback(se=>{T(Ia({handler:o,reactEvent:se}))},[T,o]),ee=M.useCallback(se=>{T(Ia({handler:l,reactEvent:se}))},[T,l]),ae=M.useCallback(se=>{T(Ia({handler:g,reactEvent:se}))},[T,g]),fe=M.useCallback(se=>{T(Ia({handler:y,reactEvent:se}))},[T,y]),ue=M.useCallback(se=>{S&&T(See(se)),T(Ia({handler:x,reactEvent:se}))},[T,S,x]),xe=M.useCallback(se=>{T(Ia({handler:m,reactEvent:se}))},[T,m]),Me=$Ve(E);return M.createElement(yJ.Provider,{value:P},M.createElement(CX.Provider,{value:I},M.createElement(Me,{width:L??v?.width,height:q??v?.height,className:Tn("recharts-wrapper",r),style:OVe({position:"relative",cursor:"default",width:L,height:q},v),onClick:V,onContextMenu:U,onDoubleClick:$,onFocus:Y,onKeyDown:Z,onMouseDown:ee,onMouseEnter:K,onMouseLeave:W,onMouseMove:ne,onMouseUp:ae,onTouchEnd:xe,onTouchMove:ue,onTouchStart:fe,ref:R},M.createElement(UVe,null),n)))}),GVe=["width","height","responsive","children","className","style","compact","title","desc"];function WVe(t,e){if(t==null)return{};var n,r,i=qVe(t,e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(t);for(r=0;r{var{width:n,height:r,responsive:i,children:s,className:a,style:o,compact:l,title:u,desc:d}=t,f=WVe(t,GVe),g=Ks(f);return l?M.createElement(M.Fragment,null,M.createElement(xE,{width:n,height:r}),M.createElement(j9,{otherAttributes:g,title:u,desc:d},s)):M.createElement(VVe,{className:a,style:o,width:n,height:r,responsive:i??!1,onClick:t.onClick,onMouseLeave:t.onMouseLeave,onMouseEnter:t.onMouseEnter,onMouseMove:t.onMouseMove,onMouseDown:t.onMouseDown,onMouseUp:t.onMouseUp,onContextMenu:t.onContextMenu,onDoubleClick:t.onDoubleClick,onTouchStart:t.onTouchStart,onTouchMove:t.onTouchMove,onTouchEnd:t.onTouchEnd},M.createElement(j9,{otherAttributes:g,title:u,desc:d,ref:e},M.createElement($He,null,s)))});function JP(){return JP=Object.assign?Object.assign.bind():function(t){for(var e=1;eM.createElement(Nee,{chartName:"BarChart",defaultTooltipEventType:"axis",validateTooltipEventTypes:YVe,tooltipPayloadSearcher:Aj,categoricalChartProps:t,ref:e}));function QVe(t){var e=rr();return M.useEffect(()=>{e(yVe(t))},[e,t]),null}var JVe=["layout"];function eR(){return eR=Object.assign?Object.assign.bind():function(t){for(var e=1;e{var n=ii(t,l9e);return M.createElement(r9e,{chartName:"PieChart",defaultTooltipEventType:"item",validateTooltipEventTypes:o9e,tooltipPayloadSearcher:Aj,categoricalChartProps:n,ref:e})}),u9e=["axis"],d9e=M.forwardRef((t,e)=>M.createElement(Nee,{chartName:"AreaChart",defaultTooltipEventType:"axis",validateTooltipEventTypes:u9e,tooltipPayloadSearcher:Aj,categoricalChartProps:t,ref:e}));const k_=["#00ae42","#3b82f6","#f59e0b","#ef4444","#8b5cf6","#ec4899","#14b8a6","#f97316"];function h9e(t){const e=new Date;switch(t){case"7d":return new Date(e.getTime()-10080*60*1e3);case"30d":return new Date(e.getTime()-720*60*60*1e3);case"90d":return new Date(e.getTime()-2160*60*60*1e3);case"365d":return new Date(e.getTime()-365*24*60*60*1e3);case"all":return new Date(0)}}function f9e({archives:t,currency:e="$"}){const[n,r]=M.useState("30d"),i=M.useMemo(()=>{const g=h9e(n);return t.filter(m=>new Date(m.completed_at||m.created_at)>=g)},[t,n]),s=M.useMemo(()=>{const g=new Map;return i.forEach(m=>{const y=new Date(m.completed_at||m.created_at).toISOString().split("T")[0],v=g.get(y)||{date:y,filament:0,cost:0,prints:0};v.filament+=m.filament_used_grams||0,v.cost+=m.cost||0,v.prints+=1,g.set(y,v)}),Array.from(g.values()).sort((m,x)=>m.date.localeCompare(x.date)).map(m=>({...m,dateLabel:new Date(m.date).toLocaleDateString("en-US",{month:"short",day:"numeric"})}))},[i]),a=M.useMemo(()=>{if(n==="7d"||n==="30d")return s;const g=new Map;return i.forEach(m=>{const x=new Date(m.completed_at||m.created_at),y=new Date(x);y.setDate(x.getDate()-x.getDay());const v=y.toISOString().split("T")[0],b=g.get(v)||{week:v,filament:0,cost:0,prints:0};b.filament+=m.filament_used_grams||0,b.cost+=m.cost||0,b.prints+=1,g.set(v,b)}),Array.from(g.values()).sort((m,x)=>m.week.localeCompare(x.week)).map(m=>({date:m.week,dateLabel:`Week of ${new Date(m.week).toLocaleDateString("en-US",{month:"short",day:"numeric"})}`,...m}))},[i,s,n]),o=M.useMemo(()=>{const g=new Map;return i.forEach(m=>{const y=(m.filament_type||"Unknown").split(", ");y.forEach(v=>{const b=(m.filament_used_grams||0)/y.length;g.set(v,(g.get(v)||0)+b)})}),Array.from(g.entries()).map(([m,x])=>({name:m,value:Math.round(x)})).sort((m,x)=>x.value-m.value)},[i]),l=M.useMemo(()=>{const g=new Date,m=[];for(let x=5;x>=0;x--){const y=new Date(g.getFullYear(),g.getMonth()-x,1),v=new Date(g.getFullYear(),g.getMonth()-x+1,0),b=y.toLocaleDateString("en-US",{month:"short",year:"2-digit"}),E=t.filter(S=>{const A=new Date(S.completed_at||S.created_at);return A>=y&&A<=v});m.push({month:b,filament:Math.round(E.reduce((S,A)=>S+(A.filament_used_grams||0),0)),cost:E.reduce((S,A)=>S+(A.cost||0),0),prints:E.length})}return m},[t]),u=n==="7d"||n==="30d"?s:a,d=i.reduce((g,m)=>g+(m.filament_used_grams||0),0),f=i.reduce((g,m)=>g+(m.cost||0),0);return c.jsxs("div",{className:"space-y-6",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("h3",{className:"text-lg font-semibold text-white",children:"Filament Usage Trends"}),c.jsx("div",{className:"flex gap-1 bg-bambu-dark rounded-lg p-1",children:["7d","30d","90d","365d","all"].map(g=>c.jsx("button",{onClick:()=>r(g),className:`px-3 py-1 text-sm rounded-md transition-colors ${n===g?"bg-bambu-green text-white":"text-bambu-gray hover:text-white"}`,children:g==="all"?"All":g.replace("d","D")},g))})]}),c.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[c.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[c.jsx("p",{className:"text-sm text-bambu-gray",children:"Period Filament"}),c.jsxs("p",{className:"text-2xl font-bold text-white",children:[(d/1e3).toFixed(2),"kg"]}),c.jsxs("p",{className:"text-xs text-bambu-gray",children:[d.toFixed(0),"g total"]})]}),c.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[c.jsx("p",{className:"text-sm text-bambu-gray",children:"Period Cost"}),c.jsxs("p",{className:"text-2xl font-bold text-white",children:[e,f.toFixed(2)]}),c.jsxs("p",{className:"text-xs text-bambu-gray",children:[i.length," prints"]})]}),c.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[c.jsx("p",{className:"text-sm text-bambu-gray",children:"Avg per Print"}),c.jsxs("p",{className:"text-2xl font-bold text-white",children:[i.length>0?(d/i.length).toFixed(0):0,"g"]}),c.jsxs("p",{className:"text-xs text-bambu-gray",children:[e,i.length>0?(f/i.length).toFixed(2):"0.00"," avg"]})]})]}),u.length>0?c.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[c.jsx("h4",{className:"text-sm font-medium text-bambu-gray mb-4",children:"Usage Over Time"}),c.jsx(oN,{width:"100%",height:250,children:c.jsxs(d9e,{data:u,children:[c.jsx("defs",{children:c.jsxs("linearGradient",{id:"colorFilament",x1:"0",y1:"0",x2:"0",y2:"1",children:[c.jsx("stop",{offset:"5%",stopColor:"#00ae42",stopOpacity:.3}),c.jsx("stop",{offset:"95%",stopColor:"#00ae42",stopOpacity:0})]})}),c.jsx(qP,{strokeDasharray:"3 3",stroke:"#3d3d3d"}),c.jsx(XP,{dataKey:"dateLabel",stroke:"#9ca3af",tick:{fontSize:12},interval:"preserveStartEnd"}),c.jsx(ZP,{stroke:"#9ca3af",tick:{fontSize:12},tickFormatter:g=>`${g}g`}),c.jsx(MN,{contentStyle:{backgroundColor:"#2d2d2d",border:"1px solid #3d3d3d",borderRadius:"8px"},labelStyle:{color:"#fff"},formatter:g=>[`${g.toFixed(0)}g`,"Filament"]}),c.jsx(fee,{type:"monotone",dataKey:"filament",stroke:"#00ae42",strokeWidth:2,fillOpacity:1,fill:"url(#colorFilament)"})]})})]}):c.jsx("div",{className:"bg-bambu-dark rounded-lg p-8 text-center text-bambu-gray",children:"No data for selected time range"}),c.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[c.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[c.jsx("h4",{className:"text-sm font-medium text-bambu-gray mb-4",children:"By Filament Type"}),o.length>0?c.jsxs("div",{className:"flex items-center gap-4",children:[c.jsx(oN,{width:160,height:160,children:c.jsxs(c9e,{children:[c.jsx(KJ,{data:o,cx:"50%",cy:"50%",innerRadius:40,outerRadius:70,paddingAngle:2,dataKey:"value",children:o.map((g,m)=>c.jsx(Fb,{fill:k_[m%k_.length]},`cell-${m}`))}),c.jsx(MN,{contentStyle:{backgroundColor:"#2d2d2d",border:"1px solid #3d3d3d",borderRadius:"8px"},formatter:g=>[`${g}g`,"Usage"]})]})}),c.jsx("div",{className:"flex-1 space-y-2 overflow-hidden",children:o.map((g,m)=>{const x=o.reduce((v,b)=>v+b.value,0),y=x>0?(g.value/x*100).toFixed(0):0;return c.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[c.jsx("div",{className:"w-3 h-3 rounded-sm flex-shrink-0",style:{backgroundColor:k_[m%k_.length]}}),c.jsx("span",{className:"text-white truncate flex-1",children:g.name}),c.jsxs("span",{className:"text-bambu-gray flex-shrink-0",children:[y,"%"]})]},g.name)})})]}):c.jsx("div",{className:"h-[160px] flex items-center justify-center text-bambu-gray",children:"No filament data"})]}),c.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[c.jsx("h4",{className:"text-sm font-medium text-bambu-gray mb-4",children:"Monthly Comparison"}),c.jsx(oN,{width:"100%",height:200,children:c.jsxs(ZVe,{data:l,children:[c.jsx(qP,{strokeDasharray:"3 3",stroke:"#3d3d3d"}),c.jsx(XP,{dataKey:"month",stroke:"#9ca3af",tick:{fontSize:12}}),c.jsx(ZP,{stroke:"#9ca3af",tick:{fontSize:12},tickFormatter:g=>`${g}g`}),c.jsx(MN,{contentStyle:{backgroundColor:"#2d2d2d",border:"1px solid #3d3d3d",borderRadius:"8px"},formatter:(g,m)=>[m==="filament"?`${g}g`:m==="cost"?`${e}${g.toFixed(2)}`:g,m==="filament"?"Filament":m==="cost"?"Cost":"Prints"]}),c.jsx(lZ,{}),c.jsx(JJ,{dataKey:"filament",name:"Filament (g)",fill:"#00ae42",radius:[4,4,0,0]})]})})]})]})]})}function p9e({id:t,title:e,children:n,isHidden:r,size:i,onToggleVisibility:s,onToggleSize:a}){const{attributes:o,listeners:l,setNodeRef:u,transform:d,transition:f,isDragging:g}=_X({id:t}),m={transform:Sm.Transform.toString(d),transition:f,opacity:g?.5:1};return r?null:c.jsxs("div",{ref:u,style:{...m,gridColumn:`span ${i}`},className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary overflow-hidden ${g?"ring-2 ring-bambu-green shadow-lg":""}`,children:[c.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark/30",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("button",{...o,...l,className:"cursor-grab active:cursor-grabbing p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",title:"Drag to reorder",children:c.jsx(c0,{className:"w-6 h-6 md:w-4 md:h-4 text-bambu-gray"})}),c.jsx("h3",{className:"text-sm font-medium text-white",children:e})]}),c.jsxs("div",{className:"flex items-center gap-1",children:[c.jsx("button",{onClick:a,className:"p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",title:`Size: ${i===1?"1/4":i===2?"1/2":"Full"} - Click to cycle`,children:i===4?c.jsx(Ele,{className:"w-4 h-4 text-bambu-gray hover:text-white"}):c.jsx(ble,{className:"w-4 h-4 text-bambu-gray hover:text-white"})}),c.jsx("button",{onClick:s,className:"p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",title:"Hide widget",children:c.jsx(mR,{className:"w-4 h-4 text-bambu-gray hover:text-white"})})]})]}),c.jsx("div",{className:"p-4",children:n})]})}function m9e({widgets:t,storageKey:e,columns:n=4,hideControls:r=!1,onResetLayout:i}){const s=()=>{const E={};return t.forEach(S=>{E[S.id]=S.defaultSize||4}),E},[a,o]=M.useState(()=>{const E=localStorage.getItem(e);if(E)try{const S=JSON.parse(E);return S.sizes||(S.sizes=s()),S}catch{}return{order:t.map(S=>S.id),hidden:t.filter(S=>S.defaultVisible===!1).map(S=>S.id),sizes:s()}}),[l,u]=M.useState(!1);M.useEffect(()=>{localStorage.setItem(e,JSON.stringify(a))},[a,e]),M.useEffect(()=>{const S=t.map(A=>A.id).filter(A=>!a.order.includes(A));S.length>0&&o(A=>({...A,order:[...A.order,...S]}))},[t,a.order]);const d=JK(fw(YS,{activationConstraint:{distance:8}}),fw(XS,{coordinateGetter:wX})),f=E=>{const{active:S,over:A}=E;A&&S.id!==A.id&&o(T=>{const P=T.order.indexOf(S.id),C=T.order.indexOf(A.id);return{...T,order:JS(T.order,P,C)}})},g=E=>{o(S=>({...S,hidden:S.hidden.includes(E)?S.hidden.filter(A=>A!==E):[...S.hidden,E]}))},m=E=>{o(S=>{const A=S.sizes[E]||4,T=A===1?2:A===2?4:1;return{...S,sizes:{...S.sizes,[E]:T}}})},x=()=>{const E={order:t.map(S=>S.id),hidden:t.filter(S=>S.defaultVisible===!1).map(S=>S.id),sizes:s()};o(E),i?.()},y=a.order.map(E=>t.find(S=>S.id===E)).filter(Boolean),v=y.filter(E=>!a.hidden.includes(E.id)),b=y.filter(E=>a.hidden.includes(E.id));return c.jsxs("div",{className:"space-y-4",children:[!r&&c.jsxs("div",{className:"flex items-center justify-end gap-2",children:[b.length>0&&c.jsxs(Ie,{variant:"secondary",size:"sm",onClick:()=>u(!l),children:[c.jsx(o0,{className:"w-4 h-4"}),b.length," Hidden"]}),c.jsxs(Ie,{variant:"secondary",size:"sm",onClick:x,children:[c.jsx(Im,{className:"w-4 h-4"}),"Reset Layout"]})]}),l&&b.length>0&&c.jsxs("div",{className:"p-4 bg-bambu-dark rounded-xl border border-bambu-dark-tertiary",children:[c.jsx("p",{className:"text-sm text-bambu-gray mb-3",children:"Hidden widgets (click to show):"}),c.jsx("div",{className:"flex flex-wrap gap-2",children:b.map(E=>c.jsxs("button",{onClick:()=>g(E.id),className:"px-3 py-1.5 bg-bambu-dark-tertiary hover:bg-bambu-green/20 rounded-lg text-sm text-white transition-colors flex items-center gap-2",children:[c.jsx(o0,{className:"w-3 h-3"}),E.title]},E.id))})]}),c.jsx(gX,{sensors:d,collisionDetection:rX,onDragEnd:f,children:c.jsx(vX,{items:v.map(E=>E.id),strategy:VD,children:c.jsx("div",{className:"grid gap-6",style:{gridTemplateColumns:`repeat(${n}, minmax(0, 1fr))`},children:v.map(E=>c.jsx(p9e,{id:E.id,title:E.title,isHidden:a.hidden.includes(E.id),size:a.sizes[E.id]||2,onToggleVisibility:()=>g(E.id),onToggleSize:()=>m(E.id),children:E.component},E.id))})})}),v.length===0&&c.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[c.jsx("p",{children:"All widgets are hidden."}),c.jsx(Ie,{className:"mt-4",onClick:x,children:"Reset Layout"})]})]})}function g9e({stats:t,currency:e}){return c.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-4",children:[c.jsxs("div",{className:"flex items-start gap-3",children:[c.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-bambu-green",children:c.jsx(u0,{className:"w-5 h-5"})}),c.jsxs("div",{children:[c.jsx("p",{className:"text-xs text-bambu-gray",children:"Total Prints"}),c.jsx("p",{className:"text-xl font-bold text-white",children:t?.total_prints||0})]})]}),c.jsxs("div",{className:"flex items-start gap-3",children:[c.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-blue-400",children:c.jsx(ti,{className:"w-5 h-5"})}),c.jsxs("div",{children:[c.jsx("p",{className:"text-xs text-bambu-gray",children:"Print Time"}),c.jsxs("p",{className:"text-xl font-bold text-white",children:[t?.total_print_time_hours.toFixed(1)||0,"h"]})]})]}),c.jsxs("div",{className:"flex items-start gap-3",children:[c.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-orange-400",children:c.jsx(u0,{className:"w-5 h-5"})}),c.jsxs("div",{children:[c.jsx("p",{className:"text-xs text-bambu-gray",children:"Filament Used"}),c.jsxs("p",{className:"text-xl font-bold text-white",children:[((t?.total_filament_grams||0)/1e3).toFixed(2),"kg"]})]})]}),c.jsxs("div",{className:"flex items-start gap-3",children:[c.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-green-400",children:c.jsx(a3,{className:"w-5 h-5"})}),c.jsxs("div",{children:[c.jsx("p",{className:"text-xs text-bambu-gray",children:"Filament Cost"}),c.jsxs("p",{className:"text-xl font-bold text-white",children:[e," ",t?.total_cost.toFixed(2)||"0.00"]})]})]}),c.jsxs("div",{className:"flex items-start gap-3",children:[c.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-yellow-400",children:c.jsx(am,{className:"w-5 h-5"})}),c.jsxs("div",{children:[c.jsx("p",{className:"text-xs text-bambu-gray",children:"Energy Used"}),c.jsxs("p",{className:"text-xl font-bold text-white",children:[t?.total_energy_kwh.toFixed(2)||"0.00"," kWh"]})]})]}),c.jsxs("div",{className:"flex items-start gap-3",children:[c.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-yellow-500",children:c.jsx(a3,{className:"w-5 h-5"})}),c.jsxs("div",{children:[c.jsx("p",{className:"text-xs text-bambu-gray",children:"Energy Cost"}),c.jsxs("p",{className:"text-xl font-bold text-white",children:[e," ",t?.total_energy_cost.toFixed(2)||"0.00"]})]})]})]})}function x9e({stats:t}){const e=t?.total_prints?Math.round(t.successful_prints/t.total_prints*100):0;return c.jsxs("div",{className:"flex items-center gap-6",children:[c.jsxs("div",{className:"relative w-28 h-28",children:[c.jsxs("svg",{className:"w-full h-full -rotate-90",children:[c.jsx("circle",{cx:"56",cy:"56",r:"48",fill:"none",stroke:"#3d3d3d",strokeWidth:"10"}),c.jsx("circle",{cx:"56",cy:"56",r:"48",fill:"none",stroke:"#00ae42",strokeWidth:"10",strokeLinecap:"round",strokeDasharray:`${e*3.02} 302`})]}),c.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:c.jsxs("span",{className:"text-xl font-bold text-white",children:[e,"%"]})})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(ds,{className:"w-4 h-4 text-bambu-green"}),c.jsx("span",{className:"text-sm text-bambu-gray",children:"Successful:"}),c.jsx("span",{className:"text-sm text-white font-medium",children:t?.successful_prints||0})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(hd,{className:"w-4 h-4 text-red-400"}),c.jsx("span",{className:"text-sm text-bambu-gray",children:"Failed:"}),c.jsx("span",{className:"text-sm text-white font-medium",children:t?.failed_prints||0})]})]})]})}function b9e({stats:t,printerMap:e}){const n=t?.average_time_accuracy;if(n==null)return c.jsx("div",{className:"flex items-center justify-center h-full",children:c.jsx("p",{className:"text-bambu-gray text-center py-4",children:"No time accuracy data yet"})});const i=(Math.min(150,Math.max(50,n))-50)/100*100,a=(l=>l>=95&&l<=105?"#00ae42":l>105?"#3b82f6":"#f97316")(n),o=n-100;return c.jsxs("div",{className:"flex items-center gap-6",children:[c.jsxs("div",{className:"relative w-28 h-28",children:[c.jsxs("svg",{className:"w-full h-full -rotate-90",children:[c.jsx("circle",{cx:"56",cy:"56",r:"48",fill:"none",stroke:"#3d3d3d",strokeWidth:"10"}),c.jsx("circle",{cx:"56",cy:"56",r:"48",fill:"none",stroke:a,strokeWidth:"10",strokeLinecap:"round",strokeDasharray:`${i*3.02} 302`})]}),c.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[c.jsxs("span",{className:"text-xl font-bold text-white",children:[n.toFixed(0),"%"]}),c.jsxs("span",{className:`text-xs ${o>=0?"text-blue-400":"text-orange-400"}`,children:[o>=0?"+":"",o.toFixed(0),"%"]})]})]}),c.jsxs("div",{className:"space-y-2 flex-1",children:[c.jsxs("div",{className:"flex items-center gap-2 text-xs text-bambu-gray",children:[c.jsx(IG,{className:"w-3 h-3"}),c.jsx("span",{children:"100% = perfect estimate"})]}),t?.time_accuracy_by_printer&&Object.keys(t.time_accuracy_by_printer).length>0&&c.jsx("div",{className:"space-y-1 mt-2",children:Object.entries(t.time_accuracy_by_printer).slice(0,3).map(([l,u])=>c.jsxs("div",{className:"flex items-center justify-between text-xs",children:[c.jsx("span",{className:"text-bambu-gray truncate max-w-[100px]",children:e.get(l)||`Printer ${l}`}),c.jsxs("span",{className:`font-medium ${u>=95&&u<=105?"text-bambu-green":u>105?"text-blue-400":"text-orange-400"}`,children:[u.toFixed(0),"%"]})]},l))})]})]})}function v9e({stats:t}){if(!t?.prints_by_filament_type||Object.keys(t.prints_by_filament_type).length===0)return c.jsx("p",{className:"text-bambu-gray text-center py-4",children:"No filament data available"});const e=Object.entries(t.prints_by_filament_type).sort(([,n],[,r])=>r-n);return c.jsx("div",{className:"space-y-3",children:e.map(([n,r])=>{const i=Math.round(r/(t.total_prints||1)*100);return c.jsxs("div",{children:[c.jsxs("div",{className:"flex justify-between text-sm mb-1",children:[c.jsx("span",{className:"text-white",children:n}),c.jsxs("span",{className:"text-bambu-gray",children:[r," prints"]})]}),c.jsx("div",{className:"h-2 bg-bambu-dark rounded-full",children:c.jsx("div",{className:"h-full bg-bambu-green rounded-full transition-all",style:{width:`${i}%`}})})]},n)})})}function y9e({printDates:t}){return c.jsx(ake,{printDates:t,months:4})}function _9e({stats:t,printerMap:e}){return!t?.prints_by_printer||Object.keys(t.prints_by_printer).length===0?c.jsx("p",{className:"text-bambu-gray text-center py-4",children:"No printer data available"}):c.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:Object.entries(t.prints_by_printer).map(([n,r])=>c.jsxs("div",{className:"flex items-center gap-3 p-3 bg-bambu-dark rounded-lg",children:[c.jsx("div",{className:"p-2 bg-bambu-dark-tertiary rounded-lg",children:c.jsx(jo,{className:"w-4 h-4 text-bambu-green"})}),c.jsxs("div",{children:[c.jsx("p",{className:"text-white font-medium text-sm",children:e.get(n)||`Printer ${n}`}),c.jsxs("p",{className:"text-xs text-bambu-gray",children:[r," prints"]})]})]},n))})}function w9e({archives:t,currency:e}){return!t||t.length===0?c.jsx("p",{className:"text-bambu-gray text-center py-4",children:"No print data available"}):c.jsx(f9e,{archives:t,currency:e})}function S9e(){const{data:t,isLoading:e}=yt({queryKey:["failureAnalysis"],queryFn:()=>Pe.getFailureAnalysis({days:30})});if(e)return c.jsx("div",{className:"flex justify-center py-4",children:c.jsx(At,{className:"w-6 h-6 text-bambu-green animate-spin"})});if(!t||t.total_prints===0)return c.jsx("p",{className:"text-bambu-gray text-center py-4",children:"No print data in the last 30 days"});const n=Object.entries(t.failures_by_reason).sort(([,r],[,i])=>i-r).slice(0,5);return c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center gap-4",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(Qr,{className:`w-5 h-5 ${t.failure_rate>20?"text-red-400":t.failure_rate>10?"text-yellow-400":"text-bambu-green"}`}),c.jsxs("span",{className:"text-2xl font-bold text-white",children:[t.failure_rate.toFixed(1),"%"]}),c.jsx("span",{className:"text-sm text-bambu-gray",children:"failure rate"})]}),c.jsxs("div",{className:"text-sm text-bambu-gray",children:[t.failed_prints," / ",t.total_prints," prints failed"]})]}),n.length>0&&c.jsxs("div",{className:"space-y-2",children:[c.jsx("p",{className:"text-xs text-bambu-gray font-medium",children:"Top Failure Reasons"}),n.map(([r,i])=>c.jsxs("div",{className:"flex items-center justify-between text-sm",children:[c.jsx("span",{className:"text-white truncate max-w-[200px]",children:r||"Unknown"}),c.jsx("span",{className:"text-bambu-gray",children:i})]},r))]}),t.trend&&t.trend.length>=2&&c.jsx("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:c.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[c.jsx(jce,{className:`w-4 h-4 ${t.trend[t.trend.length-1].failure_ratePe.getArchives(void 0,1e3,0)}),{data:f}=yt({queryKey:["settings"],queryFn:Pe.getSettings}),g=async E=>{i(!1),n(!0);try{const{blob:S,filename:A}=await Pe.exportStats({format:E,days:90}),T=URL.createObjectURL(S),P=document.createElement("a");P.href=T,P.download=A,P.click(),URL.revokeObjectURL(T),t("Export downloaded")}catch{t("Export failed","error")}finally{n(!1)}},m=f?.currency||"$",x=new Map(u?.map(E=>[String(E.id),E.name])||[]),y=d?.map(E=>E.created_at)||[];if(l)return c.jsx("div",{className:"p-4 md:p-8",children:c.jsx("div",{className:"text-center py-12 text-bambu-gray",children:"Loading statistics..."})});const v=[{id:"quick-stats",title:"Quick Stats",component:c.jsx(g9e,{stats:o,currency:m}),defaultSize:2},{id:"success-rate",title:"Success Rate",component:c.jsx(x9e,{stats:o}),defaultSize:1},{id:"time-accuracy",title:"Time Accuracy",component:c.jsx(b9e,{stats:o,printerMap:x}),defaultSize:1},{id:"filament-types",title:"Filament Types",component:c.jsx(v9e,{stats:o}),defaultSize:1},{id:"failure-analysis",title:"Failure Analysis (30 days)",component:c.jsx(S9e,{}),defaultSize:1},{id:"print-activity",title:"Print Activity",component:c.jsx(y9e,{printDates:y}),defaultSize:2},{id:"prints-by-printer",title:"Prints by Printer",component:c.jsx(_9e,{stats:o,printerMap:x}),defaultSize:2},{id:"filament-trends",title:"Filament Usage Trends",component:c.jsx(w9e,{archives:d||[],currency:m}),defaultSize:4}],b=()=>{localStorage.removeItem("bambusy-dashboard-layout"),a(E=>E+1),t("Layout reset")};return c.jsxs("div",{className:"p-4 md:p-8",children:[c.jsxs("div",{className:"flex items-center justify-between mb-6",children:[c.jsxs("div",{children:[c.jsx("h1",{className:"text-2xl font-bold text-white",children:"Dashboard"}),c.jsx("p",{className:"text-bambu-gray",children:"Drag widgets to rearrange. Click the eye icon to hide."})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs(Ie,{variant:"secondary",onClick:b,children:[c.jsx(Im,{className:"w-4 h-4"}),"Reset Layout"]}),c.jsxs("div",{className:"relative",children:[c.jsxs(Ie,{variant:"secondary",onClick:()=>i(!r),disabled:e,children:[e?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(o1,{className:"w-4 h-4"}),"Export Stats"]}),r&&c.jsxs("div",{className:"absolute right-0 top-full mt-1 w-48 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20",children:[c.jsxs("button",{className:"w-full px-4 py-2 text-left text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center gap-2 rounded-t-lg",onClick:()=>g("csv"),children:[c.jsx(Ya,{className:"w-4 h-4"}),"Export as CSV"]}),c.jsxs("button",{className:"w-full px-4 py-2 text-left text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center gap-2 rounded-b-lg",onClick:()=>g("xlsx"),children:[c.jsx(o1,{className:"w-4 h-4"}),"Export as Excel"]})]})]})]})]}),c.jsx(m9e,{widgets:v,storageKey:"bambusy-dashboard-layout",hideControls:!0},s)]})}function M9e({plug:t,onEdit:e}){const n=Sn(),[r,i]=M.useState(!1),[s,a]=M.useState(!1),[o,l]=M.useState(!1),[u,d]=M.useState(!1),{data:f,isLoading:g,refetch:m}=yt({queryKey:["smart-plug-status",t.id],queryFn:()=>Pe.getSmartPlugStatus(t.id),refetchInterval:3e4}),{data:x}=yt({queryKey:["printers"],queryFn:Pe.getPrinters}),y=x?.find(P=>P.id===t.printer_id),v=_t({mutationFn:P=>Pe.controlSmartPlug(t.id,P),onSuccess:()=>{m()}}),b=_t({mutationFn:P=>Pe.updateSmartPlug(t.id,P),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),t.printer_id&&n.invalidateQueries({queryKey:["smartPlugByPrinter",t.printer_id]})}}),E=_t({mutationFn:()=>Pe.deleteSmartPlug(t.id),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]})}}),S=f?.state==="ON",A=f?.reachable??!1,T=v.isPending;return c.jsxs(c.Fragment,{children:[c.jsx(Nt,{className:"relative",children:c.jsxs(Dt,{className:"p-4",children:[c.jsxs("div",{className:"flex items-start justify-between mb-3",children:[c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("div",{className:`p-2 rounded-lg ${A?S?"bg-bambu-green/20":"bg-bambu-dark":"bg-red-500/20"}`,children:c.jsx(Ox,{className:`w-5 h-5 ${A?S?"text-bambu-green":"text-bambu-gray":"text-red-400"}`})}),c.jsxs("div",{children:[c.jsx("h3",{className:"font-medium text-white",children:t.name}),c.jsx("p",{className:"text-sm text-bambu-gray",children:t.ip_address})]})]}),c.jsx("div",{className:"flex items-center gap-2",children:g?c.jsx(At,{className:"w-4 h-4 text-bambu-gray animate-spin"}):A?c.jsxs("div",{className:"flex items-center gap-1 text-sm",children:[c.jsx(BG,{className:"w-4 h-4 text-bambu-green"}),c.jsx("span",{className:S?"text-bambu-green":"text-bambu-gray",children:f?.state||"Unknown"})]}):c.jsxs("div",{className:"flex items-center gap-1 text-sm text-red-400",children:[c.jsx(SR,{className:"w-4 h-4"}),c.jsx("span",{children:"Offline"})]})})]}),y&&c.jsxs("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:[c.jsx("span",{className:"text-xs text-bambu-gray",children:"Linked to: "}),c.jsx("span",{className:"text-sm text-white",children:y.name})]}),(t.power_alert_enabled||t.schedule_enabled)&&c.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-3",children:[t.power_alert_enabled&&c.jsxs("span",{className:"flex items-center gap-1 px-2 py-0.5 bg-yellow-500/20 text-yellow-400 text-xs rounded-full",children:[c.jsx(fh,{className:"w-3 h-3"}),"Alerts"]}),t.schedule_enabled&&c.jsxs("span",{className:"flex items-center gap-1 px-2 py-0.5 bg-blue-500/20 text-blue-400 text-xs rounded-full",children:[c.jsx(qr,{className:"w-3 h-3"}),t.schedule_on_time&&t.schedule_off_time?`${t.schedule_on_time} - ${t.schedule_off_time}`:t.schedule_on_time?`On ${t.schedule_on_time}`:`Off ${t.schedule_off_time}`]})]}),c.jsxs("div",{className:"flex gap-2 mb-3",children:[c.jsxs(Ie,{size:"sm",variant:S?"primary":"secondary",disabled:!A||T,onClick:()=>a(!0),className:"flex-1",children:[T?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(fd,{className:"w-4 h-4"}),"On"]}),c.jsxs(Ie,{size:"sm",variant:S?"secondary":"primary",disabled:!A||T,onClick:()=>l(!0),className:"flex-1",children:[T?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(yR,{className:"w-4 h-4"}),"Off"]})]}),c.jsxs("button",{onClick:()=>d(!u),className:"w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors",children:[c.jsxs("span",{className:"flex items-center gap-2",children:[c.jsx(vS,{className:"w-4 h-4"}),"Automation Settings"]}),c.jsx("span",{children:u?"-":"+"})]}),u&&c.jsxs("div",{className:"pt-3 border-t border-bambu-dark-tertiary space-y-4",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-sm text-white",children:"Enabled"}),c.jsx("p",{className:"text-xs text-bambu-gray",children:"Enable automation for this plug"})]}),c.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[c.jsx("input",{type:"checkbox",checked:t.enabled,onChange:P=>b.mutate({enabled:P.target.checked}),className:"sr-only peer"}),c.jsx("div",{className:"w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-sm text-white",children:"Auto On"}),c.jsx("p",{className:"text-xs text-bambu-gray",children:"Turn on when print starts"})]}),c.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[c.jsx("input",{type:"checkbox",checked:t.auto_on,onChange:P=>b.mutate({auto_on:P.target.checked}),className:"sr-only peer"}),c.jsx("div",{className:"w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-sm text-white",children:"Auto Off"}),c.jsx("p",{className:"text-xs text-bambu-gray",children:"Turn off when print completes (one-shot)"})]}),c.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[c.jsx("input",{type:"checkbox",checked:t.auto_off,onChange:P=>b.mutate({auto_off:P.target.checked}),className:"sr-only peer"}),c.jsx("div",{className:"w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),t.auto_off&&c.jsxs("div",{className:"space-y-3 pl-4 border-l-2 border-bambu-dark-tertiary",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-sm text-white mb-2",children:"Turn Off Delay Mode"}),c.jsxs("div",{className:"flex gap-2",children:[c.jsxs("button",{onClick:()=>b.mutate({off_delay_mode:"time"}),className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-sm transition-colors ${t.off_delay_mode==="time"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:[c.jsx(ti,{className:"w-4 h-4"}),"Time"]}),c.jsxs("button",{onClick:()=>b.mutate({off_delay_mode:"temperature"}),className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-sm transition-colors ${t.off_delay_mode==="temperature"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:[c.jsx($p,{className:"w-4 h-4"}),"Temp"]})]})]}),t.off_delay_mode==="time"?c.jsxs("div",{children:[c.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Delay (minutes)"}),c.jsx("input",{type:"number",min:"1",max:"60",value:t.off_delay_minutes,onChange:P=>b.mutate({off_delay_minutes:parseInt(P.target.value)||5}),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none"})]}):c.jsxs("div",{children:[c.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Temperature threshold (C)"}),c.jsx("input",{type:"number",min:"30",max:"100",value:t.off_temp_threshold,onChange:P=>b.mutate({off_temp_threshold:parseInt(P.target.value)||70}),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none"}),c.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Turns off when nozzle cools below this temperature"})]})]}),c.jsxs("div",{className:"flex gap-2 pt-2",children:[c.jsxs(Ie,{size:"sm",variant:"secondary",onClick:()=>e(t),className:"flex-1",children:[c.jsx(vR,{className:"w-4 h-4"}),"Edit"]}),c.jsx(Ie,{size:"sm",variant:"secondary",onClick:()=>i(!0),className:"text-red-400 hover:text-red-300",children:c.jsx(kn,{className:"w-4 h-4"})})]})]})]})}),r&&c.jsx(Kr,{title:"Delete Smart Plug",message:`Are you sure you want to delete "${t.name}"? This cannot be undone.`,confirmText:"Delete",variant:"danger",onConfirm:()=>{E.mutate(),i(!1)},onCancel:()=>i(!1)}),s&&c.jsx(Kr,{title:"Turn On Smart Plug",message:`Are you sure you want to turn on "${t.name}"?`,confirmText:"Turn On",variant:"default",onConfirm:()=>{v.mutate("on"),a(!1)},onCancel:()=>a(!1)}),o&&c.jsx(Kr,{title:"Turn Off Smart Plug",message:`Are you sure you want to turn off "${t.name}"? This will cut power to the connected device.`,confirmText:"Turn Off",variant:"danger",onConfirm:()=>{v.mutate("off"),l(!1)},onCancel:()=>l(!1)})]})}function A9e({plug:t,onClose:e}){const n=Sn(),r=!!t,[i,s]=M.useState(t?.name||""),[a,o]=M.useState(t?.ip_address||""),[l,u]=M.useState(t?.username||""),[d,f]=M.useState(t?.password||""),[g,m]=M.useState(t?.printer_id||null),[x,y]=M.useState(null),[v,b]=M.useState(null),[E,S]=M.useState(t?.power_alert_enabled||!1),[A,T]=M.useState(t?.power_alert_high?.toString()||""),[P,C]=M.useState(t?.power_alert_low?.toString()||""),[I,N]=M.useState(t?.schedule_enabled||!1),[D,F]=M.useState(t?.schedule_on_time||""),[L,q]=M.useState(t?.schedule_off_time||""),{data:R}=yt({queryKey:["printers"],queryFn:Pe.getPrinters}),{data:V}=yt({queryKey:["smart-plugs"],queryFn:Pe.getSmartPlugs});M.useEffect(()=>{const $=ee=>{ee.key==="Escape"&&e()};return window.addEventListener("keydown",$),()=>window.removeEventListener("keydown",$)},[e]);const K=_t({mutationFn:()=>Pe.testSmartPlugConnection(a,l||null,d||null),onSuccess:$=>{y($),b(null),!i&&$.device_name&&s($.device_name)},onError:$=>{y(null),b($.message)}}),W=_t({mutationFn:$=>Pe.createSmartPlug($),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),e()},onError:$=>{b($.message)}}),ne=_t({mutationFn:$=>Pe.updateSmartPlug(t.id,$),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),e()},onError:$=>{b($.message)}}),Y=R?.filter($=>!V?.some(ae=>ae.printer_id===$.id&&ae.id!==t?.id)),Z=$=>{if($.preventDefault(),b(null),!i.trim()){b("Name is required");return}if(!a.trim()){b("IP address is required");return}const ee={name:i.trim(),ip_address:a.trim(),username:l.trim()||null,password:d.trim()||null,printer_id:g,power_alert_enabled:E,power_alert_high:A?parseFloat(A):null,power_alert_low:P?parseFloat(P):null,schedule_enabled:I,schedule_on_time:D||null,schedule_off_time:L||null};r?ne.mutate(ee):W.mutate(ee)},U=W.isPending||ne.isPending;return c.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:e,children:c.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-md",onClick:$=>$.stopPropagation(),children:[c.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[c.jsx("h2",{className:"text-lg font-semibold text-white",children:r?"Edit Smart Plug":"Add Smart Plug"}),c.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:c.jsx(Gt,{className:"w-5 h-5"})})]}),c.jsxs("form",{onSubmit:Z,className:"p-6 space-y-4",children:[v&&c.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:v}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"IP Address *"}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx("input",{type:"text",value:a,onChange:$=>{o($.target.value),y(null)},placeholder:"192.168.1.100",className:"flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),c.jsxs(Ie,{type:"button",variant:"secondary",onClick:()=>K.mutate(),disabled:!a.trim()||K.isPending,children:[K.isPending?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(BG,{className:"w-4 h-4"}),"Test"]})]})]}),x&&c.jsx("div",{className:`p-3 rounded-lg flex items-center gap-2 ${x.success?"bg-bambu-green/20 border border-bambu-green/50 text-bambu-green":"bg-red-500/20 border border-red-500/50 text-red-400"}`,children:x.success?c.jsxs(c.Fragment,{children:[c.jsx(ds,{className:"w-5 h-5"}),c.jsxs("div",{children:[c.jsx("p",{className:"font-medium",children:"Connected!"}),c.jsxs("p",{className:"text-sm opacity-80",children:[x.device_name&&`Device: ${x.device_name} - `,"State: ",x.state]})]})]}):c.jsxs(c.Fragment,{children:[c.jsx(SR,{className:"w-5 h-5"}),c.jsx("span",{children:"Connection failed"})]})}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name *"}),c.jsx("input",{type:"text",value:i,onChange:$=>s($.target.value),placeholder:"Living Room Plug",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),c.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Username"}),c.jsx("input",{type:"text",value:l,onChange:$=>u($.target.value),placeholder:"admin",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Password"}),c.jsx("input",{type:"password",value:d,onChange:$=>f($.target.value),placeholder:"********",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]})]}),c.jsx("p",{className:"text-xs text-bambu-gray -mt-2",children:"Leave empty if your Tasmota device doesn't require authentication"}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Link to Printer"}),c.jsxs("select",{value:g??"",onChange:$=>m($.target.value?Number($.target.value):null),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[c.jsx("option",{value:"",children:"No printer (manual control only)"}),Y?.map($=>c.jsx("option",{value:$.id,children:$.name},$.id))]}),c.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Linking enables automatic on/off when prints start/complete"})]}),c.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:[c.jsxs("div",{className:"flex items-center justify-between mb-3",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(fh,{className:"w-4 h-4 text-bambu-green"}),c.jsx("span",{className:"text-white font-medium",children:"Power Alerts"})]}),c.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[c.jsx("input",{type:"checkbox",checked:E,onChange:$=>S($.target.checked),className:"sr-only peer"}),c.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),E&&c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Alert if above (W)"}),c.jsx("input",{type:"number",value:A,onChange:$=>T($.target.value),placeholder:"e.g. 200",min:"0",max:"5000",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Alert if below (W)"}),c.jsx("input",{type:"number",value:P,onChange:$=>C($.target.value),placeholder:"e.g. 10",min:"0",max:"5000",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]})]}),c.jsx("p",{className:"text-xs text-bambu-gray",children:"Get notified when power consumption crosses these thresholds. Leave empty to disable that direction."})]})]}),c.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:[c.jsxs("div",{className:"flex items-center justify-between mb-3",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(ti,{className:"w-4 h-4 text-bambu-green"}),c.jsx("span",{className:"text-white font-medium",children:"Daily Schedule"})]}),c.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[c.jsx("input",{type:"checkbox",checked:I,onChange:$=>N($.target.checked),className:"sr-only peer"}),c.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),I&&c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Turn On at"}),c.jsx("input",{type:"time",value:D,onChange:$=>F($.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Turn Off at"}),c.jsx("input",{type:"time",value:L,onChange:$=>q($.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]})]}),c.jsx("p",{className:"text-xs text-bambu-gray",children:"Automatically turn the plug on/off at these times daily. Leave empty to skip that action."})]})]}),c.jsxs("div",{className:"flex gap-3 pt-2",children:[c.jsx(Ie,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:"Cancel"}),c.jsxs(Ie,{type:"submit",disabled:U,className:"flex-1",children:[U?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(To,{className:"w-4 h-4"}),r?"Save":"Add"]})]})]})]})})}function Zn({checked:t,onChange:e,disabled:n}){const r=i=>{i.preventDefault(),i.stopPropagation(),n||e(!t)};return c.jsx("button",{type:"button",role:"switch","aria-checked":t,disabled:n,onClick:r,className:`relative inline-flex w-11 h-7 md:w-9 md:h-5 rounded-full transition-colors flex-shrink-0 focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${n?"bg-bambu-dark-tertiary/50 cursor-not-allowed opacity-50":t?"bg-bambu-green cursor-pointer":"bg-bambu-dark-tertiary cursor-pointer hover:bg-bambu-dark-tertiary/80"}`,children:c.jsx("span",{className:`pointer-events-none absolute top-[3px] md:top-[2px] left-[3px] md:left-[2px] w-5 h-5 md:w-4 md:h-4 bg-white rounded-full shadow transition-transform duration-200 ease-in-out ${t?"translate-x-4":"translate-x-0"}`})})}const T9e={callmebot:"CallMeBot/WhatsApp",ntfy:"ntfy",pushover:"Pushover",telegram:"Telegram",email:"Email",discord:"Discord",webhook:"Webhook"};function C9e({provider:t,onEdit:e}){const n=Sn(),[r,i]=M.useState(!1),[s,a]=M.useState(!1),[o,l]=M.useState(null),{data:u}=yt({queryKey:["printers"],queryFn:Pe.getPrinters}),d=u?.find(y=>y.id===t.printer_id),f=_t({mutationFn:y=>Pe.updateNotificationProvider(t.id,y),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-providers"]})}}),g=_t({mutationFn:()=>Pe.deleteNotificationProvider(t.id),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-providers"]})}}),m=_t({mutationFn:()=>Pe.testNotificationProvider(t.id),onSuccess:y=>{l(y),n.invalidateQueries({queryKey:["notification-providers"]})},onError:y=>{l({success:!1,message:y.message})}}),x=y=>y||"";return c.jsxs(c.Fragment,{children:[c.jsx(Nt,{className:"relative",children:c.jsxs(Dt,{className:"p-4",children:[c.jsxs("div",{className:"flex items-start justify-between mb-3",children:[c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("div",{className:`p-2 rounded-lg ${t.enabled?"bg-bambu-green/20":"bg-bambu-dark"}`,children:c.jsx(fh,{className:`w-5 h-5 ${t.enabled?"text-bambu-green":"text-bambu-gray"}`})}),c.jsxs("div",{children:[c.jsx("h3",{className:"font-medium text-white",children:t.name}),c.jsx("p",{className:"text-sm text-bambu-gray",children:T9e[t.provider_type]||t.provider_type})]})]}),c.jsxs("div",{className:"flex items-center gap-3",children:[t.last_success&&c.jsxs("span",{className:"text-xs text-bambu-green hidden sm:inline",children:["Last: ",new Date(t.last_success).toLocaleDateString()]}),t.last_error&&t.last_error_at&&(!t.last_success||new Date(t.last_error_at)>new Date(t.last_success))&&c.jsx("span",{className:"text-xs text-red-400",title:t.last_error,children:"Error"}),c.jsx(Zn,{checked:t.enabled,onChange:y=>f.mutate({enabled:y})})]})]}),d&&c.jsxs("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:[c.jsx("span",{className:"text-xs text-bambu-gray",children:"Printer: "}),c.jsx("span",{className:"text-sm text-white",children:d.name})]}),!d&&!t.printer_id&&c.jsx("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:c.jsx("span",{className:"text-xs text-bambu-gray",children:"All printers"})}),c.jsxs("div",{className:"mb-3 flex flex-wrap gap-1",children:[t.on_print_start&&c.jsx("span",{className:"px-2 py-0.5 bg-blue-500/20 text-blue-400 text-xs rounded",children:"Start"}),t.on_print_complete&&c.jsx("span",{className:"px-2 py-0.5 bg-bambu-green/20 text-bambu-green text-xs rounded",children:"Complete"}),t.on_print_failed&&c.jsx("span",{className:"px-2 py-0.5 bg-red-500/20 text-red-400 text-xs rounded",children:"Failed"}),t.on_print_stopped&&c.jsx("span",{className:"px-2 py-0.5 bg-orange-500/20 text-orange-400 text-xs rounded",children:"Stopped"}),t.on_print_progress&&c.jsx("span",{className:"px-2 py-0.5 bg-yellow-500/20 text-yellow-400 text-xs rounded",children:"Progress"}),t.on_printer_offline&&c.jsx("span",{className:"px-2 py-0.5 bg-gray-500/20 text-gray-400 text-xs rounded",children:"Offline"}),t.on_printer_error&&c.jsx("span",{className:"px-2 py-0.5 bg-rose-500/20 text-rose-400 text-xs rounded",children:"Error"}),t.on_filament_low&&c.jsx("span",{className:"px-2 py-0.5 bg-cyan-500/20 text-cyan-400 text-xs rounded",children:"Low Filament"}),t.on_maintenance_due&&c.jsx("span",{className:"px-2 py-0.5 bg-purple-500/20 text-purple-400 text-xs rounded",children:"Maintenance"}),t.quiet_hours_enabled&&c.jsxs("span",{className:"px-2 py-0.5 bg-indigo-500/20 text-indigo-400 text-xs rounded flex items-center gap-1",children:[c.jsx(l1,{className:"w-3 h-3"}),"Quiet"]}),t.daily_digest_enabled&&c.jsxs("span",{className:"px-2 py-0.5 bg-emerald-500/20 text-emerald-400 text-xs rounded flex items-center gap-1",children:[c.jsx(qr,{className:"w-3 h-3"}),"Digest ",t.daily_digest_time]})]}),c.jsx("div",{className:"mb-3",children:c.jsxs(Ie,{size:"sm",variant:"secondary",disabled:m.isPending,onClick:()=>{l(null),m.mutate()},className:"w-full",children:[m.isPending?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(_R,{className:"w-4 h-4"}),"Send Test Notification"]})}),o&&c.jsxs("div",{className:`mb-3 p-2 rounded-lg flex items-center gap-2 text-sm ${o.success?"bg-bambu-green/20 text-bambu-green":"bg-red-500/20 text-red-400"}`,children:[o.success?c.jsx(ds,{className:"w-4 h-4"}):c.jsx(hd,{className:"w-4 h-4"}),c.jsx("span",{children:o.message})]}),c.jsxs("button",{onClick:()=>a(!s),className:"w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors border-t border-bambu-dark-tertiary",children:[c.jsxs("span",{className:"flex items-center gap-2",children:[c.jsx(vS,{className:"w-4 h-4"}),"Event Settings"]}),s?c.jsx(mS,{className:"w-4 h-4"}):c.jsx(ef,{className:"w-4 h-4"})]}),s&&c.jsxs("div",{className:"pt-3 border-t border-bambu-dark-tertiary space-y-4",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-sm text-white",children:"Enabled"}),c.jsx("p",{className:"text-xs text-bambu-gray",children:"Send notifications from this provider"})]}),c.jsx(Zn,{checked:t.enabled,onChange:y=>f.mutate({enabled:y})})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:"Print Events"}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("p",{className:"text-sm text-white",children:"Print Started"}),c.jsx(Zn,{checked:t.on_print_start,onChange:y=>f.mutate({on_print_start:y})})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("p",{className:"text-sm text-white",children:"Print Completed"}),c.jsx(Zn,{checked:t.on_print_complete,onChange:y=>f.mutate({on_print_complete:y})})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("p",{className:"text-sm text-white",children:"Print Failed"}),c.jsx(Zn,{checked:t.on_print_failed,onChange:y=>f.mutate({on_print_failed:y})})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("p",{className:"text-sm text-white",children:"Print Stopped"}),c.jsx(Zn,{checked:t.on_print_stopped,onChange:y=>f.mutate({on_print_stopped:y})})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-sm text-white",children:"Progress Milestones"}),c.jsx("p",{className:"text-xs text-bambu-gray",children:"Notify at 25%, 50%, 75%"})]}),c.jsx(Zn,{checked:t.on_print_progress,onChange:y=>f.mutate({on_print_progress:y})})]})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:"Printer Status"}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("p",{className:"text-sm text-white",children:"Printer Offline"}),c.jsx(Zn,{checked:t.on_printer_offline,onChange:y=>f.mutate({on_printer_offline:y})})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("p",{className:"text-sm text-white",children:"Printer Error"}),c.jsx(Zn,{checked:t.on_printer_error,onChange:y=>f.mutate({on_printer_error:y})})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("p",{className:"text-sm text-white",children:"Low Filament"}),c.jsx(Zn,{checked:t.on_filament_low,onChange:y=>f.mutate({on_filament_low:y})})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-sm text-white",children:"Maintenance Due"}),c.jsx("p",{className:"text-xs text-bambu-gray",children:"Notify when maintenance is needed"})]}),c.jsx(Zn,{checked:t.on_maintenance_due??!1,onChange:y=>f.mutate({on_maintenance_due:y})})]})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(l1,{className:"w-4 h-4 text-purple-400"}),c.jsx("p",{className:"text-sm text-white",children:"Quiet Hours"})]}),c.jsx(Zn,{checked:t.quiet_hours_enabled,onChange:y=>f.mutate({quiet_hours_enabled:y})})]}),t.quiet_hours_enabled&&c.jsxs("div",{className:"pl-4 border-l-2 border-bambu-dark-tertiary space-y-2",children:[c.jsx("p",{className:"text-xs text-bambu-gray",children:"No notifications during these hours"}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(ti,{className:"w-4 h-4 text-bambu-gray"}),c.jsxs("span",{className:"text-sm text-white",children:[x(t.quiet_hours_start)||"22:00"," - ",x(t.quiet_hours_end)||"07:00"]})]}),c.jsx("p",{className:"text-xs text-bambu-gray",children:"Edit provider to change quiet hours"})]})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(qr,{className:"w-4 h-4 text-emerald-400"}),c.jsx("p",{className:"text-sm text-white",children:"Daily Digest"})]}),c.jsx(Zn,{checked:t.daily_digest_enabled,onChange:y=>f.mutate({daily_digest_enabled:y})})]}),t.daily_digest_enabled&&c.jsxs("div",{className:"pl-4 border-l-2 border-bambu-dark-tertiary space-y-2",children:[c.jsx("p",{className:"text-xs text-bambu-gray",children:"Batch notifications into a single daily summary"}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(ti,{className:"w-4 h-4 text-bambu-gray"}),c.jsxs("span",{className:"text-sm text-white",children:["Send at ",x(t.daily_digest_time)||"08:00"]})]}),c.jsx("p",{className:"text-xs text-bambu-gray",children:"Edit provider to change digest time"})]})]}),c.jsxs("div",{className:"flex gap-2 pt-2",children:[c.jsxs(Ie,{size:"sm",variant:"secondary",onClick:()=>e(t),className:"flex-1",children:[c.jsx(vR,{className:"w-4 h-4"}),"Edit"]}),c.jsx(Ie,{size:"sm",variant:"secondary",onClick:()=>i(!0),className:"text-red-400 hover:text-red-300",children:c.jsx(kn,{className:"w-4 h-4"})})]})]})]})}),r&&c.jsx(Kr,{title:"Delete Notification Provider",message:`Are you sure you want to delete "${t.name}"? This cannot be undone.`,confirmText:"Delete",variant:"danger",onConfirm:()=>{g.mutate(),i(!1)},onCancel:()=>i(!1)})]})}const F9=[{value:"discord",label:"Discord",description:"Send to Discord channel via webhook"},{value:"telegram",label:"Telegram",description:"Notifications via Telegram bot"},{value:"ntfy",label:"ntfy",description:"Free, self-hostable push notifications"},{value:"pushover",label:"Pushover",description:"Simple, reliable push notifications"},{value:"email",label:"Email",description:"SMTP email notifications"},{value:"callmebot",label:"CallMeBot/WhatsApp",description:"Free WhatsApp notifications via CallMeBot"},{value:"webhook",label:"Webhook",description:"Generic HTTP POST to any URL"}];function N9e({provider:t,onClose:e}){const n=Sn(),r=!!t,[i,s]=M.useState(t?.name||""),[a,o]=M.useState(t?.provider_type||"discord"),[l,u]=M.useState(t?.printer_id||null),[d,f]=M.useState(t?.quiet_hours_enabled||!1),[g,m]=M.useState(t?.quiet_hours_start||"22:00"),[x,y]=M.useState(t?.quiet_hours_end||"07:00"),[v,b]=M.useState(t?.daily_digest_enabled||!1),[E,S]=M.useState(t?.daily_digest_time||"08:00"),[A,T]=M.useState(t?.on_print_start??!1),[P,C]=M.useState(t?.on_print_complete??!0),[I,N]=M.useState(t?.on_print_failed??!0),[D,F]=M.useState(t?.on_print_stopped??!0),[L,q]=M.useState(t?.on_print_progress??!1),[R,V]=M.useState(t?.on_printer_offline??!1),[K,W]=M.useState(t?.on_printer_error??!1),[ne,Y]=M.useState(t?.on_filament_low??!1),[Z,U]=M.useState(t?.on_maintenance_due??!1),[$,ee]=M.useState(t?.config?Object.fromEntries(Object.entries(t.config).map(([G,J])=>[G,String(J)])):{}),[ae,fe]=M.useState(null),[ue,xe]=M.useState(null),{data:Me}=yt({queryKey:["printers"],queryFn:Pe.getPrinters});M.useEffect(()=>{const G=J=>{J.key==="Escape"&&e()};return window.addEventListener("keydown",G),()=>window.removeEventListener("keydown",G)},[e]);const se=_t({mutationFn:()=>Pe.testNotificationConfig({provider_type:a,config:$}),onSuccess:G=>{fe(G),xe(null)},onError:G=>{fe({success:!1,message:G.message})}}),ve=_t({mutationFn:G=>Pe.createNotificationProvider(G),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-providers"]}),e()},onError:G=>{xe(G.message)}}),je=_t({mutationFn:G=>Pe.updateNotificationProvider(t.id,G),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-providers"]}),e()},onError:G=>{xe(G.message)}}),de=G=>{if(G.preventDefault(),xe(null),!i.trim()){xe("Name is required");return}const J=z(a);for(const ke of J)if(!$[ke.key]?.trim()){xe(`${ke.label} is required`);return}const le={name:i.trim(),provider_type:a,config:$,printer_id:l,quiet_hours_enabled:d,quiet_hours_start:d?g:null,quiet_hours_end:d?x:null,daily_digest_enabled:v,daily_digest_time:v?E:null,on_print_start:A,on_print_complete:P,on_print_failed:I,on_print_stopped:D,on_print_progress:L,on_printer_offline:R,on_printer_error:K,on_filament_low:ne,on_maintenance_due:Z};r?je.mutate(le):ve.mutate(le)},ut=ve.isPending||je.isPending,H=G=>{switch(G){case"callmebot":return[{key:"phone",label:"Phone Number",placeholder:"+1234567890",type:"text",required:!0},{key:"apikey",label:"API Key",placeholder:"Your CallMeBot API key",type:"text",required:!0}];case"ntfy":return[{key:"server",label:"Server URL",placeholder:"https://ntfy.sh",type:"text",required:!1},{key:"topic",label:"Topic",placeholder:"my-bambuddy",type:"text",required:!0},{key:"auth_token",label:"Auth Token",placeholder:"Optional authentication",type:"password",required:!1}];case"pushover":return[{key:"user_key",label:"User Key",placeholder:"Your Pushover user key",type:"text",required:!0},{key:"app_token",label:"App Token",placeholder:"Your Pushover app token",type:"text",required:!0},{key:"priority",label:"Priority",placeholder:"0 (normal)",type:"number",required:!1}];case"telegram":return[{key:"bot_token",label:"Bot Token",placeholder:"Bot token from @BotFather",type:"password",required:!0},{key:"chat_id",label:"Chat ID",placeholder:"Your chat or group ID",type:"text",required:!0}];case"email":return[{key:"smtp_server",label:"SMTP Server",placeholder:"smtp.gmail.com",type:"text",required:!0},{key:"smtp_port",label:"SMTP Port",placeholder:"587",type:"number",required:!1},{key:"security",label:"Security",type:"select",required:!1,options:[{value:"starttls",label:"STARTTLS (Port 587)"},{value:"ssl",label:"SSL/TLS (Port 465)"},{value:"none",label:"None (Port 25)"}]},{key:"auth_enabled",label:"Authentication",type:"select",required:!1,options:[{value:"true",label:"Enabled"},{value:"false",label:"Disabled"}]},{key:"username",label:"Username",placeholder:"your@email.com",type:"text",required:!1},{key:"password",label:"Password",placeholder:"App password",type:"password",required:!1},{key:"from_email",label:"From Email",placeholder:"your@email.com",type:"text",required:!0},{key:"to_email",label:"To Email",placeholder:"recipient@email.com",type:"text",required:!0}];case"discord":return[{key:"webhook_url",label:"Webhook URL",placeholder:"https://discord.com/api/webhooks/...",type:"text",required:!0}];case"webhook":return[{key:"webhook_url",label:"Webhook URL",placeholder:"https://example.com/webhook",type:"text",required:!0},{key:"auth_header",label:"Authorization",placeholder:"Bearer token (optional)",type:"password",required:!1},{key:"field_title",label:"Title Field Name",placeholder:"title",type:"text",required:!1},{key:"field_message",label:"Message Field Name",placeholder:"message",type:"text",required:!1}];default:return[]}},z=G=>H(G).filter(J=>J.required),re=H(a);return c.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4 overflow-y-auto",onClick:e,children:c.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg my-8",onClick:G=>G.stopPropagation(),children:[c.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[c.jsx("h2",{className:"text-lg font-semibold text-white",children:r?"Edit Notification Provider":"Add Notification Provider"}),c.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:c.jsx(Gt,{className:"w-5 h-5"})})]}),c.jsxs("form",{onSubmit:de,className:"p-6 space-y-4",children:[ue&&c.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:ue}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name *"}),c.jsx("input",{type:"text",value:i,onChange:G=>s(G.target.value),placeholder:"My Notifications",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Provider Type *"}),c.jsx("select",{value:a,onChange:G=>{o(G.target.value),ee({}),fe(null)},disabled:r,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none disabled:opacity-50",children:F9.map(G=>c.jsx("option",{value:G.value,children:G.label},G.value))}),c.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:F9.find(G=>G.value===a)?.description})]}),c.jsxs("div",{className:"space-y-3",children:[c.jsx("p",{className:"text-sm text-bambu-gray",children:"Configuration"}),re.map(G=>c.jsxs("div",{children:[c.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[G.label," ",G.required&&"*"]}),G.type==="select"&&G.options?c.jsx("select",{value:$[G.key]||G.options[0]?.value||"",onChange:J=>{ee({...$,[G.key]:J.target.value}),fe(null)},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:G.options.map(J=>c.jsx("option",{value:J.value,children:J.label},J.value))}):c.jsx("input",{type:G.type,value:$[G.key]||"",onChange:J=>{ee({...$,[G.key]:J.target.value}),fe(null)},placeholder:G.placeholder,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]},G.key))]}),c.jsx("div",{className:"flex gap-2",children:c.jsxs(Ie,{type:"button",variant:"secondary",onClick:()=>{fe(null),se.mutate()},disabled:se.isPending||!$[z(a)[0]?.key],className:"flex-1",children:[se.isPending?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(_R,{className:"w-4 h-4"}),"Test Configuration"]})}),ae&&c.jsx("div",{className:`p-3 rounded-lg flex items-center gap-2 ${ae.success?"bg-bambu-green/20 border border-bambu-green/50 text-bambu-green":"bg-red-500/20 border border-red-500/50 text-red-400"}`,children:ae.success?c.jsxs(c.Fragment,{children:[c.jsx(ds,{className:"w-5 h-5"}),c.jsx("span",{children:ae.message})]}):c.jsxs(c.Fragment,{children:[c.jsx(hd,{className:"w-5 h-5"}),c.jsx("span",{children:ae.message})]})}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Printer Filter"}),c.jsxs("select",{value:l??"",onChange:G=>u(G.target.value?Number(G.target.value):null),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[c.jsx("option",{value:"",children:"All printers"}),Me?.map(G=>c.jsx("option",{value:G.id,children:G.name},G.id))]}),c.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Only send notifications for events from this printer"})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("label",{className:"text-sm text-white",children:"Quiet Hours (Do Not Disturb)"}),c.jsx(Zn,{checked:d,onChange:f})]}),d&&c.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[c.jsxs("div",{children:[c.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Start"}),c.jsx("input",{type:"time",value:g,onChange:G=>m(G.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"End"}),c.jsx("input",{type:"time",value:x,onChange:G=>y(G.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]})]})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("label",{className:"text-sm text-white",children:"Daily Digest"}),c.jsx("p",{className:"text-xs text-bambu-gray",children:"Batch notifications into a single daily summary"})]}),c.jsx(Zn,{checked:v,onChange:b})]}),v&&c.jsxs("div",{children:[c.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Send digest at"}),c.jsx("input",{type:"time",value:E,onChange:G=>S(G.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),c.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Events will be collected and sent as a single summary at this time"})]})]}),c.jsxs("div",{className:"space-y-3",children:[c.jsx("p",{className:"text-sm text-bambu-gray",children:"Notification Events"}),c.jsxs("div",{className:"space-y-2 p-3 bg-bambu-dark rounded-lg",children:[c.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide mb-2",children:"Print Events"}),c.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm text-white",children:"Start"}),c.jsx(Zn,{checked:A,onChange:T})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm text-white",children:"Complete"}),c.jsx(Zn,{checked:P,onChange:C})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm text-white",children:"Failed"}),c.jsx(Zn,{checked:I,onChange:N})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm text-white",children:"Stopped"}),c.jsx(Zn,{checked:D,onChange:F})]}),c.jsxs("div",{className:"flex items-center justify-between col-span-2",children:[c.jsxs("div",{children:[c.jsx("span",{className:"text-sm text-white",children:"Progress"}),c.jsx("span",{className:"text-xs text-bambu-gray ml-1",children:"(25%, 50%, 75%)"})]}),c.jsx(Zn,{checked:L,onChange:q})]})]})]}),c.jsxs("div",{className:"space-y-2 p-3 bg-bambu-dark rounded-lg",children:[c.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide mb-2",children:"Printer Status"}),c.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm text-white",children:"Offline"}),c.jsx(Zn,{checked:R,onChange:V})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm text-white",children:"Error"}),c.jsx(Zn,{checked:K,onChange:W})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm text-white",children:"Low Filament"}),c.jsx(Zn,{checked:ne,onChange:Y})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm text-white",children:"Maintenance"}),c.jsx(Zn,{checked:Z,onChange:U})]})]})]})]}),c.jsxs("div",{className:"flex gap-3 pt-2",children:[c.jsx(Ie,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:"Cancel"}),c.jsxs(Ie,{type:"submit",disabled:ut,className:"flex-1",children:[ut?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(To,{className:"w-4 h-4"}),r?"Save":"Add"]})]})]})]})})}function k9e({template:t,onClose:e}){const n=Sn(),r=M.useRef(null),[i,s]=M.useState(t.title_template),[a,o]=M.useState(t.body_template),[l,u]=M.useState(null),[d,f]=M.useState(!0),{data:g}=yt({queryKey:["template-variables"],queryFn:Pe.getTemplateVariables}),m=g?.find(T=>T.event_type===t.event_type),{data:x,isLoading:y}=yt({queryKey:["template-preview",t.event_type,i,a],queryFn:()=>Pe.previewTemplate({event_type:t.event_type,title_template:i,body_template:a}),enabled:d&&i.length>0&&a.length>0});M.useEffect(()=>{const T=P=>{P.key==="Escape"&&e()};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)},[e]);const v=_t({mutationFn:T=>Pe.updateNotificationTemplate(t.id,T),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-templates"]}),e()},onError:T=>{u(T.message)}}),b=_t({mutationFn:()=>Pe.resetNotificationTemplate(t.id),onSuccess:T=>{s(T.title_template),o(T.body_template),n.invalidateQueries({queryKey:["notification-templates"]})},onError:T=>{u(T.message)}}),E=T=>{if(T.preventDefault(),u(null),!i.trim()){u("Title is required");return}if(!a.trim()){u("Body is required");return}v.mutate({title_template:i,body_template:a})},S=T=>{const P=r.current;if(!P)return;const C=P.selectionStart,I=P.selectionEnd,N=a,D=N.substring(0,C),F=N.substring(I),L=D+`{${T}}`+F;o(L),setTimeout(()=>{P.focus();const q=C+T.length+2;P.setSelectionRange(q,q)},0)},A=i!==t.title_template||a!==t.body_template;return c.jsx("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4",children:c.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-2xl max-h-[90vh] flex flex-col",children:[c.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0",children:[c.jsxs("h2",{className:"text-lg font-semibold text-white",children:["Edit Template: ",t.name]}),c.jsx("button",{onClick:e,className:"p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",children:c.jsx(Gt,{className:"w-5 h-5 text-bambu-gray"})})]}),c.jsxs("form",{onSubmit:E,className:"flex-1 overflow-y-auto p-4 space-y-4",children:[l&&c.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded text-red-400 text-sm",children:l}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:"Title"}),c.jsx("input",{type:"text",value:i,onChange:T=>s(T.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white focus:outline-none focus:ring-1 focus:ring-bambu-green",placeholder:"Notification title..."})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:"Body"}),c.jsx("textarea",{ref:r,value:a,onChange:T=>o(T.target.value),rows:4,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white focus:outline-none focus:ring-1 focus:ring-bambu-green font-mono text-sm resize-none",placeholder:"Notification body..."})]}),m&&c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-2",children:"Available Variables"}),c.jsx("div",{className:"flex flex-wrap gap-2",children:m.variables.map(T=>c.jsxs("button",{type:"button",onClick:()=>S(T),className:"inline-flex items-center gap-1 px-2 py-1 bg-bambu-dark hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-xs text-bambu-gray hover:text-white transition-colors",children:[c.jsx(fr,{className:"w-3 h-3"}),T]},T))}),c.jsx("p",{className:"text-xs text-bambu-gray/60 mt-1",children:"Click to insert at cursor position in body"})]}),c.jsxs("div",{children:[c.jsxs("div",{className:"flex items-center justify-between mb-2",children:[c.jsxs("label",{className:"text-sm font-medium text-bambu-gray flex items-center gap-2",children:[c.jsx(o0,{className:"w-4 h-4"}),"Live Preview"]}),c.jsx("button",{type:"button",onClick:()=>f(!d),className:"text-xs text-bambu-green hover:text-bambu-green-light",children:d?"Hide":"Show"})]}),d&&c.jsx("div",{className:"bg-bambu-dark border border-bambu-dark-tertiary rounded p-3 space-y-2",children:y?c.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-sm",children:[c.jsx(At,{className:"w-4 h-4 animate-spin"}),"Loading preview..."]}):x?c.jsxs(c.Fragment,{children:[c.jsxs("div",{children:[c.jsx("span",{className:"text-xs text-bambu-gray",children:"Title:"}),c.jsx("div",{className:"text-white font-medium",children:x.title})]}),c.jsxs("div",{children:[c.jsx("span",{className:"text-xs text-bambu-gray",children:"Body:"}),c.jsx("div",{className:"text-white whitespace-pre-wrap text-sm",children:x.body})]})]}):c.jsx("div",{className:"text-bambu-gray text-sm",children:"Enter template content to see preview"})})]})]}),c.jsxs("div",{className:"flex items-center justify-between p-4 border-t border-bambu-dark-tertiary shrink-0",children:[c.jsxs(Ie,{type:"button",variant:"ghost",onClick:()=>b.mutate(),disabled:b.isPending,className:"text-orange-400 hover:text-orange-300",children:[b.isPending?c.jsx(At,{className:"w-4 h-4 animate-spin mr-2"}):c.jsx(Im,{className:"w-4 h-4 mr-2"}),"Reset to Default"]}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(Ie,{type:"button",variant:"secondary",onClick:e,children:"Cancel"}),c.jsxs(Ie,{onClick:E,disabled:v.isPending||!A,children:[v.isPending?c.jsx(At,{className:"w-4 h-4 animate-spin mr-2"}):c.jsx(To,{className:"w-4 h-4 mr-2"}),"Save"]})]})]})]})})}const P9e={print_start:"Print Started",print_complete:"Print Complete",print_failed:"Print Failed",print_stopped:"Print Stopped",print_progress:"Progress",printer_offline:"Printer Offline",printer_error:"Printer Error",filament_low:"Low Filament",maintenance_due:"Maintenance Due",test:"Test"},R9e={print_start:"text-blue-400",print_complete:"text-bambu-green",print_failed:"text-red-400",print_stopped:"text-orange-400",print_progress:"text-yellow-400",printer_offline:"text-gray-400",printer_error:"text-rose-400",filament_low:"text-cyan-400",maintenance_due:"text-purple-400",test:"text-bambu-gray"};function D9e({onClose:t}){const e=Sn(),{showToast:n}=ri(),[r,i]=M.useState(7),[s,a]=M.useState(null),[o,l]=M.useState(!1),{data:u,isLoading:d,refetch:f,isRefetching:g}=yt({queryKey:["notification-logs",r,o],queryFn:()=>Pe.getNotificationLogs({days:r,limit:100,success:o?!1:void 0})}),{data:m}=yt({queryKey:["notification-log-stats",r],queryFn:()=>Pe.getNotificationLogStats(r)}),x=_t({mutationFn:()=>Pe.clearNotificationLogs(30),onSuccess:v=>{n(v.message,"success"),e.invalidateQueries({queryKey:["notification-logs"]}),e.invalidateQueries({queryKey:["notification-log-stats"]})},onError:v=>{n(`Failed to clear logs: ${v.message}`,"error")}}),y=v=>{const b=new Date(v),S=new Date().getTime()-b.getTime();return S<6e4?"Just now":S<36e5?`${Math.floor(S/6e4)}m ago`:S<864e5?`${Math.floor(S/36e5)}h ago`:b.toLocaleDateString()+" "+b.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})};return c.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:c.jsxs("div",{className:"bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg w-full max-w-3xl max-h-[85vh] flex flex-col",children:[c.jsxs("div",{className:"p-4 border-b border-bambu-dark-tertiary flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx(o3,{className:"w-5 h-5 text-bambu-green"}),c.jsx("h2",{className:"text-lg font-semibold text-white",children:"Notification Log"})]}),c.jsx("button",{onClick:t,className:"text-bambu-gray hover:text-white transition-colors",children:"×"})]}),m&&c.jsx("div",{className:"px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark/50",children:c.jsxs("div",{className:"flex items-center gap-6 text-sm",children:[c.jsxs("span",{className:"text-bambu-gray",children:["Last ",r," days: ",c.jsx("span",{className:"text-white font-medium",children:m.total})," notifications"]}),c.jsxs("span",{className:"flex items-center gap-1 text-bambu-green",children:[c.jsx(ds,{className:"w-4 h-4"}),m.success_count," sent"]}),m.failure_count>0&&c.jsxs("span",{className:"flex items-center gap-1 text-red-400",children:[c.jsx(hd,{className:"w-4 h-4"}),m.failure_count," failed"]})]})}),c.jsxs("div",{className:"px-4 py-3 border-b border-bambu-dark-tertiary flex items-center gap-4",children:[c.jsxs("select",{value:r,onChange:v=>i(Number(v.target.value)),className:"px-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:ring-1 focus:ring-bambu-green",children:[c.jsx("option",{value:1,children:"Last 24 hours"}),c.jsx("option",{value:7,children:"Last 7 days"}),c.jsx("option",{value:30,children:"Last 30 days"}),c.jsx("option",{value:90,children:"Last 90 days"})]}),c.jsxs("label",{className:"flex items-center gap-2 text-sm text-bambu-gray cursor-pointer",children:[c.jsx("input",{type:"checkbox",checked:o,onChange:v=>l(v.target.checked),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),"Show failed only"]}),c.jsx("div",{className:"flex-1"}),c.jsxs(Ie,{size:"sm",variant:"secondary",onClick:()=>f(),disabled:g,children:[g?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(qs,{className:"w-4 h-4"}),"Refresh"]}),c.jsxs(Ie,{size:"sm",variant:"secondary",onClick:()=>x.mutate(),disabled:x.isPending,className:"text-red-400 hover:text-red-300",children:[x.isPending?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(kn,{className:"w-4 h-4"}),"Clear Old"]})]}),c.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:d?c.jsx("div",{className:"flex justify-center py-12",children:c.jsx(At,{className:"w-6 h-6 text-bambu-green animate-spin"})}):u&&u.length>0?c.jsx("div",{className:"space-y-2",children:u.map(v=>c.jsx(O9e,{log:v,isExpanded:s===v.id,onToggle:()=>a(s===v.id?null:v.id),formatDate:y},v.id))}):c.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[c.jsx(o3,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),c.jsx("p",{className:"text-sm",children:o?"No failed notifications":"No notifications logged"})]})})]})})}function O9e({log:t,isExpanded:e,onToggle:n,formatDate:r}){return c.jsxs("div",{className:`border rounded-lg overflow-hidden transition-colors ${t.success?"border-bambu-dark-tertiary bg-bambu-dark/30":"border-red-500/30 bg-red-500/5"}`,children:[c.jsxs("button",{className:"w-full px-3 py-2 flex items-center gap-3 text-left hover:bg-bambu-dark/50 transition-colors",onClick:n,children:[t.success?c.jsx(ds,{className:"w-4 h-4 text-bambu-green shrink-0"}):c.jsx(hd,{className:"w-4 h-4 text-red-400 shrink-0"}),c.jsx("span",{className:`text-xs font-medium ${R9e[t.event_type]||"text-bambu-gray"}`,children:P9e[t.event_type]||t.event_type}),c.jsx("span",{className:"text-sm text-white truncate flex-1",children:t.provider_name||"Unknown Provider"}),t.printer_name&&c.jsx("span",{className:"text-xs text-bambu-gray",children:t.printer_name}),c.jsx("span",{className:"text-xs text-bambu-gray shrink-0",children:r(t.created_at)}),e?c.jsx(mS,{className:"w-4 h-4 text-bambu-gray shrink-0"}):c.jsx(ef,{className:"w-4 h-4 text-bambu-gray shrink-0"})]}),e&&c.jsxs("div",{className:"px-3 py-2 border-t border-bambu-dark-tertiary bg-bambu-dark/20 space-y-2",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-xs text-bambu-gray mb-1",children:"Title"}),c.jsx("p",{className:"text-sm text-white",children:t.title})]}),c.jsxs("div",{children:[c.jsx("p",{className:"text-xs text-bambu-gray mb-1",children:"Message"}),c.jsx("p",{className:"text-sm text-white whitespace-pre-wrap",children:t.message})]}),!t.success&&t.error_message&&c.jsxs("div",{children:[c.jsx("p",{className:"text-xs text-red-400 mb-1",children:"Error"}),c.jsx("p",{className:"text-sm text-red-300",children:t.error_message})]}),c.jsxs("div",{className:"flex gap-4 text-xs text-bambu-gray pt-1",children:[c.jsxs("span",{children:["Provider: ",t.provider_type]}),c.jsxs("span",{children:["Time: ",new Date(t.created_at).toLocaleString()]})]})]})]})}const P_=[{id:"settings",labelKey:"backup.categories.settings",defaultLabel:"App Settings",icon:c.jsx(wR,{className:"w-4 h-4"}),default:!0,description:"Language, theme, update preferences"},{id:"notifications",labelKey:"backup.categories.notifications",defaultLabel:"Notification Providers",icon:c.jsx(fh,{className:"w-4 h-4"}),default:!0,description:"ntfy, Pushover, Discord, etc."},{id:"templates",labelKey:"backup.categories.templates",defaultLabel:"Notification Templates",icon:c.jsx(Ya,{className:"w-4 h-4"}),default:!0,description:"Custom message templates"},{id:"smart_plugs",labelKey:"backup.categories.smartPlugs",defaultLabel:"Smart Plugs",icon:c.jsx(Ox,{className:"w-4 h-4"}),default:!0,description:"Tasmota plug configurations"},{id:"printers",labelKey:"backup.categories.printers",defaultLabel:"Printers",icon:c.jsx(jo,{className:"w-4 h-4"}),default:!1,description:"Printer info (access codes excluded)"},{id:"filaments",labelKey:"backup.categories.filaments",defaultLabel:"Filament Inventory",icon:c.jsx(Dle,{className:"w-4 h-4"}),default:!1,description:"Filament types and costs"},{id:"maintenance",labelKey:"backup.categories.maintenance",defaultLabel:"Maintenance Types",icon:c.jsx(Ju,{className:"w-4 h-4"}),default:!1,description:"Custom maintenance schedules"},{id:"archives",labelKey:"backup.categories.archives",defaultLabel:"Print Archives",icon:c.jsx(pS,{className:"w-4 h-4"}),default:!1,description:"All print data + files (3MF, thumbnails, photos)"}];function j9e({onClose:t,onExport:e}){const{t:n}=uS(),[r,i]=M.useState(()=>{const x={};return P_.forEach(y=>{x[y.id]=y.default}),x}),[s,a]=M.useState(!1),[o,l]=M.useState(!1);M.useEffect(()=>{const x=y=>{y.key==="Escape"&&t()};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[t]);const u=x=>{i(y=>({...y,[x]:!y[x]}))},d=()=>{const x={};P_.forEach(y=>{x[y.id]=!0}),i(x)},f=()=>{const x={};P_.forEach(y=>{x[y.id]=!1}),i(x)},g=Object.values(r).filter(Boolean).length,m=async()=>{l(!0);try{await e({...r,access_codes:s&&r.printers})}finally{l(!1)}};return c.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onClick:o?void 0:t,children:c.jsx(Nt,{className:"w-full max-w-lg",onClick:x=>x.stopPropagation(),children:c.jsxs(Dt,{className:"p-0",children:[c.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("div",{className:"p-2 rounded-full bg-bambu-green/20 text-bambu-green",children:c.jsx(ya,{className:"w-5 h-5"})}),c.jsxs("div",{children:[c.jsx("h3",{className:"text-lg font-semibold text-white",children:n("backup.exportTitle",{defaultValue:"Export Backup"})}),c.jsx("p",{className:"text-sm text-bambu-gray",children:n("backup.selectCategories",{defaultValue:"Select data to include"})})]})]}),c.jsx("button",{onClick:t,className:"p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors",children:c.jsx(Gt,{className:"w-5 h-5"})})]}),c.jsxs("div",{className:"flex gap-2 px-4 pt-4",children:[c.jsx("button",{onClick:d,disabled:o,className:"text-sm text-bambu-green hover:text-bambu-green/80 disabled:opacity-50 disabled:cursor-not-allowed",children:n("common.selectAll",{defaultValue:"Select All"})}),c.jsx("span",{className:"text-bambu-gray",children:"|"}),c.jsx("button",{onClick:f,disabled:o,className:"text-sm text-bambu-gray hover:text-white disabled:opacity-50 disabled:cursor-not-allowed",children:n("common.selectNone",{defaultValue:"Select None"})})]}),c.jsx("div",{className:`p-4 space-y-2 max-h-[400px] overflow-y-auto ${o?"opacity-50 pointer-events-none":""}`,children:P_.map(x=>c.jsxs("label",{className:`flex items-center gap-3 p-3 rounded-lg cursor-pointer transition-colors ${r[x.id]?"bg-bambu-green/10 border border-bambu-green/30":"bg-bambu-dark hover:bg-bambu-dark-tertiary border border-transparent"}`,children:[c.jsx("input",{type:"checkbox",checked:r[x.id],onChange:()=>u(x.id),disabled:o,className:"w-4 h-4 rounded border-bambu-gray bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0"}),c.jsx("div",{className:`${r[x.id]?"text-bambu-green":"text-bambu-gray"}`,children:x.icon}),c.jsxs("div",{className:"flex-1",children:[c.jsx("div",{className:"text-white text-sm font-medium",children:n(x.labelKey,{defaultValue:x.defaultLabel})}),c.jsx("div",{className:"text-xs text-bambu-gray",children:x.description})]})]},x.id))}),r.archives&&c.jsx("div",{className:"mx-4 mb-2 p-3 rounded-lg bg-yellow-500/10 border border-yellow-500/30",children:c.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[c.jsx(pS,{className:"w-4 h-4 text-yellow-500 mt-0.5 flex-shrink-0"}),c.jsxs("div",{className:"text-yellow-200 dark:text-yellow-200 text-yellow-700",children:[c.jsx("span",{className:"font-medium",children:"ZIP file will be created."}),c.jsx("span",{className:"text-yellow-600 dark:text-yellow-200/70",children:" Includes all 3MF files, thumbnails, timelapses, and photos. This may take a while and result in a large file."})]})]})}),r.printers&&c.jsxs("div",{className:"mx-4 mb-2 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-start gap-2",children:[c.jsx(Op,{className:"w-4 h-4 text-orange-500 dark:text-orange-400 mt-0.5 flex-shrink-0"}),c.jsxs("div",{children:[c.jsx("p",{className:"text-sm font-medium text-white",children:"Include Access Codes"}),c.jsx("p",{className:"text-xs text-bambu-gray",children:"For transferring to another machine"})]})]}),c.jsx(Zn,{checked:s,onChange:a})]}),s&&c.jsx("div",{className:"mt-2 p-2 rounded bg-orange-500/10 border border-orange-500/30",children:c.jsxs("div",{className:"flex items-start gap-2 text-xs",children:[c.jsx(Qr,{className:"w-3 h-3 text-orange-500 dark:text-orange-400 mt-0.5 flex-shrink-0"}),c.jsx("span",{className:"text-orange-700 dark:text-orange-200",children:"Access codes will be included in plain text. Keep this backup file secure!"})]})})]}),c.jsxs("div",{className:"flex items-center justify-between p-4 border-t border-bambu-dark-tertiary",children:[c.jsx("span",{className:"text-sm text-bambu-gray",children:n("backup.selectedCount",{count:g,defaultValue:`${g} categories selected`})}),c.jsxs("div",{className:"flex gap-3",children:[c.jsx(Ie,{variant:"secondary",onClick:t,disabled:o,children:n("common.cancel",{defaultValue:"Cancel"})}),c.jsx(Ie,{onClick:m,disabled:g===0||o,className:"bg-bambu-green hover:bg-bambu-green-dark disabled:opacity-50 disabled:cursor-not-allowed min-w-[100px]",children:o?c.jsxs(c.Fragment,{children:[c.jsx(At,{className:"w-4 h-4 mr-2 animate-spin"}),n("backup.exporting",{defaultValue:"Exporting..."})]}):c.jsxs(c.Fragment,{children:[c.jsx(ya,{className:"w-4 h-4 mr-2"}),n("backup.export",{defaultValue:"Export"})]})})]})]})]})})})}const z9={settings:"Settings",notification_providers:"Notification Providers",notification_templates:"Notification Templates",smart_plugs:"Smart Plugs",printers:"Printers",filaments:"Filaments",maintenance_types:"Maintenance Types",archives:"Archives"};function L9e({onClose:t,onRestore:e,onSuccess:n}){const[r,i]=M.useState("options"),[s,a]=M.useState(!1),[o,l]=M.useState(null),[u,d]=M.useState(null),[f,g]=M.useState(new Set),m=M.useRef(null);M.useEffect(()=>{const S=A=>{A.key==="Escape"&&r!=="restoring"&&t()};return window.addEventListener("keydown",S),()=>window.removeEventListener("keydown",S)},[t,r]);const x=S=>{const A=S.target.files?.[0];A&&l(A)},y=async()=>{if(o){i("restoring");try{const S=await e(o,s);d(S),i("result"),S.success&&n()}catch{d({success:!1,message:"Failed to restore backup. Please check the file format."}),i("result")}}},v=S=>{g(A=>{const T=new Set(A);return T.has(S)?T.delete(S):T.add(S),T})},b=u?.restored?Object.values(u.restored).reduce((S,A)=>S+A,0)+(u.files_restored||0):0,E=u?.total_skipped||0;return c.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onMouseDown:S=>{S.target===S.currentTarget&&r!=="restoring"&&t()},children:c.jsx(Nt,{className:"w-full max-w-lg",children:c.jsxs(Dt,{className:"p-0",children:[c.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("div",{className:`p-2 rounded-full ${r==="result"&&u?.success?"bg-bambu-green/20 text-bambu-green":r==="result"&&!u?.success?"bg-red-500/20 text-red-500":"bg-blue-500/20 text-blue-500"}`,children:r==="result"&&u?.success?c.jsx(ds,{className:"w-5 h-5"}):r==="result"&&!u?.success?c.jsx(Qr,{className:"w-5 h-5"}):c.jsx(ma,{className:"w-5 h-5"})}),c.jsxs("div",{children:[c.jsxs("h3",{className:"text-lg font-semibold text-white",children:[r==="options"&&"Restore Backup",r==="restoring"&&"Restoring...",r==="result"&&(u?.success?"Restore Complete":"Restore Failed")]}),c.jsxs("p",{className:"text-sm text-bambu-gray",children:[r==="options"&&"Import settings from a backup file",r==="restoring"&&"Please wait while your data is being restored",r==="result"&&u?.message]})]})]}),r!=="restoring"&&c.jsx("button",{onClick:t,className:"p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors",children:c.jsx(Gt,{className:"w-5 h-5"})})]}),r==="options"&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"p-4 space-y-4",children:[c.jsxs("div",{children:[c.jsx("input",{ref:m,type:"file",accept:".json,.zip",className:"hidden",onChange:x}),c.jsx("button",{type:"button",onClick:()=>m.current?.click(),className:`w-full p-4 border-2 border-dashed rounded-lg transition-colors ${o?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:o?c.jsxs("div",{className:"flex items-center justify-center gap-2 text-bambu-green",children:[c.jsx(ds,{className:"w-5 h-5"}),c.jsx("span",{className:"font-medium",children:o.name})]}):c.jsxs("div",{className:"flex flex-col items-center gap-2 text-bambu-gray",children:[c.jsx(ma,{className:"w-8 h-8"}),c.jsx("span",{children:"Click to select backup file (.json or .zip)"})]})})]}),c.jsx("div",{className:"p-3 rounded-lg bg-blue-500/10 border border-blue-500/30",children:c.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[c.jsx(Qr,{className:"w-4 h-4 text-blue-500 dark:text-blue-400 mt-0.5 flex-shrink-0"}),c.jsxs("div",{className:"text-blue-700 dark:text-blue-200",children:[c.jsx("p",{className:"font-medium mb-1",children:"How duplicate handling works:"}),c.jsxs("ul",{className:"text-blue-600 dark:text-blue-200/80 space-y-1 text-xs",children:[c.jsxs("li",{children:[c.jsx("strong",{children:"Printers"})," - matched by serial number"]}),c.jsxs("li",{children:[c.jsx("strong",{children:"Smart Plugs"})," - matched by IP address"]}),c.jsxs("li",{children:[c.jsx("strong",{children:"Notification Providers"})," - matched by name"]}),c.jsxs("li",{children:[c.jsx("strong",{children:"Filaments"})," - matched by name + type + brand"]}),c.jsxs("li",{children:[c.jsx("strong",{children:"Archives"})," - matched by content hash (always skipped)"]}),c.jsxs("li",{children:[c.jsx("strong",{children:"Settings & Templates"})," - always overwritten"]})]})]})]})}),c.jsx("div",{className:"p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary",children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsxs("p",{className:"text-white font-medium flex items-center gap-2",children:[s?c.jsx(qs,{className:"w-4 h-4 text-orange-400"}):c.jsx(c1,{className:"w-4 h-4 text-bambu-gray"}),s?"Replace existing data":"Keep existing data"]}),c.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:s?"Overwrite items that already exist with backup data":"Only restore items that don't already exist"})]}),c.jsx(Zn,{checked:s,onChange:a})]})}),s&&c.jsx("div",{className:"p-3 rounded-lg bg-orange-500/10 border border-orange-500/30",children:c.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[c.jsx(Qr,{className:"w-4 h-4 text-orange-500 dark:text-orange-400 mt-0.5 flex-shrink-0"}),c.jsxs("div",{className:"text-orange-700 dark:text-orange-200",children:[c.jsx("span",{className:"font-medium",children:"Caution:"})," Overwriting will replace your current configurations with data from the backup. Printer access codes are never overwritten for security."]})]})})]}),c.jsxs("div",{className:"flex items-center justify-end gap-3 p-4 border-t border-bambu-dark-tertiary",children:[c.jsx(Ie,{type:"button",variant:"secondary",onClick:t,children:"Cancel"}),c.jsxs(Ie,{type:"button",onClick:y,disabled:!o,className:"bg-bambu-green hover:bg-bambu-green-dark disabled:opacity-50",children:[c.jsx(ma,{className:"w-4 h-4 mr-2"}),"Restore"]})]})]}),r==="restoring"&&c.jsxs("div",{className:"p-8 flex flex-col items-center gap-4",children:[c.jsx(At,{className:"w-12 h-12 text-bambu-green animate-spin"}),c.jsx("p",{className:"text-bambu-gray",children:"Processing backup file..."})]}),r==="result"&&u&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"p-4 space-y-4 max-h-[400px] overflow-y-auto",children:[c.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[c.jsxs("div",{className:"p-3 rounded-lg bg-bambu-green/10 border border-bambu-green/30",children:[c.jsx("div",{className:"text-2xl font-bold text-bambu-green",children:b}),c.jsx("div",{className:"text-sm text-bambu-gray",children:"Items Restored"})]}),c.jsxs("div",{className:"p-3 rounded-lg bg-yellow-500/10 border border-yellow-500/30",children:[c.jsx("div",{className:"text-2xl font-bold text-yellow-500",children:E}),c.jsx("div",{className:"text-sm text-bambu-gray",children:"Items Skipped"})]})]}),u.restored&&Object.entries(u.restored).some(([,S])=>S>0)&&c.jsxs("div",{className:"space-y-2",children:[c.jsxs("h4",{className:"text-sm font-medium text-bambu-gray flex items-center gap-2",children:[c.jsx(ds,{className:"w-4 h-4 text-bambu-green"}),"Restored"]}),c.jsxs("div",{className:"space-y-1",children:[Object.entries(u.restored).filter(([,S])=>S>0).map(([S,A])=>c.jsxs("div",{className:"flex items-center justify-between text-sm p-2 rounded bg-bambu-dark",children:[c.jsx("span",{className:"text-white",children:z9[S]||S}),c.jsx("span",{className:"text-bambu-green font-medium",children:A})]},S)),(u.files_restored||0)>0&&c.jsxs("div",{className:"flex items-center justify-between text-sm p-2 rounded bg-bambu-dark",children:[c.jsx("span",{className:"text-white",children:"Files (3MF, thumbnails, etc.)"}),c.jsx("span",{className:"text-bambu-green font-medium",children:u.files_restored})]})]})]}),u.skipped&&Object.entries(u.skipped).some(([,S])=>S>0)&&c.jsxs("div",{className:"space-y-2",children:[c.jsxs("h4",{className:"text-sm font-medium text-bambu-gray flex items-center gap-2",children:[c.jsx(c1,{className:"w-4 h-4 text-yellow-500"}),"Skipped (already exist)"]}),c.jsx("div",{className:"space-y-1",children:Object.entries(u.skipped).filter(([,S])=>S>0).map(([S,A])=>{const T=u.skipped_details?.[S]||[],P=f.has(S);return c.jsxs("div",{children:[c.jsxs("button",{onClick:()=>T.length>0&&v(S),className:`w-full flex items-center justify-between text-sm p-2 rounded bg-bambu-dark ${T.length>0?"hover:bg-bambu-dark-tertiary cursor-pointer":""}`,children:[c.jsxs("span",{className:"text-white flex items-center gap-2",children:[z9[S]||S,T.length>0&&(P?c.jsx(mS,{className:"w-3 h-3"}):c.jsx(ef,{className:"w-3 h-3"}))]}),c.jsx("span",{className:"text-yellow-500 font-medium",children:A})]}),P&&T.length>0&&c.jsxs("div",{className:"mt-1 ml-4 p-2 rounded bg-bambu-dark-tertiary text-xs text-bambu-gray space-y-1",children:[T.slice(0,10).map((C,I)=>c.jsx("div",{children:C},I)),T.length>10&&c.jsxs("div",{className:"text-bambu-gray/60",children:["...and ",T.length-10," more"]})]})]},S)})})]}),b===0&&E===0&&c.jsx("div",{className:"p-4 text-center text-bambu-gray",children:"No data was found to restore in the backup file."})]}),c.jsx("div",{className:"flex items-center justify-end gap-3 p-4 border-t border-bambu-dark-tertiary",children:c.jsx(Ie,{onClick:t,children:"Close"})})]})]})})})}async function I9e(){const t=await fetch("/api/v1/settings/spoolman");if(!t.ok)throw new Error("Failed to load Spoolman settings");return t.json()}async function U9e(t){const e=await fetch("/api/v1/settings/spoolman",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!e.ok)throw new Error("Failed to save Spoolman settings");return e.json()}function F9e(){const t=Sn(),[e,n]=M.useState(!1),[r,i]=M.useState(""),[s,a]=M.useState("auto"),[o,l]=M.useState(!1),[u,d]=M.useState("all"),[f,g]=M.useState(!1),{data:m,isLoading:x}=yt({queryKey:["spoolman-settings"],queryFn:I9e}),{data:y,isLoading:v,refetch:b}=yt({queryKey:["spoolman-status"],queryFn:Pe.getSpoolmanStatus,refetchInterval:3e4}),{data:E}=yt({queryKey:["printers"],queryFn:Pe.getPrinters});M.useEffect(()=>{m&&(n(m.spoolman_enabled==="true"),i(m.spoolman_url||""),a(m.spoolman_sync_mode||"auto"),g(!0))},[m]),M.useEffect(()=>{if(!f||!m)return;if(m.spoolman_enabled==="true"!==e||(m.spoolman_url||"")!==r||(m.spoolman_sync_mode||"auto")!==s){const q=setTimeout(()=>{S.mutate()},500);return()=>clearTimeout(q)}},[e,r,s,f]);const S=_t({mutationFn:()=>U9e({spoolman_enabled:e?"true":"false",spoolman_url:r,spoolman_sync_mode:s}),onSuccess:()=>{t.invalidateQueries({queryKey:["spoolman-settings"]}),t.invalidateQueries({queryKey:["spoolman-status"]}),l(!0),setTimeout(()=>l(!1),2e3)}}),A=_t({mutationFn:Pe.connectSpoolman,onSuccess:()=>{b()}}),T=_t({mutationFn:Pe.disconnectSpoolman,onSuccess:()=>{b()}}),P=_t({mutationFn:Pe.syncAllPrintersAms,onSuccess:L=>{L.success}}),C=_t({mutationFn:L=>Pe.syncPrinterAms(L),onSuccess:L=>{L.success}}),I=()=>{u==="all"?P.mutate():C.mutate(u)},N=P.isPending||C.isPending,D=u==="all"?P.data:C.data,F=u==="all"?P.isSuccess:C.isSuccess;return x?c.jsxs(Nt,{children:[c.jsx(za,{children:c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(s3,{className:"w-5 h-5 text-bambu-green"}),c.jsx("h2",{className:"text-lg font-semibold text-white",children:"Spoolman Integration"})]})}),c.jsx(Dt,{children:c.jsx("div",{className:"flex justify-center py-8",children:c.jsx(At,{className:"w-6 h-6 text-bambu-green animate-spin"})})})]}):c.jsxs(Nt,{children:[c.jsx(za,{children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(s3,{className:"w-5 h-5 text-bambu-green"}),c.jsx("h2",{className:"text-lg font-semibold text-white",children:"Spoolman Integration"})]}),S.isPending&&c.jsx(At,{className:"w-4 h-4 text-bambu-green animate-spin"}),o&&c.jsx(Ph,{className:"w-4 h-4 text-bambu-green"})]})}),c.jsxs(Dt,{className:"space-y-4",children:[c.jsx("p",{className:"text-sm text-bambu-gray",children:"Connect to Spoolman for filament inventory tracking. AMS data will sync automatically."}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-white",children:"Enable Spoolman"}),c.jsx("p",{className:"text-sm text-bambu-gray",children:"Sync filament data with Spoolman server"})]}),c.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[c.jsx("input",{type:"checkbox",checked:e,onChange:L=>n(L.target.checked),className:"sr-only peer"}),c.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Spoolman URL"}),c.jsx("input",{type:"text",placeholder:"http://192.168.1.100:7912",value:r,onChange:L=>i(L.target.value),disabled:!e,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray/50 focus:border-bambu-green focus:outline-none disabled:opacity-50"}),c.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"URL of your Spoolman server (e.g., http://localhost:7912)"})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Sync Mode"}),c.jsxs("select",{value:s,onChange:L=>a(L.target.value),disabled:!e,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none disabled:opacity-50",children:[c.jsx("option",{value:"auto",children:"Automatic"}),c.jsx("option",{value:"manual",children:"Manual Only"})]}),c.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:s==="auto"?"AMS data syncs automatically when changes are detected":"Only sync when manually triggered"})]}),e&&c.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[c.jsxs("div",{className:"flex items-center justify-between mb-3",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"text-sm text-bambu-gray",children:"Status:"}),v?c.jsx(At,{className:"w-4 h-4 text-bambu-gray animate-spin"}):y?.connected?c.jsxs("span",{className:"flex items-center gap-1 text-sm text-green-500",children:[c.jsx(Ph,{className:"w-4 h-4"}),"Connected"]}):c.jsxs("span",{className:"flex items-center gap-1 text-sm text-red-500",children:[c.jsx(Gt,{className:"w-4 h-4"}),"Disconnected"]})]}),c.jsx("div",{className:"flex gap-2",children:y?.connected?c.jsxs(Ie,{variant:"secondary",size:"sm",onClick:()=>T.mutate(),disabled:T.isPending,children:[T.isPending?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(nle,{className:"w-4 h-4"}),"Disconnect"]}):c.jsxs(Ie,{size:"sm",onClick:()=>A.mutate(),disabled:A.isPending||!r,children:[A.isPending?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(c3,{className:"w-4 h-4"}),"Connect"]})})]}),A.isError&&c.jsx("div",{className:"mb-3 p-2 bg-red-500/20 border border-red-500/50 rounded text-sm text-red-400",children:A.error.message}),y?.connected&&c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-sm text-white",children:"Sync AMS Data"}),c.jsx("p",{className:"text-xs text-bambu-gray",children:"Manually sync printer AMS data to Spoolman"})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("div",{className:"relative flex-1",children:[c.jsxs("select",{value:u,onChange:L=>d(L.target.value==="all"?"all":Number(L.target.value)),className:"w-full px-3 py-2 pr-8 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:[c.jsx("option",{value:"all",children:"All Printers"}),E?.map(L=>c.jsx("option",{value:L.id,children:L.name},L.id))]}),c.jsx(ef,{className:"absolute right-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),c.jsxs(Ie,{variant:"secondary",size:"sm",onClick:I,disabled:N,children:[N?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(qs,{className:"w-4 h-4"}),"Sync"]})]})]}),F&&D&&c.jsx("div",{className:`mt-2 p-2 rounded text-sm ${D.success?"bg-green-500/20 border border-green-500/50 text-green-400":"bg-yellow-500/20 border border-yellow-500/50 text-yellow-400"}`,children:D.success?`Synced ${D.synced_count} trays successfully`:`Synced ${D.synced_count} trays with ${D.errors.length} errors`})]})]})]})}function z9e({link:t,onClose:e}){const n=Sn(),{theme:r}=yS(),i=!!t,s=M.useRef(null),[a,o]=M.useState(t?.name||""),[l,u]=M.useState(t?.url||""),[d,f]=M.useState(t?.icon||"link"),[g,m]=M.useState(!!t?.custom_icon),[x,y]=M.useState(t?.custom_icon?Pe.getExternalLinkIconUrl(t.id):null),[v,b]=M.useState(null),[E,S]=M.useState(null);M.useEffect(()=>{const F=L=>{L.key==="Escape"&&e()};return window.addEventListener("keydown",F),()=>window.removeEventListener("keydown",F)},[e]);const A=_t({mutationFn:async F=>{const L=await Pe.createExternalLink(F);return v?await Pe.uploadExternalLinkIcon(L.id,v):L},onSuccess:()=>{n.invalidateQueries({queryKey:["external-links"]}),e()},onError:F=>{S(F.message)}}),T=_t({mutationFn:async F=>{let L=await Pe.updateExternalLink(t.id,F);return v?L=await Pe.uploadExternalLinkIcon(t.id,v):!g&&t?.custom_icon&&(L=await Pe.deleteExternalLinkIcon(t.id)),L},onSuccess:()=>{n.invalidateQueries({queryKey:["external-links"]}),e()},onError:F=>{S(F.message)}}),P=F=>{const L=F.target.files?.[0];if(L){if(!["image/png","image/jpeg","image/gif","image/svg+xml","image/webp","image/x-icon"].includes(L.type)){S("Please select a valid image file (PNG, JPG, GIF, SVG, WebP, or ICO)");return}if(L.size>1024*1024){S("Image file must be less than 1MB");return}b(L),m(!0);const R=new FileReader;R.onload=V=>{y(V.target?.result)},R.readAsDataURL(L)}},C=()=>{b(null),y(null),m(!1),s.current&&(s.current.value="")},I=F=>{if(F.preventDefault(),S(null),!a.trim()){S("Name is required");return}if(!l.trim()){S("URL is required");return}if(!l.startsWith("http://")&&!l.startsWith("https://")){S("URL must start with http:// or https://");return}const L={name:a.trim(),url:l.trim(),icon:d};i?T.mutate(L):A.mutate(L)},N=A.isPending||T.isPending,D=_S(d);return c.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:e,children:c.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-md",onClick:F=>F.stopPropagation(),children:[c.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("div",{className:"p-2 rounded-full bg-bambu-green/20 text-bambu-green",children:g&&x?c.jsx("img",{src:x,alt:"",className:`w-5 h-5 rounded ${r==="dark"?"invert opacity-[0.65]":"opacity-60"}`}):c.jsx(D,{className:"w-5 h-5"})}),c.jsx("h2",{className:"text-lg font-semibold text-white",children:i?"Edit Link":"Add External Link"})]}),c.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:c.jsx(Gt,{className:"w-5 h-5"})})]}),c.jsxs("form",{onSubmit:I,className:"p-6 space-y-4",children:[E&&c.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:E}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name *"}),c.jsx("input",{type:"text",value:a,onChange:F=>o(F.target.value),placeholder:"My Link",maxLength:50,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"URL *"}),c.jsx("input",{type:"text",value:l,onChange:F=>u(F.target.value),placeholder:"https://example.com",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),c.jsxs("div",{className:"space-y-3",children:[c.jsx("label",{className:"block text-sm text-bambu-gray",children:"Icon"}),c.jsxs("div",{className:"p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary",children:[c.jsxs("div",{className:"flex items-center justify-between mb-2",children:[c.jsx("span",{className:"text-sm text-white",children:"Custom Icon"}),c.jsx("input",{ref:s,type:"file",accept:"image/png,image/jpeg,image/gif,image/svg+xml,image/webp,image/x-icon",className:"hidden",onChange:P}),g&&x?c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("img",{src:x,alt:"Custom icon",className:`w-8 h-8 rounded border border-bambu-dark-tertiary ${r==="dark"?"invert opacity-[0.65]":"opacity-60"}`}),c.jsx("button",{type:"button",onClick:C,className:"p-1 text-red-400 hover:text-red-300 transition-colors",title:"Remove custom icon",children:c.jsx(kn,{className:"w-4 h-4"})})]}):c.jsxs(Ie,{type:"button",variant:"secondary",size:"sm",onClick:()=>s.current?.click(),children:[c.jsx(ma,{className:"w-4 h-4"}),"Upload"]})]}),c.jsx("p",{className:"text-xs text-bambu-gray",children:"PNG, JPG, GIF, SVG, WebP, or ICO. Max 1MB."})]}),!g&&c.jsxs("div",{children:[c.jsx("span",{className:"text-sm text-bambu-gray block mb-2",children:"Or choose a preset icon"}),c.jsx(oue,{value:d,onChange:f})]})]}),c.jsxs("div",{className:"flex gap-3 pt-2",children:[c.jsx(Ie,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:"Cancel"}),c.jsxs(Ie,{type:"submit",disabled:N,className:"flex-1",children:[N?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(To,{className:"w-4 h-4"}),i?"Save":"Add"]})]})]})]})})}function B9e(){const t=Sn(),[e,n]=M.useState(!1),[r,i]=M.useState(null),[s,a]=M.useState(null),[o,l]=M.useState(null),{data:u,isLoading:d}=yt({queryKey:["external-links"],queryFn:Pe.getExternalLinks}),f=_t({mutationFn:E=>Pe.deleteExternalLink(E),onSuccess:()=>{t.invalidateQueries({queryKey:["external-links"]})}}),g=_t({mutationFn:E=>Pe.reorderExternalLinks(E),onSuccess:()=>{t.invalidateQueries({queryKey:["external-links"]})}}),m=(E,S)=>{l(S),E.dataTransfer.effectAllowed="move"},x=E=>{E.preventDefault(),E.dataTransfer.dropEffect="move"},y=(E,S)=>{if(E.preventDefault(),o===null||o===S||!u)return;const A=u.map(I=>I.id),T=A.indexOf(o),P=A.indexOf(S);if(T===-1||P===-1)return;const C=[...A];C.splice(T,1),C.splice(P,0,o),g.mutate(C),l(null)},v=E=>{a(E)},b=()=>{s&&(f.mutate(s.id),a(null))};return c.jsxs(c.Fragment,{children:[c.jsxs(Nt,{children:[c.jsx(za,{children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(c3,{className:"w-5 h-5 text-bambu-green"}),c.jsx("h2",{className:"text-lg font-semibold text-white",children:"Sidebar Links"})]}),c.jsxs(Ie,{size:"sm",onClick:()=>n(!0),children:[c.jsx(fr,{className:"w-4 h-4"}),"Add Link"]})]})}),c.jsxs(Dt,{children:[c.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:"Add external links to the sidebar navigation. Drag to reorder."}),d?c.jsx("div",{className:"flex justify-center py-8",children:c.jsx(At,{className:"w-6 h-6 text-bambu-green animate-spin"})}):u&&u.length>0?c.jsx("div",{className:"space-y-2",children:u.map(E=>{const S=_S(E.icon);return c.jsxs("div",{draggable:!0,onDragStart:A=>m(A,E.id),onDragOver:x,onDrop:A=>y(A,E.id),className:`flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary transition-colors ${o===E.id?"opacity-50":""}`,children:[c.jsx(c0,{className:"w-6 h-6 md:w-4 md:h-4 text-bambu-gray cursor-grab flex-shrink-0"}),c.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark-tertiary text-bambu-gray",children:c.jsx(S,{className:"w-4 h-4"})}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"text-white font-medium truncate",children:E.name}),c.jsx(ro,{className:"w-3 h-3 text-bambu-gray flex-shrink-0"})]}),c.jsx("span",{className:"text-sm text-bambu-gray truncate block",children:E.url})]}),c.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[c.jsx("button",{onClick:()=>i(E),className:"p-2 rounded-lg hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors",title:"Edit",children:c.jsx(Zu,{className:"w-4 h-4"})}),c.jsx("button",{onClick:()=>v(E),disabled:f.isPending,className:"p-2 rounded-lg hover:bg-red-500/20 text-bambu-gray hover:text-red-400 transition-colors disabled:opacity-50",title:"Delete",children:c.jsx(kn,{className:"w-4 h-4"})})]})]},E.id)})}):c.jsxs("div",{className:"text-center py-8 text-bambu-gray",children:[c.jsx(c3,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),c.jsx("p",{children:"No external links configured"}),c.jsx("p",{className:"text-sm",children:'Click "Add Link" to add one'})]})]})]}),(e||r)&&c.jsx(z9e,{link:r,onClose:()=>{n(!1),i(null)}}),s&&c.jsx(Kr,{title:"Delete Link",message:`Are you sure you want to delete "${s.name}"? This action cannot be undone.`,confirmText:"Delete",cancelText:"Cancel",variant:"danger",onConfirm:b,onCancel:()=>a(null)})]})}function H9e(){const t=Sn(),{t:e,i18n:n}=uS(),{showToast:r}=ri(),[i,s]=M.useState(null),[a,o]=M.useState(!1),[l,u]=M.useState(null),[d,f]=M.useState(!1),[g,m]=M.useState(null),[x,y]=M.useState(null),[v,b]=M.useState(!1),[E,S]=M.useState(GG()),[A,T]=M.useState("general"),[P,C]=M.useState(!1),[I,N]=M.useState(""),[D,F]=M.useState({can_queue:!0,can_control_printer:!1,can_read_status:!0}),[L,q]=M.useState(null),[R,V]=M.useState(null),[K,W]=M.useState(!1),[ne,Y]=M.useState(!1),[Z,U]=M.useState(null),[$,ee]=M.useState(!1),[ae,fe]=M.useState(!1),ue=Q=>{S(Q),uue(Q)},xe=()=>{localStorage.removeItem("sidebarOrder"),window.location.reload()},{data:Me,isLoading:se}=yt({queryKey:["settings"],queryFn:Pe.getSettings}),{data:ve,isLoading:je}=yt({queryKey:["smart-plugs"],queryFn:Pe.getSmartPlugs}),{data:de,isLoading:ut}=yt({queryKey:["smart-plugs-energy",ve?.map(Q=>Q.id)],queryFn:async()=>{if(!ve||ve.length===0)return null;const Q=await Promise.all(ve.filter(He=>He.enabled).map(async He=>{try{const ht=await Pe.getSmartPlugStatus(He.id);return{plug:He,status:ht}}catch{return{plug:He,status:null}}}));let Fe=0,pe=0,Ue=0,Ce=0,ye=0;for(const{status:He}of Q)He?.reachable&&He.energy&&(ye++,He.energy.power!=null&&(Fe+=He.energy.power),He.energy.today!=null&&(pe+=He.energy.today),He.energy.yesterday!=null&&(Ue+=He.energy.yesterday),He.energy.total!=null&&(Ce+=He.energy.total));return{totalPower:Fe,totalToday:pe,totalYesterday:Ue,totalLifetime:Ce,reachableCount:ye,totalPlugs:ve.filter(He=>He.enabled).length}},enabled:A==="plugs"&&!!ve&&ve.length>0,refetchInterval:A==="plugs"?1e4:!1}),{data:H,isLoading:z}=yt({queryKey:["notification-providers"],queryFn:Pe.getNotificationProviders}),{data:re,isLoading:G}=yt({queryKey:["api-keys"],queryFn:Pe.getAPIKeys,enabled:A==="apikeys"}),J=_t({mutationFn:Q=>Pe.createAPIKey(Q),onSuccess:Q=>{q(Q.key||null),C(!1),N(""),t.invalidateQueries({queryKey:["api-keys"]}),r("API key created")},onError:Q=>{r(`Failed to create API key: ${Q.message}`,"error")}}),le=_t({mutationFn:Q=>Pe.deleteAPIKey(Q),onSuccess:()=>{t.invalidateQueries({queryKey:["api-keys"]}),r("API key deleted")},onError:Q=>{r(`Failed to delete API key: ${Q.message}`,"error")}}),{data:ke}=yt({queryKey:["printers"],queryFn:Pe.getPrinters}),{data:Ne,isLoading:we}=yt({queryKey:["notification-templates"],queryFn:Pe.getNotificationTemplates}),{data:B}=yt({queryKey:["ffmpeg-status"],queryFn:Pe.checkFfmpeg}),{data:j}=yt({queryKey:["version"],queryFn:Pe.getVersion}),{data:te,refetch:be,isRefetching:_e}=yt({queryKey:["updateCheck"],queryFn:Pe.checkForUpdates,staleTime:300*1e3}),{data:ge,refetch:me}=yt({queryKey:["updateStatus"],queryFn:Pe.getUpdateStatus,refetchInterval:Q=>{const Fe=Q.state.data;return Fe?.status==="downloading"||Fe?.status==="installing"?1e3:!1}}),Ae=_t({mutationFn:Pe.applyUpdate,onSuccess:()=>{me()}}),[ze,st]=M.useState(null),Ve=_t({mutationFn:Pe.testAllNotificationProviders,onSuccess:Q=>{st(Q),t.invalidateQueries({queryKey:["notification-providers"]}),Q.failed===0?r(`All ${Q.tested} providers tested successfully!`,"success"):r(`${Q.success}/${Q.tested} providers succeeded`,Q.failed>0?"error":"success")},onError:Q=>{r(`Failed to test providers: ${Q.message}`,"error")}}),ce=_t({mutationFn:async Q=>{if(!ve)return{success:0,failed:0};const Fe=ve.filter(Ue=>Ue.enabled),pe=await Promise.all(Fe.map(async Ue=>{try{return await Pe.controlSmartPlug(Ue.id,Q),{success:!0}}catch{return{success:!1}}}));return{success:pe.filter(Ue=>Ue.success).length,failed:pe.filter(Ue=>!Ue.success).length}},onSuccess:(Q,Fe)=>{t.invalidateQueries({queryKey:["smart-plugs"]}),t.invalidateQueries({queryKey:["smart-plugs-energy"]}),Q.failed===0?r(`All ${Q.success} plugs turned ${Fe}`,"success"):r(`${Q.success} plugs turned ${Fe}, ${Q.failed} failed`,"error")},onError:Q=>{r(`Failed: ${Q.message}`,"error")}}),Ye=M.useRef(null),$e=M.useRef(!0);M.useEffect(()=>{Me&&!i&&(s(Me),setTimeout(()=>{$e.current=!1},100))},[Me,i]);const Ze=_t({mutationFn:Pe.updateSettings,onSuccess:Q=>{t.setQueryData(["settings"],Q),t.invalidateQueries({queryKey:["archiveStats"]}),r("Settings saved","success")},onError:Q=>{r(`Failed to save: ${Q.message}`,"error")}});M.useEffect(()=>{if(!($e.current||!i||!Me||!(Me.auto_archive!==i.auto_archive||Me.save_thumbnails!==i.save_thumbnails||Me.capture_finish_photo!==i.capture_finish_photo||Me.default_filament_cost!==i.default_filament_cost||Me.currency!==i.currency||Me.energy_cost_per_kwh!==i.energy_cost_per_kwh||Me.energy_tracking_mode!==i.energy_tracking_mode||Me.check_updates!==i.check_updates||Me.notification_language!==i.notification_language||Me.ams_humidity_good!==i.ams_humidity_good||Me.ams_humidity_fair!==i.ams_humidity_fair||Me.ams_temp_good!==i.ams_temp_good||Me.ams_temp_fair!==i.ams_temp_fair||Me.date_format!==i.date_format||Me.time_format!==i.time_format||Me.default_printer_id!==i.default_printer_id)))return Ye.current&&clearTimeout(Ye.current),Ye.current=setTimeout(()=>{Ze.mutate(i)},500),()=>{Ye.current&&clearTimeout(Ye.current)}},[i,Me,Ze]);const at=M.useCallback((Q,Fe)=>{s(pe=>pe?{...pe,[Q]:Fe}:null)},[]);return se||!i?c.jsx("div",{className:"p-4 md:p-8 flex justify-center",children:c.jsx(At,{className:"w-8 h-8 text-bambu-green animate-spin"})}):c.jsxs("div",{className:"p-4 md:p-8",children:[c.jsxs("div",{className:"mb-8",children:[c.jsx("h1",{className:"text-2xl font-bold text-white",children:"Settings"}),c.jsx("p",{className:"text-bambu-gray",children:"Configure Bambuddy"})]}),c.jsxs("div",{className:"flex gap-1 mb-6 border-b border-bambu-dark-tertiary",children:[c.jsx("button",{onClick:()=>T("general"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px ${A==="general"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:"General"}),c.jsxs("button",{onClick:()=>T("plugs"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${A==="plugs"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[c.jsx(Ox,{className:"w-4 h-4"}),"Smart Plugs",ve&&ve.length>0&&c.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:ve.length})]}),c.jsxs("button",{onClick:()=>T("notifications"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${A==="notifications"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[c.jsx(fh,{className:"w-4 h-4"}),"Notifications",H&&H.length>0&&c.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:H.length})]}),c.jsxs("button",{onClick:()=>T("apikeys"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${A==="apikeys"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[c.jsx(Op,{className:"w-4 h-4"}),"API Keys",re&&re.length>0&&c.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:re.length})]})]}),A==="general"&&c.jsxs("div",{className:"flex flex-col lg:flex-row gap-6 lg:gap-8",children:[c.jsxs("div",{className:"space-y-6 flex-1 lg:max-w-xl",children:[c.jsxs(Nt,{children:[c.jsx(za,{children:c.jsx("h2",{className:"text-lg font-semibold text-white",children:e("settings.general")})}),c.jsxs(Dt,{className:"space-y-4",children:[c.jsxs("div",{children:[c.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[c.jsx(l0,{className:"w-4 h-4 inline mr-1"}),e("settings.language")]}),c.jsx("select",{value:n.language,onChange:Q=>n.changeLanguage(Q.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:r5.map(Q=>c.jsxs("option",{value:Q.code,children:[Q.nativeName," (",Q.name,")"]},Q.code))}),c.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:e("settings.languageDescription")})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("settings.defaultView")}),c.jsx("select",{value:E,onChange:Q=>ue(Q.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:p0.map(Q=>c.jsx("option",{value:Q.to,children:e(Q.labelKey)},Q.id))}),c.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:e("settings.defaultViewDescription")})]}),c.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Date Format"}),c.jsxs("select",{value:i.date_format||"system",onChange:Q=>at("date_format",Q.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[c.jsx("option",{value:"system",children:"System Default"}),c.jsx("option",{value:"us",children:"US (MM/DD/YYYY)"}),c.jsx("option",{value:"eu",children:"EU (DD/MM/YYYY)"}),c.jsx("option",{value:"iso",children:"ISO (YYYY-MM-DD)"})]})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Time Format"}),c.jsxs("select",{value:i.time_format||"system",onChange:Q=>at("time_format",Q.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[c.jsx("option",{value:"system",children:"System Default"}),c.jsx("option",{value:"12h",children:"12-hour (3:30 PM)"}),c.jsx("option",{value:"24h",children:"24-hour (15:30)"})]})]})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Default Printer"}),c.jsxs("select",{value:i.default_printer_id??"",onChange:Q=>at("default_printer_id",Q.target.value?Number(Q.target.value):null),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[c.jsx("option",{value:"",children:"No default (ask each time)"}),ke?.map(Q=>c.jsx("option",{value:Q.id,children:Q.name},Q.id))]}),c.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Pre-select this printer for uploads, reprints, and other operations."})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-white",children:"Sidebar order"}),c.jsx("p",{className:"text-sm text-bambu-gray",children:"Drag items in the sidebar to reorder. Reset to default order here."})]}),c.jsxs(Ie,{variant:"secondary",size:"sm",onClick:xe,children:[c.jsx(Im,{className:"w-4 h-4"}),"Reset"]})]})]})]}),c.jsxs(Nt,{children:[c.jsx(za,{children:c.jsx("h2",{className:"text-lg font-semibold text-white",children:"Archive Settings"})}),c.jsxs(Dt,{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-white",children:"Auto-archive prints"}),c.jsx("p",{className:"text-sm text-bambu-gray",children:"Automatically save 3MF files when prints complete"})]}),c.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[c.jsx("input",{type:"checkbox",checked:i.auto_archive,onChange:Q=>at("auto_archive",Q.target.checked),className:"sr-only peer"}),c.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-white",children:"Save thumbnails"}),c.jsx("p",{className:"text-sm text-bambu-gray",children:"Extract and save preview images from 3MF files"})]}),c.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[c.jsx("input",{type:"checkbox",checked:i.save_thumbnails,onChange:Q=>at("save_thumbnails",Q.target.checked),className:"sr-only peer"}),c.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-white",children:"Capture finish photo"}),c.jsx("p",{className:"text-sm text-bambu-gray",children:"Take a photo from printer camera when print completes"})]}),c.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[c.jsx("input",{type:"checkbox",checked:i.capture_finish_photo,onChange:Q=>at("capture_finish_photo",Q.target.checked),className:"sr-only peer"}),c.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),i.capture_finish_photo&&B&&!B.installed&&c.jsxs("div",{className:"flex items-start gap-2 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[c.jsx(Qr,{className:"w-5 h-5 text-yellow-500 flex-shrink-0 mt-0.5"}),c.jsxs("div",{className:"text-sm",children:[c.jsx("p",{className:"text-yellow-500 font-medium",children:"ffmpeg not installed"}),c.jsxs("p",{className:"text-bambu-gray mt-1",children:["Camera capture requires ffmpeg. Install it via"," ",c.jsx("code",{className:"bg-bambu-dark-tertiary px-1 rounded",children:"brew install ffmpeg"})," (macOS) or"," ",c.jsx("code",{className:"bg-bambu-dark-tertiary px-1 rounded",children:"apt install ffmpeg"})," (Linux)."]})]})]})]})]}),c.jsxs(Nt,{children:[c.jsx(za,{children:c.jsx("h2",{className:"text-lg font-semibold text-white",children:"Cost Tracking"})}),c.jsxs(Dt,{className:"space-y-4",children:[c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Default filament cost (per kg)"}),c.jsx("input",{type:"number",step:"0.01",min:"0",value:i.default_filament_cost,onChange:Q=>at("default_filament_cost",parseFloat(Q.target.value)||0),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Currency"}),c.jsxs("select",{value:i.currency,onChange:Q=>at("currency",Q.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[c.jsx("option",{value:"USD",children:"USD ($)"}),c.jsx("option",{value:"EUR",children:"EUR (€)"}),c.jsx("option",{value:"GBP",children:"GBP (£)"}),c.jsx("option",{value:"CHF",children:"CHF (Fr.)"}),c.jsx("option",{value:"JPY",children:"JPY (¥)"}),c.jsx("option",{value:"CNY",children:"CNY (¥)"}),c.jsx("option",{value:"CAD",children:"CAD ($)"}),c.jsx("option",{value:"AUD",children:"AUD ($)"})]})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Electricity cost per kWh"}),c.jsx("input",{type:"number",step:"0.01",min:"0",value:i.energy_cost_per_kwh,onChange:Q=>at("energy_cost_per_kwh",parseFloat(Q.target.value)||0),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Energy display mode"}),c.jsxs("select",{value:i.energy_tracking_mode||"total",onChange:Q=>at("energy_tracking_mode",Q.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[c.jsx("option",{value:"print",children:"Prints Only"}),c.jsx("option",{value:"total",children:"Total Consumption"})]}),c.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i.energy_tracking_mode==="print"?"Dashboard shows sum of energy used during prints":"Dashboard shows lifetime energy from smart plugs"})]})]})]})]}),c.jsxs("div",{className:"space-y-6 flex-1 lg:max-w-md",children:[c.jsxs(Nt,{children:[c.jsx(za,{children:c.jsx("h2",{className:"text-lg font-semibold text-white",children:"AMS Display Thresholds"})}),c.jsxs(Dt,{className:"space-y-4",children:[c.jsx("p",{className:"text-sm text-bambu-gray",children:"Configure color thresholds for AMS humidity and temperature indicators."}),c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{className:"flex items-center gap-2 text-white",children:[c.jsx(loe,{className:"w-4 h-4 text-blue-400"}),c.jsx("span",{className:"font-medium",children:"Humidity"})]}),c.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Good (green) ≤"}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("input",{type:"number",min:"0",max:"100",value:i.ams_humidity_good??40,onChange:Q=>at("ams_humidity_good",parseInt(Q.target.value)||40),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),c.jsx("span",{className:"text-bambu-gray",children:"%"})]})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Fair (orange) ≤"}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("input",{type:"number",min:"0",max:"100",value:i.ams_humidity_fair??60,onChange:Q=>at("ams_humidity_fair",parseInt(Q.target.value)||60),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),c.jsx("span",{className:"text-bambu-gray",children:"%"})]})]})]}),c.jsx("p",{className:"text-xs text-bambu-gray",children:"Above fair threshold shows as red (bad)"})]}),c.jsxs("div",{className:"space-y-3 pt-2 border-t border-bambu-dark-tertiary",children:[c.jsxs("div",{className:"flex items-center gap-2 text-white",children:[c.jsx($p,{className:"w-4 h-4 text-orange-400"}),c.jsx("span",{className:"font-medium",children:"Temperature"})]}),c.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Good (blue) ≤"}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("input",{type:"number",step:"0.5",min:"0",max:"60",value:i.ams_temp_good??28,onChange:Q=>at("ams_temp_good",parseFloat(Q.target.value)||28),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),c.jsx("span",{className:"text-bambu-gray",children:"°C"})]})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Fair (orange) ≤"}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("input",{type:"number",step:"0.5",min:"0",max:"60",value:i.ams_temp_fair??35,onChange:Q=>at("ams_temp_fair",parseFloat(Q.target.value)||35),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),c.jsx("span",{className:"text-bambu-gray",children:"°C"})]})]})]}),c.jsx("p",{className:"text-xs text-bambu-gray",children:"Above fair threshold shows as red (hot)"})]})]})]}),c.jsx(F9e,{}),c.jsx(B9e,{})]}),c.jsxs("div",{className:"space-y-6 flex-1 lg:max-w-sm",children:[c.jsxs(Nt,{children:[c.jsx(za,{children:c.jsx("h2",{className:"text-lg font-semibold text-white",children:"Updates"})}),c.jsxs(Dt,{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-white",children:"Check for updates"}),c.jsx("p",{className:"text-sm text-bambu-gray",children:"Automatically check for new versions on startup"})]}),c.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[c.jsx("input",{type:"checkbox",checked:i.check_updates,onChange:Q=>at("check_updates",Q.target.checked),className:"sr-only peer"}),c.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),c.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:[c.jsxs("div",{className:"flex items-center justify-between mb-2",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-white",children:"Current version"}),c.jsxs("p",{className:"text-sm text-bambu-gray",children:["v",j?.version||"..."]})]}),c.jsxs(Ie,{variant:"secondary",size:"sm",onClick:()=>be(),disabled:_e,children:[_e?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(qs,{className:"w-4 h-4"}),"Check now"]})]}),te?.update_available?c.jsxs("div",{className:"mt-4 p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg",children:[c.jsxs("div",{className:"flex items-start justify-between",children:[c.jsxs("div",{children:[c.jsxs("p",{className:"text-bambu-green font-medium",children:["Update available: v",te.latest_version]}),te.release_name&&te.release_name!==te.latest_version&&c.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:te.release_name}),te.release_notes&&c.jsx("p",{className:"text-sm text-bambu-gray mt-2 whitespace-pre-line line-clamp-3",children:te.release_notes})]}),te.release_url&&c.jsx("a",{href:te.release_url,target:"_blank",rel:"noopener noreferrer",className:"text-bambu-gray hover:text-white transition-colors",title:"View release on GitHub",children:c.jsx(ro,{className:"w-4 h-4"})})]}),ge?.status==="downloading"||ge?.status==="installing"?c.jsxs("div",{className:"mt-3",children:[c.jsxs("div",{className:"flex items-center gap-2 text-sm text-bambu-gray",children:[c.jsx(At,{className:"w-4 h-4 animate-spin"}),c.jsx("span",{children:ge.message})]}),c.jsx("div",{className:"mt-2 w-full bg-bambu-dark-tertiary rounded-full h-2",children:c.jsx("div",{className:"bg-bambu-green h-2 rounded-full transition-all duration-300",style:{width:`${ge.progress}%`}})})]}):ge?.status==="complete"?c.jsx("div",{className:"mt-3 p-2 bg-bambu-green/20 rounded text-sm text-bambu-green",children:ge.message}):ge?.status==="error"?c.jsx("div",{className:"mt-3 p-2 bg-red-500/20 rounded text-sm text-red-400",children:ge.error||ge.message}):c.jsxs(Ie,{className:"mt-3",onClick:()=>Ae.mutate(),disabled:Ae.isPending,children:[Ae.isPending?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(ya,{className:"w-4 h-4"}),"Install Update"]})]}):te?.error?c.jsxs("div",{className:"mt-2 p-2 bg-red-500/10 border border-red-500/30 rounded text-sm text-red-400",children:["Failed to check for updates: ",te.error]}):te&&!te.update_available?c.jsx("p",{className:"mt-2 text-sm text-bambu-gray",children:"You're running the latest version"}):null]})]})]}),c.jsxs(Nt,{children:[c.jsx(za,{children:c.jsx("h2",{className:"text-lg font-semibold text-white",children:"Data Management"})}),c.jsxs(Dt,{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-white",children:"Backup Data"}),c.jsx("p",{className:"text-sm text-bambu-gray",children:"Export settings, providers, printers, and more"})]}),c.jsxs(Ie,{variant:"secondary",size:"sm",onClick:()=>ee(!0),children:[c.jsx(ya,{className:"w-4 h-4"}),"Export"]})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-white",children:"Restore Backup"}),c.jsx("p",{className:"text-sm text-bambu-gray",children:"Import settings from a backup file with duplicate handling options"})]}),c.jsxs(Ie,{variant:"secondary",size:"sm",onClick:()=>fe(!0),children:[c.jsx(ma,{className:"w-4 h-4"}),"Restore"]})]}),c.jsx("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-white",children:"Clear Notification Logs"}),c.jsx("p",{className:"text-sm text-bambu-gray",children:"Delete notification logs older than 30 days"})]}),c.jsxs(Ie,{variant:"secondary",size:"sm",onClick:()=>W(!0),children:[c.jsx(kn,{className:"w-4 h-4"}),"Clear"]})]})}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-white",children:"Reset UI Preferences"}),c.jsx("p",{className:"text-sm text-bambu-gray",children:"Reset sidebar order, theme, view modes, and layout preferences. Printers, archives, and settings are not affected."})]}),c.jsxs(Ie,{variant:"secondary",size:"sm",onClick:()=>Y(!0),children:[c.jsx(kn,{className:"w-4 h-4"}),"Reset"]})]})]})]})]})]}),A==="plugs"&&c.jsxs("div",{className:"max-w-4xl",children:[c.jsxs("div",{className:"flex items-start justify-between mb-6",children:[c.jsxs("div",{children:[c.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[c.jsx(Ox,{className:"w-5 h-5 text-bambu-green"}),"Smart Plugs"]}),c.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:"Connect Tasmota-based smart plugs to automate power control and track energy usage for your printers."})]}),c.jsxs("div",{className:"flex items-center gap-2 pt-1 shrink-0",children:[ve&&ve.filter(Q=>Q.enabled).length>1&&c.jsxs(c.Fragment,{children:[c.jsxs(Ie,{variant:"secondary",size:"sm",className:"whitespace-nowrap",onClick:()=>U("on"),disabled:ce.isPending,title:"Turn all plugs on",children:[ce.isPending?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(fd,{className:"w-4 h-4 text-bambu-green"}),"All On"]}),c.jsxs(Ie,{variant:"secondary",size:"sm",className:"whitespace-nowrap",onClick:()=>U("off"),disabled:ce.isPending,title:"Turn all plugs off",children:[ce.isPending?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(yR,{className:"w-4 h-4 text-red-400"}),"All Off"]})]}),c.jsxs(Ie,{className:"whitespace-nowrap",onClick:()=>{u(null),o(!0)},children:[c.jsx(fr,{className:"w-4 h-4"}),"Add Smart Plug"]})]})]}),ve&&ve.length>0&&c.jsxs(Nt,{className:"mb-6",children:[c.jsx(za,{children:c.jsxs("h3",{className:"text-base font-semibold text-white flex items-center gap-2",children:[c.jsx(am,{className:"w-4 h-4 text-yellow-400"}),"Energy Summary",ut&&c.jsx(At,{className:"w-4 h-4 animate-spin text-bambu-gray ml-2"})]})}),c.jsx(Dt,{children:de?c.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[c.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[c.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[c.jsx(am,{className:"w-3 h-3"}),"Current Power"]}),c.jsxs("div",{className:"text-xl font-bold text-white",children:[de.totalPower.toFixed(1),c.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"W"})]}),c.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:[de.reachableCount,"/",de.totalPlugs," plugs online"]})]}),c.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[c.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[c.jsx(qr,{className:"w-3 h-3"}),"Today"]}),c.jsxs("div",{className:"text-xl font-bold text-white",children:[de.totalToday.toFixed(2),c.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"kWh"})]}),i&&i.energy_cost_per_kwh>0&&c.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:["~",(de.totalToday*i.energy_cost_per_kwh).toFixed(2)," ",i.currency]})]}),c.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[c.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[c.jsx(Ice,{className:"w-3 h-3"}),"Yesterday"]}),c.jsxs("div",{className:"text-xl font-bold text-white",children:[de.totalYesterday.toFixed(2),c.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"kWh"})]}),i&&i.energy_cost_per_kwh>0&&c.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:["~",(de.totalYesterday*i.energy_cost_per_kwh).toFixed(2)," ",i.currency]})]}),c.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[c.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[c.jsx(a3,{className:"w-3 h-3"}),"Total"]}),c.jsxs("div",{className:"text-xl font-bold text-white",children:[de.totalLifetime.toFixed(1),c.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"kWh"})]}),i&&i.energy_cost_per_kwh>0&&c.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:["~",(de.totalLifetime*i.energy_cost_per_kwh).toFixed(2)," ",i.currency]})]})]}):ut?null:c.jsx("p",{className:"text-sm text-bambu-gray",children:"Enable plugs to see energy summary"})})]}),je?c.jsx("div",{className:"flex justify-center py-12",children:c.jsx(At,{className:"w-8 h-8 text-bambu-green animate-spin"})}):ve&&ve.length>0?c.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:ve.map(Q=>c.jsx(M9e,{plug:Q,onEdit:Fe=>{u(Fe),o(!0)}},Q.id))}):c.jsx(Nt,{children:c.jsx(Dt,{className:"py-12",children:c.jsxs("div",{className:"text-center text-bambu-gray",children:[c.jsx(Ox,{className:"w-16 h-16 mx-auto mb-4 opacity-30"}),c.jsx("p",{className:"text-lg font-medium text-white mb-2",children:"No smart plugs configured"}),c.jsx("p",{className:"text-sm mb-4",children:"Add a Tasmota-based smart plug to track energy usage and automate power control."}),c.jsxs(Ie,{onClick:()=>{u(null),o(!0)},children:[c.jsx(fr,{className:"w-4 h-4"}),"Add Your First Smart Plug"]})]})})})]}),A==="notifications"&&c.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-8",children:[c.jsxs("div",{children:[c.jsxs("div",{className:"flex items-center justify-between mb-4",children:[c.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[c.jsx(fh,{className:"w-5 h-5 text-bambu-green"}),"Providers"]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs(Ie,{size:"sm",variant:"secondary",onClick:()=>b(!0),children:[c.jsx(o3,{className:"w-4 h-4"}),"Log"]}),H&&H.length>0&&c.jsxs(Ie,{size:"sm",variant:"secondary",onClick:()=>{st(null),Ve.mutate()},disabled:Ve.isPending,children:[Ve.isPending?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(_R,{className:"w-4 h-4"}),"Test All"]}),c.jsxs(Ie,{size:"sm",onClick:()=>{m(null),f(!0)},children:[c.jsx(fr,{className:"w-4 h-4"}),"Add"]})]})]}),c.jsx(Nt,{className:"mb-4",children:c.jsx(Dt,{className:"py-3",children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-white text-sm font-medium",children:e("settings.notificationLanguage")}),c.jsx("p",{className:"text-xs text-bambu-gray",children:e("settings.notificationLanguageDescription")})]}),c.jsx("select",{value:i.notification_language||"en",onChange:Q=>at("notification_language",Q.target.value),className:"px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:ring-1 focus:ring-bambu-green",children:r5.map(Q=>c.jsx("option",{value:Q.code,children:Q.nativeName},Q.code))})]})})}),ze&&c.jsx(Nt,{className:"mb-4",children:c.jsxs(Dt,{className:"py-3",children:[c.jsxs("div",{className:"flex items-center justify-between mb-2",children:[c.jsx("span",{className:"text-sm font-medium text-white",children:"Test Results"}),c.jsx("button",{onClick:()=>st(null),className:"text-bambu-gray hover:text-white text-xs",children:"Dismiss"})]}),c.jsxs("div",{className:"flex items-center gap-4 text-sm mb-2",children:[c.jsxs("span",{className:"flex items-center gap-1 text-bambu-green",children:[c.jsx(ds,{className:"w-4 h-4"}),ze.success," passed"]}),ze.failed>0&&c.jsxs("span",{className:"flex items-center gap-1 text-red-400",children:[c.jsx(hd,{className:"w-4 h-4"}),ze.failed," failed"]})]}),ze.results.filter(Q=>!Q.success).length>0&&c.jsx("div",{className:"space-y-1 mt-2 pt-2 border-t border-bambu-dark-tertiary",children:ze.results.filter(Q=>!Q.success).map(Q=>c.jsxs("div",{className:"text-xs text-red-400",children:[c.jsxs("span",{className:"font-medium",children:[Q.provider_name,":"]})," ",Q.message]},Q.provider_id))})]})}),z?c.jsx("div",{className:"flex justify-center py-12",children:c.jsx(At,{className:"w-6 h-6 text-bambu-green animate-spin"})}):H&&H.length>0?c.jsx("div",{className:"space-y-3",children:H.map(Q=>c.jsx(C9e,{provider:Q,onEdit:Fe=>{m(Fe),f(!0)}},Q.id))}):c.jsx(Nt,{children:c.jsx(Dt,{className:"py-8",children:c.jsxs("div",{className:"text-center text-bambu-gray",children:[c.jsx(fh,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),c.jsx("p",{className:"text-sm font-medium text-white mb-2",children:"No providers configured"}),c.jsx("p",{className:"text-xs mb-3",children:"Add a provider to receive alerts."}),c.jsxs(Ie,{size:"sm",onClick:()=>{m(null),f(!0)},children:[c.jsx(fr,{className:"w-4 h-4"}),"Add Provider"]})]})})})]}),c.jsxs("div",{children:[c.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2 mb-4",children:[c.jsx(Ya,{className:"w-5 h-5 text-bambu-green"}),"Message Templates"]}),c.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:"Customize notification messages for each event."}),we?c.jsx("div",{className:"flex justify-center py-8",children:c.jsx(At,{className:"w-6 h-6 text-bambu-green animate-spin"})}):Ne&&Ne.length>0?c.jsx("div",{className:"space-y-2",children:Ne.map(Q=>c.jsx(Nt,{className:"cursor-pointer hover:border-bambu-green/50 transition-colors",onClick:()=>y(Q),children:c.jsx(Dt,{className:"py-2.5 px-3",children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsx("p",{className:"text-white font-medium text-sm truncate",children:Q.name}),c.jsx("p",{className:"text-bambu-gray text-xs truncate mt-0.5",children:Q.title_template})]}),c.jsx("button",{className:"p-1.5 hover:bg-bambu-dark-tertiary rounded transition-colors shrink-0 ml-2",onClick:Fe=>{Fe.stopPropagation(),y(Q)},children:c.jsx(vR,{className:"w-4 h-4 text-bambu-gray"})})]})})},Q.id))}):c.jsx(Nt,{children:c.jsx(Dt,{className:"py-8",children:c.jsxs("div",{className:"text-center text-bambu-gray",children:[c.jsx(Ya,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),c.jsx("p",{className:"text-sm",children:"No templates available. Restart the backend to seed default templates."})]})})})]})]}),A==="apikeys"&&c.jsxs("div",{className:"max-w-3xl",children:[c.jsxs("div",{className:"flex items-start justify-between gap-4 mb-6",children:[c.jsxs("div",{className:"flex-1",children:[c.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[c.jsx(Op,{className:"w-5 h-5 text-bambu-green"}),"API Keys"]}),c.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:"Create API keys for external integrations and webhooks. Use these keys to control your printers from automation tools like Home Assistant."})]}),c.jsxs(Ie,{size:"sm",onClick:()=>C(!0),className:"flex-shrink-0",children:[c.jsx(fr,{className:"w-4 h-4"}),"Create Key"]})]}),L&&c.jsx(Nt,{className:"mb-6 border-bambu-green",children:c.jsx(Dt,{className:"py-4",children:c.jsxs("div",{className:"flex items-start gap-3",children:[c.jsx(ds,{className:"w-5 h-5 text-bambu-green flex-shrink-0 mt-0.5"}),c.jsxs("div",{className:"flex-1",children:[c.jsx("p",{className:"text-white font-medium mb-1",children:"API Key Created Successfully"}),c.jsx("p",{className:"text-sm text-bambu-gray mb-2",children:"Copy this key now - it won't be shown again!"}),c.jsxs("div",{className:"flex items-center gap-2 bg-bambu-dark rounded-lg p-2",children:[c.jsx("code",{className:"flex-1 text-sm text-bambu-green font-mono break-all",children:L}),c.jsx(Ie,{variant:"secondary",size:"sm",onClick:async()=>{try{if(navigator.clipboard&&navigator.clipboard.writeText)await navigator.clipboard.writeText(L);else{const Q=document.createElement("textarea");Q.value=L,Q.style.position="fixed",Q.style.left="-999999px",document.body.appendChild(Q),Q.select(),document.execCommand("copy"),document.body.removeChild(Q)}r("Key copied to clipboard")}catch{r("Failed to copy key","error")}},children:c.jsx(Dh,{className:"w-4 h-4"})})]}),c.jsx(Ie,{variant:"secondary",size:"sm",className:"mt-3",onClick:()=>q(null),children:"Dismiss"})]})]})})}),P&&c.jsxs(Nt,{className:"mb-6",children:[c.jsx(za,{children:c.jsx("h3",{className:"text-base font-semibold text-white",children:"Create New API Key"})}),c.jsxs(Dt,{className:"space-y-4",children:[c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Key Name"}),c.jsx("input",{type:"text",value:I,onChange:Q=>N(Q.target.value),placeholder:"e.g., Home Assistant, OctoPrint",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:"Permissions"}),c.jsxs("div",{className:"space-y-2",children:[c.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[c.jsx("input",{type:"checkbox",checked:D.can_read_status,onChange:Q=>F(Fe=>({...Fe,can_read_status:Q.target.checked})),className:"w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green"}),c.jsxs("div",{children:[c.jsx("span",{className:"text-white",children:"Read Status"}),c.jsx("p",{className:"text-xs text-bambu-gray",children:"View printer status and queue"})]})]}),c.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[c.jsx("input",{type:"checkbox",checked:D.can_queue,onChange:Q=>F(Fe=>({...Fe,can_queue:Q.target.checked})),className:"w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green"}),c.jsxs("div",{children:[c.jsx("span",{className:"text-white",children:"Manage Queue"}),c.jsx("p",{className:"text-xs text-bambu-gray",children:"Add and remove items from print queue"})]})]}),c.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[c.jsx("input",{type:"checkbox",checked:D.can_control_printer,onChange:Q=>F(Fe=>({...Fe,can_control_printer:Q.target.checked})),className:"w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green"}),c.jsxs("div",{children:[c.jsx("span",{className:"text-white",children:"Control Printer"}),c.jsx("p",{className:"text-xs text-bambu-gray",children:"Pause, resume, and stop prints"})]})]})]})]}),c.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[c.jsxs(Ie,{onClick:()=>J.mutate({name:I||"Unnamed Key",...D}),disabled:J.isPending,children:[J.isPending?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(fr,{className:"w-4 h-4"}),"Create Key"]}),c.jsx(Ie,{variant:"secondary",onClick:()=>C(!1),children:"Cancel"})]})]})]}),G?c.jsx("div",{className:"flex justify-center py-12",children:c.jsx(At,{className:"w-8 h-8 text-bambu-green animate-spin"})}):re&&re.length>0?c.jsx("div",{className:"space-y-3",children:re.map(Q=>c.jsx(Nt,{children:c.jsx(Dt,{className:"py-3",children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx(Op,{className:`w-5 h-5 ${Q.enabled?"text-bambu-green":"text-bambu-gray"}`}),c.jsxs("div",{children:[c.jsx("p",{className:"text-white font-medium",children:Q.name}),c.jsxs("p",{className:"text-xs text-bambu-gray",children:[Q.key_prefix,"••••••••",Q.last_used&&` · Last used: ${new Date(Q.last_used).toLocaleDateString()}`]})]})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("div",{className:"flex gap-1 text-xs",children:[Q.can_read_status&&c.jsx("span",{className:"px-1.5 py-0.5 bg-blue-500/20 text-blue-400 rounded",children:"Read"}),Q.can_queue&&c.jsx("span",{className:"px-1.5 py-0.5 bg-green-500/20 text-green-400 rounded",children:"Queue"}),Q.can_control_printer&&c.jsx("span",{className:"px-1.5 py-0.5 bg-orange-500/20 text-orange-400 rounded",children:"Control"})]}),c.jsx(Ie,{variant:"secondary",size:"sm",onClick:()=>V(Q.id),children:c.jsx(kn,{className:"w-4 h-4 text-red-400"})})]})]})})},Q.id))}):c.jsx(Nt,{children:c.jsx(Dt,{className:"py-12",children:c.jsxs("div",{className:"text-center text-bambu-gray",children:[c.jsx(Op,{className:"w-16 h-16 mx-auto mb-4 opacity-30"}),c.jsx("p",{className:"text-lg font-medium text-white mb-2",children:"No API keys"}),c.jsx("p",{className:"text-sm mb-4",children:"Create an API key to integrate with external services."}),c.jsxs(Ie,{onClick:()=>C(!0),children:[c.jsx(fr,{className:"w-4 h-4"}),"Create Your First Key"]})]})})}),c.jsxs(Nt,{className:"mt-6",children:[c.jsx(za,{children:c.jsx("h3",{className:"text-base font-semibold text-white",children:"Webhook Endpoints"})}),c.jsxs(Dt,{className:"space-y-3 text-sm",children:[c.jsxs("p",{className:"text-bambu-gray",children:["Use your API key in the ",c.jsx("code",{className:"text-bambu-green",children:"X-API-Key"})," header."]}),c.jsxs("div",{className:"space-y-2 font-mono text-xs",children:[c.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[c.jsx("span",{className:"text-blue-400",children:"GET"})," ",c.jsx("span",{className:"text-white",children:"/api/v1/webhook/status"}),c.jsx("span",{className:"text-bambu-gray",children:" - Get all printer status"})]}),c.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[c.jsx("span",{className:"text-blue-400",children:"GET"})," ",c.jsx("span",{className:"text-white",children:"/api/v1/webhook/status/:id"}),c.jsx("span",{className:"text-bambu-gray",children:" - Get specific printer status"})]}),c.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[c.jsx("span",{className:"text-green-400",children:"POST"})," ",c.jsx("span",{className:"text-white",children:"/api/v1/webhook/queue"}),c.jsx("span",{className:"text-bambu-gray",children:" - Add to print queue"})]}),c.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[c.jsx("span",{className:"text-orange-400",children:"POST"})," ",c.jsx("span",{className:"text-white",children:"/api/v1/webhook/printer/:id/pause"}),c.jsx("span",{className:"text-bambu-gray",children:" - Pause print"})]}),c.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[c.jsx("span",{className:"text-orange-400",children:"POST"})," ",c.jsx("span",{className:"text-white",children:"/api/v1/webhook/printer/:id/resume"}),c.jsx("span",{className:"text-bambu-gray",children:" - Resume print"})]}),c.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[c.jsx("span",{className:"text-red-400",children:"POST"})," ",c.jsx("span",{className:"text-white",children:"/api/v1/webhook/printer/:id/stop"}),c.jsx("span",{className:"text-bambu-gray",children:" - Stop print"})]})]})]})]})]}),R!==null&&c.jsx(Kr,{title:"Delete API Key",message:"Are you sure you want to delete this API key? Any integrations using this key will stop working.",confirmText:"Delete Key",variant:"danger",onConfirm:()=>{le.mutate(R),V(null)},onCancel:()=>V(null)}),a&&c.jsx(A9e,{plug:l,onClose:()=>{o(!1),u(null)}}),d&&c.jsx(N9e,{provider:g,onClose:()=>{f(!1),m(null)}}),x&&c.jsx(k9e,{template:x,onClose:()=>y(null)}),v&&c.jsx(D9e,{onClose:()=>b(!1)}),K&&c.jsx(Kr,{title:"Clear Notification Logs",message:"This will permanently delete all notification logs older than 30 days. This action cannot be undone.",confirmText:"Clear Logs",variant:"warning",onConfirm:async()=>{W(!1);try{const Q=await Pe.clearNotificationLogs(30);r(Q.message,"success")}catch{r("Failed to clear logs","error")}},onCancel:()=>W(!1)}),ne&&c.jsx(Kr,{title:"Reset UI Preferences",message:"This will reset all UI preferences to defaults: sidebar order, theme, dashboard layout, view modes, and sorting preferences. Your printers, archives, and server settings will NOT be affected. The page will reload after clearing.",confirmText:"Reset Preferences",variant:"default",onConfirm:()=>{Y(!1),localStorage.clear(),r("UI preferences reset. Refreshing...","success"),setTimeout(()=>window.location.reload(),1e3)},onCancel:()=>Y(!1)}),Z&&c.jsx(Kr,{title:`Turn All Plugs ${Z==="on"?"On":"Off"}`,message:`This will turn ${Z==="on"?"ON":"OFF"} all ${ve?.filter(Q=>Q.enabled).length||0} enabled smart plugs. ${Z==="off"?"Any running printers may be affected!":""}`,confirmText:`Turn All ${Z==="on"?"On":"Off"}`,variant:Z==="off"?"danger":"warning",onConfirm:()=>{const Q=Z;U(null),ce.mutate(Q)},onCancel:()=>U(null)}),$&&c.jsx(j9e,{onClose:()=>ee(!1),onExport:async Q=>{ee(!1);try{const{blob:Fe,filename:pe}=await Pe.exportBackup(Q),Ue=URL.createObjectURL(Fe),Ce=document.createElement("a");Ce.href=Ue,Ce.download=pe,Ce.click(),URL.revokeObjectURL(Ue),r("Backup downloaded","success")}catch{r("Failed to create backup","error")}}}),ae&&c.jsx(L9e,{onClose:()=>fe(!1),onRestore:async(Q,Fe)=>await Pe.importBackup(Q,Fe),onSuccess:()=>{t.invalidateQueries()}})]})}const Pee=t=>{const e=parseFloat(t);return(Math.trunc(e*1e3)/1e3).toFixed(3)},$9e=t=>t.startsWith("HH")?"HF":"S",V9e=t=>{const e=t.match(/^([A-Z]{2}\d{2})/);return e?e[1]:"HH00"},tR=t=>{const e=["High Flow_","High Flow ","Standard_","Standard ","HF_","HF ","S_","S "];for(const r of e)if(t.startsWith(r))return t.slice(r.length);const n=t.indexOf("_");return n>0?t.slice(n+1):t};function BN({profile:t,onEdit:e,onCopy:n,selectionMode:r,isSelected:i,onToggleSelect:s,note:a}){const o=$9e(t.nozzle_id),l=t.nozzle_diameter,u=()=>{r&&s?s():e()};return c.jsxs("div",{className:"flex items-center gap-2",children:[r&&c.jsx("button",{onClick:s,className:"text-bambu-gray hover:text-white transition-colors p-1",children:i?c.jsx(jh,{className:"w-4 h-4 text-bambu-green"}):c.jsx(im,{className:"w-4 h-4"})}),c.jsxs("button",{onClick:u,className:`flex-1 text-left px-3 py-2 bg-bambu-dark rounded hover:bg-bambu-dark-tertiary transition-colors ${i?"ring-1 ring-bambu-green":""}`,children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"text-bambu-green font-mono text-sm font-bold whitespace-nowrap",children:Pee(t.k_value)}),c.jsx("span",{className:"text-white text-sm truncate flex-1",title:t.name,children:t.name||"Unnamed"}),a&&c.jsx("span",{title:"Has note",children:c.jsx(LG,{className:"w-3 h-3 text-yellow-500"})}),c.jsxs("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:[o," ",l]})]}),a&&c.jsxs("div",{className:"text-xs mt-0.5 truncate text-yellow-500/70",title:a,children:["Note: ",a.length>50?a.substring(0,50)+"...":a]})]}),!r&&n&&c.jsx("button",{onClick:d=>{d.stopPropagation(),n()},className:"text-bambu-gray hover:text-white transition-colors p-1",title:"Copy profile",children:c.jsx(Dh,{className:"w-4 h-4"})})]})}function HN({profile:t,printerId:e,nozzleDiameter:n,existingProfiles:r=[],isDualNozzle:i=!1,initialNote:s="",initialNoteKey:a=null,onClose:o,onSave:l,onSaveNote:u}){const{showToast:d}=ri(),[f,g]=M.useState(t?.name||""),[m,x]=M.useState(t?.k_value?Pee(t.k_value):"0.020"),[y,v]=M.useState(t?.filament_id||""),[b,E]=M.useState(t?.nozzle_id?V9e(t.nozzle_id):"HH00"),[S,A]=M.useState(t?.nozzle_diameter||n),[T,P]=M.useState(t?[t.extruder_id]:i?[0,1]:[0]),[C,I]=M.useState(!1),[N,D]=M.useState({current:0,total:0}),[F,L]=M.useState(s),q=pr.useMemo(()=>{const Z=new Map;for(const U of r)if(U.filament_id&&!Z.has(U.filament_id)){const $=tR(U.name||"");Z.set(U.filament_id,{id:U.filament_id,name:$||U.filament_id})}return Array.from(Z.values()).sort((U,$)=>U.name.localeCompare($.name))},[r]),R=_t({mutationFn:Z=>(console.log("[KProfile] Calling API..."),Pe.setKProfile(e,Z)),onSuccess:Z=>{if(console.log("[KProfile] Save success:",Z),d("K-profile saved"),u&&F!==s){let U;F===""&&a?U=a:t&&t.slot_id>0?U=t.setting_id||`slot_${t.slot_id}_${t.filament_id}_${t.extruder_id}`:U=`name_${f}_${y}`,u(U,F)}I(!0),setTimeout(()=>{I(!1),l()},2500)},onError:Z=>{console.error("[KProfile] Save error:",Z),d(Z.message,"error"),I(!1)}}),V=_t({mutationFn:Z=>(console.log("[KProfile] Deleting profile..."),Pe.deleteKProfile(e,Z)),onSuccess:Z=>{console.log("[KProfile] Delete success:",Z),d("K-profile deleted"),I(!0),setTimeout(()=>{I(!1),o()},4e3)},onError:Z=>{console.error("[KProfile] Delete error:",Z),d(Z.message,"error"),I(!1)}}),[K,W]=M.useState(!1),ne=()=>{t&&V.mutate({slot_id:t.slot_id,extruder_id:t.extruder_id,nozzle_id:t.nozzle_id,nozzle_diameter:t.nozzle_diameter,filament_id:t.filament_id,setting_id:t.setting_id})},Y=async Z=>{if(Z.preventDefault(),i&&!t&&T.length===0){d("Please select at least one extruder","error");return}const U=parseFloat(m).toFixed(6),$=`${b}-${S}`;if(t||T.length===1){const ae={name:f,k_value:U,filament_id:y,nozzle_id:$,nozzle_diameter:S,extruder_id:t?t.extruder_id:T[0],setting_id:t?.setting_id,slot_id:t?.slot_id??0};console.log("[KProfile] Saving profile:",ae),R.mutate(ae);return}I(!0),D({current:1,total:T.length});const ee=T.map(ae=>({name:f,k_value:U,filament_id:y,nozzle_id:$,nozzle_diameter:S,extruder_id:ae,setting_id:void 0,slot_id:0}));console.log(`[KProfile] Saving ${ee.length} profiles in batch:`,ee);try{if(await Pe.setKProfilesBatch(e,ee),d(`K-profile saved to ${T.length} extruders`),u&&F){const ae=`name_${f}_${y}`;u(ae,F)}}catch(ae){console.error("[KProfile] Failed to save batch:",ae),d("Failed to save K-profiles","error"),I(!1),D({current:0,total:0});return}D({current:T.length,total:T.length}),setTimeout(()=>{I(!1),D({current:0,total:0}),l()},3e3)};return c.jsxs("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:[c.jsxs(Nt,{className:"w-full max-w-md relative",children:[C&&c.jsxs("div",{className:"absolute inset-0 bg-bambu-dark-secondary/90 flex flex-col items-center justify-center z-10 rounded-lg",children:[c.jsx(At,{className:"w-8 h-8 text-bambu-green animate-spin mb-3"}),c.jsx("p",{className:"text-white font-medium",children:N.total>1?`Saving to extruder ${N.current}/${N.total}...`:"Syncing with printer..."}),c.jsx("p",{className:"text-bambu-gray text-sm mt-1",children:"Please wait"})]}),c.jsxs(Dt,{className:"p-0",children:[c.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[c.jsx("h2",{className:"text-xl font-semibold text-white",children:t?"Edit K-Profile":"Add K-Profile"}),c.jsx("button",{onClick:o,className:"text-bambu-gray hover:text-white transition-colors",disabled:C,children:c.jsx(Gt,{className:"w-5 h-5"})})]}),c.jsxs("form",{onSubmit:Y,className:"p-4 space-y-4",children:[c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Profile Name"}),c.jsx("input",{type:"text",value:f,onChange:Z=>g(Z.target.value),disabled:!!t,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${t?"opacity-60 cursor-not-allowed":""}`,placeholder:"My PLA Profile",required:!t})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"K-Value"}),c.jsx("input",{type:"text",inputMode:"decimal",value:m,onChange:Z=>{const U=Z.target.value;(U===""||/^\d*\.?\d*$/.test(U))&&x(U)},onBlur:Z=>{const U=parseFloat(Z.target.value);isNaN(U)||x((Math.trunc(U*1e3)/1e3).toFixed(3))},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none font-mono",placeholder:"0.020",required:!0}),c.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Typical range: 0.01 - 0.06 for PLA, 0.02 - 0.10 for PETG"})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Filament"}),c.jsxs("select",{value:y,onChange:Z=>{const U=Z.target.value;if(v(U),!t&&U&&!f){const $=q.find(ee=>ee.id===U);$&&g(`${b==="HH00"?"HF":"S"} ${$.name}`)}},disabled:!!t,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${t?"opacity-60 cursor-not-allowed":""}`,required:!t,children:[c.jsx("option",{value:"",children:"Select filament..."}),t?.filament_id&&c.jsx("option",{value:t.filament_id,children:q.find(Z=>Z.id===t.filament_id)?.name||t.filament_id},t.filament_id),!t&&q.map(Z=>c.jsx("option",{value:Z.id,children:Z.name},Z.id))]}),!t&&q.length===0&&c.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"No filaments found. Create a K-profile in Bambu Studio first."})]}),c.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Flow Type"}),c.jsxs("select",{value:b,onChange:Z=>{const U=Z.target.value;if(E(U),!t&&y&&!f){const $=q.find(ee=>ee.id===y);$&&g(`${U==="HS00"?"HF":"S"} ${$.name}`)}},disabled:!!t,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${t?"opacity-60 cursor-not-allowed":""}`,children:[c.jsx("option",{value:"HH00",children:"High Flow"}),c.jsx("option",{value:"HS00",children:"Standard"})]})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Nozzle Size"}),c.jsxs("select",{value:S,onChange:Z=>A(Z.target.value),disabled:!!t,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${t?"opacity-60 cursor-not-allowed":""}`,children:[c.jsx("option",{value:"0.2",children:"0.2mm"}),c.jsx("option",{value:"0.4",children:"0.4mm"}),c.jsx("option",{value:"0.6",children:"0.6mm"}),c.jsx("option",{value:"0.8",children:"0.8mm"})]})]})]}),i&&c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:t?"Extruder":"Extruders"}),t?c.jsx("div",{className:"px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white opacity-60",children:t.extruder_id===1?"Left":"Right"}):c.jsxs("div",{className:"flex gap-4",children:[c.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[c.jsx("input",{type:"checkbox",checked:T.includes(1),onChange:Z=>{Z.target.checked?P([...T,1]):P(T.filter(U=>U!==1))},className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0 accent-bambu-green"}),c.jsx("span",{className:"text-white",children:"Left"})]}),c.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[c.jsx("input",{type:"checkbox",checked:T.includes(0),onChange:Z=>{Z.target.checked?P([...T,0]):P(T.filter(U=>U!==0))},className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0 accent-bambu-green"}),c.jsx("span",{className:"text-white",children:"Right"})]})]})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Notes (stored locally)"}),c.jsx("textarea",{value:F,onChange:Z=>L(Z.target.value),placeholder:"Add notes about this profile...",rows:2,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none resize-none"}),c.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Notes are saved in Bambuddy, not on the printer"})]}),c.jsxs("div",{className:"flex gap-2 pt-4",children:[t&&c.jsx(Ie,{type:"button",variant:"secondary",onClick:()=>W(!0),disabled:V.isPending||C,className:"text-red-500 hover:bg-red-500/10",children:V.isPending?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(kn,{className:"w-4 h-4"})}),c.jsx(Ie,{type:"button",variant:"secondary",onClick:o,disabled:C,className:"flex-1",children:"Cancel"}),c.jsxs(Ie,{type:"submit",disabled:R.isPending||C,className:"flex-1",children:[R.isPending?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(xR,{className:"w-4 h-4"}),"Save"]})]})]})]})]}),K&&c.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-[60]",children:c.jsx(Nt,{className:"w-full max-w-sm",children:c.jsxs(Dt,{className:"p-6",children:[c.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[c.jsx("div",{className:"w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center",children:c.jsx(kn,{className:"w-5 h-5 text-red-500"})}),c.jsxs("div",{children:[c.jsx("h3",{className:"text-lg font-semibold text-white",children:"Delete Profile"}),c.jsx("p",{className:"text-sm text-bambu-gray",children:"This cannot be undone"})]})]}),c.jsxs("p",{className:"text-bambu-gray mb-6",children:["Are you sure you want to delete ",c.jsxs("span",{className:"text-white font-medium",children:['"',t?.name,'"']})," from the printer?"]}),c.jsxs("div",{className:"flex gap-3",children:[c.jsx(Ie,{variant:"secondary",onClick:()=>W(!1),className:"flex-1",children:"Cancel"}),c.jsxs(Ie,{onClick:()=>{W(!1),ne()},disabled:V.isPending,className:"flex-1 bg-red-500 hover:bg-red-600 text-white",children:[V.isPending?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(kn,{className:"w-4 h-4"}),"Delete"]})]})]})})})]})}const R_={NOZZLE_DIAMETER:"bambusy_kprofiles_nozzle",SORT_OPTION:"bambusy_kprofiles_sort"};function G9e(){const{showToast:t}=ri(),[e,n]=M.useState(null),[r,i]=M.useState(()=>localStorage.getItem(R_.NOZZLE_DIAMETER)||"0.4"),[s,a]=M.useState(null),[o,l]=M.useState(!1),[u,d]=M.useState(null),[f,g]=M.useState(""),[m,x]=M.useState("all"),[y,v]=M.useState("all"),[b,E]=M.useState(()=>localStorage.getItem(R_.SORT_OPTION)||"name"),[S,A]=M.useState(!1),[T,P]=M.useState(new Set),[C,I]=M.useState(!1),[N,D]=M.useState(!1),F=G=>`${G.slot_id}_${G.extruder_id}`;M.useEffect(()=>{localStorage.setItem(R_.NOZZLE_DIAMETER,r)},[r]),M.useEffect(()=>{localStorage.setItem(R_.SORT_OPTION,b)},[b]);const{data:L,isLoading:q}=yt({queryKey:["printers"],queryFn:Pe.getPrinters}),{data:R,isLoading:V,isFetching:K,error:W,refetch:ne}=yt({queryKey:["kprofiles",e,r],queryFn:async()=>{console.log("[KProfiles] Fetching profiles for printer",e,"nozzle",r);const G=await Pe.getKProfiles(e,r);return console.log("[KProfiles] Received profiles:",G?.profiles?.length||0,"profiles"),G},enabled:!!e,retry:!1,staleTime:0,gcTime:0,refetchOnMount:"always"}),{data:Y}=yt({queryKey:["kprofiles",e,"0.4"],queryFn:()=>Pe.getKProfiles(e,"0.4"),enabled:!!e,staleTime:6e4}),{data:Z,refetch:U}=yt({queryKey:["kprofile-notes",e],queryFn:()=>Pe.getKProfileNotes(e),enabled:!!e,staleTime:3e4}),$=W?.message?.includes("not connected");M.useEffect(()=>{if(!e&&L&&L.length>0){const G=L.find(J=>J.is_active);G&&n(G.id)}},[e,L]),M.useEffect(()=>{if(e){const G=setTimeout(()=>{ne()},150);return()=>clearTimeout(G)}},[e,r]);const ee=L?.filter(G=>G.is_active)||[],ae=pr.useMemo(()=>R?.profiles?R.profiles.filter(J=>{const le=f.toLowerCase(),ke=!le||J.name.toLowerCase().includes(le)||J.filament_id.toLowerCase().includes(le),Ne=m==="all"||m==="left"&&J.extruder_id===1||m==="right"&&J.extruder_id===0,we=y==="all"||y==="hf"&&J.nozzle_id.startsWith("HH")||y==="s"&&J.nozzle_id.startsWith("HS");return ke&&Ne&&we}).sort((J,le)=>{switch(b){case"k_value":return parseFloat(J.k_value)-parseFloat(le.k_value);case"filament":return tR(J.name).localeCompare(tR(le.name));case"name":default:return J.name.localeCompare(le.name)}}):[],[R?.profiles,f,m,y,b]),fe=L?.find(G=>G.id===e),ue=fe?.nozzle_count===2;M.useEffect(()=>{const G=J=>{J.target instanceof HTMLInputElement||J.target instanceof HTMLTextAreaElement||J.target instanceof HTMLSelectElement||s||o||u||(J.key==="r"||J.key==="R"?(J.preventDefault(),ne()):J.key==="n"||J.key==="N"?(J.preventDefault(),l(!0)):J.key==="Escape"&&S&&(J.preventDefault(),A(!1),P(new Set)))};return window.addEventListener("keydown",G),()=>window.removeEventListener("keydown",G)},[s,o,u,S,ne]);const xe=M.useCallback(()=>{if(!R?.profiles||R.profiles.length===0){t("No profiles to export","error");return}const G={version:1,exported_at:new Date().toISOString(),printer:fe?.name||"Unknown",nozzle_diameter:r,profiles:R.profiles.map(Ne=>({name:Ne.name,k_value:Ne.k_value,filament_id:Ne.filament_id,nozzle_id:Ne.nozzle_id,nozzle_diameter:Ne.nozzle_diameter,extruder_id:Ne.extruder_id}))},J=new Blob([JSON.stringify(G,null,2)],{type:"application/json"}),le=URL.createObjectURL(J),ke=document.createElement("a");ke.href=le,ke.download=`kprofiles_${fe?.name||"printer"}_${r}mm_${new Date().toISOString().split("T")[0]}.json`,document.body.appendChild(ke),ke.click(),document.body.removeChild(ke),URL.revokeObjectURL(le),t(`Exported ${R.profiles.length} profiles`)},[R?.profiles,fe,r,t]),Me=M.useCallback(()=>{const G=document.createElement("input");G.type="file",G.accept=".json",G.onchange=async J=>{const le=J.target.files?.[0];if(le)try{const ke=await le.text(),Ne=JSON.parse(ke);if(!Ne.profiles||!Array.isArray(Ne.profiles)){t("Invalid file format","error");return}let we=0;for(const B of Ne.profiles)if(!(!B.name||!B.k_value||!B.filament_id))try{await Pe.setKProfile(e,{name:B.name,k_value:parseFloat(B.k_value).toFixed(6),filament_id:B.filament_id,nozzle_id:B.nozzle_id||`HH00-${r}`,nozzle_diameter:B.nozzle_diameter||r,extruder_id:B.extruder_id??0,slot_id:0}),we++,await new Promise(j=>setTimeout(j,500))}catch(j){console.error("Failed to import profile:",B.name,j)}t(`Imported ${we} of ${Ne.profiles.length} profiles`),ne()}catch(ke){console.error("Import error:",ke),t("Failed to parse import file","error")}},G.click()},[e,r,t,ne]),se=M.useCallback(G=>{P(J=>{const le=new Set(J);return le.has(G)?le.delete(G):le.add(G),le})},[]),ve=M.useCallback(()=>{P(new Set(ae.map(G=>F(G))))},[ae,F]),je=M.useCallback(()=>{T.size!==0&&I(!0)},[T.size]),de=M.useCallback(async()=>{const G=ae.filter(le=>T.has(F(le)));D(!0);let J=0;for(const le of G)try{await Pe.deleteKProfile(e,{slot_id:le.slot_id,extruder_id:le.extruder_id,nozzle_id:le.nozzle_id,nozzle_diameter:le.nozzle_diameter,filament_id:le.filament_id,setting_id:le.setting_id}),J++,await new Promise(ke=>setTimeout(ke,300))}catch(ke){console.error("Failed to delete profile:",le.name,ke)}t(`Deleted ${J} profiles`),D(!1),I(!1),A(!1),P(new Set),ne()},[e,T,ae,t,ne,F]),ut=M.useCallback(G=>{const J=[];return G.setting_id&&J.push(G.setting_id),J.push(`slot_${G.slot_id}_${G.filament_id}_${G.extruder_id}`),J.push(`name_${G.name}_${G.filament_id}`),J},[]),H=M.useCallback(async(G,J)=>{if(e)try{await Pe.setKProfileNote(e,G,J),U()}catch(le){console.error("Failed to save note:",le),t("Failed to save note","error")}},[e,U,t]),z=M.useCallback(G=>{if(!Z?.notes)return{note:"",key:null};const J=ut(G);for(const le of J)if(Z.notes[le])return{note:Z.notes[le],key:le};return{note:"",key:null}},[Z,ut]),re=M.useCallback(G=>z(G).note,[z]);return q?c.jsx("div",{className:"flex justify-center py-12",children:c.jsx(At,{className:"w-8 h-8 text-bambu-green animate-spin"})}):!L||L.length===0?c.jsx(Nt,{children:c.jsxs(Dt,{className:"py-12 text-center",children:[c.jsx(Oo,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),c.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"No Printers Configured"}),c.jsx("p",{className:"text-bambu-gray",children:"Add a printer in Settings to manage K-profiles"})]})}):ee.length===0?c.jsx(Nt,{children:c.jsxs(Dt,{className:"py-12 text-center",children:[c.jsx(jo,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),c.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"No Active Printers"}),c.jsx("p",{className:"text-bambu-gray",children:"Enable a printer connection to view its K-profiles"})]})}):c.jsxs(c.Fragment,{children:[K&&!V&&c.jsxs("div",{className:"fixed inset-0 bg-black/50 flex flex-col items-center justify-center z-40",children:[c.jsx(At,{className:"w-10 h-10 text-bambu-green animate-spin mb-3"}),c.jsx("p",{className:"text-white font-medium",children:"Loading K-Profiles..."})]}),c.jsxs("div",{className:"flex flex-wrap gap-4 mb-6",children:[c.jsxs("div",{className:"flex-1 min-w-48",children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Printer"}),c.jsx("select",{value:e||"",onChange:G=>n(parseInt(G.target.value)),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:ee.map(G=>c.jsx("option",{value:G.id,children:G.name},G.id))})]}),c.jsxs("div",{className:"w-32",children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Nozzle"}),c.jsxs("select",{value:r,onChange:G=>i(G.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[c.jsx("option",{value:"0.2",children:"0.2mm"}),c.jsx("option",{value:"0.4",children:"0.4mm"}),c.jsx("option",{value:"0.6",children:"0.6mm"}),c.jsx("option",{value:"0.8",children:"0.8mm"})]})]}),c.jsxs("div",{className:"flex items-end gap-2",children:[c.jsxs(Ie,{variant:"secondary",onClick:()=>ne(),disabled:K,children:[c.jsx(qs,{className:`w-4 h-4 ${K?"animate-spin":""}`}),"Refresh"]}),c.jsxs(Ie,{onClick:()=>l(!0),children:[c.jsx(fr,{className:"w-4 h-4"}),"Add Profile"]})]})]}),c.jsxs("div",{className:"flex flex-wrap gap-4 mb-4",children:[c.jsxs("div",{className:"flex-1 min-w-48 relative",children:[c.jsx(Qu,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),c.jsx("input",{type:"text",value:f,onChange:G=>g(G.target.value),placeholder:"Search by name or filament...",className:"w-full pl-10 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]}),ue&&c.jsx("div",{className:"w-36",children:c.jsxs("select",{value:m,onChange:G=>x(G.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[c.jsx("option",{value:"all",children:"All Extruders"}),c.jsx("option",{value:"left",children:"Left Only"}),c.jsx("option",{value:"right",children:"Right Only"})]})}),c.jsx("div",{className:"w-32",children:c.jsxs("select",{value:y,onChange:G=>v(G.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[c.jsx("option",{value:"all",children:"All Flow"}),c.jsx("option",{value:"hf",children:"HF Only"}),c.jsx("option",{value:"s",children:"S Only"})]})}),c.jsx("div",{className:"w-32",children:c.jsxs("select",{value:b,onChange:G=>E(G.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[c.jsx("option",{value:"name",children:"Sort: Name"}),c.jsx("option",{value:"k_value",children:"Sort: K-Value"}),c.jsx("option",{value:"filament",children:"Sort: Filament"})]})})]}),c.jsxs("div",{className:"flex flex-wrap gap-2 mb-6",children:[c.jsxs(Ie,{variant:"secondary",onClick:xe,disabled:!R?.profiles?.length,title:"Export profiles to JSON",children:[c.jsx(ya,{className:"w-4 h-4"}),"Export"]}),c.jsxs(Ie,{variant:"secondary",onClick:Me,title:"Import profiles from JSON",children:[c.jsx(ma,{className:"w-4 h-4"}),"Import"]}),c.jsx("div",{className:"flex-1"}),S?c.jsxs(c.Fragment,{children:[c.jsxs(Ie,{variant:"secondary",onClick:ve,title:"Select all visible profiles",children:[c.jsx(jh,{className:"w-4 h-4"}),"Select All"]}),c.jsxs(Ie,{variant:"secondary",onClick:je,disabled:T.size===0,className:"text-red-500 hover:bg-red-500/10",title:`Delete ${T.size} selected profiles`,children:[c.jsx(kn,{className:"w-4 h-4"}),"Delete (",T.size,")"]}),c.jsxs(Ie,{variant:"secondary",onClick:()=>{A(!1),P(new Set)},children:[c.jsx(Gt,{className:"w-4 h-4"}),"Cancel"]})]}):c.jsxs(Ie,{variant:"secondary",onClick:()=>A(!0),disabled:!ae.length,title:"Enter selection mode for bulk delete",children:[c.jsx(jh,{className:"w-4 h-4"}),"Select"]})]}),V?c.jsx("div",{className:"flex justify-center py-12",children:c.jsx(At,{className:"w-8 h-8 text-bambu-green animate-spin"})}):$?c.jsx(Nt,{children:c.jsxs(Dt,{className:"py-12 text-center",children:[c.jsx(SR,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),c.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"Printer Offline"}),c.jsx("p",{className:"text-bambu-gray mb-4",children:"The selected printer is not connected. Power it on to view K-profiles."}),c.jsxs(Ie,{variant:"secondary",onClick:()=>ne(),children:[c.jsx(qs,{className:"w-4 h-4"}),"Retry"]})]})}):ae.length>0?ue?c.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[c.jsxs("div",{children:[c.jsx("h3",{className:"text-sm font-medium text-bambu-gray mb-2 px-1",children:"Left Extruder"}),c.jsx("div",{className:"space-y-1",children:ae.filter(G=>G.extruder_id===1).map(G=>c.jsx(BN,{profile:G,onEdit:()=>a(G),onCopy:()=>d(G),selectionMode:S,isSelected:T.has(F(G)),onToggleSelect:()=>se(F(G)),note:re(G)},F(G)))})]}),c.jsxs("div",{children:[c.jsx("h3",{className:"text-sm font-medium text-bambu-gray mb-2 px-1",children:"Right Extruder"}),c.jsx("div",{className:"space-y-1",children:ae.filter(G=>G.extruder_id===0).map(G=>c.jsx(BN,{profile:G,onEdit:()=>a(G),onCopy:()=>d(G),selectionMode:S,isSelected:T.has(F(G)),onToggleSelect:()=>se(F(G)),note:re(G)},F(G)))})]})]}):c.jsx("div",{className:"space-y-1",children:ae.map(G=>c.jsx(BN,{profile:G,onEdit:()=>a(G),onCopy:()=>d(G),selectionMode:S,isSelected:T.has(F(G)),onToggleSelect:()=>se(F(G)),note:re(G)},F(G)))}):f||m!=="all"||y!=="all"?c.jsx(Nt,{children:c.jsxs(Dt,{className:"py-12 text-center",children:[c.jsx(Qu,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),c.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"No Matching Profiles"}),c.jsx("p",{className:"text-bambu-gray",children:"No profiles match your search criteria"})]})}):c.jsx(Nt,{children:c.jsxs(Dt,{className:"py-12 text-center",children:[c.jsx(xR,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),c.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"No K-Profiles"}),c.jsxs("p",{className:"text-bambu-gray mb-4",children:["No pressure advance profiles found for ",r,"mm nozzle"]}),c.jsxs(Ie,{onClick:()=>l(!0),children:[c.jsx(fr,{className:"w-4 h-4"}),"Create First Profile"]})]})}),s&&e&&(()=>{const{note:G,key:J}=z(s);return c.jsx(HN,{profile:s,printerId:e,nozzleDiameter:r,existingProfiles:Y?.profiles||R?.profiles,isDualNozzle:ue,initialNote:G,initialNoteKey:J,onSaveNote:H,onClose:()=>{console.log("[KProfiles] Edit modal onClose - refetching profiles..."),a(null),ne()},onSave:()=>{a(null),ne()}})})(),o&&e&&c.jsx(HN,{printerId:e,nozzleDiameter:r,existingProfiles:Y?.profiles||R?.profiles,isDualNozzle:ue,onSaveNote:H,onClose:()=>{l(!1),ne()},onSave:()=>{l(!1),ne()}}),u&&e&&c.jsx(HN,{printerId:e,nozzleDiameter:r,existingProfiles:Y?.profiles||R?.profiles,isDualNozzle:ue,onSaveNote:H,profile:{...u,slot_id:0,name:`${u.name} (Copy)`},onClose:()=>{d(null),ne()},onSave:()=>{d(null),ne()}}),C&&c.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:c.jsx(Nt,{className:"w-full max-w-sm",children:c.jsxs(Dt,{className:"p-6",children:[c.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[c.jsx("div",{className:"w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center",children:c.jsx(kn,{className:"w-5 h-5 text-red-500"})}),c.jsxs("div",{children:[c.jsx("h3",{className:"text-lg font-semibold text-white",children:"Delete Profiles"}),c.jsx("p",{className:"text-sm text-bambu-gray",children:"This cannot be undone"})]})]}),c.jsxs("p",{className:"text-bambu-gray mb-6",children:["Are you sure you want to delete ",c.jsx("span",{className:"text-white font-medium",children:T.size})," selected profiles from the printer?"]}),c.jsxs("div",{className:"flex gap-3",children:[c.jsx(Ie,{variant:"secondary",onClick:()=>I(!1),disabled:N,className:"flex-1",children:"Cancel"}),c.jsxs(Ie,{onClick:de,disabled:N,className:"flex-1 bg-red-500 hover:bg-red-600 text-white",children:[N?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(kn,{className:"w-4 h-4"}),"Delete"]})]})]})})})]})}function Gj(t,e){const n=`${t} ${e||""}`,r=n.match(/@?\s*(?:BBL\s+)?(?:Bambu\s+Lab\s+)?([XPAH][1-9][A-Z]?(?:\s*(?:Carbon|mini))?|H2D)/i),i=r?r[1].trim():null,s=n.match(/(\d+\.?\d*)\s*(?:mm\s*)?nozzle|nozzle\s*(\d+\.?\d*)/i),a=s?(s[1]||s[2])+"mm":null,o=n.match(/(\d+\.?\d*)mm\s*(?:Standard|Fine|Extra Fine|Draft|Quality)?/i),l=o?o[1]+"mm":null,u=n.match(/\b(PLA|PETG|ABS|ASA|TPU|PC|PA|PVA|HIPS|PP|PET(?:-?CF)?|PA(?:-?CF)?|PLA(?:-?CF)?)\b/i),d=u?u[1].toUpperCase():null;return{printer:i,nozzle:a,layerHeight:l,filamentType:d}}function J0(t){return/^(P[FPM]US|PF\d|PP\d)/.test(t)}function W9e(t){const e=new Date(t),r=new Date().getTime()-e.getTime(),i=Math.floor(r/6e4),s=Math.floor(r/36e5),a=Math.floor(r/864e5);return i<1?"Just now":i<60?`${i}m ago`:s<24?`${s}h ago`:a<7?`${a}d ago`:e.toLocaleDateString()}function q9e({onSuccess:t}){const{showToast:e}=ri(),[n,r]=M.useState("email"),[i,s]=M.useState(""),[a,o]=M.useState(""),[l,u]=M.useState(""),[d,f]=M.useState(""),[g,m]=M.useState("global"),x=_t({mutationFn:()=>Pe.cloudLogin(i,a,g),onSuccess:S=>{S.success?(e("Logged in successfully"),t()):S.needs_verification?(e("Verification code sent to your email"),r("code")):e(S.message,"error")},onError:S=>e(S.message,"error")}),y=_t({mutationFn:()=>Pe.cloudVerify(i,l),onSuccess:S=>{S.success?(e("Logged in successfully"),t()):e(S.message,"error")},onError:S=>e(S.message,"error")}),v=_t({mutationFn:()=>Pe.cloudSetToken(d),onSuccess:()=>{e("Token set successfully"),t()},onError:S=>e(S.message,"error")}),b=S=>{S.preventDefault(),n==="email"?x.mutate():n==="code"?y.mutate():n==="token"&&v.mutate()},E=x.isPending||y.isPending||v.isPending;return c.jsx(Nt,{className:"max-w-md mx-auto",children:c.jsxs(Dt,{children:[c.jsxs("div",{className:"text-center mb-6",children:[c.jsx("div",{className:"inline-flex items-center justify-center w-12 h-12 rounded-xl bg-bambu-green/20 mb-3",children:c.jsx(gS,{className:"w-6 h-6 text-bambu-green"})}),c.jsx("h2",{className:"text-xl font-semibold text-white",children:"Connect to Bambu Cloud"}),c.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:"Sync your slicer presets across devices"})]}),c.jsxs("form",{onSubmit:b,className:"space-y-4",children:[n==="email"&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Email"}),c.jsx("input",{type:"email",value:i,onChange:S=>s(S.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none",placeholder:"your@email.com",required:!0})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Password"}),c.jsx("input",{type:"password",value:a,onChange:S=>o(S.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none",placeholder:"••••••••",required:!0})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Region"}),c.jsxs("select",{value:g,onChange:S=>m(S.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[c.jsx("option",{value:"global",children:"Global"}),c.jsx("option",{value:"china",children:"China"})]})]})]}),n==="code"&&c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Verification Code"}),c.jsxs("p",{className:"text-xs text-bambu-gray mb-2",children:["Check your email (",i,") for a 6-digit code"]}),c.jsx("input",{type:"text",value:l,onChange:S=>u(S.target.value.replace(/\D/g,"").slice(0,6)),className:"w-full px-3 py-3 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-center text-2xl tracking-widest font-mono focus:border-bambu-green focus:outline-none",placeholder:"000000",maxLength:6,required:!0})]}),n==="token"&&c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Access Token"}),c.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:"Paste your Bambu Lab access token (from Bambu Studio)"}),c.jsx("textarea",{value:d,onChange:S=>f(S.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-xs font-mono placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none resize-none",placeholder:"eyJ...",rows:4,required:!0})]}),c.jsxs("div",{className:"flex gap-2",children:[n==="code"&&c.jsx(Ie,{type:"button",variant:"secondary",onClick:()=>r("email"),className:"flex-1",children:"Back"}),c.jsxs(Ie,{type:"submit",disabled:E,className:"flex-1",children:[E?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(E5,{className:"w-4 h-4"}),n==="email"?"Login":n==="code"?"Verify":"Set Token"]})]}),n==="email"&&c.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:c.jsxs("button",{type:"button",onClick:()=>r("token"),className:"text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors",children:[c.jsx(Op,{className:"w-4 h-4"}),"Use access token instead"]})}),n==="token"&&c.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:c.jsxs("button",{type:"button",onClick:()=>r("email"),className:"text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors",children:[c.jsx(E5,{className:"w-4 h-4"}),"Login with email instead"]})})]})]})})}function Ap({label:t,value:e,options:n,onChange:r}){const[i,s]=M.useState(!1),a=n.find(o=>o.value===e);return c.jsxs("div",{className:"relative",children:[c.jsxs("button",{onClick:()=>s(!i),className:"flex items-center gap-2 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-white hover:border-bambu-gray-dark transition-colors",children:[c.jsxs("span",{className:"text-bambu-gray",children:[t,":"]}),c.jsx("span",{children:a?.label||"All"}),c.jsx(ef,{className:`w-4 h-4 text-bambu-gray transition-transform ${i?"rotate-180":""}`})]}),i&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>s(!1)}),c.jsx("div",{className:"absolute top-full left-0 mt-1 min-w-[160px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20 py-1 max-h-60 overflow-y-auto",children:n.map(o=>c.jsxs("button",{onClick:()=>{r(o.value),s(!1)},className:`w-full px-3 py-2 text-left text-sm flex items-center justify-between hover:bg-bambu-dark-tertiary transition-colors ${e===o.value?"text-bambu-green":"text-white"}`,children:[c.jsx("span",{children:o.label}),o.count!==void 0&&c.jsx("span",{className:"text-bambu-gray text-xs",children:o.count})]},o.value))})]})]})}function K9e(){const[t,e]=M.useState(!1);M.useEffect(()=>{const r=()=>{e(window.scrollY>300)};return window.addEventListener("scroll",r),()=>window.removeEventListener("scroll",r)},[]);const n=()=>{window.scrollTo({top:0,behavior:"smooth"})};return t?c.jsx("button",{onClick:n,className:"fixed bottom-6 right-6 p-3 bg-bambu-green hover:bg-bambu-green-light text-white rounded-full shadow-lg shadow-bambu-green/25 transition-all z-40","aria-label":"Scroll to top",children:c.jsx(nm,{className:"w-5 h-5"})}):null}function $N({setting:t,onClick:e,onDuplicate:n,compareMode:r,isCompareSelected:i,compareIndex:s,compareDisabled:a}){const o=Gj(t.name),l=J0(t.setting_id);return c.jsxs("div",{className:"flex items-center gap-2 group",children:[c.jsx("button",{onClick:e,disabled:a,className:`flex-1 text-left px-3 py-2 rounded transition-colors ${i?"bg-blue-500/20 border border-blue-500/50":a?"bg-bambu-dark/50 opacity-40 cursor-not-allowed":"bg-bambu-dark hover:bg-bambu-dark-tertiary"} ${r&&!a?"cursor-pointer":""}`,children:c.jsxs("div",{className:"flex items-center gap-2",children:[i&&s!==void 0&&c.jsx("span",{className:"flex-shrink-0 w-5 h-5 rounded-full bg-blue-500 text-white text-xs flex items-center justify-center font-medium",children:s+1}),!i&&l&&c.jsx("span",{className:"flex-shrink-0 w-1.5 h-1.5 rounded-full bg-bambu-green",title:"My preset (editable)"}),c.jsx("span",{className:"text-white text-sm truncate flex-1",title:t.name,children:t.name}),o.filamentType&&t.type==="filament"&&c.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:o.filamentType}),o.layerHeight&&t.type==="process"&&c.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:o.layerHeight}),o.printer&&c.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:o.printer})]})}),c.jsx("button",{onClick:u=>{u.stopPropagation(),n()},className:"opacity-0 group-hover:opacity-100 text-bambu-gray hover:text-white transition-all p-1",title:"Duplicate",children:c.jsx(Dh,{className:"w-4 h-4"})})]})}function nR(t,e=0){const n=" ".repeat(e);if(t===null)return"null";if(t===void 0)return"undefined";if(typeof t=="string"){if(t.includes("\\n")||t.includes(` `)){const i=t.replace(/\\n/g,` `).replace(/\\"/g,'"').replace(/\\t/g," ").split(` `);if(i.length>1)return`""" @@ -8608,4 +8608,4 @@ Accuracy: ${t.time_accuracy.toFixed(0)}%`:t.actual_time_seconds?`Actual: ${hx(t. `+n+"]";if(typeof t=="object"){const r=Object.entries(t);return r.length===0?"{}":`{ `+r.map(([s,a])=>n+" "+JSON.stringify(s)+": "+nR(a,e+1)).join(`, `)+` -`+n+"}"}return String(t)}function X9e({setting:t,onClose:e,onDeleted:n,onDuplicate:r,onEdit:i}){const{showToast:s}=ri(),a=Sn(),[o,l]=M.useState(!1),{data:u,isLoading:d}=yt({queryKey:["cloudSettingDetail",t.setting_id],queryFn:()=>Pe.getCloudSettingDetail(t.setting_id)}),f=_t({mutationFn:()=>Pe.deleteCloudSetting(t.setting_id),onSuccess:()=>{s("Preset deleted"),a.invalidateQueries({queryKey:["cloudSettings"]}),n()},onError:x=>s(x.message,"error")}),g=J0(t.setting_id),m=Gj(t.name,u?.setting?.inherits);return c.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:c.jsx(Nt,{className:"w-full max-w-3xl max-h-[90vh] flex flex-col overflow-hidden",children:c.jsxs(Dt,{className:"p-0 flex flex-col min-h-0 flex-1",children:[c.jsxs("div",{className:"flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("h2",{className:"text-xl font-semibold text-white truncate",children:t.name}),g&&c.jsx("span",{className:"px-2 py-0.5 text-xs font-medium bg-bambu-green/20 text-bambu-green rounded-full",children:"Editable"})]}),c.jsxs("div",{className:"flex items-center gap-2 mt-1 text-sm text-bambu-gray",children:[c.jsxs("span",{className:"capitalize",children:[t.type," preset"]}),m.printer&&c.jsxs(c.Fragment,{children:[c.jsx("span",{children:"•"}),c.jsx("span",{children:m.printer})]})]})]}),c.jsx("button",{onClick:e,className:"p-2 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors",children:c.jsx(Gt,{className:"w-5 h-5"})})]}),c.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto p-4",children:d?c.jsx("div",{className:"flex items-center justify-center py-16",children:c.jsx(At,{className:"w-8 h-8 text-bambu-green animate-spin"})}):u?c.jsx("pre",{className:"text-xs text-bambu-gray font-mono whitespace-pre-wrap break-all bg-bambu-dark p-4 rounded-lg border border-bambu-dark-tertiary overflow-x-auto max-w-full",children:nR(u)}):c.jsx("div",{className:"text-center py-16 text-bambu-gray",children:"Failed to load preset details"})}),o?c.jsxs("div",{className:"flex-shrink-0 p-4 border-t border-bambu-dark-tertiary bg-red-500/5",children:[c.jsxs("div",{className:"flex items-center gap-2 mb-3 text-red-400",children:[c.jsx(Qr,{className:"w-5 h-5"}),c.jsx("span",{className:"font-medium",children:"Delete this preset?"})]}),c.jsxs("p",{className:"text-sm text-bambu-gray mb-4",children:['This will permanently delete "',t.name,'" from Bambu Cloud. This cannot be undone.']}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(Ie,{variant:"secondary",onClick:()=>l(!1),disabled:f.isPending,className:"flex-1",children:"Cancel"}),c.jsxs(Ie,{variant:"danger",onClick:()=>f.mutate(),disabled:f.isPending,className:"flex-1",children:[f.isPending?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(kn,{className:"w-4 h-4"}),"Delete"]})]})]}):c.jsx("div",{className:"flex-shrink-0 p-4 border-t border-bambu-dark-tertiary",children:c.jsxs("div",{className:"flex gap-2",children:[c.jsx(Ie,{variant:"secondary",onClick:e,className:"flex-1",children:"Close"}),c.jsxs(Ie,{variant:"secondary",onClick:r,children:[c.jsx(Dh,{className:"w-4 h-4"}),"Duplicate"]}),g&&c.jsxs(c.Fragment,{children:[c.jsxs(Ie,{variant:"secondary",onClick:i,disabled:d||!u,children:[c.jsx(Zu,{className:"w-4 h-4"}),"Edit"]}),c.jsx(Ie,{variant:"danger",onClick:()=>l(!0),children:c.jsx(kn,{className:"w-4 h-4"})})]})]})})]})})})}function Ree(){try{const t=localStorage.getItem("bambusy_preset_templates");return t?JSON.parse(t):[]}catch{return[]}}function Dee(t){localStorage.setItem("bambusy_preset_templates",JSON.stringify(t))}function Y9e({onClose:t,onApply:e}){const{showToast:n}=ri(),[r,i]=M.useState(Ree),[s,a]=M.useState("all"),[o,l]=M.useState(null),[u,d]=M.useState(""),[f,g]=M.useState(""),[m,x]=M.useState("{}"),[y,v]=M.useState(null),[b,E]=M.useState(null),S=s==="all"?r:r.filter(L=>L.type===s),A=L=>{i(L),Dee(L)},T=L=>{const q=r.filter(R=>R.id!==L);A(q),E(null),n("Template deleted")},P=L=>{l(L.id),d(L.name),g(L.description),x(JSON.stringify(L.settings,null,2)),v(null)},C=()=>{if(!(!o||!u.trim()))try{const L=JSON.parse(m),q=r.map(R=>R.id===o?{...R,name:u.trim(),description:f.trim(),settings:L}:R);A(q),l(null),n("Template updated")}catch(L){v(L.message)}},I=()=>{l(null),d(""),g(""),x("{}"),v(null)},N=L=>{const q=r.map(R=>R.id===L?{...R,showInModal:!R.showInModal}:R);A(q)},D={filament:{label:"Filament",icon:pR,color:"text-amber-400"},print:{label:"Process",icon:vS,color:"text-blue-400"},printer:{label:"Printer",icon:jo,color:"text-purple-400"}},F=b?r.find(L=>L.id===b):null;return M.useEffect(()=>{const L=q=>{q.key==="Escape"&&(b?E(null):o?I():t())};return window.addEventListener("keydown",L),()=>window.removeEventListener("keydown",L)},[b,o,t]),c.jsxs("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:[F&&c.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-60",children:c.jsx(Nt,{className:"w-full max-w-md",children:c.jsxs(Dt,{className:"p-6",children:[c.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[c.jsx("div",{className:"p-2 bg-red-500/20 rounded-lg",children:c.jsx(Qr,{className:"w-6 h-6 text-red-400"})}),c.jsxs("div",{children:[c.jsx("h3",{className:"text-lg font-semibold text-white",children:"Delete Template"}),c.jsx("p",{className:"text-sm text-bambu-gray",children:"This action cannot be undone"})]})]}),c.jsxs("p",{className:"text-white mb-6",children:['Are you sure you want to delete "',c.jsx("span",{className:"font-medium",children:F.name}),'"?']}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(Ie,{variant:"secondary",onClick:()=>E(null),className:"flex-1",children:"Cancel"}),c.jsxs(Ie,{onClick:()=>T(b),className:"flex-1 bg-red-500 hover:bg-red-600",children:[c.jsx(kn,{className:"w-4 h-4"}),"Delete"]})]})]})})}),c.jsx(Nt,{className:"w-full max-w-2xl max-h-[80vh] flex flex-col",children:c.jsxs(Dt,{className:"p-0 flex flex-col h-full",children:[c.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[c.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[c.jsx(h0,{className:"w-5 h-5 text-amber-400"}),"Quick Templates"]}),c.jsx("button",{onClick:t,className:"text-bambu-gray hover:text-white",children:c.jsx(Gt,{className:"w-5 h-5"})})]}),c.jsxs("div",{className:"flex items-center gap-2 p-4 border-b border-bambu-dark-tertiary",children:[c.jsx("span",{className:"text-sm text-bambu-gray",children:"Type:"}),["all","filament","print","printer"].map(L=>c.jsx("button",{onClick:()=>a(L),className:`px-3 py-1 text-sm rounded-lg transition-colors ${s===L?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:L==="all"?"All":D[L].label},L))]}),c.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:S.length===0?c.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[c.jsx(h0,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),c.jsx("p",{children:"No templates yet"}),c.jsx("p",{className:"text-sm mt-1",children:"Create templates from the preset editor"})]}):c.jsx("div",{className:"space-y-2",children:S.map(L=>{const q=D[L.type],R=q.icon;return o===L.id?c.jsxs("div",{className:"p-4 bg-bambu-dark rounded-lg border border-bambu-green",children:[c.jsxs("div",{className:"grid grid-cols-2 gap-3 mb-3",children:[c.jsx("input",{type:"text",value:u,onChange:V=>d(V.target.value),placeholder:"Template name",className:"px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none",autoFocus:!0}),c.jsx("input",{type:"text",value:f,onChange:V=>g(V.target.value),placeholder:"Description",className:"px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none"})]}),c.jsxs("div",{className:"mb-3",children:[c.jsx("label",{className:"text-xs text-bambu-gray mb-1 block",children:"Settings (JSON)"}),c.jsx("textarea",{value:m,onChange:V=>{x(V.target.value),v(null)},rows:6,className:`w-full px-3 py-2 bg-bambu-dark-secondary border rounded text-white text-sm font-mono focus:outline-none ${y?"border-red-500":"border-bambu-dark-tertiary focus:border-bambu-green"}`}),y&&c.jsx("p",{className:"text-xs text-red-400 mt-1",children:y})]}),c.jsxs("div",{className:"flex gap-2",children:[c.jsxs(Ie,{size:"sm",onClick:C,disabled:!u.trim(),children:[c.jsx(To,{className:"w-4 h-4"}),"Save"]}),c.jsx(Ie,{size:"sm",variant:"secondary",onClick:I,children:"Cancel"})]})]},L.id):c.jsxs("div",{className:"flex items-center gap-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary hover:border-bambu-gray-dark transition-colors",children:[c.jsx(R,{className:`w-5 h-5 ${q.color} flex-shrink-0`}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsx("p",{className:"text-sm font-medium text-white",children:L.name}),c.jsx("p",{className:"text-xs text-bambu-gray truncate",children:L.description})]}),c.jsxs("span",{className:"text-xs text-bambu-gray-dark px-2 py-1 bg-bambu-dark-secondary rounded",children:[Object.keys(L.settings).length," fields"]}),c.jsx("button",{onClick:()=>N(L.id),className:`p-1 transition-colors ${L.showInModal?"text-bambu-green hover:text-bambu-green/70":"text-bambu-gray hover:text-white"}`,title:L.showInModal?"Shown in modals":"Hidden in modals",children:L.showInModal?c.jsx(o0,{className:"w-4 h-4"}):c.jsx(mR,{className:"w-4 h-4"})}),c.jsx("button",{onClick:()=>e(L),className:"px-3 py-1 text-xs bg-bambu-green/20 text-bambu-green rounded hover:bg-bambu-green/30 transition-colors",children:"Apply"}),c.jsx("button",{onClick:()=>P(L),className:"p-1 text-bambu-gray hover:text-white",title:"Edit",children:c.jsx(Zu,{className:"w-4 h-4"})}),c.jsx("button",{onClick:()=>E(L.id),className:"p-1 text-bambu-gray hover:text-red-400",title:"Delete",children:c.jsx(kn,{className:"w-4 h-4"})})]},L.id)})})})]})})]})}function Oee({onClose:t,leftPreset:e,rightPreset:n,leftLabel:r,rightLabel:i}){const[s,a]=M.useState("changes"),[o,l]=M.useState(""),u=M.useMemo(()=>{const m=new Set([...Object.keys(e),...Object.keys(n)]),x=[];for(const y of m){if(y==="inherits"||y==="version")continue;const v=e[y],b=n[y],E=y in e,S=y in n;let A;!E&&S?A="added":E&&!S?A="removed":JSON.stringify(v)!==JSON.stringify(b)?A="changed":A="same",x.push({key:y,left:v,right:b,status:A})}return x.sort((y,v)=>{const b={changed:0,added:1,removed:2,same:3};return b[y.status]!==b[v.status]?b[y.status]-b[v.status]:y.key.localeCompare(v.key)})},[e,n]),d=M.useMemo(()=>{let m=[...u];if(s==="changes"&&(m=m.filter(x=>x.status!=="same")),o){const x=o.toLowerCase();m=m.filter(y=>y.key.toLowerCase().includes(x)||String(y.left).toLowerCase().includes(x)||String(y.right).toLowerCase().includes(x))}return m},[u,s,o]),f=M.useMemo(()=>({added:u.filter(m=>m.status==="added").length,removed:u.filter(m=>m.status==="removed").length,changed:u.filter(m=>m.status==="changed").length,same:u.filter(m=>m.status==="same").length}),[u]),g=m=>{if(m===void 0)return"—";if(m===null)return"null";if(Array.isArray(m))return m.length===0?"[]":m.length===1?String(m[0]):m.join(", ");if(typeof m=="object")return JSON.stringify(m);const x=String(m);if(x.includes("\\n")||x.length>100){const y=x.split("\\n").length;if(y>1)return`[${y} lines of G-code/script]`;if(x.length>100)return x.substring(0,100)+"…"}return x};return M.useEffect(()=>{const m=x=>{x.key==="Escape"&&t()};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[t]),c.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:c.jsx(Nt,{className:"w-full max-w-4xl max-h-[85vh] flex flex-col overflow-hidden",children:c.jsxs(Dt,{className:"p-0 flex flex-col min-h-0 flex-1",children:[c.jsxs("div",{className:"flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[c.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[c.jsx(Hp,{className:"w-5 h-5 text-blue-400"}),"Compare Presets"]}),c.jsx("button",{onClick:t,className:"text-bambu-gray hover:text-white",children:c.jsx(Gt,{className:"w-5 h-5"})})]}),c.jsxs("div",{className:"flex-shrink-0 grid grid-cols-2 gap-4 p-4 border-b border-bambu-dark-tertiary bg-bambu-dark",children:[c.jsxs("div",{className:"text-center",children:[c.jsx("span",{className:"text-sm text-bambu-gray",children:"Left:"}),c.jsx("p",{className:"text-white font-medium truncate",children:r})]}),c.jsxs("div",{className:"text-center",children:[c.jsx("span",{className:"text-sm text-bambu-gray",children:"Right:"}),c.jsx("p",{className:"text-white font-medium truncate",children:i})]})]}),c.jsxs("div",{className:"flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[c.jsxs("div",{className:"flex items-center gap-4 text-sm",children:[c.jsxs("span",{className:"flex items-center gap-1 text-green-400",children:[c.jsx(fr,{className:"w-3.5 h-3.5"}),f.added," added"]}),c.jsxs("span",{className:"flex items-center gap-1 text-red-400",children:[c.jsx(M5,{className:"w-3.5 h-3.5"}),f.removed," removed"]}),c.jsxs("span",{className:"flex items-center gap-1 text-amber-400",children:[c.jsx(i3,{className:"w-3.5 h-3.5"}),f.changed," changed"]}),c.jsxs("span",{className:"flex items-center gap-1 text-bambu-gray",children:[c.jsx(oA,{className:"w-3.5 h-3.5"}),f.same," same"]})]}),c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsxs("div",{className:"relative",children:[c.jsx(Qu,{className:"absolute left-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),c.jsx("input",{type:"text",value:o,onChange:m=>l(m.target.value),placeholder:"Search fields...",className:"pl-8 pr-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none w-48"})]}),f.same>0&&c.jsxs("div",{className:"flex rounded overflow-hidden border border-bambu-dark-tertiary",children:[c.jsx("button",{onClick:()=>a("changes"),className:`px-3 py-1.5 text-sm transition-colors ${s==="changes"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:"Changes"}),c.jsx("button",{onClick:()=>a("all"),className:`px-3 py-1.5 text-sm transition-colors ${s==="all"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:"All"})]})]})]}),c.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto",children:d.length===0?c.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[c.jsx(oA,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),c.jsx("p",{children:s==="changes"?"No differences found":"No fields match the search"})]}):c.jsxs("table",{className:"w-full",children:[c.jsx("thead",{className:"sticky top-0 bg-bambu-dark-secondary",children:c.jsxs("tr",{className:"text-sm text-bambu-gray border-b border-bambu-dark-tertiary",children:[c.jsx("th",{className:"text-left p-3 w-1/3",children:"Field"}),c.jsx("th",{className:"text-left p-3 w-1/3",children:r}),c.jsx("th",{className:"text-left p-3 w-1/3",children:i})]})}),c.jsx("tbody",{children:d.map(m=>{const x={added:"bg-green-500/10",removed:"bg-red-500/10",changed:"bg-amber-500/10",same:""}[m.status],y={added:c.jsx(fr,{className:"w-3.5 h-3.5 text-green-400"}),removed:c.jsx(M5,{className:"w-3.5 h-3.5 text-red-400"}),changed:c.jsx(i3,{className:"w-3.5 h-3.5 text-amber-400"}),same:c.jsx(oA,{className:"w-3.5 h-3.5 text-bambu-gray-dark"})}[m.status];return c.jsxs("tr",{className:`border-b border-bambu-dark-tertiary ${x}`,children:[c.jsx("td",{className:"p-3",children:c.jsxs("div",{className:"flex items-center gap-2",children:[y,c.jsx("span",{className:"text-sm text-white font-mono",children:m.key})]})}),c.jsx("td",{className:"p-3",children:c.jsx("span",{className:`text-sm font-mono break-all ${m.status==="removed"?"text-red-300":m.status==="changed"?"text-white":"text-bambu-gray"}`,children:g(m.left)})}),c.jsx("td",{className:"p-3",children:c.jsx("span",{className:`text-sm font-mono break-all ${m.status==="added"?"text-green-300":m.status==="changed"?"text-white":"text-bambu-gray"}`,children:g(m.right)})})]},m.key)})})]})})]})})})}function Z9e({onClose:t,initialData:e,allPresets:n}){const{showToast:r}=ri(),i=Sn(),s=!!e?.setting_id,[a,o]=M.useState("common"),[l,u]=M.useState(e?.type||"filament"),[d,f]=M.useState(e?.name?s?e.name:`${e.name} (Copy)`:""),[g,m]=M.useState(e?.base_id||""),[x,y]=M.useState(""),[v,b]=M.useState(e?.setting||{inherits:""}),[E,S]=M.useState(JSON.stringify(e?.setting||{inherits:""},null,2)),[A,T]=M.useState(null),[P,C]=M.useState(""),[I,N]=M.useState(!1),[D,F]=M.useState(""),[L,q]=M.useState(!1),[R,V]=M.useState(Ree),[K,W]=M.useState(!1),[ne,Y]=M.useState(""),[Z,U]=M.useState(""),[$,ee]=M.useState(!0),[ae,fe]=M.useState(null),[ue,xe]=M.useState(!1),Me=M.useMemo(()=>({filament:n.filament,print:n.process,printer:n.printer})[l]||[],[n,l]),se=M.useMemo(()=>Me.filter(ce=>J0(ce.setting_id)),[Me]),{data:ve}=yt({queryKey:["cloudFields",l],queryFn:()=>Pe.getCloudFields(l==="print"?"process":l),staleTime:1e3*60*60}),{data:je}=yt({queryKey:["allPresetDetails",l,se.map(ce=>ce.setting_id).join(",")],queryFn:async()=>{const ce={};for(let $e=0;$e{try{const Fe=await Pe.getCloudSettingDetail(Q.setting_id);return{id:Q.setting_id,detail:Fe}}catch{return null}}))).forEach(Q=>{Q&&(ce[Q.id]=Q.detail)})}return ce},enabled:se.length>0,staleTime:1e3*60*10}),{data:de,isLoading:ut}=yt({queryKey:["cloudSettingDetail",g],queryFn:()=>Pe.getCloudSettingDetail(g),enabled:!!g});M.useEffect(()=>{a!=="json"&&S(JSON.stringify(v,null,2))},[v,a]);const H=M.useMemo(()=>({filament:n.filament,print:n.process,printer:n.printer}[l]||[]).filter(Ye=>!J0(Ye.setting_id)).sort((Ye,$e)=>Ye.name.localeCompare($e.name)),[n,l]);M.useEffect(()=>{if(!g)return;const ce=H.find(Ye=>Ye.setting_id===g);ce&&(y(ce.name),s||(b({inherits:ce.name}),S(JSON.stringify({inherits:ce.name},null,2))))},[g,H,s]);const z=M.useMemo(()=>{const ce=ve?.fields||[],Ye=new Set(ce.map(Q=>Q.key)),$e=new Set,Ze=new Set(["inherits","updated_time","compatible_printers","compatible_prints"]);je&&Object.values(je).forEach(Q=>{Q?.setting&&Object.keys(Q.setting).forEach(Fe=>{!Ye.has(Fe)&&!Ze.has(Fe)&&$e.add(Fe)})}),Object.keys(v).forEach(Q=>{!Ye.has(Q)&&!Ze.has(Q)&&$e.add(Q)});const at=Array.from($e).sort().map(Q=>({key:Q,label:Q.replace(/_/g," ").replace(/\b\w/g,Fe=>Fe.toUpperCase()),type:"text",category:"discovered",description:"Discovered from presets"}));return[...ce,...at]},[ve,je,v]),re=z.filter(ce=>ce.label.toLowerCase().includes(P.toLowerCase())||ce.key.toLowerCase().includes(P.toLowerCase())),G=()=>{if(D.trim()){const ce=D.trim().toLowerCase().replace(/\s+/g,"_");J(ce,""),F(""),q(!1),r(`Field "${ce}" added`)}},J=(ce,Ye)=>{b($e=>{const Ze={...$e};return Ye===""||Ye===void 0?delete Ze[ce]:Ze[ce]=Ye,Ze})},le=ce=>{b(Ye=>({...Ye,...ce.settings})),fe(ce.name),r("Template applied")},ke=()=>{if(!ne.trim())return;const ce={...v};if(delete ce.inherits,Object.keys(ce).length===0){r("No overrides to save","error");return}const Ye={id:Date.now().toString(),name:ne.trim(),description:Z.trim()||"Custom template",type:l,settings:ce,showInModal:$},$e=[...R,Ye];V($e),Dee($e),W(!1),Y(""),U(""),ee(!0),r("Template saved")},Ne=M.useMemo(()=>R.filter(ce=>ce.type===l&&ce.showInModal),[l,R]),we=ce=>{S(ce);try{const Ye=JSON.parse(ce);b(Ye),T(null)}catch(Ye){T(Ye.message)}},B=ce=>{ce.preventDefault(),N(!1);const Ye=ce.dataTransfer.files[0];if(Ye&&Ye.name.endsWith(".json")){const $e=new FileReader;$e.onload=Ze=>{try{const at=Ze.target?.result,Q=JSON.parse(at),Fe=Q.setting||Q;b(pe=>({...pe,...Fe})),S(JSON.stringify({...v,...Fe},null,2)),r("File imported successfully")}catch{r("Invalid JSON file","error")}},$e.readAsText(Ye)}},j=_t({mutationFn:()=>{const ce={...v},Ye=l==="filament"?"filament_settings_id":l==="print"?"print_settings_id":"printer_settings_id";ce[Ye]=`"${d}"`;const $e={type:l,name:d,base_id:g,setting:ce};return Pe.createCloudSetting($e)},onSuccess:async()=>{r("Preset created successfully"),await i.refetchQueries({queryKey:["cloudSettings"]}),t()},onError:ce=>r(ce.message,"error")}),te=_t({mutationFn:()=>{if(!e?.setting_id)throw new Error("No setting ID for update");return Pe.updateCloudSetting(e.setting_id,{name:d,setting:v})},onSuccess:async()=>{r("Preset updated successfully"),i.removeQueries({queryKey:["cloudSettingDetail"]}),await i.refetchQueries({queryKey:["cloudSettings"]}),t()},onError:ce=>r(ce.message,"error")}),be=s?te:j,_e=de?.setting?.inherits,ge=_e?H.find(ce=>ce.name===_e):void 0,{data:me}=yt({queryKey:["cloudSettingDetail",ge?.setting_id],queryFn:()=>Pe.getCloudSettingDetail(ge.setting_id),enabled:!!ge?.setting_id}),Ae=M.useMemo(()=>{const ce=me?.setting||{},Ye=de?.setting||{},$e=g&&je?.[g]?.setting?je[g].setting:{};return{...ce,...Ye,...$e}},[g,de,me,je]),ze=ce=>{if(ce==null)return"";if(Array.isArray(ce)){const Ye=[...new Set(ce.map($e=>String($e)))];return Ye.length===1?Ye[0]:ce.join(", ")}return String(ce)},st=ce=>{const Ye=v[ce.key],$e=Ae[ce.key],Ze=ze($e),at=ut?"Loading...":Ze||"",Q="w-full px-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none";if(ce.type==="boolean"){const Fe=Ye==="1"||Ye===void 0&&$e==="1";return c.jsx("button",{type:"button",onClick:()=>J(ce.key,Ye==="1"?"0":"1"),className:`w-8 h-5 rounded-full transition-colors ${Fe?"bg-bambu-green":"bg-bambu-dark-tertiary"}`,children:c.jsx("div",{className:`w-4 h-4 rounded-full bg-white shadow transition-transform ${Fe?"translate-x-3.5":"translate-x-0.5"}`})})}return ce.type==="select"?c.jsxs("select",{value:Ye||"",onChange:Fe=>J(ce.key,Fe.target.value),className:Q,children:[c.jsx("option",{value:"",children:at}),ce.options?.map(Fe=>c.jsx("option",{value:Fe.value,children:Fe.label},Fe.value))]}):c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("input",{type:ce.type==="number"?"number":"text",value:Ye!==void 0?String(Ye):"",onChange:Fe=>J(ce.key,Fe.target.value),step:ce.step,min:ce.min,max:ce.max,placeholder:at,className:Q}),ce.unit&&c.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:ce.unit})]})},Ve=M.useMemo(()=>de?.setting?de.setting:{},[de]);return c.jsxs("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onDragOver:ce=>{ce.preventDefault(),N(!0)},onDragLeave:()=>N(!1),onDrop:B,children:[ue&&g&&c.jsx(Oee,{onClose:()=>xe(!1),leftPreset:Ve,rightPreset:v,leftLabel:`Base: ${x||g}`,rightLabel:`Current: ${d||"New Preset"}`}),c.jsx(Nt,{className:"w-full max-w-6xl max-h-[90vh] flex flex-col",children:c.jsxs(Dt,{className:"p-0 flex flex-col h-full",children:[c.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[c.jsxs("div",{children:[c.jsx("h2",{className:"text-xl font-semibold text-white",children:s?"Edit Preset":e?"Duplicate Preset":"Create New Preset"}),c.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:"Customize settings for your new preset"})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[g&&c.jsxs("button",{onClick:()=>xe(!0),className:"flex items-center gap-2 px-3 py-2 text-sm text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors",title:"Compare with base preset",children:[c.jsx(Hp,{className:"w-4 h-4"}),"Compare"]}),c.jsx("button",{onClick:t,className:"p-2 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors",children:c.jsx(Gt,{className:"w-5 h-5"})})]})]}),I&&c.jsx("div",{className:"absolute inset-0 bg-bambu-green/10 border-2 border-dashed border-bambu-green rounded-lg flex items-center justify-center z-10",children:c.jsxs("div",{className:"text-center",children:[c.jsx(ma,{className:"w-12 h-12 text-bambu-green mx-auto mb-2"}),c.jsx("p",{className:"text-bambu-green font-medium",children:"Drop JSON file to import"})]})}),c.jsxs("div",{className:"p-4 border-b border-bambu-dark-tertiary space-y-3",children:[c.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Type"}),c.jsxs("select",{value:l,onChange:ce=>{u(ce.target.value),m("")},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[c.jsx("option",{value:"filament",children:"Filament"}),c.jsx("option",{value:"print",children:"Process"}),c.jsx("option",{value:"printer",children:"Printer"})]})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Base Preset"}),c.jsxs("select",{value:g,onChange:ce=>m(ce.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none",children:[c.jsx("option",{value:"",children:"Select base preset..."}),H.map(ce=>c.jsx("option",{value:ce.setting_id,children:ce.name},ce.setting_id))]})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Preset Name"}),c.jsx("input",{type:"text",value:d,onChange:ce=>f(ce.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",placeholder:"My Custom Preset"})]})]}),x&&c.jsx("div",{className:"text-xs text-bambu-gray",children:c.jsxs("p",{className:"flex items-center gap-1",children:[c.jsx(Ph,{className:"w-3 h-3 text-bambu-green"}),"Inherits from: ",c.jsx("span",{className:"text-white",children:x}),ut&&c.jsx(At,{className:"w-3 h-3 animate-spin ml-1"})]})})]}),c.jsxs("div",{className:"flex border-b border-bambu-dark-tertiary",children:[c.jsxs("button",{onClick:()=>o("common"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${a==="common"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[c.jsx(A5,{className:"w-4 h-4"}),"Common"]}),c.jsxs("button",{onClick:()=>o("fields"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${a==="fields"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[c.jsx(bR,{className:"w-4 h-4"}),"All Fields"]}),c.jsxs("button",{onClick:()=>o("json"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${a==="json"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[c.jsx(CG,{className:"w-4 h-4"}),"JSON",A&&c.jsx(Oo,{className:"w-3 h-3 text-red-400"})]}),c.jsx("div",{className:"flex-1"}),c.jsxs("button",{onClick:()=>{const ce={name:d,type:l,base_id:g,setting:v},Ye=new Blob([JSON.stringify(ce,null,2)],{type:"application/json"}),$e=URL.createObjectURL(Ye),Ze=document.createElement("a");Ze.href=$e,Ze.download=`${d||"preset"}.json`,document.body.appendChild(Ze),Ze.click(),document.body.removeChild(Ze),URL.revokeObjectURL($e),r("Preset exported")},className:"flex items-center gap-2 px-4 py-3 text-sm text-bambu-gray hover:text-white transition-colors",title:"Export current settings to JSON file",children:[c.jsx(ya,{className:"w-4 h-4"}),"Export"]}),c.jsxs("button",{onClick:()=>document.getElementById("file-import")?.click(),className:"flex items-center gap-2 px-4 py-3 text-sm text-bambu-gray hover:text-white transition-colors",title:"Import settings from JSON file",children:[c.jsx(ma,{className:"w-4 h-4"}),"Import"]}),c.jsx("input",{id:"file-import",type:"file",accept:".json",className:"hidden",onChange:ce=>{const Ye=ce.target.files?.[0];if(Ye){const $e=new FileReader;$e.onload=Ze=>{try{const at=JSON.parse(Ze.target?.result),Q=at.setting||at;b(Fe=>({...Fe,...Q})),r("File imported")}catch{r("Invalid JSON","error")}},$e.readAsText(Ye)}}})]}),c.jsxs("div",{className:"flex-1 overflow-y-auto p-4",children:[a==="common"&&c.jsxs("div",{className:"space-y-6",children:[c.jsxs("div",{children:[c.jsxs("div",{className:"flex items-center justify-between mb-3",children:[c.jsxs("h3",{className:"text-sm font-medium text-white flex items-center gap-2",children:[c.jsx(h0,{className:"w-4 h-4 text-amber-400"}),"Quick Templates"]}),Object.keys(v).filter(ce=>ce!=="inherits").length>0&&c.jsxs("button",{onClick:()=>W(!K),className:"text-xs text-bambu-gray hover:text-white flex items-center gap-1 transition-colors",children:[c.jsx(To,{className:"w-3 h-3"}),"Save as template"]})]}),K&&c.jsxs("div",{className:"mb-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[c.jsxs("div",{className:"grid grid-cols-2 gap-2 mb-2",children:[c.jsx("input",{type:"text",value:ne,onChange:ce=>Y(ce.target.value),placeholder:"Template name",className:"px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none",autoFocus:!0}),c.jsx("input",{type:"text",value:Z,onChange:ce=>U(ce.target.value),placeholder:"Description (optional)",className:"px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none"})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex gap-2",children:[c.jsxs(Ie,{size:"sm",onClick:ke,disabled:!ne.trim(),children:[c.jsx(To,{className:"w-3 h-3"}),"Save"]}),c.jsx(Ie,{size:"sm",variant:"secondary",onClick:()=>W(!1),children:"Cancel"})]}),c.jsxs("button",{onClick:()=>ee(!$),className:`flex items-center gap-1.5 text-xs transition-colors ${$?"text-bambu-green":"text-bambu-gray hover:text-white"}`,children:[$?c.jsx(o0,{className:"w-3.5 h-3.5"}):c.jsx(mR,{className:"w-3.5 h-3.5"}),$?"Show in modals":"Hidden in modals"]})]})]}),ae&&c.jsxs("div",{className:"mb-3 px-3 py-2 bg-bambu-green/10 border border-bambu-green/30 rounded-lg flex items-center gap-2",children:[c.jsx(Ph,{className:"w-4 h-4 text-bambu-green"}),c.jsxs("span",{className:"text-sm text-bambu-green",children:["Template applied: ",c.jsx("span",{className:"font-medium",children:ae})]}),c.jsx("button",{onClick:()=>fe(null),className:"ml-auto text-bambu-green/70 hover:text-bambu-green",children:c.jsx(Gt,{className:"w-4 h-4"})})]}),c.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[Ne.map(ce=>c.jsxs("button",{onClick:()=>le(ce),className:"p-3 text-left bg-bambu-dark border border-bambu-dark-tertiary rounded-lg hover:border-bambu-gray-dark transition-colors",children:[c.jsx("p",{className:"text-sm font-medium text-white",children:ce.name}),c.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:ce.description})]},ce.id)),Ne.length===0&&c.jsx("p",{className:"col-span-3 text-center text-bambu-gray text-sm py-4",children:"No templates selected. Use the Templates button to enable templates for quick access."})]}),c.jsx("p",{className:"text-xs text-bambu-gray-dark mt-2 text-center",children:"Manage templates via the Templates button on the main page"})]}),c.jsxs("div",{children:[c.jsx("h3",{className:"text-sm font-medium text-white mb-3",children:"Common Settings"}),c.jsx("div",{className:"grid grid-cols-2 gap-x-6 gap-y-3",children:z.slice(0,10).map(ce=>c.jsxs("div",{className:"flex items-center justify-between gap-4",children:[c.jsx("label",{className:"text-sm text-bambu-gray flex-shrink-0",children:ce.label}),c.jsx("div",{className:"w-48",children:st(ce)})]},ce.key))})]}),Object.keys(v).length>1&&c.jsxs("div",{children:[c.jsx("h3",{className:"text-sm font-medium text-white mb-3",children:"Current Overrides"}),c.jsx("div",{className:"flex flex-wrap gap-2",children:Object.entries(v).filter(([ce])=>ce!=="inherits").map(([ce,Ye])=>c.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 bg-bambu-green/10 text-bambu-green text-xs rounded",children:[ce,": ",String(Ye).slice(0,20),c.jsx("button",{onClick:()=>J(ce,void 0),className:"hover:text-white",children:c.jsx(Gt,{className:"w-3 h-3"})})]},ce))})]})]}),a==="fields"&&c.jsxs("div",{className:"grid grid-cols-2 gap-6",style:{height:"400px"},children:[c.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[c.jsxs("div",{className:"flex items-center justify-between mb-3 flex-shrink-0",children:[c.jsx("h3",{className:"text-sm font-medium text-white",children:"Available Fields"}),c.jsx("span",{className:"text-xs text-bambu-gray",children:je?`${z.length} fields`:"Loading..."})]}),c.jsxs("div",{className:"relative mb-3 flex-shrink-0",children:[c.jsx(Qu,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),c.jsx("input",{type:"text",value:P,onChange:ce=>C(ce.target.value),placeholder:"Search fields...",className:"w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none"})]}),c.jsxs("div",{className:"flex-1 overflow-y-auto space-y-1 pr-2 min-h-0",children:[re.filter(ce=>!(ce.key in v)).map(ce=>{const Ye=Ae[ce.key],$e=ze(Ye);return c.jsxs("div",{onClick:()=>{b(Ze=>({...Ze,[ce.key]:$e||""}))},className:"flex items-center justify-between gap-2 p-2 rounded-lg hover:bg-bambu-dark-tertiary transition-colors cursor-pointer group",children:[c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsx("p",{className:"text-sm text-white truncate",children:ce.label}),c.jsx("p",{className:"text-xs text-bambu-gray-dark truncate",children:ce.key})]}),c.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[$e&&c.jsxs("span",{className:"text-xs text-bambu-gray bg-bambu-dark px-2 py-0.5 rounded max-w-32 truncate",title:$e,children:[$e.slice(0,20),$e.length>20?"...":""]}),c.jsx("div",{className:"w-6 h-6 flex items-center justify-center rounded bg-bambu-dark-tertiary group-hover:bg-bambu-green/20 transition-colors",children:c.jsx(fr,{className:"w-4 h-4 text-bambu-gray group-hover:text-bambu-green transition-colors"})})]})]},ce.key)}),re.filter(ce=>!(ce.key in v)).length===0&&c.jsx("p",{className:"text-center text-bambu-gray py-4 text-sm",children:P?"No matching fields":"All fields added"})]}),c.jsx("div",{className:"pt-3 mt-3 border-t border-bambu-dark-tertiary flex-shrink-0",children:L?c.jsxs("div",{className:"flex gap-2",children:[c.jsx("input",{type:"text",value:D,onChange:ce=>F(ce.target.value),onKeyDown:ce=>ce.key==="Enter"&&G(),placeholder:"custom_field_name",className:"flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white font-mono text-sm placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none",autoFocus:!0}),c.jsx(Ie,{size:"sm",onClick:G,disabled:!D.trim(),children:c.jsx(fr,{className:"w-4 h-4"})}),c.jsx(Ie,{size:"sm",variant:"secondary",onClick:()=>{q(!1),F("")},children:c.jsx(Gt,{className:"w-4 h-4"})})]}):c.jsxs("button",{onClick:()=>q(!0),className:"w-full flex items-center justify-center gap-2 p-2 text-sm text-bambu-gray hover:text-white border border-dashed border-bambu-dark-tertiary hover:border-bambu-gray-dark rounded-lg transition-colors",children:[c.jsx(fr,{className:"w-4 h-4"}),"Add custom field"]})})]}),c.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[c.jsxs("div",{className:"flex items-center justify-between mb-3 flex-shrink-0",children:[c.jsx("h3",{className:"text-sm font-medium text-white",children:"Your Overrides"}),c.jsxs("span",{className:"text-xs text-bambu-gray",children:[Object.keys(v).filter(ce=>ce!=="inherits").length," fields"]})]}),c.jsxs("div",{className:"flex-1 overflow-y-auto space-y-2 pr-2 min-h-0",children:[Object.entries(v).filter(([ce])=>ce!=="inherits").map(([ce,Ye])=>{const $e=z.find(Ze=>Ze.key===ce);return c.jsxs("div",{className:"p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[c.jsxs("div",{className:"flex items-center justify-between mb-2",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-sm font-medium text-white",children:$e?.label||ce}),c.jsx("p",{className:"text-xs text-bambu-gray-dark",children:ce})]}),c.jsx("button",{onClick:()=>J(ce,void 0),className:"p-1 text-bambu-gray hover:text-red-400 transition-colors",children:c.jsx(Gt,{className:"w-4 h-4"})})]}),$e?st($e):c.jsx("input",{type:"text",value:String(Ye),onChange:Ze=>J(ce,Ze.target.value),className:"w-full px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none"})]},ce)}),Object.keys(v).filter(ce=>ce!=="inherits").length===0&&c.jsxs("div",{className:"text-center py-8 text-bambu-gray",children:[c.jsx(A5,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),c.jsx("p",{className:"text-sm",children:"No overrides yet"}),c.jsx("p",{className:"text-xs mt-1",children:"Click fields on the left to add them"})]})]}),Object.keys(v).filter(ce=>ce!=="inherits").length>0&&c.jsx("div",{className:"pt-3 mt-3 border-t border-bambu-dark-tertiary flex-shrink-0",children:c.jsxs("button",{onClick:()=>{W(!0),o("common")},className:"w-full flex items-center justify-center gap-2 p-2 text-sm text-bambu-gray hover:text-white border border-dashed border-bambu-dark-tertiary hover:border-bambu-gray-dark rounded-lg transition-colors",children:[c.jsx(To,{className:"w-4 h-4"}),"Save as template"]})})]})]}),a==="json"&&c.jsxs("div",{className:"space-y-2",children:[A&&c.jsxs("div",{className:"flex items-center gap-2 text-red-400 text-sm",children:[c.jsx(Oo,{className:"w-4 h-4"}),A]}),c.jsx("textarea",{value:E,onChange:ce=>we(ce.target.value),className:`w-full h-80 px-3 py-2 bg-bambu-dark border rounded-lg text-white text-xs font-mono focus:outline-none resize-none ${A?"border-red-500 focus:border-red-500":"border-bambu-dark-tertiary focus:border-bambu-green"}`,spellCheck:!1}),c.jsx("p",{className:"text-xs text-bambu-gray",children:"Tip: Drag & drop a .json file anywhere on this modal to import settings"})]})]}),c.jsxs("div",{className:"p-4 border-t border-bambu-dark-tertiary flex gap-2",children:[c.jsx(Ie,{variant:"secondary",onClick:t,className:"flex-1",children:"Cancel"}),c.jsxs(Ie,{onClick:()=>be.mutate(),disabled:be.isPending||!d.trim()||!s&&!g||!!A,className:"flex-1",children:[be.isPending?c.jsx(At,{className:"w-4 h-4 animate-spin"}):s?c.jsx(To,{className:"w-4 h-4"}):c.jsx(fr,{className:"w-4 h-4"}),s?"Save":e?"Duplicate":"Create"]})]})]})})]})}function Q9e({settings:t,lastSyncTime:e,onRefresh:n,isRefreshing:r,printers:i}){const[s,a]=M.useState(""),[o,l]=M.useState("all"),[u,d]=M.useState("all"),[f,g]=M.useState("all"),[m,x]=M.useState("all"),[y,v]=M.useState("all"),[b,E]=M.useState("all"),[S,A]=M.useState(null),[T,P]=M.useState(!1),[C,I]=M.useState(!1),[N,D]=M.useState(null),[F,L]=M.useState(null),[q,R]=M.useState(null),[V,K]=M.useState(!1),[W,ne]=M.useState([null,null]),[Y,Z]=M.useState(!1),[U,$]=M.useState(null),ee=Sn(),ae=M.useMemo(()=>[...t.filament.map(re=>({...re,type:"filament"})),...t.printer.map(re=>({...re,type:"printer"})),...t.process.map(re=>({...re,type:"process"}))].map(re=>({...re,meta:Gj(re.name)})),[t]),fe=M.useMemo(()=>{const z=new Set,re=new Set,G=new Set;return ae.forEach(J=>{J.meta.nozzle&&z.add(J.meta.nozzle),J.meta.filamentType&&re.add(J.meta.filamentType),J.meta.layerHeight&&G.add(J.meta.layerHeight)}),{printers:i.map(J=>({id:J.id.toString(),name:J.name})),nozzles:Array.from(z).sort((J,le)=>parseFloat(J)-parseFloat(le)),filaments:Array.from(re).sort(),layerHeights:Array.from(G).sort((J,le)=>parseFloat(J)-parseFloat(le))}},[ae,i]),ue=M.useMemo(()=>f==="all"?null:i.find(re=>re.id.toString()===f)?.model||null,[f,i]),xe=M.useMemo(()=>ae.filter(z=>o==="all"||z.type===o).filter(z=>{if(u==="all")return!0;const re=J0(z.setting_id);return u==="custom"?re:!re}).filter(z=>{if(f==="all"||!ue)return!0;const re=z.meta.printer?.toLowerCase()||"",G=ue.toLowerCase();return re.includes(G)||G.includes(re)}).filter(z=>m==="all"||z.meta.nozzle===m).filter(z=>y==="all"||z.meta.filamentType===y).filter(z=>b==="all"||z.meta.layerHeight===b).filter(z=>s===""||z.name.toLowerCase().includes(s.toLowerCase())).sort((z,re)=>z.name.localeCompare(re.name)),[ae,o,u,f,ue,m,y,b,s]),Me=z=>{if(V){const re=W[0]?.setting_id===z.setting_id,G=W[1]?.setting_id===z.setting_id;if(re)ne([W[1],null]);else if(G)ne([W[0],null]);else if(!W[0])ne([z,null]);else if(W[1]){if(W[0].type!==z.type)return;ne([W[0],z])}else{if(W[0].type!==z.type)return;ne([W[0],z])}}else A(z)},se=z=>{if(W[0]?.setting_id===z.setting_id)return 0;if(W[1]?.setting_id===z.setting_id)return 1},ve=async z=>{try{const re=await Pe.getCloudSettingDetail(z.setting_id),G=z.type==="process"?"print":z.type;D({type:G,name:z.name,base_id:re.base_id||"GFSA00",setting:re.setting||{}}),A(null)}catch(re){console.error("Failed to fetch preset details for duplication:",re)}},je=async z=>{try{ee.removeQueries({queryKey:["cloudSettingDetail",z.setting_id]});const re=await Pe.getCloudSettingDetail(z.setting_id),G=z.type==="process"?"print":z.type;L({type:G,name:z.name,base_id:re.base_id||"GFSA00",setting:re.setting||{},setting_id:z.setting_id}),A(null)}catch(re){console.error("Failed to fetch preset details for editing:",re)}},de=()=>{l("all"),d("all"),g("all"),x("all"),v("all"),E("all"),a("")},ut=o!=="all"||u!=="all"||f!=="all"||m!=="all"||y!=="all"||b!=="all"||s!=="",H=t.filament.length+t.printer.length+t.process.length;return c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"space-y-4 mb-6",children:[c.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[c.jsxs("div",{className:"relative flex-1",children:[c.jsx(Qu,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),c.jsx("input",{type:"text",value:s,onChange:z=>a(z.target.value),placeholder:"Search presets...",className:"w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none"})]}),c.jsxs("div",{className:"flex gap-2",children:[c.jsxs(Ie,{variant:V?"primary":"secondary",onClick:()=>{V?(K(!1),ne([null,null])):K(!0)},children:[c.jsx(Hp,{className:"w-4 h-4"}),V?"Cancel":"Compare"]}),c.jsxs(Ie,{variant:"secondary",onClick:()=>I(!0),children:[c.jsx(h0,{className:"w-4 h-4"}),"Templates"]}),c.jsxs(Ie,{variant:"secondary",onClick:n,disabled:r,children:[c.jsx(qs,{className:`w-4 h-4 ${r?"animate-spin":""}`}),"Refresh"]}),c.jsxs(Ie,{onClick:()=>P(!0),children:[c.jsx(fr,{className:"w-4 h-4"}),"New Preset"]})]})]}),c.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[c.jsx(gR,{className:"w-4 h-4 text-bambu-gray"}),c.jsx(Ap,{label:"Type",value:o,options:[{value:"all",label:"All",count:H},{value:"filament",label:"Filament",count:t.filament.length},{value:"printer",label:"Printer",count:t.printer.length},{value:"process",label:"Process",count:t.process.length}],onChange:z=>l(z)}),c.jsx(Ap,{label:"Owner",value:u,options:[{value:"all",label:"All"},{value:"custom",label:"My Presets"},{value:"builtin",label:"Built-in"}],onChange:z=>d(z)}),fe.printers.length>0&&c.jsx(Ap,{label:"Printer",value:f,options:[{value:"all",label:"All"},...fe.printers.map(z=>({value:z.id,label:z.name}))],onChange:g}),fe.nozzles.length>0&&c.jsx(Ap,{label:"Nozzle",value:m,options:[{value:"all",label:"All"},...fe.nozzles.map(z=>({value:z,label:z}))],onChange:x}),fe.filaments.length>0&&(o==="all"||o==="filament")&&c.jsx(Ap,{label:"Filament",value:y,options:[{value:"all",label:"All"},...fe.filaments.map(z=>({value:z,label:z}))],onChange:v}),fe.layerHeights.length>0&&(o==="all"||o==="process")&&c.jsx(Ap,{label:"Layer",value:b,options:[{value:"all",label:"All"},...fe.layerHeights.map(z=>({value:z,label:z}))],onChange:E}),ut&&c.jsx("button",{onClick:de,className:"px-3 py-2 text-sm text-bambu-gray hover:text-white transition-colors",children:"Clear filters"})]})]}),V&&c.jsx("div",{className:"mb-4 p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg",children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-4",children:[c.jsx(Hp,{className:"w-5 h-5 text-blue-400"}),c.jsx("span",{className:"text-white font-medium",children:"Compare Mode"}),c.jsx("span",{className:"text-bambu-gray",children:W[0]?`Select another ${W[0].type} preset`:"Click two presets of the same type to compare"})]}),c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:`px-2 py-1 text-sm rounded truncate max-w-[200px] ${W[0]?"bg-blue-500/30 text-blue-700 dark:text-blue-300":"bg-bambu-dark text-bambu-gray"}`,children:W[0]?W[0].name:"1. Select first"}),c.jsx(i3,{className:"w-4 h-4 text-bambu-gray"}),c.jsx("span",{className:`px-2 py-1 text-sm rounded truncate max-w-[200px] ${W[1]?"bg-blue-500/30 text-blue-700 dark:text-blue-300":"bg-bambu-dark text-bambu-gray"}`,children:W[1]?W[1].name:"2. Select second"})]}),W[0]&&W[1]&&c.jsxs(Ie,{size:"sm",onClick:async()=>{try{const[z,re]=await Promise.all([Pe.getCloudSettingDetail(W[0].setting_id),Pe.getCloudSettingDetail(W[1].setting_id)]);$([z.setting||{},re.setting||{}]),Z(!0)}catch{}},children:[c.jsx(Hp,{className:"w-4 h-4"}),"Compare Now"]})]})]})}),c.jsxs("div",{className:"flex flex-wrap items-center gap-4 mb-4 text-sm text-bambu-gray",children:[e&&c.jsxs("div",{className:"flex items-center gap-1",children:[c.jsx(ti,{className:"w-3 h-3"}),"Last synced: ",W9e(e.toISOString())]}),c.jsxs("span",{children:["Showing ",xe.length," of ",H," presets"]}),c.jsxs("div",{className:"flex items-center gap-1",children:[c.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-bambu-green"}),c.jsx("span",{children:"= My preset (editable)"})]})]}),xe.length===0?c.jsxs("div",{className:"text-center py-16",children:[c.jsx(Oh,{className:"w-12 h-12 text-bambu-gray-dark mx-auto mb-4"}),c.jsx("p",{className:"text-bambu-gray",children:"No presets found"}),ut&&c.jsx("button",{onClick:de,className:"mt-2 text-sm text-bambu-green hover:text-bambu-green-light",children:"Clear filters"})]}):c.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6",children:[c.jsxs("div",{children:[c.jsxs("div",{className:"flex items-center gap-2 mb-3 px-1",children:[c.jsx(pR,{className:"w-4 h-4 text-amber-400"}),c.jsx("h3",{className:"text-sm font-medium text-bambu-gray",children:"Filament"}),c.jsxs("span",{className:"text-xs text-bambu-gray-dark",children:["(",xe.filter(z=>z.type==="filament").length,")"]})]}),c.jsxs("div",{className:"space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1",children:[xe.filter(z=>z.type==="filament").map(z=>c.jsx($N,{setting:z,onClick:()=>Me(z),onDuplicate:()=>ve(z),compareMode:V,isCompareSelected:se(z)!==void 0,compareIndex:se(z),compareDisabled:V&&!!W[0]&&W[0].type!==z.type},z.setting_id)),xe.filter(z=>z.type==="filament").length===0&&c.jsx("p",{className:"text-xs text-bambu-gray-dark px-3 py-2",children:"No filament presets"})]})]}),c.jsxs("div",{children:[c.jsxs("div",{className:"flex items-center gap-2 mb-3 px-1",children:[c.jsx(vS,{className:"w-4 h-4 text-blue-400"}),c.jsx("h3",{className:"text-sm font-medium text-bambu-gray",children:"Process"}),c.jsxs("span",{className:"text-xs text-bambu-gray-dark",children:["(",xe.filter(z=>z.type==="process").length,")"]})]}),c.jsxs("div",{className:"space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1",children:[xe.filter(z=>z.type==="process").map(z=>c.jsx($N,{setting:z,onClick:()=>Me(z),onDuplicate:()=>ve(z),compareMode:V,isCompareSelected:se(z)!==void 0,compareIndex:se(z),compareDisabled:V&&!!W[0]&&W[0].type!==z.type},z.setting_id)),xe.filter(z=>z.type==="process").length===0&&c.jsx("p",{className:"text-xs text-bambu-gray-dark px-3 py-2",children:"No process presets"})]})]}),c.jsxs("div",{children:[c.jsxs("div",{className:"flex items-center gap-2 mb-3 px-1",children:[c.jsx(jo,{className:"w-4 h-4 text-purple-400"}),c.jsx("h3",{className:"text-sm font-medium text-bambu-gray",children:"Printer"}),c.jsxs("span",{className:"text-xs text-bambu-gray-dark",children:["(",xe.filter(z=>z.type==="printer").length,")"]})]}),c.jsxs("div",{className:"space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1",children:[xe.filter(z=>z.type==="printer").map(z=>c.jsx($N,{setting:z,onClick:()=>Me(z),onDuplicate:()=>ve(z),compareMode:V,isCompareSelected:se(z)!==void 0,compareIndex:se(z),compareDisabled:V&&!!W[0]&&W[0].type!==z.type},z.setting_id)),xe.filter(z=>z.type==="printer").length===0&&c.jsx("p",{className:"text-xs text-bambu-gray-dark px-3 py-2",children:"No printer presets"})]})]})]}),S&&c.jsx(X9e,{setting:S,onClose:()=>A(null),onDeleted:()=>A(null),onDuplicate:()=>ve(S),onEdit:()=>je(S)}),(T||N||F||q)&&c.jsx(Z9e,{onClose:()=>{P(!1),D(null),L(null),R(null)},initialData:F||N||(q?{type:q.type,name:"",base_id:"",setting:q.setting}:void 0),allPresets:t}),C&&c.jsx(Y9e,{onClose:()=>I(!1),onApply:z=>{R({type:z.type,setting:z.settings}),I(!1)}}),Y&&U&&W[0]&&W[1]&&c.jsx(Oee,{onClose:()=>{Z(!1),$(null)},leftPreset:U[0],rightPreset:U[1],leftLabel:W[0].name,rightLabel:W[1].name})]})}function J9e(){const t=Sn(),{showToast:e}=ri(),[n,r]=M.useState("cloud"),[i,s]=M.useState(),{data:a,isLoading:o}=yt({queryKey:["cloudStatus"],queryFn:Pe.getCloudStatus}),{data:l=[]}=yt({queryKey:["printers"],queryFn:Pe.getPrinters}),{data:u,isLoading:d,refetch:f,dataUpdatedAt:g}=yt({queryKey:["cloudSettings"],queryFn:()=>Pe.getCloudSettings(),enabled:!!a?.is_authenticated,retry:!1,staleTime:1e3*60*5});M.useEffect(()=>{g&&s(new Date(g))},[g]);const m=_t({mutationFn:Pe.cloudLogout,onSuccess:()=>{t.invalidateQueries({queryKey:["cloudStatus"]}),t.removeQueries({queryKey:["cloudSettings"]}),e("Logged out")}}),x=()=>{t.invalidateQueries({queryKey:["cloudStatus"]})};return o?c.jsx("div",{className:"p-4 md:p-8 flex items-center justify-center min-h-[400px]",children:c.jsx(At,{className:"w-8 h-8 text-bambu-green animate-spin"})}):c.jsxs("div",{className:"p-6 lg:p-8",children:[c.jsxs("div",{className:"mb-6",children:[c.jsx("h1",{className:"text-2xl font-bold text-white",children:"Profiles"}),c.jsx("p",{className:"text-bambu-gray",children:"Manage your slicer presets and pressure advance calibrations"})]}),c.jsxs("div",{className:"flex border-b border-bambu-dark-tertiary mb-6",children:[c.jsxs("button",{onClick:()=>r("cloud"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${n==="cloud"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[c.jsx(gS,{className:"w-4 h-4"}),"Cloud Profiles"]}),c.jsxs("button",{onClick:()=>r("kprofiles"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${n==="kprofiles"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[c.jsx(xR,{className:"w-4 h-4"}),"K-Profiles"]})]}),n==="cloud"&&c.jsxs(c.Fragment,{children:[a?.is_authenticated&&c.jsxs("div",{className:"flex items-center justify-between p-3 mb-6 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("div",{className:"w-2 h-2 rounded-full bg-bambu-green animate-pulse"}),c.jsxs("span",{className:"text-sm text-bambu-gray",children:["Connected as ",c.jsx("span",{className:"text-white",children:a.email})]})]}),c.jsxs(Ie,{variant:"secondary",size:"sm",onClick:()=>m.mutate(),disabled:m.isPending,children:[c.jsx(hle,{className:"w-4 h-4"}),"Logout"]})]}),a?.is_authenticated?d?c.jsx("div",{className:"flex items-center justify-center py-16",children:c.jsx(At,{className:"w-8 h-8 text-bambu-green animate-spin"})}):u?c.jsx(Q9e,{settings:u,lastSyncTime:i,onRefresh:()=>f(),isRefreshing:d,printers:l}):c.jsxs("div",{className:"text-center py-16",children:[c.jsx("p",{className:"text-bambu-gray mb-4",children:"Failed to load profiles"}),c.jsx(Ie,{onClick:()=>f(),children:"Retry"})]}):c.jsx(q9e,{onSuccess:x})]}),n==="kprofiles"&&c.jsx(G9e,{}),c.jsx(K9e,{})]})}const Px={Droplet:pR,Flame:Aoe,Ruler:Qle,Sparkles:h0,Square:im,Cable:Mae,Wrench:Ju,Calendar:qr,Timer:Ou,Cog:Jae,Fan:moe,Zap:am,Wind:Yce,Thermometer:$p,Layers:Oh,Box:rm,Target:IG,RefreshCw:qs,Settings:wR,Filter:gR,CircleDot:Bae};function t0(t){return t&&Px[t]||Ju}function Tp(t,e){return e==="days"?t<1?"Today":t===1?"1 day":t<7?`${Math.round(t)} days`:t<30?`${Math.round(t/7)} weeks`:`${Math.round(t/30)} months`:t<1?`${Math.round(t*60)}m`:t<10?`${t.toFixed(1)}h`:`${Math.round(t)}h`}function VN(t,e){return e==="days"?t===1?"1 day":t===7?"1 week":t===14?"2 weeks":t===30?"1 month":t===60?"2 months":t===90?"3 months":t===180?"6 months":t===365?"1 year":`${t} days`:`${t}h`}function eGe({item:t,onPerform:e,onToggle:n}){const r=t0(t.maintenance_type_icon),i=t.interval_type||"hours",a=(()=>{if(i==="days"){const f=t.days_since_maintenance??0;return Math.max(0,Math.min(100,f/t.interval_hours*100))}return Math.max(0,Math.min(100,(t.interval_hours-t.hours_until_due)/t.interval_hours*100))})(),o=()=>t.enabled?t.is_due?"text-red-400":t.is_warning?"text-amber-400":"text-bambu-green":"text-bambu-gray",l=()=>t.enabled?t.is_due?"bg-red-500":t.is_warning?"bg-amber-500":"bg-bambu-green":"bg-bambu-gray/30",u=()=>t.enabled?t.is_due?"bg-red-500/5 border-red-500/20":t.is_warning?"bg-amber-500/5 border-amber-500/20":"bg-bambu-dark-secondary border-bambu-dark-tertiary":"bg-bambu-dark-secondary/50",d=()=>{if(!t.enabled)return"Disabled";if(i==="days"){const f=t.days_until_due??0;return t.is_due?`Overdue by ${Tp(Math.abs(f),"days")}`:t.is_warning?`Due in ${Tp(f,"days")}`:`${Tp(f,"days")} left`}else return t.is_due?`Overdue by ${Tp(Math.abs(t.hours_until_due),"hours")}`:t.is_warning?`Due in ${Tp(t.hours_until_due,"hours")}`:`${Tp(t.hours_until_due,"hours")} left`};return c.jsx("div",{className:`rounded-xl border p-4 transition-all ${u()}`,children:c.jsxs("div",{className:"flex items-start gap-3",children:[c.jsxs("div",{className:`relative p-2.5 rounded-lg ${t.is_due?"bg-red-500/20":t.is_warning?"bg-amber-500/20":t.enabled?"bg-bambu-dark":"bg-bambu-dark/50"}`,children:[c.jsx(r,{className:`w-5 h-5 ${o()}`}),t.enabled&&(t.is_due||t.is_warning)&&c.jsx("span",{className:`absolute -top-1 -right-1 w-2.5 h-2.5 rounded-full ${t.is_due?"bg-red-500":"bg-amber-500"} animate-pulse`})]}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("h3",{className:`font-medium truncate ${t.enabled?"text-white":"text-bambu-gray"}`,children:t.maintenance_type_name}),i==="days"&&c.jsx("span",{title:"Time-based interval",children:c.jsx(qr,{className:"w-3.5 h-3.5 text-bambu-gray shrink-0"})})]}),c.jsx("div",{className:"mt-2 mb-1.5",children:c.jsx("div",{className:"w-full h-1.5 bg-bambu-dark rounded-full overflow-hidden",children:c.jsx("div",{className:`h-full rounded-full transition-all duration-500 ${l()}`,style:{width:`${a}%`}})})}),c.jsxs("div",{className:`text-xs flex items-center gap-1 ${o()}`,children:[t.is_due&&c.jsx(Qr,{className:"w-3 h-3"}),t.is_warning&&!t.is_due&&c.jsx(ti,{className:"w-3 h-3"}),!t.is_due&&!t.is_warning&&t.enabled&&c.jsx(Ph,{className:"w-3 h-3"}),d()]})]}),c.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[c.jsx(tr,{checked:t.enabled,onChange:f=>n(t.id,f)}),c.jsxs(Ie,{size:"sm",variant:t.is_due?"primary":"secondary",onClick:()=>e(t.id),disabled:!t.enabled,className:"!px-3",children:[c.jsx(Im,{className:"w-3.5 h-3.5"}),"Reset"]})]})]})})}function tGe({overview:t,onPerform:e,onToggle:n,onSetHours:r}){const[i,s]=M.useState(!0),[a,o]=M.useState(!1),[l,u]=M.useState(t.total_print_hours.toFixed(1)),d=[...t.maintenance_items].sort((m,x)=>m.is_due&&!x.is_due?-1:!m.is_due&&x.is_due?1:m.is_warning&&!x.is_warning?-1:!m.is_warning&&x.is_warning?1:m.maintenance_type_id-x.maintenance_type_id),f=d.find(m=>m.enabled&&(m.is_due||m.is_warning)),g=()=>{const m=parseFloat(l);!isNaN(m)&&m>=0&&(r(t.printer_id,m),o(!1))};return c.jsxs(Nt,{className:"overflow-hidden",children:[c.jsxs("div",{className:"p-5",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-4",children:[c.jsx("h2",{className:"text-xl font-semibold text-white",children:t.printer_name}),c.jsxs("div",{className:"flex items-center gap-2",children:[t.due_count>0&&c.jsxs("span",{className:"px-2.5 py-1 bg-red-500/20 text-red-400 text-xs font-medium rounded-full flex items-center gap-1.5",children:[c.jsx(Qr,{className:"w-3 h-3"}),t.due_count," overdue"]}),t.warning_count>0&&c.jsxs("span",{className:"px-2.5 py-1 bg-amber-500/20 text-amber-400 text-xs font-medium rounded-full flex items-center gap-1.5",children:[c.jsx(ti,{className:"w-3 h-3"}),t.warning_count," due soon"]}),t.due_count===0&&t.warning_count===0&&c.jsxs("span",{className:"px-2.5 py-1 bg-bambu-green/20 text-bambu-green text-xs font-medium rounded-full flex items-center gap-1.5",children:[c.jsx(Ph,{className:"w-3 h-3"}),"All good"]})]})]}),c.jsxs("button",{onClick:()=>s(!i),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm text-bambu-gray hover:text-white hover:bg-bambu-dark rounded-lg transition-colors",children:[i?c.jsx(mS,{className:"w-4 h-4"}):c.jsx(ef,{className:"w-4 h-4"}),i?"Collapse":"Expand"]})]}),c.jsxs("div",{className:"flex items-center gap-6 mt-4",children:[c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("div",{className:"p-2 bg-bambu-dark/50 rounded-lg",children:c.jsx(Ou,{className:"w-4 h-4 text-bambu-gray"})}),a?c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("input",{type:"number",value:l,onChange:m=>u(m.target.value),onKeyDown:m=>{m.key==="Enter"&&g(),m.key==="Escape"&&o(!1)},className:"w-24 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm",min:"0",step:"1",autoFocus:!0}),c.jsx("span",{className:"text-xs text-bambu-gray",children:"hours"}),c.jsx(Ie,{size:"sm",onClick:g,children:"Save"}),c.jsx(Ie,{size:"sm",variant:"secondary",onClick:()=>o(!1),children:"Cancel"})]}):c.jsxs("button",{onClick:()=>{u(Math.round(t.total_print_hours).toString()),o(!0)},className:"group",children:[c.jsxs("div",{className:"text-sm font-medium text-white group-hover:text-bambu-green transition-colors flex items-center gap-1",children:[Math.floor(t.total_print_hours)," hours",c.jsx(d0,{className:"w-3 h-3 text-bambu-gray group-hover:text-bambu-green"})]}),c.jsx("div",{className:"text-xs text-bambu-gray",children:"Total print time"})]})]}),c.jsx("div",{className:"w-px h-10 bg-bambu-dark-tertiary"}),f&&c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("div",{className:`p-2 rounded-lg ${f.is_due?"bg-red-500/20":"bg-amber-500/20"}`,children:(()=>{const m=t0(f.maintenance_type_icon);return c.jsx(m,{className:`w-4 h-4 ${f.is_due?"text-red-400":"text-amber-400"}`})})()}),c.jsxs("div",{children:[c.jsx("div",{className:`text-sm font-medium ${f.is_due?"text-red-400":"text-amber-400"}`,children:f.maintenance_type_name}),c.jsx("div",{className:`text-xs ${f.is_due?"text-red-400/70":"text-amber-400/70"}`,children:f.is_due?"Overdue":"Due soon"})]})]})]})]}),i&&c.jsx(Dt,{className:"pt-0 border-t border-bambu-dark-tertiary",children:c.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-3 pt-4",children:d.map(m=>c.jsx(eGe,{item:m,onPerform:e,onToggle:n},m.id))})})]})}function nGe({overview:t,types:e,onUpdateInterval:n,onAddType:r,onUpdateType:i,onDeleteType:s}){const[a,o]=M.useState(null),[l,u]=M.useState(""),[d,f]=M.useState("hours"),[g,m]=M.useState(!1),[x,y]=M.useState(""),[v,b]=M.useState("100"),[E,S]=M.useState("hours"),[A,T]=M.useState("Wrench"),[P,C]=M.useState(null),[I,N]=M.useState(""),[D,F]=M.useState(""),[L,q]=M.useState("hours"),[R,V]=M.useState("Wrench"),K=ee=>{C(ee),N(ee.name),F(ee.default_interval_hours.toString()),q(ee.interval_type||"hours"),V(ee.icon||"Wrench")},W=()=>{P&&I.trim()&&parseFloat(D)>0&&(i(P.id,{name:I.trim(),default_interval_hours:parseFloat(D),interval_type:L,icon:R}),C(null))},ne=(ee,ae,fe)=>{const ue=parseFloat(l);if(!isNaN(ue)&&ue>0){const xe=Math.abs(ue-ae)<.01?null:ue;n(ee,{custom_interval_hours:xe,custom_interval_type:d!==fe?d:null})}o(null)},Y=ee=>{ee.preventDefault(),x.trim()&&parseFloat(v)>0&&(r({name:x.trim(),default_interval_hours:parseFloat(v),interval_type:E,icon:A}),y(""),b("100"),S("hours"),m(!1))},Z=t?.map(ee=>({printerId:ee.printer_id,printerName:ee.printer_name,items:ee.maintenance_items.sort((ae,fe)=>ae.maintenance_type_id-fe.maintenance_type_id)})).sort((ee,ae)=>ee.printerName.localeCompare(ae.printerName))||[],U=e.filter(ee=>ee.is_system),$=e.filter(ee=>!ee.is_system);return c.jsxs("div",{className:"space-y-8",children:[c.jsxs("div",{children:[c.jsxs("div",{className:"flex items-center justify-between mb-4",children:[c.jsxs("div",{children:[c.jsx("h2",{className:"text-lg font-semibold text-white",children:"Maintenance Types"}),c.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:"System types and your custom maintenance tasks"})]}),c.jsxs(Ie,{onClick:()=>m(!g),children:[c.jsx(fr,{className:"w-4 h-4"}),"Add Custom Type"]})]}),g&&c.jsx(Nt,{className:"mb-6",children:c.jsx(Dt,{className:"py-4",children:c.jsxs("form",{onSubmit:Y,children:[c.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:[c.jsxs("div",{className:"lg:col-span-2",children:[c.jsx("label",{className:"block text-xs text-bambu-gray mb-1.5",children:"Name"}),c.jsx("input",{type:"text",value:x,onChange:ee=>y(ee.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none",placeholder:"e.g., Replace HEPA Filter",autoFocus:!0})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-xs text-bambu-gray mb-1.5",children:"Interval Type"}),c.jsxs("select",{value:E,onChange:ee=>{S(ee.target.value),ee.target.value==="days"?b("30"):b("100")},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none",children:[c.jsx("option",{value:"hours",children:"Print Hours"}),c.jsx("option",{value:"days",children:"Calendar Days"})]})]}),c.jsxs("div",{children:[c.jsxs("label",{className:"block text-xs text-bambu-gray mb-1.5",children:["Interval (",E==="days"?"days":"hours",")"]}),c.jsx("input",{type:"number",value:v,onChange:ee=>b(ee.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none",min:"1"})]})]}),c.jsxs("div",{className:"mt-4 flex items-end justify-between",children:[c.jsxs("div",{children:[c.jsx("label",{className:"block text-xs text-bambu-gray mb-1.5",children:"Icon"}),c.jsx("div",{className:"flex gap-1",children:Object.keys(Px).map(ee=>{const ae=Px[ee];return c.jsx("button",{type:"button",onClick:()=>T(ee),className:`p-2 rounded-lg transition-colors ${A===ee?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary"}`,children:c.jsx(ae,{className:"w-4 h-4"})},ee)})})]}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(Ie,{type:"button",variant:"secondary",onClick:()=>m(!1),children:"Cancel"}),c.jsx(Ie,{type:"submit",disabled:!x.trim(),children:"Add Type"})]})]})]})})}),c.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3",children:[U.map(ee=>{const ae=t0(ee.icon),fe=ee.interval_type||"hours";return c.jsx("div",{className:"bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-dark-tertiary",children:c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("div",{className:"p-2.5 bg-bambu-dark rounded-lg",children:c.jsx(ae,{className:"w-5 h-5 text-bambu-gray"})}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsx("div",{className:"text-sm font-medium text-white truncate",children:ee.name}),c.jsxs("div",{className:"text-xs text-bambu-gray mt-0.5 flex items-center gap-1",children:[fe==="days"?c.jsx(qr,{className:"w-3 h-3"}):c.jsx(Ou,{className:"w-3 h-3"}),VN(ee.default_interval_hours,fe)]})]})]})},ee.id)}),$.map(ee=>{const ae=t0(ee.icon),fe=ee.interval_type||"hours";return P?.id===ee.id?c.jsx("div",{className:"bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-green",children:c.jsxs("div",{className:"space-y-3",children:[c.jsx("input",{type:"text",value:I,onChange:xe=>N(xe.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none",placeholder:"Name",autoFocus:!0}),c.jsxs("div",{className:"flex gap-2",children:[c.jsxs("select",{value:L,onChange:xe=>q(xe.target.value),className:"flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none",children:[c.jsx("option",{value:"hours",children:"Print Hours"}),c.jsx("option",{value:"days",children:"Calendar Days"})]}),c.jsx("input",{type:"number",value:D,onChange:xe=>F(xe.target.value),className:"w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none",min:"1"})]}),c.jsx("div",{className:"flex flex-wrap gap-1",children:Object.keys(Px).map(xe=>{const Me=Px[xe];return c.jsx("button",{type:"button",onClick:()=>V(xe),className:`p-1.5 rounded transition-colors ${R===xe?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:c.jsx(Me,{className:"w-3.5 h-3.5"})},xe)})}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(Ie,{size:"sm",onClick:W,disabled:!I.trim(),children:"Save"}),c.jsx(Ie,{size:"sm",variant:"secondary",onClick:()=>C(null),children:"Cancel"})]})]})},ee.id):c.jsx("div",{className:"bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-green/30",children:c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("div",{className:"p-2.5 bg-bambu-green/20 rounded-lg",children:c.jsx(ae,{className:"w-5 h-5 text-bambu-green"})}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"text-sm font-medium text-white truncate",children:ee.name}),c.jsx("span",{className:"px-1.5 py-0.5 bg-bambu-green/20 text-bambu-green text-[10px] font-medium rounded",children:"Custom"})]}),c.jsxs("div",{className:"text-xs text-bambu-gray mt-0.5 flex items-center gap-1",children:[fe==="days"?c.jsx(qr,{className:"w-3 h-3"}):c.jsx(Ou,{className:"w-3 h-3"}),VN(ee.default_interval_hours,fe)]})]}),c.jsx("button",{onClick:()=>K(ee),className:"p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors",children:c.jsx(d0,{className:"w-4 h-4"})}),c.jsx("button",{onClick:()=>{confirm(`Delete "${ee.name}"?`)&&s(ee.id)},className:"p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-red-400 transition-colors",children:c.jsx(kn,{className:"w-4 h-4"})})]})},ee.id)})]})]}),Z.length>0&&c.jsxs("div",{children:[c.jsxs("div",{className:"mb-4",children:[c.jsx("h2",{className:"text-lg font-semibold text-white",children:"Interval Overrides"}),c.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:"Customize intervals for specific printers"})]}),c.jsx("div",{className:"space-y-4",children:Z.map(ee=>c.jsx(Nt,{children:c.jsxs(Dt,{className:"py-4",children:[c.jsx("h3",{className:"text-sm font-medium text-white mb-3",children:ee.printerName}),c.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-2",children:ee.items.map(ae=>{const fe=t0(ae.maintenance_type_icon),ue=e.find(je=>je.id===ae.maintenance_type_id),xe=ue?.default_interval_hours||ae.interval_hours,Me=ue?.interval_type||"hours",se=ae.interval_type||"hours",ve=a===ae.id;return c.jsxs("div",{className:"flex items-center gap-2 p-2.5 bg-bambu-dark rounded-lg",children:[c.jsx(fe,{className:"w-4 h-4 text-bambu-gray shrink-0"}),c.jsx("span",{className:"text-xs text-bambu-gray flex-1 truncate",children:ae.maintenance_type_name}),ve?c.jsxs("div",{className:"flex items-center gap-1",children:[d==="days"?c.jsx(qr,{className:"w-3.5 h-3.5 text-bambu-gray shrink-0"}):c.jsx(Ou,{className:"w-3.5 h-3.5 text-bambu-gray shrink-0"}),c.jsxs("select",{value:d,onChange:je=>f(je.target.value),className:"px-1.5 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs",children:[c.jsx("option",{value:"hours",children:"Print Hours"}),c.jsx("option",{value:"days",children:"Calendar Days"})]}),c.jsx("input",{type:"number",value:l,onChange:je=>u(je.target.value),onKeyDown:je=>{je.key==="Enter"&&ne(ae.id,xe,Me),je.key==="Escape"&&o(null)},className:"w-16 px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs",min:"1"}),c.jsx(Ie,{size:"sm",onClick:()=>ne(ae.id,xe,Me),children:"OK"})]}):c.jsxs("button",{onClick:()=>{o(ae.id),u(ae.interval_hours.toString()),f(se)},className:"px-2 py-1 bg-bambu-dark-tertiary hover:bg-bambu-dark-secondary border border-bambu-dark-tertiary hover:border-bambu-green rounded text-xs font-medium text-white transition-colors flex items-center gap-1",children:[se==="days"?c.jsx(qr,{className:"w-3 h-3"}):c.jsx(Ou,{className:"w-3 h-3"}),VN(ae.interval_hours,se),c.jsx(d0,{className:"w-3 h-3 text-bambu-gray"})]})]},ae.id)})})]})},ee.printerId))})]}),Z.length===0&&c.jsx(Nt,{children:c.jsxs(Dt,{className:"text-center py-12",children:[c.jsx(ti,{className:"w-12 h-12 mx-auto mb-4 text-bambu-gray/30"}),c.jsx("p",{className:"text-bambu-gray",children:"No printers configured"}),c.jsx("p",{className:"text-sm text-bambu-gray/70 mt-1",children:"Add printers to configure maintenance intervals"})]})})]})}function rGe(){const t=Sn(),{showToast:e}=ri(),[n,r]=M.useState("status"),{data:i,isLoading:s}=yt({queryKey:["maintenanceOverview"],queryFn:Pe.getMaintenanceOverview}),{data:a}=yt({queryKey:["maintenanceTypes"],queryFn:Pe.getMaintenanceTypes}),o=_t({mutationFn:({id:E,notes:S})=>Pe.performMaintenance(E,S),onSuccess:()=>{t.invalidateQueries({queryKey:["maintenanceOverview"]}),t.invalidateQueries({queryKey:["maintenanceSummary"]}),e("Maintenance marked as complete")},onError:E=>{e(E.message,"error")}}),l=_t({mutationFn:({id:E,data:S})=>Pe.updateMaintenanceItem(E,S),onSuccess:()=>{t.invalidateQueries({queryKey:["maintenanceOverview"]})},onError:E=>{e(E.message,"error")}}),u=_t({mutationFn:Pe.createMaintenanceType,onSuccess:()=>{t.invalidateQueries({queryKey:["maintenanceTypes"]}),t.invalidateQueries({queryKey:["maintenanceOverview"]}),e("Maintenance type added")},onError:E=>{e(E.message,"error")}}),d=_t({mutationFn:({id:E,data:S})=>Pe.updateMaintenanceType(E,S),onSuccess:()=>{t.invalidateQueries({queryKey:["maintenanceTypes"]}),t.invalidateQueries({queryKey:["maintenanceOverview"]}),e("Maintenance type updated")},onError:E=>{e(E.message,"error")}}),f=_t({mutationFn:Pe.deleteMaintenanceType,onSuccess:()=>{t.invalidateQueries({queryKey:["maintenanceTypes"]}),t.invalidateQueries({queryKey:["maintenanceOverview"]}),e("Maintenance type deleted")},onError:E=>{e(E.message,"error")}}),g=_t({mutationFn:({printerId:E,hours:S})=>Pe.setPrinterHours(E,S),onSuccess:()=>{t.invalidateQueries({queryKey:["maintenanceOverview"]}),t.invalidateQueries({queryKey:["maintenanceSummary"]}),e("Print hours updated")},onError:E=>{e(E.message,"error")}}),m=E=>{o.mutate({id:E})},x=(E,S)=>{l.mutate({id:E,data:{enabled:S}})},y=(E,S)=>{g.mutate({printerId:E,hours:S})};if(s)return c.jsx("div",{className:"p-4 md:p-8 flex justify-center",children:c.jsx(At,{className:"w-8 h-8 text-bambu-green animate-spin"})});const v=i?.reduce((E,S)=>E+S.due_count,0)||0,b=i?.reduce((E,S)=>E+S.warning_count,0)||0;return c.jsxs("div",{className:"p-4 md:p-8",children:[c.jsxs("div",{className:"mb-6",children:[c.jsx("h1",{className:"text-2xl font-bold text-white",children:"Maintenance"}),c.jsx("p",{className:"text-bambu-gray text-sm mt-1",children:n==="status"?c.jsxs(c.Fragment,{children:[v>0&&c.jsxs("span",{className:"text-red-400",children:[v," task",v!==1?"s":""," overdue"]}),v>0&&b>0&&" · ",b>0&&c.jsxs("span",{className:"text-amber-400",children:[b," due soon"]}),v===0&&b===0&&c.jsx("span",{className:"text-bambu-green",children:"All maintenance up to date"})]}):"Configure maintenance types and intervals"})]}),c.jsxs("div",{className:"flex gap-1 mb-6 border-b border-bambu-dark-tertiary",children:[c.jsx("button",{onClick:()=>r("status"),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${n==="status"?"text-bambu-green border-bambu-green":"text-bambu-gray border-transparent hover:text-white"}`,children:"Status"}),c.jsx("button",{onClick:()=>r("settings"),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${n==="settings"?"text-bambu-green border-bambu-green":"text-bambu-gray border-transparent hover:text-white"}`,children:"Settings"})]}),n==="status"?c.jsx("div",{className:"space-y-6",children:i&&i.length>0?[...i].sort((E,S)=>{const A=E.due_count*10+E.warning_count,T=S.due_count*10+S.warning_count;return A!==T?T-A:E.printer_name.localeCompare(S.printer_name)}).map(E=>c.jsx(tGe,{overview:E,onPerform:m,onToggle:x,onSetHours:y},E.printer_id)):c.jsx(Nt,{children:c.jsxs(Dt,{className:"text-center py-16",children:[c.jsx(Ju,{className:"w-16 h-16 mx-auto mb-4 text-bambu-gray/30"}),c.jsx("p",{className:"text-lg font-medium text-white mb-2",children:"No printers configured"}),c.jsx("p",{className:"text-bambu-gray",children:"Add printers to start tracking maintenance"})]})})}):c.jsx(nGe,{overview:i,types:a||[],onUpdateInterval:(E,S)=>l.mutate({id:E,data:S}),onAddType:E=>u.mutate(E),onUpdateType:(E,S)=>d.mutate({id:E,data:S}),onDeleteType:E=>f.mutate(E)})]})}const B9=["#ef4444","#f97316","#eab308","#22c55e","#06b6d4","#3b82f6","#8b5cf6","#ec4899","#6b7280"];function iGe({project:t,onClose:e,onSave:n,isLoading:r}){const[i,s]=M.useState(t?.name||""),[a,o]=M.useState(t?.description||""),[l,u]=M.useState(t?.color||B9[0]),[d,f]=M.useState(t?.target_count?.toString()||""),[g,m]=M.useState(t?.status||"active"),x=y=>{y.preventDefault(),n({name:i.trim(),description:a.trim()||void 0,color:l,target_count:d?parseInt(d,10):void 0,...t&&{status:g}})};return c.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:c.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary",children:[c.jsx("div",{className:"p-4 border-b border-bambu-dark-tertiary",children:c.jsx("h2",{className:"text-lg font-semibold text-white",children:t?"Edit Project":"New Project"})}),c.jsxs("form",{onSubmit:x,className:"p-4 space-y-4",children:[c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:"Name"}),c.jsx("input",{type:"text",value:i,onChange:y=>s(y.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:"e.g., Voron 2.4 Build",required:!0})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:"Description"}),c.jsx("textarea",{value:a,onChange:y=>o(y.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green resize-none",placeholder:"Optional description...",rows:2})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:"Color"}),c.jsx("div",{className:"flex gap-2 flex-wrap",children:B9.map(y=>c.jsx("button",{type:"button",onClick:()=>u(y),className:`w-8 h-8 rounded-full transition-transform ${l===y?"ring-2 ring-white ring-offset-2 ring-offset-bambu-dark-secondary scale-110":""}`,style:{backgroundColor:y}},y))})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:"Target Print Count (optional)"}),c.jsx("input",{type:"number",value:d,onChange:y=>f(y.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:"e.g., 50 parts to print",min:"1"})]}),t&&c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:"Status"}),c.jsxs("select",{value:g,onChange:y=>m(y.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green",children:[c.jsx("option",{value:"active",children:"Active"}),c.jsx("option",{value:"completed",children:"Completed"}),c.jsx("option",{value:"archived",children:"Archived"})]})]}),c.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[c.jsx(Ie,{type:"button",variant:"secondary",onClick:e,children:"Cancel"}),c.jsx(Ie,{type:"submit",disabled:!i.trim()||r,children:r?c.jsx(At,{className:"w-4 h-4 animate-spin"}):t?"Save":"Create"})]})]})]})})}function sGe({project:t,onClick:e,onEdit:n,onDelete:r}){const i=t.progress_percent??0,s=t.status==="completed",a=t.status==="archived";return c.jsx(Nt,{className:"hover:border-bambu-gray/30 transition-colors cursor-pointer",onClick:e,children:c.jsxs(Dt,{className:"p-4",children:[c.jsxs("div",{className:"flex items-start justify-between mb-3",children:[c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("div",{className:"w-3 h-3 rounded-full flex-shrink-0",style:{backgroundColor:t.color||"#6b7280"}}),c.jsxs("div",{children:[c.jsx("h3",{className:"font-medium text-white",children:t.name}),t.description&&c.jsx("p",{className:"text-sm text-bambu-gray/70 mt-0.5 line-clamp-1",children:t.description})]})]}),c.jsxs("div",{className:"flex items-center gap-1",onClick:o=>o.stopPropagation(),children:[s&&c.jsx("span",{className:"text-xs bg-bambu-green/20 text-bambu-green px-2 py-0.5 rounded",children:"Completed"}),a&&c.jsx("span",{className:"text-xs bg-bambu-gray/20 text-bambu-gray px-2 py-0.5 rounded",children:"Archived"}),c.jsx(Ie,{variant:"ghost",size:"sm",onClick:n,className:"p-1",children:c.jsx(d0,{className:"w-4 h-4"})}),c.jsx(Ie,{variant:"ghost",size:"sm",onClick:r,className:"p-1 text-red-400 hover:text-red-300",children:c.jsx(kn,{className:"w-4 h-4"})})]})]}),t.target_count&&c.jsxs("div",{className:"mb-3",children:[c.jsxs("div",{className:"flex justify-between text-xs text-bambu-gray mb-1",children:[c.jsxs("span",{children:[t.archive_count," / ",t.target_count," prints"]}),c.jsxs("span",{children:[i.toFixed(0),"%"]})]}),c.jsx("div",{className:"h-2 bg-bambu-dark rounded-full overflow-hidden",children:c.jsx("div",{className:"h-full transition-all duration-300",style:{width:`${Math.min(i,100)}%`,backgroundColor:i>=100?"#22c55e":t.color||"#6b7280"}})})]}),t.archives&&t.archives.length>0&&c.jsx("div",{className:"mb-3",children:c.jsxs("div",{className:"flex gap-2",children:[t.archives.slice(0,5).map(o=>c.jsxs("a",{href:`/archives?search=${encodeURIComponent(o.print_name||"")}`,onClick:l=>l.stopPropagation(),className:"relative w-14 h-14 rounded-lg bg-bambu-dark flex-shrink-0 overflow-hidden border border-bambu-dark-tertiary hover:border-bambu-green transition-colors",title:o.print_name||"Unknown",children:[o.thumbnail_path?c.jsx("img",{src:`/api/v1/archives/${o.id}/thumbnail`,alt:o.print_name||"",className:"w-full h-full object-cover"}):c.jsx("div",{className:"w-full h-full flex items-center justify-center text-bambu-gray",children:c.jsx(u0,{className:"w-6 h-6"})}),o.status==="failed"&&c.jsx("div",{className:"absolute inset-0 bg-red-500/40 flex items-center justify-center",children:c.jsx("span",{className:"text-white text-xs font-bold",children:"✗"})})]},o.id)),t.archive_count>5&&c.jsxs("div",{className:"w-14 h-14 rounded-lg bg-bambu-dark flex-shrink-0 flex items-center justify-center text-sm text-bambu-gray border border-bambu-dark-tertiary",children:["+",t.archive_count-5]})]})}),c.jsxs("div",{className:"flex items-center gap-4 text-sm text-bambu-gray",children:[c.jsxs("div",{className:"flex items-center gap-1",title:"Archives",children:[c.jsx(pS,{className:"w-4 h-4"}),c.jsx("span",{children:t.archive_count})]}),c.jsxs("div",{className:"flex items-center gap-1",title:"Queued",children:[c.jsx(ole,{className:"w-4 h-4"}),c.jsx("span",{children:t.queue_count})]})]})]})})}function aGe(){const t=Sn(),{showToast:e}=ri(),[n,r]=M.useState(!1),[i,s]=M.useState(),[a,o]=M.useState("active"),[l,u]=M.useState(null),{data:d,isLoading:f}=yt({queryKey:["projects",a==="all"?void 0:a],queryFn:()=>Pe.getProjects(a==="all"?void 0:a)}),g=_t({mutationFn:A=>Pe.createProject(A),onSuccess:()=>{t.invalidateQueries({queryKey:["projects"]}),r(!1),e("Project created","success")},onError:A=>{e(A.message,"error")}}),m=_t({mutationFn:({id:A,data:T})=>Pe.updateProject(A,T),onSuccess:()=>{t.invalidateQueries({queryKey:["projects"]}),r(!1),s(void 0),e("Project updated","success")},onError:A=>{e(A.message,"error")}}),x=_t({mutationFn:A=>Pe.deleteProject(A),onSuccess:()=>{t.invalidateQueries({queryKey:["projects"]}),u(null),e("Project deleted","success")},onError:A=>{e(A.message,"error")}}),y=A=>{i?m.mutate({id:i.id,data:A}):g.mutate(A)},v=A=>{s(A),r(!0)},b=A=>{v(A)},E=A=>{u(A)},S=()=>{l!==null&&x.mutate(l)};return c.jsxs("div",{className:"space-y-6",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx(ph,{className:"w-6 h-6 text-bambu-green"}),c.jsx("h1",{className:"text-2xl font-bold text-white",children:"Projects"})]}),c.jsxs(Ie,{onClick:()=>r(!0),children:[c.jsx(fr,{className:"w-4 h-4 mr-2"}),"New Project"]})]}),c.jsx("div",{className:"flex gap-2",children:["active","completed","archived","all"].map(A=>c.jsx("button",{onClick:()=>o(A),className:`px-3 py-1.5 text-sm rounded-lg transition-colors ${a===A?"bg-bambu-green text-white":"bg-bambu-card text-bambu-gray hover:bg-bambu-gray/20"}`,children:A.charAt(0).toUpperCase()+A.slice(1)},A))}),f?c.jsx("div",{className:"flex items-center justify-center py-12",children:c.jsx(At,{className:"w-8 h-8 animate-spin text-bambu-green"})}):d?.length===0?c.jsx(Nt,{children:c.jsxs(Dt,{className:"py-12 text-center",children:[c.jsx(ph,{className:"w-12 h-12 text-bambu-gray/50 mx-auto mb-4"}),c.jsx("p",{className:"text-bambu-gray",children:"No projects found"}),c.jsx("p",{className:"text-bambu-gray/70 text-sm mt-1",children:"Create a project to group related prints together"})]})}):c.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:d?.map(A=>c.jsx(sGe,{project:A,onClick:()=>b(A),onEdit:()=>v(A),onDelete:()=>E(A.id)},A.id))}),l!==null&&c.jsx(Kr,{title:"Delete Project",message:"Are you sure you want to delete this project? Archives and queue items will be unlinked but not deleted.",confirmText:"Delete Project",variant:"danger",onConfirm:S,onCancel:()=>u(null)}),n&&c.jsx(iGe,{project:i,onClose:()=>{r(!1),s(void 0)},onSave:y,isLoading:g.isPending||m.isPending})]})}function oGe(){const{printerId:t}=lG(),e=parseInt(t||"0",10),[n,r]=M.useState("stream"),[i,s]=M.useState(!1),[a,o]=M.useState(!0),[l,u]=M.useState(Date.now()),[d,f]=M.useState(!1),[g,m]=M.useState(!1),x=M.useRef(null),y=M.useRef(null),{data:v}=yt({queryKey:["printer",e],queryFn:()=>Pe.getPrinter(e),enabled:e>0});M.useEffect(()=>(v&&(document.title=`${v.name} - Camera`),()=>{document.title="Bambuddy"}),[v]),M.useEffect(()=>()=>{x.current&&(x.current.src="")},[]),M.useEffect(()=>{if(a&&!d){const N=setTimeout(()=>{o(!1)},n==="stream"?3e3:2e4);return()=>clearTimeout(N)}},[n,a,l,d]),M.useEffect(()=>{const I=()=>{m(!!document.fullscreenElement)};return document.addEventListener("fullscreenchange",I),()=>document.removeEventListener("fullscreenchange",I)},[]);const b=()=>{s(!0),o(!1)},E=()=>{o(!1),s(!1)},S=I=>{n===I||d||(f(!0),o(!0),s(!1),x.current&&(x.current.src=""),setTimeout(()=>{r(I),u(Date.now()),f(!1)},100))},A=()=>{d||(f(!0),o(!0),s(!1),x.current&&(x.current.src=""),setTimeout(()=>{u(Date.now()),f(!1)},100))},T=()=>{y.current&&(document.fullscreenElement?document.exitFullscreen():y.current.requestFullscreen())},P=d?"":n==="stream"?`/api/v1/printers/${e}/camera/stream?fps=10&t=${l}`:`/api/v1/printers/${e}/camera/snapshot?t=${l}`,C=a||d;return e?c.jsxs("div",{ref:y,className:"min-h-screen bg-black flex flex-col",children:[c.jsxs("div",{className:"flex items-center justify-between px-4 py-2 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary",children:[c.jsxs("h1",{className:"text-sm font-medium text-white flex items-center gap-2",children:[c.jsx(a0,{className:"w-4 h-4"}),v?.name||`Printer ${e}`]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("div",{className:"flex bg-bambu-dark rounded p-0.5",children:[c.jsx("button",{onClick:()=>S("stream"),disabled:C,className:`px-3 py-1 text-xs rounded transition-colors ${n==="stream"?"bg-bambu-green text-white":"text-bambu-gray hover:text-white disabled:opacity-50"}`,children:"Live"}),c.jsx("button",{onClick:()=>S("snapshot"),disabled:C,className:`px-3 py-1 text-xs rounded transition-colors ${n==="snapshot"?"bg-bambu-green text-white":"text-bambu-gray hover:text-white disabled:opacity-50"}`,children:"Snapshot"})]}),c.jsx("button",{onClick:A,disabled:C,className:"p-1.5 hover:bg-bambu-dark-tertiary rounded disabled:opacity-50",title:n==="stream"?"Restart stream":"Refresh snapshot",children:c.jsx(qs,{className:`w-4 h-4 text-bambu-gray ${C?"animate-spin":""}`})}),c.jsx("button",{onClick:T,className:"p-1.5 hover:bg-bambu-dark-tertiary rounded",title:g?"Exit fullscreen":"Fullscreen",children:g?c.jsx(Ale,{className:"w-4 h-4 text-bambu-gray"}):c.jsx(yle,{className:"w-4 h-4 text-bambu-gray"})})]})]}),c.jsx("div",{className:"flex-1 flex items-center justify-center p-2",children:c.jsxs("div",{className:"relative w-full h-full flex items-center justify-center",children:[(a||d)&&c.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/50 z-10",children:c.jsxs("div",{className:"text-center",children:[c.jsx(qs,{className:"w-8 h-8 text-bambu-gray animate-spin mx-auto mb-2"}),c.jsx("p",{className:"text-sm text-bambu-gray",children:n==="stream"?"Connecting to camera...":"Capturing snapshot..."})]})}),i&&c.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black z-10",children:c.jsxs("div",{className:"text-center p-4",children:[c.jsx(Qr,{className:"w-12 h-12 text-orange-400 mx-auto mb-3"}),c.jsx("p",{className:"text-white mb-2",children:"Camera unavailable"}),c.jsx("p",{className:"text-xs text-bambu-gray mb-4 max-w-md",children:"Make sure the printer is powered on and connected."}),c.jsx("button",{onClick:A,className:"px-4 py-2 bg-bambu-green text-white rounded hover:bg-bambu-green/80 transition-colors",children:"Retry"})]})}),c.jsx("img",{ref:x,src:P,alt:"Camera stream",className:"max-w-full max-h-full object-contain",onError:P?b:void 0,onLoad:P?E:void 0},l)]})})]}):c.jsx("div",{className:"min-h-screen bg-black flex items-center justify-center",children:c.jsx("p",{className:"text-white",children:"Invalid printer ID"})})}function lGe(){const{id:t}=lG(),{theme:e}=yS(),{data:n,isLoading:r,error:i}=yt({queryKey:["external-link",t],queryFn:()=>Pe.getExternalLink(Number(t)),enabled:!!t});return r?c.jsx("div",{className:"flex items-center justify-center h-full",children:c.jsx(At,{className:"w-8 h-8 text-bambu-green animate-spin"})}):i||!n?c.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-4 text-bambu-gray",children:[c.jsx(Qr,{className:"w-12 h-12"}),c.jsx("p",{children:"Link not found"})]}):c.jsx("iframe",{src:n.url,className:"h-full w-full border-0",style:{colorScheme:e},title:n.name,sandbox:"allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox"})}function cGe(){const t=M.useRef(null),e=M.useRef(null),n=Sn(),[r,i]=M.useState(!1),s=M.useCallback(()=>{if(t.current?.readyState===WebSocket.OPEN)return;const u=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/api/v1/ws`,d=new WebSocket(u);let f=null;d.onopen=()=>{console.log("[WebSocket] Connected"),i(!0),f=window.setInterval(()=>{d.readyState===WebSocket.OPEN&&d.send(JSON.stringify({type:"ping"}))},3e4)},d.onmessage=g=>{try{const m=JSON.parse(g.data);a(m)}catch{}},d.onclose=g=>{console.log("[WebSocket] Closed",g.code,g.reason),f&&(clearInterval(f),f=null),i(!1),t.current=null,e.current=window.setTimeout(()=>{s()},3e3)},d.onerror=g=>{console.error("[WebSocket] Error",g),d.close()},t.current=d},[]),a=M.useCallback(l=>{switch(l.type){case"printer_status":l.printer_id!==void 0&&n.setQueryData(["printerStatus",l.printer_id],u=>{const d={...u,...l.data};return d.wifi_signal==null&&u?.wifi_signal!=null&&(d.wifi_signal=u.wifi_signal),d});break;case"print_complete":n.invalidateQueries({queryKey:["archives"]}),n.invalidateQueries({queryKey:["archiveStats"]});break;case"archive_created":n.invalidateQueries({queryKey:["archives"]}),n.invalidateQueries({queryKey:["archiveStats"]});break}},[n]);M.useEffect(()=>(s(),()=>{e.current&&clearTimeout(e.current),t.current&&t.current.close()}),[s]);const o=M.useCallback(l=>{t.current?.readyState===WebSocket.OPEN&&t.current.send(JSON.stringify(l))},[]);return{isConnected:r,sendMessage:o}}const uGe=new Wse({defaultOptions:{queries:{staleTime:1e3*60,retry:1}}});function dGe({children:t}){return cGe(),c.jsx(c.Fragment,{children:t})}function hGe(){return c.jsx(iue,{children:c.jsx(pue,{children:c.jsx(qse,{client:uGe,children:c.jsx(dGe,{children:c.jsx(pse,{children:c.jsxs(Gie,{children:[c.jsx(La,{path:"/camera/:printerId",element:c.jsx(oGe,{})}),c.jsxs(La,{path:"/",element:c.jsx(due,{}),children:[c.jsx(La,{index:!0,element:c.jsx(Wue,{})}),c.jsx(La,{path:"archives",element:c.jsx(yNe,{})}),c.jsx(La,{path:"queue",element:c.jsx(ske,{})}),c.jsx(La,{path:"stats",element:c.jsx(E9e,{})}),c.jsx(La,{path:"profiles",element:c.jsx(J9e,{})}),c.jsx(La,{path:"maintenance",element:c.jsx(rGe,{})}),c.jsx(La,{path:"projects",element:c.jsx(aGe,{})}),c.jsx(La,{path:"settings",element:c.jsx(H9e,{})}),c.jsx(La,{path:"external/:id",element:c.jsx(lGe,{})})]})]})})})})})})}Xne.createRoot(document.getElementById("root")).render(c.jsx(M.StrictMode,{children:c.jsx(hGe,{})})); +`+n+"}"}return String(t)}function X9e({setting:t,onClose:e,onDeleted:n,onDuplicate:r,onEdit:i}){const{showToast:s}=ri(),a=Sn(),[o,l]=M.useState(!1),{data:u,isLoading:d}=yt({queryKey:["cloudSettingDetail",t.setting_id],queryFn:()=>Pe.getCloudSettingDetail(t.setting_id)}),f=_t({mutationFn:()=>Pe.deleteCloudSetting(t.setting_id),onSuccess:()=>{s("Preset deleted"),a.invalidateQueries({queryKey:["cloudSettings"]}),n()},onError:x=>s(x.message,"error")}),g=J0(t.setting_id),m=Gj(t.name,u?.setting?.inherits);return c.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:c.jsx(Nt,{className:"w-full max-w-3xl max-h-[90vh] flex flex-col overflow-hidden",children:c.jsxs(Dt,{className:"p-0 flex flex-col min-h-0 flex-1",children:[c.jsxs("div",{className:"flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("h2",{className:"text-xl font-semibold text-white truncate",children:t.name}),g&&c.jsx("span",{className:"px-2 py-0.5 text-xs font-medium bg-bambu-green/20 text-bambu-green rounded-full",children:"Editable"})]}),c.jsxs("div",{className:"flex items-center gap-2 mt-1 text-sm text-bambu-gray",children:[c.jsxs("span",{className:"capitalize",children:[t.type," preset"]}),m.printer&&c.jsxs(c.Fragment,{children:[c.jsx("span",{children:"•"}),c.jsx("span",{children:m.printer})]})]})]}),c.jsx("button",{onClick:e,className:"p-2 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors",children:c.jsx(Gt,{className:"w-5 h-5"})})]}),c.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto p-4",children:d?c.jsx("div",{className:"flex items-center justify-center py-16",children:c.jsx(At,{className:"w-8 h-8 text-bambu-green animate-spin"})}):u?c.jsx("pre",{className:"text-xs text-bambu-gray font-mono whitespace-pre-wrap break-all bg-bambu-dark p-4 rounded-lg border border-bambu-dark-tertiary overflow-x-auto max-w-full",children:nR(u)}):c.jsx("div",{className:"text-center py-16 text-bambu-gray",children:"Failed to load preset details"})}),o?c.jsxs("div",{className:"flex-shrink-0 p-4 border-t border-bambu-dark-tertiary bg-red-500/5",children:[c.jsxs("div",{className:"flex items-center gap-2 mb-3 text-red-400",children:[c.jsx(Qr,{className:"w-5 h-5"}),c.jsx("span",{className:"font-medium",children:"Delete this preset?"})]}),c.jsxs("p",{className:"text-sm text-bambu-gray mb-4",children:['This will permanently delete "',t.name,'" from Bambu Cloud. This cannot be undone.']}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(Ie,{variant:"secondary",onClick:()=>l(!1),disabled:f.isPending,className:"flex-1",children:"Cancel"}),c.jsxs(Ie,{variant:"danger",onClick:()=>f.mutate(),disabled:f.isPending,className:"flex-1",children:[f.isPending?c.jsx(At,{className:"w-4 h-4 animate-spin"}):c.jsx(kn,{className:"w-4 h-4"}),"Delete"]})]})]}):c.jsx("div",{className:"flex-shrink-0 p-4 border-t border-bambu-dark-tertiary",children:c.jsxs("div",{className:"flex gap-2",children:[c.jsx(Ie,{variant:"secondary",onClick:e,className:"flex-1",children:"Close"}),c.jsxs(Ie,{variant:"secondary",onClick:r,children:[c.jsx(Dh,{className:"w-4 h-4"}),"Duplicate"]}),g&&c.jsxs(c.Fragment,{children:[c.jsxs(Ie,{variant:"secondary",onClick:i,disabled:d||!u,children:[c.jsx(Zu,{className:"w-4 h-4"}),"Edit"]}),c.jsx(Ie,{variant:"danger",onClick:()=>l(!0),children:c.jsx(kn,{className:"w-4 h-4"})})]})]})})]})})})}function Ree(){try{const t=localStorage.getItem("bambusy_preset_templates");return t?JSON.parse(t):[]}catch{return[]}}function Dee(t){localStorage.setItem("bambusy_preset_templates",JSON.stringify(t))}function Y9e({onClose:t,onApply:e}){const{showToast:n}=ri(),[r,i]=M.useState(Ree),[s,a]=M.useState("all"),[o,l]=M.useState(null),[u,d]=M.useState(""),[f,g]=M.useState(""),[m,x]=M.useState("{}"),[y,v]=M.useState(null),[b,E]=M.useState(null),S=s==="all"?r:r.filter(L=>L.type===s),A=L=>{i(L),Dee(L)},T=L=>{const q=r.filter(R=>R.id!==L);A(q),E(null),n("Template deleted")},P=L=>{l(L.id),d(L.name),g(L.description),x(JSON.stringify(L.settings,null,2)),v(null)},C=()=>{if(!(!o||!u.trim()))try{const L=JSON.parse(m),q=r.map(R=>R.id===o?{...R,name:u.trim(),description:f.trim(),settings:L}:R);A(q),l(null),n("Template updated")}catch(L){v(L.message)}},I=()=>{l(null),d(""),g(""),x("{}"),v(null)},N=L=>{const q=r.map(R=>R.id===L?{...R,showInModal:!R.showInModal}:R);A(q)},D={filament:{label:"Filament",icon:pR,color:"text-amber-400"},print:{label:"Process",icon:vS,color:"text-blue-400"},printer:{label:"Printer",icon:jo,color:"text-purple-400"}},F=b?r.find(L=>L.id===b):null;return M.useEffect(()=>{const L=q=>{q.key==="Escape"&&(b?E(null):o?I():t())};return window.addEventListener("keydown",L),()=>window.removeEventListener("keydown",L)},[b,o,t]),c.jsxs("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:[F&&c.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-60",children:c.jsx(Nt,{className:"w-full max-w-md",children:c.jsxs(Dt,{className:"p-6",children:[c.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[c.jsx("div",{className:"p-2 bg-red-500/20 rounded-lg",children:c.jsx(Qr,{className:"w-6 h-6 text-red-400"})}),c.jsxs("div",{children:[c.jsx("h3",{className:"text-lg font-semibold text-white",children:"Delete Template"}),c.jsx("p",{className:"text-sm text-bambu-gray",children:"This action cannot be undone"})]})]}),c.jsxs("p",{className:"text-white mb-6",children:['Are you sure you want to delete "',c.jsx("span",{className:"font-medium",children:F.name}),'"?']}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(Ie,{variant:"secondary",onClick:()=>E(null),className:"flex-1",children:"Cancel"}),c.jsxs(Ie,{onClick:()=>T(b),className:"flex-1 bg-red-500 hover:bg-red-600",children:[c.jsx(kn,{className:"w-4 h-4"}),"Delete"]})]})]})})}),c.jsx(Nt,{className:"w-full max-w-2xl max-h-[80vh] flex flex-col",children:c.jsxs(Dt,{className:"p-0 flex flex-col h-full",children:[c.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[c.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[c.jsx(h0,{className:"w-5 h-5 text-amber-400"}),"Quick Templates"]}),c.jsx("button",{onClick:t,className:"text-bambu-gray hover:text-white",children:c.jsx(Gt,{className:"w-5 h-5"})})]}),c.jsxs("div",{className:"flex items-center gap-2 p-4 border-b border-bambu-dark-tertiary",children:[c.jsx("span",{className:"text-sm text-bambu-gray",children:"Type:"}),["all","filament","print","printer"].map(L=>c.jsx("button",{onClick:()=>a(L),className:`px-3 py-1 text-sm rounded-lg transition-colors ${s===L?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:L==="all"?"All":D[L].label},L))]}),c.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:S.length===0?c.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[c.jsx(h0,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),c.jsx("p",{children:"No templates yet"}),c.jsx("p",{className:"text-sm mt-1",children:"Create templates from the preset editor"})]}):c.jsx("div",{className:"space-y-2",children:S.map(L=>{const q=D[L.type],R=q.icon;return o===L.id?c.jsxs("div",{className:"p-4 bg-bambu-dark rounded-lg border border-bambu-green",children:[c.jsxs("div",{className:"grid grid-cols-2 gap-3 mb-3",children:[c.jsx("input",{type:"text",value:u,onChange:V=>d(V.target.value),placeholder:"Template name",className:"px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none",autoFocus:!0}),c.jsx("input",{type:"text",value:f,onChange:V=>g(V.target.value),placeholder:"Description",className:"px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none"})]}),c.jsxs("div",{className:"mb-3",children:[c.jsx("label",{className:"text-xs text-bambu-gray mb-1 block",children:"Settings (JSON)"}),c.jsx("textarea",{value:m,onChange:V=>{x(V.target.value),v(null)},rows:6,className:`w-full px-3 py-2 bg-bambu-dark-secondary border rounded text-white text-sm font-mono focus:outline-none ${y?"border-red-500":"border-bambu-dark-tertiary focus:border-bambu-green"}`}),y&&c.jsx("p",{className:"text-xs text-red-400 mt-1",children:y})]}),c.jsxs("div",{className:"flex gap-2",children:[c.jsxs(Ie,{size:"sm",onClick:C,disabled:!u.trim(),children:[c.jsx(To,{className:"w-4 h-4"}),"Save"]}),c.jsx(Ie,{size:"sm",variant:"secondary",onClick:I,children:"Cancel"})]})]},L.id):c.jsxs("div",{className:"flex items-center gap-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary hover:border-bambu-gray-dark transition-colors",children:[c.jsx(R,{className:`w-5 h-5 ${q.color} flex-shrink-0`}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsx("p",{className:"text-sm font-medium text-white",children:L.name}),c.jsx("p",{className:"text-xs text-bambu-gray truncate",children:L.description})]}),c.jsxs("span",{className:"text-xs text-bambu-gray-dark px-2 py-1 bg-bambu-dark-secondary rounded",children:[Object.keys(L.settings).length," fields"]}),c.jsx("button",{onClick:()=>N(L.id),className:`p-1 transition-colors ${L.showInModal?"text-bambu-green hover:text-bambu-green/70":"text-bambu-gray hover:text-white"}`,title:L.showInModal?"Shown in modals":"Hidden in modals",children:L.showInModal?c.jsx(o0,{className:"w-4 h-4"}):c.jsx(mR,{className:"w-4 h-4"})}),c.jsx("button",{onClick:()=>e(L),className:"px-3 py-1 text-xs bg-bambu-green/20 text-bambu-green rounded hover:bg-bambu-green/30 transition-colors",children:"Apply"}),c.jsx("button",{onClick:()=>P(L),className:"p-1 text-bambu-gray hover:text-white",title:"Edit",children:c.jsx(Zu,{className:"w-4 h-4"})}),c.jsx("button",{onClick:()=>E(L.id),className:"p-1 text-bambu-gray hover:text-red-400",title:"Delete",children:c.jsx(kn,{className:"w-4 h-4"})})]},L.id)})})})]})})]})}function Oee({onClose:t,leftPreset:e,rightPreset:n,leftLabel:r,rightLabel:i}){const[s,a]=M.useState("changes"),[o,l]=M.useState(""),u=M.useMemo(()=>{const m=new Set([...Object.keys(e),...Object.keys(n)]),x=[];for(const y of m){if(y==="inherits"||y==="version")continue;const v=e[y],b=n[y],E=y in e,S=y in n;let A;!E&&S?A="added":E&&!S?A="removed":JSON.stringify(v)!==JSON.stringify(b)?A="changed":A="same",x.push({key:y,left:v,right:b,status:A})}return x.sort((y,v)=>{const b={changed:0,added:1,removed:2,same:3};return b[y.status]!==b[v.status]?b[y.status]-b[v.status]:y.key.localeCompare(v.key)})},[e,n]),d=M.useMemo(()=>{let m=[...u];if(s==="changes"&&(m=m.filter(x=>x.status!=="same")),o){const x=o.toLowerCase();m=m.filter(y=>y.key.toLowerCase().includes(x)||String(y.left).toLowerCase().includes(x)||String(y.right).toLowerCase().includes(x))}return m},[u,s,o]),f=M.useMemo(()=>({added:u.filter(m=>m.status==="added").length,removed:u.filter(m=>m.status==="removed").length,changed:u.filter(m=>m.status==="changed").length,same:u.filter(m=>m.status==="same").length}),[u]),g=m=>{if(m===void 0)return"—";if(m===null)return"null";if(Array.isArray(m))return m.length===0?"[]":m.length===1?String(m[0]):m.join(", ");if(typeof m=="object")return JSON.stringify(m);const x=String(m);if(x.includes("\\n")||x.length>100){const y=x.split("\\n").length;if(y>1)return`[${y} lines of G-code/script]`;if(x.length>100)return x.substring(0,100)+"…"}return x};return M.useEffect(()=>{const m=x=>{x.key==="Escape"&&t()};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[t]),c.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:c.jsx(Nt,{className:"w-full max-w-4xl max-h-[85vh] flex flex-col overflow-hidden",children:c.jsxs(Dt,{className:"p-0 flex flex-col min-h-0 flex-1",children:[c.jsxs("div",{className:"flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[c.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[c.jsx(Hp,{className:"w-5 h-5 text-blue-400"}),"Compare Presets"]}),c.jsx("button",{onClick:t,className:"text-bambu-gray hover:text-white",children:c.jsx(Gt,{className:"w-5 h-5"})})]}),c.jsxs("div",{className:"flex-shrink-0 grid grid-cols-2 gap-4 p-4 border-b border-bambu-dark-tertiary bg-bambu-dark",children:[c.jsxs("div",{className:"text-center",children:[c.jsx("span",{className:"text-sm text-bambu-gray",children:"Left:"}),c.jsx("p",{className:"text-white font-medium truncate",children:r})]}),c.jsxs("div",{className:"text-center",children:[c.jsx("span",{className:"text-sm text-bambu-gray",children:"Right:"}),c.jsx("p",{className:"text-white font-medium truncate",children:i})]})]}),c.jsxs("div",{className:"flex-shrink-0 flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[c.jsxs("div",{className:"flex items-center gap-4 text-sm",children:[c.jsxs("span",{className:"flex items-center gap-1 text-green-400",children:[c.jsx(fr,{className:"w-3.5 h-3.5"}),f.added," added"]}),c.jsxs("span",{className:"flex items-center gap-1 text-red-400",children:[c.jsx(M5,{className:"w-3.5 h-3.5"}),f.removed," removed"]}),c.jsxs("span",{className:"flex items-center gap-1 text-amber-400",children:[c.jsx(i3,{className:"w-3.5 h-3.5"}),f.changed," changed"]}),c.jsxs("span",{className:"flex items-center gap-1 text-bambu-gray",children:[c.jsx(oA,{className:"w-3.5 h-3.5"}),f.same," same"]})]}),c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsxs("div",{className:"relative",children:[c.jsx(Qu,{className:"absolute left-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),c.jsx("input",{type:"text",value:o,onChange:m=>l(m.target.value),placeholder:"Search fields...",className:"pl-8 pr-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none w-48"})]}),f.same>0&&c.jsxs("div",{className:"flex rounded overflow-hidden border border-bambu-dark-tertiary",children:[c.jsx("button",{onClick:()=>a("changes"),className:`px-3 py-1.5 text-sm transition-colors ${s==="changes"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:"Changes"}),c.jsx("button",{onClick:()=>a("all"),className:`px-3 py-1.5 text-sm transition-colors ${s==="all"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:"All"})]})]})]}),c.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto",children:d.length===0?c.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[c.jsx(oA,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),c.jsx("p",{children:s==="changes"?"No differences found":"No fields match the search"})]}):c.jsxs("table",{className:"w-full",children:[c.jsx("thead",{className:"sticky top-0 bg-bambu-dark-secondary",children:c.jsxs("tr",{className:"text-sm text-bambu-gray border-b border-bambu-dark-tertiary",children:[c.jsx("th",{className:"text-left p-3 w-1/3",children:"Field"}),c.jsx("th",{className:"text-left p-3 w-1/3",children:r}),c.jsx("th",{className:"text-left p-3 w-1/3",children:i})]})}),c.jsx("tbody",{children:d.map(m=>{const x={added:"bg-green-500/10",removed:"bg-red-500/10",changed:"bg-amber-500/10",same:""}[m.status],y={added:c.jsx(fr,{className:"w-3.5 h-3.5 text-green-400"}),removed:c.jsx(M5,{className:"w-3.5 h-3.5 text-red-400"}),changed:c.jsx(i3,{className:"w-3.5 h-3.5 text-amber-400"}),same:c.jsx(oA,{className:"w-3.5 h-3.5 text-bambu-gray-dark"})}[m.status];return c.jsxs("tr",{className:`border-b border-bambu-dark-tertiary ${x}`,children:[c.jsx("td",{className:"p-3",children:c.jsxs("div",{className:"flex items-center gap-2",children:[y,c.jsx("span",{className:"text-sm text-white font-mono",children:m.key})]})}),c.jsx("td",{className:"p-3",children:c.jsx("span",{className:`text-sm font-mono break-all ${m.status==="removed"?"text-red-300":m.status==="changed"?"text-white":"text-bambu-gray"}`,children:g(m.left)})}),c.jsx("td",{className:"p-3",children:c.jsx("span",{className:`text-sm font-mono break-all ${m.status==="added"?"text-green-300":m.status==="changed"?"text-white":"text-bambu-gray"}`,children:g(m.right)})})]},m.key)})})]})})]})})})}function Z9e({onClose:t,initialData:e,allPresets:n}){const{showToast:r}=ri(),i=Sn(),s=!!e?.setting_id,[a,o]=M.useState("common"),[l,u]=M.useState(e?.type||"filament"),[d,f]=M.useState(e?.name?s?e.name:`${e.name} (Copy)`:""),[g,m]=M.useState(e?.base_id||""),[x,y]=M.useState(""),[v,b]=M.useState(e?.setting||{inherits:""}),[E,S]=M.useState(JSON.stringify(e?.setting||{inherits:""},null,2)),[A,T]=M.useState(null),[P,C]=M.useState(""),[I,N]=M.useState(!1),[D,F]=M.useState(""),[L,q]=M.useState(!1),[R,V]=M.useState(Ree),[K,W]=M.useState(!1),[ne,Y]=M.useState(""),[Z,U]=M.useState(""),[$,ee]=M.useState(!0),[ae,fe]=M.useState(null),[ue,xe]=M.useState(!1),Me=M.useMemo(()=>({filament:n.filament,print:n.process,printer:n.printer})[l]||[],[n,l]),se=M.useMemo(()=>Me.filter(ce=>J0(ce.setting_id)),[Me]),{data:ve}=yt({queryKey:["cloudFields",l],queryFn:()=>Pe.getCloudFields(l==="print"?"process":l),staleTime:1e3*60*60}),{data:je}=yt({queryKey:["allPresetDetails",l,se.map(ce=>ce.setting_id).join(",")],queryFn:async()=>{const ce={};for(let $e=0;$e{try{const Fe=await Pe.getCloudSettingDetail(Q.setting_id);return{id:Q.setting_id,detail:Fe}}catch{return null}}))).forEach(Q=>{Q&&(ce[Q.id]=Q.detail)})}return ce},enabled:se.length>0,staleTime:1e3*60*10}),{data:de,isLoading:ut}=yt({queryKey:["cloudSettingDetail",g],queryFn:()=>Pe.getCloudSettingDetail(g),enabled:!!g});M.useEffect(()=>{a!=="json"&&S(JSON.stringify(v,null,2))},[v,a]);const H=M.useMemo(()=>({filament:n.filament,print:n.process,printer:n.printer}[l]||[]).filter(Ye=>!J0(Ye.setting_id)).sort((Ye,$e)=>Ye.name.localeCompare($e.name)),[n,l]);M.useEffect(()=>{if(!g)return;const ce=H.find(Ye=>Ye.setting_id===g);ce&&(y(ce.name),s||(b({inherits:ce.name}),S(JSON.stringify({inherits:ce.name},null,2))))},[g,H,s]);const z=M.useMemo(()=>{const ce=ve?.fields||[],Ye=new Set(ce.map(Q=>Q.key)),$e=new Set,Ze=new Set(["inherits","updated_time","compatible_printers","compatible_prints"]);je&&Object.values(je).forEach(Q=>{Q?.setting&&Object.keys(Q.setting).forEach(Fe=>{!Ye.has(Fe)&&!Ze.has(Fe)&&$e.add(Fe)})}),Object.keys(v).forEach(Q=>{!Ye.has(Q)&&!Ze.has(Q)&&$e.add(Q)});const at=Array.from($e).sort().map(Q=>({key:Q,label:Q.replace(/_/g," ").replace(/\b\w/g,Fe=>Fe.toUpperCase()),type:"text",category:"discovered",description:"Discovered from presets"}));return[...ce,...at]},[ve,je,v]),re=z.filter(ce=>ce.label.toLowerCase().includes(P.toLowerCase())||ce.key.toLowerCase().includes(P.toLowerCase())),G=()=>{if(D.trim()){const ce=D.trim().toLowerCase().replace(/\s+/g,"_");J(ce,""),F(""),q(!1),r(`Field "${ce}" added`)}},J=(ce,Ye)=>{b($e=>{const Ze={...$e};return Ye===""||Ye===void 0?delete Ze[ce]:Ze[ce]=Ye,Ze})},le=ce=>{b(Ye=>({...Ye,...ce.settings})),fe(ce.name),r("Template applied")},ke=()=>{if(!ne.trim())return;const ce={...v};if(delete ce.inherits,Object.keys(ce).length===0){r("No overrides to save","error");return}const Ye={id:Date.now().toString(),name:ne.trim(),description:Z.trim()||"Custom template",type:l,settings:ce,showInModal:$},$e=[...R,Ye];V($e),Dee($e),W(!1),Y(""),U(""),ee(!0),r("Template saved")},Ne=M.useMemo(()=>R.filter(ce=>ce.type===l&&ce.showInModal),[l,R]),we=ce=>{S(ce);try{const Ye=JSON.parse(ce);b(Ye),T(null)}catch(Ye){T(Ye.message)}},B=ce=>{ce.preventDefault(),N(!1);const Ye=ce.dataTransfer.files[0];if(Ye&&Ye.name.endsWith(".json")){const $e=new FileReader;$e.onload=Ze=>{try{const at=Ze.target?.result,Q=JSON.parse(at),Fe=Q.setting||Q;b(pe=>({...pe,...Fe})),S(JSON.stringify({...v,...Fe},null,2)),r("File imported successfully")}catch{r("Invalid JSON file","error")}},$e.readAsText(Ye)}},j=_t({mutationFn:()=>{const ce={...v},Ye=l==="filament"?"filament_settings_id":l==="print"?"print_settings_id":"printer_settings_id";ce[Ye]=`"${d}"`;const $e={type:l,name:d,base_id:g,setting:ce};return Pe.createCloudSetting($e)},onSuccess:async()=>{r("Preset created successfully"),await i.refetchQueries({queryKey:["cloudSettings"]}),t()},onError:ce=>r(ce.message,"error")}),te=_t({mutationFn:()=>{if(!e?.setting_id)throw new Error("No setting ID for update");return Pe.updateCloudSetting(e.setting_id,{name:d,setting:v})},onSuccess:async()=>{r("Preset updated successfully"),i.removeQueries({queryKey:["cloudSettingDetail"]}),await i.refetchQueries({queryKey:["cloudSettings"]}),t()},onError:ce=>r(ce.message,"error")}),be=s?te:j,_e=de?.setting?.inherits,ge=_e?H.find(ce=>ce.name===_e):void 0,{data:me}=yt({queryKey:["cloudSettingDetail",ge?.setting_id],queryFn:()=>Pe.getCloudSettingDetail(ge.setting_id),enabled:!!ge?.setting_id}),Ae=M.useMemo(()=>{const ce=me?.setting||{},Ye=de?.setting||{},$e=g&&je?.[g]?.setting?je[g].setting:{};return{...ce,...Ye,...$e}},[g,de,me,je]),ze=ce=>{if(ce==null)return"";if(Array.isArray(ce)){const Ye=[...new Set(ce.map($e=>String($e)))];return Ye.length===1?Ye[0]:ce.join(", ")}return String(ce)},st=ce=>{const Ye=v[ce.key],$e=Ae[ce.key],Ze=ze($e),at=ut?"Loading...":Ze||"",Q="w-full px-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none";if(ce.type==="boolean"){const Fe=Ye==="1"||Ye===void 0&&$e==="1";return c.jsx("button",{type:"button",onClick:()=>J(ce.key,Ye==="1"?"0":"1"),className:`w-8 h-5 rounded-full transition-colors ${Fe?"bg-bambu-green":"bg-bambu-dark-tertiary"}`,children:c.jsx("div",{className:`w-4 h-4 rounded-full bg-white shadow transition-transform ${Fe?"translate-x-3.5":"translate-x-0.5"}`})})}return ce.type==="select"?c.jsxs("select",{value:Ye||"",onChange:Fe=>J(ce.key,Fe.target.value),className:Q,children:[c.jsx("option",{value:"",children:at}),ce.options?.map(Fe=>c.jsx("option",{value:Fe.value,children:Fe.label},Fe.value))]}):c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("input",{type:ce.type==="number"?"number":"text",value:Ye!==void 0?String(Ye):"",onChange:Fe=>J(ce.key,Fe.target.value),step:ce.step,min:ce.min,max:ce.max,placeholder:at,className:Q}),ce.unit&&c.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:ce.unit})]})},Ve=M.useMemo(()=>de?.setting?de.setting:{},[de]);return c.jsxs("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onDragOver:ce=>{ce.preventDefault(),N(!0)},onDragLeave:()=>N(!1),onDrop:B,children:[ue&&g&&c.jsx(Oee,{onClose:()=>xe(!1),leftPreset:Ve,rightPreset:v,leftLabel:`Base: ${x||g}`,rightLabel:`Current: ${d||"New Preset"}`}),c.jsx(Nt,{className:"w-full max-w-6xl max-h-[90vh] flex flex-col",children:c.jsxs(Dt,{className:"p-0 flex flex-col h-full",children:[c.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[c.jsxs("div",{children:[c.jsx("h2",{className:"text-xl font-semibold text-white",children:s?"Edit Preset":e?"Duplicate Preset":"Create New Preset"}),c.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:"Customize settings for your new preset"})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[g&&c.jsxs("button",{onClick:()=>xe(!0),className:"flex items-center gap-2 px-3 py-2 text-sm text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors",title:"Compare with base preset",children:[c.jsx(Hp,{className:"w-4 h-4"}),"Compare"]}),c.jsx("button",{onClick:t,className:"p-2 text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary rounded-lg transition-colors",children:c.jsx(Gt,{className:"w-5 h-5"})})]})]}),I&&c.jsx("div",{className:"absolute inset-0 bg-bambu-green/10 border-2 border-dashed border-bambu-green rounded-lg flex items-center justify-center z-10",children:c.jsxs("div",{className:"text-center",children:[c.jsx(ma,{className:"w-12 h-12 text-bambu-green mx-auto mb-2"}),c.jsx("p",{className:"text-bambu-green font-medium",children:"Drop JSON file to import"})]})}),c.jsxs("div",{className:"p-4 border-b border-bambu-dark-tertiary space-y-3",children:[c.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Type"}),c.jsxs("select",{value:l,onChange:ce=>{u(ce.target.value),m("")},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[c.jsx("option",{value:"filament",children:"Filament"}),c.jsx("option",{value:"print",children:"Process"}),c.jsx("option",{value:"printer",children:"Printer"})]})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Base Preset"}),c.jsxs("select",{value:g,onChange:ce=>m(ce.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none",children:[c.jsx("option",{value:"",children:"Select base preset..."}),H.map(ce=>c.jsx("option",{value:ce.setting_id,children:ce.name},ce.setting_id))]})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Preset Name"}),c.jsx("input",{type:"text",value:d,onChange:ce=>f(ce.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",placeholder:"My Custom Preset"})]})]}),x&&c.jsx("div",{className:"text-xs text-bambu-gray",children:c.jsxs("p",{className:"flex items-center gap-1",children:[c.jsx(Ph,{className:"w-3 h-3 text-bambu-green"}),"Inherits from: ",c.jsx("span",{className:"text-white",children:x}),ut&&c.jsx(At,{className:"w-3 h-3 animate-spin ml-1"})]})})]}),c.jsxs("div",{className:"flex border-b border-bambu-dark-tertiary",children:[c.jsxs("button",{onClick:()=>o("common"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${a==="common"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[c.jsx(A5,{className:"w-4 h-4"}),"Common"]}),c.jsxs("button",{onClick:()=>o("fields"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${a==="fields"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[c.jsx(bR,{className:"w-4 h-4"}),"All Fields"]}),c.jsxs("button",{onClick:()=>o("json"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${a==="json"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[c.jsx(CG,{className:"w-4 h-4"}),"JSON",A&&c.jsx(Oo,{className:"w-3 h-3 text-red-400"})]}),c.jsx("div",{className:"flex-1"}),c.jsxs("button",{onClick:()=>{const ce={name:d,type:l,base_id:g,setting:v},Ye=new Blob([JSON.stringify(ce,null,2)],{type:"application/json"}),$e=URL.createObjectURL(Ye),Ze=document.createElement("a");Ze.href=$e,Ze.download=`${d||"preset"}.json`,document.body.appendChild(Ze),Ze.click(),document.body.removeChild(Ze),URL.revokeObjectURL($e),r("Preset exported")},className:"flex items-center gap-2 px-4 py-3 text-sm text-bambu-gray hover:text-white transition-colors",title:"Export current settings to JSON file",children:[c.jsx(ya,{className:"w-4 h-4"}),"Export"]}),c.jsxs("button",{onClick:()=>document.getElementById("file-import")?.click(),className:"flex items-center gap-2 px-4 py-3 text-sm text-bambu-gray hover:text-white transition-colors",title:"Import settings from JSON file",children:[c.jsx(ma,{className:"w-4 h-4"}),"Import"]}),c.jsx("input",{id:"file-import",type:"file",accept:".json",className:"hidden",onChange:ce=>{const Ye=ce.target.files?.[0];if(Ye){const $e=new FileReader;$e.onload=Ze=>{try{const at=JSON.parse(Ze.target?.result),Q=at.setting||at;b(Fe=>({...Fe,...Q})),r("File imported")}catch{r("Invalid JSON","error")}},$e.readAsText(Ye)}}})]}),c.jsxs("div",{className:"flex-1 overflow-y-auto p-4",children:[a==="common"&&c.jsxs("div",{className:"space-y-6",children:[c.jsxs("div",{children:[c.jsxs("div",{className:"flex items-center justify-between mb-3",children:[c.jsxs("h3",{className:"text-sm font-medium text-white flex items-center gap-2",children:[c.jsx(h0,{className:"w-4 h-4 text-amber-400"}),"Quick Templates"]}),Object.keys(v).filter(ce=>ce!=="inherits").length>0&&c.jsxs("button",{onClick:()=>W(!K),className:"text-xs text-bambu-gray hover:text-white flex items-center gap-1 transition-colors",children:[c.jsx(To,{className:"w-3 h-3"}),"Save as template"]})]}),K&&c.jsxs("div",{className:"mb-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[c.jsxs("div",{className:"grid grid-cols-2 gap-2 mb-2",children:[c.jsx("input",{type:"text",value:ne,onChange:ce=>Y(ce.target.value),placeholder:"Template name",className:"px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none",autoFocus:!0}),c.jsx("input",{type:"text",value:Z,onChange:ce=>U(ce.target.value),placeholder:"Description (optional)",className:"px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none"})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex gap-2",children:[c.jsxs(Ie,{size:"sm",onClick:ke,disabled:!ne.trim(),children:[c.jsx(To,{className:"w-3 h-3"}),"Save"]}),c.jsx(Ie,{size:"sm",variant:"secondary",onClick:()=>W(!1),children:"Cancel"})]}),c.jsxs("button",{onClick:()=>ee(!$),className:`flex items-center gap-1.5 text-xs transition-colors ${$?"text-bambu-green":"text-bambu-gray hover:text-white"}`,children:[$?c.jsx(o0,{className:"w-3.5 h-3.5"}):c.jsx(mR,{className:"w-3.5 h-3.5"}),$?"Show in modals":"Hidden in modals"]})]})]}),ae&&c.jsxs("div",{className:"mb-3 px-3 py-2 bg-bambu-green/10 border border-bambu-green/30 rounded-lg flex items-center gap-2",children:[c.jsx(Ph,{className:"w-4 h-4 text-bambu-green"}),c.jsxs("span",{className:"text-sm text-bambu-green",children:["Template applied: ",c.jsx("span",{className:"font-medium",children:ae})]}),c.jsx("button",{onClick:()=>fe(null),className:"ml-auto text-bambu-green/70 hover:text-bambu-green",children:c.jsx(Gt,{className:"w-4 h-4"})})]}),c.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[Ne.map(ce=>c.jsxs("button",{onClick:()=>le(ce),className:"p-3 text-left bg-bambu-dark border border-bambu-dark-tertiary rounded-lg hover:border-bambu-gray-dark transition-colors",children:[c.jsx("p",{className:"text-sm font-medium text-white",children:ce.name}),c.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:ce.description})]},ce.id)),Ne.length===0&&c.jsx("p",{className:"col-span-3 text-center text-bambu-gray text-sm py-4",children:"No templates selected. Use the Templates button to enable templates for quick access."})]}),c.jsx("p",{className:"text-xs text-bambu-gray-dark mt-2 text-center",children:"Manage templates via the Templates button on the main page"})]}),c.jsxs("div",{children:[c.jsx("h3",{className:"text-sm font-medium text-white mb-3",children:"Common Settings"}),c.jsx("div",{className:"grid grid-cols-2 gap-x-6 gap-y-3",children:z.slice(0,10).map(ce=>c.jsxs("div",{className:"flex items-center justify-between gap-4",children:[c.jsx("label",{className:"text-sm text-bambu-gray flex-shrink-0",children:ce.label}),c.jsx("div",{className:"w-48",children:st(ce)})]},ce.key))})]}),Object.keys(v).length>1&&c.jsxs("div",{children:[c.jsx("h3",{className:"text-sm font-medium text-white mb-3",children:"Current Overrides"}),c.jsx("div",{className:"flex flex-wrap gap-2",children:Object.entries(v).filter(([ce])=>ce!=="inherits").map(([ce,Ye])=>c.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 bg-bambu-green/10 text-bambu-green text-xs rounded",children:[ce,": ",String(Ye).slice(0,20),c.jsx("button",{onClick:()=>J(ce,void 0),className:"hover:text-white",children:c.jsx(Gt,{className:"w-3 h-3"})})]},ce))})]})]}),a==="fields"&&c.jsxs("div",{className:"grid grid-cols-2 gap-6",style:{height:"400px"},children:[c.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[c.jsxs("div",{className:"flex items-center justify-between mb-3 flex-shrink-0",children:[c.jsx("h3",{className:"text-sm font-medium text-white",children:"Available Fields"}),c.jsx("span",{className:"text-xs text-bambu-gray",children:je?`${z.length} fields`:"Loading..."})]}),c.jsxs("div",{className:"relative mb-3 flex-shrink-0",children:[c.jsx(Qu,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),c.jsx("input",{type:"text",value:P,onChange:ce=>C(ce.target.value),placeholder:"Search fields...",className:"w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none"})]}),c.jsxs("div",{className:"flex-1 overflow-y-auto space-y-1 pr-2 min-h-0",children:[re.filter(ce=>!(ce.key in v)).map(ce=>{const Ye=Ae[ce.key],$e=ze(Ye);return c.jsxs("div",{onClick:()=>{b(Ze=>({...Ze,[ce.key]:$e||""}))},className:"flex items-center justify-between gap-2 p-2 rounded-lg hover:bg-bambu-dark-tertiary transition-colors cursor-pointer group",children:[c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsx("p",{className:"text-sm text-white truncate",children:ce.label}),c.jsx("p",{className:"text-xs text-bambu-gray-dark truncate",children:ce.key})]}),c.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[$e&&c.jsxs("span",{className:"text-xs text-bambu-gray bg-bambu-dark px-2 py-0.5 rounded max-w-32 truncate",title:$e,children:[$e.slice(0,20),$e.length>20?"...":""]}),c.jsx("div",{className:"w-6 h-6 flex items-center justify-center rounded bg-bambu-dark-tertiary group-hover:bg-bambu-green/20 transition-colors",children:c.jsx(fr,{className:"w-4 h-4 text-bambu-gray group-hover:text-bambu-green transition-colors"})})]})]},ce.key)}),re.filter(ce=>!(ce.key in v)).length===0&&c.jsx("p",{className:"text-center text-bambu-gray py-4 text-sm",children:P?"No matching fields":"All fields added"})]}),c.jsx("div",{className:"pt-3 mt-3 border-t border-bambu-dark-tertiary flex-shrink-0",children:L?c.jsxs("div",{className:"flex gap-2",children:[c.jsx("input",{type:"text",value:D,onChange:ce=>F(ce.target.value),onKeyDown:ce=>ce.key==="Enter"&&G(),placeholder:"custom_field_name",className:"flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white font-mono text-sm placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none",autoFocus:!0}),c.jsx(Ie,{size:"sm",onClick:G,disabled:!D.trim(),children:c.jsx(fr,{className:"w-4 h-4"})}),c.jsx(Ie,{size:"sm",variant:"secondary",onClick:()=>{q(!1),F("")},children:c.jsx(Gt,{className:"w-4 h-4"})})]}):c.jsxs("button",{onClick:()=>q(!0),className:"w-full flex items-center justify-center gap-2 p-2 text-sm text-bambu-gray hover:text-white border border-dashed border-bambu-dark-tertiary hover:border-bambu-gray-dark rounded-lg transition-colors",children:[c.jsx(fr,{className:"w-4 h-4"}),"Add custom field"]})})]}),c.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[c.jsxs("div",{className:"flex items-center justify-between mb-3 flex-shrink-0",children:[c.jsx("h3",{className:"text-sm font-medium text-white",children:"Your Overrides"}),c.jsxs("span",{className:"text-xs text-bambu-gray",children:[Object.keys(v).filter(ce=>ce!=="inherits").length," fields"]})]}),c.jsxs("div",{className:"flex-1 overflow-y-auto space-y-2 pr-2 min-h-0",children:[Object.entries(v).filter(([ce])=>ce!=="inherits").map(([ce,Ye])=>{const $e=z.find(Ze=>Ze.key===ce);return c.jsxs("div",{className:"p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[c.jsxs("div",{className:"flex items-center justify-between mb-2",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-sm font-medium text-white",children:$e?.label||ce}),c.jsx("p",{className:"text-xs text-bambu-gray-dark",children:ce})]}),c.jsx("button",{onClick:()=>J(ce,void 0),className:"p-1 text-bambu-gray hover:text-red-400 transition-colors",children:c.jsx(Gt,{className:"w-4 h-4"})})]}),$e?st($e):c.jsx("input",{type:"text",value:String(Ye),onChange:Ze=>J(ce,Ze.target.value),className:"w-full px-3 py-1.5 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none"})]},ce)}),Object.keys(v).filter(ce=>ce!=="inherits").length===0&&c.jsxs("div",{className:"text-center py-8 text-bambu-gray",children:[c.jsx(A5,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),c.jsx("p",{className:"text-sm",children:"No overrides yet"}),c.jsx("p",{className:"text-xs mt-1",children:"Click fields on the left to add them"})]})]}),Object.keys(v).filter(ce=>ce!=="inherits").length>0&&c.jsx("div",{className:"pt-3 mt-3 border-t border-bambu-dark-tertiary flex-shrink-0",children:c.jsxs("button",{onClick:()=>{W(!0),o("common")},className:"w-full flex items-center justify-center gap-2 p-2 text-sm text-bambu-gray hover:text-white border border-dashed border-bambu-dark-tertiary hover:border-bambu-gray-dark rounded-lg transition-colors",children:[c.jsx(To,{className:"w-4 h-4"}),"Save as template"]})})]})]}),a==="json"&&c.jsxs("div",{className:"space-y-2",children:[A&&c.jsxs("div",{className:"flex items-center gap-2 text-red-400 text-sm",children:[c.jsx(Oo,{className:"w-4 h-4"}),A]}),c.jsx("textarea",{value:E,onChange:ce=>we(ce.target.value),className:`w-full h-80 px-3 py-2 bg-bambu-dark border rounded-lg text-white text-xs font-mono focus:outline-none resize-none ${A?"border-red-500 focus:border-red-500":"border-bambu-dark-tertiary focus:border-bambu-green"}`,spellCheck:!1}),c.jsx("p",{className:"text-xs text-bambu-gray",children:"Tip: Drag & drop a .json file anywhere on this modal to import settings"})]})]}),c.jsxs("div",{className:"p-4 border-t border-bambu-dark-tertiary flex gap-2",children:[c.jsx(Ie,{variant:"secondary",onClick:t,className:"flex-1",children:"Cancel"}),c.jsxs(Ie,{onClick:()=>be.mutate(),disabled:be.isPending||!d.trim()||!s&&!g||!!A,className:"flex-1",children:[be.isPending?c.jsx(At,{className:"w-4 h-4 animate-spin"}):s?c.jsx(To,{className:"w-4 h-4"}):c.jsx(fr,{className:"w-4 h-4"}),s?"Save":e?"Duplicate":"Create"]})]})]})})]})}function Q9e({settings:t,lastSyncTime:e,onRefresh:n,isRefreshing:r,printers:i}){const[s,a]=M.useState(""),[o,l]=M.useState("all"),[u,d]=M.useState("all"),[f,g]=M.useState("all"),[m,x]=M.useState("all"),[y,v]=M.useState("all"),[b,E]=M.useState("all"),[S,A]=M.useState(null),[T,P]=M.useState(!1),[C,I]=M.useState(!1),[N,D]=M.useState(null),[F,L]=M.useState(null),[q,R]=M.useState(null),[V,K]=M.useState(!1),[W,ne]=M.useState([null,null]),[Y,Z]=M.useState(!1),[U,$]=M.useState(null),ee=Sn(),ae=M.useMemo(()=>[...t.filament.map(re=>({...re,type:"filament"})),...t.printer.map(re=>({...re,type:"printer"})),...t.process.map(re=>({...re,type:"process"}))].map(re=>({...re,meta:Gj(re.name)})),[t]),fe=M.useMemo(()=>{const z=new Set,re=new Set,G=new Set;return ae.forEach(J=>{J.meta.nozzle&&z.add(J.meta.nozzle),J.meta.filamentType&&re.add(J.meta.filamentType),J.meta.layerHeight&&G.add(J.meta.layerHeight)}),{printers:i.map(J=>({id:J.id.toString(),name:J.name})),nozzles:Array.from(z).sort((J,le)=>parseFloat(J)-parseFloat(le)),filaments:Array.from(re).sort(),layerHeights:Array.from(G).sort((J,le)=>parseFloat(J)-parseFloat(le))}},[ae,i]),ue=M.useMemo(()=>f==="all"?null:i.find(re=>re.id.toString()===f)?.model||null,[f,i]),xe=M.useMemo(()=>ae.filter(z=>o==="all"||z.type===o).filter(z=>{if(u==="all")return!0;const re=J0(z.setting_id);return u==="custom"?re:!re}).filter(z=>{if(f==="all"||!ue)return!0;const re=z.meta.printer?.toLowerCase()||"",G=ue.toLowerCase();return re.includes(G)||G.includes(re)}).filter(z=>m==="all"||z.meta.nozzle===m).filter(z=>y==="all"||z.meta.filamentType===y).filter(z=>b==="all"||z.meta.layerHeight===b).filter(z=>s===""||z.name.toLowerCase().includes(s.toLowerCase())).sort((z,re)=>z.name.localeCompare(re.name)),[ae,o,u,f,ue,m,y,b,s]),Me=z=>{if(V){const re=W[0]?.setting_id===z.setting_id,G=W[1]?.setting_id===z.setting_id;if(re)ne([W[1],null]);else if(G)ne([W[0],null]);else if(!W[0])ne([z,null]);else if(W[1]){if(W[0].type!==z.type)return;ne([W[0],z])}else{if(W[0].type!==z.type)return;ne([W[0],z])}}else A(z)},se=z=>{if(W[0]?.setting_id===z.setting_id)return 0;if(W[1]?.setting_id===z.setting_id)return 1},ve=async z=>{try{const re=await Pe.getCloudSettingDetail(z.setting_id),G=z.type==="process"?"print":z.type;D({type:G,name:z.name,base_id:re.base_id||"GFSA00",setting:re.setting||{}}),A(null)}catch(re){console.error("Failed to fetch preset details for duplication:",re)}},je=async z=>{try{ee.removeQueries({queryKey:["cloudSettingDetail",z.setting_id]});const re=await Pe.getCloudSettingDetail(z.setting_id),G=z.type==="process"?"print":z.type;L({type:G,name:z.name,base_id:re.base_id||"GFSA00",setting:re.setting||{},setting_id:z.setting_id}),A(null)}catch(re){console.error("Failed to fetch preset details for editing:",re)}},de=()=>{l("all"),d("all"),g("all"),x("all"),v("all"),E("all"),a("")},ut=o!=="all"||u!=="all"||f!=="all"||m!=="all"||y!=="all"||b!=="all"||s!=="",H=t.filament.length+t.printer.length+t.process.length;return c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"space-y-4 mb-6",children:[c.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[c.jsxs("div",{className:"relative flex-1",children:[c.jsx(Qu,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),c.jsx("input",{type:"text",value:s,onChange:z=>a(z.target.value),placeholder:"Search presets...",className:"w-full pl-10 pr-4 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none"})]}),c.jsxs("div",{className:"flex gap-2",children:[c.jsxs(Ie,{variant:V?"primary":"secondary",onClick:()=>{V?(K(!1),ne([null,null])):K(!0)},children:[c.jsx(Hp,{className:"w-4 h-4"}),V?"Cancel":"Compare"]}),c.jsxs(Ie,{variant:"secondary",onClick:()=>I(!0),children:[c.jsx(h0,{className:"w-4 h-4"}),"Templates"]}),c.jsxs(Ie,{variant:"secondary",onClick:n,disabled:r,children:[c.jsx(qs,{className:`w-4 h-4 ${r?"animate-spin":""}`}),"Refresh"]}),c.jsxs(Ie,{onClick:()=>P(!0),children:[c.jsx(fr,{className:"w-4 h-4"}),"New Preset"]})]})]}),c.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[c.jsx(gR,{className:"w-4 h-4 text-bambu-gray"}),c.jsx(Ap,{label:"Type",value:o,options:[{value:"all",label:"All",count:H},{value:"filament",label:"Filament",count:t.filament.length},{value:"printer",label:"Printer",count:t.printer.length},{value:"process",label:"Process",count:t.process.length}],onChange:z=>l(z)}),c.jsx(Ap,{label:"Owner",value:u,options:[{value:"all",label:"All"},{value:"custom",label:"My Presets"},{value:"builtin",label:"Built-in"}],onChange:z=>d(z)}),fe.printers.length>0&&c.jsx(Ap,{label:"Printer",value:f,options:[{value:"all",label:"All"},...fe.printers.map(z=>({value:z.id,label:z.name}))],onChange:g}),fe.nozzles.length>0&&c.jsx(Ap,{label:"Nozzle",value:m,options:[{value:"all",label:"All"},...fe.nozzles.map(z=>({value:z,label:z}))],onChange:x}),fe.filaments.length>0&&(o==="all"||o==="filament")&&c.jsx(Ap,{label:"Filament",value:y,options:[{value:"all",label:"All"},...fe.filaments.map(z=>({value:z,label:z}))],onChange:v}),fe.layerHeights.length>0&&(o==="all"||o==="process")&&c.jsx(Ap,{label:"Layer",value:b,options:[{value:"all",label:"All"},...fe.layerHeights.map(z=>({value:z,label:z}))],onChange:E}),ut&&c.jsx("button",{onClick:de,className:"px-3 py-2 text-sm text-bambu-gray hover:text-white transition-colors",children:"Clear filters"})]})]}),V&&c.jsx("div",{className:"mb-4 p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg",children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-4",children:[c.jsx(Hp,{className:"w-5 h-5 text-blue-400"}),c.jsx("span",{className:"text-white font-medium",children:"Compare Mode"}),c.jsx("span",{className:"text-bambu-gray",children:W[0]?`Select another ${W[0].type} preset`:"Click two presets of the same type to compare"})]}),c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:`px-2 py-1 text-sm rounded truncate max-w-[200px] ${W[0]?"bg-blue-500/30 text-blue-700 dark:text-blue-300":"bg-bambu-dark text-bambu-gray"}`,children:W[0]?W[0].name:"1. Select first"}),c.jsx(i3,{className:"w-4 h-4 text-bambu-gray"}),c.jsx("span",{className:`px-2 py-1 text-sm rounded truncate max-w-[200px] ${W[1]?"bg-blue-500/30 text-blue-700 dark:text-blue-300":"bg-bambu-dark text-bambu-gray"}`,children:W[1]?W[1].name:"2. Select second"})]}),W[0]&&W[1]&&c.jsxs(Ie,{size:"sm",onClick:async()=>{try{const[z,re]=await Promise.all([Pe.getCloudSettingDetail(W[0].setting_id),Pe.getCloudSettingDetail(W[1].setting_id)]);$([z.setting||{},re.setting||{}]),Z(!0)}catch{}},children:[c.jsx(Hp,{className:"w-4 h-4"}),"Compare Now"]})]})]})}),c.jsxs("div",{className:"flex flex-wrap items-center gap-4 mb-4 text-sm text-bambu-gray",children:[e&&c.jsxs("div",{className:"flex items-center gap-1",children:[c.jsx(ti,{className:"w-3 h-3"}),"Last synced: ",W9e(e.toISOString())]}),c.jsxs("span",{children:["Showing ",xe.length," of ",H," presets"]}),c.jsxs("div",{className:"flex items-center gap-1",children:[c.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-bambu-green"}),c.jsx("span",{children:"= My preset (editable)"})]})]}),xe.length===0?c.jsxs("div",{className:"text-center py-16",children:[c.jsx(Oh,{className:"w-12 h-12 text-bambu-gray-dark mx-auto mb-4"}),c.jsx("p",{className:"text-bambu-gray",children:"No presets found"}),ut&&c.jsx("button",{onClick:de,className:"mt-2 text-sm text-bambu-green hover:text-bambu-green-light",children:"Clear filters"})]}):c.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6",children:[c.jsxs("div",{children:[c.jsxs("div",{className:"flex items-center gap-2 mb-3 px-1",children:[c.jsx(pR,{className:"w-4 h-4 text-amber-400"}),c.jsx("h3",{className:"text-sm font-medium text-bambu-gray",children:"Filament"}),c.jsxs("span",{className:"text-xs text-bambu-gray-dark",children:["(",xe.filter(z=>z.type==="filament").length,")"]})]}),c.jsxs("div",{className:"space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1",children:[xe.filter(z=>z.type==="filament").map(z=>c.jsx($N,{setting:z,onClick:()=>Me(z),onDuplicate:()=>ve(z),compareMode:V,isCompareSelected:se(z)!==void 0,compareIndex:se(z),compareDisabled:V&&!!W[0]&&W[0].type!==z.type},z.setting_id)),xe.filter(z=>z.type==="filament").length===0&&c.jsx("p",{className:"text-xs text-bambu-gray-dark px-3 py-2",children:"No filament presets"})]})]}),c.jsxs("div",{children:[c.jsxs("div",{className:"flex items-center gap-2 mb-3 px-1",children:[c.jsx(vS,{className:"w-4 h-4 text-blue-400"}),c.jsx("h3",{className:"text-sm font-medium text-bambu-gray",children:"Process"}),c.jsxs("span",{className:"text-xs text-bambu-gray-dark",children:["(",xe.filter(z=>z.type==="process").length,")"]})]}),c.jsxs("div",{className:"space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1",children:[xe.filter(z=>z.type==="process").map(z=>c.jsx($N,{setting:z,onClick:()=>Me(z),onDuplicate:()=>ve(z),compareMode:V,isCompareSelected:se(z)!==void 0,compareIndex:se(z),compareDisabled:V&&!!W[0]&&W[0].type!==z.type},z.setting_id)),xe.filter(z=>z.type==="process").length===0&&c.jsx("p",{className:"text-xs text-bambu-gray-dark px-3 py-2",children:"No process presets"})]})]}),c.jsxs("div",{children:[c.jsxs("div",{className:"flex items-center gap-2 mb-3 px-1",children:[c.jsx(jo,{className:"w-4 h-4 text-purple-400"}),c.jsx("h3",{className:"text-sm font-medium text-bambu-gray",children:"Printer"}),c.jsxs("span",{className:"text-xs text-bambu-gray-dark",children:["(",xe.filter(z=>z.type==="printer").length,")"]})]}),c.jsxs("div",{className:"space-y-1 max-h-[calc(100vh-320px)] overflow-y-auto pr-1",children:[xe.filter(z=>z.type==="printer").map(z=>c.jsx($N,{setting:z,onClick:()=>Me(z),onDuplicate:()=>ve(z),compareMode:V,isCompareSelected:se(z)!==void 0,compareIndex:se(z),compareDisabled:V&&!!W[0]&&W[0].type!==z.type},z.setting_id)),xe.filter(z=>z.type==="printer").length===0&&c.jsx("p",{className:"text-xs text-bambu-gray-dark px-3 py-2",children:"No printer presets"})]})]})]}),S&&c.jsx(X9e,{setting:S,onClose:()=>A(null),onDeleted:()=>A(null),onDuplicate:()=>ve(S),onEdit:()=>je(S)}),(T||N||F||q)&&c.jsx(Z9e,{onClose:()=>{P(!1),D(null),L(null),R(null)},initialData:F||N||(q?{type:q.type,name:"",base_id:"",setting:q.setting}:void 0),allPresets:t}),C&&c.jsx(Y9e,{onClose:()=>I(!1),onApply:z=>{R({type:z.type,setting:z.settings}),I(!1)}}),Y&&U&&W[0]&&W[1]&&c.jsx(Oee,{onClose:()=>{Z(!1),$(null)},leftPreset:U[0],rightPreset:U[1],leftLabel:W[0].name,rightLabel:W[1].name})]})}function J9e(){const t=Sn(),{showToast:e}=ri(),[n,r]=M.useState("cloud"),[i,s]=M.useState(),{data:a,isLoading:o}=yt({queryKey:["cloudStatus"],queryFn:Pe.getCloudStatus}),{data:l=[]}=yt({queryKey:["printers"],queryFn:Pe.getPrinters}),{data:u,isLoading:d,refetch:f,dataUpdatedAt:g}=yt({queryKey:["cloudSettings"],queryFn:()=>Pe.getCloudSettings(),enabled:!!a?.is_authenticated,retry:!1,staleTime:1e3*60*5});M.useEffect(()=>{g&&s(new Date(g))},[g]);const m=_t({mutationFn:Pe.cloudLogout,onSuccess:()=>{t.invalidateQueries({queryKey:["cloudStatus"]}),t.removeQueries({queryKey:["cloudSettings"]}),e("Logged out")}}),x=()=>{t.invalidateQueries({queryKey:["cloudStatus"]})};return o?c.jsx("div",{className:"p-4 md:p-8 flex items-center justify-center min-h-[400px]",children:c.jsx(At,{className:"w-8 h-8 text-bambu-green animate-spin"})}):c.jsxs("div",{className:"p-6 lg:p-8",children:[c.jsxs("div",{className:"mb-6",children:[c.jsx("h1",{className:"text-2xl font-bold text-white",children:"Profiles"}),c.jsx("p",{className:"text-bambu-gray",children:"Manage your slicer presets and pressure advance calibrations"})]}),c.jsxs("div",{className:"flex border-b border-bambu-dark-tertiary mb-6",children:[c.jsxs("button",{onClick:()=>r("cloud"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${n==="cloud"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[c.jsx(gS,{className:"w-4 h-4"}),"Cloud Profiles"]}),c.jsxs("button",{onClick:()=>r("kprofiles"),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium transition-colors border-b-2 -mb-px ${n==="kprofiles"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-white border-transparent"}`,children:[c.jsx(xR,{className:"w-4 h-4"}),"K-Profiles"]})]}),n==="cloud"&&c.jsxs(c.Fragment,{children:[a?.is_authenticated&&c.jsxs("div",{className:"flex items-center justify-between p-3 mb-6 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("div",{className:"w-2 h-2 rounded-full bg-bambu-green animate-pulse"}),c.jsxs("span",{className:"text-sm text-bambu-gray",children:["Connected as ",c.jsx("span",{className:"text-white",children:a.email})]})]}),c.jsxs(Ie,{variant:"secondary",size:"sm",onClick:()=>m.mutate(),disabled:m.isPending,children:[c.jsx(hle,{className:"w-4 h-4"}),"Logout"]})]}),a?.is_authenticated?d?c.jsx("div",{className:"flex items-center justify-center py-16",children:c.jsx(At,{className:"w-8 h-8 text-bambu-green animate-spin"})}):u?c.jsx(Q9e,{settings:u,lastSyncTime:i,onRefresh:()=>f(),isRefreshing:d,printers:l}):c.jsxs("div",{className:"text-center py-16",children:[c.jsx("p",{className:"text-bambu-gray mb-4",children:"Failed to load profiles"}),c.jsx(Ie,{onClick:()=>f(),children:"Retry"})]}):c.jsx(q9e,{onSuccess:x})]}),n==="kprofiles"&&c.jsx(G9e,{}),c.jsx(K9e,{})]})}const Px={Droplet:pR,Flame:Aoe,Ruler:Qle,Sparkles:h0,Square:im,Cable:Mae,Wrench:Ju,Calendar:qr,Timer:Ou,Cog:Jae,Fan:moe,Zap:am,Wind:Yce,Thermometer:$p,Layers:Oh,Box:rm,Target:IG,RefreshCw:qs,Settings:wR,Filter:gR,CircleDot:Bae};function t0(t){return t&&Px[t]||Ju}function Tp(t,e){return e==="days"?t<1?"Today":t===1?"1 day":t<7?`${Math.round(t)} days`:t<30?`${Math.round(t/7)} weeks`:`${Math.round(t/30)} months`:t<1?`${Math.round(t*60)}m`:t<10?`${t.toFixed(1)}h`:`${Math.round(t)}h`}function VN(t,e){return e==="days"?t===1?"1 day":t===7?"1 week":t===14?"2 weeks":t===30?"1 month":t===60?"2 months":t===90?"3 months":t===180?"6 months":t===365?"1 year":`${t} days`:`${t}h`}function eGe({item:t,onPerform:e,onToggle:n}){const r=t0(t.maintenance_type_icon),i=t.interval_type||"hours",a=(()=>{if(i==="days"){const f=t.days_since_maintenance??0;return Math.max(0,Math.min(100,f/t.interval_hours*100))}return Math.max(0,Math.min(100,(t.interval_hours-t.hours_until_due)/t.interval_hours*100))})(),o=()=>t.enabled?t.is_due?"text-red-400":t.is_warning?"text-amber-400":"text-bambu-green":"text-bambu-gray",l=()=>t.enabled?t.is_due?"bg-red-500":t.is_warning?"bg-amber-500":"bg-bambu-green":"bg-bambu-gray/30",u=()=>t.enabled?t.is_due?"bg-red-500/5 border-red-500/20":t.is_warning?"bg-amber-500/5 border-amber-500/20":"bg-bambu-dark-secondary border-bambu-dark-tertiary":"bg-bambu-dark-secondary/50",d=()=>{if(!t.enabled)return"Disabled";if(i==="days"){const f=t.days_until_due??0;return t.is_due?`Overdue by ${Tp(Math.abs(f),"days")}`:t.is_warning?`Due in ${Tp(f,"days")}`:`${Tp(f,"days")} left`}else return t.is_due?`Overdue by ${Tp(Math.abs(t.hours_until_due),"hours")}`:t.is_warning?`Due in ${Tp(t.hours_until_due,"hours")}`:`${Tp(t.hours_until_due,"hours")} left`};return c.jsx("div",{className:`rounded-xl border p-4 transition-all ${u()}`,children:c.jsxs("div",{className:"flex items-start gap-3",children:[c.jsxs("div",{className:`relative p-2.5 rounded-lg ${t.is_due?"bg-red-500/20":t.is_warning?"bg-amber-500/20":t.enabled?"bg-bambu-dark":"bg-bambu-dark/50"}`,children:[c.jsx(r,{className:`w-5 h-5 ${o()}`}),t.enabled&&(t.is_due||t.is_warning)&&c.jsx("span",{className:`absolute -top-1 -right-1 w-2.5 h-2.5 rounded-full ${t.is_due?"bg-red-500":"bg-amber-500"} animate-pulse`})]}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("h3",{className:`font-medium truncate ${t.enabled?"text-white":"text-bambu-gray"}`,children:t.maintenance_type_name}),i==="days"&&c.jsx("span",{title:"Time-based interval",children:c.jsx(qr,{className:"w-3.5 h-3.5 text-bambu-gray shrink-0"})})]}),c.jsx("div",{className:"mt-2 mb-1.5",children:c.jsx("div",{className:"w-full h-1.5 bg-bambu-dark rounded-full overflow-hidden",children:c.jsx("div",{className:`h-full rounded-full transition-all duration-500 ${l()}`,style:{width:`${a}%`}})})}),c.jsxs("div",{className:`text-xs flex items-center gap-1 ${o()}`,children:[t.is_due&&c.jsx(Qr,{className:"w-3 h-3"}),t.is_warning&&!t.is_due&&c.jsx(ti,{className:"w-3 h-3"}),!t.is_due&&!t.is_warning&&t.enabled&&c.jsx(Ph,{className:"w-3 h-3"}),d()]})]}),c.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[c.jsx(Zn,{checked:t.enabled,onChange:f=>n(t.id,f)}),c.jsxs(Ie,{size:"sm",variant:t.is_due?"primary":"secondary",onClick:()=>e(t.id),disabled:!t.enabled,className:"!px-3",children:[c.jsx(Im,{className:"w-3.5 h-3.5"}),"Reset"]})]})]})})}function tGe({overview:t,onPerform:e,onToggle:n,onSetHours:r}){const[i,s]=M.useState(!0),[a,o]=M.useState(!1),[l,u]=M.useState(t.total_print_hours.toFixed(1)),d=[...t.maintenance_items].sort((m,x)=>m.is_due&&!x.is_due?-1:!m.is_due&&x.is_due?1:m.is_warning&&!x.is_warning?-1:!m.is_warning&&x.is_warning?1:m.maintenance_type_id-x.maintenance_type_id),f=d.find(m=>m.enabled&&(m.is_due||m.is_warning)),g=()=>{const m=parseFloat(l);!isNaN(m)&&m>=0&&(r(t.printer_id,m),o(!1))};return c.jsxs(Nt,{className:"overflow-hidden",children:[c.jsxs("div",{className:"p-5",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-4",children:[c.jsx("h2",{className:"text-xl font-semibold text-white",children:t.printer_name}),c.jsxs("div",{className:"flex items-center gap-2",children:[t.due_count>0&&c.jsxs("span",{className:"px-2.5 py-1 bg-red-500/20 text-red-400 text-xs font-medium rounded-full flex items-center gap-1.5",children:[c.jsx(Qr,{className:"w-3 h-3"}),t.due_count," overdue"]}),t.warning_count>0&&c.jsxs("span",{className:"px-2.5 py-1 bg-amber-500/20 text-amber-400 text-xs font-medium rounded-full flex items-center gap-1.5",children:[c.jsx(ti,{className:"w-3 h-3"}),t.warning_count," due soon"]}),t.due_count===0&&t.warning_count===0&&c.jsxs("span",{className:"px-2.5 py-1 bg-bambu-green/20 text-bambu-green text-xs font-medium rounded-full flex items-center gap-1.5",children:[c.jsx(Ph,{className:"w-3 h-3"}),"All good"]})]})]}),c.jsxs("button",{onClick:()=>s(!i),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm text-bambu-gray hover:text-white hover:bg-bambu-dark rounded-lg transition-colors",children:[i?c.jsx(mS,{className:"w-4 h-4"}):c.jsx(ef,{className:"w-4 h-4"}),i?"Collapse":"Expand"]})]}),c.jsxs("div",{className:"flex items-center gap-6 mt-4",children:[c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("div",{className:"p-2 bg-bambu-dark/50 rounded-lg",children:c.jsx(Ou,{className:"w-4 h-4 text-bambu-gray"})}),a?c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("input",{type:"number",value:l,onChange:m=>u(m.target.value),onKeyDown:m=>{m.key==="Enter"&&g(),m.key==="Escape"&&o(!1)},className:"w-24 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm",min:"0",step:"1",autoFocus:!0}),c.jsx("span",{className:"text-xs text-bambu-gray",children:"hours"}),c.jsx(Ie,{size:"sm",onClick:g,children:"Save"}),c.jsx(Ie,{size:"sm",variant:"secondary",onClick:()=>o(!1),children:"Cancel"})]}):c.jsxs("button",{onClick:()=>{u(Math.round(t.total_print_hours).toString()),o(!0)},className:"group",children:[c.jsxs("div",{className:"text-sm font-medium text-white group-hover:text-bambu-green transition-colors flex items-center gap-1",children:[Math.floor(t.total_print_hours)," hours",c.jsx(d0,{className:"w-3 h-3 text-bambu-gray group-hover:text-bambu-green"})]}),c.jsx("div",{className:"text-xs text-bambu-gray",children:"Total print time"})]})]}),c.jsx("div",{className:"w-px h-10 bg-bambu-dark-tertiary"}),f&&c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("div",{className:`p-2 rounded-lg ${f.is_due?"bg-red-500/20":"bg-amber-500/20"}`,children:(()=>{const m=t0(f.maintenance_type_icon);return c.jsx(m,{className:`w-4 h-4 ${f.is_due?"text-red-400":"text-amber-400"}`})})()}),c.jsxs("div",{children:[c.jsx("div",{className:`text-sm font-medium ${f.is_due?"text-red-400":"text-amber-400"}`,children:f.maintenance_type_name}),c.jsx("div",{className:`text-xs ${f.is_due?"text-red-400/70":"text-amber-400/70"}`,children:f.is_due?"Overdue":"Due soon"})]})]})]})]}),i&&c.jsx(Dt,{className:"pt-0 border-t border-bambu-dark-tertiary",children:c.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-3 pt-4",children:d.map(m=>c.jsx(eGe,{item:m,onPerform:e,onToggle:n},m.id))})})]})}function nGe({overview:t,types:e,onUpdateInterval:n,onAddType:r,onUpdateType:i,onDeleteType:s}){const[a,o]=M.useState(null),[l,u]=M.useState(""),[d,f]=M.useState("hours"),[g,m]=M.useState(!1),[x,y]=M.useState(""),[v,b]=M.useState("100"),[E,S]=M.useState("hours"),[A,T]=M.useState("Wrench"),[P,C]=M.useState(null),[I,N]=M.useState(""),[D,F]=M.useState(""),[L,q]=M.useState("hours"),[R,V]=M.useState("Wrench"),K=ee=>{C(ee),N(ee.name),F(ee.default_interval_hours.toString()),q(ee.interval_type||"hours"),V(ee.icon||"Wrench")},W=()=>{P&&I.trim()&&parseFloat(D)>0&&(i(P.id,{name:I.trim(),default_interval_hours:parseFloat(D),interval_type:L,icon:R}),C(null))},ne=(ee,ae,fe)=>{const ue=parseFloat(l);if(!isNaN(ue)&&ue>0){const xe=Math.abs(ue-ae)<.01?null:ue;n(ee,{custom_interval_hours:xe,custom_interval_type:d!==fe?d:null})}o(null)},Y=ee=>{ee.preventDefault(),x.trim()&&parseFloat(v)>0&&(r({name:x.trim(),default_interval_hours:parseFloat(v),interval_type:E,icon:A}),y(""),b("100"),S("hours"),m(!1))},Z=t?.map(ee=>({printerId:ee.printer_id,printerName:ee.printer_name,items:ee.maintenance_items.sort((ae,fe)=>ae.maintenance_type_id-fe.maintenance_type_id)})).sort((ee,ae)=>ee.printerName.localeCompare(ae.printerName))||[],U=e.filter(ee=>ee.is_system),$=e.filter(ee=>!ee.is_system);return c.jsxs("div",{className:"space-y-8",children:[c.jsxs("div",{children:[c.jsxs("div",{className:"flex items-center justify-between mb-4",children:[c.jsxs("div",{children:[c.jsx("h2",{className:"text-lg font-semibold text-white",children:"Maintenance Types"}),c.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:"System types and your custom maintenance tasks"})]}),c.jsxs(Ie,{onClick:()=>m(!g),children:[c.jsx(fr,{className:"w-4 h-4"}),"Add Custom Type"]})]}),g&&c.jsx(Nt,{className:"mb-6",children:c.jsx(Dt,{className:"py-4",children:c.jsxs("form",{onSubmit:Y,children:[c.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:[c.jsxs("div",{className:"lg:col-span-2",children:[c.jsx("label",{className:"block text-xs text-bambu-gray mb-1.5",children:"Name"}),c.jsx("input",{type:"text",value:x,onChange:ee=>y(ee.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none",placeholder:"e.g., Replace HEPA Filter",autoFocus:!0})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-xs text-bambu-gray mb-1.5",children:"Interval Type"}),c.jsxs("select",{value:E,onChange:ee=>{S(ee.target.value),ee.target.value==="days"?b("30"):b("100")},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none",children:[c.jsx("option",{value:"hours",children:"Print Hours"}),c.jsx("option",{value:"days",children:"Calendar Days"})]})]}),c.jsxs("div",{children:[c.jsxs("label",{className:"block text-xs text-bambu-gray mb-1.5",children:["Interval (",E==="days"?"days":"hours",")"]}),c.jsx("input",{type:"number",value:v,onChange:ee=>b(ee.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none",min:"1"})]})]}),c.jsxs("div",{className:"mt-4 flex items-end justify-between",children:[c.jsxs("div",{children:[c.jsx("label",{className:"block text-xs text-bambu-gray mb-1.5",children:"Icon"}),c.jsx("div",{className:"flex gap-1",children:Object.keys(Px).map(ee=>{const ae=Px[ee];return c.jsx("button",{type:"button",onClick:()=>T(ee),className:`p-2 rounded-lg transition-colors ${A===ee?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary"}`,children:c.jsx(ae,{className:"w-4 h-4"})},ee)})})]}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(Ie,{type:"button",variant:"secondary",onClick:()=>m(!1),children:"Cancel"}),c.jsx(Ie,{type:"submit",disabled:!x.trim(),children:"Add Type"})]})]})]})})}),c.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3",children:[U.map(ee=>{const ae=t0(ee.icon),fe=ee.interval_type||"hours";return c.jsx("div",{className:"bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-dark-tertiary",children:c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("div",{className:"p-2.5 bg-bambu-dark rounded-lg",children:c.jsx(ae,{className:"w-5 h-5 text-bambu-gray"})}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsx("div",{className:"text-sm font-medium text-white truncate",children:ee.name}),c.jsxs("div",{className:"text-xs text-bambu-gray mt-0.5 flex items-center gap-1",children:[fe==="days"?c.jsx(qr,{className:"w-3 h-3"}):c.jsx(Ou,{className:"w-3 h-3"}),VN(ee.default_interval_hours,fe)]})]})]})},ee.id)}),$.map(ee=>{const ae=t0(ee.icon),fe=ee.interval_type||"hours";return P?.id===ee.id?c.jsx("div",{className:"bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-green",children:c.jsxs("div",{className:"space-y-3",children:[c.jsx("input",{type:"text",value:I,onChange:xe=>N(xe.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none",placeholder:"Name",autoFocus:!0}),c.jsxs("div",{className:"flex gap-2",children:[c.jsxs("select",{value:L,onChange:xe=>q(xe.target.value),className:"flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none",children:[c.jsx("option",{value:"hours",children:"Print Hours"}),c.jsx("option",{value:"days",children:"Calendar Days"})]}),c.jsx("input",{type:"number",value:D,onChange:xe=>F(xe.target.value),className:"w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none",min:"1"})]}),c.jsx("div",{className:"flex flex-wrap gap-1",children:Object.keys(Px).map(xe=>{const Me=Px[xe];return c.jsx("button",{type:"button",onClick:()=>V(xe),className:`p-1.5 rounded transition-colors ${R===xe?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:c.jsx(Me,{className:"w-3.5 h-3.5"})},xe)})}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(Ie,{size:"sm",onClick:W,disabled:!I.trim(),children:"Save"}),c.jsx(Ie,{size:"sm",variant:"secondary",onClick:()=>C(null),children:"Cancel"})]})]})},ee.id):c.jsx("div",{className:"bg-bambu-dark-secondary rounded-xl p-4 border border-bambu-green/30",children:c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("div",{className:"p-2.5 bg-bambu-green/20 rounded-lg",children:c.jsx(ae,{className:"w-5 h-5 text-bambu-green"})}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"text-sm font-medium text-white truncate",children:ee.name}),c.jsx("span",{className:"px-1.5 py-0.5 bg-bambu-green/20 text-bambu-green text-[10px] font-medium rounded",children:"Custom"})]}),c.jsxs("div",{className:"text-xs text-bambu-gray mt-0.5 flex items-center gap-1",children:[fe==="days"?c.jsx(qr,{className:"w-3 h-3"}):c.jsx(Ou,{className:"w-3 h-3"}),VN(ee.default_interval_hours,fe)]})]}),c.jsx("button",{onClick:()=>K(ee),className:"p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-white transition-colors",children:c.jsx(d0,{className:"w-4 h-4"})}),c.jsx("button",{onClick:()=>{confirm(`Delete "${ee.name}"?`)&&s(ee.id)},className:"p-2 rounded-lg hover:bg-bambu-dark text-bambu-gray hover:text-red-400 transition-colors",children:c.jsx(kn,{className:"w-4 h-4"})})]})},ee.id)})]})]}),Z.length>0&&c.jsxs("div",{children:[c.jsxs("div",{className:"mb-4",children:[c.jsx("h2",{className:"text-lg font-semibold text-white",children:"Interval Overrides"}),c.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:"Customize intervals for specific printers"})]}),c.jsx("div",{className:"space-y-4",children:Z.map(ee=>c.jsx(Nt,{children:c.jsxs(Dt,{className:"py-4",children:[c.jsx("h3",{className:"text-sm font-medium text-white mb-3",children:ee.printerName}),c.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-2",children:ee.items.map(ae=>{const fe=t0(ae.maintenance_type_icon),ue=e.find(je=>je.id===ae.maintenance_type_id),xe=ue?.default_interval_hours||ae.interval_hours,Me=ue?.interval_type||"hours",se=ae.interval_type||"hours",ve=a===ae.id;return c.jsxs("div",{className:"flex items-center gap-2 p-2.5 bg-bambu-dark rounded-lg",children:[c.jsx(fe,{className:"w-4 h-4 text-bambu-gray shrink-0"}),c.jsx("span",{className:"text-xs text-bambu-gray flex-1 truncate",children:ae.maintenance_type_name}),ve?c.jsxs("div",{className:"flex items-center gap-1",children:[d==="days"?c.jsx(qr,{className:"w-3.5 h-3.5 text-bambu-gray shrink-0"}):c.jsx(Ou,{className:"w-3.5 h-3.5 text-bambu-gray shrink-0"}),c.jsxs("select",{value:d,onChange:je=>f(je.target.value),className:"px-1.5 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs",children:[c.jsx("option",{value:"hours",children:"Print Hours"}),c.jsx("option",{value:"days",children:"Calendar Days"})]}),c.jsx("input",{type:"number",value:l,onChange:je=>u(je.target.value),onKeyDown:je=>{je.key==="Enter"&&ne(ae.id,xe,Me),je.key==="Escape"&&o(null)},className:"w-16 px-2 py-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-xs",min:"1"}),c.jsx(Ie,{size:"sm",onClick:()=>ne(ae.id,xe,Me),children:"OK"})]}):c.jsxs("button",{onClick:()=>{o(ae.id),u(ae.interval_hours.toString()),f(se)},className:"px-2 py-1 bg-bambu-dark-tertiary hover:bg-bambu-dark-secondary border border-bambu-dark-tertiary hover:border-bambu-green rounded text-xs font-medium text-white transition-colors flex items-center gap-1",children:[se==="days"?c.jsx(qr,{className:"w-3 h-3"}):c.jsx(Ou,{className:"w-3 h-3"}),VN(ae.interval_hours,se),c.jsx(d0,{className:"w-3 h-3 text-bambu-gray"})]})]},ae.id)})})]})},ee.printerId))})]}),Z.length===0&&c.jsx(Nt,{children:c.jsxs(Dt,{className:"text-center py-12",children:[c.jsx(ti,{className:"w-12 h-12 mx-auto mb-4 text-bambu-gray/30"}),c.jsx("p",{className:"text-bambu-gray",children:"No printers configured"}),c.jsx("p",{className:"text-sm text-bambu-gray/70 mt-1",children:"Add printers to configure maintenance intervals"})]})})]})}function rGe(){const t=Sn(),{showToast:e}=ri(),[n,r]=M.useState("status"),{data:i,isLoading:s}=yt({queryKey:["maintenanceOverview"],queryFn:Pe.getMaintenanceOverview}),{data:a}=yt({queryKey:["maintenanceTypes"],queryFn:Pe.getMaintenanceTypes}),o=_t({mutationFn:({id:E,notes:S})=>Pe.performMaintenance(E,S),onSuccess:()=>{t.invalidateQueries({queryKey:["maintenanceOverview"]}),t.invalidateQueries({queryKey:["maintenanceSummary"]}),e("Maintenance marked as complete")},onError:E=>{e(E.message,"error")}}),l=_t({mutationFn:({id:E,data:S})=>Pe.updateMaintenanceItem(E,S),onSuccess:()=>{t.invalidateQueries({queryKey:["maintenanceOverview"]})},onError:E=>{e(E.message,"error")}}),u=_t({mutationFn:Pe.createMaintenanceType,onSuccess:()=>{t.invalidateQueries({queryKey:["maintenanceTypes"]}),t.invalidateQueries({queryKey:["maintenanceOverview"]}),e("Maintenance type added")},onError:E=>{e(E.message,"error")}}),d=_t({mutationFn:({id:E,data:S})=>Pe.updateMaintenanceType(E,S),onSuccess:()=>{t.invalidateQueries({queryKey:["maintenanceTypes"]}),t.invalidateQueries({queryKey:["maintenanceOverview"]}),e("Maintenance type updated")},onError:E=>{e(E.message,"error")}}),f=_t({mutationFn:Pe.deleteMaintenanceType,onSuccess:()=>{t.invalidateQueries({queryKey:["maintenanceTypes"]}),t.invalidateQueries({queryKey:["maintenanceOverview"]}),e("Maintenance type deleted")},onError:E=>{e(E.message,"error")}}),g=_t({mutationFn:({printerId:E,hours:S})=>Pe.setPrinterHours(E,S),onSuccess:()=>{t.invalidateQueries({queryKey:["maintenanceOverview"]}),t.invalidateQueries({queryKey:["maintenanceSummary"]}),e("Print hours updated")},onError:E=>{e(E.message,"error")}}),m=E=>{o.mutate({id:E})},x=(E,S)=>{l.mutate({id:E,data:{enabled:S}})},y=(E,S)=>{g.mutate({printerId:E,hours:S})};if(s)return c.jsx("div",{className:"p-4 md:p-8 flex justify-center",children:c.jsx(At,{className:"w-8 h-8 text-bambu-green animate-spin"})});const v=i?.reduce((E,S)=>E+S.due_count,0)||0,b=i?.reduce((E,S)=>E+S.warning_count,0)||0;return c.jsxs("div",{className:"p-4 md:p-8",children:[c.jsxs("div",{className:"mb-6",children:[c.jsx("h1",{className:"text-2xl font-bold text-white",children:"Maintenance"}),c.jsx("p",{className:"text-bambu-gray text-sm mt-1",children:n==="status"?c.jsxs(c.Fragment,{children:[v>0&&c.jsxs("span",{className:"text-red-400",children:[v," task",v!==1?"s":""," overdue"]}),v>0&&b>0&&" · ",b>0&&c.jsxs("span",{className:"text-amber-400",children:[b," due soon"]}),v===0&&b===0&&c.jsx("span",{className:"text-bambu-green",children:"All maintenance up to date"})]}):"Configure maintenance types and intervals"})]}),c.jsxs("div",{className:"flex gap-1 mb-6 border-b border-bambu-dark-tertiary",children:[c.jsx("button",{onClick:()=>r("status"),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${n==="status"?"text-bambu-green border-bambu-green":"text-bambu-gray border-transparent hover:text-white"}`,children:"Status"}),c.jsx("button",{onClick:()=>r("settings"),className:`px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors ${n==="settings"?"text-bambu-green border-bambu-green":"text-bambu-gray border-transparent hover:text-white"}`,children:"Settings"})]}),n==="status"?c.jsx("div",{className:"space-y-6",children:i&&i.length>0?[...i].sort((E,S)=>{const A=E.due_count*10+E.warning_count,T=S.due_count*10+S.warning_count;return A!==T?T-A:E.printer_name.localeCompare(S.printer_name)}).map(E=>c.jsx(tGe,{overview:E,onPerform:m,onToggle:x,onSetHours:y},E.printer_id)):c.jsx(Nt,{children:c.jsxs(Dt,{className:"text-center py-16",children:[c.jsx(Ju,{className:"w-16 h-16 mx-auto mb-4 text-bambu-gray/30"}),c.jsx("p",{className:"text-lg font-medium text-white mb-2",children:"No printers configured"}),c.jsx("p",{className:"text-bambu-gray",children:"Add printers to start tracking maintenance"})]})})}):c.jsx(nGe,{overview:i,types:a||[],onUpdateInterval:(E,S)=>l.mutate({id:E,data:S}),onAddType:E=>u.mutate(E),onUpdateType:(E,S)=>d.mutate({id:E,data:S}),onDeleteType:E=>f.mutate(E)})]})}const B9=["#ef4444","#f97316","#eab308","#22c55e","#06b6d4","#3b82f6","#8b5cf6","#ec4899","#6b7280"];function iGe({project:t,onClose:e,onSave:n,isLoading:r}){const[i,s]=M.useState(t?.name||""),[a,o]=M.useState(t?.description||""),[l,u]=M.useState(t?.color||B9[0]),[d,f]=M.useState(t?.target_count?.toString()||""),[g,m]=M.useState(t?.status||"active"),x=y=>{y.preventDefault(),n({name:i.trim(),description:a.trim()||void 0,color:l,target_count:d?parseInt(d,10):void 0,...t&&{status:g}})};return c.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",children:c.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-md border border-bambu-dark-tertiary",children:[c.jsx("div",{className:"p-4 border-b border-bambu-dark-tertiary",children:c.jsx("h2",{className:"text-lg font-semibold text-white",children:t?"Edit Project":"New Project"})}),c.jsxs("form",{onSubmit:x,className:"p-4 space-y-4",children:[c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:"Name"}),c.jsx("input",{type:"text",value:i,onChange:y=>s(y.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:"e.g., Voron 2.4 Build",required:!0})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:"Description"}),c.jsx("textarea",{value:a,onChange:y=>o(y.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green resize-none",placeholder:"Optional description...",rows:2})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:"Color"}),c.jsx("div",{className:"flex gap-2 flex-wrap",children:B9.map(y=>c.jsx("button",{type:"button",onClick:()=>u(y),className:`w-8 h-8 rounded-full transition-transform ${l===y?"ring-2 ring-white ring-offset-2 ring-offset-bambu-dark-secondary scale-110":""}`,style:{backgroundColor:y}},y))})]}),c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:"Target Print Count (optional)"}),c.jsx("input",{type:"number",value:d,onChange:y=>f(y.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white placeholder-bambu-gray focus:outline-none focus:border-bambu-green",placeholder:"e.g., 50 parts to print",min:"1"})]}),t&&c.jsxs("div",{children:[c.jsx("label",{className:"block text-sm font-medium text-white mb-1",children:"Status"}),c.jsxs("select",{value:g,onChange:y=>m(y.target.value),className:"w-full bg-bambu-dark border border-bambu-dark-tertiary rounded px-3 py-2 text-white focus:outline-none focus:border-bambu-green",children:[c.jsx("option",{value:"active",children:"Active"}),c.jsx("option",{value:"completed",children:"Completed"}),c.jsx("option",{value:"archived",children:"Archived"})]})]}),c.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[c.jsx(Ie,{type:"button",variant:"secondary",onClick:e,children:"Cancel"}),c.jsx(Ie,{type:"submit",disabled:!i.trim()||r,children:r?c.jsx(At,{className:"w-4 h-4 animate-spin"}):t?"Save":"Create"})]})]})]})})}function sGe({project:t,onClick:e,onEdit:n,onDelete:r}){const i=t.progress_percent??0,s=t.status==="completed",a=t.status==="archived";return c.jsx(Nt,{className:"hover:border-bambu-gray/30 transition-colors cursor-pointer",onClick:e,children:c.jsxs(Dt,{className:"p-4",children:[c.jsxs("div",{className:"flex items-start justify-between mb-3",children:[c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("div",{className:"w-3 h-3 rounded-full flex-shrink-0",style:{backgroundColor:t.color||"#6b7280"}}),c.jsxs("div",{children:[c.jsx("h3",{className:"font-medium text-white",children:t.name}),t.description&&c.jsx("p",{className:"text-sm text-bambu-gray/70 mt-0.5 line-clamp-1",children:t.description})]})]}),c.jsxs("div",{className:"flex items-center gap-1",onClick:o=>o.stopPropagation(),children:[s&&c.jsx("span",{className:"text-xs bg-bambu-green/20 text-bambu-green px-2 py-0.5 rounded",children:"Completed"}),a&&c.jsx("span",{className:"text-xs bg-bambu-gray/20 text-bambu-gray px-2 py-0.5 rounded",children:"Archived"}),c.jsx(Ie,{variant:"ghost",size:"sm",onClick:n,className:"p-1",children:c.jsx(d0,{className:"w-4 h-4"})}),c.jsx(Ie,{variant:"ghost",size:"sm",onClick:r,className:"p-1 text-red-400 hover:text-red-300",children:c.jsx(kn,{className:"w-4 h-4"})})]})]}),t.target_count&&c.jsxs("div",{className:"mb-3",children:[c.jsxs("div",{className:"flex justify-between text-xs text-bambu-gray mb-1",children:[c.jsxs("span",{children:[t.archive_count," / ",t.target_count," prints"]}),c.jsxs("span",{children:[i.toFixed(0),"%"]})]}),c.jsx("div",{className:"h-2 bg-bambu-dark rounded-full overflow-hidden",children:c.jsx("div",{className:"h-full transition-all duration-300",style:{width:`${Math.min(i,100)}%`,backgroundColor:i>=100?"#22c55e":t.color||"#6b7280"}})})]}),t.archives&&t.archives.length>0&&c.jsx("div",{className:"mb-3",children:c.jsxs("div",{className:"flex gap-2",children:[t.archives.slice(0,5).map(o=>c.jsxs("a",{href:`/archives?search=${encodeURIComponent(o.print_name||"")}`,onClick:l=>l.stopPropagation(),className:"relative w-14 h-14 rounded-lg bg-bambu-dark flex-shrink-0 overflow-hidden border border-bambu-dark-tertiary hover:border-bambu-green transition-colors",title:o.print_name||"Unknown",children:[o.thumbnail_path?c.jsx("img",{src:`/api/v1/archives/${o.id}/thumbnail`,alt:o.print_name||"",className:"w-full h-full object-cover"}):c.jsx("div",{className:"w-full h-full flex items-center justify-center text-bambu-gray",children:c.jsx(u0,{className:"w-6 h-6"})}),o.status==="failed"&&c.jsx("div",{className:"absolute inset-0 bg-red-500/40 flex items-center justify-center",children:c.jsx("span",{className:"text-white text-xs font-bold",children:"✗"})})]},o.id)),t.archive_count>5&&c.jsxs("div",{className:"w-14 h-14 rounded-lg bg-bambu-dark flex-shrink-0 flex items-center justify-center text-sm text-bambu-gray border border-bambu-dark-tertiary",children:["+",t.archive_count-5]})]})}),c.jsxs("div",{className:"flex items-center gap-4 text-sm text-bambu-gray",children:[c.jsxs("div",{className:"flex items-center gap-1",title:"Archives",children:[c.jsx(pS,{className:"w-4 h-4"}),c.jsx("span",{children:t.archive_count})]}),c.jsxs("div",{className:"flex items-center gap-1",title:"Queued",children:[c.jsx(ole,{className:"w-4 h-4"}),c.jsx("span",{children:t.queue_count})]})]})]})})}function aGe(){const t=Sn(),{showToast:e}=ri(),[n,r]=M.useState(!1),[i,s]=M.useState(),[a,o]=M.useState("active"),[l,u]=M.useState(null),{data:d,isLoading:f}=yt({queryKey:["projects",a==="all"?void 0:a],queryFn:()=>Pe.getProjects(a==="all"?void 0:a)}),g=_t({mutationFn:A=>Pe.createProject(A),onSuccess:()=>{t.invalidateQueries({queryKey:["projects"]}),r(!1),e("Project created","success")},onError:A=>{e(A.message,"error")}}),m=_t({mutationFn:({id:A,data:T})=>Pe.updateProject(A,T),onSuccess:()=>{t.invalidateQueries({queryKey:["projects"]}),r(!1),s(void 0),e("Project updated","success")},onError:A=>{e(A.message,"error")}}),x=_t({mutationFn:A=>Pe.deleteProject(A),onSuccess:()=>{t.invalidateQueries({queryKey:["projects"]}),u(null),e("Project deleted","success")},onError:A=>{e(A.message,"error")}}),y=A=>{i?m.mutate({id:i.id,data:A}):g.mutate(A)},v=A=>{s(A),r(!0)},b=A=>{v(A)},E=A=>{u(A)},S=()=>{l!==null&&x.mutate(l)};return c.jsxs("div",{className:"space-y-6",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx(ph,{className:"w-6 h-6 text-bambu-green"}),c.jsx("h1",{className:"text-2xl font-bold text-white",children:"Projects"})]}),c.jsxs(Ie,{onClick:()=>r(!0),children:[c.jsx(fr,{className:"w-4 h-4 mr-2"}),"New Project"]})]}),c.jsx("div",{className:"flex gap-2",children:["active","completed","archived","all"].map(A=>c.jsx("button",{onClick:()=>o(A),className:`px-3 py-1.5 text-sm rounded-lg transition-colors ${a===A?"bg-bambu-green text-white":"bg-bambu-card text-bambu-gray hover:bg-bambu-gray/20"}`,children:A.charAt(0).toUpperCase()+A.slice(1)},A))}),f?c.jsx("div",{className:"flex items-center justify-center py-12",children:c.jsx(At,{className:"w-8 h-8 animate-spin text-bambu-green"})}):d?.length===0?c.jsx(Nt,{children:c.jsxs(Dt,{className:"py-12 text-center",children:[c.jsx(ph,{className:"w-12 h-12 text-bambu-gray/50 mx-auto mb-4"}),c.jsx("p",{className:"text-bambu-gray",children:"No projects found"}),c.jsx("p",{className:"text-bambu-gray/70 text-sm mt-1",children:"Create a project to group related prints together"})]})}):c.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:d?.map(A=>c.jsx(sGe,{project:A,onClick:()=>b(A),onEdit:()=>v(A),onDelete:()=>E(A.id)},A.id))}),l!==null&&c.jsx(Kr,{title:"Delete Project",message:"Are you sure you want to delete this project? Archives and queue items will be unlinked but not deleted.",confirmText:"Delete Project",variant:"danger",onConfirm:S,onCancel:()=>u(null)}),n&&c.jsx(iGe,{project:i,onClose:()=>{r(!1),s(void 0)},onSave:y,isLoading:g.isPending||m.isPending})]})}function oGe(){const{printerId:t}=lG(),e=parseInt(t||"0",10),[n,r]=M.useState("stream"),[i,s]=M.useState(!1),[a,o]=M.useState(!0),[l,u]=M.useState(Date.now()),[d,f]=M.useState(!1),[g,m]=M.useState(!1),x=M.useRef(null),y=M.useRef(null),{data:v}=yt({queryKey:["printer",e],queryFn:()=>Pe.getPrinter(e),enabled:e>0});M.useEffect(()=>(v&&(document.title=`${v.name} - Camera`),()=>{document.title="Bambuddy"}),[v]),M.useEffect(()=>()=>{x.current&&(x.current.src="")},[]),M.useEffect(()=>{if(a&&!d){const N=setTimeout(()=>{o(!1)},n==="stream"?3e3:2e4);return()=>clearTimeout(N)}},[n,a,l,d]),M.useEffect(()=>{const I=()=>{m(!!document.fullscreenElement)};return document.addEventListener("fullscreenchange",I),()=>document.removeEventListener("fullscreenchange",I)},[]);const b=()=>{s(!0),o(!1)},E=()=>{o(!1),s(!1)},S=I=>{n===I||d||(f(!0),o(!0),s(!1),x.current&&(x.current.src=""),setTimeout(()=>{r(I),u(Date.now()),f(!1)},100))},A=()=>{d||(f(!0),o(!0),s(!1),x.current&&(x.current.src=""),setTimeout(()=>{u(Date.now()),f(!1)},100))},T=()=>{y.current&&(document.fullscreenElement?document.exitFullscreen():y.current.requestFullscreen())},P=d?"":n==="stream"?`/api/v1/printers/${e}/camera/stream?fps=10&t=${l}`:`/api/v1/printers/${e}/camera/snapshot?t=${l}`,C=a||d;return e?c.jsxs("div",{ref:y,className:"min-h-screen bg-black flex flex-col",children:[c.jsxs("div",{className:"flex items-center justify-between px-4 py-2 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary",children:[c.jsxs("h1",{className:"text-sm font-medium text-white flex items-center gap-2",children:[c.jsx(a0,{className:"w-4 h-4"}),v?.name||`Printer ${e}`]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("div",{className:"flex bg-bambu-dark rounded p-0.5",children:[c.jsx("button",{onClick:()=>S("stream"),disabled:C,className:`px-3 py-1 text-xs rounded transition-colors ${n==="stream"?"bg-bambu-green text-white":"text-bambu-gray hover:text-white disabled:opacity-50"}`,children:"Live"}),c.jsx("button",{onClick:()=>S("snapshot"),disabled:C,className:`px-3 py-1 text-xs rounded transition-colors ${n==="snapshot"?"bg-bambu-green text-white":"text-bambu-gray hover:text-white disabled:opacity-50"}`,children:"Snapshot"})]}),c.jsx("button",{onClick:A,disabled:C,className:"p-1.5 hover:bg-bambu-dark-tertiary rounded disabled:opacity-50",title:n==="stream"?"Restart stream":"Refresh snapshot",children:c.jsx(qs,{className:`w-4 h-4 text-bambu-gray ${C?"animate-spin":""}`})}),c.jsx("button",{onClick:T,className:"p-1.5 hover:bg-bambu-dark-tertiary rounded",title:g?"Exit fullscreen":"Fullscreen",children:g?c.jsx(Ale,{className:"w-4 h-4 text-bambu-gray"}):c.jsx(yle,{className:"w-4 h-4 text-bambu-gray"})})]})]}),c.jsx("div",{className:"flex-1 flex items-center justify-center p-2",children:c.jsxs("div",{className:"relative w-full h-full flex items-center justify-center",children:[(a||d)&&c.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/50 z-10",children:c.jsxs("div",{className:"text-center",children:[c.jsx(qs,{className:"w-8 h-8 text-bambu-gray animate-spin mx-auto mb-2"}),c.jsx("p",{className:"text-sm text-bambu-gray",children:n==="stream"?"Connecting to camera...":"Capturing snapshot..."})]})}),i&&c.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black z-10",children:c.jsxs("div",{className:"text-center p-4",children:[c.jsx(Qr,{className:"w-12 h-12 text-orange-400 mx-auto mb-3"}),c.jsx("p",{className:"text-white mb-2",children:"Camera unavailable"}),c.jsx("p",{className:"text-xs text-bambu-gray mb-4 max-w-md",children:"Make sure the printer is powered on and connected."}),c.jsx("button",{onClick:A,className:"px-4 py-2 bg-bambu-green text-white rounded hover:bg-bambu-green/80 transition-colors",children:"Retry"})]})}),c.jsx("img",{ref:x,src:P,alt:"Camera stream",className:"max-w-full max-h-full object-contain",onError:P?b:void 0,onLoad:P?E:void 0},l)]})})]}):c.jsx("div",{className:"min-h-screen bg-black flex items-center justify-center",children:c.jsx("p",{className:"text-white",children:"Invalid printer ID"})})}function lGe(){const{id:t}=lG(),{theme:e}=yS(),{data:n,isLoading:r,error:i}=yt({queryKey:["external-link",t],queryFn:()=>Pe.getExternalLink(Number(t)),enabled:!!t});return r?c.jsx("div",{className:"flex items-center justify-center h-full",children:c.jsx(At,{className:"w-8 h-8 text-bambu-green animate-spin"})}):i||!n?c.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-4 text-bambu-gray",children:[c.jsx(Qr,{className:"w-12 h-12"}),c.jsx("p",{children:"Link not found"})]}):c.jsx("iframe",{src:n.url,className:"h-full w-full border-0",style:{colorScheme:e},title:n.name,sandbox:"allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox"})}function cGe(){const t=M.useRef(null),e=M.useRef(null),n=Sn(),[r,i]=M.useState(!1),s=M.useCallback(()=>{if(t.current?.readyState===WebSocket.OPEN)return;const u=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/api/v1/ws`,d=new WebSocket(u);let f=null;d.onopen=()=>{console.log("[WebSocket] Connected"),i(!0),f=window.setInterval(()=>{d.readyState===WebSocket.OPEN&&d.send(JSON.stringify({type:"ping"}))},3e4)},d.onmessage=g=>{try{const m=JSON.parse(g.data);a(m)}catch{}},d.onclose=g=>{console.log("[WebSocket] Closed",g.code,g.reason),f&&(clearInterval(f),f=null),i(!1),t.current=null,e.current=window.setTimeout(()=>{s()},3e3)},d.onerror=g=>{console.error("[WebSocket] Error",g),d.close()},t.current=d},[]),a=M.useCallback(l=>{switch(l.type){case"printer_status":l.printer_id!==void 0&&n.setQueryData(["printerStatus",l.printer_id],u=>{const d={...u,...l.data};return d.wifi_signal==null&&u?.wifi_signal!=null&&(d.wifi_signal=u.wifi_signal),d});break;case"print_complete":n.invalidateQueries({queryKey:["archives"]}),n.invalidateQueries({queryKey:["archiveStats"]});break;case"archive_created":n.invalidateQueries({queryKey:["archives"]}),n.invalidateQueries({queryKey:["archiveStats"]});break}},[n]);M.useEffect(()=>(s(),()=>{e.current&&clearTimeout(e.current),t.current&&t.current.close()}),[s]);const o=M.useCallback(l=>{t.current?.readyState===WebSocket.OPEN&&t.current.send(JSON.stringify(l))},[]);return{isConnected:r,sendMessage:o}}const uGe=new Wse({defaultOptions:{queries:{staleTime:1e3*60,retry:1}}});function dGe({children:t}){return cGe(),c.jsx(c.Fragment,{children:t})}function hGe(){return c.jsx(iue,{children:c.jsx(pue,{children:c.jsx(qse,{client:uGe,children:c.jsx(dGe,{children:c.jsx(pse,{children:c.jsxs(Gie,{children:[c.jsx(La,{path:"/camera/:printerId",element:c.jsx(oGe,{})}),c.jsxs(La,{path:"/",element:c.jsx(due,{}),children:[c.jsx(La,{index:!0,element:c.jsx(Wue,{})}),c.jsx(La,{path:"archives",element:c.jsx(yNe,{})}),c.jsx(La,{path:"queue",element:c.jsx(ske,{})}),c.jsx(La,{path:"stats",element:c.jsx(E9e,{})}),c.jsx(La,{path:"profiles",element:c.jsx(J9e,{})}),c.jsx(La,{path:"maintenance",element:c.jsx(rGe,{})}),c.jsx(La,{path:"projects",element:c.jsx(aGe,{})}),c.jsx(La,{path:"settings",element:c.jsx(H9e,{})}),c.jsx(La,{path:"external/:id",element:c.jsx(lGe,{})})]})]})})})})})})}Xne.createRoot(document.getElementById("root")).render(c.jsx(M.StrictMode,{children:c.jsx(hGe,{})})); diff --git a/static/index.html b/static/index.html index 680ab65cf..c85981758 100644 --- a/static/index.html +++ b/static/index.html @@ -23,7 +23,7 @@ - +