1import{s}from"./index-CzijiWpJ.js";async function f(){try{const{data:e,error:r}=await s.from("alerts").select("*").order("created_at",{ascending:!0});return r?(console.warn("[alerts] fetchMyAlerts:",r.message),[]):e||[]}catch(e){return console.warn("[alerts] fetchMyAlerts failed:",e),[]}}async function g(){return(await f())[0]||null}async function _(e){try{const{data:{user:r}}=await s.auth.getUser();if(!r)return{ok:!1,error:"not_authenticated"};const t={user_id:r.id,country:e.country,city:e.city,fuel_type:e.fuel_type,brand:e.brand||null,station_id:e.station_id||null,threshold_price:e.threshold_price,direction:e.direction||"below",is_active:e.is_active!==void 0?e.is_active:!0},{data:a,error:o}=await s.from("alerts").upsert(t,{onConflict:"user_id,country,city,fuel_type"}).select().single();return o?(console.error("[alerts] saveAlert:",o.message),{ok:!1,error:o.message}):{ok:!0,alert:a}}catch(r){return console.error("[alerts] saveAlert failed:",r),{ok:!1,error:r==null?void 0:r.message}}}async function k(e){try{const{data:{user:r}}=await s.auth.getUser();if(!r)return{ok:!1,error:"not_authenticated"};const{error:t}=await s.from("alerts").delete().eq("id",e).eq("user_id",r.id);return t?{ok:!1,error:t.message}:{ok:!0}
1}catch(r){return{ok:!1,error:r==null?void 0:r.message}}}async function m({country:e,city:r,fuel_type:t}){try{const{data:{user:a}}=await s.auth.getUser();if(!a)return{ok:!1,error:"not_authenticated"};const{error:o}=await s.from("alerts").delete().eq("user_id",a.id).eq("country",e).eq("city",r).eq("fuel_type",t);return o?{ok:!1,error:o.message}:{ok:!0}}catch(a){return{ok:!1,error:a==null?void 0:a.message}}}async function h(){try{const{data:{user:e}}=await s.auth.getUser();if(!e)return{ok:!1,error:"not_authenticated"};const{error:r}=await s.from("alerts").delete().eq("user_id",e.id);return r?{ok:!1,error:r.message}:{ok:!0}}catch(e){return{ok:!1,error:e==null?void 0:e.message}}}async function w(e,r){try{const{data:{user:t}}=await s.auth.getUser();if(!t)return{ok:!1,error:"not_authenticated"};const{data:a,error:o}=await s.from("alerts").update({is_active:r}).eq("id",e).eq("user_id",t.id).select().maybeSingle();return o?{ok:!1,error:o.message}:{ok:!0,alert:a}}catch(t){return{ok:!1,error:t==null?void 0:t.message}}}async function q({country:e,city:r,network:t,threshold_price:a,direction:o}){try{const{data:{user:n}}=await s.auth.getUser();if(!n)return{ok:!1,error:"not_authenticated"};let i=s.from("alerts").select("id").eq("user_id",n.id).eq("country",e).eq("city",r).eq("alert_kind","ev");i=t?i.eq("network",t):i.is("network",null);const{data:u}=await i.maybeSingle(),c={user_id:n.id,country:e,city:r,alert_kind:"ev",network:t||null,fuel_type:null,threshold_price:a,direction:o||"below",is_active:!0},{data:d,error:l}=u?await s.from("alerts").update(c).eq("id",u.id).select().single():await s.from("alerts").insert(c).select().single();return l?(console.error("[alerts] saveEvAlert:",l.message),{ok:!1,error:l.message}):{ok:!0,alert:d}}catch(n){return console.error("[alerts] saveEvAlert failed:",n),{ok:!1,error:n==null?void 0:n.message}}}async function v({country:e,city:r,network:t}){try{const{data:{user:a}}=await s.auth.getUser();if(!a)return{ok:!1,error:"not_authenticated"};let o=s.from("alerts").delete().eq("user_id",a.id).eq("country",e).eq("city",r).eq("alert_kind","ev");o=t?o.eq("network",t):o.is("network",null);const{error:n}=await o;return n?{ok:!1,error:n.message}:{ok:!0}
1}catch(a){return{ok:!1,error:a==null?void 0:a.message}}}export{h as deleteAlert,k as deleteAlertById,m as deleteAlertByScope,v as deleteEvAlertByScope,g as fetchMyAlert,f as fetchMyAlerts,_ as saveAlert,q as saveEvAlert,w as toggleAlertActive};
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.