@wraps.dev/cli 2.24.0 → 2.25.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -123,5 +123,5 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
123
123
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Ppe(e,t){if(e){if(typeof e=="string")return Oj(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n==="Object"&&e.constructor&&(n=e.constructor.name),n==="Map"||n==="Set")return Array.from(e);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Oj(e,t)}}function kpe(e){if(typeof Symbol<"u"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function $pe(e){if(Array.isArray(e))return Oj(e)}function Oj(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function Ipe(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function D4(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,k6(r.key),r)}}function Lpe(e,t,n){return t&&D4(e.prototype,t),n&&D4(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function zpe(e,t,n){return t=wp(t),Bpe(e,P6()?Reflect.construct(t,n||[],wp(e).constructor):t.apply(e,n))}function Bpe(e,t){if(t&&(Zl(t)==="object"||typeof t=="function"))return t;if(t!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return qpe(e)}function qpe(e){if(e===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function P6(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(P6=function(){return!!e})()}function wp(e){return wp=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(n){return n.__proto__||Object.getPrototypeOf(n)},wp(e)}function Upe(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&Ej(e,t)}function Ej(e,t){return Ej=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(r,i){return r.__proto__=i,r},Ej(e,t)}function Fr(e,t,n){return t=k6(t),t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function k6(e){var t=Hpe(e,"string");return Zl(t)=="symbol"?t:t+""}function Hpe(e,t){if(Zl(e)!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(Zl(r)!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}var Ar=(function(e){function t(){var n;Ipe(this,t);for(var r=arguments.length,i=new Array(r),o=0;o<r;o++)i[o]=arguments[o];return n=zpe(this,t,[].concat(i)),Fr(n,"state",{isAnimationFinished:!0,totalLength:0}),Fr(n,"generateSimpleStrokeDasharray",function(l,f){return"".concat(f,"px ").concat(l-f,"px")}),Fr(n,"getStrokeDasharray",function(l,f,d){var h=d.reduce(function(E,_){return E+_});if(!h)return n.generateSimpleStrokeDasharray(f,l);for(var v=Math.floor(l/h),m=l%h,g=f-l,x=[],O=0,j=0;O<d.length;j+=d[O],++O)if(j+d[O]>m){x=[].concat(gl(d.slice(0,O)),[m-j]);break}var b=x.length%2===0?[0,g]:[g];return[].concat(gl(t.repeat(d,v)),gl(x),b).map(function(E){return"".concat(E,"px")}).join(", ")}),Fr(n,"id",Xf("recharts-line-")),Fr(n,"pathRef",function(l){n.mainCurve=l}),Fr(n,"handleAnimationEnd",function(){n.setState({isAnimationFinished:!0}),n.props.onAnimationEnd&&n.props.onAnimationEnd()}),Fr(n,"handleAnimationStart",function(){n.setState({isAnimationFinished:!1}),n.props.onAnimationStart&&n.props.onAnimationStart()}),n}return Upe(t,e),Lpe(t,[{key:"componentDidMount",value:function(){if(this.props.isAnimationActive){var r=this.getTotalLength();this.setState({totalLength:r})}}},{key:"componentDidUpdate",value:function(){if(this.props.isAnimationActive){var r=this.getTotalLength();r!==this.state.totalLength&&this.setState({totalLength:r})}}},{key:"getTotalLength",value:function(){var r=this.mainCurve;try{return r&&r.getTotalLength&&r.getTotalLength()||0}catch{return 0}}},{key:"renderErrorBar",value:function(r,i){if(this.props.isAnimationActive&&!this.state.isAnimationFinished)return null;var o=this.props,l=o.points,f=o.xAxis,d=o.yAxis,h=o.layout,v=o.children,m=Rr(v,nd);if(!m)return null;var g=function(j,b){return{x:j.x,y:j.y,value:j.value,errorVal:cr(j.payload,b)}},x={clipPath:r?"url(#clipPath-".concat(i,")"):null};return I.createElement(Bt,x,m.map(function(O){return I.cloneElement(O,{key:"bar-".concat(O.props.dataKey),data:l,xAxis:f,yAxis:d,layout:h,dataPointFormatter:g})}))}},{key:"renderDots",value:function(r,i,o){var l=this.props.isAnimationActive;if(l&&!this.state.isAnimationFinished)return null;var f=this.props,d=f.dot,h=f.points,v=f.dataKey,m=nt(this.props,!1),g=nt(d,!0),x=h.map(function(j,b){var E=tr(tr(tr({key:"dot-".concat(b),r:3},m),g),{},{index:b,cx:j.x,cy:j.y,value:j.value,dataKey:v,payload:j.payload,points:h});return t.renderDotItem(d,E)}),O={clipPath:r?"url(#clipPath-".concat(i?"":"dots-").concat(o,")"):null};return I.createElement(Bt,Bu({className:"recharts-line-dots",key:"dots"},O),x)}},{key:"renderCurveStatically",value:function(r,i,o,l){var f=this.props,d=f.type,h=f.layout,v=f.connectNulls;f.ref;var m=M4(f,Tpe),g=tr(tr(tr({},nt(m,!0)),{},{fill:"none",className:"recharts-line-curve",clipPath:i?"url(#clipPath-".concat(o,")"):null,points:r},l),{},{type:d,layout:h,connectNulls:v});return I.createElement(nj,Bu({},g,{pathRef:this.pathRef}))}},{key:"renderCurveWithAnimation",value:function(r,i){var o=this,l=this.props,f=l.points,d=l.strokeDasharray,h=l.isAnimationActive,v=l.animationBegin,m=l.animationDuration,g=l.animationEasing,x=l.animationId,O=l.animateNewValues,j=l.width,b=l.height,E=this.state,_=E.prevPoints,A=E.totalLength;return I.createElement(di,{begin:v,duration:m,isActive:h,easing:g,from:{t:0},to:{t:1},key:"line-".concat(x),onAnimationEnd:this.handleAnimationEnd,onAnimationStart:this.handleAnimationStart},function(C){var N=C.t;if(_){var M=_.length/f.length,R=f.map(function(U,Y){var Z=Math.floor(Y*M);if(_[Z]){var X=_[Z],k=Gr(X.x,U.x),q=Gr(X.y,U.y);return tr(tr({},U),{},{x:k(N),y:q(N)})}if(O){var V=Gr(j*2,U.x),Q=Gr(b/2,U.y);return tr(tr({},U),{},{x:V(N),y:Q(N)})}return tr(tr({},U),{},{x:U.x,y:U.y})});return o.renderCurveStatically(R,r,i)}var D=Gr(0,A),L=D(N),H;if(d){var B="".concat(d).split(/[,\s]+/gim).map(function(U){return parseFloat(U)});H=o.getStrokeDasharray(L,A,B)}else H=o.generateSimpleStrokeDasharray(A,L);return o.renderCurveStatically(f,r,i,{strokeDasharray:H})})}},{key:"renderCurve",value:function(r,i){var o=this.props,l=o.points,f=o.isAnimationActive,d=this.state,h=d.prevPoints,v=d.totalLength;return f&&l&&l.length&&(!h&&v>0||!Lv(h,l))?this.renderCurveWithAnimation(r,i):this.renderCurveStatically(l,r,i)}},{key:"render",value:function(){var r,i=this.props,o=i.hide,l=i.dot,f=i.points,d=i.className,h=i.xAxis,v=i.yAxis,m=i.top,g=i.left,x=i.width,O=i.height,j=i.isAnimationActive,b=i.id;if(o||!f||!f.length)return null;var E=this.state.isAnimationFinished,_=f.length===1,A=et("recharts-line",d),C=h&&h.allowDataOverflow,N=v&&v.allowDataOverflow,M=C||N,R=Qe(b)?this.id:b,D=(r=nt(l,!1))!==null&&r!==void 0?r:{r:3,strokeWidth:2},L=D.r,H=L===void 0?3:L,B=D.strokeWidth,U=B===void 0?2:B,Y=ate(l)?l:{},Z=Y.clipDot,X=Z===void 0?!0:Z,k=H*2+U;return I.createElement(Bt,{className:A},C||N?I.createElement("defs",null,I.createElement("clipPath",{id:"clipPath-".concat(R)},I.createElement("rect",{x:C?g:g-x/2,y:N?m:m-O/2,width:C?x:x*2,height:N?O:O*2})),!X&&I.createElement("clipPath",{id:"clipPath-dots-".concat(R)},I.createElement("rect",{x:g-k/2,y:m-k/2,width:x+k,height:O+k}))):null,!_&&this.renderCurve(M,R),this.renderErrorBar(M,R),(_||l)&&this.renderDots(M,X,R),(!j||E)&&Ji.renderCallByParent(this.props,f))}}],[{key:"getDerivedStateFromProps",value:function(r,i){return r.animationId!==i.prevAnimationId?{prevAnimationId:r.animationId,curPoints:r.points,prevPoints:i.curPoints}:r.points!==i.curPoints?{curPoints:r.points}:null}},{key:"repeat",value:function(r,i){for(var o=r.length%2!==0?[].concat(gl(r),[0]):r,l=[],f=0;f<i;++f)l=[].concat(gl(l),gl(o));return l}},{key:"renderDotItem",value:function(r,i){var o;if(I.isValidElement(r))o=I.cloneElement(r,i);else if(Ye(r))o=r(i);else{var l=i.key,f=M4(i,Mpe),d=et("recharts-line-dot",typeof r!="boolean"?r.className:"");o=I.createElement(kE,Bu({key:l},f,{className:d}))}return o}}])})(S.PureComponent);Fr(Ar,"displayName","Line");Fr(Ar,"defaultProps",{xAxisId:0,yAxisId:0,connectNulls:!1,activeDot:!0,dot:!0,legendType:"line",stroke:"#3182bd",strokeWidth:1,fill:"#fff",points:[],isAnimationActive:!bc.isSsr,animateNewValues:!0,animationBegin:0,animationDuration:1500,animationEasing:"ease",hide:!1,label:!1});Fr(Ar,"getComposedData",function(e){var t=e.props,n=e.xAxis,r=e.yAxis,i=e.xAxisTicks,o=e.yAxisTicks,l=e.dataKey,f=e.bandSize,d=e.displayedData,h=e.offset,v=t.layout,m=d.map(function(g,x){var O=cr(g,l);return v==="horizontal"?{x:XP({axis:n,ticks:i,bandSize:f,entry:g,index:x}),y:Qe(O)?null:r.scale(O),value:O,payload:g}:{x:Qe(O)?null:n.scale(O),y:XP({axis:r,ticks:o,bandSize:f,entry:g,index:x}),value:O,payload:g}});return tr({points:m,layout:v},h)});function Jl(e){"@babel/helpers - typeof";return Jl=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Jl(e)}function Fpe(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Gpe(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,L6(r.key),r)}}function Vpe(e,t,n){return t&&Gpe(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e}function Ype(e,t,n){return t=Sp(t),Wpe(e,$6()?Reflect.construct(t,n||[],Sp(e).constructor):t.apply(e,n))}function Wpe(e,t){if(t&&(Jl(t)==="object"||typeof t=="function"))return t;if(t!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return Kpe(e)}function Kpe(e){if(e===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function $6(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return($6=function(){return!!e})()}function Sp(e){return Sp=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(n){return n.__proto__||Object.getPrototypeOf(n)},Sp(e)}function Xpe(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&_j(e,t)}function _j(e,t){return _j=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(r,i){return r.__proto__=i,r},_j(e,t)}function I6(e,t,n){return t=L6(t),t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function L6(e){var t=Qpe(e,"string");return Jl(t)=="symbol"?t:t+""}function Qpe(e,t){if(Jl(e)!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(Jl(r)!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}function Aj(){return Aj=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Aj.apply(this,arguments)}function Zpe(e){var t=e.xAxisId,n=zE(),r=BE(),i=S6(t);return i==null?null:S.createElement(Oc,Aj({},i,{className:et("recharts-".concat(i.axisType," ").concat(i.axisType),i.className),viewBox:{x:0,y:0,width:n,height:r},ticksGenerator:function(l){return Qa(l,!0)}}))}var ws=(function(e){function t(){return Fpe(this,t),Ype(this,t,arguments)}return Xpe(t,e),Vpe(t,[{key:"render",value:function(){return S.createElement(Zpe,this.props)}}])})(S.Component);I6(ws,"displayName","XAxis");I6(ws,"defaultProps",{allowDecimals:!0,hide:!1,orientation:"bottom",width:0,height:30,mirror:!1,xAxisId:0,tickCount:5,type:"category",padding:{left:0,right:0},allowDataOverflow:!1,scale:"auto",reversed:!1,allowDuplicatedCategory:!0});function ec(e){"@babel/helpers - typeof";return ec=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},ec(e)}function Jpe(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function eve(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,q6(r.key),r)}}function tve(e,t,n){return t&&eve(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e}function nve(e,t,n){return t=jp(t),rve(e,z6()?Reflect.construct(t,n||[],jp(e).constructor):t.apply(e,n))}function rve(e,t){if(t&&(ec(t)==="object"||typeof t=="function"))return t;if(t!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return ave(e)}function ave(e){if(e===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function z6(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(z6=function(){return!!e})()}function jp(e){return jp=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(n){return n.__proto__||Object.getPrototypeOf(n)},jp(e)}function ive(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&Nj(e,t)}function Nj(e,t){return Nj=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(r,i){return r.__proto__=i,r},Nj(e,t)}function B6(e,t,n){return t=q6(t),t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function q6(e){var t=ove(e,"string");return ec(t)=="symbol"?t:t+""}function ove(e,t){if(ec(e)!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(ec(r)!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}function Cj(){return Cj=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Cj.apply(this,arguments)}var sve=function(t){var n=t.yAxisId,r=zE(),i=BE(),o=j6(n);return o==null?null:S.createElement(Oc,Cj({},o,{className:et("recharts-".concat(o.axisType," ").concat(o.axisType),o.className),viewBox:{x:0,y:0,width:r,height:i},ticksGenerator:function(f){return Qa(f,!0)}}))},hi=(function(e){function t(){return Jpe(this,t),nve(this,t,arguments)}return ive(t,e),tve(t,[{key:"render",value:function(){return S.createElement(sve,this.props)}}])})(S.Component);B6(hi,"displayName","YAxis");B6(hi,"defaultProps",{allowDuplicatedCategory:!0,allowDecimals:!0,hide:!1,orientation:"left",width:60,height:0,mirror:!1,yAxisId:0,tickCount:5,type:"number",padding:{top:0,bottom:0},allowDataOverflow:!1,scale:"auto",reversed:!1});function P4(e){return fve(e)||uve(e)||cve(e)||lve()}function lve(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
124
124
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function cve(e,t){if(e){if(typeof e=="string")return Tj(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n==="Object"&&e.constructor&&(n=e.constructor.name),n==="Map"||n==="Set")return Array.from(e);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Tj(e,t)}}function uve(e){if(typeof Symbol<"u"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function fve(e){if(Array.isArray(e))return Tj(e)}function Tj(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var Mj=function(t,n,r,i,o){var l=Rr(t,UE),f=Rr(t,Gv),d=[].concat(P4(l),P4(f)),h=Rr(t,Yv),v="".concat(i,"Id"),m=i[0],g=n;if(d.length&&(g=d.reduce(function(j,b){if(b.props[v]===r&&Sa(b.props,"extendDomain")&&xe(b.props[m])){var E=b.props[m];return[Math.min(j[0],E),Math.max(j[1],E)]}return j},g)),h.length){var x="".concat(m,"1"),O="".concat(m,"2");g=h.reduce(function(j,b){if(b.props[v]===r&&Sa(b.props,"extendDomain")&&xe(b.props[x])&&xe(b.props[O])){var E=b.props[x],_=b.props[O];return[Math.min(j[0],E,_),Math.max(j[1],E,_)]}return j},g)}return o&&o.length&&(g=o.reduce(function(j,b){return xe(b)?[Math.min(j[0],b),Math.max(j[1],b)]:j},g)),g},P1={exports:{}},k4;function dve(){return k4||(k4=1,(function(e){var t=Object.prototype.hasOwnProperty,n="~";function r(){}Object.create&&(r.prototype=Object.create(null),new r().__proto__||(n=!1));function i(d,h,v){this.fn=d,this.context=h,this.once=v||!1}function o(d,h,v,m,g){if(typeof v!="function")throw new TypeError("The listener must be a function");var x=new i(v,m||d,g),O=n?n+h:h;return d._events[O]?d._events[O].fn?d._events[O]=[d._events[O],x]:d._events[O].push(x):(d._events[O]=x,d._eventsCount++),d}function l(d,h){--d._eventsCount===0?d._events=new r:delete d._events[h]}function f(){this._events=new r,this._eventsCount=0}f.prototype.eventNames=function(){var h=[],v,m;if(this._eventsCount===0)return h;for(m in v=this._events)t.call(v,m)&&h.push(n?m.slice(1):m);return Object.getOwnPropertySymbols?h.concat(Object.getOwnPropertySymbols(v)):h},f.prototype.listeners=function(h){var v=n?n+h:h,m=this._events[v];if(!m)return[];if(m.fn)return[m.fn];for(var g=0,x=m.length,O=new Array(x);g<x;g++)O[g]=m[g].fn;return O},f.prototype.listenerCount=function(h){var v=n?n+h:h,m=this._events[v];return m?m.fn?1:m.length:0},f.prototype.emit=function(h,v,m,g,x,O){var j=n?n+h:h;if(!this._events[j])return!1;var b=this._events[j],E=arguments.length,_,A;if(b.fn){switch(b.once&&this.removeListener(h,b.fn,void 0,!0),E){case 1:return b.fn.call(b.context),!0;case 2:return b.fn.call(b.context,v),!0;case 3:return b.fn.call(b.context,v,m),!0;case 4:return b.fn.call(b.context,v,m,g),!0;case 5:return b.fn.call(b.context,v,m,g,x),!0;case 6:return b.fn.call(b.context,v,m,g,x,O),!0}for(A=1,_=new Array(E-1);A<E;A++)_[A-1]=arguments[A];b.fn.apply(b.context,_)}else{var C=b.length,N;for(A=0;A<C;A++)switch(b[A].once&&this.removeListener(h,b[A].fn,void 0,!0),E){case 1:b[A].fn.call(b[A].context);break;case 2:b[A].fn.call(b[A].context,v);break;case 3:b[A].fn.call(b[A].context,v,m);break;case 4:b[A].fn.call(b[A].context,v,m,g);break;default:if(!_)for(N=1,_=new Array(E-1);N<E;N++)_[N-1]=arguments[N];b[A].fn.apply(b[A].context,_)}}return!0},f.prototype.on=function(h,v,m){return o(this,h,v,m,!1)},f.prototype.once=function(h,v,m){return o(this,h,v,m,!0)},f.prototype.removeListener=function(h,v,m,g){var x=n?n+h:h;if(!this._events[x])return this;if(!v)return l(this,x),this;var O=this._events[x];if(O.fn)O.fn===v&&(!g||O.once)&&(!m||O.context===m)&&l(this,x);else{for(var j=0,b=[],E=O.length;j<E;j++)(O[j].fn!==v||g&&!O[j].once||m&&O[j].context!==m)&&b.push(O[j]);b.length?this._events[x]=b.length===1?b[0]:b:l(this,x)}return this},f.prototype.removeAllListeners=function(h){var v;return h?(v=n?n+h:h,this._events[v]&&l(this,v)):(this._events=new r,this._eventsCount=0),this},f.prototype.off=f.prototype.removeListener,f.prototype.addListener=f.prototype.on,f.prefixed=n,f.EventEmitter=f,e.exports=f})(P1)),P1.exports}var hve=dve();const mve=xt(hve);var k1=new mve,$1="recharts.syncMouseEvents";function Df(e){"@babel/helpers - typeof";return Df=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Df(e)}function pve(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function vve(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,U6(r.key),r)}}function gve(e,t,n){return t&&vve(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e}function I1(e,t,n){return t=U6(t),t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function U6(e){var t=yve(e,"string");return Df(t)=="symbol"?t:t+""}function yve(e,t){if(Df(e)!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(Df(r)!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}var xve=(function(){function e(){pve(this,e),I1(this,"activeIndex",0),I1(this,"coordinateList",[]),I1(this,"layout","horizontal")}return gve(e,[{key:"setDetails",value:function(n){var r,i=n.coordinateList,o=i===void 0?null:i,l=n.container,f=l===void 0?null:l,d=n.layout,h=d===void 0?null:d,v=n.offset,m=v===void 0?null:v,g=n.mouseHandlerCallback,x=g===void 0?null:g;this.coordinateList=(r=o??this.coordinateList)!==null&&r!==void 0?r:[],this.container=f??this.container,this.layout=h??this.layout,this.offset=m??this.offset,this.mouseHandlerCallback=x??this.mouseHandlerCallback,this.activeIndex=Math.min(Math.max(this.activeIndex,0),this.coordinateList.length-1)}},{key:"focus",value:function(){this.spoofMouse()}},{key:"keyboardEvent",value:function(n){if(this.coordinateList.length!==0)switch(n.key){case"ArrowRight":{if(this.layout!=="horizontal")return;this.activeIndex=Math.min(this.activeIndex+1,this.coordinateList.length-1),this.spoofMouse();break}case"ArrowLeft":{if(this.layout!=="horizontal")return;this.activeIndex=Math.max(this.activeIndex-1,0),this.spoofMouse();break}}}},{key:"setIndex",value:function(n){this.activeIndex=n}},{key:"spoofMouse",value:function(){var n,r;if(this.layout==="horizontal"&&this.coordinateList.length!==0){var i=this.container.getBoundingClientRect(),o=i.x,l=i.y,f=i.height,d=this.coordinateList[this.activeIndex].coordinate,h=((n=window)===null||n===void 0?void 0:n.scrollX)||0,v=((r=window)===null||r===void 0?void 0:r.scrollY)||0,m=o+d+h,g=l+this.offset.top+f/2+v;this.mouseHandlerCallback({pageX:m,pageY:g})}}}])})();function bve(e,t,n){if(n==="number"&&t===!0&&Array.isArray(e)){var r=e?.[0],i=e?.[1];if(r&&i&&xe(r)&&xe(i))return!0}return!1}function wve(e,t,n,r){var i=r/2;return{stroke:"none",fill:"#ccc",x:e==="horizontal"?t.x-i:n.left+.5,y:e==="horizontal"?n.top+.5:t.y-i,width:e==="horizontal"?r:n.width-1,height:e==="horizontal"?n.height-1:r}}function H6(e){var t=e.cx,n=e.cy,r=e.radius,i=e.startAngle,o=e.endAngle,l=pn(t,n,r,i),f=pn(t,n,r,o);return{points:[l,f],cx:t,cy:n,radius:r,startAngle:i,endAngle:o}}function Sve(e,t,n){var r,i,o,l;if(e==="horizontal")r=t.x,o=r,i=n.top,l=n.top+n.height;else if(e==="vertical")i=t.y,l=i,r=n.left,o=n.left+n.width;else if(t.cx!=null&&t.cy!=null)if(e==="centric"){var f=t.cx,d=t.cy,h=t.innerRadius,v=t.outerRadius,m=t.angle,g=pn(f,d,h,m),x=pn(f,d,v,m);r=g.x,i=g.y,o=x.x,l=x.y}else return H6(t);return[{x:r,y:i},{x:o,y:l}]}function Pf(e){"@babel/helpers - typeof";return Pf=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Pf(e)}function $4(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),n.push.apply(n,r)}return n}function Uh(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?$4(Object(n),!0).forEach(function(r){jve(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):$4(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function jve(e,t,n){return t=Ove(t),t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Ove(e){var t=Eve(e,"string");return Pf(t)=="symbol"?t:t+""}function Eve(e,t){if(Pf(e)!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(Pf(r)!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function _ve(e){var t,n,r=e.element,i=e.tooltipEventType,o=e.isActive,l=e.activeCoordinate,f=e.activePayload,d=e.offset,h=e.activeTooltipIndex,v=e.tooltipAxisBandSize,m=e.layout,g=e.chartName,x=(t=r.props.cursor)!==null&&t!==void 0?t:(n=r.type.defaultProps)===null||n===void 0?void 0:n.cursor;if(!r||!x||!o||!l||g!=="ScatterChart"&&i!=="axis")return null;var O,j=nj;if(g==="ScatterChart")O=l,j=Ode;else if(g==="BarChart")O=wve(m,l,d,v),j=PE;else if(m==="radial"){var b=H6(l),E=b.cx,_=b.cy,A=b.radius,C=b.startAngle,N=b.endAngle;O={cx:E,cy:_,startAngle:C,endAngle:N,innerRadius:A,outerRadius:A},j=QB}else O={points:Sve(m,l,d)},j=nj;var M=Uh(Uh(Uh(Uh({stroke:"#ccc",pointerEvents:"none"},d),O),nt(x,!1)),{},{payload:f,payloadIndex:h,className:et("recharts-tooltip-cursor",x.className)});return S.isValidElement(x)?S.cloneElement(x,M):S.createElement(j,M)}var Ave=["item"],Nve=["children","className","width","height","style","compact","title","desc"];function tc(e){"@babel/helpers - typeof";return tc=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},tc(e)}function bl(){return bl=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},bl.apply(this,arguments)}function I4(e,t){return Mve(e)||Tve(e,t)||G6(e,t)||Cve()}function Cve(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
125
125
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Tve(e,t){var n=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(n!=null){var r,i,o,l,f=[],d=!0,h=!1;try{if(o=(n=n.call(e)).next,t!==0)for(;!(d=(r=o.call(n)).done)&&(f.push(r.value),f.length!==t);d=!0);}catch(v){h=!0,i=v}finally{try{if(!d&&n.return!=null&&(l=n.return(),Object(l)!==l))return}finally{if(h)throw i}}return f}}function Mve(e){if(Array.isArray(e))return e}function L4(e,t){if(e==null)return{};var n=Rve(e,t),r,i;if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(i=0;i<o.length;i++)r=o[i],!(t.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}function Rve(e,t){if(e==null)return{};var n={};for(var r in e)if(Object.prototype.hasOwnProperty.call(e,r)){if(t.indexOf(r)>=0)continue;n[r]=e[r]}return n}function Dve(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Pve(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,V6(r.key),r)}}function kve(e,t,n){return t&&Pve(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e}function $ve(e,t,n){return t=Op(t),Ive(e,F6()?Reflect.construct(t,n||[],Op(e).constructor):t.apply(e,n))}function Ive(e,t){if(t&&(tc(t)==="object"||typeof t=="function"))return t;if(t!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return Lve(e)}function Lve(e){if(e===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function F6(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(F6=function(){return!!e})()}function Op(e){return Op=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(n){return n.__proto__||Object.getPrototypeOf(n)},Op(e)}function zve(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&Rj(e,t)}function Rj(e,t){return Rj=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(r,i){return r.__proto__=i,r},Rj(e,t)}function nc(e){return Uve(e)||qve(e)||G6(e)||Bve()}function Bve(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
126
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function G6(e,t){if(e){if(typeof e=="string")return Dj(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n==="Object"&&e.constructor&&(n=e.constructor.name),n==="Map"||n==="Set")return Array.from(e);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Dj(e,t)}}function qve(e){if(typeof Symbol<"u"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function Uve(e){if(Array.isArray(e))return Dj(e)}function Dj(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function z4(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),n.push.apply(n,r)}return n}function fe(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?z4(Object(n),!0).forEach(function(r){ke(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):z4(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function ke(e,t,n){return t=V6(t),t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function V6(e){var t=Hve(e,"string");return tc(t)=="symbol"?t:t+""}function Hve(e,t){if(tc(e)!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(tc(r)!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}var Fve={xAxis:["bottom","top"],yAxis:["left","right"]},Gve={width:"100%",height:"100%"},Y6={x:0,y:0};function Hh(e){return e}var Vve=function(t,n){return n==="horizontal"?t.x:n==="vertical"?t.y:n==="centric"?t.angle:t.radius},Yve=function(t,n,r,i){var o=n.find(function(v){return v&&v.index===r});if(o){if(t==="horizontal")return{x:o.coordinate,y:i.y};if(t==="vertical")return{x:i.x,y:o.coordinate};if(t==="centric"){var l=o.coordinate,f=i.radius;return fe(fe(fe({},i),pn(i.cx,i.cy,f,l)),{},{angle:l,radius:f})}var d=o.coordinate,h=i.angle;return fe(fe(fe({},i),pn(i.cx,i.cy,d,h)),{},{angle:h,radius:d})}return Y6},Kv=function(t,n){var r=n.graphicalItems,i=n.dataStartIndex,o=n.dataEndIndex,l=(r??[]).reduce(function(f,d){var h=d.props.data;return h&&h.length?[].concat(nc(f),nc(h)):f},[]);return l.length>0?l:t&&t.length&&xe(i)&&xe(o)?t.slice(i,o+1):[]};function W6(e){return e==="number"?[0,"auto"]:void 0}var Pj=function(t,n,r,i){var o=t.graphicalItems,l=t.tooltipAxis,f=Kv(n,t);return r<0||!o||!o.length||r>=f.length?null:o.reduce(function(d,h){var v,m=(v=h.props.data)!==null&&v!==void 0?v:n;m&&t.dataStartIndex+t.dataEndIndex!==0&&t.dataEndIndex-t.dataStartIndex>=r&&(m=m.slice(t.dataStartIndex,t.dataEndIndex+1));var g;if(l.dataKey&&!l.allowDuplicatedCategory){var x=m===void 0?f:m;g=Nm(x,l.dataKey,i)}else g=m&&m[r]||f[r];return g?[].concat(nc(d),[WB(h,g)]):d},[])},B4=function(t,n,r,i){var o=i||{x:t.chartX,y:t.chartY},l=Vve(o,r),f=t.orderedTooltipTicks,d=t.tooltipAxis,h=t.tooltipTicks,v=rce(l,f,h,d);if(v>=0&&h){var m=h[v]&&h[v].value,g=Pj(t,n,v,m),x=Yve(r,f,v,o);return{activeTooltipIndex:v,activeLabel:m,activePayload:g,activeCoordinate:x}}return null},Wve=function(t,n){var r=n.axes,i=n.graphicalItems,o=n.axisType,l=n.axisIdKey,f=n.stackGroups,d=n.dataStartIndex,h=n.dataEndIndex,v=t.layout,m=t.children,g=t.stackOffset,x=GB(v,o);return r.reduce(function(O,j){var b,E=j.type.defaultProps!==void 0?fe(fe({},j.type.defaultProps),j.props):j.props,_=E.type,A=E.dataKey,C=E.allowDataOverflow,N=E.allowDuplicatedCategory,M=E.scale,R=E.ticks,D=E.includeHidden,L=E[l];if(O[L])return O;var H=Kv(t.data,{graphicalItems:i.filter(function(G){var $,W=l in G.props?G.props[l]:($=G.type.defaultProps)===null||$===void 0?void 0:$[l];return W===L}),dataStartIndex:d,dataEndIndex:h}),B=H.length,U,Y,Z;bve(E.domain,C,_)&&(U=QS(E.domain,null,C),x&&(_==="number"||M!=="auto")&&(Z=Lu(H,A,"category")));var X=W6(_);if(!U||U.length===0){var k,q=(k=E.domain)!==null&&k!==void 0?k:X;if(A){if(U=Lu(H,A,_),_==="category"&&x){var V=Wee(U);N&&V?(Y=U,U=fp(0,B)):N||(U=ek(q,U,j).reduce(function(G,$){return G.indexOf($)>=0?G:[].concat(nc(G),[$])},[]))}else if(_==="category")N?U=U.filter(function(G){return G!==""&&!Qe(G)}):U=ek(q,U,j).reduce(function(G,$){return G.indexOf($)>=0||$===""||Qe($)?G:[].concat(nc(G),[$])},[]);else if(_==="number"){var Q=lce(H,i.filter(function(G){var $,W,ae=l in G.props?G.props[l]:($=G.type.defaultProps)===null||$===void 0?void 0:$[l],ce="hide"in G.props?G.props.hide:(W=G.type.defaultProps)===null||W===void 0?void 0:W.hide;return ae===L&&(D||!ce)}),A,o,v);Q&&(U=Q)}x&&(_==="number"||M!=="auto")&&(Z=Lu(H,A,"category"))}else x?U=fp(0,B):f&&f[L]&&f[L].hasStack&&_==="number"?U=g==="expand"?[0,1]:YB(f[L].stackGroups,d,h):U=FB(H,i.filter(function(G){var $=l in G.props?G.props[l]:G.type.defaultProps[l],W="hide"in G.props?G.props.hide:G.type.defaultProps.hide;return $===L&&(D||!W)}),_,v,!0);if(_==="number")U=Mj(m,U,L,o,R),q&&(U=QS(q,U,C));else if(_==="category"&&q){var ee=q,z=U.every(function(G){return ee.indexOf(G)>=0});z&&(U=ee)}}return fe(fe({},O),{},ke({},L,fe(fe({},E),{},{axisType:o,domain:U,categoricalDomain:Z,duplicateDomain:Y,originalDomain:(b=E.domain)!==null&&b!==void 0?b:X,isCategorical:x,layout:v})))},{})},Kve=function(t,n){var r=n.graphicalItems,i=n.Axis,o=n.axisType,l=n.axisIdKey,f=n.stackGroups,d=n.dataStartIndex,h=n.dataEndIndex,v=t.layout,m=t.children,g=Kv(t.data,{graphicalItems:r,dataStartIndex:d,dataEndIndex:h}),x=g.length,O=GB(v,o),j=-1;return r.reduce(function(b,E){var _=E.type.defaultProps!==void 0?fe(fe({},E.type.defaultProps),E.props):E.props,A=_[l],C=W6("number");if(!b[A]){j++;var N;return O?N=fp(0,x):f&&f[A]&&f[A].hasStack?(N=YB(f[A].stackGroups,d,h),N=Mj(m,N,A,o)):(N=QS(C,FB(g,r.filter(function(M){var R,D,L=l in M.props?M.props[l]:(R=M.type.defaultProps)===null||R===void 0?void 0:R[l],H="hide"in M.props?M.props.hide:(D=M.type.defaultProps)===null||D===void 0?void 0:D.hide;return L===A&&!H}),"number",v),i.defaultProps.allowDataOverflow),N=Mj(m,N,A,o)),fe(fe({},b),{},ke({},A,fe(fe({axisType:o},i.defaultProps),{},{hide:!0,orientation:Mr(Fve,"".concat(o,".").concat(j%2),null),domain:N,originalDomain:C,isCategorical:O,layout:v})))}return b},{})},Xve=function(t,n){var r=n.axisType,i=r===void 0?"xAxis":r,o=n.AxisComp,l=n.graphicalItems,f=n.stackGroups,d=n.dataStartIndex,h=n.dataEndIndex,v=t.children,m="".concat(i,"Id"),g=Rr(v,o),x={};return g&&g.length?x=Wve(t,{axes:g,graphicalItems:l,axisType:i,axisIdKey:m,stackGroups:f,dataStartIndex:d,dataEndIndex:h}):l&&l.length&&(x=Kve(t,{Axis:o,graphicalItems:l,axisType:i,axisIdKey:m,stackGroups:f,dataStartIndex:d,dataEndIndex:h})),x},Qve=function(t){var n=Ki(t),r=Qa(n,!1,!0);return{tooltipTicks:r,orderedTooltipTicks:oE(r,function(i){return i.coordinate}),tooltipAxis:n,tooltipAxisBandSize:tp(n,r)}},q4=function(t){var n=t.children,r=t.defaultShowTooltip,i=rr(n,Vl),o=0,l=0;return t.data&&t.data.length!==0&&(l=t.data.length-1),i&&i.props&&(i.props.startIndex>=0&&(o=i.props.startIndex),i.props.endIndex>=0&&(l=i.props.endIndex)),{chartX:0,chartY:0,dataStartIndex:o,dataEndIndex:l,activeTooltipIndex:-1,isTooltipActive:!!r}},Zve=function(t){return!t||!t.length?!1:t.some(function(n){var r=ei(n&&n.type);return r&&r.indexOf("Bar")>=0})},U4=function(t){return t==="horizontal"?{numericAxisName:"yAxis",cateAxisName:"xAxis"}:t==="vertical"?{numericAxisName:"xAxis",cateAxisName:"yAxis"}:t==="centric"?{numericAxisName:"radiusAxis",cateAxisName:"angleAxis"}:{numericAxisName:"angleAxis",cateAxisName:"radiusAxis"}},Jve=function(t,n){var r=t.props,i=t.graphicalItems,o=t.xAxisMap,l=o===void 0?{}:o,f=t.yAxisMap,d=f===void 0?{}:f,h=r.width,v=r.height,m=r.children,g=r.margin||{},x=rr(m,Vl),O=rr(m,ni),j=Object.keys(d).reduce(function(N,M){var R=d[M],D=R.orientation;return!R.mirror&&!R.hide?fe(fe({},N),{},ke({},D,N[D]+R.width)):N},{left:g.left||0,right:g.right||0}),b=Object.keys(l).reduce(function(N,M){var R=l[M],D=R.orientation;return!R.mirror&&!R.hide?fe(fe({},N),{},ke({},D,Mr(N,"".concat(D))+R.height)):N},{top:g.top||0,bottom:g.bottom||0}),E=fe(fe({},b),j),_=E.bottom;x&&(E.bottom+=x.props.height||Vl.defaultProps.height),O&&n&&(E=oce(E,i,r,n));var A=h-E.left-E.right,C=v-E.top-E.bottom;return fe(fe({brushBottom:_},E),{},{width:Math.max(A,0),height:Math.max(C,0)})},ege=function(t,n){if(n==="xAxis")return t[n].width;if(n==="yAxis")return t[n].height},K6=function(t){var n=t.chartName,r=t.GraphicalChild,i=t.defaultTooltipEventType,o=i===void 0?"axis":i,l=t.validateTooltipEventTypes,f=l===void 0?["axis"]:l,d=t.axisComponents,h=t.legendContent,v=t.formatAxisMap,m=t.defaultProps,g=function(E,_){var A=_.graphicalItems,C=_.stackGroups,N=_.offset,M=_.updateId,R=_.dataStartIndex,D=_.dataEndIndex,L=E.barSize,H=E.layout,B=E.barGap,U=E.barCategoryGap,Y=E.maxBarSize,Z=U4(H),X=Z.numericAxisName,k=Z.cateAxisName,q=Zve(A),V=[];return A.forEach(function(Q,ee){var z=Kv(E.data,{graphicalItems:[Q],dataStartIndex:R,dataEndIndex:D}),G=Q.type.defaultProps!==void 0?fe(fe({},Q.type.defaultProps),Q.props):Q.props,$=G.dataKey,W=G.maxBarSize,ae=G["".concat(X,"Id")],ce=G["".concat(k,"Id")],oe={},me=d.reduce(function(Yn,Rt){var dr=_["".concat(Rt.axisType,"Map")],tn=G["".concat(Rt.axisType,"Id")];dr&&dr[tn]||Rt.axisType==="zAxis"||ss();var Ss=dr[tn];return fe(fe({},Yn),{},ke(ke({},Rt.axisType,Ss),"".concat(Rt.axisType,"Ticks"),Qa(Ss)))},oe),ie=me[k],ve=me["".concat(k,"Ticks")],ye=C&&C[ae]&&C[ae].hasStack&&bce(Q,C[ae].stackGroups),le=ei(Q.type).indexOf("Bar")>=0,Re=tp(ie,ve),be=[],qe=q&&ace({barSize:L,stackGroups:C,totalSize:ege(me,k)});if(le){var rt,mt,vn=Qe(W)?Y:W,Mt=(rt=(mt=tp(ie,ve,!0))!==null&&mt!==void 0?mt:vn)!==null&&rt!==void 0?rt:0;be=ice({barGap:B,barCategoryGap:U,bandSize:Mt!==Re?Mt:Re,sizeList:qe[ce],maxBarSize:vn}),Mt!==Re&&(be=be.map(function(Yn){return fe(fe({},Yn),{},{position:fe(fe({},Yn.position),{},{offset:Yn.position.offset-Mt/2})})}))}var fr=Q&&Q.type&&Q.type.getComposedData;fr&&V.push({props:fe(fe({},fr(fe(fe({},me),{},{displayedData:z,props:E,dataKey:$,item:Q,bandSize:Re,barPosition:be,offset:N,stackedData:ye,layout:H,dataStartIndex:R,dataEndIndex:D}))),{},ke(ke(ke({key:Q.key||"item-".concat(ee)},X,me[X]),k,me[k]),"animationId",M)),childIndex:ste(Q,E.children),item:Q})}),V},x=function(E,_){var A=E.props,C=E.dataStartIndex,N=E.dataEndIndex,M=E.updateId;if(!mM({props:A}))return null;var R=A.children,D=A.layout,L=A.stackOffset,H=A.data,B=A.reverseStackOrder,U=U4(D),Y=U.numericAxisName,Z=U.cateAxisName,X=Rr(R,r),k=gce(H,X,"".concat(Y,"Id"),"".concat(Z,"Id"),L,B),q=d.reduce(function(G,$){var W="".concat($.axisType,"Map");return fe(fe({},G),{},ke({},W,Xve(A,fe(fe({},$),{},{graphicalItems:X,stackGroups:$.axisType===Y&&k,dataStartIndex:C,dataEndIndex:N}))))},{}),V=Jve(fe(fe({},q),{},{props:A,graphicalItems:X}),_?.legendBBox);Object.keys(q).forEach(function(G){q[G]=v(A,q[G],V,G.replace("Map",""),n)});var Q=q["".concat(Z,"Map")],ee=Qve(Q),z=g(A,fe(fe({},q),{},{dataStartIndex:C,dataEndIndex:N,updateId:M,graphicalItems:X,stackGroups:k,offset:V}));return fe(fe({formattedGraphicalItems:z,graphicalItems:X,offset:V,stackGroups:k},ee),q)},O=(function(b){function E(_){var A,C,N;return Dve(this,E),N=$ve(this,E,[_]),ke(N,"eventEmitterSymbol",Symbol("rechartsEventEmitter")),ke(N,"accessibilityManager",new xve),ke(N,"handleLegendBBoxUpdate",function(M){if(M){var R=N.state,D=R.dataStartIndex,L=R.dataEndIndex,H=R.updateId;N.setState(fe({legendBBox:M},x({props:N.props,dataStartIndex:D,dataEndIndex:L,updateId:H},fe(fe({},N.state),{},{legendBBox:M}))))}}),ke(N,"handleReceiveSyncEvent",function(M,R,D){if(N.props.syncId===M){if(D===N.eventEmitterSymbol&&typeof N.props.syncMethod!="function")return;N.applySyncEvent(R)}}),ke(N,"handleBrushChange",function(M){var R=M.startIndex,D=M.endIndex;if(R!==N.state.dataStartIndex||D!==N.state.dataEndIndex){var L=N.state.updateId;N.setState(function(){return fe({dataStartIndex:R,dataEndIndex:D},x({props:N.props,dataStartIndex:R,dataEndIndex:D,updateId:L},N.state))}),N.triggerSyncEvent({dataStartIndex:R,dataEndIndex:D})}}),ke(N,"handleMouseEnter",function(M){var R=N.getMouseInfo(M);if(R){var D=fe(fe({},R),{},{isTooltipActive:!0});N.setState(D),N.triggerSyncEvent(D);var L=N.props.onMouseEnter;Ye(L)&&L(D,M)}}),ke(N,"triggeredAfterMouseMove",function(M){var R=N.getMouseInfo(M),D=R?fe(fe({},R),{},{isTooltipActive:!0}):{isTooltipActive:!1};N.setState(D),N.triggerSyncEvent(D);var L=N.props.onMouseMove;Ye(L)&&L(D,M)}),ke(N,"handleItemMouseEnter",function(M){N.setState(function(){return{isTooltipActive:!0,activeItem:M,activePayload:M.tooltipPayload,activeCoordinate:M.tooltipPosition||{x:M.cx,y:M.cy}}})}),ke(N,"handleItemMouseLeave",function(){N.setState(function(){return{isTooltipActive:!1}})}),ke(N,"handleMouseMove",function(M){M.persist(),N.throttleTriggeredAfterMouseMove(M)}),ke(N,"handleMouseLeave",function(M){N.throttleTriggeredAfterMouseMove.cancel();var R={isTooltipActive:!1};N.setState(R),N.triggerSyncEvent(R);var D=N.props.onMouseLeave;Ye(D)&&D(R,M)}),ke(N,"handleOuterEvent",function(M){var R=ote(M),D=Mr(N.props,"".concat(R));if(R&&Ye(D)){var L,H;/.*touch.*/i.test(R)?H=N.getMouseInfo(M.changedTouches[0]):H=N.getMouseInfo(M),D((L=H)!==null&&L!==void 0?L:{},M)}}),ke(N,"handleClick",function(M){var R=N.getMouseInfo(M);if(R){var D=fe(fe({},R),{},{isTooltipActive:!0});N.setState(D),N.triggerSyncEvent(D);var L=N.props.onClick;Ye(L)&&L(D,M)}}),ke(N,"handleMouseDown",function(M){var R=N.props.onMouseDown;if(Ye(R)){var D=N.getMouseInfo(M);R(D,M)}}),ke(N,"handleMouseUp",function(M){var R=N.props.onMouseUp;if(Ye(R)){var D=N.getMouseInfo(M);R(D,M)}}),ke(N,"handleTouchMove",function(M){M.changedTouches!=null&&M.changedTouches.length>0&&N.throttleTriggeredAfterMouseMove(M.changedTouches[0])}),ke(N,"handleTouchStart",function(M){M.changedTouches!=null&&M.changedTouches.length>0&&N.handleMouseDown(M.changedTouches[0])}),ke(N,"handleTouchEnd",function(M){M.changedTouches!=null&&M.changedTouches.length>0&&N.handleMouseUp(M.changedTouches[0])}),ke(N,"handleDoubleClick",function(M){var R=N.props.onDoubleClick;if(Ye(R)){var D=N.getMouseInfo(M);R(D,M)}}),ke(N,"handleContextMenu",function(M){var R=N.props.onContextMenu;if(Ye(R)){var D=N.getMouseInfo(M);R(D,M)}}),ke(N,"triggerSyncEvent",function(M){N.props.syncId!==void 0&&k1.emit($1,N.props.syncId,M,N.eventEmitterSymbol)}),ke(N,"applySyncEvent",function(M){var R=N.props,D=R.layout,L=R.syncMethod,H=N.state.updateId,B=M.dataStartIndex,U=M.dataEndIndex;if(M.dataStartIndex!==void 0||M.dataEndIndex!==void 0)N.setState(fe({dataStartIndex:B,dataEndIndex:U},x({props:N.props,dataStartIndex:B,dataEndIndex:U,updateId:H},N.state)));else if(M.activeTooltipIndex!==void 0){var Y=M.chartX,Z=M.chartY,X=M.activeTooltipIndex,k=N.state,q=k.offset,V=k.tooltipTicks;if(!q)return;if(typeof L=="function")X=L(V,M);else if(L==="value"){X=-1;for(var Q=0;Q<V.length;Q++)if(V[Q].value===M.activeLabel){X=Q;break}}var ee=fe(fe({},q),{},{x:q.left,y:q.top}),z=Math.min(Y,ee.x+ee.width),G=Math.min(Z,ee.y+ee.height),$=V[X]&&V[X].value,W=Pj(N.state,N.props.data,X),ae=V[X]?{x:D==="horizontal"?V[X].coordinate:z,y:D==="horizontal"?G:V[X].coordinate}:Y6;N.setState(fe(fe({},M),{},{activeLabel:$,activeCoordinate:ae,activePayload:W,activeTooltipIndex:X}))}else N.setState(M)}),ke(N,"renderCursor",function(M){var R,D=N.state,L=D.isTooltipActive,H=D.activeCoordinate,B=D.activePayload,U=D.offset,Y=D.activeTooltipIndex,Z=D.tooltipAxisBandSize,X=N.getTooltipEventType(),k=(R=M.props.active)!==null&&R!==void 0?R:L,q=N.props.layout,V=M.key||"_recharts-cursor";return I.createElement(_ve,{key:V,activeCoordinate:H,activePayload:B,activeTooltipIndex:Y,chartName:n,element:M,isActive:k,layout:q,offset:U,tooltipAxisBandSize:Z,tooltipEventType:X})}),ke(N,"renderPolarAxis",function(M,R,D){var L=Mr(M,"type.axisType"),H=Mr(N.state,"".concat(L,"Map")),B=M.type.defaultProps,U=B!==void 0?fe(fe({},B),M.props):M.props,Y=H&&H[U["".concat(L,"Id")]];return S.cloneElement(M,fe(fe({},Y),{},{className:et(L,Y.className),key:M.key||"".concat(R,"-").concat(D),ticks:Qa(Y,!0)}))}),ke(N,"renderPolarGrid",function(M){var R=M.props,D=R.radialLines,L=R.polarAngles,H=R.polarRadius,B=N.state,U=B.radiusAxisMap,Y=B.angleAxisMap,Z=Ki(U),X=Ki(Y),k=X.cx,q=X.cy,V=X.innerRadius,Q=X.outerRadius;return S.cloneElement(M,{polarAngles:Array.isArray(L)?L:Qa(X,!0).map(function(ee){return ee.coordinate}),polarRadius:Array.isArray(H)?H:Qa(Z,!0).map(function(ee){return ee.coordinate}),cx:k,cy:q,innerRadius:V,outerRadius:Q,key:M.key||"polar-grid",radialLines:D})}),ke(N,"renderLegend",function(){var M=N.state.formattedGraphicalItems,R=N.props,D=R.children,L=R.width,H=R.height,B=N.props.margin||{},U=L-(B.left||0)-(B.right||0),Y=UB({children:D,formattedGraphicalItems:M,legendWidth:U,legendContent:h});if(!Y)return null;var Z=Y.item,X=L4(Y,Ave);return S.cloneElement(Z,fe(fe({},X),{},{chartWidth:L,chartHeight:H,margin:B,onBBoxUpdate:N.handleLegendBBoxUpdate}))}),ke(N,"renderTooltip",function(){var M,R=N.props,D=R.children,L=R.accessibilityLayer,H=rr(D,_r);if(!H)return null;var B=N.state,U=B.isTooltipActive,Y=B.activeCoordinate,Z=B.activePayload,X=B.activeLabel,k=B.offset,q=(M=H.props.active)!==null&&M!==void 0?M:U;return S.cloneElement(H,{viewBox:fe(fe({},k),{},{x:k.left,y:k.top}),active:q,label:X,payload:q?Z:[],coordinate:Y,accessibilityLayer:L})}),ke(N,"renderBrush",function(M){var R=N.props,D=R.margin,L=R.data,H=N.state,B=H.offset,U=H.dataStartIndex,Y=H.dataEndIndex,Z=H.updateId;return S.cloneElement(M,{key:M.key||"_recharts-brush",onChange:Lh(N.handleBrushChange,M.props.onChange),data:L,x:xe(M.props.x)?M.props.x:B.left,y:xe(M.props.y)?M.props.y:B.top+B.height+B.brushBottom-(D.bottom||0),width:xe(M.props.width)?M.props.width:B.width,startIndex:U,endIndex:Y,updateId:"brush-".concat(Z)})}),ke(N,"renderReferenceElement",function(M,R,D){if(!M)return null;var L=N,H=L.clipPathId,B=N.state,U=B.xAxisMap,Y=B.yAxisMap,Z=B.offset,X=M.type.defaultProps||{},k=M.props,q=k.xAxisId,V=q===void 0?X.xAxisId:q,Q=k.yAxisId,ee=Q===void 0?X.yAxisId:Q;return S.cloneElement(M,{key:M.key||"".concat(R,"-").concat(D),xAxis:U[V],yAxis:Y[ee],viewBox:{x:Z.left,y:Z.top,width:Z.width,height:Z.height},clipPathId:H})}),ke(N,"renderActivePoints",function(M){var R=M.item,D=M.activePoint,L=M.basePoint,H=M.childIndex,B=M.isRange,U=[],Y=R.props.key,Z=R.item.type.defaultProps!==void 0?fe(fe({},R.item.type.defaultProps),R.item.props):R.item.props,X=Z.activeDot,k=Z.dataKey,q=fe(fe({index:H,dataKey:k,cx:D.x,cy:D.y,r:4,fill:DE(R.item),strokeWidth:2,stroke:"#fff",payload:D.payload,value:D.value},nt(X,!1)),Cm(X));return U.push(E.renderActiveDot(X,q,"".concat(Y,"-activePoint-").concat(H))),L?U.push(E.renderActiveDot(X,fe(fe({},q),{},{cx:L.x,cy:L.y}),"".concat(Y,"-basePoint-").concat(H))):B&&U.push(null),U}),ke(N,"renderGraphicChild",function(M,R,D){var L=N.filterFormatItem(M,R,D);if(!L)return null;var H=N.getTooltipEventType(),B=N.state,U=B.isTooltipActive,Y=B.tooltipAxis,Z=B.activeTooltipIndex,X=B.activeLabel,k=N.props.children,q=rr(k,_r),V=L.props,Q=V.points,ee=V.isRange,z=V.baseLine,G=L.item.type.defaultProps!==void 0?fe(fe({},L.item.type.defaultProps),L.item.props):L.item.props,$=G.activeDot,W=G.hide,ae=G.activeBar,ce=G.activeShape,oe=!!(!W&&U&&q&&($||ae||ce)),me={};H!=="axis"&&q&&q.props.trigger==="click"?me={onClick:Lh(N.handleItemMouseEnter,M.props.onClick)}:H!=="axis"&&(me={onMouseLeave:Lh(N.handleItemMouseLeave,M.props.onMouseLeave),onMouseEnter:Lh(N.handleItemMouseEnter,M.props.onMouseEnter)});var ie=S.cloneElement(M,fe(fe({},L.props),me));function ve(Rt){return typeof Y.dataKey=="function"?Y.dataKey(Rt.payload):null}if(oe)if(Z>=0){var ye,le;if(Y.dataKey&&!Y.allowDuplicatedCategory){var Re=typeof Y.dataKey=="function"?ve:"payload.".concat(Y.dataKey.toString());ye=Nm(Q,Re,X),le=ee&&z&&Nm(z,Re,X)}else ye=Q?.[Z],le=ee&&z&&z[Z];if(ce||ae){var be=M.props.activeIndex!==void 0?M.props.activeIndex:Z;return[S.cloneElement(M,fe(fe(fe({},L.props),me),{},{activeIndex:be})),null,null]}if(!Qe(ye))return[ie].concat(nc(N.renderActivePoints({item:L,activePoint:ye,basePoint:le,childIndex:Z,isRange:ee})))}else{var qe,rt=(qe=N.getItemByXY(N.state.activeCoordinate))!==null&&qe!==void 0?qe:{graphicalItem:ie},mt=rt.graphicalItem,vn=mt.item,Mt=vn===void 0?M:vn,fr=mt.childIndex,Yn=fe(fe(fe({},L.props),me),{},{activeIndex:fr});return[S.cloneElement(Mt,Yn),null,null]}return ee?[ie,null,null]:[ie,null]}),ke(N,"renderCustomized",function(M,R,D){return S.cloneElement(M,fe(fe({key:"recharts-customized-".concat(D)},N.props),N.state))}),ke(N,"renderMap",{CartesianGrid:{handler:Hh,once:!0},ReferenceArea:{handler:N.renderReferenceElement},ReferenceLine:{handler:Hh},ReferenceDot:{handler:N.renderReferenceElement},XAxis:{handler:Hh},YAxis:{handler:Hh},Brush:{handler:N.renderBrush,once:!0},Bar:{handler:N.renderGraphicChild},Line:{handler:N.renderGraphicChild},Area:{handler:N.renderGraphicChild},Radar:{handler:N.renderGraphicChild},RadialBar:{handler:N.renderGraphicChild},Scatter:{handler:N.renderGraphicChild},Pie:{handler:N.renderGraphicChild},Funnel:{handler:N.renderGraphicChild},Tooltip:{handler:N.renderCursor,once:!0},PolarGrid:{handler:N.renderPolarGrid,once:!0},PolarAngleAxis:{handler:N.renderPolarAxis},PolarRadiusAxis:{handler:N.renderPolarAxis},Customized:{handler:N.renderCustomized}}),N.clipPathId="".concat((A=_.id)!==null&&A!==void 0?A:Xf("recharts"),"-clip"),N.throttleTriggeredAfterMouseMove=qz(N.triggeredAfterMouseMove,(C=_.throttleDelay)!==null&&C!==void 0?C:1e3/60),N.state={},N}return zve(E,b),kve(E,[{key:"componentDidMount",value:function(){var A,C;this.addListener(),this.accessibilityManager.setDetails({container:this.container,offset:{left:(A=this.props.margin.left)!==null&&A!==void 0?A:0,top:(C=this.props.margin.top)!==null&&C!==void 0?C:0},coordinateList:this.state.tooltipTicks,mouseHandlerCallback:this.triggeredAfterMouseMove,layout:this.props.layout}),this.displayDefaultTooltip()}},{key:"displayDefaultTooltip",value:function(){var A=this.props,C=A.children,N=A.data,M=A.height,R=A.layout,D=rr(C,_r);if(D){var L=D.props.defaultIndex;if(!(typeof L!="number"||L<0||L>this.state.tooltipTicks.length-1)){var H=this.state.tooltipTicks[L]&&this.state.tooltipTicks[L].value,B=Pj(this.state,N,L,H),U=this.state.tooltipTicks[L].coordinate,Y=(this.state.offset.top+M)/2,Z=R==="horizontal",X=Z?{x:U,y:Y}:{y:U,x:Y},k=this.state.formattedGraphicalItems.find(function(V){var Q=V.item;return Q.type.name==="Scatter"});k&&(X=fe(fe({},X),k.props.points[L].tooltipPosition),B=k.props.points[L].tooltipPayload);var q={activeTooltipIndex:L,isTooltipActive:!0,activeLabel:H,activePayload:B,activeCoordinate:X};this.setState(q),this.renderCursor(D),this.accessibilityManager.setIndex(L)}}}},{key:"getSnapshotBeforeUpdate",value:function(A,C){if(!this.props.accessibilityLayer)return null;if(this.state.tooltipTicks!==C.tooltipTicks&&this.accessibilityManager.setDetails({coordinateList:this.state.tooltipTicks}),this.props.layout!==A.layout&&this.accessibilityManager.setDetails({layout:this.props.layout}),this.props.margin!==A.margin){var N,M;this.accessibilityManager.setDetails({offset:{left:(N=this.props.margin.left)!==null&&N!==void 0?N:0,top:(M=this.props.margin.top)!==null&&M!==void 0?M:0}})}return null}},{key:"componentDidUpdate",value:function(A){xS([rr(A.children,_r)],[rr(this.props.children,_r)])||this.displayDefaultTooltip()}},{key:"componentWillUnmount",value:function(){this.removeListener(),this.throttleTriggeredAfterMouseMove.cancel()}},{key:"getTooltipEventType",value:function(){var A=rr(this.props.children,_r);if(A&&typeof A.props.shared=="boolean"){var C=A.props.shared?"axis":"item";return f.indexOf(C)>=0?C:o}return o}},{key:"getMouseInfo",value:function(A){if(!this.container)return null;var C=this.container,N=C.getBoundingClientRect(),M=Yae(N),R={chartX:Math.round(A.pageX-M.left),chartY:Math.round(A.pageY-M.top)},D=N.width/C.offsetWidth||1,L=this.inRange(R.chartX,R.chartY,D);if(!L)return null;var H=this.state,B=H.xAxisMap,U=H.yAxisMap,Y=this.getTooltipEventType(),Z=B4(this.state,this.props.data,this.props.layout,L);if(Y!=="axis"&&B&&U){var X=Ki(B).scale,k=Ki(U).scale,q=X&&X.invert?X.invert(R.chartX):null,V=k&&k.invert?k.invert(R.chartY):null;return fe(fe({},R),{},{xValue:q,yValue:V},Z)}return Z?fe(fe({},R),Z):null}},{key:"inRange",value:function(A,C){var N=arguments.length>2&&arguments[2]!==void 0?arguments[2]:1,M=this.props.layout,R=A/N,D=C/N;if(M==="horizontal"||M==="vertical"){var L=this.state.offset,H=R>=L.left&&R<=L.left+L.width&&D>=L.top&&D<=L.top+L.height;return H?{x:R,y:D}:null}var B=this.state,U=B.angleAxisMap,Y=B.radiusAxisMap;if(U&&Y){var Z=Ki(U);return rk({x:R,y:D},Z)}return null}},{key:"parseEventsOfWrapper",value:function(){var A=this.props.children,C=this.getTooltipEventType(),N=rr(A,_r),M={};N&&C==="axis"&&(N.props.trigger==="click"?M={onClick:this.handleClick}:M={onMouseEnter:this.handleMouseEnter,onDoubleClick:this.handleDoubleClick,onMouseMove:this.handleMouseMove,onMouseLeave:this.handleMouseLeave,onTouchMove:this.handleTouchMove,onTouchStart:this.handleTouchStart,onTouchEnd:this.handleTouchEnd,onContextMenu:this.handleContextMenu});var R=Cm(this.props,this.handleOuterEvent);return fe(fe({},R),M)}},{key:"addListener",value:function(){k1.on($1,this.handleReceiveSyncEvent)}},{key:"removeListener",value:function(){k1.removeListener($1,this.handleReceiveSyncEvent)}},{key:"filterFormatItem",value:function(A,C,N){for(var M=this.state.formattedGraphicalItems,R=0,D=M.length;R<D;R++){var L=M[R];if(L.item===A||L.props.key===A.key||C===ei(L.item.type)&&N===L.childIndex)return L}return null}},{key:"renderClipPath",value:function(){var A=this.clipPathId,C=this.state.offset,N=C.left,M=C.top,R=C.height,D=C.width;return I.createElement("defs",null,I.createElement("clipPath",{id:A},I.createElement("rect",{x:N,y:M,height:R,width:D})))}},{key:"getXScales",value:function(){var A=this.state.xAxisMap;return A?Object.entries(A).reduce(function(C,N){var M=I4(N,2),R=M[0],D=M[1];return fe(fe({},C),{},ke({},R,D.scale))},{}):null}},{key:"getYScales",value:function(){var A=this.state.yAxisMap;return A?Object.entries(A).reduce(function(C,N){var M=I4(N,2),R=M[0],D=M[1];return fe(fe({},C),{},ke({},R,D.scale))},{}):null}},{key:"getXScaleByAxisId",value:function(A){var C;return(C=this.state.xAxisMap)===null||C===void 0||(C=C[A])===null||C===void 0?void 0:C.scale}},{key:"getYScaleByAxisId",value:function(A){var C;return(C=this.state.yAxisMap)===null||C===void 0||(C=C[A])===null||C===void 0?void 0:C.scale}},{key:"getItemByXY",value:function(A){var C=this.state,N=C.formattedGraphicalItems,M=C.activeItem;if(N&&N.length)for(var R=0,D=N.length;R<D;R++){var L=N[R],H=L.props,B=L.item,U=B.type.defaultProps!==void 0?fe(fe({},B.type.defaultProps),B.props):B.props,Y=ei(B.type);if(Y==="Bar"){var Z=(H.data||[]).find(function(V){return mde(A,V)});if(Z)return{graphicalItem:L,payload:Z}}else if(Y==="RadialBar"){var X=(H.data||[]).find(function(V){return rk(A,V)});if(X)return{graphicalItem:L,payload:X}}else if(qv(L,M)||Uv(L,M)||Nf(L,M)){var k=ahe({graphicalItem:L,activeTooltipItem:M,itemData:U.data}),q=U.activeIndex===void 0?k:U.activeIndex;return{graphicalItem:fe(fe({},L),{},{childIndex:q}),payload:Nf(L,M)?U.data[k]:L.props.data[k]}}}return null}},{key:"render",value:function(){var A=this;if(!mM(this))return null;var C=this.props,N=C.children,M=C.className,R=C.width,D=C.height,L=C.style,H=C.compact,B=C.title,U=C.desc,Y=L4(C,Nve),Z=nt(Y,!1);if(H)return I.createElement(y4,{state:this.state,width:this.props.width,height:this.props.height,clipPathId:this.clipPathId},I.createElement(wS,bl({},Z,{width:R,height:D,title:B,desc:U}),this.renderClipPath(),vM(N,this.renderMap)));if(this.props.accessibilityLayer){var X,k;Z.tabIndex=(X=this.props.tabIndex)!==null&&X!==void 0?X:0,Z.role=(k=this.props.role)!==null&&k!==void 0?k:"application",Z.onKeyDown=function(V){A.accessibilityManager.keyboardEvent(V)},Z.onFocus=function(){A.accessibilityManager.focus()}}var q=this.parseEventsOfWrapper();return I.createElement(y4,{state:this.state,width:this.props.width,height:this.props.height,clipPathId:this.clipPathId},I.createElement("div",bl({className:et("recharts-wrapper",M),style:fe({position:"relative",cursor:"default",width:R,height:D},L)},q,{ref:function(Q){A.container=Q}}),I.createElement(wS,bl({},Z,{width:R,height:D,title:B,desc:U,style:Gve}),this.renderClipPath(),vM(N,this.renderMap)),this.renderLegend(),this.renderTooltip()))}}])})(S.Component);ke(O,"displayName",n),ke(O,"defaultProps",fe({layout:"horizontal",stackOffset:"none",barCategoryGap:"10%",barGap:4,margin:{top:5,right:5,bottom:5,left:5},reverseStackOrder:!1,syncMethod:"index"},m)),ke(O,"getDerivedStateFromProps",function(b,E){var _=b.dataKey,A=b.data,C=b.children,N=b.width,M=b.height,R=b.layout,D=b.stackOffset,L=b.margin,H=E.dataStartIndex,B=E.dataEndIndex;if(E.updateId===void 0){var U=q4(b);return fe(fe(fe({},U),{},{updateId:0},x(fe(fe({props:b},U),{},{updateId:0}),E)),{},{prevDataKey:_,prevData:A,prevWidth:N,prevHeight:M,prevLayout:R,prevStackOffset:D,prevMargin:L,prevChildren:C})}if(_!==E.prevDataKey||A!==E.prevData||N!==E.prevWidth||M!==E.prevHeight||R!==E.prevLayout||D!==E.prevStackOffset||!_l(L,E.prevMargin)){var Y=q4(b),Z={chartX:E.chartX,chartY:E.chartY,isTooltipActive:E.isTooltipActive},X=fe(fe({},B4(E,A,R)),{},{updateId:E.updateId+1}),k=fe(fe(fe({},Y),Z),X);return fe(fe(fe({},k),x(fe({props:b},k),E)),{},{prevDataKey:_,prevData:A,prevWidth:N,prevHeight:M,prevLayout:R,prevStackOffset:D,prevMargin:L,prevChildren:C})}if(!xS(C,E.prevChildren)){var q,V,Q,ee,z=rr(C,Vl),G=z&&(q=(V=z.props)===null||V===void 0?void 0:V.startIndex)!==null&&q!==void 0?q:H,$=z&&(Q=(ee=z.props)===null||ee===void 0?void 0:ee.endIndex)!==null&&Q!==void 0?Q:B,W=G!==H||$!==B,ae=!Qe(A),ce=ae&&!W?E.updateId:E.updateId+1;return fe(fe({updateId:ce},x(fe(fe({props:b},E),{},{updateId:ce,dataStartIndex:G,dataEndIndex:$}),E)),{},{prevChildren:C,dataStartIndex:G,dataEndIndex:$})}return null}),ke(O,"renderActiveDot",function(b,E,_){var A;return S.isValidElement(b)?A=S.cloneElement(b,E):Ye(b)?A=b(E):A=I.createElement(kE,E),I.createElement(Bt,{className:"recharts-active-dot",key:_},A)});var j=S.forwardRef(function(E,_){return I.createElement(O,bl({},E,{ref:_}))});return j.displayName=O.displayName,j},X6=K6({chartName:"LineChart",GraphicalChild:Ar,axisComponents:[{axisType:"xAxis",AxisComp:ws},{axisType:"yAxis",AxisComp:hi}],formatAxisMap:m6}),tge=K6({chartName:"BarChart",GraphicalChild:ao,defaultTooltipEventType:"axis",validateTooltipEventTypes:["axis","item"],axisComponents:[{axisType:"xAxis",AxisComp:ws},{axisType:"yAxis",AxisComp:hi}],formatAxisMap:m6});function L1(e){if(e===0)return"0 B";const t=1024,n=["B","KB","MB","GB","TB"],r=Math.floor(Math.log(e)/Math.log(t));return`${Number.parseFloat((e/t**r).toFixed(1))} ${n[r]}`}function Xo(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toString()}function Fh({title:e,value:t,description:n,icon:r,trend:i}){return c.jsxs(Te,{children:[c.jsxs(Me,{className:"flex flex-row items-center justify-between pb-2",children:[c.jsx(Le,{className:"font-medium text-muted-foreground text-sm",children:e}),c.jsx(r,{className:"h-4 w-4 text-muted-foreground"})]}),c.jsxs($e,{children:[c.jsx("div",{className:"font-bold text-2xl",children:t}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("p",{className:"text-muted-foreground text-xs",children:n}),i!==void 0&&i!==0&&c.jsxs("span",{className:`flex items-center text-xs ${i>0?"text-green-500":"text-red-500"}`,children:[c.jsx(Uj,{className:`h-3 w-3 ${i<0?"rotate-180":""}`}),Math.abs(i),"%"]})]})]})]})}function nge({data:e}){const t=e.map(n=>({date:new Date(n.date).toLocaleDateString("en-US",{month:"short",day:"numeric"}),size:n.size/1073741824,files:n.files}));return c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(Le,{children:"Storage Usage"}),c.jsx(We,{children:"Storage size and file count over time"})]}),c.jsx($e,{children:c.jsx(lE,{height:300,width:"100%",children:c.jsxs(X6,{data:t,children:[c.jsx(Wv,{className:"stroke-muted",strokeDasharray:"3 3"}),c.jsx(ws,{className:"text-xs",dataKey:"date",stroke:"currentColor",tick:{fill:"currentColor"}}),c.jsx(hi,{className:"text-xs",stroke:"currentColor",tick:{fill:"currentColor"},tickFormatter:n=>`${n} GB`,yAxisId:"left"}),c.jsx(hi,{className:"text-xs",orientation:"right",stroke:"currentColor",tick:{fill:"currentColor"},yAxisId:"right"}),c.jsx(_r,{contentStyle:{backgroundColor:"hsl(var(--card))",border:"1px solid hsl(var(--border))",borderRadius:"var(--radius)"},formatter:(n,r)=>[r==="size"?`${n.toFixed(2)} GB`:n,r==="size"?"Storage":"Files"]}),c.jsx(ni,{}),c.jsx(Ar,{dataKey:"size",dot:!1,name:"Storage (GB)",stroke:"hsl(var(--primary))",strokeWidth:2,type:"monotone",yAxisId:"left"}),c.jsx(Ar,{dataKey:"files",dot:!1,name:"File Count",stroke:"hsl(var(--chart-2))",strokeWidth:2,type:"monotone",yAxisId:"right"})]})})})]})}function rge({data:e}){const t=e.map(n=>({date:new Date(n.date).toLocaleDateString("en-US",{month:"short",day:"numeric"}),bandwidth:n.bytes/1048576,requests:n.requests}));return c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(Le,{children:"CDN Traffic"}),c.jsx(We,{children:"Bandwidth and requests over time"})]}),c.jsx($e,{children:c.jsx(lE,{height:300,width:"100%",children:c.jsxs(tge,{data:t,children:[c.jsx(Wv,{className:"stroke-muted",strokeDasharray:"3 3"}),c.jsx(ws,{className:"text-xs",dataKey:"date",stroke:"currentColor",tick:{fill:"currentColor"}}),c.jsx(hi,{className:"text-xs",stroke:"currentColor",tick:{fill:"currentColor"},tickFormatter:n=>`${n} MB`,yAxisId:"left"}),c.jsx(hi,{className:"text-xs",orientation:"right",stroke:"currentColor",tick:{fill:"currentColor"},tickFormatter:n=>Xo(n),yAxisId:"right"}),c.jsx(_r,{contentStyle:{backgroundColor:"hsl(var(--card))",border:"1px solid hsl(var(--border))",borderRadius:"var(--radius)"},formatter:(n,r)=>[r==="bandwidth"?`${n.toFixed(1)} MB`:Xo(n),r==="bandwidth"?"Bandwidth":"Requests"]}),c.jsx(ni,{}),c.jsx(ao,{dataKey:"bandwidth",fill:"hsl(var(--primary))",name:"Bandwidth (MB)",radius:[4,4,0,0],yAxisId:"left"}),c.jsx(ao,{dataKey:"requests",fill:"hsl(var(--chart-3))",name:"Requests",radius:[4,4,0,0],yAxisId:"right"})]})})})]})}function age({files:e}){return c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(Le,{children:"Top Files"}),c.jsx(We,{children:"Most requested files this month"})]}),c.jsx($e,{children:e.length===0?c.jsx("div",{className:"py-4 text-center text-muted-foreground",children:"No data available"}):c.jsx("div",{className:"space-y-4",children:e.map((t,n)=>{const r=t.key.split("/").pop()||t.key,i=Math.max(...e.map(l=>l.requests)),o=t.requests/i*100;return c.jsxs("div",{children:[c.jsxs("div",{className:"mb-1 flex items-center justify-between text-sm",children:[c.jsxs("span",{className:"flex items-center gap-2",children:[c.jsxs("span",{className:"text-muted-foreground",children:[n+1,"."]}),c.jsx("span",{className:"max-w-[200px] truncate font-medium",children:r})]}),c.jsxs("span",{className:"text-muted-foreground",children:[Xo(t.requests)," requests"]})]}),c.jsx(tv,{className:"h-2",value:o})]},t.key)})})})]})}function ige(){return c.jsxs("div",{className:"space-y-6",children:[c.jsx("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-4",children:Array.from({length:4}).map((e,t)=>c.jsxs(Te,{children:[c.jsx(Me,{className:"pb-2",children:c.jsx(De,{className:"h-4 w-20"})}),c.jsxs($e,{children:[c.jsx(De,{className:"h-8 w-24"}),c.jsx(De,{className:"mt-2 h-3 w-32"})]})]},t))}),c.jsxs(Te,{children:[c.jsx(Me,{children:c.jsx(De,{className:"h-6 w-32"})}),c.jsx($e,{children:c.jsx(De,{className:"h-[300px] w-full"})})]})]})}function oge(){return c.jsxs("div",{className:"flex flex-col items-center justify-center py-12",children:[c.jsx(If,{className:"mb-4 h-16 w-16 text-muted-foreground opacity-50"}),c.jsx("h2",{className:"mb-2 font-semibold text-xl",children:"No Storage Configured"}),c.jsxs("p",{className:"mb-6 max-w-md text-center text-muted-foreground",children:["Storage infrastructure has not been deployed yet. Run"," ",c.jsx("code",{className:"rounded bg-muted px-2 py-1 font-mono text-sm",children:"wraps storage init"})," ","to get started."]})]})}function sge(){const[e,t]=S.useState(null),[n,r]=S.useState(!0),[i,o]=S.useState(null),[l,f]=S.useState("7d"),d=S.useCallback(async()=>{try{r(!0),o(null);const h=sessionStorage.getItem("wraps-auth-token"),v=await fetch(`/api/cdn/metrics?token=${h}&range=${l}`);if(!v.ok){if(v.status===404){t(null);return}throw new Error("Failed to fetch storage metrics")}const m=await v.json();t(m)}catch(h){o(h instanceof Error?h.message:"An error occurred")}finally{r(!1)}},[l]);return S.useEffect(()=>{d()},[d]),n?c.jsx(ige,{}):i?c.jsxs(Un,{variant:"destructive",children:[c.jsx(lr,{className:"h-4 w-4"}),c.jsx(ro,{children:"Error"}),c.jsx(Hn,{children:i})]}):e?c.jsxs("div",{className:"space-y-6",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("h1",{className:"font-bold text-2xl",children:"Storage Metrics"}),c.jsx("p",{className:"text-muted-foreground",children:"Monitor your storage usage and CDN traffic"})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs(ga,{onValueChange:f,value:l,children:[c.jsx(xa,{className:"w-32",children:c.jsx(ya,{})}),c.jsxs(ba,{children:[c.jsx(Fe,{value:"7d",children:"Last 7 days"}),c.jsx(Fe,{value:"30d",children:"Last 30 days"}),c.jsx(Fe,{value:"90d",children:"Last 90 days"})]})]}),c.jsxs(Ce,{onClick:d,size:"sm",variant:"outline",children:[c.jsx(Lf,{className:"mr-2 h-4 w-4"}),"Refresh"]})]})]}),c.jsxs("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-4",children:[c.jsx(Fh,{description:`${Xo(e.summary.fileCount)} files`,icon:KH,title:"Storage Used",value:L1(e.summary.totalSize)}),c.jsx(Fh,{description:`${L1(e.summary.bandwidth.thisMonth)} this month`,icon:UH,title:"Bandwidth Today",value:L1(e.summary.bandwidth.today)}),c.jsx(Fh,{description:`${Xo(e.summary.requests.thisMonth)} this month`,icon:Fu,title:"Requests Today",value:Xo(e.summary.requests.today)}),c.jsx(Fh,{description:"Files in storage",icon:FH,title:"Total Files",value:Xo(e.summary.fileCount)})]}),c.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[c.jsx(nge,{data:e.usage}),c.jsx(rge,{data:e.bandwidth})]}),c.jsx(age,{files:e.topFiles})]}):c.jsx(oge,{})}function Ep({status:e}){const t={SUCCESS:{icon:so,label:"Active",className:"bg-green-500/10 text-green-700 dark:text-green-400 border-green-500/20"},PENDING:{icon:Jo,label:"Pending",className:"bg-yellow-500/10 text-yellow-700 dark:text-yellow-400 border-yellow-500/20"},FAILED:{icon:m$,label:"Failed",className:"bg-red-500/10 text-red-700 dark:text-red-400 border-red-500/20"},DISABLED:{icon:lr,label:"Disabled",className:"bg-gray-500/10 text-gray-700 dark:text-gray-400 border-gray-500/20"}},{icon:n,label:r,className:i}=t[e];return c.jsxs(Be,{className:i,variant:"outline",children:[c.jsx(n,{className:"mr-1 h-3 w-3"}),r]})}function wl({text:e}){const t=async()=>{await navigator.clipboard.writeText(e),jt.success("Copied to clipboard")};return c.jsx(Ce,{onClick:t,size:"sm",variant:"ghost",children:c.jsx(zj,{className:"h-3 w-3"})})}function lge({settings:e}){return c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(If,{className:"h-5 w-5"}),c.jsx(Le,{children:"S3 Bucket"})]}),c.jsx(Ep,{status:"SUCCESS"})]}),c.jsx(We,{children:"Your storage bucket for uploading files"})]}),c.jsx($e,{className:"space-y-4",children:c.jsxs("div",{className:"grid gap-4",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-muted-foreground text-sm",children:"Bucket Name"}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("code",{className:"rounded bg-muted px-2 py-1 font-mono text-sm",children:e.bucketName}),c.jsx(wl,{text:e.bucketName})]})]}),c.jsx(Vt,{}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-muted-foreground text-sm",children:"Region"}),c.jsx("code",{className:"rounded bg-muted px-2 py-1 font-mono text-sm",children:e.region})]}),c.jsx(Vt,{}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-muted-foreground text-sm",children:"Versioning"}),c.jsx(Be,{variant:e.versioning?"default":"secondary",children:e.versioning?"Enabled":"Disabled"})]}),c.jsx(Vt,{}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-muted-foreground text-sm",children:"Encryption"}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(tm,{className:"h-4 w-4 text-green-500"}),c.jsx("span",{className:"text-sm",children:"AES-256"})]})]}),e.retention&&e.retention!=="none"&&c.jsxs(c.Fragment,{children:[c.jsx(Vt,{}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-muted-foreground text-sm",children:"Auto-Cleanup"}),c.jsx("span",{className:"text-sm",children:e.retention})]})]})]})})]})}function cge({settings:e}){const[t,n]=S.useState(!1);if(!e.cdn?.enabled)return c.jsx(Te,{children:c.jsxs(Me,{children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(Fu,{className:"h-5 w-5"}),c.jsx(Le,{children:"CloudFront CDN"})]}),c.jsx(Ep,{status:"DISABLED"})]}),c.jsx(We,{children:"CDN is not enabled for this storage bucket"})]})});const r=e.cdn.status==="Deployed"?"SUCCESS":e.cdn.status==="InProgress"?"PENDING":"FAILED";return c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(Fu,{className:"h-5 w-5"}),c.jsx(Le,{children:"CloudFront CDN"})]}),c.jsx(Ep,{status:r})]}),c.jsx(We,{children:"Global content delivery network for fast file access"})]}),c.jsxs($e,{className:"space-y-4",children:[c.jsxs("div",{className:"grid gap-4",children:[e.cdn.distributionId&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-muted-foreground text-sm",children:"Distribution ID"}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("code",{className:"rounded bg-muted px-2 py-1 font-mono text-sm",children:e.cdn.distributionId}),c.jsx(wl,{text:e.cdn.distributionId})]})]}),c.jsx(Vt,{})]}),e.cdn.distributionDomain&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-muted-foreground text-sm",children:"CloudFront URL"}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("a",{className:"text-blue-600 text-sm hover:underline dark:text-blue-400",href:`https://${e.cdn.distributionDomain}`,rel:"noopener noreferrer",target:"_blank",children:[e.cdn.distributionDomain,c.jsx(Hu,{className:"ml-1 inline h-3 w-3"})]}),c.jsx(wl,{text:`https://${e.cdn.distributionDomain}`})]})]}),c.jsx(Vt,{})]}),e.cdn.customDomain&&c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-muted-foreground text-sm",children:"Custom Domain"}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("a",{className:"text-blue-600 text-sm hover:underline dark:text-blue-400",href:`https://${e.cdn.customDomain}`,rel:"noopener noreferrer",target:"_blank",children:[e.cdn.customDomain,c.jsx(Hu,{className:"ml-1 inline h-3 w-3"})]}),c.jsx(wl,{text:`https://${e.cdn.customDomain}`})]})]})]}),e.certificate?.validationRecords&&e.certificate.validationRecords.length>0&&e.certificate.status==="PENDING_VALIDATION"&&c.jsxs(ms,{onOpenChange:n,open:t,children:[c.jsx(ps,{asChild:!0,children:c.jsxs(Ce,{className:"w-full justify-between",variant:"ghost",children:[c.jsxs("span",{className:"flex items-center gap-2",children:[c.jsx(lr,{className:"h-4 w-4 text-yellow-500"}),"Certificate DNS Records Required"]}),t?c.jsx("span",{className:"text-xs",children:"Hide"}):c.jsx("span",{className:"text-xs",children:"Show"})]})}),c.jsxs(vs,{className:"mt-2 space-y-2",children:[c.jsxs(Un,{children:[c.jsx(lr,{className:"h-4 w-4"}),c.jsx(ro,{children:"Action Required"}),c.jsx(Hn,{children:"Add these DNS records to verify your custom domain certificate"})]}),e.certificate.validationRecords.map((i,o)=>c.jsxs("div",{className:"rounded-lg border bg-muted/50 p-3 font-mono text-xs",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-muted-foreground",children:i.type}),c.jsx(wl,{text:i.value})]}),c.jsx("div",{className:"mt-1 break-all",children:i.name}),c.jsxs("div",{className:"mt-1 break-all text-muted-foreground",children:["→ ",i.value]})]},o))]})]})]})]})}function uge({settings:e}){return c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(tm,{className:"h-5 w-5"}),c.jsx(Le,{children:"IAM Role"})]}),c.jsx(Ep,{status:"SUCCESS"})]}),c.jsx(We,{children:"Role used by your application to access storage"})]}),c.jsx($e,{children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-muted-foreground text-sm",children:"Role ARN"}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("code",{className:"max-w-[300px] truncate rounded bg-muted px-2 py-1 font-mono text-xs",children:e.roleArn}),c.jsx(wl,{text:e.roleArn})]})]})})]})}function fge(){return c.jsxs("div",{className:"space-y-6",children:[c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(De,{className:"h-6 w-32"}),c.jsx(De,{className:"h-4 w-64"})]}),c.jsx($e,{children:c.jsxs("div",{className:"space-y-4",children:[c.jsx(De,{className:"h-8 w-full"}),c.jsx(De,{className:"h-8 w-full"}),c.jsx(De,{className:"h-8 w-full"})]})})]}),c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(De,{className:"h-6 w-32"}),c.jsx(De,{className:"h-4 w-64"})]}),c.jsx($e,{children:c.jsxs("div",{className:"space-y-4",children:[c.jsx(De,{className:"h-8 w-full"}),c.jsx(De,{className:"h-8 w-full"})]})})]})]})}function dge(){return c.jsxs("div",{className:"flex flex-col items-center justify-center py-12",children:[c.jsx(If,{className:"mb-4 h-16 w-16 text-muted-foreground opacity-50"}),c.jsx("h2",{className:"mb-2 font-semibold text-xl",children:"No Storage Configured"}),c.jsxs("p",{className:"mb-6 max-w-md text-center text-muted-foreground",children:["Storage infrastructure has not been deployed yet. Run"," ",c.jsx("code",{className:"rounded bg-muted px-2 py-1 font-mono text-sm",children:"wraps storage init"})," ","to get started."]})]})}function hge(){const[e,t]=S.useState(null),[n,r]=S.useState(!0),[i,o]=S.useState(null),l=S.useCallback(async()=>{try{r(!0),o(null);const f=sessionStorage.getItem("wraps-auth-token"),d=await fetch(`/api/cdn/settings?token=${f}`);if(!d.ok){if(d.status===404){t(null);return}throw new Error("Failed to fetch storage settings")}const h=await d.json();t(h)}catch(f){o(f instanceof Error?f.message:"An error occurred")}finally{r(!1)}},[]);return S.useEffect(()=>{l()},[l]),n?c.jsx(fge,{}):i?c.jsxs(Un,{variant:"destructive",children:[c.jsx(lr,{className:"h-4 w-4"}),c.jsx(ro,{children:"Error"}),c.jsx(Hn,{children:i})]}):e?c.jsxs("div",{className:"space-y-6",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("h1",{className:"font-bold text-2xl",children:"Storage Settings"}),c.jsx("p",{className:"text-muted-foreground",children:"Manage your S3 bucket and CloudFront CDN configuration"})]}),c.jsxs(Ce,{onClick:l,size:"sm",variant:"outline",children:[c.jsx(Lf,{className:"mr-2 h-4 w-4"}),"Refresh"]})]}),c.jsx(lge,{settings:e}),c.jsx(cge,{settings:e}),c.jsx(uge,{settings:e})]}):c.jsx(dge,{})}function Cl({className:e,...t}){return c.jsx("div",{className:pe("group/input-group relative flex w-full items-center rounded-md border border-input shadow-xs outline-none transition-[color,box-shadow] dark:bg-input/30","h-9 min-w-0 has-[>textarea]:h-auto","has-[>[data-align=inline-start]]:[&>input]:pl-2","has-[>[data-align=inline-end]]:[&>input]:pr-2","has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>[data-align=block-start]]:[&>input]:pb-3","has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-end]]:[&>input]:pt-3","has-[[data-slot=input-group-control]:focus-visible]:border-ring has-[[data-slot=input-group-control]:focus-visible]:ring-[3px] has-[[data-slot=input-group-control]:focus-visible]:ring-ring/50","has-[[data-slot][aria-invalid=true]]:border-destructive has-[[data-slot][aria-invalid=true]]:ring-destructive/20 dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40",e),"data-slot":"input-group",role:"group",...t})}const mge=ic("flex h-auto cursor-text select-none items-center justify-center gap-2 py-1.5 font-medium text-muted-foreground text-sm group-data-[disabled=true]/input-group:opacity-50 [&>kbd]:rounded-[calc(var(--radius)-5px)] [&>svg:not([class*='size-'])]:size-4",{variants:{align:{"inline-start":"order-first pl-3 has-[>button]:ml-[-0.45rem] has-[>kbd]:ml-[-0.35rem]","inline-end":"order-last pr-3 has-[>button]:mr-[-0.45rem] has-[>kbd]:mr-[-0.35rem]","block-start":"order-first w-full justify-start px-3 pt-3 group-has-[>input]/input-group:pt-2.5 [.border-b]:pb-3","block-end":"order-last w-full justify-start px-3 pb-3 group-has-[>input]/input-group:pb-2.5 [.border-t]:pt-3"}},defaultVariants:{align:"inline-start"}});function ca({className:e,align:t="inline-start",...n}){return c.jsx("div",{className:pe(mge({align:t}),e),"data-align":t,"data-slot":"input-group-addon",onClick:r=>{r.target.closest("button")||r.currentTarget.parentElement?.querySelector("input")?.focus()},role:"group",...n})}function Tl({className:e,...t}){return c.jsx("span",{className:pe("flex items-center gap-2 text-muted-foreground text-sm [&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none",e),...t})}function Ml({className:e,...t}){return c.jsx(fs,{className:pe("flex-1 rounded-none border-0 bg-transparent shadow-none focus-visible:ring-0 dark:bg-transparent",e),"data-slot":"input-group-control",...t})}var Xv="Tabs",[pge]=jn(Xv,[mc]),Q6=mc(),[vge,GE]=pge(Xv),Z6=S.forwardRef((e,t)=>{const{__scopeTabs:n,value:r,onValueChange:i,defaultValue:o,orientation:l="horizontal",dir:f,activationMode:d="automatic",...h}=e,v=hc(f),[m,g]=An({prop:r,onChange:i,defaultProp:o??"",caller:Xv});return c.jsx(vge,{scope:n,baseId:Cr(),value:m,onValueChange:g,orientation:l,dir:v,activationMode:d,children:c.jsx(Ae.div,{dir:v,"data-orientation":l,...h,ref:t})})});Z6.displayName=Xv;var J6="TabsList",e8=S.forwardRef((e,t)=>{const{__scopeTabs:n,loop:r=!0,...i}=e,o=GE(J6,n),l=Q6(n);return c.jsx(xO,{asChild:!0,...l,orientation:o.orientation,dir:o.dir,loop:r,children:c.jsx(Ae.div,{role:"tablist","aria-orientation":o.orientation,...i,ref:t})})});e8.displayName=J6;var t8="TabsTrigger",n8=S.forwardRef((e,t)=>{const{__scopeTabs:n,value:r,disabled:i=!1,...o}=e,l=GE(t8,n),f=Q6(n),d=i8(l.baseId,r),h=o8(l.baseId,r),v=r===l.value;return c.jsx(bO,{asChild:!0,...f,focusable:!i,active:v,children:c.jsx(Ae.button,{type:"button",role:"tab","aria-selected":v,"aria-controls":h,"data-state":v?"active":"inactive","data-disabled":i?"":void 0,disabled:i,id:d,...o,ref:t,onMouseDown:ge(e.onMouseDown,m=>{!i&&m.button===0&&m.ctrlKey===!1?l.onValueChange(r):m.preventDefault()}),onKeyDown:ge(e.onKeyDown,m=>{[" ","Enter"].includes(m.key)&&l.onValueChange(r)}),onFocus:ge(e.onFocus,()=>{const m=l.activationMode!=="manual";!v&&!i&&m&&l.onValueChange(r)})})})});n8.displayName=t8;var r8="TabsContent",a8=S.forwardRef((e,t)=>{const{__scopeTabs:n,value:r,forceMount:i,children:o,...l}=e,f=GE(r8,n),d=i8(f.baseId,r),h=o8(f.baseId,r),v=r===f.value,m=S.useRef(v);return S.useEffect(()=>{const g=requestAnimationFrame(()=>m.current=!1);return()=>cancelAnimationFrame(g)},[]),c.jsx(Nn,{present:i||v,children:({present:g})=>c.jsx(Ae.div,{"data-state":v?"active":"inactive","data-orientation":f.orientation,role:"tabpanel","aria-labelledby":d,hidden:!g,id:h,tabIndex:0,...l,ref:t,style:{...e.style,animationDuration:m.current?"0s":void 0},children:g&&o})})});a8.displayName=r8;function i8(e,t){return`${e}-trigger-${t}`}function o8(e,t){return`${e}-content-${t}`}var gge=Z6,yge=e8,xge=n8,bge=a8;function s8({className:e,...t}){return c.jsx(gge,{className:pe("flex flex-col gap-2",e),"data-slot":"tabs",...t})}function l8({className:e,...t}){return c.jsx(yge,{className:pe("inline-flex h-9 w-fit items-center justify-center rounded-lg bg-muted p-[3px] text-muted-foreground",e),"data-slot":"tabs-list",...t})}function qu({className:e,...t}){return c.jsx(xge,{className:pe("inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 whitespace-nowrap rounded-md border border-transparent px-2 py-1 font-medium text-foreground text-sm transition-[color,box-shadow] focus-visible:border-ring focus-visible:outline-1 focus-visible:outline-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:shadow-sm dark:text-muted-foreground dark:data-[state=active]:border-input dark:data-[state=active]:bg-input/30 dark:data-[state=active]:text-foreground [&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",e),"data-slot":"tabs-trigger",...t})}function Uu({className:e,...t}){return c.jsx(bge,{className:pe("flex-1 outline-none",e),"data-slot":"tabs-content",...t})}function wge({messageId:e,archivingEnabled:t}){const[n,r]=S.useState(null),[i,o]=S.useState(!0),[l,f]=S.useState(null);return S.useEffect(()=>{async function d(){if(!t){o(!1);return}try{o(!0),f(null);const h=sessionStorage.getItem("wraps-auth-token");if(!h)throw new Error("Authentication token not found");const v=encodeURIComponent(e),m=await fetch(`/api/emails/${v}/archive?token=${h}`);if(!m.ok){if(m.status===404){r(null),o(!1);return}throw new Error(`Failed to fetch archived email: ${m.statusText}`)}const g=await m.json();r({...g,timestamp:new Date(g.timestamp)})}catch(h){const v=h instanceof Error?h.message:"Unknown error";f(v),console.error("Error fetching archived email:",h)}finally{o(!1)}}d()},[e,t]),t?i?c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(Le,{children:"Email Archive"}),c.jsx(We,{children:"Loading archived email content..."})]}),c.jsx($e,{className:"space-y-4",children:c.jsx(De,{className:"h-[400px] w-full"})})]}):l?c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(Le,{children:"Email Archive"}),c.jsx(We,{children:"Failed to load archived email"})]}),c.jsx($e,{children:c.jsx(Un,{variant:"destructive",children:c.jsx(Hn,{children:l})})})]}):n?c.jsxs(Te,{children:[c.jsx(Me,{children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx(Le,{children:"Email Archive"}),c.jsx(We,{children:"Full email content stored in AWS SES Mail Manager"})]}),n.attachments.length>0&&c.jsxs(Be,{variant:"secondary",children:[n.attachments.length," attachment",n.attachments.length>1?"s":""]})]})}),c.jsxs($e,{children:[c.jsxs(s8,{className:"w-full",defaultValue:"rendered",children:[c.jsxs(l8,{className:"grid w-full grid-cols-3",children:[c.jsxs(qu,{className:"gap-2",value:"rendered",children:[c.jsx(Fu,{className:"h-4 w-4"}),"Rendered Email"]}),c.jsxs(qu,{className:"gap-2",value:"text",children:[c.jsx(p$,{className:"h-4 w-4"}),"Plain Text"]}),c.jsxs(qu,{className:"gap-2",value:"html",children:[c.jsx(WH,{className:"h-4 w-4"}),"HTML Source"]})]}),c.jsxs(Uu,{className:"space-y-4",value:"rendered",children:[n.html?c.jsx("div",{className:"rounded-md border",children:c.jsx("iframe",{className:"h-[600px] w-full rounded-md",sandbox:"allow-same-origin",srcDoc:n.html,title:"Email preview"})}):c.jsx(Un,{children:c.jsx(Hn,{children:"No HTML content available for this email. View the plain text tab instead."})}),n.attachments.length>0&&c.jsxs("div",{className:"space-y-2",children:[c.jsx("div",{className:"font-medium text-sm",children:"Attachments"}),c.jsx("div",{className:"space-y-2",children:n.attachments.map((d,h)=>c.jsx("div",{className:"flex items-center justify-between rounded-md border p-3",children:c.jsxs("div",{className:"space-y-1",children:[c.jsx("div",{className:"font-mono text-sm",children:d.filename||`Attachment ${h+1}`}),c.jsxs("div",{className:"text-muted-foreground text-xs",children:[d.contentType," •"," ",(d.size/1024).toFixed(2)," KB"]})]})},d.filename||`attachment-${h}`))})]})]}),c.jsx(Uu,{className:"space-y-4",value:"text",children:n.text?c.jsx("div",{className:"rounded-md border bg-muted p-4",children:c.jsx("pre",{className:"whitespace-pre-wrap font-mono text-sm",children:n.text})}):c.jsx(Un,{children:c.jsx(Hn,{children:"No plain text content available for this email."})})}),c.jsx(Uu,{className:"space-y-4",value:"html",children:n.html?c.jsx("div",{className:"rounded-md border bg-muted p-4",children:c.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap font-mono text-xs",children:n.html})}):c.jsx(Un,{children:c.jsx(Hn,{children:"No HTML content available for this email."})})})]}),n.metadata&&c.jsxs("div",{className:"mt-6 space-y-3 rounded-md border p-4",children:[c.jsx("div",{className:"font-medium text-sm",children:"SMTP Metadata"}),c.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[n.metadata.senderIp&&c.jsxs("div",{className:"space-y-1",children:[c.jsx("div",{className:"text-muted-foreground text-xs",children:"Sender IP"}),c.jsx("div",{className:"font-mono text-sm",children:n.metadata.senderIp})]}),n.metadata.tlsProtocol&&c.jsxs("div",{className:"space-y-1",children:[c.jsx("div",{className:"text-muted-foreground text-xs",children:"TLS Protocol"}),c.jsx("div",{className:"font-mono text-sm",children:n.metadata.tlsProtocol})]}),n.metadata.senderHostname&&c.jsxs("div",{className:"space-y-1",children:[c.jsx("div",{className:"text-muted-foreground text-xs",children:"Sender Hostname"}),c.jsx("div",{className:"font-mono text-sm",children:n.metadata.senderHostname})]})]})]})]})]}):c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(Le,{children:"Email Archive"}),c.jsx(We,{children:"Email content not available"})]}),c.jsx($e,{children:c.jsx(Un,{children:c.jsx(Hn,{children:"This email was not archived. It may have been sent before email archiving was enabled for this deployment."})})})]}):c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(Le,{children:"Email Archive"}),c.jsx(We,{children:"Enable email archiving to view full email content"})]}),c.jsx($e,{children:c.jsx(Un,{children:c.jsxs(Hn,{children:["Email archiving is not enabled for this deployment. Run"," ",c.jsx("code",{className:"rounded bg-muted px-1.5 py-0.5 font-mono text-xs",children:"wraps upgrade"})," ","to enable archiving and view full email content with HTML rendering."]})})})]})}const Sge={sent:Sl,delivered:ai,bounced:or,suppressed:GH,complained:or,opened:Sl,clicked:Sl,failed:or},jge={sent:"text-blue-500",delivered:"text-green-500",bounced:"text-red-500",suppressed:"text-amber-500",complained:"text-red-500",opened:"text-purple-500",clicked:"text-indigo-500",failed:"text-red-500"},Oge={delivered:"default",sent:"secondary",bounced:"destructive",suppressed:"destructive",complained:"destructive",failed:"destructive",opened:"default",clicked:"default"};function Ege(){const{id:e}=hO(),t=_a(),[n,r]=S.useState(null),[i,o]=S.useState(!0),[l,f]=S.useState(null),[d,h]=S.useState(!1);S.useEffect(()=>{async function g(){try{o(!0),f(null);const x=sessionStorage.getItem("wraps-auth-token");if(!x)throw new Error("Authentication token not found");try{const _=await fetch(`/api/settings/deployment?token=${x}`);if(_.ok){const A=await _.json();h(A.archivingEnabled??!1)}}catch(_){console.warn("Failed to fetch deployment config:",_)}const O=encodeURIComponent(e||"");console.log("Fetching email with ID:",e),console.log("Encoded ID:",O),console.log("Full URL:",`/api/emails/${O}?token=${x.substring(0,8)}...`);const j=await fetch(`/api/emails/${O}?token=${x}`);if(!j.ok){let _="Failed to fetch email details";try{_=(await j.json()).error||_}catch{_=`${j.status}: ${j.statusText}`}throw new Error(_)}if(!j.headers.get("content-type")?.includes("application/json")){const _=await j.text();throw console.error("Non-JSON response:",_),new Error("Server returned non-JSON response")}const E=await j.json();console.log("Email data received:",{id:E.id,hasHtmlBody:!!E.htmlBody,hasTextBody:!!E.textBody,htmlBodyLength:E.htmlBody?.length||0,textBodyLength:E.textBody?.length||0,events:E.events?.length||0}),r(E)}catch(x){const O=x instanceof Error?x.message:"Unknown error";f(O),console.error("Error fetching email details:",x)}finally{o(!1)}}e&&g()},[e]);const v=g=>new Date(g).toLocaleString("en-US",{month:"short",day:"numeric",hour:"numeric",minute:"2-digit",hour12:!0}),m=g=>new Date(g).toLocaleString("en-US",{weekday:"short",month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit",second:"2-digit",hour12:!0});return i?c.jsx("div",{className:"flex h-[600px] items-center justify-center",children:c.jsx("div",{className:"text-muted-foreground",children:"Loading email details..."})}):l?c.jsxs("div",{className:"space-y-4",children:[c.jsxs(Ce,{onClick:()=>t("/email"),size:"sm",variant:"ghost",children:[c.jsx(Za,{className:"mr-2 h-4 w-4"}),"Back to emails"]}),c.jsx("div",{className:"rounded-md border border-destructive bg-destructive/10 p-4 text-destructive text-sm",children:l})]}):n?c.jsxs("div",{className:"space-y-6",children:[c.jsx("div",{className:"flex items-center gap-4",children:c.jsxs(Ce,{onClick:()=>t("/email"),size:"sm",variant:"ghost",children:[c.jsx(Za,{className:"mr-2 h-4 w-4"}),"Back"]})}),c.jsx(Te,{children:c.jsxs(Me,{className:"space-y-1.5",children:[c.jsxs(Le,{className:"flex flex-row items-center gap-2 text-xl",children:[c.jsx("span",{className:"text-xl",children:n.subject||"(no subject)"}),c.jsx(Be,{className:"shrink-0",variant:Oge[n.status],children:n.status.charAt(0).toUpperCase()+n.status.slice(1)})]}),c.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[c.jsx("code",{className:"min-w-0 truncate rounded bg-muted px-2 py-0.5 font-mono text-muted-foreground text-xs",children:n.messageId}),c.jsx(ma,{className:"h-6 w-6 shrink-0",size:"sm",value:n.messageId,variant:"ghost"})]}),c.jsxs("div",{className:"flex flex-col gap-3 pt-2 sm:flex-row sm:flex-wrap",children:[c.jsxs(Cl,{className:"w-full cursor-text! sm:w-auto sm:min-w-[518px]",children:[c.jsx(ca,{align:"inline-start",children:c.jsx(Tl,{children:"From"})}),c.jsx(Ml,{className:"min-w-0 cursor-text! truncate font-mono text-sm *:select-all",disabled:!0,readOnly:!0,value:n.from}),c.jsx(ca,{align:"inline-end",children:c.jsx(ma,{className:"h-6 w-6",size:"sm",value:n.from,variant:"ghost"})})]}),c.jsxs(Cl,{className:"w-full cursor-text! sm:w-auto sm:min-w-[518px]",children:[c.jsx(ca,{align:"inline-start",children:c.jsx(Tl,{children:"To"})}),c.jsx(Ml,{className:"min-w-0 cursor-text! truncate font-mono text-sm *:select-all",disabled:!0,readOnly:!0,value:n.to.length>0?n.to.join(", "):"(no recipients)"}),c.jsx(ca,{align:"inline-end",children:c.jsx(ma,{className:"h-6 w-6",size:"sm",value:n.to.join(", "),variant:"ghost"})})]}),n.replyTo&&c.jsxs(Cl,{className:"w-full sm:w-auto sm:max-w-md",children:[c.jsx(ca,{align:"inline-start",children:c.jsx(Tl,{children:"Reply-To"})}),c.jsx(Ml,{className:"min-w-0 truncate font-mono text-sm",readOnly:!0,value:n.replyTo}),c.jsx(ca,{align:"inline-end",children:c.jsx(ma,{className:"h-6 w-6",size:"sm",value:n.replyTo,variant:"ghost"})})]})]})]})}),d&&c.jsx(wge,{archivingEnabled:d,messageId:n.messageId}),c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(Le,{children:"Email Events"}),c.jsx(We,{children:"Lifecycle of this email from send to delivery"})]}),c.jsx($e,{children:c.jsx("div",{className:"space-y-4",children:n.events.length===0?c.jsx("div",{className:"text-muted-foreground text-sm",children:"No events recorded yet"}):n.events.map((g,x)=>{const O=Sge[g.type]||Jo,j=x===n.events.length-1;return c.jsx("div",{children:c.jsxs("div",{className:"flex gap-4",children:[c.jsxs("div",{className:"flex flex-col items-center",children:[c.jsx("div",{className:`rounded-full border-2 border-background bg-muted p-2 ${jge[g.type]}`,children:c.jsx(O,{className:"h-4 w-4"})}),!j&&c.jsx("div",{className:"my-1 w-px flex-1 bg-border"})]}),c.jsxs("div",{className:"flex-1 pb-6",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("div",{className:"font-medium capitalize",children:g.type}),c.jsx("div",{className:"text-muted-foreground text-sm",children:v(g.timestamp)})]}),c.jsx("div",{className:"text-muted-foreground text-sm",children:m(g.timestamp)}),g.metadata&&Object.keys(g.metadata).length>0&&c.jsx("div",{className:"mt-2 rounded-md border bg-muted/50 p-2 font-mono text-xs",children:c.jsx("pre",{className:"overflow-x-auto",children:JSON.stringify(g.metadata,null,2)})})]})]})},`${g.type}-${g.timestamp}`)})})})]})]}):c.jsxs("div",{className:"space-y-4",children:[c.jsxs(Ce,{onClick:()=>t("/email"),size:"sm",variant:"ghost",children:[c.jsx(Za,{className:"mr-2 h-4 w-4"}),"Back to emails"]}),c.jsx("div",{className:"rounded-md border p-4 text-muted-foreground text-sm",children:"Email not found"})]})}function _ge(e){const t=new Date(e),r=Math.floor((new Date().getTime()-t.getTime())/(1e3*60*60*24));return r===0?t.toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}):r===1?"Yesterday":r<7?`${r} days ago`:t.toLocaleDateString()}function Age(){const e=_a(),[t,n]=S.useState([]),[r,i]=S.useState(!0),[o,l]=S.useState(null),[f,d]=S.useState("");S.useEffect(()=>{async function v(){try{i(!0),l(null);const m=sessionStorage.getItem("wraps-auth-token");if(!m)throw new Error("Authentication token not found. Please use the URL provided by 'wraps console' command.");const g=await fetch(`/api/inbound?limit=50&token=${m}`);if(!g.ok){let O="Failed to fetch inbound emails";try{O=(await g.json()).error||O}catch{O=`${g.status}: ${g.statusText}`}throw new Error(O)}const x=await g.json();n(x.emails||[])}catch(m){const g=m instanceof Error?m.message:"Unknown error";l(g),console.error("Error fetching inbound emails:",m)}finally{i(!1)}}v()},[]);const h=t.filter(v=>{if(!f)return!0;const m=f.toLowerCase(),g=v.from.address.toLowerCase().includes(m)||v.from.name.toLowerCase().includes(m),x=v.subject.toLowerCase().includes(m),O=v.to.some(j=>j.address.toLowerCase().includes(m)||j.name.toLowerCase().includes(m));return g||x||O});return c.jsxs("div",{className:"space-y-4",children:[o&&c.jsx("div",{className:"rounded-md border border-destructive bg-destructive/10 p-4 text-destructive text-sm",children:o}),c.jsx("div",{className:"flex items-center gap-2",children:c.jsxs("div",{className:"relative flex-1",children:[c.jsx(Cp,{className:"absolute top-2.5 left-2.5 h-4 w-4 text-muted-foreground"}),c.jsx(fs,{className:"pl-8",onChange:v=>d(v.target.value),placeholder:"Search inbound emails...",value:f})]})}),c.jsx("div",{className:"rounded-md border",children:c.jsxs(cv,{children:[c.jsx(uv,{children:c.jsxs(Fn,{children:[c.jsx(Pt,{children:"From"}),c.jsx(Pt,{children:"Subject"}),c.jsx(Pt,{children:"Received"}),c.jsx(Pt,{className:"w-[100px]",children:"Attachments"}),c.jsx(Pt,{className:"w-[80px]",children:"Spam"}),c.jsx(Pt,{className:"w-[50px]"})]})}),c.jsx(fv,{children:r?c.jsx(Fn,{children:c.jsx(ht,{className:"h-24 text-center text-muted-foreground",colSpan:6,children:"Loading inbound emails..."})}):h.length===0?c.jsx(Fn,{children:c.jsx(ht,{className:"h-24 text-center text-muted-foreground",colSpan:6,children:t.length===0?"No inbound emails received yet":"No emails match your search"})}):h.map(v=>c.jsxs(Fn,{className:"cursor-pointer hover:bg-muted/50",onClick:()=>e(`/email/inbound/${v.emailId}`),children:[c.jsxs(ht,{className:"font-mono text-sm",children:[v.from.name||v.from.address,v.from.name&&c.jsxs("span",{className:"ml-1 text-muted-foreground text-xs",children:["<",v.from.address,">"]})]}),c.jsx(ht,{className:"max-w-[300px] truncate",children:v.subject||"(no subject)"}),c.jsx(ht,{className:"text-muted-foreground",children:_ge(v.receivedAt)}),c.jsx(ht,{children:v.hasAttachments&&c.jsxs(Be,{className:"bg-gray-500/10 text-gray-700 dark:text-gray-400 border-gray-500/20",variant:"outline",children:[c.jsx(g$,{className:"mr-1 h-3 w-3"}),v.attachmentCount]})}),c.jsx(ht,{children:v.spamVerdict==="PASS"?c.jsx(x$,{className:"h-4 w-4 text-green-500"}):v.spamVerdict==="FAIL"?c.jsx(y$,{className:"h-4 w-4 text-red-500"}):null}),c.jsx(ht,{children:c.jsx(HH,{className:"h-4 w-4 text-muted-foreground"})})]},v.emailId))})]})}),h.length>0&&!r&&c.jsx("div",{className:"flex items-center justify-between text-muted-foreground text-sm",children:c.jsxs("div",{children:["Showing ",h.length," of ",t.length," inbound emails"]})})]})}const z1={clicked:{variant:"default",description:"Recipient clicked a link in the email",className:"bg-purple-500/10 text-purple-700 dark:text-purple-400 hover:bg-purple-500/20 border-purple-500/20"},opened:{variant:"default",description:"Recipient opened the email",className:"bg-blue-500/10 text-blue-700 dark:text-blue-400 hover:bg-blue-500/20 border-blue-500/20"},delivered:{variant:"default",description:"Email was successfully delivered to recipient's mailbox",className:"bg-green-500/10 text-green-700 dark:text-green-400 hover:bg-green-500/20 border-green-500/20"},sent:{variant:"secondary",description:"Email was sent but delivery not yet confirmed",className:"bg-gray-500/10 text-gray-700 dark:text-gray-400 hover:bg-gray-500/20 border-gray-500/20"},bounced:{variant:"default",description:"Email bounced - recipient's mailbox may not exist or be full",className:"bg-orange-500/10 text-orange-700 dark:text-orange-400 hover:bg-orange-500/20 border-orange-500/20"},suppressed:{variant:"default",description:"Email blocked - recipient is on the suppression list",className:"bg-amber-500/10 text-amber-700 dark:text-amber-400 hover:bg-amber-500/20 border-amber-500/20"},complained:{variant:"default",description:"Recipient marked this email as spam",className:"bg-red-500/10 text-red-700 dark:text-red-400 hover:bg-red-500/20 border-red-500/20"},failed:{variant:"default",description:"Email failed to send due to an error",className:"bg-red-500/10 text-red-700 dark:text-red-400 hover:bg-red-500/20 border-red-500/20"}};function Nge(){const e=_a(),[t,n]=S.useState(""),[r,i]=S.useState("15"),[o,l]=S.useState("all"),[f,d]=XY(),[h,v]=S.useState(f.get("tab")==="receiving"?"receiving":"sending"),[m,g]=S.useState([]),[x,O]=S.useState(!0),[j,b]=S.useState(null);S.useEffect(()=>{async function A(){try{O(!0),b(null);let C=sessionStorage.getItem("wraps-auth-token");if(C||(C=new URLSearchParams(window.location.search).get("token"),C&&sessionStorage.setItem("wraps-auth-token",C)),!C)throw new Error("Authentication token not found. Please use the URL provided by 'wraps console' command.");const N=Number.parseInt(r,10),M=Date.now()-N*24*60*60*1e3,R=Date.now(),D=await fetch(`/api/emails?startTime=${M}&endTime=${R}&limit=100&token=${C}`);if(!D.ok){let H="Failed to fetch email logs";try{H=(await D.json()).error||H}catch{H=`${D.status}: ${D.statusText}`}throw new Error(H)}const L=await D.json();g(L.logs.map(H=>({id:H.messageId,to:H.to,from:H.from,subject:H.subject,status:H.status,timestamp:H.sentAt,messageId:H.messageId})))}catch(C){const N=C instanceof Error?C.message:"Unknown error";b(N),console.error("Error fetching email logs:",C)}finally{O(!1)}}A()},[r]);const E=m.filter(A=>{if(t){const C=t.toLowerCase(),N=A.to.some(R=>R.toLowerCase().includes(C)),M=A.subject.toLowerCase().includes(C);if(!(N||M))return!1}return!(o!=="all"&&A.status!==o)}),_=A=>{const C=new Date(A),M=Math.floor((new Date().getTime()-C.getTime())/(1e3*60*60*24));return M===0?"Today":M===1?"Yesterday":M<7?`${M} days ago`:C.toLocaleDateString()};return c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(Le,{children:"Emails"}),c.jsx(We,{children:"View and manage your email sending history"})]}),c.jsx($e,{children:c.jsxs(s8,{onValueChange:A=>{v(A),d(A==="sending"?{}:{tab:A})},value:h,children:[c.jsxs(l8,{children:[c.jsx(qu,{value:"sending",children:"Sending"}),c.jsx(qu,{value:"receiving",children:"Receiving"})]}),c.jsxs(Uu,{className:"space-y-4",value:"sending",children:[j&&c.jsx("div",{className:"rounded-md border border-destructive bg-destructive/10 p-4 text-destructive text-sm",children:j}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("div",{className:"relative flex-1",children:[c.jsx(Cp,{className:"absolute top-2.5 left-2.5 h-4 w-4 text-muted-foreground"}),c.jsx(fs,{className:"pl-8",onChange:A=>n(A.target.value),placeholder:"Search...",value:t})]}),c.jsxs(ga,{onValueChange:i,value:r,children:[c.jsx(xa,{className:"w-[180px]",children:c.jsx(ya,{})}),c.jsxs(ba,{children:[c.jsx(Fe,{value:"1",children:"Last 24 hours"}),c.jsx(Fe,{value:"7",children:"Last 7 days"}),c.jsx(Fe,{value:"15",children:"Last 15 days"}),c.jsx(Fe,{value:"30",children:"Last 30 days"}),c.jsx(Fe,{value:"90",children:"Last 90 days"})]})]}),c.jsxs(ga,{onValueChange:l,value:o,children:[c.jsx(xa,{className:"w-[180px]",children:c.jsx(ya,{})}),c.jsxs(ba,{children:[c.jsx(Fe,{value:"all",children:"All Statuses"}),c.jsx(Fe,{value:"clicked",children:"Clicked"}),c.jsx(Fe,{value:"opened",children:"Opened"}),c.jsx(Fe,{value:"delivered",children:"Delivered"}),c.jsx(Fe,{value:"sent",children:"Sent"}),c.jsx(Fe,{value:"bounced",children:"Bounced"}),c.jsx(Fe,{value:"suppressed",children:"Suppressed"}),c.jsx(Fe,{value:"complained",children:"Complained"}),c.jsx(Fe,{value:"failed",children:"Failed"})]})]}),c.jsxs(Ce,{size:"icon",variant:"outline",children:[c.jsx("span",{className:"sr-only",children:"Download"}),"↓"]})]}),c.jsx("div",{className:"rounded-md border",children:c.jsxs(cv,{children:[c.jsx(uv,{children:c.jsxs(Fn,{children:[c.jsx(Pt,{children:"To"}),c.jsx(Pt,{children:"Status"}),c.jsx(Pt,{children:"Subject"}),c.jsx(Pt,{children:"Sent"}),c.jsx(Pt,{className:"w-[50px]"})]})}),c.jsx(fv,{children:x?c.jsx(Fn,{children:c.jsx(ht,{className:"h-24 text-center text-muted-foreground",colSpan:5,children:"Loading email logs..."})}):E.length===0?c.jsx(Fn,{children:c.jsx(ht,{className:"h-24 text-center text-muted-foreground",colSpan:5,children:"No emails found"})}):E.map(A=>c.jsxs(Fn,{className:"cursor-pointer hover:bg-muted/50",onClick:()=>e(`/email/${A.id}`),children:[c.jsx(ht,{className:"font-mono text-sm",children:A.to.length>0?c.jsxs(c.Fragment,{children:[A.to[0],A.to.length>1&&c.jsxs("span",{className:"ml-1 text-muted-foreground text-xs",children:["+",A.to.length-1," more"]})]}):c.jsx("span",{className:"text-muted-foreground",children:"(no recipients)"})}),c.jsx(ht,{children:c.jsxs(Vp,{children:[c.jsx(Yp,{asChild:!0,children:c.jsx(Be,{className:z1[A.status]?.className,variant:z1[A.status]?.variant??"default",children:A.status.charAt(0).toUpperCase()+A.status.slice(1)})}),c.jsx(Wp,{children:c.jsx("p",{children:z1[A.status]?.description??"Unknown status"})})]})}),c.jsx(ht,{className:"max-w-[400px] truncate",children:A.subject}),c.jsx(ht,{className:"text-muted-foreground",children:_(A.timestamp)}),c.jsx(ht,{children:c.jsxs(Ce,{onClick:C=>{C.stopPropagation()},size:"icon",variant:"ghost",children:[c.jsx("span",{className:"sr-only",children:"More options"}),"⋯"]})})]},A.id))})]})}),E.length>0&&!x&&c.jsx("div",{className:"flex items-center justify-between text-muted-foreground text-sm",children:c.jsxs("div",{children:["Showing ",E.length," of ",m.length," emails"]})})]}),c.jsx(Uu,{className:"space-y-4",value:"receiving",children:c.jsx(Age,{})})]})})]})}function Cge({data:e}){const t=Tge(e);return t.length===0?c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(Le,{children:"Email Metrics"}),c.jsx(We,{children:"Performance over the last 24 hours"})]}),c.jsx($e,{children:c.jsx("div",{className:"flex h-[400px] items-center justify-center text-muted-foreground",children:"No metrics data available yet"})})]}):c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(Le,{children:"Email Metrics"}),c.jsx(We,{children:"Performance over the last 24 hours"})]}),c.jsx($e,{children:c.jsx(lE,{height:400,width:"100%",children:c.jsxs(X6,{data:t,children:[c.jsx(Wv,{className:"stroke-muted",strokeDasharray:"3 3"}),c.jsx(ws,{className:"text-xs",dataKey:"timestamp",tickFormatter:n=>oS(new Date(n),"HH:mm")}),c.jsx(hi,{className:"text-xs"}),c.jsx(_r,{contentStyle:{backgroundColor:"hsl(var(--popover))",border:"1px solid hsl(var(--border))"},labelFormatter:n=>oS(new Date(n),"MMM d, HH:mm")}),c.jsx(ni,{}),c.jsx(Ar,{dataKey:"sends",name:"Sends",stroke:"hsl(var(--primary))",strokeWidth:2,type:"monotone"}),c.jsx(Ar,{dataKey:"deliveries",name:"Deliveries",stroke:"#82ca9d",strokeWidth:2,type:"monotone"}),c.jsx(Ar,{dataKey:"opens",name:"Opens",stroke:"#8884d8",strokeWidth:2,type:"monotone"}),c.jsx(Ar,{dataKey:"clicks",name:"Clicks",stroke:"#ffc658",strokeWidth:2,type:"monotone"}),c.jsx(Ar,{dataKey:"bounces",name:"Bounces",stroke:"#ff7300",strokeWidth:2,type:"monotone"}),c.jsx(Ar,{dataKey:"complaints",name:"Complaints",stroke:"hsl(var(--destructive))",strokeWidth:2,type:"monotone"})]})})})]})}function Tge(e){const t=new Map;[...e.sends,...e.bounces,...e.complaints,...e.deliveries,...e.opens,...e.clicks].forEach(n=>{t.has(n.timestamp)||t.set(n.timestamp,{timestamp:n.timestamp,sends:0,bounces:0,complaints:0,deliveries:0,opens:0,clicks:0})});for(const n of e.sends)t.get(n.timestamp).sends=n.value;for(const n of e.bounces)t.get(n.timestamp).bounces=n.value;for(const n of e.complaints)t.get(n.timestamp).complaints=n.value;for(const n of e.deliveries)t.get(n.timestamp).deliveries=n.value;for(const n of e.opens)t.get(n.timestamp).opens=n.value;for(const n of e.clicks)t.get(n.timestamp).clicks=n.value;return Array.from(t.values()).sort((n,r)=>n.timestamp-r.timestamp)}function Mge({quota:e}){const t=e.sentLast24Hours/e.max24HourSend*100,n=t>90?"destructive":t>70?"warning":"default";return c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsxs(Le,{className:"flex items-center justify-between",children:["SES Quota",c.jsxs(Be,{variant:n==="destructive"?"destructive":"secondary",children:[t.toFixed(1),"% used"]})]}),c.jsx(We,{children:"24-hour sending limits"})]}),c.jsxs($e,{className:"space-y-4",children:[c.jsxs("div",{children:[c.jsxs("div",{className:"mb-2 flex justify-between text-sm",children:[c.jsx("span",{className:"text-muted-foreground",children:"Emails sent"}),c.jsxs("span",{className:"font-medium",children:[e.sentLast24Hours.toLocaleString()," /"," ",e.max24HourSend.toLocaleString()]})]}),c.jsx(tv,{className:"h-2",value:t})]}),c.jsxs("div",{className:"flex items-center justify-between border-t pt-2",children:[c.jsx("span",{className:"text-muted-foreground text-sm",children:"Max send rate"}),c.jsxs("span",{className:"font-medium text-sm",children:[e.maxSendRate," emails/sec"]})]})]})]})}function Rge(){const[e,t]=S.useState("1"),[n,r]=S.useState(null),[i,o]=S.useState(!0),[l,f]=S.useState(null);if(S.useEffect(()=>{async function _(){try{o(!0),f(null);let A=sessionStorage.getItem("wraps-auth-token");if(A||(A=new URLSearchParams(window.location.search).get("token"),A&&sessionStorage.setItem("wraps-auth-token",A)),!A)throw new Error("Authentication token not found. Please use the URL provided by 'wraps console' command.");const C=Number.parseInt(e,10),N=Date.now()-C*24*60*60*1e3,M=Date.now(),R=await fetch(`/api/metrics?startTime=${N}&endTime=${M}&token=${A}`);if(!R.ok){let L="Failed to fetch email metrics";try{L=(await R.json()).error||L}catch{L=`${R.status}: ${R.statusText}`}throw new Error(L)}const D=await R.json();r(D)}catch(A){const C=A instanceof Error?A.message:"Unknown error";f(C),console.error("Error fetching email metrics:",A)}finally{o(!1)}}_()},[e]),l)return c.jsxs(c.Fragment,{children:[c.jsxs("div",{children:[c.jsx("h1",{className:"font-semibold text-3xl tracking-tight",children:"Email Metrics"}),c.jsx("p",{className:"mt-2 text-muted-foreground",children:"View detailed metrics and analytics for your email campaigns"})]}),c.jsx("div",{className:"mt-4 rounded-md border border-destructive bg-destructive/10 p-4 text-destructive text-sm",children:l})]});if(i||!n)return c.jsxs(c.Fragment,{children:[c.jsxs("div",{children:[c.jsx("h1",{className:"font-semibold text-3xl tracking-tight",children:"Email Metrics"}),c.jsx("p",{className:"mt-2 text-muted-foreground",children:"View detailed metrics and analytics for your email campaigns"})]}),c.jsx("div",{className:"mt-4 flex h-[400px] items-center justify-center text-muted-foreground",children:"Loading metrics..."})]});const d=n.metrics.sends.reduce((_,A)=>_+A.value,0)||0,h=n.metrics.deliveries.reduce((_,A)=>_+A.value,0)||0,v=n.metrics.bounces.reduce((_,A)=>_+A.value,0)||0,m=n.metrics.complaints.reduce((_,A)=>_+A.value,0)||0,g=n.metrics.opens.reduce((_,A)=>_+A.value,0)||0,x=n.metrics.clicks.reduce((_,A)=>_+A.value,0)||0,O=d>0?h/d*100:0,j=h>0?g/h*100:0,b=g>0?x/g*100:0,E=[{title:"Emails Sent",value:d.toLocaleString(),description:`${e==="1"?"Last 24 hours":`Last ${e} days`}`,icon:Sl},{title:"Delivery Rate",value:`${O.toFixed(1)}%`,description:`${h.toLocaleString()} delivered`,icon:Uj},{title:"Open Rate",value:`${j.toFixed(1)}%`,description:`${g.toLocaleString()} opened`,icon:Np},{title:"Click Rate",value:`${b.toFixed(1)}%`,description:`${x.toLocaleString()} clicked`,icon:lF}];return c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("h1",{className:"font-semibold text-3xl tracking-tight",children:"Email Metrics"}),c.jsx("p",{className:"mt-2 text-muted-foreground",children:"View detailed metrics and analytics for your email campaigns"})]}),c.jsxs(ga,{onValueChange:t,value:e,children:[c.jsx(xa,{className:"w-[180px]",children:c.jsx(ya,{})}),c.jsxs(ba,{children:[c.jsx(Fe,{value:"1",children:"Last 24 hours"}),c.jsx(Fe,{value:"7",children:"Last 7 days"}),c.jsx(Fe,{value:"15",children:"Last 15 days"}),c.jsx(Fe,{value:"30",children:"Last 30 days"}),c.jsx(Fe,{value:"90",children:"Last 90 days"})]})]})]}),c.jsx("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-4",children:E.map(_=>c.jsxs(Te,{children:[c.jsxs(Me,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[c.jsx(Le,{className:"font-medium text-sm",children:_.title}),c.jsx(_.icon,{className:"h-4 w-4 text-muted-foreground"})]}),c.jsxs($e,{children:[c.jsx("div",{className:"font-bold text-2xl",children:_.value}),c.jsx("p",{className:"text-muted-foreground text-xs",children:_.description})]})]},_.title))}),c.jsx(Mge,{quota:n.quota}),c.jsx(Cge,{data:n.metrics}),c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(Le,{children:"Metrics Summary"}),c.jsx(We,{children:"Detailed breakdown of your email performance"})]}),c.jsxs($e,{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm",children:"Total Emails Sent"}),c.jsx(Be,{variant:"outline",children:d.toLocaleString()})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm",children:"Successfully Delivered"}),c.jsx(Be,{variant:"default",children:h.toLocaleString()})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm",children:"Opened"}),c.jsx(Be,{variant:"default",children:g.toLocaleString()})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm",children:"Clicked"}),c.jsx(Be,{variant:"default",children:x.toLocaleString()})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm",children:"Bounced"}),c.jsx(Be,{variant:"destructive",children:v.toLocaleString()})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm",children:"Complaints"}),c.jsx(Be,{variant:"destructive",children:m.toLocaleString()})]})]})]})]})}async function Dge(){const e=sessionStorage.getItem("wraps-auth-token");if(!e)throw new Error("Authentication token not found");const t=await fetch(`/api/settings?token=${e}`);if(!t.ok)throw new Error(`Failed to fetch settings: ${t.statusText}`);return await t.json()}const c8="wraps-dns-verification",Pge=1e3*60*60;function u8(){try{const e=localStorage.getItem(c8);return e?JSON.parse(e):{}}catch{return{}}}function _p(e){try{localStorage.setItem(c8,JSON.stringify(e))}catch(t){console.error("Failed to save DNS verification cache:",t)}}function f8(e){return e?Date.now()-e.lastChecked<Pge:!1}async function H4(e,t){console.log("[DNS Verify] verifyTrackingDomain called",{domain:e,expectedTarget:t});const n=u8(),r=`${e}->${t}`;if(n.trackingDomain?.[r]&&f8(n.trackingDomain[r]))return console.log("[DNS Verify] Returning cached result"),n.trackingDomain[r];try{const o=`/api/settings/verify-tracking-domain?token=${sessionStorage.getItem("wraps-auth-token")}&domain=${encodeURIComponent(e)}&expectedTarget=${encodeURIComponent(t)}`;console.log("[DNS Verify] Fetching:",o);const l=await fetch(o);if(console.log("[DNS Verify] Response status:",l.status),!l.ok)throw new Error(`HTTP ${l.status}: ${l.statusText}`);const f=await l.json();console.log("[DNS Verify] Response data:",f);const d={verified:f.verified,lastChecked:Date.now(),error:f.error};return n.trackingDomain||(n.trackingDomain={}),n.trackingDomain[r]=d,_p(n),d}catch(i){console.error("Tracking domain verification request failed:",i);const o={verified:!1,lastChecked:Date.now(),error:i instanceof Error?i.message:"Failed to verify"};return n.trackingDomain||(n.trackingDomain={}),n.trackingDomain[r]=o,_p(n),o}}async function F4(e){console.log("[DNS Verify] verifyDmarc called",{domain:e});const t=u8(),n=`_dmarc.${e}`;if(t.dmarc?.[n]&&f8(t.dmarc[n]))return console.log("[DNS Verify] Returning cached DMARC result"),t.dmarc[n];try{const i=`/api/settings/verify-dmarc?token=${sessionStorage.getItem("wraps-auth-token")}&domain=${encodeURIComponent(e)}`;console.log("[DNS Verify] Fetching:",i);const o=await fetch(i);if(console.log("[DNS Verify] Response status:",o.status),!o.ok)throw new Error(`HTTP ${o.status}: ${o.statusText}`);const l=await o.json();console.log("[DNS Verify] Response data:",l);const f={verified:l.verified,lastChecked:Date.now(),error:l.error};return t.dmarc||(t.dmarc={}),t.dmarc[n]=f,_p(t),f}catch(r){console.error("DMARC verification request failed:",r);const i={verified:!1,lastChecked:Date.now(),error:r instanceof Error?r.message:"Failed to verify"};return t.dmarc||(t.dmarc={}),t.dmarc[n]=i,_p(t),i}}function VE({status:e}){const t={SUCCESS:{icon:so,label:"Verified",variant:"default",className:"bg-green-500/10 text-green-700 dark:text-green-400 border-green-500/20"},PENDING:{icon:Jo,label:"Pending",variant:"secondary",className:"bg-yellow-500/10 text-yellow-700 dark:text-yellow-400 border-yellow-500/20"},FAILED:{icon:m$,label:"Failed",variant:"destructive",className:"bg-red-500/10 text-red-700 dark:text-red-400 border-red-500/20"},TEMPORARY_FAILURE:{icon:lr,label:"Temporary Failure",variant:"secondary",className:"bg-orange-500/10 text-orange-700 dark:text-orange-400 border-orange-500/20"},NOT_STARTED:{icon:Jo,label:"Not Started",variant:"outline",className:"bg-gray-500/10 text-gray-700 dark:text-gray-400 border-gray-500/20"}},{icon:n,label:r,className:i}=t[e];return c.jsxs(Be,{className:i,variant:"outline",children:[c.jsx(n,{className:"mr-1 h-3 w-3"}),r]})}function rc({text:e}){const t=async()=>{await navigator.clipboard.writeText(e),jt.success("Copied to clipboard",{description:"DNS record value copied successfully"})};return c.jsx(Ce,{onClick:t,size:"sm",variant:"ghost",children:c.jsx(zj,{className:"h-3 w-3"})})}function kge({identity:e}){const t=e?.dkimAttributes,n=t?.status==="SUCCESS",[r,i]=S.useState(!n);return t?c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"font-medium",children:"DKIM Authentication"}),c.jsxs("p",{className:"text-muted-foreground text-sm",children:[t.signingEnabled?"Enabled":"Disabled",t.signingKeyLength&&` · ${t.signingKeyLength}`]})]}),c.jsx(VE,{status:t.status})]}),t.tokens&&t.tokens.length>0&&c.jsxs(ms,{onOpenChange:i,open:r,children:[c.jsx(ps,{asChild:!0,children:c.jsxs(Ce,{className:"h-auto w-full justify-between p-0",size:"sm",variant:"ghost",children:[c.jsx("p",{className:"font-medium text-sm",children:"DNS Records (CNAME)"}),r?c.jsx(ac,{className:"h-4 w-4"}):c.jsx(oo,{className:"h-4 w-4"})]})}),c.jsx(vs,{className:"mt-2 space-y-2",children:t.tokens.map(o=>c.jsxs("div",{className:"rounded-md border bg-muted/50 p-3",children:[c.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[c.jsxs("p",{className:"font-mono text-xs",children:[o,"._domainkey.",e.identityName]}),c.jsx(rc,{text:`${o}._domainkey.${e.identityName}`})]}),c.jsxs("p",{className:"font-mono text-muted-foreground text-xs",children:["CNAME → ",o,".dkim.amazonses.com"]})]},o))})]})]}):c.jsx("div",{className:"space-y-4",children:c.jsx("div",{className:"flex items-center justify-between",children:c.jsxs("div",{children:[c.jsx("p",{className:"font-medium",children:"DKIM Authentication"}),c.jsx("p",{className:"text-muted-foreground text-sm",children:"Not configured"})]})})})}function $ge({identity:e}){const t=e?.mailFromAttributes,n=t?.mailFromDomainStatus==="SUCCESS",[r,i]=S.useState(!n);return c.jsx("div",{className:"space-y-4",children:t?.mailFromDomain?c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"font-medium",children:"Mail-From Domain"}),c.jsxs("p",{className:"text-muted-foreground text-sm",children:[t.mailFromDomain,t.behaviorOnMxFailure&&` · ${t.behaviorOnMxFailure==="USE_DEFAULT_VALUE"?"Fallback enabled":"Reject on failure"}`]})]}),t.mailFromDomainStatus&&c.jsx(VE,{status:t.mailFromDomainStatus})]}),c.jsxs(ms,{onOpenChange:i,open:r,children:[c.jsx(ps,{asChild:!0,children:c.jsxs(Ce,{className:"h-auto w-full justify-between p-0",size:"sm",variant:"ghost",children:[c.jsx("p",{className:"font-medium text-sm",children:"DNS Record (MX)"}),r?c.jsx(ac,{className:"h-4 w-4"}):c.jsx(oo,{className:"h-4 w-4"})]})}),c.jsx(vs,{className:"mt-2",children:c.jsx("div",{className:"rounded-md border bg-muted/50 p-3",children:c.jsxs("div",{className:"space-y-1",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("p",{className:"font-mono text-xs",children:["MX ",t.mailFromDomain]}),c.jsx(rc,{text:`10 feedback-smtp.${e?.identityName.split(".")[0]}.amazonses.com`})]}),c.jsxs("p",{className:"font-mono text-muted-foreground text-xs",children:["Priority 10 → feedback-smtp.",e?.identityName.split(".")[0],".amazonses.com"]})]})})})]})]}):c.jsx("div",{className:"flex items-center justify-between",children:c.jsxs("div",{children:[c.jsx("p",{className:"font-medium",children:"Mail-From Domain"}),c.jsx("p",{className:"text-muted-foreground text-sm",children:"Using default amazonses.com domain"})]})})})}function Ige({identity:e}){const[t,n]=S.useState(null),[r,i]=S.useState(!1),[o,l]=S.useState(!t?.verified);S.useEffect(()=>{e?.identityName&&F4(e.identityName).then(n)},[e?.identityName]),S.useEffect(()=>{t&&l(!t.verified)},[t]);const f=async()=>{if(e?.identityName){i(!0);try{const d=await F4(e.identityName);n(d),d.verified?jt.success("DMARC record verified",{description:"DNS TXT record found and configured correctly"}):(console.error("DMARC verification failed:",d.error),jt.error("Verification failed",{description:d.error||"DMARC record not found"}))}catch(d){console.error("DMARC verification error:",d),jt.error("Verification error",{description:d instanceof Error?d.message:"Unknown error"})}finally{i(!1)}}};return c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"font-medium",children:"DMARC Policy"}),c.jsx("p",{className:"text-muted-foreground text-sm",children:t?.verified?"Configured":"Recommended for better deliverability"})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[t?.verified&&c.jsxs(Be,{className:"border-green-500/20 bg-green-500/10 text-green-700 dark:text-green-400",variant:"outline",children:[c.jsx(so,{className:"mr-1 h-3 w-3"}),"Verified by Wraps"]}),c.jsx(Ce,{className:"h-8 w-8 p-0",disabled:r,onClick:f,size:"sm",variant:"ghost",children:c.jsx(Lf,{className:`h-4 w-4 ${r?"animate-spin":""}`})})]})]}),c.jsxs(ms,{onOpenChange:l,open:o,children:[c.jsx(ps,{asChild:!0,children:c.jsxs(Ce,{className:"h-auto w-full justify-between p-0",size:"sm",variant:"ghost",children:[c.jsx("p",{className:"font-medium text-sm",children:"DNS Record (TXT)"}),o?c.jsx(ac,{className:"h-4 w-4"}):c.jsx(oo,{className:"h-4 w-4"})]})}),c.jsx(vs,{className:"mt-2",children:c.jsxs("div",{className:"rounded-md border bg-muted/50 p-3",children:[c.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[c.jsxs("p",{className:"font-mono text-xs",children:["_dmarc.",e?.identityName||"yourdomain.com"]}),c.jsx(rc,{text:`_dmarc.${e?.identityName||"yourdomain.com"}`})]}),c.jsxs("div",{className:"flex items-start justify-between gap-2",children:[c.jsxs("p",{className:"font-mono text-muted-foreground text-xs",children:["v=DMARC1; p=quarantine; rua=mailto:dmarc@",e?.identityName||"yourdomain.com"]}),c.jsx(rc,{text:`v=DMARC1; p=quarantine; rua=mailto:dmarc@${e?.identityName||"yourdomain.com"}`})]})]})})]})]})}function Lge({configSet:e,region:t,onRefresh:n}){const r=e?.trackingOptions,[i,o]=S.useState(null),[l,f]=S.useState(!1),[d,h]=S.useState(!1),[v,m]=S.useState(""),[g,x]=S.useState(!1),[O,j]=S.useState(!i?.verified);S.useEffect(()=>{if(r?.customRedirectDomain&&t){const A=`r.${t}.awstrack.me`;H4(r.customRedirectDomain,A).then(o)}},[r?.customRedirectDomain,t]),S.useEffect(()=>{i&&j(!i.verified)},[i]);const b=async()=>{if(r?.customRedirectDomain&&t){f(!0);try{const A=`r.${t}.awstrack.me`,C=await H4(r.customRedirectDomain,A);o(C),C.verified?jt.success("Tracking domain verified",{description:"DNS records are configured correctly"}):(console.error("Tracking domain verification failed:",C.error),jt.error("Verification failed",{description:C.error||"DNS records not found"}))}catch(A){console.error("Tracking domain verification error:",A),jt.error("Verification error",{description:A instanceof Error?A.message:"Unknown error"})}finally{f(!1)}}},E=()=>{m(r?.customRedirectDomain||""),h(!0)},_=async()=>{if(!v.trim()){jt.error("Invalid domain",{description:"Please enter a valid domain name"});return}x(!0);try{const A=sessionStorage.getItem("wraps-auth-token"),C=await fetch(`/api/settings/config-set/tracking-domain?token=${A}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({domain:v})});if(!C.ok){const N=await C.json();throw new Error(N.error||`Failed to update: ${C.statusText}`)}h(!1),jt.success("Tracking domain updated",{description:"Don't forget to configure the DNS records"}),n&&await n()}catch(A){console.error("Failed to update tracking domain:",A),jt.error("Failed to update tracking domain",{description:A instanceof Error?A.message:"Unknown error"})}finally{x(!1)}};return c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(Le,{children:"Tracking Domain"}),c.jsx(We,{children:"Custom domain for open and click tracking links"})]}),c.jsx($e,{className:"space-y-4",children:r?.customRedirectDomain?c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex-1",children:[c.jsx("p",{className:"font-medium",children:r.customRedirectDomain}),c.jsx("p",{className:"text-muted-foreground text-sm",children:"Custom Tracking Domain"})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[i?.verified&&c.jsxs(Be,{className:"border-green-500/20 bg-green-500/10 text-green-700 dark:text-green-400",variant:"outline",children:[c.jsx(so,{className:"mr-1 h-3 w-3"}),"Verified by Wraps"]}),c.jsx(Be,{variant:"outline",children:r.httpsPolicy==="REQUIRE"?"HTTPS Only":"HTTPS Optional"}),c.jsx(Ce,{className:"h-8 w-8 p-0",disabled:l,onClick:b,size:"sm",variant:"ghost",children:c.jsx(Lf,{className:`h-4 w-4 ${l?"animate-spin":""}`})}),c.jsx(Ce,{className:"h-8 w-8 p-0",onClick:E,size:"sm",variant:"ghost",children:c.jsx(nC,{className:"h-4 w-4"})})]})]}),c.jsxs(ms,{onOpenChange:j,open:O,children:[c.jsx(ps,{asChild:!0,children:c.jsxs(Ce,{className:"h-auto w-full justify-between p-0",size:"sm",variant:"ghost",children:[c.jsx("p",{className:"font-medium text-sm",children:"Required DNS Record (CNAME)"}),O?c.jsx(ac,{className:"h-4 w-4"}):c.jsx(oo,{className:"h-4 w-4"})]})}),c.jsx(vs,{className:"mt-2",children:c.jsxs("div",{className:"rounded-md border bg-muted/50 p-3",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("p",{className:"font-mono text-xs",children:r.customRedirectDomain}),c.jsx(rc,{text:r.customRedirectDomain})]}),c.jsxs("div",{className:"mt-1 flex items-start justify-between gap-2",children:[c.jsxs("p",{className:"font-mono text-muted-foreground text-xs",children:["CNAME → r.",e?.name||"region",".awstrack.me"]}),c.jsx(rc,{text:`r.${e?.name||"region"}.awstrack.me`})]})]})})]})]}):c.jsxs("div",{className:"space-y-4",children:[c.jsx("p",{className:"text-muted-foreground text-sm",children:"No custom tracking domain configured. Using default awstrack.me domain."}),c.jsxs(Ce,{onClick:E,size:"sm",variant:"outline",children:[c.jsx(nC,{className:"mr-2 h-4 w-4"}),"Configure Tracking Domain"]})]})}),c.jsx(MO,{onOpenChange:h,open:d,children:c.jsxs(RO,{children:[c.jsxs(bL,{children:[c.jsx(SL,{children:"Update Tracking Domain"}),c.jsx(PX,{children:"Enter the custom domain you want to use for email tracking links. You'll need to configure DNS records after saving."})]}),c.jsx("div",{className:"space-y-4 py-4",children:c.jsxs("div",{className:"space-y-2",children:[c.jsx(Ho,{htmlFor:"domain",children:"Tracking Domain"}),c.jsx(fs,{disabled:g,id:"domain",onChange:A=>m(A.target.value),placeholder:"track.example.com",value:v}),c.jsx("p",{className:"text-muted-foreground text-xs",children:"Example: track.yourdomain.com or email.yourdomain.com"})]})}),c.jsxs(wL,{children:[c.jsx(Ce,{disabled:g,onClick:()=>h(!1),variant:"outline",children:"Cancel"}),c.jsx(Ce,{disabled:g,onClick:_,children:g?"Updating...":"Update Domain"})]})]})})]})}function zge({configSet:e,onRefresh:t}){const[n,r]=S.useState(!1),[i,o]=S.useState(!1),[l,f]=S.useState(!1);if(!e)return c.jsx(Te,{children:c.jsxs(Me,{children:[c.jsx(Le,{children:"Configuration Set"}),c.jsx(We,{children:"No configuration set found"})]})});const d=async()=>{f(!0);try{const v=sessionStorage.getItem("wraps-auth-token"),m=!e.sendingOptions?.sendingEnabled,g=await fetch(`/api/settings/config-set/sending?token=${v}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:m})});if(!g.ok)throw new Error(`Failed to update: ${g.statusText}`);r(!1),jt.success(m?"Email sending enabled":"Email sending disabled"),t&&await t()}catch(v){console.error("Failed to toggle sending:",v),jt.error("Failed to update setting",{description:v instanceof Error?v.message:"Unknown error"})}finally{f(!1)}},h=async()=>{f(!0);try{const v=sessionStorage.getItem("wraps-auth-token"),m=!e.reputationOptions?.reputationMetricsEnabled,g=await fetch(`/api/settings/config-set/reputation?token=${v}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:m})});if(!g.ok)throw new Error(`Failed to update: ${g.statusText}`);o(!1),jt.success(m?"Reputation metrics enabled":"Reputation metrics disabled"),t&&await t()}catch(v){console.error("Failed to toggle reputation:",v),jt.error("Failed to update setting",{description:v instanceof Error?v.message:"Unknown error"})}finally{f(!1)}};return c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(Le,{children:"Configuration Set"}),c.jsx(We,{children:"Email sending and tracking configuration"})]}),c.jsxs($e,{className:"space-y-6",children:[c.jsxs("div",{children:[c.jsx("p",{className:"font-medium",children:e.name}),c.jsx("p",{className:"text-muted-foreground text-sm",children:"Configuration Set Name"})]}),c.jsx(Vt,{}),e.sendingOptions&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex-1 space-y-0.5",children:[c.jsx("p",{className:"font-medium text-sm",children:"Email Sending"}),c.jsx("p",{className:"text-muted-foreground text-sm",children:e.sendingOptions.sendingEnabled?"Emails can be sent":"Email sending is disabled"})]}),c.jsx(Ce,{onClick:()=>r(!0),size:"sm",variant:e.sendingOptions.sendingEnabled?"destructive":"default",children:e.sendingOptions.sendingEnabled?"Disable":"Enable"})]}),c.jsx(dm,{onOpenChange:r,open:n,children:c.jsxs(hm,{children:[c.jsxs(mm,{children:[c.jsx(vm,{children:e.sendingOptions.sendingEnabled?"Disable email sending?":"Enable email sending?"}),c.jsx(gm,{children:e.sendingOptions.sendingEnabled?"All outgoing emails will be blocked until you re-enable sending. Emails in the queue will not be sent.":"This will allow emails to be sent through this configuration set. Make sure your domain is verified before enabling."})]}),c.jsxs(pm,{children:[c.jsx(xm,{disabled:l,children:"Cancel"}),c.jsx(ym,{disabled:l,onClick:d,children:l?"Updating...":e.sendingOptions.sendingEnabled?"Disable sending":"Enable sending"})]})]})})]}),e.reputationOptions&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex-1 space-y-0.5",children:[c.jsx("p",{className:"font-medium text-sm",children:"Reputation Metrics"}),c.jsx("p",{className:"text-muted-foreground text-sm",children:e.reputationOptions.reputationMetricsEnabled?"Tracking bounce and complaint rates":"Reputation tracking disabled"})]}),c.jsx(Ce,{onClick:()=>o(!0),size:"sm",variant:"outline",children:e.reputationOptions.reputationMetricsEnabled?"Disable":"Enable"})]}),c.jsx(dm,{onOpenChange:o,open:i,children:c.jsxs(hm,{children:[c.jsxs(mm,{children:[c.jsx(vm,{children:e.reputationOptions.reputationMetricsEnabled?"Disable reputation metrics?":"Enable reputation metrics?"}),c.jsx(gm,{children:e.reputationOptions.reputationMetricsEnabled?"You will stop collecting bounce and complaint rate data. Historical data will be preserved but no new metrics will be tracked.":"This will start tracking bounce and complaint rates for your sending domain. This helps monitor your email reputation and deliverability."})]}),c.jsxs(pm,{children:[c.jsx(xm,{disabled:l,children:"Cancel"}),c.jsx(ym,{disabled:l,onClick:h,children:l?"Updating...":e.reputationOptions.reputationMetricsEnabled?"Disable metrics":"Enable metrics"})]})]})})]}),e.deliveryOptions?.tlsPolicy&&c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"space-y-0.5",children:[c.jsx("p",{className:"font-medium text-sm",children:"TLS Encryption"}),c.jsx("p",{className:"text-muted-foreground text-sm",children:e.deliveryOptions.tlsPolicy==="REQUIRE"?"Required for all connections":"Optional (opportunistic)"})]}),c.jsx(Be,{variant:"outline",children:e.deliveryOptions.tlsPolicy==="REQUIRE"?"Required":"Optional"})]}),e.suppressionOptions&&c.jsxs("div",{className:"space-y-2",children:[c.jsxs("div",{className:"space-y-0.5",children:[c.jsx("p",{className:"font-medium text-sm",children:"Suppression List"}),c.jsx("p",{className:"text-muted-foreground text-sm",children:"Automatically suppress emails to addresses that bounced or complained"})]}),e.suppressionOptions.suppressedReasons&&e.suppressionOptions.suppressedReasons.length>0?c.jsx("div",{className:"flex gap-2",children:e.suppressionOptions.suppressedReasons.map(v=>c.jsx(Be,{variant:"secondary",children:v},v))}):c.jsx("p",{className:"text-muted-foreground text-sm",children:"Not configured"})]}),e.deliveryOptions?.sendingPoolName&&c.jsxs("div",{children:[c.jsx("p",{className:"font-medium text-sm",children:"IP Pool"}),c.jsx("p",{className:"text-muted-foreground text-sm",children:e.deliveryOptions.sendingPoolName})]})]})]})}function Bge(){const[e,t]=S.useState(null),[n,r]=S.useState(!0),[i,o]=S.useState(null),l=S.useCallback(async()=>{try{r(!0);const f=await Dge();t(f),o(null)}catch(f){console.error("Failed to fetch email settings:",f),o(f instanceof Error?f.message:"Failed to load settings")}finally{r(!1)}},[]);return S.useEffect(()=>{l()},[l]),n?c.jsxs(c.Fragment,{children:[c.jsxs("div",{children:[c.jsx("h1",{className:"font-semibold text-3xl tracking-tight",children:"Email Settings"}),c.jsx("p",{className:"mt-2 text-muted-foreground",children:"Configure your email settings and preferences"})]}),c.jsxs("div",{className:"mt-6 grid gap-6 md:grid-cols-2",children:[c.jsxs(Te,{className:"md:row-span-2",children:[c.jsxs(Me,{children:[c.jsx(De,{className:"h-6 w-48"}),c.jsx(De,{className:"mt-2 h-4 w-64"})]}),c.jsxs($e,{className:"space-y-6",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(De,{className:"h-4 w-32"}),c.jsx(De,{className:"h-4 w-24"})]}),c.jsx(De,{className:"h-px w-full"}),c.jsxs("div",{className:"space-y-2",children:[c.jsx(De,{className:"h-4 w-40"}),c.jsx(De,{className:"h-4 w-28"})]}),c.jsx(De,{className:"h-px w-full"}),c.jsxs("div",{className:"space-y-2",children:[c.jsx(De,{className:"h-4 w-36"}),c.jsx(De,{className:"h-4 w-32"})]}),c.jsx(De,{className:"h-px w-full"}),c.jsxs("div",{className:"space-y-2",children:[c.jsx(De,{className:"h-4 w-32"}),c.jsx(De,{className:"h-4 w-44"})]})]})]}),c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(De,{className:"h-6 w-48"}),c.jsx(De,{className:"mt-2 h-4 w-64"})]}),c.jsx($e,{children:c.jsx(De,{className:"h-20 w-full"})})]}),c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(De,{className:"h-6 w-48"}),c.jsx(De,{className:"mt-2 h-4 w-64"})]}),c.jsx($e,{children:c.jsx(De,{className:"h-20 w-full"})})]})]})]}):i?c.jsxs(c.Fragment,{children:[c.jsxs("div",{children:[c.jsx("h1",{className:"font-semibold text-3xl tracking-tight",children:"Email Settings"}),c.jsx("p",{className:"mt-2 text-muted-foreground",children:"Configure your email settings and preferences"})]}),c.jsxs(Un,{className:"mt-6",variant:"destructive",children:[c.jsx(lr,{className:"h-4 w-4"}),c.jsx(ro,{children:"Error Loading Settings"}),c.jsx(Hn,{children:i})]})]}):c.jsxs(c.Fragment,{children:[c.jsxs("div",{children:[c.jsx("h1",{className:"font-semibold text-3xl tracking-tight",children:"Email Settings"}),c.jsx("p",{className:"mt-2 text-muted-foreground",children:"Configure your email settings and preferences"})]}),c.jsxs("div",{className:"mt-6 grid gap-6 md:grid-cols-2",children:[c.jsxs(Te,{className:"md:row-span-2",children:[c.jsxs(Me,{children:[c.jsx(Le,{children:"Sending Domain"}),c.jsx(We,{children:"Email domain configuration and authentication"})]}),c.jsxs($e,{className:"space-y-6",children:[c.jsx("div",{className:"space-y-4",children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex-1",children:[c.jsx("p",{className:"font-medium",children:e?.identity?.identityName}),c.jsx("p",{className:"text-muted-foreground text-sm",children:"Domain Identity"})]}),c.jsx(VE,{status:e?.identity?.verificationStatus||"NOT_STARTED"})]})}),c.jsx(Vt,{}),c.jsx(kge,{identity:e?.identity}),c.jsx(Vt,{}),c.jsx($ge,{identity:e?.identity}),c.jsx(Vt,{}),c.jsx(Ige,{identity:e?.identity})]})]}),c.jsx(zge,{configSet:e?.configurationSet,onRefresh:l}),c.jsx(Lge,{configSet:e?.configurationSet,onRefresh:l,region:e?.region})]})]})}function B1(e){return e.name?`${e.name} <${e.address}>`:e.address}function qge(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function Gh({label:e,verdict:t}){if(!t)return null;const n=t==="PASS";return c.jsxs(Be,{className:n?"bg-green-500/10 text-green-700 dark:text-green-400 border-green-500/20":"bg-red-500/10 text-red-700 dark:text-red-400 border-red-500/20",variant:"outline",children:[n?c.jsx(x$,{className:"mr-1 h-3 w-3"}):c.jsx(y$,{className:"mr-1 h-3 w-3"}),e,": ",t]})}function Uge(){const{emailId:e}=hO(),t=_a(),[n,r]=S.useState(null),[i,o]=S.useState(!0),[l,f]=S.useState(null),[d,h]=S.useState(!1);return S.useEffect(()=>{async function v(){try{o(!0),f(null);const m=sessionStorage.getItem("wraps-auth-token");if(!m)throw new Error("Authentication token not found");const g=await fetch(`/api/inbound/${encodeURIComponent(e||"")}?token=${m}`);if(!g.ok){let O="Failed to fetch inbound email";try{O=(await g.json()).error||O}catch{O=`${g.status}: ${g.statusText}`}throw new Error(O)}const x=await g.json();r(x)}catch(m){const g=m instanceof Error?m.message:"Unknown error";f(g),console.error("Error fetching inbound email:",m)}finally{o(!1)}}e&&v()},[e]),i?c.jsx("div",{className:"flex h-[600px] items-center justify-center",children:c.jsx("div",{className:"text-muted-foreground",children:"Loading inbound email..."})}):l?c.jsxs("div",{className:"space-y-4",children:[c.jsxs(Ce,{onClick:()=>t("/email?tab=receiving"),size:"sm",variant:"ghost",children:[c.jsx(Za,{className:"mr-2 h-4 w-4"}),"Back to emails"]}),c.jsx("div",{className:"rounded-md border border-destructive bg-destructive/10 p-4 text-destructive text-sm",children:l})]}):n?c.jsxs("div",{className:"space-y-6",children:[c.jsx("div",{className:"flex items-center gap-4",children:c.jsxs(Ce,{onClick:()=>t("/email?tab=receiving"),size:"sm",variant:"ghost",children:[c.jsx(Za,{className:"mr-2 h-4 w-4"}),"Back"]})}),c.jsx(Te,{children:c.jsxs(Me,{className:"space-y-1.5",children:[c.jsx(Le,{className:"flex flex-row items-center gap-2 text-xl",children:c.jsx("span",{children:n.subject||"(no subject)"})}),c.jsxs("div",{className:"flex flex-wrap gap-2",children:[c.jsx(Gh,{label:"Spam",verdict:n.spamVerdict}),c.jsx(Gh,{label:"Virus",verdict:n.virusVerdict}),n.headers["x-ses-dkim-verdict"]&&c.jsx(Gh,{label:"DKIM",verdict:n.headers["x-ses-dkim-verdict"]}),n.headers["x-ses-spf-verdict"]&&c.jsx(Gh,{label:"SPF",verdict:n.headers["x-ses-spf-verdict"]})]}),c.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[c.jsx("code",{className:"min-w-0 truncate rounded bg-muted px-2 py-0.5 font-mono text-muted-foreground text-xs",children:n.messageId}),c.jsx(ma,{className:"h-6 w-6 shrink-0",size:"sm",value:n.messageId,variant:"ghost"})]}),c.jsxs("div",{className:"flex flex-col gap-3 pt-2 sm:flex-row sm:flex-wrap",children:[c.jsxs(Cl,{className:"w-full cursor-text! sm:w-auto sm:min-w-[518px]",children:[c.jsx(ca,{align:"inline-start",children:c.jsx(Tl,{children:"From"})}),c.jsx(Ml,{className:"min-w-0 cursor-text! truncate font-mono text-sm",disabled:!0,readOnly:!0,value:B1(n.from)}),c.jsx(ca,{align:"inline-end",children:c.jsx(ma,{className:"h-6 w-6",size:"sm",value:n.from.address,variant:"ghost"})})]}),c.jsxs(Cl,{className:"w-full cursor-text! sm:w-auto sm:min-w-[518px]",children:[c.jsx(ca,{align:"inline-start",children:c.jsx(Tl,{children:"To"})}),c.jsx(Ml,{className:"min-w-0 cursor-text! truncate font-mono text-sm",disabled:!0,readOnly:!0,value:n.to.length>0?n.to.map(B1).join(", "):"(no recipients)"})]}),n.cc.length>0&&c.jsxs(Cl,{className:"w-full cursor-text! sm:w-auto sm:min-w-[518px]",children:[c.jsx(ca,{align:"inline-start",children:c.jsx(Tl,{children:"CC"})}),c.jsx(Ml,{className:"min-w-0 cursor-text! truncate font-mono text-sm",disabled:!0,readOnly:!0,value:n.cc.map(B1).join(", ")})]})]}),c.jsxs("div",{className:"text-muted-foreground text-sm",children:["Received: ",new Date(n.receivedAt).toLocaleString()]})]})}),c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(Le,{children:"Message Body"}),n.htmlTruncated&&c.jsx(We,{className:"text-amber-600",children:"HTML content was truncated due to size limits"})]}),c.jsx($e,{children:n.html?c.jsx("iframe",{className:"h-[500px] w-full rounded-md border bg-white",sandbox:"allow-same-origin",srcDoc:n.html,title:"Email content"}):n.text?c.jsx("pre",{className:"max-h-[500px] overflow-auto whitespace-pre-wrap rounded-md border bg-muted/50 p-4 font-mono text-sm",children:n.text}):c.jsx("div",{className:"text-muted-foreground text-sm",children:"No message body"})})]}),n.attachments.length>0&&c.jsxs(Te,{children:[c.jsx(Me,{children:c.jsxs(Le,{className:"flex items-center gap-2",children:[c.jsx(g$,{className:"h-4 w-4"}),"Attachments (",n.attachments.length,")"]})}),c.jsx($e,{children:c.jsx("div",{className:"space-y-2",children:n.attachments.map(v=>c.jsx("div",{className:"flex items-center justify-between rounded-md border p-3",children:c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx(p$,{className:"h-5 w-5 text-muted-foreground"}),c.jsxs("div",{children:[c.jsx("div",{className:"font-medium text-sm",children:v.filename}),c.jsxs("div",{className:"text-muted-foreground text-xs",children:[v.contentType," · ",qge(v.size),v.contentDisposition==="inline"&&c.jsx(Be,{className:"ml-2 bg-blue-500/10 text-blue-700 dark:text-blue-400 border-blue-500/20",variant:"outline",children:"inline"})]})]})]})},v.id))})})]}),c.jsx(ms,{onOpenChange:h,open:d,children:c.jsxs(Te,{children:[c.jsx(ps,{asChild:!0,children:c.jsx(Me,{className:"cursor-pointer",children:c.jsxs(Le,{className:"flex items-center justify-between",children:[c.jsx("span",{children:"Raw Headers"}),d?c.jsx(ac,{className:"h-4 w-4"}):c.jsx(oo,{className:"h-4 w-4"})]})})}),c.jsx(vs,{children:c.jsx($e,{children:c.jsx("pre",{className:"max-h-[400px] overflow-auto whitespace-pre-wrap rounded-md border bg-muted/50 p-4 font-mono text-xs",children:Object.entries(n.headers).map(([v,m])=>`${v}: ${m}`).join(`
126
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function G6(e,t){if(e){if(typeof e=="string")return Dj(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n==="Object"&&e.constructor&&(n=e.constructor.name),n==="Map"||n==="Set")return Array.from(e);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Dj(e,t)}}function qve(e){if(typeof Symbol<"u"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function Uve(e){if(Array.isArray(e))return Dj(e)}function Dj(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function z4(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),n.push.apply(n,r)}return n}function fe(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?z4(Object(n),!0).forEach(function(r){ke(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):z4(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function ke(e,t,n){return t=V6(t),t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function V6(e){var t=Hve(e,"string");return tc(t)=="symbol"?t:t+""}function Hve(e,t){if(tc(e)!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(tc(r)!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}var Fve={xAxis:["bottom","top"],yAxis:["left","right"]},Gve={width:"100%",height:"100%"},Y6={x:0,y:0};function Hh(e){return e}var Vve=function(t,n){return n==="horizontal"?t.x:n==="vertical"?t.y:n==="centric"?t.angle:t.radius},Yve=function(t,n,r,i){var o=n.find(function(v){return v&&v.index===r});if(o){if(t==="horizontal")return{x:o.coordinate,y:i.y};if(t==="vertical")return{x:i.x,y:o.coordinate};if(t==="centric"){var l=o.coordinate,f=i.radius;return fe(fe(fe({},i),pn(i.cx,i.cy,f,l)),{},{angle:l,radius:f})}var d=o.coordinate,h=i.angle;return fe(fe(fe({},i),pn(i.cx,i.cy,d,h)),{},{angle:h,radius:d})}return Y6},Kv=function(t,n){var r=n.graphicalItems,i=n.dataStartIndex,o=n.dataEndIndex,l=(r??[]).reduce(function(f,d){var h=d.props.data;return h&&h.length?[].concat(nc(f),nc(h)):f},[]);return l.length>0?l:t&&t.length&&xe(i)&&xe(o)?t.slice(i,o+1):[]};function W6(e){return e==="number"?[0,"auto"]:void 0}var Pj=function(t,n,r,i){var o=t.graphicalItems,l=t.tooltipAxis,f=Kv(n,t);return r<0||!o||!o.length||r>=f.length?null:o.reduce(function(d,h){var v,m=(v=h.props.data)!==null&&v!==void 0?v:n;m&&t.dataStartIndex+t.dataEndIndex!==0&&t.dataEndIndex-t.dataStartIndex>=r&&(m=m.slice(t.dataStartIndex,t.dataEndIndex+1));var g;if(l.dataKey&&!l.allowDuplicatedCategory){var x=m===void 0?f:m;g=Nm(x,l.dataKey,i)}else g=m&&m[r]||f[r];return g?[].concat(nc(d),[WB(h,g)]):d},[])},B4=function(t,n,r,i){var o=i||{x:t.chartX,y:t.chartY},l=Vve(o,r),f=t.orderedTooltipTicks,d=t.tooltipAxis,h=t.tooltipTicks,v=rce(l,f,h,d);if(v>=0&&h){var m=h[v]&&h[v].value,g=Pj(t,n,v,m),x=Yve(r,f,v,o);return{activeTooltipIndex:v,activeLabel:m,activePayload:g,activeCoordinate:x}}return null},Wve=function(t,n){var r=n.axes,i=n.graphicalItems,o=n.axisType,l=n.axisIdKey,f=n.stackGroups,d=n.dataStartIndex,h=n.dataEndIndex,v=t.layout,m=t.children,g=t.stackOffset,x=GB(v,o);return r.reduce(function(O,j){var b,E=j.type.defaultProps!==void 0?fe(fe({},j.type.defaultProps),j.props):j.props,_=E.type,A=E.dataKey,C=E.allowDataOverflow,N=E.allowDuplicatedCategory,M=E.scale,R=E.ticks,D=E.includeHidden,L=E[l];if(O[L])return O;var H=Kv(t.data,{graphicalItems:i.filter(function(G){var $,W=l in G.props?G.props[l]:($=G.type.defaultProps)===null||$===void 0?void 0:$[l];return W===L}),dataStartIndex:d,dataEndIndex:h}),B=H.length,U,Y,Z;bve(E.domain,C,_)&&(U=QS(E.domain,null,C),x&&(_==="number"||M!=="auto")&&(Z=Lu(H,A,"category")));var X=W6(_);if(!U||U.length===0){var k,q=(k=E.domain)!==null&&k!==void 0?k:X;if(A){if(U=Lu(H,A,_),_==="category"&&x){var V=Wee(U);N&&V?(Y=U,U=fp(0,B)):N||(U=ek(q,U,j).reduce(function(G,$){return G.indexOf($)>=0?G:[].concat(nc(G),[$])},[]))}else if(_==="category")N?U=U.filter(function(G){return G!==""&&!Qe(G)}):U=ek(q,U,j).reduce(function(G,$){return G.indexOf($)>=0||$===""||Qe($)?G:[].concat(nc(G),[$])},[]);else if(_==="number"){var Q=lce(H,i.filter(function(G){var $,W,ae=l in G.props?G.props[l]:($=G.type.defaultProps)===null||$===void 0?void 0:$[l],ce="hide"in G.props?G.props.hide:(W=G.type.defaultProps)===null||W===void 0?void 0:W.hide;return ae===L&&(D||!ce)}),A,o,v);Q&&(U=Q)}x&&(_==="number"||M!=="auto")&&(Z=Lu(H,A,"category"))}else x?U=fp(0,B):f&&f[L]&&f[L].hasStack&&_==="number"?U=g==="expand"?[0,1]:YB(f[L].stackGroups,d,h):U=FB(H,i.filter(function(G){var $=l in G.props?G.props[l]:G.type.defaultProps[l],W="hide"in G.props?G.props.hide:G.type.defaultProps.hide;return $===L&&(D||!W)}),_,v,!0);if(_==="number")U=Mj(m,U,L,o,R),q&&(U=QS(q,U,C));else if(_==="category"&&q){var ee=q,z=U.every(function(G){return ee.indexOf(G)>=0});z&&(U=ee)}}return fe(fe({},O),{},ke({},L,fe(fe({},E),{},{axisType:o,domain:U,categoricalDomain:Z,duplicateDomain:Y,originalDomain:(b=E.domain)!==null&&b!==void 0?b:X,isCategorical:x,layout:v})))},{})},Kve=function(t,n){var r=n.graphicalItems,i=n.Axis,o=n.axisType,l=n.axisIdKey,f=n.stackGroups,d=n.dataStartIndex,h=n.dataEndIndex,v=t.layout,m=t.children,g=Kv(t.data,{graphicalItems:r,dataStartIndex:d,dataEndIndex:h}),x=g.length,O=GB(v,o),j=-1;return r.reduce(function(b,E){var _=E.type.defaultProps!==void 0?fe(fe({},E.type.defaultProps),E.props):E.props,A=_[l],C=W6("number");if(!b[A]){j++;var N;return O?N=fp(0,x):f&&f[A]&&f[A].hasStack?(N=YB(f[A].stackGroups,d,h),N=Mj(m,N,A,o)):(N=QS(C,FB(g,r.filter(function(M){var R,D,L=l in M.props?M.props[l]:(R=M.type.defaultProps)===null||R===void 0?void 0:R[l],H="hide"in M.props?M.props.hide:(D=M.type.defaultProps)===null||D===void 0?void 0:D.hide;return L===A&&!H}),"number",v),i.defaultProps.allowDataOverflow),N=Mj(m,N,A,o)),fe(fe({},b),{},ke({},A,fe(fe({axisType:o},i.defaultProps),{},{hide:!0,orientation:Mr(Fve,"".concat(o,".").concat(j%2),null),domain:N,originalDomain:C,isCategorical:O,layout:v})))}return b},{})},Xve=function(t,n){var r=n.axisType,i=r===void 0?"xAxis":r,o=n.AxisComp,l=n.graphicalItems,f=n.stackGroups,d=n.dataStartIndex,h=n.dataEndIndex,v=t.children,m="".concat(i,"Id"),g=Rr(v,o),x={};return g&&g.length?x=Wve(t,{axes:g,graphicalItems:l,axisType:i,axisIdKey:m,stackGroups:f,dataStartIndex:d,dataEndIndex:h}):l&&l.length&&(x=Kve(t,{Axis:o,graphicalItems:l,axisType:i,axisIdKey:m,stackGroups:f,dataStartIndex:d,dataEndIndex:h})),x},Qve=function(t){var n=Ki(t),r=Qa(n,!1,!0);return{tooltipTicks:r,orderedTooltipTicks:oE(r,function(i){return i.coordinate}),tooltipAxis:n,tooltipAxisBandSize:tp(n,r)}},q4=function(t){var n=t.children,r=t.defaultShowTooltip,i=rr(n,Vl),o=0,l=0;return t.data&&t.data.length!==0&&(l=t.data.length-1),i&&i.props&&(i.props.startIndex>=0&&(o=i.props.startIndex),i.props.endIndex>=0&&(l=i.props.endIndex)),{chartX:0,chartY:0,dataStartIndex:o,dataEndIndex:l,activeTooltipIndex:-1,isTooltipActive:!!r}},Zve=function(t){return!t||!t.length?!1:t.some(function(n){var r=ei(n&&n.type);return r&&r.indexOf("Bar")>=0})},U4=function(t){return t==="horizontal"?{numericAxisName:"yAxis",cateAxisName:"xAxis"}:t==="vertical"?{numericAxisName:"xAxis",cateAxisName:"yAxis"}:t==="centric"?{numericAxisName:"radiusAxis",cateAxisName:"angleAxis"}:{numericAxisName:"angleAxis",cateAxisName:"radiusAxis"}},Jve=function(t,n){var r=t.props,i=t.graphicalItems,o=t.xAxisMap,l=o===void 0?{}:o,f=t.yAxisMap,d=f===void 0?{}:f,h=r.width,v=r.height,m=r.children,g=r.margin||{},x=rr(m,Vl),O=rr(m,ni),j=Object.keys(d).reduce(function(N,M){var R=d[M],D=R.orientation;return!R.mirror&&!R.hide?fe(fe({},N),{},ke({},D,N[D]+R.width)):N},{left:g.left||0,right:g.right||0}),b=Object.keys(l).reduce(function(N,M){var R=l[M],D=R.orientation;return!R.mirror&&!R.hide?fe(fe({},N),{},ke({},D,Mr(N,"".concat(D))+R.height)):N},{top:g.top||0,bottom:g.bottom||0}),E=fe(fe({},b),j),_=E.bottom;x&&(E.bottom+=x.props.height||Vl.defaultProps.height),O&&n&&(E=oce(E,i,r,n));var A=h-E.left-E.right,C=v-E.top-E.bottom;return fe(fe({brushBottom:_},E),{},{width:Math.max(A,0),height:Math.max(C,0)})},ege=function(t,n){if(n==="xAxis")return t[n].width;if(n==="yAxis")return t[n].height},K6=function(t){var n=t.chartName,r=t.GraphicalChild,i=t.defaultTooltipEventType,o=i===void 0?"axis":i,l=t.validateTooltipEventTypes,f=l===void 0?["axis"]:l,d=t.axisComponents,h=t.legendContent,v=t.formatAxisMap,m=t.defaultProps,g=function(E,_){var A=_.graphicalItems,C=_.stackGroups,N=_.offset,M=_.updateId,R=_.dataStartIndex,D=_.dataEndIndex,L=E.barSize,H=E.layout,B=E.barGap,U=E.barCategoryGap,Y=E.maxBarSize,Z=U4(H),X=Z.numericAxisName,k=Z.cateAxisName,q=Zve(A),V=[];return A.forEach(function(Q,ee){var z=Kv(E.data,{graphicalItems:[Q],dataStartIndex:R,dataEndIndex:D}),G=Q.type.defaultProps!==void 0?fe(fe({},Q.type.defaultProps),Q.props):Q.props,$=G.dataKey,W=G.maxBarSize,ae=G["".concat(X,"Id")],ce=G["".concat(k,"Id")],oe={},me=d.reduce(function(Yn,Rt){var dr=_["".concat(Rt.axisType,"Map")],tn=G["".concat(Rt.axisType,"Id")];dr&&dr[tn]||Rt.axisType==="zAxis"||ss();var Ss=dr[tn];return fe(fe({},Yn),{},ke(ke({},Rt.axisType,Ss),"".concat(Rt.axisType,"Ticks"),Qa(Ss)))},oe),ie=me[k],ve=me["".concat(k,"Ticks")],ye=C&&C[ae]&&C[ae].hasStack&&bce(Q,C[ae].stackGroups),le=ei(Q.type).indexOf("Bar")>=0,Re=tp(ie,ve),be=[],qe=q&&ace({barSize:L,stackGroups:C,totalSize:ege(me,k)});if(le){var rt,mt,vn=Qe(W)?Y:W,Mt=(rt=(mt=tp(ie,ve,!0))!==null&&mt!==void 0?mt:vn)!==null&&rt!==void 0?rt:0;be=ice({barGap:B,barCategoryGap:U,bandSize:Mt!==Re?Mt:Re,sizeList:qe[ce],maxBarSize:vn}),Mt!==Re&&(be=be.map(function(Yn){return fe(fe({},Yn),{},{position:fe(fe({},Yn.position),{},{offset:Yn.position.offset-Mt/2})})}))}var fr=Q&&Q.type&&Q.type.getComposedData;fr&&V.push({props:fe(fe({},fr(fe(fe({},me),{},{displayedData:z,props:E,dataKey:$,item:Q,bandSize:Re,barPosition:be,offset:N,stackedData:ye,layout:H,dataStartIndex:R,dataEndIndex:D}))),{},ke(ke(ke({key:Q.key||"item-".concat(ee)},X,me[X]),k,me[k]),"animationId",M)),childIndex:ste(Q,E.children),item:Q})}),V},x=function(E,_){var A=E.props,C=E.dataStartIndex,N=E.dataEndIndex,M=E.updateId;if(!mM({props:A}))return null;var R=A.children,D=A.layout,L=A.stackOffset,H=A.data,B=A.reverseStackOrder,U=U4(D),Y=U.numericAxisName,Z=U.cateAxisName,X=Rr(R,r),k=gce(H,X,"".concat(Y,"Id"),"".concat(Z,"Id"),L,B),q=d.reduce(function(G,$){var W="".concat($.axisType,"Map");return fe(fe({},G),{},ke({},W,Xve(A,fe(fe({},$),{},{graphicalItems:X,stackGroups:$.axisType===Y&&k,dataStartIndex:C,dataEndIndex:N}))))},{}),V=Jve(fe(fe({},q),{},{props:A,graphicalItems:X}),_?.legendBBox);Object.keys(q).forEach(function(G){q[G]=v(A,q[G],V,G.replace("Map",""),n)});var Q=q["".concat(Z,"Map")],ee=Qve(Q),z=g(A,fe(fe({},q),{},{dataStartIndex:C,dataEndIndex:N,updateId:M,graphicalItems:X,stackGroups:k,offset:V}));return fe(fe({formattedGraphicalItems:z,graphicalItems:X,offset:V,stackGroups:k},ee),q)},O=(function(b){function E(_){var A,C,N;return Dve(this,E),N=$ve(this,E,[_]),ke(N,"eventEmitterSymbol",Symbol("rechartsEventEmitter")),ke(N,"accessibilityManager",new xve),ke(N,"handleLegendBBoxUpdate",function(M){if(M){var R=N.state,D=R.dataStartIndex,L=R.dataEndIndex,H=R.updateId;N.setState(fe({legendBBox:M},x({props:N.props,dataStartIndex:D,dataEndIndex:L,updateId:H},fe(fe({},N.state),{},{legendBBox:M}))))}}),ke(N,"handleReceiveSyncEvent",function(M,R,D){if(N.props.syncId===M){if(D===N.eventEmitterSymbol&&typeof N.props.syncMethod!="function")return;N.applySyncEvent(R)}}),ke(N,"handleBrushChange",function(M){var R=M.startIndex,D=M.endIndex;if(R!==N.state.dataStartIndex||D!==N.state.dataEndIndex){var L=N.state.updateId;N.setState(function(){return fe({dataStartIndex:R,dataEndIndex:D},x({props:N.props,dataStartIndex:R,dataEndIndex:D,updateId:L},N.state))}),N.triggerSyncEvent({dataStartIndex:R,dataEndIndex:D})}}),ke(N,"handleMouseEnter",function(M){var R=N.getMouseInfo(M);if(R){var D=fe(fe({},R),{},{isTooltipActive:!0});N.setState(D),N.triggerSyncEvent(D);var L=N.props.onMouseEnter;Ye(L)&&L(D,M)}}),ke(N,"triggeredAfterMouseMove",function(M){var R=N.getMouseInfo(M),D=R?fe(fe({},R),{},{isTooltipActive:!0}):{isTooltipActive:!1};N.setState(D),N.triggerSyncEvent(D);var L=N.props.onMouseMove;Ye(L)&&L(D,M)}),ke(N,"handleItemMouseEnter",function(M){N.setState(function(){return{isTooltipActive:!0,activeItem:M,activePayload:M.tooltipPayload,activeCoordinate:M.tooltipPosition||{x:M.cx,y:M.cy}}})}),ke(N,"handleItemMouseLeave",function(){N.setState(function(){return{isTooltipActive:!1}})}),ke(N,"handleMouseMove",function(M){M.persist(),N.throttleTriggeredAfterMouseMove(M)}),ke(N,"handleMouseLeave",function(M){N.throttleTriggeredAfterMouseMove.cancel();var R={isTooltipActive:!1};N.setState(R),N.triggerSyncEvent(R);var D=N.props.onMouseLeave;Ye(D)&&D(R,M)}),ke(N,"handleOuterEvent",function(M){var R=ote(M),D=Mr(N.props,"".concat(R));if(R&&Ye(D)){var L,H;/.*touch.*/i.test(R)?H=N.getMouseInfo(M.changedTouches[0]):H=N.getMouseInfo(M),D((L=H)!==null&&L!==void 0?L:{},M)}}),ke(N,"handleClick",function(M){var R=N.getMouseInfo(M);if(R){var D=fe(fe({},R),{},{isTooltipActive:!0});N.setState(D),N.triggerSyncEvent(D);var L=N.props.onClick;Ye(L)&&L(D,M)}}),ke(N,"handleMouseDown",function(M){var R=N.props.onMouseDown;if(Ye(R)){var D=N.getMouseInfo(M);R(D,M)}}),ke(N,"handleMouseUp",function(M){var R=N.props.onMouseUp;if(Ye(R)){var D=N.getMouseInfo(M);R(D,M)}}),ke(N,"handleTouchMove",function(M){M.changedTouches!=null&&M.changedTouches.length>0&&N.throttleTriggeredAfterMouseMove(M.changedTouches[0])}),ke(N,"handleTouchStart",function(M){M.changedTouches!=null&&M.changedTouches.length>0&&N.handleMouseDown(M.changedTouches[0])}),ke(N,"handleTouchEnd",function(M){M.changedTouches!=null&&M.changedTouches.length>0&&N.handleMouseUp(M.changedTouches[0])}),ke(N,"handleDoubleClick",function(M){var R=N.props.onDoubleClick;if(Ye(R)){var D=N.getMouseInfo(M);R(D,M)}}),ke(N,"handleContextMenu",function(M){var R=N.props.onContextMenu;if(Ye(R)){var D=N.getMouseInfo(M);R(D,M)}}),ke(N,"triggerSyncEvent",function(M){N.props.syncId!==void 0&&k1.emit($1,N.props.syncId,M,N.eventEmitterSymbol)}),ke(N,"applySyncEvent",function(M){var R=N.props,D=R.layout,L=R.syncMethod,H=N.state.updateId,B=M.dataStartIndex,U=M.dataEndIndex;if(M.dataStartIndex!==void 0||M.dataEndIndex!==void 0)N.setState(fe({dataStartIndex:B,dataEndIndex:U},x({props:N.props,dataStartIndex:B,dataEndIndex:U,updateId:H},N.state)));else if(M.activeTooltipIndex!==void 0){var Y=M.chartX,Z=M.chartY,X=M.activeTooltipIndex,k=N.state,q=k.offset,V=k.tooltipTicks;if(!q)return;if(typeof L=="function")X=L(V,M);else if(L==="value"){X=-1;for(var Q=0;Q<V.length;Q++)if(V[Q].value===M.activeLabel){X=Q;break}}var ee=fe(fe({},q),{},{x:q.left,y:q.top}),z=Math.min(Y,ee.x+ee.width),G=Math.min(Z,ee.y+ee.height),$=V[X]&&V[X].value,W=Pj(N.state,N.props.data,X),ae=V[X]?{x:D==="horizontal"?V[X].coordinate:z,y:D==="horizontal"?G:V[X].coordinate}:Y6;N.setState(fe(fe({},M),{},{activeLabel:$,activeCoordinate:ae,activePayload:W,activeTooltipIndex:X}))}else N.setState(M)}),ke(N,"renderCursor",function(M){var R,D=N.state,L=D.isTooltipActive,H=D.activeCoordinate,B=D.activePayload,U=D.offset,Y=D.activeTooltipIndex,Z=D.tooltipAxisBandSize,X=N.getTooltipEventType(),k=(R=M.props.active)!==null&&R!==void 0?R:L,q=N.props.layout,V=M.key||"_recharts-cursor";return I.createElement(_ve,{key:V,activeCoordinate:H,activePayload:B,activeTooltipIndex:Y,chartName:n,element:M,isActive:k,layout:q,offset:U,tooltipAxisBandSize:Z,tooltipEventType:X})}),ke(N,"renderPolarAxis",function(M,R,D){var L=Mr(M,"type.axisType"),H=Mr(N.state,"".concat(L,"Map")),B=M.type.defaultProps,U=B!==void 0?fe(fe({},B),M.props):M.props,Y=H&&H[U["".concat(L,"Id")]];return S.cloneElement(M,fe(fe({},Y),{},{className:et(L,Y.className),key:M.key||"".concat(R,"-").concat(D),ticks:Qa(Y,!0)}))}),ke(N,"renderPolarGrid",function(M){var R=M.props,D=R.radialLines,L=R.polarAngles,H=R.polarRadius,B=N.state,U=B.radiusAxisMap,Y=B.angleAxisMap,Z=Ki(U),X=Ki(Y),k=X.cx,q=X.cy,V=X.innerRadius,Q=X.outerRadius;return S.cloneElement(M,{polarAngles:Array.isArray(L)?L:Qa(X,!0).map(function(ee){return ee.coordinate}),polarRadius:Array.isArray(H)?H:Qa(Z,!0).map(function(ee){return ee.coordinate}),cx:k,cy:q,innerRadius:V,outerRadius:Q,key:M.key||"polar-grid",radialLines:D})}),ke(N,"renderLegend",function(){var M=N.state.formattedGraphicalItems,R=N.props,D=R.children,L=R.width,H=R.height,B=N.props.margin||{},U=L-(B.left||0)-(B.right||0),Y=UB({children:D,formattedGraphicalItems:M,legendWidth:U,legendContent:h});if(!Y)return null;var Z=Y.item,X=L4(Y,Ave);return S.cloneElement(Z,fe(fe({},X),{},{chartWidth:L,chartHeight:H,margin:B,onBBoxUpdate:N.handleLegendBBoxUpdate}))}),ke(N,"renderTooltip",function(){var M,R=N.props,D=R.children,L=R.accessibilityLayer,H=rr(D,_r);if(!H)return null;var B=N.state,U=B.isTooltipActive,Y=B.activeCoordinate,Z=B.activePayload,X=B.activeLabel,k=B.offset,q=(M=H.props.active)!==null&&M!==void 0?M:U;return S.cloneElement(H,{viewBox:fe(fe({},k),{},{x:k.left,y:k.top}),active:q,label:X,payload:q?Z:[],coordinate:Y,accessibilityLayer:L})}),ke(N,"renderBrush",function(M){var R=N.props,D=R.margin,L=R.data,H=N.state,B=H.offset,U=H.dataStartIndex,Y=H.dataEndIndex,Z=H.updateId;return S.cloneElement(M,{key:M.key||"_recharts-brush",onChange:Lh(N.handleBrushChange,M.props.onChange),data:L,x:xe(M.props.x)?M.props.x:B.left,y:xe(M.props.y)?M.props.y:B.top+B.height+B.brushBottom-(D.bottom||0),width:xe(M.props.width)?M.props.width:B.width,startIndex:U,endIndex:Y,updateId:"brush-".concat(Z)})}),ke(N,"renderReferenceElement",function(M,R,D){if(!M)return null;var L=N,H=L.clipPathId,B=N.state,U=B.xAxisMap,Y=B.yAxisMap,Z=B.offset,X=M.type.defaultProps||{},k=M.props,q=k.xAxisId,V=q===void 0?X.xAxisId:q,Q=k.yAxisId,ee=Q===void 0?X.yAxisId:Q;return S.cloneElement(M,{key:M.key||"".concat(R,"-").concat(D),xAxis:U[V],yAxis:Y[ee],viewBox:{x:Z.left,y:Z.top,width:Z.width,height:Z.height},clipPathId:H})}),ke(N,"renderActivePoints",function(M){var R=M.item,D=M.activePoint,L=M.basePoint,H=M.childIndex,B=M.isRange,U=[],Y=R.props.key,Z=R.item.type.defaultProps!==void 0?fe(fe({},R.item.type.defaultProps),R.item.props):R.item.props,X=Z.activeDot,k=Z.dataKey,q=fe(fe({index:H,dataKey:k,cx:D.x,cy:D.y,r:4,fill:DE(R.item),strokeWidth:2,stroke:"#fff",payload:D.payload,value:D.value},nt(X,!1)),Cm(X));return U.push(E.renderActiveDot(X,q,"".concat(Y,"-activePoint-").concat(H))),L?U.push(E.renderActiveDot(X,fe(fe({},q),{},{cx:L.x,cy:L.y}),"".concat(Y,"-basePoint-").concat(H))):B&&U.push(null),U}),ke(N,"renderGraphicChild",function(M,R,D){var L=N.filterFormatItem(M,R,D);if(!L)return null;var H=N.getTooltipEventType(),B=N.state,U=B.isTooltipActive,Y=B.tooltipAxis,Z=B.activeTooltipIndex,X=B.activeLabel,k=N.props.children,q=rr(k,_r),V=L.props,Q=V.points,ee=V.isRange,z=V.baseLine,G=L.item.type.defaultProps!==void 0?fe(fe({},L.item.type.defaultProps),L.item.props):L.item.props,$=G.activeDot,W=G.hide,ae=G.activeBar,ce=G.activeShape,oe=!!(!W&&U&&q&&($||ae||ce)),me={};H!=="axis"&&q&&q.props.trigger==="click"?me={onClick:Lh(N.handleItemMouseEnter,M.props.onClick)}:H!=="axis"&&(me={onMouseLeave:Lh(N.handleItemMouseLeave,M.props.onMouseLeave),onMouseEnter:Lh(N.handleItemMouseEnter,M.props.onMouseEnter)});var ie=S.cloneElement(M,fe(fe({},L.props),me));function ve(Rt){return typeof Y.dataKey=="function"?Y.dataKey(Rt.payload):null}if(oe)if(Z>=0){var ye,le;if(Y.dataKey&&!Y.allowDuplicatedCategory){var Re=typeof Y.dataKey=="function"?ve:"payload.".concat(Y.dataKey.toString());ye=Nm(Q,Re,X),le=ee&&z&&Nm(z,Re,X)}else ye=Q?.[Z],le=ee&&z&&z[Z];if(ce||ae){var be=M.props.activeIndex!==void 0?M.props.activeIndex:Z;return[S.cloneElement(M,fe(fe(fe({},L.props),me),{},{activeIndex:be})),null,null]}if(!Qe(ye))return[ie].concat(nc(N.renderActivePoints({item:L,activePoint:ye,basePoint:le,childIndex:Z,isRange:ee})))}else{var qe,rt=(qe=N.getItemByXY(N.state.activeCoordinate))!==null&&qe!==void 0?qe:{graphicalItem:ie},mt=rt.graphicalItem,vn=mt.item,Mt=vn===void 0?M:vn,fr=mt.childIndex,Yn=fe(fe(fe({},L.props),me),{},{activeIndex:fr});return[S.cloneElement(Mt,Yn),null,null]}return ee?[ie,null,null]:[ie,null]}),ke(N,"renderCustomized",function(M,R,D){return S.cloneElement(M,fe(fe({key:"recharts-customized-".concat(D)},N.props),N.state))}),ke(N,"renderMap",{CartesianGrid:{handler:Hh,once:!0},ReferenceArea:{handler:N.renderReferenceElement},ReferenceLine:{handler:Hh},ReferenceDot:{handler:N.renderReferenceElement},XAxis:{handler:Hh},YAxis:{handler:Hh},Brush:{handler:N.renderBrush,once:!0},Bar:{handler:N.renderGraphicChild},Line:{handler:N.renderGraphicChild},Area:{handler:N.renderGraphicChild},Radar:{handler:N.renderGraphicChild},RadialBar:{handler:N.renderGraphicChild},Scatter:{handler:N.renderGraphicChild},Pie:{handler:N.renderGraphicChild},Funnel:{handler:N.renderGraphicChild},Tooltip:{handler:N.renderCursor,once:!0},PolarGrid:{handler:N.renderPolarGrid,once:!0},PolarAngleAxis:{handler:N.renderPolarAxis},PolarRadiusAxis:{handler:N.renderPolarAxis},Customized:{handler:N.renderCustomized}}),N.clipPathId="".concat((A=_.id)!==null&&A!==void 0?A:Xf("recharts"),"-clip"),N.throttleTriggeredAfterMouseMove=qz(N.triggeredAfterMouseMove,(C=_.throttleDelay)!==null&&C!==void 0?C:1e3/60),N.state={},N}return zve(E,b),kve(E,[{key:"componentDidMount",value:function(){var A,C;this.addListener(),this.accessibilityManager.setDetails({container:this.container,offset:{left:(A=this.props.margin.left)!==null&&A!==void 0?A:0,top:(C=this.props.margin.top)!==null&&C!==void 0?C:0},coordinateList:this.state.tooltipTicks,mouseHandlerCallback:this.triggeredAfterMouseMove,layout:this.props.layout}),this.displayDefaultTooltip()}},{key:"displayDefaultTooltip",value:function(){var A=this.props,C=A.children,N=A.data,M=A.height,R=A.layout,D=rr(C,_r);if(D){var L=D.props.defaultIndex;if(!(typeof L!="number"||L<0||L>this.state.tooltipTicks.length-1)){var H=this.state.tooltipTicks[L]&&this.state.tooltipTicks[L].value,B=Pj(this.state,N,L,H),U=this.state.tooltipTicks[L].coordinate,Y=(this.state.offset.top+M)/2,Z=R==="horizontal",X=Z?{x:U,y:Y}:{y:U,x:Y},k=this.state.formattedGraphicalItems.find(function(V){var Q=V.item;return Q.type.name==="Scatter"});k&&(X=fe(fe({},X),k.props.points[L].tooltipPosition),B=k.props.points[L].tooltipPayload);var q={activeTooltipIndex:L,isTooltipActive:!0,activeLabel:H,activePayload:B,activeCoordinate:X};this.setState(q),this.renderCursor(D),this.accessibilityManager.setIndex(L)}}}},{key:"getSnapshotBeforeUpdate",value:function(A,C){if(!this.props.accessibilityLayer)return null;if(this.state.tooltipTicks!==C.tooltipTicks&&this.accessibilityManager.setDetails({coordinateList:this.state.tooltipTicks}),this.props.layout!==A.layout&&this.accessibilityManager.setDetails({layout:this.props.layout}),this.props.margin!==A.margin){var N,M;this.accessibilityManager.setDetails({offset:{left:(N=this.props.margin.left)!==null&&N!==void 0?N:0,top:(M=this.props.margin.top)!==null&&M!==void 0?M:0}})}return null}},{key:"componentDidUpdate",value:function(A){xS([rr(A.children,_r)],[rr(this.props.children,_r)])||this.displayDefaultTooltip()}},{key:"componentWillUnmount",value:function(){this.removeListener(),this.throttleTriggeredAfterMouseMove.cancel()}},{key:"getTooltipEventType",value:function(){var A=rr(this.props.children,_r);if(A&&typeof A.props.shared=="boolean"){var C=A.props.shared?"axis":"item";return f.indexOf(C)>=0?C:o}return o}},{key:"getMouseInfo",value:function(A){if(!this.container)return null;var C=this.container,N=C.getBoundingClientRect(),M=Yae(N),R={chartX:Math.round(A.pageX-M.left),chartY:Math.round(A.pageY-M.top)},D=N.width/C.offsetWidth||1,L=this.inRange(R.chartX,R.chartY,D);if(!L)return null;var H=this.state,B=H.xAxisMap,U=H.yAxisMap,Y=this.getTooltipEventType(),Z=B4(this.state,this.props.data,this.props.layout,L);if(Y!=="axis"&&B&&U){var X=Ki(B).scale,k=Ki(U).scale,q=X&&X.invert?X.invert(R.chartX):null,V=k&&k.invert?k.invert(R.chartY):null;return fe(fe({},R),{},{xValue:q,yValue:V},Z)}return Z?fe(fe({},R),Z):null}},{key:"inRange",value:function(A,C){var N=arguments.length>2&&arguments[2]!==void 0?arguments[2]:1,M=this.props.layout,R=A/N,D=C/N;if(M==="horizontal"||M==="vertical"){var L=this.state.offset,H=R>=L.left&&R<=L.left+L.width&&D>=L.top&&D<=L.top+L.height;return H?{x:R,y:D}:null}var B=this.state,U=B.angleAxisMap,Y=B.radiusAxisMap;if(U&&Y){var Z=Ki(U);return rk({x:R,y:D},Z)}return null}},{key:"parseEventsOfWrapper",value:function(){var A=this.props.children,C=this.getTooltipEventType(),N=rr(A,_r),M={};N&&C==="axis"&&(N.props.trigger==="click"?M={onClick:this.handleClick}:M={onMouseEnter:this.handleMouseEnter,onDoubleClick:this.handleDoubleClick,onMouseMove:this.handleMouseMove,onMouseLeave:this.handleMouseLeave,onTouchMove:this.handleTouchMove,onTouchStart:this.handleTouchStart,onTouchEnd:this.handleTouchEnd,onContextMenu:this.handleContextMenu});var R=Cm(this.props,this.handleOuterEvent);return fe(fe({},R),M)}},{key:"addListener",value:function(){k1.on($1,this.handleReceiveSyncEvent)}},{key:"removeListener",value:function(){k1.removeListener($1,this.handleReceiveSyncEvent)}},{key:"filterFormatItem",value:function(A,C,N){for(var M=this.state.formattedGraphicalItems,R=0,D=M.length;R<D;R++){var L=M[R];if(L.item===A||L.props.key===A.key||C===ei(L.item.type)&&N===L.childIndex)return L}return null}},{key:"renderClipPath",value:function(){var A=this.clipPathId,C=this.state.offset,N=C.left,M=C.top,R=C.height,D=C.width;return I.createElement("defs",null,I.createElement("clipPath",{id:A},I.createElement("rect",{x:N,y:M,height:R,width:D})))}},{key:"getXScales",value:function(){var A=this.state.xAxisMap;return A?Object.entries(A).reduce(function(C,N){var M=I4(N,2),R=M[0],D=M[1];return fe(fe({},C),{},ke({},R,D.scale))},{}):null}},{key:"getYScales",value:function(){var A=this.state.yAxisMap;return A?Object.entries(A).reduce(function(C,N){var M=I4(N,2),R=M[0],D=M[1];return fe(fe({},C),{},ke({},R,D.scale))},{}):null}},{key:"getXScaleByAxisId",value:function(A){var C;return(C=this.state.xAxisMap)===null||C===void 0||(C=C[A])===null||C===void 0?void 0:C.scale}},{key:"getYScaleByAxisId",value:function(A){var C;return(C=this.state.yAxisMap)===null||C===void 0||(C=C[A])===null||C===void 0?void 0:C.scale}},{key:"getItemByXY",value:function(A){var C=this.state,N=C.formattedGraphicalItems,M=C.activeItem;if(N&&N.length)for(var R=0,D=N.length;R<D;R++){var L=N[R],H=L.props,B=L.item,U=B.type.defaultProps!==void 0?fe(fe({},B.type.defaultProps),B.props):B.props,Y=ei(B.type);if(Y==="Bar"){var Z=(H.data||[]).find(function(V){return mde(A,V)});if(Z)return{graphicalItem:L,payload:Z}}else if(Y==="RadialBar"){var X=(H.data||[]).find(function(V){return rk(A,V)});if(X)return{graphicalItem:L,payload:X}}else if(qv(L,M)||Uv(L,M)||Nf(L,M)){var k=ahe({graphicalItem:L,activeTooltipItem:M,itemData:U.data}),q=U.activeIndex===void 0?k:U.activeIndex;return{graphicalItem:fe(fe({},L),{},{childIndex:q}),payload:Nf(L,M)?U.data[k]:L.props.data[k]}}}return null}},{key:"render",value:function(){var A=this;if(!mM(this))return null;var C=this.props,N=C.children,M=C.className,R=C.width,D=C.height,L=C.style,H=C.compact,B=C.title,U=C.desc,Y=L4(C,Nve),Z=nt(Y,!1);if(H)return I.createElement(y4,{state:this.state,width:this.props.width,height:this.props.height,clipPathId:this.clipPathId},I.createElement(wS,bl({},Z,{width:R,height:D,title:B,desc:U}),this.renderClipPath(),vM(N,this.renderMap)));if(this.props.accessibilityLayer){var X,k;Z.tabIndex=(X=this.props.tabIndex)!==null&&X!==void 0?X:0,Z.role=(k=this.props.role)!==null&&k!==void 0?k:"application",Z.onKeyDown=function(V){A.accessibilityManager.keyboardEvent(V)},Z.onFocus=function(){A.accessibilityManager.focus()}}var q=this.parseEventsOfWrapper();return I.createElement(y4,{state:this.state,width:this.props.width,height:this.props.height,clipPathId:this.clipPathId},I.createElement("div",bl({className:et("recharts-wrapper",M),style:fe({position:"relative",cursor:"default",width:R,height:D},L)},q,{ref:function(Q){A.container=Q}}),I.createElement(wS,bl({},Z,{width:R,height:D,title:B,desc:U,style:Gve}),this.renderClipPath(),vM(N,this.renderMap)),this.renderLegend(),this.renderTooltip()))}}])})(S.Component);ke(O,"displayName",n),ke(O,"defaultProps",fe({layout:"horizontal",stackOffset:"none",barCategoryGap:"10%",barGap:4,margin:{top:5,right:5,bottom:5,left:5},reverseStackOrder:!1,syncMethod:"index"},m)),ke(O,"getDerivedStateFromProps",function(b,E){var _=b.dataKey,A=b.data,C=b.children,N=b.width,M=b.height,R=b.layout,D=b.stackOffset,L=b.margin,H=E.dataStartIndex,B=E.dataEndIndex;if(E.updateId===void 0){var U=q4(b);return fe(fe(fe({},U),{},{updateId:0},x(fe(fe({props:b},U),{},{updateId:0}),E)),{},{prevDataKey:_,prevData:A,prevWidth:N,prevHeight:M,prevLayout:R,prevStackOffset:D,prevMargin:L,prevChildren:C})}if(_!==E.prevDataKey||A!==E.prevData||N!==E.prevWidth||M!==E.prevHeight||R!==E.prevLayout||D!==E.prevStackOffset||!_l(L,E.prevMargin)){var Y=q4(b),Z={chartX:E.chartX,chartY:E.chartY,isTooltipActive:E.isTooltipActive},X=fe(fe({},B4(E,A,R)),{},{updateId:E.updateId+1}),k=fe(fe(fe({},Y),Z),X);return fe(fe(fe({},k),x(fe({props:b},k),E)),{},{prevDataKey:_,prevData:A,prevWidth:N,prevHeight:M,prevLayout:R,prevStackOffset:D,prevMargin:L,prevChildren:C})}if(!xS(C,E.prevChildren)){var q,V,Q,ee,z=rr(C,Vl),G=z&&(q=(V=z.props)===null||V===void 0?void 0:V.startIndex)!==null&&q!==void 0?q:H,$=z&&(Q=(ee=z.props)===null||ee===void 0?void 0:ee.endIndex)!==null&&Q!==void 0?Q:B,W=G!==H||$!==B,ae=!Qe(A),ce=ae&&!W?E.updateId:E.updateId+1;return fe(fe({updateId:ce},x(fe(fe({props:b},E),{},{updateId:ce,dataStartIndex:G,dataEndIndex:$}),E)),{},{prevChildren:C,dataStartIndex:G,dataEndIndex:$})}return null}),ke(O,"renderActiveDot",function(b,E,_){var A;return S.isValidElement(b)?A=S.cloneElement(b,E):Ye(b)?A=b(E):A=I.createElement(kE,E),I.createElement(Bt,{className:"recharts-active-dot",key:_},A)});var j=S.forwardRef(function(E,_){return I.createElement(O,bl({},E,{ref:_}))});return j.displayName=O.displayName,j},X6=K6({chartName:"LineChart",GraphicalChild:Ar,axisComponents:[{axisType:"xAxis",AxisComp:ws},{axisType:"yAxis",AxisComp:hi}],formatAxisMap:m6}),tge=K6({chartName:"BarChart",GraphicalChild:ao,defaultTooltipEventType:"axis",validateTooltipEventTypes:["axis","item"],axisComponents:[{axisType:"xAxis",AxisComp:ws},{axisType:"yAxis",AxisComp:hi}],formatAxisMap:m6});function L1(e){if(e===0)return"0 B";const t=1024,n=["B","KB","MB","GB","TB"],r=Math.floor(Math.log(e)/Math.log(t));return`${Number.parseFloat((e/t**r).toFixed(1))} ${n[r]}`}function Xo(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toString()}function Fh({title:e,value:t,description:n,icon:r,trend:i}){return c.jsxs(Te,{children:[c.jsxs(Me,{className:"flex flex-row items-center justify-between pb-2",children:[c.jsx(Le,{className:"font-medium text-muted-foreground text-sm",children:e}),c.jsx(r,{className:"h-4 w-4 text-muted-foreground"})]}),c.jsxs($e,{children:[c.jsx("div",{className:"font-bold text-2xl",children:t}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("p",{className:"text-muted-foreground text-xs",children:n}),i!==void 0&&i!==0&&c.jsxs("span",{className:`flex items-center text-xs ${i>0?"text-green-500":"text-red-500"}`,children:[c.jsx(Uj,{className:`h-3 w-3 ${i<0?"rotate-180":""}`}),Math.abs(i),"%"]})]})]})]})}function nge({data:e}){const t=e.map(n=>({date:new Date(n.date).toLocaleDateString("en-US",{month:"short",day:"numeric"}),size:n.size/1073741824,files:n.files}));return c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(Le,{children:"Storage Usage"}),c.jsx(We,{children:"Storage size and file count over time"})]}),c.jsx($e,{children:c.jsx(lE,{height:300,width:"100%",children:c.jsxs(X6,{data:t,children:[c.jsx(Wv,{className:"stroke-muted",strokeDasharray:"3 3"}),c.jsx(ws,{className:"text-xs",dataKey:"date",stroke:"currentColor",tick:{fill:"currentColor"}}),c.jsx(hi,{className:"text-xs",stroke:"currentColor",tick:{fill:"currentColor"},tickFormatter:n=>`${n} GB`,yAxisId:"left"}),c.jsx(hi,{className:"text-xs",orientation:"right",stroke:"currentColor",tick:{fill:"currentColor"},yAxisId:"right"}),c.jsx(_r,{contentStyle:{backgroundColor:"hsl(var(--card))",border:"1px solid hsl(var(--border))",borderRadius:"var(--radius)"},formatter:(n,r)=>[r==="size"?`${n.toFixed(2)} GB`:n,r==="size"?"Storage":"Files"]}),c.jsx(ni,{}),c.jsx(Ar,{dataKey:"size",dot:!1,name:"Storage (GB)",stroke:"hsl(var(--primary))",strokeWidth:2,type:"monotone",yAxisId:"left"}),c.jsx(Ar,{dataKey:"files",dot:!1,name:"File Count",stroke:"hsl(var(--chart-2))",strokeWidth:2,type:"monotone",yAxisId:"right"})]})})})]})}function rge({data:e}){const t=e.map(n=>({date:new Date(n.date).toLocaleDateString("en-US",{month:"short",day:"numeric"}),bandwidth:n.bytes/1048576,requests:n.requests}));return c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(Le,{children:"CDN Traffic"}),c.jsx(We,{children:"Bandwidth and requests over time"})]}),c.jsx($e,{children:c.jsx(lE,{height:300,width:"100%",children:c.jsxs(tge,{data:t,children:[c.jsx(Wv,{className:"stroke-muted",strokeDasharray:"3 3"}),c.jsx(ws,{className:"text-xs",dataKey:"date",stroke:"currentColor",tick:{fill:"currentColor"}}),c.jsx(hi,{className:"text-xs",stroke:"currentColor",tick:{fill:"currentColor"},tickFormatter:n=>`${n} MB`,yAxisId:"left"}),c.jsx(hi,{className:"text-xs",orientation:"right",stroke:"currentColor",tick:{fill:"currentColor"},tickFormatter:n=>Xo(n),yAxisId:"right"}),c.jsx(_r,{contentStyle:{backgroundColor:"hsl(var(--card))",border:"1px solid hsl(var(--border))",borderRadius:"var(--radius)"},formatter:(n,r)=>[r==="bandwidth"?`${n.toFixed(1)} MB`:Xo(n),r==="bandwidth"?"Bandwidth":"Requests"]}),c.jsx(ni,{}),c.jsx(ao,{dataKey:"bandwidth",fill:"hsl(var(--primary))",name:"Bandwidth (MB)",radius:[4,4,0,0],yAxisId:"left"}),c.jsx(ao,{dataKey:"requests",fill:"hsl(var(--chart-3))",name:"Requests",radius:[4,4,0,0],yAxisId:"right"})]})})})]})}function age({files:e}){return c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(Le,{children:"Top Files"}),c.jsx(We,{children:"Most requested files this month"})]}),c.jsx($e,{children:e.length===0?c.jsx("div",{className:"py-4 text-center text-muted-foreground",children:"No data available"}):c.jsx("div",{className:"space-y-4",children:e.map((t,n)=>{const r=t.key.split("/").pop()||t.key,i=Math.max(...e.map(l=>l.requests)),o=t.requests/i*100;return c.jsxs("div",{children:[c.jsxs("div",{className:"mb-1 flex items-center justify-between text-sm",children:[c.jsxs("span",{className:"flex items-center gap-2",children:[c.jsxs("span",{className:"text-muted-foreground",children:[n+1,"."]}),c.jsx("span",{className:"max-w-[200px] truncate font-medium",children:r})]}),c.jsxs("span",{className:"text-muted-foreground",children:[Xo(t.requests)," requests"]})]}),c.jsx(tv,{className:"h-2",value:o})]},t.key)})})})]})}function ige(){return c.jsxs("div",{className:"space-y-6",children:[c.jsx("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-4",children:Array.from({length:4}).map((e,t)=>c.jsxs(Te,{children:[c.jsx(Me,{className:"pb-2",children:c.jsx(De,{className:"h-4 w-20"})}),c.jsxs($e,{children:[c.jsx(De,{className:"h-8 w-24"}),c.jsx(De,{className:"mt-2 h-3 w-32"})]})]},t))}),c.jsxs(Te,{children:[c.jsx(Me,{children:c.jsx(De,{className:"h-6 w-32"})}),c.jsx($e,{children:c.jsx(De,{className:"h-[300px] w-full"})})]})]})}function oge(){return c.jsxs("div",{className:"flex flex-col items-center justify-center py-12",children:[c.jsx(If,{className:"mb-4 h-16 w-16 text-muted-foreground opacity-50"}),c.jsx("h2",{className:"mb-2 font-semibold text-xl",children:"No Storage Configured"}),c.jsxs("p",{className:"mb-6 max-w-md text-center text-muted-foreground",children:["Storage infrastructure has not been deployed yet. Run"," ",c.jsx("code",{className:"rounded bg-muted px-2 py-1 font-mono text-sm",children:"wraps storage init"})," ","to get started."]})]})}function sge(){const[e,t]=S.useState(null),[n,r]=S.useState(!0),[i,o]=S.useState(null),[l,f]=S.useState("7d"),d=S.useCallback(async()=>{try{r(!0),o(null);const h=sessionStorage.getItem("wraps-auth-token"),v=await fetch(`/api/cdn/metrics?token=${h}&range=${l}`);if(!v.ok){if(v.status===404){t(null);return}throw new Error("Failed to fetch storage metrics")}const m=await v.json();t(m)}catch(h){o(h instanceof Error?h.message:"An error occurred")}finally{r(!1)}},[l]);return S.useEffect(()=>{d()},[d]),n?c.jsx(ige,{}):i?c.jsxs(Un,{variant:"destructive",children:[c.jsx(lr,{className:"h-4 w-4"}),c.jsx(ro,{children:"Error"}),c.jsx(Hn,{children:i})]}):e?c.jsxs("div",{className:"space-y-6",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("h1",{className:"font-bold text-2xl",children:"Storage Metrics"}),c.jsx("p",{className:"text-muted-foreground",children:"Monitor your storage usage and CDN traffic"})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs(ga,{onValueChange:f,value:l,children:[c.jsx(xa,{className:"w-32",children:c.jsx(ya,{})}),c.jsxs(ba,{children:[c.jsx(Fe,{value:"7d",children:"Last 7 days"}),c.jsx(Fe,{value:"30d",children:"Last 30 days"}),c.jsx(Fe,{value:"90d",children:"Last 90 days"})]})]}),c.jsxs(Ce,{onClick:d,size:"sm",variant:"outline",children:[c.jsx(Lf,{className:"mr-2 h-4 w-4"}),"Refresh"]})]})]}),c.jsxs("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-4",children:[c.jsx(Fh,{description:`${Xo(e.summary.fileCount)} files`,icon:KH,title:"Storage Used",value:L1(e.summary.totalSize)}),c.jsx(Fh,{description:`${L1(e.summary.bandwidth.thisMonth)} this month`,icon:UH,title:"Bandwidth Today",value:L1(e.summary.bandwidth.today)}),c.jsx(Fh,{description:`${Xo(e.summary.requests.thisMonth)} this month`,icon:Fu,title:"Requests Today",value:Xo(e.summary.requests.today)}),c.jsx(Fh,{description:"Files in storage",icon:FH,title:"Total Files",value:Xo(e.summary.fileCount)})]}),c.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[c.jsx(nge,{data:e.usage}),c.jsx(rge,{data:e.bandwidth})]}),c.jsx(age,{files:e.topFiles})]}):c.jsx(oge,{})}function Ep({status:e}){const t={SUCCESS:{icon:so,label:"Active",className:"bg-green-500/10 text-green-700 dark:text-green-400 border-green-500/20"},PENDING:{icon:Jo,label:"Pending",className:"bg-yellow-500/10 text-yellow-700 dark:text-yellow-400 border-yellow-500/20"},FAILED:{icon:m$,label:"Failed",className:"bg-red-500/10 text-red-700 dark:text-red-400 border-red-500/20"},DISABLED:{icon:lr,label:"Disabled",className:"bg-gray-500/10 text-gray-700 dark:text-gray-400 border-gray-500/20"}},{icon:n,label:r,className:i}=t[e];return c.jsxs(Be,{className:i,variant:"outline",children:[c.jsx(n,{className:"mr-1 h-3 w-3"}),r]})}function wl({text:e}){const t=async()=>{await navigator.clipboard.writeText(e),jt.success("Copied to clipboard")};return c.jsx(Ce,{onClick:t,size:"sm",variant:"ghost",children:c.jsx(zj,{className:"h-3 w-3"})})}function lge({settings:e}){return c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(If,{className:"h-5 w-5"}),c.jsx(Le,{children:"S3 Bucket"})]}),c.jsx(Ep,{status:"SUCCESS"})]}),c.jsx(We,{children:"Your storage bucket for uploading files"})]}),c.jsx($e,{className:"space-y-4",children:c.jsxs("div",{className:"grid gap-4",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-muted-foreground text-sm",children:"Bucket Name"}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("code",{className:"rounded bg-muted px-2 py-1 font-mono text-sm",children:e.bucketName}),c.jsx(wl,{text:e.bucketName})]})]}),c.jsx(Vt,{}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-muted-foreground text-sm",children:"Region"}),c.jsx("code",{className:"rounded bg-muted px-2 py-1 font-mono text-sm",children:e.region})]}),c.jsx(Vt,{}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-muted-foreground text-sm",children:"Versioning"}),c.jsx(Be,{variant:e.versioning?"default":"secondary",children:e.versioning?"Enabled":"Disabled"})]}),c.jsx(Vt,{}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-muted-foreground text-sm",children:"Encryption"}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(tm,{className:"h-4 w-4 text-green-500"}),c.jsx("span",{className:"text-sm",children:"AES-256"})]})]}),e.retention&&e.retention!=="none"&&c.jsxs(c.Fragment,{children:[c.jsx(Vt,{}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-muted-foreground text-sm",children:"Auto-Cleanup"}),c.jsx("span",{className:"text-sm",children:e.retention})]})]})]})})]})}function cge({settings:e}){const[t,n]=S.useState(!1);if(!e.cdn?.enabled)return c.jsx(Te,{children:c.jsxs(Me,{children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(Fu,{className:"h-5 w-5"}),c.jsx(Le,{children:"CloudFront CDN"})]}),c.jsx(Ep,{status:"DISABLED"})]}),c.jsx(We,{children:"CDN is not enabled for this storage bucket"})]})});const r=e.cdn.status==="Deployed"?"SUCCESS":e.cdn.status==="InProgress"?"PENDING":"FAILED";return c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(Fu,{className:"h-5 w-5"}),c.jsx(Le,{children:"CloudFront CDN"})]}),c.jsx(Ep,{status:r})]}),c.jsx(We,{children:"Global content delivery network for fast file access"})]}),c.jsxs($e,{className:"space-y-4",children:[c.jsxs("div",{className:"grid gap-4",children:[e.cdn.distributionId&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-muted-foreground text-sm",children:"Distribution ID"}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("code",{className:"rounded bg-muted px-2 py-1 font-mono text-sm",children:e.cdn.distributionId}),c.jsx(wl,{text:e.cdn.distributionId})]})]}),c.jsx(Vt,{})]}),e.cdn.distributionDomain&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-muted-foreground text-sm",children:"CloudFront URL"}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("a",{className:"text-blue-600 text-sm hover:underline dark:text-blue-400",href:`https://${e.cdn.distributionDomain}`,rel:"noopener noreferrer",target:"_blank",children:[e.cdn.distributionDomain,c.jsx(Hu,{className:"ml-1 inline h-3 w-3"})]}),c.jsx(wl,{text:`https://${e.cdn.distributionDomain}`})]})]}),c.jsx(Vt,{})]}),e.cdn.customDomain&&c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-muted-foreground text-sm",children:"Custom Domain"}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("a",{className:"text-blue-600 text-sm hover:underline dark:text-blue-400",href:`https://${e.cdn.customDomain}`,rel:"noopener noreferrer",target:"_blank",children:[e.cdn.customDomain,c.jsx(Hu,{className:"ml-1 inline h-3 w-3"})]}),c.jsx(wl,{text:`https://${e.cdn.customDomain}`})]})]})]}),e.certificate?.validationRecords&&e.certificate.validationRecords.length>0&&e.certificate.status==="PENDING_VALIDATION"&&c.jsxs(ms,{onOpenChange:n,open:t,children:[c.jsx(ps,{asChild:!0,children:c.jsxs(Ce,{className:"w-full justify-between",variant:"ghost",children:[c.jsxs("span",{className:"flex items-center gap-2",children:[c.jsx(lr,{className:"h-4 w-4 text-yellow-500"}),"Certificate DNS Records Required"]}),t?c.jsx("span",{className:"text-xs",children:"Hide"}):c.jsx("span",{className:"text-xs",children:"Show"})]})}),c.jsxs(vs,{className:"mt-2 space-y-2",children:[c.jsxs(Un,{children:[c.jsx(lr,{className:"h-4 w-4"}),c.jsx(ro,{children:"Action Required"}),c.jsx(Hn,{children:"Add these DNS records to verify your custom domain certificate"})]}),e.certificate.validationRecords.map((i,o)=>c.jsxs("div",{className:"rounded-lg border bg-muted/50 p-3 font-mono text-xs",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-muted-foreground",children:i.type}),c.jsx(wl,{text:i.value})]}),c.jsx("div",{className:"mt-1 break-all",children:i.name}),c.jsxs("div",{className:"mt-1 break-all text-muted-foreground",children:["→ ",i.value]})]},o))]})]})]})]})}function uge({settings:e}){return c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(tm,{className:"h-5 w-5"}),c.jsx(Le,{children:"IAM Role"})]}),c.jsx(Ep,{status:"SUCCESS"})]}),c.jsx(We,{children:"Role used by your application to access storage"})]}),c.jsx($e,{children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-muted-foreground text-sm",children:"Role ARN"}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("code",{className:"max-w-[300px] truncate rounded bg-muted px-2 py-1 font-mono text-xs",children:e.roleArn}),c.jsx(wl,{text:e.roleArn})]})]})})]})}function fge(){return c.jsxs("div",{className:"space-y-6",children:[c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(De,{className:"h-6 w-32"}),c.jsx(De,{className:"h-4 w-64"})]}),c.jsx($e,{children:c.jsxs("div",{className:"space-y-4",children:[c.jsx(De,{className:"h-8 w-full"}),c.jsx(De,{className:"h-8 w-full"}),c.jsx(De,{className:"h-8 w-full"})]})})]}),c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(De,{className:"h-6 w-32"}),c.jsx(De,{className:"h-4 w-64"})]}),c.jsx($e,{children:c.jsxs("div",{className:"space-y-4",children:[c.jsx(De,{className:"h-8 w-full"}),c.jsx(De,{className:"h-8 w-full"})]})})]})]})}function dge(){return c.jsxs("div",{className:"flex flex-col items-center justify-center py-12",children:[c.jsx(If,{className:"mb-4 h-16 w-16 text-muted-foreground opacity-50"}),c.jsx("h2",{className:"mb-2 font-semibold text-xl",children:"No Storage Configured"}),c.jsxs("p",{className:"mb-6 max-w-md text-center text-muted-foreground",children:["Storage infrastructure has not been deployed yet. Run"," ",c.jsx("code",{className:"rounded bg-muted px-2 py-1 font-mono text-sm",children:"wraps storage init"})," ","to get started."]})]})}function hge(){const[e,t]=S.useState(null),[n,r]=S.useState(!0),[i,o]=S.useState(null),l=S.useCallback(async()=>{try{r(!0),o(null);const f=sessionStorage.getItem("wraps-auth-token"),d=await fetch(`/api/cdn/settings?token=${f}`);if(!d.ok){if(d.status===404){t(null);return}throw new Error("Failed to fetch storage settings")}const h=await d.json();t(h)}catch(f){o(f instanceof Error?f.message:"An error occurred")}finally{r(!1)}},[]);return S.useEffect(()=>{l()},[l]),n?c.jsx(fge,{}):i?c.jsxs(Un,{variant:"destructive",children:[c.jsx(lr,{className:"h-4 w-4"}),c.jsx(ro,{children:"Error"}),c.jsx(Hn,{children:i})]}):e?c.jsxs("div",{className:"space-y-6",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("h1",{className:"font-bold text-2xl",children:"Storage Settings"}),c.jsx("p",{className:"text-muted-foreground",children:"Manage your S3 bucket and CloudFront CDN configuration"})]}),c.jsxs(Ce,{onClick:l,size:"sm",variant:"outline",children:[c.jsx(Lf,{className:"mr-2 h-4 w-4"}),"Refresh"]})]}),c.jsx(lge,{settings:e}),c.jsx(cge,{settings:e}),c.jsx(uge,{settings:e})]}):c.jsx(dge,{})}function Cl({className:e,...t}){return c.jsx("div",{className:pe("group/input-group relative flex w-full items-center rounded-md border border-input shadow-xs outline-none transition-[color,box-shadow] dark:bg-input/30","h-9 min-w-0 has-[>textarea]:h-auto","has-[>[data-align=inline-start]]:[&>input]:pl-2","has-[>[data-align=inline-end]]:[&>input]:pr-2","has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>[data-align=block-start]]:[&>input]:pb-3","has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-end]]:[&>input]:pt-3","has-[[data-slot=input-group-control]:focus-visible]:border-ring has-[[data-slot=input-group-control]:focus-visible]:ring-[3px] has-[[data-slot=input-group-control]:focus-visible]:ring-ring/50","has-[[data-slot][aria-invalid=true]]:border-destructive has-[[data-slot][aria-invalid=true]]:ring-destructive/20 dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40",e),"data-slot":"input-group",role:"group",...t})}const mge=ic("flex h-auto cursor-text select-none items-center justify-center gap-2 py-1.5 font-medium text-muted-foreground text-sm group-data-[disabled=true]/input-group:opacity-50 [&>kbd]:rounded-[calc(var(--radius)-5px)] [&>svg:not([class*='size-'])]:size-4",{variants:{align:{"inline-start":"order-first pl-3 has-[>button]:ml-[-0.45rem] has-[>kbd]:ml-[-0.35rem]","inline-end":"order-last pr-3 has-[>button]:mr-[-0.45rem] has-[>kbd]:mr-[-0.35rem]","block-start":"order-first w-full justify-start px-3 pt-3 group-has-[>input]/input-group:pt-2.5 [.border-b]:pb-3","block-end":"order-last w-full justify-start px-3 pb-3 group-has-[>input]/input-group:pb-2.5 [.border-t]:pt-3"}},defaultVariants:{align:"inline-start"}});function ca({className:e,align:t="inline-start",...n}){return c.jsx("div",{className:pe(mge({align:t}),e),"data-align":t,"data-slot":"input-group-addon",onClick:r=>{r.target.closest("button")||r.currentTarget.parentElement?.querySelector("input")?.focus()},role:"group",...n})}function Tl({className:e,...t}){return c.jsx("span",{className:pe("flex items-center gap-2 text-muted-foreground text-sm [&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none",e),...t})}function Ml({className:e,...t}){return c.jsx(fs,{className:pe("flex-1 rounded-none border-0 bg-transparent shadow-none focus-visible:ring-0 dark:bg-transparent",e),"data-slot":"input-group-control",...t})}var Xv="Tabs",[pge]=jn(Xv,[mc]),Q6=mc(),[vge,GE]=pge(Xv),Z6=S.forwardRef((e,t)=>{const{__scopeTabs:n,value:r,onValueChange:i,defaultValue:o,orientation:l="horizontal",dir:f,activationMode:d="automatic",...h}=e,v=hc(f),[m,g]=An({prop:r,onChange:i,defaultProp:o??"",caller:Xv});return c.jsx(vge,{scope:n,baseId:Cr(),value:m,onValueChange:g,orientation:l,dir:v,activationMode:d,children:c.jsx(Ae.div,{dir:v,"data-orientation":l,...h,ref:t})})});Z6.displayName=Xv;var J6="TabsList",e8=S.forwardRef((e,t)=>{const{__scopeTabs:n,loop:r=!0,...i}=e,o=GE(J6,n),l=Q6(n);return c.jsx(xO,{asChild:!0,...l,orientation:o.orientation,dir:o.dir,loop:r,children:c.jsx(Ae.div,{role:"tablist","aria-orientation":o.orientation,...i,ref:t})})});e8.displayName=J6;var t8="TabsTrigger",n8=S.forwardRef((e,t)=>{const{__scopeTabs:n,value:r,disabled:i=!1,...o}=e,l=GE(t8,n),f=Q6(n),d=i8(l.baseId,r),h=o8(l.baseId,r),v=r===l.value;return c.jsx(bO,{asChild:!0,...f,focusable:!i,active:v,children:c.jsx(Ae.button,{type:"button",role:"tab","aria-selected":v,"aria-controls":h,"data-state":v?"active":"inactive","data-disabled":i?"":void 0,disabled:i,id:d,...o,ref:t,onMouseDown:ge(e.onMouseDown,m=>{!i&&m.button===0&&m.ctrlKey===!1?l.onValueChange(r):m.preventDefault()}),onKeyDown:ge(e.onKeyDown,m=>{[" ","Enter"].includes(m.key)&&l.onValueChange(r)}),onFocus:ge(e.onFocus,()=>{const m=l.activationMode!=="manual";!v&&!i&&m&&l.onValueChange(r)})})})});n8.displayName=t8;var r8="TabsContent",a8=S.forwardRef((e,t)=>{const{__scopeTabs:n,value:r,forceMount:i,children:o,...l}=e,f=GE(r8,n),d=i8(f.baseId,r),h=o8(f.baseId,r),v=r===f.value,m=S.useRef(v);return S.useEffect(()=>{const g=requestAnimationFrame(()=>m.current=!1);return()=>cancelAnimationFrame(g)},[]),c.jsx(Nn,{present:i||v,children:({present:g})=>c.jsx(Ae.div,{"data-state":v?"active":"inactive","data-orientation":f.orientation,role:"tabpanel","aria-labelledby":d,hidden:!g,id:h,tabIndex:0,...l,ref:t,style:{...e.style,animationDuration:m.current?"0s":void 0},children:g&&o})})});a8.displayName=r8;function i8(e,t){return`${e}-trigger-${t}`}function o8(e,t){return`${e}-content-${t}`}var gge=Z6,yge=e8,xge=n8,bge=a8;function s8({className:e,...t}){return c.jsx(gge,{className:pe("flex flex-col gap-2",e),"data-slot":"tabs",...t})}function l8({className:e,...t}){return c.jsx(yge,{className:pe("inline-flex h-9 w-fit items-center justify-center rounded-lg bg-muted p-[3px] text-muted-foreground",e),"data-slot":"tabs-list",...t})}function qu({className:e,...t}){return c.jsx(xge,{className:pe("inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 whitespace-nowrap rounded-md border border-transparent px-2 py-1 font-medium text-foreground text-sm transition-[color,box-shadow] focus-visible:border-ring focus-visible:outline-1 focus-visible:outline-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:shadow-sm dark:text-muted-foreground dark:data-[state=active]:border-input dark:data-[state=active]:bg-input/30 dark:data-[state=active]:text-foreground [&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",e),"data-slot":"tabs-trigger",...t})}function Uu({className:e,...t}){return c.jsx(bge,{className:pe("flex-1 outline-none",e),"data-slot":"tabs-content",...t})}function wge({messageId:e,archivingEnabled:t}){const[n,r]=S.useState(null),[i,o]=S.useState(!0),[l,f]=S.useState(null);return S.useEffect(()=>{async function d(){if(!t){o(!1);return}try{o(!0),f(null);const h=sessionStorage.getItem("wraps-auth-token");if(!h)throw new Error("Authentication token not found");const v=encodeURIComponent(e),m=await fetch(`/api/emails/${v}/archive?token=${h}`);if(!m.ok){if(m.status===404){r(null),o(!1);return}throw new Error(`Failed to fetch archived email: ${m.statusText}`)}const g=await m.json();r({...g,timestamp:new Date(g.timestamp)})}catch(h){const v=h instanceof Error?h.message:"Unknown error";f(v),console.error("Error fetching archived email:",h)}finally{o(!1)}}d()},[e,t]),t?i?c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(Le,{children:"Email Archive"}),c.jsx(We,{children:"Loading archived email content..."})]}),c.jsx($e,{className:"space-y-4",children:c.jsx(De,{className:"h-[400px] w-full"})})]}):l?c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(Le,{children:"Email Archive"}),c.jsx(We,{children:"Failed to load archived email"})]}),c.jsx($e,{children:c.jsx(Un,{variant:"destructive",children:c.jsx(Hn,{children:l})})})]}):n?c.jsxs(Te,{children:[c.jsx(Me,{children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx(Le,{children:"Email Archive"}),c.jsx(We,{children:"Full email content stored in AWS SES Mail Manager"})]}),n.attachments.length>0&&c.jsxs(Be,{variant:"secondary",children:[n.attachments.length," attachment",n.attachments.length>1?"s":""]})]})}),c.jsxs($e,{children:[c.jsxs(s8,{className:"w-full",defaultValue:"rendered",children:[c.jsxs(l8,{className:"grid w-full grid-cols-3",children:[c.jsxs(qu,{className:"gap-2",value:"rendered",children:[c.jsx(Fu,{className:"h-4 w-4"}),"Rendered Email"]}),c.jsxs(qu,{className:"gap-2",value:"text",children:[c.jsx(p$,{className:"h-4 w-4"}),"Plain Text"]}),c.jsxs(qu,{className:"gap-2",value:"html",children:[c.jsx(WH,{className:"h-4 w-4"}),"HTML Source"]})]}),c.jsxs(Uu,{className:"space-y-4",value:"rendered",children:[n.html?c.jsx("div",{className:"rounded-md border",children:c.jsx("iframe",{className:"h-[600px] w-full rounded-md",sandbox:"allow-same-origin",srcDoc:n.html,title:"Email preview"})}):c.jsx(Un,{children:c.jsx(Hn,{children:"No HTML content available for this email. View the plain text tab instead."})}),n.attachments.length>0&&c.jsxs("div",{className:"space-y-2",children:[c.jsx("div",{className:"font-medium text-sm",children:"Attachments"}),c.jsx("div",{className:"space-y-2",children:n.attachments.map((d,h)=>c.jsx("div",{className:"flex items-center justify-between rounded-md border p-3",children:c.jsxs("div",{className:"space-y-1",children:[c.jsx("div",{className:"font-mono text-sm",children:d.filename||`Attachment ${h+1}`}),c.jsxs("div",{className:"text-muted-foreground text-xs",children:[d.contentType," •"," ",(d.size/1024).toFixed(2)," KB"]})]})},d.filename||`attachment-${h}`))})]})]}),c.jsx(Uu,{className:"space-y-4",value:"text",children:n.text?c.jsx("div",{className:"rounded-md border bg-muted p-4",children:c.jsx("pre",{className:"whitespace-pre-wrap font-mono text-sm",children:n.text})}):c.jsx(Un,{children:c.jsx(Hn,{children:"No plain text content available for this email."})})}),c.jsx(Uu,{className:"space-y-4",value:"html",children:n.html?c.jsx("div",{className:"rounded-md border bg-muted p-4",children:c.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap font-mono text-xs",children:n.html})}):c.jsx(Un,{children:c.jsx(Hn,{children:"No HTML content available for this email."})})})]}),n.metadata&&c.jsxs("div",{className:"mt-6 space-y-3 rounded-md border p-4",children:[c.jsx("div",{className:"font-medium text-sm",children:"SMTP Metadata"}),c.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[n.metadata.senderIp&&c.jsxs("div",{className:"space-y-1",children:[c.jsx("div",{className:"text-muted-foreground text-xs",children:"Sender IP"}),c.jsx("div",{className:"font-mono text-sm",children:n.metadata.senderIp})]}),n.metadata.tlsProtocol&&c.jsxs("div",{className:"space-y-1",children:[c.jsx("div",{className:"text-muted-foreground text-xs",children:"TLS Protocol"}),c.jsx("div",{className:"font-mono text-sm",children:n.metadata.tlsProtocol})]}),n.metadata.senderHostname&&c.jsxs("div",{className:"space-y-1",children:[c.jsx("div",{className:"text-muted-foreground text-xs",children:"Sender Hostname"}),c.jsx("div",{className:"font-mono text-sm",children:n.metadata.senderHostname})]})]})]})]})]}):c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(Le,{children:"Email Archive"}),c.jsx(We,{children:"Email content not available"})]}),c.jsx($e,{children:c.jsx(Un,{children:c.jsx(Hn,{children:"This email was not archived. It may have been sent before email archiving was enabled for this deployment."})})})]}):c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(Le,{children:"Email Archive"}),c.jsx(We,{children:"Enable email archiving to view full email content"})]}),c.jsx($e,{children:c.jsx(Un,{children:c.jsxs(Hn,{children:["Email archiving is not enabled for this deployment. Run"," ",c.jsx("code",{className:"rounded bg-muted px-1.5 py-0.5 font-mono text-xs",children:"wraps upgrade"})," ","to enable archiving and view full email content with HTML rendering."]})})})]})}const Sge={sent:Sl,delivered:ai,bounced:or,suppressed:GH,complained:or,opened:Sl,clicked:Sl,failed:or},jge={sent:"text-blue-500",delivered:"text-green-500",bounced:"text-red-500",suppressed:"text-amber-500",complained:"text-red-500",opened:"text-purple-500",clicked:"text-indigo-500",failed:"text-red-500"},Oge={delivered:"default",sent:"secondary",bounced:"destructive",suppressed:"destructive",complained:"destructive",failed:"destructive",opened:"default",clicked:"default"};function Ege(){const{id:e}=hO(),t=_a(),[n,r]=S.useState(null),[i,o]=S.useState(!0),[l,f]=S.useState(null),[d,h]=S.useState(!1);S.useEffect(()=>{async function g(){try{o(!0),f(null);const x=sessionStorage.getItem("wraps-auth-token");if(!x)throw new Error("Authentication token not found");try{const _=await fetch(`/api/settings/deployment?token=${x}`);if(_.ok){const A=await _.json();h(A.archivingEnabled??!1)}}catch(_){console.warn("Failed to fetch deployment config:",_)}const O=encodeURIComponent(e||"");console.log("Fetching email with ID:",e),console.log("Encoded ID:",O),console.log("Full URL:",`/api/emails/${O}?token=${x.substring(0,8)}...`);const j=await fetch(`/api/emails/${O}?token=${x}`);if(!j.ok){let _="Failed to fetch email details";try{_=(await j.json()).error||_}catch{_=`${j.status}: ${j.statusText}`}throw new Error(_)}if(!j.headers.get("content-type")?.includes("application/json")){const _=await j.text();throw console.error("Non-JSON response:",_),new Error("Server returned non-JSON response")}const E=await j.json();console.log("Email data received:",{id:E.id,hasHtmlBody:!!E.htmlBody,hasTextBody:!!E.textBody,htmlBodyLength:E.htmlBody?.length||0,textBodyLength:E.textBody?.length||0,events:E.events?.length||0}),r(E)}catch(x){const O=x instanceof Error?x.message:"Unknown error";f(O),console.error("Error fetching email details:",x)}finally{o(!1)}}e&&g()},[e]);const v=g=>new Date(g).toLocaleString("en-US",{month:"short",day:"numeric",hour:"numeric",minute:"2-digit",hour12:!0}),m=g=>new Date(g).toLocaleString("en-US",{weekday:"short",month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit",second:"2-digit",hour12:!0});return i?c.jsx("div",{className:"flex h-[600px] items-center justify-center",children:c.jsx("div",{className:"text-muted-foreground",children:"Loading email details..."})}):l?c.jsxs("div",{className:"space-y-4",children:[c.jsxs(Ce,{onClick:()=>t("/email"),size:"sm",variant:"ghost",children:[c.jsx(Za,{className:"mr-2 h-4 w-4"}),"Back to emails"]}),c.jsx("div",{className:"rounded-md border border-destructive bg-destructive/10 p-4 text-destructive text-sm",children:l})]}):n?c.jsxs("div",{className:"space-y-6",children:[c.jsx("div",{className:"flex items-center gap-4",children:c.jsxs(Ce,{onClick:()=>t("/email"),size:"sm",variant:"ghost",children:[c.jsx(Za,{className:"mr-2 h-4 w-4"}),"Back"]})}),c.jsx(Te,{children:c.jsxs(Me,{className:"space-y-1.5",children:[c.jsxs(Le,{className:"flex flex-row items-center gap-2 text-xl",children:[c.jsx("span",{className:"text-xl",children:n.subject||"(no subject)"}),c.jsx(Be,{className:"shrink-0",variant:Oge[n.status],children:n.status.charAt(0).toUpperCase()+n.status.slice(1)})]}),c.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[c.jsx("code",{className:"min-w-0 truncate rounded bg-muted px-2 py-0.5 font-mono text-muted-foreground text-xs",children:n.messageId}),c.jsx(ma,{className:"h-6 w-6 shrink-0",size:"sm",value:n.messageId,variant:"ghost"})]}),c.jsxs("div",{className:"flex flex-col gap-3 pt-2 sm:flex-row sm:flex-wrap",children:[c.jsxs(Cl,{className:"w-full cursor-text! sm:w-auto sm:min-w-[518px]",children:[c.jsx(ca,{align:"inline-start",children:c.jsx(Tl,{children:"From"})}),c.jsx(Ml,{className:"min-w-0 cursor-text! truncate font-mono text-sm *:select-all",disabled:!0,readOnly:!0,value:n.from}),c.jsx(ca,{align:"inline-end",children:c.jsx(ma,{className:"h-6 w-6",size:"sm",value:n.from,variant:"ghost"})})]}),c.jsxs(Cl,{className:"w-full cursor-text! sm:w-auto sm:min-w-[518px]",children:[c.jsx(ca,{align:"inline-start",children:c.jsx(Tl,{children:"To"})}),c.jsx(Ml,{className:"min-w-0 cursor-text! truncate font-mono text-sm *:select-all",disabled:!0,readOnly:!0,value:n.to.length>0?n.to.join(", "):"(no recipients)"}),c.jsx(ca,{align:"inline-end",children:c.jsx(ma,{className:"h-6 w-6",size:"sm",value:n.to.join(", "),variant:"ghost"})})]}),n.replyTo&&c.jsxs(Cl,{className:"w-full sm:w-auto sm:max-w-md",children:[c.jsx(ca,{align:"inline-start",children:c.jsx(Tl,{children:"Reply-To"})}),c.jsx(Ml,{className:"min-w-0 truncate font-mono text-sm",readOnly:!0,value:n.replyTo}),c.jsx(ca,{align:"inline-end",children:c.jsx(ma,{className:"h-6 w-6",size:"sm",value:n.replyTo,variant:"ghost"})})]})]})]})}),d&&c.jsx(wge,{archivingEnabled:d,messageId:n.messageId}),c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(Le,{children:"Email Events"}),c.jsx(We,{children:"Lifecycle of this email from send to delivery"})]}),c.jsx($e,{children:c.jsx("div",{className:"space-y-4",children:n.events.length===0?c.jsx("div",{className:"text-muted-foreground text-sm",children:"No events recorded yet"}):n.events.map((g,x)=>{const O=Sge[g.type]||Jo,j=x===n.events.length-1;return c.jsx("div",{children:c.jsxs("div",{className:"flex gap-4",children:[c.jsxs("div",{className:"flex flex-col items-center",children:[c.jsx("div",{className:`rounded-full border-2 border-background bg-muted p-2 ${jge[g.type]}`,children:c.jsx(O,{className:"h-4 w-4"})}),!j&&c.jsx("div",{className:"my-1 w-px flex-1 bg-border"})]}),c.jsxs("div",{className:"flex-1 pb-6",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("div",{className:"font-medium capitalize",children:g.type}),c.jsx("div",{className:"text-muted-foreground text-sm",children:v(g.timestamp)})]}),c.jsx("div",{className:"text-muted-foreground text-sm",children:m(g.timestamp)}),g.metadata&&Object.keys(g.metadata).length>0&&c.jsx("div",{className:"mt-2 rounded-md border bg-muted/50 p-2 font-mono text-xs",children:c.jsx("pre",{className:"overflow-x-auto",children:JSON.stringify(g.metadata,null,2)})})]})]})},`${g.type}-${g.timestamp}`)})})})]})]}):c.jsxs("div",{className:"space-y-4",children:[c.jsxs(Ce,{onClick:()=>t("/email"),size:"sm",variant:"ghost",children:[c.jsx(Za,{className:"mr-2 h-4 w-4"}),"Back to emails"]}),c.jsx("div",{className:"rounded-md border p-4 text-muted-foreground text-sm",children:"Email not found"})]})}function _ge(e){const t=new Date(e),r=Math.floor((new Date().getTime()-t.getTime())/(1e3*60*60*24));return r===0?t.toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}):r===1?"Yesterday":r<7?`${r} days ago`:t.toLocaleDateString()}function Age(){const e=_a(),[t,n]=S.useState([]),[r,i]=S.useState(!0),[o,l]=S.useState(null),[f,d]=S.useState("");S.useEffect(()=>{async function v(){try{i(!0),l(null);const m=sessionStorage.getItem("wraps-auth-token");if(!m)throw new Error("Authentication token not found. Please use the URL provided by 'wraps console' command.");const g=await fetch(`/api/inbound?limit=50&token=${m}`);if(!g.ok){let O="Failed to fetch inbound emails";try{O=(await g.json()).error||O}catch{O=`${g.status}: ${g.statusText}`}throw new Error(O)}const x=await g.json();n(x.emails||[])}catch(m){const g=m instanceof Error?m.message:"Unknown error";l(g),console.error("Error fetching inbound emails:",m)}finally{i(!1)}}v()},[]);const h=t.filter(v=>{if(!f)return!0;const m=f.toLowerCase(),g=v.from.address.toLowerCase().includes(m)||v.from.name.toLowerCase().includes(m),x=v.subject.toLowerCase().includes(m),O=v.to.some(j=>j.address.toLowerCase().includes(m)||j.name.toLowerCase().includes(m));return g||x||O});return c.jsxs("div",{className:"space-y-4",children:[o&&c.jsx("div",{className:"rounded-md border border-destructive bg-destructive/10 p-4 text-destructive text-sm",children:o}),c.jsx("div",{className:"flex items-center gap-2",children:c.jsxs("div",{className:"relative flex-1",children:[c.jsx(Cp,{className:"absolute top-2.5 left-2.5 h-4 w-4 text-muted-foreground"}),c.jsx(fs,{className:"pl-8",onChange:v=>d(v.target.value),placeholder:"Search inbound emails...",value:f})]})}),c.jsx("div",{className:"rounded-md border",children:c.jsxs(cv,{children:[c.jsx(uv,{children:c.jsxs(Fn,{children:[c.jsx(Pt,{children:"From"}),c.jsx(Pt,{children:"Subject"}),c.jsx(Pt,{children:"Received"}),c.jsx(Pt,{className:"w-[100px]",children:"Attachments"}),c.jsx(Pt,{className:"w-[80px]",children:"Spam"}),c.jsx(Pt,{className:"w-[50px]"})]})}),c.jsx(fv,{children:r?c.jsx(Fn,{children:c.jsx(ht,{className:"h-24 text-center text-muted-foreground",colSpan:6,children:"Loading inbound emails..."})}):h.length===0?c.jsx(Fn,{children:c.jsx(ht,{className:"h-24 text-center text-muted-foreground",colSpan:6,children:t.length===0?"No inbound emails received yet":"No emails match your search"})}):h.map(v=>c.jsxs(Fn,{className:"cursor-pointer hover:bg-muted/50",onClick:()=>e(`/email/inbound/${v.emailId}`),children:[c.jsxs(ht,{className:"font-mono text-sm",children:[v.from.name||v.from.address,v.from.name&&c.jsxs("span",{className:"ml-1 text-muted-foreground text-xs",children:["<",v.from.address,">"]})]}),c.jsx(ht,{className:"max-w-[300px] truncate",children:v.subject||"(no subject)"}),c.jsx(ht,{className:"text-muted-foreground",children:_ge(v.receivedAt)}),c.jsx(ht,{children:v.hasAttachments&&c.jsxs(Be,{className:"bg-gray-500/10 text-gray-700 dark:text-gray-400 border-gray-500/20",variant:"outline",children:[c.jsx(g$,{className:"mr-1 h-3 w-3"}),v.attachmentCount]})}),c.jsx(ht,{children:v.spamVerdict==="PASS"?c.jsx(x$,{className:"h-4 w-4 text-green-500"}):v.spamVerdict==="FAIL"?c.jsx(y$,{className:"h-4 w-4 text-red-500"}):null}),c.jsx(ht,{children:c.jsx(HH,{className:"h-4 w-4 text-muted-foreground"})})]},v.emailId))})]})}),h.length>0&&!r&&c.jsx("div",{className:"flex items-center justify-between text-muted-foreground text-sm",children:c.jsxs("div",{children:["Showing ",h.length," of ",t.length," inbound emails"]})})]})}const z1={clicked:{variant:"default",description:"Recipient clicked a link in the email",className:"bg-purple-500/10 text-purple-700 dark:text-purple-400 hover:bg-purple-500/20 border-purple-500/20"},opened:{variant:"default",description:"Recipient opened the email",className:"bg-blue-500/10 text-blue-700 dark:text-blue-400 hover:bg-blue-500/20 border-blue-500/20"},delivered:{variant:"default",description:"Email was successfully delivered to recipient's mailbox",className:"bg-green-500/10 text-green-700 dark:text-green-400 hover:bg-green-500/20 border-green-500/20"},sent:{variant:"secondary",description:"Email was sent but delivery not yet confirmed",className:"bg-gray-500/10 text-gray-700 dark:text-gray-400 hover:bg-gray-500/20 border-gray-500/20"},bounced:{variant:"default",description:"Email bounced - recipient's mailbox may not exist or be full",className:"bg-orange-500/10 text-orange-700 dark:text-orange-400 hover:bg-orange-500/20 border-orange-500/20"},suppressed:{variant:"default",description:"Email blocked - recipient is on the suppression list",className:"bg-amber-500/10 text-amber-700 dark:text-amber-400 hover:bg-amber-500/20 border-amber-500/20"},complained:{variant:"default",description:"Recipient marked this email as spam",className:"bg-red-500/10 text-red-700 dark:text-red-400 hover:bg-red-500/20 border-red-500/20"},failed:{variant:"default",description:"Email failed to send due to an error",className:"bg-red-500/10 text-red-700 dark:text-red-400 hover:bg-red-500/20 border-red-500/20"}};function Nge(){const e=_a(),[t,n]=S.useState(""),[r,i]=S.useState("15"),[o,l]=S.useState("all"),[f,d]=XY(),[h,v]=S.useState(f.get("tab")==="receiving"?"receiving":"sending"),[m,g]=S.useState([]),[x,O]=S.useState(!0),[j,b]=S.useState(null);S.useEffect(()=>{async function A(){try{O(!0),b(null);let C=sessionStorage.getItem("wraps-auth-token");if(C||(C=new URLSearchParams(window.location.search).get("token"),C&&sessionStorage.setItem("wraps-auth-token",C)),!C)throw new Error("Authentication token not found. Please use the URL provided by 'wraps console' command.");const N=Number.parseInt(r,10),M=Date.now()-N*24*60*60*1e3,R=Date.now(),D=await fetch(`/api/emails?startTime=${M}&endTime=${R}&limit=100&token=${C}`);if(!D.ok){let H="Failed to fetch email logs";try{H=(await D.json()).error||H}catch{H=`${D.status}: ${D.statusText}`}throw new Error(H)}const L=await D.json();g(L.logs.map(H=>({id:H.messageId,to:H.to,from:H.from,subject:H.subject,status:H.status,timestamp:H.sentAt,messageId:H.messageId})))}catch(C){const N=C instanceof Error?C.message:"Unknown error";b(N),console.error("Error fetching email logs:",C)}finally{O(!1)}}A()},[r]);const E=m.filter(A=>{if(t){const C=t.toLowerCase(),N=A.to.some(R=>R.toLowerCase().includes(C)),M=A.subject.toLowerCase().includes(C);if(!(N||M))return!1}return!(o!=="all"&&A.status!==o)}),_=A=>{const C=new Date(A),M=Math.floor((new Date().getTime()-C.getTime())/(1e3*60*60*24));return M===0?"Today":M===1?"Yesterday":M<7?`${M} days ago`:C.toLocaleDateString()};return c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(Le,{children:"Emails"}),c.jsx(We,{children:"View and manage your email sending history"})]}),c.jsx($e,{children:c.jsxs(s8,{onValueChange:A=>{v(A),d(A==="sending"?{}:{tab:A})},value:h,children:[c.jsxs(l8,{children:[c.jsx(qu,{value:"sending",children:"Sending"}),c.jsx(qu,{value:"receiving",children:"Receiving"})]}),c.jsxs(Uu,{className:"space-y-4",value:"sending",children:[j&&c.jsx("div",{className:"rounded-md border border-destructive bg-destructive/10 p-4 text-destructive text-sm",children:j}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("div",{className:"relative flex-1",children:[c.jsx(Cp,{className:"absolute top-2.5 left-2.5 h-4 w-4 text-muted-foreground"}),c.jsx(fs,{className:"pl-8",onChange:A=>n(A.target.value),placeholder:"Search...",value:t})]}),c.jsxs(ga,{onValueChange:i,value:r,children:[c.jsx(xa,{className:"w-[180px]",children:c.jsx(ya,{})}),c.jsxs(ba,{children:[c.jsx(Fe,{value:"1",children:"Last 24 hours"}),c.jsx(Fe,{value:"7",children:"Last 7 days"}),c.jsx(Fe,{value:"15",children:"Last 15 days"}),c.jsx(Fe,{value:"30",children:"Last 30 days"}),c.jsx(Fe,{value:"90",children:"Last 90 days"})]})]}),c.jsxs(ga,{onValueChange:l,value:o,children:[c.jsx(xa,{className:"w-[180px]",children:c.jsx(ya,{})}),c.jsxs(ba,{children:[c.jsx(Fe,{value:"all",children:"All Statuses"}),c.jsx(Fe,{value:"clicked",children:"Clicked"}),c.jsx(Fe,{value:"opened",children:"Opened"}),c.jsx(Fe,{value:"delivered",children:"Delivered"}),c.jsx(Fe,{value:"sent",children:"Sent"}),c.jsx(Fe,{value:"bounced",children:"Bounced"}),c.jsx(Fe,{value:"suppressed",children:"Suppressed"}),c.jsx(Fe,{value:"complained",children:"Complained"}),c.jsx(Fe,{value:"failed",children:"Failed"})]})]}),c.jsxs(Ce,{size:"icon",variant:"outline",children:[c.jsx("span",{className:"sr-only",children:"Download"}),"↓"]})]}),c.jsx("div",{className:"rounded-md border",children:c.jsxs(cv,{children:[c.jsx(uv,{children:c.jsxs(Fn,{children:[c.jsx(Pt,{children:"To"}),c.jsx(Pt,{children:"Status"}),c.jsx(Pt,{children:"Subject"}),c.jsx(Pt,{children:"Sent"}),c.jsx(Pt,{className:"w-[50px]"})]})}),c.jsx(fv,{children:x?c.jsx(Fn,{children:c.jsx(ht,{className:"h-24 text-center text-muted-foreground",colSpan:5,children:"Loading email logs..."})}):E.length===0?c.jsx(Fn,{children:c.jsx(ht,{className:"h-24 text-center text-muted-foreground",colSpan:5,children:"No emails found"})}):E.map(A=>c.jsxs(Fn,{className:"cursor-pointer hover:bg-muted/50",onClick:()=>e(`/email/${A.id}`),children:[c.jsx(ht,{className:"font-mono text-sm",children:A.to.length>0?c.jsxs(c.Fragment,{children:[A.to[0],A.to.length>1&&c.jsxs("span",{className:"ml-1 text-muted-foreground text-xs",children:["+",A.to.length-1," more"]})]}):c.jsx("span",{className:"text-muted-foreground",children:"(no recipients)"})}),c.jsx(ht,{children:c.jsxs(Vp,{children:[c.jsx(Yp,{asChild:!0,children:c.jsx(Be,{className:z1[A.status]?.className,variant:z1[A.status]?.variant??"default",children:A.status.charAt(0).toUpperCase()+A.status.slice(1)})}),c.jsx(Wp,{children:c.jsx("p",{children:z1[A.status]?.description??"Unknown status"})})]})}),c.jsx(ht,{className:"max-w-[400px] truncate",children:A.subject}),c.jsx(ht,{className:"text-muted-foreground",children:_(A.timestamp)}),c.jsx(ht,{children:c.jsxs(Ce,{onClick:C=>{C.stopPropagation()},size:"icon",variant:"ghost",children:[c.jsx("span",{className:"sr-only",children:"More options"}),"⋯"]})})]},A.id))})]})}),E.length>0&&!x&&c.jsx("div",{className:"flex items-center justify-between text-muted-foreground text-sm",children:c.jsxs("div",{children:["Showing ",E.length," of ",m.length," emails"]})})]}),c.jsx(Uu,{className:"space-y-4",value:"receiving",children:c.jsx(Age,{})})]})})]})}function Cge({data:e}){const t=Tge(e);return t.length===0?c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(Le,{children:"Email Metrics"}),c.jsx(We,{children:"Performance over the last 24 hours"})]}),c.jsx($e,{children:c.jsx("div",{className:"flex h-[400px] items-center justify-center text-muted-foreground",children:"No metrics data available yet"})})]}):c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(Le,{children:"Email Metrics"}),c.jsx(We,{children:"Performance over the last 24 hours"})]}),c.jsx($e,{children:c.jsx(lE,{height:400,width:"100%",children:c.jsxs(X6,{data:t,children:[c.jsx(Wv,{className:"stroke-muted",strokeDasharray:"3 3"}),c.jsx(ws,{className:"text-xs",dataKey:"timestamp",tickFormatter:n=>oS(new Date(n),"HH:mm")}),c.jsx(hi,{className:"text-xs"}),c.jsx(_r,{contentStyle:{backgroundColor:"hsl(var(--popover))",border:"1px solid hsl(var(--border))"},labelFormatter:n=>oS(new Date(n),"MMM d, HH:mm")}),c.jsx(ni,{}),c.jsx(Ar,{dataKey:"sends",name:"Sends",stroke:"hsl(var(--primary))",strokeWidth:2,type:"monotone"}),c.jsx(Ar,{dataKey:"deliveries",name:"Deliveries",stroke:"#82ca9d",strokeWidth:2,type:"monotone"}),c.jsx(Ar,{dataKey:"opens",name:"Opens",stroke:"#8884d8",strokeWidth:2,type:"monotone"}),c.jsx(Ar,{dataKey:"clicks",name:"Clicks",stroke:"#ffc658",strokeWidth:2,type:"monotone"}),c.jsx(Ar,{dataKey:"bounces",name:"Bounces",stroke:"#ff7300",strokeWidth:2,type:"monotone"}),c.jsx(Ar,{dataKey:"complaints",name:"Complaints",stroke:"hsl(var(--destructive))",strokeWidth:2,type:"monotone"})]})})})]})}function Tge(e){const t=new Map;[...e.sends,...e.bounces,...e.complaints,...e.deliveries,...e.opens,...e.clicks].forEach(n=>{t.has(n.timestamp)||t.set(n.timestamp,{timestamp:n.timestamp,sends:0,bounces:0,complaints:0,deliveries:0,opens:0,clicks:0})});for(const n of e.sends)t.get(n.timestamp).sends=n.value;for(const n of e.bounces)t.get(n.timestamp).bounces=n.value;for(const n of e.complaints)t.get(n.timestamp).complaints=n.value;for(const n of e.deliveries)t.get(n.timestamp).deliveries=n.value;for(const n of e.opens)t.get(n.timestamp).opens=n.value;for(const n of e.clicks)t.get(n.timestamp).clicks=n.value;return Array.from(t.values()).sort((n,r)=>n.timestamp-r.timestamp)}function Mge({quota:e}){const t=e.sentLast24Hours/e.max24HourSend*100,n=t>90?"destructive":t>70?"warning":"default";return c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsxs(Le,{className:"flex items-center justify-between",children:["SES Quota",c.jsxs(Be,{variant:n==="destructive"?"destructive":"secondary",children:[t.toFixed(1),"% used"]})]}),c.jsx(We,{children:"24-hour sending limits"})]}),c.jsxs($e,{className:"space-y-4",children:[c.jsxs("div",{children:[c.jsxs("div",{className:"mb-2 flex justify-between text-sm",children:[c.jsx("span",{className:"text-muted-foreground",children:"Emails sent"}),c.jsxs("span",{className:"font-medium",children:[e.sentLast24Hours.toLocaleString()," /"," ",e.max24HourSend.toLocaleString()]})]}),c.jsx(tv,{className:"h-2",value:t})]}),c.jsxs("div",{className:"flex items-center justify-between border-t pt-2",children:[c.jsx("span",{className:"text-muted-foreground text-sm",children:"Max send rate"}),c.jsxs("span",{className:"font-medium text-sm",children:[e.maxSendRate," emails/sec"]})]})]})]})}function Rge(){const[e,t]=S.useState("1"),[n,r]=S.useState(null),[i,o]=S.useState(!0),[l,f]=S.useState(null);if(S.useEffect(()=>{async function _(){try{o(!0),f(null);let A=sessionStorage.getItem("wraps-auth-token");if(A||(A=new URLSearchParams(window.location.search).get("token"),A&&sessionStorage.setItem("wraps-auth-token",A)),!A)throw new Error("Authentication token not found. Please use the URL provided by 'wraps console' command.");const C=Number.parseInt(e,10),N=Date.now()-C*24*60*60*1e3,M=Date.now(),R=await fetch(`/api/metrics?startTime=${N}&endTime=${M}&token=${A}`);if(!R.ok){let L="Failed to fetch email metrics";try{L=(await R.json()).error||L}catch{L=`${R.status}: ${R.statusText}`}throw new Error(L)}const D=await R.json();r(D)}catch(A){const C=A instanceof Error?A.message:"Unknown error";f(C),console.error("Error fetching email metrics:",A)}finally{o(!1)}}_()},[e]),l)return c.jsxs(c.Fragment,{children:[c.jsxs("div",{children:[c.jsx("h1",{className:"font-semibold text-3xl tracking-tight",children:"Email Metrics"}),c.jsx("p",{className:"mt-2 text-muted-foreground",children:"View detailed metrics and analytics for your email campaigns"})]}),c.jsx("div",{className:"mt-4 rounded-md border border-destructive bg-destructive/10 p-4 text-destructive text-sm",children:l})]});if(i||!n)return c.jsxs(c.Fragment,{children:[c.jsxs("div",{children:[c.jsx("h1",{className:"font-semibold text-3xl tracking-tight",children:"Email Metrics"}),c.jsx("p",{className:"mt-2 text-muted-foreground",children:"View detailed metrics and analytics for your email campaigns"})]}),c.jsx("div",{className:"mt-4 flex h-[400px] items-center justify-center text-muted-foreground",children:"Loading metrics..."})]});const d=n.metrics.sends.reduce((_,A)=>_+A.value,0)||0,h=n.metrics.deliveries.reduce((_,A)=>_+A.value,0)||0,v=n.metrics.bounces.reduce((_,A)=>_+A.value,0)||0,m=n.metrics.complaints.reduce((_,A)=>_+A.value,0)||0,g=n.metrics.opens.reduce((_,A)=>_+A.value,0)||0,x=n.metrics.clicks.reduce((_,A)=>_+A.value,0)||0,O=d>0?h/d*100:0,j=h>0?g/h*100:0,b=g>0?x/g*100:0,E=[{title:"Emails Sent",value:d.toLocaleString(),description:`${e==="1"?"Last 24 hours":`Last ${e} days`}`,icon:Sl},{title:"Delivery Rate",value:`${O.toFixed(1)}%`,description:`${h.toLocaleString()} delivered`,icon:Uj},{title:"Open Rate",value:`${j.toFixed(1)}%`,description:`${g.toLocaleString()} opened`,icon:Np},{title:"Click Rate",value:`${b.toFixed(1)}%`,description:`${x.toLocaleString()} clicked`,icon:lF}];return c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("h1",{className:"font-semibold text-3xl tracking-tight",children:"Email Metrics"}),c.jsx("p",{className:"mt-2 text-muted-foreground",children:"View detailed metrics and analytics for your email campaigns"})]}),c.jsxs(ga,{onValueChange:t,value:e,children:[c.jsx(xa,{className:"w-[180px]",children:c.jsx(ya,{})}),c.jsxs(ba,{children:[c.jsx(Fe,{value:"1",children:"Last 24 hours"}),c.jsx(Fe,{value:"7",children:"Last 7 days"}),c.jsx(Fe,{value:"15",children:"Last 15 days"}),c.jsx(Fe,{value:"30",children:"Last 30 days"}),c.jsx(Fe,{value:"90",children:"Last 90 days"})]})]})]}),c.jsx("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-4",children:E.map(_=>c.jsxs(Te,{children:[c.jsxs(Me,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[c.jsx(Le,{className:"font-medium text-sm",children:_.title}),c.jsx(_.icon,{className:"h-4 w-4 text-muted-foreground"})]}),c.jsxs($e,{children:[c.jsx("div",{className:"font-bold text-2xl",children:_.value}),c.jsx("p",{className:"text-muted-foreground text-xs",children:_.description})]})]},_.title))}),c.jsx(Mge,{quota:n.quota}),c.jsx(Cge,{data:n.metrics}),c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(Le,{children:"Metrics Summary"}),c.jsx(We,{children:"Detailed breakdown of your email performance"})]}),c.jsxs($e,{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm",children:"Total Emails Sent"}),c.jsx(Be,{variant:"outline",children:d.toLocaleString()})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm",children:"Successfully Delivered"}),c.jsx(Be,{variant:"default",children:h.toLocaleString()})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm",children:"Opened"}),c.jsx(Be,{variant:"default",children:g.toLocaleString()})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm",children:"Clicked"}),c.jsx(Be,{variant:"default",children:x.toLocaleString()})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm",children:"Bounced"}),c.jsx(Be,{variant:"destructive",children:v.toLocaleString()})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm",children:"Complaints"}),c.jsx(Be,{variant:"destructive",children:m.toLocaleString()})]})]})]})]})}async function Dge(){const e=sessionStorage.getItem("wraps-auth-token");if(!e)throw new Error("Authentication token not found");const t=await fetch(`/api/settings?token=${e}`);if(!t.ok)throw new Error(`Failed to fetch settings: ${t.statusText}`);return await t.json()}const c8="wraps-dns-verification",Pge=1e3*60*60;function u8(){try{const e=localStorage.getItem(c8);return e?JSON.parse(e):{}}catch{return{}}}function _p(e){try{localStorage.setItem(c8,JSON.stringify(e))}catch(t){console.error("Failed to save DNS verification cache:",t)}}function f8(e){return e?Date.now()-e.lastChecked<Pge:!1}async function H4(e,t){console.log("[DNS Verify] verifyTrackingDomain called",{domain:e,expectedTarget:t});const n=u8(),r=`${e}->${t}`;if(n.trackingDomain?.[r]&&f8(n.trackingDomain[r]))return console.log("[DNS Verify] Returning cached result"),n.trackingDomain[r];try{const o=`/api/settings/verify-tracking-domain?token=${sessionStorage.getItem("wraps-auth-token")}&domain=${encodeURIComponent(e)}&expectedTarget=${encodeURIComponent(t)}`;console.log("[DNS Verify] Fetching:",o);const l=await fetch(o);if(console.log("[DNS Verify] Response status:",l.status),!l.ok)throw new Error(`HTTP ${l.status}: ${l.statusText}`);const f=await l.json();console.log("[DNS Verify] Response data:",f);const d={verified:f.verified,lastChecked:Date.now(),error:f.error};return n.trackingDomain||(n.trackingDomain={}),n.trackingDomain[r]=d,_p(n),d}catch(i){console.error("Tracking domain verification request failed:",i);const o={verified:!1,lastChecked:Date.now(),error:i instanceof Error?i.message:"Failed to verify"};return n.trackingDomain||(n.trackingDomain={}),n.trackingDomain[r]=o,_p(n),o}}async function F4(e){console.log("[DNS Verify] verifyDmarc called",{domain:e});const t=u8(),n=`_dmarc.${e}`;if(t.dmarc?.[n]&&f8(t.dmarc[n]))return console.log("[DNS Verify] Returning cached DMARC result"),t.dmarc[n];try{const i=`/api/settings/verify-dmarc?token=${sessionStorage.getItem("wraps-auth-token")}&domain=${encodeURIComponent(e)}`;console.log("[DNS Verify] Fetching:",i);const o=await fetch(i);if(console.log("[DNS Verify] Response status:",o.status),!o.ok)throw new Error(`HTTP ${o.status}: ${o.statusText}`);const l=await o.json();console.log("[DNS Verify] Response data:",l);const f={verified:l.verified,lastChecked:Date.now(),error:l.error};return t.dmarc||(t.dmarc={}),t.dmarc[n]=f,_p(t),f}catch(r){console.error("DMARC verification request failed:",r);const i={verified:!1,lastChecked:Date.now(),error:r instanceof Error?r.message:"Failed to verify"};return t.dmarc||(t.dmarc={}),t.dmarc[n]=i,_p(t),i}}function VE({status:e}){const t={SUCCESS:{icon:so,label:"Verified",variant:"default",className:"bg-green-500/10 text-green-700 dark:text-green-400 border-green-500/20"},PENDING:{icon:Jo,label:"Pending",variant:"secondary",className:"bg-yellow-500/10 text-yellow-700 dark:text-yellow-400 border-yellow-500/20"},FAILED:{icon:m$,label:"Failed",variant:"destructive",className:"bg-red-500/10 text-red-700 dark:text-red-400 border-red-500/20"},TEMPORARY_FAILURE:{icon:lr,label:"Temporary Failure",variant:"secondary",className:"bg-orange-500/10 text-orange-700 dark:text-orange-400 border-orange-500/20"},NOT_STARTED:{icon:Jo,label:"Not Started",variant:"outline",className:"bg-gray-500/10 text-gray-700 dark:text-gray-400 border-gray-500/20"}},{icon:n,label:r,className:i}=t[e];return c.jsxs(Be,{className:i,variant:"outline",children:[c.jsx(n,{className:"mr-1 h-3 w-3"}),r]})}function rc({text:e}){const t=async()=>{await navigator.clipboard.writeText(e),jt.success("Copied to clipboard",{description:"DNS record value copied successfully"})};return c.jsx(Ce,{onClick:t,size:"sm",variant:"ghost",children:c.jsx(zj,{className:"h-3 w-3"})})}function kge({identity:e}){const t=e?.dkimAttributes,n=t?.status==="SUCCESS",[r,i]=S.useState(!n);return t?c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"font-medium",children:"DKIM Authentication"}),c.jsxs("p",{className:"text-muted-foreground text-sm",children:[t.signingEnabled?"Enabled":"Disabled",t.signingKeyLength&&` · ${t.signingKeyLength}`]})]}),c.jsx(VE,{status:t.status})]}),t.tokens&&t.tokens.length>0&&c.jsxs(ms,{onOpenChange:i,open:r,children:[c.jsx(ps,{asChild:!0,children:c.jsxs(Ce,{className:"h-auto w-full justify-between p-0",size:"sm",variant:"ghost",children:[c.jsx("p",{className:"font-medium text-sm",children:"DNS Records (CNAME)"}),r?c.jsx(ac,{className:"h-4 w-4"}):c.jsx(oo,{className:"h-4 w-4"})]})}),c.jsx(vs,{className:"mt-2 space-y-2",children:t.tokens.map(o=>c.jsxs("div",{className:"rounded-md border bg-muted/50 p-3",children:[c.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[c.jsxs("p",{className:"font-mono text-xs",children:[o,"._domainkey.",e.identityName]}),c.jsx(rc,{text:`${o}._domainkey.${e.identityName}`})]}),c.jsxs("p",{className:"font-mono text-muted-foreground text-xs",children:["CNAME → ",o,".dkim.amazonses.com"]})]},o))})]})]}):c.jsx("div",{className:"space-y-4",children:c.jsx("div",{className:"flex items-center justify-between",children:c.jsxs("div",{children:[c.jsx("p",{className:"font-medium",children:"DKIM Authentication"}),c.jsx("p",{className:"text-muted-foreground text-sm",children:"Not configured"})]})})})}function $ge({identity:e}){const t=e?.mailFromAttributes,n=t?.mailFromDomainStatus==="SUCCESS",[r,i]=S.useState(!n);return c.jsx("div",{className:"space-y-4",children:t?.mailFromDomain?c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"font-medium",children:"Mail-From Domain"}),c.jsxs("p",{className:"text-muted-foreground text-sm",children:[t.mailFromDomain,t.behaviorOnMxFailure&&` · ${t.behaviorOnMxFailure==="USE_DEFAULT_VALUE"?"Fallback enabled":"Reject on failure"}`]})]}),t.mailFromDomainStatus&&c.jsx(VE,{status:t.mailFromDomainStatus})]}),c.jsxs(ms,{onOpenChange:i,open:r,children:[c.jsx(ps,{asChild:!0,children:c.jsxs(Ce,{className:"h-auto w-full justify-between p-0",size:"sm",variant:"ghost",children:[c.jsx("p",{className:"font-medium text-sm",children:"DNS Record (MX)"}),r?c.jsx(ac,{className:"h-4 w-4"}):c.jsx(oo,{className:"h-4 w-4"})]})}),c.jsx(vs,{className:"mt-2",children:c.jsx("div",{className:"rounded-md border bg-muted/50 p-3",children:c.jsxs("div",{className:"space-y-1",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("p",{className:"font-mono text-xs",children:["MX ",t.mailFromDomain]}),c.jsx(rc,{text:`10 feedback-smtp.${e?.identityName.split(".")[0]}.amazonses.com`})]}),c.jsxs("p",{className:"font-mono text-muted-foreground text-xs",children:["Priority 10 → feedback-smtp.",e?.identityName.split(".")[0],".amazonses.com"]})]})})})]})]}):c.jsx("div",{className:"flex items-center justify-between",children:c.jsxs("div",{children:[c.jsx("p",{className:"font-medium",children:"Mail-From Domain"}),c.jsx("p",{className:"text-muted-foreground text-sm",children:"Using default amazonses.com domain"})]})})})}function Ige({identity:e}){const[t,n]=S.useState(null),[r,i]=S.useState(!1),[o,l]=S.useState(!t?.verified);S.useEffect(()=>{e?.identityName&&F4(e.identityName).then(n)},[e?.identityName]),S.useEffect(()=>{t&&l(!t.verified)},[t]);const f=async()=>{if(e?.identityName){i(!0);try{const d=await F4(e.identityName);n(d),d.verified?jt.success("DMARC record verified",{description:"DNS TXT record found and configured correctly"}):(console.error("DMARC verification failed:",d.error),jt.error("Verification failed",{description:d.error||"DMARC record not found"}))}catch(d){console.error("DMARC verification error:",d),jt.error("Verification error",{description:d instanceof Error?d.message:"Unknown error"})}finally{i(!1)}}};return c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"font-medium",children:"DMARC Policy"}),c.jsx("p",{className:"text-muted-foreground text-sm",children:t?.verified?"Configured":"Recommended for better deliverability"})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[t?.verified&&c.jsxs(Be,{className:"border-green-500/20 bg-green-500/10 text-green-700 dark:text-green-400",variant:"outline",children:[c.jsx(so,{className:"mr-1 h-3 w-3"}),"Verified by Wraps"]}),c.jsx(Ce,{className:"h-8 w-8 p-0",disabled:r,onClick:f,size:"sm",variant:"ghost",children:c.jsx(Lf,{className:`h-4 w-4 ${r?"animate-spin":""}`})})]})]}),c.jsxs(ms,{onOpenChange:l,open:o,children:[c.jsx(ps,{asChild:!0,children:c.jsxs(Ce,{className:"h-auto w-full justify-between p-0",size:"sm",variant:"ghost",children:[c.jsx("p",{className:"font-medium text-sm",children:"DNS Record (TXT)"}),o?c.jsx(ac,{className:"h-4 w-4"}):c.jsx(oo,{className:"h-4 w-4"})]})}),c.jsx(vs,{className:"mt-2",children:c.jsxs("div",{className:"rounded-md border bg-muted/50 p-3",children:[c.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[c.jsxs("p",{className:"font-mono text-xs",children:["_dmarc.",e?.identityName||"yourdomain.com"]}),c.jsx(rc,{text:`_dmarc.${e?.identityName||"yourdomain.com"}`})]}),c.jsxs("div",{className:"flex items-start justify-between gap-2",children:[c.jsxs("p",{className:"font-mono text-muted-foreground text-xs",children:["v=DMARC1; p=quarantine; sp=quarantine; np=reject; rua=mailto:dmarc@",e?.identityName||"yourdomain.com"]}),c.jsx(rc,{text:`v=DMARC1; p=quarantine; sp=quarantine; np=reject; rua=mailto:dmarc@${e?.identityName||"yourdomain.com"}`})]})]})})]})]})}function Lge({configSet:e,region:t,onRefresh:n}){const r=e?.trackingOptions,[i,o]=S.useState(null),[l,f]=S.useState(!1),[d,h]=S.useState(!1),[v,m]=S.useState(""),[g,x]=S.useState(!1),[O,j]=S.useState(!i?.verified);S.useEffect(()=>{if(r?.customRedirectDomain&&t){const A=`r.${t}.awstrack.me`;H4(r.customRedirectDomain,A).then(o)}},[r?.customRedirectDomain,t]),S.useEffect(()=>{i&&j(!i.verified)},[i]);const b=async()=>{if(r?.customRedirectDomain&&t){f(!0);try{const A=`r.${t}.awstrack.me`,C=await H4(r.customRedirectDomain,A);o(C),C.verified?jt.success("Tracking domain verified",{description:"DNS records are configured correctly"}):(console.error("Tracking domain verification failed:",C.error),jt.error("Verification failed",{description:C.error||"DNS records not found"}))}catch(A){console.error("Tracking domain verification error:",A),jt.error("Verification error",{description:A instanceof Error?A.message:"Unknown error"})}finally{f(!1)}}},E=()=>{m(r?.customRedirectDomain||""),h(!0)},_=async()=>{if(!v.trim()){jt.error("Invalid domain",{description:"Please enter a valid domain name"});return}x(!0);try{const A=sessionStorage.getItem("wraps-auth-token"),C=await fetch(`/api/settings/config-set/tracking-domain?token=${A}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({domain:v})});if(!C.ok){const N=await C.json();throw new Error(N.error||`Failed to update: ${C.statusText}`)}h(!1),jt.success("Tracking domain updated",{description:"Don't forget to configure the DNS records"}),n&&await n()}catch(A){console.error("Failed to update tracking domain:",A),jt.error("Failed to update tracking domain",{description:A instanceof Error?A.message:"Unknown error"})}finally{x(!1)}};return c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(Le,{children:"Tracking Domain"}),c.jsx(We,{children:"Custom domain for open and click tracking links"})]}),c.jsx($e,{className:"space-y-4",children:r?.customRedirectDomain?c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex-1",children:[c.jsx("p",{className:"font-medium",children:r.customRedirectDomain}),c.jsx("p",{className:"text-muted-foreground text-sm",children:"Custom Tracking Domain"})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[i?.verified&&c.jsxs(Be,{className:"border-green-500/20 bg-green-500/10 text-green-700 dark:text-green-400",variant:"outline",children:[c.jsx(so,{className:"mr-1 h-3 w-3"}),"Verified by Wraps"]}),c.jsx(Be,{variant:"outline",children:r.httpsPolicy==="REQUIRE"?"HTTPS Only":"HTTPS Optional"}),c.jsx(Ce,{className:"h-8 w-8 p-0",disabled:l,onClick:b,size:"sm",variant:"ghost",children:c.jsx(Lf,{className:`h-4 w-4 ${l?"animate-spin":""}`})}),c.jsx(Ce,{className:"h-8 w-8 p-0",onClick:E,size:"sm",variant:"ghost",children:c.jsx(nC,{className:"h-4 w-4"})})]})]}),c.jsxs(ms,{onOpenChange:j,open:O,children:[c.jsx(ps,{asChild:!0,children:c.jsxs(Ce,{className:"h-auto w-full justify-between p-0",size:"sm",variant:"ghost",children:[c.jsx("p",{className:"font-medium text-sm",children:"Required DNS Record (CNAME)"}),O?c.jsx(ac,{className:"h-4 w-4"}):c.jsx(oo,{className:"h-4 w-4"})]})}),c.jsx(vs,{className:"mt-2",children:c.jsxs("div",{className:"rounded-md border bg-muted/50 p-3",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("p",{className:"font-mono text-xs",children:r.customRedirectDomain}),c.jsx(rc,{text:r.customRedirectDomain})]}),c.jsxs("div",{className:"mt-1 flex items-start justify-between gap-2",children:[c.jsxs("p",{className:"font-mono text-muted-foreground text-xs",children:["CNAME → r.",e?.name||"region",".awstrack.me"]}),c.jsx(rc,{text:`r.${e?.name||"region"}.awstrack.me`})]})]})})]})]}):c.jsxs("div",{className:"space-y-4",children:[c.jsx("p",{className:"text-muted-foreground text-sm",children:"No custom tracking domain configured. Using default awstrack.me domain."}),c.jsxs(Ce,{onClick:E,size:"sm",variant:"outline",children:[c.jsx(nC,{className:"mr-2 h-4 w-4"}),"Configure Tracking Domain"]})]})}),c.jsx(MO,{onOpenChange:h,open:d,children:c.jsxs(RO,{children:[c.jsxs(bL,{children:[c.jsx(SL,{children:"Update Tracking Domain"}),c.jsx(PX,{children:"Enter the custom domain you want to use for email tracking links. You'll need to configure DNS records after saving."})]}),c.jsx("div",{className:"space-y-4 py-4",children:c.jsxs("div",{className:"space-y-2",children:[c.jsx(Ho,{htmlFor:"domain",children:"Tracking Domain"}),c.jsx(fs,{disabled:g,id:"domain",onChange:A=>m(A.target.value),placeholder:"track.example.com",value:v}),c.jsx("p",{className:"text-muted-foreground text-xs",children:"Example: track.yourdomain.com or email.yourdomain.com"})]})}),c.jsxs(wL,{children:[c.jsx(Ce,{disabled:g,onClick:()=>h(!1),variant:"outline",children:"Cancel"}),c.jsx(Ce,{disabled:g,onClick:_,children:g?"Updating...":"Update Domain"})]})]})})]})}function zge({configSet:e,onRefresh:t}){const[n,r]=S.useState(!1),[i,o]=S.useState(!1),[l,f]=S.useState(!1);if(!e)return c.jsx(Te,{children:c.jsxs(Me,{children:[c.jsx(Le,{children:"Configuration Set"}),c.jsx(We,{children:"No configuration set found"})]})});const d=async()=>{f(!0);try{const v=sessionStorage.getItem("wraps-auth-token"),m=!e.sendingOptions?.sendingEnabled,g=await fetch(`/api/settings/config-set/sending?token=${v}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:m})});if(!g.ok)throw new Error(`Failed to update: ${g.statusText}`);r(!1),jt.success(m?"Email sending enabled":"Email sending disabled"),t&&await t()}catch(v){console.error("Failed to toggle sending:",v),jt.error("Failed to update setting",{description:v instanceof Error?v.message:"Unknown error"})}finally{f(!1)}},h=async()=>{f(!0);try{const v=sessionStorage.getItem("wraps-auth-token"),m=!e.reputationOptions?.reputationMetricsEnabled,g=await fetch(`/api/settings/config-set/reputation?token=${v}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:m})});if(!g.ok)throw new Error(`Failed to update: ${g.statusText}`);o(!1),jt.success(m?"Reputation metrics enabled":"Reputation metrics disabled"),t&&await t()}catch(v){console.error("Failed to toggle reputation:",v),jt.error("Failed to update setting",{description:v instanceof Error?v.message:"Unknown error"})}finally{f(!1)}};return c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(Le,{children:"Configuration Set"}),c.jsx(We,{children:"Email sending and tracking configuration"})]}),c.jsxs($e,{className:"space-y-6",children:[c.jsxs("div",{children:[c.jsx("p",{className:"font-medium",children:e.name}),c.jsx("p",{className:"text-muted-foreground text-sm",children:"Configuration Set Name"})]}),c.jsx(Vt,{}),e.sendingOptions&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex-1 space-y-0.5",children:[c.jsx("p",{className:"font-medium text-sm",children:"Email Sending"}),c.jsx("p",{className:"text-muted-foreground text-sm",children:e.sendingOptions.sendingEnabled?"Emails can be sent":"Email sending is disabled"})]}),c.jsx(Ce,{onClick:()=>r(!0),size:"sm",variant:e.sendingOptions.sendingEnabled?"destructive":"default",children:e.sendingOptions.sendingEnabled?"Disable":"Enable"})]}),c.jsx(dm,{onOpenChange:r,open:n,children:c.jsxs(hm,{children:[c.jsxs(mm,{children:[c.jsx(vm,{children:e.sendingOptions.sendingEnabled?"Disable email sending?":"Enable email sending?"}),c.jsx(gm,{children:e.sendingOptions.sendingEnabled?"All outgoing emails will be blocked until you re-enable sending. Emails in the queue will not be sent.":"This will allow emails to be sent through this configuration set. Make sure your domain is verified before enabling."})]}),c.jsxs(pm,{children:[c.jsx(xm,{disabled:l,children:"Cancel"}),c.jsx(ym,{disabled:l,onClick:d,children:l?"Updating...":e.sendingOptions.sendingEnabled?"Disable sending":"Enable sending"})]})]})})]}),e.reputationOptions&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex-1 space-y-0.5",children:[c.jsx("p",{className:"font-medium text-sm",children:"Reputation Metrics"}),c.jsx("p",{className:"text-muted-foreground text-sm",children:e.reputationOptions.reputationMetricsEnabled?"Tracking bounce and complaint rates":"Reputation tracking disabled"})]}),c.jsx(Ce,{onClick:()=>o(!0),size:"sm",variant:"outline",children:e.reputationOptions.reputationMetricsEnabled?"Disable":"Enable"})]}),c.jsx(dm,{onOpenChange:o,open:i,children:c.jsxs(hm,{children:[c.jsxs(mm,{children:[c.jsx(vm,{children:e.reputationOptions.reputationMetricsEnabled?"Disable reputation metrics?":"Enable reputation metrics?"}),c.jsx(gm,{children:e.reputationOptions.reputationMetricsEnabled?"You will stop collecting bounce and complaint rate data. Historical data will be preserved but no new metrics will be tracked.":"This will start tracking bounce and complaint rates for your sending domain. This helps monitor your email reputation and deliverability."})]}),c.jsxs(pm,{children:[c.jsx(xm,{disabled:l,children:"Cancel"}),c.jsx(ym,{disabled:l,onClick:h,children:l?"Updating...":e.reputationOptions.reputationMetricsEnabled?"Disable metrics":"Enable metrics"})]})]})})]}),e.deliveryOptions?.tlsPolicy&&c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"space-y-0.5",children:[c.jsx("p",{className:"font-medium text-sm",children:"TLS Encryption"}),c.jsx("p",{className:"text-muted-foreground text-sm",children:e.deliveryOptions.tlsPolicy==="REQUIRE"?"Required for all connections":"Optional (opportunistic)"})]}),c.jsx(Be,{variant:"outline",children:e.deliveryOptions.tlsPolicy==="REQUIRE"?"Required":"Optional"})]}),e.suppressionOptions&&c.jsxs("div",{className:"space-y-2",children:[c.jsxs("div",{className:"space-y-0.5",children:[c.jsx("p",{className:"font-medium text-sm",children:"Suppression List"}),c.jsx("p",{className:"text-muted-foreground text-sm",children:"Automatically suppress emails to addresses that bounced or complained"})]}),e.suppressionOptions.suppressedReasons&&e.suppressionOptions.suppressedReasons.length>0?c.jsx("div",{className:"flex gap-2",children:e.suppressionOptions.suppressedReasons.map(v=>c.jsx(Be,{variant:"secondary",children:v},v))}):c.jsx("p",{className:"text-muted-foreground text-sm",children:"Not configured"})]}),e.deliveryOptions?.sendingPoolName&&c.jsxs("div",{children:[c.jsx("p",{className:"font-medium text-sm",children:"IP Pool"}),c.jsx("p",{className:"text-muted-foreground text-sm",children:e.deliveryOptions.sendingPoolName})]})]})]})}function Bge(){const[e,t]=S.useState(null),[n,r]=S.useState(!0),[i,o]=S.useState(null),l=S.useCallback(async()=>{try{r(!0);const f=await Dge();t(f),o(null)}catch(f){console.error("Failed to fetch email settings:",f),o(f instanceof Error?f.message:"Failed to load settings")}finally{r(!1)}},[]);return S.useEffect(()=>{l()},[l]),n?c.jsxs(c.Fragment,{children:[c.jsxs("div",{children:[c.jsx("h1",{className:"font-semibold text-3xl tracking-tight",children:"Email Settings"}),c.jsx("p",{className:"mt-2 text-muted-foreground",children:"Configure your email settings and preferences"})]}),c.jsxs("div",{className:"mt-6 grid gap-6 md:grid-cols-2",children:[c.jsxs(Te,{className:"md:row-span-2",children:[c.jsxs(Me,{children:[c.jsx(De,{className:"h-6 w-48"}),c.jsx(De,{className:"mt-2 h-4 w-64"})]}),c.jsxs($e,{className:"space-y-6",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(De,{className:"h-4 w-32"}),c.jsx(De,{className:"h-4 w-24"})]}),c.jsx(De,{className:"h-px w-full"}),c.jsxs("div",{className:"space-y-2",children:[c.jsx(De,{className:"h-4 w-40"}),c.jsx(De,{className:"h-4 w-28"})]}),c.jsx(De,{className:"h-px w-full"}),c.jsxs("div",{className:"space-y-2",children:[c.jsx(De,{className:"h-4 w-36"}),c.jsx(De,{className:"h-4 w-32"})]}),c.jsx(De,{className:"h-px w-full"}),c.jsxs("div",{className:"space-y-2",children:[c.jsx(De,{className:"h-4 w-32"}),c.jsx(De,{className:"h-4 w-44"})]})]})]}),c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(De,{className:"h-6 w-48"}),c.jsx(De,{className:"mt-2 h-4 w-64"})]}),c.jsx($e,{children:c.jsx(De,{className:"h-20 w-full"})})]}),c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(De,{className:"h-6 w-48"}),c.jsx(De,{className:"mt-2 h-4 w-64"})]}),c.jsx($e,{children:c.jsx(De,{className:"h-20 w-full"})})]})]})]}):i?c.jsxs(c.Fragment,{children:[c.jsxs("div",{children:[c.jsx("h1",{className:"font-semibold text-3xl tracking-tight",children:"Email Settings"}),c.jsx("p",{className:"mt-2 text-muted-foreground",children:"Configure your email settings and preferences"})]}),c.jsxs(Un,{className:"mt-6",variant:"destructive",children:[c.jsx(lr,{className:"h-4 w-4"}),c.jsx(ro,{children:"Error Loading Settings"}),c.jsx(Hn,{children:i})]})]}):c.jsxs(c.Fragment,{children:[c.jsxs("div",{children:[c.jsx("h1",{className:"font-semibold text-3xl tracking-tight",children:"Email Settings"}),c.jsx("p",{className:"mt-2 text-muted-foreground",children:"Configure your email settings and preferences"})]}),c.jsxs("div",{className:"mt-6 grid gap-6 md:grid-cols-2",children:[c.jsxs(Te,{className:"md:row-span-2",children:[c.jsxs(Me,{children:[c.jsx(Le,{children:"Sending Domain"}),c.jsx(We,{children:"Email domain configuration and authentication"})]}),c.jsxs($e,{className:"space-y-6",children:[c.jsx("div",{className:"space-y-4",children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex-1",children:[c.jsx("p",{className:"font-medium",children:e?.identity?.identityName}),c.jsx("p",{className:"text-muted-foreground text-sm",children:"Domain Identity"})]}),c.jsx(VE,{status:e?.identity?.verificationStatus||"NOT_STARTED"})]})}),c.jsx(Vt,{}),c.jsx(kge,{identity:e?.identity}),c.jsx(Vt,{}),c.jsx($ge,{identity:e?.identity}),c.jsx(Vt,{}),c.jsx(Ige,{identity:e?.identity})]})]}),c.jsx(zge,{configSet:e?.configurationSet,onRefresh:l}),c.jsx(Lge,{configSet:e?.configurationSet,onRefresh:l,region:e?.region})]})]})}function B1(e){return e.name?`${e.name} <${e.address}>`:e.address}function qge(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function Gh({label:e,verdict:t}){if(!t)return null;const n=t==="PASS";return c.jsxs(Be,{className:n?"bg-green-500/10 text-green-700 dark:text-green-400 border-green-500/20":"bg-red-500/10 text-red-700 dark:text-red-400 border-red-500/20",variant:"outline",children:[n?c.jsx(x$,{className:"mr-1 h-3 w-3"}):c.jsx(y$,{className:"mr-1 h-3 w-3"}),e,": ",t]})}function Uge(){const{emailId:e}=hO(),t=_a(),[n,r]=S.useState(null),[i,o]=S.useState(!0),[l,f]=S.useState(null),[d,h]=S.useState(!1);return S.useEffect(()=>{async function v(){try{o(!0),f(null);const m=sessionStorage.getItem("wraps-auth-token");if(!m)throw new Error("Authentication token not found");const g=await fetch(`/api/inbound/${encodeURIComponent(e||"")}?token=${m}`);if(!g.ok){let O="Failed to fetch inbound email";try{O=(await g.json()).error||O}catch{O=`${g.status}: ${g.statusText}`}throw new Error(O)}const x=await g.json();r(x)}catch(m){const g=m instanceof Error?m.message:"Unknown error";f(g),console.error("Error fetching inbound email:",m)}finally{o(!1)}}e&&v()},[e]),i?c.jsx("div",{className:"flex h-[600px] items-center justify-center",children:c.jsx("div",{className:"text-muted-foreground",children:"Loading inbound email..."})}):l?c.jsxs("div",{className:"space-y-4",children:[c.jsxs(Ce,{onClick:()=>t("/email?tab=receiving"),size:"sm",variant:"ghost",children:[c.jsx(Za,{className:"mr-2 h-4 w-4"}),"Back to emails"]}),c.jsx("div",{className:"rounded-md border border-destructive bg-destructive/10 p-4 text-destructive text-sm",children:l})]}):n?c.jsxs("div",{className:"space-y-6",children:[c.jsx("div",{className:"flex items-center gap-4",children:c.jsxs(Ce,{onClick:()=>t("/email?tab=receiving"),size:"sm",variant:"ghost",children:[c.jsx(Za,{className:"mr-2 h-4 w-4"}),"Back"]})}),c.jsx(Te,{children:c.jsxs(Me,{className:"space-y-1.5",children:[c.jsx(Le,{className:"flex flex-row items-center gap-2 text-xl",children:c.jsx("span",{children:n.subject||"(no subject)"})}),c.jsxs("div",{className:"flex flex-wrap gap-2",children:[c.jsx(Gh,{label:"Spam",verdict:n.spamVerdict}),c.jsx(Gh,{label:"Virus",verdict:n.virusVerdict}),n.headers["x-ses-dkim-verdict"]&&c.jsx(Gh,{label:"DKIM",verdict:n.headers["x-ses-dkim-verdict"]}),n.headers["x-ses-spf-verdict"]&&c.jsx(Gh,{label:"SPF",verdict:n.headers["x-ses-spf-verdict"]})]}),c.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[c.jsx("code",{className:"min-w-0 truncate rounded bg-muted px-2 py-0.5 font-mono text-muted-foreground text-xs",children:n.messageId}),c.jsx(ma,{className:"h-6 w-6 shrink-0",size:"sm",value:n.messageId,variant:"ghost"})]}),c.jsxs("div",{className:"flex flex-col gap-3 pt-2 sm:flex-row sm:flex-wrap",children:[c.jsxs(Cl,{className:"w-full cursor-text! sm:w-auto sm:min-w-[518px]",children:[c.jsx(ca,{align:"inline-start",children:c.jsx(Tl,{children:"From"})}),c.jsx(Ml,{className:"min-w-0 cursor-text! truncate font-mono text-sm",disabled:!0,readOnly:!0,value:B1(n.from)}),c.jsx(ca,{align:"inline-end",children:c.jsx(ma,{className:"h-6 w-6",size:"sm",value:n.from.address,variant:"ghost"})})]}),c.jsxs(Cl,{className:"w-full cursor-text! sm:w-auto sm:min-w-[518px]",children:[c.jsx(ca,{align:"inline-start",children:c.jsx(Tl,{children:"To"})}),c.jsx(Ml,{className:"min-w-0 cursor-text! truncate font-mono text-sm",disabled:!0,readOnly:!0,value:n.to.length>0?n.to.map(B1).join(", "):"(no recipients)"})]}),n.cc.length>0&&c.jsxs(Cl,{className:"w-full cursor-text! sm:w-auto sm:min-w-[518px]",children:[c.jsx(ca,{align:"inline-start",children:c.jsx(Tl,{children:"CC"})}),c.jsx(Ml,{className:"min-w-0 cursor-text! truncate font-mono text-sm",disabled:!0,readOnly:!0,value:n.cc.map(B1).join(", ")})]})]}),c.jsxs("div",{className:"text-muted-foreground text-sm",children:["Received: ",new Date(n.receivedAt).toLocaleString()]})]})}),c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(Le,{children:"Message Body"}),n.htmlTruncated&&c.jsx(We,{className:"text-amber-600",children:"HTML content was truncated due to size limits"})]}),c.jsx($e,{children:n.html?c.jsx("iframe",{className:"h-[500px] w-full rounded-md border bg-white",sandbox:"allow-same-origin",srcDoc:n.html,title:"Email content"}):n.text?c.jsx("pre",{className:"max-h-[500px] overflow-auto whitespace-pre-wrap rounded-md border bg-muted/50 p-4 font-mono text-sm",children:n.text}):c.jsx("div",{className:"text-muted-foreground text-sm",children:"No message body"})})]}),n.attachments.length>0&&c.jsxs(Te,{children:[c.jsx(Me,{children:c.jsxs(Le,{className:"flex items-center gap-2",children:[c.jsx(g$,{className:"h-4 w-4"}),"Attachments (",n.attachments.length,")"]})}),c.jsx($e,{children:c.jsx("div",{className:"space-y-2",children:n.attachments.map(v=>c.jsx("div",{className:"flex items-center justify-between rounded-md border p-3",children:c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx(p$,{className:"h-5 w-5 text-muted-foreground"}),c.jsxs("div",{children:[c.jsx("div",{className:"font-medium text-sm",children:v.filename}),c.jsxs("div",{className:"text-muted-foreground text-xs",children:[v.contentType," · ",qge(v.size),v.contentDisposition==="inline"&&c.jsx(Be,{className:"ml-2 bg-blue-500/10 text-blue-700 dark:text-blue-400 border-blue-500/20",variant:"outline",children:"inline"})]})]})]})},v.id))})})]}),c.jsx(ms,{onOpenChange:h,open:d,children:c.jsxs(Te,{children:[c.jsx(ps,{asChild:!0,children:c.jsx(Me,{className:"cursor-pointer",children:c.jsxs(Le,{className:"flex items-center justify-between",children:[c.jsx("span",{children:"Raw Headers"}),d?c.jsx(ac,{className:"h-4 w-4"}):c.jsx(oo,{className:"h-4 w-4"})]})})}),c.jsx(vs,{children:c.jsx($e,{children:c.jsx("pre",{className:"max-h-[400px] overflow-auto whitespace-pre-wrap rounded-md border bg-muted/50 p-4 font-mono text-xs",children:Object.entries(n.headers).map(([v,m])=>`${v}: ${m}`).join(`
127
127
  `)})})})]})})]}):c.jsxs("div",{className:"space-y-4",children:[c.jsxs(Ce,{onClick:()=>t("/email?tab=receiving"),size:"sm",variant:"ghost",children:[c.jsx(Za,{className:"mr-2 h-4 w-4"}),"Back to emails"]}),c.jsx("div",{className:"rounded-md border p-4 text-muted-foreground text-sm",children:"Inbound email not found"})]})}const Hge={sent:eo,delivered:ai,failed:or,queued:Jo,blocked:or,carrier_unreachable:em,invalid:or,opted_out:or,ttl_expired:Jo},Fge={sent:"text-blue-500",delivered:"text-green-500",failed:"text-red-500",queued:"text-gray-500",blocked:"text-orange-500",carrier_unreachable:"text-red-500",invalid:"text-red-500",opted_out:"text-yellow-500",ttl_expired:"text-gray-500"},Gge={delivered:"default",sent:"secondary",queued:"secondary",failed:"destructive",blocked:"destructive",invalid:"destructive",opted_out:"default"};function Vge(){const{id:e}=hO(),t=_a(),[n,r]=S.useState(null),[i,o]=S.useState(!0),[l,f]=S.useState(null);S.useEffect(()=>{async function m(){try{o(!0),f(null);const g=sessionStorage.getItem("wraps-auth-token");if(!g)throw new Error("Authentication token not found");const x=encodeURIComponent(e||""),O=await fetch(`/api/sms/${x}?token=${g}`);if(!O.ok){let E="Failed to fetch SMS details";try{E=(await O.json()).error||E}catch{E=`${O.status}: ${O.statusText}`}throw new Error(E)}if(!O.headers.get("content-type")?.includes("application/json")){const E=await O.text();throw console.error("Non-JSON response:",E),new Error("Server returned non-JSON response")}const b=await O.json();r(b)}catch(g){const x=g instanceof Error?g.message:"Unknown error";f(x),console.error("Error fetching SMS details:",g)}finally{o(!1)}}e&&m()},[e]);const d=m=>new Date(m).toLocaleString("en-US",{month:"short",day:"numeric",hour:"numeric",minute:"2-digit",hour12:!0}),h=m=>new Date(m).toLocaleString("en-US",{weekday:"short",month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit",second:"2-digit",hour12:!0}),v=m=>m.startsWith("+1")&&m.length===12?`(${m.slice(2,5)}) ${m.slice(5,8)}-${m.slice(8)}`:m;return i?c.jsx("div",{className:"flex h-[600px] items-center justify-center",children:c.jsx("div",{className:"text-muted-foreground",children:"Loading SMS details..."})}):l?c.jsxs("div",{className:"space-y-4",children:[c.jsxs(Ce,{onClick:()=>t("/sms"),size:"sm",variant:"ghost",children:[c.jsx(Za,{className:"mr-2 h-4 w-4"}),"Back to messages"]}),c.jsx("div",{className:"rounded-md border border-destructive bg-destructive/10 p-4 text-destructive text-sm",children:l})]}):n?c.jsxs("div",{className:"space-y-6",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs(Ce,{onClick:()=>t("/sms"),size:"sm",variant:"ghost",children:[c.jsx(Za,{className:"mr-2 h-4 w-4"}),"Back to messages"]}),c.jsx(Be,{variant:Gge[n.status],children:n.status.charAt(0).toUpperCase()+n.status.slice(1).replace("_"," ")})]}),c.jsxs(Te,{children:[c.jsx(Me,{children:c.jsx("div",{className:"flex items-start justify-between",children:c.jsxs("div",{className:"space-y-1.5",children:[c.jsxs(Le,{className:"flex items-center gap-2 text-2xl",children:[c.jsx(eo,{className:"h-6 w-6"}),"SMS Message"]}),c.jsx(We,{className:"font-mono text-xs",children:n.messageId})]})})}),c.jsx($e,{className:"space-y-4",children:c.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[c.jsxs("div",{className:"space-y-1",children:[c.jsx("div",{className:"text-muted-foreground text-sm",children:"FROM"}),c.jsx("div",{className:"font-mono text-sm",children:v(n.from)})]}),c.jsxs("div",{className:"space-y-1",children:[c.jsx("div",{className:"text-muted-foreground text-sm",children:"TO"}),c.jsx("div",{className:"font-mono text-sm",children:v(n.to)})]}),c.jsxs("div",{className:"space-y-1",children:[c.jsx("div",{className:"text-muted-foreground text-sm",children:"SEGMENTS"}),c.jsx("div",{className:"font-mono text-sm",children:n.segments})]}),c.jsxs("div",{className:"space-y-1",children:[c.jsx("div",{className:"text-muted-foreground text-sm",children:"ID"}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("code",{className:"rounded bg-muted px-2 py-1 font-mono text-xs",children:n.id}),c.jsx(Ce,{className:"h-6 w-6",onClick:()=>navigator.clipboard.writeText(n.id),size:"icon",variant:"ghost",children:c.jsx("span",{className:"sr-only",children:"Copy ID"})})]})]})]})})]}),c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(Le,{children:"Message Content"}),c.jsx(We,{children:"The SMS message body"})]}),c.jsx($e,{children:c.jsx("div",{className:"rounded-md border bg-muted/50 p-4",children:c.jsx("p",{className:"whitespace-pre-wrap text-sm",children:n.body})})})]}),c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(Le,{children:"Message Events"}),c.jsx(We,{children:"Lifecycle of this message from send to delivery"})]}),c.jsx($e,{children:c.jsx("div",{className:"space-y-4",children:n.events.length===0?c.jsx("div",{className:"text-muted-foreground text-sm",children:"No events recorded yet"}):n.events.map((m,g)=>{const x=Hge[m.type]||Jo,O=g===n.events.length-1;return c.jsx("div",{children:c.jsxs("div",{className:"flex gap-4",children:[c.jsxs("div",{className:"flex flex-col items-center",children:[c.jsx("div",{className:`rounded-full border-2 border-background bg-muted p-2 ${Fge[m.type]}`,children:c.jsx(x,{className:"h-4 w-4"})}),!O&&c.jsx("div",{className:"my-1 w-px flex-1 bg-border"})]}),c.jsxs("div",{className:"flex-1 pb-6",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("div",{className:"font-medium capitalize",children:m.type.replace("_"," ")}),c.jsx("div",{className:"text-muted-foreground text-sm",children:d(m.timestamp)})]}),c.jsx("div",{className:"text-muted-foreground text-sm",children:h(m.timestamp)}),m.metadata&&Object.keys(m.metadata).length>0&&c.jsx("div",{className:"mt-2 rounded-md border bg-muted/50 p-2 font-mono text-xs",children:c.jsx("pre",{className:"overflow-x-auto",children:JSON.stringify(m.metadata,null,2)})})]})]})},`${m.type}-${m.timestamp}`)})})})]})]}):c.jsxs("div",{className:"space-y-4",children:[c.jsxs(Ce,{onClick:()=>t("/sms"),size:"sm",variant:"ghost",children:[c.jsx(Za,{className:"mr-2 h-4 w-4"}),"Back to messages"]}),c.jsx("div",{className:"rounded-md border p-4 text-muted-foreground text-sm",children:"SMS message not found"})]})}const q1={delivered:{variant:"default",description:"Message was delivered to recipient's device",className:"bg-green-500/10 text-green-700 dark:text-green-400 hover:bg-green-500/20 border-green-500/20"},sent:{variant:"secondary",description:"Message was sent but delivery not yet confirmed",className:"bg-blue-500/10 text-blue-700 dark:text-blue-400 hover:bg-blue-500/20 border-blue-500/20"},queued:{variant:"secondary",description:"Message is queued for delivery",className:"bg-gray-500/10 text-gray-700 dark:text-gray-400 hover:bg-gray-500/20 border-gray-500/20"},failed:{variant:"destructive",description:"Message failed to deliver",className:"bg-red-500/10 text-red-700 dark:text-red-400 hover:bg-red-500/20 border-red-500/20"},blocked:{variant:"destructive",description:"Message was blocked by carrier or filter",className:"bg-orange-500/10 text-orange-700 dark:text-orange-400 hover:bg-orange-500/20 border-orange-500/20"},invalid:{variant:"destructive",description:"Invalid phone number or message format",className:"bg-red-500/10 text-red-700 dark:text-red-400 hover:bg-red-500/20 border-red-500/20"},opted_out:{variant:"default",description:"Recipient has opted out of receiving messages",className:"bg-yellow-500/10 text-yellow-700 dark:text-yellow-400 hover:bg-yellow-500/20 border-yellow-500/20"}};function Yge(){const e=_a(),[t,n]=S.useState(""),[r,i]=S.useState("15"),[o,l]=S.useState("all"),[f,d]=S.useState([]),[h,v]=S.useState(!0),[m,g]=S.useState(null);S.useEffect(()=>{async function b(){try{v(!0),g(null);let E=sessionStorage.getItem("wraps-auth-token");if(E||(E=new URLSearchParams(window.location.search).get("token"),E&&sessionStorage.setItem("wraps-auth-token",E)),!E)throw new Error("Authentication token not found. Please use the URL provided by 'wraps console' command.");const _=Number.parseInt(r,10),A=Date.now()-_*24*60*60*1e3,C=Date.now(),N=await fetch(`/api/sms?startTime=${A}&endTime=${C}&limit=100&token=${E}`);if(!N.ok){let R="Failed to fetch SMS logs";try{R=(await N.json()).error||R}catch{R=`${N.status}: ${N.statusText}`}throw new Error(R)}const M=await N.json();d(M.logs.map(R=>({id:R.messageId,to:R.to,from:R.from,body:R.body,status:R.status,timestamp:R.sentAt,messageId:R.messageId,segments:R.segments})))}catch(E){const _=E instanceof Error?E.message:"Unknown error";g(_),console.error("Error fetching SMS logs:",E)}finally{v(!1)}}b()},[r]);const x=f.filter(b=>{if(t){const E=t.toLowerCase(),_=b.to.toLowerCase().includes(E),A=b.body.toLowerCase().includes(E);if(!(_||A))return!1}return!(o!=="all"&&b.status!==o)}),O=b=>{const E=new Date(b),A=Math.floor((new Date().getTime()-E.getTime())/(1e3*60*60*24));return A===0?"Today":A===1?"Yesterday":A<7?`${A} days ago`:E.toLocaleDateString()},j=b=>b.startsWith("+1")&&b.length===12?`(${b.slice(2,5)}) ${b.slice(5,8)}-${b.slice(8)}`:b;return c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsxs(Le,{className:"flex items-center gap-2",children:[c.jsx(eo,{className:"h-5 w-5"}),"SMS Messages"]}),c.jsx(We,{children:"View and manage your SMS sending history"})]}),c.jsxs($e,{children:[m&&c.jsx("div",{className:"mb-4 rounded-md border border-destructive bg-destructive/10 p-4 text-destructive text-sm",children:m}),c.jsxs("div",{className:"mb-4 flex items-center gap-2",children:[c.jsxs("div",{className:"relative flex-1",children:[c.jsx(Cp,{className:"absolute top-2.5 left-2.5 h-4 w-4 text-muted-foreground"}),c.jsx(fs,{className:"pl-8",onChange:b=>n(b.target.value),placeholder:"Search by phone or message...",value:t})]}),c.jsxs(ga,{onValueChange:i,value:r,children:[c.jsx(xa,{className:"w-[180px]",children:c.jsx(ya,{})}),c.jsxs(ba,{children:[c.jsx(Fe,{value:"1",children:"Last 24 hours"}),c.jsx(Fe,{value:"7",children:"Last 7 days"}),c.jsx(Fe,{value:"15",children:"Last 15 days"}),c.jsx(Fe,{value:"30",children:"Last 30 days"}),c.jsx(Fe,{value:"90",children:"Last 90 days"})]})]}),c.jsxs(ga,{onValueChange:l,value:o,children:[c.jsx(xa,{className:"w-[180px]",children:c.jsx(ya,{})}),c.jsxs(ba,{children:[c.jsx(Fe,{value:"all",children:"All Statuses"}),c.jsx(Fe,{value:"delivered",children:"Delivered"}),c.jsx(Fe,{value:"sent",children:"Sent"}),c.jsx(Fe,{value:"queued",children:"Queued"}),c.jsx(Fe,{value:"failed",children:"Failed"}),c.jsx(Fe,{value:"blocked",children:"Blocked"}),c.jsx(Fe,{value:"opted_out",children:"Opted Out"})]})]}),c.jsx(Ce,{size:"icon",variant:"outline",children:c.jsx("span",{className:"sr-only",children:"Download"})})]}),c.jsx("div",{className:"rounded-md border",children:c.jsxs(cv,{children:[c.jsx(uv,{children:c.jsxs(Fn,{children:[c.jsx(Pt,{children:"To"}),c.jsx(Pt,{children:"Status"}),c.jsx(Pt,{children:"Message"}),c.jsx(Pt,{children:"Sent"}),c.jsx(Pt,{className:"w-[50px]"})]})}),c.jsx(fv,{children:h?c.jsx(Fn,{children:c.jsx(ht,{className:"h-24 text-center text-muted-foreground",colSpan:5,children:"Loading SMS logs..."})}):x.length===0?c.jsx(Fn,{children:c.jsx(ht,{className:"h-24 text-center text-muted-foreground",colSpan:5,children:"No SMS messages found"})}):x.map(b=>c.jsxs(Fn,{className:"cursor-pointer hover:bg-muted/50",onClick:()=>e(`/sms/${b.id}`),children:[c.jsx(ht,{className:"font-mono text-sm",children:j(b.to)}),c.jsx(ht,{children:c.jsxs(Vp,{children:[c.jsx(Yp,{asChild:!0,children:c.jsx(Be,{className:q1[b.status]?.className,variant:q1[b.status]?.variant??"default",children:b.status.charAt(0).toUpperCase()+b.status.slice(1).replace("_"," ")})}),c.jsx(Wp,{children:c.jsx("p",{children:q1[b.status]?.description??"Unknown status"})})]})}),c.jsx(ht,{className:"max-w-[400px] truncate",children:b.body}),c.jsx(ht,{className:"text-muted-foreground",children:O(b.timestamp)}),c.jsx(ht,{children:c.jsx(Ce,{onClick:E=>{E.stopPropagation()},size:"icon",variant:"ghost",children:c.jsx("span",{className:"sr-only",children:"More options"})})})]},b.id))})]})}),x.length>0&&!h&&c.jsx("div",{className:"mt-4 flex items-center justify-between text-muted-foreground text-sm",children:c.jsxs("div",{children:["Showing ",x.length," of ",f.length," messages"]})})]})]})}function Wge(){const[e,t]=S.useState("7"),[n,r]=S.useState(null),[i,o]=S.useState(!0),[l,f]=S.useState(null);if(S.useEffect(()=>{async function j(){try{o(!0),f(null);let b=sessionStorage.getItem("wraps-auth-token");if(b||(b=new URLSearchParams(window.location.search).get("token"),b&&sessionStorage.setItem("wraps-auth-token",b)),!b)throw new Error("Authentication token not found. Please use the URL provided by 'wraps console' command.");const E=Number.parseInt(e,10),_=Date.now()-E*24*60*60*1e3,A=Date.now(),C=await fetch(`/api/sms/metrics?startTime=${_}&endTime=${A}&token=${b}`);if(!C.ok){let M="Failed to fetch SMS metrics";try{M=(await C.json()).error||M}catch{M=`${C.status}: ${C.statusText}`}throw new Error(M)}const N=await C.json();r(N)}catch(b){const E=b instanceof Error?b.message:"Unknown error";f(E),console.error("Error fetching SMS metrics:",b)}finally{o(!1)}}j()},[e]),l)return c.jsxs(c.Fragment,{children:[c.jsxs("div",{children:[c.jsx("h1",{className:"font-semibold text-3xl tracking-tight",children:"SMS Metrics"}),c.jsx("p",{className:"mt-2 text-muted-foreground",children:"View detailed metrics and analytics for your SMS messaging"})]}),c.jsx("div",{className:"mt-4 rounded-md border border-destructive bg-destructive/10 p-4 text-destructive text-sm",children:l})]});if(i||!n)return c.jsxs(c.Fragment,{children:[c.jsxs("div",{children:[c.jsx("h1",{className:"font-semibold text-3xl tracking-tight",children:"SMS Metrics"}),c.jsx("p",{className:"mt-2 text-muted-foreground",children:"View detailed metrics and analytics for your SMS messaging"})]}),c.jsx("div",{className:"mt-4 flex h-[400px] items-center justify-center text-muted-foreground",children:"Loading metrics..."})]});const d=n.metrics.sends.reduce((j,b)=>j+b.value,0)||0,h=n.metrics.deliveries.reduce((j,b)=>j+b.value,0)||0,v=n.metrics.failures.reduce((j,b)=>j+b.value,0)||0,m=n.metrics.optOuts.reduce((j,b)=>j+b.value,0)||0,g=d>0?h/d*100:0,x=d>0?v/d*100:0,O=[{title:"Messages Sent",value:d.toLocaleString(),description:`${e==="1"?"Last 24 hours":`Last ${e} days`}`,icon:eo},{title:"Delivery Rate",value:`${g.toFixed(1)}%`,description:`${h.toLocaleString()} delivered`,icon:Uj},{title:"Failure Rate",value:`${x.toFixed(1)}%`,description:`${v.toLocaleString()} failed`,icon:Np},{title:"Opt Outs",value:m.toLocaleString(),description:"Recipients unsubscribed",icon:em}];return c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("h1",{className:"font-semibold text-3xl tracking-tight",children:"SMS Metrics"}),c.jsx("p",{className:"mt-2 text-muted-foreground",children:"View detailed metrics and analytics for your SMS messaging"})]}),c.jsxs(ga,{onValueChange:t,value:e,children:[c.jsx(xa,{className:"w-[180px]",children:c.jsx(ya,{})}),c.jsxs(ba,{children:[c.jsx(Fe,{value:"1",children:"Last 24 hours"}),c.jsx(Fe,{value:"7",children:"Last 7 days"}),c.jsx(Fe,{value:"15",children:"Last 15 days"}),c.jsx(Fe,{value:"30",children:"Last 30 days"}),c.jsx(Fe,{value:"90",children:"Last 90 days"})]})]})]}),c.jsx("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-4",children:O.map(j=>c.jsxs(Te,{children:[c.jsxs(Me,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[c.jsx(Le,{className:"font-medium text-sm",children:j.title}),c.jsx(j.icon,{className:"h-4 w-4 text-muted-foreground"})]}),c.jsxs($e,{children:[c.jsx("div",{className:"font-bold text-2xl",children:j.value}),c.jsx("p",{className:"text-muted-foreground text-xs",children:j.description})]})]},j.title))}),n.phoneNumber&&c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(Le,{children:"Phone Number"}),c.jsx(We,{children:"Your SMS sending number"})]}),c.jsxs($e,{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm",children:"Number"}),c.jsx("span",{className:"font-mono text-sm",children:n.phoneNumber.number})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm",children:"Type"}),c.jsx(Be,{variant:"outline",children:n.phoneNumber.type})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm",children:"Status"}),c.jsx(Be,{variant:n.phoneNumber.status==="ACTIVE"?"default":"secondary",children:n.phoneNumber.status})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm",children:"Throughput"}),c.jsx("span",{className:"text-muted-foreground text-sm",children:n.phoneNumber.throughput})]})]})]}),n.quota&&c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(Le,{children:"Spend Limits"}),c.jsx(We,{children:"Your AWS SMS spending limits"})]}),c.jsxs($e,{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm",children:"Monthly Spend"}),c.jsxs("span",{className:"font-medium",children:["$",n.quota.spentThisMonth.toFixed(2)," / $",n.quota.spendLimitMonthly.toFixed(2)]})]}),c.jsx("div",{className:"h-2 w-full overflow-hidden rounded-full bg-secondary",children:c.jsx("div",{className:"h-full bg-primary transition-all",style:{width:`${Math.min(n.quota.spentThisMonth/n.quota.spendLimitMonthly*100,100)}%`}})})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm",children:"Daily Limit"}),c.jsxs("span",{className:"text-muted-foreground text-sm",children:["$",n.quota.spendLimitDaily.toFixed(2)]})]})]})]}),c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(Le,{children:"Metrics Summary"}),c.jsx(We,{children:"Detailed breakdown of your SMS performance"})]}),c.jsxs($e,{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm",children:"Total Messages Sent"}),c.jsx(Be,{variant:"outline",children:d.toLocaleString()})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm",children:"Successfully Delivered"}),c.jsx(Be,{variant:"default",children:h.toLocaleString()})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm",children:"Failed"}),c.jsx(Be,{variant:"destructive",children:v.toLocaleString()})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-sm",children:"Opt Outs"}),c.jsx(Be,{variant:"secondary",children:m.toLocaleString()})]})]})]})]})}function G4({status:e}){const t=e==="ACTIVE"||e==="SUCCESS";return c.jsxs(Be,{className:t?"border-green-500/20 bg-green-500/10 text-green-700 dark:text-green-400":"border-yellow-500/20 bg-yellow-500/10 text-yellow-700 dark:text-yellow-400",variant:"outline",children:[t?c.jsx(so,{className:"mr-1 h-3 w-3"}):c.jsx(lr,{className:"mr-1 h-3 w-3"}),e]})}function Kge({phoneNumber:e}){if(!e)return c.jsx(Te,{children:c.jsxs(Me,{children:[c.jsxs(Le,{className:"flex items-center gap-2",children:[c.jsx(em,{className:"h-5 w-5"}),"Phone Number"]}),c.jsx(We,{children:"No phone number configured"})]})});const t=r=>r.startsWith("+1")&&r.length===12?`(${r.slice(2,5)}) ${r.slice(5,8)}-${r.slice(8)}`:r,n=r=>{switch(r){case"simulator":return"Simulator";case"toll-free":return"Toll-Free";case"10dlc":return"10DLC";case"short-code":return"Short Code";default:return r}};return c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsxs(Le,{className:"flex items-center gap-2",children:[c.jsx(em,{className:"h-5 w-5"}),"Phone Number"]}),c.jsx(We,{children:"Your SMS sending number"})]}),c.jsxs($e,{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"font-medium font-mono text-lg",children:t(e.number)}),c.jsx("p",{className:"text-muted-foreground text-sm",children:n(e.type)})]}),c.jsx(G4,{status:e.status})]}),e.registrationStatus&&c.jsxs(c.Fragment,{children:[c.jsx(Vt,{}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"font-medium text-sm",children:"Registration Status"}),c.jsx("p",{className:"text-muted-foreground text-sm",children:e.type==="toll-free"?"Toll-free verification":"Campaign registration"})]}),c.jsx(G4,{status:e.registrationStatus})]})]}),e.capabilities.length>0&&c.jsxs(c.Fragment,{children:[c.jsx(Vt,{}),c.jsxs("div",{className:"space-y-2",children:[c.jsx("p",{className:"font-medium text-sm",children:"Capabilities"}),c.jsx("div",{className:"flex flex-wrap gap-2",children:e.capabilities.map(r=>c.jsx(Be,{variant:"secondary",children:r},r))})]})]}),e.monthlyLeasingPrice&&c.jsxs(c.Fragment,{children:[c.jsx(Vt,{}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"font-medium text-sm",children:"Monthly Cost"}),c.jsx("p",{className:"text-muted-foreground text-sm",children:"Phone number lease"})]}),c.jsxs("span",{className:"font-mono text-sm",children:["$",e.monthlyLeasingPrice,"/mo"]})]})]}),e.type==="simulator"&&c.jsxs(Un,{children:[c.jsx(lr,{className:"h-4 w-4"}),c.jsx(ro,{children:"Simulator Mode"}),c.jsx(Hn,{children:"This number is for testing only. Messages are simulated and not actually sent. Upgrade to a toll-free number for production use."})]}),e.type==="toll-free"&&e.registrationStatus!=="VERIFIED"&&c.jsxs(Un,{children:[c.jsx(lr,{className:"h-4 w-4"}),c.jsx(ro,{children:"Registration Required"}),c.jsxs(Hn,{children:["Toll-free numbers require registration before they can send messages. Run ",c.jsx("code",{children:"wraps sms register"})," to complete registration."]})]})]})]})}function Xge({protectConfig:e}){return e?.enabled?c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsxs(Le,{className:"flex items-center gap-2",children:[c.jsx(tm,{className:"h-5 w-5"}),"Fraud Protection"]}),c.jsx(We,{children:"Country restrictions and AIT filtering"})]}),c.jsxs($e,{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"font-medium text-sm",children:"Status"}),c.jsx("p",{className:"text-muted-foreground text-sm",children:"Protect configuration active"})]}),c.jsxs(Be,{className:"border-green-500/20 bg-green-500/10 text-green-700 dark:text-green-400",variant:"outline",children:[c.jsx(so,{className:"mr-1 h-3 w-3"}),"Enabled"]})]}),c.jsx(Vt,{}),c.jsxs("div",{className:"space-y-2",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(Fu,{className:"h-4 w-4 text-muted-foreground"}),c.jsx("p",{className:"font-medium text-sm",children:"Allowed Countries"})]}),c.jsx("div",{className:"flex flex-wrap gap-2",children:e.allowedCountries.map(t=>c.jsx(Be,{variant:"secondary",children:t},t))}),c.jsx("p",{className:"text-muted-foreground text-xs",children:"Messages can only be sent to these countries. All others are blocked."})]}),c.jsx(Vt,{}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"font-medium text-sm",children:"AIT Filtering"}),c.jsx("p",{className:"text-muted-foreground text-sm",children:e.aitFiltering?"Enabled - adds per-message cost":"Disabled - no extra cost"})]}),c.jsx(Be,{variant:e.aitFiltering?"default":"secondary",children:e.aitFiltering?"Enabled":"Disabled"})]})]})]}):c.jsx(Te,{children:c.jsxs(Me,{children:[c.jsxs(Le,{className:"flex items-center gap-2",children:[c.jsx(tm,{className:"h-5 w-5"}),"Fraud Protection"]}),c.jsx(We,{children:"Not configured"})]})})}function Qge({configSet:e,onRefresh:t}){const[n,r]=S.useState(!1),[i,o]=S.useState(!1);if(!e)return c.jsx(Te,{children:c.jsxs(Me,{children:[c.jsxs(Le,{className:"flex items-center gap-2",children:[c.jsx(eo,{className:"h-5 w-5"}),"Configuration Set"]}),c.jsx(We,{children:"No configuration set found"})]})});const l=async()=>{o(!0);try{const f=sessionStorage.getItem("wraps-auth-token"),d=!e.sendingEnabled,h=await fetch(`/api/sms/settings/sending?token=${f}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:d})});if(!h.ok)throw new Error(`Failed to update: ${h.statusText}`);r(!1),jt.success(d?"SMS sending enabled":"SMS sending disabled"),t&&await t()}catch(f){console.error("Failed to toggle sending:",f),jt.error("Failed to update setting",{description:f instanceof Error?f.message:"Unknown error"})}finally{o(!1)}};return c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsxs(Le,{className:"flex items-center gap-2",children:[c.jsx(eo,{className:"h-5 w-5"}),"Configuration Set"]}),c.jsx(We,{children:"SMS sending configuration"})]}),c.jsxs($e,{className:"space-y-4",children:[c.jsxs("div",{children:[c.jsx("p",{className:"font-medium",children:e.name}),c.jsx("p",{className:"text-muted-foreground text-sm",children:"Configuration Set Name"})]}),c.jsx(Vt,{}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex-1 space-y-0.5",children:[c.jsx("p",{className:"font-medium text-sm",children:"SMS Sending"}),c.jsx("p",{className:"text-muted-foreground text-sm",children:e.sendingEnabled?"Messages can be sent":"Message sending is disabled"})]}),c.jsx(Ce,{onClick:()=>r(!0),size:"sm",variant:e.sendingEnabled?"destructive":"default",children:e.sendingEnabled?"Disable":"Enable"})]}),c.jsx(dm,{onOpenChange:r,open:n,children:c.jsxs(hm,{children:[c.jsxs(mm,{children:[c.jsx(vm,{children:e.sendingEnabled?"Disable SMS sending?":"Enable SMS sending?"}),c.jsx(gm,{children:e.sendingEnabled?"All outgoing SMS messages will be blocked until you re-enable sending.":"This will allow SMS messages to be sent through this configuration set."})]}),c.jsxs(pm,{children:[c.jsx(xm,{disabled:i,children:"Cancel"}),c.jsx(ym,{disabled:i,onClick:l,children:i?"Updating...":e.sendingEnabled?"Disable sending":"Enable sending"})]})]})})]})]})}function Zge({eventTracking:e}){return c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(Le,{children:"Event Tracking"}),c.jsx(We,{children:"Message history and event storage"})]}),c.jsxs($e,{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"font-medium text-sm",children:"Event Tracking"}),c.jsx("p",{className:"text-muted-foreground text-sm",children:e?.enabled?"Tracking delivery events":"Event tracking disabled"})]}),c.jsx(Be,{variant:e?.enabled?"default":"secondary",children:e?.enabled?"Enabled":"Disabled"})]}),e?.enabled&&c.jsxs(c.Fragment,{children:[c.jsx(Vt,{}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"font-medium text-sm",children:"Message History"}),c.jsx("p",{className:"text-muted-foreground text-sm",children:e.dynamoDBHistory?"Stored in DynamoDB":"Not stored"})]}),c.jsx(Be,{variant:e.dynamoDBHistory?"default":"secondary",children:e.dynamoDBHistory?"Enabled":"Disabled"})]}),e.archiveRetention&&c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"font-medium text-sm",children:"Retention Period"}),c.jsx("p",{className:"text-muted-foreground text-sm",children:"How long message history is kept"})]}),c.jsx(Be,{variant:"outline",children:e.archiveRetention})]})]})]})]})}function Jge(){const[e,t]=S.useState(null),[n,r]=S.useState(!0),[i,o]=S.useState(null),l=S.useCallback(async()=>{try{r(!0);const f=sessionStorage.getItem("wraps-auth-token");if(!f)throw new Error("Authentication token not found");const d=await fetch(`/api/sms/settings?token=${f}`);if(!d.ok)throw new Error(`Failed to fetch settings: ${d.statusText}`);const h=await d.json();t(h),o(null)}catch(f){console.error("Failed to fetch SMS settings:",f),o(f instanceof Error?f.message:"Failed to load settings")}finally{r(!1)}},[]);return S.useEffect(()=>{l()},[l]),n?c.jsxs(c.Fragment,{children:[c.jsxs("div",{children:[c.jsx("h1",{className:"font-semibold text-3xl tracking-tight",children:"SMS Settings"}),c.jsx("p",{className:"mt-2 text-muted-foreground",children:"Configure your SMS settings and preferences"})]}),c.jsxs("div",{className:"mt-6 grid gap-6 md:grid-cols-2",children:[c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(De,{className:"h-6 w-48"}),c.jsx(De,{className:"mt-2 h-4 w-64"})]}),c.jsx($e,{children:c.jsx(De,{className:"h-20 w-full"})})]}),c.jsxs(Te,{children:[c.jsxs(Me,{children:[c.jsx(De,{className:"h-6 w-48"}),c.jsx(De,{className:"mt-2 h-4 w-64"})]}),c.jsx($e,{children:c.jsx(De,{className:"h-20 w-full"})})]})]})]}):i?c.jsxs(c.Fragment,{children:[c.jsxs("div",{children:[c.jsx("h1",{className:"font-semibold text-3xl tracking-tight",children:"SMS Settings"}),c.jsx("p",{className:"mt-2 text-muted-foreground",children:"Configure your SMS settings and preferences"})]}),c.jsxs(Un,{className:"mt-6",variant:"destructive",children:[c.jsx(lr,{className:"h-4 w-4"}),c.jsx(ro,{children:"Error Loading Settings"}),c.jsx(Hn,{children:i})]})]}):c.jsxs(c.Fragment,{children:[c.jsxs("div",{children:[c.jsx("h1",{className:"font-semibold text-3xl tracking-tight",children:"SMS Settings"}),c.jsx("p",{className:"mt-2 text-muted-foreground",children:"Configure your SMS settings and preferences"})]}),c.jsxs("div",{className:"mt-6 grid gap-6 md:grid-cols-2",children:[c.jsx(Kge,{phoneNumber:e?.phoneNumber}),c.jsx(Qge,{configSet:e?.configurationSet,onRefresh:l}),c.jsx(Xge,{protectConfig:e?.protectConfiguration}),c.jsx(Zge,{eventTracking:e?.eventTracking})]})]})}function eye({children:e,defaultTheme:t="system",storageKey:n="vite-ui-theme",...r}){const[i,o]=S.useState(()=>localStorage.getItem(n)||t);S.useEffect(()=>{const f=window.document.documentElement;if(f.classList.remove("light","dark"),i==="system"){const d=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";f.classList.add(d),f.style.colorScheme=d;return}f.classList.add(i),f.style.colorScheme=i},[i]);const l={theme:i,setTheme:f=>{localStorage.setItem(n,f),o(f)}};return c.jsx(KI.Provider,{...r,value:l,children:e})}function tye(){const e=Jr(),[t,n]=S.useState(!1);S.useEffect(()=>{let i=sessionStorage.getItem("wraps-auth-token");if(!i){const o=new URLSearchParams(window.location.search);if(i=o.get("token"),i){sessionStorage.setItem("wraps-auth-token",i),o.delete("token");const l=o.toString()?`${window.location.pathname}?${o.toString()}`:window.location.pathname;window.history.replaceState({},"",l)}}n(!0)},[]),S.useEffect(()=>{document.cookie="sidebar_state=; path=/; max-age=0"},[]);const r=()=>{if(e.pathname.startsWith("/email/inbound/"))return"Inbound Email Details";if(e.pathname.startsWith("/email/")&&e.pathname!=="/email/metrics"&&e.pathname!=="/email/settings")return"Email Details";if(e.pathname.startsWith("/sms/")&&e.pathname!=="/sms/metrics"&&e.pathname!=="/sms/settings")return"SMS Details";if(e.pathname.startsWith("/cdn/")&&e.pathname!=="/cdn/metrics"&&e.pathname!=="/cdn/settings")return"File Details";switch(e.pathname){case"/":case"/email":return"Emails";case"/email/metrics":return"Email Metrics";case"/email/settings":return"Email Settings";case"/sms":return"SMS Messages";case"/sms/metrics":return"SMS Metrics";case"/sms/settings":return"SMS Settings";case"/cdn":return"CDN";case"/cdn/metrics":return"CDN Metrics";case"/cdn/settings":return"CDN Settings";default:return"Emails"}};return c.jsxs(zG,{defaultOpen:!1,children:[c.jsx(VK,{}),c.jsxs(qG,{children:[c.jsxs("header",{className:"sticky top-0 flex shrink-0 items-center gap-2 border-b bg-background p-4",children:[c.jsx(BG,{className:"-ml-1"}),c.jsx(Vt,{className:"mr-2 data-[orientation=vertical]:h-4",orientation:"vertical"}),c.jsx(TH,{children:c.jsx(MH,{children:c.jsx(RH,{children:c.jsx(DH,{children:r()})})})})]}),c.jsx("div",{className:"flex flex-1 flex-col gap-6 p-6",children:t?c.jsxs(bY,{children:[c.jsx(Bn,{element:c.jsx(yY,{replace:!0,to:"/email"}),path:"/"}),c.jsx(Bn,{element:c.jsx(Nge,{}),path:"/email"}),c.jsx(Bn,{element:c.jsx(Uge,{}),path:"/email/inbound/:emailId"}),c.jsx(Bn,{element:c.jsx(Ege,{}),path:"/email/:id"}),c.jsx(Bn,{element:c.jsx(Rge,{}),path:"/email/metrics"}),c.jsx(Bn,{element:c.jsx(Bge,{}),path:"/email/settings"}),c.jsx(Bn,{element:c.jsx(Yge,{}),path:"/sms"}),c.jsx(Bn,{element:c.jsx(Vge,{}),path:"/sms/:id"}),c.jsx(Bn,{element:c.jsx(Wge,{}),path:"/sms/metrics"}),c.jsx(Bn,{element:c.jsx(Jge,{}),path:"/sms/settings"}),c.jsx(Bn,{element:c.jsx(iee,{}),path:"/cdn"}),c.jsx(Bn,{element:c.jsx(sge,{}),path:"/cdn/metrics"}),c.jsx(Bn,{element:c.jsx(hge,{}),path:"/cdn/settings"})]}):c.jsx("div",{className:"flex items-center justify-center p-8",children:c.jsx("div",{className:"text-muted-foreground",children:"Loading..."})})})]})]})}function nye(){return c.jsx(eye,{defaultTheme:"system",storageKey:"console-ui-theme",children:c.jsxs(GY,{children:[c.jsx(tye,{}),c.jsx(SV,{})]})})}RU.createRoot(document.getElementById("root")).render(c.jsx(S.StrictMode,{children:c.jsx(nye,{})}));