1import{r as o,j as e,B as P,a4 as ye,a5 as _e,a6 as Ne,z as et,bt as tt}from"./index-BBmhd2fr.js";import{C as ee,d as te,a as st,b as nt}from"./card-CQyLwhIa.js";import{S as se,a as ne,b as ae,c as re,f as q}from"./select-CEXh0zDM.js";import{S as at,T as we,C as rt}from"./ChartLoader-BjUnuW8l.js";import{P as ot,a as lt,b as it}from"./popover-D1J7po4f.js";import{a as ct}from"./custom-slider-oh8DeDnI.js";import{C as Se}from"./checkbox-CV_YF9Sp.js";import{C as mt,a as dt,b as ut,c as ht,d as gt,e as ve,f as xt}from"./command-DNxd_Xf0.js";import{T as pt,a as Me}from"./toggle-group-Bhe3TW7u.js";import{u as De,g as ft}from"./useChartData-0UgdQKqV.js";import{u as jt}from"./useMatFilters-DtS3IoMv.js";import{u as Ct}from"./DataSourceContext-BwGd8XgI.js";import{e as bt,b as Te,d as yt,j as Le}from"./chartExport-ZbI8p08_.js";import Re from"./EChartsLineChart-D5FdcpAB.js";import{D as Ie}from"./chartTheme-DSkSEph5.js";import{I as ke}from"./image-L9VFLUq1.js";import{T as _t}from"./tag-x6Ghbr16.js";import"./index-BdQq_4o_.js";import"./index-B7nojceh.js";import"./chevron-up-rK4xo6gt.js";import"./altavia-logo-compressed-BXS6R1Nc.js";import"./index-DYm_9zBf.js";import"./dialog-Cv-lzPma.js";import"./search-rphmc9_k.js";import"./useAppAccess-C2DvWl9l.js";import"./core-B_YBDarH.js";import"./echarts-zFUb0SoC.js";const oe="__claims__",O="__benchmark__",le=Ie.magentaRise,ie=Ie.cobaltClarity;function $(s){const a=s.getFullYear(),d=String(s.getMonth()+1).padStart(2,"0"),c=String(s.getDate()).padStart(2,"0");return`${a}-${d}-${c}`}function B(s){const[a,d,c]=s.split("-").map(Number);return new Date(a,d-1,c)}function ce(s){return String(s).slice(0,7)}function Nt(s,a){const[d,c]=s.split("-").map(Number),x=new Date(Date.UTC(d,c-1+a,1));return`${x.getUTCFullYear()}-${String(x.getUTCMonth()+1).padStart(2,"0")}`}function Ae(s){const[a,d]=s.split("-").map(Number);return new Date(Date.UTC(a,d-1,1)).toLocaleDateString("en-US",{month:"short",year:"numeric",timeZone:"UTC"})}const Fe=()=>({pos:0,neg:0,neu:0,r1:0,r2:0,r3:0,r4:0,r5:0});function wt(s){const a=s.r1+s.r2+s.r3+s.r4+s.r5;return a===0?null:(1*s.r1+2*s.r2+3*s.r3+4*s.r4+5*s.r5)/a}function St(s,a){const d=s.pos+s.neg+s.neu,c=a.pos+a.neg+a.neu;if(d===0||c===0)return null;const x=a.pos,p=a.neg;let u;x===0?u=s.pos>0?200:0:u=Math.min(s.pos/x*(c/d)*100,200);let i;return p===0?i=s.neg>0?200:0:i=Math.min(s.neg/p*(c/d)*100,200),Math.round(u-i)}function vt({retailers:s,selectedNames:a,onChange:d,disabled:c=!1}){const[x,p]=o.useState(!1);return e.jsxs(ot,{open:c?!1:x,onOpenChange:c?void 0:p,children:[e.jsx(lt,{asChild:!0,children:e.jsxs(P,{variant:"outline",role:"combobox","aria-expanded":x,disabled:c,className:"w-[200px] justify-between text-sm h-10 font-normal overflow-hidden",children:[e.jsx("span",{className:"truncate",children:a.length===0?"All Retailers":a.length===1?a[0]:`${a.length} retailers`}),e.jsx(et,{className:"h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(it,{className:"w-[min(26rem,calc(100vw-2rem))] p-0",children:e.jsxs(mt,{children:[e.jsx(dt,{placeholder:"Search retailers..."}),e.jsxs(ut,{children:[e.jsx(ht,{children:"No retailer found."}),e.jsxs(gt,{children:[e.jsxs(ve,{value:"__all_retailers__",onSelect:()=>d([]),className:a.length===0?"font-semibold":"",children:[e.jsx(Se,{checked:a.length===0,className:"mr-2 h-3 w-3"}),"All Retailers"]}),e.jsx(xt,{}),s.map(u=>e.jsxs(ve,{value:u.source_name,onSelect:()=>{d(a.includes(u.source_name)?a.filter(i=>i!==u.source_name):[...a,u.source_name])},children:[e.jsx(Se,{checked:a.includes(u.source_name),className:"mr-2 h-3 w-3"}),e.jsx(tt,{className:"mr-2 h-4 w-4 opacity-70"}),u.source_name]},u.source_name))]})]})]})})]})}function ss(){var je;const{sourceId:s,sources:a}=Ct(),d=(je=a==null?void 0:a.find(t=>t.id===s))==null?void 0:je.name,[c,x]=o.useState([]),[p,u]=o.useState([]),[i,H]=o.useState(null),[j,W]=o.useState(null),[S,X]=o.useState(oe),[h,Y]=o.useState(null),[f,z]=o.useState(null),[C,Ee]=o.useState("running12m"),me=o.useRef(null),Oe=t=>{const l=t.toLowerCase().replace(/[^a-z]/g,"");return l==="category"||l==="subcategory"},{properties:de,claims:V,dateBounds:v,isLoading:$e}=jt(s),b=o.useMemo(()=>{const t=[];((V==null?void 0:V.length)??0)>0&&t.push({id:oe,label:"Claims"});for(const l of de??[])Oe(l.name)||t.push({id:String(l.property_type_id
1),label:l.name});return t},[de,V]),Be=o.useMemo(()=>{var t;return((t=b.find(l=>l.id===S))==null?void 0:t.label)??"Claims"},[b,S]);o.useEffect(()=>{b.length&&(b.some(t=>t.id===S)||X(b[0].id))},[b,S]);const ue=o.useRef(!0);o.useEffect(()=>{if(ue.current){ue.current=!1;return}Y(null),z(null)},[S]);const{categories:Mt,retailers:F,subcategories:K,filters:he,totalReviews:Pe,totalProducts:Ye,chartData:Z,isLoading:ze,notStarted:Ve}=De(s&&i&&j?{source_id:s,query_type:"nos_by_claim",claim_dimension:S,subcategory_ids:c.length>0?c.map(Number):void 0,source_name:p.length>0?p:void 0,date_from:i,date_to:j,min_reviews:0}:null),I=(Z==null?void 0:Z.data)??[];o.useEffect(()=>{if(h!==null||I.length===0)return;const t=[...I].sort((l,k)=>k.opinion_count-l.opinion_count);t.length>=1&&Y(t[0].brand),t.length>=2&&z(t[1].brand)},[I,h]);const U=o.useMemo(()=>[...new Set(I.map(t=>t.brand).filter(Boolean))].sort((t,l)=>t.localeCompare(l)),[I]),y=o.useMemo(()=>[h,f].filter(Boolean),[h,f]),Ke=o.useMemo(()=>{if(C==="running12m"&&i){const t=B(i);return t.setMonth(t.getMonth()-11),$(t)}return i},[i,C]),{chartData:Ue,isLoading:Ge,isFetching:qe,notStarted:He}=De(s&&i&&j&&y.length>0?{source_id:s,query_type:"nos_by_claim",claim_dimension:S,group_by_month:!0,claim_names:y,subcategory_ids:c.length>0?c.map(Number):void 0,source_name:p.length>0?p:void 0,date_from:Ke||void 0,date_to:j,min_reviews:0}:null),_=Ue,G=o.useMemo(()=>ft(he,["nos","avg_rating"]),[he]),M=o.useMemo(()=>{const t=G.min_date??(v==null?void 0:v.min_date)??null;return t?B(t):null},[G,v]),T=o.useMemo(()=>{const t=G.max_date??(v==null?void 0:v.max_date)??null;return t?B(t):null},[G,v]);o.useEffect(()=>{if(M&&T&&!i){const t=new Date(T);t.setFullYear(t.getFullYear()-1);const l=t<M?M:t;H($(l)),W($(T))}},[M,T]);const ge=o.useRef(!0);o.useEffect(()=>{if(ge.current){ge.current=!1;return}x([]),u([]),X(oe),Y(null),z(null),H(null),W(null)},[s]);const{ratingChartData:R,nosChartData:J}=o.useMemo(()=>{if(!(_!=null&&_.data)||!(_!=null&&_.benchmark)||y.length===0)return{ratingChartData:[],nosChartData:[]};const t=new Map,l=(n,r,N)=>{t.has(n)||t.set(n,new Map);const m=t.get(n);m.has(r)||m.set(r,Fe()),N(m.get(r))};for(const n of _.data)y.includes(n.brand)&&l(ce(n.month),n.brand,r=>{r.pos+=n.c_pos,r.neg+=n.c_neg,r.neu+=n.c_neu,r.r1+=n.rc1,r.r2+=n.rc2,r.r3+=n.rc3,r.r4+=n.rc4,r.r5+=n.rc5});for(const n of _.benchmark)l(ce(n.month),O,r=>{r.pos+=n.tp,r.neg+=n.tn,r.neu+=Math.max(0,n.ta-n.tp-n.tn),r.r1+=n.br1,r.r2+=n.br2,r.r3+=n.br3,r.r4+=n.br4,r.r5+=n.br5});const k=Array.from(t.keys()).sort(),g=[O,...y],A=(n,r,N)=>{var be;const m=Fe();let D=!1;for(let Q=-(N-1);Q<=0;Q++){const w=(be=t.get(Nt(n,Q)))==null?void 0:be.get(r);w&&(D=!0,m.pos+=w.pos,m.neg+=w.neg,m.neu+=w.neu,m.r1+=w.r1,m.r2+=w.r2,m.r3+=w.r3,m.r4+=w.r4,m.r5+=w.r5)}return D?m:null},L=C==="running12m"?12:1,E=i?ce(i):null,Ce=C==="running12m"&&E?k.filter(n=>n>=E):k,Je=Ce.map(n=>{const r={month:n};for(const N of g){const m=A(n,N,L),D=m?wt(m):null;r[N]=D!=null?Number(D.toFixed(3)):null}return r}),Qe=Ce.map(n=>{const r={month:n},N=A(n,O,L);for(const m of y){const D=A(n,m,L);r[m]=D&&N?St(D,N):null}return r});return{ratingChartData:Je,nosChartData:Qe}},[_,y,C,i]),We=o.useMemo(()=>{const t=[{key:O,label:"Market Avg",color:"#1a1a1a",lineStyle:{type:"solid",width:2},showLabel:!1}];return h&&t.push({key:h,label:h,color:le,showLabel:!1}),f&&t.push({key:f,label:f,color:ie,showLabel:!1}),t},[h,f]),xe=o.useMemo(()=>{const t=[];return h&&t.push({key:h,label:h,color:le,showLabel:!1}),f&&t.push({key:f,label:f,color:ie,showLabel:!1}),t},[h,f]),pe=ze||Ve&&($e||!!M)||b.length>0&&(Ge||He)&&!_,fe=()=>({"Claim Dimension":Be,"Market Segments":Le(c),Retailers:Le(p),Claims:y.join(" vs ")||"All",Mode:C==="running12m"?"Rolling 12m":"Monthly"}),Xe=()=>{var l;const t=(l=me.current)==null?void 0:l.getEchartsInstance();t&&bt(t,Te("Claim Trend","png"),{segmentName:d,dateRange:i&&j?`${i} â ${j}`:"Last 12 months",filters:fe(),title:"Claim Satisfaction Trend"})}
1,Ze=()=>{if(!R.length)return;const t=["Month","Market Avg Rating"];for(const g of y)t.push(`${g} Rating`,`${g} NOS`);const l=new Map(J.map(g=>[g.month,g])),k=R.map(g=>{const A=[g.month,g[O]??null],L=l.get(g.month);for(const E of y)A.push(g[E]??null,(L==null?void 0:L[E])??null);return A});yt(t,k,Te("Claim Trend","csv"),{segmentName:d,dateRange:i&&j?`${i} â ${j}`:"Last 12 months",filters:fe()})};return e.jsxs("div",{className:"space-y-3",children:[e.jsx(ee,{children:e.jsxs(te,{className:"p-4 relative",children:[pe&&e.jsx("div",{className:"absolute inset-0 bg-background/50 z-10 rounded-lg"}),e.jsxs("div",{className:"flex items-center flex-wrap gap-x-6 gap-y-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"block text-xs font-medium text-muted-foreground",children:"Market Segments"}),e.jsx(at,{subcategories:K??[],selectedIds:c,onChange:x,disabled:!(K!=null&&K.length)})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"block text-xs font-medium text-muted-foreground",children:"Retailers"}),e.jsx(vt,{retailers:F??[],selectedNames:p,onChange:u,disabled:!(F!=null&&F.length)||F.length<=1})]}),e.jsxs("div",{className:"w-[160px] space-y-1.5 px-[8px]",children:[e.jsx(ct,{minDate:M??new Date(new Date().getFullYear()-1,new Date().getMonth(),1),maxDate:T??new Date,value:[i?B(i):M??new Date(new Date().getFullYear()-1,new Date().getMonth(),1),j?B(j):T??new Date],onValueChange:([t,l])=>{H($(t)),W($(l))},disabled:!M||!T}),e.jsx("p",{className:"text-xs font-medium text-muted-foreground text-center",children:"Date Range"})]})]})]})}),s?e.jsxs(ee,{children:[e.jsxs(st,{className:"py-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsxs("div",{className:"shrink-0 flex items-center gap-1 invisible",children:[e.jsx(P,{variant:"ghost",size:"icon",className:"h-8 w-8",children:e.jsx(ke,{className:"h-4 w-4"})}),e.jsx(P,{variant:"ghost",size:"icon",className:"h-8 w-8",children:e.jsx(we,{className:"h-4 w-4"})})]}),e.jsx(nt,{className:"flex-1 text-center text-2xl leading-tight",children:"Claim Satisfaction Trend"}),e.jsxs("div",{className:"shrink-0 flex items-center gap-1",children:[e.jsxs(ye,{children:[e.jsx(_e,{asChild:!0,children:e.jsx(P,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:Xe,disabled:!R.length,children:e.jsx(ke,{className:"h-4 w-4"})})}),e.jsx(Ne,{side:"bottom",children:"Download chart as image"})]}),e.jsxs(ye,{children:[e.jsx(_e,{asChild:!0,children:e.jsx(P,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:Ze,disabled:!R.length,children:e.jsx(we,{className:"h-4 w-4"})})}),e.jsx(Ne,{side:"bottom",children:"Download data as CSV"})]})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"Claim Dimension"}),e.jsxs(se,{value:S,onValueChange:X,disabled:!b.length,children:[e.jsx(ne,{className:"w-[180px] h-8 text-xs",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_t,{className:"h-3.5 w-3.5 shrink-0 opacity-50"}),e.jsx(ae,{placeholder:"Select a dimension"})]})}),e.jsx(re,{children:b.map(t=>e.jsx(q,{value:t.id,children:t.label},t.id))})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"Claim A"}),e.jsxs(se,{value:h??"",onValueChange:t=>Y(t||null),disabled:!U.length,children:[e.jsx(ne,{className:"w-[190px] h-8 text-xs",style:{borderColor:le},children:e.jsx(ae,{placeholder:"Select claim"})}),e.jsx(re,{children:U.map(t=>e.jsx(q,{value:t,children:t},t))})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"Claim B"}),e.jsxs(se,{value:f??"__none__",onValueChange:t=>z(t==="__none__"?null:t),disabled:!U.length,children:[e.jsx(ne,{className:"w-[190px] h-8 text-xs",style:{borderColor:ie},children:e.jsx(ae,{placeholder:"None"})}),e.jsxs(re,{children:[e.jsx(q,{value:"__none__",children:"None"}),U.filter(t=>t!==h).map(t=>e.jsx(q,{value:t,children:t},t))]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"Mode"}),e.jsxs(pt,{type:"single",value:C,onValueChange:t=>t&&Ee(t),className:"h-8",children:[e.jsx(Me,{value:"running12m",className:"h-8 px-3 text-xs",children:"Rolling 12m"}),e.jsx(Me,{value:"monthly",className:"h-8 px-3 text-xs",children:"Monthly"})]})]})]})]}),e.jsx(te,{children:pe?e.jsx(rt,{totalReviews:Pe,totalProducts:Ye}):b.length?R.length?e.jsxs(e.Fragment,{children:[e.jsx(Re,{ref:me,data:R,xKey:"month",formatX:Ae,series:We,formatY:t=>t.toFixed(2),yAxisName:C==="running12m"?"Rating (Rolling 12m)":"Rating",scaleY:!0,hideGrid:!0,hideCategoryLabels:!0,height:300,symbolSize:0,lineWidth:3}),J.length>0&&xe.length>0&&e.jsx("div",{className:"mt-8",children:e.jsx(Re,{data:J,xKey:"month",formatX:Ae,series:xe,formatY:t=>
1Math.round(t).toLocaleString(),yAxisName:C==="running12m"?"NOS (Rolling 12m)":"NOS",scaleY:!0,hideGrid:!0,height:220,showZeroLine:!0,hideCategoryLabels:!0,hideLegend:!0,symbolSize:0,lineWidth:3})}),qe&&e.jsx("p",{className:"text-[10px] text-muted-foreground/70 mt-2 text-center",children:"Updatingâ¦"}),e.jsxs("p",{className:"text-[10px] text-muted-foreground/70 mt-4 text-center",children:["Top: average star rating of products carrying each claim vs. the market average (black). Bottom: each claim's NOS vs. the ",C==="running12m"?"rolling-12-month":"monthly"," category benchmark."]})]}):e.jsx("p",{className:"text-sm text-muted-foreground text-center py-12",children:"No trend data for the selected claims and filters. Try adjusting the retailers, claims, or date range."}):e.jsx("p",{className:"text-sm text-muted-foreground text-center py-12",children:"This data source has no product claims or properties to analyze yet."})})]}):e.jsx(ee,{children:e.jsx(te,{className:"p-12 text-center text-muted-foreground",children:"Select a data source to begin analysis."})})]})}export{ss 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.