1import{r as s}from"./vendor--fUMgQTJ.js";import{i as d}from"./index-BZGD9K13.js";function j(o,c,u,m=3e4){const[S,y]=s.useState(null),[_,i]=s.useState(!1),l=s.useRef(null),f=s.useCallback(async r=>{if(!o)return;i(!0);const n={},a=r.filter(t=>t.sync_mode!=="manual");if(a.length>0&&await Promise.allSettled(a.map(async t=>{try{const{data:e,error:h}=await d.from("donations").select("amount").eq("campaign_id",t.id).in("status",["completed","succeeded"]);if(!h&&e){const p=e.reduce((w,v)=>w+Number(v.amount||0),0);p!==t.current_amount&&(n[t.id]=p)}}catch{}})),Object.keys(n).length>0){u(t=>t.map(e=>n[e.id]!==void 0?{...e,current_amount:n[e.id]}:e));for(const[t,e]of Object.entries(n))d.from("donation_campaigns").update({current_amount:e}).eq("id",t).then()}y(new Date),i(!1)},[o,u]),b=s.useCallback(async()=>{if(o){i(!0);try{const{data:r,error:n}=await d.functions.invoke("sync-stripe-campaign-donations",{body:{organisation_id:o}});if(n)console.error("Stripe sync error:",n);else if(r!=null&&r.campaign_totals){const a=r.campaign_totals;u(t=>t.map(e=>a[e.id]!==void 0?{...e,current_amount:a[e.id]}:e))}}catch(r){console.error("Stripe sync failed:",r)}y(new Date),i(!1)}},[o,u]);return s.useEffect(()=>{if(!(!o||c.length===0))return f(c),l.current=setInterval(()=>{f(c)},m),()=>{l.current&&clearInterval(l.current)}},[o,c.length,m,f]),{lastSynced:S,isSyncing:_,syncNow:b}}export{j as u};
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.