1import{r as e,b3 as t,b as s,a5 as a,j as r,aq as n,Y as i,ar as l,as as o,at as c,au as d,av as x,B as h,C as m,ai as u,aj as p,F as g,I as j,S as f,M as b,v as y,h as v,i as N,T as w,g as k,_ as S,A,l as C,t as O,D as P,c as T,d as E,f as R,a0 as _,w as L,x as F,ax as D,E as U,V as I,b4 as M,b5 as B,b6 as z,b7 as $,b8 as V,b9 as W,ba as H,bb as K,bc as Z,bd as q,P as G}from"./mui-7de4f23d.js";import{u as Y,A as X}from"./index-2ba3c2ef.js";import{u as J}from"./axiosInstance-9d8a485a.js";import{f as Q,_ as ee,c as te,d as se,e as ae,g as re,p as ne,h as ie,i as le,j as oe,k as ce,D as de,l as xe,m as he,n as me,S as ue,A as pe,o as ge,q as je,r as fe,s as be,G as ye,t as ve,u as Ne,v as we,w as ke,x as Se,y as Ae,z as Ce,B as Oe,E as Pe,F as Te,H as Ee,I as Re,J as _e,X as Le,Y as Fe,K as De,M as Ue,R as Ie,C as Me,T as Be,a as ze,L as $e,b as Ve}from"./LineChart-e8bf1231.js";import{d as We}from"./Download-f6d93036.js";import{e as He,x as Ke}from"./isEqual-08ac78f1.js";import{a as Ze}from"./axios-c6845f15.js";import{d as qe}from"./Refresh-675949e3.js";import{d as Ge}from"./PlayArrow-d9775cde.js";import{d as Ye}from"./Search-a443ec17.js";import{p as Xe}from"./IconBase.es-72733db7.js";import{s as Je}from"./CheckCircle.es-45a35217.js";import{m as Qe}from"./WarningCircle.es-0694590c.js";import"./react-vendor-60cd4be3.js";import"./createSvgIcon-e6c3e379.js";const et=new Map([["bold",e.createElement(e.Fragment,null,e.createElement("path",{d:"M228,48V96a12,12,0,0,1-12,12H168a12,12,0,0,1,0-24h19l-7.8-7.8a75.55,75.55,0,0,0-53.32-22.26h-.43A75.49,75.49,0,0,0,72.39,75.57,12,12,0,1,1,55.61,58.41a99.38,99.38,0,0,1,69.87-28.47H126A99.42,99.42,0,0,1,196.2,59.23L204,67V48a12,12,0,0,1,24,0ZM183.61,180.43a75.49,75.49,0,0,1-53.09,21.63h-.43A75.55,75.55,0,0,1,76.77,179.8L69,172H88a12,12,0,0,0,0-24H40a12,12,0,0,0-12,12v48a12,12,0,0,0,24,0V189l7.8,7.8A99.42,99.42,0,0,0,130,226.06h.56a99.38,99.38,0,0,0,69.87-28.47,12,12,0,0,0-16.78-17.16Z"}))],["duotone",e.createElement(e.Fragment,null,e.createElement("path",{d:"M216,128a88,88,0,1,1-88-88A88,88,0,0,1,216,128Z",opacity:"0.2"}),e.createElement("path",{d:"M224,48V96a8,8,0,0,1-8,8H168a8,8,0,0,1,0-16h28.69L182.06,73.37a79.56,79.56,0,0,0-56.13-23.43h-.45A79.52,79.52,0,0,0,69.59,72.71,8,8,0,0,1,58.41,61.27a96,96,0,0,1,135,.79L208,76.69V48a8,8,0,0,1,16,0ZM186.41,183.29a80,80,0,0,1-112.47-.66L59.31,168H88a8,8,0,0,0,0-16H40a8,8,0,0,0-8,8v48a8,8,0,0,0,16,0V179.31l14.63,14.63A95.43,95.43,0,0,0,130,222.06h.53a95.36,95.36,0,0,0,67.07-27.33,8,8,0,0,0-11.18-11.44Z"}))],["fill",e.createElement(e.Fragment,null,e.createElement("path",{d:"M224,48V96a8,8,0,0,1-8,8H168a8,8,0,0,1-5.66-13.66L180.65,72a79.48,79.48,0,0,0-54.72-22.09h-.45A79.52,79.52,0,0,0,69.59,72.71,8,8,0,0,1,58.41,61.27,96,96,0,0,1,192,60.7l18.36-18.36A8,8,0,0,1,224,48ZM186.41,183.29A80,80,0,0,1,75.35,184l18.31-18.31A8,8,0,0,0,88,152H40a8,8,0,0,0-8,8v48a8,8,0,0,0,13.66,5.66L64,195.3a95.42,95.42,0,0,0,66,26.76h.53a95.36,95.36,0,0,0,67.07-27.33,8,8,0,0,0-11.18-11.44Z"}))],["light",e.createElement(e.Fragment,null,e.createElement("path",{d:"M222,48V96a6,6,0,0,1-6,6H168a6,6,0,0,1,0-12h33.52L183.47,72a81.51,81.51,0,0,0-57.53-24h-.46A81.5,81.5,0,0,0,68.19,71.28a6,6,0,1,1-8.38-8.58,93.38,93.38,0,0,1,65.67-26.76H126a93.45,93.45,0,0,1,66,27.53l18,18V48a6,6,0,0,1,12,0ZM187.81,184.72a81.5,81.5,0,0,1-57.29,23.34h-.46a81.51,81.51,0,0,1-57.53-24L54.48,166H88a6,6,0,0,0,0-12H40a6,6,0,0,0-6,6v48a6,6,0,0,0,12,0V174.48l18,18.05a93.45,93.45,0,0,0,66,27.53h.52a93.38,93.38,0,0,0,65.67-26.76,6,6,0,1,0-8.38-8.58Z"}))],["regular",e.createElement(e.Fragment,null,e.createElement("path",{d:"M224,48V96a8,8,0,0,1-8,8H168a8,8,0,0,1,0-16h28.69L182.06,73.37a79.56,79.56,0,0,0-56.13-23.43h-.45A79.52,79.52,0,0,0,69.59,72.71,8,8,0,0,1,58.41,61.27a96,96,0,0,1,135,.79L208,76.69V48a8,8,0,0,1,16,0ZM186.41,183.29a80,80,0,0,1-112.47-.66L59.31,168H88a8,8,0,0,0,0-16H40a8,8,0,0,0-8,8v48a8,8,0,0,0,16,0V179.31l14.63,14.63A95.43,95.43,0,0,0,130,222.06h.53a95.36,95.36,0,0,0,67.07-27.33,8,8,0,0,0-11.18-11.44Z"}))],["thin",e.createElement(e.Fragment,null,e.createElement("path",{d:"M220,48V96a4,4,0,0,1-4,4H168a4,4,0,0,1,0-8h38.34L184.89,70.54A84,84,0,0,0,66.8,69.85a4,4,0,1,1-5.6-5.72,92,92,0,0,1,129.34.76L212,86.34V48a4,4,0,0,1,8,0ZM189.2,186.15a83.44,83.44,0,0,1-58.68,23.91h-.47a83.52,83.52,0,0,1-58.94-24.6L49.66,164H88a4,4,0,0,0,0-8H40a4,4,0,0,0-4,4v48a4,4,0,0,0,8,0V169.66l21.46,21.45A91.43,91.43,0,0,0,130,218.06h.51a91.45,91.45,0,0,0,64.28-26.19,4,4,0,1,0-5.6-5.72Z"}))]]),tt=new Map([["bold",e.createElement(e.Fragment,null,e.createElement("path",{d:"M225.15,197.71,164,95.81V44h4a12,12,0,0,0,0-24H88a12,12,0,0,0,0,24h4V95.81L30.85,197.71A20,20,0,0,0,48,228H208a20,20,0,0,0,17.15-30.29ZM140,44V99.14a12,12,0,0,0,1.71,6.17l35.13,58.54c-10.79.86-25.15-1.31-43.42-10.56-14-7.08-27.46-11.33-40.27-12.76l21.14-35.22A12,12,0,0,0,116,99.14V44ZM55.06,204,79,164.19c13-1.11,27.62,2.42,43.62,10.52,19.61,9.92,36.25,13.31,49.85,13.31A75.44,75.44,0,0,0,190.11,186l10.83,18Z"}))],["duotone",e.createElement(e.Fragment,null,e.createElement("path",{d:"M208,216H48a8,8,0,0,1-6.86-12.12l30.48-50.8h0c13.23-2.48,32-1.41,56.37,10.92,32.25,16.33,54.75,12.91,67.5,7.65h0l19.34,32.23A8,8,0,0,1,208,216Z",opacity:"0.2"}),e.createElement("path",{d:"M221.69,199.77,160,96.92V40h8a8,8,0,0,0,0-16H88a8,8,0,0,0,0,16h8V96.92L34.31,199.77A16,16,0,0,0,48,224H208a16,16,0,0,0,13.72-24.23ZM110.86,103.25A7.93,7.93,0,0,0,112,99.14V40h32V99.14a7.93,7.93,0,0,0,1.14,4.11L183.36,167c-12,2.37-29.07,1.37-51.75-10.11-15.91-8.05-31.05-12.32-45.22-12.81ZM48,208l28.54-47.58c14.25-1.73,30.31,1.85,47.82,10.72,19,9.61,35,12.88,48,12.88a69.89,69.89,0,0,0,19.55-2.7L208,208Z"}))],["fill",e.createElement(e.Fragment,null,e.createElement("path",{d:"M221.69,199.77,160,96.92V40h8a8,8,0,0,0,0-16H88a8,8,0,0,0,0,16h8V96.92L34.31,199.77A16,16,0,0,0,48,224H208a16,16,0,0,0,13.72-24.23Zm-90.08-42.91c-15.91-8.05-31.05-12.32-45.22-12.81l24.47-40.8A7.93,7.93,0,0,0,112,99.14V40h32V99.14a7.93,7.93,0,0,0,1.14,4.11L183.36,167C171.4,169.34,154.29,168.34,131.61,156.86Z"}))],["light",e.createElement(e.Fragment,null,e.createElement("path",{d:"M220,200.8,158,97.48V38h10a6,6,0,0,0,0-12H88a6,6,0,0,0,0,12H98
1V97.48L36,200.8A14,14,0,0,0,48,222H208a14,14,0,0,0,12-21.2ZM109.15,102.23a6,6,0,0,0,.85-3.09V38h36V99.14a6,6,0,0,0,.85,3.09l39.65,66.08c-12.41,3.16-30.86,3-55.79-9.66-16.94-8.58-33-12.8-47.83-12.64ZM209.72,209a2,2,0,0,1-1.74,1H48a2,2,0,0,1-1.71-3l29-48.41c14.89-2.08,31.68,1.55,49.94,10.79C144,178.8,159.67,182,172.42,182A67.89,67.89,0,0,0,192.89,179l16.8,28A2,2,0,0,1,209.72,209Z"}))],["regular",e.createElement(e.Fragment,null,e.createElement("path",{d:"M221.69,199.77,160,96.92V40h8a8,8,0,0,0,0-16H88a8,8,0,0,0,0,16h8V96.92L34.31,199.77A16,16,0,0,0,48,224H208a16,16,0,0,0,13.72-24.23ZM110.86,103.25A7.93,7.93,0,0,0,112,99.14V40h32V99.14a7.93,7.93,0,0,0,1.14,4.11L183.36,167c-12,2.37-29.07,1.37-51.75-10.11-15.91-8.05-31.05-12.32-45.22-12.81ZM48,208l28.54-47.58c14.25-1.74,30.31,1.85,47.82,10.72,19,9.61,35,12.88,48,12.88a69.89,69.89,0,0,0,19.55-2.7L208,208Z"}))],["thin",e.createElement(e.Fragment,null,e.createElement("path",{d:"M218.27,201.83,156,98V36h12a4,4,0,0,0,0-8H88a4,4,0,0,0,0,8h12V98L37.73,201.83A12,12,0,0,0,48,220H208a12,12,0,0,0,10.29-18.17ZM107.43,101.2a4.07,4.07,0,0,0,.57-2.06V36h40V99.14a4.07,4.07,0,0,0,.57,2.06l41,68.33c-12.76,3.94-32.54,4.68-59.75-9.1-18-9.14-35-13.24-50.54-12.29ZM211.46,210a3.94,3.94,0,0,1-3.48,2H48a4,4,0,0,1-3.43-6.06l29.53-49.21c15.54-2.43,33.05,1.21,52.07,10.84C144.54,176.86,160,180,172.42,180a65,65,0,0,0,21.36-3.46l17.63,29.38A3.92,3.92,0,0,1,211.46,210Z"}))]]),st=e.forwardRef((t,s)=>e.createElement(Xe,{ref:s,...t,weights:et}));st.displayName="ArrowsClockwiseIcon";const at=st,rt=e.forwardRef((t,s)=>e.createElement(Xe,{ref:s,...t,weights:tt}));rt.displayName="FlaskIcon";const nt=rt;var it=["points","className","baseLinePoints","connectNulls"];function lt(){return lt=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var s=arguments[t];for(var a in s)Object.prototype.hasOwnProperty.call(s,a)&&(e[a]=s[a])}return e},lt.apply(this,arguments)}function ot(e){return function(e){if(Array.isArray(e))return ct(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(e){if("string"==typeof e)return ct(e,t);var s=Object.prototype.toString.call(e).slice(8,-1);return"Object"===s&&e.constructor&&(s=e.constructor.name),"Map"===s||"Set"===s?Array.from(e):"Arguments"===s||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(s)?ct(e,t):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function ct(e,t){(null==t||t>e.length)&&(t=e.length);for(var s=0,a=new Array(t);s<t;s++)a[s]=e[s];return a}var dt=function(e){return e&&e.x===+e.x&&e.y===+e.y},xt=function(e,t){var s=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=[[]];return e.forEach(function(e){dt(e)?t[t.length-1].push(e):t[t.length-1].length>0&&t.push([])}),dt(e[0])&&t[t.length-1].push(e[0]),t[t.length-1].length<=0&&(t=t.slice(0,-1)),t}(e);t&&(s=[s.reduce(function(e,t){return[].concat(ot(e),ot(t))},[])]);var a=s.map(function(e){return e.reduce(function(e,t,s){return"".concat(e).concat(0===s?"M":"L").concat(t.x,",").concat(t.y)},"")}).join("");return 1===s.length?"".concat(a,"Z"):a},ht=function(e){var a=e.points,r=e.className,n=e.baseLinePoints,i=e.connectNulls,l=function(e,t){if(null==e)return{};var s,a,r=function(e,t){if(null==e)return{};var s={};for(var a in e)if(Object.prototype.hasOwnProperty.call(e,a)){if(t.indexOf(a)>=0)continue;s[a]=e[a]}return s}(e,t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);for(a=0;a<n.length;a++)s=n[a],t.indexOf(s)>=0||Object.prototype.propertyIsEnumerable.call(e,s)&&(r[s]=e[s])}return r}(e,it);if(!a||!a.length)return null;var o=t("recharts-polygon",r);if(n&&n.length){var c=l.stroke&&"none"!==l.stroke,d=function(e,t,s){var a=xt(e,s);return"".concat("Z"===a.slice(-1)?a.slice(0,-1):a,"L").concat(xt(t.reverse(),s).slice(1))}(a,n,i);return s.createElement("g",{className:o},s.createElement("path",lt({},Q(l,!0),{fill:"Z"===d.slice(-1)?l.fill:"none",stroke:"none",d:d})),c?s.createElement("path",lt({},Q(l,!0),{fill:"none",d:xt(a,i)})):null,c?s.createElement("path",lt({},Q(l,!0),{fill:"none",d:xt(n,i)})):null)}var x=xt(a,i);return s.createElement("path",lt({},Q(l,!0),{fill:"Z"===x.slice(-1)?l.fill:"none",className:o,d:x}))},mt=ee,ut=se,pt=te;const gt=a(function(e,t){return e&&e.length?mt(e,pt(t),ut):void 0});var jt=ee,ft=te,bt=ae;const yt=a(function(e,t){return e&&e.length?jt(e,ft(t),bt):void 0});
1var vt=["cx","cy","angle","ticks","axisLine"],Nt=["ticks","tick","angle","tickFormatter","stroke"];function wt(e){return(wt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function kt(){return kt=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var s=arguments[t];for(var a in s)Object.prototype.hasOwnProperty.call(s,a)&&(e[a]=s[a])}return e},kt.apply(this,arguments)}function St(e,t){var s=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),s.push.apply(s,a)}return s}function At(e){for(var t=1;t<arguments.length;t++){var s=null!=arguments[t]?arguments[t]:{};t%2?St(Object(s),!0).forEach(function(t){Rt(e,t,s[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(s)):St(Object(s)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(s,t))})}return e}function Ct(e,t){if(null==e)return{};var s,a,r=function(e,t){if(null==e)return{};var s={};for(var a in e)if(Object.prototype.hasOwnProperty.call(e,a)){if(t.indexOf(a)>=0)continue;s[a]=e[a]}return s}(e,t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);for(a=0;a<n.length;a++)s=n[a],t.indexOf(s)>=0||Object.prototype.propertyIsEnumerable.call(e,s)&&(r[s]=e[s])}return r}function Ot(e,t){for(var s=0;s<t.length;s++){var a=t[s];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,_t(a.key),a)}}function Pt(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(Pt=function(){return!!e})()}function Tt(e){return(Tt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function Et(e,t){return(Et=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e})(e,t)}function Rt(e,t,s){return(t=_t(t))in e?Object.defineProperty(e,t,{value:s,enumerable:!0,configurable:!0,writable:!0}):e[t]=s,e}function _t(e){var t=function(e){if("object"!=wt(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var s=t.call(e,"string");if("object"!=wt(s))return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==wt(t)?t:t+""}var Lt=function(){function a(){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,a),e=this,s=arguments,t=Tt(t=a),function(e,t){if(t&&("object"===wt(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,Pt()?Reflect.construct(t,s||[],Tt(e).constructor):t.apply(e,s));var e,t,s}return function(e,t){if("function"!=typeof t&&null!==t)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&&Et(e,t)}(a,e.PureComponent),r=a,i=[{key:"renderTickItem",value:function(e,t,a){return s.isValidElement(e)?s.cloneElement(e,t):He(e)?e(t):s.createElement(re,kt({},t,{className:"recharts-polar-radius-axis-tick-value"}),a)}}],(n=[{key:"getTickValueCoord",value:function(e){var t=e.coordinate,s=this.props,a=s.angle,r=s.cx,n=s.cy;return ne(r,n,t,a)}},{key:"getTickTextAnchor",value:function(){var e;switch(this.props.orientation){case"left":e="end";break;case"right":e="start";break;default:e="middle"}return e}},{key:"getViewBox",value:function(){var e=this.props,t=e.cx,s=e.cy,a=e.angle,r=e.ticks,n=gt(r,function(e){return e.coordinate||0});return{cx:t,cy:s,startAngle:a,endAngle:a,innerRadius:yt(r,function(e){return e.coordinate||0}).coordinate||0,outerRadius:n.coordinate||0}}},{key:"renderAxisLine",value:function(){var e=this.props,t=e.cx,a=e.cy,r=e.angle,n=e.ticks,i=e.axisLine,l=Ct(e,vt),o=n.reduce(function(e,t){return[Math.min(e[0],t.coordinate),Math.max(e[1],t.coordinate)]},[1/0,-1/0]),c=ne(t,a,o[0],r),d=ne(t,a,o[1],r),x=At(At(At({},Q(l,!1)),{},{fill:"none"},Q(i,!1)),{},{x1:c.x,y1:c.y,x2:d.x,y2:d.y});return s.createElement("line",kt({className:"recharts-polar-radius-axis-line"},x))}},{key:"renderTicks",value:function(){var e=this,r=this.props,n=r.ticks,i=r.tick,l=r.angle,o=r.tickFormatter,c=r.stroke,d=Ct(r,Nt),x=this.getTickTextAnchor(),h=Q(d,!1),m=Q(i,!1),u=n.map(function(r,n){var d=e.getTickValueCoord(r),u=At(At(At(At({textAnchor:x,transform:"rotate(".concat(90-l,", ").concat(d.x,", ").concat(d.y,")")},h),{},{stroke:"none",fill:c},m),{},{index:n},d),{},{payload:r});return s.createElement(ie,kt({className:t("recharts-polar-radius-axis-tick",le(i)),key:"tick-".concat(r.coordinate)},oe(e.props,r,n)),a.renderTickItem(i,u,o?o(r.value,n):r.value))});return s.createElement(ie,{className:"recharts-polar-radius-axis-ticks"},u)}},{key:"render",value:function(){var e=this.props,a=e.ticks,r=e.axisLine,n=e.tick;return a&&a.length?s.createElement(ie,{className:t("recharts-polar-radius-axis",this.props.className)},r&&this.renderAxisLine(),n&&this.renderTicks(),ce.renderCallByParent(this.props,this.getViewBox())):null}}])&&Ot(r.prototype,n),i&&Ot(r,i),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,i}();function Ft(e){return(Ft="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function Dt(){return Dt=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var s=arguments[t];for(var a in s)Object.prototype.hasOwnProperty.call(s,a)&&(e[a]=s[a])}return e},Dt.apply(this,arguments)}function Ut(e,t){var s=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),s.push.apply(s,a)}return s}function It(e){for(var t=1;t<arguments.length;t++){var s=null!=arguments[t]?arguments[t]:{};
1t%2?Ut(Object(s),!0).forEach(function(t){Vt(e,t,s[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(s)):Ut(Object(s)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(s,t))})}return e}function Mt(e,t){for(var s=0;s<t.length;s++){var a=t[s];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,Wt(a.key),a)}}function Bt(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(Bt=function(){return!!e})()}function zt(e){return(zt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function $t(e,t){return($t=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e})(e,t)}function Vt(e,t,s){return(t=Wt(t))in e?Object.defineProperty(e,t,{value:s,enumerable:!0,configurable:!0,writable:!0}):e[t]=s,e}function Wt(e){var t=function(e){if("object"!=Ft(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var s=t.call(e,"string");if("object"!=Ft(s))return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==Ft(t)?t:t+""}Rt(Lt,"displayName","PolarRadiusAxis"),Rt(Lt,"axisType","radiusAxis"),Rt(Lt,"defaultProps",{type:"number",radiusAxisId:0,cx:0,cy:0,angle:0,orientation:"right",stroke:"#ccc",axisLine
1:!0,tick:!0,tickCount:5,allowDataOverflow:!1,scale:"auto",allowDuplicatedCategory:!0});var Ht,Kt=Math.PI/180,Zt=1e-5,qt=function(){function a(){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,a),e=this,s=arguments,t=zt(t=a),function(e,t){if(t&&("object"===Ft(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,Bt()?Reflect.construct(t,s||[],zt(e).constructor):t.apply(e,s));var e,t,s}return function(e,t){if("function"!=typeof t&&null!==t)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&&$t(e,t)}(a,e.PureComponent),r=a,i=[{key:"renderTickItem",value:function(e,t,a){return s.isValidElement(e)?s.cloneElement(e,t):He(e)?e(t):s.createElement(re,Dt({},t,{className:"recharts-polar-angle-axis-tick-value"}),a)}}],(n=[{key:"getTickLineCoord",value:function(e){var t=this.props,s=t.cx,a=t.cy,r=t.radius,n=t.orientation,i=t.tickSize||8,l=ne(s,a,r,e.coordinate),o=ne(s,a,r+("inner"===n?-1:1)*i,e.coordinate);return{x1:l.x,y1:l.y,x2:o.x,y2:o.y}}},{key:"getTickTextAnchor",value:function(e){var t=this.props.orientation,s=Math.cos(-e.coordinate*Kt);return s>Zt?"outer"===t?"start":"end":s<-Zt?"outer"===t?"end":"start":"middle"}},{key:"renderAxisLine",value:function(){var e=this.props,t=e.cx,a=e.cy,r=e.radius,n=e.axisLine,i=e.axisLineType,l=It(It({},Q(this.props,!1)),{},{fill:"none"},Q(n,!1));if("circle"===i)return s.createElement(de,Dt({className:"recharts-polar-angle-axis-line"},l,{cx:t,cy:a,r:r}));var o=this.props.ticks.map(function(e){return ne(t,a,r,e.coordinate)});return s.createElement(ht,Dt({className:"recharts-polar-angle-axis-line"},l,{points:o}))}},{key:"renderTicks",value:function(){var e=this,r=this.props,n=r.ticks,i=r.tick,l=r.tickLine,o=r.tickFormatter,c=r.stroke,d=Q(this.props,!1),x=Q(i,!1),h=It(It({},d),{},{fill:"none"},Q(l,!1)),m=n.map(function(r,n){var m=e.getTickLineCoord(r),u=It(It(It({textAnchor:e.getTickTextAnchor(r)},d),{},{stroke:"none",fill:c},x),{},{index:n,payload:r,x:m.x2,y:m.y2});return s.createElement(ie,Dt({className:t("recharts-polar-angle-axis-tick",le(i)),key:"tick-".concat(r.coordinate)},oe(e.props,r,n)),l&&s.createElement("line",Dt({className:"recharts-polar-angle-axis-tick-line"},h,m)),i&&a.renderTickItem(i,u,o?o(r.value,n):r.value))});return s.createElement(ie,{className:"recharts-polar-angle-axis-ticks"},m)}},{key:"render",value:function(){var e=this.props,a=e.ticks,r=e.radius,n=e.axisLine;return r<=0||!a||!a.length?null:s.createElement(ie,{className:t("recharts-polar-angle-axis",this.props.className)},n&&this.renderAxisLine(),this.renderTicks())}}])&&Mt(r.prototype,n),i&&Mt(r,i),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,i}();function Gt(e){return(Gt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function Yt(){return Yt=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var s=arguments[t];for(var a in s)Object.prototype.hasOwnProperty.call(s,a)&&(e[a]=s[a])}return e},Yt.apply(this,arguments)}function Xt(e,t){var s=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),s.push.apply(s,a)}return s}function Jt(e){for(var t=1;t<arguments.length;t++){var s=null!=arguments[t]?arguments[t]:{};t%2?Xt(Object(s),!0).forEach(function(t){as(e,t,s[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(s)):Xt(Object(s)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(s,t))})}return e}function Qt(e,t){for(var s=0;s<t.length;s++){var a=t[s];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,rs(a.key),a)}}function es(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(es=function(){return!!e})()}
1function ts(e){return(ts=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function ss(e,t){return(ss=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e})(e,t)}function as(e,t,s){return(t=rs(t))in e?Object.defineProperty(e,t,{value:s,enumerable:!0,configurable:!0,writable:!0}):e[t]=s,e}function rs(e){var t=function(e){if("object"!=Gt(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var s=t.call(e,"string");if("object"!=Gt(s))return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==Gt(t)?t:t+""}Vt(qt,"displayName","PolarAngleAxis"),Vt(qt,"axisType","angleAxis"),Vt(qt,"defaultProps",{type:"category",angleAxisId:0,scale:"auto",cx:0,cy:0,orientation:"outer",axisLine:!0,tickLine:!0,tickSize:8,tick:!0,hide:!1,allowDuplicatedCategory:!0});var ns=function(){function a(e){var t,s,r,n;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,a),as((s=this,n=[e],r=ts(r=a),t=function(e,t){if(t&&("object"===Gt(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(s,es()?Reflect.construct(r,n||[],ts(s).constructor):r.apply(s,n))),"pieRef",null),as(t,"sectorRefs",[]),as(t,"id",Ae("recharts-pie-")),as(t,"handleAnimationEnd",function(){var e=t.props.onAnimationEnd;t.setState({isAnimationFinished:!0}),He(e)&&e()}),as(t,"handleAnimationStart",function(){var e=t.props.onAnimationStart;t.setState({isAnimationFinished:!1}),He(e)&&e()}),t.state={isAnimationFinished:!e.isAnimationActive,prevIsAnimationActive:e.isAnimationActive,prevAnimationId:e.animationId,sectorToFocus:0},t}return function(e,t){if("function"!=typeof t&&null!==t)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&&ss(e,t)}(a,e.PureComponent),r=a,i=[{key:"getDerivedStateFromProps",value:function(e,t){return t.prevIsAnimationActive!==e.isAnimationActive?{prevIsAnimationActive:e.isAnimationActive,prevAnimationId:e.animationId,curSectors:e.sectors,prevSectors:[],isAnimationFinished:!0}:e.isAnimationActive&&e.animationId!==t.prevAnimationId?{prevAnimationId:e.animationId,curSectors:e.sectors,prevSectors:t.curSectors,isAnimationFinished:!0}:e.sectors!==t.curSectors?{curSectors:e.sectors,isAnimationFinished:!0}:null}},{key:"getTextAnchor",value:function(e,t){return e>t?"start":e<t?"end":"middle"}},{key:"renderLabelLineItem",value:function(e,a,r){if(s.isValidElement(e))return s.cloneElement(e,a);if(He(e))return e(a);var n=t("recharts-pie-label-line","boolean"!=typeof e?e.className:"");return s.createElement(xe,Yt({},a,{key:r,type:"linear",className:n}))}},{key:"renderLabelItem",value:function(e,a,r){if(s.isValidElement(e))return s.cloneElement(e,a);var n=r;if(He(e)&&(n=e(a),s.isValidElement(n)))return n;
1var i=t("recharts-pie-label-text","boolean"==typeof e||He(e)?"":e.className);return s.createElement(re,Yt({},a,{alignmentBaseline:"middle",className:i}),n)}}],(n=[{key:"isActiveIndex",value:function(e){var t=this.props.activeIndex;return Array.isArray(t)?-1!==t.indexOf(e):e===t}},{key:"hasActiveIndex",value:function(){var e=this.props.activeIndex;return Array.isArray(e)?0!==e.length:e||0===e}},{key:"renderLabels",value:function(e){if(this.props.isAnimationActive&&!this.state.isAnimationFinished)return null;var t=this.props,r=t.label,n=t.labelLine,i=t.dataKey,l=t.valueKey,o=Q(this.props,!1),c=Q(r,!1),d=Q(n,!1),x=r&&r.offsetRadius||20,h=e.map(function(e,t){var h=(e.startAngle+e.endAngle)/2,m=ne(e.cx,e.cy,e.outerRadius+x,h),u=Jt(Jt(Jt(Jt({},o),e),{},{stroke:"none"},c),{},{index:t,textAnchor:a.getTextAnchor(m.x,e.cx)},m),p=Jt(Jt(Jt(Jt({},o),e),{},{fill:"none",stroke:e.fill},d),{},{index:t,points:[ne(e.cx,e.cy,e.outerRadius,h),m]}),g=i;return he(i)&&he(l)?g="value":he(i)&&(g=l),s.createElement(ie,{key:"label-".concat(e.startAngle,"-").concat(e.endAngle,"-").concat(e.midAngle,"-").concat(t)},n&&a.renderLabelLineItem(n,p,"line"),a.renderLabelItem(r,u,me(e,g)))});return s.createElement(ie,{className:"recharts-pie-labels"},h)}},{key:"renderSectorsStatically",value:function(e){var t=this,a=this.props,r=a.activeShape,n=a.blendStroke,i=a.inactiveShape;return e.map(function(a,l){if(0===(null==a?void 0:a.startAngle)&&0===(null==a?void 0:a.endAngle)&&1!==e.length)return null;var o=t.isActiveIndex(l),c=i&&t.hasActiveIndex()?i:null,d=o?r:c,x=Jt(Jt({},a),{},{stroke:n?a.fill:a.stroke,tabIndex:-1});return s.createElement(ie,Yt({ref:function(e){e&&!t.sectorRefs.includes(e)&&t.sectorRefs.push(e)},tabIndex:-1,className:"recharts-pie-sector"},oe(t.props,a,l),{key:"sector-".concat(null==a?void 0:a.startAngle,"-").concat(null==a?void 0:a.endAngle,"-").concat(a.midAngle,"-").concat(l)}),s.createElement(ue,Yt({option:d,isActive:o,shapeType:"sector"},x)))})}},{key:"renderSectorsWithAnimation",value:function(){var e=this,t=this.props,a=t.sectors,r=t.isAnimationActive,n=t.animationBegin,i=t.animationDuration,l=t.animationEasing,o=t.animationId,c=this.state,d=c.prevSectors,x=c.prevIsAnimationActive;return s.createElement(pe,{begin:n,duration:i,isActive:r,easing:l,from:{t:0},to:{t:1},key:"pie-".concat(o,"-").concat(x),onAnimationStart:this.handleAnimationStart,onAnimationEnd:this.handleAnimationEnd},function(t){var r=t.t,n=[],i=(a&&a[0]).startAngle;return a.forEach(function(e,t){var s=d&&d[t],a=t>0?ge(e,"paddingAngle",0):0;if(s){var l=je(s.endAngle-s.startAngle,e.endAngle-e.startAngle),o=Jt(Jt({},e),{},{startAngle:i+a,endAngle:i+l(r)+a});n.push(o),i=o.endAngle}else{var c=e.endAngle,x=e.startAngle,h=je(0,c-x)(r),m=Jt(Jt({},e),{},{startAngle:i+a,endAngle:i+h+a});n.push(m),i=m.endAngle}}),s.createElement(ie,null,e.renderSectorsStatically(n))})}},{key:"attachKeyboardHandlers",value:function(e){var t=this;e.onkeydown=function(e){if(!e.altKey)switch(e.key){case"ArrowLeft":var s=++t.state.sectorToFocus%t.sectorRefs.length;t.sectorRefs[s].focus(),t.setState({sectorToFocus:s});break;case"ArrowRight":var a=--t.state.sectorToFocus<0?t.sectorRefs.length-1:t.state.sectorToFocus%t.sectorRefs.length;t.sectorRefs[a].focus(),t.setState({sectorToFocus:a});break;case"Escape":t.sectorRefs[t.state.sectorToFocus].blur(),t.setState({sectorToFocus:0})}}}},{key:"renderSectors",value:function(){var e=this.props,t=e.sectors,s=e.isAnimationActive,a=this.state.prevSectors;return!(s&&t&&t.length)||a&&Ke(a,t)?this.renderSectorsStatically(t):this.renderSectorsWithAnimation()}},{key:"componentDidMount",value:function(){this.pieRef&&this.attachKeyboardHandlers(this.pieRef)}},{key:"render",value:function(){var e=this,a=this.props,r=a.hide,n=a.sectors,i=a.className,l=a.label,o=a.cx,c=a.cy,d=a.innerRadius,x=a.outerRadius,h=a.isAnimationActive,m=this.state.isAnimationFinished;if(r||!n||!n.length||!fe(o)||!fe(c)||!fe(d)||!fe(x))return null;var u=t("recharts-pie",i);return s.createElement(ie,{tabIndex:this.props.rootTabIndex,className:u,ref:function(t){e.pieRef=t}},this.renderSectors(),l&&this.renderLabels(n),ce.renderCallByParent(this.props,null,!1),(!h||m)&&be.renderCallByParent(this.props,n,!1))}}])&&Qt(r.prototype,n),i&&Qt(r,i),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,i}();Ht=ns,as(ns,"displayName","Pie"),as(ns,"defaultProps",{stroke:"#fff",fill:"#808080",legendType:"rect",cx:"50%",cy:"50%",startAngle:0,endAngle:360,innerRadius:0,outerRadius:"80%",paddingAngle:0,labelLine:!0,hide:!1,minA
1ngle:0,isAnimationActive:!ye.isSsr,animationBegin:400,animationDuration:1500,animationEasing:"ease",nameKey:"name",blendStroke:!1,rootTabIndex:0}),as(ns,"parseDeltaAngle",function(e,t){return Se(t-e)*Math.min(Math.abs(t-e),360)}),as(ns,"getRealPieData",function(e){var t=e.data,s=e.children,a=Q(e,!1),r=ve(s,Ce);return t&&t.length?t.map(function(e,t){return Jt(Jt(Jt({payload:e},a),e),r&&r[t]&&r[t].props)}):r&&r.length?r.map(function(e){return Jt(Jt({},a),e.props)}):[]}),as(ns,"parseCoordinateOfPie",function(e,t){var s=t.top,a=t.left,r=t.width,n=t.height,i=Ne(r,n);return{cx:a+we(e.cx,r,r/2),cy:s+we(e.cy,n,n/2),innerRadius:we(e.innerRadius,i,0),outerRadius:we(e.outerRadius,i,.8*i),maxRadius:e.maxRadius||Math.sqrt(r*r+n*n)/2}}),as(ns,"getComposedData",function(e){var t=e.item,s=e.offset,a=void 0!==t.type.defaultProps?Jt(Jt({},t.type.defaultProps),t.props):t.props,r=Ht.getRealPieData(a);if(!r||!r.length)return null;var n=a.cornerRadius,i=a.startAngle,l=a.endAngle,o=a.paddingAngle,c=a.dataKey,d=a.nameKey,x=a.valueKey,h=a.tooltipType,m=Math.abs(a.minAngle),u=Ht.parseCoordinateOfPie(a,s),p=Ht.parseDeltaAngle(i,l),g=Math.abs(p),j=c;he(c)&&he(x)?(ke(!1,'Use "dataKey" to specify the value of pie,\n the props "valueKey" will be deprecated
1in 1.1.0'),j="value"):he(c)&&(ke(!1,'Use "dataKey" to specify the value of pie,\n the props "valueKey" will be deprecated in 1.1.0'),j=x);var f,b,y=r.filter(function(e){return 0!==me(e,j,0)}).length,v=g-y*m-(g>=360?y:y-1)*o,N=r.reduce(function(e,t){var s=me(t,j,0);return e+(fe(s)?s:0)},0);return N>0&&(f=r.map(function(e,t){var s,a=me(e,j,0),r=me(e,d,t),l=(fe(a)?a:0)/N,c=(s=t?b.endAngle+Se(p)*o*(0!==a?1:0):i)+Se(p)*((0!==a?m:0)+l*v),x=(s+c)/2,g=(u.innerRadius+u.outerRadius)/2,f=[{name:r,value:a,payload:e,dataKey:j,type:h}],y=ne(u.cx,u.cy,g,x);return b=Jt(Jt(Jt({percent:l,cornerRadius:n,name:r,tooltipPayload:f,midAngle:x,middleRadius:g,tooltipPosition:y},e),u),{},{value:me(e,j),startAngle:s,endAngle:c,payload:e,paddingAngle:Se(p)*o})})),Jt(Jt({},u),{},{sectors:f,data:r})});var is,ls=["layout","type","stroke","connectNulls","isRange","ref"],os=["key"];function cs(e){return(cs="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function ds(e,t){if(null==e)return{};var s,a,r=function(e,t){if(null==e)return{};var s={};for(var a in e)if(Object.prototype.hasOwnProperty.call(e,a)){if(t.indexOf(a)>=0)continue;s[a]=e[a]}return s}(e,t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);for(a=0;a<n.length;a++)s=n[a],t.indexOf(s)>=0||Object.prototype.propertyIsEnumerable.call(e,s)&&(r[s]=e[s])}return r}function xs(){return xs=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var s=arguments[t];for(var a in s)Object.prototype.hasOwnProperty.call(s,a)&&(e[a]=s[a])}return e},xs.apply(this,arguments)}function hs(e,t){var s=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),s.push.apply(s,a)}return s}function ms(e){for(var t=1;t<arguments.length;t++){var s=null!=arguments[t]?arguments[t]:{};t%2?hs(Object(s),!0).forEach(function(t){fs(e,t,s[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(s)):hs(Object(s)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(s,t))})}return e}function us(e,t){for(var s=0;s<t.length;s++){var a=t[s];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,bs(a.key),a)}}function ps(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(ps=function(){return!!e})()}function gs(e){return(gs=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function js(e,t){return(js=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e})(e,t)}function fs(e,t,s){return(t=bs(t))in e?Object.defineProperty(e,t,{value:s,enumerable:!0,configurable:!0,writable:!0}):e[t]=s,e}function bs(e){var t=function(e){if("object"!=cs(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var s=t.call(e,"string");if("object"!=cs(s))return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==cs(t)?t:t+""}var ys=function(){function a(){var e,t,s,r;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,a);for(var n=arguments.length,i=new Array(n),l=0;l<n;l++)i[l]=arguments[l];return fs((t=this,s=a,r=[].concat(i),s=gs(s),e=function(e,t){if(t&&("object"===cs(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(t,ps()?Reflect.construct(s,r||[],gs(t).constructor):s.apply(t,r))),"state",{isAnimationFinished:!0}),fs(e,"id",Ae("recharts-area-")),fs(e,"handleAnimationEnd",function(){var t=e.props.onAnimationEnd;e.setState({isAnimationFinished:!0}),He(t)&&t()}),fs(e,"handleAnimationStart",function(){var t=e.props.onAnimationStart;e.setState({isAnimationFinished:!1}),He(t)&&t()}),e}return function(e,t){if("function"!=typeof t&&null!==t)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&&js(e,t)}(a,e.PureComponent),r=a,i=[{key:"getDerivedStateFromProps",value:function(e,t){return e.animationId!==t.prevAnimationId?{prevAnimationId:e.animationId,curPoints:e.points,curBaseLine:e.baseLine,prevPoints:t.curPoints,prevBaseLine:t.curBaseLine}:e.points!==t.curPoints||e.baseLine!==t.curBaseLine?{curPoints:e.points,curBaseLine:e.baseLine}:null}}],(n=[{key:"renderDots",value:function(e,t,r){var n=this.props.isAnimationActive,i=this.state.isAnimationFinished;if(n&&!i)return null;var l=this.props,o=l.dot,c=l.points,d=l.dataKey,x=Q(this.props,!1),h=Q(o,!0),m=c.map(function(e,t){var s=ms(ms(ms({ke
1y:"dot-".concat(t),r:3},x),h),{},{index:t,cx:e.x,cy:e.y,dataKey:d,value:e.value,payload:e.payload,points:c});return a.renderDotItem(o,s)}),u={clipPath:e?"url(#clipPath-".concat(t?"":"dots-").concat(r,")"):null};return s.createElement(ie,xs({className:"recharts-area-dots"},u),m)}},{key:"renderHorizontalRect",value:function(e){var t=this.props,a=t.baseLine,r=t.points,n=t.strokeWidth,i=r[0].x,l=r[r.length-1].x,o=e*Math.abs(i-l),c=Oe(r.map(function(e){return e.y||0}));return fe(a)&&"number"==typeof a?c=Math.max(a,c):a&&Array.isArray(a)&&a.length&&(c=Math.max(Oe(a.map(function(e){return e.y||0})),c)),fe(c)?s.createElement("rect",{x:i<l?i:i-o,y:0,width:o,height:Math.floor(c+(n?parseInt("".concat(n),10):1))}):null}},{key:"renderVerticalRect",value:function(e){var t=this.props,a=t.baseLine,r=t.points,n=t.strokeWidth,i=r[0].y,l=r[r.length-1].y,o=e*Math.abs(i-l),c=Oe(r.map(function(e){return e.x||0}));return fe(a)&&"number"==typeof a?c=Math.max(a,c):a&&Array.isArray(a)&&a.length&&(c=Math.max(Oe(a.map(function(e){return e.x||0})),c)),fe(c)?s.createElement("rect",{x:0,y:i<l?i:i-o,width:c+(n?parseInt("".concat(n),10):1),height:Math.floor(o)}):null}},{key:"renderClipRect",value:function(e){return"vertical"===this.props.layout?this.renderVerticalRect(e):this.renderHorizontalRect(e)}},{key:"renderAreaStatically",value:function(e,t,a,r){var n=this.props,i=n.layout,l=n.type,o=n.stroke,c=n.connectNulls,d=n.isRange;n.ref;var x=ds(n,ls);return s.createElement(ie,{clipPath:a?"url(#clipPath-".concat(r,")"):null},s.createElement(xe,xs({},Q(x,!0),{points:e,connectNulls:c,type:l,baseLine:t,layout:i,stroke:"none",className:"recharts-area-area"})),"none"!==o&&s.createElement(xe,xs({},Q(this.props,!1),{className:"recharts-area-curve",layout:i,type:l,connectNulls:c,fill:"none",points:e})),"none"!==o&&d&&s.createElement(xe,xs({},Q(this.props,!1),{className:"recharts-area-curve",layout:i,type:l,connectNulls:c,fill:"none",points:t})))}},{key:"renderAreaWithAnimation",value:function(e,t){var a=this,r=this.props,n=r.points,i=r.baseLine,l=r.isAnimationActive,o=r.animationBegin,c=r.animationDuration,d=r.animationEasing,x=r.animationId,h=this.state,m=h.prevPoints,u=h.prevBaseLine;return s.createElement(pe,{begin:o,duration:c,isActive:l,easing:d,from:{t:0},to:{t:1},key:"area-".concat(x),onAnimationEnd:this.handleAnimationEnd,onAnimationStart:this.handleAnimationStart},function(r){var l=r.t;if(m){var o,c=m.length/n.length,d=n.map(function(e,t){var s=Math.floor(t*c);if(m[s]){var a=m[s],r=je(a.x,e.x),n=je(a.y,e.y);return ms(ms({},e),{},{x:r(l),y:n(l)})}return e});return o=fe(i)&&"number"==typeof i?je(u,i)(l):he(i)||Pe(i)?je(u,0)(l):i.map(function(e,t){var s=Math.floor(t*c);if(u[s]){var a=u[s],r=je(a.x,e.x),n=je(a.y,e.y);return ms(ms({},e),{},{x:r(l),y:n(l)})}return e}),a.renderAreaStatically(d,o,e,t)}return s.createElement(ie,null,s.createElement("defs",null,s.createElement("clipPath",{id:"animationClipPath-".concat(t)},a.renderClipRect(l))),s.createElement(ie,{clipPath:"url(#animationClipPath-".concat(t,")")},a.renderAreaStatically(n,i,e,t)))})}},{key:"renderArea",value:function(e,t){var s=this.props,a=s.points,r=s.baseLine,n=s.isAnimationActive,i=this.state,l=i.prevPoints,o=i.prevBaseLine,c=i.totalLength;return n&&a&&a.length&&(!l&&c>0||!Ke(l,a)||!Ke(o,r))?this.renderAreaWithAnimation(e,t):this.renderAreaStatically(a,r,e,t)}},{key:"render",value:function(){var e,a=this.props,r=a.hide,n=a.dot,i=a.points,l=a.className,o=a.top,c=a.left,d=a.xAxis,x=a.yAxis,h=a.width,m=a.height,u=a.isAnimationActive,p=a.id;if(r||!i||!i.length)return null;var g=this.state.isAnimationFinished,j=1===i.length,f=t("recharts-area",l),b=d&&d.allowDataOverflow,y=x&&x.allowDataOverflow,v=b||y,N=he(p)?this.id:p,w=null!==(e=Q(n,!1))&&void 0!==e?e:{r:3,strokeWidth:2},k=w.r,S=void 0===k?3:k,A=w.strokeWidth,C=void 0===A?2:A,O=(Te(n)?n:{}).clipDot,P=void 0===O||O,T=2*S+C;return s.createElement(ie,{className:f},b||y?s.createElement("defs",null,s.createElement("clipPath",{id:"clipPath-".concat(N)},s.createElement("rect",{x:b?c:c-h/2,y:y?o:o-m/2,width:b?h:2*h,height:y?m:2*m})),!P&&s.createElement("clipPath",{id:"clipPath-dots-".concat(N)},s.createElement("rect",{x:c-T/2,y:o-T/2,width:h+T,height:m+T}))):null,j?null:this.renderArea(v,N),(n||j)&&this.renderDots(v,P,N),(!u||g)&&be.renderCallByParent(this.props,i))}}
1])&&us(r.prototype,n),i&&us(r,i),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,i}();is=ys,fs(ys,"displayName","Area"),fs(ys,"defaultProps",{stroke:"#3182bd",fill:"#3182bd",fillOpacity:.6,xAxisId:0,yAxisId:0,legendType:"line",connectNulls:!1,points:[],dot:!1,activeDot:!0,hide:!1,isAnimationActive:!ye.isSsr,animationBegin:0,animationDuration:1500,animationEasing:"ease"}),fs(ys,"getBaseValue",function(e,t,s,a){var r=e.layout,n=e.baseValue,i=t.props.baseValue,l=null!=i?i:n;if(fe(l)&&"number"==typeof l)return l;var o="horizontal"===r?a:s,c=o.scale.domain();if("number"===o.type){var d=Math.max(c[0],c[1]),x=Math.min(c[0],c[1]);return"dataMin"===l?x:"dataMax"===l||d<0?d:Math.max(Math.min(c[0],c[1]),0)}return"dataMin"===l?c[0]:"dataMax"===l?c[1]:c[0]}),fs(ys,"getComposedData",function(e){var t,s=e.props,a=e.item,r=e.xAxis,n=e.yAxis,i=e.xAxisTicks,l=e.yAxisTicks,o=e.bandSize,c=e.dataKey,d=e.stackedData,x=e.dataStartIndex,h=e.displayedData,m=e.offset,u=s.layout,p=d&&d.length,g=is.getBaseValue(s,a,r,n),j="horizontal"===u,f=!1,b=h.map(function(e,t){var s;p?s=d[x+t]:(s=me(e,c),Array.isArray(s)?f=!0:s=[g,s]);var a=null==s[1]||p&&null==me(e,c);return j?{x:Ee({axis:r,ticks:i,bandSize:o,entry:e,index:t}),y:a?null:n.scale(s[1]),value:s,payload:e}:{x:a?null:r.scale(s[1]),y:Ee({axis:n,ticks:l,bandSize:o,entry:e,index:t}),value:s,payload:e}});return t=p||f?b.map(function(e){var t=Array.isArray(e.value)?e.value[0]:null;return j?{x:e.x,y:null!=t&&null!=e.y?n.scale(t):null}:{x:null!=t?r.scale(t):null,y:e.y}}):j?n.scale(g):r.scale(g),ms({points:b,baseLine:t,layout:u,isRange:f},m)}),fs(ys,"renderDotItem",function(e,a){var r;if(s.isValidElement(e))r=s.cloneElement(e,a);else if(He(e))r=e(a);else{var n=t("recharts-area-dot","boolean"!=typeof e?e.className:""),i=a.key,l=ds(a,os);r=s.createElement(de,xs({},l,{key:i,className:n}))}return r});var vs=Re({chartName:"BarChart",GraphicalChild:_e,defaultTooltipEventType:"axis",validateTooltipEventTypes:["axis","item"],axisComponents:[{axisType:"xAxis",AxisComp:Le},{axisType:"yAxis",AxisComp:Fe}],formatAxisMap:De}),Ns=Re({chartName:"PieChart",GraphicalChild:ns,validateTooltipEventTypes:["item"],defaultTooltipEventType:"item",legendContent:"children",axisComponents:[{axisType:"angleAxis",AxisComp:qt},{axisType:"radiusAxis",AxisComp:Lt}],formatAxisMap:Ue,defaultProps:{layout:"centric",startAngle:0,endAngle:360,cx:"50%",cy:"50%",innerRadius:0,outerRadius:"80%"}}),ws=Re({chartName:"AreaChart",GraphicalChild:ys,axisComponents:[{axisType:"xAxis",AxisComp:Le},{axisType:"yAxis",AxisComp:Fe}],formatAxisMap:De});const ks=({data:e})=>{const t=e.slice(0,10).map(e=>({name:s(e.referrer),total:e.total_users,paid:e.paid_users,free:e.free_users}));function s(e){if(!e)return"Direct / Unknown";e=e.replace(/"/g,"");try{return new URL(e).hostname}catch(t){return e}}return r.jsxs("div",{children:[r.jsx("h2",{className:"text-2xl font-bold mb-4",children:"Referrer Statistics"}),r.jsxs("div",{className:"mb-8",children:[r.jsx("h3",{className:"text-xl font-semibold mb-4",children:"Top 10 Referrers"}),r.jsx("div",{className:"h-96",children:r.jsx(Ie,{width:"100%",height:"100%",children:r.jsxs(vs,{data:t,margin:{top:20,right:30,left:20,bottom:70},children:[r.jsx(Me,{strokeDasharray:"3 3"}),r.jsx(Le,{dataKey:"name",angle:-45,textAnchor:"end",height:70,interval:0}),r.jsx(Fe,{}),r.jsx(Be,{}),r.jsx(ze,{}),r.jsx(_e,{dataKey:"total",name:"Total Users",fill:"#8884d8"}),r.jsx(_e,{dataKey:"paid",name:"Paid Users",fill:"#82ca9d"}),r.jsx(_e,{dataKey:"free",name:"Free Users",fill:"#ffc658"})]})})})]}),r.jsx(n,{component:i,children:r.jsxs(l,{children:[r.jsx(o,{children:r.jsxs(c,{children:[r.jsx(d,{children:"Referrer"}),r.jsx(d,{align:"right",children:"Total Users"}),r.jsx(d,{align:"right",children:"Paid Users"}),r.jsx(d,{align:"right",children:"Free Users"}),r.jsx(d,{align:"right",children:"Conversion Rate"})]})}),r.jsxs(x,{children:[e.map((e,t)=>{return r.jsxs(c,{children:[r.jsx(d,{component:"th",scope:"row",children:s(e.referrer)}),r.jsx(d,{align:"right",children:e.total_users}),r.jsx(d,{align:"right",children:e.paid_users}),r.jsx(d,{align:"right",children:e.free_users}),r.jsx(d,{align:"right",children:(a=e.paid_users,n=e.total_users,n?`${(a/n*100).toFixed(2)}%`:"0%")})]},t);var a,n}),0===e.length&&r.jsx(c,{children:r.jsx(d,{colSpan:5,align:"center",children:"No referrer data available"})})]})]})})]})},Ss=({data:e})=>{const t=J(),{enqueueSnackbar:s}=Y(),a=["#0088FE","#00C49F","#FFBB28","#FF8042","#8884d8","#82ca9d"],m=e.reduce((e,t)=>
1e+t.user_count,0),u=e.map((e,t)=>({name:e.plan_type||"Unknown",value:e.user_count,color:a[t%a.length]})),p=({active:e,payload:t})=>{if(e&&t&&t.length){const e=t[0].payload;return r.jsxs("div",{className:"bg-white p-3 border border-gray-200 shadow-md rounded",children:[r.jsx("p",{className:"font-semibold",children:e.name}),r.jsxs("p",{children:["Users: ",e.value]}),r.jsxs("p",{children:["Percentage: ",(e.value/m*100).toFixed(2),"%"]})]})}return null},g=async e=>{try{const a=await t.get(`/api/analytics/download-users/${e}`,{responseType:"blob"}),r=window.URL.createObjectURL(new Blob([a.data])),n=document.createElement("a");n.href=r,n.setAttribute("download",`automateed-${e}-users-${(new Date).toISOString().slice(0,10)}.csv`),document.body.appendChild(n),n.click(),n.remove(),s(`${e.charAt(0).toUpperCase()+e.slice(1)} users downloaded successfully`,{variant:"success"})}catch(a){s(`Failed to download ${e} users`,{variant:"error"})}};return r.jsxs("div",{children:[r.jsx("h2",{className:"text-2xl font-bold mb-4",children:"User Plan Distribution"}),r.jsxs("div",{className:"mb-4 flex flex-wrap gap-2",children:[r.jsx(h,{variant:"outlined",color:"primary",startIcon:r.jsx(We,{}),onClick:()=>g("free"),children:"Download Free Users"}),r.jsx(h,{variant:"outlined",color:"primary",startIcon:r.jsx(We,{}),onClick:()=>g("paid"),children:"Download Paid Users"}),r.jsx(h,{variant:"outlined",color:"primary",startIcon:r.jsx(We,{}),onClick:()=>g("appsumo"),children:"Download AppSumo Users"}),r.jsx(h,{variant:"outlined",color:"primary",startIcon:r.jsx(We,{}),onClick:()=>g("all"),children:"Download All Users"})]}),r.jsxs("div",{className:"mb-8 flex flex-col md:flex-row",children:[r.jsx("div",{className:"w-full md:w-1/2 h-96",children:r.jsx(Ie,{width:"100%",height:"100%",children:r.jsxs(Ns,{children:[r.jsx(ns,{data:u,cx:"50%",cy:"50%",labelLine:!1,outerRadius:150,fill:"#8884d8",dataKey:"value",label:({name:e,percent:t})=>`${e} ${(100*t).toFixed(0)}%`,children:u.map((e,t)=>r.jsx(Ce,{fill:e.color},`cell-${t}`))}),r.jsx(Be,{content:r.jsx(p,{})}),r.jsx(ze,{})]})})}),r.jsxs("div",{className:"w-full md:w-1/2 p-4",children:[r.jsx("h3",{className:"text-xl font-semibold mb-4",children:"Summary"}),r.jsxs("div",{className:"bg-gray-50 p-4 rounded-lg",children:[r.jsxs("p",{className:"mb-2",children:[r.jsx("span",{className:"font-semibold",children:"Total Users:"})," ",m]}),e.map((e,t)=>r.jsxs("div",{className:"mb-2",children:[r.jsxs("p",{children:[r.jsxs("span",{className:"font-semibold",children:[e.plan_type||"Unknown",":"]})," ",e.user_count," users (",(e.user_count/m*100).toFixed(2),"%)"]}),r.jsx("div",{className:"w-full bg-gray-200 rounded-full h-2.5",children:r.jsx("div",{className:"h-2.5 rounded-full",style:{width:e.user_count/m*100+"%",backgroundColor:a[t%a.length]}})})]},t))]})]})]}),r.jsx(n,{component:i,children:r.jsxs(l,{children:[r.jsx(o,{children:r.jsxs(c,{children:[r.jsx(d,{children:"Plan Type"}),r.jsx(d,{align:"right",children:"User Count"}),r.jsx(d,{align:"right",children:"Percentage"})]})}),r.jsxs(x,{children:[e.map((e,t)=>r.jsxs(c,{children:[r.jsx(d,{component:"th",scope:"row",children:e.plan_type||"Unknown"}),r.jsx(d,{align:"right",children:e.user_count}),r.jsxs(d,{align:"right",children:[(e.user_count/m*100).toFixed(2),"%"]})]},t)),0===e.length&&r.jsx(c,{children:r.jsx(d,{colSpan:3,align:"center",children:"No user plan data available"})})]})]})})]})},As=({data:e})=>{if(null==e)return r.jsx("div",{className:"flex justify-center items-center h-64",children:r.jsx(m,{})});if(!Array.isArray(e))return r.jsx("div",{className:"flex justify-center items-center h-64",children:r.jsx(m,{})});if(0===e.length)return r.jsx(i,{className:"p-8 text-center",children:r.jsx("p",{className:"text-gray-500",children:"No user growth data available"})});const t=[...e].filter(e=>null!=e.month).sort((e,t)=>new Date(e.month)-new Date(t.month)),s=[...e].filter(e=>null!=e.month).sort((e,t)=>new Date(t.month)-new Date(e.month)),a=e=>{if(!e)return"Unknown";const[t,s]=e.split("-");return new Date(t,parseInt(s)-1).toLocaleDateString("en-US",{month:"short",year:"numeric"})},h=t.reduce((e,t)=>
1e+parseInt(t.new_users||0),0),u=t.reduce((e,t)=>e+parseInt(t.new_paid_users||0),0),p=h?(u/h*100).toFixed(2):0;return r.jsxs("div",{children:[r.jsx("h2",{className:"text-2xl font-bold mb-4",children:"User Growth Statistics"}),r.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4 mb-8",children:[r.jsxs(i,{className:"p-4",children:[r.jsx("h3",{className:"text-lg font-semibold text-gray-600",children:"Total New Users"}),r.jsx("p",{className:"text-3xl font-bold text-blue-600",children:h})]}),r.jsxs(i,{className:"p-4",children:[r.jsx("h3",{className:"text-lg font-semibold text-gray-600",children:"New Paid Users"}),r.jsx("p",{className:"text-3xl font-bold text-green-600",children:u})]}),r.jsxs(i,{className:"p-4",children:[r.jsx("h3",{className:"text-lg font-semibold text-gray-600",children:"Conversion Rate"}),r.jsxs("p",{className:"text-3xl font-bold text-purple-600",children:[p,"%"]})]})]}),r.jsxs("div",{className:"mb-8",children:[r.jsx("h3",{className:"text-xl font-semibold mb-4",children:"Monthly User Growth"}),r.jsx("div",{className:"h-96",children:r.jsx(Ie,{width:"100%",height:"100%",children:r.jsxs(ws,{data:t,margin:{top:20,right:30,left:20,bottom:10},children:[r.jsx(Me,{strokeDasharray:"3 3"}),r.jsx(Le,{dataKey:"month",tickFormatter:a}),r.jsx(Fe,{}),r.jsx(Be,{labelFormatter:a}),r.jsx(ze,{}),r.jsx(ys,{type:"monotone",dataKey:"new_users",name:"Total New Users",stroke:"#8884d8",fill:"#8884d8",fillOpacity:.3}),r.jsx(ys,{type:"monotone",dataKey:"new_paid_users",name:"New Paid Users",stroke:"#82ca9d",fill:"#82ca9d",fillOpacity:.3})]})})})]}),r.jsx(n,{component:i,children:r.jsxs(l,{children:[r.jsx(o,{children:r.jsxs(c,{children:[r.jsx(d,{children:"Month"}),r.jsx(d,{align:"right",children:"New Users"}),r.jsx(d,{align:"right",children:"New Paid Users"}),r.jsx(d,{align:"right",children:"Conversion Rate"})]})}),r.jsxs(x,{children:[s.map((e,t)=>r.jsxs(c,{children:[r.jsx(d,{component:"th",scope:"row",children:a(e.month)}),r.jsx(d,{align:"right",children:e.new_users}),r.jsx(d,{align:"right",children:e.new_paid_users}),r.jsxs(d,{align:"right",children:[e.new_users?(e.new_paid_users/e.new_users*100).toFixed(2):0,"%"]})]},t)),0===s.length&&r.jsx(c,{children:r.jsx(d,{colSpan:4,align:"center",children:"No user growth data available"})})]})]})})]})},Cs=({data:t})=>{const[s,a]=e.useState(["facebook.com","google.com","instagram.com","Direct / Unknown"]),[h,v]=e.useState(0),[N,w]=e.useState([]),[k,S]=e.useState(!1),[A,C]=e.useState(""),O=e.useMemo(()=>{const e=new Set;return t.forEach(t=>e.add(t.referrer)),Array.from(e)},[t]),P=e.useMemo(()=>{const e=new Set;return t.forEach(t=>e.add(t.month)),Array.from(e).sort()},[t]);e.useMemo(()=>{const e=new Map;return P.forEach(s=>{const a=t.filter(e=>e.month===s);e.set(s,a)}),e},[t,P]),e.useMemo(()=>{const e=new Map;return O.forEach(s=>{const a=t.filter(e=>e.referrer===s);e.set(s,a)}),e},[t,O]);const T=e.useMemo(()=>{const e=[];return P.forEach(s=>{const a=t.filter(e=>e.month===s),r=a.reduce((e,t)=>e+parseInt(t.total_users||0),0),n=a.reduce((e,t)=>e+parseInt(t.paid_users||0),0),i=a.reduce((e,t)=>e+parseInt(t.free_users||0),0),l=r?(n/r*100).toFixed(2):0;e.push({month:s,totalUsers:r,paidUsers:n,freeUsers:i,conversionRate:l})}),e},[t,P]),E=e=>{if(!e)return"";const[t,s]=e.split("-");return new Date(t,parseInt(s)-1).toLocaleDateString("en-US",{month:"short",year:"numeric"})},R=e.useMemo(()=>{const e=[];return P.forEach(t=>{const s={month:t,formattedMonth:E(t)};O.forEach(e=>{s[e]=0}),e.push(s)}),t.forEach(t=>{const s=e.find(e=>e.month===t.month);s&&(s[t.referrer]=parseFloat(t.conversion_rate))}),e},[t,P,O]),_=e.useMemo(()=>P.map(e=>{const s={month:e,formattedMonth:E(e)};return O.forEach(a=>{const r=t.find(t=>t.month===e&&t.referrer===a);s[a]=r?parseFloat(r.conversion_rate):0}),s}),[t,P,O]),L=async e=>{S(!0);try{const t=await Ze.get(`/api/analytics/platform-purchases?platform=${e}`);t.data&&t.data.success?w(t.data.data||[]):w([])}catch(t){t.response,w([])}finally{S(!1)}},F=e=>{const t=["#8884d8","#82ca9d","#ffc658","#ff7300","#0088fe","#00c49f","#ffbb28","#ff8042"];return t[e%t.length]},D=e.useMemo(()=>N&&0!==N.length?N.reduce((e,t)=>
1{const s=t.amount?parseFloat(t.amount):0;return e+(isNaN(s)?0:s)},0).toFixed(2):"0.00",[N]);return r.jsxs("div",{children:[r.jsx("h2",{className:"text-2xl font-bold mb-4",children:"Platform Conversion Statistics"}),r.jsx(i,{className:"mb-6",children:r.jsxs(u,{value:h,onChange:(e,t)=>{v(t),4===t&&A&&L(A)},indicatorColor:"primary",textColor:"primary",variant:"fullWidth",children:[r.jsx(p,{label:"Trend Chart"}),r.jsx(p,{label:"Monthly Comparison"}),r.jsx(p,{label:"Monthly Summary"}),r.jsx(p,{label:"Platform Detail"}),r.jsx(p,{label:"Purchase Details"})]})}),4!==h&&r.jsxs(g,{className:"w-full md:w-1/2 mb-4",children:[r.jsx(j,{id:"platform-select-label",children:"Select Platforms"}),r.jsx(f,{labelId:"platform-select-label",id:"platform-select",multiple:!0,value:s,onChange:e=>{a(e.target.value)},renderValue:e=>e.join(", "),children:O.map(e=>r.jsx(b,{value:e,children:e},e))})]}),4===h&&r.jsxs(g,{className:"w-full md:w-1/2 mb-4",children:[r.jsx(j,{id:"purchase-platform-select-label",children:"Select Platform"}),r.jsx(f,{labelId:"purchase-platform-select-label",id:"purchase-platform-select",value:A,onChange:e=>{const t=e.target.value;C(t),t&&4===h&&L(t)},children:O.map(e=>r.jsx(b,{value:e,children:e},e))})]}),0===h&&r.jsxs("div",{className:"mb-6",children:[r.jsx("h3",{className:"text-xl font-semibold mb-4",children:"Conversion Rate Trends by Platform"}),r.jsx("div",{className:"h-96",children:r.jsx(Ie,{width:"100%",height:"100%",children:r.jsxs($e,{data:R,margin:{top:20,right:30,left:20,bottom:70},children:[r.jsx(Me,{strokeDasharray:"3 3"}),r.jsx(Le,{dataKey:"formattedMonth",angle:-45,textAnchor:"end",height:70,interval:0}),r.jsx(Fe,{label:{value:"Conversion Rate (%)",angle:-90,position:"insideLeft",style:{textAnchor:"middle"}},domain:[0,"dataMax + 5"]}),r.jsx(Be,{formatter:e=>[`${e}%`,"Conversion Rate"]}),r.jsx(ze,{}),s.map((e,t)=>r.jsx(Ve,{type:"monotone",dataKey:e,name:e,stroke:F(t),activeDot:{r:8}},e))]})})})]}),1===h&&r.jsxs("div",{className:"mb-6",children:[r.jsx("h3",{className:"text-xl font-semibold mb-4",children:"Monthly Platform Comparison"}),r.jsx("div",{className:"h-96",children:r.jsx(Ie,{width:"100%",height:"100%",children:r.jsxs(vs,{data:_,margin:{top:20,right:30,left:20,bottom:70},children:[r.jsx(Me,{strokeDasharray:"3 3"}),r.jsx(Le,{dataKey:"formattedMonth",angle:-45,textAnchor:"end",height:70,interval:0}),r.jsx(Fe,{label:{value:"Conversion Rate (%)",angle:-90,position:"insideLeft",style:{textAnchor:"middle"}}}),r.jsx(Be,{formatter:e=>[`${e}%`,"Conversion Rate"]}),r.jsx(ze,{}),s.map((e,t)=>r.jsx(_e,{dataKey:e,name:e,fill:F(t)},e))]})})})]}),2===h&&r.jsxs("div",{className:"mb-6",children:[r.jsx("h3",{className:"text-xl font-semibold mb-4",children:"Monthly Conversion Summary"}),r.jsx(n,{component:i,children:r.jsxs(l,{children:[r.jsx(o,{children:r.jsxs(c,{children:[r.jsx(d,{children:"Month"}),r.jsx(d,{align:"right",children:"Total Users"}),r.jsx(d,{align:"right",children:"Paid Users"}),r.jsx(d,{align:"right",children:"Free Users"}),r.jsx(d,{align:"right",children:"Overall Conversion Rate"})]})}),r.jsx(x,{children:T.map((e,t)=>r.jsxs(c,{children:[r.jsx(d,{children:E(e.month)}),r.jsx(d,{align:"right",children:e.totalUsers}),r.jsx(d,{align:"right",children:e.paidUsers}),r.jsx(d,{align:"right",children:e.freeUsers}),r.jsxs(d,{align:"right",children:[e.conversionRate,"%"]})]},t))})]})})]}),3===h&&r.jsxs("div",{className:"mb-6",children:[r.jsx("h3",{className:"text-xl font-semibold mb-4",children:"Platform Performance Details"}),s.map(e=>r.jsxs("div",{className:"mb-8",children:[r.jsx(y,{variant:"h6",className:"font-bold mb-2",children:e}),r.jsx(n,{component:i,children:r.jsxs(l,{children:[r.jsx(o,{children:r.jsxs(c,{children:[r.jsx(d,{children:"Month"}),r.jsx(d,{align:"right",children:"Total Users"}),r.jsx(d,{align:"right",children:"Paid Users"}),r.jsx(d,{align:"right",children:"Free Users"}),r.jsx(d,{align:"right",children:"Conversion Rate"})]})}),r.jsx(x,{children:t.filter(t=>t.referrer===e).sort((e,t)=>e.month.localeCompare(t.month)).map((e,t)=>r.jsxs(c,{children:[r.jsx(d,{children:E(e.month)}),r.jsx(d,{align:"right",children:e.total_users}),r.jsx(d,{align:"right",children:e.paid_users}),r.jsx(d,{align:"right",children:e.free_users}),r.jsxs(d,{align:"right",children:[e.conversion_rate,"%"]})]},t))})]})})]},e))]}),4===h&&r.jsxs("div",{className:"mb-6",children:[r.jsxs("h3",{className:"text-xl font-semibold mb-4",children:["Purchase Details for ",A||"Selected Platform"]}),!A&&r.jsx(y,{variant:"body1",className:"mb-4",children:"Please select a platform to view purchase details."}),A&&k&&r.jsx("div",{className:"flex justify-center my-8",children:r.jsx(m,{})}),A&&!k&&(!N||0===N.length)&&r.jsx(y,{variant:"body1",className:"mb-4",children:"No purchase data found for the selected platform."}),A&&!k&&N&&N.length>0&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"mb-4",children:[r.jsxs(y,{variant:"body1",className:"font-semibold",children:["Total Revenue: $",D]}),r.jsxs(y,{variant:"body1",children:["Total Purchases: ",N.length]})]}),r.jsx(n,{component:i,children:r.jsxs(l,{children:[r.jsx(o,{children:r.jsxs(c,{children:[r.jsx(d,{children:"Email"}),r.jsx(d,{align:"right",children:"Purchase Date"}),r.jsx(d,{align:"right",children:"Amount"}),r.jsx(d,{align:"right",children:"Plan"}),r.jsx(d,{align:"right",children:"Type"})]})}),r.jsx(x,{children:N.map((e,t)=>{return r.jsxs(c,{children:[r.jsx(d,{children:e.email||"Unknown"}),r.jsx(d,{align:"right",children:(s=e.purchase_date,s?new Date(s).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}):"N/A")}),r.jsx(d,{align:"right",children:e.amount?`$${parseFloat(e.amount).toFixed(2)}`:"N/A"}),r.jsx(d,{align:"right",children:e.plan||"Unknown"}),r.jsx(d,{align:"right",children:e.type||"Unknown"})]},t);var s})})]})})]})]})]})},Os=["#4f46e5","#10b981","#f59e0b","#ef4444","#8b5cf6","#06b6d4","#ec4899","#84cc16","#f97316","#6366f1","#14b8a6","#a855f7","#22c55e","#eab308","#3b82f6","#d946ef","#0ea5e9","#f43f5e","#64748b","#78716c","#94a3b8","#9ca3af"],Ps={US:"ðºð¸",GB:"ð¬ð§",CA:"ð¨ð¦",AU:"ð¦ðº",DE:"ð©ðª",FR:"ð«ð·",IT:"ð®ð¹",ES:"ðªð¸",NL:"ð³ð±",BE:"ð§ðª",AT:"ð¦ð¹",CH:"ð¨ð",SE:"ð¸ðª",NO:"ð³ð´",DK:"ð©ð°",FI:"ð«ð®",PL:"ðµð±",CZ:"ð¨ð¿",PT:"ðµð¹",IE:"ð®ðª",NZ:"ð³ð¿",SG:"ð¸ð¬",HK:"ðð°",JP:"ð¯ðµ",KR:"ð°
1ð·",IN:"ð®ð³",BR:"ð§ð·",MX:"ð²ð½",AR:"ð¦ð·",CO:"ð¨ð´",CL:"ð¨ð±",ZA:"ð¿ð¦",AE:"ð¦ðª",SA:"ð¸ð¦",IL:"ð®ð±",TR:"ð¹ð·",RU:"ð·ðº",UA:"ðºð¦",PH:"ðµð",TH:"ð¹ð",MY:"ð²ð¾",ID:"ð®ð©",VN:"ð»ð³",PK:"ðµð°",BD:"ð§ð©",NG:"ð³ð¬",EG:"ðªð¬",KE:"ð°ðª",GH:"ð¬ð",TW:"ð¹ð¼",RO:"ð·ð´",HU:"ððº",GR:"ð¬ð·",BG:"ð§ð¬",HR:"ðð·",SK:"ð¸ð°",SI:"ð¸ð®",RS:"ð·ð¸",LT:"ð±ð¹",LV:"ð±ð»",EE:"ðªðª",IS:"ð®ð¸",LU:"ð±ðº",MT:"ð²ð¹",CY:"ð¨ð¾",CN:"ð¨ð³"},Ts=({data:t})=>{const[s,a]=e.useState(null),[u,p]=e.useState(!0),[g,j]=e.useState(!1),[f,b]=e.useState(null),[y,_]=e.useState([]),[L,F]=e.useState(!1),[D,U]=e.useState(null),[I,M]=e.useState(!0),[B,z]=e.useState(""),$=J(),{enqueueSnackbar:V}=Y(),W=[{key:"coloring",label:"Coloring Books",value:t?.coloring||0},{key:"storybook",label:"Storybooks",value:t?.storybook||0},{key:"ebook",label:"eBooks",value:t?.ebook||0},{key:"novel",label:"Novels",value:t?.novel||0}],H=W.map(e=>({name:e.label,count:e.value})),K=W.reduce((e,t)=>e+t.value,0),Z=async()=>{try{const e=await $.get("/api/analytics/ebook-categories");e.data.success&&a(e.data.data)}catch(e){}finally{p(!1)}},q=async()=>{M(!0);try{const e=await $.get("/api/analytics/book-creation-stats-by-country");e.data.success&&U(e.data.data)}catch(e){503!==e.response?.status&&V("Failed to load country statistics",{variant:"error"})}finally{M(!1)}},G=async(e=!1)=>{j(!0);try{const t=e?"/api/analytics/ebook-categories/trigger?reset=true":"/api/analytics/ebook-categories/trigger";(await $.post(t)).data.success&&(V(e?"Restarting categorization from scratch...":"Categorization started!",{variant:"success"}),X())}catch(t){V(t.response?.data?.msg||"Failed to start categorization",{variant:"error"})}finally{j(!1)}},X=()=>{const e=setInterval(async()=>{try{const t=await $.get("/api/analytics/ebook-categories");t.data.success&&(a(t.data.data),"running"!==t.data.data.progress.status&&(clearInterval(e),"completed"===t.data.data.progress.status&&V("Categorization completed!",{variant:"success"})))}catch(t){clearInterval(e)}},3e3)};e.useEffect(()=>{Z(),q()},[]),e.useEffect(()=>{"running"===s?.progress?.status&&X()},[s?.progress?.status]);const Q=s?.categories?.slice(0,12).map((e,t)=>({name:e.category,value:e.count,color:Os[t%Os.length]}))||[];return r.jsxs("div",{className:"space-y-8",children:[r.jsxs("div",{children:[r.jsx("h2",{className:"text-2xl font-bold mb-4",children:"Book Creation by Type"}),r.jsx("div",{className:"mb-8",children:r.jsx("div",{className:"h-80",children:r.jsx(Ie,{width:"100%",height:"100%",children:r.jsxs(vs,{data:H,margin:{top:20,right:20,left:10,bottom:40},children:[r.jsx(Me,{strokeDasharray:"3 3"}),r.jsx(Le,{dataKey:"name",angle:-20,textAnchor:"end",height:50}),r.jsx(Fe,{allowDecimals:!1}),r.jsx(Be,{}),r.jsx(ze,{}),r.jsx(_e,{dataKey:"count",name:"Created",fill:"#4f46e5"})]})})})}),r.jsx(n,{component:i,children:r.jsxs(l,{children:[r.jsx(o,{children:r.jsxs(c,{children:[r.jsx(d,{children:"Type"}),r.jsx(d,{align:"right",children:"Count"}),r.jsx(d,{align:"right",children:"Share"})]})}),r.jsx(x,{children:W.map(e=>r.jsxs(c,{children:[r.jsx(d,{component:"th",scope:"row",children:e.label}),r.jsx(d,{align:"right",children:e.value.toLocaleString()}),r.jsx(d,{align:"right",children:K?`${(e.value/K*100).toFixed(1)}%`:"0%"})]},e.key))})]})})]}),r.jsxs("div",{className:"border-t pt-8",children:[r.jsxs("div",{className:"flex justify-between items-center mb-4",children:[r.jsxs("div",{children:[r.jsx("h2",{className:"text-2xl font-bold",children:"ð Book Creation by Country"}),r.jsx("p",{className:"text-gray-500 text-sm",children:"Book creation broken down by user location (based on IP geolocation)"})]}),r.jsx(v,{title:"Refresh country stats",children:r.jsx(N,{onClick:q,disabled:I,children:r.jsx(qe,{})})})]}),I?r.jsx("div",{className:"flex justify-center py-8",children:r.jsx(m,{})}):D?r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-5 gap-4 mb-6",children:[r.jsxs(i,{className:"p-4 text-center",children:[r.jsx("p",{className:"text-3xl font-bold text-blue-600",children:D.summary.totalBooks.toLocaleStr
1ing()}),r.jsx("p",{className:"text-gray-500 text-sm",children:"Total Books (with location)"})]}),r.jsxs(i,{className:"p-4 text-center",children:[r.jsx("p",{className:"text-3xl font-bold text-green-600",children:D.summary.totalCountries}),r.jsx("p",{className:"text-gray-500 text-sm",children:"Countries"})]}),r.jsxs(i,{className:"p-4 text-center",children:[r.jsx("p",{className:"text-3xl font-bold text-purple-600",children:D.summary.totalByType.ebook.toLocaleString()}),r.jsx("p",{className:"text-gray-500 text-sm",children:"eBooks"})]}),r.jsxs(i,{className:"p-4 text-center",children:[r.jsx("p",{className:"text-3xl font-bold text-orange-600",children:D.summary.totalByType.storybook.toLocaleString()}),r.jsx("p",{className:"text-gray-500 text-sm",children:"Storybooks"})]}),r.jsxs(i,{className:"p-4 text-center",children:[r.jsx("p",{className:"text-3xl font-bold text-pink-600",children:D.summary.totalByType.coloring.toLocaleString()}),r.jsx("p",{className:"text-gray-500 text-sm",children:"Coloring Books"})]})]}),r.jsxs("div",{className:"grid grid-cols-2 gap-6 mb-6",children:[r.jsxs(i,{className:"p-4",children:[r.jsx("h3",{className:"font-semibold mb-4",children:"Top 10 Countries by Book Creation"}),r.jsx("div",{className:"h-80",children:r.jsx(Ie,{width:"100%",height:"100%",children:r.jsxs(Ns,{children:[r.jsx(ns,{data:D.topCountries.map((e,t)=>({name:`${Ps[e.countryCode]||"ð³ï¸"} ${e.countryName}`,value:e.total,color:Os[t%Os.length]})),dataKey:"value",nameKey:"name",cx:"50%",cy:"50%",outerRadius:100,label:({name:e,percent:t})=>`${e.slice(0,12)}... (${(100*t).toFixed(0)}%)`,children:D.topCountries.map((e,t)=>r.jsx(Ce,{fill:Os[t%Os.length]},`cell-${t}`))}),r.jsx(Be,{})]})})})]}),r.jsxs(i,{className:"p-4",children:[r.jsx("h3",{className:"font-semibold mb-4",children:"Top 10 Countries - By Book Type"}),r.jsx("div",{className:"h-80",children:r.jsx(Ie,{width:"100%",height:"100%",children:r.jsxs(vs,{data:D.topCountries.slice(0,10).map(e=>({name:`${Ps[e.countryCode]||""} ${e.countryCode}`,eBooks:e.ebook,Storybooks:e.storybook,Coloring:e.coloring,Novels:e.novel})),margin:{top:20,right:20,left:10,bottom:40},children:[r.jsx(Me,{strokeDasharray:"3 3"}),r.jsx(Le,{dataKey:"name",angle:-20,textAnchor:"end",height:50,tick:{fontSize:11}}),r.jsx(Fe,{allowDecimals:!1}),r.jsx(Be,{}),r.jsx(ze,{}),r.jsx(_e,{dataKey:"eBooks",stackId:"a",fill:"#4f46e5"}),r.jsx(_e,{dataKey:"Storybooks",stackId:"a",fill:"#f59e0b"}),r.jsx(_e,{dataKey:"Coloring",stackId:"a",fill:"#ec4899"}),r.jsx(_e,{dataKey:"Novels",stackId:"a",fill:"#10b981"})]})})})]})]}),r.jsx(w,{fullWidth:!0,variant:"outlined",placeholder:"Search countries...",value:B,onChange:e=>z(e.target.value),className:"mb-4",size:"small",InputProps:{startAdornment:r.jsx(k,{position:"start",children:r.jsx(Ye,{})})}}),r.jsx(n,{component:i,style:{maxHeight:500},children:r.jsxs(l,{stickyHeader:!0,size:"small",children:[r.jsx(o,{children:r.jsxs(c,{className:"bg-gray-100",children:[r.jsx(d,{children:r.jsx("strong",{children:"#"})}),r.jsx(d,{children:r.jsx("strong",{children:"Country"})}),r.jsx(d,{align:"right",children:r.jsx("strong",{children:"Total"})}),r.jsx(d,{align:"right",children:r.jsx("strong",{children:"eBooks"})}),r.jsx(d,{align:"right",children:r.jsx("strong",{children:"Novels"})}),r.jsx(d,{align:"right",children:r.jsx("strong",{children:"Storybooks"})}),r.jsx(d,{align:"right",children:r.jsx("strong",{children:"Coloring"})}),r.jsx(d,{align:"right",children:r.jsx("strong",{children:"Share"})})]})}),r.jsx(x,{children:D.countries.filter(e=>""===B||e.countryName.toLowerCase().includes(B.toLowerCase())||e.countryCode.toLowerCase().includes(B.toLowerCase())).map((e,t)=>r.jsxs(c,{hover:!0,className:t%2==0?"bg-white":"bg-gray-50",children:[r.jsx(d,{children:t+1}),r.jsx(d,{children:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-lg",children:Ps[e.countryCode]||"ð³ï¸"}),r.jsx("span",{children:e.countryName}),r.jsxs("span",{className:"text-gray-400 text-xs",children:["(",e.countryCode,")"]})]})}),r.jsx(d,{align:"right",children:r.jsx("strong",{children:e.total.toLocaleString()})}
1),r.jsx(d,{align:"right",children:e.ebook.toLocaleString()}),r.jsx(d,{align:"right",children:e.novel.toLocaleString()}),r.jsx(d,{align:"right",children:e.storybook.toLocaleString()}),r.jsx(d,{align:"right",children:e.coloring.toLocaleString()}),r.jsx(d,{align:"right",children:r.jsx(S,{label:`${e.percentage}%`,size:"small",color:parseFloat(e.percentage)>5?"primary":"default"})})]},e.countryCode))})]})}),D.summary.unknownCountry>0&&r.jsx(i,{className:"p-4 mt-4 bg-gray-50",children:r.jsxs("p",{className:"text-sm text-gray-600",children:["â ï¸ ",r.jsx("strong",{children:D.summary.unknownCountry.toLocaleString()})," books have unknown location (eBooks: ",D.summary.unknownByType.ebook.toLocaleString(),", Novels: ",D.summary.unknownByType.novel.toLocaleString(),", Storybooks: ",D.summary.unknownByType.storybook.toLocaleString(),", Coloring: ",D.summary.unknownByType.coloring.toLocaleString(),")"]})})]}):r.jsx(A,{severity:"info",children:"Country statistics unavailable. This may be because the geoip-lite module is not installed on the server."})]}),r.jsxs("div",{className:"border-t pt-8",children:[r.jsxs("div",{className:"flex justify-between items-center mb-4",children:[r.jsxs("div",{children:[r.jsx("h2",{className:"text-2xl font-bold",children:"ð AI-Powered Category Analysis"}),r.jsx("p",{className:"text-gray-500 text-sm",children:"Ebook titles categorized by AI into topic categories"})]}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx(v,{title:"Refresh stats",children:r.jsx(N,{onClick:Z,disabled:u,children:r.jsx(qe,{})})}),"running"===s?.progress?.status&&r.jsx(h,{variant:"outlined",color:"error",size:"small",onClick:()=>{window.confirm("This will force reset the status to idle. Use this if categorization is stuck. Are you sure?")&&(async()=>{try{(await $.post("/api/analytics/ebook-categories/reset-status")).data.success&&(V("Status reset to idle. You can now continue or restart.",{variant:"success"}),Z())}catch(e){V("Failed to reset status",{variant:"error"})}})()},children:"â Force Stop"}),r.jsx(h,{variant:"outlined",color:"warning",onClick:()=>{window.confirm("This will DELETE all existing categorizations and re-categorize all ebooks from scratch. This will take a while. Are you sure?")&&G(!0)},disabled:g,children:"ð Restart All"}),r.jsx(h,{variant:"outlined",color:"secondary",onClick:()=>{window.confirm('This will re-categorize only books currently in "Other" category using improved prompts. Continue?')&&(async()=>{j(!0);try{const e=await $.post("/api/analytics/ebook-categories/recategorize-other");e.data.success&&(V(e.data.msg||"Re-categorizing 'Other' books...",{variant:"success"}),X())}catch(e){V(e.response?.data?.msg||"Failed to start re-categorization",{variant:"error"})}finally{j(!1)}})()},disabled:g||"running"===s?.progress?.status,children:"ð Re-categorize Other"}),r.jsx(h,{variant:"contained",color:"primary",startIcon:g?r.jsx(m,{size:16,color:"inherit"}):r.jsx(Ge,{}),onClick:()=>G(!1),disabled:g||"running"===s?.progress?.status,children:"running"===s?.progress?.status?"Running...":"Continue/Start"})]})]}),s?.progress&&r.jsxs(C,{className:"mb-6 p-4 bg-gray-50 rounded-lg",children:[r.jsxs("div",{className:"flex justify-between items-center mb-2",children:[r.jsxs("span",{className:"font-medium",children:["Categorization Progress",r.jsx(S,{size:"small",label:s.progress.status,color:"completed"===s.progress.status?"success":"running"===s.progress.status?"primary":"error"===s.progress.status?"error":"default",className:"ml-2"})]}),r.jsxs("span",{className:"text-sm text-gray-600",children:[s.progress.processed.toLocaleString()," / ",s.progress.total.toLocaleString(),"(",s.progress.percentComplete,"%)"]})]}),r.jsx(O,{variant:"determinate",value:parseFloat(s.progress.percentComplete)||0,className:"h-2 rounded"}),s.progress.errors>0&&r.jsxs(A,{severity:"warning",className:"mt-2",children:[s.progress.errors," errors during processing"]})]}),s?.summary&&r.jsxs("div",{className:"grid grid-cols-4 gap-4 mb-6",children:[r.jsxs(i,{className:"p-4 text-center",children:[r.jsx("p",{className:"text-3xl font-bold text-blue-600",children:s.summary.total.toLocaleStr
1ing()}),r.jsx("p",{className:"text-gray-500 text-sm",children:"Total Ebooks"})]}),r.jsxs(i,{className:"p-4 text-center",children:[r.jsx("p",{className:"text-3xl font-bold text-green-600",children:s.summary.categorized.toLocaleString()}),r.jsx("p",{className:"text-gray-500 text-sm",children:"Categorized"})]}),r.jsxs(i,{className:"p-4 text-center",children:[r.jsx("p",{className:"text-3xl font-bold text-orange-600",children:s.summary.uncategorized.toLocaleString()}),r.jsx("p",{className:"text-gray-500 text-sm",children:"Uncategorized"})]}),r.jsxs(i,{className:"p-4 text-center",children:[r.jsxs("p",{className:"text-3xl font-bold text-purple-600",children:[s.summary.percentCategorized,"%"]}),r.jsx("p",{className:"text-gray-500 text-sm",children:"Complete"})]})]}),s?.categories?.length>0&&r.jsxs("div",{className:"grid grid-cols-2 gap-6 mb-6",children:[r.jsxs(i,{className:"p-4",children:[r.jsx("h3",{className:"font-semibold mb-4",children:"Category Distribution (Top 12)"}),r.jsx("div",{className:"h-80",children:r.jsx(Ie,{width:"100%",height:"100%",children:r.jsxs(Ns,{children:[r.jsx(ns,{data:Q,dataKey:"value",nameKey:"name",cx:"50%",cy:"50%",outerRadius:100,label:({name:e,percent:t})=>`${e.slice(0,15)}${e.length>15?"...":""} (${(100*t).toFixed(0)}%)`,children:Q.map((e,t)=>r.jsx(Ce,{fill:e.color},`cell-${t}`))}),r.jsx(Be,{})]})})})]}),r.jsxs(i,{className:"p-4",children:[r.jsx("h3",{className:"font-semibold mb-4",children:"Top Categories"}),r.jsx("div",{className:"h-80",children:r.jsx(Ie,{width:"100%",height:"100%",children:r.jsxs(vs,{data:s.categories.slice(0,10),layout:"vertical",margin:{top:5,right:30,left:100,bottom:5},children:[r.jsx(Me,{strokeDasharray:"3 3"}),r.jsx(Le,{type:"number"}),r.jsx(Fe,{dataKey:"category",type:"category",width:100,tick:{fontSize:11}}),r.jsx(Be,{}),r.jsx(_e,{dataKey:"count",fill:"#4f46e5"})]})})})]})]}),s?.categories?.length>0&&r.jsx(n,{component:i,children:r.jsxs(l,{children:[r.jsx(o,{children:r.jsxs(c,{className:"bg-gray-100",children:[r.jsx(d,{children:r.jsx("strong",{children:"Category"})}),r.jsx(d,{align:"right",children:r.jsx("strong",{children:"Count"})}),r.jsx(d,{align:"right",children:r.jsx("strong",{children:"Percentage"})}),r.jsx(d,{children:r.jsx("strong",{children:"Top Countries"})}),r.jsx(d,{align:"center",children:r.jsx("strong",{children:"Actions"})})]})}),r.jsx(x,{children:s.categories.map((e,t)=>r.jsxs(c,{hover:!0,className:t%2==0?"bg-white":"bg-gray-50",children:[r.jsx(d,{children:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("div",{className:"w-3 h-3 rounded-full",style:{backgroundColor:Os[t%Os.length]}}),e.category]})}),r.jsx(d,{align:"right",children:e.count.toLocaleString()}),r.jsxs(d,{align:"right",children:[e.percentage,"%"]}),r.jsx(d,{children:e.topCountries&&e.topCountries.length>0?r.jsx("div",{className:"flex flex-wrap gap-1",children:e.topCountries.map((e,t)=>r.jsx(v,{title:`${e.countryName}: ${e.count.toLocaleString()} books`,children:r.jsx(S,{size:"small",label:`${Ps[e.countryCode]||"ð³ï¸"} ${e.count.toLocaleString()}`,variant:0===t?"filled":"outlined",color:0===t?"primary":"default",className:"text-xs"})},e.countryCode))}):r.jsx("span",{className:"text-gray-400 text-sm",children:"â"})}),r.jsx(d,{align:"center",children:r.jsx(h,{size:"small",onClick:()=>(async e=>{b(e),F(!0);try{const t=await $.get(`/api/analytics/ebook-categories/${encodeURIComponent(e)}`);t.data.success&&_(t.data.data.ebooks)}catch(t){V("Failed to load books",{variant:"error"})}finally{F(!1)}})(e.category),children:"View Books"})})]},e.category))})]})}),!u&&(!s?.categories||0===s.categories.length)&&r.jsxs(A,{severity:"info",className:"mt-4",children:['No categories found yet. Click "Start Categorization" to analyze your ebook titles with AI. This will process all ',s?.summary?.total||0," ebooks and categorize them into topics."]})]}),r.jsxs(P,{open:!!f,onClose:()=>b(null),maxWidth:"md",fullWidth:!0,children:[r.jsxs(T,{children:['ð Books in "',f,'"']}),r.jsx(E,{children:L?r.jsx("div",{className:"flex justify-center py-8",children:r.jsx(m,{})}):r.jsx(n,{children:r.jsxs(l,{size:"small",children:[r.jsx(o,{children:r.jsxs(c,{children:[r.jsx(d,{children:"Title"}),r.jsx(d,{children:"User"}),r.jsx(d,{children:"Created"})]})}),r.jsx(x,{children:y.map(e=>r.jsxs(c,{children:[r.jsx(d,{className:"max-w-xs truncate",children:e.book_title}),r.jsx(d,{children:e.email||"Unknown"}),r.jsx(d,{children:new Date(e.created_at).toLocaleDateString()})]},e.id))})]})})}),r.jsx(R,{children:r.jsx(h,{onClick:()=>b(null),children:"Close"})})]})]})};function Es(){const t=J(),[s,a]=e.useState(null),[n,i]=e.useState(!1),[l,o]=e.useState(null);return e.useEffect(()=>{(async()=>{i(!0);try{const e=await t.get("/api/analytics/market-research-feedback");e?.data?.success&&a(e.data.data)}catch(e){o(e?.message||"Failed to load feedback")}finally{i(!1)}})()},[]),n?r.jsx("div",{className:"p-4",children:"Loading..."}):l?r.jsx("div",{className:"p-4 text-red-600",children:l}):s?r.jsxs("div",{className:"space-y-6",children:[r.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:[r.jsx(Rs,{label:"Total Feedback",value:s.total}),r.jsx(Rs,{label:"Helpful Votes",value:s.helpful_yes}),r.jsx(Rs,{label:"History Requests",value:s.want_history}),r.jsx(Rs,{label:"Marketplaces",value:Object.keys(s.by_marketplace||{}).length})]}),r.jsxs("div",{className:"bg-white border rounded p-4",children:[r.jsx("h3",{className:"font-semibold mb-2",children:"Top Queries"}),s.top_queries?.length?r.jsx("ul",{className:"list-disc pl-5 space-y-1 text-sm",children:s.top_queries.map(e=>r.jsxs("li",{className:"flex justify-between",children:[r.jsx("span",{className:"truncate mr-3",children:e.q}),r.jsx("span",{className:"text-gray-500",children:e.count})]},e.q))}):r.jsx("div",{className:"text-sm text-gray-500",children:"No data yet"})]}),r.jsxs("div",{className:"bg-white border rounded p-4",children:[r.jsx("h3",{className:"font-semibold mb-2",children:"Recent (last 100)"}),r.jsx("div",{className:"overflow-auto",children:r.jsxs("table",{className:"min-w-full text-sm",children:[r.jsx("thead",{children:r.jsxs("tr",{className:"text-left text-gray-500",children:[r.jsx("th",{className:"p-2",children:"Time"}),r.jsx("th",{className:"p-2",children:"User"}),r.jsx("th",{className:"p-2",children:"Query"}),r.jsx("th",{className:"p-2",children:"Market"}),r.jsx("th",{className:"p-2",children:"Helpful"}),r.jsx("th",{className:"p-2",children:"Wants History"})]})}),r.jsx("tbody",{children:s.recent?.map((e,t)=>r.jsxs("tr",{className:"border-t",children:[r.jsx("td",{className:"p-2 whitespace-nowrap",children:e.ts}),r.jsx("td",{className:"p-2 whitespace-nowrap",children:e.userId??"-"}),r.jsx("td",{className:"p-2",children:e.q}),r.jsx("td",{className:"p-2",children:e.marketplace}),r.jsx("td",{className:"p-2",children:e.helpful?"Yes":"No"}),r.jsx("td",{className:"p-2",children:e.want_history?"Yes":"No"})]},t))})]})})]})]}):null}function Rs({label:e,value:t}){return r.jsxs("div",{className:"rounded-xl border border-gray-200 bg-white p-5 shadow-sm",children:[r.jsx("div",{className:"text-xs uppercase tracking-wide text-gray-400",children:e}),r.jsx("div",{className:"text-2xl font-bold mt-1",children:t??0})]})}function _s(){const t=J(),[s,a]=e.useState(null),[n,i]=e.useState(!1),[l,o]=e.useState(null);return e.useEffect(()=>{let e=!0;return(async()=>{try{i(!0);const[s,r]=await Promise.all([t.get("/api/analytics/book-feedback"),t.get("/api/analytics/feature-feedback").cat
1ch(()=>null)]);e&&(a(s?.data?.data||null),o(r?.data?.data||null))}catch(s){}finally{e&&i(!1)}})(),()=>{e=!1}},[]),n?r.jsx("div",{className:"flex justify-center items-center h-64",children:r.jsx(m,{})}):s?r.jsxs("div",{className:"space-y-6",children:[r.jsxs(_,{container:!0,spacing:2,children:[r.jsx(_,{item:!0,xs:12,md:3,children:r.jsx(L,{children:r.jsxs(F,{children:[r.jsx(y,{variant:"overline",children:"Total"}),r.jsx(y,{variant:"h4",children:s.total})]})})}),r.jsx(_,{item:!0,xs:12,md:3,children:r.jsx(L,{children:r.jsxs(F,{children:[r.jsx(y,{variant:"overline",children:"Likes"}),r.jsx(y,{variant:"h4",color:"success.main",children:s.likes})]})})}),r.jsx(_,{item:!0,xs:12,md:3,children:r.jsx(L,{children:r.jsxs(F,{children:[r.jsx(y,{variant:"overline",children:"Dislikes"}),r.jsx(y,{variant:"h4",color:"error.main",children:s.dislikes})]})})}),r.jsx(_,{item:!0,xs:12,md:3,children:r.jsx(L,{children:r.jsxs(F,{children:[r.jsx(y,{variant:"overline",children:"Severities (Dislikes)"}),r.jsx("div",{className:"space-y-1",children:Object.entries(s.bySeverity||{}).map(([e,t])=>r.jsxs("div",{className:"flex justify-between text-sm",children:[r.jsx("span",{className:"capitalize",children:e}),r.jsx("span",{children:t})]},e))})]})})})]}),r.jsxs(_,{container:!0,spacing:2,children:[r.jsx(_,{item:!0,xs:12,md:6,children:r.jsx(L,{children:r.jsxs(F,{children:[r.jsx(y,{variant:"h6",gutterBottom:!0,children:"By Type"}),r.jsx("div",{className:"space-y-2",children:Object.entries(s.byType||{}).map(([e,t])=>r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx(y,{className:"capitalize",children:e}),r.jsxs(D,{direction:"row",spacing:1,children:[r.jsx(S,{label:`Total ${t.total}`,size:"small"}),r.jsx(S,{label:`ð ${t.likes}`,color:"success",size:"small"}),r.jsx(S,{label:`ð ${t.dislikes}`,color:"error",size:"small"})]})]},e))})]})})}),r.jsx(_,{item:!0,xs:12,md:6,children:r.jsx(L,{children:r.jsxs(F,{children:[r.jsx(y,{variant:"h6",gutterBottom:!0,children:"By Page"}),r.jsx("div",{className:"space-y-2",children:Object.entries(s.byPage||{}).map(([e,t])=>r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx(y,{className:"capitalize",children:e}),r.jsxs(D,{direction:"row",spacing:1,children:[r.jsx(S,{label:`Total ${t.total}`,size:"small"}),r.jsx(S,{label:`ð ${t.likes}`,color:"success",size:"small"}),r.jsx(S,{label:`ð ${t.dislikes}`,color:"error",size:"small"})]})]},e))})]})})})]}),r.jsx(L,{children:r.jsxs(F,{children:[r.jsx(y,{variant:"h6",gutterBottom:!0,children:"Top Reasons"}),r.jsx(D,{direction:"row",spacing:1,flexWrap:"wrap",children:(s.topReasons||[]).map(e=>r.jsx(S,{label:`${e.reason} (${e.count})`},e.reason))}),r.jsx(U,{sx:{my:2}}),r.jsx(y,{variant:"h6",gutterBottom:!0,children:"Desired Outcomes"}),r.jsx(D,{direction:"row",spacing:1,flexWrap:"wrap",children:Object.entries(s.byOutcome||{}).map(([e,t])=>r.jsx(S,{label:`${e} (${t})`},e))})]})}),l&&r.jsx(L,{children:r.jsxs(F,{children:[r.jsx(y,{variant:"h6",gutterBottom:!0,children:"Voice to Book Feedback"}),(()=>{const e=l.byFeature?.["voice-to-book"]||{total:0,likes:0,dislikes:0};return r.jsxs(_,{container:!0,spacing:2,sx:{mb:1},children:[r.jsxs(_,{item:!0,xs:12,md:3,children:[r.jsx(y,{variant:"overline",children:"Total"}),r.jsx(y,{variant:"h5",children:e.total})]}),r.jsxs(_,{item:!0,xs:12,md:3,children:[r.jsx(y,{variant:"overline",children:"Likes"}),r.jsx(y,{variant:"h5",color:"success.main",children:e.likes})]}),r.jsxs(_,{item:!0,xs:12,md:3,children:[r.jsx(y,{variant:"overline",children:"Dislikes"}),r.jsx(y,{variant:"h5",color:"error.main",children:e.dislikes})]})]})})(),r.jsx(U,{sx:{my:2}}),r.jsx(y,{variant:"subtitle1",gutterBottom:!0,children:"Top Reasons (Voice to Book)"}),r.jsx(D,{direction:"row",spacing:1,flexWrap:"wrap",children:(l.topReasonsByFeature?.["voice-to-book"]||[]).map(e=>r.jsx(S,{label:`${e.reason} (${e.count})`},e.reason))})]})})]}):null}const Ls=()=>{const[t,s]=e.useState(!0),[a,u]=e.useState(null),[p,g]=e.useState("30d"),{enqueueSnackbar:j}=Y(),f=J(),b=async(e=p)=>{s(!0);try{const t=await f.get(`/api/lifetime-tracking/analytics?timeframe=${e}`);t.data.success&&u(t.data.data)}catch(t){j("Failed to load lifetime page analytics",{variant:"error"})}finally{s(!1)}};e.useEffect(()=>{b()},[]);const v=({title:e,value:t,subtitle:s,icon:a,trend:n,color:i="primary"})=>r.jsx(L,{elevation:0,sx:{border:"1px solid",borderColor:"divider",borderRadius:2,transition:"all 0.3s ease","&:hover":{boxShadow:3,transform:"translateY(-2px)",borderColor:`${i}.main`}},children:r.jsxs(F,{sx:{p:2.5},children:[r.jsxs(C,{display:"flex",justifyContent:"space-between",alignItems:"flex-start",children:[r.jsxs(C,{flex:1,children:[r.jsx(y,{variant:"caption",color:"textSecondary",sx:{textTransform:"uppercase",fontWeight:600,letterSpacing:.5},children:e}),r.jsx(y,{variant:"h4",component:"div",sx:{color:`${i}.main`,fontWeight:700,my:1},children:t}),s&&r.jsx(y,{variant:"caption",color:"textSecondary",children:s})]}),a&&r.jsx(C,{sx:{background:`linear-gradient(135deg, ${"primary"===i?"#1976d2":"success"===i?"#2e7d32":"warning"===i?"#ed6c02":"#0288d1"} 0%, ${"primary"===i?"#42a5f5":"success"===i?"#66bb6a":"warning"===i?"#ffa726":"#29b6f6"} 100%)`,borderRadius:2,p:1.25,display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 4px 12px "+("primary"===i?"rgba(25, 118, 210, 0.3)":"success"===i?"rgba(46, 125, 50, 0.3)":"warning"===i?"rgba(237, 108, 2, 0.3)":"rgba(2, 136, 209, 0.3)")},children:r.jsx(a,{sx:{color:"white",fontSize:28}})})]}),n&&r.jsxs(C,{display:"flex",alignItems:"center",mt:2,children:[n>0?r.jsx(Z,{sx:{color:"success.main",mr:.5,fontSize:18}}):r.jsx(q,{sx:{color:"error.main",mr:.5,fontSize:18}}),r.jsxs(y,{variant:"caption",color:n>0?"success.main":"error.main",fontWeight:600,children:[Math.abs(n),"% vs previous"]})]})]})});if(t&&!a)return r.jsxs(C,{display:"flex",flexDirection:"column",justifyContent:"center",alignItems:"center",minHeight:"400px",gap:2,children:[r.jsx(m,{size:60,thickness:4}),r.jsx(y,{variant:"body1",color:"textSecondary",children:"Loading analytics data..."})]});if(!a)return r.jsx(C,{textAlign:"center",p:4,children:r.jsx(y,{variant:"h6",color:"textSecondary",children:"No anal
1ytics data available"})});const{summary:N,dailyTrends:w,planStats:k,deviceStats:A,referrerStats:P,funnelStats:T,scrollStats:E,exitIntentStats:R,timeToActionStats:D,recentConversions:U}=a;return r.jsxs(C,{sx:{width:"100%",maxWidth:"100%",overflow:"hidden",bgcolor:"#f8fafc",minHeight:"100vh",pb:4,position:"relative",mx:"auto",px:{xs:0,sm:1,md:2}},children:[t&&a&&r.jsx(C,{sx:{position:"fixed",top:0,left:0,right:0,bottom:0,bgcolor:"rgba(255,255,255,0.8)",zIndex:9999,display:"flex",alignItems:"center",justifyContent:"center"},children:r.jsxs(C,{textAlign:"center",children:[r.jsx(m,{size:50}),r.jsx(y,{variant:"body2",color:"textSecondary",sx:{mt:2},children:"Refreshing data..."})]})}),r.jsx(C,{sx:{background:"linear-gradient(135deg, #667eea 0%, #764ba2 100%)",borderRadius:{xs:0,sm:2},p:{xs:2,sm:2.5,md:3},mb:{xs:2,md:3},boxShadow:"0 4px 20px rgba(102, 126, 234, 0.3)",mx:{xs:-2,sm:0}},children:r.jsxs(C,{display:"flex",justifyContent:"space-between",alignItems:"center",flexWrap:"wrap",gap:{xs:1.5,md:2},children:[r.jsxs(C,{sx:{flex:{xs:"1 1 100%",sm:"1 1 auto"}},children:[r.jsx(y,{variant:"h4",fontWeight:"bold",color:"white",sx:{mb:.5,fontSize:{xs:"1.5rem",sm:"1.75rem",md:"2rem"}},children:"ð Lifetime Page Analytics"}),r.jsx(y,{variant:"body2",sx:{color:"rgba(255,255,255,0.9)",display:{xs:"none",sm:"block"}},children:"Track user behavior and conversions in real-time"})]}),r.jsxs(C,{display:"flex",gap:1.5,flexWrap:"wrap",sx:{flex:{xs:"1 1 100%",sm:"0 1 auto"},justifyContent:{xs:"flex-start",sm:"flex-end"}},children:[r.jsx(h,{startIcon:r.jsx(I,{}),onClick:()=>b(),disabled:t,size:"small",sx:{bgcolor:"rgba(255,255,255,0.2)",color:"white",fontWeight:600,border:"1px solid rgba(255,255,255,0.3)",px:2,"&:hover":{bgcolor:"rgba(255,255,255,0.3)"},"&:disabled":{bgcolor:"rgba(255,255,255,0.1)",color:"rgba(255,255,255,0.5)"}},children:"Refresh"}),r.jsx(M,{variant:"contained",size:"small",sx:{bgcolor:"rgba(255,255,255,0.2)",borderRadius:1.5},children:["7d","30d","90d","all"].map(e=>r.jsx(h,{onClick:()=>{return g(t=e),void b(t);var t},sx:{minWidth:{xs:"55px",md:"65px"},px:{xs:1.5,md:2},fontSize:{xs:"0.75rem",md:"0.875rem"},bgcolor:p===e?"white":"transparent",color:p===e?"#667eea":"white",fontWeight:600,"&:hover":{bgcolor:p===e?"white":"rgba(255,255,255,0.1)"}},children:"all"===e?"All":e.toUpperCase()},e))})]})]})}),r.jsxs(_,{container:!0,spacing:{xs:1.5,sm:2},sx:{mb:3,px:{xs:1,sm:0}},children:[r.jsx(_,{item:!0,xs:12,sm:6,lg:3,children:r.jsx(v,{title:"Total Sessions",value:N.total_sessions?.toLocaleString()||"0",icon:B,color:"primary"})}),r.jsx(_,{item:!0,xs:12,sm:6,lg:3,children:r.jsx(v,{title:"Conversions",value:N.total_conversions?.toLocaleString()||"0",subtitle:`${N.conversion_rate}% CVR`,icon:z,color:"success"})}),r.jsx(_,{item:!0,xs:12,sm:6,lg:3,children:r.jsx(v,{title:"Total Revenue",value:`$${parseFloat(N.total_revenue||0).toLocaleString()}`,subtitle:`$${N.avg_order_value} avg`,icon:$,color:"warning"})}),r.jsx(_,{item:!0,xs:12,sm:6,lg:3,children:r.jsx(v,{title:"Avg Time",value:`${Math.round(N.avg_time_on_page||0)}s`,subtitle:`${Math.round(N.avg_scroll_depth||0)}% scroll`,icon:V,color:"info"})})]}),r.jsxs(i,{elevation:0,sx:{p:{xs:2,md:3},mb:{xs:2,md:3},mx:{xs:1,sm:0},border:"1px solid",borderColor:"divider",borderRadius:2,bgcolor:"white"},children:[r.jsxs(C,{display:"flex",alignItems:"center",mb:2,gap:1,children:[r.jsx(C,{sx:{bgcolor:"primary.light",borderRadius:1.5,p:1,display:"flex",alignItems:"center"},children:r.jsx(y,{sx:{fontSize:24},children:"ð¯"})}),r.jsx(y,{variant:"h6",fontWeight:"bold",children:"Conversion Funnel"})]}),r.jsx(C,{sx:{mt:2},children:[{label:"Page Sessions",value:N.total_sessions,gradient:"linear-gradient(90deg, #667eea 0%, #764ba2 100%)",percent:100,icon:"ð"},{label:"Checkout Initiated",value:N.checkout_initiations,gradient:"linear-gradient(90deg, #ffa726 0%, #fb8c00 100%)",percent:(N.checkout_initiations/N.total_sessions*100).toFixed(1),icon:"ð"},{label:"Conversions",value:N.total_conversions,gradient:"linear-gradient(90deg, #66bb6a 0%, #43a047 100%)",percent:N.conversion_rate,icon:"ð°"}].map((e,t)=>r.jsxs(C,{sx:{mb:2.5,position:"relative"},children:[r.jsxs(C,{display:"flex",justifyContent:"space-between",mb:1,flexWrap:"wrap",gap:1,children:[r.jsxs(C,{display:"flex",alignItems:"center",gap:1,children:[r.jsx(y,{sx:{fontSize:20},children:e.icon}),r.jsx(y,{variant:"body1",fontWeight:600,children:e.label})]}),r.jsxs(C,{display:"flex",alignItems:"center",gap:1,children:[r.jsx(y,{variant:"h6",fontWeight:"bold",color:"primary",children:e.value?.toLocaleStr
1ing()||0}),r.jsx(S,{label:`${e.percent}%`,size:"small",sx:{fontWeight:700,background:e.gradient,color:"white"}})]})]}),r.jsx(O,{variant:"determinate",value:parseFloat(e.percent),sx:{height:12,borderRadius:6,backgroundColor:"grey.200","& .MuiLinearProgress-bar":{borderRadius:6,background:e.gradient,boxShadow:"0 2px 8px "+(e.gradient.includes("667eea")?"rgba(102, 126, 234, 0.4)":e.gradient.includes("66bb6a")?"rgba(102, 187, 106, 0.4)":"rgba(255, 167, 38, 0.4)")}}}),t<2&&r.jsx(C,{sx:{textAlign:"center",my:1},children:r.jsx(y,{sx:{fontSize:24,color:"grey.400"},children:"â"})})]},t))})]}),r.jsxs(i,{elevation:0,sx:{p:{xs:2,md:3},mb:{xs:2,md:3},mx:{xs:1,sm:0},overflow:"hidden",border:"1px solid",borderColor:"divider",borderRadius:2,bgcolor:"white"},children:[r.jsxs(C,{display:"flex",alignItems:"center",mb:2,gap:1,children:[r.jsx(C,{sx:{bgcolor:"warning.light",borderRadius:1.5,p:1,display:"flex",alignItems:"center"},children:r.jsx(y,{sx:{fontSize:24},children:"ð°"})}),r.jsx(y,{variant:"h6",fontWeight:"bold",children:"Plan Performance"})]}),k&&k.length>0?r.jsx(n,{sx:{maxWidth:"100%"},children:r.jsxs(l,{size:"small",children:[r.jsx(o,{children:r.jsxs(c,{sx:{bgcolor:"grey.50"},children:[r.jsx(d,{sx:{fontWeight:700},children:"Plan"}),r.jsx(d,{align:"right",sx:{fontWeight:700},children:"Conv"}),r.jsx(d,{align:"right",sx:{fontWeight:700},children:"Revenue"}),r.jsx(d,{align:"right",sx:{display:{xs:"none",md:"table-cell"},fontWeight:700},children:"Avg $"}),r.jsx(d,{align:"right",sx:{display:{xs:"none",lg:"table-cell"},fontWeight:700},children:"Avg Time"}),r.jsx(d,{align:"right",sx:{display:{xs:"none",lg:"table-cell"},fontWeight:700},children:"Bumps"})]})}),r.jsx(x,{children:k.map(e=>r.jsxs(c,{sx:{"&:hover":{bgcolor:"grey.50"}},children:[r.jsx(d,{children:r.jsx(S,{label:e.plan_name.toUpperCase(),color:"elite"===e.plan_name?"primary":"default",size:"small",sx:{fontWeight:600}})}),r.jsx(d,{align:"right",sx:{fontWeight:600},children:e.conversions}),r.jsxs(d,{align:"right",sx:{color:"success.main",fontWeight:700},children:["$",parseFloat(e.revenue).toLocaleString()]}),r.jsxs(d,{align:"right",sx:{display:{xs:"none",md:"table-cell"}},children:["$",parseFloat(e.avg_amount).toFixed(0)]}),r.jsxs(d,{align:"right",sx:{display:{xs:"none",lg:"table-cell"}},children:[Math.round(e.avg_time_to_purchase),"s"]}),r.jsx(d,{align:"right",sx:{display:{xs:"none",lg:"table-cell"}},children:e.order_bumps_accepted})]},e.plan_name))})]})}):r.jsx(C,{textAlign:"center",py:4,children:r.jsx(y,{variant:"body2",color:"textSecondary",children:"No conversion data yet. Start tracking when users make purchases!"})})]}),r.jsxs(_,{container:!0,spacing:{xs:1.5,sm:2},sx:{mb:3,px:{xs:1,sm:0}},children:[r.jsx(_,{item:!0,xs:12,lg:6,children:r.jsxs(i,{elevation:0,sx:{p:{xs:2,md:3},height:"100%",border:"1px solid",borderColor:"divider",borderRadius:2,bgcolor:"white"},children:[r.jsxs(C,{display:"flex",alignItems:"center",mb:2,gap:1,children:[r.jsx(C,{sx:{bgcolor:"primary.light",borderRadius:1.5,p:1,display:"flex",alignItems:"center"},children:r.jsx(W,{sx:{color:"primary.main",fontSize:20}})}),r.jsx(y,{variant:"h6",fontWeight:"bold",sx:{fontSize:{xs:"1rem",md:"1.25rem"}},children:"Device Types"})]}),A&&A.length>0?A.map(e=>r.jsxs(C,{sx:{mb:2.5},children:[r.jsxs(C,{display:"flex",justifyContent:"space-between",mb:1,flexWrap:"wrap",gap:1,children:[r.jsx(y,{variant:"body2",fontWeight:600,sx:{fontSize:{xs:"0.875rem",md:"1rem"}},children:"mobile"===e.device_type?"ð± Mobile":"desktop"===e.device_type?"ð» Desktop":"ð± Tablet"}),r.jsxs(y,{variant:"body2",color:"textSecondary",sx:{fontSize:{xs:"0.75rem",md:"0.875rem"}},children:[e.sessions," sessions ⢠",parseFloat(e.conversion_rate||0).toFixed(1),"% CVR"]})]}),r.jsx(O,{variant:"determinate",value:Math.min(e.sessions/N.total_sessions*100,100),sx:{height:8,borderRadius:4,bgcolor:"grey.200","& .MuiLinearProgress-bar":{borderRadius:4,background:"mobile"===e.device_type?"linear-gradient(90deg, #667eea 0%, #764ba2 100%)":"linear-gradient(90deg, #f093fb 0%, #f5576c 100%)"}}})]},e.device_type)):r.jsx(C,{textAlign:"center",py:3,children:r.jsx(y,{variant:"body2",color:"textSecondary",children:"No device data yet"})})]})}),r.jsx(_,{item:!0,xs:12,lg:6,children:r.jsxs(i,{elevation:0,sx:{p:{xs:2,md:3},height:"100%",border:"1px solid",borderColor:"divider",borderRadius:2,bgcolor:"white"},children:[r.jsxs(C,{display:"flex",alignItems:"center",mb:2,gap:1,children:[r.jsx(C,{sx:{bgcolor:"secondary.light",borderRadius:1.5,p:1,display:"flex",alignItems:"center"},children:r.jsx(H,{sx:{color:"secondary.main",fontSize:20}})}),r.jsx(y,{variant:"h6",fontWeight:"bold",sx:{fontSize:{xs:"1rem",md:"1.25rem"}},children:"Traffic Sources"})]}),P&&P.length>0?P.map((e,t)=>r.jsxs(C,{sx:{mb:2.5},children:[r.jsxs(C,{display:"flex",justifyContent:"space-between",mb:1,flexWrap:"wrap",gap:1,children:[r.jsx(y,{variant:"body2",fontWeight:600,sx:{fontSize:{xs:"0.875rem",md:"1rem"}},children:e.referrer_group}),r.jsxs(y,{variant:"body2",color:"textSecondary",sx:{fontSize:{xs:"0.75rem",md:"0.875rem"}},children:[e.sessions," sessions ⢠",e.conversions," conv"]})]}),r.jsx(O,{variant:"determinate",value:Math.min(e.sessions/N.total_sessions*100,100),sx:{height:8,borderRadius:4,bgcolor:"grey.200","& .MuiLinearProgress-bar":{borderRadius:4,background:`linear-gradient(90deg, ${["#4facfe","#00f2fe","#43e97b","#38f9d7","#fa709a"][t%5]} 0%, ${["#00f2fe","#43e97b","#38f9d7","#fa709a","#fee140"][t%5]} 100%)`}}})]},e.referrer_group)):r.jsx(C,{textAlign:"center",py:3,children:r.jsx(y,{variant:"body2",color:"textSecondary",children:"No traffic source data yet"})})]})})]}),r.jsxs(i,{elevation:0,sx:{p:{xs:2,md:3},mb:{xs:2,md:3},mx:{xs:1,sm:0},border:"1px solid",borderColor:"divider",borderRadius:2,bgcolor:"white"},children:[r.jsxs(C,{display:"flex",alignItems:"center",mb:2,gap:1,children:[r.jsx(C,{sx:{bgcolor:"info.light",borderRadius:1.5,p:1,display:"flex",alignItems:"center"},children:r.jsx(K,{sx:{color:"info.main",fontSize:20}})}),r.jsx(y,{variant:"h6",fontWeight:"bold",sx:{fontSize:{xs:"1rem",md:"1.25rem"}},children:"Scroll Behavior"})]}),r.jsx(_,{container:!0,spacing:2,children:E&&[{label:"25%",value:E.scrolled_25,icon:"ð",color:"#e3f2fd"},{label:"50%",value:E.scrolled_50,icon:"ð",color:"#bbdefb"},{label:"75%",value:E.scrolled_75,icon:"ð",color:"#90caf9"},{label:"90%+",value:E.scrolled_90,icon:"ð¯",color:"#64b5f6"},{label:"Pricing",value:E.reached_pricing,icon:"ð°",color:"#fff3e0"},{label:"Testimonials",value:E.reached_testimonials,icon:"â",color:"#e8f5e9"},{label:"FAQ",value:E.reached_faq,icon:"â",color:"#f3e5f5"},{label:"Bottom",value:E.reached_bottom,icon:"â¬ï¸",color:"#fce4ec"}].map(e=>r.jsx(_,{item:!0,xs:6,sm:4,md:3,children:r.jsxs(C,{sx:{textAlign:"center",p:2,bgcolor:e.color,borderRadius:2,border:"1px solid",borderColor:"divider",transition:"all 0.3s ease","&:hover":{transform:"scale(1.05)",boxShadow:2}},children:[r.jsx(y,{sx:{fontSize:32,mb:.5},children:e.icon}),r.jsx(y,{variant:"h4",fontWeight:"bold",color:"primary",sx:{mb:.5},children:e.value||0}),r.jsx(y,{variant:"caption",color:"textSecondary",fontWeight:600,sx:{textTransform:"uppercase",letterSpacing:.5},children:e.label})]})},e.label))})]}),r.jsxs(i,{elevation:0,sx:{p:{xs:2,md:3},mx:{xs:1,sm:0},overflow:"hidden",border:"1px solid",borderColor:"divider",borderRadius:2,bgcolor:"white"},children:[r.jsxs(C,{display:"flex",alignItems:"center",mb:2,gap:1,children:[r.jsx(C,{sx:{bgcolor:"success.light",borderRadius:1.5,p:1,display:"flex",alignItems:"center"},children:r.jsx(y,{sx:{fontSize:24},children:"ð"})}
1),r.jsx(y,{variant:"h6",fontWeight:"bold",children:"Recent Conversions"})]}),U&&U.length>0?r.jsx(n,{sx:{maxWidth:"100%"},children:r.jsxs(l,{size:"small",children:[r.jsx(o,{children:r.jsxs(c,{sx:{bgcolor:"grey.50"},children:[r.jsx(d,{sx:{fontWeight:700},children:"Date"}),r.jsx(d,{sx:{fontWeight:700},children:"Plan"}),r.jsx(d,{align:"right",sx:{fontWeight:700},children:"Amount"}),r.jsx(d,{sx:{display:{xs:"none",sm:"table-cell"},fontWeight:700},children:"Payment"}),r.jsx(d,{align:"right",sx:{display:{xs:"none",md:"table-cell"},fontWeight:700},children:"Time"}),r.jsx(d,{align:"right",sx:{display:{xs:"none",lg:"table-cell"},fontWeight:700},children:"Scroll"})]})}),r.jsx(x,{children:U.slice(0,10).map((e,t)=>r.jsxs(c,{sx:{"&:hover":{bgcolor:"grey.50"}},children:[r.jsx(d,{sx:{fontSize:{xs:"0.75rem",md:"0.875rem"}},children:new Date(e.created_at).toLocaleDateString("en-US",{month:"short",day:"numeric"})}),r.jsx(d,{children:r.jsx(S,{label:e.plan_name.toUpperCase(),size:"small",color:"elite"===e.plan_name?"primary":"default",sx:{fontSize:"0.7rem",height:"22px",fontWeight:600}})}),r.jsx(d,{align:"right",children:r.jsxs(y,{fontWeight:700,color:"success.main",sx:{fontSize:"0.875rem"},children:["$",parseFloat(e.amount).toFixed(0)]})}),r.jsx(d,{sx:{display:{xs:"none",sm:"table-cell"},fontSize:"1.2rem"},children:"stripe"===e.payment_method?"ð³":"ð°"}),r.jsxs(d,{align:"right",sx:{display:{xs:"none",md:"table-cell"},fontSize:"0.875rem"},children:[Math.round(e.time_on_page||0),"s"]}),r.jsxs(d,{align:"right",sx:{display:{xs:"none",lg:"table-cell"},fontSize:"0.875rem"},children:[Math.round(e.scroll_depth||0),"%"]})]},t))})]})}):r.jsxs(C,{textAlign:"center",py:6,children:[r.jsx(y,{sx:{fontSize:48,mb:2},children:"ð"}),r.jsx(y,{variant:"h6",color:"textSecondary",gutterBottom:!0,children:"No Conversions Yet"}),r.jsx(y,{variant:"body2",color:"textSecondary",children:"Conversions will appear here once users complete purchases"})]})]})]})},Fs={US:"ðºð¸",GB:"ð¬ð§",CA:"ð¨ð¦",AU:"ð¦ðº",DE:"ð©ðª",FR:"ð«ð·",IT:"ð®ð¹",ES:"ðªð¸",NL:"ð³ð±",BE:"ð§ðª",AT:"ð¦ð¹",CH:"ð¨ð",SE:"ð¸ðª",NO:"ð³ð´",DK:"ð©ð°",FI:"ð«ð®",PL:"ðµð±",CZ:"ð¨ð¿",PT:"ðµð¹",IE:"ð®ðª",NZ:"ð³ð¿",SG:"ð¸ð¬",HK:"ðð°",JP:"ð¯ðµ",KR:"ð°ð·",IN:"ð®ð³",BR:"ð§ð·",MX:"ð²ð½",AR:"ð¦ð·",CO:"ð¨ð´",CL:"ð¨ð±",ZA:"ð¿ð¦",AE:"ð¦ðª",SA:"ð¸ð¦",IL:"ð®ð±",TR:"ð¹ð·",RU:"ð·ðº",UA:"ðºð¦",PH:"ðµð",TH:"ð¹ð",MY:"ð²ð¾",ID:"ð®ð©",VN:"ð»ð³",PK:"ðµð°",BD:"ð§ð©",NG:"ð³ð¬",EG:"ðªð¬",KE:"ð°ðª",GH:"ð¬ð",TW:"ð¹ð¼",RO:"ð·ð´",HU:"ððº",GR:"ð¬ð·",BG:"ð§ð¬",HR:"ðð·",SK:"ð¸ð°",SI:"ð¸ð®",RS:"ð·ð¸",LT:"ð±ð¹",LV:"ð±ð»",EE:"ðªðª",IS:"ð®ð¸",LU:"ð±ðº",MT:"ð²ð¹",CY:"ð¨ð¾"},Ds=["#0088FE","#00C49F","#FFBB28","#FF8042","#8884d8","#82ca9d","#ffc658","#ff7300","#a4de6c","#d0ed57"],Us=()=>{const[t,s]=e.useState(!0),[a,h]=e.useState(null),[u,p]=e.useState(""),[g,j]=e.useState(null),{enqueueSnackbar:f}=Y(),b=J();e.useEffect(()=>{y()},[]);const y=async()=>{s(!0),j(null);try{const e=await b.get("/api/analytics/country-stats");e.data.success?h(e.data.data):j(e.data.msg||"Failed to load country statistics")}catch(e){const t=e.response?.data?.msg||"Failed to load country statistics";j(t),f(t,{variant:"error"})}finally{s(!1)}};if(t)return r.jsx("div",{className:"flex justify-center items-center h-64",children:r.jsx(m,{})});if(g)return r.jsxs(i,{className:"p-8 text-center",children:[r.jsx("p",{className:"text-gray-500 mb-4",children:"ð Country Statistics Unavailable"}),r.jsx("p",{className:"text-sm text-gray-400",children:g}),r.jsx("p",{className:"text-xs text-gray-400 mt-2",children:"The geoip-lite module needs to be installed on the server."})]});if(!a)return r.jsx("p",{className:"text-gray-500",children:"No country data available"});const v=a.countries.filter(e=>e.countryName.toLowerCase().includes(u.toLowerCase())||e.countryCode.toLowerCase().includes(u.toLowerCase())),N=a.topCountries.map((e,t)=>({name:`${Fs[e.countryCode]||"ð³ï¸"} ${e.countryCode}`,fullName:e.countryName,total:e.totalUsers,paid:e.paidUsers,free:e.freeUsers,conversionRate:parseFloat(e.conversionRate)})),S=a.topCountries.slice(0,8).map((e,t)=>({name:e.countryName,value:e.paidUsers,color:Ds[t%Ds.length]})).filter(e=>e.value>0),A=({active:e,payload:t})=>{if(e&&t&&t.length){const e=t[0].payload;return r.jsxs("div",{className:"bg-white p-3 border border-gray-200 shadow-md rounded",children:[r.jsx("p",{className:"font-semibold",children:e.fullName||e.name}),r.jsxs("p",{className:"text-blue-600",children:["Total: ",e.total?.toLocaleStr
1ing()||e.value?.toLocaleString()]}),void 0!==e.paid&&r.jsxs("p",{className:"text-green-600",children:["Paid: ",e.paid?.toLocaleString()]}),void 0!==e.conversionRate&&r.jsxs("p",{className:"text-purple-600",children:["Conversion: ",e.conversionRate,"%"]})]})}return null};return r.jsxs("div",{children:[r.jsx("h2",{className:"text-2xl font-bold mb-4",children:"ð Country Statistics"}),r.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4 mb-6",children:[r.jsxs(i,{className:"p-4 text-center",children:[r.jsx("p",{className:"text-sm text-gray-500",children:"Total Countries"}),r.jsx("p",{className:"text-3xl font-bold text-blue-600",children:a.summary.totalCountries})]}),r.jsxs(i,{className:"p-4 text-center",children:[r.jsx("p",{className:"text-sm text-gray-500",children:"Users with Location"}),r.jsx("p",{className:"text-3xl font-bold text-green-600",children:a.summary.totalUsersWithCountry.toLocaleString()})]}),r.jsxs(i,{className:"p-4 text-center",children:[r.jsx("p",{className:"text-sm text-gray-500",children:"Paid Users"}),r.jsx("p",{className:"text-3xl font-bold text-purple-600",children:a.summary.totalPaidWithCountry.toLocaleString()})]}),r.jsxs(i,{className:"p-4 text-center",children:[r.jsx("p",{className:"text-sm text-gray-500",children:"Overall Conversion"}),r.jsxs("p",{className:"text-3xl font-bold text-orange-600",children:[a.summary.overallConversionRate,"%"]})]})]}),r.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6 mb-6",children:[r.jsxs(i,{className:"p-4",children:[r.jsx("h3",{className:"text-lg font-semibold mb-4",children:"Top 10 Countries by Users"}),r.jsx("div",{className:"h-80",children:r.jsx(Ie,{width:"100%",height:"100%",children:r.jsxs(vs,{data:N,margin:{top:20,right:30,left:20,bottom:70},children:[r.jsx(Me,{strokeDasharray:"3 3"}),r.jsx(Le,{dataKey:"name",angle:-45,textAnchor:"end",height:70,interval:0,fontSize:12}),r.jsx(Fe,{}),r.jsx(Be,{content:r.jsx(A,{})}),r.jsx(ze,{}),r.jsx(_e,{dataKey:"total",name:"Total Users",fill:"#8884d8"}),r.jsx(_e,{dataKey:"paid",name:"Paid Users",fill:"#82ca9d"})]})})})]}),r.jsxs(i,{className:"p-4",children:[r.jsx("h3",{className:"text-lg font-semibold mb-4",children:"Paid Users Distribution (Top 8)"}),r.jsx("div",{className:"h-80",children:r.jsx(Ie,{width:"100%",height:"100%",children:r.jsxs(Ns,{children:[r.jsx(ns,{data:S,cx:"50%",cy:"50%",labelLine:!1,label:({name:e,percent:t})=>`${e} (${(100*t).toFixed(0)}%)`,outerRadius:100,fill:"#8884d8",dataKey:"value",children:S.map((e,t)=>r.jsx(Ce,{fill:e.color},`cell-${t}`))}),r.jsx(Be,{})]})})})]})]}),r.jsxs(i,{className:"p-4 mb-6",children:[r.jsx("h3",{className:"text-lg font-semibold mb-4",children:"Conversion Rate by Country (Top 10)"}),r.jsx("div",{className:"h-64",children:r.jsx(Ie,{width:"100%",height:"100%",children:r.jsxs(vs,{data:N,margin:{top:20,right:30,left:20,bottom:70},children:[r.jsx(Me,{strokeDasharray:"3 3"}),r.jsx(Le,{dataKey:"name",angle:-45,textAnchor:"end",height:70,interval:0,fontSize:12}),r.jsx(Fe,{unit:"%"}),r.jsx(Be,{formatter:e=>`${e}%`}),r.jsx(_e,{dataKey:"conversionRate",name:"Conversion Rate",fill:"#FF8042"})]})})})]}),r.jsxs(i,{className:"p-4",children:[r.jsxs("div",{className:"flex justify-between items-center mb-4",children:[r.jsx("h3",{className:"text-lg font-semibold",children:"All Countries"}),r.jsx(w,{size:"small",placeholder:"Search countries...",value:u,onChange:e=>p(e.target.value),InputProps:{startAdornment:r.jsx(k,{position:"start",children:r.jsx(Ye,{})})}})]}),r.jsx(n,{style:{maxHeight:500},children:r.jsxs(l,{stickyHeader:!0,size:"small",children:[r.jsx(o,{children:r.jsxs(c,{children:[r.jsx(d,{children:r.jsx("strong",{children:"Country"})}),r.jsx(d,{align:"right",children:r.jsx("strong",{children:"Total Users"})}),r.jsx(d,{align:"right",children:r.jsx("strong",{children:"Paid Users"})}),r.jsx(d,{align:"right",children:r.jsx("strong",{children:"Free Users"})}),r.jsx(d,{align:"right",children:r.jsx("strong",{children:"Conversion Rate"})})]})}),r.jsxs(x,{children:[v.map((e,t)=>r.jsxs(c,{sx:{backgroundColor:t%2==0?"#f9fafb":"white","&:hover":{backgroundColor:"#f0f9ff"}},children:[r.jsxs(d,{children:[r.jsx("span",{className:"mr-2",children:Fs[e.countryCode]||"ð³ï¸"}),e.countryName,r.jsxs("span",{className:"text-gray-400 ml-2 text-xs",children:["(",e.countryCode,")"]})]}
1),r.jsx(d,{align:"right",children:e.totalUsers.toLocaleString()}),r.jsx(d,{align:"right",children:r.jsx("span",{className:"text-green-600 font-medium",children:e.paidUsers.toLocaleString()})}),r.jsx(d,{align:"right",children:e.freeUsers.toLocaleString()}),r.jsx(d,{align:"right",children:r.jsxs("span",{className:"font-medium "+(parseFloat(e.conversionRate)>5?"text-green-600":parseFloat(e.conversionRate)>2?"text-blue-600":"text-gray-600"),children:[e.conversionRate,"%"]})})]},e.countryCode)),0===v.length&&r.jsx(c,{children:r.jsxs(d,{colSpan:5,align:"center",className:"py-8 text-gray-500",children:['No countries found matching "',u,'"']})})]})]})}),r.jsxs("div",{className:"mt-4 text-sm text-gray-500",children:["Showing ",v.length," of ",a.countries.length," countries",a.summary.unknownCountry>0&&r.jsxs("span",{className:"ml-4",children:["(",a.summary.unknownCountry.toLocaleString()," users with unknown location)"]})]})]})]})},Is=()=>{const t=J(),[s,a]=e.useState(!1),[n,i]=e.useState(null),[l,o]=e.useState((new Date).toISOString().split("T")[0]),[c,d]=e.useState(""),[x,h]=e.useState(""),[m,u]=e.useState(null),[p,g]=e.useState("overview"),[j,f]=e.useState({field:"total",direction:"desc"}),[b,y]=e.useState(!1),N=async(e={})=>{a(!0);try{let s="/api/today-users-with-referrers";const a=new URLSearchParams;e.startDate&&e.endDate?(a.append("startDate",e.startDate),a.append("endDate",e.endDate)):e.date&&a.append("date",e.date),a.toString()&&(s+=`?${a.toString()}`);const r=await t.get(s);r.data?.success&&r.data?.data&&i(r.data.data)}catch(s){}finally{a(!1)}};e.useEffect(()=>{N({date:l})},[]);const w=e=>{o(e),u(null),N({date:e})},k=e=>{const t=new Date,s=new Date;s.setDate(s.getDate()-e);const a=s.toISOString().split("T")[0],r=t.toISOString().split("T")[0];d(a),h(r),u(null),N({startDate:a,endDate:r})};return s&&!n?r.jsx("div",{className:"flex justify-center items-center py-12",children:r.jsx(X,{size:"lg"})}):r.jsxs("div",{className:"bg-white rounded-xl shadow-lg p-6",children:[r.jsxs("div",{className:"mb-4",children:[r.jsxs("h2",{className:"text-xl sm:text-2xl font-bold text-gray-800",children:["ð Traffic Analytics ",n?.isRange?`(${n.rangeStart} to ${n.rangeEnd})`:n?.isToday?"(Today)":`(${l})`]}),n&&r.jsxs("div",{className:"flex flex-wrap gap-4 mt-2",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-2xl font-bold text-gray-800",children:n.totalToday}),r.jsx("span",{className:"text-sm text-gray-500",children:"Total Sign-ups"})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-2xl font-bold text-green-600",children:n.totalPaid}),r.jsx("span",{className:"text-sm text-gray-500",children:"Paid"})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("span",{className:"text-2xl font-bold text-blue-600",children:[n.overallConversionRate,"%"]}),r.jsx("span",{className:"text-sm text-gray-500",children:"Conversion Rate"})]})]})]}),r.jsxs("div",{className:"mb-4 p-4 bg-gray-50 rounded-lg",children:[r.jsxs("div",{className:"flex flex-wrap items-center gap-3 mb-3",children:[r.jsx("label",{className:"text-sm font-medium text-gray-700",children:"Single Date:"}),r.jsx("input",{type:"date",value:l,onChange:e=>w(e.target.value),max:(new Date).toISOString().split("T")[0],className:"px-3 py-1.5 border border-gray-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"}),r.jsx("button",{onClick:()=>w((new Date).toISOString().split("T")[0]),className:"px-3 py-1.5 text-sm rounded-lg transition-colors "+(n?.isToday&&!n?.isRange?"bg-green-500 text-white":"bg-gray-200 text-gray-700 hover:bg-gray-300"),children:"Today"}),r.jsx("button",{onClick:()=>{const e=new Date;e.setDate(e.getDate()-1),w(e.toISOString().split("T")[0])},className:"px-3 py-1.5 text-sm bg-gray-200 text-gray-700 rounded-lg hover:bg-gray-300 transition-colors",children:"Yesterday"})]}),r.jsxs("div",{className:"flex flex-wrap items-center gap-3 pt-3 border-t border-gray-200",children:[r.jsx("label",{className:"text-sm font-medium text-gray-700",children:"Date Range:"}),r.jsx("input",{type:"date",value:c,onChange:e=>d(e.target.value),max:(new Date).toISOString().split("T")[0],className:"px-3 py-1.5 border border-gray-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"Start"}),r.jsx("span",{className:"text-gray-400",children:"to"}),r.jsx("input",{type:"date",value:x,onChange:e=>h(e.target.value),max:(new Date).toISOString().split("T")[0],className:"px-3 py-1.5 border border-gray-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"End"}),r.jsx("button",{onClick:()=>{c&&x&&(u(null),N({startDate:c,endDate:x}))},disabled:!c||!x,className:"px-3 py-1.5 text-sm bg-blue-500 text-white rounded-lg hover:bg-blue-600 disabled:bg-gray-300 disabled:cursor-not-allowed transition-colors",children:"Apply Range"}),r.jsxs("div",{className:"flex gap-2 ml-2",children:[r.jsx("button",{onClick:()=>k(7),className:"px-3 py-1.5 text-sm rounded-lg transition-colors "+(n?.isRange?"bg-indigo-100 text-indigo-700 hover:bg-indigo-200":"bg-gray-200 text-gray-700 hover:bg-gray-300"),children:"Last 7 Days"}),r.jsx("button",{onClick:()=>k(30),className:"px-3 py-1.5 text-sm bg-gray-200 text-gray-700 rounded-lg hover:bg-gray-300 transition-colors",children:"Last 30 Days"}),r.jsx("button",{onClick:()=>k(90),className:"px-3 py-1.5 text-sm bg-gray-200 text-gray-700 rounded-lg hover:bg-gray-300 transition-colors",children:"Last 90 Days"})]})]})]}),s&&r.jsx("div",{className:"flex justify-center items-center py-4",children:r.jsx(X,{size:"md"})}),n&&!s&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex border-b border-gray-200 mb-4",children:[r.jsx("button",{onClick:()=>g("overview"),className:"px-4 py-2 text-sm font-medium border-b-2 transition-colors "+("overview"===p?"border-blue-500 text-blue-600":"border-transparent text-gray-500 hover:text-gray-700"),children:"ð Overview"}),r.jsx("button",{onClick:()=>
1g("campaigns"),className:"px-4 py-2 text-sm font-medium border-b-2 transition-colors "+("campaigns"===p?"border-blue-500 text-blue-600":"border-transparent text-gray-500 hover:text-gray-700"),children:"ð¯ Campaign Performance"}),r.jsx("button",{onClick:()=>g("conversions"),className:"px-4 py-2 text-sm font-medium border-b-2 transition-colors "+("conversions"===p?"border-blue-500 text-blue-600":"border-transparent text-gray-500 hover:text-gray-700"),children:"ð° Conversion Rates"})]}),"overview"===p&&r.jsxs(r.Fragment,{children:[n.metaTotals?.total>0&&r.jsxs("div",{className:"mb-4 bg-gradient-to-r from-blue-500 to-purple-500 rounded-xl text-white shadow-lg overflow-hidden",children:[r.jsx("div",{className:"p-4 cursor-pointer hover:bg-white/10 transition-colors",onClick:()=>y(!b),children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("h3",{className:"text-lg font-bold flex items-center gap-2",children:["ð± META Ads (Facebook + Instagram)",r.jsx("span",{className:"bg-white text-blue-600 px-3 py-1 rounded-full text-lg font-bold",children:n.metaTotals.total})]}),r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsxs("div",{className:"flex gap-4 text-sm",children:[r.jsxs("span",{className:"bg-white/20 px-2 py-1 rounded",children:["FB: ",r.jsx("strong",{children:n.metaTotals.facebook})]}),r.jsxs("span",{className:"bg-white/20 px-2 py-1 rounded",children:["IG: ",r.jsx("strong",{children:n.metaTotals.instagram})]})]}),r.jsx("span",{className:"text-2xl transition-transform duration-200",style:{transform:b?"rotate(180deg)":"rotate(0deg)"},children:"â¼"})]})]})}),b&&r.jsxs("div",{className:"px-4 pb-4 border-t border-white/20",children:[r.jsxs("div",{className:"grid grid-cols-2 gap-4 my-4",children:[r.jsxs("div",{className:"bg-white/20 rounded-lg p-4",children:[r.jsx("p",{className:"text-sm opacity-90",children:"Facebook"}),r.jsx("p",{className:"text-3xl font-bold",children:n.metaTotals.facebook}),r.jsxs("p",{className:"text-xs opacity-70 mt-1",children:[n.metaTotals.facebookUsers?.filter(e=>"Free"!==e.type).length||0," paid"]})]}),r.jsxs("div",{className:"bg-white/20 rounded-lg p-4",children:[r.jsx("p",{className:"text-sm opacity-90",children:"Instagram"}),r.jsx("p",{className:"text-3xl font-bold",children:n.metaTotals.instagram}),r.jsxs("p",{className:"text-xs opacity-70 mt-1",children:[n.metaTotals.instagramUsers?.filter(e=>"Free"!==e.type).length||0," paid"]})]})]}),n.metaTotals.byCampaign&&Object.keys(n.metaTotals.byCampaign).length>0&&r.jsxs("div",{className:"border-t border-white/30 pt-4",children:[r.jsxs("p",{className:"text-sm opacity-90 mb-3 font-semibold",children:["ð Campaigns Breakdown (",Object.keys(n.metaTotals.byCampaign).length," campaigns)"]}),r.jsx("div",{className:"space-y-2 max-h-[400px] overflow-y-auto",children:Object.entries(n.metaTotals.byCampaign).map(([e,t])=>r.jsxs("div",{className:"bg-white/10 rounded-lg p-3",children:[r.jsxs("div",{className:"flex justify-between items-center mb-2",children:[r.jsx("span",{className:"text-sm font-medium truncate flex-1 mr-2",title:e,children:e}),r.jsxs("div",{className:"flex gap-2",children:[r.jsxs("span",{className:"bg-white text-blue-600 px-2 py-0.5 rounded text-xs font-bold",children:[t.count," signups"]}),r.jsxs("span",{className:"bg-green-400 text-green-900 px-2 py-0.5 rounded text-xs font-bold",children:[t.paidCount," paid"]})]})]}),r.jsx("div",{className:"mt-2 text-xs space-y-1 max-h-32 overflow-y-auto bg-white/5 rounded p-2",children:t.users?.map((e,t)=>r.jsxs("div",{className:"flex justify-between items-center py-1 border-b border-white/10 last:border-0",children:[r.jsx("span",{className:"truncate flex-1",children:e.email}),r.jsx("span",{className:"text-[10px] opacity-70 mx-2",children:new Date(e.createdAt).toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit"})}),r.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] "+("Free"===e.type?"bg-gray-200 text-gray-700":"bg-green-200 text-green-800"),children:e.type})]},t))})]},e))})]}),r.jsxs("div",{className:"border-t border-white/30 pt-4 mt-4",children:[r.jsxs("p",{className:"text-sm opacity-90 mb-3 font-semibold",children:["ð¥ All META Users (",n.metaTotals.total,")"]}),r.jsx("div",{className:"bg-white/10 rounded-lg overflow-hidden",children:r.jsxs("table",{className:"w-full text-xs",children:[r.jsx("thead",{className:"bg-white/20",children:r.jsxs("tr",{children:[r.jsx("th",{className:"text-left p-2",children:"Email"}),r.jsx("th",{className:"text-left p-2",children:"Platform"}),r.jsx("th",{className:"text-left p-2",children:"Campaign"}),r.jsx("th",{className:"text-left p-2",children:"Type"}),r.jsx("th",{className:"text-left p-2",children:"Time"})]})}),r.jsx("tbody",{className:"max-h-48 overflow-y-auto",children:[...n.metaTotals.facebookUsers||[],...n.metaTotals.instagramUsers||[]].sort((e,t)=>
1new Date(t.createdAt)-new Date(e.createdAt)).map((e,t)=>r.jsxs("tr",{className:"border-t border-white/10 hover:bg-white/10",children:[r.jsx("td",{className:"p-2 truncate max-w-[200px]",children:e.email}),r.jsx("td",{className:"p-2",children:r.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] "+(n.metaTotals.facebookUsers?.some(t=>t.id===e.id)?"bg-blue-200 text-blue-800":"bg-pink-200 text-pink-800"),children:n.metaTotals.facebookUsers?.some(t=>t.id===e.id)?"Facebook":"Instagram"})}),r.jsx("td",{className:"p-2 truncate max-w-[150px]",title:e.utm_campaign,children:e.utm_campaign||"-"}),r.jsx("td",{className:"p-2",children:r.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] "+("Free"===e.type?"bg-gray-200 text-gray-700":"bg-green-200 text-green-800"),children:e.type})}),r.jsx("td",{className:"p-2 opacity-70",children:new Date(e.createdAt).toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit"})})]},t))})]})})]})]})]}),r.jsxs("div",{className:"space-y-2",children:[r.jsx("h3",{className:"font-semibold text-gray-700 text-sm",children:"All Referrer Sources:"}),Object.entries(n.referrerStats||{}).map(([e,t])=>r.jsxs("div",{className:"border rounded-lg overflow-hidden "+("meta"===t.group?"border-blue-300 bg-blue-50":"google"===t.group?"border-yellow-300 bg-yellow-50":"ai"===t.group?"border-teal-300 bg-teal-50":"directories"===t.group?"border-orange-300 bg-orange-50":"app"===t.group?"border-purple-300 bg-purple-50":"internal"===t.group?"border-green-300 bg-green-50":"border-gray-200 bg-gray-50"),children:[r.jsxs("div",{className:"p-3 flex justify-between items-center cursor-pointer hover:bg-opacity-80",onClick:()=>u(m===e?null:e),children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"font-medium text-sm",children:e}),"meta"===t.group&&r.jsx("span",{className:"text-xs bg-blue-200 text-blue-800 px-1.5 py-0.5 rounded",children:"META"}),"google"===t.group&&r.jsx("span",{className:"text-xs bg-yellow-200 text-yellow-800 px-1.5 py-0.5 rounded",children:"Search"}),"ai"===t.group&&r.jsx("span",{className:"text-xs bg-teal-200 text-teal-800 px-1.5 py-0.5 rounded",children:"AI"}),"directories"===t.group&&r.jsx("span",{className:"text-xs bg-orange-200 text-orange-800 px-1.5 py-0.5 rounded",children:"Directory"}),"app"===t.group&&r.jsx("span",{className:"text-xs bg-purple-200 text-purple-800 px-1.5 py-0.5 rounded",children:"ð± App"})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"bg-white px-2 py-1 rounded text-sm font-bold shadow-sm",children:t.count}),r.jsxs("span",{className:"text-xs text-gray-500",children:["(",t.paidCount," paid)"]}),r.jsx("span",{className:"text-gray-400",children:m===e?"â²":"â¼"})]})]}),m===e&&r.jsx("div",{className:"border-t p-2 bg-white max-h-48 overflow-y-auto",children:r.jsxs("table",{className:"w-full text-xs",children:[r.jsx("thead",{className:"bg-gray-100 sticky top-0",children:r.jsxs("tr",{children:[r.jsx("th",{className:"text-left p-1",children:"Email"}),r.jsx("th",{className:"text-left p-1 hidden sm:table-cell",children:"Name"}),r.jsx("th",{className:"text-left p-1",children:"Type"}),r.jsx("th",{className:"text-left p-1 hidden lg:table-cell",children:"UTM"}),r.jsx("th",{className:"text-left p-1 hidden sm:table-cell",children:"Time"})]})}),r.jsx("tbody",{children:t.users?.map((e,t)=>r.jsxs("tr",{className:"border-b hover:bg-gray-50",children:[r.jsx("td",{className:"p-1 truncate max-w-[150px]",children:e.email}),r.jsx("td",{className:"p-1 hidden sm:table-cell truncate max-w-[100px]",children:e.name}),r.jsx("td",{className:"p-1",children:r.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] "+("Free"===e.type?"bg-gray-200 text-gray-700":"bg-purple-200 text-purple-800"),children:e.type})}),r.jsx("td",{className:"p-1 hidden lg:table-cell",children:e.utm_source&&r.jsx(v,{title:`Source: ${e.utm_source||"N/A"}\nMedium: ${e.utm_medium||"N/A"}\nCampaign: ${e.utm_campaign||"N/A"}`,children:r.jsx("span",{className:"text-[10px] bg-indigo-100 text-indigo-700 px-1 py-0.5 rounded cursor-help",children:e.utm_source})})}),r.jsx("td",{className:"p-1 hidden sm:table-cell text-gray-500",children:new Date(e.createdAt).toLocaleTimeString("en-US",{hour:"2-digit",minute:"2-digit"})})]},t))})]})})]},e))]}),r.jsxs("div",{className:"mt-4 pt-4 border-t flex flex-wrap gap-3 text-xs text-gray-600",children:[r.jsxs("span",{children:["Date: ",r.jsx("strong",{children:n.isRange?`${n.rangeStart} to ${n.rangeEnd}`:n.isToday?"Today":l})]}),r.jsxs("span",{children:["Total: ",r.jsx("strong",{children:n.totalToday})]}),r.jsxs("span",{children:["META: ",r.jsx("strong",{children:n.metaTotals?.total||0})]}),r.jsxs("span",{children:["Google: ",r.jsx("strong",{children:n.referrerStats?.Google?.count||0})]}),r.jsxs("span",{children:["Direct: ",r.jsx("strong",{children:n.referrerStats?.["Direct / Unknown"]?.count||0})]})]})]}),"campaigns"===p&&r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{className:"flex justify-between items-center",children:[r.jsx("h3",{className:"font-semibold text-gray-700",children:"Campaign Performance"}),r.jsxs("div",{className:"flex gap-2 text-xs",children:[r.jsx("span",{className:"text-gray-500",children:"Sort by:"}),r.jsxs("button",{onClick:()=>f({field:"total",direction:"total"===j.field&&"desc"===j.direction?"asc":"desc"}),className:"px-2 py-1 rounded "+("total"===j.field?"bg-blue-100 text-blue-700":"bg-gray-100"),children:["Sign-ups ","total"===j.field&&("desc"===j.direction?"â":"â")]}),r.jsxs("button",{onClick:()=>f({field:"paid",direction:"paid"===j.field&&"desc"===j.direction?"asc":"desc"}),className:"px-2 py-1 rounded "+("paid"===j.field?"bg-green-100 text-green-700":"bg-gray-100"),children:["Paid ","paid"===j.field&&("desc"===j.direction?"â":"â")]}),r.jsxs("button",{onClick:()=>f({field:"conversionRate",direction:"conversionRate"===j.field&&"desc"===j.direction?"asc":"desc"}),className:"px-2 py-1 rounded "+("conversionRate"===j.field?"bg-purple-100 text-purple-700":"bg-gray-100"),children:["Conv% ","conversionRate"===j.field&&("desc"===j.direction?"â":"â")]})]})]}),r.jsx("div",{className:"overflow-x-auto",children:r.jsxs("table",{className:"w-full text-sm border-collapse",children:[r.jsx("thead",{className:"bg-gray-100",children:r.jsxs("tr",{children:[r.jsx("th",{className:"text-left p-3 font-semibold",children:"Campaign"}),r.jsx("th",{className:"text-left p-3 font-semibold",children:"Source"}),r.jsx("th",{className:"text-left p-3 font-semibold",children:"Medium"}),r.jsx("th",{className:"text-center p-3 font-semibold",children:"Sign-ups"}),r.jsx("th",{className:"text-center p-3 font-semibold",children:"Paid"}),r.jsx("th",{className:"text-center p-3 font-semibold",children:"Free"}),r.jsx("th",{className:"text-center p-3 font-semibold",children:"Conv %"})]})}),r.jsx("tbody",{children:(n?.campaignPerformance?[...n.campaignPerformance].sort((e,t)=>
1{const s="conversionRate"===j.field?parseFloat(e[j.field]):e[j.field],a="conversionRate"===j.field?parseFloat(t[j.field]):t[j.field];return"desc"===j.direction?a-s:s-a}):[]).map((e,t)=>r.jsxs("tr",{className:"border-b hover:bg-gray-50 "+(e.source?.toLowerCase().includes("fb")||e.source?.toLowerCase().includes("facebook")||e.source?.toLowerCase().includes("ig")||e.source?.toLowerCase().includes("instagram")?"bg-blue-50":""),children:[r.jsx("td",{className:"p-3",children:r.jsx("div",{className:"max-w-[200px] truncate",title:e.campaign,children:e.campaign})}),r.jsx("td",{className:"p-3",children:r.jsx("span",{className:"px-2 py-1 rounded text-xs "+(e.source?.toLowerCase().includes("fb")||e.source?.toLowerCase().includes("facebook")?"bg-blue-100 text-blue-800":e.source?.toLowerCase().includes("ig")||e.source?.toLowerCase().includes("instagram")?"bg-pink-100 text-pink-800":e.source?.toLowerCase().includes("google")?"bg-yellow-100 text-yellow-800":"bg-gray-100 text-gray-700"),children:e.source||"Direct"})}),r.jsx("td",{className:"p-3 text-gray-500 text-xs",children:e.medium||"-"}),r.jsx("td",{className:"p-3 text-center font-semibold",children:e.total}),r.jsx("td",{className:"p-3 text-center",children:r.jsx("span",{className:"bg-green-100 text-green-800 px-2 py-1 rounded font-semibold",children:e.paid})}),r.jsx("td",{className:"p-3 text-center text-gray-500",children:e.free}),r.jsx("td",{className:"p-3 text-center",children:r.jsxs("span",{className:"px-2 py-1 rounded font-bold "+(parseFloat(e.conversionRate)>=10?"bg-green-200 text-green-800":parseFloat(e.conversionRate)>=5?"bg-yellow-200 text-yellow-800":"bg-gray-100 text-gray-700"),children:[e.conversionRate,"%"]})})]},t))})]})}),(!n.campaignPerformance||0===n.campaignPerformance.length)&&r.jsx("div",{className:"text-center py-8 text-gray-500",children:"No campaign data available"})]}),"conversions"===p&&r.jsxs("div",{className:"space-y-4",children:[r.jsx("h3",{className:"font-semibold text-gray-700",children:"Conversion Rates by Source"}),r.jsx("div",{className:"bg-gradient-to-r from-green-500 to-emerald-600 rounded-xl p-4 text-white mb-4",children:r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-sm opacity-90",children:"Overall Conversion Rate"}),r.jsxs("p",{className:"text-3xl font-bold",children:[n.overallConversionRate,"%"]})]}),r.jsx("div",{className:"text-right",children:r.jsxs("p",{className:"text-sm opacity-90",children:[n.totalPaid," paid / ",n.totalToday," total"]})})]})}),r.jsx("div",{className:"grid gap-3",children:n.sourceConversionRates?.map((e,t)=>r.jsxs("div",{className:"p-4 rounded-lg border "+("meta"===e.group?"border-blue-300 bg-blue-50":"google"===e.group?"border-yellow-300 bg-yellow-50":"ai"===e.group?"border-teal-300 bg-teal-50":"border-gray-200 bg-gray-50"),children:[r.jsxs("div",{className:"flex items-center justify-between mb-2",children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"font-semibold",children:e.source}),"meta"===e.group&&r.jsx("span",{className:"text-xs bg-blue-200 text-blue-800 px-1.5 py-0.5 rounded",children:"META"})]}),r.jsxs("span",{className:"text-xl font-bold "+(parseFloat(e.conversionRate)>=10?"text-green-600":parseFloat(e.conversionRate)>=5?"text-yellow-600":"text-gray-600"),children:[e.conversionRate,"%"]})]}),r.jsxs("div",{className:"flex gap-4 text-sm",children:[r.jsxs("span",{className:"text-gray-600",children:["Total: ",r.jsx("strong",{children:e.total})]}),r.jsxs("span",{className:"text-green-600",children:["Paid: ",r.jsx("strong",{children:e.paid})]}),r.jsxs("span",{className:"text-gray-500",children:["Free: ",r.jsx("strong",{children:e.free})]})]}),r.jsx("div",{className:"mt-2 h-2 bg-gray-200 rounded-full overflow-hidden",children:r.jsx("div",{className:"h-full "+(parseFloat(e.conversionRate)>=10?"bg-green-500":parseFloat(e.conversionRate)>=5?"bg-yellow-500":"bg-gray-400"),style:{width:`${Math.min(parseFloat(e.conversionRate),100)}%`}})})]},t))}),(!n.sourceConversionRates||0===n.sourceConversionRates.length)&&r.jsx("div",{className:"text-center py-8 text-gray-500",children:"No conversion data available"})]})]}),!n&&!s&&r.jsx("div",{className:"text-center py-8 text-gray-500",children:"No data available. Select a date or date range to load traffic analytics."})]})},Ms=[["studio_exposed","Experience shown"],["studio_create_clicked","Create clicked"],["studio_type_selected","Format selected"],["studio_generation_started","Generation screen reached"],["studio_editor_opened","Editor opened"],["studio_save_succeeded","First save"],["studio_upsell_shown","Upgrade shown"],["studio_checkout_started","Checkout started"],["studio_switched_to_legacy","Switched to old dashboard"]],Bs=new Set(["studio_client_error","studio_generation_failed","
1studio_save_failed","studio_export_failed","studio_publish_failed","studio_checkout_failed"]),zs=e=>Number(e||0),$s=e=>zs(e).toLocaleString(),Vs=(e,t)=>t>0?`${(e/t*100).toFixed(1)}%`:"â",Ws=({label:e,value:t,tone:s})=>r.jsxs("div",{className:"rounded-2xl border border-slate-200 bg-white p-4 shadow-sm",children:[r.jsxs("div",{className:"flex items-center justify-between gap-3",children:[r.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.12em] text-slate-500",children:e}),r.jsx("span",{className:`h-2.5 w-2.5 rounded-full ${s}`})]}),r.jsx("p",{className:"mt-2 text-3xl font-semibold tracking-tight text-slate-950",children:$s(t)})]});Ws.propTypes={label:G.string.isRequired,value:G.number.isRequired,tone:G.string.isRequired};const Hs=({title:e,description:t,rows:s,denominatorKey:a,metrics:n})=>r.jsxs("div",{className:"overflow-hidden rounded-2xl border border-slate-200 bg-white shadow-sm",children:[r.jsxs("div",{className:"border-b border-slate-200 px-5 py-4",children:[r.jsx("h3",{className:"font-semibold text-slate-950",children:e}),r.jsx("p",{className:"mt-0.5 text-xs text-slate-500",children:t})]}),r.jsx("div",{className:"overflow-x-auto",children:r.jsxs("table",{className:"min-w-full text-sm",children:[r.jsx("thead",{className:"bg-slate-50 text-left text-xs uppercase tracking-wide text-slate-500",children:r.jsxs("tr",{children:[r.jsx("th",{className:"px-5 py-3",children:"Variant"}),n.map(e=>r.jsx("th",{className:"px-5 py-3",children:e.label},e.key))]})}),r.jsx("tbody",{className:"divide-y divide-slate-100",children:s.map(e=>{const t=zs(e[a]);return r.jsxs("tr",{children:[r.jsx("td",{className:"px-5 py-3 font-semibold capitalize text-slate-900",children:"treatment"===e.variant?"Book Studio":"Standard"}),n.map(s=>{const a=zs(e[s.key]);return r.jsxs("td",{className:"px-5 py-3",children:[r.jsx("p",{className:"font-medium text-slate-900",children:s.currency?`$${a.toFixed(2)}`:Vs(a,t)}),r.jsx("p",{className:"mt-0.5 whitespace-nowrap text-xs text-slate-500",children:s.currency?`$${zs(e.revenuePerAssignedUser).toFixed(2)} / assigned`:`${$s(a)} users · n=${$s(t)}`})]},s.key)})]},e.variant)})})]})})]});Hs.propTypes={title:G.string.isRequired,description:G.string.isRequired,rows:G.arrayOf(G.object).isRequired,denominatorKey:G.string.isRequired,metrics:G.arrayOf(G.shape({key:G.string.isRequired,label:G.string.isRequired,currency:G.bool})).isRequired};const Ks=()=>{const t=J(),s=e.useRef(t);s.current=t;const[a,n]=e.useState(7),[i,l]=e.useState(null),[o,c]=e.useState(!0),[d,x]=e.useState(!1),[h,m]=e.useState(""),u=e.useCallback(async({quiet:e=!1}={})=>{e?x(!0):c(!0),m("");try{const e=await s.current.get(`/api/book-studio/analytics/summary?days=${a}`);l(e?.data||null)}catch(t){m(t?.response?.data?.msg||"Book Studio experiment statistics could not be loaded.")}finally{c(!1),x(!1)}},[a]);e.useEffect(()=>{u();const e=window.setInterval(()=>u({quiet:!0}),6e4);return()=>window.clearInterval(e)},[u]);const p=e.useMemo(()=>{const e={control:0,treatment:0};return(i?.assignments||[]).forEach(t=>{t?.variant in e&&(e[t.variant]=zs(t.assignedUsers))}),e},[i?.assignments]),g=e.useMemo(()=>{const e=new Map;return(i?.events||[]).forEach(t=>{e.set(`${t.variant}:${t.name}`,t)}),e},[i?.events]),j=e.useMemo(()=>{const e=new Map;return(i?.exposures||[]).forEach(t=>{e.set(`${t.variant}:${t.surface}`,t)}),e},[i?.exposures]),f=p.control+p.treatment,b=f>0?Math.abs(p.control-p.treatment)/f:0,y=i?.srm?.status||(f>=100&&b>.1?"warning":"ok"),v=zs(j.get("treatment:book_studio")?.uniqueUsers),N=zs(j.get("control:legacy_dashboard")?.uniqueUsers),w=zs(g.get("treatment:studio_switched_to_legacy")?.uniqueUsers),k=zs(g.get("treatment:studio_switched_to_studio")?.uniqueUsers),S=(i?.events||[]).filter(e=>Bs.has(e.name)).reduce((e,t)=>e+zs(t.eventCount),0),A=i?.outcomes||[],C=i?.liveOutcomes||[],O=i?.firstHourOutcomes||[],P=i?.credits||[],T=i?.feedback||[],E=i?.trackingHealth||[];return r.jsxs("section",{className:"space-y-5","aria-busy":o||d,children:[r.jsxs("div",{className:"flex flex-col gap-3 rounded-2xl border border-slate-200 bg-slate-50 p-5 sm:flex-row sm:items-center sm:justify-between",children:[r.jsxs("div",{children:[r.jsxs("div",{className:"flex items-center gap-2 text-xs font-semibold uppercase tracking-[0.12em] text-violet-700",children:[r.jsx(nt,{size:17,weight:"duotone"}),i?.experimentKey||"book_studio_new_users_v1"]}
1),r.jsx("h2",{className:"mt-1 text-2xl font-semibold tracking-tight text-slate-950",children:"New-user Book Studio 50/50 experiment"}),r.jsxs("p",{className:"mt-1 text-sm text-slate-600",children:["New registrations only. Assignment, activation, credit usage, and paid conversion stay grouped by the original server variant.",i?.eligibilityCutoff?` Cohort starts ${new Date(i.eligibilityCutoff).toLocaleString()}.`:"",i?.generatedAt?` Updated ${new Date(i.generatedAt).toLocaleTimeString()}.`:""]})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("label",{className:"text-xs font-semibold text-slate-600",children:["Window",r.jsxs("select",{value:a,onChange:e=>n(Number(e.target.value)),className:"ml-2 h-10 rounded-xl border border-slate-300 bg-white px-3 text-sm text-slate-800",children:[r.jsx("option",{value:1,children:"24 hours"}),r.jsx("option",{value:7,children:"7 days"}),r.jsx("option",{value:14,children:"14 days"}),r.jsx("option",{value:30,children:"30 days"})]})]}),r.jsx("button",{type:"button",onClick:()=>u({quiet:!0}),disabled:d,className:"grid h-10 w-10 place-items-center rounded-xl border border-slate-300 bg-white text-slate-600 hover:text-violet-700 disabled:opacity-50","aria-label":"Refresh Book Studio experiment statistics",children:d?r.jsx(X,{size:"sm"}):r.jsx(at,{size:18})})]})]}),h?r.jsxs("div",{role:"alert",className:"flex items-start gap-3 rounded-2xl border border-rose-200 bg-rose-50 p-4 text-sm text-rose-800",children:[r.jsx(Qe,{size:20,className:"mt-0.5 shrink-0"}),r.jsx("span",{children:h})]}):null,o?r.jsx("div",{className:"grid min-h-56 place-items-center rounded-2xl border border-slate-200 bg-white",children:r.jsx(X,{size:"md"})}):r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[r.jsx(Ws,{label:"Control assigned",value:p.control,tone:"bg-slate-500"}),r.jsx(Ws,{label:"Studio assigned",value:p.treatment,tone:"bg-violet-600"}),r.jsx(Ws,{label:"Control exposed",value:N,tone:"bg-sky-500"}),r.jsx(Ws,{label:"Studio exposed",value:v,tone:"bg-emerald-500"})]}),r.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[r.jsxs("div",{className:"rounded-2xl border border-slate-200 bg-white p-4 shadow-sm",children:[r.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.12em] text-slate-500",children:"Studio â old dashboard"}),r.jsxs("p",{className:"mt-2 text-2xl font-semibold text-slate-950",children:[$s(w)," users"]}),r.jsxs("p",{className:"mt-1 text-xs text-slate-500",children:[Vs(w,p.treatment)," of Studio assignments"]})]}),r.jsxs("div",{className:"rounded-2xl border border-slate-200 bg-white p-4 shadow-sm",children:[r.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.12em] text-slate-500",children:"Old dashboard â Studio"}),r.jsxs("p",{className:"mt-2 text-2xl font-semibold text-slate-950",children:[$s(k)," users"]}),r.jsx("p",{className:"mt-1 text-xs text-slate-500",children:"Persistent preference changes; assignment remains unchanged"})]})]}),r.jsxs("div",{className:"flex items-start gap-3 rounded-2xl border p-4 text-sm "+("ok"===y?"border-emerald-200 bg-emerald-50 text-emerald-900":"border-amber-200 bg-amber-50 text-amber-900"),children:["ok"===y?r.jsx(Je,{size:20,className:"mt-0.5 shrink-0"}):r.jsx(Qe,{size:20,className:"mt-0.5 shrink-0"}),r.jsxs("div",{children:[r.jsx("strong",{children:"ok"===y?"Assignment split looks healthy":"Check sample-ratio mismatch"}),r.jsxs("p",{className:"mt-0.5",children:["Control ",Vs(p.control,f)," · Studio"," ",Vs(p.treatment,f),void 0!==i?.srm?.pValue?` · p=${Number(i.srm.pValue).toFixed(4)}`:""]})]})]}),C.length?r.jsx(Hs,{title:"Live experiment direction",description:"Directional, server-side outcomes for everyone assigned in the selected window. Real credit deductions, completed books, downloads, checkout records, and confirmed payments are used instead of browser success events.",rows:C,denominatorKey:"assignedUsers",metrics:[{key:"activatedUsers",label:"Any credit used"},{key:"bookSpendingUsers",label:"Book credit used"},{key:"completedUsers",label:"Book completed"},{key:"downloadedUsers",label:"Downloaded"},{key:"checkoutUsers",label:"Checkout"},{key:"paidUsers",label:"Paid"},{key:"revenue",label:"Revenue",currency:!0}]}):null,O.length?r.jsx(Hs,{title:"Fair first-hour comparison",description:"Only users assigned for at least one hour are included. Every outcome must happen inside that user's first 60 minutes, so newer registrations cannot skew one variant.",rows:O,denominatorKey:"eligibleUsers",metrics:[{key:"exposedUsers",label:"Exposed"},{key:"activatedUsers",label:"Any credit used"},{key:"bookSpendingUsers",label:"Book credit used"},{key:"completedUsers",label:"Book completed"},{key:"checkoutUsers",label:"Checkout"},{key:"paidUsers",label:"Paid"}]}):null,A.length?r.jsxs("div",{className:"overflow-hidden rounded-2xl border border-slate-200 bg-white shadow-sm",children:[r.jsxs("div",{className:"border-b border-slate-200 px-5 py-4",children:[r.jsx("h3",{className:"font-semibold text-slate-950",children:"Comparable experiment outcomes"}),r.jsx("p",{className:"mt-0.5 text-xs text-slate-500",children:"Symmetric server-side engagement, publication, and payment records use only assignments old enough to complete each observation window. Internal
1canaries and Studio-only client events are excluded from this comparison."})]}),r.jsx("div",{className:"overflow-x-auto",children:r.jsxs("table",{className:"min-w-full text-sm",children:[r.jsx("thead",{className:"bg-slate-50 text-left text-xs uppercase tracking-wide text-slate-500",children:r.jsxs("tr",{children:[r.jsx("th",{className:"px-5 py-3",children:"Variant"}),r.jsx("th",{className:"px-5 py-3",children:"Completion â¤24h"}),r.jsx("th",{className:"px-5 py-3",children:"Export/publish â¤7d"}),r.jsx("th",{className:"px-5 py-3",children:"Paid users â¤7d"}),r.jsx("th",{className:"px-5 py-3",children:"Revenue â¤7d / eligible"})]})}),r.jsx("tbody",{className:"divide-y divide-slate-100",children:A.map(e=>r.jsxs("tr",{children:[r.jsx("td",{className:"px-5 py-3 font-semibold capitalize text-slate-900",children:e.variant}),r.jsxs("td",{className:"px-5 py-3",children:[r.jsx("p",{className:"font-medium text-slate-900",children:Vs(e.firstBook24h,e.firstBook24hEligibleUsers)}),r.jsxs("p",{className:"mt-0.5 text-xs text-slate-500",children:[$s(e.firstBook24h)," users · eligible n=",$s(e.firstBook24hEligibleUsers)]})]}),r.jsxs("td",{className:"px-5 py-3",children:[r.jsx("p",{className:"font-medium text-slate-900",children:Vs(e.exportOrPublish7d,e.sevenDayEligibleUsers)}),r.jsxs("p",{className:"mt-0.5 text-xs text-slate-500",children:[$s(e.exportOrPublish7d)," users · eligible n=",$s(e.sevenDayEligibleUsers)]})]}),r.jsxs("td",{className:"px-5 py-3",children:[r.jsx("p",{className:"font-medium text-slate-900",children:Vs(e.paidUsers,e.sevenDayEligibleUsers)}),r.jsxs("p",{className:"mt-0.5 text-xs text-slate-500",children:[$s(e.paidUsers)," users · eligible n=",$s(e.sevenDayEligibleUsers)]})]}),r.jsxs("td",{className:"px-5 py-3",children:[r.jsx("p",{className:"font-medium text-slate-900",children:zs(e.sevenDayEligibleUsers)>0?`$${zs(e.revenuePerSevenDayEligibleUser).toFixed(2)}`:"â"}),r.jsxs("p",{className:"mt-0.5 text-xs text-slate-500",children:["$",zs(e.revenue).toFixed(2)," total · eligible n=",$s(e.sevenDayEligibleUsers)]})]})]},e.variant))})]})})]}):null,P.length?r.jsxs("div",{className:"overflow-hidden rounded-2xl border border-slate-200 bg-white shadow-sm",children:[r.jsxs("div",{className:"border-b border-slate-200 px-5 py-4",children:[r.jsx("h3",{className:"font-semibold text-slate-950",children:"Credit consumption by assigned variant"}),r.jsx("p",{className:"mt-0.5 text-xs text-slate-500",children:"Book-credit deductions are covered across Studio generation controllers. The 24-hour comparison uses only mature assignments. Image/task columns are logged-deduction diagnostics; legacy operations that bypass token history are not included."})]}),r.jsx("div",{className:"overflow-x-auto",children:r.jsxs("table",{className:"min-w-full text-sm",children:[r.jsx("thead",{className:"bg-slate-50 text-left text-xs uppercase tracking-wide text-slate-500",children:r.jsxs("tr",{children:[r.jsx("th",{className:"px-5 py-3",children:"Variant"}),r.jsx("th",{className:"px-5 py-3",children:"Book use â¤24h"}),r.jsx("th",{className:"px-5 py-3",children:"Book credits total"}),r.jsx("th",{className:"px-5 py-3",children:"Logged image credits"}),r.jsx("th",{className:"px-5 py-3",children:"Logged task credits"})]})}),r.jsx("tbody",{className:"divide-y divide-slate-100",children:P.map(e=>r.jsxs("tr",{children:[r.jsx("td",{className:"px-5 py-3 font-semibold capitalize text-slate-900",children:e.variant}),r.jsxs("td",{className:"px-5 py-3",children:[r.jsx("p",{className:"font-medium text-slate-900",children:Vs(e.bookSpendingUsers24h,e.first24hEligibleUsers)}),r.jsxs("p",{className:"mt-0.5 text-xs text-slate-500",children:[$s(e.bookCreditsSpent24h)," credits ·"," ",$s(e.bookSpendingUsers24h)," users · n=",$s(e.first24hEligibleUsers)]})]}),r.jsxs("td",{className:"px-5 py-3",children:[r.jsx("p",{className:"font-medium text-slate-900",children:$s(e.bookCreditsSpent)}),r.jsxs("p",{className:"mt-0.5 text-xs text-slate-500",children:[$s(e.bookSpendingUsers)," users ·"," ",zs(e.bookCreditsPerAssignedUser).toFixed(2),"/ assigned"]})]}),r.jsxs("td",{className:"px-5 py-3",children:[r.jsx("p",{className:"font-medium text-slate-900",children:$s(e.imageCreditsSpent)}),r.jsxs("p",{className:"mt-0.5 text-xs text-slate-500",children:[$s(e.imageSpendingUsers)," users"]})]}),r.jsxs("td",{className:"px-5 py-3",children:[r.jsx("p",{className:"font-medium text-slate-900",children:$s(e.taskCreditsSpent)}),r.jsxs("p",{className:"mt-0.5 text-xs text-slate-500",children:[$s(e.taskSpendingUsers)," users"]})]})]},e.variant))})]})})]}):null,T.length?r.jsxs("div",{className:"overflow-hidden rounded-2xl border border-slate-200 bg-white shadow-sm",children:[r.jsxs("div",{className:"border-b border-slate-200 px-5 py-4",children:[r.jsx("h3",{className:"font-semibold text-slate-950",children:"Satisfaction by assigned variant"}),r.jsx("p",{className:"mt-0.5 text-xs text-slate-500",children:"Latest persisted response per user;
1 internal canary responses are excluded."})]}),r.jsx("div",{className:"grid gap-3 p-5 sm:grid-cols-2",children:T.map(e=>r.jsxs("div",{className:"rounded-xl border border-slate-200 bg-slate-50 p-4",children:[r.jsx("p",{className:"text-xs font-semibold uppercase tracking-wide text-slate-500",children:e.variant}),r.jsx("p",{className:"mt-1 text-2xl font-semibold text-slate-950",children:Vs(e.likes,e.responses)}),r.jsxs("p",{className:"mt-1 text-xs text-slate-500",children:[$s(e.likes)," positive ·"," ",$s(e.dislikes)," needs improvement ·"," ",$s(e.responses)," total"]})]},e.variant))})]}):null,E.length?r.jsxs("div",{className:"overflow-hidden rounded-2xl border border-slate-200 bg-white shadow-sm",children:[r.jsxs("div",{className:"border-b border-slate-200 px-5 py-4",children:[r.jsx("h3",{className:"font-semibold text-slate-950",children:"Tracking diagnostics"}),r.jsx("p",{className:"mt-0.5 text-xs text-slate-500",children:"Canonical counts come from persisted books, downloads, and confirmed payments. Browser signals are diagnostic only and never determine the experiment winner."})]}),r.jsx("div",{className:"overflow-x-auto",children:r.jsxs("table",{className:"min-w-full text-sm",children:[r.jsx("thead",{className:"bg-slate-50 text-left text-xs uppercase tracking-wide text-slate-500",children:r.jsxs("tr",{children:[r.jsx("th",{className:"px-5 py-3",children:"Variant"}),r.jsx("th",{className:"px-5 py-3",children:"Outcome"}),r.jsx("th",{className:"px-5 py-3",children:"Canonical users"}),r.jsx("th",{className:"px-5 py-3",children:"Browser signals"})]})}),r.jsx("tbody",{className:"divide-y divide-slate-100",children:E.flatMap(e=>[["Completed book",e.completed],["Downloaded",e.downloaded],["Paid",e.paid]].map(([t,s])=>r.jsxs("tr",{children:[r.jsx("td",{className:"px-5 py-3 font-semibold text-slate-900",children:"treatment"===e.variant?"Book Studio":"Standard"}),r.jsx("td",{className:"px-5 py-3 text-slate-700",children:t}),r.jsx("td",{className:"px-5 py-3 font-medium text-slate-950",children:$s(s?.canonicalUsers)}),r.jsx("td",{className:"px-5 py-3 text-slate-500",children:$s(s?.browserEventUsers)})]},`${e.variant}:${t}`)))})]})})]}):null,r.jsxs("div",{className:"overflow-hidden rounded-2xl border border-slate-200 bg-white shadow-sm",children:[r.jsxs("div",{className:"flex items-center justify-between border-b border-slate-200 px-5 py-4",children:[r.jsxs("div",{children:[r.jsx("h3",{className:"font-semibold text-slate-950",children:"Book Studio interaction funnel"}),r.jsx("p",{className:"mt-0.5 text-xs text-slate-500",children:"Browser events cover the Book Studio UI journey only. Real completion, download, and payment outcomes are shown in the server-side tables above."})]}),r.jsxs("span",{className:"rounded-full px-2.5 py-1 text-xs font-semibold "+(S?"bg-amber-100 text-amber-800":"bg-emerald-100 text-emerald-800"),children:[$s(S)," failure events"]})]}),r.jsx("div",{className:"overflow-x-auto",children:r.jsxs("table",{className:"min-w-full text-sm",children:[r.jsx("thead",{className:"bg-slate-50 text-left text-xs uppercase tracking-wide text-slate-500",children:r.jsxs("tr",{children:[r.jsx("th",{className:"px-5 py-3",children:"Step"}),r.jsx("th",{className:"px-5 py-3",children:"Users"}),r.jsx("th",{className:"px-5 py-3",children:"From assigned"}),r.jsx("th",{className:"px-5 py-3",children:"Events"})]})}),r.jsx("tbody",{className:"divide-y divide-slate-100",children:Ms.map(([e,t])=>{const s=g.get(`treatment:${e}`)||{};return r.jsxs("tr",{children:[r.jsx("td",{className:"px-5 py-3 font-medium text-slate-900",children:t}),r.jsx("td",{className:"px-5 py-3",children:$s(s.uniqueUsers)}),r.jsx("td",{className:"px-5 py-3",children:Vs(zs(s.uniqueUsers),p.treatment)}),r.jsx("td",{className:"px-5 py-3 text-slate-500",children:$s(s.eventCount)})]},e)})})]})})]})]})]})},Zs=()=>{const[t,s]=e.useState(0),[a,n]=e.useState(!1),[l,o]=e.useState([]),[c,d]=e.useState([]),[x,h]=e.useState(null),[m,g]=e.useState([]),[j,f]=e.useState(null),{enqueueSnackbar:b}=Y(),y=J();return e.useEffect(()=>{(async()=>{n(!0);try{const e=await y.get("/api/analytics/referrer-stats");e.data.success&&o(e.data.data)}catch(e){b("Failed to load referrer statistics",{variant:"error"})}finally{n(!1)}})(),(async()=>{n(!0);try{const e=await y.get("/api/analytics/user-plan-stats");e.data.success&&d(e.data.data)}catch(e){b("Failed to load user plan statistics",{variant:"error"})}finally{n(!1)}})(),(async()=>{try{const e=await y.get("/api/analytics/user-registration-stats");e.data.success&&e.data.data?h(e.data.data):h([])}catch(e){b("Failed to load user registration statistics",{variant:"error"}),h([])}})(),(async()=>{n(!0);try{const e=await y.get("/api/analytics/platform-conversion-stats");e.data.success&&g(e.data.data)}catch(e){b("Failed to load platform conversion statistics",{variant:"error"})}finally{n(!1)}})(),(async()=>{n(!0);try{const e=await y.get("/api/analytics/book-creation-stats");e.data.success&&f(e.data.data)}catch(e){b("Failed to load book creation statistics",{variant:"error"})}finally{n(!1)}})()},[]),r.jsxs("div",{className:"container mx-auto px-4 py-8",style:{maxWidth:"100%",overflowX:"hidden"},children:[r.jsx("h1",{className:"text-3xl font-bold mb-6",children:"Business Analytics"}),r.jsx(i,{className:"mb-8",children:r.jsxs(u,{value:t,onChange:(e,t)=>
1{s(t)},indicatorColor:"primary",textColor:"primary",variant:"scrollable",scrollButtons:"auto",children:[r.jsx(p,{label:"𧪠Book Studio A/B"}),r.jsx(p,{label:"ð Traffic Analytics"}),r.jsx(p,{label:"ð Country Stats"}),r.jsx(p,{label:"Referrer Stats"}),r.jsx(p,{label:"User Plans"}),r.jsx(p,{label:"ð User Growth"}),r.jsx(p,{label:"Platform Conversion"}),r.jsx(p,{label:"Book Creation"}),r.jsx(p,{label:"Market Research Feedback"}),r.jsx(p,{label:"Book Feedback"}),r.jsx(p,{label:"Lifetime Page Analytics"})]})}),r.jsxs(r.Fragment,{children:[0===t&&r.jsx(Ks,{}),1===t&&r.jsx(Is,{}),2===t&&r.jsx(Us,{}),3===t&&r.jsx(ks,{data:l}),4===t&&r.jsx(Ss,{data:c}),5===t&&r.jsx(As,{data:x}),6===t&&r.jsx(Cs,{data:m}),7===t&&r.jsx(Ts,{data:j}),8===t&&r.jsx(Es,{}),9===t&&r.jsx(_s,{}),10===t&&r.jsx(Ls,{})]})]})};export{Zs as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.