1import{c as E,O as I,u as B,r as t,t as d,j as e,B as n,L as $}from"./index-BR09kpgA.js";import{u as M,c as f,A as U}from"./AdminLayout-CaoiDr9b.js";import{C as F}from"./ConfirmDestructive-C16MFEXS.js";import{I as H}from"./input-BOjp5jaq.js";import{S as J}from"./search-u6ca6lUv.js";import{P as V}from"./plus-DM-8OypB.js";import{D as G}from"./download-DrfXPA67.js";import{L as K}from"./loader-circle-Kc4wcxth.js";import{P as q}from"./pencil-CrrUuT3q.js";import{T as Z}from"./trash-2-D0XPklX7.js";import"./client-1Eb_KJrN.js";import"./index-t3oJdvkF.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const Q=E("Pause",[["rect",{x:"14",y:"4",width:"4",height:"16",rx:"1",key:"zuxfzm"}],["rect",{x:"6",y:"4",width:"4",height:"16",rx:"1",key:"1okwgv"}]]);/** 7 * @license lucide-react v0.462.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const W=E("Play",[["polygon",{points:"6 3 20 12 6 21 6 3",key:"1oa8hb"}]]),X=["Alla","Hem & TrädgÃ¥rd","Hälsa","Mat & Dryck","Mobil & Bredband","Resor","Shopping","UnderhÃ¥llning","Ekonomi"],b=25,A=({active:a})=>e.jsx("span",{className:`inline-flex items-center px-2 py-1 rounded text-xs font-medium shrink-0 ${a?"bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-100":"bg-amber-100 text-amber-800 dark:bg-amber-900 dark:text-amber-100"}`,children:a?"Aktiv":"Pausad"}),C=({row:a,busy:c,isEditor:u,onToggle:r,onDelete:v})=>e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx(n,{size:"sm",variant:"admin",asChild:!0,className:"min-h-[44px] md:min-h-0",children:e.jsxs($,{to:`/admin/deals/${a.id}`,children:[e.jsx(q,{className:"h-4 w-4 mr-1.5"})," Redigera"]})}),a.is_active?e.jsxs(n,{size:"sm",variant:"admin",disabled:c,onClick:()=>r("pause",[a.id]),className:"min-h-[44px] md:min-h-0",children:[e.jsx(Q,{className:"h-4 w-4 mr-1.5"})," Pausa"]}):e.jsxs(n,{size:"sm",variant:"admin",disabled:c,onClick:()=>r("activate",[a.id]),className:"min-h-[44px] md:min-h-0",children:[e.jsx(W,{className:"h-4 w-4 mr-1.5"})," Aktivera"]}),u&&e.jsx(F,{title:`Radera dealen ${a.brand_name}?`,description:"Dealen tas bort permanent frÃ¥n databasen och försvinner direkt frÃ¥n sajten. à tgärden gÃ¥r inte att Ã¥ngra â pausa dealen istället om du vill kunna Ã¥terställa den.",onConfirm:()=>v(a.id),children:e.jsxs(n,{size:"sm",variant:"adminDanger",disabled:c,className:"min-h-[44px] md:min-h-0",children:[e.jsx(Z,{className:"h-4 w-4 mr-1.5"})," Radera"]})})]}),me=()=>{const{isEditor:a}=M(),c=I(),[u]=B(),[r,v]=t.useState([]),[N,R]=t.useState(0),[l,o]=t.useState(0),[m,D]=t.useState(u.get("search")??""),[h,L]=t.useState("Alla"),[x,_]=t.useState(u.get("status")??"all"),[O,k]=t.useState(!1),[w,p]=t.useState(!1),g=t.useCallback(async()=>{k(!0);try{const s={limit:String(b),offset:String(l)};m.trim()&&(s.search=m.trim()),h!=="Alla"&&(s.category=h),x!=="all"&&(s.status=x);const i=await f("admin-deals-list",{query:s});v(i.rows),R(i.total)}catch(s){d({title:"Kunde inte hämta deals",description:s.message})}finally{k(!1)}},[l,m,h,x]);t.useEffect(()=>{g()},[g]);const S=async(s,i)=>{if(i.length){p(!0);try{await f("admin-deals-write",{method:"POST",body:{action:s,ids:i}}),d({title:s==="activate"?"Aktiverad":"Pausad"}),g()}catch(j){d({title:"Misslyckades",description:j.message})}finally{p(!1)}}},P=async s=>{p(!0);try{await f("admin-deals-write",{method:"POST",body:{action:"delete",deal:{id:s}}}),d({title:"Raderad"}),g()}catch(i){d({title:"Misslyckades",description:i.message})}finally{p(!1)}},z=async()=>{try{const s=await f("admin-deals-export"),i=new Blob([JSON.stringify(s.deals,null,2)],{type:"application/json"}),j=URL.createObjectURL(i),y=document.createElement("a");y.href=j,y.download=`deals-se-${new Date().toISOString().slice(0,10)}.json`,y.click(),URL.revokeObjectURL(j),d({title:"Export nedladdad",description:`${s.deals.length} deals`})}catch(s){d({title:"Export misslyckades",description:s.message})}},T=m||h!=="Alla"||x!=="all";return e.jsxs(U,{title:"Deals",children:[e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center gap-3 mb-6",children:[e.jsxs("div",{className:"flex-1 relative",children:[e.jsx(J,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(H,{placeholder:"Sök varumärke, headline...",value:m,onChange:s=>{D(s.target.value),o(0)},className:"pl-9"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("select",{className:"h-10 rounded-md border border-input bg-background px-3 text-sm",value:h,onChange:s=>{L(s.target.value),o(0)},children:X.map(s=>e.jsx("option",{value:s,children:s},s))}),e.jsxs("select",{className:"h-10 rounded-md border border-input bg-background px-3 text-sm",value:x,onChange:s=>{_(s.target.value),o(0)},children:[e.jsx("option",{value:"all",children:"Alla status"}),e.jsx("option",{value:"active",children:"Aktiva"}),e.jsx("option",{value:"paused",children:"Pausade"})]}),a&&e.jsxs(n,{variant:"adminPrimary",onClick:()=>c("/admin/deals/ny"),children:[e.jsx(V,{className:"h-4 w-4 mr-2"})," Ny deal"]}),e.jsxs(n,{variant:"admin",onClick:z,children:[e.jsx(G,{className:"h-4 w-4 mr-2"})," Exportera JSON"]})]})]}),T&&e.jsxs("p",{className:"text-sm text-muted-foreground mb-2",children:["Visar ",r.length," av ",N," resultat"]}),O?e.jsx("div",{className:"bg-card border border-border rounded-lg p-8 flex justify-center",children:e.jsx(K,{className:"h-8 w-8 animate-spin text-primary"})}):r.length===0?e.jsx("div",{className:"bg-card border border-border rounded-lg",children:e.jsx("p",{className:"p-4 text-sm text-muted-foreground",children:"Inga deal
11s hittades."})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"md:hidden space-y-3",children:r.map(s=>e.jsxs("div",{className:`bg-card border border-border rounded-lg p-4 ${s.is_active?"":"bg-muted/40"}`,children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 mb-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-bold text-foreground truncate",children:s.brand_name}),e.jsx("p",{className:"text-sm text-muted-foreground line-clamp-2",children:s.headline})]}),e.jsx(A,{active:s.is_active})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mb-3",children:[s.hejsenior_category," · prioritet ",s.priority]}),e.jsx(C,{row:s,busy:w,isEditor:a,onToggle:S,onDelete:P})]},s.id))}),e.jsx("div",{className:"hidden md:block bg-card border border-border rounded-lg overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/50 text-left",children:e.jsxs("tr",{children:[e.jsx("th",{className:"p-3",children:"Status"}),e.jsx("th",{className:"p-3",children:"Varumärke"}),e.jsx("th",{className:"p-3",children:"Headline"}),e.jsx("th",{className:"p-3",children:"Kategori"}),e.jsx("th",{className:"p-3",children:"Prioritet"}),e.jsx("th",{className:"p-3",children:"Ã
tgärder"})]})}),e.jsx("tbody",{className:"divide-y divide-border",children:r.map(s=>e.jsxs("tr",{className:s.is_active?"":"bg-muted/40 opacity-70",children:[e.jsx("td",{className:"p-3",children:e.jsx(A,{active:s.is_active})}),e.jsx("td",{className:"p-3 font-medium",children:s.brand_name}),e.jsx("td",{className:"p-3 max-w-xs truncate",title:s.headline,children:s.headline}),e.jsx("td",{className:"p-3",children:s.hejsenior_category}),e.jsx("td",{className:"p-3",children:s.priority}),e.jsx("td",{className:"p-3",children:e.jsx(C,{row:s,busy:w,isEditor:a,onToggle:S,onDelete:P})})]},s.id))})]})})]}),e.jsxs("div",{className:"flex items-center justify-between mt-4 text-sm",children:[e.jsxs("span",{className:"text-muted-foreground",children:["Visar ",r.length?l+1:0,"â",l+r.length," av ",N]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(n,{variant:"admin",size:"sm",disabled:l===0,onClick:()=>o(Math.max(l-b,0)),children:"FöregÃ¥ende"}),e.jsx(n,{variant:"admin",size:"sm",disabled:l+b>=N,onClick:()=>o(l+b),children:"Nästa"})]})]})]})};export{me 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.