1import{_ as ge}from"./Tabs-CsIQORIM.js";import{aw as fe,P as he,q as H,I as Pt,R as $t,e as A,g as o,b9 as re,d as yt,c as u,z as Tt,k as w,a as t,Z as W,A as a,E as M,o as l,f as ot,av as ie,X as At,y as $,bS as Dt,O as lt,x as Z,bd as de,l as St,a7 as zt,aq as Ut,a1 as _t,an as rt,bA as it,Y as ht,a5 as vt,t as Et,M as Nt,fo as Vt,aM as Bt,aN as Gt,br as ve,af as ye,bC as te,ac as ce,H as xe,u as ue,gU as be,gV as ke,j as Ce,bL as se,V as Zt,aD as oe,am as ae,gW as $e,Q as Se,L as Re}from"./entry-BPpzu7Al.js";import{Q as It}from"./query-cache-awNgePv1.js";import{u as st,w as qt}from"./xlsx-S-siJU1O.js";import{f as Ft,c as Le,g as Wt}from"./dateHelper-DmDD4NIY.js";import{T as we}from"./TransaxPagination-I6pmMlBE.js";import{d as Mt}from"./formatHelper--FTfgu5K.js";import{_ as Pe}from"./AutoComplete-5yYWwrQd.js";import{_ as pe}from"./Select-D_qikc3l.js";import{u as Te}from"./useLeadSources-BTwXeL45.js";import{_ as Ee}from"./nuxt-link-BnPjs7m5.js";import{u as Ae}from"./general-C6yQfo1l.js";import{u as De,b as Ie}from"./timezone-ogcuuznA.js";import{u as le}from"./useRbacStore-DERMt1dK.js";import{D as ne}from"./DatePicker-CX3j-oIk.js";import"./VTabs-OjjnrIdc.js";
1import"./VWindowItem-ClUmd_r8.js";import"./VTooltip-BFCN09Rf.js";import"./Label-BUhFDx1h.js";import"./VAutocomplete-BtYsrZuK.js";import"./TextField-DTP5qN9N.js";import"./CheckBox.vue-CEb_bWPo.js";import"./VCheckbox-BNPmQQ_A.js";import"./useMutation-BKeNoDf7.js";import"./main-C6efnUN_.js";function jt(I,S){var R,v;(R=S==null?void 0:S.user_ids)!=null&&R.length&&(I.user_ids=S.user_ids),(v=S==null?void 0:S.role_ids)!=null&&v.length&&(I.role_ids=S.role_ids)}function Rt(){const I=fe();return{fetchMasterLeadReport:async s=>{const e={};return s!=null&&s.period&&s.period!=="custom"?e.period=s.period:s!=null&&s.from&&(s!=null&&s.to)&&(e.from=s.from,e.to=s.to),s!=null&&s.filter_by_customer_id&&(e.filter_by_customer_id=s.filter_by_customer_id),jt(e,s),(await I.get("/reports/crm/master-lead-reports",{params:e})).data},fetchSalespersonActivitiesReport:async s=>{const e={};return s.period&&s.period!=="custom"?e.period=s.period:s.from&&s.to&&(e.from=s.from,e.to=s.to),s.filter_by_customer_id&&(e.filter_by_customer_id=s.filter_by_customer_id),jt(e,s),(await I.get("/reports/crm/salesperson-activities-reports",{params:e})).data},fetchAppointmentStatisticsReport:async s=>{const e={};return s.period&&s.period!=="custom"?e.period=s.period:s.from&&s.to&&(e.from=s.from,e.to=s.to),s.filter_by_customer_id&&(e.filter_by_customer_id=s.filter_by_customer_id),s.salesperson_id!=null&&(e.salesperson_id=s.salesperson_id),s.lead_source_id!=null&&(e.lead_source_id=s.lead_source_id),(await I.get("/reports/crm/appointment-statistics-reports",{params:e})).data},fetchAppointmentStatisticsSalespeople:async()=>(await I.get("/reports/crm/appointment-statistics-reports/salespeople")).data,fetchLeadSourcesReport:async s=>{const e={};return s.period&&s.period!=="custom"?e.period=s.period:s.from&&s.to&&(e.from=s.from,e.to=s.to),s.filter_by_customer_id&&(e.filter_by_customer_id=s.filter_by_customer_id),jt(e,s),(await I.get("/reports/crm/lead-sources-reports",{params:e})).data},fetchLeadStatusBySalespersonReport:async s=>{const e={};return s.period&&s.period!=="custom"?e.period=s.period:s.from&&s.to&&(e.from=s.from,e.to=s.to),s.filter_by_customer_id&&(e.filter_by_customer_id=s.filter_by_customer_id),jt(e,s),(await I.get("/reports/crm/lead-status-by-salesperson-reports",{params:e})).data},fetchTextBlastReport:async s=>{const e={};return s.period&&s.period!=="custom"?e.period=s.period:s.from&&s.to&&(e.from=s.from,e.to=s.to),s.filter_by_customer_id&&(e.filter_by_customer_id=s.filter_by_customer_id),(await I.get("/reports/marketing/text-blast-reports",{params:e})).data},fetchLeadsDrilldown:async s=>(await I.get("/reports/crm/leads-drilldown",{params:s})).data,fetchAppointmentsDrilldown:async s=>(await I.get("/reports/crm/appointments-drilldown",{params:s})).data,fetchCrmReportUsers:async()=>(await I.get("/reports/crm/users")).data}}const xt=he("crmReports",()=>{const I=H({period:"this_month",from:"",to:"",user_ids:[],role_ids:[]});return{dateFilter:I,setDateFilter:k=>{I.value={...I.value,...k}},setPeriod:k=>{const g={...I.value,period:k};k!=="custom"&&(g.from="",g.to=""),I.value=g},setCustomDates:(k,g)=>{I.value={...I.value,period:"custom",from:k,to:g}},setCustomerId:k=>{I.value={...I.value,filter_by_customer_id:k}},setUserIds:k=>{I.value={...I.value,user_ids:k??[]}},setRoleIds:k=>{I.value={...I.value,role_ids:k??[]}},resetFilter:()=>{I.value={period:"this_month",from:"",to:"",filter_by_customer_id:void 0,user_ids:[],role_ids:[]}}}});function Fe(){const I=Rt(),S=xt(),{dateFilter:R}=Pt(S),v=H(new Set),d=H(new Set),{data:b,isLoading:C,isFetching:P,error:k,refetch:g}=$t({queryKey:["masterLeadReport",R],queryFn:async()=>await I.fetchMasterLeadReport(R.value),staleTime:It.REALTIME,refetchOnWindowFocus:!0,refetchOnMount:!0,retry:1}),U=A(()=>{var i;return(i=b.value)==null?void 0:i.headers}),s=A(()=>{var i;return((i=b.value)==null?void 0:i.data)||[]}),e=(i,p,D,r)=>i==="channel"?`channel-${p}`:i==="group"?`group-${p}-${D}`:i==="source"?`source-${p}-${D}-${r}`:"total",y=i=>v.value.has(i),L=(i,p)=>d.value.has(`${i}-${p}`),G=i=>{v.value.has(i)?v.value.delete(i):v.value.add(i)},F=(i,p)=>{const D=`${i}-${p}`;d.value.has(D)?d.value.delete(D):d.value.add(D)},N=A(()=>{if(!s.value.length)return[];const i=[];return s.value.forEach(p=>{const D=y(p.channel_id);i.push({id:e("channel",p.channel_id),type:"channel",name:p.channel_name,level:0,isExpandable:p.groups.length>0,isExpanded:D,channelId:p.channel_id,month_0_prev_year:p.month_0_prev_year,month_0:p.month_0,month_1:p.month_1,month_2:p.month_2,month_3:p.month_3,month_4:p.month_4,month_5:p.month_5,month_6:p.month_6,sold_prev_year:p.sold_prev_year,sold_curr_year:p.sold_curr_year,close_12mo:p.close_12mo,close_3mo:p.close_3mo,close_last_mo:p.close_last_mo}),D&&p.groups.forEach(r=>{const T=L(p.channel_id,r.group_id);i.push({id:e("group",p.channel_id,r.group_id),type:"group",name:r.group_name,level:1,isExpandable:r.sources.length>0,isExpanded:T,parentId:e("channel",p.channel_id),channelId:p.channel_id,groupId:r.group_id,month_0_prev_year:r.month_0_prev_year,month_0:r.month_0,month_1:r.month_1,month_2:r.month_2,month_3:r.month_3,month_4:r.month_4,month_5:r.month_5,month_6:r.month_6,sold_prev_year:r.sold_prev_year,sold_curr_year:r.sold_curr_year,close_12mo:r.close_12mo,close_3mo:r.close_3mo,close_last_mo:r.close_last_mo}
1),T&&r.sources.forEach(m=>{i.push({id:e("source",p.channel_id,r.group_id,m.source_id),type:"source",name:m.source_name,level:2,isExpandable:!1,parentId:e("group",p.channel_id,r.group_id),channelId:p.channel_id,groupId:r.group_id,sourceId:m.source_id,month_0_prev_year:m.month_0_prev_year,month_0:m.month_0,month_1:m.month_1,month_2:m.month_2,month_3:m.month_3,month_4:m.month_4,month_5:m.month_5,month_6:m.month_6,sold_prev_year:m.sold_prev_year,sold_curr_year:m.sold_curr_year,close_12mo:m.close_12mo,close_3mo:m.close_3mo,close_last_mo:m.close_last_mo})})})}),i}),V=A(()=>{if(!s.value.length)return null;const i={month_0_prev_year:0,month_0:0,month_1:0,month_2:0,month_3:0,month_4:0,month_5:0,month_6:0,sold_prev_year:0,sold_curr_year:0,close_12mo:0,close_3mo:0,close_last_mo:0};s.value.forEach(Y=>{i.month_0_prev_year+=Y.month_0_prev_year,i.month_0+=Y.month_0,i.month_1+=Y.month_1,i.month_2+=Y.month_2,i.month_3+=Y.month_3,i.month_4+=Y.month_4,i.month_5+=Y.month_5,i.month_6+=Y.month_6,i.sold_prev_year+=Y.sold_prev_year,i.sold_curr_year+=Y.sold_curr_year});let p=0,D=0,r=0,T=0,m=0,J=0;return s.value.forEach(Y=>{Y.groups.forEach(Q=>{p+=Q.leads_12mo||0,D+=Q.sold_12mo||0,r+=Q.leads_3mo||0,T+=Q.sold_3mo||0,m+=Q.leads_last_mo||0,J+=Q.sold_last_mo||0})}),i.close_12mo=p?Math.round(D/p*100):0,i.close_3mo=r?Math.round(T/r*100):0,i.close_last_mo=m?Math.round(J/m*100):0,{id:"total",type:"total",name:"Total",level:3,isExpandable:!1,...i}});return{headers:U,channels:s,tableRows:N,totalsRow:V,isLoading:C,isFetching:P,error:k,toggleChannel:G,toggleGroup:F,isChannelExpanded:y,isGroupExpanded:L,expandAll:()=>{s.value.forEach(i=>{v.value.add(i.channel_id),i.groups.forEach(p=>{d.value.add(`${i.channel_id}-${p.group_id}`)})})},collapseAll:()=>{v.value.clear(),d.value.clear()},refresh:()=>g()}}function Me(){return{downloadExcel:(S,R,v)=>{const d=o(S),b=o(R),C=o(v);if(!(C!=null&&C.length)||!(d!=null&&d.length))return;const P=C.filter(c=>c.key!=="name"),k=new Set(["close_12mo","close_3mo","close_last_mo"]),g=["Type","Channel","Group","Source",...P.map(c=>c.title)],U=[],s=c=>typeof c=="number"?c:c??"",e=(c,B,j)=>{const i=P.map(p=>{if(k.has(p.key)){const D=j[p.key];return typeof D=="number"?D/100:0}return s(j[p.key])});U.push([c,B.channel??"",B.group??"",B.source??"",...i])};if(d.forEach(c=>{e("channel",{channel:c.channel_name},c),c.groups.forEach(B=>{e("group",{channel:c.channel_name,group:B.group_name},B),B.sources.forEach(j=>{e("source",{channel:c.channel_name,group:B.group_name,source:j.source_name},j)})})}),b){const c=b,B=P.map(j=>{if(k.has(j.key)){const p=c[j.key];return typeof p=="number"?p/100:0}const i=c[j.key];return typeof i=="number"?i:i??""});U.push(["total","TOTAL","","",...B])}const y=[g,...U],L=st.aoa_to_sheet(y);L["!freeze"]={xSplit:3,ySplit:1};const G=st.decode_range(L["!ref"]);L["!autofilter"]={ref:st.encode_range(G)},L["!cols"]=[{wch:10},{wch:24},{wch:24},{wch:28},...P.map(()=>({wch:12}))];const F=P.map((c,B)=>k.has(c.key)?B:-1).filter(c=>c>=0).map(c=>c+4);for(let c=1;c<=G.e.r;c++)for(const B of F){const j=st.encode_cell({r:c,c:B}),i=L[j];i&&typeof i.v=="number"&&(i.t="n",i.z="0%")}const N=st.book_new();st.book_append_sheet(N,L,"Master Lead Report");const V=`Master_Lead_Report_${new Date().toISOString().slice(0,10)}.xlsx`;qt(N,V)}}}function Yt(){const I=Rt(),S=H(!1),R=H(""),v=H(1),d=H(20),b=H(null),C=A(()=>(v.value-1)*d.value),{data:P,isLoading:k,isFetching:g,error:U,refetch:s}=$t({queryKey:["leadDrilldown",b,v,d],queryFn:async()=>b.value?await I.fetchLeadsDrilldown({...b.value,per_page:d.value,offset:C.value}):{data:[],total:0,per_page:20,current_page:1},enabled:A(()=>b.value!==null),staleTime:re,refetchOnWindowFocus:!1,retry:1}),e=A(()=>{var c;return((c=P.value)==null?void 0:c.data)||[]}),y=A(()=>{var c;return((c=P.value)==null?void 0:c.total)||0}),L=A(()=>Math.ceil(y.value/d.value));return{isModalOpen:S,modalTitle:R,leads:e,totalLeads:y,totalPages:L,currentPage:v,itemsPerPage:d,isLoading:k,isFetching:g,error:U,openDrilldown:(c,B)=>{b.value=c,R.value=B,v.value=1,S.value=!0},closeDrilldown:()=>{S.value=!1,setTimeout(()=>{b.value=null,R.value="",v.value=1},300)},handlePageChange:c=>{v.value=c},handleItemsPerPageChange:c=>{d.value=c,v.value=1},refetch:s}}const Qt=!1,Kt="Drilldown on total row is currently unavailable",Ht=yt({__name:"DownloadExcelButton",emits:["download"],setup(I){return(S,R)=>(l(),u("a",{href:"#",onClick:R[0]||(R[0]=Tt(v=>S.$emit("download"),["prevent"])),class:"tw-inline-flex tw-items-center tw-gap-1.5 tw-text-sm tw-text-gray-700 hover:tw-text-gray-900 tw-font-medium tw-transition-colors tw-duration-150","data-testid":"download-excel-link"},[w(W,{size:"16",color:"#32ba8f"},{default:a(()=>R[1]||(R[1]=[M("mdi-file-excel")])),_:1}
1),R[2]||(R[2]=t("span",null,"Download Full Excel",-1))]))}}),Oe={class:"drilldown-content"},ze={key:0,class:"tw-p-8","data-testid":"drilldown-loading"},Ue={class:"tw-flex tw-flex-col tw-items-center tw-justify-center"},Ne={key:1,class:"tw-p-8 tw-text-center","data-testid":"drilldown-error"},Ve={class:"tw-text-sm tw-text-gray-500"},Be={key:2,class:"tw-p-8 tw-text-center","data-testid":"drilldown-empty"},Ge={key:3,class:"table-with-pagination"},qe={class:"tw-relative tw-overflow-x-auto","data-testid":"drilldown-table-wrapper"},He={class:"tw-text-sm tw-text-gray-700"},je={key:0},We={key:1,class:"tw-text-gray-400"},Ye={class:"tw-text-sm tw-text-gray-700"},Qe={key:0},Ke={key:1,class:"tw-text-gray-400"},Xe={class:"tw-flex tw-flex-col"},Ze={class:"tw-text-sm tw-font-semibold tw-text-gray-900"},Je={key:0},ts={key:1,class:"tw-text-gray-400"},es={key:0,class:"status-timestamp"},ss={class:"tw-flex tw-flex-col"},os={class:"tw-text-sm tw-font-semibold tw-text-gray-900"},as={key:0},ls={key:1,class:"tw-text-gray-400"},ns={key:0,class:"status-timestamp"},rs={class:"tw-flex tw-flex-col"},is=["href"],ds={key:1,class:"tw-text-sm tw-text-gray-400"},cs={key:2,class:"contact-phone"},us={class:"tw-text-sm tw-text-gray-700"},ws={key:0},ps={key:1,class:"tw-text-gray-400"},ms={class:"tw-text-sm tw-text-gray-700"},_s={class:"tw-text-sm tw-text-gray-700"},gs={key:0},fs={key:1,class:"tw-text-gray-400"},hs={class:"tw-text-sm tw-text-gray-700"},vs={key:0},ys={key:1,class:"tw-text-gray-400"},xs={class:"tw-text-sm tw-text-gray-700"},bs={key:0},ks={key:1,class:"tw-text-gray-400"},Cs=yt({__name:"LeadDrilldownModal",props:{visible:{type:Boolean},title:{},leads:{},totalLeads:{},currentPage:{},totalPages:{},itemsPerPage:{},isLoading:{type:Boolean},isFetching:{type:Boolean},error:{}},emits:["update:visible","close","page-change","items-per-page-change"],setup(I,{emit:S}){const R=S,v=H(!1);typeof window<"u"&&(v.value=window.innerWidth<768);const d=[{title:"Created At",key:"created_at",sortable:!1,align:"start",width:130},{title:"Last Updated",key:"updated_at",sortable:!1,align:"start",width:130},{title:"Furthest Status",key:"furthest_status",sortable:!1,align:"start",width:160},{title:"Current Status",key:"latest_status",sortable:!1,align:"start",width:160},{title:"Contact",key:"contact",sortable:!1,align:"start",width:200},{title:"Assigned To",key:"assigned_to",sortable:!1,align:"start",width:140},{title:"Vehicle",key:"vehicle",sortable:!1,align:"start",width:180},{title:"Channel",key:"channel_name",sortable:!1,align:"start",width:120},{title:"Source Group",key:"source_group_name",sortable:!1,align:"start",width:150},{title:"Source",key:"source_name",sortable:!1,align:"start",width:150}],b=g=>g.year&&g.make&&g.model?{text:`${g.year} ${g.make} ${g.model}`,isEmpty:!1}:g.inventory_title?{text:g.inventory_title,isEmpty:!1}:{text:"-",isEmpty:!0},C=()=>{R("update:visible",!1),R("close")},P=g=>{R("page-change",g)},k=g=>{R("items-per-page-change",g)};return(g,U)=>{const s=de,e=ie;return l(),ot(e,{"model-value":g.visible,"onUpdate:modelValue":U[0]||(U[0]=y=>R("update:visible",y)),"custom-title":g.title,entity:"",onClose:C,width:v.value?"95vw":"1400"},{footer:a(()=>[w(s,{text:"Close",onClick:C})]),default:a(()=>[t("div",Oe,[g.isLoading&&!g.leads.length?(l(),u("div",ze,[t("div",Ue,[w(At,{indeterminate:"",color:"primary",size:40,width:4}),U[1]||(U[1]=t("p",{class:"tw-mt-4 tw-text-gray-600"},"Loading lead details...",-1))])])):g.error?(l(),u("div",Ne,[w(W,{icon:"mdi-alert-circle-outline",size:"large",color:"error",class:"tw-mb-4"}),U[2]||(U[2]=t("p",{class:"tw-text-gray-700 tw-mb-2"},"Failed to load lead details",-1)),t("p",Ve,$(g.error),1)])):!g.leads.length&&!g.isLoading?(l(),u("div",Be,[w(W,{icon:"mdi-information-outline",size:"large",color:"grey",class:"tw-mb-4"}),U[3]||(U[3]=t("p",{class:"tw-text-gray-700"},"No leads found for this selection",-1))])):(l(),u("div",Ge,[t("div",qe,[w(Dt,{headers:d,items:g.leads,loading:g.isFetching,class:"elevation-0 drilldown-table","item-key":"id","items-per-page":-1,"hide-default-footer":"",density:"compact","fixed-header":"","data-testid":"drilldown-table"},{"item.created_at":a(({item:y}
1)=>[t("div",He,[y.created_at?(l(),u("span",je,$(o(Ft)(y.created_at)),1)):(l(),u("span",We,"-"))])]),"item.updated_at":a(({item:y})=>[t("div",Ye,[y.updated_at?(l(),u("span",Qe,$(o(Ft)(y.updated_at)),1)):(l(),u("span",Ke,"-"))])]),"item.furthest_status":a(({item:y})=>[t("div",Xe,[t("div",Ze,[y.furthest_status_name?(l(),u("span",Je,$(y.furthest_status_name),1)):(l(),u("span",ts,"-"))]),y.furthest_status_updated_at?(l(),u("div",es,$(o(Ft)(y.furthest_status_updated_at)),1)):Z("",!0)])]),"item.latest_status":a(({item:y})=>[t("div",ss,[t("div",os,[y.latest_status_name?(l(),u("span",as,$(y.latest_status_name),1)):(l(),u("span",ls,"-"))]),y.latest_status_updated_at?(l(),u("div",ns,$(o(Ft)(y.latest_status_updated_at)),1)):Z("",!0)])]),"item.contact":a(({item:y})=>[t("div",rs,[y.contact_name?(l(),u("a",{key:0,href:`/redirect?contactId=${y.contact_id}&tab=overview`,target:"_blank",class:"tw-text-sm tw-font-semibold tw-text-gray-900 hover:tw-underline"},$(y.contact_name),9,is)):(l(),u("span",ds,"-")),y.mobile?(l(),u("div",cs,$(y.mobile),1)):Z("",!0)])]),"item.assigned_to":a(({item:y})=>[t("div",us,[y.assigned_to?(l(),u("span",ws,$(y.assigned_to),1)):(l(),u("span",ps,"-"))])]),"item.vehicle":a(({item:y})=>[t("div",ms,[t("span",{class:lt({"tw-text-gray-400":b(y).isEmpty})},$(b(y).text),3)])]),"item.channel_name":a(({item:y})=>[t("div",_s,[y.channel_name?(l(),u("span",gs,$(y.channel_name),1)):(l(),u("span",fs,"-"))])]),"item.source_group_name":a(({item:y})=>[t("div",hs,[y.source_group_name?(l(),u("span",vs,$(y.source_group_name),1)):(l(),u("span",ys,"-"))])]),"item.source_name":a(({item:y})=>[t("div",xs,[y.source_name?(l(),u("span",bs,$(y.source_name),1)):(l(),u("span",ks,"-"))])]),_:1},8,["items","loading"])]),w(we,{"current-page":g.currentPage,"total-pages":g.totalPages,"items-per-page":g.itemsPerPage,"total-items":g.totalLeads,"onUpdate:currentPage":P,"onUpdate:itemsPerPage":k},null,8,["current-page","total-pages","items-per-page","total-items"])]))])]),_:1},8,["model-value","custom-title","width"])}}}),Xt=St(Cs,[["__scopeId","data-v-5b9deb85"]]),$s={class:"tw-flex tw-flex-col tw-space-y-4","data-testid":"master-lead-report-container"},Ss={class:"tw-flex tw-items-start tw-gap-2 tw-rounded-md tw-border tw-p-3 tw-text-sm",style:{"background-color":"rgba(50, 186, 143, 0.12)","border-color":"#32ba8f",color:"#157657"},"data-testid":"master-lead-report-period-note"},Rs={key:0,class:"tw-flex tw-justify-between tw-items-center"},Ls={key:1,class:"tw-p-8","data-testid":"master-lead-report-loading"},Ps={class:"tw-flex tw-flex-col tw-items-center tw-justify-center"},Ts={key:2,class:"tw-p-8 tw-text-center","data-testid":"master-lead-report-error"},Es={class:"tw-text-sm tw-text-gray-500 tw-mb-4"},As={key:3,class:"tw-relative tw-overflow-x-auto","data-testid":"master-lead-report-table-wrapper"},Ds={class:"custom-header-row-1"},Is={colspan:"3",class:"text-center custom-header-cell-1"},Fs={class:"custom-header-row-2"},Ms=["onClick"],Os={key:1,class:"tw-w-5"},zs=["data-testid"],Us={class:"tw-text-sm tw-text-white"},Ns=["onClick"],Vs={key:4,class:"tw-mt-6"},Bs={class:"tw-mt-3","data-testid":"how-to-read-report-content"},Gs={class:"tw-space-y-5"},qs={class:"tw-text-sm tw-text-gray-600 tw-space-y-2"},Hs={class:"tw-flex tw-items-start tw-gap-2 tw-mt-2 tw-p-3 tw-rounded-md tw-border tw-text-sm",style:{"background-color":"rgba(50, 186, 143, 0.12)","border-color":"#32ba8f",color:"#157657"}},js={class:"tw-text-sm tw-text-gray-600 tw-space-y-2"},Ws={class:"tw-flex tw-items-start tw-gap-2 tw-mt-2 tw-p-3 tw-rounded-md tw-border tw-text-sm",style:{"background-color":"rgba(50, 186, 143, 0.12)","border-color":"#32ba8f",color:"#157657"}},Ys={class:"tw-text-sm tw-text-gray-600 tw-space-y-2"},Qs={class:"tw-flex tw-items-start tw-gap-2 tw-mt-2 tw-p-3 tw-rounded-md tw-border tw-text-sm",style:{"background-color":"rgba(50, 186, 143, 0.12)","border-color":"#32ba8f",color:"#157657"}},Ks={class:"tw-mt-6 tw-pt-4 tw-border-t tw-border-gray-200 tw-flex tw-items-start tw-gap-2"},Xs=yt({__name:"MasterLeadReport",setup(I){const S=H(!1),R=H(Qt),v=H(Kt),{headers:d,channels:b,tableRows:C,totalsRow:P,isLoading:k,error:g,toggleChannel:U,toggleGroup:s,expandAll:e,collapseAll:y,refresh:L}=Fe(),G=A(()=>d.value?[{title:"Channel / Group / Source",key:"name",sortable:!1,align:"start",width:250},{title:d.value.month_0_prev_year_label,key:"month_0_prev_year",sortable:!1,align:"center",width:100},{title:d.value.month_0_label,key:"month_0",sortable:!1,align:"center",width:100},{title:d.value.month_1_label,key:"month_1",sortable:!1,align:"center",width:80},{title:d.value.month_2_label,key:"month_2",sortable:!1,align:"center",width:80},{title:d.value.month_3_label,key:"month_3",sortable:!1,align:"center",width:80},{title:d.value.month_4_label,key:"month_4",sortable:!1,align:"center",width:80},{title:d.value.month_5_label,key:"month_5",sortable:!1,align:"center",width:80},{title:d.value.month_6_label,key:"month_6",sortable:!1,align:"center",width:80},{title:d.value.sold_prev_year_label,key:"sold_prev_year",sortable:!1,align:"center",width:100},{title:d.value.sold_curr_year_label,key:"sold_curr_year",sortable:!1,align:"center",width:100},{title:"Last 12 Months",key:"close_12mo",sortable:!1,align:"center",width:120},{title:"Last 3 Months",key:"close_3mo",sortable:!1,align:"center",width:120},{title:"Last Month",key:"close_last_mo",sortable:!1,align:"center",width:120}]:[]),F=["month_0_prev_year","month_0","month_1","month_2","month_3","month_4","month_5","month_6","sold_prev_year","sold_curr_year","close_12mo","close_3mo","close_last_mo"],N=A(()=>P.value?[...C.value,P.value]:C.value),V=A(()=>Le()),c=A(()=>{const O=C.value.filter(_=>_.isExpandable);return O.length===0?!1:O.every(_=>_.isExpanded)}),B=()=>{c.value?y():e()},j=O=>{O.isExpandable&&(O.type==="channel"&&O.channelId!==void 0?U(O.channelId):O.type==="group"&&O.channelId!==void 0&&O.groupId!==void 0&&s(O.channelId,O.groupId))},{downloadExcel:i}=Me(),p=()=>{i(b,P,G)},{isModalOpen:D,modalTitle:r,leads:T,totalLeads:m,totalPages:J,currentPage:Y,itemsPerPage:Q,isLoading:wt,isFetching:gt,error:ft,openDrilldown:pt,closeDrilldown:bt,handlePageChange:ct,handleItemsPerPageChange:kt}=Yt(),dt=xt(),Ct=(O,_)=>{var n,h;if(!d.value||_.type==="total"&&!R.value)return;const f={report_type:"master_lead",filter_level:ut(_),filter_type:tt(O)};(n=dt.dateFilter.user_ids)!=null&&n.length&&(f.user_ids=dt.dateFilter.user_ids),(h=dt.dateFilter.role_ids)!=null&&h.length&&(f.role_ids=dt.dateFilter.role_ids),_.channelId!==void 0&&(f.channel_id=_.channelId),_.groupId!==void 0&&(f.group_id=_.groupId),_.sourceId!==void 0&&(f.source_id=_.sourceId),E(f,O,d.value);const x=z(O,_);pt(f,x)},ut=O=>{switch(O.type){case"total":return"total";case"channel":return"channel";case"group":return"group";case"source":return"source";default:return"total"}},tt=O=>["month_0_prev_year","month_0","month_1","month_2","month_3","month_4","month_5","month_6"].includes(O)?"created_month":["sold_prev_year","sold_curr_year"].includes(O)?"sold_month":O==="close_12mo"?"close_rate_12mo":O==="close_3mo"?"close_rate_3mo":O==="close_last_mo"?"close_rate_last_mo":"created_month",E=(O,_,f)=>{const x={month_0_prev_year:f.month_0_prev_year_date,month_0:f.month_0_date,month_1:f.month_1_date,month_2:f.month_2_date,month_3:f.month_3_date,month_4:f.month_4_date,month_5:f.month_5_date,month_6:f.month_6_date};if(x[_]?O.target_month=x[_]:_==="sold_prev_year"?O.target_month=f.month_0_prev_year_date:_==="sold_curr_year"&&(O.target_month=f.month_0_date),_==="close_12mo"){const n=new Date,h=new Date;h.setMonth(n.getMonth()-12),O.start_date=h.toISOString(),O.end_date=n.toISOString()}else if(_==="close_3mo"){const n=new Date,h=new Date;h.setMonth(n.getMonth()-3),O.start_date=h.toISOString(),O.end_date=n.toISOString()}else if(_==="close_last_mo"){const n=new Date,h=new Date;h.setMonth(n.getMonth()-1),O.start_date=h.toISOString(),O.end_date=n.toISOString()}},z=(O,_)=>{var h,at,nt,K,et,q,X,mt,Lt,Ot;const x={month_0_prev_year:((h=d.value)==null?void 0:h.month_0_prev_year_label)||"",month_0:((at=d.value)==null?void 0:at.month_0_label)||"",month_1:((nt=d.value)==null?void 0:nt.month_1_label)||"",month_2:((K=d.value)==null?void 0:K.month_2_label)||"",month_3:((et=d.value)==null?void 0:et.month_3_label)||"",month_4:((q=d.value)==null?void 0:q.month_4_label)||"",month_5:((X=d.value)==null?void 0:X.month_5_label)||"",month_6:((mt=d.value)==null?void 0:mt.month_6_label)||"",sold_prev_year:`Sold ${((Lt=d.value)==null?void 0:Lt.sold_prev_year_label)||""}`,sold_curr_year:`Sold ${((Ot=d.value)==null?void 0:Ot.sold_curr_year_label)||""}`,close_12mo:"Closing % - Last 12 Months",close_3mo:"Closing % - Last 3 Months",close_last_mo:"Closing % - Last Month"}[O]||O;return`${_.name||"All"} - ${x}`};return(O,_)=>(l(),u("div",$s,[t("div",Ss,[w(W,{size:"18",color:"#32ba8f",class:"tw-mt-0.5"},{default:a(()=>_[2]||(_[2]=[M(" mdi-information-outline ")])),_:1}),_[3]||(_[3]=t("span",null," Heads up: The Master Lead Report always reflects the current month's data, regardless of the time period filter selected above. ",-1))]),!o(k)&&o(C).length>
10?(l(),u("div",Rs,[t("a",{href:"#",onClick:Tt(B,["prevent"]),class:"tw-inline-flex tw-items-center tw-gap-1.5 tw-text-sm tw-text-gray-700 hover:tw-text-gray-900 tw-font-medium tw-transition-colors tw-duration-150","data-testid":"expand-collapse-all-link"},[w(W,{size:"16",color:"#32ba8f"},{default:a(()=>[M($(c.value?"mdi-arrow-collapse-all":"mdi-arrow-expand-all"),1)]),_:1}),t("span",null,$(c.value?"Collapse all Channels & Groups":"Expand all Channels & Groups"),1)]),w(Ht,{onDownload:p})])):Z("",!0),o(k)&&!o(C).length?(l(),u("div",Ls,[t("div",Ps,[w(At,{indeterminate:"",color:"primary",size:40,width:4}),_[4]||(_[4]=t("p",{class:"tw-mt-4 tw-text-gray-600"},"Loading master lead report...",-1))])])):o(g)?(l(),u("div",Ts,[w(W,{icon:"mdi-alert-circle-outline",size:"large",color:"error",class:"tw-mb-4"}),_[6]||(_[6]=t("p",{class:"tw-text-gray-700 tw-mb-2"},"Failed to load master lead report",-1)),t("p",Es,$(o(g)),1),w(zt,{color:"primary",size:"small",onClick:o(L),"data-testid":"master-lead-report-retry-btn"},{default:a(()=>_[5]||(_[5]=[M(" Try Again ")])),_:1},8,["onClick"])])):(l(),u("div",As,[w(Dt,{headers:G.value,items:N.value,loading:o(k),class:"elevation-0 master-lead-report-table","item-key":"id","items-per-page":-1,"hide-default-footer":"",density:"compact","fixed-header":"","data-testid":"master-lead-report-table"},Ut({headers:a(()=>[t("tr",Ds,[t("th",Is,$(V.value),1),_[7]||(_[7]=t("th",{colspan:"6",class:"text-center custom-header-cell-1"}," 6 Months Trend Leads ",-1)),_[8]||(_[8]=t("th",{colspan:"2",class:"text-center custom-header-cell-1"}," Sold Leads ",-1)),_[9]||(_[9]=t("th",{colspan:"3",class:"text-center custom-header-cell-1"}," Closing % ",-1))]),t("tr",Fs,[(l(!0),u(Et,null,_t(G.value,f=>(l(),u("th",{key:f.key,style:Nt({width:f.width+"px"}),class:lt(["custom-header-cell-2",f.align==="center"?"text-center":"text-start"])},$(f.title),7))),128))])]),"item.name":a(({item:f})=>[t("div",{class:lt(["tw-flex tw-items-center tw-gap-2 tw-whitespace-nowrap tw-text-sm tw-py-2",{"tw-pl-0":f.level===0,"tw-pl-6":f.level===1,"tw-pl-12":f.level===2,"tw-font-bold tw-text-gray-900":f.type==="total","tw-font-semibold tw-text-gray-900":f.type==="channel","tw-font-medium tw-text-gray-800":f.type==="group","tw-text-gray-700":f.type==="source","tw-cursor-pointer":f.isExpandable}]),onClick:x=>f.isExpandable?j(f):null},[f.isExpandable?(l(),ot(W,{key:0,size:"small","data-testid":`toggle-${f.type}-${f.id}`},{default:a(()=>[M($(f.isExpanded?"mdi-chevron-down":"mdi-chevron-right"),1)]),_:2},1032,["data-testid"])):(l(),u("span",Os)),t("span",{"data-testid":`name-${f.id}`},$(f.name),9,zs)],10,Ms)]),_:2},[_t(F,f=>({name:`item.${f}`,fn:a(({item:x})=>{var n;return[x.type==="total"&&!R.value?(l(),ot(vt,{key:0,"open-on-hover":!0,location:"top","close-delay":200,offset:8},{activator:a(({props:h})=>{var at;return[t("div",ht(h,{class:["tw-text-center tw-text-sm tw-cursor-not-allowed clickable-cell",{"tw-font-bold":x.type==="total","tw-font-semibold":x.type==="channel","tw-font-medium":x.type==="group"}]}),$(f.includes("close_")?`${x[f]}%`:((at=x[f])==null?void 0:at.toLocaleString())||0),17)]}),default:a(()=>[w(rt,{density:"compact","max-width":"250",elevation:"2",class:"total-row-tooltip-card"},{default:a(()=>[w(it,{class:"tw-py-2 tw-px-3"},{default:a(()=>[t("div",Us,$(v.value),1)]),_:1})]),_:1})]),_:2},1024)):(l(),u("div",{key:1,class:lt(["tw-text-center tw-text-sm tw-cursor-pointer hover:tw-bg-gray-100 tw-transition-colors clickable-cell",{"tw-font-bold":x.type==="total","tw-font-semibold":x.type==="channel","tw-font-medium":x.type==="group"}]),onClick:h=>Ct(f,x)},$(f.includes("close_")?`${x[f]}%`:((n=x[f])==null?void 0:n.toLocaleString())||0),11,Ns))]})}))]),1032,["headers","items","loading"])])),!o(k)&&o(C).length>0?(l(),u("div",Vs,[t("a",{href:"#",onClick:_[0]||(_[0]=Tt(f=>S.value=!S.value,["prevent"])),class:"tw-inline-flex tw-items-center tw-gap-1.5 tw-text-sm tw-text-gray-700 hover:tw-text-gray-900 tw-font-medium tw-transition-colors tw-duration-150","data-testid":"how-to-read-report-link"},[w(W,{size:"16",color:"#32ba8f"},{default:a(()=>[M($(S.value?"mdi-chevron-up":"mdi-chevron-down"),1)]),_:1}),_[10]||(_[10]=t("span",null,"How to read this report",-1))]),w(Vt,null,{default:a(()=>[Bt(t("div",Bs,[w(rt,{elevation:"0",class:"tw-border tw-border-gray-200"},{default:a(()=>[w(it,{class:"tw-p-6"},{default:a(()=>[_[30]||(_[30]=t("h3",{class:"tw-text-base tw-font-semibold tw-text-gray-900 tw-mb-5 tw-pb-3 tw-border-b tw-border-gray-200"}," Understanding Your Report Columns ",-1)),t("div",Gs,[_[27]||(_[27]=t("div",null,[t("div",{class:"tw-font-semibold tw-text-gray-900 tw-text-sm tw-mb-1"}," Channel / Group / Source "),t("div",{class:"tw-text-sm tw-text-gray-600"}," Hierarchical view showing your lead channels, source groups within each channel, and individual sources within each group. Click the chevron icons to expand or collapse each level. ")],-1)),t("div",null,[_[15]||(_[15]=t("div",{class:"tw-font-semibold tw-text-gray-900 tw-text-sm tw-mb-1"}," Month Columns ",-1)),t("div",qs,[_[13]||(_[13]=t("div",null,[M(" Shows the count of leads "),t("strong",null,"created"),M(" during each specific month. The report displays: ")],-1)),_[14]||(_[14]=t("ul",{class:"tw-list-disc tw-ml-6 tw-space-y-1"}
1,[t("li",null,` First column: Same month from previous year (e.g., "Oct '24") `),t("li",null," Next columns: Last 5 months plus current month (e.g., May-Oct) ")],-1)),t("div",Hs,[w(W,{size:"18",color:"#32ba8f",class:"tw-mt-0.5"},{default:a(()=>_[11]||(_[11]=[M(" mdi-information-outline ")])),_:1}),_[12]||(_[12]=t("div",{class:"tw-text-xs"},[M(" These columns track when leads were "),t("strong",null,"created"),M(", not when their status was updated. ")],-1))])])]),t("div",null,[_[20]||(_[20]=t("div",{class:"tw-font-semibold tw-text-gray-900 tw-text-sm tw-mb-1"}," Sold Columns ",-1)),t("div",js,[_[18]||(_[18]=t("div",null,[M(" Shows the count of leads where the status was "),t("strong",null,'updated to "Sold"'),M(" during that specific month: ")],-1)),_[19]||(_[19]=t("ul",{class:"tw-list-disc tw-ml-6 tw-space-y-1"},[t("li",null,` Previous Year: Same month last year (e.g., "Sold Oct '24") `),t("li",null,"Current Year: Current month")],-1)),t("div",Ws,[w(W,{size:"18",color:"#32ba8f",class:"tw-mt-0.5"},{default:a(()=>_[16]||(_[16]=[M(" mdi-information-outline ")])),_:1}),_[17]||(_[17]=t("div",{class:"tw-text-xs"},[M(" Sold columns use the status "),t("strong",null,"update date"),M(" when a lead was marked as sold, not the lead creation date. ")],-1))])])]),t("div",null,[_[26]||(_[26]=t("div",{class:"tw-font-semibold tw-text-gray-900 tw-text-sm tw-mb-1"}," Close Rate Columns ",-1)),t("div",Ys,[_[23]||(_[23]=t("div",null,[M(" Percentage of leads created within a time period where the "),t("strong",null,"current status"),M(' is "Sold": ')],-1)),_[24]||(_[24]=t("ul",{class:"tw-list-disc tw-ml-6 tw-space-y-1"},[t("li",null,[t("strong",null,"Last 12 Months:"),M(" Leads created in the last 12 months (up to current date/time) ")]),t("li",null,[t("strong",null,"Last 3 Months:"),M(" Leads created in the last 3 months (up to current date/time) ")]),t("li",null,[t("strong",null,"Last Month:"),M(" Leads created in the previous complete month ")])],-1)),_[25]||(_[25]=t("div",null," Formula: (Sold Leads Created in Period ÷ Total Leads Created in Period) à 100 ",-1)),t("div",Qs,[w(W,{size:"18",color:"#32ba8f",class:"tw-mt-0.5"},{default:a(()=>_[21]||(_[21]=[M(" mdi-alert-circle-outline ")])),_:1}),_[22]||(_[22]=t("div",{class:"tw-text-xs"},[t("strong",null,"Important:"),M(" Close rates use the lead "),t("strong",null,"creation date"),M(" for the time window, but check the "),t("strong",null,"current (latest) status"),M(` to determine if it's sold. A lead that was sold but later moved to "Lost" will NOT count in close rate calculations. `)],-1))])])])]),t("div",Ks,[w(W,{size:"16",color:"#32ba8f",class:"tw-mt-0.5"},{default:a(()=>_[28]||(_[28]=[M(" mdi-information-outline ")])),_:1}),_[29]||(_[29]=t("div",{class:"tw-text-sm tw-text-gray-600"}," Note: This report always reflects the current month's data, regardless of the time period filter selected above. ",-1))])]),_:1})]),_:1})],512),[[Gt,S.value]])]),_:1})])):Z("",!0),o(D)?(l(),ot(Xt,{key:5,visible:o(D),title:o(r),leads:o(T),"total-leads":o(m),"total-pages":o(J),"current-page":o(Y),"items-per-page":o(Q),"is-loading":o(wt),"is-fetching":o(gt),error:o(ft),"onUpdate:visible":_[1]||(_[1]=f=>D.value=f),onClose:o(bt),onPageChange:o(ct),onItemsPerPageChange:o(kt)}
1,null,8,["visible","title","leads","total-leads","total-pages","current-page","items-per-page","is-loading","is-fetching","error","onClose","onPageChange","onItemsPerPageChange"])):Z("",!0)]))}}),Zs=St(Xs,[["__scopeId","data-v-d448ce82"]]);function Js(){const I=Rt(),S=xt(),{dateFilter:R}=Pt(S),{data:v,isLoading:d,isFetching:b,error:C,refetch:P}=$t({queryKey:["salespersonActivitiesReport",R],queryFn:async()=>await I.fetchSalespersonActivitiesReport(R.value),staleTime:It.REALTIME,refetchOnWindowFocus:!0,refetchOnMount:!0,retry:1}),k=A(()=>v.value||[]),g=A(()=>{if(!k.value.length)return null;const s={sit:0,greet:0,leads:0,calls:0,emails:0,gmail:0,texts:0,facebook:0,total_activities:0,total_sold:0,appointments:0};return k.value.forEach(e=>{s.sit+=e.sit,s.greet+=e.greet,s.leads+=e.leads,s.calls+=e.calls,s.emails+=e.emails,s.gmail+=e.gmail,s.texts+=e.texts,s.facebook+=e.facebook,s.total_activities+=e.total_activities,s.total_sold+=e.total_sold,s.appointments+=e.appointments}),{id:0,name:"Total",location:"",...s}});return{reportData:k,totalsRow:g,isLoading:d,isFetching:b,error:C,refresh:()=>P()}}function to(){return{downloadExcel:(S,R,v)=>{const d=o(S),b=o(R),C=o(v);if(!(C!=null&&C.length)||!(d!=null&&d.length))return;const P=C.map(L=>L.title),k=[];if(d.forEach(L=>{const G=C.map(F=>{const N=L[F.key];return typeof N=="number"?N:N||""});k.push(G)}),b){const L=C.map(G=>{const F=b[G.key];return typeof F=="number"?F:F||""});k.push(L)}const g=[P,...k],U=st.aoa_to_sheet(g);U["!freeze"]={xSplit:0,ySplit:1};const s=st.decode_range(U["!ref"]);U["!autofilter"]={ref:st.encode_range(s)},U["!cols"]=C.map(L=>({wch:Math.ceil(L.width/8)}));const e=st.book_new();st.book_append_sheet(e,U,"Salesperson Activities");const y=`Salesperson_Activities_Report_${new Date().toISOString().slice(0,10)}.xlsx`;qt(e,y)}}}function eo(){const I=Rt(),S=H(!1),R=H(""),v=H(1),d=H(20),b=H(null),C=A(()=>(v.value-1)*d.value),{data:P,isLoading:k,isFetching:g,error:U,refetch:s}=$t({queryKey:["appointmentDrilldown",b,v,d],queryFn:async()=>b.value?await I.fetchAppointmentsDrilldown({...b.value,per_page:d.value,offset:C.value}):{data:[],total:0,per_page:20,current_page:1},enabled:A(()=>b.value!==null),staleTime:re,refetchOnWindowFocus:!1,retry:1}),e=A(()=>{var c;return((c=P.value)==null?void 0:c.data)||[]}),y=A(()=>{var c;return((c=P.value)==null?void 0:c.total)||0}),L=A(()=>Math.ceil(y.value/d.value));return{isModalOpen:S,modalTitle:R,appointments:e,totalAppointments:y,totalPages:L,currentPage:v,itemsPerPage:d,isLoading:k,isFetching:g,error:U,openDrilldown:(c,B)=>{b.value=c,R.value=B,v.value=1,S.value=!0},closeDrilldown:()=>{S.value=!1,setTimeout(()=>{b.value=null,R.value="",v.value=1},300)},handlePageChange:c=>{v.value=c},handleItemsPerPageChange:c=>{d.value=c,v.value=1},refetch:s}}const so={class:"drilldown-content"},oo={key:0,class:"tw-p-8","data-testid":"drilldown-loading"},ao={class:"tw-flex tw-flex-col tw-items-center tw-justify-center"},lo={key:1,class:"tw-p-8 tw-text-center","data-testid":"drilldown-error"},no={class:"tw-text-sm tw-text-gray-500"},ro={key:2,class:"tw-p-8 tw-text-center","data-testid":"drilldown-empty"},io={key:3,class:"table-with-pagination"},co={class:"tw-relative tw-overflow-x-auto","data-testid":"drilldown-table-wrapper"},uo={class:"tw-text-sm tw-font-medium tw-text-gray-900"},wo={key:0},po={key:1,class:"tw-text-gray-400"},mo={class:"tw-text-sm tw-text-gray-700"},_o={key:0},go={key:1,class:"tw-text-gray-400"},fo={class:"tw-text-sm"},ho={key:1,class:"tw-text-gray-400"},vo=["href"],yo={key:1,class:"tw-text-sm tw-text-gray-400"},xo={class:"tw-text-sm tw-text-gray-700"},bo={key:0},ko={key:1,class:"tw-text-gray-400"},Co={class:"tw-text-sm tw-text-gray-700"},$o={key:0},So={key:1,class:"tw-text-gray-400"},Ro={class:"tw-text-sm tw-text-gray-700"},Lo={key:0},Po={key:1,class:"tw-text-gray-400"},To={class:"tw-text-sm tw-text-gray-700"},Eo={key:0},Ao={key:1,class:"tw-text-gray-400"},Do={class:"tw-text-sm tw-text-gray-700"},Io={key:0},Fo={key:1,class:"tw-text-gray-400"},Mo={class:"tw-text-sm tw-text-gray-700 tw-max-w-xs tw-truncate"},Oo=["title"],zo={key:1,class:"tw-text-gray-400"},Uo=yt({__name:"AppointmentsDrilldownModal",props:{visible:{type:Boolean},title:{},appointments:{},totalAppointments:{},currentPage:{},totalPages:{},itemsPerPage:{},isLoading:{type:Boolean},isFetching:{type:Boolean},error:{}},emits:["update:visible","close","page-change","items-per-page-change"],setup(I,{emit:S}){const R=S,v=H(!1);typeof window<"u"&&(v.value=window.innerWidth<768);const d=[{title:"Title",key:"title",sortable:!1,align:"start",width:200},{title:"Status",key:"status",sortable:!1,align:"start",width:120},{title:"Due Date",key:"dueDate",sortable:!1,align:"start",width:150},{title:"Contact",key:"contact",sortable:!1,align:"start",width:180},{title:"Phone",key:"contactPhone",sortable:!1,align:"start",width:140},{title:"Email",key:"contactEmail",sortable:!1,align:"start",width:200},{title:"Assigned To",key:"assignee",sortable:!1,align:"start",width:150}
1,{title:"Created By",key:"creator",sortable:!1,align:"start",width:150},{title:"Created At",key:"createdAt",sortable:!1,align:"start",width:150},{title:"Note",key:"note",sortable:!1,align:"start",width:250}],b=()=>{R("update:visible",!1),R("close")},C=k=>{R("page-change",k)},P=k=>{R("items-per-page-change",k)};return(k,g)=>{const U=de,s=ie;return l(),ot(s,{"model-value":k.visible,"onUpdate:modelValue":g[0]||(g[0]=e=>R("update:visible",e)),"custom-title":k.title,entity:"",onClose:b,width:v.value?"95vw":"1400"},{footer:a(()=>[w(U,{text:"Close",onClick:b})]),default:a(()=>[t("div",so,[k.isLoading&&!k.appointments.length?(l(),u("div",oo,[t("div",ao,[w(At,{indeterminate:"",color:"primary",size:40,width:4}),g[1]||(g[1]=t("p",{class:"tw-mt-4 tw-text-gray-600"},"Loading appointment details...",-1))])])):k.error?(l(),u("div",lo,[w(W,{icon:"mdi-alert-circle-outline",size:"large",color:"error",class:"tw-mb-4"}),g[2]||(g[2]=t("p",{class:"tw-text-gray-700 tw-mb-2"}," Failed to load appointment details ",-1)),t("p",no,$(k.error),1)])):!k.appointments.length&&!k.isLoading?(l(),u("div",ro,[w(W,{icon:"mdi-information-outline",size:"large",color:"grey",class:"tw-mb-4"}),g[3]||(g[3]=t("p",{class:"tw-text-gray-700"},"No appointments found for this selection",-1))])):(l(),u("div",io,[t("div",co,[w(Dt,{headers:d,items:k.appointments,loading:k.isFetching,class:"elevation-0 drilldown-table","item-key":"id","items-per-page":-1,"hide-default-footer":"",density:"compact","fixed-header":"","data-testid":"drilldown-table"},{"item.title":a(({item:e})=>[t("div",uo,[e.title?(l(),u("span",wo,$(e.title),1)):(l(),u("span",po,"-"))])]),"item.status":a(({item:e})=>[t("div",mo,[e.status?(l(),u("span",_o,$(o(ve)(e.status)),1)):(l(),u("span",go,"-"))])]),"item.dueDate":a(({item:e})=>[t("div",fo,[e.dueDate?(l(),u("span",{key:0,class:lt(e.dueGroup==="overdue"?"tw-text-red-600":"tw-text-gray-700")},$(o(Ft)(e.dueDate)),3)):(l(),u("span",ho,"-"))])]),"item.contact":a(({item:e})=>[e.contact?(l(),u("a",{key:0,href:`/redirect?contactId=${e.contact.id}&tab=overview`,target:"_blank",class:"tw-text-sm tw-text-gray-900 hover:tw-underline"},$(e.contact.firstName)+" "+$(e.contact.lastName),9,vo)):(l(),u("span",yo,"-"))]),"item.contactPhone":a(({item:e})=>{var y;return[t("div",xo,[(y=e.contact)!=null&&y.mobile?(l(),u("span",bo,$(e.contact.mobile),1)):(l(),u("span",ko,"-"))])]}),"item.contactEmail":a(({item:e})=>{var y;return[t("div",Co,[(y=e.contact)!=null&&y.email?(l(),u("span",$o,$(e.contact.email),1)):(l(),u("span",So,"-"))])]}),"item.assignee":a(({item:e})=>[t("div",Ro,[e.assignee?(l(),u("span",Lo,$(e.assignee.firstName)+" "+$(e.assignee.lastName),1)):(l(),u("span",Po,"-"))])]),"item.creator":a(({item:e})=>[t("div",To,[e.creator?(l(),u("span",Eo,$(e.creator.firstName)+" "+$(e.creator.lastName),1)):(l(),u("span",Ao,"-"))])]),"item.createdAt":a(({item:e})=>[t("div",Do,[e.createdAt?(l(),u("span",Io,$(o(Ft)(e.createdAt)),1)):(l(),u("span",Fo,"-"))])]),"item.note":a(({item:e})=>[t("div",Mo,[e.note?(l(),u("span",{key:0,title:e.note},$(e.note),9,Oo)):(l(),u("span",zo,"-"))])]),_:1},8,["items","loading"])]),w(we,{"current-page":k.currentPage,"total-pages":k.totalPages,"items-per-page":k.itemsPerPage,"total-items":k.totalAppointments,"onUpdate:currentPage":C,"onUpdate:itemsPerPage":P},null,8,["current-page","total-pages","items-per-page","total-items"])]))])]),_:1},8,["model-value","custom-title","width"])}}}),No=St(Uo,[["__scopeId","data-v-8c4b0640"]]),Vo={class:"tw-flex tw-flex-col tw-space-y-4","data-testid":"salesperson-activities-report-container"},Bo={key:0,class:"tw-p-8","data-testid":"salesperson-activities-report-loading"},Go={class:"tw-flex tw-flex-col tw-items-center tw-justify-center"},qo={key:1,class:"tw-p-8 tw-text-center","data-testid":"salesperson-activities-report-error"},Ho={class:"tw-text-sm tw-text-gray-500 tw-mb-4"},jo={key:2,class:"tw-flex tw-flex-col tw-items-center tw-justify-center tw-rounded-lg tw-border tw-border-gray-200 tw-bg-gray-50 tw-p-10 tw-text-center","data-testid":"salesperson-activities-report-empty"},Wo={key:3,class:"tw-flex tw-justify-end"},Yo={key:4,class:"tw-relative tw-overflow-x-auto","data-testid":"salesperson-activities-report-table-wrapper"},Qo={class:"custom-header-row"},Ko=["data-testid"],Xo={class:"tw-text-sm tw-text-gray-700"},Zo={class:"tw-text-sm tw-text-white"},Jo=["onClick"],ta={key:5,class:"tw-mt-6"},ea={class:"tw-mt-3","data-testid":"how-to-read-report-content"},sa={class:"tw-mt-6 tw-pt-4 tw-border-t tw-border-gray-200 tw-flex tw-items-start tw-gap-2"},oa=yt({__name:"SalespersonActivitiesReport",setup(I){const S=H(!1),R=H(Qt),v=H(Kt),d=[{key:"name",title:"Salesperson",align:"start",width:220},{key:"location",title:"Location",align:"start",width:160},{key:"sit",title:"Sit",align:"center",width:80},{key:"greet",title:"Greet",align:"center",width:80},{key:"leads",title:"Leads",align:"center",width:90},{key:"calls",title:"Calls",align:"center",width:90},{key:"emails",title:"Emails",align:"center",width:90},{key:"gmail",title:"Gmail",align:"center",width:90},{key:"texts",title:"Texts",align:"center",width:90},{key:"facebook",title:"Facebook",align:"center",width:110}
1,{key:"total_activities",title:"Total Activities",align:"center",width:130},{key:"total_sold",title:"Total Sold",align:"center",width:120},{key:"appointments",title:"Appointments",align:"center",width:130}],b=A(()=>d.map(et=>({title:et.title,key:et.key,sortable:!1,align:et.align,width:et.width}))),C=d.filter(et=>et.align==="center").map(et=>et.key),{reportData:P,totalsRow:k,isLoading:g,isFetching:U,error:s,refresh:e}=Js(),y=A(()=>k.value?[...P.value,k.value]:P.value),L=A(()=>g.value&&P.value.length===0),G=A(()=>!!s.value),F=A(()=>s.value?typeof s.value=="string"?s.value:s.value instanceof Error?s.value.message:"An unexpected error occurred.":""),N=(et,q)=>Mt(et[q]),{downloadExcel:V}=to(),c=()=>{V(P,k,b)},{isModalOpen:B,modalTitle:j,leads:i,totalLeads:p,totalPages:D,currentPage:r,itemsPerPage:T,isLoading:m,isFetching:J,error:Y,openDrilldown:Q,closeDrilldown:wt,handlePageChange:gt,handleItemsPerPageChange:ft}=Yt(),{isModalOpen:pt,modalTitle:bt,appointments:ct,totalAppointments:kt,totalPages:dt,currentPage:Ct,itemsPerPage:ut,isLoading:tt,isFetching:E,error:z,openDrilldown:O,closeDrilldown:_,handlePageChange:f,handleItemsPerPageChange:x}=eo(),n=xt(),h=ye(),at=(et,q)=>{var Lt;if(q.id===0&&!R.value)return;if(et==="appointments"){const Ot=Wt(n.dateFilter),ee={start_date:Ot.start_date||"",end_date:Ot.end_date||"",timezone:((Lt=h.user)==null?void 0:Lt.timezone)||"UTC",...nt(n.dateFilter)};q.id!==0&&(ee.salesperson_id=q.id);const _e=q.id===0?"Appointments - All Salespeople":`Appointments - ${q.name}`;O(ee,_e);return}if(!["sit","greet","leads","total_sold"].includes(et))return;const X={report_type:"salesperson_activities",filter_level:q.id===0?"total":"salesperson",filter_type:et,...Wt(n.dateFilter),...nt(n.dateFilter)};q.id!==0&&(X.salesperson_id=q.id);const mt=`${q.name} - ${K(et)}`;Q(X,mt)};function nt(et){var X,mt;const q={};return(X=et.user_ids)!=null&&X.length&&(q.user_ids=et.user_ids),(mt=et.role_ids)!=null&&mt.length&&(q.role_ids=et.role_ids),q}const K=et=>({sit:"Sit",greet:"Greet",leads:"Leads",total_sold:"Total Sold"})[et]||et;return(et,q)=>(l(),u("div",Vo,[L.value?(l(),u("div",Bo,[t("div",Go,[w(At,{indeterminate:"",color:"primary",size:40,width:4}),q[3]||(q[3]=t("p",{class:"tw-mt-4 tw-text-gray-600"}," Loading salesperson activities report... ",-1))])])):G.value?(l(),u("div",qo,[w(W,{icon:"mdi-alert-circle-outline",size:"large",color:"error",class:"tw-mb-4"}),q[5]||(q[5]=t("p",{class:"tw-text-gray-700 tw-mb-2"}," Failed to load salesperson activities report ",-1)),t("p",Ho,$(F.value),1),w(zt,{color:"primary",size:"small",onClick:o(e),"data-testid":"salesperson-activities-report-retry-btn"},{default:a(()=>q[4]||(q[4]=[M(" Try Again ")])),_:1},8,["onClick"])])):o(P).length?Z("",!0):(l(),u("div",jo,[w(W,{icon:"mdi-account-tie-outline",size:"48",color:"grey-lighten-2",class:"tw-mb-3"}),q[6]||(q[6]=t("p",{class:"tw-text-sm tw-font-medium tw-text-gray-700 tw-mb-1"}," No salesperson activity found ",-1)),q[7]||(q[7]=t("p",{class:"tw-text-xs tw-text-gray-500"}," Try a different time period or invite salesperson to Transax. ",-1))])),!L.value&&o(P).length>0?(l(),u("div",Wo,[w(Ht,{onDownload:c})])):Z("",!0),!L.value&&!G.value&&o(P).length>0?(l(),u("div",Yo,[w(Dt,{headers:b.value,items:y.value,loading:o(g)&&!o(P).length,class:"elevation-0 salesperson-activities-report-table","item-key":"id","items-per-page":-1,"hide-default-footer":"",density:"compact","data-testid":"salesperson-activities-report-table"},Ut({headers:a(()=>[t("tr",Qo,[(l(!0),u(Et,null,_t(b.value,X=>(l(),u("th",{key:X.key,style:Nt({width:X.width+"px"}),class:lt(["custom-header-cell",X.align==="center"?"text-center":"text-start"])},$(X.title),7))),128))])]),"item.name":a(({item:X})=>[t("div",{class:lt(["tw-flex tw-items-center tw-text-sm tw-text-gray-900",{"tw-font-bold":X.id===0,"tw-font-medium":X.id!==0}]),"data-testid":`salesperson-name-${X.id}`},$(X.name),11,Ko)]),"item.location":a(({item:X})=>[t("span",Xo,$(X.location||"â"),1)]),bottom:a(()=>[]),_:2},[_t(o(C),X=>({name:`item.${X}`,fn:a(({item:mt})=>[mt.id===0&&!R.value&&["sit","greet","leads","total_sold","appointments"].includes(X)?(l(),ot(vt,{key:0,"open-on-hover":!0,location:"top","close-delay":200,offset:8},{activator:a(({props:Lt})=>[t("div",ht(Lt,{class:"tw-text-center tw-text-sm tw-text-gray-900 tw-cursor-not-allowed clickable-cell"}),$(N(mt,X)),17)]),default:a(()=>[w(rt,{density:"compact","max-width":"250",elevation:"2",class:"total-row-tooltip-card"},{default:a(()=>[w(it,{class:"tw-py-2 tw-px-3"},{default:a(()=>[t("div",Zo,$(v.value),1)]),_:1})]),_:1})]),_:2},1024)):(l(),u("div",{key:1,class:lt(["tw-text-center tw-text-sm tw-text-gray-900",{"tw-cursor-pointer hover:tw-bg-gray-100 tw-transition-colors clickable-cell":["sit","greet","leads","total_sold","appointments"].includes(X)}]),onClick:Lt=>["sit","greet","leads","total_sold","appointments"].includes(X)?at(X,mt):null},$(N(mt,X)),11,Jo))])}))]),1032,["headers","items","loading"]),o(U)&&o(P).length?(l(),ot(te,{key:0,indeterminate:"",color:"primary",class:"tw-absolute tw-left-0 tw-right-0 tw-top-0",height:"3"})):Z("",!0)])):Z("",!0),!L.value&&!G.value&&o(P).length>0?(l(),u("div",ta,[t("a",{href:"#",onClick:q[0]||(q[0]=Tt(X=>S.value=!S.value,["prevent"])),class:"tw-inline-flex tw-items-center tw-gap-1.5 tw-text-sm tw-text-gray-700 hover:tw-text-gray-900 tw-font-medium tw-transition-colors tw-duration-150","data-testid":"how-to-read-report-link"},[w(W,{size:"16",color:"#32ba8f"},{default:a(()=>[M($(S.value?"mdi-chevron-up":"mdi-chevron-down"),1)]),_:1}),q[8]||(q[8]=t("span",null,"How to read this report",-1))]),w(Vt,null,{default:a(()=>[Bt(t("div",ea,[w(rt,{elevation:"0",class:"tw-border tw-border-gray-200"},{default:a(()=>[w(it,{class:"tw-p-6"},{default:a(()=>[q[11]||(q[11]=t("h3",{class:"tw-text-base tw-font-semibold tw-text-gray-900 tw-mb-5 tw-pb-3 tw-border-b tw-border-gray-200"}," Understanding Your Report Columns ",-1)),q[12]||(q[12]=t("div",{class:"tw-grid tw-gri
1d-cols-1 md:tw-grid-cols-2 tw-gap-x-8 tw-gap-y-4"},[t("div",{class:"tw-space-y-4"},[t("div",null,[t("div",{class:"tw-font-semibold tw-text-gray-900 tw-text-sm tw-mb-1"}," Salesperson "),t("div",{class:"tw-text-sm tw-text-gray-600"}," Lists all active salespeople. Salespeople appear in this report even if they have no activities during the selected time period. ")]),t("div",null,[t("div",{class:"tw-font-semibold tw-text-gray-900 tw-text-sm tw-mb-1"}," Location "),t("div",{class:"tw-text-sm tw-text-gray-600"}," The salesperson's location. ")]),t("div",null,[t("div",{class:"tw-font-semibold tw-text-gray-900 tw-text-sm tw-mb-1"}," Sit "),t("div",{class:"tw-text-sm tw-text-gray-600"},' Number of leads the salesperson worked on that reached "Sit" status during the selected time period. ')]),t("div",null,[t("div",{class:"tw-font-semibold tw-text-gray-900 tw-text-sm tw-mb-1"}," Greet "),t("div",{class:"tw-text-sm tw-text-gray-600"},' Number of leads the salesperson worked on that reached "Greet" status during the selected time period. ')]),t("div",null,[t("div",{class:"tw-font-semibold tw-text-gray-900 tw-text-sm tw-mb-1"}," Leads "),t("div",{class:"tw-text-sm tw-text-gray-600"}," Total number of leads the salesperson worked on during the selected time period. ")]),t("div",null,[t("div",{class:"tw-font-semibold tw-text-gray-900 tw-text-sm tw-mb-1"}," Calls "),t("div",{class:"tw-text-sm tw-text-gray-600"}," Number of phone calls the salesperson made (from logged phone call activities). ")]),t("div",null,[t("div",{class:"tw-font-semibold tw-text-gray-900 tw-text-sm tw-mb-1"}," Emails "),t("div",{class:"tw-text-sm tw-text-gray-600"}," Number of emails the salesperson sent. ")])]),t("div",{class:"tw-space-y-4"},[t("div",null,[t("div",{class:"tw-font-semibold tw-text-gray-900 tw-text-sm tw-mb-1"}," Gmail "),t("div",{class:"tw-text-sm tw-text-gray-600"}," Number of Gmail messages the salesperson sent. ")]),t("div",null,[t("div",{class:"tw-font-semibold tw-text-gray-900 tw-text-sm tw-mb-1"}," Texts "),t("div",{class:"tw-text-sm tw-text-gray-600"}," Number of SMS text conversations (counted once per day, even if multiple texts were sent). ")]),t("div",null,[t("div",{class:"tw-font-semibold tw-text-gray-900 tw-text-sm tw-mb-1"}," Facebook "),t("div",{class:"tw-text-sm tw-text-gray-600"}," Number of Facebook message conversations (counted once per day, similar to Texts). ")]),t("div",null,[t("div",{class:"tw-font-semibold tw-text-gray-900 tw-text-sm tw-mb-1"}," Total Activities "),t("div",{class:"tw-text-sm tw-text-gray-600"}," The combined total of all activities (calls, emails, texts, etc.). ")]),t("div",null,[t("div",{class:"tw-font-semibold tw-text-gray-900 tw-text-sm tw-mb-1"}," Total Sold "),t("div",{class:"tw-text-sm tw-text-gray-600"}," Number of leads that were marked as sold during the selected time period. This counts when leads got sold, regardless of when they were originally created. ")]),t("div",null,[t("div",{class:"tw-font-semibold tw-text-gray-900 tw-text-sm tw-mb-1"}," Appointments "),t("div",{class:"tw-text-sm tw-text-gray-600"}," Number of appointments based on their scheduled date & time (not when the appointment entry was created). ")])])],-1)),t("div",sa,[w(W,{size:"16",color:"#32ba8f",class:"tw-mt-0.5"},{default:a(()=>q[9]||(q[9]=[M(" mdi-information-outline ")])),_:1}),q[10]||(q[10]=t("div",{class:"tw-text-sm tw-text-gray-600"}," All columns reflect data from the time period selected in the filter above. ",-1))])]),_:1})]),_:1})],512),[[Gt,S.value]])]),_:1})])):Z("",!0),o(B)?(l(),ot(Xt,{key:6,visible:o(B),title:o(j),leads:o(i),"total-leads":o(p),"total-pages":o(D),"current-page":o(r),"items-per-page":o(T),"is-loading":o(m),"is-fetching":o(J),error:o(Y),"onUpdate:visible":q[1]||(q[1]=X=>B.value=X),onClose:o(wt),onPageChange:o(gt),onItemsPerPageChange:o(ft)}
1,null,8,["visible","title","leads","total-leads","total-pages","current-page","items-per-page","is-loading","is-fetching","error","onClose","onPageChange","onItemsPerPageChange"])):Z("",!0),o(pt)?(l(),ot(No,{key:7,visible:o(pt),title:o(bt),appointments:o(ct),"total-appointments":o(kt),"total-pages":o(dt),"current-page":o(Ct),"items-per-page":o(ut),"is-loading":o(tt),"is-fetching":o(E),error:o(z),"onUpdate:visible":q[2]||(q[2]=X=>pt.value=X),onClose:o(_),onPageChange:o(f),onItemsPerPageChange:o(x)},null,8,["visible","title","appointments","total-appointments","total-pages","current-page","items-per-page","is-loading","is-fetching","error","onClose","onPageChange","onItemsPerPageChange"])):Z("",!0)]))}}),aa=St(oa,[["__scopeId","data-v-98b94f0d"]]);function la(){const I=Rt(),S=xt(),{dateFilter:R}=Pt(S),v=H(new Set),d=H(new Set),{data:b,isLoading:C,isFetching:P,error:k,refetch:g}=$t({queryKey:["leadSourcesReport",R],queryFn:async()=>await I.fetchLeadSourcesReport(R.value),staleTime:It.REALTIME,refetchOnWindowFocus:!0,refetchOnMount:!0,retry:1}),U=A(()=>{var i;return((i=b.value)==null?void 0:i.statuses)||[]}),s=(i,p,D,r)=>i==="channel"?`channel-${p}`:i==="group"?`group-${p}-${D}`:i==="source"?`source-${p}-${D}-${r}`:"total",e=i=>v.value.has(i),y=(i,p)=>d.value.has(`${i}-${p}`),L=i=>{v.value.has(i)?v.value.delete(i):v.value.add(i)},G=(i,p)=>{const D=`${i}-${p}`;d.value.has(D)?d.value.delete(D):d.value.add(D)},F=A(()=>{var D;if(!((D=b.value)!=null&&D.data)||!b.value.data.length)return[];const i=new Map;b.value.data.forEach(r=>{let T=i.get(r.channel_id);T||(T={type:"channel",channel_id:r.channel_id,channel_name:r.channel_name,channel_slug:r.channel_slug,groups:[],new_lead:0,contacted:0,greet:0,probe:0,sit_on:0,presented_demo:0,sit_down:0,write_up:0,close:0,f_and_i:0,sold:0,lost:0,lead_total:0,close_rate:0},i.set(r.channel_id,T));let m=T.groups.find(Y=>Y.group_id===r.group_id);m||(m={type:"group",group_id:r.group_id,group_name:r.group_name,group_slug:r.group_slug,sources:[],new_lead:0,contacted:0,greet:0,probe:0,sit_on:0,presented_demo:0,sit_down:0,write_up:0,close:0,f_and_i:0,sold:0,lost:0,lead_total:0,close_rate:0},T.groups.push(m));const J={type:"source",source_id:r.source_id,source_name:r.source_name,source_slug:r.source_slug,new_lead:r.new_lead,contacted:r.contacted,greet:r.greet,probe:r.probe,sit_on:r.sit_on,presented_demo:r.presented_demo,sit_down:r.sit_down,write_up:r.write_up,close:r.close,f_and_i:r.f_and_i,sold:r.sold,lost:r.lost,lead_total:r.lead_total,close_rate:r.close_rate};m.sources.push(J),m.new_lead+=r.new_lead,m.contacted+=r.contacted,m.greet+=r.greet,m.probe+=r.probe,m.sit_on+=r.sit_on,m.presented_demo+=r.presented_demo,m.sit_down+=r.sit_down,m.write_up+=r.write_up,m.close+=r.close,m.f_and_i+=r.f_and_i,m.sold+=r.sold,m.lost+=r.lost,m.lead_total+=r.lead_total,T.new_lead+=r.new_lead,T.contacted+=r.contacted,T.greet+=r.greet,T.probe+=r.probe,T.sit_on+=r.sit_on,T.presented_demo+=r.presented_demo,T.sit_down+=r.sit_down,T.write_up+=r.write_up,T.close+=r.close,T.f_and_i+=r.f_and_i,T.sold+=r.sold,T.lost+=r.lost,T.lead_total+=r.lead_total});const p=Array.from(i.values());return p.forEach(r=>{if(r.groups.forEach(T=>{if(T.lead_total>0){const m=T.sources.reduce((J,Y)=>J+Y.close_rate*Y.lead_total,0);T.close_rate=Math.round(m/T.lead_total)}else T.close_rate=0}),r.lead_total>0){const T=r.groups.reduce((m,J)=>m+J.close_rate*J.lead_total,0);r.close_rate=Math.round(T/r.lead_total)}else r.close_rate=0}),p}),N=A(()=>{if(!F.value.length)return[];const i=[];return F.value.forEach(p=>{const D=e(p.channel_id);i.push({id:s("channel",p.channel_id),type:"channel",name:p.channel_name,level:0,isExpandable:p.groups.length>0,isExpanded:D,channelId:p.channel_id,new_lead:p.new_lead,contacted:p.contacted,greet:p.greet,probe:p.probe,sit_on:p.sit_on,presented_demo:p.presented_demo,sit_down:p.sit_down,write_up:p.write_up,close:p.close,f_and_i:p.f_and_i,sold:p.sold,lost:p.lost,lead_total:p.lead_total,close_rate:p.close_rate}),D&&p.groups.forEach(r=>{const T=y(p.channel_id,r.group_id);i.push({id:s("group",p.channel_id,r.group_id),type:"group",name:r.group_name,level:1,isExpandable:r.sources.length>0,isExpanded:T,parentId:s("channel",p.channel_id),channelId:p.channel_id,groupId:r.group_id,new_lead:r.new_lead,contacted:r.contacted,greet:r.greet,probe:r.probe,sit_on:r.sit_on,presented_demo:r.presented_demo,sit_down:r.sit_down,write_up:r.write_up,close:r.close,f_and_i:r.f_and_i,sold:r.sold,lost:r.lost,lead_total:r.lead_total,close_rate:r.close_rate}
1),T&&r.sources.forEach(m=>{i.push({id:s("source",p.channel_id,r.group_id,m.source_id),type:"source",name:m.source_name,level:2,isExpandable:!1,parentId:s("group",p.channel_id,r.group_id),channelId:p.channel_id,groupId:r.group_id,sourceId:m.source_id,new_lead:m.new_lead,contacted:m.contacted,greet:m.greet,probe:m.probe,sit_on:m.sit_on,presented_demo:m.presented_demo,sit_down:m.sit_down,write_up:m.write_up,close:m.close,f_and_i:m.f_and_i,sold:m.sold,lost:m.lost,lead_total:m.lead_total,close_rate:m.close_rate})})})}),i}),V=A(()=>{if(!F.value.length)return null;const i={new_lead:0,contacted:0,greet:0,probe:0,sit_on:0,presented_demo:0,sit_down:0,write_up:0,close:0,f_and_i:0,sold:0,lost:0,lead_total:0};F.value.forEach(D=>{i.new_lead+=D.new_lead,i.contacted+=D.contacted,i.greet+=D.greet,i.probe+=D.probe,i.sit_on+=D.sit_on,i.presented_demo+=D.presented_demo,i.sit_down+=D.sit_down,i.write_up+=D.write_up,i.close+=D.close,i.f_and_i+=D.f_and_i,i.sold+=D.sold,i.lost+=D.lost,i.lead_total+=D.lead_total});let p=0;if(i.lead_total>0){const D=F.value.reduce((r,T)=>r+T.close_rate*T.lead_total,0);p=Math.round(D/i.lead_total)}return{id:"total",type:"total",name:"Total",level:3,isExpandable:!1,...i,close_rate:p}});return{statuses:U,hierarchicalData:F,tableRows:N,totalsRow:V,isLoading:C,isFetching:P,error:k,toggleChannel:L,toggleGroup:G,isChannelExpanded:e,isGroupExpanded:y,expandAll:()=>{F.value.forEach(i=>{v.value.add(i.channel_id),i.groups.forEach(p=>{d.value.add(`${i.channel_id}-${p.group_id}`)})})},collapseAll:()=>{v.value.clear(),d.value.clear()},refresh:()=>g()}}function na(){return{downloadExcel:(S,R,v)=>{const d=o(S),b=o(R),C=o(v);if(!(C!=null&&C.length)||!(d!=null&&d.length))return;const P=C.filter(c=>c.key!=="name"),k=new Set(["close_rate"]),g=["Type","Channel","Group","Source",...P.map(c=>c.title)],U=[],s=c=>typeof c=="number"?c:c??"",e=(c,B,j)=>{const i=P.map(p=>{if(k.has(p.key)){const D=j[p.key];return typeof D=="number"?D/100:0}return s(j[p.key])});U.push([c,B.channel??"",B.group??"",B.source??"",...i])};if(d.forEach(c=>{e("channel",{channel:c.channel_name},c),c.groups.forEach(B=>{e("group",{channel:c.channel_name,group:B.group_name},B),B.sources.forEach(j=>{e("source",{channel:c.channel_name,group:B.group_name,source:j.source_name},j)})})}),b){const c=b,B=P.map(j=>{if(k.has(j.key)){const p=c[j.key];return typeof p=="number"?p/100:0}const i=c[j.key];return typeof i=="number"?i:i??""});U.push(["total","TOTAL","","",...B])}const y=[g,...U],L=st.aoa_to_sheet(y);L["!freeze"]={xSplit:3,ySplit:1};const G=st.decode_range(L["!ref"]);L["!autofilter"]={ref:st.encode_range(G)},L["!cols"]=[{wch:10},{wch:24},{wch:24},{wch:28},...P.map(()=>({wch:12}))];const F=P.map((c,B)=>k.has(c.key)?B:-1).filter(c=>c>=0).map(c=>c+4);for(let c=1;c<=G.e.r;c++)for(const B of F){const j=st.encode_cell({r:c,c:B}),i=L[j];i&&typeof i.v=="number"&&(i.t="n",i.z="0%")}const N=st.book_new();st.book_append_sheet(N,L,"Lead Sources Report");const V=`Lead_Sources_Report_${new Date().toISOString().slice(0,10)}.xlsx`;qt(N,V)}}}const Jt={1:"new_lead",2:"contacted",3:"greet",4:"probe",5:"sit_on",6:"presented_demo",7:"sit_down",8:"write_up",9:"close",10:"f_and_i",11:"sold",12:"lost"};function me(){return{STATUS_ORDER_TO_FIELD_KEY:Jt,getShortName:v=>{const d=v.replace(/[^a-zA-Z]/g,"");if(d.length===0)return"";if(d.length===1)return d.toUpperCase();const b=d[0],C=d[d.length-1];return(b+C).toUpperCase()},getFieldKeyByOrder:v=>Jt[v],getAllFieldKeys:()=>Object.values(Jt)}}const ra={class:"tw-flex tw-flex-col tw-space-y-4","data-testid":"lead-sources-report-container"},ia={key:0,class:"tw-flex tw-justify-between tw-items-center"},da={key:1,class:"tw-p-8","data-testid":"lead-sources-report-loading"},ca={class:"tw-flex tw-flex-col tw-items-center tw-justify-center"},ua={key:2,class:"tw-p-8 tw-text-center","data-testid":"lead-sources-report-error"},wa={class:"tw-text-sm tw-text-gray-500 tw-mb-4"},pa={key:3,class:"tw-flex tw-flex-col tw-items-center tw-justify-center tw-rounded-lg tw-border tw-border-gray-200 tw-bg-gray-50 tw-p-10 tw-text-center","data-testid":"lead-sources-report-empty"},ma={key:4,class:"tw-relative tw-overflow-x-auto","data-testid":"lead-sources-report-table-wrapper"},_a={class:"custom-header-row"},ga={class:"tw-font-semibold tw-text-sm tw-text-white"},fa={key:1},ha=["onClick"],va={key:1,class:"tw-w-5"},ya=["data-testid"],xa={class:"tw-text-sm tw-text-white"},ba=["onClick"],ka={class:"tw-text-sm tw-text-white"},Ca=["onClick"],$a={class:"tw-text-sm tw-text-white"},Sa=["onClick"],Ra={key:5,class:"tw-mt-6"},La={class:"tw-mt-3","data-testid":"how-to-read-report-content"},Pa={class:"tw-space-y-5"},Ta={class:"tw-text-sm tw-text-gray-600 tw-space-y-2"},Ea={class:"tw-flex tw-items-start tw-gap-2 tw-mt-2 tw-p-3 tw-rounded-md tw-border tw-text-sm",style:{"background-color":"rgba(50, 186, 143, 0.12)","border-color":"#32ba8f",color:"#157657"}},Aa={class:"tw-text-sm tw-text-gray-600 tw-space-y-2"},Da={class:"tw-flex tw-items-start tw-gap-2 tw-mt-2 tw-p-3 tw-rounded-md tw-border tw-text-sm",style:{"background-color":"rgba(50, 186, 143, 0.12)","border-color":"#32ba8f",color:"#157657"}},Ia={class:"tw-mt-6 tw-pt-4 tw-border-t tw-border-gray-200 tw-flex tw-items-start tw-gap-2"},Fa=yt({__name:"LeadSourcesReport",setup(I){const S=H(!1),R=H(Qt),v=H(Kt),{statuses:d,hierarchicalData:b,tableRows:C,totalsRow:P,isLoading:k,error:g,toggleChannel:U,toggleGroup:s,expandAll:e,collapseAll:y,refresh:L}=la(),{STATUS_ORDER_TO_FIELD_KEY:G,getShortName:F}=me(),N=G,V=A(()=>{const f=[{title:"Channel / Group / Source",key:"name",sortable:!1,align:"start",width:250}];return d.value.forEach(x=>{const n=N[x.order];n&&f.push({title:x.name,shortName:F(x.name),key:n,sortable:!1,align:"center",width:60})}),f.push({title:"Lead Total",key:"lead_total",sortable:!1,align:"center",width:100},{title:"Close Rate",key:"close_rate",sortable:!1,align:"center",width:120}),f}),c=A(()=>d.value.map(f=>
1N[f.order]).filter(Boolean)),B=A(()=>P.value?[...C.value,P.value]:C.value),j=A(()=>{const f=C.value.filter(x=>x.isExpandable);return f.length===0?!1:f.every(x=>x.isExpanded)}),i=()=>{j.value?y():e()},p=f=>{f.isExpandable&&(f.type==="channel"&&f.channelId!==void 0?U(f.channelId):f.type==="group"&&f.channelId!==void 0&&f.groupId!==void 0&&s(f.channelId,f.groupId))},{downloadExcel:D}=na(),r=()=>{D(b,P,V)},{isModalOpen:T,modalTitle:m,leads:J,totalLeads:Y,totalPages:Q,currentPage:wt,itemsPerPage:gt,isLoading:ft,isFetching:pt,error:bt,openDrilldown:ct,closeDrilldown:kt,handlePageChange:dt,handleItemsPerPageChange:Ct}=Yt(),ut=xt(),tt=A(()=>{const f={};return d.value.forEach(x=>{const n=N[x.order];n&&(f[n]=x.id)}),f}),E=(f,x)=>{var at,nt;if(x.type==="total"&&!R.value)return;const n={report_type:"lead_sources",filter_level:z(x),filter_type:O(f),...Wt(ut.dateFilter)};(at=ut.dateFilter.user_ids)!=null&&at.length&&(n.user_ids=ut.dateFilter.user_ids),(nt=ut.dateFilter.role_ids)!=null&&nt.length&&(n.role_ids=ut.dateFilter.role_ids),x.channelId!==void 0&&(n.channel_id=x.channelId),x.groupId!==void 0&&(n.group_id=x.groupId),x.sourceId!==void 0&&(n.source_id=x.sourceId),f!=="lead_total"&&f!=="close_rate"&&(n.status_id=tt.value[f]);const h=`${x.name} - ${_(f)}`;ct(n,h)},z=f=>f.type,O=f=>f==="lead_total"?"lead_total":f==="close_rate"?"close_rate":"status_latest",_=f=>{const x=V.value.find(n=>n.key===f);return(x==null?void 0:x.title)||f};return(f,x)=>(l(),u("div",ra,[!o(k)&&o(C).length>0?(l(),u("div",ia,[t("a",{href:"#",onClick:Tt(i,["prevent"]),class:"tw-inline-flex tw-items-center tw-gap-1.5 tw-text-sm tw-text-gray-700 hover:tw-text-gray-900 tw-font-medium tw-transition-colors tw-duration-150","data-testid":"expand-collapse-all-link"},[w(W,{size:"16",color:"#32ba8f"},{default:a(()=>[M($(j.value?"mdi-arrow-collapse-all":"mdi-arrow-expand-all"),1)]),_:1}),t("span",null,$(j.value?"Collapse all Channels & Groups":"Expand all Channels & Groups"),1)]),w(Ht,{onDownload:r})])):Z("",!0),o(k)&&!o(C).length?(l(),u("div",da,[t("div",ca,[w(At,{indeterminate:"",color:"primary",size:40,width:4}),x[2]||(x[2]=t("p",{class:"tw-mt-4 tw-text-gray-600"},"Loading lead sources report...",-1))])])):o(g)?(l(),u("div",ua,[w(W,{icon:"mdi-alert-circle-outline",size:"large",color:"error",class:"tw-mb-4"}),x[4]||(x[4]=t("p",{class:"tw-text-gray-700 tw-mb-2"},"Failed to load lead sources report",-1)),t("p",wa,$(o(g)),1),w(zt,{color:"primary",size:"small",onClick:o(L),"data-testid":"lead-sources-report-retry-btn"},{default:a(()=>x[3]||(x[3]=[M(" Try Again ")])),_:1},8,["onClick"])])):o(C).length?(l(),u("div",ma,[w(Dt,{headers:V.value,items:B.value,loading:o(k),class:"elevation-0 lead-sources-report-table","item-key":"id","items-per-page":-1,"hide-default-footer":"",density:"compact","fixed-header":"","data-testid":"lead-sources-report-table"},Ut({headers:a(()=>[t("tr",_a,[(l(!0),u(Et,null,_t(V.value,n=>(l(),u("th",{key:n.key,style:Nt({width:n.width+"px"}),class:lt(["custom-header-cell",n.align==="center"?"text-center":"text-start"])},[n.shortName?(l(),ot(vt,{key:0,"open-on-hover":!0,location:"top","close-delay":200,offset:8},{activator:a(({props:h})=>[t("span",ht({ref_for:!0},h,{class:"tw-cursor-help"}),$(n.shortName),17)]),default:a(()=>[w(rt,{density:"compact","max-width":"200",elevation:"2",class:"status-tooltip-card"},{default:a(()=>[w(it,{class:"tw-py-2 tw-px-3"},{default:a(()=>[t("div",ga,$(n.title),1)]),_:2},1024)]),_:2},1024)]),_:2},1024)):(l(),u("span",fa,$(n.title),1))],6))),128))])]),"item.name":a(({item:n})=>[t("div",{class:lt(["tw-flex tw-items-center tw-gap-2 tw-whitespace-nowrap tw-text-sm",{"tw-pl-0":n.level===0,"tw-pl-6":n.level===1,"tw-pl-12":n.level===2,"tw-font-bold tw-text-gray-900":n.type==="total","tw-font-semibold tw-text-gray-900":n.type==="channel","tw-font-medium tw-text-gray-800":n.type==="group","tw-text-gray-700":n.type==="source","tw-cursor-pointer":n.isExpandable}]),onClick:h=>n.isExpandable?p(n):null},[n.isExpandable?(l(),ot(W,{key:0,size:"small","data-testid":`toggle-${n.type}-${n.id}`},{default:a(()=>[M($(n.isExpanded?"mdi-chevron-down":"mdi-chevron-right"),1)]),_:2},1032,["data-testid"])):(l(),u("span",va)),t("span",{"data-testid":`name-${n.id}`},$(n.name),9,ya)],10,ha)]),"item.lead_total":a(({item:n})=>{var h;return[n.type==="total"&&!R.value?(l(),ot(vt,{key:0,"open-on-hover":!0,location:"top","close-delay":200,offset:8},{activator:a(({props:at})=>{var nt;return[t("div",ht(at,{class:["tw-text-center tw-text-sm tw-cursor-not-allowed clickable-cell",{"tw-font-bold":n.type==="total","tw-font-semibold":n.type==="channel","tw-font-medium":n.type==="group"}]}
1),$(((nt=n.lead_total)==null?void 0:nt.toLocaleString())||0),17)]}),default:a(()=>[w(rt,{density:"compact","max-width":"250",elevation:"2",class:"total-row-tooltip-card"},{default:a(()=>[w(it,{class:"tw-py-2 tw-px-3"},{default:a(()=>[t("div",ka,$(v.value),1)]),_:1})]),_:1})]),_:2},1024)):(l(),u("div",{key:1,class:lt(["tw-text-center tw-text-sm tw-cursor-pointer hover:tw-bg-gray-100 tw-transition-colors clickable-cell",{"tw-font-bold":n.type==="total","tw-font-semibold":n.type==="channel","tw-font-medium":n.type==="group"}]),onClick:at=>E("lead_total",n)},$(((h=n.lead_total)==null?void 0:h.toLocaleString())||0),11,Ca))]}),"item.close_rate":a(({item:n})=>[n.type==="total"&&!R.value?(l(),ot(vt,{key:0,"open-on-hover":!0,location:"top","close-delay":200,offset:8},{activator:a(({props:h})=>[t("div",ht(h,{class:["tw-text-center tw-text-sm tw-cursor-not-allowed clickable-cell",{"tw-font-bold":n.type==="total","tw-font-semibold":n.type==="channel","tw-font-medium":n.type==="group"}]}),$(n.close_rate)+"% ",17)]),default:a(()=>[w(rt,{density:"compact","max-width":"250",elevation:"2",class:"total-row-tooltip-card"},{default:a(()=>[w(it,{class:"tw-py-2 tw-px-3"},{default:a(()=>[t("div",$a,$(v.value),1)]),_:1})]),_:1})]),_:2},1024)):(l(),u("div",{key:1,class:lt(["tw-text-center tw-text-sm tw-cursor-pointer hover:tw-bg-gray-100 tw-transition-colors clickable-cell",{"tw-font-bold":n.type==="total","tw-font-semibold":n.type==="channel","tw-font-medium":n.type==="group"}]),onClick:h=>E("close_rate",n)},$(n.close_rate)+"% ",11,Sa))]),_:2},[_t(c.value,n=>({name:`item.${n}`,fn:a(({item:h})=>{var at;return[h.type==="total"&&!R.value?(l(),ot(vt,{key:0,"open-on-hover":!0,location:"top","close-delay":200,offset:8},{activator:a(({props:nt})=>{var K;return[t("div",ht(nt,{class:["tw-text-center tw-text-sm tw-cursor-not-allowed clickable-cell",{"tw-font-bold":h.type==="total","tw-font-semibold":h.type==="channel","tw-font-medium":h.type==="group"}]}),$(((K=h[n])==null?void 0:K.toLocaleString())||0),17)]}),default:a(()=>[w(rt,{density:"compact","max-width":"250",elevation:"2",class:"total-row-tooltip-card"},{default:a(()=>[w(it,{class:"tw-py-2 tw-px-3"},{default:a(()=>[t("div",xa,$(v.value),1)]),_:1})]),_:1})]),_:2},1024)):(l(),u("div",{key:1,class:lt(["tw-text-center tw-text-sm tw-cursor-pointer hover:tw-bg-gray-100 tw-transition-colors clickable-cell",{"tw-font-bold":h.type==="total","tw-font-semibold":h.type==="channel","tw-font-medium":h.type==="group"}]),onClick:nt=>E(n,h)},$(((at=h[n])==null?void 0:at.toLocaleString())||0),11,ba))]})}))]),1032,["headers","items","loading"])])):(l(),u("div",pa,[w(W,{icon:"mdi-source-branch",size:"48",color:"grey-lighten-2",class:"tw-mb-3"}),x[5]||(x[5]=t("p",{class:"tw-text-sm tw-font-medium tw-text-gray-700 tw-mb-1"}," No data available ",-1)),x[6]||(x[6]=t("p",{class:"tw-text-xs tw-text-gray-500"}," There are no leads for the selected time period. ",-1))])),!o(k)&&o(C).length>0?(l(),u("div",Ra,[t("a",{href:"#",onClick:x[0]||(x[0]=Tt(n=>S.value=!S.value,["prevent"])),class:"tw-inline-flex tw-items-center tw-gap-1.5 tw-text-sm tw-text-gray-700 hover:tw-text-gray-900 tw-font-medium tw-transition-colors tw-duration-150","data-testid":"how-to-read-report-link"},[w(W,{size:"16",color:"#32ba8f"},{default:a(()=>[M($(S.value?"mdi-chevron-up":"mdi-chevron-down"),1)]),_:1}),x[7]||(x[7]=t("span",null,"How to read this report",-1))]),w(Vt,null,{default:a(()=>[Bt(t("div",La,[w(rt,{elevation:"0",class:"tw-border tw-border-gray-200"},{default:a(()=>[w(it,{class:"tw-p-6"},{default:a(()=>[x[20]||(x[20]=t("h3",{class:"tw-text-base tw-font-semibold tw-text-gray-900 tw-mb-5 tw-pb-3 tw-border-b tw-border-gray-200"}," Understanding Your Report Columns ",-1)),t("div",Pa,[x[16]||(x[16]=t("div",null,[t("div",{class:"tw-font-semibold tw-text-gray-900 tw-text-sm tw-mb-1"}," Channel / Group / Source "),t("div",{class:"tw-text-sm tw-text-gray-600"}," Hierarchical view showing your lead channels, groups within each channel, and individual sources within each group. Click the chevron icons to expand or collapse each level. ")],-1)),t("div",null,[x[11]||(x[11]=t("div",{class:"tw-font-semibold tw-text-gray-900 tw-text-sm tw-mb-1"}," Status Columns ",-1)),t("div",Ta,[x[10]||(x[10]=t("div",null,[M(" Shows the count of leads by the "),t("strong",null,"furthest status"),M(' they reached during the selected time period. For example, if a lead progressed from "New Lead" to "Contacted" to "Greet", it would be counted in the "Greet" column. ')],-1)),t("div",Ea,[w(W,{size:"18",color:"#32ba8f",class:"tw-mt-0.5"},{default:a(()=>x[8]||(x[8]=[M(" mdi-lightbulb-outline ")])),_:1}),x[9]||(x[9]=t("div",{class:"tw-text-xs"},[t("strong",null,"Tip:"),M(" Column headers show abbreviated names (first and last letter). Hover over any header to see the full status name. ")],-1))])])]),x[17]||(x[17]=t("div",null,[t("div",{class:"tw-font-semibold tw-text-gray-900 tw-text-sm tw-mb-1"}," Lead Total "),t("div",{class:"tw-text-sm tw-text-gray-600"}," Total number of leads that had at least one status update during the selected time period. This doesn't include leads that exist in the system but had no activity during the selected dates. ")],-1)),t("div",null,[x[15]||(x[15]=t("div",{class:"tw-font-semibold tw-text-gray-900 tw-text-sm tw-mb-1"}," Close Rate ",-1)),t("div",Aa,[x[14]||(x[14]=t("div",null,[M(" Percentage of leads whose "),t("strong",null,"current status"),M(' is "Sold". This is calculated as: (Currently Sold Leads ÷ Lead Total) à 100 ')],-1)),t("div",Da,[w(W,{size:"18",color:"#32ba8f",class:"tw-mt-0.5"},{default:a(()=>
1x[12]||(x[12]=[M(" mdi-alert-circle-outline ")])),_:1}),x[13]||(x[13]=t("div",{class:"tw-text-xs"},[t("strong",null,"Important:"),M(" Close Rate is based on the lead's "),t("em",null,"latest"),M(` status (where they are now), not their furthest progression. A lead could have reached "Sold" status earlier but won't count in Close Rate if their current status changed to something else. `)],-1))])])])]),t("div",Ia,[w(W,{size:"16",color:"#32ba8f",class:"tw-mt-0.5"},{default:a(()=>x[18]||(x[18]=[M(" mdi-information-outline ")])),_:1}),x[19]||(x[19]=t("div",{class:"tw-text-sm tw-text-gray-600"}," All data reflects the time period selected in the filter above. ",-1))])]),_:1})]),_:1})],512),[[Gt,S.value]])]),_:1})])):Z("",!0),o(T)?(l(),ot(Xt,{key:6,visible:o(T),title:o(m),leads:o(J),"total-leads":o(Y),"total-pages":o(Q),"current-page":o(wt),"items-per-page":o(gt),"is-loading":o(ft),"is-fetching":o(pt),error:o(bt),"onUpdate:visible":x[1]||(x[1]=n=>T.value=n),onClose:o(kt),onPageChange:o(dt),onItemsPerPageChange:o(Ct)}
1,null,8,["visible","title","leads","total-leads","total-pages","current-page","items-per-page","is-loading","is-fetching","error","onClose","onPageChange","onItemsPerPageChange"])):Z("",!0)]))}}),Ma=St(Fa,[["__scopeId","data-v-e6e2699f"]]);function Oa(){const I=Rt(),S=xt(),{dateFilter:R}=Pt(S),{data:v,isLoading:d,isFetching:b,error:C,refetch:P}=$t({queryKey:["leadStatusBySalespersonReport",R],queryFn:async()=>await I.fetchLeadStatusBySalespersonReport(R.value),staleTime:It.REALTIME,refetchOnWindowFocus:!0,refetchOnMount:!0,retry:1}),k=A(()=>{var e;return((e=v.value)==null?void 0:e.statuses)||[]}),g=A(()=>{var e;return((e=v.value)==null?void 0:e.data)||[]}),U=A(()=>{if(!g.value.length)return null;const e={new_lead:0,contacted:0,greet:0,probe:0,sit_on:0,presented_demo:0,sit_down:0,write_up:0,close:0,f_and_i:0,sold:0,lost:0,lead_total:0};g.value.forEach(L=>{e.new_lead+=L.new_lead,e.contacted+=L.contacted,e.greet+=L.greet,e.probe+=L.probe,e.sit_on+=L.sit_on,e.presented_demo+=L.presented_demo,e.sit_down+=L.sit_down,e.write_up+=L.write_up,e.close+=L.close,e.f_and_i+=L.f_and_i,e.sold+=L.sold,e.lost+=L.lost,e.lead_total+=L.lead_total});
1const y=e.lead_total?Math.round(e.sold/e.lead_total*100):0;return{user_id:0,name:"Total",email:"",...e,close_rate:y}});return{statuses:k,reportData:g,totalsRow:U,isLoading:d,isFetching:b,error:C,refresh:()=>P()}}function za(){return{downloadExcel:(S,R,v)=>{const d=o(S),b=o(R),C=o(v);if(!(C!=null&&C.length)||!(d!=null&&d.length))return;const P=new Set(["close_rate"]),k=C.map(F=>F.title),g=[];if(d.forEach(F=>{const N=C.map(V=>{const c=F[V.key];return P.has(V.key)&&typeof c=="number"?c/100:typeof c=="number"?c:c||""});g.push(N)}),b){const F=C.map(N=>{const V=b[N.key];return P.has(N.key)&&typeof V=="number"?V/100:typeof V=="number"?V:V||""});g.push(F)}const U=[k,...g],s=st.aoa_to_sheet(U);s["!freeze"]={xSplit:0,ySplit:1};const e=st.decode_range(s["!ref"]);s["!autofilter"]={ref:st.encode_range(e)},s["!cols"]=C.map(F=>({wch:Math.ceil(F.width/8)}));const y=C.map((F,N)=>P.has(F.key)?N:-1).filter(F=>F>=0);for(let F=1;F<=e.e.r;F++)for(const N of y){const V=st.encode_cell({r:F,c:N}),c=s[V];c&&typeof c.v=="number"&&(c.t="n",c.z="0%")}const L=st.book_new();st.book_append_sheet(L,s,"Lead Status by Salesperson");const G=`Lead_Status_by_Salesperson_Report_${new Date().toISOString().slice(0,10)}.xlsx`;qt(L,G)}}}const Ua={class:"tw-flex tw-flex-col tw-space-y-4","data-testid":"lead-status-by-salesperson-report-container"},Na={key:0,class:"tw-p-8","data-testid":"lead-status-by-salesperson-report-loading"},Va={class:"tw-flex tw-flex-col tw-items-center tw-justify-center"},Ba={key:1,class:"tw-p-8 tw-text-center","data-testid":"lead-status-by-salesperson-report-error"},Ga={class:"tw-text-sm tw-text-gray-500 tw-mb-4"},qa={key:2,class:"tw-flex tw-flex-col tw-items-center tw-justify-center tw-rounded-lg tw-border tw-border-gray-200 tw-bg-gray-50 tw-p-10 tw-text-center","data-testid":"lead-status-by-salesperson-report-empty"},Ha={key:3,class:"tw-flex tw-justify-end"},ja={key:4,class:"tw-relative tw-overflow-x-auto","data-testid":"lead-status-by-salesperson-report-table-wrapper"},Wa={class:"custom-header-row"},Ya={class:"tw-font-semibold tw-text-sm tw-text-white"},Qa={key:1},Ka=["data-testid"],Xa={class:"tw-text-sm tw-text-white"},Za=["onClick"],Ja={class:"tw-text-sm tw-text-white"},tl=["onClick"],el={class:"tw-text-sm tw-text-white"},sl=["onClick"],ol={key:5,class:"tw-mt-6"},al={class:"tw-mt-3","data-testid":"how-to-read-report-content"},ll={class:"tw-space-y-5"},nl={class:"tw-text-sm tw-text-gray-600 tw-space-y-2"},rl={class:"tw-flex tw-items-start tw-gap-2 tw-mt-2 tw-p-3 tw-rounded-md tw-border tw-text-sm",style:{"background-color":"rgba(50, 186, 143, 0.12)","border-color":"#32ba8f",color:"#157657"}},il={class:"tw-text-sm tw-text-gray-600 tw-space-y-2"},dl={class:"tw-flex tw-items-start tw-gap-2 tw-mt-2 tw-p-3 tw-rounded-md tw-border tw-text-sm",style:{"background-color":"rgba(50, 186, 143, 0.12)","border-color":"#32ba8f",color:"#157657"}},cl={class:"tw-mt-6 tw-pt-4 tw-border-t tw-border-gray-200 tw-flex tw-items-start tw-gap-2"},ul=yt({__name:"LeadStatusBySalespersonReport",setup(I){const S=H(!1),R=H(Qt),v=H(Kt),{statuses:d,reportData:b,totalsRow:C,isLoading:P,isFetching:k,error:g,refresh:U}=Oa(),{STATUS_ORDER_TO_FIELD_KEY:s,getShortName:e}=me(),y=s,L=A(()=>{const tt=[{title:"Salesperson",key:"name",sortable:!1,align:"start",width:220}];return d.value.forEach(E=>{const z=y[E.order];z&&tt.push({title:E.name,shortName:e(E.name),key:z,sortable:!1,align:"center",width:60})}),tt.push({title:"Lead Total",key:"lead_total",sortable:!1,align:"center",width:100},{title:"Close Rate",key:"close_rate",sortable:!1,align:"center",width:120}),tt}),G=A(()=>d.value.map(tt=>y[tt.order]).filter(Boolean)),F=A(()=>C.value?[...b.value,C.value]:b.value),N=A(()=>P.value&&b.value.length===0),V=A(()=>!!g.value),c=A(()=>g.value?typeof g.value=="string"?g.value:g.value instanceof Error?g.value.message:"An unexpected error occurred.":""),{downloadExcel:B}=za(),j=()=>{B(b,C,L)},{isModalOpen:i,modalTitle:p,leads:D,totalLeads:r,totalPages:T,currentPage:m,itemsPerPage:J,isLoading:Y,isFetching:Q,error:wt,openDrilldown:gt,closeDrilldown:ft,handlePageChange:pt,handleItemsPerPageChange:bt}=Yt(),ct=xt(),kt=A(()=>{const tt={};return d.value.forEach(E=>{const z=y[E.order];
1z&&(tt[z]=E.id)}),tt}),dt=(tt,E)=>{var _,f;if(E.user_id===0&&!R.value)return;const z={report_type:"lead_status_by_salesperson",filter_level:E.user_id===0?"total":"salesperson",filter_type:Ct(tt),...Wt(ct.dateFilter)};(_=ct.dateFilter.user_ids)!=null&&_.length&&(z.user_ids=ct.dateFilter.user_ids),(f=ct.dateFilter.role_ids)!=null&&f.length&&(z.role_ids=ct.dateFilter.role_ids),E.user_id!==0&&(z.salesperson_id=E.user_id),tt!=="lead_total"&&tt!=="close_rate"&&(z.status_id=kt.value[tt]);const O=`${E.name} - ${ut(tt)}`;gt(z,O)},Ct=tt=>tt==="lead_total"?"lead_total":tt==="close_rate"?"close_rate":"status_latest",ut=tt=>{const E=L.value.find(z=>z.key===tt);return(E==null?void 0:E.title)||tt};return(tt,E)=>(l(),u("div",Ua,[N.value?(l(),u("div",Na,[t("div",Va,[w(At,{indeterminate:"",color:"primary",size:40,width:4}),E[2]||(E[2]=t("p",{class:"tw-mt-4 tw-text-gray-600"}," Loading lead status by salesperson report... ",-1))])])):V.value?(l(),u("div",Ba,[w(W,{icon:"mdi-alert-circle-outline",size:"large",color:"error",class:"tw-mb-4"}),E[4]||(E[4]=t("p",{class:"tw-text-gray-700 tw-mb-2"}," Failed to load lead status by salesperson report ",-1)),t("p",Ga,$(c.value),1),w(zt,{color:"primary",size:"small",onClick:o(U),"data-testid":"lead-status-by-salesperson-report-retry-btn"},{default:a(()=>E[3]||(E[3]=[M(" Try Again ")])),_:1},8,["onClick"])])):o(b).length?Z("",!0):(l(),u("div",qa,[w(W,{icon:"mdi-account-tie-outline",size:"48",color:"grey-lighten-2",class:"tw-mb-3"}),E[5]||(E[5]=t("p",{class:"tw-text-sm tw-font-medium tw-text-gray-700 tw-mb-1"}," No salesperson lead status found ",-1)),E[6]||(E[6]=t("p",{class:"tw-text-xs tw-text-gray-500"}," Try a different time period or invite salesperson to Transax. ",-1))])),!N.value&&o(b).length>0?(l(),u("div",Ha,[w(Ht,{onDownload:j})])):Z("",!0),!N.value&&!V.value&&o(b).length>0?(l(),u("div",ja,[w(Dt,{headers:L.value,items:F.value,loading:o(P)&&!o(b).length,class:"elevation-0 lead-status-by-salesperson-report-table","item-key":"user_id","items-per-page":-1,"hide-default-footer":"",density:"compact","data-testid":"lead-status-by-salesperson-report-table"},Ut({headers:a(()=>[t("tr",Wa,[(l(!0),u(Et,null,_t(L.value,z=>(l(),u("th",{key:z.key,style:Nt({width:z.width+"px"}),class:lt(["custom-header-cell",z.align==="center"?"text-center":"text-start"])},[z.shortName?(l(),ot(vt,{key:0,"open-on-hover":!0,location:"top","close-delay":200,offset:8},{activator:a(({props:O})=>[t("span",ht({ref_for:!0},O,{class:"tw-cursor-help"}),$(z.shortName),17)]),default:a(()=>[w(rt,{density:"compact","max-width":"200",elevation:"2",class:"status-tooltip-card"},{default:a(()=>[w(it,{class:"tw-py-2 tw-px-3"},{default:a(()=>[t("div",Ya,$(z.title),1)]),_:2},1024)]),_:2},1024)]),_:2},1024)):(l(),u("span",Qa,$(z.title),1))],6))),128))])]),"item.name":a(({item:z})=>[t("div",{class:lt(["tw-flex tw-items-center tw-text-sm tw-text-gray-900",{"tw-font-bold":z.user_id===0,"tw-font-medium":z.user_id!==0}]),"data-testid":`salesperson-name-${z.user_id}`},$(z.name),11,Ka)]),"item.lead_total":a(({item:z})=>[z.user_id===0&&!R.value?(l(),ot(vt,{key:0,"open-on-hover":!0,location:"top","close-delay":200,offset:8},{activator:a(({props:O})=>[t("div",ht(O,{class:["tw-text-center tw-text-sm tw-text-gray-900 tw-cursor-not-allowed clickable-cell",{"tw-font-bold":z.user_id===0}]}),$(o(Mt)(z.lead_total)),17)]),default:a(()=>[w(rt,{density:"compact","max-width":"250",elevation:"2",class:"total-row-tooltip-card"},{default:a(()=>[w(it,{class:"tw-py-2 tw-px-3"},{default:a(()=>[t("div",Ja,$(v.value),1)]),_:1})]),_:1})]),_:2},1024)):(l(),u("div",{key:1,class:lt(["tw-text-center tw-text-sm tw-text-gray-900 tw-cursor-pointer hover:tw-bg-gray-100 tw-transition-colors clickable-cell",{"tw-font-bold":z.user_id===0}]),onClick:O=>dt("lead_total",z)},$(o(Mt)(z.lead_total)),11,tl))]),"item.close_rate":a(({item:z})=>[z.user_id===0&&!R.value?(l(),ot(vt,{key:0,"open-on-hover":!0,location:"top","close-delay":200,offset:8},{activator:a(({props:O})=>[t("div",ht(O,{class:["tw-text-center tw-text-sm tw-text-gray-900 tw-cursor-not-allowed clickable-cell",{"tw-font-bold":z.user_id===0}]}),$(z.close_rate)+"% ",17)]),default:a(()=>[w(rt,{density:"compact","max-width":"250",elevation:"2",class:"total-row-tooltip-card"},{default:a(()=>[w(it,{class:"tw-py-2 tw-px-3"},{default:a(()=>[t("div",el,$(v.value),1)]),_:1})]),_:1})]),_:2},1024)):(l(),u("div",{key:1,class:lt(["tw-text-center tw-text-sm tw-text-gray-900 tw-cursor-pointer hover:tw-bg-gray-100 tw-transition-colors clickable-cell",{"tw-font-bold":z.user_id===0}]),onClick:O=>dt("close_rate",z)},$(z.close_rate)+"% ",11,sl))]),bottom:a(()=>[]),_:2},[_t(G.value,z=>({name:`item.${z}`,fn:a(({item:O})=>[O.user_id===0&&!R.value?(l(),ot(vt,{key:0,"open-on-hover":!0,location:"top","close-delay":200,offset:8},{activator:a(({props:_})=>[t("div",ht(_,{class:["tw-text-center tw-text-sm tw-text-gray-900 tw-cursor-not-allowed clickable-cell",{"tw-font-bold":O.user_id===0}]}),$(o(Mt)(O[z])),17)]),default:a(()=>[w(rt,{density:"compact","max-width":"250",elevation:"2",class:"total-row-tooltip-card"},{default:a(()=>[w(it,{class:"tw-py-2 tw-px-3"},{default:a(()=>[t("div",Xa,$(v.value),1)]),_:1})]),_:1})]),_:2},1024)):(l(),u("div",{key:1,class:lt(["tw-text-center tw-text-sm tw-text-gray-900 tw-cursor-pointer hover:tw-bg-gray-100 tw-transition-colors clickable-cell",{"tw-font-bold":O.user_id===0}]),onClick:_=>dt(z,O)},$(o(Mt)(O[z])),11,Za))])}))]),1032,["headers","items","loading"]),o(k)&&o(b).length?(l(),ot(te,{key:0,indeterminate:"",color:"primary",class:"tw-absolute tw-left-0 tw-right-0 tw-top-0",height:"3"})):Z("",!0)])):Z("",!0),!N.value&&!V.value&&o(b).length>0?(l(),u("div",ol,[t("a",{href:"#",onClick:E[0]||(E[0]=Tt(z=>S.value=!S.value,["prevent"])),class:"tw-inline-flex tw-items-center tw-gap-1.5 tw-text-sm tw-text-gray-700 hover:tw-text-gray-900 tw-font-medium tw-transition-colors tw-duration-150","data-testid":"how-to-read-report-link"},[w(W,{size:"16",color:"#32ba8f"},{default:a(()=>[M($(S.value?"mdi-chevron-up":"mdi-chevron-down"),1)]),_:1}),E[7]||(E[7]=t("span",null,"How to read this report",-1))]),w(Vt,null,{default:a(()=>[Bt(t("div",al,[w(rt,{elevation:"0",class:"tw-border tw-border-gray-200"},{default:a(()=>[w(it,{class:"tw-p-6"},{default:a(()=>[E[20]||(E[20]=t("h3",{class:"tw-text-base tw-font-semibold tw-text-gray-900 tw-mb-5 tw-pb-3 tw-border-b tw-border-gray-200"}," Understanding Your Report Columns ",-1)),t("div",ll,[E[16]||(E[16]=t("div",null,[t("div",{class:"tw-font-semibold tw-text-gray-900 tw-text-sm tw-mb-1"}," Salesperson "),t("div",{class:"tw-text-sm tw-text-gray-600"}," Lists all active salespeople. Salespeople appear in this report even if they have no leads during the selected time period. ")],-1)),t("div",null,[E[11]||(E[11]=t("div",{class:"tw-font-semibold tw-text-gray-900 tw-text-sm tw-mb-1"}," Status Columns ",-1)),t("div",nl,[E[10]||(E[10]=t("div",null,[M(" Shows the count of leads by the "),t("strong",null,"furthest status"),M(' they reached during the selected time period. For example, if a lead progressed from "New Lead" to "Contacted" to "Greet", it would be counted in the "Greet" column. ')],-1)),t("div",rl,[w(W,{size:"18",color:"#32ba8f",class:"tw-mt-0.5"},{default:a(()=>E[8]||(E[8]=[M(" mdi-lightbulb-outline ")])),_:1}),E[9]||(E[9]=t("div",{class:"tw-text-xs"},[t("strong",null,"Tip:"),M(" Column headers show abbreviated names (first and last letter). Hover over any header to see the full status name. ")],-1))])])]),E[17]||(E[17]=t("div",null,[t("div",{class:"tw-font-semibold tw-text-gray-900 tw-text-sm tw-mb-1"}," Lead Total "),t("div",{class:"tw-text-sm tw-text-gray-600"}," Total number of leads that had at least one status update during the selected time period. This doesn't include leads that exist in the system but had no activity during the selected dates. ")],-1)),t("div",null,[E[15]||(E[15]=t("div",{class:"tw-font-semibold tw-text-gray-900 tw-text-sm tw-mb-1"}," Close Rate ",-1)),t("div",il,[E[14]||(E[14]=t("div",null,[M(" Percentage of leads whose "),t("strong",null,"current status"),M(' is "Sold". This is calculated as: (Currently Sold Leads ÷ Lead Total) à 100 ')],-1)),t("div",dl,[w(W,{size:"18",color:"#32ba8f",class:"tw-mt-0.5"},{default:a(()=>E[12]||(E[12]=[M(" mdi-alert-circle-outline ")])),_:1}),E[13]||(E[13]=t("div",{class:"tw-text-xs"},[t("strong",null,"Important:"),M(" Close Rate is based on the lead's "),t("em",null,"latest"),M(` status (where they are now), not their furthest progression. A lead could have reached "Sold" status earlier but won't count in Close Rate if their current status changed to something else. `)],-1))])])])]),t("div",cl,[w(W,{size:"16",color:"#32ba8f",class:"tw-mt-0.5"},{default:a(()=>E[18]||(E[18]=[M(" mdi-information-outline ")])),_:1}),E[19]||(E[19]=t("div",{class:"tw-text-sm tw-text-gray-600"}," All data reflects the time period selected in the filter above. ",-1))])]),_:1})]),_:1})],512),[[Gt,S.value]])]),_:1})])):Z("",!0),o(i)?(l(),ot(Xt,{key:6,visible:o(i),title:o(p),leads:o(D),"total-leads":o(r),"total-pages":o(T),"current-page":o(m),"items-per-page":o(J),"is-loading":o(Y),"is-fetching":
1o(Q),error:o(wt),"onUpdate:visible":E[1]||(E[1]=z=>i.value=z),onClose:o(ft),onPageChange:o(pt),onItemsPerPageChange:o(bt)},null,8,["visible","title","leads","total-leads","total-pages","current-page","items-per-page","is-loading","is-fetching","error","onClose","onPageChange","onItemsPerPageChange"])):Z("",!0)]))}}),wl=St(ul,[["__scopeId","data-v-c87813da"]]);function pl(I){const S=Rt(),R=xt(),{dateFilter:v}=Pt(R),{data:d,isLoading:b,isFetching:C,error:P,refetch:k}=$t({queryKey:["appointmentStatisticsReport",v,I.salespersonId,I.leadSourceId],queryFn:async()=>await S.fetchAppointmentStatisticsReport({...v.value,salesperson_id:I.salespersonId.value??void 0,lead_source_id:I.leadSourceId.value??void 0}),staleTime:It.REALTIME,refetchOnWindowFocus:!0,refetchOnMount:!0,retry:1}),g=A(()=>d.value||[]),U=A(()=>{if(!g.value.length)return null;const e=g.value.reduce((L,G)=>({pending:L.pending+G.pending,confirmed:L.confirmed+G.confirmed,kept:L.kept+G.kept,no_show:L.no_show+G.no_show,total_appointments:L.total_appointments+G.total_appointments}),{pending:0,confirmed:0,kept:0,no_show:0,total_appointments:0}),y=e.total_appointments;return{id:0,name:"Total",location:"",...e,show_rate:y>0?Number((e.kept/y*100).toFixed(2)):0}});return{reportData:g,totalsRow:U,isLoading:b,isFetching:C,error:P,refresh:()=>k()}}function ml(){return{downloadExcel:(S,R,v)=>{const d=o(S),b=o(R),C=o(v);if(!(C!=null&&C.length)||!(d!=null&&d.length))return;const P=new Set(["show_rate"]),k=C.map(F=>F.title),g=[];if(d.forEach(F=>{const N=C.map(V=>{const c=F[V.key];return P.has(V.key)?typeof c=="number"?c/100:0:typeof c=="number"?c:c||""});g.push(N)}),b){const F=C.map(N=>{const V=b[N.key];return P.has(N.key)?typeof V=="number"?V/100:0:typeof V=="number"?V:V||""});g.push(F)}const U=[k,...g],s=st.aoa_to_sheet(U);s["!freeze"]={xSplit:0,ySplit:1};const e=st.decode_range(s["!ref"]);s["!autofilter"]={ref:st.encode_range(e)},s["!cols"]=C.map(F=>({wch:Math.ceil(F.width/8)}));const y=C.map((F,N)=>P.has(F.key)?N:-1).filter(F=>F>=0);for(let F=1;F<=e.e.r;F++)for(const N of y){const V=st.encode_cell({r:F,c:N}),c=s[V];c&&typeof c.v=="number"&&(c.t="n",c.z="0.00%")}const L=st.book_new();st.book_append_sheet(L,s,"Appointment Statistics");const G=`Appointment_Statistics_Report_${new Date().toISOString().slice(0,10)}.xlsx`;qt(L,G)}}}function _l(){const I=Rt(),{data:S,isLoading:R,isFetching:v,error:d,refetch:b}=$t({queryKey:["appointmentStatisticsSalespeople"],queryFn:async()=>await I.fetchAppointmentStatisticsSalespeople(),staleTime:It.REALTIME,refetchOnWindowFocus:!1,refetchOnMount:!0,retry:1});return{salespeople:A(()=>S.value||[]),isLoading:R,isFetching:v,error:d,refetch:b}}const gl={class:"tw-flex tw-flex-col tw-space-y-4","data-testid":"appointment-statistics-report-container"},fl={class:"tw-flex tw-flex-wrap tw-items-end tw-gap-4","data-testid":"appointment-statistics-report-filters"},hl={class:"tw-w-full sm:tw-w-64"},vl={class:"tw-w-full sm:tw-w-64"},yl={key:0,class:"tw-p-8","data-testid":"appointment-statistics-report-loading"},xl={class:"tw-flex tw-flex-col tw-items-center tw-justify-center"},bl={key:1,class:"tw-p-8 tw-text-center","data-testid":"appointment-statistics-report-error"},kl={class:"tw-text-sm tw-text-gray-500 tw-mb-4"},Cl={key:2,class:"tw-flex tw-flex-col tw-items-center tw-justify-center tw-rounded-lg tw-border tw-border-gray-200 tw-bg-gray-50 tw-p-10 tw-text-center","data-testid":"appointment-statistics-report-empty"},$l={class:"tw-flex tw-justify-end"},Sl={class:"tw-relative tw-overflow-x-auto","data-testid":"appointment-statistics-report-table-wrapper"},Rl={class:"custom-header-row"},Ll=["data-testid"],Pl={class:"tw-text-center tw-text-sm tw-text-gray-900 numeric-cell"},Tl={class:"tw-text-center tw-text-sm tw-text-gray-900 numeric-cell"},El={class:"tw-mt-6"},Al={class:"tw-mt-3","data-testid":"appointment-statistics-how-to-read-content"},Dl={class:"tw-mt-6 tw-pt-4 tw-border-t tw-border-gray-200 tw-flex tw-items-start tw-gap-2"},Il=yt({__name:"AppointmentStatisticsReport",setup(I){const S=[{key:"name",title:"Salesperson",align:"start",width:220},{key:"total_appointments",title:"Total Appointments",align:"center",width:150},{key:"pending",title:"Pending",align:"center",width:100},{key:"confirmed",title:"Confirmed",align:"center",width:110},{key:"kept",title:"Kept",align:"center",width:100},{key:"no_show",title:"No Show",align:"center",width:110},{key:"show_rate",title:"Show Rate",align:"center",width:110}],R=A(()=>S.map(T=>({title:T.title,key:T.key,sortable:!1,align:T.align,width:T.width}
1))),v=["total_appointments","pending","confirmed","kept","no_show"],d=H(null),b=H(null),{salespeople:C}=_l(),P=A(()=>[{text:"All Salespeople",value:null},...C.value.map(T=>({text:T.name||`User #${T.id}`,value:T.id}))]),{leadSources:k,isLoading:g}=Te(),U=A(()=>[{text:"All Sources",value:null},...k.value.map(T=>({text:T.name,value:T.id}))]),{reportData:s,totalsRow:e,isLoading:y,isFetching:L,error:G,refresh:F}=pl({salespersonId:d,leadSourceId:b}),N=A(()=>e.value?[...s.value,e.value]:s.value),V=A(()=>y.value&&s.value.length===0),c=A(()=>!!G.value),B=A(()=>G.value?typeof G.value=="string"?G.value:G.value instanceof Error?G.value.message:"An unexpected error occurred.":""),j=(T,m)=>Mt(T[m]),i=T=>`${T.toFixed(2)}%`,{downloadExcel:p}=ml(),D=()=>{p(s,e,R)},r=H(!1);return(T,m)=>{const J=Pe,Y=pe;return l(),u("div",gl,[t("div",fl,[t("div",hl,[w(J,{modelValue:d.value,"onUpdate:modelValue":m[0]||(m[0]=Q=>d.value=Q),items:P.value,"item-title":"text","item-value":"value",label:"Salesperson",placeholder:"All Salespeople",variant:"outlined",density:"comfortable",clearable:"","hide-details":"","data-testid":"appointment-statistics-salesperson-filter"},null,8,["modelValue","items"])]),t("div",vl,[w(Y,{modelValue:b.value,"onUpdate:modelValue":m[1]||(m[1]=Q=>b.value=Q),items:U.value,"item-title":"text","item-value":"value",label:"Lead Source",variant:"outlined",density:"comfortable","hide-details":"",loading:o(g),"data-testid":"appointment-statistics-lead-source-filter"},null,8,["modelValue","items","loading"])])]),V.value?(l(),u("div",yl,[t("div",xl,[w(At,{indeterminate:"",color:"primary",size:40,width:4}),m[3]||(m[3]=t("p",{class:"tw-mt-4 tw-text-gray-600"}," Loading appointment statistics report... ",-1))])])):c.value?(l(),u("div",bl,[w(W,{icon:"mdi-alert-circle-outline",size:"large",color:"error",class:"tw-mb-4"}),m[5]||(m[5]=t("p",{class:"tw-text-gray-700 tw-mb-2"}," Failed to load appointment statistics report ",-1)),t("p",kl,$(B.value),1),w(zt,{color:"primary",size:"small",onClick:o(F),"data-testid":"appointment-statistics-report-retry-btn"},{default:a(()=>m[4]||(m[4]=[M(" Try Again ")])),_:1},8,["onClick"])])):o(s).length?(l(),u(Et,{key:3},[t("div",$l,[w(Ht,{onDownload:D})]),t("div",Sl,[w(Dt,{headers:R.value,items:N.value,loading:o(y)&&!o(s).length,class:"elevation-0 appointment-statistics-report-table","item-key":"id","items-per-page":-1,"hide-default-footer":"",density:"compact","data-testid":"appointment-statistics-report-table"},Ut({headers:a(()=>[t("tr",Rl,[(l(!0),u(Et,null,_t(R.value,Q=>(l(),u("th",{key:Q.key,style:Nt({width:Q.width+"px"}),class:lt(["custom-header-cell",Q.align==="center"?"text-center":"text-start"])},$(Q.title),7))),128))])]),"item.name":a(({item:Q})=>[t("div",{class:lt(["tw-flex tw-items-center tw-text-sm tw-text-gray-900",{"tw-font-bold":Q.id===0,"tw-font-medium":Q.id!==0}]),"data-testid":`appointment-statistics-salesperson-name-${Q.id}`},$(Q.name),11,Ll)]),"item.show_rate":a(({item:Q})=>[t("div",Tl,$(i(Q.show_rate)),1)]),bottom:a(()=>[]),_:2},[_t(v,Q=>({name:`item.${Q}`,fn:a(({item:wt})=>[t("div",Pl,$(j(wt,Q)),1)])}))]),1032,["headers","items","loading"]),o(L)&&o(s).length?(l(),ot(te,{key:0,indeterminate:"",color:"primary",class:"tw-absolute tw-left-0 tw-right-0 tw-top-0",height:"3"})):Z("",!0)]),t("div",El,[t("a",{href:"#",onClick:m[2]||(m[2]=Tt(Q=>r.value=!r.value,["prevent"])),class:"tw-inline-flex tw-items-center tw-gap-1.5 tw-text-sm tw-text-gray-700 hover:tw-text-gray-900 tw-font-medium tw-transition-colors tw-duration-150","data-testid":"appointment-statistics-how-to-read-link"},[w(W,{size:"16",color:"#32ba8f"},{default:a(()=>[M($(r.value?"mdi-chevron-up":"mdi-chevron-down"),1)]),_:1}),m[8]||(m[8]=t("span",null,"How to read this report",-1))]),w(Vt,null,{default:a(()=>[Bt(t("div",Al,[w(rt,{elevation:"0",class:"tw-border tw-border-gray-200"},{default:a(()=>[w(it,{class:"tw-p-6"},{default:a(()=>[m[11]||(m[11]=t("h3",{class:"tw-text-base tw-font-semibold tw-text-gray-900 tw-mb-5 tw-pb-3 tw-border-b tw-border-gray-200"}," Understanding Your Report Columns ",-1)),m[12]||(m[12]=t("div",{class:"tw-grid tw-gri
1d-cols-1 md:tw-grid-cols-2 tw-gap-x-8 tw-gap-y-4"},[t("div",{class:"tw-space-y-4"},[t("div",null,[t("div",{class:"tw-font-semibold tw-text-gray-900 tw-text-sm tw-mb-1"}," Salesperson "),t("div",{class:"tw-text-sm tw-text-gray-600"}," Lists all active salespeople assigned to appointments. ")]),t("div",null,[t("div",{class:"tw-font-semibold tw-text-gray-900 tw-text-sm tw-mb-1"}," Total Appointments "),t("div",{class:"tw-text-sm tw-text-gray-600"}," All appointments scheduled in the selected time period, regardless of status. ")]),t("div",null,[t("div",{class:"tw-font-semibold tw-text-gray-900 tw-text-sm tw-mb-1"}," Pending "),t("div",{class:"tw-text-sm tw-text-gray-600"}," Appointments created but not yet confirmed by the customer. ")]),t("div",null,[t("div",{class:"tw-font-semibold tw-text-gray-900 tw-text-sm tw-mb-1"}," Confirmed "),t("div",{class:"tw-text-sm tw-text-gray-600"}," Appointments the customer has confirmed they'll attend. ")])]),t("div",{class:"tw-space-y-4"},[t("div",null,[t("div",{class:"tw-font-semibold tw-text-gray-900 tw-text-sm tw-mb-1"}," Kept "),t("div",{class:"tw-text-sm tw-text-gray-600"}," Appointments where the customer showed up and the meeting took place. ")]),t("div",null,[t("div",{class:"tw-font-semibold tw-text-gray-900 tw-text-sm tw-mb-1"}," No Show "),t("div",{class:"tw-text-sm tw-text-gray-600"}," Appointments where the customer did not show up. ")]),t("div",null,[t("div",{class:"tw-font-semibold tw-text-gray-900 tw-text-sm tw-mb-1"}," Show Rate "),t("div",{class:"tw-text-sm tw-text-gray-600"}," Kept appointments as a percentage of total appointments (kept / total à 100). ")])])],-1)),t("div",Dl,[w(W,{size:"16",color:"#32ba8f",class:"tw-mt-0.5"},{default:a(()=>m[9]||(m[9]=[M(" mdi-information-outline ")])),_:1}),m[10]||(m[10]=t("div",{class:"tw-text-sm tw-text-gray-600"}," All columns reflect data from the time period selected in the filter above. ",-1))])]),_:1})]),_:1})],512),[[Gt,r.value]])]),_:1})])],64)):(l(),u("div",Cl,[w(W,{icon:"mdi-calendar-clock-outline",size:"48",color:"grey-lighten-2",class:"tw-mb-3"}),m[6]||(m[6]=t("p",{class:"tw-text-sm tw-font-medium tw-text-gray-700 tw-mb-1"}," No appointment data found ",-1)),m[7]||(m[7]=t("p",{class:"tw-text-xs tw-text-gray-500"}," Try a different time period or adjust your filters. ",-1))]))])}}}),Fl=St(Il,[["__scopeId","data-v-c403bf1e"]]);function Ml(){const I=Rt(),{data:S,isLoading:R,isFetching:v,error:d,refetch:b}=$t({queryKey:["crmReportUsers"],queryFn:async()=>await I.fetchCrmReportUsers(),staleTime:It.REALTIME,refetchOnWindowFocus:!1,refetchOnMount:!0,retry:1});return{users:A(()=>S.value||[]),isLoading:R,isFetching:v,error:d,refetch:b}}function Ol(){const{isRbacEnabled:I}=ce(),S=A(()=>I.value),R=A(()=>S.value?(le().roles??[]).map(b=>({id:b.id,name:b.name})):[]),v=A(()=>S.value?!!le().isLoadingGrid:!1);return{roleOptions:R,isLoading:v,isAvailable:S}}const zl={class:"tw-flex tw-flex-col tw-space-y-4 tw-mb-6"},Ul={class:"tw-flex tw-items-center tw-text-sm tw-text-gray-600"},Nl={class:"tw-font-medium tw-text-gray-700"},Vl={class:"tw-grid tw-grid-cols-1 md:tw-grid-cols-3 tw-gap-4"},Bl={class:"tw-col-span-1"},Gl={key:0,class:"tw-col-span-1"},ql={key:1,class:"tw-col-span-1"},Hl={key:2,class:"tw-col-span-1"},jl={key:3,class:"tw-col-span-1","data-testid":"crm-report-user-filter"},Wl={key:4,class:"tw-col-span-1","data-testid":"crm-report-role-filter"},Yl={key:0,class:"tw-flex tw-flex-wrap tw-gap-2","data-testid":"crm-report-active-chips"},Ql={key:1,class:"tw-px-4 tw-py-3 tw-bg-green-50 tw-border tw-border-green-200 tw-rounded"},Kl={class:"tw-flex tw-items-center"},Xl=yt({__name:"CRMReportDateFilter",setup(I){const S=xt(),R=xe(),{dateFilter:v}=Pt(S),{isMasterAccount:d,subAccounts:b}=Pt(R),{featureFlagEnabled:C}=ue(),P=C(be),k=C(ke),g=A(()=>d.value&&P.value&&b.value.length>0),U=A(()=>b.value.map(n=>{var h;return{title:((h=n.subAccount)==null?void 0:h.name)||`Sub Account ${n.subAccountId}`,value:n.subAccountId}})),s=Ae(),e=De(),{timezones:y}=Pt(e),L=A(()=>s.userInfo.timezone||"America/New_York"),G=A(()=>{const h=Ie(y.value,L.value).find(at=>at.value===L.value);
1return(h==null?void 0:h.label)||L.value});Ce(async()=>{await e.fetchTimezones()});const F=[{text:"Today",value:"today"},{text:"Yesterday",value:"yesterday"},{text:"This Week",value:"this_week"},{text:"Last Week",value:"last_week"},{text:"This Month",value:"this_month"},{text:"Last Month",value:"last_month"},{text:"Custom Range",value:"custom"}],{hasManagerPermission:N}=ce(),V=A(()=>N().value),{users:c,isLoading:B}=Ml(),{roleOptions:j,isLoading:i,isAvailable:p}=Ol(),D=H(v.value.period),r=H(v.value.from),T=H(v.value.to),m=H(v.value.filter_by_customer_id),J=H(v.value.user_ids??[]),Y=H(v.value.role_ids??[]),Q=A(()=>c.value.filter(n=>J.value.includes(n.id)).map(n=>({id:n.id,name:n.name}))),wt=A(()=>j.value.filter(n=>Y.value.includes(n.id)).map(n=>({id:n.id,name:n.name}))),gt=H(""),ft=H(""),pt=(n,h)=>{const at=h.trim().toLowerCase();return at?n.filter(nt=>{var K;return(K=nt.name)==null?void 0:K.toLowerCase().includes(at)}):n},bt=A(()=>pt(c.value,gt.value)),ct=A(()=>pt(j.value,ft.value)),kt=A(()=>J.value.length?J.value.length:se.id),dt=A(()=>
1Y.value.length?Y.value.length:se.id),Ct=A(()=>D.value!=="custom"?!0:!!(r.value&&T.value)),ut=n=>{n!=="custom"&&(r.value="",T.value="",S.setPeriod(n))},tt=n=>{S.setCustomerId(n||void 0)},E=n=>{const h=Array.isArray(n)?n:[];J.value=h,S.setUserIds(h)},z=n=>{const h=Array.isArray(n)?n:[];Y.value=h,S.setRoleIds(h)},O=()=>{E([])},_=()=>{z([])},f=n=>{E(J.value.filter(h=>h!==n))},x=n=>{z(Y.value.filter(h=>h!==n))};return Zt([r,T],([n,h])=>{D.value==="custom"&&n&&h&&S.setCustomDates(n,h)}),Zt(k,n=>{n||(J.value.length&&S.setUserIds([]),Y.value.length&&S.setRoleIds([]))},{immediate:!0}),Zt(v,n=>{D.value=n.period,r.value=n.from,T.value=n.to,m.value=n.filter_by_customer_id,J.value=n.user_ids??[],Y.value=n.role_ids??[]},{deep:!0}),(n,h)=>{const at=Ee,nt=pe;return l(),u("div",zl,[t("div",Ul,[w(W,{icon:"mdi-clock-outline",size:"16",color:"#32ba8f",class:"tw-mr-1.5"}),t("span",null,[h[9]||(h[9]=M(" Report data is based on your timezone: ")),t("span",Nl,$(G.value),1),h[10]||(h[10]=M(". ")),w(at,{to:"/settings",class:"tw-text-primary tw-font-medium hover:tw-underline tw-ml-1 tw-text-transax-green-400"},{default:a(()=>h[8]||(h[8]=[M(" Update timezone ")])),_:1})])]),t("div",Vl,[t("div",Bl,[h[11]||(h[11]=t("div",{class:"tw-text-sm tw-font-medium tw-text-gray-700 tw-mb-1.5"}," Time Period ",-1)),w(oe,{modelValue:D.value,"onUpdate:modelValue":[h[0]||(h[0]=K=>D.value=K),ut],items:F,"item-title":"text","item-value":"value",density:"comfortable",variant:"outlined","hide-details":"",placeholder:"Select period"},null,8,["modelValue"])]),D.value==="custom"?(l(),u("div",Gl,[w(ne,{modelValue:r.value,"onUpdate:modelValue":h[1]||(h[1]=K=>r.value=K),label:"From Date"},null,8,["modelValue"])])):Z("",!0),D.value==="custom"?(l(),u("div",ql,[w(ne,{modelValue:T.value,"onUpdate:modelValue":h[2]||(h[2]=K=>T.value=K),label:"To Date"},null,8,["modelValue"])])):Z("",!0),g.value?(l(),u("div",Hl,[h[12]||(h[12]=t("div",{class:"tw-text-sm tw-font-medium tw-text-gray-700 tw-mb-1.5"}," Sub Account ",-1)),w(oe,{modelValue:m.value,"onUpdate:modelValue":[h[3]||(h[3]=K=>m.value=K),tt],items:U.value,"item-title":"title","item-value":"value",density:"comfortable",variant:"outlined","hide-details":"",placeholder:"Select Sub Account",clearable:""},null,8,["modelValue","items"])])):Z("",!0),V.value&&o(k)?(l(),u("div",jl,[h[13]||(h[13]=t("div",{class:"tw-text-sm tw-font-medium tw-text-gray-700 tw-mb-1.5"}," User ",-1)),w(nt,{modelValue:J.value,"onUpdate:modelValue":[h[4]||(h[4]=K=>J.value=K),E],label:"","hide-label":"",items:bt.value,"item-title":"name","item-value":"id",variant:"outlined",density:"comfortable","hide-details":"",multiple:"",clearable:"",placeholder:"All","bg-color":"white",class:"filter-autocomplete",loading:o(B),"multi-select-all":kt.value,onSearchEmit:h[5]||(h[5]=K=>gt.value=K),onEmitAllClick:O},null,8,["modelValue","items","loading","multi-select-all"])])):Z("",!0),V.value&&o(k)&&o(p)?(l(),u("div",Wl,[h[14]||(h[14]=t("div",{class:"tw-text-sm tw-font-medium tw-text-gray-700 tw-mb-1.5"}," Role ",-1)),w(nt,{modelValue:Y.value,"onUpdate:modelValue":[h[6]||(h[6]=K=>Y.value=K),z],label:"","hide-label":"",items:ct.value,"item-title":"name","item-value":"id",variant:"outlined",density:"comfortable","hide-details":"",multiple:"",clearable:"",placeholder:"All","bg-color":"white",class:"filter-autocomplete",loading:o(i),"multi-select-all":dt.value,onSearchEmit:h[7]||(h[7]=K=>ft.value=K),onEmitAllClick:_},null,8,["modelValue","items","loading","multi-select-all"])])):Z("",!0)]),V.value&&o(k)&&(Q.value.length||wt.value.length)?(l(),u("div",Yl,[(l(!0),u(Et,null,_t(Q.value,K=>(l(),ot(ae,{key:`user-${K.id}`,size:"small",closable:"",color:"#32ba8f",class:"filter-chip","onClick:close":et=>f(K.id)},{default:a(()=>[M(" User: "+$(K.name),1)]),_:2},1032,["onClick:close"]))),128)),(l(!0),u(Et,null,_t(wt.value,K=>(l(),ot(ae,{key:`role-${K.id}`,size:"small",closable:"",color:"#32ba8f",class:"filter-chip","onClick:close":et=>x(K.id)},{default:a(()=>[M(" Role: "+$(K.name),1)]),_:2},1032,["onClick:close"]))),128))])):Z("",!0),D.value==="custom"&&!Ct.value?(l(),u("div",Ql,[t("div",Kl,[w(W,{icon:"mdi-alert-circle",color:"green",size:"small",class:"tw-mr
1-2"}),h[15]||(h[15]=t("div",{class:"tw-text-green-800 tw-text-sm"}," Please select both From Date and To Date when using custom date range. ",-1))])])):Z("",!0)])}}}),Zl=St(Xl,[["__scopeId","data-v-8505089b"]]),Jl={class:"crm-report"},tn={class:"tw-p-4"},en={class:"tw-p-4"},sn={class:"tw-p-4"},on={class:"tw-p-4"},an={class:"tw-p-4"},ln=yt({__name:"CRMReport",setup(I){const S=H("master-lead"),{featureFlagEnabled:R}=ue(),v=R($e),d=A(()=>{const C=[{value:"master-lead",label:"Master Lead Report",testId:"master-lead-tab"},{value:"salesperson-activities",label:"Salesperson Activities Report",testId:"salesperson-activities-tab"},{value:"lead-sources",label:"Lead Sources Report",testId:"lead-sources-tab"},{value:"lead-status-by-salesperson",label:"Lead Status by Salesperson Report",testId:"lead-status-by-salesperson-tab"}];return v.value&&C.push({value:"appointment-statistics",label:"Appointment Statistics Report",testId:"appointment-statistics-tab"}),C}),b=Se();return Re(()=>{b.invalidateQueries({queryKey:["masterLeadReport"]}),b.invalidateQueries({queryKey:["salespersonActivitiesReport"]}),b.invalidateQueries({queryKey:["leadSourcesReport"]}),b.invalidateQueries({queryKey:["leadStatusBySalespersonReport"]}),b.invalidateQueries({queryKey:["appointmentStatisticsReport"]})}),(C,P)=>{const k=ge;return l(),u("div",Jl,[w(Zl),w(k,{modelValue:S.value,"onUpdate:modelValue":P[0]||(P[0]=g=>S.value=g),tabs:d.value},{"master-lead":a(()=>[t("div",tn,[w(Zs)])]),"salesperson-activities":a(()=>[t("div",en,[w(aa)])]),"lead-sources":a(()=>[t("div",sn,[w(Ma)])]),"lead-status-by-salesperson":a(()=>[t("div",on,[w(wl)])]),"appointment-statistics":a(()=>[t("div",an,[w(Fl)])]),_:1},8,["modelValue","tabs"])])}}}),An=St(ln,[["__scopeId","data-v-04e3c55c"]]);export{An 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.