1import{j as o,u as ze,c as pt,b as ue}from"./query-Q_ThwKGI.js";import{i as ht,r as M,R as h,l as Ue,u as gt}from"./react-vendor-wefok28f.js";import{s as _}from"./client-DjLwxtrO.js";import{B as ye}from"./button-DrepnwkX.js";import{u as We,l as D}from"./index-C4Kq7kkR.js";import{A as vt,a as yt,b as xt,c as bt,d as jt,e as At,f as wt,g as _t}from"./alert-dialog-BzFKdENb.js";import{u as L}from"./useTranslation-DNoH3foE.js";import{A as kt,aa as Ot,Q as Pt,U as St,a5 as Nt,ae as Lt,af as Rt}from"./icons-By8asZST.js";import{u as Tt}from"./useLogger-CDsXA2_R.js";import{S as we}from"./skeleton-B8BTwlen.js";import{D as ne}from"./DashboardStatCard-Du7a8-ug.js";import{S as He,a as Qe,b as Ge,c as Ye,d as H}from"./select-DECm7gW5.js";import{s as Ze}from"./subDays-rNULONAo.js";import{e as Et,B as Dt}from"./BarChart-tyxo_96n.js";import{f as ve}from"./format-NnwPU_mP.js";import{f as A,_ as Xe,a as Je,b as Ct,c as $t,i as F,T as _e,p as T,L as P,g as et,d as ke,e as tt,D as It,C as Ft,h as Q,j as V,S as Kt,A as Mt,k as Bt,l as Le,m as qt,n as z,o as Vt,G as zt,q as Ut,r as Oe,s as Wt,t as ae,w as Re,u as ie,v as Ht,x as Qt,y as Gt,R as de,z as Yt,B as rt,X as nt,Y as at,E as fe,F as Zt,H as Xt}from"./LineChart-CjBOByky.js";import{L as Jt}from"./LeadsList-CtN4ZRzY.js";import"./supabase-COHOFxoQ.js";import"./index-DC33WZD-.js";import"./index-DviHZN-M.js";import"./index-CryppvJw.js";import"./index-CSO0Tzy2.js";import"./tiny-invariant-BaFNuDhB.js";import"./table-D25X3X5Y.js";import"./badge-u_30_p7s.js";import"./sheet-BNa5OgBl.js";import"./label-Ch0F7L4t.js";import"./switch-CnLyyNmH.js";import"./input-Cu6Tiemi.js";import"./WhatsAppTimelineComposer-wTlFnG2J.js";import"./textarea-DJfrjX2A.js";import"./useWhatsAppConnection-BkLcuBJO.js";import"./AuthProvider-BSQZ2YtM.js";import"./checkbox-Gmf95s3M.js";import"./card-DYyqUxY6.js";import"./formatDistanceToNow-g8DDsg0V.js";import"./pt-BR-9-TZCPQM.js";function er({open:t,onOpenChange:e,onConfirm:n}){const{t:r}=L("forms");return o.jsx(vt,{open:t,onOpenChange:e,children:o.jsxs(yt,{children:[o.jsxs(xt,{children:[o.jsx(bt,{children:r("dialogs.clearStatsTitle")}),o.jsx(jt,{children:r("dialogs.clearStatsMessage")})]}),o.jsxs(At,{children:[o.jsx(wt,{children:r("dialogs.clearStatsCancel")}),o.jsx(_t,{onClick:n,children:r("dialogs.clearStatsConfirm")})]})]})})}const tr=({formId:t,name:e,description:n})=>{const r=ht(),{t:a}=L("forms"),{toast:i}=We(),s=ze(),[l,u]=M.useState(!1),c=pt({mutationFn:async()=>{const{error:f}=await _.from("forms").update({views_count:0}).eq("id",t);if(f)throw f},onSuccess:()=>{s.invalidateQueries({queryKey:["form",t]}),i({title:a("common:success"),description:a("details.viewsCleared")}),u(!1)},onError:f=>{i({title:a("common:error"),description:a("details.viewsClearedError"),variant:"destructive"}),console.error("Error clearing views:",f)}});return o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsxs("div",{className:"flex items-center gap-4",children:[o.jsx(ye,{variant:"ghost",size:"icon",onClick:()=>r("/app/forms"),className:"h-8 w-8 rounded-lg",children:o.jsx(kt,{className:"h-4 w-4"})}),o.jsxs("div",{children:[o.jsx("h1",{className:"text-2xl font-semibold tracking-tight",children:e}),n&&o.jsx("p",{className:"text-sm text-muted-foreground mt-0.5",children:n})]})]}),o.jsxs(ye,{variant:"outline",size:"sm",onClick:()=>u(!0),className:"h-8 px-3 rounded-lg gap-2",children:[o.jsx(Ot,{className:"h-3.5 w-3.5"}),a("details.clearTotalViews")]})]}),o.jsx(er,{open:l,onOpenChange:u,onConfirm:()=>c.mutate()})]})},rr=({formId:t})=>{const{t:e}=L("forms"),n=Tt("FormStats"),{data:r,isLoading:a}=ue({queryKey:["form-stats",t],queryFn:async()=>{n.info("Fetching stats for form",{formId:t});const{data:i,error:s}=await _.from("forms").select("views_count").eq("id",t).single();if(s)throw n.error("Error fetching form",{error:s}),s;const{data:l,error:u}=await _.from("leads").select("id, is_registered, is_checked_in, is_purchased").eq("form_id",t);if(u)throw n.error("Error fetching leads",{error:u}),u;const c=(i==null?void 0:i.views_count)||0,f=(l==null?void 0:l.filter(v=>v.is_registered).length)||0,d=(l==null?void 0:l.filter(v=>v.is_checked_in).length)||0,p=(l==null?void 0:l.filter(v=>v.is_purchased).length)||0,y=c>0?(f/c*100).toFixed(1):"0",g=f>0?(d/f*100).toFixed(1):"0",m=d>0?(p/d*100).toFixed(1):"0";return{totalViews:c,totalRegistrations:f,totalCheckIns:d,totalPurchases:p,registrationRate:y,checkInRate:g,purchaseRate:m}}});return a||!r||r.totalViews===void 0?o.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:[...Array(4)].map((i,s)=>o.jsx(we,{className:"h-32 rounded-2xl"},s))}):o.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:[o.jsx(ne,{label:e("stats.totalViews"),value:r.totalViews.toLocaleStr
vendor: 25,007 bytes, lines 1-2
1ing(),subtext:e("stats.views"),icon:Pt,color:"text-blue-600"}),o.jsx(ne,{label:e("stats.registrations"),value:r.totalRegistrations.toLocaleString(),subtext:`${r.registrationRate}% ${e("stats.ofViews")}`,icon:St,color:"text-emerald-600"}),o.jsx(ne,{label:e("stats.checkIns"),value:r.totalCheckIns.toLocaleString(),subtext:`${r.checkInRate}% ${e("stats.ofRegistrations")}`,icon:Nt,color:"text-violet-600"}),o.jsx(ne,{label:e("stats.purchases"),value:r.totalPurchases.toLocaleString(),subtext:`${r.purchaseRate}% ${e("stats.ofCheckIns")}`,icon:Lt,color:"text-amber-600"})]})};var nr=["points","className","baseLinePoints","connectNulls"];function U(){return U=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},U.apply(this,arguments)}function ar(t,e){if(t==null)return{};var n=ir(t,e),r,a;if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(a=0;a<i.length;a++)r=i[a],!(e.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(t,r)&&(n[r]=t[r])}return n}function ir(t,e){if(t==null)return{};var n={};for(var r in t)if(Object.prototype.hasOwnProperty.call(t,r)){if(e.indexOf(r)>=0)continue;n[r]=t[r]}return n}function Te(t){return lr(t)||cr(t)||or(t)||sr()}function sr(){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 or(t,e){if(t){if(typeof t=="string")return xe(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);if(n==="Object"&&t.constructor&&(n=t.constructor.name),n==="Map"||n==="Set")return Array.from(t);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return xe(t,e)}}function cr(t){if(typeof Symbol<"u"&&t[Symbol.iterator]!=null||t["@@iterator"]!=null)return Array.from(t)}function lr(t){if(Array.isArray(t))return xe(t)}function xe(t,e){(e==null||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}var Ee=function(e){return e&&e.x===+e.x&&e.y===+e.y},ur=function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],n=[[]];return e.forEach(function(r){Ee(r)?n[n.length-1].push(r):n[n.length-1].length>0&&n.push([])}),Ee(e[0])&&n[n.length-1].push(e[0]),n[n.length-1].length<=0&&(n=n.slice(0,-1)),n},J=function(e,n){var r=ur(e);n&&(r=[r.reduce(function(i,s){return[].concat(Te(i),Te(s))},[])]);var a=r.map(function(i){return i.reduce(function(s,l,u){return"".concat(s).concat(u===0?"M":"L").concat(l.x,",").concat(l.y)},"")}).join("");return r.length===1?"".concat(a,"Z"):a},dr=function(e,n,r){var a=J(e,r);return"".concat(a.slice(-1)==="Z"?a.slice(0,-1):a,"L").concat(J(n.reverse(),r).slice(1))},fr=function(e){var n=e.points,r=e.className,a=e.baseLinePoints,i=e.connectNulls,s=ar(e,nr);if(!n||!n.length)return null;var l=D("recharts-polygon",r);if(a&&a.length){var u=s.stroke&&s.stroke!=="none",c=dr(n,a,i);return h.createElement("g",{className:l},h.createElement("path",U({},A(s,!0),{fill:c.slice(-1)==="Z"?s.fill:"none",stroke:"none",d:c})),u?h.createElement("path",U({},A(s,!0),{fill:"none",d:J(n,i)})):null,u?h.createElement("path",U({},A(s,!0),{fill:"none",d:J(a,i)})):null)}var f=J(n,i);return h.createElement("path",U({},A(s,!0),{fill:f.slice(-1)==="Z"?s.fill:"none",className:l,d:f}))},mr=Xe,pr=Ct,hr=Je;function gr(t,e){return t&&t.length?mr(t,hr(e),pr):void 0}var vr=gr;const yr=Ue(vr);var xr=Xe,br=Je,jr=$t;function Ar(t,e){return t&&t.length?xr(t,br(e),jr):void 0}var wr=Ar;const _r=Ue(wr);var kr=["cx","cy","angle","ticks","axisLine"],Or=["ticks","tick","angle","tickFormatter","stroke"];function G(t){"@babel/helpers - typeof";return G=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(e){return typeof e}:function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},G(t)}function ee(){return ee=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},ee.apply(this,arguments)}function De(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(a){return Object.getOwnPropertyDescriptor(t,a).enumerable})),n.push.apply(n,r)}return n}function $(t){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?De(Object(n),!0).forEach(function(r){me(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):De(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}function Ce(t,e){if(t==null)return{};var n=Pr(t,e),r,a;if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(a=0;a<i.length;a++)r=i[a],!(e.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(t,r)&&(n[r]=t[r])}return n}function Pr(t,e){if(t==null)return{};var n={};for(var r in t)if(Object.prototype.hasOwnProperty.call(t,r)){if(e.indexOf(r)>=0)continue;n[r]=t[r]}return n}function Sr(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function $e(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,st(r.key),r)}}function Nr(t,e,n){return e&&$e(t.prototype,e),n&&$e(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function Lr(t,e,n){return e=oe(e),Rr(t,it()?Reflect.construct(e,n||[],oe(t).constructor):e.apply(t,n))}function Rr(t,e){if(e&&(G(e)==="object"||typeof e=="function"))return e;if(e!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return Tr(t)}function Tr(t){if(t===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function it(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(it=function(){return!!t})()}function oe(t){return oe=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(n){return n.__proto__||Object.getPrototypeOf(n)},oe(t)}function Er(t,e){if(typeof e!="function"&&e!==null)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&be(t,e)}function be(t,e){return be=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(r,a){return r.__proto__=a,r},be(t,e)}function me(t,e,n){return e=st(e),e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function st(t){var e=Dr(t,"string");return G(e)=="symbol"?e:e+""}function Dr(t,e){if(G(t)!="object"||!t)return t;var n=t[Symbol.toPrimitive];if(n!==void 0){var r=n.call(t,e||"default");if(G(r)!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(t)}var pe=function(t){function e(){return Sr(this,e),Lr(this,e,arguments)}return Er(e,t),Nr(e,[{key:"getTickValueCoord",value:function(r){var a=r.coordinate,i=this.props,s=i.angle,l=i.cx,u=i.cy;return T(l,u,a,s)}},{key:"getTickTextAnchor",value:function(){var r=this.props.orientation,a;switch(r){case"left":a="end";break;case"right":a="start";break;default:a="middle";break}return a}},{key:"getViewBox",value:function(){var r=this.props,a=r.cx,i=r.cy,s=r.angle,l=r.ticks,u=yr(l,function(f){return f.coordinate||0}),c=_r(l,function(f){return f.coordinate||0});return{cx:a,cy:i,startAngle:s,endAngle:s,innerRadius:c.coordinate||0,outerRadius:u.coordinate||0}}},{key:"renderAxisLine",value:function(){var r=this.props,a=r.cx,i=r.cy,s=r.angle,l=r.ticks,u=r.axisLine,c=Ce(r,kr),f=l.reduce(function(g,m){return[Math.min(g[0],m.coordinate),Math.max(g[1],m.coordinate)]},[1/0,-1/0]),d=T(a,i,f[0],s),p=T(a,i,f[1],s),y=$($($({},A(c,!1)),{},{fill:"none"},A(u,!1)),{},{x1:d.x,y1:d.y,x2:p.x,y2:p.y});return h.createElement("line",ee({className:"recharts-polar-radius-axis-line"},y))}},{key:"renderTicks",value:function(){var r=this,a=this.props,i=a.ticks,s=a.tick,l=a.angle,u=a.tickFormatter,c=a.stroke,f=Ce(a,Or),d=this.getTickTextAnchor(),p=A(f,!1),y=A(s,!1),g=i.map(function(m,v){var b=r.getTickValueCoord(m),j=$($($($({textAnchor:d,transform:"rotate(".concat(90-l,", ").concat(b.x,", ").concat(b.y,")")},p),{},{stroke:"none",fill:c},y),{},{index:v},b),{},{payload:m});return h.createElement(P,ee({className:D("recharts-polar-radius-axis-tick",et(s)),key:"tick-".concat(m.coordinate)},ke(r.props,m,v)),e.renderTickItem(s,j,u?u(m.value,v):m.value))});return h.createElement(P,{className:"recharts-polar-radius-axis-ticks"},g)}},{key:"render",value:function(){var r=this.props,a=r.ticks,i=r.axisLine,s=r.tick;return!a||!a.length?null:h.createElement(P,{className:D("recharts-polar-radius-axis",this.props.className)},i&&this.renderAxisLine(),s&&this.renderTicks(),tt.renderCallByParent(this.props,this.getViewBox()))}}],[{key:"renderTickItem",value:function(r,a,i){var s;return h.isValidElement(r)?s=h.cloneElement(r,a):F(r)?s=r(a):s=h.createElement(_e,ee({},a,{className:"recharts-polar-radius-axis-tick-value"}),i),s}}])}(M.PureComponent);me(pe,"displayName","PolarRadiusAxis");me(pe,"axisType","radiusAxis");me(pe,"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 Y(t){"@babel/helpers - typeof";return Y=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(e){return typeof e}:function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Y(t)}function K(){return K=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},K.apply(this,arguments)}function Ie(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(a){return Object.getOwnPropertyDescriptor(t,a).enumerable})),n.push.apply(n,r)}return n}function I(t){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?Ie(Object(n),!0).forEach(function(r){he(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ie(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}function Cr(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function Fe(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,ct(r.key),r)}}function $r(t,e,n){return e&&Fe(t.prototype,e),n&&Fe(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function Ir(t,e,n){return e=ce(e),Fr(t,ot()?Reflect.construct(e,n||[],ce(t).constructor):e.apply(t,n))}function Fr(t,e){if(e&&(Y(e)==="object"||typeof e=="function"))return e;if(e!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return Kr(t)}function Kr(t){if(t===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function ot(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(ot=function(){return!!t})()}function ce(t){return ce=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(n){return n.__proto__||Object.getPrototypeOf(n)},ce(t)}function Mr(t,e){if(typeof e!="function"&&e!==null)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&je(t,e)}function je(t,e){return je=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(r,a){return r.__proto__=a,r},je(t,e)}function he(t,e,n){return e=ct(e),e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function ct(t){var e=Br(t,"string");return Y(e)=="symbol"?e:e+""}function Br(t,e){if(Y(t)!="object"||!t)return t;var n=t[Symbol.toPrimitive];if(n!==void 0){var r=n.call(t,e||"default");if(Y(r)!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(t)}var qr=Math.PI/180,Ke=1e-5,ge=function(t){function e(){return Cr(this,e),Ir(this,e,arguments)}return Mr(e,t),$r(e,[{key:"getTickLineCoord",value:function(r){var a=this.props,i=a.cx,s=a.cy,l=a.radius,u=a.orientation,c=a.tickSize,f=c||8,d=T(i,s,l,r.coordinate),p=T(i,s,l+(u==="inner"?-1:1)*f,r.coordinate);return{x1:d.x,y1:d.y,x2:p.x,y2:p.y}}},{key:"getTickTextAnchor",value:function(r){var a=this.props.orientation,i=Math.cos(-r.coordinate*qr),s;return i>Ke?s=a==="outer"?"start":"end":i<-Ke?s=a==="outer"?"end":"start":s="middle",s}},{key:"renderAxisLine",value:function(){var r=this.props,a=r.cx,i=r.cy,s=r.radius,l=r.axisLine,u=r.axisLineType,c=I(I({},A(this.props,!1)),{},{fill:"none"},A(l,!1));if(u==="circle")return h.createElement(It,K({className:"recharts-polar-angle-axis-line"},c,{cx:a,cy:i,r:s}));var f=this.props.ticks,d=f.map(function(p){return T(a,i,s,p.coordinate)});return h.createElement(fr,K({className:"recharts-polar-angle-axis-line"},c,{points:d}))}},{key:"renderTicks",value:function(){var r=this,a=this.props,i=a.ticks,s=a.tick,l=a.tickLine,u=a.tickFormatter,c=a.stroke,f=A(this.props,!1),d=A(s,!1),p=I(I({},f),{},{fill:"none"},A(l,!1)),y=i.map(function(g,m){var v=r.getTickLineCoord(g),b=r.getTickTextAnchor(g),j=I(I(I({textAnchor:b},f),{},{stroke:"none",fill:c},d),{},{index:m,payload:g,x:v.x2,y:v.y2});return h.createElement(P,K({className:D("recharts-polar-angle-axis-tick",et(s)),key:"tick-".concat(g.coordinate)},ke(r.props,g,m)),l&&h.createElement("line",K({className:"recharts-polar-angle-axis-tick-line"},p,v)),s&&e.renderTickItem(s,j,u?u(g.value,m):g.value))});return h.createElement(P,{className:"recharts-polar-angle-axis-ticks"},y)}},{key:"render",value:function(){var r=this.props,a=r.ticks,i=r.radius,s=r.axisLine;return i<=0||!a||!a.length?null:h.createElement(P,{className:D("recharts-polar-angle-axis",this.props.className)},s&&this.renderAxisLine(),this.renderTicks())}}],[{key:"renderTickItem",value:function(r,a,i){var s;return h.isValidElement(r)?s=h.cloneElement(r,a):F(r)?s=r(a):s=h.createElement(_e,K({},a,{className:"recharts-polar-angle-axis-tick-value"}),i),s}}])}(M.PureComponent);he(ge,"displayName","PolarAngleAxis");he(ge,"axisType","angleAxis");he(ge,"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 se;function Z(t){"@babel/helpers - typeof";return Z=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(e){return typeof e}:function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},Z(t)}function W(){return W=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},W.apply(this,arguments)}function Me(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(a){return Object.getOwnPropertyDescriptor(t,a).enumerable})),n.push.apply(n,r)}return n}function x(t){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?Me(Object(n),!0).forEach(function(r){k(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Me(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}function Vr(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function Be(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,ut(r.key),r)}}function zr(t,e,n){return e&&Be(t.prototype,e),n&&Be(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function Ur(t,e,n){return e=le(e),Wr(t,lt()?Reflect.construct(e,n||[],le(t).constructor):e.apply(t,n))}function Wr(t,e){if(e&&(Z(e)==="object"||typeof e=="function"))return e;if(e!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return Hr(t)}function Hr(t){if(t===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function lt(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(lt=function(){return!!t})()}function le(t){return le=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(n){return n.__proto__||Object.getPrototypeOf(n)},le(t)}function Qr(t,e){if(typeof e!="function"&&e!==null)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&Ae(t,e)}function Ae(t,e){return Ae=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(r,a){return r.__proto__=a,r},Ae(t,e)}function k(t,e,n){return e=ut(e),e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function ut(t){var e=Gr(t,"string");return Z(e)=="symbol"?e:e+""}function Gr(t,e){if(Z(t)!="object"||!t)return t;var n=t[Symbol.toPrimitive];if(n!==void 0){var r=n.call(t,e||"default");if(Z(r)!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(t)}var R=function(t){function e(n){var r;return Vr(this,e),r=Ur(this,e,[n]),k(r,"pieRef",null),k(r,"sectorRefs",[]),k(r,"id",Ht("recharts-pie-")),k(r,"handleAnimationEnd",function(){var a=r.props.onAnimationEnd;r.setState({isAnimationFinished:!0}),F(a)&&a()}),k(r,"handleAnimationStart",function(){var a=r.props.onAnimationStart;r.setState({isAnimationFinished:!1}),F(a)&&a()}),r.state={isAnimationFinished:!n.isAnimationActive,prevIsAnimationActive:n.isAnimationActive,prevAnimationId:n.animationId,sectorToFocus:0},r}return Qr(e,t),zr(e,[{key:"isActiveIndex",value:function(r){var a=this.props.activeIndex;return Array.isArray(a)?a.indexOf(r)!==-1:r===a}},{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 a=this.props.isAnimationActive;if(a&&!this.state.isAnimationFinished)return null;var i=this.props,s=i.label,l=i.labelLine,u=i.dataKey,c=i.valueKey,f=A(this.props,!1),d=A(s,!1),p=A(l,!1),y=s&&s.offsetRadius||20,g=r.map(function(m,v){var b=(m.startAngle+m.endAngle)/2,j=T(m.cx,m.cy,m.outerRadius+y,b),O=x(x(x(x({},f),m),{},{stroke:"none"},d),{},{index:v,textAnchor:e.getTextAnchor(j.x,m.cx)},j),B=x(x(x(x({},f),m),{},{fill:"none",stroke:m.fill},p),{},{index:v,points:[T(m.cx,m.cy,m.outerRadius,b),j]}),S=u;return Q(u)&&Q(c)?S="value":Q(u)&&(S=c),h.createElement(P,{key:"label-".concat(m.startAngle,"-").concat(m.endAngle,"-").concat(m.midAngle,"-").concat(v)},l&&e.renderLabelLineItem(l,B,"line"),e.renderLabelItem(s,O,V(m,S)))});return h.createElement(P,{className:"recharts-pie-labels"},g)}},{key:"renderSectorsStatically",value:function(r){var a=this,i=this.props,s=i.activeShape,l=i.blendStroke,u=i.inactiveShape;return r.map(function(c,f){if((c==null?void 0:c.startAngle)===0&&(c==null?void 0:c.endAngle)===0&&r.length!==1)return null;var d=a.isActiveIndex(f),p=u&&a.hasActiveIndex()?u:null,y=d?s:p,g=x(x({},c),{},{stroke:l?c.fill:c.stroke,tabIndex:-1});return h.createElement(P,W({ref:function(v){v&&!a.sectorRefs.includes(v)&&a.sectorRefs.push(v)},tabIndex:-1,className:"recharts-pie-sector"},ke(a.props,c,f),{key:"sector-".concat(c==null?void 0:c.startAngle,"-").concat(c==null?void 0:c.endAngle,"-").concat(c.midAngle,"-").concat(f)}),h.createElement(Kt,W({option:y,isActive:d,shapeType:"sector"},g)))})}},{key:"renderSectorsWithAnimation",value:function(){var r=this,a=this.props,i=a.sectors,s=a.isAnimationActive,l=a.animationBegin,u=a.animationDuration,c=a.animationEasing,f=a.animationId,d=this.state,p=d.prevSectors,y=d.prevIsAnimationActive;return h.createElement(Mt,{begin:l,duration:u,isActive:s,easing:c,from:{t:0},to:{t:1},key:"pie-".concat(f,"-").concat(y),onAnimationStart:this.handleAnimationStart,onAnimationEnd:this.handleAnimationEnd},function(g){var m=g.t,v=[],b=i&&i[0],j=b.startAngle;return i.forEach(function(O,B){var S=p&&p[B],C=B>0?Bt(O,"paddingAngle",0):0;if(S){var X=Le(S.endAngle-S.startAngle,O.endAngle-O.startAngle),w=x(x({},O),{},{startAngle:j+C,endAngle:j+X(m)+C});v.push(w),j=w.endAngle}else{var q=O.endAngle,N=O.startAngle,te=Le(0,q-N),re=te(m),E=x(x({},O),{},{startAngle:j+C,endAngle:j+re+C});v.push(E),j=E.endAngle}}),h.createElement(P,null,r.renderSectorsStatically(v))})}},{key:"attachKeyboardHandlers",value:function(r){var a=this;r.onkeydown=function(i){if(!i.altKey)switch(i.key){case"ArrowLeft":{var s=++a.state.sectorToFocus%a.sectorRefs.length;a.sectorRefs[s].focus(),a.setState({sectorToFocus:s});break}case"ArrowRight":{var l=--a.state.sectorToFocus<0?a.sectorRefs.length-1:a.state.sectorToFocus%a.sectorRefs.length;a.sectorRefs[l].focus(),a.setState({sectorToFocus:l});break}case"Escape":{a.sectorRefs[a.state.sectorToFocus].blur(),a.setState({sectorToFocus:0});break}}}}},{key:"renderSectors",value:function(){var r=this.props,a=r.sectors,i=r.isAnimationActive,s=this.state.prevSectors;return i&&a&&a.length&&(!s||!qt(s,a))?this.renderSectorsWithAnimation():this.renderSectorsStatically(a)}},{key:"componentDidMount",value:function(){this.pieRef&&this.attachKeyboardHandlers(this.pieRef)}},{key:"render",value:function(){var r=this,a=this.props,i=a.hide,s=a.sectors,l=a.className,u=a.label,c=a.cx,f=a.cy,d=a.innerRadius,p=a.outerRadius,y=a.isAnimationActive,g=this.state.isAnimationFinished;if(i||!s||!s.length||!z(c)||!z(f)||!z(d)||!z(p))return null;var m=D("recharts-pie",l);return h.createElement(P,{tabIndex:this.props.rootTabIndex,className:m,ref:function(b){r.pieRef=b}},this.renderSectors(),u&&this.renderLabels(s),tt.renderCallByParent(this.props,null,!1),(!y||g)&&Vt.renderCallByParent(this.props,s,!1))}}],[{key:"getDerivedStateFromProps",value:function(r,a){return a.prevIsAnimationActive!==r.isAnimationActive?{prevIsAnimationActive:r.isAnimationActive,prevAnimationId:r.animationId,curSectors:r.sectors,prevSectors:[],isAnimationFinished:!0}:r.isAnimationActive&&r.animationId!==a.prevAnimationId?{prevAnimationId:r.animationId,curSectors:r.sectors,prevSectors:a.curSectors,isAnimationFinished:!0}:r.sectors!==a.curSectors?{curSectors:r.sectors,isAnimationFinished:!0}:null}},{key:"getTextAnchor",value:function(r,a){return r>a?"start":r<a?"end":"middle"}},{key:"renderLabelLineItem",value:function(r,a,i){if(h.isValidElement(r))return h.cloneElement(r,a);if(F(r))return r(a);var s=D("recharts-pie-label-line",typeof r!="boolean"?r.className:"");return h.createElement(Ft,W({},a,{key:i,type:"linear",className:s}))}},{key:"renderLabelItem",value:function(r,a,i){if(h.isValidElement(r))return h.cloneElement(r,a);var s=i;if(F(r)&&(s=r(a),h.isValidElement(s)))return s;var l=D("recharts-pie-label-text",typeof r!="boolean"&&!F(r)?r.className:"");return h.createElement(_e,W({},a,{alignmentBaseline:"middle",className:l}),s)}}])}(M.PureComponent);se=R;k(R,"displayName","Pie");k(R,"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:!zt.isSsr,animationBegin:400,animationDuration:1500,animationEasing:"ease",nameKey:"name",blendStroke:!1,rootTabIndex:0});k(R,"parseDeltaAngle",function(t,e){var n=ie(e-t),r=Math.min(Math.abs(e-t),360);return n*r});k(R,"getRealPieData",function(t){var e=t.data,n=t.children,r=A(t,!1),a=Ut(n,Oe);return e&&e.length?e.map(function(i,s){return x(x(x({payload:i},r),i),a&&a[s]&&a[s].props)}):a&&a.length?a.map(function(i){return x(x({},r),i.props)}):[]});k(R,"parseCoordinateOfPie",function(t,e){var n=e.top,r=e.left,a=e.width,i=e.height,s=Wt(a,i),l=r+ae(t.cx,a,a/2),u=n+ae(t.cy,i,i/2),c=ae(t.innerRadius,s,0),f=ae(t.outerRadius,s,s*.8),d=t.maxRadius||Math.sqrt(a*a+i*i)/2;return{cx:l,cy:u,innerRadius:c,outerRadius:f,maxRadius:d}});k(R,"getComposedData",function(t){var e=t.item,n=t.offset,r=e.type.defaultProps!==void 0?x(x({},e.type.defaultProps),e.props):e.props,a=se.getRealPieData(r);if(!a||!a.length)return null;var i=r.cornerRadius,s=r.startAngle,l=r.endAngle,u=r.paddingAngle,c=r.dataKey,f=r.nameKey,d=r.valueKey,p=r.tooltipType,y=Math.abs(r.minAngle),g=se.parseCoordinateOfPie(r,n),m=se.parseDeltaAngle(s,l),v=Math.abs(m),b=c;Q(c)&&Q(d)?(Re(!1,`Use "dataKey" to specify the value of pie,
3 the props "valueKey" will be deprecated in 1.1.0`),b="value"):Q(c)&&(Re(!1,`Use "dataKey" to specify the value of pie, 4 the props "valueKey" will be deprecated in 1.1.0`),b=d);var j=a.filter(function(w){return V(w,b,0)!==0}).length,O=(v>=360?j:j-1)*u,B=v-j*y-O,S=a.reduce(function(w,q){var N=V(q,b,0);return w+(z(N)?N:0)},0),C;if(S>0){var X;C=a.map(function(w,q){var N=V(w,b,0),te=V(w,f,q),re=(z(N)?N:0)/S,E;q?E=X.endAngle+ie(m)*u*(N!==0?1:0):E=s;var Pe=E+ie(m)*((N!==0?y:0)+re*B),Se=(E+Pe)/2,Ne=(g.innerRadius+g.outerRadius)/2,ft=[{name:te,value:N,payload:w,dataKey:b,type:p}],mt=T(g.cx,g.cy,Ne,Se);return X=x(x(x({percent:re,cornerRadius:i,name:te,tooltipPayload:ft,midAngle:Se,middleRadius:Ne,tooltipPosition:mt},w),g),{},{value:V(w,b),startAngle:E,endAngle:Pe,payload:w,paddingAngle:ie(m)*u}),X})}return x(x({},g),{},{sectors:C,data:a})});var dt=Qt({chartName:"PieChart",GraphicalChild:R,validateTooltipEventTypes:["item"],defaultTooltipEventType:"item",legendContent:"children",axisComponents:[{axisType:"angleAxis",AxisComp:ge},{axisType:"radiusAxis",AxisComp:pe}],formatAxisMap:Gt,defaultProps:{layout:"centric",startAngle:0,endAngle:360,cx:"50%",cy:"50%",innerRadius:0,outerRadius:"80%"}});const Yr=(t,e)=>ue({queryKey:["form-daily-stats",t,e],queryFn:async()=>{const n=new Date,r=e?Ze(n,e):null;let a=_.from("leads").select("created_at").eq("form_id",t);r&&(a=a.gte("created_at",r.toISOString()));const{data:i,error:s}=await a.order("created_at",{ascending:!0});if(s)throw console.error("Error fetching form daily stats:",s),s;const l=r||(i.length>0?new Date(i[0].created_at):n),u=Et({start:l,end:n}),c=i.reduce((d,p)=>{const y=ve(new Date(p.created_at),"yyyy-MM-dd");return d[y]=(d[y]||0)+1,d},{});return u.map(d=>{const p=ve(d,"yyyy-MM-dd");return{date:ve(d,"MMM dd"),registrations:c[p]||0}})},staleTime:3e4}),Zr=({formId:t})=>{const{t:e}=L("forms"),[n,r]=M.useState("30"),a={30:30,365:365,all:null},{data:i,isLoading:s}=Yr(t,a[n]),l={30:e("periods.last30Days"),365:e("periods.lastYear"),all:e("periods.wholePeriod")};if(s)return o.jsxs("div",{className:"rounded-2xl border border-border/50 bg-card shadow-sm p-6",children:[o.jsxs("div",{className:"space-y-1 mb-6",children:[o.jsx("p",{className:"text-[10px] font-bold text-muted-foreground uppercase tracking-widest",children:e("charts.dailyRegistrations")}),o.jsxs("p",{className:"text-xs text-muted-foreground",children:[e("charts.registrationsOver")," ",l[n].toLowerCase()]})]}),o.jsx(we,{className:"h-[400px] w-full rounded-xl"})]});const u=i&&i.some(c=>c.registrations>0);return o.jsxs("div",{className:"rounded-2xl border border-border/50 bg-card shadow-sm p-6",children:[o.jsxs("div",{className:"flex items-start justify-between mb-6",children:[o.jsxs("div",{className:"space-y-1",children:[o.jsx("p",{className:"text-[10px] font-bold text-muted-foreground uppercase tracking-widest",children:e("charts.dailyRegistrations")}),o.jsxs("p",{className:"text-xs text-muted-foreground",children:[e("charts.registrationsOver")," ",l[n].toLowerCase()]})]}),o.jsxs(He,{value:n,onValueChange:c=>r(c),children:[o.jsx(Qe,{className:"w-[160px] h-8 rounded-lg text-xs",children:o.jsx(Ge,{})}),o.jsxs(Ye,{children:[o.jsx(H,{value:"30",children:e("periods.last30Days")}),o.jsx(H,{value:"365",children:e("periods.lastYear")}),o.jsx(H,{value:"all",children:e("periods.wholePeriod")})]})]})]}),u?o.jsx(de,{width:"100%",height:400,children:o.jsxs(Yt,{data:i,children:[o.jsx(rt,{strokeDasharray:"3 3",stroke:"hsl(var(--border))"}),o.jsx(nt,{dataKey:"date",stroke:"hsl(var(--muted-foreground))",fontSize:11,tickLine:!1,axisLine:!1}),o.jsx(at,{stroke:"hsl(var(--muted-foreground))",fontSize:11,tickLine:!1,axisLine:!1,allowDecimals:!1}),o.jsx(fe,{contentStyle:{backgroundColor:"hsl(var(--card))",border:"1px solid hsl(var(--border))",borderRadius:"12px",boxShadow:"0 4px 6px -1px rgba(0, 0, 0, 0.1)",fontSize:"12px"},labelStyle:{color:"hsl(var(--foreground))"}}),o.jsx(Zt,{type:"monotone",dataKey:"registrations",stroke:"hsl(var(--primary))",strokeWidth:2.5,dot:{r:3,fill:"hsl(var(--primary))"},activeDot:{r:5}})]})}):o.jsx("div",{className:"flex items-center justify-center h-[400px] text-muted-foreground",children:o.jsx("p",{className:"text-sm",children:e("charts.noRegistrations")})})]})},Xr=(t,e)=>ue({queryKey:["form-utm-stats",t,e],queryFn:async()=>{const r=e?Ze(new Date,e):null;let a=_.from("leads").select("utm_data").eq("form_id",t).not("utm_data","is",null);
4r&&(a=a.gte("created_at",r.toISOString()));const{data:i,error:s}=await a;if(s)throw console.error("Error fetching UTM stats:",s),s;const l={},u={},c={};i.forEach(d=>{const p=d.utm_data;p&&(p.utm_source&&(l[p.utm_source]=(l[p.utm_source]||0)+1),p.utm_medium&&(u[p.utm_medium]=(u[p.utm_medium]||0)+1),p.utm_campaign&&(c[p.utm_campaign]=(c[p.utm_campaign]||0)+1))});const f=d=>Object.entries(d).map(([p,y])=>({name:p,count:y})).sort((p,y)=>y.count-p.count);return{sources:f(l),mediums:f(u),campaigns:f(c).slice(0,10)}},staleTime:3e4}),qe=["#8b5cf6","#06b6d4","#10b981","#f59e0b","#ef4444","#ec4899","#6366f1","#84cc16"],Jr=({data:t})=>{const{t:e}=L("forms");return t.length===0?o.jsx("div",{className:"flex items-center justify-center h-[250px] text-muted-foreground",children:o.jsx("p",{children:e("charts.noSourceData")})}):o.jsx(de,{width:"100%",height:250,children:o.jsxs(dt,{children:[o.jsx(R,{data:t,cx:"50%",cy:"50%",innerRadius:50,outerRadius:80,paddingAngle:2,dataKey:"count",nameKey:"name",label:({name:n,percent:r})=>`${n} (${(r*100).toFixed(0)}%)`,labelLine:!1,children:t.map((n,r)=>o.jsx(Oe,{fill:qe[r%qe.length]},`cell-${r}`))}),o.jsx(fe,{contentStyle:{backgroundColor:"hsl(var(--card))",border:"1px solid hsl(var(--border))",borderRadius:"8px"},formatter:n=>[n,"Leads"]})]})})},Ve=["#06b6d4","#8b5cf6","#10b981","#f59e0b","#ef4444","#ec4899","#6366f1","#84cc16"],en=({data:t})=>{const{t:e}=L("forms");return t.length===0?o.jsx("div",{className:"flex items-center justify-center h-[250px] text-muted-foreground",children:o.jsx("p",{children:e("charts.noMediumData")})}):o.jsx(de,{width:"100%",height:250,children:o.jsxs(dt,{children:[o.jsx(R,{data:t,cx:"50%",cy:"50%",innerRadius:50,outerRadius:80,paddingAngle:2,dataKey:"count",nameKey:"name",label:({name:n,percent:r})=>`${n} (${(r*100).toFixed(0)}%)`,labelLine:!1,children:t.map((n,r)=>o.jsx(Oe,{fill:Ve[r%Ve.length]},`cell-${r}`))}),o.jsx(fe,{contentStyle:{backgroundColor:"hsl(var(--card))",border:"1px solid hsl(var(--border))",borderRadius:"8px"},formatter:n=>[n,"Leads"]})]})})},tn=({data:t})=>{const{t:e}=L("forms");return t.length===0?o.jsx("div",{className:"flex items-center justify-center h-[250px] text-muted-foreground",children:o.jsx("p",{children:e("charts.noCampaignData")})}):o.jsx(de,{width:"100%",height:250,children:o.jsxs(Dt,{data:t,layout:"vertical",margin:{left:20,right:20},children:[o.jsx(rt,{strokeDasharray:"3 3",stroke:"hsl(var(--border))"}),o.jsx(nt,{type:"number",stroke:"hsl(var(--muted-foreground))",fontSize:12,tickLine:!1,axisLine:!1,allowDecimals:!1}),o.jsx(at,{type:"category",dataKey:"name",stroke:"hsl(var(--muted-foreground))",fontSize:11,tickLine:!1,axisLine:!1,width:100,tickFormatter:n=>n.length>15?`${n.slice(0,15)}...`:n}),o.jsx(fe,{contentStyle:{backgroundColor:"hsl(var(--card))",border:"1px solid hsl(var(--border))",borderRadius:"8px"},formatter:n=>[n,"Leads"]}),o.jsx(Xt,{dataKey:"count",fill:"#10b981",radius:[0,4,4,0]})]})})},rn=({formId:t})=>{const{t:e}=L("forms"),[n,r]=M.useState("30"),a={30:30,365:365,all:null},{data:i,isLoading:s}=Xr(t,a[n]),l={30:e("periods.last30Days"),365:e("periods.lastYear"),all:e("periods.wholePeriod")};if(s)return o.jsxs("div",{className:"rounded-2xl border border-border/50 bg-card shadow-sm p-6",children:[o.jsxs("div",{className:"space-y-1 mb-6",children:[o.jsx("p",{className:"text-[10px] font-bold text-muted-foreground uppercase tracking-widest",children:e("charts.utmAnalytics")}),o.jsxs("p",{className:"text-xs text-muted-foreground",children:[e("charts.trafficSources")," ",l[n].toLowerCase()]})]}),o.jsx(we,{className:"h-[300px] w-full rounded-xl"})]});const u=i&&(i.sources.length>0||i.mediums.length>0||i.campaigns.length>0);return o.jsxs("div",{className:"rounded-2xl border border-border/50 bg-card shadow-sm p-6",children:[o.jsxs("div",{className:"flex items-start justify-between mb-6",children:[o.jsxs("div",{className:"space-y-1",children:[o.jsx("p",{className:"text-[10px] font-bold text-muted-foreground uppercase tracking-widest",children:e("charts.utmAnalytics")}),o.jsxs("p",{className:"text-xs text-muted-foreground",children:[e("charts.trafficSources")," ",l[n].toLowerCase()]})]}),o.jsxs(He,{value:n,onValueChange:c=>r(c),children:[o.jsx(Qe,{className:"w-[160px] h-8 rounded-lg text-xs",children:o.jsx(Ge,{})}),o.jsxs(Ye,{children:[o.jsx(H,{value:"30",children:e("periods.last30Days")}),o.jsx(H,{value:"365",children:e("periods.lastYear")}),o.jsx(H,{value:"all",children:e("periods.wholePeriod")})]})]})]}),u?o.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:[o.jsxs("div",{children:[o.jsx("p",{className:"text-[10px] font-bold text-muted-foreground uppercase tracking-widest mb-3 text-center",children:e("charts.leadsBySource")}),o.jsx(Jr,{data:(i==null?void 0:i.sources)||[]})]}),o.jsxs("div",{children:[o.jsx("p",{className:"text-[10px] font-bold text-muted-foreground uppercase tracking-widest mb-3 text-center",children:e("charts.leadsByMedium")}),o.jsx(en,{data:(i==null?void 0:i.mediums)||[]})]}),o.jsxs("div",{className:"md:col-span-2 lg:col-span-1",children:[o.jsx("p",{className:"text-[10px] font-bold text-muted-foreground uppercase tracking-widest mb-3 text-center",children:e("charts.topCampaigns")}),o.jsx(tn,{data:(i==null?void 0:i.campaigns)||[]})]})]}):o.jsx("div",{className:"flex items-center justify-center h-[200px] text-muted-foreground",children:o.jsx("p",{className:"text-sm",children:e("charts.noUtmData")})})]})},nn=({leads:t})=>{const{t:e}=L("forms"),{toast:n}=We(),r=async i=>{try{const{error:s}=await _.from("leads").delete().eq("id",i);if(s)throw s;n({title:e("common:success"),description:e("details.leadDeleted")})}catch(s){console.error("Error deleting lead:",s),n({title:e("common:error"),description:e("details.leadDeleteError"),variant:"destructive"})}},a=()=>{try{const i=[e("export.name"),e("export.email"),e("export.phone"),e("export.registrationDate"),e("export.checkInDate"),e("export.purchaseDate"),e("export.status"),e("export.tags"),e("export.additionalData")].join(","),s=t.map(d=>{const p=d.additional_data?Object.entries(d.additional_data).map(([m,v])=>`${m}: ${v}`).join("; "):"",y=(d.tags||[]).join(";
4 "),g=d.is_purchased?e("export.purchased"):d.is_checked_in?e("export.checkedIn"):d.is_registered?e("export.registered"):e("export.lead");return[d.name||"",d.email||"",d.phone||"",d.registered_at||"",d.checked_in_at||"",d.purchased_at||"",g,y,p].map(m=>`"${m}"`).join(",")}),l=[i,...s].join(` 5`),u=new Blob([l],{type:"text/csv;charset=utf-8;"}),c=document.createElement("a"),f=URL.createObjectURL(u);c.setAttribute("href",f),c.setAttribute("download",`leads_export_${new Date().toISOString()}.csv`),document.body.appendChild(c),c.click(),document.body.removeChild(c),n({title:e("common:success"),description:e("details.exportSuccess")})}catch(i){console.error("Error exporting leads:",i),n({title:e("common:error"),description:e("details.exportError"),variant:"destructive"})}};return o.jsxs("div",{className:"space-y-4",children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("p",{className:"text-[10px] font-bold text-muted-foreground uppercase tracking-widest",children:e("details.formLeads")}),o.jsxs(ye,{onClick:a,variant:"outline",size:"sm",className:"h-8 px-3 rounded-lg gap-2 text-xs",children:[o.jsx(Rt,{className:"h-3.5 w-3.5"}),e("details.exportLeads")]})]}),o.jsx("div",{className:"rounded-2xl border border-border/50 bg-card shadow-sm p-6",children:o.jsx(Jt,{leads:t,onViewLead:i=>{console.log("View lead:",i)},onDeleteLead:r})})]})},qn=()=>{const{formId:t}=gt(),e=ze(),{t:n}=L("forms");M.useEffect(()=>{const i=_.channel("form-changes").on("postgres_changes",{event:"*",schema:"public",table:"forms",filter:`id=eq.${t}`},()=>{e.invalidateQueries({queryKey:["form",t]})}).subscribe(),s=_.channel("leads-changes").on("postgres_changes",{event:"*",schema:"public",table:"leads",filter:`form_id=eq.${t}`},()=>{e.invalidateQueries({queryKey:["form",t]})}).subscribe(),l=_.channel("submissions-changes").on("postgres_changes",{event:"*",schema:"public",table:"form_submissions",filter:`form_id=eq.${t}`},()=>{e.invalidateQueries({queryKey:["form",t]})}).subscribe();return()=>{_.removeChannel(i),_.removeChannel(s),_.removeChannel(l)}},[t,e]);const{data:r,isLoading:a}=ue({queryKey:["form",t],queryFn:async()=>{const{data:i,error:s}=await _.from("forms").select(` 6 *, 7 form_submissions(count), 8 leads!leads_form_id_fkey(*) 9 `).eq("id",t).single();if(s)throw s;return i}});return a?o.jsx("div",{className:"animate-pulse p-6",children:n("loading")}):r?o.jsxs("div",{className:"space-y-6 animate-fade-in max-w-5xl mx-auto",children:[o.jsx(tr,{formId:t,name:r.name,description:r.description}),t&&o.jsx(rr,{formId:t}),t&&o.jsx(Zr,{formId:t}),t&&o.jsx(rn,{formId:t}),o.jsx(nn,{leads:r.leads||[]})]}):o.jsx("div",{className:"p-6 text-muted-foreground",children:n("formNotFound")})};export{qn 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.