1import{o as T,aJ as k,e as w,t as $,i as g,aK as R,j as e,l as z,r as n,L as O,aL as U}from"./index-B-idN6ke.js";import{A as B,t as m}from"./AdminLayout-8C7-CnjE.js";import{C}from"./CampoTextoLeve-AX-0tQ6c.js";import{u,O as D,m as h,I as V}from"./fields-Bm8LbIpQ.js";import{B as x}from"./button-BL94M8ii.js";import{I as p,m as G}from"./erros-CBRup9Qc.js";import{L}from"./label-CKAyPMHe.js";import{E as J}from"./external-link-AIty2drp.js";import{P as I}from"./plus-JN9dpJp2.js";import{A as K}from"./arrow-left-CaWY7oWj.js";import{L as M}from"./index-D-ot6EFf.js";import"./logo-ceap-white-CVcuEPIZ.js";import"./x-CyS2atpu.js";import"./TextoLeve-DuEdbHUn.js";import"./dialog-Cd_1n5aM.js";import"./alert-dialog-Cz5s-iOl.js";import"./index-BHyEgwHv.js";import"./url-CEpkYIRk.js";import"./trash-2-BSQU5kk6.js";const _=T({heading:g().trim().max(160),body:k}),H=T({slug:g().regex(/^[a-z0-9-]{2,60}$/),titulo:g().trim().min(1,"Informe o tÃtulo da página.").max(120),subtitulo:g().trim().max(160),intro:k,secoes:w(_).max(20),fotos:w($).max(5,"Limite de 5 fotos")});function pe(){const r=R.useLoaderData();return e.jsx(Q,{pagina:r},r.slug)}function Q({pagina:r}){const A=z(),[f,E]=n.useState(r.titulo),[v,P]=n.useState(r.subtitulo),[b,q]=n.useState(r.intro),[i,d]=n.useState(()=>r.secoes.map(a=>({chave:u(),heading:a.heading,body:a.body}))),[l,c]=n.useState(()=>r.fotos.map(a=>({chave:u(),arquivoId:a.arquivoId,alt:a.alt}))),[j,N]=n.useState(!1),y=(a,o)=>d(s=>s.map(t=>t.chave===a?{...t,...o}:t)),S=(a,o)=>c(s=>s.map(t=>t.chave===a?{...t,...o}:t));async function F(){if(!f.trim()){m.error("Informe o tÃtulo da página.");return}const a=l.findIndex(s=>!s.arquivoId);if(a!==-1){m.error(`A foto ${a+1} da galeria está sem imagem.`);return}const o=H.safeParse({slug:r.slug,titulo:f,subtitulo:v,intro:b,secoes:i.map(({heading:s,body:t})=>({heading:s,body:t})),fotos:l.map(({arquivoId:s,alt:t})=>({arquivoId:s,alt:t}))});if(!o.success){m.error(o.error.issues[0]?.message??"Verifique os campos.");return}N(!0);try{await U({data:o.data}),m.success("Página salva com sucesso"),await A.invalidate()}catch(s){m.error(G(s,"Não foi possÃvel salvar a página."))}finally{N(!1)}}return e.jsx(B,{title:`Página: ${r.rotulo}`,description:"Altere os textos e as fotos da página deste diferencial. O card da página inicial se edita em Seções.",actions:e.jsxs("div",{className:"flex gap-2",children:[e.jsx(x,{asChild:!0,variant:"outline",children:e.jsxs(O,{to:"/admin/secoes",children:[e.jsx(K,{className:"mr-2 h-4 w-4"})," Voltar"]})}),e.jsxs(x,{className:"bg-ceap-blue hover:bg-ceap-blue/90",disabled:j,onClick:F,children:[j&&e.jsx(M,{className:"mr-2 h-4 w-4 animate-spin"}),"Salvar"]})]}),children:e.jsxs("div",{className:"space-y-6",children:[r.ativo?e.jsxs("p",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:["Endereço no site: /diferenciais/",r.slug,e.jsxs("a",{href:`/diferenciais/${r.slug}`,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 underline underline-offset-4",children:["abrir ",e.jsx(J,{className:"h-3 w-3"})]})]}):e.jsx("p",{className:"rounded-xl border border-dashed bg-muted/40 px-4 py-3 text-sm text-muted-foreground",children:"Este diferencial está desativado: a página não abre no site até ser reativado em Seções. O que você salvar aqui fica guardado."}),e.jsxs("div",{className:"space-y-4 rounded-2xl border bg-background p-5 shadow-sm",children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{htmlFor:"t",children:"TÃtulo da página"}),e.jsx(p,{id:"t",value:f,onChange:a=>E(a.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(L,{htmlFor:"s",children:"SubtÃtulo"}),e.jsx(p,{id:"s",value:v,onChange:a=>P(a.target.value)})]})]}),e.jsx(C,{id:"i",label:"Texto de apresentação",value:b,onChange:q})]}),e.jsxs("div",{className:"space-y-4 rounded-2xl border bg-background p-5 shadow-sm",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"font-bold text-ceap-blue",children:"Seções"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[i.length,"/20 seções · cada uma com subtÃtulo e texto."]})]}),e.jsxs(x,{type:"button",variant:"outline",size:"sm",disabled:i.length>=20,onClick:()=>d(a=>a.length>=20?a:[...a,{chave:u(),heading:"",body:""}]),children:[e.jsx(I,{className:"mr-1 h-3.5 w-3.5"})," Adicionar seção"]})]}),i.map((a,o)=>e.jsx("div",{className:"rounded-xl border p-3",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsxs("div",{className:"flex-1 space-y-3",children:[e.jsx(p,{placeholder:"SubtÃtulo da seção","aria-label":`SubtÃtulo da seção ${o+1}`,value:a.heading,onChange:s=>y(a.chave,{heading:s.target.value})}),e.jsx(C,{id:`secao-${a.chave}`,value:a.body,placeholder:"Texto da seção",onChange:s=>y(a.chave,{body:s})})]}),e.jsx(D,{onUp:()=>d(s=>h(s,o,o-1)),onDown:()=>d(s=>h(s,o,o+1)),onRemove:()=>d(s=>s.filter(t=>t.chave!==a.chave)),disableUp:o===0,disableDown:o===i.length-1,confirmTitle:"Excluir esta seção?",confirmDescription:"O subtÃtulo e o texto desta seção serão removidos da página."})]})},a.chave)),i.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"Nenhuma seção ainda."})]}),e.jsxs("div",{className:"space-y-4 rounded-2xl border bg-background p-5 shadow-sm",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"font-bold text-ceap-blue",children:"Galeria"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[l.length,"/5 fotos · limite de 5 fotos por página. Sem foto, a página mostra a imagem do card."]})]}),e.jsxs(x,{type:"button",variant:"outline",size:"sm",disabled:l.length>=5,onClick:()=>c(a=>a.length>=5?a:[...a,{chave:u(),arquivoId:"",alt:""}]),children:[e.jsx(I,{className:"mr-1 h-3.5 w-3.5"})," Adicionar foto"]})]}),e.jsx("div",{className:"grid gap-4 sm:grid-cols-2 lg:grid-cols-3",children:l.map((a,o)=>e.jsxs("div",{className:"space-y-2 rounded-xl border p-3",children:[e.jsx(V,{label:`Foto ${o+1}`,value:a.arquivoId,aspect:"aspect-[4/3]",hint:"1200 x 900 px",maxSizeMB:.8,onChange:s=>S(a.chave,{arquivoId:s})}),e.jsx(p,{placeholder:"Descrição da foto","aria-label":`Descrição da foto ${o+1}`,value:a.alt,onChange:s=>S(a.chave,{alt:s.target.value})}),e.jsx("div",{className:"flex justify-end",children:e.jsx(D,{onUp:()=>c(s=>h(s,o,o-1)),onDown:()=>c(s=>h(s,o,o+1)),onRemove:()=>c(s=>s.filter(t=>t.chave!==a.chave)),disableUp:o===0,disableDown:o===l.length-1,confirmTitle:"Excluir esta foto?",confirmDescription:"A foto será removida da galeria desta página."})})]},a.chave))})]})]})})}export{pe as component};
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.