1import{j as e,ct as Q,a_ as H,N as se,b6 as te,cu as ae,bu as re,co as le,cn as ne,ck as ie,ao as G,cl as ce}from"./vendor-ui-COZs5eRx.js";import{r as N}from"./vendor-recharts-BJMZlXlQ.js";import{e as oe,L as W}from"./vendor-react-C1U_s4yj.js";import{u as Z}from"./vendor-misc-DXRBUnIG.js";import{a as de}from"./vendor-query-BLov83O-.js";import{I as K,a8 as me,T as xe,f as ue,h as he,Z as I,B as j,k as pe,a as fe,as as ge,a3 as je,ai as ve,at as we,au as _e,a5 as T}from"./index-DzxWwI0n.js";import{C as M}from"./card-BEpJch0K.js";import{u as S,q as C,z as Ne,f,A as be,B as ye,i as ke,D as Ce,G as Se,J as Ae,s as R}from"./constants-B5KVbg4C.js";import{L as w}from"./label-CM2YLNH3.js";import{S as O,a as L,b as F,c as P,d as D}from"./select-CAK0mh2U.js";import{a as Te,C as b,c as Oe,b as Le,P as Fe,d as Pe,D as De}from"./PixelChips-DPX7shu0.js";import"./vendor-supabase-BXq42zaU.js";import"./vendor-motion-CrKW_0K1.js";import"./checkbox-CRB5AnrL.js";import"./dialog-GFeawQXL.js";const Ie=["all","text","image","video","unknown"],Me=["all","active","inactive"],Ee=["all","30d","90d","365d","custom"],ze=["last_shown_desc","first_shown_desc","days_desc"];function Re({value:t,onChange:r}){const{c:n}=S(),o=s=>r({...t,...s,page:1});return e.jsxs("div",{className:"flex flex-wrap items-end gap-3",children:[e.jsxs("div",{className:"w-full space-y-1 sm:w-40",children:[e.jsx(w,{className:"text-xs text-muted-foreground",children:n.filters.format}),e.jsxs(O,{value:t.format??"all",onValueChange:s=>o({format:s}),children:[e.jsx(L,{className:"h-9",children:e.jsx(F,{})}),e.jsx(P,{children:Ie.map(s=>e.jsx(D,{value:s,children:s==="all"?n.filters.allFormats:n.ad.formats[s]},s))})]})]}),e.jsxs("div",{className:"w-full space-y-1 sm:w-48",children:[e.jsx(w,{className:"text-xs text-muted-foreground",children:n.filters.status}),e.jsxs(O,{value:t.status??"all",onValueChange:s=>o({status:s}),children:[e.jsx(L,{className:"h-9",children:e.jsx(F,{})}),e.jsx(P,{children:Me.map(s=>e.jsx(D,{value:s,children:s==="all"?n.filters.allStatus:s==="active"?n.filters.active:n.filters.inactive},s))})]})]}),e.jsxs("div",{className:"w-full space-y-1 sm:w-44",children:[e.jsx(w,{className:"text-xs text-muted-foreground",children:n.filters.period}),e.jsxs(O,{value:t.period??"all",onValueChange:s=>o({period:s}),children:[e.jsx(L,{className:"h-9",children:e.jsx(F,{})}),e.jsx(P,{children:Ee.map(s=>e.jsx(D,{value:s,children:n.filters.periods[s]},s))})]})]}),t.period==="custom"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"w-[calc(50%-0.375rem)] space-y-1 sm:w-40",children:[e.jsx(w,{className:"text-xs text-muted-foreground",children:n.filters.from}),e.jsx(K,{type:"date",className:"h-9",value:t.from??"",onChange:s=>o({from:s.target.value||void 0})})]}),e.jsxs("div",{className:"w-[calc(50%-0.375rem)] space-y-1 sm:w-40",children:[e.jsx(w,{className:"text-xs text-muted-foreground",children:n.filters.to}),e.jsx(K,{type:"date",className:"h-9",value:t.to??"",onChange:s=>o({to:s.target.value||void 0})})]})]}),e.jsxs("div",{className:"w-full space-y-1 sm:ml-auto sm:w-48",children:[e.jsx(w,{className:"text-xs text-muted-foreground",children:n.filters.sort}),e.jsxs(O,{value:t.sort??"last_shown_desc",onValueChange:s=>o({sort:s}),children:[e.jsx(L,{className:"h-9",children:e.jsx(F,{})}),e.jsx(P,{children:ze.map(s=>e.jsx(D,{value:s,children:n.filters.sorts[s]},s))})]})]})]})}const Ue={text:se,image:te,video:ae,unknown:Q};function Ve({ad:t,showAdvertiser:r=!1}){const{c:n,lang:o}=S(),s=t.is_recent,x=Ue[t.format]??Q,u=C(t.first_shown_at,o),d=C(t.last_shown_at,o),l=Ne(t.days_shown,n);return e.jsxs(M,{className:"flex h-full flex-col gap-3 p-3","data-testid":"cw-ad-card",children:[e.jsx(Te,{ad:t}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[t.is_new&&e.jsx(b,{tone:"iceSolid",dot:!0,children:n.ad.new}),s?e.jsx(me,{delayDuration:200,children:e.jsxs(xe,{children:[e.jsx(ue,{asChild:!0,children:e.jsx("span",{tabIndex:0,children:e.jsx(b,{tone:"ice",children:n.ad.recent})})}),e.jsx(he,{children:n.ad.recentTooltip})]})}):d?e.jsx(b,{tone:"neutral",children:f(n.ad.lastShown,{date:d})}):null,e.jsxs(b,{tone:"neutral",className:"gap-1",children:[e.jsx(x,{className:"h-3 w-3","aria-hidden":!0}),be(t.format,n)]})]}),e.jsxs("div",{className:"space-y-1 text-xs text-muted-foreground",children:[r&&t.advertiser_name&&e.jsx("p",{className:"truncate",children:f(n.ad.by,{name:t.advertiser_name})}),u&&d&&e.jsx("p",{children:f(n.ad.firstLast,{first:u,last:d})}),l&&e.jsx("p",{children:l})]}),e.jsx("div",{className:"mt-auto flex items-center gap-2 pt-1",children:ye(t.atc_url)&&e.jsxs("a",{href:t.atc_url,target:"_blank",rel:"noopener noreferrer nofollow",className:"inline-flex items-center gap-1 text-xs font-medium text-primary hover:underline",children:[n.common.viewOnGoogle,e.jsx(H,{className:"h-3 w-3","aria-hidden":!0})]})})]})}function $e({ads:t,loading:r,showAdvertiser:n}){return r?e.jsx("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4",children:Array.from({length:8},(o,s)=>
1e.jsx(I,{className:"h-64 rounded-xl"},s))}):e.jsx("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4",children:t.map(o=>e.jsx(Ve,{ad:o,showAdvertiser:n},o.creative_id))})}function _({label:t,value:r}){return e.jsxs("div",{className:"min-w-0",children:[e.jsx("dt",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:t}),e.jsx("dd",{className:"truncate text-sm font-medium",children:r})]})}function Be({data:t,onToggleFavorite:r,onToggleAlerts:n,busy:o}){const{c:s,lang:x}=S(),[u,d]=N.useState(!1),{shop:l,watch:c,advertisers:h}=t,p=s.common.notVerified,a=h.filter(m=>m.selected),g=l.enrichment_status==="ok",y=C(l.domain_created_at,x),k=C(l.oldest_product_published_at,x);return e.jsxs(M,{className:"space-y-5 p-4 sm:p-5",children:[e.jsxs("div",{className:"flex flex-wrap items-start gap-3",children:[e.jsx("div",{className:"flex h-11 w-11 shrink-0 items-center justify-center rounded-xl bg-primary/10 text-lg font-bold text-primary","aria-hidden":!0,children:ke(l.name,l.domain)}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h1",{className:"truncate text-xl font-bold",children:c.label||l.name||l.domain}),l.domain&&e.jsxs("a",{href:`https://${l.domain}`,target:"_blank",rel:"noopener noreferrer nofollow",className:"inline-flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground",children:[l.domain,e.jsx(H,{className:"h-3 w-3","aria-hidden":!0})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap gap-1.5",children:[e.jsx(Oe,{status:t.ads.status}),t.ads.coverage==="partial"&&e.jsx(b,{tone:"warning",children:s.status.partial})]})]}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx(j,{variant:"ghost",size:"icon",onClick:r,disabled:o,"aria-label":c.is_favorite?s.watchlist.unfavorite:s.watchlist.favorite,title:c.is_favorite?s.watchlist.unfavorite:s.watchlist.favorite,children:e.jsx(re,{className:pe("h-4 w-4",c.is_favorite&&"fill-primary text-primary")})}),e.jsx(j,{variant:"ghost",size:"icon",onClick:n,disabled:o,"aria-label":c.alerts_enabled?s.watchlist.disableAlerts:s.watchlist.enableAlerts,title:c.alerts_enabled?s.watchlist.alertsOn:s.watchlist.alertsOff,children:c.alerts_enabled?e.jsx(le,{className:"h-4 w-4"}):e.jsx(ne,{className:"h-4 w-4 text-muted-foreground"})})]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"mb-2 text-xs font-semibold text-muted-foreground",children:s.shop.facts}),l.enrichment_status==="pending"&&e.jsx("p",{className:"mb-2 text-xs text-amber-700 dark:text-amber-300",children:s.shop.enrichmentPending}),!g&&l.enrichment_status!=="pending"&&e.jsx("p",{className:"mb-2 text-xs text-muted-foreground",children:l.enrichment_status==="not_ecommerce"?s.shop.notShopify:s.shop.enrichmentFailed}),e.jsxs("dl",{className:"grid grid-cols-2 gap-x-4 gap-y-3 sm:grid-cols-3 lg:grid-cols-6",children:[e.jsx(_,{label:s.shop.theme,value:l.theme_name??p}),e.jsx(_,{label:s.shop.language,value:l.language?l.language.toUpperCase():p}),e.jsx(_,{label:s.shop.currency,value:l.currency??p}),e.jsx(_,{label:s.shop.country,value:l.shop_country??p}),e.jsx(_,{label:s.shop.products,value:Ce(l.product_count,l.product_count_is_lower_bound,s,x)}),e.jsx(_,{label:s.shop.tags,value:l.niche_tags.length?l.niche_tags.slice(0,3).join(", "):p})]}),(()=>{const m=Se(l.popularity,s,x);return e.jsxs("p",{className:"mt-3 text-xs text-muted-foreground",title:m.tooltip??void 0,children:[s.popularity.title," : ",e.jsx("span",{className:"font-medium text-foreground",children:m.label}),m.scope?` (${m.scope})`:""]})})(),e.jsxs("div",{className:"mt-3 space-y-0.5 text-xs text-muted-foreground",children:[e.jsx("p",{children:y?f(s.shop.domainCreated,{date:y}):s.shop.domainCreatedUnknown}),k&&e.jsx("p",{children:f(s.shop.productsSince,{date:k})})]})]}),t.ads.status==="advertisers_found"&&e.jsx("dl",{className:"grid grid-cols-3 gap-3 rounded-lg border border-border bg-muted/20 p-3","data-testid":"cw-ads-metrics",children:[["activeAds",t.ads.active_count,!1],["newAds7",t.ads.new_7d,!0],["newAds30",t.ads.new_30d,!0]].map(([m,E,v])=>{const A=Ae(E,t.ads.metrics_partial,x,v);return e.jsxs("div",{className:"min-w-0",children:[e.jsx("dt",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:s.shop[m]}),e.jsx("dd",{className:A===null?"text-sm text-muted-foreground":"text-xl font-bold tabular-nums",children:A??p})]},m)})}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"mb-2 text-xs font-semibold text-muted-foreground",children:s.shop.pixels}),e.jsx(Le,{pixels:l.pixels})]}),l.sample_products.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"mb-2 text-xs font-semibold text-muted-foreground",children:s.shop.samples}),e.jsx(Fe,{products:l.sample_products,size:"h-14 w-14"})]})]}),(h.length>0||t.ads.status==="advertisers_found")&&e.jsxs("div",{children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsxs("p",{className:"text-xs font-semibold text-muted-foreground",children:[s.advertisers.title,c.advertiser_selection==="user"&&e.jsxs("span",{className:"ml-1.5 font-normal",children:["· ",s.advertisers.selectionUser]})]}),h.length>0&&e.jsxs(j,{variant:"ghost",size:"sm",className:"h-7 gap-1 px-2 text-xs",onClick:()=>d(!0),children:[e.jsx(ie,{className:"h-3 w-3"}),s.common.edit]})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:a.length===0?e.jsx("span",{className:"text-xs text-muted-foreground",children:s.states.noSelection}):a.map(m=>e.jsx(b,{tone:"ice",children:m.name??m.advertiser_id},m.advertiser_id))}),e.jsx(Pe,{open:u,onOpenChange:d,watchId:c.watch_id,domain:l.domain,advertisers:h})]})]})}function qe({launches:t}){var d,l;const{c:r,lang:n}=S(),o=t.weeks,s=Math.max(1,...o.map(c=>c.count)),x=o.reduce((c,h)=>c+h.count,0),u=f(x<=1?r.launches.totalOne:r.launches.total,{n:x});return e.jsxs(M,{className:"space-y-3 p-4","data-testid":"cw-launch-chart",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-semibold",children:r.launches.title}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r.launches.subtitle})]}),e.jsx("span",{className:"text-sm font-semibold tabular-nums",children:u})]}),e.jsx("div",{className:"flex h-28 items-end gap-1",role:"img","aria-label":`${r.launches.title} : ${u}`,children:o.map(c=>{const h=f(r.launches.weekOf,{date:R(`${c.week_start}T00:00:00Z`,n,"UTC")??c.week_start,n:c.count});return e.jsxs("div",{className:"flex h-full flex-1 flex-col items-center justify-end gap-1",title:h,children:[e.jsx("span",{className:"text-[10px] tabular-nums text-muted-foreground",children:c.count>0?c.count:""}),e.jsx("div",{className:"w-full rounded-t bg-primary/70",style:{height:`${Math.max(c.count>0?6:2,c.count/s*100)}%`,opacity:c.count>0?1:.25}})]},c.week_start)})}),e.jsxs("div",{className:"flex justify-between text-[10px] text-muted-foreground",children:[e.jsx("span",{children:R(`${(d=o[0])==null?void 0:d.week_start}T00:00:00Z`,n,"UTC")}),e.jsx("span",{children:R(`${(l=o[o.length-1])==null?void 0:l.week_start}T00:00:00Z`,n,"UTC")})]}),t.coverage==="partial"&&e.jsx("p",{className:"text-xs text-amber-700 dark:text-amber-300",children:r.launches.partial})]})}const Ge=24;function U(t){return t.length===0||t.some(r=>r===null)?null:t.reduce((r,n)=>r+n,0)}function is(){const{watchId:t}
1=oe(),{c:r,lang:n}=S(),{getLocalizedPath:o}=fe(),s=de(),[x,u]=N.useState({format:"all",status:"all",period:"all",sort:"last_shown_desc",page:1,per_page:Ge}),d=ge(t,x),l=je(),c=ve(),h=N.useRef(null),p=N.useRef(!1);N.useEffect(()=>{!t||!d.data||h.current===t||p.current||(p.current=!0,we({watch_id:t,mark_viewed:!0}).then(()=>(h.current=t,s.invalidateQueries({queryKey:_e.watchlist}))).catch(i=>console.warn("[competitor-watch] mark_viewed",i instanceof T?i.code:i)).finally(()=>{p.current=!1}))},[t,d.data,s]);const a=d.data,g=N.useMemo(()=>((a==null?void 0:a.advertisers)??[]).filter(i=>i.selected),[a]),y=o("/dashboard/competitor-watch");if(d.isLoading)return e.jsxs("div",{className:"mx-auto w-full max-w-7xl space-y-4",children:[e.jsx(I,{className:"h-5 w-40"}),e.jsx(I,{className:"h-64 rounded-xl"}),e.jsx(I,{className:"h-96 rounded-xl"})]});if(d.isError||!a){const i=d.error instanceof T?d.error.code:null;return e.jsxs("div",{className:"mx-auto w-full max-w-3xl space-y-4",children:[e.jsxs(W,{to:y,className:"inline-flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground",children:[e.jsx(G,{className:"h-4 w-4"}),r.common.back]}),e.jsxs(M,{className:"space-y-3 p-6 text-sm",children:[e.jsx("p",{className:"text-muted-foreground",children:i?r.errors[i]:r.errors.loadFailed}),i!=="CW_NOT_FOUND"&&e.jsx(j,{variant:"outline",size:"sm",onClick:()=>d.refetch(),children:r.common.retry})]})]})}const k=async i=>{try{await l.mutateAsync({watch_id:a.watch.watch_id,...i})}catch(q){Z.error(q instanceof T?r.errors[q.code]:r.errors.generic)}},m=async()=>{try{await c.mutateAsync({watchId:a.watch.watch_id})}catch(i){Z.error(i instanceof T?r.errors[i.code]:r.errors.generic)}},E=a.ads.status==="advertisers_found"&&a.watch.advertiser_selection==="auto"&&a.advertisers.length>0&&!a.advertisers.some(i=>i.role==="primary"),v=g.filter(i=>i.last_refreshed_at),A=U(v.map(i=>i.creatives_seen_count)),J=U(v.map(i=>i.ads_count_min)),X=U(v.map(i=>i.ads_count_max)),z=Math.max(1,Math.ceil(a.ads.total/a.ads.per_page)),Y=a.ads.items.some(i=>i.is_new),ee=a.ads.status==="no_advertiser_found"?a.ads.checked_at:a.ads.last_refreshed_at??(a.ads.status==="advertisers_found"?a.ads.checked_at:null),V=C(ee,n),$=g.length>0&&v.length===0,B=a.ads.status==="advertisers_found"&&g.length>0&&!$;return e.jsxs("div",{className:"mx-auto w-full max-w-7xl space-y-5",children:[e.jsxs(W,{to:y,className:"inline-flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground",children:[e.jsx(G,{className:"h-4 w-4"}),r.title]}),e.jsx(Be,{data:a,busy:l.isPending,onToggleFavorite:()=>k({is_favorite:!a.watch.is_favorite}),onToggleAlerts:()=>k({alerts_enabled:!a.watch.alerts_enabled})}),e.jsx(De,{status:a.ads.status,domain:a.shop.domain,checkedAt:a.ads.checked_at,lastRefreshedAt:a.ads.last_refreshed_at,coverage:a.ads.coverage,collected:A,countMin:J,countMax:X,selectedCount:a.advertisers.length>0?g.length:void 0,unsure:E,notRefreshed:$}),B&&a.launches&&a.launches.weeks.length>0&&e.jsx(qe,{launches:a.launches}),B&&e.jsxs("section",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("h2",{className:"text-lg font-semibold",children:[r.ads.title,e.jsx("span",{className:"ml-2 text-sm font-normal text-muted-foreground",children:a.ads.total===1?r.filters.totalOne:f(r.filters.total,{n:a.ads.total})})]}),Y&&e.jsxs(j,{variant:"outline",size:"sm",onClick:m,disabled:c.isPending,children:[e.jsx(ce,{className:"mr-2 h-4 w-4"}),r.feed.markAll]})]}),e.jsx(Re,{value:x,onChange:u}),a.ads.items.length===0&&!d.isFetching?e.jsx("p",{className:"rounded-xl border border-dashed border-border px-4 py-10 text-center text-sm text-muted-foreground",children:r.states.noAdsMatch}):e.jsx($e,{ads:a.ads.items,loading:d.isFetching&&d.isPlaceholderData,showAdvertiser:g.length>1}),z>1&&e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(j,{variant:"outline",size:"sm",disabled:a.ads.page<=1||d.isFetching,onClick:()=>u(i=>({...i,page:(i.page??1)-1})),children:r.common.previous}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[a.ads.page," / ",z]}
1),e.jsx(j,{variant:"outline",size:"sm",disabled:a.ads.page>=z||d.isFetching,onClick:()=>u(i=>({...i,page:(i.page??1)+1})),children:r.common.next})]})]}),V&&(a.ads.status==="advertisers_found"||a.ads.status==="no_advertiser_found"||a.ads.status==="degraded")&&e.jsxs("footer",{className:"space-y-1 border-t border-border pt-4 text-xs text-muted-foreground","data-testid":"cw-attribution",children:[e.jsx("p",{children:f(r.ads.attribution,{date:V})}),e.jsx("p",{children:r.ads.publicViewNote})]})]})}export{is 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.