var r=(e,t,n)=>new Promise((o,u)=>{var d=i=>{try{s(n.next(i))}catch(c){u(c)}},f=i=>{try{s(n.throw(i))}catch(c){u(c)}},s=i=>i.done?o(i.value):Promise.resolve(i.value).then(d,f);s((n=n.apply(e,t)).next())});import{cb as w,bf as l}from"./bootstrap-Bqxdt4iG.js";import{A as g}from"./announcements-BeK93bSh.js";const A=[{value:g.NORMAL,label:"Normal",color:"default"},{value:g.IMPORTANT,label:"Important",color:"processing"},{value:g.URGENT,label:"Urgent",color:"error"}],b=w("announcements",{state:()=>({version:0}),getters:{isMockMode:()=>!1},actions:{getList(e){return r(this,null,function*(){var c,a;let t=l.from("announcements").select("*",{count:"exact"});t=t.eq("isDelete",!1),e!=null&&e.title&&(t=t.ilike("title",`%${e.title}%`)),e!=null&&e.priority&&(t=t.eq("priority",e.priority)),t=e!=null&&e.sortBy?t.order(e.sortBy,{ascending:e.sortOrder!=="desc"}):t.order("publishedAt",{ascending:!1});const n=(c=e==null?void 0:e.page)!=null?c:1,o=(a=e==null?void 0:e.pageSize)!=null?a:10,u=(n-1)*o,d=u+o-1;t=t.range(u,d);const{data:f,error:s,count:i}=yield t;if(s)throw s;return{items:f!=null?f:[],total:i!=null?i:0,page:n,pageSize:o}})},getActive(e=5){return r(this,null,function*(){const t=new Date().toISOString(),{data:n,error:o}=yield l.from("announcements").select("*").eq("isDelete",!1).lte("publishedAt",t).or(`expiresAt.is.null,expiresAt.gt.${t}`).order("priority",{ascending:!1}).order("publishedAt",{ascending:!1}).limit(e);if(o)throw o;return n!=null?n:[]})},getDetail(e){return r(this,null,function*(){const{data:t,error:n}=yield l.from("announcements").select("*").eq("id",e).eq("isDelete",!1).single();if(n)throw n;return t})},create(e){return r(this,null,function*(){const{data:t,error:n}=yield l.from("announcements").insert(e).select().single();if(n||!t)throw n!=null?n:new Error("Create failed");return this.version++,t})},update(e,t){return r(this,null,function*(){const{data:n,error:o}=yield l.from("announcements").update(t).eq("id",e).select().single();if(o)throw o;return this.version++,n})},remove(e){return r(this,null,function*(){const{error:t}=yield l.from("announcements").update({isDelete:!0}).eq("id",e);if(t)throw t;return this.version++,!0})},invalidate(){this.version++}}});export{A as a,b as u};
