1import{r as m,u as b,j as e,L as r,I as a,T as f,B as N,s as o,t as i}from"./index-EhlWxbWg.js";import{L as S}from"./Linkify-Bft9p4tv.js";import{P as k}from"./PageShell-DH7nPkNN.js";import"./BreakingBanner-BO31IdU1.js";function I(){const[n,x]=m.useState([]),{HoneypotField:u,checkSpam:g}=b();async function p(){const{data:t}=await o.from("letters").select("*").eq("status","published").order("created_at",{ascending:!1});x(t??[])}m.useEffect(()=>{p()},[]);async function h(t){if(t.preventDefault(),g(t.currentTarget))return;const d=t.currentTarget,s=new FormData(d),c=String(s.get("text")??"");if(c.length<100){i.error("Insändaren bör vara minst 100 tecken.");return}const j={title:String(s.get("title")??"").trim(),author_name:String(s.get("name")??"").trim(),signature:String(s.get("sig")??"").trim()||null,text:c,status:"pending"},{error:l}=await o.from("letters").insert(j);if(l){i.error(l.message);return}i.success("Tack! Din insändare har skickats till redaktionen."),d.reset()}return e.jsxs(k,{title:"Insändare & Debatt",eyebrow:"Läsarnas sida",children:[e.jsx("div",{className:"mb-6 border-l-4 border-primary bg-muted/50 p-4 text-sm",children:"Samtliga texter på denna sida är insändare och åsikterna är skribentens egna."}),e.jsxs("div",{className:"grid gap-10 lg:grid-cols-[1fr_400px]",children:[e.jsx("section",{children:n.length===0?e.jsx("p",{className:"text-muted-foreground",children:"Inga insändare publicerade ännu."}):e.jsx("div",{className:"divide-y divide-border rule-top rule-bottom",children:n.map(t=>e.jsxs("article",{className:"py-5",children:[e.jsx("div",{className:"eyebrow text-primary",children:"Insändare"}),e.jsx("h2",{className:"headline-md mt-1",children:t.title}),e.jsx(S,{text:t.text,className:"text-sm whitespace-pre-wrap mt-2"}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-3",children:[t.signature||t.author_name," · ",new Date(t.created_at).toLocaleDateString("sv-SE")]})]},t.id))})}),e.jsxs("section",{className:"bg-card border p-6",children:[e.jsx("h2",{className:"font-serif text-2xl mb-1",children:"Skicka in din insändare"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"Max 3 500 tecken. Vi publicerar under signatur, men måste alltid ha ditt namn."}),e.jsxs("form",{onSubmit:h,className:"grid gap-3",children:[e.jsx(u,{}),e.jsxs("div",{className:"grid gap-1.5",children:[e.jsx(r,{htmlFor:"title",children:"Rubrik *"}),e.jsx(a,{id:"title",name:"title",required:!0})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"grid gap-1.5",children:[e.jsx(r,{htmlFor:"name",children:"Ditt namn *"}),e.jsx(a,{id:"name",name:"name",required:!0})]}),e.jsxs("div",{className:"grid gap-1.5",children:[e.jsx(r,{htmlFor:"sig",children:"Signatur"}),e.jsx(a,{id:"sig",name:"sig",placeholder:"Trött Strömsundsbo"})]})]}),e.jsxs("div",{className:"grid gap-1.5",children:[e.jsx(r,{htmlFor:"text",children:"Insändaren *"}),e.jsx(f,{id:"text",name:"text",rows:10,required:!0})]}),e.jsx(N,{type:"submit",className:"bg-primary text-primary-foreground",children:"Skicka in"})]})]})]})]})}export{I 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.