1import{u as S,r as l,W as n}from"./main-DX7XzkoU.js";const F=()=>{const{user:i}=S(),[y,d]=l.useState([]),[u,f]=l.useState(null),[m,s]=l.useState(!0),[E,o]=l.useState(null),p=l.useCallback(async()=>{try{if(s(!0),o(null),!i)return;const{data:t,error:e}=await n.from("bio_pages").select("*").eq("user_id",i.id).order("created_at",{ascending:!1});if(e)throw e;d(t)}catch(t){o(t instanceof Error?t.message:"Failed to fetch bio pages")}finally{s(!1)}},[i]),_=l.useCallback(async t=>{try{s(!0),o(null);const{data:e,error:r}=await n.from("bio_pages").select("*").eq("id",t).single();if(r)throw r;return f(e),e}catch(e){return o(e instanceof Error?e.message:"Failed to fetch bio page"),null}finally{s(!1)}},[]),P=l.useCallback(async t=>{try{if(s(!0),o(null),!i)return null;const{data:e,error:r}=await n.from("bio_pages").select("*").eq("user_id",i.id).eq("instagram_profile_id",t).order("created_at",{ascending:!1}).limit(1).maybeSingle();if(r)throw r;return e&&f(e),e}catch(e){return o(e instanceof Error?e.message:"Failed to fetch bio page by instagram profile"),null}finally{s(!1)}},[i]),g=l.useCallback(async(t,e)=>{try{let r=n.from("bio_pages").select("id").eq("slug",t);e&&(r=r.neq("id",e));const{data:a}=await r;return!a||a.length===0}catch{return!1}},[]),k=l.useCallback(async t=>{try{if(s(!0),o(null),!i)throw new Error("User not authenticated");if(!await g(t.slug))throw new Error("Este slug já está em uso. Escolha outro.");const{data:r,error:a}=await n.from("bio_pages").insert({...t,user_id:i.id}).select().single();if(a)throw a;const c=r;return d(h=>[c,...h]),c}catch(e){const r=e instanceof Error?e.message:"Failed to create bio page";throw o(r),new Error(r)}finally{s(!1)}},[i,g]),b=l.useCallback(async(t,e)=>{try{if(s(!0),o(null),e.slug&&!await g(e.slug,t))throw new Error("Este slug já está em uso. Escolha outro.");const{data:r,error:a}=await n.from("bio_pages").update({...e,updated_at:new Date().toISOString()}).eq("id",t).select().single();if(a)throw a;const c=r;return d(h=>h.map(w=>w.id===t?c:w)),f(c),c}catch(r){const a=r instanceof Error?r.message:"Failed to update bio page";throw o(a),new Error(a)}finally{s(!1)}},[g]),q=l.useCallback(async t=>{try{s(!0),o(null);const{error:e}=await n.from("bio_pages").delete().eq("id",t);if(e)throw e;d(r=>r.filter(a=>a.id!==t)),(u==null?void 0:u.id)===t&&f(null)}catch(e){const r=e instanceof Error?e.message:"Failed to delete bio page";throw o(r),new Error(r)}finally{s(!1)}},[u]),C=l.useCallback(async(t,e)=>b(t,{is_published:e}),[b]);return{pages:y,currentPage:u,loading:m,error:E,fetchPages:p,fetchPageById:_,fetchPageByInstagramProfileId:P,checkSlugAvailability:g,createPage:k,updatePage:b,deletePage:q,togglePublish:C,setCurrentPage:f}};export{F 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.