PageSourceSearch

https://javawhiskers.co.uk/assets/AdminAnalytics-CtY7uWHk.js

js javawhiskers.co.uk collected 2026-10-05 01:09:28 UTC 110,337 bytes, 4 lines download raw bytes

1import{R as $,q as us,r as f,j as e}from"./vendor-react-Bt3w6bFX.js";import{supabase as de}from"./client-Dq1sIdUg.js";import{C as N,b as D,c as E,a as k}from"./card-Bi2qPvvW.js";import{B as te}from"./button-Df1CPV9Y.js";import{B as K}from"./badge-DDbBmJ7-.js";import{T as ms,a as hs,b as q,c as U}from"./tabs-Db3X4Xz7.js";import{$ as xe,a0 as Xs,j as Ve,D as Qs,o as er,V as xs,W as ps,x as fs,s as gs,v as Le,w as vs,J as tr,X as sr,Y as rr,q as ar,_ as nr,r as ir,M as or,N as lr}from"./index-B3NwW_rO.js";import{x as Bt,B as Be,a_ as cr,b6 as dr,b7 as ur,b8 as Vt,l as jt,q as mr,i as hr,aI as xr,E as pr,ax as fr,y as bs,b9 as Ie,X as gr,A as yt,ao as js,U as tt,ac as vr,ba as Kt,au as br,j as ys,b5 as jr,a as yr,aM as gt,bb as Nr,aX as wr,a6 as kr,aL as Ze,bc as _r,R as Gt,bd as zt,k as Ar,be as Sr,M as Pr,bf as Or,bg as Rr,aZ as Cr,bh as Tr,aY as Dr}from"./vendor-icons-Bt7APd9S.js";import{f as W,_ as Ns,a as ws,b as Er,c as $r,i as be,T as Et,p as ue,L as ae,g as ks,d as $t,e as _s,D as Ir,C as Lr,h as Oe,j as ke,S as Mr,A as Fr,k as Br,l as qt,m as Vr,n as _e,o as Kr,G as Gr,q as zr,r as qr,s as Ye,w as Ut,t as st,u as Ur,v as Nt,x as As,B as Ae,X as he,Y as oe,y as Wr,z as Hr,R as le,E as je,F as ce,H as rt,I as Zr,J as wt,K as kt,M as it}from"./AreaChart-CC-Bh0Bc.js";import{I as Yr}from"./input-CV5g6U6p.js";import{D as Jr,a as Xr,b as Qr,c as ea}from"./dialog-CLm41hUJ.js";import{a as ta,C as Wt,s as me}from"./calendar-HlsOsz4o.js";import{h as sa,R as ra,u as aa,F as na}from"./index-fipoPpet.js";import{S as ia,a as oa,b as la,c as ca,d as Je}from"./select-oaumXKtM.js";import{t as da,d as ua,s as ne,f as ma}from"./format-BeSPVV7H.js";import{e as _t}from"./en-GB-aDVu6SJh.js";import{e as ha}from"./slideDeck-C_7-CdBn.js";import"./vendor-supabase-B8wCO4e6.js";import"./index-De_AyhTI.js";import"./index-CtAg43hq.js";import"./index-BdQq_4o_.js";import"./index-SFeaFU0a.js";function At(t){const s=da(t);return s.setHours(23,59,59,999),s}function Ht(t,s){return ta(t,-s)}var xa=["points","className","baseLinePoints","connectNulls"];function Se(){return Se=Object.assign?Object.assign.bind():function(t){for(var s=1;s<arguments.length;s++){var a=arguments[s];for(var r in a)Object.prototype.hasOwnProperty.call(a,r)&&(t[r]=a[r])}return t},Se.apply(this,arguments)}function pa(t,s){if(t==null)return{};var a=fa(t,s),r,n;if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(t);for(n=0;n<l.length;n++)r=l[n],!(s.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(t,r)&&(a[r]=t[r])}return a}function fa(t,s){if(t==null)return{};var a={};for(var r in t)if(Object.prototype.hasOwnProperty.call(t,r)){if(s.indexOf(r)>=0)continue;a[r]=t[r]}return a}function Zt(t){return ja(t)||ba(t)||va(t)||ga()}function ga(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
2In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function va(t,s){if(t){if(typeof t=="string")return St(t,s);var a=Object.prototype.toString.call(t).slice(8,-1);if(a==="Object"&&t.constructor&&(a=t.constructor.name),a==="Map"||a==="Set")return Array.from(t);if(a==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(a))return St(t,s)}}function ba(t){if(typeof Symbol<"u"&&t[Symbol.iterator]!=null||t["@@iterator"]!=null)return Array.from(t)}function ja(t){if(Array.isArray(t))return St(t)}function St(t,s){(s==null||s>t.length)&&(s=t.length);for(var a=0,r=new Array(s);a<s;a++)r[a]=t[a];return r}var Yt=function(s){return s&&s.x===+s.x&&s.y===+s.y},ya=function(){var s=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],a=[[]];return s.forEach(function(r){Yt(r)?a[a.length-1].push(r):a[a.length-1].length>0&&a.push([])}),Yt(s[0])&&a[a.length-1].push(s[0]),a[a.length-1].length<=0&&(a=a.slice(0,-1)),a},Me=function(s,a){var r=ya(s);a&&(r=[r.reduce(function(l,i){return[].concat(Zt(l),Zt(i))},[])]);var n=r.map(function(l){return l.reduce(function(i,h,u){return"".concat(i).concat(u===0?"M":"L").concat(h.x,",").concat(h.y)},"")}).join("");return r.length===1?"".concat(n,"Z"):n},Na=function(s,a,r){var n=Me(s,r);return"".concat(n.slice(-1)==="Z"?n.slice(0,-1):n,"L").concat(Me(a.reverse(),r).slice(1))},wa=function(s){var a=s.points,r=s.className,n=s.baseLinePoints,l=s.connectNulls,i=pa(s,xa);if(!a||!a.length)return null;var h=xe("recharts-polygon",r);if(n&&n.length){var u=i.stroke&&i.stroke!=="none",p=Na(a,n,l);return $.createElement("g",{className:h},$.createElement("path",Se({},W(i,!0),{fill:p.slice(-1)==="Z"?i.fill:"none",stroke:"none",d:p})),u?$.createElement("path",Se({},W(i,!0),{fill:"none",d:Me(a,l)})):null,u?$.createElement("path",Se({},W(i,!0),{fill:"none",d:Me(n,l)})):null)}var j=Me(a,l);return $.createElement("path",Se({},W(i,!0),{fill:j.slice(-1)==="Z"?i.fill:"none",className:h,d:j}))},ka=Ns,_a=Er,Aa=ws;function Sa(t,s){return t&&t.length?ka(t,Aa(s),_a):void 0}var Pa=Sa;const Oa=us(Pa);var Ra=Ns,Ca=ws,Ta=$r;function Da(t,s){return t&&t.length?Ra(t,Ca(s),Ta):void 0}var Ea=Da;const $a=us(Ea);
vendor: 21,505 bytes, line 2
2var Ia=["cx","cy","angle","ticks","axisLine"],La=["ticks","tick","angle","tickFormatter","stroke"];function Re(t){"@babel/helpers - typeof";return Re=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(s){return typeof s}:function(s){return s&&typeof Symbol=="function"&&s.constructor===Symbol&&s!==Symbol.prototype?"symbol":typeof s},Re(t)}function Fe(){return Fe=Object.assign?Object.assign.bind():function(t){for(var s=1;s<arguments.length;s++){var a=arguments[s];for(var r in a)Object.prototype.hasOwnProperty.call(a,r)&&(t[r]=a[r])}return t},Fe.apply(this,arguments)}function Jt(t,s){var a=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);s&&(r=r.filter(function(n){return Object.getOwnPropertyDescriptor(t,n).enumerable})),a.push.apply(a,r)}return a}function fe(t){for(var s=1;s<arguments.length;s++){var a=arguments[s]!=null?arguments[s]:{};s%2?Jt(Object(a),!0).forEach(function(r){ut(t,r,a[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):Jt(Object(a)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(a,r))})}return t}function Xt(t,s){if(t==null)return{};var a=Ma(t,s),r,n;if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(t);for(n=0;n<l.length;n++)r=l[n],!(s.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(t,r)&&(a[r]=t[r])}return a}function Ma(t,s){if(t==null)return{};var a={};for(var r in t)if(Object.prototype.hasOwnProperty.call(t,r)){if(s.indexOf(r)>=0)continue;a[r]=t[r]}return a}function Fa(t,s){if(!(t instanceof s))throw new TypeError("Cannot call a class as a function")}function Qt(t,s){for(var a=0;a<s.length;a++){var r=s[a];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,Ps(r.key),r)}}function Ba(t,s,a){return s&&Qt(t.prototype,s),a&&Qt(t,a),Object.defineProperty(t,"prototype",{writable:!1}),t}function Va(t,s,a){return s=ot(s),Ka(t,Ss()?Reflect.construct(s,a||[],ot(t).constructor):s.apply(t,a))}function Ka(t,s){if(s&&(Re(s)==="object"||typeof s=="function"))return s;if(s!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return Ga(t)}function Ga(t){if(t===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function Ss(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(Ss=function(){return!!t})()}function ot(t){return ot=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(a){return a.__proto__||Object.getPrototypeOf(a)},ot(t)}function za(t,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(s&&s.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),s&&Pt(t,s)}function Pt(t,s){return Pt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(r,n){return r.__proto__=n,r},Pt(t,s)}function ut(t,s,a){return s=Ps(s),s in t?Object.defineProperty(t,s,{value:a,enumerable:!0,configurable:!0,writable:!0}):t[s]=a,t}function Ps(t){var s=qa(t,"string");return Re(s)=="symbol"?s:s+""}function qa(t,s){if(Re(t)!="object"||!t)return t;var a=t[Symbol.toPrimitive];if(a!==void 0){var r=a.call(t,s||"default");if(Re(r)!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(s==="string"?String:Number)(t)}var mt=function(t){function s(){return Fa(this,s),Va(this,s,arguments)}return za(s,t),Ba(s,[{key:"getTickValueCoord",value:function(r){var n=r.coordinate,l=this.props,i=l.angle,h=l.cx,u=l.cy;return ue(h,u,n,i)}},{key:"getTickTextAnchor",value:function(){var r=this.props.orientation,n;switch(r){case"left":n="end";break;case"right":n="start";break;default:n="middle";break}return n}},{key:"getViewBox",value:function(){var r=this.props,n=r.cx,l=r.cy,i=r.angle,h=r.ticks,u=Oa(h,function(j){return j.coordinate||0}),p=$a(h,function(j){return j.coordinate||0});return{cx:n,cy:l,startAngle:i,endAngle:i,innerRadius:p.coordinate||0,outerRadius:u.coordinate||0}}},{key:"renderAxisLine",value:function(){var r=this.props,n=r.cx,l=r.cy,i=r.angle,h=r.ticks,u=r.axisLine,p=Xt(r,Ia),j=h.reduce(function(w,m){return[Math.min(w[0],m.coordinate),Math.max(w[1],m.coordinate)]},[1/0,-1/0]),_=ue(n,l,j[0],i),O=ue(n,l,j[1],i),T=fe(fe(fe({},W(p,!1)),{},{fill:"none"},W(u,!1)),{},{x1:_.x,y1:_.y,x2:O.x,y2:O.y});return $.createElement("line",Fe({className:"recharts-polar-radius-axis-line"},T))}},{key:"renderTicks",value:function(){var r=this,n=this.props,l=n.ticks,i=n.tick,h=n.angle,u=n.tickFormatter,p=n.stroke,j=Xt(n,La),_=this.getTickTextAnchor(),O=W(j,!1),T=W(i,!1),w=l.map(function(m,S){var R=r.getTickValueCoord(m),g=fe(fe(fe(fe({textAnchor:_,transform:"rotate(".concat(90-h,", ").concat(R.x,", ").concat(R.y,")")},O),{},{stroke:"none",fill:p},T),{},{index:S},R),{},{payload:m});return $.createElement(ae,Fe({className:xe("recharts-polar-radius-axis-tick",ks(i)),key:"tick-".concat(m.coordinate)},$t(r.props,m,S)),s.renderTickItem(i,g,u?u(m.value,S):m.value))});return $.createElement(ae,{className:"recharts-polar-radius-axis-ticks"},w)}},{key:"render",value:function(){var r=this.props,n=r.ticks,l=r.axisLine,i=r.tick;return!n||!n.length?null:$.createElement(ae,{className:xe("recharts-polar-radius-axis",this.props.className)},l&&this.renderAxisLine(),i&&this.renderTicks(),_s.renderCallByParent(this.props,this.getViewBox()))}}],[{key:"renderTickItem",value:function(r,n,l){var i;return $.isValidElement(r)?i=$.cloneElement(r,n):be(r)?i=r(n):i=$.createElement(Et,Fe({},n,{className:"recharts-polar-radius-axis-tick-value"}),l),i}}])}(f.PureComponent);ut(mt,"displayName","PolarRadiusAxis");ut(mt,"axisType","radiusAxis");ut(mt,"defaultProps",{type:"number",radiusAxisId:0,cx:0,cy:0,angle:0,orientation:"right",stroke:"#ccc",axisLine:!0,tick:!0,tickCount:5,allowDataOverflow:!1,scale:"auto",allowDuplicatedCategory:!0});function Ce(t){"@babel/helpers - typeof";return Ce=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(s){return typeof s}:function(s){return s&&typeof Symbol=="function"&&s.constructor===Symbol&&s!==Symbol.prototype?"symbol":typeof s},Ce(t)}function ye(){return ye=Object.assign?Object.assign.bind():function(t){for(var s=1;s<arguments.length;s++){var a=arguments[s];for(var r in a)Object.prototype.hasOwnProperty.call(a,r)&&(t[r]=a[r])}return t},ye.apply(this,arguments)}function es(t,s){var a=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);s&&(r=r.filter(function(n){return Object.getOwnPropertyDescriptor(t,n).enumerable})),a.push.apply(a,r)}return a}function ge(t){for(var s=1;s<arguments.length;s++){var a=arguments[s]!=null?arguments[s]:{};s%2?es(Object(a),!0).forEach(function(r){ht(t,r,a[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):es(Object(a)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(a,r))})}return t}function Ua(t,s){if(!(t instanceof s))throw new TypeError("Cannot call a class as a function")}function ts(t,s){for(var a=0;a<s.length;a++){var r=s[a];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,Rs(r.key),r)}}function Wa(t,s,a){return s&&ts(t.prototype,s),a&&ts(t,a),Object.defineProperty(t,"prototype",{writable:!1}),t}function Ha(t,s,a){return s=lt(s),Za(t,Os()?Reflect.construct(s,a||[],lt(t).constructor):s.apply(t,a))}function Za(t,s){if(s&&(Ce(s)==="object"||typeof s=="function"))return s;if(s!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return Ya(t)}function Ya(t){if(t===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function Os(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(Os=function(){return!!t})()}function lt(t){return lt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(a){return a.__proto__||Object.getPrototypeOf(a)},lt(t)}function Ja(t,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(s&&s.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),s&&Ot(t,s)}function Ot(t,s){return Ot=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(r,n){return r.__proto__=n,r},Ot(t,s)}function ht(t,s,a){return s=Rs(s),s in t?Object.defineProperty(t,s,{value:a,enumerable:!0,configurable:!0,writable:!0}):t[s]=a,t}function Rs(t){var s=Xa(t,"string");return Ce(s)=="symbol"?s:s+""}function Xa(t,s){if(Ce(t)!="object"||!t)return t;var a=t[Symbol.toPrimitive];if(a!==void 0){var r=a.call(t,s||"default");if(Ce(r)!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(s==="string"?String:Number)(t)}var Qa=Math.PI/180,ss=1e-5,xt=function(t){function s(){return Ua(this,s),Ha(this,s,arguments)}return Ja(s,t),Wa(s,[{key:"getTickLineCoord",value:function(r){var n=this.props,l=n.cx,i=n.cy,h=n.radius,u=n.orientation,p=n.tickSize,j=p||8,_=ue(l,i,h,r.coordinate),O=ue(l,i,h+(u==="inner"?-1:1)*j,r.coordinate);return{x1:_.x,y1:_.y,x2:O.x,y2:O.y}}},{key:"getTickTextAnchor",value:function(r){var n=this.props.orientation,l=Math.cos(-r.coordinate*Qa),i;return l>ss?i=n==="outer"?"start":"end":l<-ss?i=n==="outer"?"end":"start":i="middle",i}},{key:"renderAxisLine",value:function(){var r=this.props,n=r.cx,l=r.cy,i=r.radius,h=r.axisLine,u=r.axisLineType,p=ge(ge({},W(this.props,!1)),{},{fill:"none"},W(h,!1));if(u==="circle")return $.createElement(Ir,ye({className:"recharts-polar-angle-axis-line"},p,{cx:n,cy:l,r:i}));var j=this.props.ticks,_=j.map(function(O){return ue(n,l,i,O.coordinate)});return $.createElement(wa,ye({className:"recharts-polar-angle-axis-line"},p,{points:_}))}},{key:"renderTicks",value:function(){var r=this,n=this.props,l=n.ticks,i=n.tick,h=n.tickLine,u=n.tickFormatter,p=n.stroke,j=W(this.props,!1),_=W(i,!1),O=ge(ge({},j),{},{fill:"none"},W(h,!1)),T=l.map(function(w,m){var S=r.getTickLineCoord(w),R=r.getTickTextAnchor(w),g=ge(ge(ge({textAnchor:R},j),{},{stroke:"none",fill:p},_),{},{index:m,payload:w,x:S.x2,y:S.y2});return $.createElement(ae,ye({className:xe("recharts-polar-angle-axis-tick",ks(i)),key:"tick-".concat(w.coordinate)},$t(r.props,w,m)),h&&$.createElement("line",ye({className:"recharts-polar-angle-axis-tick-line"},O,S)),i&&s.renderTickItem(i,g,u?u(w.value,m):w.value))});return $.createElement(ae,{className:"recharts-polar-angle-axis-ticks"},T)}},{key:"render",value:function(){var r=this.props,n=r.ticks,l=r.radius,i=r.axisLine;return l<=0||!n||!n.length?null:$.createElement(ae,{className:xe("recharts-polar-angle-axis",this.props.className)},i&&this.renderAxisLine(),this.renderTicks())}}],[{key:"renderTickItem",value:function(r,n,l){var i;return $.isValidElement(r)?i=$.cloneElement(r,n):be(r)?i=r(n):i=$.createElement(Et,ye({},n,{className:"recharts-polar-angle-axis-tick-value"}),l),i}}])}(f.PureComponent);ht(xt,"displayName","PolarAngleAxis");ht(xt,"axisType","angleAxis");ht(xt,"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 at;function Te(t){"@babel/helpers - typeof";return Te=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(s){return typeof s}:function(s){return s&&typeof Symbol=="function"&&s.constructor===Symbol&&s!==Symbol.prototype?"symbol":typeof s},Te(t)}function Pe(){return Pe=Object.assign?Object.assign.bind():function(t){for(var s=1;s<arguments.length;s++){var a=arguments[s];for(var r in a)Object.prototype.hasOwnProperty.call(a,r)&&(t[r]=a[r])}return t},Pe.apply(this,arguments)}function rs(t,s){var a=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);s&&(r=r.filter(function(n){return Object.getOwnPropertyDescriptor(t,n).enumerable})),a.push.apply(a,r)}return a}function B(t){for(var s=1;s<arguments.length;s++){var a=arguments[s]!=null?arguments[s]:{};s%2?rs(Object(a),!0).forEach(function(r){re(t,r,a[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):rs(Object(a)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(a,r))})}return t}function en(t,s){if(!(t instanceof s))throw new TypeError("Cannot call a class as a function")}function as(t,s){for(var a=0;a<s.length;a++){var r=s[a];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,Ts(r.key),r)}}function tn(t,s,a){return s&&as(t.prototype,s),a&&as(t,a),Object.defineProperty(t,"prototype",{writable:!1}),t}function sn(t,s,a){return s=ct(s),rn(t,Cs()?Reflect.construct(s,a||[],ct(t).constructor):s.apply(t,a))}function rn(t,s){if(s&&(Te(s)==="object"||typeof s=="function"))return s;if(s!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return an(t)}function an(t){if(t===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function Cs(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(Cs=function(){return!!t})()}function ct(t){return ct=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(a){return a.__proto__||Object.getPrototypeOf(a)},ct(t)}function nn(t,s){if(typeof s!="function"&&s!==null)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(s&&s.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),s&&Rt(t,s)}function Rt(t,s){return Rt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(r,n){return r.__proto__=n,r},Rt(t,s)}function re(t,s,a){return s=Ts(s),s in t?Object.defineProperty(t,s,{value:a,enumerable:!0,configurable:!0,writable:!0}):t[s]=a,t}function Ts(t){var s=on(t,"string");return Te(s)=="symbol"?s:s+""}function on(t,s){if(Te(t)!="object"||!t)return t;var a=t[Symbol.toPrimitive];if(a!==void 0){var r=a.call(t,s||"default");if(Te(r)!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(s==="string"?String:Number)(t)}var ie=function(t){function s(a){var r;return en(this,s),r=sn(this,s,[a]),re(r,"pieRef",null),re(r,"sectorRefs",[]),re(r,"id",Ur("recharts-pie-")),re(r,"handleAnimationEnd",function(){var n=r.props.onAnimationEnd;r.setState({isAnimationFinished:!0}),be(n)&&n()}),re(r,"handleAnimationStart",function(){var n=r.props.onAnimationStart;r.setState({isAnimationFinished:!1}),be(n)&&n()}),r.state={isAnimationFinished:!a.isAnimationActive,prevIsAnimationActive:a.isAnimationActive,prevAnimationId:a.animationId,sectorToFocus:0},r}return nn(s,t),tn(s,[{key:"isActiveIndex",value:function(r){var n=this.props.activeIndex;return Array.isArray(n)?n.indexOf(r)!==-1:r===n}},{key:"hasActiveIndex",value:function(){var r=this.props.activeIndex;return Array.isArray(r)?r.length!==0:r||r===0}},{key:"renderLabels",value:function(r){var n=this.props.isAnimationActive;if(n&&!this.state.isAnimationFinished)return null;var l=this.props,i=l.label,h=l.labelLine,u=l.dataKey,p=l.valueKey,j=W(this.props,!1),_=W(i,!1),O=W(h,!1),T=i&&i.offsetRadius||20,w=r.map(function(m,S){var R=(m.startAngle+m.endAngle)/2,g=ue(m.cx,m.cy,m.outerRadius+T,R),b=B(B(B(B({},j),m),{},{stroke:"none"},_),{},{index:S,textAnchor:s.getTextAnchor(g.x,m.cx)},g),M=B(B(B(B({},j),m),{},{fill:"none",stroke:m.fill},O),{},{index:S,points:[ue(m.cx,m.cy,m.outerRadius,R),g]}),V=u;return Oe(u)&&Oe(p)?V="value":Oe(u)&&(V=p),$.createElement(ae,{key:"label-".concat(m.startAngle,"-").concat(m.endAngle,"-").concat(m.midAngle,"-").concat(S)},h&&s.renderLabelLineItem(h,M,"line"),s.renderLabelItem(i,b,ke(m,V)))});return $.createElement(ae,{className:"recharts-pie-labels"},w)}},{key:"renderSectorsStatically",value:function(r){var n=this,l=this.props,i=l.activeShape,h=l.blendStroke,u=l.inactiveShape;return r.map(function(p,j){if(p?.startAngle===0&&p?.endAngle===0&&r.length!==1)return null;var _=n.isActiveIndex(j),O=u&&n.hasActiveIndex()?u:null,T=_?i:O,w=B(B({},p),{},{stroke:h?p.fill:p.stroke,tabIndex:-1});return $.createElement(ae,Pe({ref:function(S){S&&!n.sectorRefs.includes(S)&&n.sectorRefs.push(S)},tabIndex:-1,className:"recharts-pie-sector"},$t(n.props,p,j),{key:"sector-".concat(p?.startAngle,"-").concat(p?.endAngle,"-").concat(p.midAngle,"-").concat(j)}),$.createElement(Mr,Pe({option:T,isActive:_,shapeType:"sector"},w)))})}},{key:"renderSectorsWithAnimation",value:function(){var r=this,n=this.props,l=n.sectors,i=n.isAnimationActive,h=n.animationBegin,u=n.animationDuration,p=n.animationEasing,j=n.animationId,_=this.state,O=_.prevSectors,T=_.prevIsAnimationActive;return $.createElement(Fr,{begin:h,duration:u,isActive:i,easing:p,from:{t:0},to:{t:1},key:"pie-".concat(j,"-").concat(T),onAnimationStart:this.handleAnimationStart,onAnimationEnd:this.handleAnimationEnd},function(w){var m=w.t,S=[],R=l&&l[0],g=R.startAngle;return l.forEach(function(b,M){var V=O&&O[M],F=M>0?Br(b,"paddingAngle",0):0;if(V){var v=qt(V.endAngle-V.startAngle,b.endAngle-b.startAngle),A=B(B({},b),{},{startAngle:g+F,endAngle:g+v(m)+F});S.push(A),g=A.endAngle}else{var o=b.endAngle,P=b.startAngle,I=qt(0,o-P),L=I(m),C=B(B({},b),{},{startAngle:g+F,endAngle:g+L+F});S.push(C),g=C.endAngle}}),$.createElement(ae,null,r.renderSectorsStatically(S))})}},{key:"attachKeyboardHandlers",value:function(r){var n=this;r.onkeydown=function(l){if(!l.altKey)switch(l.key){case"ArrowLeft":{var i=++n.state.sectorToFocus%n.sectorRefs.length;n.sectorRefs[i].focus(),n.setState({sectorToFocus:i});break}case"ArrowRight":{var h=--n.state.sectorToFocus<0?n.sectorRefs.length-1:n.state.sectorToFocus%n.sectorRefs.length;n.sectorRefs[h].focus(),n.setState({sectorToFocus:h});break}case"Escape":{n.sectorRefs[n.state.sectorToFocus].blur(),n.setState({sectorToFocus:0});break}}}}},{key:"renderSectors",value:function(){var r=this.props,n=r.sectors,l=r.isAnimationActive,i=this.state.prevSectors;return l&&n&&n.length&&(!i||!Vr(i,n))?this.renderSectorsWithAnimation():this.renderSectorsStatically(n)}},{key:"componentDidMount",value:function(){this.pieRef&&this.attachKeyboardHandlers(this.pieRef)}},{key:"render",value:function(){var r=this,n=this.props,l=n.hide,i=n.sectors,h=n.className,u=n.label,p=n.cx,j=n.cy,_=n.innerRadius,O=n.outerRadius,T=n.isAnimationActive,w=this.state.isAnimationFinished;if(l||!i||!i.length||!_e(p)||!_e(j)||!_e(_)||!_e(O))return null;var m=xe("recharts-pie",h);return $.createElement(ae,{tabIndex:this.props.rootTabIndex,className:m,ref:function(R){r.pieRef=R}},this.renderSectors(),u&&this.renderLabels(i),_s.renderCallByParent(this.props,null,!1),(!T||w)&&Kr.renderCallByParent(this.props,i,!1))}}],[{key:"getDerivedStateFromProps",value:function(r,n){return n.prevIsAnimationActive!==r.isAnimationActive?{prevIsAnimationActive:r.isAnimationActive,prevAnimationId:r.animationId,curSectors:r.sectors,prevSectors:[],isAnimationFinished:!0}:r.isAnimationActive&&r.animationId!==n.prevAnimationId?{prevAnimationId:r.animationId,curSectors:r.sectors,prevSectors:n.curSectors,isAnimationFinished:!0}:r.sectors!==n.curSectors?{curSectors:r.sectors,isAnimationFinished:!0}:null}},{key:"getTextAnchor",value:function(r,n){return r>n?"start":r<n?"end":"middle"}},{key:"renderLabelLineItem",value:function(r,n,l){if($.isValidElement(r))return $.cloneElement(r,n);if(be(r))return r(n);var i=xe("recharts-pie-label-line",typeof r!="boolean"?r.className:"");return $.createElement(Lr,Pe({},n,{key:l,type:"linear",className:i}))}},{key:"renderLabelItem",value:function(r,n,l){if($.isValidElement(r))return $.cloneElement(r,n);var i=l;if(be(r)&&(i=r(n),$.isValidElement(i)))return i;var h=xe("recharts-pie-label-text",typeof r!="boolean"&&!be(r)?r.className:"");return $.createElement(Et,Pe({},n,{alignmentBaseline:"middle",className:h}),i)}}])}(f.PureComponent);at=ie;re(ie,"displayName","Pie");re(ie,"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,minAngle:0,isAnimationActive:!Gr.isSsr,animationBegin:400,animationDuration:1500,animationEasing:"ease",nameKey:"name",blendStroke:!1,rootTabIndex:0});re(ie,"parseDeltaAngle",function(t,s){var a=st(s-t),r=Math.min(Math.abs(s-t),360);return a*r});re(ie,"getRealPieData",function(t){var s=t.data,a=t.children,r=W(t,!1),n=zr(a,Nt);return s&&s.length?s.map(function(l,i){return B(B(B({payload:l},r),l),n&&n[i]&&n[i].props)}):n&&n.length?n.map(function(l){return B(B({},r),l.props)}):[]});re(ie,"parseCoordinateOfPie",function(t,s){var a=s.top,r=s.left,n=s.width,l=s.height,i=qr(n,l),h=r+Ye(t.cx,n,n/2),u=a+Ye(t.cy,l,l/2),p=Ye(t.innerRadius,i,0),j=Ye(t.outerRadius,i,i*.8),_=t.maxRadius||Math.sqrt(n*n+l*l)/2;return{cx:h,cy:u,innerRadius:p,outerRadius:j,maxRadius:_}});re(ie,"getComposedData",function(t){var s=t.item,a=t.offset,r=s.type.defaultProps!==void 0?B(B({},s.type.defaultProps),s.props):s.props,n=at.getRealPieData(r);if(!n||!n.length)return null;var l=r.cornerRadius,i=r.startAngle,h=r.endAngle,u=r.paddingAngle,p=r.dataKey,j=r.nameKey,_=r.valueKey,O=r.tooltipType,T=Math.abs(r.minAngle),w=at.parseCoordinateOfPie(r,a),m=at.parseDeltaAngle(i,h),S=Math.abs(m),R=p;Oe(p)&&Oe(_)?(Ut(!1,`Use "dataKey" to specify the value of pie,
3      the props "valueKey" will be deprecated in 1.1.0`),R="value"):Oe(p)&&(Ut(!1,`Use "dataKey" to specify the value of pie,
4      the props "valueKey" will be deprecated in 1.1.0`),R=_);var g=n.filter(function(A){return ke(A,R,0)!==0}).length,b=(S>=360?g:g-1)*u,M=S-g*T-b,V=n.reduce(function(A,o){var P=ke(o,R,0);return A+(_e(P)?P:0)},0),F;if(V>0){var v;F=n.map(function(A,o){var P=ke(A,R,0),I=ke(A,j,o),L=(_e(P)?P:0)/V,C;o?C=v.endAngle+st(m)*u*(P!==0?1:0):C=i;var J=C+st(m)*((P!==0?T:0)+L*M),Q=(C+J)/2,Ne=(w.innerRadius+w.outerRadius)/2,Ge=[{name:I,value:P,payload:A,dataKey:R,type:O}],ze=ue(w.cx,w.cy,Ne,Q);return v=B(B(B({percent:L,cornerRadius:l,name:I,tooltipPayload:Ge,midAngle:Q,middleRadius:Ne,tooltipPosition:ze},A),w),{},{value:ke(A,R),startAngle:C,endAngle:J,payload:A,paddingAngle:st(m)*u}),v})}return B(B({},w),{},{sectors:F,data:n})});var Ct=As({chartName:"BarChart",GraphicalChild:Ae,defaultTooltipEventType:"axis",validateTooltipEventTypes:["axis","item"],axisComponents:[{axisType:"xAxis",AxisComp:he},{axisType:"yAxis",AxisComp:oe}],formatAxisMap:Wr}),ns=As({chartName:"PieChart",GraphicalChild:ie,validateTooltipEventTypes:["item"],defaultTooltipEventType:"item",legendContent:"children",axisComponents:[{axisType:"angleAxis",AxisComp:xt},{axisType:"radiusAxis",AxisComp:mt}],formatAxisMap:Hr,defaultProps:{layout:"centric",startAngle:0,endAngle:360,cx:"50%",cy:"50%",innerRadius:0,outerRadius:"80%"}});const ln={analytics:"traffic data",heatmap:"heatmap data",acquisition:"acquisition data (channels & campaigns)",engagement:"engagement data (pages, time, scroll)",conversions:"conversion and revenue data",flow:"flow and booking funnel",retention:"retention (new vs returning)",demographics:"devices, browsers and geography"},ve=({type:t,dateRange:s,pagePath:a,title:r,from:n,to:l})=>{const[i,h]=f.useState(null),[u,p]=f.useState(!1),j=async()=>{p(!0);try{const{data:_,error:O}=await de.functions.invoke("analytics-insight",{body:{type:t,date_range:s,page_path:a,from:n?.toISOString(),to:l?.toISOString()}});if(O)throw O;if(_?.error)throw new Error(_.error);h(_.insight)}catch(_){Xs({title:"Error",description:_.message||"Failed to get AI insight",variant:"destructive"})}finally{p(!1)}};return e.jsxs(N,{className:"border-primary/20",children:[e.jsx(D,{className:"pb-3",children:e.jsxs(E,{className:"text-sm flex items-center gap-2",children:[e.jsx(Bt,{className:"h-4 w-4 text-primary"}),r||"AI Insights & Recommendations"]})}),e.jsxs(k,{children:[!i&&!u&&e.jsxs("div",{className:"text-center py-6",children:[e.jsxs("p",{className:"text-muted-foreground text-sm mb-3",children:["Get an AI analysis of ",ln[t]," with concrete recommendations."]}),e.jsxs(te,{onClick:j,className:"gap-2",children:[e.jsx(Bt,{className:"h-4 w-4"}),"Generate insights"]})]}),u&&e.jsxs("div",{className:"flex items-center justify-center py-8 gap-2 text-muted-foreground",children:[e.jsx(Be,{className:"h-4 w-4 animate-spin"}),"Analysing data..."]}),i&&!u&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"text-sm whitespace-pre-wrap leading-relaxed text-foreground bg-muted/50 rounded-lg p-4 max-h-[400px] overflow-y-auto",children:i}),e.jsxs(te,{onClick:j,variant:"outline",size:"sm",className:"gap-2",children:[e.jsx(cr,{className:"h-3 w-3"}),"Update"]})]})]})]})},Z=t=>new Intl.NumberFormat("en-GB").format(Math.round(t||0)),$e=t=>`£${Z(t)}`,Xe=t=>`${(t||0).toFixed(1)}%`,cn=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],dn=({from:t,to:s})=>{const[a,r]=f.useState(!0),[n,l]=f.useState(null),[i,h]=f.useState(null);if(f.useEffect(()=>{let o=!1;return(async()=>{r(!0),h(null);const{data:P,error:I}=await de.rpc("get_analytics_extras",{p_from:t.toISOString(),p_to:s.toISOString()});o||(I?h(I.message):l(P),r(!1))})(),()=>{o=!0}},[t.getTime(),s.getTime()]),a)return e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(Be,{className:"h-6 w-6 animate-spin text-primary"})});if(i)return e.jsx(N,{children:e.jsx(k,{className:"pt-4",children:e.jsx("p",{className:"text-destructive text-sm",children:i})})});if(!n)return null;const u=n.abandoned||{},p=Number(u.abandoned_count||0),j=Number(u.recovered_count||0),_=Number(u.total_count||0),O=_>0?j/_*100:0,T=n.detailed_funnel||[],w=T[0]?.n||1,m=(n.aov_daily||[]).map(o=>({date:new Date(o.day).toLocaleDateString("en-GB",{month:"short",day:"numeric"}),aov:Number(o.orders)>0?Number(o.revenue)/Number(o.orders):0,rpv:Number(o.visitors)>0?Number(o.revenue)/Number(o.visitors):0,revenue:Number(o.revenue),orders:Number(o.orders)})),S=Array.from({length:7},()=>Array(24).fill(0));
4(n.hour_heatmap||[]).forEach(o=>{S[o.dow][o.hour]=Number(o.sessions)});const R=Math.max(1,...S.flat()),g=n.chat?.stats||{},b=(n.chat?.daily||[]).map(o=>({date:new Date(o.day).toLocaleDateString("en-GB",{month:"short",day:"numeric"}),sessions:Number(o.sessions)})),M=n.newsletter?.totals||{},V=(n.newsletter?.daily||[]).map(o=>({date:new Date(o.day).toLocaleDateString("en-GB",{month:"short",day:"numeric"}),subscribed:Number(o.subscribed),unsubscribed:-Number(o.unsubscribed)})),F=n.waitlist?.totals||{},v=(n.waitlist?.daily||[]).map(o=>({date:new Date(o.day).toLocaleDateString("en-GB",{month:"short",day:"numeric"}),entries:Number(o.entries)})),A={};return(n.ab_tests||[]).forEach(o=>{var P;A[P=o.test_id]||(A[P]={name:o.test_name,status:o.status,variants:[]}),A[o.test_id].variants.push(o)}),e.jsxs(ms,{defaultValue:"abandoned",className:"space-y-4",children:[e.jsxs(hs,{className:"flex-wrap h-auto",children:[e.jsxs(q,{value:"abandoned",children:[e.jsx(dr,{className:"h-4 w-4 mr-1"}),"Abandoned"]}),e.jsxs(q,{value:"funnel",children:[e.jsx(ur,{className:"h-4 w-4 mr-1"}),"Detailed funnel"]}),e.jsxs(q,{value:"value",children:[e.jsx(Vt,{className:"h-4 w-4 mr-1"}),"AOV & RPV"]}),e.jsxs(q,{value:"discounts",children:[e.jsx(Vt,{className:"h-4 w-4 mr-1"}),"Discount codes"]}),e.jsxs(q,{value:"heatmap",children:[e.jsx(jt,{className:"h-4 w-4 mr-1"}),"Time heatmap"]}),e.jsxs(q,{value:"chat",children:[e.jsx(mr,{className:"h-4 w-4 mr-1"}),"Chatbot"]}),e.jsxs(q,{value:"growth",children:[e.jsx(hr,{className:"h-4 w-4 mr-1"}),"Growth"]}),e.jsxs(q,{value:"ab",children:[e.jsx(xr,{className:"h-4 w-4 mr-1"}),"A/B tests"]}),e.jsxs(q,{value:"outbound",children:[e.jsx(pr,{className:"h-4 w-4 mr-1"}),"Outbound links"]})]}),e.jsxs(U,{value:"abandoned",className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsx(N,{children:e.jsxs(k,{className:"pt-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase",children:"Abandoned"}),e.jsx("p",{className:"text-2xl font-bold text-destructive",children:Z(p)})]})}),e.jsx(N,{children:e.jsxs(k,{className:"pt-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase",children:"Recovered"}),e.jsx("p",{className:"text-2xl font-bold text-emerald-500",children:Z(j)})]})}),e.jsx(N,{children:e.jsxs(k,{className:"pt-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase",children:"Recovery rate"}),e.jsx("p",{className:"text-2xl font-bold",children:Xe(O)})]})}),e.jsx(N,{children:e.jsxs(k,{className:"pt-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase",children:"Lost value"}),e.jsx("p",{className:"text-2xl font-bold text-amber-500",children:$e(Number(u.abandoned_value||0))})]})})]}),e.jsxs(N,{children:[e.jsx(D,{children:e.jsx(E,{className:"text-sm",children:"Abandoned vs recovered per day"})}),e.jsx(k,{children:e.jsx(le,{width:"100%",height:260,children:e.jsxs(Ct,{data:n.abandoned_daily||[],children:[e.jsx(je,{strokeDasharray:"3 3"}),e.jsx(he,{dataKey:"day",tick:{fontSize:11}}),e.jsx(oe,{tick:{fontSize:11}}),e.jsx(ce,{}),e.jsx(rt,{}),e.jsx(Ae,{dataKey:"abandoned",stackId:"a",fill:"hsl(var(--destructive))",name:"Abandoned"}),e.jsx(Ae,{dataKey:"recovered",stackId:"a",fill:"#10b981",name:"Recovered"})]})})})]}),e.jsxs(N,{children:[e.jsx(D,{children:e.jsx(E,{className:"text-sm",children:"Top products with drop-offs"})}),e.jsx(k,{children:(n.abandoned_products||[]).length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No drop-offs in the period."}):e.jsx("div",{className:"space-y-2",children:(n.abandoned_products||[]).map(o=>e.jsxs("div",{className:"flex items-center justify-between text-sm border-b border-border py-1.5",children:[e.jsx("span",{className:"text-foreground font-mono text-xs",children:o.product_id}),e.jsxs(K,{variant:"outline",children:[o.abandons," drop-offs"]})]},o.product_id))})})]})]}),e.jsx(U,{value:"funnel",className:"space-y-4",children:e.jsxs(N,{children:[e.jsx(D,{children:e.jsx(E,{className:"text-sm",children:"Detailed booking funnel"})}),e.jsx(k,{className:"space-y-3",children:T.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No funnel events. Ensure that view_item/add_to_cart/begin_checkout are being sent."}):T.map((o,P)=>{const I=w>0?o.n/w*100:0,L=P>0?T[P-1].n:o.n,C=L>0?o.n/L*100:100,J=P>0?L-o.n:0;return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between text-xs mb-1",children:[e.jsxs("span",{className:"font-medium text-foreground",children:[o.step,". ",o.label]}),e.jsxs("span",{className:"text-muted-foreground",children:[Z(o.n)," (",Xe(I)," of top)",P>0&&` · step ${Xe(C)} · ${Z(J)} drop-off`]})]}),e.jsx("div",{className:"h-8 bg-muted rounded overflow-hidden",children:e.jsx("div",{className:"h-full bg-gradient-to-r from-primary to-primary/60 flex items-center px-2 text-xs text-primary-foreground font-medium",style:{width:`${Math.max(I,2)}%`},children:o.v>0&&$e(o.v)})})]},o.step)})})]})}),e.jsx(U,{value:"value",className:"space-y-4",children:e.jsxs(N,{children:[e.jsx(D,{children:e.jsx(E,{className:"text-sm",children:"Average Order Value (AOV) & Revenue Per Visitor (RPV)"})}),e.jsx(k,{children:e.jsx(le,{width:"100%",height:300,children:e.jsxs(Zr,{data:m,children:[e.jsx(je,{strokeDasharray:"3 3"}),e.jsx(he,{dataKey:"date",tick:{fontSize:11}}),e.jsx(oe,{tick:{fontSize:11}}),e.jsx(ce,{formatter:o=>`${Z(Number(o))} £`}),e.jsx(rt,{}),e.jsx(wt,{type:"monotone",dataKey:"aov",stroke:"hsl(var(--primary))",name:"AOV (£)",strokeWidth:2}),e.jsx(wt,{type:"monotone",dataKey:"rpv",stroke:"#f59e0b",name:"RPV (£)",strokeWidth:2})]})})})]})}),e.jsx(U,{value:"discounts",children:e.jsxs(N,{children:[e.jsx(D,{children:e.jsx(E,{className:"text-sm",children:"Discount code performance"})}),e.jsx(k,{children:(n.discounts||[]).length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No redeemed codes in the peri
4od."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-left border-b border-border",children:[e.jsx("th",{className:"py-2",children:"Code"}),e.jsx("th",{children:"Type"}),e.jsx("th",{children:"Uses"}),e.jsx("th",{children:"Revenue"}),e.jsx("th",{children:"Discount"}),e.jsx("th",{children:"Commission"}),e.jsx("th",{children:"Status"})]})}),e.jsx("tbody",{children:(n.discounts||[]).map(o=>e.jsxs("tr",{className:"border-b border-border/50",children:[e.jsx("td",{className:"py-2 font-mono text-xs text-foreground",children:o.code}),e.jsx("td",{children:e.jsx(K,{variant:"outline",children:o.code_type})}),e.jsx("td",{children:Z(o.uses)}),e.jsx("td",{children:$e(Number(o.revenue))}),e.jsxs("td",{className:"text-blue-600",children:["−",$e(Number(o.discount_given))]}),e.jsx("td",{className:"text-emerald-500",children:$e(Number(o.commission))}),e.jsxs("td",{className:"text-xs text-muted-foreground",children:[o.paid_uses," paid · ",o.pending_uses," ongoing"]})]},o.code))})]})})})]})}),e.jsx(U,{value:"heatmap",children:e.jsxs(N,{children:[e.jsx(D,{children:e.jsx(E,{className:"text-sm",children:"Sessions per day of week × hour (London time)"})}),e.jsx(k,{className:"overflow-x-auto",children:e.jsxs("table",{className:"text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left pr-2"}),Array.from({length:24},(o,P)=>e.jsx("th",{className:"text-center font-normal text-muted-foreground px-1 w-7",children:P},P))]})}),e.jsx("tbody",{children:cn.map((o,P)=>e.jsxs("tr",{children:[e.jsx("td",{className:"pr-2 text-right text-muted-foreground font-medium",children:o}),Array.from({length:24},(I,L)=>{const C=S[P][L],J=C/R;return e.jsx("td",{className:"p-0.5",children:e.jsx("div",{className:"w-6 h-6 rounded text-[10px] flex items-center justify-center text-foreground",style:{backgroundColor:C===0?"hsl(var(--muted))":`hsla(var(--primary), ${.15+J*.85})`,color:J>.5?"white":void 0},title:`${o} ${L}:00, ${C} sessions`,children:C>0?C:""})},L)})]},P))})]})})]})}),e.jsxs(U,{value:"chat",className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsx(N,{children:e.jsxs(k,{className:"pt-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase",children:"Sessions"}),e.jsx("p",{className:"text-2xl font-bold",children:Z(g.total_sessions||0)})]})}),e.jsx(N,{children:e.jsxs(k,{className:"pt-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase",children:"Avg rating"}),e.jsx("p",{className:"text-2xl font-bold",children:g.avg_rating?`${Number(g.avg_rating).toFixed(1)} ★`:"-"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[g.rated_sessions||0," ratings"]})]})}),e.jsx(N,{children:e.jsxs(k,{className:"pt-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase",children:"Avg messages"}),e.jsx("p",{className:"text-2xl font-bold",children:g.avg_messages?Number(g.avg_messages).toFixed(1):"-"})]})}),e.jsx(N,{children:e.jsxs(k,{className:"pt-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase",children:"Avg duration"}),e.jsx("p",{className:"text-2xl font-bold",children:g.avg_duration?`${Math.round(Number(g.avg_duration)/60)}m`:"-"})]})})]}),e.jsxs(N,{children:[e.jsx(D,{children:e.jsx(E,{className:"text-sm",children:"Chatsessions per dag"})}),e.jsx(k,{children:e.jsx(le,{width:"100%",height:240,children:e.jsxs(kt,{data:b,children:[e.jsx(je,{strokeDasharray:"3 3"}),e.jsx(he,{dataKey:"date",tick:{fontSize:11}}),e.jsx(oe,{tick:{fontSize:11}}),e.jsx(ce,{}),e.jsx(it,{type:"monotone",dataKey:"sessions",stroke:"hsl(var(--primary))",fill:"hsl(var(--primary) / 0.2)"})]})})})]})]}),e.jsxs(U,{value:"growth",className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsx(N,{children:e.jsxs(k,{className:"pt-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase",children:"Active subscribers"}),e.jsx("p",{className:"text-2xl font-bold",children:Z(M.total_active||0)})]})}),e.jsx(N,{children:e.jsxs(k,{className:"pt-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase",children:"New in period"}),e.jsxs("p",{className:"text-2xl font-bold text-emerald-500",children:["+",Z(M.new_subs||0)]})]})}),e.jsx(N,{children:e.jsxs(k,{className:"pt-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase",children:"Unsubscribed"}),e.jsxs("p",{className:"text-2xl font-bold text-destructive",children:["−",Z(M.unsubs||0)]})]})}),e.jsx(N,{children:e.jsxs(k,{className:"pt-4",children:[e.jsxs("p",{className:"text-xs text-muted-foreground uppercase flex items-center gap-1",children:[e.jsx(fr,{className:"h-3 w-3"}),"Waitlist (new)"]}),e.jsx("p",{className:"text-2xl font-bold",children:Z(F.new_entries||0)}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[Z(F.total_entries||0)," total"]})]})})]}),e.jsxs(N,{children:[e.jsx(D,{children:e.jsx(E,{className:"text-sm",children:"Newsletter, net growth per day"})}),e.jsx(k,{children:e.jsx(le,{width:"100%",height:240,children:e.jsxs(Ct,{data:V,children:[e.jsx(je,{strokeDasharray:"3 3"}),e.jsx(he,{dataKey:"date",tick:{fontSize:11}}),e.jsx(oe,{tick:{fontSize:11}}),e.jsx(ce,{}),e.jsx(rt,{}),e.jsx(Ae,{dataKey:"subscribed",stackId:"a",fill:"#10b981",name:"New"}),e.jsx(Ae,{dataKey:"unsubscribed",stackId:"a",fill:"hsl(var(--destructive))",name:"Unsub"})]})})})]}),e.jsxs(N,{children:[e.jsx(D,{children:e.jsx(E,{className:"text-sm",children:"Sources for new subscribers"})}
4),e.jsx(k,{children:(n.newsletter?.sources||[]).length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No new subscribers."}):e.jsx("div",{className:"space-y-1.5",children:n.newsletter.sources.map(o=>e.jsxs("div",{className:"flex items-center justify-between text-sm border-b border-border py-1",children:[e.jsx("span",{className:"text-foreground",children:o.source}),e.jsx(K,{children:o.subscribers})]},o.source))})})]}),e.jsxs(N,{children:[e.jsx(D,{children:e.jsx(E,{className:"text-sm",children:"Waitlist per day"})}),e.jsx(k,{children:e.jsx(le,{width:"100%",height:200,children:e.jsxs(kt,{data:v,children:[e.jsx(je,{strokeDasharray:"3 3"}),e.jsx(he,{dataKey:"date",tick:{fontSize:11}}),e.jsx(oe,{tick:{fontSize:11}}),e.jsx(ce,{}),e.jsx(it,{type:"monotone",dataKey:"entries",stroke:"#f59e0b",fill:"#f59e0b33"})]})})})]})]}),e.jsx(U,{value:"ab",className:"space-y-4",children:Object.keys(A).length===0?e.jsx(N,{children:e.jsx(k,{className:"pt-6 text-center text-muted-foreground text-sm",children:"No A/B assignments in the period."})}):Object.entries(A).map(([o,P])=>{const I=P.variants.find(C=>C.is_control),L=I&&I.assignments>0?I.conversions/I.assignments:0;return e.jsxs(N,{children:[e.jsx(D,{children:e.jsxs(E,{className:"text-sm flex items-center justify-between",children:[e.jsx("span",{children:P.name}),e.jsx(K,{variant:P.status==="running"?"default":"outline",children:P.status})]})}),e.jsx(k,{children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-left border-b border-border",children:[e.jsx("th",{className:"py-2",children:"Variant"}),e.jsx("th",{children:"Visitors"}),e.jsx("th",{children:"Conv."}),e.jsx("th",{children:"CR"}),e.jsx("th",{children:"Lift"})]})}),e.jsx("tbody",{children:P.variants.map(C=>{const J=C.assignments>0?C.conversions/C.assignments:0,Q=L>0&&!C.is_control?(J-L)/L*100:null;return e.jsxs("tr",{className:"border-b border-border/50",children:[e.jsxs("td",{className:"py-2 text-foreground",children:[C.variant_name," ",C.is_control&&e.jsx(K,{variant:"outline",className:"ml-1 text-xs",children:"Control"})]}),e.jsx("td",{children:Z(C.assignments)}),e.jsx("td",{children:Z(C.conversions)}),e.jsx("td",{children:Xe(J*100)}),e.jsx("td",{className:Q===null?"":Q>0?"text-emerald-500":"text-destructive",children:Q===null?"-":`${Q>0?"+":""}${Q.toFixed(1)}%`})]},C.variant_id)})})]})})]},o)})}),e.jsx(U,{value:"outbound",children:e.jsxs(N,{children:[e.jsx(D,{children:e.jsx(E,{className:"text-sm",children:"Most clicked outbound links"})}),e.jsx(k,{children:(n.outbound||[]).length===0?e.jsxs("p",{className:"text-sm text-muted-foreground",children:["No outbound clicks. Log an event named ",e.jsx("code",{children:"outbound_click"})," with the ",e.jsx("code",{children:"url"})," field on external links to see data here."]}):e.jsx("div",{className:"space-y-1.5",children:n.outbound.map((o,P)=>e.jsxs("div",{className:"flex items-center justify-between text-sm border-b border-border py-1.5",children:[e.jsx("a",{href:o.url,target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline truncate flex-1 mr-3",children:o.url}),e.jsx(K,{children:Z(o.clicks)})]},P))})})]})})]})},un=Qs("relative w-full rounded-lg border p-4 [&>svg~*]:pl-7 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground",{variants:{variant:{default:"bg-background text-foreground",destructive:"border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive"}},defaultVariants:{variant:"default"}}),Ds=f.forwardRef(({className:t,variant:s,...a},r)=>e.jsx("div",{ref:r,role:"alert",className:Ve(un({variant:s}),t),...a}));Ds.displayName="Alert";const mn=f.forwardRef(({className:t,...s},a)=>e.jsx("h5",{ref:a,className:Ve("mb-1 font-medium leading-none tracking-tight",t),...s}));mn.displayName="AlertTitle";const Es=f.forwardRef(({className:t,...s},a)=>e.jsx("div",{ref:a,className:Ve("text-sm [&_p]:leading-relaxed",t),...s}));Es.displayName="AlertDescription";const G=t=>new Intl.NumberFormat("en-GB").format(Math.round(Number(t)||0)),vt=(t,s)=>s>0?t/s*100:0,is=({value:t})=>e.jsx("span",{className:"text-[11px] font-mono leading-relaxed break-words",children:t.split(" → ").map((s,a,r)=>e.jsxs("span",{children:[e.jsx("span",{className:"px-1.5 py-0.5 rounded bg-muted inline-block my-0.5",children:s}),a<r.length-1&&e.jsx("span",{className:"text-muted-foreground mx-1",children:"→"})]},a))}),hn=({from:t,to:s})=>{const[a,r]=f.useState(null),[n,l]=f.useState(null),[i,h]=f.useState(!0),[u,p]=f.useState(null);f.useEffect(()=>{let v=!0;return(async()=>{h(!0);const{data:A,error:o}=await de.rpc("get_landing_to_booking",{p_from:t.toISOString(),p_to:s.toISOString()});v&&(o?l(o.message):(r(A),l(null)),h(!1))})(),()=>{v=!1}},[t,s]);const j=f.useMemo(()=>(a?.columns||[]).map(A=>({...A,sessions:Number(A.sessions),reached:Number(A.reached),checkouts:Number(A.checkouts),purchases:Number(A.purchases),bounced:Number(A.bounced),rate:vt(Number(A.reached),Number(A.sessions))})),[a]);if(i&&!a)return e.jsx(N,{children:e.jsx(k,{className:"pt-6 text-sm text-muted-foreground",children:"Loading paths to booking page..."})});if(n)return e.jsx(N,{children:e.jsx(k,{className:"pt-6 text-sm text-destructive",children:n})});if(!a)return null;const _=a.totals,O=a.meta||{all_sessions:0,server_purchases:0},T=Number(_.sessions_excl_direct||0),w=Number(_.reached_excl_direct||0),m=j.filter(v=>!v.booking_entry),S=m.filter(v=>v.sessions>=20).sort((v,A)=>A.rate-v.rate)[0],R=m.filter(v=>v.sessions>=20).sort((v,A)=>v.rate-A.rate)[0],g=j.find(v=>v.path===u)||null,b=g?a.paths.filter(v=>v.entry===g.path).slice(0,12):[],M=g?a.drop_exits.filter(v=>v.entry===g.path).slice(0,12):[],V=vt(Number(_.sessions),Number(O.all_sessions)),F=({label:v,value:A,sub:o,tone:P})=>e.jsxs("div",{className:"rounded-xl border border-border bg-card p-4",children:[e.jsx("p",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:v}),e.jsx("p",{className:`text-2xl font-bold mt-1 truncate ${P||""}`,children:A}),o&&e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:o})]});return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-3",children:[e.jsx(F,{label:"Sessions with entry page",value:G(Number(_.sessions)),sub:`av ${G(Number(O.all_sessions))} sessions total (${V.toFixed(0)}% have page views)`}),e.jsx(F,{label:"Reached booking page",value:G(w),tone:"text-emerald-500",sub:`${vt(w,T).toFixed(1)}% av ${G(T)} who entered via a page other than /book`}),e.jsx(F,{label:"Best entry",value:S?S.path:"-",sub:S?`${S.rate.toFixed(1)}% reach /book · ${G(S.sessions)} sessions`:"insufficient data"}),e.jsx(F,{label:"Weakest entry",value:R?R.path:"-",tone:"text-destructive",sub:R?`${R.rate.toFixed(1)}% reach /book · ${G(R.sessions)} sessions`:"insufficient data"})]}),e.jsxs(Ds,{children:[e.jsx(bs,{className:"h-4 w-4"}),e.jsxs(Es,{className:"text-xs leading-relaxed",children:["How the figures are calculated: a session is counted on the ",e.jsx("strong",{children:"first page"})," it opened. “Reached /book” = the same session opened the booking page later. Sessions that ",e.jsx("strong",{children:"landed directly on /book"})," are shown separately (they have 100% by definition and are not included in the target figure above)."," ",V<90&&e.jsxs(e.Fragment,{children:["Only ",V.toFixed(0),"% of all sessions have page views, the rest are usually bots/preloads that leave before the page is measured, so the base here is lower than 
4in Overview."," "]}),"Purchases are measured in the browser (",G(Number(_.purchases))," in the period); the server side has"," ",G(Number(O.server_purchases))," confirmed purchases, as payment takes place on Roller's domain and not can always be linked to a session."]})]}),e.jsxs(N,{children:[e.jsxs(D,{children:[e.jsxs(E,{className:"text-sm flex items-center gap-2",children:[e.jsx(Ie,{className:"h-4 w-4"})," Entry pages, click a box for its full analysis"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Each box is a page the visitor arrived on. The figure in the middle is the percentage who made it all the way to bokningssidan."})]}),e.jsxs(k,{children:[e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-6 gap-2",children:j.map(v=>{const A=u===v.path;return e.jsxs("button",{type:"button",onClick:()=>p(A?null:v.path),className:`min-w-0 rounded-xl border p-2.5 text-left flex flex-col gap-1 transition-colors ${A?"border-primary bg-primary/10":"border-border bg-card hover:bg-muted/50"}`,children:[e.jsx("p",{className:"font-mono text-[10px] truncate",children:v.path}),v.booking_entry?e.jsx(K,{variant:"outline",className:"w-fit text-[9px] px-1 py-0",children:"directly on /book"}):e.jsxs("p",{className:"text-[10px] text-muted-foreground",children:[G(v.sessions)," sessions"]}),e.jsxs("div",{className:"flex items-baseline justify-between gap-1",children:[e.jsx("p",{className:`text-xl font-bold leading-none ${v.booking_entry?"text-muted-foreground":v.rate>=30?"text-emerald-500":v.rate>=10?"":"text-destructive"}`,children:v.booking_entry?"-":`${v.rate.toFixed(0)}%`}),e.jsx("p",{className:"text-[10px] text-muted-foreground truncate",children:v.booking_entry?`${G(v.sessions)} sess.`:`${G(v.reached)} → /boka`})]}),e.jsx("div",{className:"w-full h-1 bg-muted rounded-full overflow-hidden",children:e.jsx("div",{className:`h-1 rounded-full ${v.booking_entry?"bg-muted-foreground/40":"bg-primary"}`,style:{width:`${Math.min(v.booking_entry?100:v.rate,100)}%`}})})]},v.path)})}),j.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground py-6 text-center",children:"No data in the period."})]})]}),g&&e.jsxs(N,{className:"border-primary/50",children:[e.jsxs(D,{className:"flex flex-row items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx(E,{className:"text-sm font-mono truncate",children:g.path}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:g.booking_entry?"Visitors landed directly on the booking page, the goal was achieved on arrival.":`${G(g.reached)} av ${G(g.sessions)} proceeded to the booking page (${g.rate.toFixed(1)}%).`})]}),e.jsx("button",{type:"button",onClick:()=>p(null),className:"text-muted-foreground hover:text-foreground",children:e.jsx(gr,{className:"h-4 w-4"})})]}),e.jsxs(k,{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-3",children:[e.jsx(F,{label:"Sessioner",value:G(g.sessions)}),e.jsx(F,{label:"Reached /book",value:G(g.reached),tone:"text-emerald-500"}),e.jsx(F,{label:"Dropped off",value:G(g.sessions-g.reached),tone:"text-destructive"}),e.jsx(F,{label:"Opened checkout",value:G(g.checkouts)}),e.jsx(F,{label:"Pages before /book",value:Number(g.avg_steps_to_book).toFixed(1),sub:"average, incl. booking page"}),e.jsx(F,{label:"Avg. time in session",value:`${Math.round(Number(g.avg_time))}s`,sub:`${G(g.bounced)} saw only one page`})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"text-xs font-medium mb-2 flex items-center gap-1.5",children:[e.jsx(yt,{className:"h-3.5 w-3.5"})," The path to the booking page"]}),b.length?e.jsx("div",{className:"space-y-2",children:b.map((v,A)=>e.jsxs("div",{className:"flex items-start justify-between gap-3 py-1.5 border-b border-border/60 last:border-0",children:[e.jsx(is,{value:v.path}),e.jsx(K,{variant:"secondary",className:"shrink-0",children:G(Number(v.sessions))})]},A))}):e.jsx("p",{className:"text-xs text-muted-foreground",children:"No one reached the booking page from this entry in the peri
4od."})]}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-xs font-medium mb-2 flex items-center gap-1.5",children:[e.jsx(js,{className:"h-3.5 w-3.5"})," Last page for those who did not reach the goal"]}),M.length?e.jsx("div",{className:"space-y-1.5",children:M.map((v,A)=>e.jsxs("div",{className:"flex items-center justify-between gap-3 py-1.5 border-b border-border/60 last:border-0",children:[e.jsx("span",{className:"text-xs font-mono truncate flex-1",children:v.path}),e.jsx(K,{variant:"outline",className:"shrink-0",children:G(Number(v.sessions))})]},A))}):e.jsx("p",{className:"text-xs text-muted-foreground",children:"Everyone reached the goal."})]})]})]})]}),e.jsxs(N,{children:[e.jsxs(D,{children:[e.jsx(E,{className:"text-sm",children:"Most common paths to the booking page (all entries)"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Exact page sequence from entry to /book."})]}),e.jsx(k,{children:e.jsx("div",{className:"space-y-2 max-h-[420px] overflow-auto",children:a.paths.length?a.paths.slice(0,30).map((v,A)=>e.jsxs("div",{className:"flex items-start justify-between gap-3 py-2 border-b border-border last:border-0",children:[e.jsx(is,{value:v.path}),e.jsxs(K,{variant:"secondary",className:"shrink-0",children:[G(Number(v.sessions))," sessions"]})]},A)):e.jsx("p",{className:"text-sm text-muted-foreground py-4 text-center",children:"No paths to the booking page in the period."})})})]})]})},xn=[{id:"all",label:"All visit",hint:"All sessions in the period"},{id:"bounce",label:"Left immediately",hint:"One page, under 10 seconds"},{id:"engaged",label:"Engaged",hint:"Multiple pages or at least 10 seconds"},{id:"cta_drop",label:"Clicked book, never arrived",hint:"Booking click but no booking page"},{id:"bookpage_drop",label:"Stuck on booking page",hint:"Was on /book but did not start payment"},{id:"checkout_drop",label:"Dropped out during payment",hint:"Opened payment without completing"},{id:"converted",label:"Converted",hint:"Completed a purchase"},{id:"with_replay",label:"Has video recording",hint:"Sessions with session replay"}],os=t=>new Intl.NumberFormat("en-GB").format(Math.round(t||0)),ls=t=>t>=60?`${Math.floor(t/60)}m ${t%60}s`:`${t||0}s`,bt=t=>new Date(t).toLocaleString("en-GB",{dateStyle:"short",timeStyle:"medium"}),pn=t=>{if(t.utm_source)return`${t.utm_source}${t.utm_medium?` / ${t.utm_medium}`:""}`;if(t.referrer)try{return new URL(t.referrer).hostname}catch{return t.referrer}return"Direct"},fn=t=>t==="Converted"?"bg-primary/15 text-primary border-primary/30":t.startsWith("Left immediately")?"bg-destructive/10 text-destructive border-destructive/30":"bg-muted text-muted-foreground border-border",gn=({from:t,to:s})=>{const[a,r]=f.useState(null),[n,l]=f.useState(!0),[i,h]=f.useState(null),[u,p]=f.useState("all"),[j,_]=f.useState(""),[O,T]=f.useState(""),[w,m]=f.useState(0),S=50,[R,g]=f.useState(null),[b,M]=f.useState(null),[V,F]=f.useState(!1),v=f.useCallback(async()=>{l(!0);const{data:o,error:P}=await de.rpc("get_visitor_sessions",{p_from:t.toISOString(),p_to:s.toISOString(),p_limit:S,p_offset:w*S,p_filter:u,p_search:O||null});P?(h(P.message),r(null)):(r(o),h(null)),l(!1)},[t,s,w,u,O]);f.useEffect(()=>{v()},[v]),f.useEffect(()=>{m(0)},[u,O,t,s]),f.useEffect(()=>{if(!R){M(null);return}let o=!0;return(async()=>{F(!0);const{data:P}=await de.rpc("get_visitor_session_detail",{p_session_id:R});o&&(M(P),F(!1))})(),()=>{o=!1}},[R]);const A=f.useMemo(()=>Math.max(1,Math.ceil((a?.total||0)/S)),[a]);return e.jsxs(e.Fragment,{children:[e.jsxs(N,{children:[e.jsxs(D,{children:[e.jsxs(E,{className:"text-sm flex items-center gap-2",children:[e.jsx(tt,{className:"h-4 w-4"})," Visitor logs, exact navigation per person"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Each row is a visit. Click on the row to see the full timeline: every page, every click and exactly where the visitor left. Filter by drop-off type to understand why they did not book."})]}),e.jsxs(k,{className:"space-y-4",children:[a?.outcomes?.length?e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-2",children:a.outcomes.map(o=>e.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md border border-border px-3 py-2",children:[e.jsx("span",{className:"text-xs",children:o.k}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsx(K,{variant:"secondary",children:os(Number(o.v))}),e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:[a.grand_total>0?Math.round(Number(o.v)/a.grand_total*100):0,"%"]})]})]},o.k))}):null,e.jsx("div",{className:"flex flex-wrap gap-2",children:xn.map(o=>e.jsx(te,{size:"sm",variant:u===o.id?"default":"outline",onClick:()=>p(o.id),title:o.hint,children:o.label},o.id))}),e.jsxs("form",{className:"flex gap-2",onSubmit:o=>{o.preventDefault(),T(j.trim())},children:[e.jsx(Yr,{value:j,onChange:o=>_(o.target.value),placeholder:"Search by page (e.g. /book), source or visitor ID"}),e.jsxs(te,{type:"submit",variant:"outline",className:"gap-2 shrink-0",children:[e.jsx(vr,{className:"h-4 w-4"})," Search"]})]}),i&&e.jsx("p",{className:"text-sm text-destructive",children:i}),n&&!a&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground py-6 justify-center",children:[e.jsx(Be,{className:"h-4 w-4 animate-spin"})," Fetching visitor logs..."]}),e.jsxs("div",{className:"space-y-2",children:[a?.sessions?.length===0&&!n&&e.jsx("p",{className:"text-sm text-muted-foreground text-center py-6",children:"No visit match the filter."}),a?.sessions?.map(o=>e.jsx("button",{onClick:()=>g(o.session_id),className:"w-full text-left rounded-lg border border-border p-3 hover:bg-muted/50 transition-colors",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-1",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:bt(o.started_at)}),e.jsx(K,{variant:"outline",className:`text-[10px] ${fn(o.outcome)}`,children:o.outcome}),o.recording_id&&e.jsxs(K,{variant:"secondary",className:"text-[10px] gap-1",children:[e.jsx(Kt,{className:"h-3 w-3"}),"Video"]})]}),e.jsx("div",{className:"text-xs font-mono truncate",children:o.journey||o.landing||"(no pageview)"}),e.jsxs("div",{className:"flex flex-wrap gap-3 mt-1 text-[11px] text-muted-foreground",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(br,{className:"h-3 w-3"}),o.pageviews," pages"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(ys,{className:"h-3 w-3"}),ls(o.total_time)]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(jr,{className:"h-3 w-3"}),o.events," events"]}),e.jsx("span",{children:pn(o)}),e.jsx("span",{children:[o.device_type,o.browser,o.city||o.country].filter(
4Boolean).join(" · ")})]})]}),e.jsx(yr,{className:"h-4 w-4 text-muted-foreground shrink-0 mt-1"})]})},o.session_id))]}),a&&a.total>S&&e.jsxs("div",{className:"flex items-center justify-between pt-2",children:[e.jsxs("span",{className:"text-xs text-muted-foreground",children:[os(a.total)," visit · page ",w+1," of ",A]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(te,{size:"sm",variant:"outline",disabled:w===0,onClick:()=>m(o=>o-1),children:"Previous"}),e.jsx(te,{size:"sm",variant:"outline",disabled:w+1>=A,onClick:()=>m(o=>o+1),children:"Next"})]})]})]})]}),e.jsx(Jr,{open:!!R,onOpenChange:o=>!o&&g(null),children:e.jsxs(Xr,{className:"max-w-3xl max-h-[85vh] overflow-auto",children:[e.jsx(Qr,{children:e.jsx(ea,{className:"text-base",children:"Visit timeline"})}),V&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground py-6 justify-center",children:[e.jsx(Be,{className:"h-4 w-4 animate-spin"})," Fetching timeline..."]}),b?.session&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-2 text-xs",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Start:"})," ",bt(b.session.started_at)]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Device:"})," ",[b.session.device_type,b.session.browser,b.session.os].filter(Boolean).join(" · ")||"-"]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Location:"})," ",[b.session.city,b.session.country].filter(Boolean).join(", ")||"-"]}),e.jsxs("div",{className:"col-span-2 sm:col-span-3 break-all",children:[e.jsx("span",{className:"text-muted-foreground",children:"Source:"})," ",b.session.utm_source||b.session.referrer||"Direct",b.session.utm_campaign?` · campaign: ${b.session.utm_campaign}`:""]}),e.jsxs("div",{className:"col-span-2 sm:col-span-3 text-muted-foreground break-all",children:["Visitor ID: ",b.session.visitor_id]})]}),b.recording&&e.jsxs("div",{className:"rounded-md border border-border p-3 text-xs flex items-center gap-2",children:[e.jsx(Kt,{className:"h-4 w-4 text-primary"}),"Videoinspelning finns for this visit (",Math.round((b.recording.duration_ms||0)/1e3),"s) - play it back under Heatmaps → Session Recordings."]}),e.jsxs("div",{className:"space-y-1",children:[b.timeline.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground py-4 text-center",children:"No events recorded."}),b.timeline.map((o,P)=>e.jsxs("div",{className:"flex gap-3 items-start border-l-2 border-border pl-3 py-1.5",children:[e.jsx("span",{className:"text-[10px] text-muted-foreground w-16 shrink-0 mt-0.5",children:new Date(o.at).toLocaleTimeString("en-GB")}),e.jsx(K,{variant:o.kind==="pageview"?"default":o.kind==="event"?"secondary":"outline",className:"text-[10px] shrink-0",children:o.kind==="pageview"?"Page":o.kind==="event"?"Event":"Click"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-xs font-mono break-all",children:o.label}),o.kind==="pageview"&&e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[ls(Number(o.meta?.time_on_page)||0)," on the page · scroll ",Number(o.meta?.scroll_depth)||0,"%"]}),o.kind!=="pageview"&&Object.keys(o.meta||{}).length>0&&e.jsx("div",{className:"text-[10px] text-muted-foreground break-all",children:JSON.stringify(o.meta)})]})]},P))]}),b.other_sessions?.length>0&&e.jsxs("div",{className:"text-xs",children:[e.jsxs("p",{className:"text-muted-foreground mb-1",children:["The same visitor has ",b.other_sessions.length," other visits:"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:b.other_sessions.map(o=>e.jsx(te,{size:"sm",variant:"outline",className:"h-7 text-[11px]",onClick:()=>g(o.id),children:bt(o.started_at)},o.id))})]})]})]})})]})};var pt="Popover",[$s,si]=er(pt,[xs]),Ke=xs(),[vn,pe]=$s(pt),Is=t=>{const{__scopePopover:s,children:a,open:r,defaultOpen:n,onOpenChange:l,modal:i=!1}=t,h=Ke(s),u=f.useRef(null),[p,j]=f.useState(!1),[_,O]=ar({prop:r,defaultProp:n??!1,onChange:l,caller:pt});return e.jsx(nr,{...h,children:e.jsx(vn,{scope:s,contentId:ir(),triggerRef:u,open:_,onOpenChange:O,onOpenToggle:f.useCallback(()=>O(T=>!T),[O]),hasCustomAnchor:p,onCustomAnchorAdd:f.useCallback(()=>j(!0),[]),onCustomAnchorRemove:f.useCallback(()=>j(!1),[]),modal:i,children:a})})};Is.displayName=pt;var Ls="PopoverAnchor",bn=f.forwardRef((t,s)=>{const{__scopePopover:a,...r}=t,n=pe(Ls,a),l=Ke(a),{onCustomAnchorAdd:i,onCustomAnchorRemove:h}=n;return f.useEffect(()=>(i(),()=>h()),[i,h]),e.jsx(ps,{...l,...r,ref:s})});bn.displayName=Ls;var Ms="PopoverTrigger",Fs=f.forwardRef((t,s)=>{const{__scopePopover:a,...r}=t,n=pe(Ms,a),l=Ke(a),i=fs(s,n.triggerRef),h=e.jsx(gs.button,{type:"button","aria-haspopup":"dialog","aria-expanded":n.open,"aria-controls":n.contentId,"data-state":zs(n.open),...r,ref:i,onClick:Le(t.onClick,n.onOpenToggle)});return n.hasCustomAnchor?h:e.jsx(ps,{asChild:!0,...l,children:h})});Fs.displayName=Ms;var It="PopoverPortal",[jn,yn]=$s(It,{forceMount:void 0}),Bs=t=>{const{__scopePopover:s,forceMount:a,children:r,container:n}=t,l=pe(It,s);return e.jsx(jn,{scope:s,forceMount:a,children:e.jsx(vs,{present:a||l.open,children:e.jsx(or,{asChild:!0,container:n,children:r})})})};Bs.displayName=It;var De="PopoverContent",Vs=f.forwardRef((t,s)=>{const a=yn(De,t.__scopePopover),{forceMount:r=a.forceMount,...n}=t,l=pe(De,t.__scopePopover);return e.jsx(vs,{present:r||l.open,children:l.modal?e.jsx(wn,{...n,ref:s}):e.jsx(kn,{...n,ref:s})})});Vs.displayName=De;var Nn=lr("PopoverContent.RemoveScroll"),wn=f.forwardRef((t,s)=>{const a=pe(De,t.__scopePopover),r=f.useRef(null),n=fs(s,r),l=f.useRef(!1);return f.useEffect(()=>{const i=r.current;if(i)return sa(i)},[]),e.jsx(ra,{as:Nn,allowPinchZoom:!0,children:e.jsx(Ks,{...t,ref:n,trapFocus:a.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:Le(t.onCloseAutoFocus,i=>{i.preventDefault(),l.current||a.triggerRef.current?.focus()}),onPointerDownOutside:Le(t.onPointerDownOutside,i=>{const h=i.detail.originalEvent,u=h.button===0&&h.ctrlKey===!0,p=h.button===2||u;l.current=p},{checkForDefaultPrevented:!1}),onFocusOutside:Le(t.onFocusOutside,i=>i.preventDefault(),{checkForDefaultPrevented:!1})})})}),kn=f.forwardRef((t,s)=>{const a=pe(De,t.__scopePopover),r=f.useRef(!1),n=f.useRef(!1);return e.jsx(Ks,{...t,ref:s,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:l=>{t.onCloseAutoFocus?.(l),l.defaultPrevented||(r.current||a.triggerRef.current?.focus(),l.preventDefault()),r.current=!1,n.current=!1},onInteractOutside:l=>{t.onInteractOutside?.(l),l.defaultPrevented||(r.current=!0,l.detail.originalEvent.type==="pointerdown"&&(n.current=!0));const i=l.target;a.triggerRef.current?.contains(i)&&l.preventDefault(),l.detail.originalEvent.type==="focusin"&&n.current&&l.preventDefault()}})}),Ks=f.forwardRef((t,s)=>{const{__scopePopover:a,trapFocus:r,onOpenAutoFocus:n,onCloseAutoFocus:l,disableOutsidePointerEvents:i,onEscapeKeyDown:h,onPointerDownOutside:u,onFocusOutside:p,onInteractOutside:j,..._}
4=t,O=pe(De,a),T=Ke(a);return aa(),e.jsx(na,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:n,onUnmountAutoFocus:l,children:e.jsx(tr,{asChild:!0,disableOutsidePointerEvents:i,onInteractOutside:j,onEscapeKeyDown:h,onPointerDownOutside:u,onFocusOutside:p,onDismiss:()=>O.onOpenChange(!1),children:e.jsx(sr,{"data-state":zs(O.open),role:"dialog",id:O.contentId,...T,..._,ref:s,style:{..._.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}})})})}),Gs="PopoverClose",_n=f.forwardRef((t,s)=>{const{__scopePopover:a,...r}=t,n=pe(Gs,a);return e.jsx(gs.button,{type:"button",...r,ref:s,onClick:Le(t.onClick,()=>n.onOpenChange(!1))})});_n.displayName=Gs;var An="PopoverArrow",Sn=f.forwardRef((t,s)=>{const{__scopePopover:a,...r}=t,n=Ke(a);return e.jsx(rr,{...n,...r,ref:s})});Sn.displayName=An;function zs(t){return t?"open":"closed"}var Pn=Is,On=Fs,Rn=Bs,qs=Vs;const Tt=Pn,Dt=On,dt=f.forwardRef(({className:t,align:s="center",sideOffset:a=4,...r},n)=>e.jsx(Rn,{children:e.jsx(qs,{ref:n,align:s,sideOffset:a,className:Ve("z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",t),...r})}));dt.displayName=qs.displayName;const cs=[{key:"today",label:"Today",build:()=>({from:ne(new Date),to:new Date})},{key:"yesterday",label:"Yesterday",build:()=>({from:ne(me(new Date,1)),to:At(me(new Date,1))})},{key:"3d",label:"Last 3 days",build:()=>({from:ne(me(new Date,2)),to:new Date})},{key:"7d",label:"7 days",build:()=>({from:ne(me(new Date,6)),to:new Date})},{key:"14d",label:"14 days",build:()=>({from:ne(me(new Date,13)),to:new Date})},{key:"30d",label:"30 days",build:()=>({from:ne(me(new Date,29)),to:new Date})},{key:"90d",label:"90 days",build:()=>({from:ne(me(new Date,89)),to:new Date})}];function nt(t,s,a,r,n){if(a==="none")return{compareFrom:void 0,compareTo:void 0};if(a==="custom")return{compareFrom:r,compareTo:n};if(a==="year")return{compareFrom:Ht(t,1),compareTo:Ht(s,1)};const l=s.getTime()-t.getTime();return{compareFrom:new Date(t.getTime()-l),compareTo:t}}const we=t=>ma(t,"d MMM yyyy",{locale:_t});function Cn({value:t,onChange:s}){const[a,r]=f.useState(!1),[n,l]=f.useState(!1),[i,h]=f.useState({from:t.from,to:t.to}),[u,p]=f.useState(t.compareFrom?{from:t.compareFrom,to:t.compareTo}:void 0),j=m=>{const S=cs.find(M=>M.key===m);if(!S)return;const{from:R,to:g}=S.build(),b=nt(R,g,t.compareMode,t.compareFrom,t.compareTo);s({from:R,to:g,compareMode:t.compareMode,...b,presetLabel:S.label})},_=()=>{if(!i?.from||!i?.to)return;const m=ne(i.from),S=At(i.to),R=nt(m,S,t.compareMode,t.compareFrom,t.compareTo);s({from:m,to:S,compareMode:t.compareMode,...R,presetLabel:`${we(m)}, ${we(S)}`}),r(!1)},O=m=>{if(m==="custom"){s({...t,compareMode:m});return}const S=nt(t.from,t.to,m);s({...t,compareMode:m,...S})},T=()=>{!u?.from||!u?.to||(s({...t,compareMode:"custom",compareFrom:ne(u.from),compareTo:At(u.to)}),l(!1))},w=ua(t.to,t.from)+1;return e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("div",{className:"flex flex-wrap gap-1",children:[cs.map(m=>e.jsx(te,{variant:t.presetLabel===m.label?"default":"outline",size:"sm",onClick:()=>j(m.key),children:m.label},m.key)),e.jsxs(Tt,{open:a,onOpenChange:r,children:[e.jsx(Dt,{asChild:!0,children:e.jsxs(te,{variant:t.presetLabel.includes("-")?"default":"outline",size:"sm",className:Ve("gap-1"),children:[e.jsx(jt,{className:"h-3.5 w-3.5"}),"Custom"]})}),e.jsxs(dt,{className:"w-auto p-0 pointer-events-auto",align:"end",children:[e.jsx(Wt,{mode:"range",selected:i,onSelect:h,numberOfMonths:2,locale:_t,className:"p-3 pointer-events-auto"}),e.jsxs("div",{className:"p-3 border-t flex justify-between items-center",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:i?.from&&i?.to?`${we(i.from)}, ${we(i.to)}`:"Select period"}),e.jsx(te,{size:"sm",onClick:_,disabled:!i?.from||!i?.to,children:"Apply"})]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 ml-auto",children:[e.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:"Compare with:"}),e.jsxs(ia,{value:t.compareMode,onValueChange:m=>O(m),children:[e.jsx(oa,{className:"w-[200px] h-9",children:e.jsx(la,{})}),e.jsxs(ca,{children:[e.jsxs(Je,{value:"previous",children:["Previous period (",w,"d)"]}),e.jsx(Je,{value:"year",children:"Same period last year"}),e.jsx(Je,{value:"custom",children:"Custom period"}),e.jsx(Je,{value:"none",children:"No comparison"})]})]}),t.compareMode==="custom"&&e.jsxs(Tt,{open:n,onOpenChange:l,children:[e.jsx(Dt,{asChild:!0,children:e.jsxs(te,{variant:"outline",size:"sm",className:"gap-1",children:[e.jsx(jt,{className:"h-3.5 w-3.5"}),t.compareFrom&&t.compareTo?`${we(t.compareFrom)}, ${we(t.compareTo)}`:"Select comparison"]})}),e.jsxs(dt,{className:"w-auto p-0 pointer-events-auto",align:"end",children:[e.jsx(Wt,{mode:"range",selected:u,onSelect:p,numberOfMonths:2,locale:_t,className:"p-3 pointer-events-auto"}),e.jsx("div",{className:"p-3 border-t flex justify-end",children:e.jsx(te,{size:"sm",onClick:T,disabled:!u?.from||!u?.to,children:"Apply"})})]})]})]})]})}function Tn(){const t=new Date,s=ne(me(t,6)),a=nt(s,t,"previous");return{from:s,to:t,compareMode:"previous",...a,presetLabel:"7 dagar"}}
4const Dn={"Unique visitors":"The number of individual people who have visited the website during the period. The same person returning several times is only counted once.",Sessions:"Total number of visits to the website. One person can account for several sessions. A session ends after 30 minutes of inactivity.","Page views":"Total number of pages viewed. If a visitor looks at five pages, it counts as five page views.","Engagement rate":"Percentage of sessions where the visitor actually did something: stayed longer than 10 seconds, viewed multiple pages, or performed an event (e.g. clicked Book).","Engagement­rate":"Percentage of sessions where the visitor actually did something: stayed longer than 10 seconds, viewed multiple pages, or performed an event (e.g. clicked Book).","Average session duration":"How long an average visit lasts. Calculated per session (not total for all visitors) and capped at 30 minutes to prevent open tabs from skewing the average.","Average­session duration":"How long an average visit lasts. Calculated per session (not total for all visitors) and capped at 30 minutes to prevent open tabs from skewing the average.","Pages / session":"How many pages a visitor views on average per visit. A higher number indicates more curious visitors.","Bounce rate":"Percentage of visits where the person only viewed one page and left without doing anything. A high number often means the page did not match expectations.","New / returning":"Number of sessions from first-time visitors compared to sessions from people who have visited before.","New sessions":"Visits from people who have never been to the website before.",Returning:"Visits from people who have been here before.","Return rate":"Percentage of all sessions that come from returning visitors.",Revenue:"Total value of bookings tracked as purchases during the period (in pounds).",Purchases:"Number of completed bookings/purchases tracked during the period.","Average order value":"Average value per purchase: revenue divided by number of purchases.",AOV:"Average Order Value, average value per purchase (revenue divided by number of purchases).","Conv. rate":"Conversion rate: percentage of all sessions that resulted in a purchase. 1% means 1 out of 100 visits became a booking.","Traffic & conversion over time":"Daily development: how many visits and page views you received, and how many purchases were made.",Channels:"Where the traffic comes from at a high level: organic (Google), direct (typed the address), social media, paid advertising, or referral from another site.","Source / Medium":"More detailed breakdown of the traffic source, e.g. google/organic or instagram/social.","Campaigns (UTM)":"Traffic from links marked with campaign codes, e.g. newsletters or advertisements.","Landing pages":"The first page the visitor arrived on. Shows which pages Google and social media send people to.","Pages, views, time, scroll, bounce"
4:"How each individual page performs: number of views, how long people stay, how far down they scroll, and how often they leave immediately.","Custom events":"Specific events we measure, e.g. clicks on Book buttons or steps in the booking flow.","Revenue over time":"How revenue is distributed day by day during the period.","Details per page":"Filter the entire analysis to a specific page to see how that specific page performs.","Entry pages":"Pages where visitors start their visit.","Exit pages":"Pages where visitors leave the website. Many drop-offs on a page can mean something is missing or unclear there.","Most common navigation paths":"The most frequent jumps between two pages, shows how people actually move on the site.","Complete customer journeys":"Complete click paths from the first to the last page in a visit.","Cohort, percentage returning per week":"Of the visitors who came a certain week: what percentage came back in the following weeks.",Countries:"Which countries visitors are located in, useful for seeing the extent of international traffic."},Y=({label:t,text:s,className:a=""})=>{const r=s??(t?Dn[t]:void 0);return r?e.jsxs(Tt,{children:[e.jsx(Dt,{asChild:!0,children:e.jsx("button",{type:"button","aria-label":`Explanation: ${t??"metric"}`,onClick:n=>n.stopPropagation(),className:`inline-flex items-center justify-center text-muted-foreground/60 hover:text-primary transition-colors shrink-0 ${a}`,children:e.jsx(bs,{className:"h-3.5 w-3.5"})})}),e.jsxs(dt,{side:"top",align:"start",className:"w-72 text-xs leading-relaxed normal-case tracking-normal",children:[t&&e.jsx("p",{className:"font-semibold mb-1 text-foreground",children:t}),e.jsx("p",{className:"text-muted-foreground",children:r})]})]}):null},ds={overview:"Overview",acquisition:"Acquisition",engagement:"Engagement",conversions:"Conversion",flow:"Flow & Funnel",retention:"Retention",demographics:"Devices & Geo",realtime:"Real-time",extras:"More insights"},Qe=["hsl(var(--primary))","#f59e0b","#10b981","#8b5cf6","#ec4899","#3b82f6","#ef4444","#14b8a6"],x=t=>new Intl.NumberFormat("en-GB").format(Math.round(t||0)),H=t=>`£${new Intl.NumberFormat("en-GB").format(Math.round(t||0))}`,se=t=>`${(t||0).toFixed(1)}%`,et=t=>!t||t<0?"0s":t<60?`${Math.round(t)}s`:`${Math.floor(t/60)}m ${Math.round(t%60)}s`,X=(t,s)=>s?(t-s)/s*100:t>0?100:null,z=({icon:t,label:s,value:a,sub:r,change:n})=>e.jsx(N,{children:e.jsxs(k,{className:"pt-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground text-xs uppercase tracking-wide",children:[e.jsx(t,{className:"h-3.5 w-3.5"}),s,e.jsx(Y,{label:s})]}),typeof n=="number"&&e.jsxs("span",{className:`text-xs flex items-center gap-0.5 ${n>=0?"text-emerald-500":"text-destructive"}`,children:[n>=0?e.jsx(Or,{className:"h-3 w-3"}):e.jsx(Rr,{className:"h-3 w-3"}),Math.abs(n).toFixed(0),"%"]})]}),e.jsx("p",{className:"text-2xl font-bold mt-1",children:a}),r&&e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:r})]})}),ri=()=>{const[t,s]=f.useState(Tn()),[a,r]=f.useState("overview"),[n,l]=f.useState(!1),[i,h]=f.useState(null),[u,p]=f.useState(null),[j,_]=f.useState(!0),[O,T]=f.useState(null),w=t.from,m=t.to,S=async()=>{_(!0),T(null);const c=t.from,y=t.to,d=y.getTime()-c.getTime(),ee=t.compareFrom??new Date(c.getTime()-d),He=t.compareTo??c,{data:Ys,error:Ft}=await de.rpc("get_analytics_dashboard",{p_from:c.toISOString(),p_to:y.toISOString(),p_prev_from:ee.toISOString(),p_prev_to:He.toISOString()});Ft?T(Ft.message):h(Ys);const{data:Js}=await de.rpc("get_roller_sales_summary",{p_from:c.toISOString(),p_to:y.toISOString(),p_prev_from:ee.toISOString(),p_prev_to:He.toISOString()});p(Js??null),_(!1)};if(f.useEffect(()=>{S()},[t.from,t.to,t.compareFrom,t.compareTo,t.compareMode]),f.useEffect(()=>{const c=de.channel("active-sessions-rpc").on("postgres_changes",{event:"*",schema:"public",table:"analytics_sessions"},()=>{S()}).subscribe();return()=>{de.removeChannel(c)}},[]),j&&!i)return e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx("p",{className:"text-muted-foreground",children:"Loading analytics..."})});if(O)return e.jsx("div",{className:"p-6",children:e.jsx(N,{children:e.jsx(k,{className:"pt-4",children:e.jsx("p",{className:"text-destructive text-sm",children:O})})})});if(!i)return null;const R=i.totals||{},g=i.prev_totals||{},b=Number(R.sessions||0),M=Number(R.unique_visitors||0),V=Number(R.pageviews||0),F=Number(R.bounces||0),v=Number(R.engaged_sessions||0),A=Number(R.avg_duration||0),o=Number(R.new_sessions||0),P=b-o,I=!!u&&Number(u.orders||0)>0,L=Number(I?u.revenue||0:R.revenue||0),C=Number(I?u.orders||0:R.transactions||0),J=Number(I?u.prev_revenue||0:g.revenue||0),Q=Number(I?u.prev_orders||0:g.transactions||0),Ne=b>0?F/b*100:0,Ge=b>0?v/b*100:0,ze=b>0?V/b:0,qe=C>0?L/C:0,Ee=I?Number(u.orders_online||0):C;I&&Number(u.prev_orders_online??u.prev_orders??0);const Ue=b>0?Ee/b*100:0,Lt=g.sessions>0?Number(g.bounces||0)/Number(g.sessions)*100:0,Mt=(i.timeseries||[]).map(c=>({date:new Date(c.date).toLocaleDateString("en-GB",{month:"short",day:"numeric"}),sessions:Number(c.sessions),visitors:Number(c.visitors),pageviews:Number(c.pageviews),conversions:Number(c.conversions),revenue:Number(c.revenue)})),ft={};
4(u?.daily||[]).forEach(c=>{ft[new Date(c.date).toLocaleDateString("en-GB",{month:"short",day:"numeric"})]={conversions:Number(c.conversions||0),revenue:Number(c.revenue||0)}});const We=I?Mt.map(c=>({...c,conversions:ft[c.date]?.conversions??0,revenue:ft[c.date]?.revenue??0})):Mt,Us=({type:c})=>c==="mobile"?e.jsx(Cr,{className:"h-4 w-4"}):c==="tablet"?e.jsx(Tr,{className:"h-4 w-4"}):e.jsx(Dr,{className:"h-4 w-4"}),Ws=`${w.toLocaleDateString("en-GB")}, ${m.toLocaleDateString("en-GB")}`,Hs=async()=>{l(!0);try{await ha({title:ds[a]??"Analytics",subtitle:`${Ws} · Java Whiskers Analytics`,fileName:`javawhiskers-analytics-${a}-${w.toISOString().slice(0,10)}.pdf`,slides:Zs()})}finally{l(!1)}},Zs=()=>{const c=ds[a]??"Analytics",y=(d,ee)=>({title:d,kicker:c,blocks:ee});switch(a){case"overview":return[y("Nyckeltal",[{type:"kpis",items:[{label:"Unique visitors",value:x(M),change:X(M,Number(g.unique_visitors||0))},{label:"Sessions",value:x(b),change:X(b,Number(g.sessions||0))},{label:"Page views",value:x(V),change:X(V,Number(g.pageviews||0))},{label:"Engagementsgrad",value:se(Ge),sub:`${x(v)} engaged`},{label:"Average session time",value:et(A),sub:"per session"},{label:"Pages / session",value:ze.toFixed(2)},{label:"Bounce rate",value:se(Ne)},{label:"New / returning",value:`${x(o)} / ${x(P)}`}]},{type:"note",text:"Sessions, visitors and engagement come from first-party-trackingen on javawhiskers.co.uk."}]),y("Sales",[{type:"kpis",items:[{label:"Revenue",value:H(L),change:X(L,J),sub:I?"Roller, all channels":"browser-tracked"},{label:"Purchases",value:x(C),change:X(C,Q),sub:I?`${x(Number(u.orders_online||0))} online / ${x(Number(u.orders_pos||0))} on site`:"browser-tracked"},{label:"Average order value",value:H(qe)},{label:"Online conversion rate",value:se(Ue),sub:"online purchases / sessions"}]},{type:"table",title:"Traffic & purchases per day",cols:[{header:"Date",width:1.4},{header:"Sessions"},{header:"Visitors"},{header:"Page views"},{header:"Purchases"},{header:"Revenue"}],rows:We.map(d=>[d.date,x(d.sessions),x(d.visitors),x(d.pageviews),x(d.conversions),H(d.revenue)])}])];case"acquisition":return[y("Channels",[{type:"bars",title:"Sessions per kanal",items:i.channels.map(d=>({label:d.name,value:Number(d.sessions)}))},{type:"table",title:"Channels, purchases & revenue",cols:[{header:"Channel",width:2},{header:"Sessions"},{header:"Purchases"},{header:"Revenue"}],rows:i.channels.map(d=>[d.name,x(Number(d.sessions)),x(Number(d.conversions)),H(Number(d.revenue))])}]),y("Sources & campaigns",[{type:"table",title:"Source / Medium",cols:[{header:"Source / Medium",width:3},{header:"Sessions"}],rows:i.source_medium.map(d=>[d.name,x(Number(d.sessions))]),maxRows:40},{type:"table",title:"Campaigns (UTM)",cols:[{header:"Campaign",width:3},{header:"Sessions"}],rows:i.campaigns.map(d=>[d.name,x(Number(d.sessions))]),maxRows:30}]),y("Landing pages",[{type:"bars",title:"Sessions per landningssida",items:i.landing_pages.slice(0,14).map(d=>({label:d.path,value:Number(d.sessions)}))}])];case"engagement":return[y("Page performance",[{type:"table",title:"Pages, views, time, scroll, bounce",cols:[{header:"Page",width:3},{header:"Views"},{header:"Sess."},{header:"Avg. time"},{header:"Scroll"},{header:"Bounce"}],rows:i.page_metrics.map(d=>[d.path,x(Number(d.views)),x(Number(d.sessions)),et(Number(d.avg_time)),`${Math.round(Number(d.avg_scroll))}%`,se(Number(d.bounce_rate))]),maxRows:40}]),y("Events",[{type:"bars",title:"Custom events",items:i.events.slice(0,16).map(d=>({label:d.name,value:Number(d.count)}))}])];case"conversions":return[y("Conversion",[{type:"kpis",items:[{label:"Revenue",value:H(L),change:X(L,J)},{label:"Purchases",value:x(C),change:X(C,Q)},{label:"AOV",value:H(qe)},{label:"Online conversion rate",value:se(Ue),sub:`${x(Ee)} / ${x(b)}`}]},{type:"note",text:I?`Purchases and revenue are fetched from Roller (online + kassa). The conversion rate is calculated on Roller online purchases (${x(Ee)}) divided by web sessions (${x(b)}); POS purchases (${x(Number(u.orders_pos||0))}) are not included.`:"Purchase figures come from browser tracking i denna period."}]),y("Revenue per dag",[{type:"table",cols:[{header:"Date",width:1.5},{header:"Purchases"},{header:"Revenue"}],rows:We.map(d=>[d.date,x(d.conversions),H(d.revenue)])}]),y("Attribution",[{type:"table",title:"Latest browser-tracked purchases",cols:[{header:"Date",width:1.6},{header:"Booking",align:"left",width:1.4},{header:"Attribution",align:"left",width:1.4},{header:"Value"}],rows:i.purchases.map(d=>
4[new Date(d.created_at).toLocaleString("en-GB"),d.booking_reference||d.booking_id||"-",d.gclid?"Google Ads":d.fbclid?"Meta":d.ttclid?"TikTok":d.awc?"Awin":"Direct/Organic",H(Number(d.value)||0)]),maxRows:30}])];case"flow":return[y("Funnel",[{type:"funnel",title:"From visit to purchase",items:(i.flow.funnel||[]).map(d=>({label:d.label,value:Number(d.sessions)}))}]),y("Entrances & exits",[{type:"bars",title:"Entrance pages",items:i.flow.entry.slice(0,10).map(d=>({label:d.k,value:Number(d.v)}))},{type:"bars",title:"Exit pages",items:i.flow.exit.slice(0,10).map(d=>({label:d.k,value:Number(d.v)}))}]),y("Navigation paths",[{type:"table",title:"Most common steps",cols:[{header:"Path",width:4},{header:"Sessions"}],rows:i.flow.transitions.map(d=>[d.k,x(Number(d.v))]),maxRows:25}]),y("Entire customer journeys",[{type:"table",cols:[{header:"Journey",width:5},{header:"Steps"},{header:"Sessions"}],rows:(i.flow.journeys||[]).map(d=>[d.journey,String(d.steps),x(Number(d.sessions))]),maxRows:25}])];case"retention":return[y("Retention",[{type:"kpis",items:[{label:"New sessions",value:x(o)},{label:"Returning",value:x(P)},{label:"Returning rate",value:se(b?P/b*100:0)},{label:"Unique visitors",value:x(M)}]},{type:"table",title:"Cohort, percentage returning",cols:[{header:"Cohort",width:1.6},{header:"Size"},{header:"V0"},{header:"V1"},{header:"V2"},{header:"V3"}],rows:i.retention.map(d=>[d.week,x(Number(d.total)),...d.pct.map(ee=>`${ee}%`)])}])];case"demographics":return[y("Devices & browsers",[{type:"bars",title:"Devices",items:i.demographics.device.map(d=>({label:d.name,value:Number(d.value)}))},{type:"bars",title:"Browsers",items:i.demographics.browser.slice(0,8).map(d=>({label:d.name,value:Number(d.value)}))}]),y("Systems & geography",[{type:"bars",title:"Operating systems",items:i.demographics.os.slice(0,8).map(d=>({label:d.name,value:Number(d.value)}))},{type:"table",title:"Countries",cols:[{header:"Country",width:3},{header:"Sessions"}],rows:i.demographics.country.map(d=>[d.name,x(Number(d.value))]),maxRows:20}])];case"realtime":return[y("Active visitors",[{type:"kpis",items:[{label:"Aktiva just nu",value:x(i.realtime.length)}]},{type:"table",cols:[{header:"Enhet",width:1.4},{header:"Browsers",align:"left",width:1.4},{header:"OS",align:"left",width:1.4},{header:"Source",align:"left",width:2.5}],rows:i.realtime.map(d=>[d.device_type||"-",d.browser||"-",d.os||"-",d.referrer||"Direkt"])}])];default:return[y("Sammanfattning",[{type:"kpis",items:[{label:"Sessions",value:x(b)},{label:"Unique visitors",value:x(M)},{label:"Revenue",value:H(L)},{label:"Purchases",value:x(C)}]},{type:"note",text:"The tab shows deeper insights in admin, the key figures above summarise the period."}])]}};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-3",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"font-display text-3xl text-foreground",children:"Analytics"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"First-party analysis, compared to previous period"})]}),e.jsx(Cn,{value:t,onChange:s})]}),e.jsx(N,{className:"border-primary/20 bg-primary/5",children:e.jsxs(k,{className:"pt-4 flex items-center gap-3 flex-wrap",children:[e.jsx(gt,{className:"h-5 w-5 text-primary animate-pulse"}),e.jsx("span",{className:"font-bold text-lg text-foreground",children:i.realtime?.length||0}),e.jsx("span",{className:"text-muted-foreground",children:"active visitors right now"})]})}),e.jsxs(ms,{value:a,onValueChange:r,children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 flex-wrap",children:[e.jsxs(hs,{className:"flex-wrap h-auto",children:[e.jsx(q,{value:"overview",children:"Overview"}),e.jsx(q,{value:"acquisition",children:"Acquisition"}),e.jsx(q,{value:"engagement",children:"Engagement"}),e.jsx(q,{value:"conversions",children:"Conversion"}),e.jsx(q,{value:"flow",children:"Flow & Funnel"}),e.jsx(q,{value:"retention",children:"Retention"}),e.jsx(q,{value:"demographics",children:"Devices & Geo"}),e.jsx(q,{value:"realtime",children:"Real-time"}),e.jsx(q,{value:"extras",children:"More insights"})]}),e.jsxs(te,{variant:"outline",size:"sm",onClick:Hs,disabled:n,className:"shrink-0",children:[n?e.jsx(Be,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(Nr,{className:"h-4 w-4 mr-2"}),n?"Skapar PDF…":"Exportera som slides (PDF)"]})]}),e.jsxs(U,{value:"overview",className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsx(z,{icon:tt,label:"Unique visitors",value:x(M),change:X(M,Number(g.unique_visitors||0))}),e.jsx(z,{icon:gt,label:"Sessions",value:x(b),change:X(b,Number(g.sessions||0))}),e.jsx(z,{icon:wr,label:"Page views",value:x(V),change:X(V,Number(g.pageviews||0))}),e.jsx(z,{icon:kr,label:"Engagement rate",value:se(Ge),sub:`${x(v)} engaged`}),e.jsx(z,{icon:ys,label:"Average session time",value:et(A),sub:"per session (max 30 min)"}),e.jsx(z,{icon:Ze,label:"Pages / session",value:ze.toFixed(2)}),e.jsx(z,{icon:_r,label:"Bounce rate",value:se(Ne),change:Lt?-(X(Ne,Lt)||0):null}),e.jsx(z,{icon:Gt,label:"New / returning",value:`${x(o)} / ${x(P)}`})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsx(z,{icon:zt,label:"Revenue",value:H(L),change:X(L,J),sub:I?"Roller (alla kanaler)":"browser-tracked"}),e.jsx(z,{icon:Ie,label:"Purchases",value:x(C),change:X(C,Q),sub:I?`${x(Number(u.orders_online||0))} online / ${x(Number(u.orders_pos||0))} on site`:"browser-tracked"}),e.jsx(z,{icon:Ze,label:"Average order value",value:H(qe)}),e.jsx(z,{icon:Ie,label:"Conv. rate (online)",value:se(Ue),sub:"Roller online purchases / sessions"})]}),e.jsxs(N,{children:[e.jsx(D,{children:e.jsxs(E,{className:"text-sm",children:["Traffic & conversion over time",e.jsx(Y,{label:"Trafik & konvertering över tid"})]})}),e.jsx(k,{children:e.jsx(le,{width:"100%",height:320,children:e.jsxs(kt,{data:We,children:[e.jsx(je,{strokeDasharray:"3 3",className:"stroke-border"}),e.jsx(he,{dataKey:"date",className:"text-xs"}),e.jsx(oe,{yAxisId:"left",className:"text-xs"}),e.jsx(oe,{yAxisId:"right",orientation:"right",className:"text-xs"}),e.jsx(ce,{}),e.jsx(rt,{}),e.jsx(it,{yAxisId:"left",type:"monotone",dataKey:"sessions",name:"Sessions",stroke:"hsl(var(--primary))",fill:"hsl(var(--primary))",fillOpacity:.15}),e.jsx(it,{yAxisId:"left",type:"monotone",dataKey:"pageviews",name:"Page views",stroke:"#10b981",fill:"#10b981",fillOpacity:.1}),e.jsx(wt,{yAxisId:"right",type:"monotone",dataKey:"conversions",name:"Purchases",stroke:"#f59e0b",strokeWidth:2,dot:!0})]})})})]}),e.jsx(ve,{type:"analytics",dateRange:t.presetLabel,from:w,to:m})]}),e.jsxs(U,{value:"acquisition",className:"space-y-6",children:[e.jsxs(N,{children:[e.jsx(D,{children:e.jsxs(E,{className:"text-sm",children:["Channels",e.jsx(Y,{label:"Channels"})]})}),e.jsx(k,{children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsx(le,{width:"100%",height:260,children:e.jsxs(ns,{children:[e.jsx(ie,{data:i.channels,dataKey:"sessions",nameKey:"name",cx:"50%",cy:"50%",outerRadius:90,label:({name:c,percent:y})=>`${c} ${(y*100).toFixed(0)}%`,children:i.channels.map((c,y)=>e.jsx(Nt,{fill:Qe[y%Qe.length]},y))}),e.jsx(ce,{})]})}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-xs text-muted-foreground",children:[e.jsx("th",{className:"text-left py-1.5",children:"Channel"}),e.jsx("th",{className:"text-right",children:"Sess."}),e.jsx("th",{className:"text-right",children:"Purchases"}),e.jsx("th",{className:"text-right",children:"Revenue"})]})}),e.jsx("tbody",{children:i.channels.map((c,y)=>e.jsxs("tr",{className:"border-t border-border",children:[e.jsx("td",{className:"py-1.5",children:c.name}),e.jsx("td",{className:"text-right",children:x(Number(c.sessions))}),e.jsx("td",{className:"text-right",children:x(Number(c.conversions))}),e.jsx("td",{className:"text-right",children:H(Number(c.revenue))})]},y))})]})})]})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs(N,{children:[e.jsx(D,{children:e.jsxs(E,{className:"text-sm",children:["Source / Medium",e.jsx(Y,{label:"Källa / Medium"})]})}),e.jsx(k,{children:e.jsx("div",{className:"overflow-x-auto max-h-[400px]",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-xs text-muted-foreground",children:[e.jsx("th",{className:"text-left py-1.5",children:"Source / Medium"}),e.jsx("th",{className:"text-right",children:"Sess."})]})}),e.jsx("tbody",{children:i.source_medium.map((c,y)=>e.jsxs("tr",{className:"border-t border-border",children:[e.jsx("td",{className:"py-1.5 truncate max-w-[200px]",children:c.name}),e.jsx("td",{className:"text-right",children:x(Number(c.sessions))})]},y))})]})})})]}),e.jsxs(N,{children:[e.jsx(D,{children:e.jsxs(E,{className:"text-sm",children:["Campaigns (UTM)",e.jsx(Y,{label:"Campaigns (UTM)"})]})}),e.jsx(k,{children:e.jsx("div",{className:"overflow-x-auto max-h-[400px]",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-xs text-muted-foreground",children:[e.jsx("th",{className:"text-left py-1.5",children:"Campaign"}),e.jsx("th",{className:"text-right",children:"Sess."})]})}),e.jsxs("tbody",{children:[i.campaigns.map((c,y)=>e.jsxs("tr",{className:"border-t border-border",children:[e.jsx("td",{className:"py-1.5 truncate max-w-[200px]",children:c.name}),e.jsx("td",{className:"text-right",children:x(Number(c.sessions))})]},y)),i.campaigns.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:2,className:"text-center text-muted-foreground py-4",children:"No UTM campaigns yet."})})]})]})})})]})]}),e.jsxs(N,{children:[e.jsx(D,{children:e.jsxs(E,{className:"text-sm",children:["Landing pages",e.jsx(Y,{label:"Landing pages"})]})}),e.jsx(k,{children:e.jsx("div",{className:"space-y-2 max-h-[380px] overflow-auto",children:i.landing_pages.map((c,y)=>e.jsxs("div",{className:"flex justify-between items-center py-1.5 border-b border-border last:border-0",children:[e.jsx("span",{className:"text-xs font-mono truncate flex-1 pr-2",children:c.path}),e.jsx(K,{variant:"secondary",children:x(Number(c.sessions))})]},y))})})]}),e.jsx(ve,{type:"acquisition",dateRange:t.presetLabel,from:w,to:m})]}),e.jsxs(U,{value:"engagement",className:"space-y-6",children:[e.jsxs(N,{children:[e.jsx(D,{children:e.jsxs(E,{className:"text-sm",children:["Pages, views, time, scroll, bounce",e.jsx(Y,{label:"Pages, views, time, scroll, bounce"})]})}),e.jsx(k,{children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-xs text-muted-foreground",children:[e.jsx("th",{className:"text-left py-1.5",children:"Page"}),e.jsx("th",{className:"text-right",children:"Views"}),e.jsx("th",{className:"text-right",children:"Sess."}),e.jsx("th",{className:"text-right",children:"Avg. time"}),e.jsx("th",{className:"text-right",children:"Scroll"}),e.jsx("th",{className:"text-right",children:"Bounce"})]})}),e.jsx("tbody",{children:i.page_metrics.map((c,y)=>e.jsxs("tr",{className:"border-t border-border",children:[e.jsx("td",{className:"py-1.5 font-mono text-xs truncate max-w-[260px]",children:c.path}),e.jsx("td",{className:"text-right",children:x(Number(c.views))}),e.jsx("td",{className:"text-right",children:x(Number(c.sessions))}),e.jsx("td",{className:"text-right",children:et(Number(c.avg_time))}),e.jsxs("td",{className:"text-right",children:[Math.round(Number(c.avg_scroll)),"%"]}),e.jsx("td",{className:"text-right",children:se(Number(c.bounce_rate))})]},y))})]})})})]}),e.jsxs(N,{children:[e.jsx(D,{children:e.jsxs(E,{className:"text-sm",children:["Custom events",e.jsx(Y,{label:"Custom events"})]})}),e.jsx(k,{children:i.events.length>0?e.jsx("div",{className:"space-y-2",children:i.events.map((c,y)=>e.jsxs("div",{className:"flex justify-between items-center py-2 border-b border-border last:border-0",children:[e.jsx("span",{className:"text-sm font-medium",children:c.name}),e.jsx(K,{children:x(Number(c.count))})]},y))}):e.jsx("p",{className:"text-muted-foreground text-sm text-center py-6",children:"No events tracked yet."})})]}),e.jsx(ve,{type:"engagement",dateRange:t.presetLabel,from:w,to:m})]}),e.jsxs(U,{value:"conversions",className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsx(z,{icon:zt,label:"Revenue",value:H(L),change:X(L,J),sub:I?"Roller (alla kanaler)":"browser-tracked"}),e.jsx(z,{icon:Ie,label:"Purchases",value:x(C),change:X(C,Q),sub:I?`${x(Number(u.orders_online||0))} online / ${x(Number(u.orders_pos||0))} on site`:"browser-tracked"}),e.jsx(z,{icon:Ze,label:"AOV",value:H(qe)}),e.jsx(z,{icon:Ie,label:"Conv. rate (online)",value:se(Ue),sub:`${x(Ee)} online-purchases / ${x(b)} sessions`})]}),I&&e.jsx(N,{className:"border-primary/20 bg-primary/5",children:e.jsxs(k,{className:"pt-4 text-sm text-muted-foreground space-y-1",children:[e.jsxs("p",{children:[e.jsx("strong",{className:"text-foreground",children:"Source:"})," purchases and revenue are fetched from Roller (both online and POS), not from browser tracking."]}),e.jsxs("p",{children:[e.jsx("strong",{className:"text-foreground",children:"Conv. rate:"})," calculated on Roller online purchases (",x(Ee),") divided by web sessions (",x(b),"). POS purchases (",x(Number(u.orders_pos||0)),") are not included. as they do not come from web traffic."]}),e.jsxs("p",{children:[e.jsx("strong",{className:"text-foreground",children:"Browser tracking"})," is not used for purchase figures (captured only ",x(Number(u.browser_tracked||0))," purchases), it is used solely for sessions and flow analysis."]}),u.last_synced_at&&e.jsxs("p",{children:["Last synced from Roller: ",new Date(u.last_synced_at).toLocaleStr
4ing("en-GB")]})]})}),e.jsxs(N,{children:[e.jsx(D,{children:e.jsxs(E,{className:"text-sm",children:["Revenue over time",e.jsx(Y,{label:"Intäkter över tid"})]})}),e.jsx(k,{children:e.jsx(le,{width:"100%",height:280,children:e.jsxs(Ct,{data:We,children:[e.jsx(je,{strokeDasharray:"3 3",className:"stroke-border"}),e.jsx(he,{dataKey:"date",className:"text-xs"}),e.jsx(oe,{className:"text-xs"}),e.jsx(ce,{formatter:c=>H(Number(c))}),e.jsx(Ae,{dataKey:"revenue",name:"Revenue",fill:"hsl(var(--primary))",radius:[4,4,0,0]})]})})})]}),e.jsxs(N,{children:[e.jsx(D,{children:e.jsxs(E,{className:"text-sm",children:["Latest browser-tracked purchases (",i.purchases.length,")"]})}),e.jsx(k,{children:e.jsx("div",{className:"overflow-x-auto max-h-[420px]",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-xs text-muted-foreground",children:[e.jsx("th",{className:"text-left py-1.5",children:"Date"}),e.jsx("th",{className:"text-left",children:"Booking"}),e.jsx("th",{className:"text-left",children:"Attribution"}),e.jsx("th",{className:"text-right",children:"Value"})]})}),e.jsxs("tbody",{children:[i.purchases.map((c,y)=>e.jsxs("tr",{className:"border-t border-border",children:[e.jsx("td",{className:"py-1.5 text-xs",children:new Date(c.created_at).toLocaleString("en-GB")}),e.jsx("td",{className:"text-xs font-mono",children:c.booking_reference||c.booking_id||"-"}),e.jsx("td",{className:"text-xs",children:c.gclid?"Google Ads":c.fbclid?"Meta":c.ttclid?"TikTok":c.awc?"Awin":"Direct/Organic"}),e.jsx("td",{className:"text-right font-medium",children:H(Number(c.value)||0)})]},y)),i.purchases.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:4,className:"text-center text-muted-foreground py-4",children:"No purchases in this period."})})]})]})})})]}),e.jsx(ve,{type:"conversions",dateRange:t.presetLabel,from:w,to:m})]}),e.jsxs(U,{value:"flow",className:"space-y-6",children:[e.jsx(hn,{from:w,to:m}),e.jsx(N,{children:e.jsxs(D,{children:[e.jsxs(E,{className:"text-sm flex items-center gap-2",children:[e.jsx(Ar,{className:"h-4 w-4"})," Detaljer per sida",e.jsx(Y,{label:"Detaljer per sida"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Deep dive, entrances, exits and navigation paths."})]})}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs(N,{children:[e.jsx(D,{children:e.jsxs(E,{className:"text-sm flex items-center gap-2",children:[e.jsx(Sr,{className:"h-4 w-4"})," Entrance pages",e.jsx(Y,{label:"Ingångssidor"})]})}),e.jsx(k,{children:e.jsx("div",{className:"space-y-2",children:i.flow.entry.map((c,y)=>e.jsxs("div",{className:"flex justify-between items-center py-1.5 border-b border-border last:border-0",children:[e.jsx("span",{className:"text-xs font-mono truncate flex-1 pr-2",children:c.k}),e.jsx(K,{variant:"secondary",children:c.v})]},y))})})]}),e.jsxs(N,{children:[e.jsx(D,{children:e.jsxs(E,{className:"text-sm flex items-center gap-2",children:[e.jsx(js,{className:"h-4 w-4"})," Exit pages",e.jsx(Y,{label:"Utgångssidor"})]})}),e.jsx(k,{children:e.jsx("div",{className:"space-y-2",children:i.flow.exit.map((c,y)=>e.jsxs("div",{className:"flex justify-between items-center py-1.5 border-b border-border last:border-0",children:[e.jsx("span",{className:"text-xs font-mono truncate flex-1 pr-2",children:c.k}),e.jsx(K,{variant:"secondary",children:c.v})]},y))})})]})]}),e.jsxs(N,{children:[e.jsx(D,{children:e.jsxs(E,{className:"text-sm flex items-center gap-2",children:[e.jsx(yt,{className:"h-4 w-4"})," Most common navigation paths",e.jsx(Y,{label:"Vanligaste navigeringsvägar"})]})}),e.jsx(k,{children:e.jsx("div",{className:"space-y-2",children:i.flow.transitions.map((c,y)=>e.jsxs("div",{className:"flex justify-between items-center py-1.5 border-b border-border last:border-0",children:[e.jsx("span",{className:"text-xs font-mono truncate flex-1 pr-2",children:c.k}),e.jsx(K,{children:c.v})]},y))})})]}),e.jsxs(N,{children:[e.jsxs(D,{children:[e.jsxs(E,{className:"text-sm flex items-center gap-2",children:[e.jsx(yt,{className:"h-4 w-4"})," Entire customer journeys",e.jsx(Y,{label:"Entire customer journeys"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Exact sequence of pages visitors navigate, from the landing page all the way to the exit page. Most common journeys first."})]}),e.jsx(k,{children:e.jsx("div",{className:"space-y-2 max-h-[520px] overflow-auto",children:i.flow.journeys?.length?
4i.flow.journeys.map((c,y)=>e.jsxs("div",{className:"py-2 border-b border-border last:border-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 mb-1",children:[e.jsxs(K,{variant:"secondary",className:"shrink-0",children:[x(Number(c.sessions))," sessions"]}),e.jsxs("span",{className:"text-[10px] text-muted-foreground shrink-0",children:[c.steps," steg"]})]}),e.jsx("div",{className:"text-xs font-mono leading-relaxed break-words",children:String(c.journey).split(" → ").map((d,ee,He)=>e.jsxs("span",{children:[e.jsx("span",{className:"px-1.5 py-0.5 rounded bg-muted inline-block my-0.5",children:d}),ee<He.length-1&&e.jsx("span",{className:"text-muted-foreground mx-1",children:"→"})]},ee))})]},y)):e.jsx("p",{className:"text-muted-foreground text-sm text-center py-6",children:"No complete journeys in the period yet."})})})]}),e.jsx(gn,{from:w,to:m}),e.jsx(ve,{type:"flow",dateRange:t.presetLabel,from:w,to:m})]}),e.jsxs(U,{value:"retention",className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsx(z,{icon:tt,label:"New sessions",value:x(o)}),e.jsx(z,{icon:Gt,label:"Returning",value:x(P)}),e.jsx(z,{icon:Ze,label:"Returning rate",value:se(b?P/b*100:0)}),e.jsx(z,{icon:tt,label:"Unique visitors",value:x(M)})]}),e.jsxs(N,{children:[e.jsx(D,{children:e.jsxs(E,{className:"text-sm",children:["Cohort, percentage returning per vecka",e.jsx(Y,{label:"Cohort — andel som återvänder per vecka"})]})}),e.jsx(k,{children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-xs text-muted-foreground",children:[e.jsx("th",{className:"text-left py-1.5",children:"Cohort"}),e.jsx("th",{className:"text-right",children:"Size"}),e.jsx("th",{className:"text-right",children:"V0"}),e.jsx("th",{className:"text-right",children:"V1"}),e.jsx("th",{className:"text-right",children:"V2"}),e.jsx("th",{className:"text-right",children:"V3"})]})}),e.jsxs("tbody",{children:[i.retention.map((c,y)=>e.jsxs("tr",{className:"border-t border-border",children:[e.jsx("td",{className:"py-1.5 text-xs",children:c.week}),e.jsx("td",{className:"text-right",children:x(Number(c.total))}),c.pct.map((d,ee)=>e.jsx("td",{className:"text-right",children:e.jsxs("span",{className:"px-2 py-0.5 rounded",style:{background:`hsl(var(--primary) / ${d/100})`,color:d>50?"white":void 0},children:[d,"%"]})},ee))]},y)),i.retention.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"text-center text-muted-foreground py-4",children:"Too little data."})})]})]})})})]}),e.jsx(ve,{type:"retention",dateRange:t.presetLabel,from:w,to:m})]}),e.jsxs(U,{value:"demographics",className:"space-y-6",children:[e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6",children:[{title:"Devices",data:i.demographics.device},{title:"Browsers",data:i.demographics.browser},{title:"Operating systems",data:i.demographics.os}].map((c,y)=>e.jsxs(N,{children:[e.jsx(D,{children:e.jsx(E,{className:"text-sm",children:c.title})}),e.jsx(k,{children:e.jsx(le,{width:"100%",height:200,children:e.jsxs(ns,{children:[e.jsx(ie,{data:c.data,dataKey:"value",nameKey:"name",cx:"50%",cy:"50%",outerRadius:80,label:!0,children:c.data.map((d,ee)=>e.jsx(Nt,{fill:Qe[ee%Qe.length]},ee))}),e.jsx(ce,{})]})})})]},y))}),e.jsxs(N,{children:[e.jsx(D,{children:e.jsxs(E,{className:"text-sm flex items-center gap-2",children:[e.jsx(Pr,{className:"h-4 w-4"})," Countries",e.jsx(Y,{label:"Länder"})]})}),e.jsx(k,{children:i.demographics.country.some(c=>c.name!=="unknown")?e.jsx("div",{className:"space-y-2 max-h-[400px] overflow-auto",children:i.demographics.country.map((c,y)=>e.jsxs("div",{className:"flex justify-between items-center py-1.5 border-b border-border last:border-0",children:[e.jsx("span",{className:"text-sm",children:c.name}),e.jsx(K,{variant:"secondary",children:x(Number(c.value))})]},y))}):e.jsx("p",{className:"text-muted-foreground text-sm text-center py-6",children:"Geo-data not tracked yet."})})]}),e.jsx(ve,{type:"demographics",dateRange:t.presetLabel,from:w,to:m})]}),e.jsx(U,{value:"realtime",className:"space-y-6",children:e.jsxs(N,{children:[e.jsx(D,{children:e.jsxs(E,{className:"text-sm flex items-center gap-2",children:[e.jsx(gt,{className:"h-4 w-4 text-emerald-500 animate-pulse"}),"Active visitors (",i.realtime.length,")"]})}),e.jsx(k,{children:i.realtime.length>0?e.jsx("div",{className:"space-y-3",children:i.realtime.map(c=>e.jsxs("div",{className:"flex items-center gap-4 py-2 border-b border-border last:border-0",children:[e.jsx(Us,{type:c.device_type}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("p",{className:"text-sm font-medium",children:[c.browser," on ",c.os]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:c.referrer?`From: ${c.referrer}`:"Direkt"})]}),e.jsx(K,{variant:"outline",className:"text-xs",children:c.device_type})]},c.id))}):e.jsx("p",{className:"text-muted-foreground text-sm text-center py-8",children:"No active visitors right now."})})]})}),e.jsx(U,{value:"extras",children:e.jsx(dn,{from:w,to:m})})]})]})};export{ri 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.