1import{r as n,j as e}from"./vendor-react-CoH7wDUq.js";import{ak as R,al as z}from"./AdminApp-DKqxBNNv.js";import{p as X}from"./index-DarzfxaQ.js";import"./vendor-pdf-DNjb9-t8.js";const g={posX:50,posY:50,zoom:1,brightness:1,sharpness:1},P="rounded-lg bg-blue-600 px-4 py-2.5 text-sm font-semibold text-white shadow-sm transition hover:bg-blue-700 disabled:opacity-50";function C(o){return{atracao:"Atração",hospedagem:"Hospedagem",restaurante:"Restaurante",servico:"Serviço"}[o]||o}function Y(o){const d=String(o||"").trim();if(d)return/^https?:\/\//i.test(d)?d:X(d.replace(/^\//,""))}function _(){const[o,d]=n.useState(""),[w,x]=n.useState([]),[f,p]=n.useState([]),[k,h]=n.useState(!1),[F,E]=n.useState(!1),[j,N]=n.useState(!1),[I,m]=n.useState(""),[q,u]=n.useState(""),[a,v]=n.useState(null),[l,i]=n.useState(()=>({...g})),b=n.useRef(null),y=n.useRef(0);n.useLayoutEffect(()=>{const s=document.getElementById("admin-main-scroll");s&&(s.scrollTop=0),window.scrollTo(0,0)},[]),n.useEffect(()=>{const s=o.trim();if(b.current&&clearTimeout(b.current),s.length<2){p([]),h(!1);return}return h(!0),b.current=setTimeout(()=>{const t=++y.current;R(s).then(r=>{t===y.current&&p(r)}).catch(()=>{t===y.current&&p([])}).finally(()=>{t===y.current&&h(!1)})},280),()=>{b.current&&clearTimeout(b.current)}},[o]);const D=n.useCallback(async s=>{s==null||s.preventDefault(),m(""),u("");const t=o.trim();if(!t){x([]);return}E(!0);try{const r=await R(t);p([]),h(!1),x(r),r.length===1&&(v(r[0]),i(r[0].cardImageFraming?{...r[0].cardImageFraming}:{...g}))}catch(r){m(r instanceof Error?r.message:"Erro na pesquisa"),x([])}finally{E(!1)}},[o]),A=s=>{v(s),i(s.cardImageFraming?{...s.cardImageFraming}:{...g}),u(""),m("")},L=(s,t)=>{A(s),x(t.length?t:[s]),p([]),h(!1)},T=async()=>{if(a){N(!0),m(""),u("");try{const{cardImageFraming:s}=await z(a.id,l);u("Enquadramento guardado na base. A página inicial pública mostrará o resultado após recarregar.");const t=s;v(r=>r&&{...r,cardImageFraming:t}),x(r=>r.map(S=>S.id===a.id?{...S,cardImageFraming:t}:S)),i(t?{...t}:{...g})}catch(s){m(s instanceof Error?s.message:"Erro ao guardar")}finally{N(!1)}}},$=async()=>{if(a){N(!0),m(""),u("");try{await z(a.id,{clear:!0}),u("Ajustes do cartão removidos (volta ao padrão no site)."),i({...g}),v(s=>s&&{...s,cardImageFraming:null}),x(s=>s.map(t=>t.id===a.id?{...t,cardImageFraming:null}:t))}catch(s){m(s instanceof Error?s.message:"Erro ao limpar")}finally{N(!1)}}},c=Y((a==null?void 0:a.imageUrl)??null);return e.jsxs("div",{className:"max-w-5xl space-y-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-bold text-slate-800 md:text-2xl",style:{fontFamily:"'Poppins', sans-serif"},children:"Ajuste de imagens"}),e.jsx("p",{className:"mt-1 text-sm text-slate-600",children:'Pesquise por nome, slug ou texto da descrição, selecione um local e ajuste como a foto aparece nos cartões da secção "Nossos associados" na home (igual ao enquadramento do hero em Config. do site).'})]}),e.jsxs("div",{className:"rounded-xl border border-slate-200 bg-white p-4 shadow-sm md:p-6",children:[e.jsxs("form",{onSubmit:s=>void D(s),className:"flex flex-col gap-3 sm:flex-row sm:items-end",children:[e.jsxs("div",{className:"relative min-w-0 flex-1",children:[e.jsx("label",{htmlFor:"admin-card-img-q",className:"block text-sm font-medium text-slate-700",children:"Pesquisar cartão"}),e.jsx("input",{id:"admin-card-img-q",value:o,onChange:s=>d(s.target.value),autoComplete:"off",placeholder:"Comece a escrever (2+ letras) â sugestões aparecem abaixo",className:"mt-2 w-full rounded-lg border border-slate-300 px-3 py-2 text-sm","aria-autocomplete":"list","aria-controls":"admin-card-img-suggestions","aria-expanded":o.trim().length>=2}),o.trim().length>=2?e.jsxs("div",{id:"admin-card-img-suggestions",className:"absolute left-0 right-0 top-full z-30 mt-1 max-h-56 overflow-auto rounded-lg border border-slate-200 bg-white py-1 shadow-lg",role:"listbox",children:[k&&f.length===0?e.jsx("p",{className:"px-3 py-2 text-xs text-slate-500",children:"A procurarâ¦"}):null,f.map(s=>e.jsxs("button",{type:"button",role:"option",onMouseDown:t=>{t.preventDefault(),L(s,f)},className:"flex w-full flex-col gap-0.5 px-3 py-2.5 text-left text-sm hover:bg-blue-50",children:[e.jsx("span",{className:"font-medium text-slate-900",children:s.nome}),e.jsxs("span",{className:"text-xs text-slate-500",children:[C(s.categoria)," · ",s.slug]})]},s.id)),!k&&f.length===0?e.jsx("p",{className:"px-3 py-2 text-xs text-slate-500",children:"Nenhum resultado â tente outro termo."}):null]}):null]}),e.jsx("button",{type:"submit",disabled:F,className:P,children:F?"A pesquisarâ¦":"Pesquisar"})]}),I?e.jsx("div",{className:"mt-4 rounded-lg border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-800",children:I}):null,q?e.jsx("div",{className:"mt-4 rounded-lg border border-emerald-200 bg-emerald-50 px-4 py-3 text-sm text-emerald-900",children:q}):null,w.length>0?e.jsxs("div",{className:"mt-6",children:[e.jsxs("p",{className:"text-sm font-semibold text-slate-800",children:["Resultados (",w.length,")"]}),e.jsx("ul",{className:"mt-2 max-h-52 divide-y divide-slate-200 overflow-auto rounded-lg border border-slate-200 bg-slate-50/50",children:w.map(s=>e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:()=>A(s),className:`flex w-full flex-col gap-0.5 px-4 py-3 text-left text-sm transition hover:bg-white ${(a==null?void 0:a.id)===s.id?"bg-blue-50":""}`,children:[e.jsx("span",{className:"font-semibold text-slate-900",children:s.nome}),e.jsxs("span",{className:"text-xs text-slate-500",children:[C(s.categoria)," · slug: ",s.slug]})]})},s.id))})]}):null]}),a?e.jsxs("div",{className:"rounded-xl border border-slate-200 bg-white p-4 shadow-sm md:p-6",children:[e.jsx("h2",{className:"text-lg font-bold text-slate-800",children:"Cartão selecionado"}),e.jsxs("p",{className:"mt-1 text-sm text-slate-600",children:[e.jsx("strong",{children:a.nome})," · ",C(a.categoria)," · id ",a.id]}),e.jsxs("div",{className:"mt-6 flex flex-col gap-6 lg:flex-row",children:[e.jsxs("div",{className:"mx-auto w-full max-w-sm shrink-0",children:[e.jsx("p",{className:"mb-2 text-xs font-semibold uppercase tracking-wider text-slate-500",children:"Pré-visualização"}),e.jsx("div",{className:"h-56 overflow-hidden rounded-2xl border border-slate-200 bg-slate-200",children:c?e.jsx("div",{className:"h-full w-full",style:{transform:`scale(${l.zoom})`,transformOrigin:"center center"},children:e.jsx("img",{src:c,alt:"",className:"h-full w-full object-cover",style:{objectPosition:`${l.posX}% ${l.posY}%`,filter:`brightness(${l.brightness}) contrast(${l.sharpness})`}})}):e.jsx("div",{className:"flex h-full items-center justify-center text-sm text-slate-500",children:"Sem imagem no cadastro"})})]}),e.jsxs("div",{className:"min-w-0 flex-1 space-y-4",children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("label",{className:"text-xs text-slate-600",children:[e.jsx("span",{className:"mb-1 block font-medium text-slate-700",children:"Horizontal"}),e.jsx("input",{type:"range",min:0,max:100,value:l.posX,disabled:!c,onChange:s=>i(t=>({...t,posX:Number(s.target.value)})),className:"w-full"}),e.jsxs("span",{className:"text-[11px] text-slate-500",children:[l.posX,"%"]})]}),e.jsxs("label",{className:"text-xs text-slate-600",children:[e.jsx("span",{className:"mb-1 block font-medium text-slate-700",children:"Vertical"}),e.jsx("input",{type:"range",min:0,max:100,value:l.posY,disabled:!c,onChange:s=>i(t=>({...t,posY:Number(s.target.value)})),className:"w-full"}),e.jsxs("span",{className:"text-[11px] text-slate-500",children:[l.posY,"%"]})]}),e.jsxs("label",{className:"text-xs text-slate-600",children:[e.jsx("span",{className:"mb-1 block font-medium text-slate-700",children:"Zoom"}),e.jsx("input",{type:"range",min:1,max:3,step:.01,value:l.zoom,disabled:!c,onChange:s=>i(t=>({...t,zoom:Number(s.target.value)})),className:"w-full"}),e.jsxs("span",{className:"text-[11px] text-slate-500",children:[l.zoom.toFixed(2),"Ã"]})]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("label",{className:"text-xs text-slate-600",children:[e.jsx("span",{className:"mb-1 block font-medium text-slate-700",children:"Brilho"}),e.jsx("input",{type:"range",min:.25,max:2,step:.01,value:l.brightness,disabled:!c,onChange:s=>i(t=>({...t,brightness:Number(s.target.value)})),className:"w-full"}),e.jsxs("span",{className:"text-[11px] text-slate-500",children:[l.brightness.toFixed(2),"Ã"]})]}),e.jsxs("label",{className:"text-xs text-slate-600",children:[e.jsx("span",{className:"mb-1 block font-medium text-slate-700",children:"Contraste"}),e.jsx("input",{type:"range",min:.25,max:3,step:.01,value:l.sharpness,disabled:!c,onChange:s=>i(t=>({...t,sharpness:Number(s.target.value)})),className:"w-full"}),e.jsxs("span",{className:"text-[11px] text-slate-500",children:[l.sharpness.toFixed(2),"Ã"]})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",disabled:j||!c,onClick:()=>void T(),className:P,children:j?"A guardarâ¦":"Guardar na base"}),e.jsx("button",{type:"button",disabled:j,onClick:()=>i({...g}),className:"rounded-lg border border-slate-300 bg-white px-4 py-2.5 text-sm font-semibold text-slate-700 hover:bg-slate-50 disabled:opacity-50",children:"Repor controlos"}),e.jsx("button",{type:"button",disabled:j,onClick:()=>void $(),className:"rounded-lg border border-red-200 bg-red-50 px-4 py-2.5 text-sm font-semibold text-red-800 hover:bg-red-100 disabled:opacity-50",children:"Remover ajustes guardados"})]})]})]})]}):e.jsx("p",{className:"text-center text-sm text-slate-500",children:"Pesquise e escolha um local na lista para ajustar a imagem do cartão."})]})}
1export{_ 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.