1import{aT as W,x as n,bs as oe,by as we,ck as vt,cl as Ue,z as e,cd as Tt,ce as Me,cm as Et,bX as At,bY as kt,cn as It,bZ as Ot,b_ as _t,ci as Nt,b$ as Ft,cf as Rt,cg as Pt,ch as Ut,cj as Mt}from"./vendor-DUAuXWev.js";import{aj as Lt,ak as Vt,B as F,T as E,e as ke,a3 as Be,cZ as $e,am as zt,aP as ue,b as G,b6 as Wt,b7 as Yt,b8 as wt,M as z,az as He,P as Te,aA as Ge,aB as Je,aC as Y,aD as j,aE as ne,k as Ee,ai as Ae,C as Ie,as as Bt,c as me,cP as $t,d1 as Ht,bU as Gt,aY as Jt,bV as qt,v as Qt,b9 as Kt,r as Zt}from"./vendor_ui-BBCpt_2H.js";import{u as Xt,D as er}from"./DateRangePicker-5R0PBg3i.js";import{b as qe,c as fe,u as tr,a0 as rr,ad as Z,s as ar}from"./index-BIF91r-S.js";import{a as or,S as nr}from"./ShopperApi.service-BGoZ81eO.js";import{D as sr}from"./AIInsights-DXKwyyic.js";import{P as Qe}from"./PerformanceApi.service-BQQ9rE7V.js";import{A as ir,M as lr}from"./add-schedule-CsDSU0GG.js";import{D as cr,a as ur,T as dr}from"./DraggableTableCell-8cYVoZQg.js";import{C as mr}from"./ColumnFilterPopover-DJiN9cxL.js";import"./parse.util-Cg9Ngn63.js";import"./parse.util-C4zncjBt.js";import"./factory-D1K1Zqmg.js";const fr=r=>{if(!r)return"";let i;return Array.isArray(r)?i=new Date(r[0],r[1]-1,r[2],r[3]||0,r[4]||0,r[5]||0):i=new Date(r),isNaN(i.getTime())?"Unknown Date":`${i.toLocaleDateString()} ${i.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}`},T=Object.freeze({EQUALS:1,STARTS_WITH:2,ENDS_WITH:3,INCLUDES:4,LENGTH:5});let Le={"--COMMON--":[{pattern:"gform",option:T.STARTS_WITH},{pattern:"state",option:T.LENGTH,value:2},{pattern:"is_submit",option:T.STARTS_WITH},{pattern:"version_hash",option:T.EQUALS},{pattern:"adkey",option:T.EQUALS},{pattern:"adKey",option:T.EQUALS},{pattern:"nsTracking",option:T.EQUALS},{pattern:"nstracking",option:T.EQUALS},{pattern:"touchpoints",option:T.EQUALS},{pattern:"recaptcha_response",option:T.EQUALS},{pattern:"input_",option:T.LENGTH,value:100}]};const ve={"Window Hero":{input_7:"address","input_11.1":"your-message"},"60338 - Airport Chrysler Dodge Jeep":{input_7:"model",input_8:"model-year",input_9:"brand",input_10:"model",input_11:"vin",input_12:"stock",input_13:"level",input_14:"details-url",input_18:"condition",input_1337:"device"},"45821 - Sarasota Chrysler Dodge Jeep Ram Fiat":{input_7:"model",input_8:"model-year",input_9:"brand",input_10:"model",input_12:"stock",input_13:"level",input_14:"details-url",input_18:"condition",input_1337:"device"},"The Lash Lounge":{input_5:"your-message",utm_medium:"Medium",utm_source:"Channel",utm_vendor:"Vendor"},"Yard Patrol Pros":{input_10:"address","input_12.1":"your-message"},FranNet:{input_8:"shop"}},Ve=["preferredcontactmethod","preferred_contact_method","preferred-contact-method","preferred"];function pr(r,i=!1){if(i)return ve[r];for(const m of Object.keys(ve))if(r.includes(m))return ve[m];return{}}function hr(r,i,m){for(const h of Object.keys(Le))if(h==="--COMMON--"||r.startsWith(h)){let P=Le[h];for(const g of P)switch(g.option){case T.EQUALS:if(i==g.pattern)return!0;break;case T.STARTS_WITH:if(i.startsWith(g.pattern))return!0;break;case T.ENDS_WITH:if(i.endsWith(g.pattern))return!0;break;case T.INCLUDES:if(i.includes(g.pattern))return!0;break;case T.LENGTH:const y=g.value?g.value:-1;if(y>0&&i==g.pattern&&(""+m).length>y)return!0;break}}return!1}const gr=({lead:r,onCategoryChange:i,onClose:m,onIsFavoriteChange:h,onNoteChange:P,onValueChange:g})=>{const[y,f]=n.useState(!1),[v,se]=n.useState(""),[Oe,pe]=n.useState(""),[w,ie]=n.useState("Uncategorized"),[A,q]=n.useState(null),[he,Q]=n.useState(!1),{selectedAccount:V}=qe(),M=oe(l=>l.context.selectedAccount),B=oe(l=>l.context.parentAccountId),L=oe(l=>l.auth.enhancedJWT);n.useEffect(()=>{let l=!0;if(r!=null&&r.platformTrackingId&&L&&(r==null?void 0:r.source)==="webForm"){const S=fe.PERFORMANCE_DATA_SERVICE_V8_URL;if(!S)return;const k=we.create({baseURL:S.replace(/\/+$/,"")});k.interceptors.request.use(x=>(x.headers=x.headers||{},x.headers.Authorization=`Bearer ${L}`,x));const C=new Qe(k,()=>"Unauthorized");Q(!0),C.getAttributionProLeadById(String(r.platformTrackingId)).then(x=>{if(l)if(x&&x.length>0){x.sort((O,_)=>{const U=O.leadHistoryEventOrder??0,R=_.leadHistoryEventOrder??0;if(U!==R)return U-R;const K=new Date(O.leadHistoryEventCreateDate||0).getTime(),ce=new Date(_.leadHistoryEventCreateDate||0).getTime();return K-ce});let I=null;x.forEach(O=>{var R;const _=new Date(O.leadHistoryEventCreateDate||0).toDateString();((R=O.leadHistoryEventType)==null?void 0:R.toLowerCase())==="ad"?I=_:I===_?O.leadHistoryEventType="Ad":I=null}),q(x)}else q([])}).catch(x=>{console.error("Error fetching attribution pro journey for lead:",x),l&&q([])}).finally(()=>{l&&Q(!1)})}else q([]);return()=>{l=!1}},[r==null?void 0:r.platformTrackingId,r==null?void 0:r.source,L]);const X=n.useMemo(()=>{var S;const l="16141";if(String(B)===l||(V==null?void 0:V.brandId)===l||String(V==null?void 0:V.id)===l)return!0;
1if(M){const k=M.brandId||M.parentAccountId||M.parent_account_id||((S=M.brand)==null?void 0:S.id)||M.id||M.accountId;if(String(k)===l)return!0}return!1},[V,M,B]),ee=n.useMemo(()=>{var k;let l=((k=r.formData)==null?void 0:k.data)??{},S=[];return Object.keys(l).map(C=>{let x=C;const I=pr(r.accountName);I[C]&&(x=I[C]);let O=!1,_=hr(r.accountName,x,l[C]);if(Ve.includes(C)&&(O=Ve.filter(R=>R!==C).some(R=>!!l[R])),!_&&!O&&typeof l[C]<"u"&&l[C]!==null){const U=vt(x.replace(/_|-/g," ").trim());if(X){const R=U.toLowerCase(),K=x.toLowerCase();if(R==="referer title"||R==="referrer title"||K==="referer_title"||K==="referrer_title")return}S.push({field:C,label:U,value:String(l[C]??"")})}}),S},[r,X]);n.useEffect(()=>{f(r.leadIsFavorite??!1),se(String(r.leadValue??"")),ie(r.leadCategory?r.leadCategory:"Uncategorized"),pe(String(r.leadNote??""))},[r]);const ge=n.useCallback(l=>{i==null||i(r,l.target.value),ie(l.target.value)},[r,i]),te=Ue(n.useCallback(l=>P==null?void 0:P(r,l),[r,P]),500),le=n.useCallback(l=>{te(l.target.value),pe(l.target.value)},[te]),re=Ue(n.useCallback(l=>g==null?void 0:g(r,l),[r,g]),500),xe=n.useCallback(l=>{const S=parseFloat(l.target.value);re(isNaN(S)?void 0:S),se(l.target.value)},[re]),be=n.useCallback(()=>{f(l=>(h==null||h(r,!l),!l))},[r,h]),ye=n.useCallback(()=>{m==null||m()},[m]);return e.jsxs(Lt,{open:!0,onClose:m,maxWidth:A&&A.length>0?"lg":"md",fullWidth:!0,children:[e.jsx(Vt,{children:e.jsxs(F,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs(E,{variant:"h6",children:["Form Submit Details: ",e.jsx(E,{component:"span",color:"text.primary",children:r.name})]}),e.jsx(F,{children:e.jsx(ke,{onClick:be,size:"small",children:y?e.jsx(Be,{color:"primary"}):e.jsx($e,{})})})]})}),e.jsx(zt,{dividers:!0,sx:{p:0,overflowY:"hidden"},children:e.jsxs(ue,{container:!0,sx:{minHeight:"500px"},children:[e.jsxs(ue,{item:!0,xs:12,md:A&&A.length>0?8:12,sx:{p:3,borderRight:A&&A.length>0?1:0,borderColor:"divider",overflowY:"auto",maxHeight:"70vh"},children:[e.jsxs(F,{sx:{mb:3,display:"flex",flexWrap:"wrap",gap:2},children:[e.jsx(G,{label:"Name",value:r.name??"",InputProps:{readOnly:!0},variant:"outlined",size:"small"}),e.jsx(G,{label:"Email",value:r.email,InputProps:{readOnly:!0},variant:"outlined",size:"small"}),e.jsx(G,{label:"Phone",value:r.phoneNumber,InputProps:{readOnly:!0},variant:"outlined",size:"small"}),e.jsx(G,{label:"Date",value:or(r.reportDate),InputProps:{readOnly:!0},variant:"outlined",size:"small"}),e.jsx(G,{label:"Source",value:r.source,InputProps:{readOnly:!0},variant:"outlined",size:"small"}),e.jsx(G,{label:"Campaign",value:r.campaignName,InputProps:{readOnly:!0},variant:"outlined",size:"small"}),e.jsxs(Wt,{size:"small",sx:{minWidth:150},children:[e.jsx(Yt,{children:"Category"}),e.jsxs(wt,{label:"Category",onChange:ge,value:w,children:[e.jsx(z,{value:"Uncategorized",children:"Uncategorized"}),e.jsx(z,{value:"New Customer",children:"New Customer"}),e.jsx(z,{value:"Existing Customer",children:"Existing Customer"}),e.jsx(z,{value:"Duplicate",children:"Duplicate"}),e.jsx(z,{value:"Test Lead",children:"Test Lead"}),e.jsx(z,{value:"Spam",children:"Spam"}),e.jsx(z,{value:"Other",children:"Other"})]})]}),e.jsx(G,{label:"Value",type:"number",value:v,onChange:xe,InputProps:{startAdornment:"$"},variant:"outlined",size:"small"})]}),ee.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(E,{variant:"h6",gutterBottom:!0,children:"Form Fields"}),e.jsx(He,{component:Te,sx:{mb:3},children:e.jsxs(Ge,{size:"small",children:[e.jsx(Je,{children:e.jsxs(Y,{children:[e.jsx(j,{children:"Field"}),e.jsx(j,{children:"Value"})]})}),e.jsx(ne,{children:ee.map(l=>e.jsxs(Y,{children:[e.jsx(j,{children:e.jsx(Ee,{title:`Field Name: ${l.field}`,children:e.jsx("span",{children:l.label})})}),e.jsx(j,{children:l.value})]},l.field))})]})})]}),e.jsx(sr,{type:"form"}),e.jsx(E,{variant:"h6",gutterBottom:!0,children:"Notes"}),e.jsx(G,{fullWidth:!0,multiline:!0,onChange:le,placeholder:"Add notes about this form submission...",rows:4,sx:{mb:3},value:Oe,variant:"outlined"})]}),A&&A.length>0&&e.jsxs(ue,{item:!0,xs:12,md:4,sx:{p:3,bgcolor:"grey.50",overflowY:"auto",maxHeight:"70vh"},children:[e.jsx(E,{variant:"h6",gutterBottom:!0,children:"Journey Timeline"}
1),e.jsx(F,{sx:{position:"relative",ml:2,borderLeft:"2px solid",borderColor:"grey.300",pt:1,pb:2},children:A.map((l,S)=>{var O;const k=S===A.length-1,C=((O=l.leadHistoryEventType)==null?void 0:O.toLowerCase())==="ad",x=fr(l.leadHistoryEventCreateDate);let I=l.leadHistoryEventUrl||"";if(I)try{I=new URL(I).pathname}catch{}return e.jsxs(F,{sx:{position:"relative",pl:3,mb:4,"&:last-child":{mb:0}},children:[e.jsx(F,{sx:{position:"absolute",left:"-6px",top:"24px",width:"10px",height:"10px",borderRadius:"50%",bgcolor:k?"success.main":"primary.main",boxShadow:"0 0 0 4px #fafafa"}}),e.jsxs(Te,{elevation:1,sx:{p:2,borderRadius:2},children:[e.jsxs(F,{sx:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",mb:1},children:[e.jsxs(E,{variant:"subtitle2",color:"text.secondary",children:["Step ",S+1]}),e.jsx(Ae,{label:C?"Ad":"Organic",size:"small",color:C?"primary":"default",variant:C?"filled":"outlined",sx:{height:20,fontSize:"0.7rem"}})]}),e.jsx(E,{variant:"body2",sx:{fontWeight:500,mb:1},children:x}),l.leadHistoryEventUrl&&e.jsx(Ee,{title:l.leadHistoryEventUrl,arrow:!0,placement:"top",children:e.jsx(E,{variant:"caption",sx:{display:"block",wordBreak:"break-all",color:"text.secondary",mb:1,cursor:"help",textDecoration:"underline",textDecorationStyle:"dotted"},children:I})}),k&&e.jsx(F,{sx:{mt:2},children:e.jsx(Ae,{label:"Form Submitted",color:"success",size:"small",sx:{fontWeight:"bold"}})})]})]},S)})})]}),he&&e.jsx(ue,{item:!0,xs:12,md:4,sx:{p:3,display:"flex",justifyContent:"center",alignItems:"center"},children:e.jsx(Ie,{})})]})}),e.jsx(Bt,{children:e.jsx(me,{onClick:ye,children:"Close"})})]})},xr=W.memo(gr),br=({colSpan:r})=>e.jsx(Y,{children:e.jsx(j,{colSpan:r,align:"center",children:e.jsx(E,{variant:"subtitle1",color:"text.secondary",sx:{m:5},children:"No matching records founds"})})}),yr=W.memo(br),Cr=$t(({className:r,...i})=>e.jsx(Ee,{...i,classes:{popper:r}}))({[`& .${Ht.tooltip}`]:{maxWidth:500,fontWeight:"normal",fontFamily:"monospace"}});function Sr(r){const i=Array.isArray(r)?r[0]||"":r||"";return i==="devhub"||i==="wordPressForm"||i==="landingPage"?"Netsertive Landing Page Form":i==="facebook"?"Facebook Form":i==="webForm"?"Attribution Pro Website Form":i==="googleLeadForm"?"Google Form":i||"-"}const Dr=({isLocation:r,lead:i,onClick:m,onFavoriteToggle:h,visibleColumns:P})=>{n.useCallback(()=>{m==null||m(i)},[i,m]);const g=n.useCallback(f=>{f.stopPropagation(),h==null||h(i,!i.leadIsFavorite)},[i,h]),y=i;return e.jsxs(e.Fragment,{children:[e.jsx(j,{padding:"checkbox",sx:{background:"inherit",width:20},children:e.jsx(ke,{onClick:g,size:"small",children:y.leadIsFavorite?e.jsx(Be,{color:"primary"}):e.jsx($e,{})})}),P.map(f=>{if(r&&f==="accountName")return null;if(f==="phoneNumber"||f==="eventDate")return e.jsx(j,{sx:{background:"inherit",width:50},children:e.jsx("span",{style:{textWrap:"nowrap"},children:y[f]??""})},f);if(f==="salesTotal")return e.jsx(j,{align:"right",sx:{background:"inherit",width:50},children:e.jsx("span",{style:{textWrap:"nowrap"},children:y.salesTotal??""})},f);if(f==="leadNote")return e.jsx(j,{sx:{background:"inherit",width:250},children:e.jsx(E,{variant:"inherit",noWrap:!0,sx:{maxWidth:250},children:y[f]})},f);if(f==="leadCategory")return e.jsx(j,{sx:{background:"inherit",width:150},children:e.jsx(Ae,{label:y[f]??"",size:"small",skipFocusWhenDisabled:!0,variant:"outlined"})},f);if(f==="leadValue")return e.jsx(j,{sx:{background:"inherit",width:50},children:y[f]??"-"},f);if(f==="source")return e.jsx(j,{sx:{background:"inherit",width:100},children:Sr(y.source)},f);if(f==="formData"){const v=JSON.stringify(y[f]??{},null," ");return e.jsx(j,{sx:{background:"inherit",width:250},children:e.jsx(Cr,{arrow:!0,enterDelay:500,placement:"left",title:v,children:e.jsx(E,{variant:"inherit",noWrap:!0,sx:{maxWidth:250},children:v})})},f)}return e.jsx(j,{sx:{background:"inherit",width:150,maxWidth:150},children:e.jsx(E,{variant:"inherit",noWrap:!0,sx:{maxWidth:"100%"},children:y[f]??""})},f)})]})},jr=W.memo(Dr),ze=r=>{if(!r)return null;if(typeof r=="string")return r;if(typeof r=="object"){const i=r.data??null;return typeof i=="string"?i:null}return null},We=["accountName","name","email","phoneNumber","eventDate","source","campaignName","adGroupName","formComments","formAddress","formCity","formState","formProvince","formCountry","formZipCode","formPostalCode","formDOB","formGender","formCompany","formJobTitle","formWorkEmail","formWorkPhone","formPreferredContact","formDesiredProgram","formOffer","formYourMessage","formModel","formOther","fullUrl","formLeadSourceId","formLeadClassification","formMedium","formChannel","formVendor","salesTotal","leadCategory","leadValue","leadNote","formData"],Ye=["accountName","name","email","phoneNumber","eventDate","source","adGroupName","campaignName","leadCategory","leadValue"],de={accountName:"Account Name",name:"Name",email:"Email",phoneNumber:"Phone #",eventDate:"Date",source:"Source",campaignName:"Campaign",adGroupName:"Ad Group",formComments:"Comments",formAddress:"Address",formCity:"City",formState:"State",formProvince:"Province",formCountry:"Country",formZipCode:"Zip Code",formPostalCode:"Postal Code",formDOB:"Date of Birth",formGender:"Gender",formCompany:"Company",formJobTitle:"Job Title",formWorkEmail:"Work Email",formWorkPhone:"Work Phone",formPreferredContact:"Preferred Contact Method",formDesiredProgram:"Desired Program",formOffer:"Offer",formYourMessage:"Your Message",formModel:"Model",formOther:"Other",fullUrl:"Form Origin URL",formLeadSourceId:"Lead Source Id",formLeadClassification:"Lead Classification",formMedium:"Medium",formChannel:"Channel",formVendor:"Vendor",salesTotal:"Actual Sales ($)",leadCategory:"Category",leadValue:"Value",leadNote:"Note",formData:"Raw Form Data"},vr=({context:r,item:i,...m})=>{if(r.loading||r.error)return e.jsx(Y,{children:e.jsx(j,{colSpan:r.sortedVisibleColumns.length+1,align:"center",children:r.loading?e.jsx(Ie,{size:24,sx:{m:5}}):e.jsx(E,{sx:{m:5,color:"error.main"},children:"Error fetching form submits"})})});if(i&&i.type==="account"){const g=n.useCallback(()=>{var y;return(y=r==null?void 0:r.onToggleAccount)==null?void 0:y.call(r,i.accountName)},[r,i]);return e.jsx(Y,{hover:!0,...m,onClick:g,sx:{cursor:"pointer"}})}const h=i,P=n.useCallback(()=>{var g;return(g=r==null?void 0:r.onClick)==null?void 0:g.call(r,h)},[r,h]);return e.jsx(Y,{hover:!0,...m,onClick:P,sx:{cursor:"pointer"}})},Tr=({context:r,...i})=>{if(r){if(r.loading||r.error)return e.jsx(ne,{children:e.jsx(Y,{children:e.jsx(j,{colSpan:r.sortedVisibleColumns.length+1,align:"center",children:r.loading?e.jsx(Ie,{size:24,sx:{m:5}}):e.jsx(E,{sx:{m:5,color:"error.main"},children:"Error fetching form submits"})})})});if(!r.loading)return e.jsx(ne,{children:e.jsx(Y,{children:e.jsx(j,{colSpan:r.sortedVisibleColumns.length+1,align:"center",children:e.jsx(yr,{colSpan:r.sortedVisibleColumns.length+1})})})})}return e.jsx(ne,{...i})},Er={Scroller:n.forwardRef((r,i)=>e.jsx(He,{component:Te,...r,ref:i})),EmptyPlaceholder:n.forwardRef((r,i)=>e.jsx(Tr,{...r})),Table:r=>e.jsx(Ge,{...r,style:{borderCollapse:"separate",tableLayout:"auto"}}),TableHead:n.forwardRef((r,i)=>e.jsx(Je,{...r,ref:i})),TableRow:vr,TableBody:n.forwardRef((r,i)=>e.jsx(ne,{...r,ref:i}))},Ar=["source","campaignName","adGroupName","leadCategory","formMedium","formChannel","formVendor","accountName"],Wr=()=>{const{selectedAccount:r}=qe(),i=oe(a=>a.auth.enhancedJWT),m=oe(a=>a.context.selectedAccount),[h,P]=W.useState(!0),[g,y]=W.useState([]),{token:f}=tr();rr(()=>{if(!(m!=null&&m.id)){y([]),P(!0);return}const a=u=>parseInt(u.id,10),d=(m==null?void 0:m.accoutType)||(m==null?void 0:m.accountType)||(m==null?void 0:m.type),o=(typeof d=="str
1ing"?d.trim().toLowerCase():"")!=="rollup";let c=[];if(o){const u=a(m);u&&(c=[u])}else if(c=(Array.isArray(m==null?void 0:m.subAccounts)?m.subAccounts:[]).map(a).filter(p=>!!p),c.length===0){const p=a(m);p&&(c=[p])}let t=Array.from(new Set(c));P(o),y(t)},[m],500);const[v,se]=Xt("today"),[Oe,pe]=n.useState("month"),[w,ie]=n.useState("eventDate"),[A,q]=n.useState("desc"),[he,Q]=n.useState(!1),[V,M]=n.useState(!1),[B,L]=n.useState([]),[X,ee]=n.useState(null),[ge,te]=n.useState(!1),[le,re]=n.useState(!1),[xe,be]=n.useState({}),ye=(a,d)=>{be(s=>({...s,[a]:d}))},[l,S]=n.useState([...We]),[k,C]=n.useState([...Ye]),[x,I]=n.useState(null),[O,_]=n.useState(!1),[U,R]=n.useState({}),[K,ce]=n.useState(null),[$,_e]=n.useState(null),Ke=Tt(Me(Ut,{activationConstraint:{distance:5}}),Me(Pt,{coordinateGetter:Rt})),Ze=a=>{I(a.active.id),_(!1)},Xe=a=>{const{over:d,delta:s}=a;Math.abs(s.y)>40?_(!0):_(!d)},et=a=>{const{active:d,over:s}=a;if(O||!s)C(o=>o.filter(c=>c!==d.id));else if(s&&d.id!==s.id){const o=d.id,c=s.id,t=l.filter(H=>h&&H==="accountName"?!1:k.includes(H)),u=t.indexOf(o),p=t.indexOf(c),D=Ft(t,u,p),b=[...l],jt=b.map((H,je)=>t.includes(H)?je:-1).filter(H=>H!==-1);D.forEach((H,je)=>{b[jt[je]]=H}),S(b)}I(null),_(!1)},tt=()=>{I(null),_(!1)},rt={sideEffects:Mt({styles:{active:{opacity:"0.4"}}})},[Ce,at]=n.useState({}),ot=n.useCallback(a=>{at(d=>({...d,[a]:!d[a]}))},[]),ae=n.useMemo(()=>l.filter(a=>h&&a==="accountName"?!1:k.includes(a)),[l,k,h]),nt=n.useCallback(()=>re(!0),[]),st=n.useCallback(()=>{re(!1)},[]),Se=W.useMemo(()=>{const a=ze(i);let d=`${fe.PERFORMANCE_DATA_SERVICE_V8_URL}`;const s=we.create({baseURL:d.replace(/\/+$/,"")}),o=new Qe(s,()=>"Unauthorized");return o.setAuthToken(a),o},[i]),N=W.useMemo(()=>{const a={get:async(s,o)=>{let c=`${fe.SHOPPER_API_URL}${s}`;if(o&&o.params){const u=new URLSearchParams;Object.keys(o.params).forEach(D=>{const b=o.params[D];Array.isArray(b)?u.append(D,"["+String(b)+"]"):b!=null&&u.append(D,String(b))});const p=u.toString();p&&(c+=`?${p}`)}return(await fetch(c,{headers:f?{Authorization:`Bearer ${f}`}:void 0})).json()},put:async(s,o)=>{let c=`${fe.SHOPPER_API_URL}${s}`;return(await fetch(c,{method:"PUT",headers:{Accept:"application/json","Content-Type":"application/json",...f?{Authorization:`Bearer ${f}`}:{}},body:JSON.stringify(o)})).json()},defaults:{headers:{}},interceptors:{request:{use:()=>{}},response:{use:(s,o)=>({id:5})}}};return new nr(a,()=>"")},[f]);n.useEffect(()=>{if(!ze(i))return;const d=new AbortController;return Se&&N&&(g==null?void 0:g.length)>0?(L([]),Q(!0),M(!1),(async()=>{try{const s=`accountId:${g.map(p=>`eq:${p}`).join(":")}`,o=await Se.getLeads({filters:s,startDate:Z(v.startDate,"YYYY-MM-DD",""),endDate:Z(v.endDate,"YYYY-MM-DD","")}),t=(await N.getLeadsAttributes({accountIds:g,startDate:Z(v.startDate,"YYYY-MM-DD",""),endDate:Z(v.endDate,"YYYY-MM-DD","")})??[]).reduce((p,D)=>{const b=`${D.source}:${D.id}`;return{...p,[b]:D}},{}),u=o.map(p=>{const D=typeof p.id>"u"?`external:${p.platformTrackingId}`:`lead:${p.id}`;if(t.hasOwnProperty(D)){const b=t[D];return{...p,leadIsFavorite:!!b.STARRED,leadNote:b.NOTE,leadCategory:b.LEAD_CATEGORY??"Uncategorized",leadValue:b.VALUE}}return p});L(u??[])}catch(s){console.error("Error fetching leads",s),M(!0)}finally{Q(!1)}})()):(L([]),Q(!1),M(!1)),()=>d.abort()},[Se,N,v,g]);const it=a=>{se(a)},lt=a=>{q(w===a&&A==="asc"?"desc":"asc"),ie(a)},ct=n.useCallback(a=>{ee(a)},[]),ut=()=>{ee(null)},dt=n.useCallback(()=>{const a=l;let s=a.map(u=>'"'+(de[u]??u).replace(/_/g," ").trim()+'"').join(",");B.forEach(u=>{s+=` 2`,s+=a.map(p=>{const D=u[p];if(p==="formData"){if(D){let b=JSON.stringify(D);return b=b.replace(/\r\n/g," ").replace(/\n/g," ").replace(/\r/g," ").trim(),'"'+b.replace(/"/g,'""')+'"'}return""}
2if(typeof D=="string"&&D){let b=D??"";return b=b.replace(/\r\n/g," ").replace(/\n/g," ").replace(/\r/g," ").trim(),'"'+b+'"'}return D??""}).join(",")});const o="YYYY-MM-DD",c=Et(`Form_Submits_${r==null?void 0:r.name.replace(/\s+/g,"_")}_${Z(v&&v.startDate,o)}_${Z(v&&v.endDate,o)}`),t=document.createElement("a");t.href="data:text/csv;charset=utf-8,"+encodeURIComponent(s),t.target="_blank",t.download=c,t.click()},[B,l,r,v]),[Ne,Fe]=n.useState(null),mt=!!Ne,[ft,Re]=n.useState(!1),pt=n.useCallback(a=>Fe(a.currentTarget),[]),J=n.useCallback(()=>Fe(null),[]),ht=n.useCallback(()=>{te(!0),J()},[J]),gt=n.useCallback(()=>{te(!1),J()},[J]),xt=n.useCallback(()=>{Re(!0),J()},[J]),bt=n.useCallback(()=>Re(!1),[]),yt=n.useCallback((a,d)=>{let s=[];L(o=>(s=o.map(c=>c.platformTrackingId===a.platformTrackingId?{...c,leadCategory:d}:c),s)),(async()=>{var c;let o={accountId:a.accountId,reportDate:(c=a.eventDateTime)==null?void 0:c.toISOString()};if(typeof a.guid<"u"){const t=s.find(u=>u.guid===a.guid);o.STARRED=t==null?void 0:t.leadIsFavorite,o.NOTE=t==null?void 0:t.leadNote,o.VALUE=t==null?void 0:t.leadValue,o.LEAD_CATEGORY=t==null?void 0:t.leadCategory,await N.saveLeadAttributes(a.guid,o)}else if(typeof a.platformTrackingId<"u"){const t=s.find(u=>u.platformTrackingId===a.platformTrackingId);
2o.STARRED=t==null?void 0:t.leadIsFavorite,o.NOTE=t==null?void 0:t.leadNote,o.VALUE=t==null?void 0:t.leadValue,o.LEAD_CATEGORY=t==null?void 0:t.leadCategory,await N.saveLeadAttributesByPlatformTrackingId(String(a.platformTrackingId),o)}})()},[N]),Ct=n.useCallback((a,d)=>{let s=[];L(o=>(s=o.map(c=>c.platformTrackingId===a.platformTrackingId?{...c,leadValue:d}:c),s)),(async()=>{var c;let o={accountId:a.accountId,reportDate:(c=a.eventDateTime)==null?void 0:c.toISOString()};if(typeof a.guid<"u"){const t=s.find(u=>u.guid===a.guid);o.STARRED=t==null?void 0:t.leadIsFavorite,o.NOTE=t==null?void 0:t.leadNote,o.VALUE=t==null?void 0:t.leadValue,o.LEAD_CATEGORY=t==null?void 0:t.leadCategory,await N.saveLeadAttributes(a.guid,o)}else if(typeof a.platformTrackingId<"u"){const t=s.find(u=>u.platformTrackingId===a.platformTrackingId);o.STARRED=t==null?void 0:t.leadIsFavorite,o.NOTE=t==null?void 0:t.leadNote,o.VALUE=t==null?void 0:t.leadValue,o.LEAD_CATEGORY=t==null?void 0:t.leadCategory,await N.saveLeadAttributesByPlatformTrackingId(String(a.platformTrackingId),o)}})()},[N]),St=n.useCallback((a,d)=>{let s=[];L(o=>(s=o.map(c=>c.platformTrackingId===a.platformTrackingId?{...c,leadNote:d}:c),s)),(async()=>{var c;let o={accountId:a.accountId,reportDate:(c=a.eventDateTime)==null?void 0:c.toISOString()};if(typeof a.guid<"u"){const t=s.find(u=>u.guid===a.guid);
2o.STARRED=t==null?void 0:t.leadIsFavorite,o.NOTE=t==null?void 0:t.leadNote,o.VALUE=t==null?void 0:t.leadValue,o.LEAD_CATEGORY=t==null?void 0:t.leadCategory,await N.saveLeadAttributes(a.guid,o)}else if(typeof a.platformTrackingId<"u"){const t=s.find(u=>u.platformTrackingId===a.platformTrackingId);o.STARRED=t==null?void 0:t.leadIsFavorite,o.NOTE=t==null?void 0:t.leadNote,o.VALUE=t==null?void 0:t.leadValue,o.LEAD_CATEGORY=t==null?void 0:t.leadCategory,await N.saveLeadAttributesByPlatformTrackingId(String(a.platformTrackingId),o)}})()},[N]),Pe=n.useCallback((a,d)=>{let s=[];L(o=>(s=o.map(c=>c.platformTrackingId===a.platformTrackingId?{...c,leadIsFavorite:d}:c),s)),(async()=>{var c;let o={accountId:a.accountId,reportDate:(c=a.eventDateTime)==null?void 0:c.toISOString()};if(typeof a.guid<"u"){const t=s.find(u=>u.guid===a.guid);o.STARRED=t==null?void 0:t.leadIsFavorite,o.NOTE=t==null?void 0:t.leadNote,o.VALUE=t==null?void 0:t.leadValue,o.LEAD_CATEGORY=t==null?void 0:t.leadCategory,await N.saveLeadAttributes(a.guid,o)}else if(typeof a.platformTrackingId<"u"){const t=s.find(u=>u.platformTrackingId===a.platformTrackingId);
2o.STARRED=t==null?void 0:t.leadIsFavorite,o.NOTE=t==null?void 0:t.leadNote,o.VALUE=t==null?void 0:t.leadValue,o.LEAD_CATEGORY=t==null?void 0:t.leadCategory,await N.saveLeadAttributesByPlatformTrackingId(String(a.platformTrackingId),o)}})()},[N]),De=W.useMemo(()=>{const a=A==="asc";return[...B.filter(o=>{for(const[c,t]of Object.entries(U)){if(t===void 0)continue;let u=String(o[c]??"");if(c==="formData"&&typeof o.formData=="object"&&(u=JSON.stringify(o.formData)),Array.isArray(t)){if(t.length===0||!t.includes(u||"Unknown"))return!1}else if(t&&!u.toLowerCase().includes(t.toLowerCase()))return!1}return!0})].sort((o,c)=>{const t=o[w],u=c[w];if(h){if(t===void 0&&u===void 0)return 0;if(t===void 0)return 1;if(u===void 0)return-1;if(a){if(t===null||u===null||t<u)return-1;if(t>u)return 1}else{if(t===null||u===null||t>u)return-1;if(t<u)return 1}return 0}else{const p=o.accountName&&c.accountName?o.accountName.localeCompare(c.accountName):0;if(t===void 0&&u===void 0)return p||0;if(t===void 0)return p||1;if(u===void 0||t===null||u===null)return p||-1;if(a){if(t<u)return p||-1;if(t>u)return p||1}else{if(t>u)return p||-1;if(t<u)return p||1}return p||0}})},[B,A,w,h,U]),Dt=n.useMemo(()=>{if(h)return De;const a=new Map;for(const s of De){const o=s.accountName||"Unknown Account";a.has(o)||a.set(o,[]),a.get(o).push(s)}const d=[];for(const[s,o]of a.entries())d.push({type:"account",accountName:s,count:o.length}),Ce[s]&&d.push(...o);return d},[De,h,Ce]);return e.jsxs(F,{sx:{display:"flex",flexDirection:"column",flexGrow:1},children:[e.jsxs(F,{sx:ar,children:[e.jsx(E,{variant:"h3",component:"h1",fontWeight:"bold",children:"Form Submit Details"}),e.jsx(er,{onChange:it,initialStartDate:v.startDate,initialEndDate:v.endDate,enableCompare:!0,initialPreset:v.preset})]}),e.jsxs(F,{sx:{display:"flex",flexDirection:"column",flexGrow:1,paddingTop:0,paddingLeft:3,paddingRight:3,paddingBottom:3},children:[!1,e.jsxs(F,{sx:{mb:3,display:"flex",justifyContent:"flex-end",alignItems:"center"},children:[e.jsx(me,{variant:"outlined",startIcon:e.jsx(Gt,{}),sx:{mr:2},onClick:nt,children:"Customize Table"}),e.jsx(me,{variant:"outlined",startIcon:e.jsx(Jt,{}),onClick:dt,sx:{mr:2},children:"Export CSV"}),e.jsx(me,{variant:"outlined",startIcon:e.jsx(qt,{}),onClick:pt,children:"Schedule Report"}),e.jsxs(Qt,{anchorEl:Ne,open:mt,onClose:J,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},children:[e.jsx(z,{onClick:ht,children:"Add new schedule"}),e.jsx(z,{onClick:xt,children:"Manage scheduled reports"})]})]}),e.jsx(mr,{anchorEl:K,columnId:$,filterType:$&&Ar.includes($)?"select":"text",options:$?Array.from(new Set(B.map(a=>$==="formData"?"Unknown":String(a[$]??"Unknown")))).sort():[],value:$?U[$]:void 0,onClose:()=>{ce(null),_e(null)},onChange:(a,d)=>{R(s=>{const o={...s};return d===void 0?delete o[a]:o[a]=d,o})}}),e.jsx(F,{sx:{display:"flex",flexDirection:"column",flexGrow:1},children:e.jsxs(At,{sensors:Ke,collisionDetection:kt,onDragStart:Ze,onDragMove:Xe,onDragEnd:et,onDragCancel:tt,children:[e.jsx(It,{style:{height:"100%",maxHeight:"100%",minHeight:"100%"},data:Dt,context:{onClick:ct,onToggleAccount:ot,sortedVisibleColumns:ae,isLocation:h,loading:he,error:V},components:Er,fixedHeaderContent:()=>e.jsx(Ot,{items:ae,strategy:_t,children:e.jsxs(Y,{children:[e.jsx(j,{padding:"checkbox",sx:{background:"white",width:20}}),ae.map((a,d)=>{if(h&&a==="accountName")return null;const s=a,o=a,c=a!=="formData";return e.jsxs(cr,{id:o,sx:{background:"white","&:hover .filter-icon":{opacity:1}},width:xe[o],onResize:ye,children:[e.jsx(Kt,{active:c?w===s:!1,direction:w===s?A:"asc",hideSortIcon:!c,onClick:c?()=>lt(s):void 0,children:de[a]??""}),e.jsx(ke,{className:"filter-icon",size:"small",onClick:t=>{t.stopPropagation(),ce(t.currentTarget),_e(o)},onPointerDown:t=>t.stopPropagation(),sx:{opacity:U[o]!==void 0?1:0,transition:"opacity 0.2s",position:"absolute",right:16,top:"50%",transform:"translateY(-50%)",zIndex:10},children:e.jsx(Zt,{fontSize:"small",color:U[o]!==void 0?"primary":"action"})})]},o)})]})}),itemContent:(a,d)=>d.type==="account"?e.jsx(W.Fragment,{children:e.jsx(j,{sx:{background:"inherit",width:400},colSpan:ae.length+1,children:e.jsxs(F,{sx:{display:"flex",alignItems:"center"},children:[e.jsx(F,{sx:{mr:1,display:"flex"},children:e.jsx("svg",{style:{transform:Ce[d.accountName]?"rotate(90deg)":"rotate(0)",transition:"transform 0.2s"},width:"24",height:"24",viewBox:"0 0 24 24",children:e.jsx("path",{fill:"currentColor",d:"M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"})})}),e.jsxs(E,{variant:"body2",fontWeight:"500",children:[d.accountName,"
2(",d.count,")"]})]})})}):e.jsx(jr,{isLocation:h,lead:d,onFavoriteToggle:Pe,visibleColumns:ae})}),e.jsx(Nt,{dropAnimation:rt,children:x?e.jsx(ur,{id:x,isDraggedAway:O,label:de[x]||x}):null})]})}),X&&e.jsx(xr,{lead:X,onCategoryChange:yt,onClose:ut,onIsFavoriteChange:Pe,onNoteChange:St,onValueChange:Ct}),ge&&e.jsx(ir,{dimensions:["accountName","fullName","email","phone","eventDate","source","campaignName","adGroupName","formComments","formAddress","formCity","formState","formProvince","formCountry","formZipCode","formPostalCode","formDOB","formGender","formCompany","formJobTitle","formWorkEmail","formWorkPhone","formPreferredContact","formDesiredProgram","formOffer","formYourMessage","formModel","formOther","formOriginUrl","formLeadSourceId","formMedium","formChannel","formVendor","salesTotal","leadTag","leadValue","leadNote","formData"],metrics:["formSubmitConversions"],networks:["Unknown","Search","Display","Video","Social"],reportType:"CUSTOM_LEADS",onClose:gt}),ft&&e.jsx(lr,{onClose:bt}),le&&e.jsx(dr,{open:le,onClose:st,items:l.filter(a=>!(h&&a==="accountName")).map(a=>({id:a,label:de[a],visible:k.includes(a)})),onReorder:S,onToggleVisibility:(a,d)=>{C(s=>d?Array.from(new Set([...s,a])):s.filter(o=>o!==a))},onReset:()=>{S([...We]),C([...Ye])}})]})]})};export{Wr 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.