1import{s as m}from"./index-DuSE7Tbu.js";import"./markdown-BniUNT3b.js";import"./stripe-DNH-pMf_.js";import"./recharts-BxZy5o_C.js";import"./supabase-H0uDwzZe.js";const k={facebook:["click","save","share","comment"],nextdoor:["view"],craigslist:["message"]},S={view:"Views",click:"Clicks",save:"Saves",message:"Messages",share:"Shares",comment:"Comments"},u=new Set(["facebook"]),g=14;async function L(i){var t;const{data:o}=await m.auth.getUser(),n=(t=o.user)==null?void 0:t.id;if(!n)throw new Error("Not signed in");const{error:r}=await m.from("listing_engagement_metrics").insert({...i,user_id:n});if(r)throw r}const _=(i,o)=>{const n=new Date(`${i}T00:00:00`).getTime(),r=new Date(`${o}T00:00:00`).getTime();return Math.round((n-r)/864e5)};function d(i){const o=new Map;for(const r of i){const t=`${r.platform}:${r.metric_type}`,e=o.get(t)??[];e.push(r),o.set(t,e)}const n=[];for(const[,r]of o){let t=null;for(const e of r){const c=u.has(e.platform);let s=e.count;if(c&&t){const a=_(e.recorded_on,t.recorded_on);a>0&&a<=g?s=Math.max(0,e.count-t.count):s=e.count}n.push({recorded_on:e.recorded_on,platform:e.platform,metric_type:e.metric_type,raw:e.count,incremental:s}),t={recorded_on:e.recorded_on,count:e.count}}}return n.sort((r,t)=>r.recorded_on.localeCompare(t.recorded_on)),n}async function v(i){const{data:o,error:n}=await m.from("listing_engagement_metrics").select("recorded_on,platform,metric_type,count").eq("listing_id",i).order("recorded_on",{ascending:!0});return n?(console.error("fetchMetricTimeline failed:",n.message),[]):d(o??[])}const l=150;async function E(i,o={}){const n=new Map;if(i.length===0)return n;const r=[];for(let c=0;c<i.length;c+=l)r.push(i.slice(c,c+l));const t=await Promise.all(r.map(c=>{let s=m.from("listing_engagement_metrics").select("listing_id,recorded_on,platform,metric_type,count").in("listing_id",c);return o.since&&(s=s.gte("recorded_on",o.since)),s.order("recorded_on",{ascending:!0})})),e=new Map;for(const{data:c,error:s}of t){if(s){console.error("fetchMetricTimelines failed:",s.message);continue}for(const a of c??[]){const f=e.get(a.listing_id)??[];f.push(a),e.set(a.listing_id,f)}}for(const[c,s]of e)n.set(c,d(s));return n}const p=()=>({view:0,click:0,save:0,message:0,share:0,comment:0});async function R(i){const o=new Map;if(i.length===0)return o;const{data:n,error:r}=await m.from("listing_engagement_metrics").select("listing_id,platform,metric_type,count").in("listing_id",i);return r?(console.error("fetchMetricSums failed:",r.message),o):((n??[]).forEach(t=>{const e=`${t.listing_id}:${t.platform}`,c=o.get(e)??p(),s=t.metric_type;s in c&&(c[s]+=t.count),o.set(e,c)}),o)}export{S as METRIC_LABELS,k as PLATFORM_METRIC_TYPES,R as fetchMetricSums,v as fetchMetricTimeline,E as fetchMetricTimelines,L as recordEngagementMetric};
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.