import{c as D,r,j as s,B as T,a as Y,D as Z,e as ee,S as te,f as se,h as ae,i as le,k as oe,I as ne,m as ce}from"./main-C5rJoLCl.js";import{D as re}from"./layout-2E7L6V5j.js";import{D as ie}from"./date-range-picker-DTzyhuMJ.js";import{C as de,F as ue}from"./FetchWrapper-DZ79aYT8.js";import{C as ge,a as me,b as be,c as pe,d as he,e as xe}from"./command-dpeRkPW7.js";import{P as fe,a as ve,b as Ce}from"./popover-Bp_kD6bA.js";import{C as we}from"./chevrons-up-down-DCCBwKIg.js";import{D as w,A as Se,i as je,u as ke,f as R,a as Ne,j as ye,g as Fe,b as Me,c as De,d as Ve,e as Re,h as Te}from"./data-table-column-header-Bzq2hgMJ.js";import{T as _e,a as Pe,b as y,c as Le,d as He,e as M}from"./table-C_lg7wFA.js";import{S as $e}from"./spinner-zDOxBldC.js";import{C as Ae,a as Ie,D as $}from"./data-table-faceted-filter-3oMq9jOA.js";import{X as Ee}from"./dialog-DoT6WXg8.js";import"./separator-CJhMgss0.js";/**
 * @license lucide-react v0.302.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Ue=D("ArrowRight",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]);/**
 * @license lucide-react v0.302.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Oe=D("Circle",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]]);/**
 * @license lucide-react v0.302.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Ke=D("HelpCircle",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3",key:"1u773s"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);/**
 * @license lucide-react v0.302.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const qe=D("Timer",[["line",{x1:"10",x2:"14",y1:"2",y2:"2",key:"14vaq8"}],["line",{x1:"12",x2:"15",y1:"14",y2:"11",key:"17fdiu"}],["circle",{cx:"12",cy:"14",r:"8",key:"1e1u0o"}]]);function F({data:e,placeholder:t="Select an option",searchPlaceholder:a="Search...",emptyMessage:l="No items found.",onSelect:c,selectedValue:o="",isDisabled:n}){var x;const[i,u]=r.useState(!1),[h,m]=r.useState(o??"");return r.useEffect(()=>{m(o??"")},[o]),s.jsxs(fe,{open:i,onOpenChange:u,children:[s.jsx(ve,{asChild:!0,children:s.jsxs(T,{variant:"outline",role:"combobox","aria-expanded":i,className:"w-[200px] justify-between",disabled:n,children:[h?(x=e.find(b=>b.value===h))==null?void 0:x.label:t,s.jsx(we,{className:"opacity-50"})]})}),s.jsx(Ce,{className:"w-[200px] p-0",children:s.jsxs(ge,{children:[s.jsx(me,{placeholder:a,className:"h-9"}),s.jsxs(be,{children:[s.jsx(pe,{children:l}),s.jsx(he,{children:e.map(b=>s.jsxs(xe,{value:b.value,onSelect:g=>{const C=g===h?"":g;m(C),c(C),u(!1)},children:[b.label,s.jsx(de,{className:Y("ml-auto",h===b.value?"opacity-100":"opacity-0")})]},b.value))})]})]})})]})}const Be=[{value:"",label:"Select Heatmaps"},{value:"profit",label:"Profit"},{value:"leadsPercentage",label:"Leads"},{value:"uniqueClicks",label:"Unique Clicks"},{value:"Att %",label:"Attention %"},{value:"I %",label:"Interest %"},{value:"D %",label:"Desire %"},{value:"atc",label:"ATC %"},{value:"ic",label:"IC %"},{value:"pur",label:"PUR %"},{value:"s1",label:"Scroll 25%"},{value:"s2",label:"Scroll 50%"},{value:"s3",label:"Scroll 75%"},{value:"s4",label:"Scroll 90%"},{value:"t1",label:"10 seconds"},{value:"t2",label:"20 seconds"},{value:"t3",label:"30 seconds"},{value:"t4",label:"40 seconds"},{value:"t5",label:"50 seconds"},{value:"t6",label:"60 seconds"},{value:"t7",label:"70 seconds"},{value:"t8",label:"80 seconds"},{value:"t9",label:"90 seconds"},{value:"t10",label:"100 seconds"},{value:"t110",label:"110 seconds"},{value:"t120",label:"120 seconds"}],A=(e,t)=>{if(!e||!t){console.error("Invalid parameters:",{table:e,value:t});return}const a=e.getAllColumns();if(!a||!a.length){console.error("No columns found in table");return}console.log("Available columns:",a.map(u=>({id:u.id,header:u.columnDef.header}))),console.log("Looking for heatmap value:",t);const l=a.find(u=>{var x,b,g,C;const h=((b=(x=u.columnDef)==null?void 0:x.header)==null?void 0:b.toString().toLowerCase())||"",m=((g=t.value)==null?void 0:g.toLowerCase())||t.toLowerCase();return h.includes(m)||((C=u.id)==null?void 0:C.toLowerCase().includes(m))});if(!l){console.error(`Column ${t.value||t} not found`);return}const c=e.getRowModel();if(!c||!c.rows){console.error("No rows found in table");return}const o=c.rows,n=o.map(u=>{const h=u.getValue(l.id),m=parseFloat((h==null?void 0:h.toString().replace("%",""))||"0");return console.log("Parsed value:",m),m}).filter(u=>!isNaN(u)&&u!==0),i={min:n.length?Math.min(...n):0,max:n.length?Math.max(...n):100};console.log("Calculated minMax:",i),o.forEach((u,h)=>{var g;const m=Number(u.getValue("uniqueClicks"))||0;parseFloat(((g=u.getValue(l.id))==null?void 0:g.toString().replace("%",""))||"0");const b=document.querySelectorAll("tr[data-state]")[h];if(b){const C=Array.from(b.querySelectorAll("td")),f=a.indexOf(l);C[f]&&ze(m,b,t.label||t,f,i)}})};function ze(e,t,a,l,c){console.log(c);let o=0,n=0,i=0;const u=a.toLowerCase();switch(u){case"profit":n=10,i=-5,o=10;break;case"leadspercentage":case"leads":case"lead %":n=35,i=15,o=15;break;case"uniqueclicks":n=40,i=20,o=10;break;case"scroll 25%":case"25%":n=40,i=20,o=10;break;case"scroll 50%":case"50%":n=35,i=15,o=15;break;case"scroll 75%":case"75%":n=20,i=10,o=20;break;case"scroll 90%":case"90%":n=15,i=5,o=25;break;case"10 seconds":n=40,i=20,o=10;break;case"20 seconds":n=35,i=15,o=15;break;case"30 seconds":n=20,i=10,o=20;break;default:console.log("No matching case for:",u);break}if(c&&c.max!==c.min){const h=t.children[l].innerText,m=parseFloat(h.replace("%",""));if(console.log("Debug values:",{clicks:e,value:m,ceilPositive:n,ceilNegative:i,minClicksForNegative:o,minMax:c}),e>0&&m>n){const x=c.max-n,b=x>0?(m-n)/x:0,g=Math.min(Math.max(b,0),1);console.log("Applying positive color with scale:",g),t.style.backgroundColor=`rgba(0, 255, 111, ${g})`,t.style.color="#222"}else if(e>o&&m<i){const x=Math.abs(c.min-i),b=x>0?Math.abs((m-i)/x):0,g=Math.min(Math.max(b,0),1);console.log("Applying negative color with scale:",g),t.style.backgroundColor=`rgba(253, 56, 56, ${g})`,t.style.color="#222"}else console.log("Resetting colors - conditions not met:",{clickCheck:e>o,valueCheck:m<i}),t.style.color="#fff",t.style.backgroundColor=""}else t.style.color="#fff",t.style.backgroundColor="",console.log("Applying color:#fff")}const Ge=[{accessorKey:"segments",header:({table:e})=>s.jsxs(s.Fragment,{children:[s.jsx("button",{onClick:e.getToggleAllRowsExpandedHandler(),children:e.getIsAllRowsExpanded()?"🔽":"▶️"})," ","Segments"]}),cell:({row:e,getValue:t})=>{var o;const a=t(),l=e.parent,c=l&&((o=l.subRows[l.subRows.length-1])==null?void 0:o.id)===e.id;return s.jsxs("div",{className:"relative rounded-md px-2 py-1 text-black",style:{marginLeft:`${e.depth*1.5}rem`},children:[e.depth>0&&!c&&s.jsx("div",{className:"absolute top-0 bottom-0 left-[-1rem] w-px bg-gray-300"}),e.depth>0&&s.jsx("div",{className:"absolute top-4 left-[-1rem] w-4 h-px bg-gray-300"}),s.jsxs("div",{className:"flex items-center gap-2 whitespace-nowrap",children:[e.getCanExpand()?s.jsx("button",{onClick:e.getToggleExpandedHandler(),className:"cursor-pointer",children:e.getIsExpanded()?"🔽":"▶️"}):s.jsx("span",{className:"w-5"}),s.jsx("span",{className:"ml-2",children:a})]})]})},footer:()=>"Total"},{accessorKey:"clicks",header:({column:e})=>s.jsx(w,{column:e,title:"Clicks"}),cell:({row:e})=>s.jsx("div",{className:"w-[80px]",children:e.getValue("clicks")}),footer:e=>e.table.getFilteredRowModel().rows.reduce((a,l)=>a+l.getValue("clicks"),0),enableSorting:!1,enableHiding:!1},{accessorKey:"scroll_25",header:({column:e})=>s.jsx(w,{column:e,title:"Scroll 25 %"}),cell:({row:e})=>{const t=Number(e.getValue("clicks"))||0,a=Number(e.getValue("scroll_25"))||0,l=t>0?(a/t*100).toFixed(1):"0.0";return s.jsxs("div",{className:"w-[80px]",children:[l," %"]})},footer:e=>{const t=e.table.getFilteredRowModel().rows,a=t.reduce((o,n)=>o+(Number(n.getValue("clicks"))||0),0),l=t.reduce((o,n)=>o+(Number(n.getValue("scroll_25"))||0),0);return`${a>0?(l/a*100).toFixed(1):"0.0"} %`},enableSorting:!0,enableHiding:!1},{accessorKey:"scroll_50",header:({column:e})=>s.jsx(w,{column:e,title:"Scroll 50 %"}),cell:({row:e})=>{const t=Number(e.getValue("clicks"))||0,a=Number(e.getValue("scroll_50"))||0,l=t>0?(a/t*100).toFixed(1):"0.0";return s.jsxs("div",{className:"w-[80px]",children:[l,"%"]})},footer:e=>{const t=e.table.getFilteredRowModel().rows,a=t.reduce((o,n)=>o+(Number(n.getValue("clicks"))||0),0),l=t.reduce((o,n)=>o+(Number(n.getValue("scroll_50"))||0),0);return`${a>0?(l/a*100).toFixed(1):"0.0"}%`},enableSorting:!0,enableHiding:!1},{accessorKey:"scroll_75",header:({column:e})=>s.jsx(w,{column:e,title:"Scroll 75 %"}),cell:({row:e})=>{const t=Number(e.getValue("clicks"))||0,a=Number(e.getValue("scroll_75"))||0,l=t>0?(a/t*100).toFixed(1):"0.0";return s.jsxs("div",{className:"w-[80px]",children:[l,"%"]})},footer:e=>{const t=e.table.getFilteredRowModel().rows,a=t.reduce((o,n)=>o+(Number(n.getValue("clicks"))||0),0),l=t.reduce((o,n)=>o+(Number(n.getValue("scroll_75"))||0),0);return`${a>0?(l/a*100).toFixed(1):"0.0"}%`},enableSorting:!0,enableHiding:!1},{accessorKey:"scroll_90",header:({column:e})=>s.jsx(w,{column:e,title:"Scroll 90 %"}),cell:({row:e})=>{const t=Number(e.getValue("clicks"))||0,a=Number(e.getValue("scroll_90"))||0,l=t>0?(a/t*100).toFixed(1):"0.0";return s.jsxs("div",{className:"w-[80px]",children:[l,"%"]})},footer:e=>{const t=e.table.getFilteredRowModel().rows,a=t.reduce((o,n)=>o+(Number(n.getValue("clicks"))||0),0),l=t.reduce((o,n)=>o+(Number(n.getValue("scroll_90"))||0),0);return`${a>0?(l/a*100).toFixed(1):"0.0"}%`},enableSorting:!0,enableHiding:!1},{accessorKey:"form_open",header:({column:e})=>s.jsx(w,{column:e,title:"Form open"}),cell:({row:e})=>s.jsx("div",{className:"w-[80px]",children:e.getValue("form_open")}),footer:e=>e.table.getFilteredRowModel().rows.reduce((a,l)=>a+l.getValue("form_open"),0),enableSorting:!1,enableHiding:!1},{accessorKey:"formPercentage",header:({column:e})=>s.jsx(w,{column:e,title:"Form Open %"}),cell:({row:e})=>{const t=Number(e.getValue("clicks"))||0,a=Number(e.getValue("form_open"))||0,l=t>0?(a/t*100).toFixed(1):"0.0";return s.jsxs("div",{className:"w-[80px]",children:[l,"%"]})},footer:e=>{const t=e.table.getFilteredRowModel().rows,a=t.reduce((o,n)=>o+(Number(n.getValue("clicks"))||0),0),l=t.reduce((o,n)=>o+(Number(n.getValue("form_open"))||0),0);return`${a>0?(l/a*100).toFixed(1):"0.0"}%`},enableSorting:!0,enableHiding:!1},{accessorKey:"leads",header:({column:e})=>s.jsx(w,{column:e,title:"Leads"}),cell:({row:e})=>s.jsx("div",{className:"w-[80px]",children:e.getValue("leads")}),footer:e=>e.table.getFilteredRowModel().rows.reduce((a,l)=>a+l.getValue("leads"),0),enableSorting:!1,enableHiding:!1},{accessorKey:"leadsPercentage",header:({column:e})=>s.jsx(w,{column:e,title:"Leads %"}),cell:({row:e})=>{const t=Number(e.getValue("clicks"))||0,a=Number(e.getValue("leads"))||0,l=t>0?(a/t*100).toFixed(1):"0.0";return s.jsxs("div",{className:"w-[80px]",children:[l,"%"]})},footer:e=>{const t=e.table.getFilteredRowModel().rows,a=t.reduce((o,n)=>o+(Number(n.getValue("clicks"))||0),0),l=t.reduce((o,n)=>o+(Number(n.getValue("leads"))||0),0);return`${a>0?(l/a*100).toFixed(1):"0.0"}%`},enableSorting:!0,enableHiding:!1},{accessorKey:"time_10s",header:({column:e})=>s.jsx(w,{column:e,title:"10s %"}),cell:({row:e})=>{const t=Number(e.getValue("clicks"))||0,a=Number(e.getValue("time_10s"))||0,l=t>0?(a/t*100).toFixed(1):"0.0";return s.jsxs("div",{className:"w-[80px]",children:[l,"%"]})},footer:e=>{const t=e.table.getFilteredRowModel().rows,a=t.reduce((o,n)=>o+(Number(n.getValue("clicks"))||0),0),l=t.reduce((o,n)=>o+(Number(n.getValue("time_10s"))||0),0);return`${a>0?(l/a*100).toFixed(1):"0.0"}%`},enableSorting:!0,enableHiding:!1},{accessorKey:"time_20s",header:({column:e})=>s.jsx(w,{column:e,title:"20s %"}),cell:({row:e})=>{const t=Number(e.getValue("clicks"))||0,a=Number(e.getValue("time_20s"))||0,l=t>0?(a/t*100).toFixed(1):"0.0";return s.jsxs("div",{className:"w-[80px]",children:[l,"%"]})},footer:e=>{const t=e.table.getFilteredRowModel().rows,a=t.reduce((o,n)=>o+(Number(n.getValue("clicks"))||0),0),l=t.reduce((o,n)=>o+(Number(n.getValue("time_20s"))||0),0);return`${a>0?(l/a*100).toFixed(1):"0.0"}%`},enableSorting:!0,enableHiding:!1},{accessorKey:"time_40s",header:({column:e})=>s.jsx(w,{column:e,title:"40s %"}),cell:({row:e})=>{const t=Number(e.getValue("clicks"))||0,a=Number(e.getValue("time_40s"))||0,l=t>0?(a/t*100).toFixed(1):"0.0";return s.jsxs("div",{className:"w-[80px]",children:[l,"%"]})},footer:e=>{const t=e.table.getFilteredRowModel().rows,a=t.reduce((o,n)=>o+(Number(n.getValue("clicks"))||0),0),l=t.reduce((o,n)=>o+(Number(n.getValue("time_40s"))||0),0);return`${a>0?(l/a*100).toFixed(1):"0.0"}%`},enableSorting:!0,enableHiding:!1},{accessorKey:"time_60s",header:({column:e})=>s.jsx(w,{column:e,title:"60s %"}),cell:({row:e})=>{const t=Number(e.getValue("clicks"))||0,a=Number(e.getValue("time_60s"))||0,l=t>0?(a/t*100).toFixed(1):"0.0";return s.jsxs("div",{className:"w-[80px]",children:[l,"%"]})},footer:e=>{const t=e.table.getFilteredRowModel().rows,a=t.reduce((o,n)=>o+(Number(n.getValue("clicks"))||0),0),l=t.reduce((o,n)=>o+(Number(n.getValue("time_60s"))||0),0);return`${a>0?(l/a*100).toFixed(1):"0.0"}%`},enableSorting:!0,enableHiding:!1},{accessorKey:"time_80s",header:({column:e})=>s.jsx(w,{column:e,title:"80s %"}),cell:({row:e})=>{const t=Number(e.getValue("clicks"))||0,a=Number(e.getValue("time_80s"))||0,l=t>0?(a/t*100).toFixed(1):"0.0";return s.jsxs("div",{className:"w-[80px]",children:[l,"%"]})},footer:e=>{const t=e.table.getFilteredRowModel().rows,a=t.reduce((o,n)=>o+(Number(n.getValue("clicks"))||0),0),l=t.reduce((o,n)=>o+(Number(n.getValue("time_80s"))||0),0);return`${a>0?(l/a*100).toFixed(1):"0.0"}%`},enableSorting:!0,enableHiding:!1}];function Je({table:e}){return s.jsxs(Z,{children:[s.jsx(ee,{asChild:!0,children:s.jsxs(T,{variant:"outline",size:"sm",className:"ml-auto hidden h-8 lg:flex",children:[s.jsx(te,{}),"View"]})}),s.jsxs(se,{align:"end",className:"w-[150px]",children:[s.jsx(ae,{children:"Toggle columns"}),s.jsx(le,{}),e.getAllColumns().filter(t=>typeof t.accessorFn<"u"&&t.getCanHide()).map(t=>s.jsx(oe,{className:"capitalize",checked:t.getIsVisible(),onCheckedChange:a=>t.toggleVisibility(!!a),children:t.id},t.id))]})]})}function We({table:e}){const[t,a]=r.useState({value:"profit",label:"Profit"});r.useEffect(()=>{var c;if(e&&((c=e.getRowModel().rows)==null?void 0:c.length)>0&&t){const o=setTimeout(()=>{A(e,t)},100);return()=>clearTimeout(o)}},[e,t,e==null?void 0:e.getRowModel().rows]);const l=c=>{var o;c&&(a(c),e&&((o=e.getRowModel().rows)==null?void 0:o.length)>0&&A(e,c))};return s.jsx(F,{data:Be,placeholder:"Choose Heatmap",searchPlaceholder:"Search heatmaps...",onSelect:l,selectedValue:t,value:t})}const Xe=[{value:"backlog",label:"Backlog",icon:Ke},{value:"todo",label:"Todo",icon:Oe},{value:"in progress",label:"In Progress",icon:qe},{value:"done",label:"Done",icon:Ae},{value:"canceled",label:"Canceled",icon:Ie}],Qe=[{label:"Low",value:"low",icon:Se},{label:"Medium",value:"medium",icon:Ue},{label:"High",value:"high",icon:je}];function Ye({table:e}){const t=e.getState().columnFilters.length>0;return s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsxs("div",{className:"flex flex-1 items-center space-x-2",children:[s.jsx(ne,{placeholder:"Filter Campaigns...",className:"h-8 w-[150px] lg:w-[250px]"}),e.getColumn("status")&&s.jsx($,{column:e.getColumn("status"),title:"Status",options:Xe}),e.getColumn("priority")&&s.jsx($,{column:e.getColumn("priority"),title:"Priority",options:Qe}),t&&s.jsxs(T,{variant:"ghost",onClick:()=>e.resetColumnFilters(),className:"h-8 px-2 lg:px-3",children:["Reset",s.jsx(Ee,{})]})]}),s.jsx(We,{table:e}),s.jsx(Je,{table:e})]})}function Ze({columns:e,data:t,isLoading:a=!1}){var C;const[l,c]=r.useState({}),[o,n]=r.useState({}),[i,u]=r.useState([]),[h,m]=r.useState([]),[x,b]=r.useState({}),g=ke({data:t,columns:e,state:{sorting:h,columnVisibility:o,rowSelection:l,columnFilters:i,expanded:x},enableRowSelection:!0,onRowSelectionChange:c,onSortingChange:m,onColumnFiltersChange:u,onColumnVisibilityChange:n,getCoreRowModel:Te(),getFilteredRowModel:Re(),getPaginationRowModel:Ve(),getSortedRowModel:De(),getFacetedRowModel:Me(),getFacetedUniqueValues:Fe(),getExpandedRowModel:ye(),onExpandedChange:b,getSubRows:f=>f.subRows});return s.jsxs("div",{className:"space-y-4",children:[s.jsx(Ye,{table:g}),s.jsx("div",{className:"rounded-md border",children:s.jsxs(_e,{children:[s.jsx(Pe,{children:g.getHeaderGroups().map(f=>s.jsx(y,{children:f.headers.map(p=>s.jsx(Le,{colSpan:p.colSpan,children:p.isPlaceholder?null:R(p.column.columnDef.header,p.getContext())},p.id))},f.id))}),s.jsx(He,{children:a?s.jsx(y,{children:s.jsx(M,{colSpan:e.length,className:"h-24 text-center",children:s.jsx($e,{children:"Loading..."})})}):(C=g.getRowModel().rows)!=null&&C.length?g.getRowModel().rows.map(f=>s.jsx(y,{"data-state":f.getIsSelected()&&"selected",children:f.getVisibleCells().map(p=>s.jsx(M,{className:"p-0 px-2",children:R(p.column.columnDef.cell,p.getContext())},p.id))},f.id)):s.jsx(y,{children:s.jsx(M,{colSpan:e.length,className:"h-24 text-center",children:"No results."})})}),s.jsx("tfoot",{children:s.jsx(y,{className:"bg-muted/50 font-medium",children:g.getFooterGroups().map(f=>s.jsx(r.Fragment,{children:f.headers.map(p=>s.jsx(M,{children:p.isPlaceholder?null:R(p.column.columnDef.footer,p.getContext())},p.id))},f.id))})})]})}),s.jsx(Ne,{table:g})]})}const et=e=>{const t=Array.from({length:10},(o,n)=>({value:`v${n+1}`,label:e[`v${n+1}`]||`Custom V${n+1}`})),a=[{value:"",label:"Select Segments"},{value:"utm_source",label:"UTM Source"},{value:"utm_medium",label:"UTM Medium"},{value:"utm_campaign",label:"UTM Campaign"},{value:"utm_term",label:"UTM Term"},{value:"utm_content",label:"UTM Content"},{value:"utm_id",label:"UTM ID"},{value:"keyword",label:"Keyword"},...t],l=[{value:"",label:"Select Segments"},{value:"utm_medium",label:"UTM Medium"},{value:"utm_campaign",label:"UTM Campaign"},{value:"utm_term",label:"UTM Term"},{value:"utm_content",label:"UTM Content"},{value:"utm_id",label:"UTM ID"},{value:"device",label:"Device Type"},{value:"country",label:"Country"},...t],c=[{value:"",label:"Select Segments"},{value:"utm_term",label:"UTM Term"},{value:"utm_content",label:"UTM Content"},{value:"utm_id",label:"UTM ID"},{value:"device",label:"Device Type"},{value:"country",label:"Country"},...t];return{segmentOptions1:a,segmentOptions2:l,segmentOptions3:c}},I=e=>Array.isArray(e)?e.map(t=>({...t,id:t.id||"",slug:t.slug||"",clicks:Number(t.clicks)||0,uniqueClicks:Number(t.uniqueClicks)||0,leads:Number(t.leads)||0,subRows:t._children?I(t._children):void 0})):[];function bt(){const e=new ue(chatizy==null?void 0:chatizy.pluginApiUrl,chatizy==null?void 0:chatizy.nonce),[t,a]=r.useState(!0),{campaignId:l}=ce(),[c,o]=r.useState({}),[n,i]=r.useState({segmentOptions1:[],segmentOptions2:[],segmentOptions3:[]}),[u,h]=r.useState(null),[m,x]=r.useState(null),[b,g]=r.useState(null),[C,f]=r.useState(!1),[p,E]=r.useState(!1),[U,_]=r.useState(null),[O,K]=r.useState([]),P=new Date,L=new Date;L.setDate(P.getDate()-6);const H=d=>d.toISOString().split("T")[0],[N,q]=r.useState({from:H(L),to:H(P)}),[B,z]=r.useState([]),G=async d=>{a(!0);try{const v=[u,C?m:null,p?b:null].filter(Boolean),k={dateStart:d.dateStart||N.from,dateEnd:d.dateEnd||N.to,segments:v,campaignId:l},S=await e.post("/stats",JSON.stringify(k)),j=I(S.data);z(j),a(!1)}catch(v){console.error("Error fetching data:",v)}finally{a(!1)}};r.useEffect(()=>{l&&(async()=>{try{const v=await e.get(`/campaign/get/${l}`);if(v.status==="success"){const k=JSON.parse(v.data.settings),S={};for(let j=1;j<=10;j++){const Q=k[`custom${j}_param`];S[`v${j}`]=`V${j} : ${Q||`Custom V${j}`}`}o(S),i(et(S))}}catch(v){console.error("Failed to load custom field labels",v)}})()},[l]);const J=d=>{_(d||null),window.location.hash=`#/stats/${d}`},W=d=>{const v=S=>S.toISOString().split("T")[0],k={from:v(d.range.from),to:v(d.range.to)};q(k)},V=(d,v)=>{switch(v){case 1:h(d),f(!0);break;case 2:x(d),E(!!d);break;case 3:g(d);break}};r.useEffect(()=>{G({})},[l,u,m,b,N]),r.useEffect(()=>{l&&_(l)},[l]),r.useEffect(()=>{(async()=>{try{const k=(await e.get("/campaigns")).data.map(S=>({value:S.id.toString(),label:S.name}));K(k)}catch(v){console.error("Failed to load campaigns:",v)}})()},[]);const X=[{name:"Dashboard",href:"#/dashboard"},{name:"Stats"}];return s.jsx(re,{breadcrumb:X,toolbarRight:s.jsx(ie,{onUpdate:W,initialDateFrom:N.from,initialDateTo:N.to,align:"start",locale:"en-GB",showCompare:!1}),children:s.jsxs("div",{className:"space-y-6",children:[s.jsx(F,{data:O,placeholder:"Choose Campaign",searchPlaceholder:"Search campaign...",onSelect:d=>J(d),isDisabled:!1,selectedValue:U},"campaign"),s.jsx(F,{data:n.segmentOptions1,placeholder:"Choose Segment 1",searchPlaceholder:"Search segments...",onSelect:d=>V(d,1),isDisabled:!1},"segment1"),s.jsx(F,{data:n.segmentOptions2,placeholder:"Choose Segment 2",searchPlaceholder:"Search segments...",onSelect:d=>V(d,2),isDisabled:!C},`segment2-${C}`),s.jsx(F,{data:n.segmentOptions3,placeholder:"Choose Segment 3",searchPlaceholder:"Search segments...",onSelect:d=>V(d,3),isDisabled:!p},`segment3-${p}`),s.jsx(Ze,{data:B,columns:Ge,isLoading:t})]})})}export{bt as default};
//# sourceMappingURL=index-Dd__J1Dr.js.map
