1import{r as o,i as C,j as e,s as p,t as N}from"./index-BxLXqTQ2.js";import{u as _}from"./useQuery-BDmSQyFx.js";import{I as M}from"./input-CLsjmqjp.js";import{D as S,a as D,b as q,c as E,d as I,e as L}from"./dialog-BmaqYyba.js";import{B as m}from"./button-CBLNMq4C.js";import{S as Q}from"./search-NX13Wv6g.js";import{C as y}from"./circle-alert-L6GXJG0B.js";import{T as b}from"./trash-2-CTBVs1FC.js";import{C as K}from"./circle-check-DH_DxWSB.js";import{M as R}from"./mail-CTHa8-8n.js";import"./useBaseQuery-DmgI0yD8.js";import"./utils-D8NipYgD.js";import"./index-7HJisURy.js";const h=50;function V(){const[r,g]=o.useState(""),[n,c]=o.useState(0),[s,x]=o.useState(null),d=C(),{data:u=[],isLoading:w}=_({queryKey:["admin-contact-messages"],queryFn:async()=>{const{data:a,error:t}=await p.from("contact_messages").select("*").order("created_at",{ascending:!1});if(t)throw t;return a}}),i=o.useMemo(()=>{const a=r.trim().toLowerCase();return a?u.filter(t=>t.name.toLowerCase().includes(a)||t.email.toLowerCase().includes(a)||t.message.toLowerCase().includes(a)):u},[u,r]),l=Math.max(1,Math.ceil(i.length/h)),f=i.slice(n*h,(n+1)*h);async function k(a){if(x(a),!a.is_read){const{error:t}=await p.from("contact_messages").update({is_read:!0}).eq("id",a.id);t||(d.invalidateQueries({queryKey:["admin-contact-messages"]}),d.invalidateQueries({queryKey:["admin-unread-counts"]}))}}async function j(a){if(!confirm("Radera meddelandet permanent?"))return;const{error:t}=await p.from("contact_messages").delete().eq("id",a);if(t){N.error(t.message);return}N.success("Meddelandet raderat"),x(null),d.invalidateQueries({queryKey:["admin-contact-messages"]}),d.invalidateQueries({queryKey:["admin-unread-counts"]})}return e.jsxs("div",{className:"px-8 py-10 max-w-6xl",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold text-primary-dark",children:"Meddelanden"}),e.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"Inkomna meddelanden frÃ¥n kontaktformuläret. Klicka pÃ¥ ett meddelande för att läsa hela."})]}),e.jsxs("div",{className:"mt-8 flex items-center gap-3",children:[e.jsxs("div",{className:"relative flex-1 max-w-md",children:[e.jsx(Q,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(M,{placeholder:"Sök pÃ¥ namn, e-post eller innehÃ¥ll...",value:r,onChange:a=>{g(a.target.value),c(0)},className:"pl-9"})]}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:[i.length," ",i.length===1?"meddelande":"meddelanden"]})]}),e.jsx("div",{className:"mt-6 rounded-lg border border-border bg-card overflow-hidden",children:w?e.jsx("div",{className:"p-10 text-center text-sm text-muted-foreground",children:"Laddarâ¦"}):f.length===0?e.jsx("div",{className:"p-10 text-center text-sm text-muted-foreground",children:r?"Inga meddelanden matchar sökningen.":"Inga meddelanden ännu."}):e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/50 text-left text-xs uppercase tracking-wide text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-3 font-medium",children:"Namn"}),e.jsx("th",{className:"px-4 py-3 font-medium",children:"E-post"}),e.jsx("th",{className:"px-4 py-3 font-medium",children:"Meddelande"}),e.jsx("th",{className:"px-4 py-3 font-medium",children:"Datum"}),e.jsx("th",{className:"px-4 py-3 font-medium w-10"})]})}),e.jsx("tbody",{className:"divide-y divide-border",children:f.map(a=>e.jsxs("tr",{onClick:()=>k(a),className:`cursor-pointer hover:bg-muted/40 transition-colors ${a.is_read?"":"bg-blue-50/60"}`,children:[e.jsx("td",{className:`px-4 py-3 whitespace-nowrap ${a.is_read?"font-medium text-foreground":"font-semibold text-foreground"}`,children:e.jsxs("div",{className:"flex items-center gap-2",children:[!a.is_read&&e.jsx("span",{className:"h-2 w-2 rounded-full bg-blue-500 shrink-0","aria-label":"Oläst"}),a.name,!a.email_sent&&e.jsx("span",{title:"Mejlet kunde inte skickas â meddelandet finns sparat här",children:e.jsx(y,{className:"h-3.5 w-3.5 text-amber-500"})})]})}),e.jsx("td",{className:"px-4 py-3 text-muted-foreground whitespace-nowrap",children:a.email}),e.jsx("td",{className:"px-4 py-3 text-muted-foreground max-w-md truncate",children:a.message}),e.jsx("td",{className:"px-4 py-3 text-muted-foreground whitespace-nowrap",children:v(a.created_at)}),e.jsx("td",{className:"px-4 py-3 text-right",children:e.jsx("button",{onClick:t=>{t.stopPropagation(),j(a.id)},className:"text-muted-foreground hover:text-destructive p-1","aria-label":"Radera",children:e.jsx(b,{className:"h-4 w-4"})})})]},a.id))})]})}),l>1&&e.jsxs("div",{className:"mt-4 flex items-center justify-between text-sm",children:[e.jsxs("span",{className:"text-muted-foreground",children:["Sida ",n+1," av ",l]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(m,{variant:"outline",size:"sm",disabled:n===0,onClick:()=>c(a=>Math.max(0,a-1)),children:"FöregÃ¥ende"}),e.jsx(m,{variant:"outline",size:"sm",disabled:n>=l-1,onClick:()=>c(a=>Math.min(l-1,a+1)),children:"Nästa"})]})]}),e.jsx(S,{open:!!s,onOpenChange:a=>!a&&x(null),children:e.jsx(D,{className:"max-w-2xl",children:s&&e.jsxs(e.Fragment,{children:[e.jsxs(q,{children:[e.jsx(E,{children:s.name}),e.jsxs(I,{className:"flex items-center gap-2",children:[e.jsx("a",{href:`mailto:${s.email}`,className:"text-primary hover:underline",children:s.email}),e.jsx("span",{children:"·"}),e.jsx("span",{children:v(s.created_at)}),e.jsx("span",{children:"·"}),e.jsx("span",{children:s.locale==="en"?"Engelska":"Svenska"})]})]}),s.email_sent?e.jsxs("div",{className:"flex items-center gap-2 text-xs text-emerald-700 bg-emerald-50 border border-emerald-200 rounded-md px-3 py-2",children:[e.jsx(K,{className:"h-3.5 w-3.5"}),"Notifikationsmejl skickades till [email protected]"]}):e.jsxs("div",{className:"text-xs text-amber-800 bg-amber-50 border border-amber-200 rounded-md px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-2 font-medium",children:[e.jsx(y,{className:"h-3.5 w-3.5"}),"Notifikationsmejlet kunde inte skickas"]}),s.email_error&&e.jsx("div",{className:"mt-1 text-[11px] font-mono break-all opacity-80",children:s.email_error})]}),e.jsx("div",{className:"whitespace-pre-wrap text-sm bg-muted/50 border border-border rounded-md p-4 max-h-96 overflow-y-auto",children:s.message}),e.jsxs(L,{className:"gap-2 sm:gap-2",children:[e.jsxs(m,{variant:"outline",onClick:()=>j(s.id),className:"gap-2",children:[e.jsx(b,{className:"h-4 w-4"})," Radera"]}),e.jsx(m,{asChild:!0,className:"gap-2",children:e.jsxs("a",{href:`mailto:${s.email}?subject=Re: Ditt meddelande till Carumed`,children:[e.jsx(R,{className:"h-4 w-4"})," Svara via mejl"]})})]})]})})})]})}
1function v(r){return new Date(r).toLocaleString("sv-SE",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}export{V 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.