var e=Object.defineProperty,t=Object.defineProperties,o=Object.getOwnPropertyDescriptors,n=Object.getOwnPropertySymbols,r=Object.prototype.hasOwnProperty,a=Object.prototype.propertyIsEnumerable,c=(t,o,n)=>o in t?e(t,o,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[o]=n,i=(e,t,o)=>new Promise((n,r)=>{var a=e=>{try{i(o.next(e))}catch(t){r(t)}},c=e=>{try{i(o.throw(e))}catch(t){r(t)}},i=e=>e.done?n(e.value):Promise.resolve(e.value).then(a,c);i((o=o.apply(e,t)).next())});import{r as s}from"./vendor-uppOmrO1-1766272187855.js";const d="https://enkijdqewoikjczpfgch.supabase.co",l="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImVua2lqZHFld29pa2pjenBmZ2NoIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTYxMjY1NDgsImV4cCI6MjA3MTcwMjU0OH0.jti_3Veh6rH12-_WcVKgnbFvpsPVu_CLjY5GLvVpBBk",p="390cbdab-ad64-4033-b5ef-6ba72c5336a5",u=()=>{const[e,u]=s.useState([]),[h,y]=s.useState([]),[f,m]=s.useState(!1),[g,b]=s.useState(null),v=e=>i(void 0,null,function*(){try{const t=yield fetch("".concat(d,"/rest/v1/blog_posts?id=eq.").concat(e,"&select=views"),{headers:{apikey:l,Authorization:"Bearer ".concat(l)}}),o=yield t.json();if(o[0]){const t=(o[0].views||0)+1;yield fetch("".concat(d,"/rest/v1/blog_posts?id=eq.").concat(e),{method:"PATCH",headers:{apikey:l,Authorization:"Bearer ".concat(l),"Content-Type":"application/json"},body:JSON.stringify({views:t})})}}catch(t){}});return{posts:e,categories:h,loading:f,error:g,fetchPosts:(...e)=>i(void 0,[...e],function*(e={}){m(!0),b(null);try{const{limit:i=10,categoryId:s,status:h="published",featured:y}=e;let f="".concat(d,"/rest/v1/blog_posts");const m=new URLSearchParams;m.append("select","\n id,\n title,\n slug,\n content,\n excerpt,\n featured_image,\n author_id,\n status,\n featured,\n meta_title,\n meta_description,\n tags,\n reading_time,\n views,\n likes,\n published_at,\n created_at,\n updated_at,\n category_id\n "),m.append("site_id","eq.".concat(p)),m.append("status","eq.".concat(h)),m.append("limit",i.toString()),m.append("order","published_at.desc"),void 0!==y&&m.append("featured","eq.".concat(y)),s&&m.append("category_id","eq.".concat(s)),f+="?"+m.toString();const g=yield fetch(f,{method:"GET",headers:{apikey:l,Authorization:"Bearer ".concat(l),"Content-Type":"application/json",Accept:"application/json"}});if(!g.ok)throw new Error("Erro ao buscar posts: ".concat(g.status));const b=(yield g.json()).map(e=>{var i,s,d;return s=((e,t)=>{for(var o in t||(t={}))r.call(t,o)&&c(e,o,t[o]);if(n)for(var o of n(t))a.call(t,o)&&c(e,o,t[o]);return e})({},e),d={featured_image:(null==(i=e.featured_image)?void 0:i.trim())||void 0},t(s,o(d))});return u(b),b}catch(i){const e=i instanceof Error?i.message:"Erro desconhecido";return b(e),[]}finally{m(!1)}}),fetchPost:e=>i(void 0,null,function*(){m(!0),b(null);try{const t="".concat(d,"/rest/v1/blog_posts?slug=eq.").concat(e,"&site_id=eq.").concat(p,"&status=eq.published&limit=1"),o=yield fetch(t,{method:"GET",headers:{apikey:l,Authorization:"Bearer ".concat(l),"Content-Type":"application/json"}});if(!o.ok)throw new Error("Erro ao buscar post: ".concat(o.status));const n=(yield o.json())[0]||null;return n&&n.featured_image&&(n.featured_image=n.featured_image.trim()),n&&(yield v(n.id)),n}catch(t){const e=t instanceof Error?t.message:"Erro desconhecido";return b(e),null}finally{m(!1)}}),fetchCategories:()=>i(void 0,null,function*(){m(!0),b(null);try{const e="".concat(d,"/rest/v1/blog_categories?site_id=eq.").concat(p,"&is_active=eq.true&order=name"),t=yield fetch(e,{method:"GET",headers:{apikey:l,Authorization:"Bearer ".concat(l),"Content-Type":"application/json"}});if(!t.ok)throw new Error("Erro ao buscar categorias: ".concat(t.status));const o=yield t.json();return y(o),o}catch(e){const t=e instanceof Error?e.message:"Erro desconhecido";return b(t),[]}finally{m(!1)}}),incrementViews:v}};export{u};