1import{a as $,u as w,b as B,j as e}from"./query-pTPNpZtY.js";import{u as K,i as M,r as Q,L as A}from"./react-vendor-DXQsCdhI.js";import{u as z,F as R,a as n,b as c,c as d,d as m,e as h,t as U}from"./form-CFrQyFDA.js";import{bD as D,B as y,I as g,bo as V,M as O,o as X,g as u,bu as v,an as G,s as b}from"./index-B5OGvPOn.js";import{t as P}from"./autoTranslate-C28r2bOQ.js";import{A as S}from"./AdminLayout-DWJU8O-h.js";import{I as H}from"./ImageUpload-B5cE7Hlb.js";import{P as T}from"./pencil-C2xdXlSY.js";import"./supabase-C6OG0I2D.js";import"./charts-IsTpienw.js";import"./carousel-CtlbL2Hu.js";import"./tiptap-DaxmquCz.js";import"./layout-grid-DRB2MxP9.js";import"./folder-open-BeXpwn13.js";import"./list-checks-4xDbuwgY.js";import"./upload-mYV-_1BB.js";import"./circle-alert-Dk_20iad.js";const J=X({name:u().min(2,"Nome deve ter no mÃnimo 2 caracteres"),public_title:u().max(120).optional().or(v("")),role:u().optional(),bio:u().optional(),avatar_url:u().url("URL inválida").optional().or(v("")),email:u().email("E-mail inválido").optional().or(v("")),instagram:u().max(100).optional().or(v("")),twitter:u().max(100).optional().or(v(""))});function he(){const{id:a}=K(),_=M(),{toast:q}=D(),I=$(),o=a==="new",{data:r,isLoading:L}=w({queryKey:["admin-author",a],queryFn:async()=>{const{data:s,error:i}=await b.from("authors").select("*").eq("id",a).single();if(i)throw i;return s},enabled:!!a&&!o}),{data:p}=w({queryKey:["author-linked-collections",a],queryFn:async()=>{const{data:s,error:i}=await b.from("collection_authors").select("collection_id, collections:collection_id(id, title, slug)").eq("author_id",a);if(i)throw i;return(s==null?void 0:s.map(l=>l.collections).filter(Boolean))||[]},enabled:!!a&&!o}),{data:j}=w({queryKey:["author-linked-places",a],queryFn:async()=>{const{data:s,error:i}=await b.from("place_item_authors").select("place_item_id, place_items:place_item_id(id, title, slug, kind)").eq("author_id",a);if(i)throw i;return(s||[]).map(l=>l.place_items).filter(l=>l!=null)},enabled:!!a&&!o}),t=z({resolver:U(J),defaultValues:{name:"",public_title:"",role:"",bio:"",avatar_url:"",email:"",instagram:"",twitter:""}});Q.useEffect(()=>{r&&t.reset({name:r.name||"",public_title:r.public_title||"",role:r.role||"",bio:r.bio||"",avatar_url:r.avatar_url||"",email:r.email||"",instagram:r.instagram||"",twitter:r.twitter||""})},[r,t]);const N=B({mutationFn:async s=>{let i=(r==null?void 0:r.slug)||"";if(!i){const x=G(s.name);let f=x,F=1;for(;;){const C=b.from("authors").select("id").eq("slug",f).limit(1);!o&&a&&C.neq("id",a);const{data:E,error:k}=await C;if(k)throw k;if(!E||E.length===0)break;F+=1,f=`${x}-${F}`}i=f}const l={name:s.name,slug:i,public_title:s.public_title||null,role:s.role||null,bio:s.bio||null,avatar_url:s.avatar_url||null,email:s.email||null,instagram:s.instagram||null,twitter:s.twitter||null};if(o){const{data:x,error:f}=await b.from("authors").insert(l).select("id").single();if(f)throw f;P("author",x.id)}else{const{error:x}=await b.from("authors").update(l).eq("id",a);if(x)throw x;P("author",a,{force:!0})}},onSuccess:()=>{I.invalidateQueries({queryKey:["admin-authors"]}),q({title:o?"Autor criado com sucesso":"Autor atualizado com sucesso"}),_("/admin/authors")},onError:s=>{q({title:"Erro ao salvar",description:s.message,variant:"destructive"})}});return L&&!o?e.jsx(S,{title:"Carregando...",children:e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx("span",{className:"text-muted-foreground",children:"Carregando..."})})}):e.jsxs(S,{title:o?"Novo Autor":`Editar Autor: ${(r==null?void 0:r.name)||""}`,children:[e.jsxs("div",{className:"flex items-center justify-end gap-3 mb-6",children:[e.jsx(y,{type:"button",variant:"outline",onClick:()=>_("/admin/authors"),children:"Voltar"}),e.jsx(y,{type:"submit",form:"author-form",disabled:N.isPending||!o&&!t.formState.isDirty,children:N.isPending?"Salvando...":"Salvar"})]}),e.jsxs("div",{className:"mx-auto max-w-2xl",children:[e.jsx(R,{...t,children:e.jsxs("form",{id:"author-form",onSubmit:t.handleSubmit(s=>N.mutate(s)),className:"space-y-6",children:[e.jsxs("div",{className:"flex gap-6 items-start",children:[e.jsx(n,{control:t.control,name:"avatar_url",render:({field:s})=>e.jsxs(c,{className:"shrink-0",children:[e.jsx(d,{children:e.jsx(H,{value:s.value,onChange:s.onChange,folder:"avatars",aspectRatio:"square",className:"w-[120px]"})}),e.jsx(m,{})]})}),e.jsxs("div",{className:"flex-1 space-y-4",children:[e.jsx(n,{control:t.control,name:"name",render:({field:s})=>e.jsxs(c,{children:[e.jsx(h,{children:"Nome *"}),e.jsx(d,{children:e.jsx(g,{placeholder:"Nome do autor",...s})}),e.jsx(m,{})]})}),e.jsx(n,{control:t.control,name:"public_title",render:({field:s})=>e.jsxs(c,{children:[e.jsx(h,{children:"TÃtulo público"}),e.jsx(d,{children:e.jsx(g,{placeholder:"Ex: nome do canal/coluna (opcional)",...s})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Quando preenchido, substitui o nome do autor nas páginas públicas (cards e créditos). Na página do próprio autor, ambos são exibid
1os."}),e.jsx(m,{})]})}),e.jsx(n,{control:t.control,name:"role",render:({field:s})=>e.jsxs(c,{children:[e.jsx(h,{children:"Cargo"}),e.jsx(d,{children:e.jsx(g,{placeholder:"Ex: Sommelier, Editor, Product Owner",...s})}),e.jsx(m,{})]})})]})]}),e.jsx(n,{control:t.control,name:"bio",render:({field:s})=>e.jsxs(c,{children:[e.jsx(h,{children:"Biografia"}),e.jsx(d,{children:e.jsx(V,{placeholder:"Uma breve descrição sobre o autor...",className:"min-h-[120px]",...s})}),e.jsx(m,{})]})}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-3",children:[e.jsx(n,{control:t.control,name:"email",render:({field:s})=>e.jsxs(c,{children:[e.jsx(h,{children:"E-mail"}),e.jsx(d,{children:e.jsx(g,{type:"email",placeholder:"[email protected]",...s})}),e.jsx(m,{})]})}),e.jsx(n,{control:t.control,name:"instagram",render:({field:s})=>e.jsxs(c,{children:[e.jsx(h,{children:"Instagram"}),e.jsx(d,{children:e.jsx(g,{placeholder:"@usuario",...s})}),e.jsx(m,{})]})}),e.jsx(n,{control:t.control,name:"twitter",render:({field:s})=>e.jsxs(c,{children:[e.jsx(h,{children:"Twitter / X"}),e.jsx(d,{children:e.jsx(g,{placeholder:"@usuario",...s})}),e.jsx(m,{})]})})]})]})}),!o&&(p&&p.length>0||j&&j.length>0)&&e.jsxs("div",{className:"mt-8 space-y-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-muted-foreground uppercase tracking-wider",children:"Itens vinculados"}),p&&p.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{className:"text-sm font-medium",children:["Coleções (",p.length,")"]}),e.jsx("div",{className:"rounded-lg border border-border/60 divide-y divide-border/40",children:p.map(s=>e.jsxs("div",{className:"flex items-center justify-between px-4 py-2.5",children:[e.jsx("span",{className:"text-sm",children:s.title}),e.jsx(y,{variant:"ghost",size:"icon",className:"h-7 w-7",asChild:!0,children:e.jsx(A,{to:`/admin/collections/${s.id}`,children:e.jsx(T,{className:"h-3.5 w-3.5"})})})]},s.id))})]}),j&&j.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{className:"text-sm font-medium",children:["Lugares (",j.length,")"]}),e.jsx("div",{className:"rounded-lg border border-border/60 divide-y divide-border/40",children:j.map(s=>e.jsxs("div",{className:"flex items-center justify-between px-4 py-2.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(O,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"text-sm",children:s.title})]}),e.jsx(y,{variant:"ghost",size:"icon",className:"h-7 w-7",asChild:!0,children:e.jsx(A,{to:`/admin/places/${s.id}`,children:e.jsx(T,{className:"h-3.5 w-3.5"})})})]},s.id))})]})]})]})]})}export{he as default};
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.