1import{T as F,u as ae,l as re,r as s,j as e,P as M,d as z,N as O,V as se,L as W,t as i,W as te,X as oe,Y as ne}from"./index-YoOVmf7B.js";import{I as le,A as ie,a as ce,b as de,c as ue,d as me,e as pe,f as ge,g as xe,h as be,i as fe}from"./AddressPicker-BpBX1N_c.js";import{X as he}from"./x-DidePgA0.js";import"./index-BbdjBWTQ.js";function Ce(){const{categories:n}=F.useLoaderData(),{category:l}=F.useSearch(),{user:h,userInfo:d,loading:p}=ae(),g=re(),A=s.useRef(null),L=s.useRef(null),x=s.useRef(null),b=s.useRef([]),[f,G]=s.useState(""),[j,V]=s.useState(""),[y,X]=s.useState(l||""),[v,P]=s.useState(""),[R,_]=s.useState("es"),[D,J]=s.useState(""),[E,Q]=s.useState(!0),[I,Y]=s.useState(!1),[U,N]=s.useState(!1),[C,T]=s.useState([]),[w,$]=s.useState([]),[S,q]=s.useState(!1),B=n.find(a=>a.slug===l);if(s.useEffect(()=>()=>{b.current.forEach(a=>URL.revokeObjectURL(a))},[]),p)return e.jsx(M,{children:e.jsxs("div",{className:"flex min-h-[60vh] items-center justify-center gap-2 text-muted-foreground",children:[e.jsx(z,{className:"h-5 w-5 animate-spin"})," Cargando..."]})});if(!h)return e.jsx(O,{to:"/login",replace:!0});if(!d?.onboardingComplete)return e.jsx(O,{to:"/onboarding",replace:!0});const K=a=>{if(!a)return;const r=[];for(const t of Array.from(a)){if(!["image/jpeg","image/png","image/webp"].includes(t.type)){i.error(`${t.name}: solo se admiten imágenes JPEG, PNG o WebP.`);continue}if(t.size>10*1024*1024){i.error(`${t.name}: la imagen no puede superar los 10 MB.`);continue}const o=URL.createObjectURL(t);b.current.push(o),r.push({file:t,preview:o})}T(t=>{const o=Math.max(0,5-t.length);return r.slice(o).forEach(({preview:u})=>URL.revokeObjectURL(u)),r.length>o&&i.error("Puedes añadir un máximo de 5 imágenes."),[...t,...r.slice(0,o)]}),x.current&&(x.current.value="")},Z=a=>{URL.revokeObjectURL(a),b.current=b.current.filter(r=>r!==a),T(r=>r.filter(t=>t.preview!==a))},ee=async a=>{if(a.preventDefault(),!S){if(!y){i.error("Selecciona una categorÃa.");return}if(w.some(r=>!r.name.trim())){i.error("Indica el nombre de cada sitio añadido.");return}q(!0);try{if(!await L.current?.confirmBeforeSubmit())return;const r=[];for(const m of C)r.push(await te(m.file));const t=await oe(w),o=f.normalize("NFD").replace(/[\u0300-\u036f]/g,"").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,190),u=await ne({slug:o.length>=3?o:`publicacion-${Date.now()}`,title:f.trim(),excerpt:j.trim().slice(0,700),body:j.trim(),categorySlug:y,language:R,location:v.trim(),tags:D.split(",").map(m=>m.trim()).filter(Boolean),commentsEnabled:E,mapVisible:U,recommendation:d.role==="admin"&&I,images:r.map(m=>({url:m.publicUrl,alt:f.trim()})),addresses:t});i.success(u.status==="pending"?"Publicación enviada y pendiente de revisión.":"Publicación creada."),await g(u.status==="pending"?{to:"/comunidad"}:{to:"/post/$postSlug",params:{postSlug:u.slug}})}catch(r){i.error(r instanceof Error?r.message:"No se pudo crear la publicación.")}finally{q(!1)}}};return e.jsx(M,{children:e.jsxs("div",{className:"mx-auto max-w-3xl px-4 py-8 md:px-8",children:[e.jsx("h1",{className:"font-display text-3xl font-semibold",children:"Crear publicación"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Comparte una pregunta, una historia, una recomendación o algo útil para otros asturianos."}),e.jsxs("form",{ref:A,onSubmit:ee,className:"mt-6 space-y-5 rounded-3xl border border-border bg-card p-6 shadow-soft",children:[e.jsx(c,{label:"TÃtulo",children:e.jsx("input",{className:"w-full rounded-xl border border-border bg-surface px-4 py-3 text-base focus:border-secondary focus:outline-none",placeholder:"Un buen tÃtulo capta la atención",value:f,onChange:a=>G(a.target.value),minLength:6,maxLength:240,required:!0})}),B?e.jsx("input",{type:"hidden",name:"category",value:B.slug}):e.jsx(c,{label:"CategorÃa",children:e.jsxs("select",{name:"category",value:y,onChange:a=>X(a.target.value),required:!0,className:"w-full rounded-xl border border-border bg-surface px-4 py-3 text-base focus:border-secondary focus:outline-none",children:[e.jsx("option",{value:"",children:"Selecciona una categorÃa"}),n.map(a=>e.jsx("option",{value:a.slug,children:a.name},a.id))]})}),e.jsx(c,{label:"Texto",children:e.jsx("textarea",{rows:8,className:"w-full rounded-xl border border-border bg-surface px-4 py-3 text-base focus:border-secondary focus:outline-none",placeholder:"Cuenta tu historia, pregunta o recomendaciónâ¦",value:j,onChange:a=>V(a.target.value),minLength:10,maxLength:5e4,required:!0})}),e.jsxs(c,{label:"Fotos",children:[e.jsxs("button",{type:"button",onClick:()=>x.current?.click(),className:"flex h-32 w-full items-center justify-center gap-2 rounded-xl border-2 border-dashed border-border bg-surface-muted text-sm text-muted-foreground hover:border-secondary",children:[e.jsx(le,{className:"h-5 w-5"})," Añadir imágenes"]}),e.jsx("input",{ref:x,type:"file",accept:"image/jpeg,image/png,image/webp",multiple:!0,className:"sr-only",onChange:a=>K(a.target.files)}),C.length>0&&e.jsx("div",{className:"mt-3 grid grid-cols-2 gap-3 sm:grid-cols-3",children:C.map(({file:a,preview:r})=>e.jsxs("div",{className:"group relative overflow-hidden rounded-xl border border-border",children:[e.jsx("img",{src:r,alt:a.name,className:"aspect-square w-full object-cover"}),e.jsx("button",{type:"button","aria-label":`Quitar ${a.name}`,onClick:()=>Z(r),className:"absolute right-2 top-2 rounded-full bg-black/65 p-1 text-white hover:bg-black/80",children:e.jsx(he,{className:"h-4 w-4"})})]},r))})]}),e.jsx(ie,{ref:L,value:w,onChange:$}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsx(c,{label:"Ubicación opcional",children:e.jsxs("div",{className:"flex items-center gap-2 rounded-xl border border-border bg-surface px-4 py-3",children:[e.jsx(se,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("input",{className:"w-full bg-transparent text-base focus:outline-none",placeholder:"Ej: Somiedo, Asturias",value:v,onCh
1ange:a=>{const r=a.target.value;P(r),r.trim()||N(!1)}})]})}),e.jsx(c,{label:"Idioma de la publicación",children:e.jsxs("select",{value:R,onChange:a=>_(a.target.value),className:"w-full rounded-xl border border-border bg-surface px-4 py-3 text-base focus:border-secondary focus:outline-none",children:[e.jsx("option",{value:"es",children:"Español"}),e.jsx("option",{value:"en",children:"English"}),e.jsx("option",{value:"fr",children:"Français"}),e.jsx("option",{value:"de",children:"Deutsch"})]})})]}),e.jsx(c,{label:"Etiquetas",children:e.jsx("input",{className:"w-full rounded-xl border border-border bg-surface px-4 py-3 text-base",placeholder:"senderismo, somiedo, naturaleza",value:D,onChange:a=>J(a.target.value)})}),e.jsxs("div",{className:"space-y-2 rounded-xl border border-border bg-surface-muted p-4",children:[e.jsx(k,{label:"Permitir comentarios",checked:E,onChange:Q}),e.jsx(k,{label:"Asociar esta publicación al mapa",checked:U,disabled:!v.trim(),onChange:N}),d.role==="admin"&&e.jsx(k,{label:"Destacar como recomendación",checked:I,onChange:Y})]}),e.jsxs("fieldset",{className:"space-y-3 rounded-xl border border-border p-4",children:[e.jsx("legend",{className:"px-1 text-sm font-medium text-foreground",children:"Aceptación legal"}),e.jsxs(H,{name:"privacyAccepted",children:["He leÃdo y acepto la"," ",e.jsx(W,{to:"/privacidad",target:"_blank",className:"font-medium text-primary hover:underline",children:"PolÃtica de privacidad"}),"."]}),e.jsxs(H,{name:"termsAccepted",children:["He leÃdo y acepto las"," ",e.jsx(W,{to:"/terminos",target:"_blank",className:"font-medium text-primary hover:underline",children:"Condiciones de uso"}),"."]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-3 border-t border-border pt-4",children:[e.jsxs(ce,{children:[e.jsx(de,{asChild:!0,children:e.jsx("button",{type:"button",className:"rounded-full px-5 py-2.5 text-sm font-medium text-muted-foreground hover:bg-muted",children:"Cancelar"})}),e.jsxs(ue,{children:[e.jsxs(me,{children:[e.jsx(pe,{children:"¿Cancelar la publicación?"}),e.jsx(ge,{children:"Se borrará todo el contenido introducido y no podrás recuperarlo."})]}),e.jsxs(xe,{children:[e.jsx(be,{children:"Seguir editando"}),e.jsx(fe,{type:"button",className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",onClick:()=>{A.current?.reset(),P(""),N(!1),$([]),g({to:"/comunidad"})},children:"SÃ, borrar contenido"})]})]})]}),e.jsx("button",{type:"submit",disabled:S,className:"rounded-full bg-primary px-6 py-2.5 text-sm font-semibold text-primary-foreground shadow-soft hover:bg-primary/90",children:S?e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx(z,{className:"h-4 w-4 animate-spin"})," Publicando..."]}):"Publicar"})]})]})]})})}function H({name:n,children:l}){return e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 text-sm leading-5 text-foreground",children:[e.jsx("input",{type:"checkbox",name:n,required:!0,className:"mt-0.5 h-4 w-4 shrink-0 accent-primary"}),e.jsx("span",{children:l})]})}function c({label:n,children:l}){return e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"mb-1.5 block text-sm font-medium text-foreground",children:n}),l]})}function k({label:n,defaultChecked:l,checked:h,disabled:d=!1,onChange:p}){return e.jsxs("label",{className:`flex items-center justify-between py-2 ${d?"cursor-not-allowed opacity-50":"cursor-pointer"}`,children:[e.jsx("span",{className:"text-sm",children:n}),e.jsx("input",{type:"checkbox",defaultChecked:l,checked:h,disabled:d,onChange:p?g=>p(g.target.checked):void 0,className:"h-4 w-8 appearance-none rounded-full bg-border transition checked:bg-primary"})]})}export{Ce 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.