PageSourceSearch

https://brekke-sport-intern.lovable.app/assets/Nettbutikk-D5o1dU1F.js

js brekke-sport-intern.lovable.app collected 2026-10-03 03:25:11 UTC 153,888 bytes, 259 lines download raw bytes

1import{t as cs,r as c,j as e,a2 as rt,s as j,D as ls,v as is,w as Hs,x as Ws,aZ as _e,V as mn,I as tt,S as Me,a as Fe,b as De,c as Ue,d as L,e as st,M as I,K as Be,q as pn,ag as w,b6 as wt,o as ka,_ as ba,H as wa,an as Na,B as b,ac as Zr,P as As,X as H,ai as es,as as ya,m as jt,F as he,G as ge,J as fe,Z as Nt,b7 as va,aX as Ks,af as Sa,f as Ca,g as $a,a7 as za,ad as Xr}from"./index-BGVGRJOp.js";import{H as Ta}from"./history-xH3iWCP7.js";import{f as Ea}from"./useProductUrls-BDmvWg26.js";import{T as ts}from"./textarea-Bu05igJL.js";import{T as Jr,a as en,b as ss,c as rs}from"./tabs-DEBdQkO-.js";import{T as tn,a as sn,b as Je,c as R,d as rn,e as K}from"./table-Z_x1kwWC.js";import{A as Is,a as Rs,b as Ms,c as Fs,d as Ds,e as Us,f as Bs,g as Vs}from"./alert-dialog-W2rZxXIW.js";import{S as nn}from"./slider-C8vfqtRO.js";import{H as La,a as Pa,b as Oa}from"./hover-card-D-CX-OS4.js";import{S as Aa}from"./switch-DuUYmfZi.js";import{C as os}from"./copy-Dr6uW5QA.js";import{E as Ka}from"./external-link-B5tKIchL.js";import{C as Ia,a as Ra,b as Ma,c as Fa,d as Da,e as Ua}from"./command-V9tf_xOl.js";import{P as an}from"./package-check-BrZADdyY.js";import{S as Ba}from"./settings-2-BCyCQkEk.js";import{A as ln}from"./arrow-up-down-B772eRmL.js";import{A as on}from"./arrow-left-DOpklLLN.js";import{P as ns}from"./printer-CmkWgo8w.js";import{C as Re}from"./circle-check-BuZ2etEF.js";import{T as cn}from"./trash-2-bDZxFW3-.js";import{S as qs}from"./sticky-note-Cy6PocNk.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 ye=cs("ArrowRightLeft",[["path",{d:"m16 3 4 4-4 4",key:"1x1c3m"}],["path",{d:"M20 7H4",key:"zbl0bi"}],["path",{d:"m8 21-4-4 4-4",key:"h9nckh"}],["path",{d:"M4 17h16",key:"g4d7ey"}]]);/**
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 Va=cs("PinOff",[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M15 9.34V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H7.89",key:"znwnzq"}],["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M9 9v1.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h11",key:"c9qhm2"}]]);/**
12 * @license lucide-react v0.462.0 - ISC
13 *
14 * This source code is licensed under the ISC license.
15 * See the LICENSE file in the root directory of this source tree.
16 */const qa=cs("Pin",[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z",key:"1nkz8b"}]]);/**
17 * @license lucide-react v0.462.0 - ISC
18 *
19 * This source code is licensed under the ISC license.
20 * See the LICENSE file in the root directory of this source tree.
21 */const Ha=cs("SlidersHorizontal",[["line",{x1:"21",x2:"14",y1:"4",y2:"4",key:"obuewd"}],["line",{x1:"10",x2:"3",y1:"4",y2:"4",key:"1q6298"}],["line",{x1:"21",x2:"12",y1:"12",y2:"12",key:"1iu8h1"}],["line",{x1:"8",x2:"3",y1:"12",y2:"12",key:"ntss68"}],["line",{x1:"21",x2:"16",y1:"20",y2:"20",key:"14d8ph"}],["line",{x1:"12",x2:"3",y1:"20",y2:"20",key:"m0wm8r"}],["line",{x1:"14",x2:"14",y1:"2",y2:"6",key:"14e1ph"}],["line",{x1:"8",x2:"8",y1:"10",y2:"14",key:"1i6ji0"}],["line",{x1:"16",x2:"16",y1:"18",y2:"22",key:"1lctlv"}]]),Wa={opprettet:"Opprettet",endret:"Endret",svar:"Svar",slettet:"Slettet"};function Ya({orderId:Z}){const[T,Y]=c.useState(!1),[X,ne]=c.useState(!1),[y,J]=c.useState([]),M=async()=>{ne(!0);const{data:z}=await j.from("web_order_note_log").select("*").eq("order_id",Z).order("created_at",{ascending:!1}).limit(100),je=z||[],U=[...new Set(je.map(f=>f.changed_by).filter(Boolean))];let oe={};if(U.length){const{data:f}=await j.from("employees").select("id, full_name").in("id",U);oe=Object.fromEntries((f||[]).map(G=>[G.id,G.full_name]))}J(je.map(f=>({...f,name:f.changed_by&&oe[f.changed_by]||f.source||"Ukjent"}))),ne(!1)},ee=z=>{z.stopPropagation(),T||M(),Y(!T)};return e.jsxs("div",{className:"mt-1.5",onClick:z=>z.stopPropagation(),children:[e.jsxs("button",{onClick:ee,className:"text-[10px] text-muted-foreground hover:text-foreground inline-flex items-center gap-1",children:[e.jsx(Ta,{className:"h-3 w-3"})," ",T?"Skjul logg":"Vis logg"]}),T&&e.jsx("div",{className:"mt-1 space-y-1 max-h-48 overflow-y-auto",children:X?e.jsx(rt,{className:"h-3 w-3 animate-spin text-muted-foreground"}):y.length===0?e.jsx("p",{className:"text-[10px] text-muted-foreground italic",children:"Ingen endringer logget ennå"}):y.map(z=>e.jsxs("div",{className:"text-[10px] border-l-2 border-border pl-1.5",children:[e.jsxs("div",{className:"text-muted-foreground",children:[e.jsx("span",{className:"font-medium text-foreground",children:Wa[z.action]||z.action}
21)," · ",z.name," ·"," ",new Date(z.created_at).toLocaleString("nb-NO",{day:"2-digit",month:"2-digit",hour:"2-digit",minute:"2-digit"})]}),z.action==="svar"?e.jsx("div",{className:"whitespace-pre-wrap",children:z.new_answer||e.jsx("span",{className:"italic text-muted-foreground",children:"svar fjernet"})}):z.action==="slettet"?e.jsx("div",{className:"whitespace-pre-wrap line-through text-muted-foreground",children:z.old_note}):e.jsxs(e.Fragment,{children:[z.old_note&&z.old_note!==z.new_note&&e.jsx("div",{className:"whitespace-pre-wrap line-through text-muted-foreground",children:z.old_note}),e.jsx("div",{className:"whitespace-pre-wrap",children:z.new_note})]})]},z.id))})]})}const et="/assets/brekke-sport-logo-print-icEFfvdN.png";function Ga({open:Z,onOpenChange:T,initialOrderId:Y}){const[X,ne]=c.useState([]),[y,J]=c.useState(!1),[M,ee]=c.useState(!1),[z,je]=c.useState("7"),[U,oe]=c.useState(""),[f,G]=c.useState(""),[ke,Ve]=c.useState(new Set),ve=async g=>{J(!0);try{const{data:P,error:E}=await j.functions.invoke("pck-shipped-web-orders",{body:{days_back:g}});if(E)throw E;ne(P.orders||[]),ee(!0)}catch(P){console.error("Error fetching shipped orders:",P),w.error("Kunne ikke hente sendte ordre: "+(P.message||"Ukjent feil"))}finally{J(!1)}},yt=async g=>{const P=String(g).trim();if(!P||!/^[A-Za-z0-9_\-]+$/.test(P)||P.length>64){w.error("Ugyldig ordrenummer");return}J(!0);try{const{data:E,error:se}=await j.functions.invoke("pck-shipped-web-orders",{body:{order_id:P}});if(se)throw se;const $=E.orders||[];ne($),ee(!0),$.length===0?w.info(`Fant ingen ferdigmeldt ordre med nr ${P}`):Ve(new Set($.map(V=>V.order_id)))}catch(E){console.error("Error fetching order by id:",E),w.error("Kunne ikke hente ordre: "+(E.message||"Ukjent feil"))}finally{J(!1)}},be=g=>{T(g),g&&!M&&!Y&&ve(Number(z))};c.useEffect(()=>{if(Z&&Y){const g=String(Y).trim();g&&/^[A-Za-z0-9_\-]+$/.test(g)&&(G(g),yt(g))}else Z&&!M&&!y&&ve(Number(z))},[Z,Y]);const nt=g=>{je(g),G(""),ve(Number(g))},at=g=>{Ve(P=>{const E=new Set(P);return E.has(g)?E.delete(g):E.add(g),E})},qe=g=>g?new Date(g).toLocaleDateString("nb-NO",{day:"2-digit",month:"2-digit",year:"numeric"}):"",we=g=>{if(!g)return"";const P=new Date(g);return`${P.toLocaleDateString("nb-NO",{day:"2-digit",month:"2-digit",year:"numeric"})} ${P.toLocaleTimeString("nb-NO",{hour:"2-digit",minute:"2-digit"})}`},lt=g=>g&&g.length>=10?`https://sporing.posten.no/sporing/${g}`:null,te=c.useMemo(()=>{const g=U.trim().toLowerCase();if(!g)return X;const P=g.split(/\s+/).filter(Boolean);return X.filter(E=>{const se=[String(E.order_id),E.external_ref||"",E.delivery_name,E.delivery_address,E.delivery_zipcode,E.delivery_city,E.customer_phone,E.shipping_method,E.tracking_number,...E.items.flatMap($=>[$.article_name,$.article_no,$.manufacturer_name,$.color_name,$.size_name])].join(" ").toLowerCase();return P.every($=>se.includes($))})},[X,U]);return e.jsx(ls,{open:Z,onOpenChange:be,children:e.jsxs(is,{className:"max-w-2xl max-h-[85vh] overflow-hidden flex flex-col",children:[e.jsx(Hs,{children:e.jsxs(Ws,{className:"flex items-center gap-2",children:[e.jsx(_e,{className:"h-5 w-5"}),"Ferdigmeldte ordre (",te.length,")"]})}),e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsxs("div",{className:"relative flex-1 min-w-0",children:[e.jsx(mn,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(tt,{placeholder:"Søk vare, kunde, ordrenr, sporing...",value:U,onChange:g=>oe(g.target.value),onKeyDown:g=>{if(g.key==="Enter"){const P=U.trim();P&&/^[A-Za-z0-9_\-]+$/.test(P)&&P.length<=64&&te.length===0&&yt(P)}},className:"pl-9 h-9"})]}),e.jsxs(Me,{value:z,onValueChange:nt,children:[e.jsx(Fe,{className:"w-[140px] h-9",children:e.jsx(De,{})}),e.jsxs(Ue,{children:[e.jsx(L,{value:"7",children:"Siste 7 dager"}),e.jsx(L,{value:"14",children:"Siste 14 dager"}),e.jsx(L,{value:"30",children:"Siste 30 dager"}),e.jsx(L,{value:"60",children:"Siste 60 dager"}),e.jsx(L,{value:"90",children:"Siste 90 dager"}),e.jsx(L,{value:"180",children:"Siste 180 dager"}),e.jsx(L,{value:"365",children:"Siste 12 mnd"}),e.jsx(L,{value:"730",children:"Siste 24 mnd"}),e.jsx(L,{value:"1095",children:"Siste 36 mnd"})]})]})]}),e.jsx("div",{className:"overflow-y-auto flex-1 space-y-2 pr-1",children:y?e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx(rt,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):te.length===0?e.jsxs("div",{className:"py-12 text-center text-muted-foreground",children:[e.jsx(_e,{className:"h-12 w-12 mx-auto mb-3 opacity-50"}),e.jsx("p",{children:"Ingen sendte ordre funnet"})]}):te.map((g,P)=>{const E=ke.has(g.order_id),se=lt(g.tracking_number);return e.jsxs(st,{className:P%2===1?"bg-muted/20":"",children:[e.jsxs("div",{className:"flex items-start gap-2 sm:gap-3 px-3 sm:px-4 py-3 cursor-pointer hover:bg-muted/30 transition-colors",onClick:()=>at(g.order_id),children:[e.jsx(I,{variant:"outline",className:"text-[10px] shrink-0 bg-emerald-100 text-emerald-800 dark:bg-emerald-900/30 dark:text-emerald-300",children:"Sendt"}),E?e.jsx(Be,{className:"h-4 w-4 text-muted-foreground shrink-0 mt-0.5"}):e.jsx(pn,{className:"h-4 w-4 text-muted-foreground shrink-0 mt-0.5"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5 sm:gap-2",children:[e.jsx("button",{onClick:$=>{$.stopPropagation(),navigator.clipboard.writeText(String(g.order_id)),w.success("Ordrenummer kopiert")},className:"text-muted-foreground hover:text-foreground transition-colors shrink-0",title:"Kopier ordrenummer",children:e.jsx(os,{className:"h-3 w-3 sm:h-3.5 sm:w-3.5"})}),e.jsx("span",{className:"font-mono font-bold text-xs sm:text-sm shrink-0",children:g.order_id}),e.jsx("span",{className:"text-xs sm:text-sm truncate",children:g.delivery_name}),e.jsxs("span",{className:"text-xs sm:text-sm font-medium whitespace-nowrap ml-auto",children:[g.total_revenue.toLocaleStr
21ing("nb-NO",{minimumFractionDigits:0})," kr"]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap mt-1",children:[e.jsxs(I,{variant:"outline",className:"text-[10px] bg-muted/50 text-muted-foreground",children:[e.jsx(wt,{className:"h-3 w-3 mr-0.5"}),g.shipping_method||"Ukjent"]}),g.tracking_number&&e.jsxs(I,{variant:"outline",className:"text-[10px] bg-blue-50 text-blue-700 dark:bg-blue-900/30 dark:text-blue-300 cursor-pointer",onClick:$=>{$.stopPropagation(),navigator.clipboard.writeText(g.tracking_number),w.success("Pakkenummer kopiert")},children:["📦 ",g.tracking_number.length>20?g.tracking_number.slice(0,10)+"…"+g.tracking_number.slice(-6):g.tracking_number,e.jsx(os,{className:"h-2.5 w-2.5 ml-0.5"})]})]}),e.jsxs("div",{className:"text-[11px] sm:text-xs mt-0.5 text-muted-foreground",children:[e.jsxs("span",{children:["Bestilt: ",qe(g.order_date)]}),g.shipped_at&&e.jsxs("span",{children:[" • Sendt: ",we(g.shipped_at)]}),e.jsxs("span",{children:[" • ",g.items.length," varer • ",g.delivery_city]})]})]})]}),E&&e.jsxs("div",{className:"border-t px-2 sm:px-4 pb-3 pt-2",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-1 text-xs text-muted-foreground mb-3",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"Adresse:"})," ",g.delivery_address,", ",g.delivery_zipcode," ",g.delivery_city]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"Telefon:"})," ",g.customer_phone||"-"]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"Sendingsmåte:"})," ",g.shipping_method]}),g.shipped_at&&e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"Sendt:"})," ",we(g.shipped_at)]}),g.tracking_number&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"font-medium text-foreground",children:"Pakkenr:"}),e.jsx("span",{className:"font-mono text-[11px]",children:g.tracking_number}),e.jsx("button",{onClick:()=>{navigator.clipboard.writeText(g.tracking_number),w.success("Kopiert")},className:"text-muted-foreground hover:text-foreground",children:e.jsx(os,{className:"h-3 w-3"})}),se&&e.jsxs("a",{href:se,target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:text-primary/80 inline-flex items-center gap-0.5 text-[11px]",onClick:$=>$.stopPropagation(),children:["Spor ",e.jsx(Ka,{className:"h-3 w-3"})]})]})]}),e.jsx("div",{className:"space-y-1",children:g.items.map(($,V)=>e.jsxs("div",{className:"flex items-center gap-2 text-xs py-1.5 border-b last:border-0 border-border/50",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"font-medium truncate",children:$.article_name}),$.units>1&&e.jsxs(I,{variant:"outline",className:"text-[9px]",children:[$.units,"x"]})]}),e.jsxs("div",{className:"text-[10px] text-muted-foreground mt-0.5",children:[$.manufacturer_name&&e.jsxs("span",{children:[$.manufacturer_name," • "]}),$.color_name&&e.jsx("span",{children:$.color_name}),$.size_name&&e.jsxs("span",{children:[" / ",$.size_name]}),e.jsxs("span",{className:"hidden sm:inline",children:[" • ",$.article_no]})]})]}),e.jsxs("span",{className:"text-xs font-medium whitespace-nowrap",children:[$.gross_amount.toLocaleString("nb-NO",{minimumFractionDigits:0})," kr"]})]},V))})]})]},g.order_id)})})]})})}const Qa={0:"nnnwwnwnn",1:"wnnwnnnnw",2:"nnwwnnnnw",3:"wnwwnnnnn",4:"nnnwwnnnw",5:"wnnwwnnnn",6:"nnwwwnnnn",7:"nnnwnnwnw",8:"wnnwnnwnn",9:"nnwwnnwnn",A:"wnnnnwnnw",B:"nnwnnwnnw",C:"wnwnnwnnn",D:"nnnnwwnnw",E:"wnnnwwnnn",F:"nnwnwwnnn",G:"nnnnnwwnw",H:"wnnnnwwnn",I:"nnwnnwwnn",J:"nnnnwwwnn",K:"wnnnnnnww",L:"nnwnnnnww",M:"wnwnnnnwn",N:"nnnnwnnww",O:"wnnnwnnwn",P:"nnwnwnnwn",Q:"nnnnnnwww",R:"wnnnnnwwn",S:"nnwnnnwwn",T:"nnnnwnwwn",U:"wwnnnnnnw",V:"nwwnnnnnw",W:"wwwnnnnnn",X:"nwnnwnnnw",Y:"wwnnwnnnn",Z:"nwwnwnnnn","-":"nwnnnnwnw",".":"wwnnnnwnn"," ":"nwwnnnwnn","*":"nwnnwnwnn"};function dn(Z,T){const Y=(T==null?void 0:T.height)??40,X=(T==null?void 0:T.narrow)??2,ne=X*3,y=(T==null?void 0:T.showText)!==!1,J=String(Z).toUpperCase().replace(/[^0-9A-Z\-. ]/g,""),M=["*",...J.split(""),"*"];let ee=0,z="";for(const oe of M){const f=Qa[oe];if(f){for(let G=0;G<f.length;G++){const ke=f[G]==="w"?ne:X;G%2===0&&(z+=`<rect x="${ee}" y="0" width="${ke}" height="${Y}" fill="#000"/>`),ee+=ke}ee+=X}}const je=Y+(y?14:0),U=y?`<text x="${ee/2}" y="${Y+12}" font-family="Arial, sans-serif" font-size="11" text-anchor="middle" fill="#000">${J}</text>`:"";return`<svg xmlns="http://www.w3.org/2000/svg" width="${ee}" height="${je}
21" viewBox="0 0 ${ee} ${je}">${z}${U}</svg>`}const Za=[{value:"maingroup",label:"Hovedgruppe",dim:"maingroup"},{value:"webgroup1",label:"Webgruppe 1",dim:"webgroup1"},{value:"webgroup2",label:"Webgruppe 2",dim:"webgroup2"},{value:"webgroup3",label:"Webgruppe 3",dim:"webgroup3"}];function xn({options:Z,value:T,onChange:Y,placeholder:X,className:ne}){const[y,J]=c.useState(!1);return e.jsxs(he,{open:y,onOpenChange:J,children:[e.jsx(ge,{asChild:!0,children:e.jsxs(b,{variant:"outline",role:"combobox",className:Xr("justify-between h-9 font-normal",ne),children:[e.jsx("span",{className:"truncate",children:T||X}),e.jsx(Be,{className:"ml-1 h-3.5 w-3.5 shrink-0 opacity-50"})]})}),e.jsx(fe,{className:"w-[260px] p-0",align:"start",children:e.jsxs(Ia,{children:[e.jsx(Ra,{placeholder:"Søk...",className:"h-8 text-xs"}),e.jsxs(Ma,{children:[e.jsx(Fa,{children:"Ingen treff"}),e.jsx(Da,{children:Z.map(M=>e.jsxs(Ua,{value:M,onSelect:()=>{Y(M),J(!1)},children:[e.jsx(Nt,{className:Xr("mr-2 h-3 w-3",T===M?"opacity-100":"opacity-0")}),M]},M))})]})]})})]})}const kt=new Map,bt=new Set,_={BESTILT_STADION:"bestilt_stadion",PLUKKET_SENTRUM:"plukket_sentrum",PLUKKET_STOA:"plukket_stoa",KLAR_OVERFORING:"klar_overforing",IKKE_FUNNET:"ikke_funnet",OVERSTYR_SENTRUM:"overstyr_sentrum",OVERSTYR_STOA:"overstyr_stoa",OVERSTYR_STADION:"overstyr_stadion"},as=[_.OVERSTYR_SENTRUM,_.OVERSTYR_STOA,_.OVERSTYR_STADION],Xa={[_.OVERSTYR_SENTRUM]:"Sentrum",[_.OVERSTYR_STOA]:"Stoa",[_.OVERSTYR_STADION]:"Stadion"},Ja={Sentrum:_.OVERSTYR_SENTRUM,Stoa:_.OVERSTYR_STOA,Stadion:_.OVERSTYR_STADION},Le=Z=>Z.replace(/^tillegg?s?informasjon\s*[,:;.]?\s*/i,"").trim();function bl({user:Z}){const[T,Y]=ka(),[X]=c.useState(()=>{const t=T.get("from"),s=T.get("ticket");return t==="support"&&s?s:null}),ne=ba(),[y,J]=c.useState([]),[M,ee]=c.useState(!0),[z,je]=c.useState(0),[U,oe]=c.useState(T.get("search")||""),[f,G]=c.useState("all"),[ke,Ve]=c.useState("asc"),[ve,yt]=c.useState("date"),[be,nt]=c.useState("all"),[at,qe]=c.useState(new Set),[we,lt]=c.useState(new Set),[te,g]=c.useState(new Map),[P,E]=c.useState(!1),[se,$]=c.useState(""),[V,He]=c.useState(new Map),[vt,it]=c.useState(null),[St,Ct]=c.useState(""),[$t,Ys]=c.useState("off"),[zt,Gs]=c.useState("off"),[Tt,Qs]=c.useState("off"),[Et,Zs]=c.useState("off"),[Lt,Xs]=c.useState("off");c.useState(!1);const[Pt,Js]=c.useState("off"),[Ot,er]=c.useState("off"),[At,tr]=c.useState("hide"),[sr,un]=c.useState(new Map),[ds,hn]=c.useState(!1),[Pe,xs]=c.useState("category"),[Oe,ot]=c.useState(new Set),[ms,Kt]=c.useState(!1),[Ae,gn]=c.useState(!1),[It,ct]=c.useState(!1),[fn,Rt]=c.useState(null),[rr,Mt]=c.useState(""),[N,Ke]=c.useState(new Map),[We,nr]=c.useState([]),[_n,jn]=c.useState([]),[ar,kn]=c.useState({}),[bn,wn]=c.useState(!1),[ps,lr]=c.useState(""),[ir,Nn]=c.useState("Stoa"),[B,dt]=c.useState(new Map),[or,yn]=c.useState(()=>localStorage.getItem("nettbutikk_remember_routing")==="1"),vn=t=>{yn(t),localStorage.setItem("nettbutikk_remember_routing",t?"1":"0")},[Se,us]=c.useState([]),[Sn,Cn]=c.useState("rules"),[ae,$n]=c.useState("keyword"),[Ft,Dt]=c.useState(""),[cr,zn]=c.useState("Sentrum"),[dr,Tn]=c.useState("2"),[xt,xr]=c.useState("none"),[hs,gs]=c.useState(""),[Ne,En]=c.useState(""),[mr,pr]=c.useState([]),[ur,fs]=c.useState(!1),[_s,hr]=c.useState(""),[gr,Ln]=c.useState("Stoa"),[fr,_r]=c.useState(!1);c.useRef(null);const[jr,js]=c.useState(T.get("tab")||"orders");c.useEffect(()=>{const t=T.get("tab");t&&t!==jr&&js(t)},[T]);const[ks,Pn]=c.useState(new Set),[On,bs]=c.useState(!1),[kr,An]=c.useState(new Set),[Kn,Ut]=c.useState(!1),[br,In]=c.useState(new Map),[q,Rn]=c.useState(()=>new Map(kt)),[mt,wr]=c.useState(new Set),[ws,Ce]=c.useState(null),[Mn,Fn]=c.useState(new Set),[Nr,yr]=c.useState(null),[Ns,Dn]=c.useState(new Set),vr=t=>{Dn(s=>{const n=new Set(s);return n.has(t)?n.delete(t):n.add(t),n})},[$e,Un]=c.useState(new Map),[pt,ys]=c.useState(new Map),[Sr,Cr]=c.useState(null),[$r,zr]=c.useState(null),[Ye,vs]=c.useState(null),[le,Bt]=c.useState(null),Bn=t=>{Fn(s=>{const n=new Set(s);return n.has(t)?n.delete(t):n.add(t),n})},Vt=({item:t,eanKey:s,className:n=""})=>{var o;const a=((o=t.ean_codes)==null?void 0:o.length)>0?t.ean_codes:t.ean_code?[t.ean_code]:[];if(a.length===0)return e.jsx("span",{className:n,children:"–"});const r=a.length>1,l=Mn.has(s);return e.jsxs("span",{className:n,children:[e.jsxs("span",{className:"inline-flex items-center gap-0.5",children:[a[0],r&&e.jsx("button",{onClick:x=>{x.stopPropagation(),Bn(s)},className:"inline-flex items-center justify-center rounded hover:bg-muted transition-colors ml-0.5",title:`${a.length} strekkoder`,children:e.jsxs(I,{variant:"outline",className:"text-[9px] px-1 py-0 h-3.5 cursor-pointer hover:bg-accent",children:["+",a.length-1]})})]}),r&&l&&e.jsx("span",{className:"block mt-0.5 space-y-0.5",children:a.slice(1).map((x,d)=>e.jsx("span",{className:"block text-muted-foreground",children:x},d))})]})},Tr=t=>{An(s=>{const n=new Set(s);return n.has(t)?n.delete(t):n.add(t),n})},qt=t=>{var n;return(((n=t.ean_codes)==null?void 0:n.length)>0?t.ean_codes:t.ean_code?[t.ean_code]:[]).join("<br>")},S=c.useCallback(t=>te.has(t),[te]),v=(t,s,n,a,r)=>`${t}|${s}|${n}|${a}|${r}`,Ht=c.useCallback(t=>{const s=Se.filter(n=>n.is_active);for(const n of s){const a=(n.match_value||"").toLowerCase().trim();if(n.rule_type==="stock_diff"){const o=Math.max(0,t.available_stoa||0),x=Math.max(0,t.available_sentrum||0),d=o-x,m=d>0?"Stoa":"Sentrum",p=d>0?o:x;if(Math.abs(d)>=(n.threshold||2)&&p>=1)return{store:m,label:`Lagerregel: forskjell på ${Math.abs(d)} stk (grense ${n.threshold||2})`};continue}const r=(n.category_value||"").toLowerCase().trim();if(r&&((n.category_field==="maingroup"?t.maingroup_name:n.category_field==="webgroup1"?t.webgroup1_name:n.category_field==="webgroup2"?t.webgroup2_name:n.category_field==="webgroup3"?t.webgroup3_name:"")||"").toLowerCase()!==r||!a)continue;if(n.rule_type==="webgroup1"?(t.webgroup1_name||"").toLowerCase()===a:n.rule_type==="webgroup2"?(t.webgroup2_name||"").toLowerCase()===a:n.rule_type==="webgroup3"?(t.webgroup3_name||"").toLowerCase()===a:n.rule_type==="maingroup"?(t.maingroup_name||"").toLowerCase()===a:n.rule_type==="manufacturer"?(t.manufacturer_name||"").toLowerCase().includes(a):`${t.article_name||""} ${t.manufacturer_name||""}`.toLowerCase().includes(a))return{store:n.target_store,label:`Butikkregel: ${n.rule_type} «${n.match_value}»${r?` + ${n.category_value}
21`:""}`}}return null},[Se]),Ss=c.useCallback(t=>{var s;return((s=Ht(t))==null?void 0:s.store)??null},[Ht]),Er=c.useCallback(t=>{const s=B.get(t.article_no);return s?s.target_store:Ss(t)??t.warehouse},[B,Ss]),O=c.useCallback((t,s)=>{for(const n of as)if(N.has(v(t,s.article_no,s.size_name,s.color_name,n)))return Xa[n];return Er(s)},[N,Er]),Wt=c.useCallback((t,s)=>as.some(n=>N.has(v(t,s.article_no,s.size_name,s.color_name,n)))||B.has(s.article_no),[N,B]),Vn=async(t,s,n,a=!1)=>{const{data:{user:r}}=await j.auth.getUser();if(!r)return;for(const d of as){const m=v(t,s.article_no,s.size_name,s.color_name,d),p=N.get(m);p&&(await j.from("web_order_item_actions").delete().eq("id",p.id),Ke(u=>{const h=new Map(u);return h.delete(m),h}))}const l=Ss(s)??s.warehouse;if(n===l){await Cs(s.article_no,!0);return}const o=Ja[n];if(!o)return;const{data:x}=await j.from("web_order_item_actions").insert({order_id:t,article_no:s.article_no,size_name:s.size_name,color_name:s.color_name,action_type:o,created_by:r.id}).select().single();if(x){const d=v(t,s.article_no,s.size_name,s.color_name,o);Ke(m=>new Map([...m,[d,x]]))}a?(await Hn(s,n,r.id),w.success(`Lager overstyrt til ${n} – varenr ${s.article_no} huskes til neste bestilling`)):w.success(`Lager overstyrt til ${n} for denne ordren`)},qn=async(t,s)=>{let n=!1;for(const a of as){const r=v(t,s.article_no,s.size_name,s.color_name,a),l=N.get(r);if(l){const{error:o}=await j.from("web_order_item_actions").delete().eq("id",l.id);if(o){w.error("Kunne ikke fjerne overstyring");return}Ke(x=>{const d=new Map(x);return d.delete(r),d}),n=!0}}if(B.has(s.article_no)&&(await Cs(s.article_no,!0),n=!0),n)w.success("Overstyring fjernet");else{const a=Ht(s);w.info(a?`Ingen manuell overstyring her – lageret er satt av en butikkregel (${a.label}). Endre regelen under «Butikkregler».`:"Ingen manuell overstyring å fjerne på denne varelinjen.")}},Hn=async(t,s,n)=>{const{data:a,error:r}=await j.from("web_order_article_routing").upsert({article_no:t.article_no,article_name:t.article_name||null,color_name:t.color_name||null,target_store:s,source:"manual",created_by:n},{onConflict:"article_no"}).select().single();if(r){console.error("saveArticleRouting",r);return}dt(l=>new Map([...l,[t.article_no,a]]))},Cs=async(t,s=!1)=>{if(!B.has(t))return;const{error:n}=await j.from("web_order_article_routing").delete().eq("article_no",t);if(n){w.error("Kunne ikke fjerne fast butikkvalg");return}dt(a=>{const r=new Map(a);return r.delete(t),r}),s||w.success(`Fast butikkvalg fjernet for ${t}`)},Q=c.useCallback((t,s,n,a,r)=>N.has(v(t,s,n,a,r)),[N]),me=c.useCallback(t=>Math.max(1,(t.delivered_qty>0?t.remaining_units:t.units)||1),[]),ze=c.useCallback((t,s,n)=>{const a=me(s),r=n?[n]:[_.PLUKKET_SENTRUM,_.PLUKKET_STOA];let l=0;for(const o of r){const x=N.get(v(t,s.article_no,s.size_name,s.color_name,o));x&&(l+=x.picked_qty==null?a:Math.max(0,x.picked_qty))}return l},[N,me]),Ie=c.useCallback((t,s)=>ze(t,s)>=me(s),[ze,me]),Lr=c.useCallback((t,s)=>{const n=ze(t,s);return n>0&&n<me(s)},[ze,me]),Wn=c.useCallback((t,s,n,a)=>{const r=[];for(const[l,o]of N)l.startsWith(`${t}|${s}|${n}|${a}|`)&&r.push(o);return r},[N]),Yn=async()=>{const{data:t}=await j.from("frakt_produkter").select("article_no, article_name");t&&g(new Map(t.map(s=>[s.article_no,s.article_name||""])))},$s=async()=>{const t=[];for(let a=0;;a+=1e3){const{data:r,error:l}=await j.from("web_order_notes").select("*").order("id").range(a,a+999);if(l){console.error("Kunne ikke hente notater",l);return}if(t.push(...r||[]),!r||r.length<1e3)break}const s=[...new Set(t.flatMap(a=>[a.created_by,a.updated_by].filter(Boolean)))];let n={};if(s.length>0){const{data:a}=await j.from("employees").select("id, full_name").in("id",s);a&&(n=Object.fromEntries(a.map(r=>[r.id,r.full_name])))}He(new Map(t.map(a=>[a.order_id,{...a,updated_employee:a.updated_by?{full_name:n[a.updated_by]||""}:null,created_employee:a.created_by?{full_name:n[a.created_by]||""}:null}])))},Pr=async()=>{let s=0;const n=new Map;for(;;){const{data:a,error:r}=await j.from("web_order_shipments").select("order_id, article_no, size_name, color_name, shipped_qty").order("created_at",{ascending:!0}).range(s,s+1e3-1);if(r){console.error("Failed to fetch web_order_shipments:",r);return}for(const l of a||[]){const o=`${l.order_id}|${l.article_no}|${l.size_name||""}|${l.color_name||""}`;n.set(o,(n.get(o)||0)+(l.shipped_qty||0))}if(!a||a.length<1e3)break;s+=1e3}un(n)},Or=c.useCallback((t,s)=>sr.get(`${t}|${s.article_no}|${s.size_name||""}|${s.color_name||""}`)||0,[sr]),Ge=c.useCallback((t,s)=>Or(t,s)>=Math.max(1,s.remaining_units||s.units||1),[Or]),Qe=async()=>{let s=0;const n=[];for(;;){const{data:r,error:l}=await j.from("web_order_item_actions").select("*").order("created_at",{ascending:!1}).range(s,s+1e3-1);if(l){console.error("Failed to fetch web_order_item_actions:",l);return}if(!r||r.length===0||(n.push(...r),r.length<1e3))break;s+=1e3}const a=new Map;for(const r of n)a.set(v(r.order_id,r.article_no,r.size_name,r.color_name,r.action_type),r);Ke(a)},Ar=async()=>{var n;const{data:t}=await j.from("webgroup_store_rules").select("id, webgroup1_name, target_store");t&&nr(t);const{data:s}=await j.from("pck_dimension_cache").select("dimension, dim_name").in("dimension",["manufacturer","maingroup","webgroup1","webgroup2","webgroup3"]).order("dim_name");if(s){const a={};for(const r of s)r.dim_name&&(a[n=r.dimension]||(a[n]=[])).push(r.dim_name);kn(a),jn(a.webgroup1||[])}},Gn=async()=>{const{data:t}=await j.from("web_order_article_routing").select("id, article_no, article_name, color_name, target_store, created_by, created_at").order("created_at",{ascending:!1});t&&dt(new Map(t.map(s=>[s.article_no,s])))},Kr=async()=>{const{data:t}=await j.from("store_routing_rules").select("id, rule_type, match_value, category_field, category_value, target_store, threshold, priority, is_active").order("priority",{ascending:!0});t&&us(t)},Qn=async()=>{const{data:{user:t}}=await j.auth.getUser();if(!t)return;if(ae!=="stock_diff"&&!Ft.trim()){w.error("Fyll inn verdi for regelen");return}const s=ae!=="stock_diff"&&xt!=="none"&&!!hs.trim(),{error:n}=await j.from("store_routing_rules").insert({rule_type:ae,match_value:ae==="stock_diff"?null:Ft.trim(),category_field:s?xt:null,category_value:s?hs.trim():null,target_store:ae==="stock_diff"?"auto":cr,threshold:Number(dr)||2,priority:(Se.length+1)*10,created_by:t.id});if(n){w.error("Kunne ikke legge til regel");return}Dt(""),xr("none"),gs(""),await Kr(),w.success("Regel lagt til")},Zn=async t=>{const{error:s}=await j.from("store_routing_rules").update({is_active:!t.is_active}).eq("id",t.id);if(s){w.error("Kunne ikke oppdatere regel");return}us(n=>n.map(a=>a.id===t.id?{...a,is_active:!a.is_active}:a))},Xn=async t=>{const{error:s}=await j.from("store_routing_rules").delete().eq("id",t);if(s){w.error("Kunne ikke fjerne regel");return}us(n=>n.filter(a=>a.id!==t))},Jn=async()=>{const{data:t}=await j.from("employees").select("id, full_name");t&&In(new Map(t.map(s=>[s.id,s.full_name])))},Yt=c.useCallback((t,s,n,a,r)=>{const l=N.get(v(t,s,n,a,r));if(!(l!=null&&l.created_by))return"";const o=br.get(l.created_by);return o?o.split(" ")[0]:""},[N,br]),ea=async()=>
21{if(!ps.trim())return;const{data:{user:t}}=await j.auth.getUser();if(!t)return;const{error:s}=await j.from("webgroup_store_rules").insert({webgroup1_name:ps.trim(),target_store:ir,created_by:t.id});if(s){w.error(s.message.includes("duplicate")?"Denne webgruppen har allerede en regel":"Kunne ikke legge til");return}await Ar(),lr(""),w.success("Regel lagt til – oppdater ordrelisten for å se endringer")},ta=async t=>{await j.from("webgroup_store_rules").delete().eq("id",t),nr(s=>s.filter(n=>n.id!==t)),w.success("Regel fjernet – oppdater ordrelisten for å se endringer")},Ir=async(t,s)=>{const{data:{user:n}}=await j.auth.getUser();if(!n)return;const{error:a}=await j.from("frakt_produkter").insert({article_no:t,article_name:null,created_by:n.id});if(a){w.error("Kunne ikke legge til");return}g(r=>new Map([...r,[t,""]])),w.success(`${t} lagt til i ekskluderingslisten`)},sa=async t=>{const{error:s}=await j.from("frakt_produkter").delete().eq("article_no",t);if(s){w.error("Kunne ikke fjerne");return}g(n=>{const a=new Map(n);return a.delete(t),a}),w.success(`${t} fjernet fra ekskluderingslisten`)},Gt=async(t,s,n=!1)=>{const{data:{user:a}}=await j.auth.getUser();if(!a)return;const r=V.get(t);if(s.trim()==="")r&&(await j.from("web_order_notes").delete().eq("order_id",t),He(l=>{const o=new Map(l);return o.delete(t),o}));else if(r){const{data:l}=await j.from("web_order_notes").update({note:s,is_question:n,updated_by:a.id,updated_at:new Date().toISOString()}).eq("order_id",t).select().single();l&&He(o=>new Map([...o,[t,l]]))}else{const{data:l}=await j.from("web_order_notes").insert({order_id:t,note:s,is_question:n,created_by:a.id}).select().single();l&&He(o=>new Map([...o,[t,l]]))}it(null),ct(!1),w.success("Notat lagret")},ra=async(t,s)=>{const{data:{user:n}}=await j.auth.getUser();if(!n)return;const{data:a}=await j.from("web_order_notes").update({answer:s.trim()||null,answered_by:s.trim()?n.id:null,answered_at:s.trim()?new Date().toISOString():null}).eq("order_id",t).select().single();a&&He(r=>new Map([...r,[t,a]])),Rt(null),Mt(""),w.success(s.trim()?"Svar lagret":"Svar slettet")},na=async t=>{const s=V.get(t);if(!s)return;const n=!s.is_pinned,{data:a}=await j.from("web_order_notes").update({is_pinned:n}).eq("order_id",t).select().single();a&&He(r=>new Map([...r,[t,a]])),w.success(n?"Notat festet til plukkliste":"Notat fjernet fra plukkliste")},ut=c.useRef(0),zs=c.useRef(new Set),Rr=async(t,s,n,a,r,l)=>{const o=v(t,s,n,a,r),x=N.get(o);if(!x)return;ut.current=Date.now();const{error:d}=await j.from("web_order_item_actions").update({picked_qty:l}).eq("id",x.id);if(d){w.error("Kunne ikke oppdatere antall");return}Ke(m=>new Map([...m,[o,{...x,picked_qty:l}]])),ut.current=Date.now()},re=async(t,s,n,a,r,l,o)=>{const x=v(t,s,n,a,r);if(!zs.current.has(x)){zs.current.add(x),ut.current=Date.now();try{const d=N.get(x);if(d){const{error:m}=await j.from("web_order_item_actions").delete().eq("id",d.id);if(m){w.error("Kunne ikke oppdatere plukkstatus");return}Ke(p=>{const u=new Map(p);return u.delete(x),u})}else{const{data:{user:m}}=await j.auth.getUser();if(!m)return;const{data:p,error:u}=await j.from("web_order_item_actions").insert({order_id:t,article_no:s,size_name:n,color_name:a,action_type:r,created_by:m.id,...l?{action_date:l}:{},...o!=null?{picked_qty:o}:{}}).select().single();if(u){if(u.code==="23505"){await Qe();return}w.error("Kunne ikke oppdatere plukkstatus");return}const h=p??{id:`optimistic-${x}-${Date.now()}`,order_id:t,article_no:s,size_name:n,color_name:a,action_type:r,created_by:m.id,created_at:new Date().toISOString(),picked_qty:o??null};Ke(k=>new Map([...k,[x,h]])),p||setTimeout(()=>{Qe()},500)}}finally{zs.current.delete(x),ut.current=Date.now()}}},Mr=async()=>{ee(!0);try{const{data:t,error:s}=await j.functions.invoke("pck-active-web-orders");if(s)throw s;J(t.orders||[])}catch(t){console.error("Error fetching orders:",t),w.error("Kunne ikke hente nettordre: "+(t.message||"Ukjent feil"))}finally{ee(!1)}},aa=async()=>{try{const{data:t,error:s}=await j.functions.invoke("pck-web-orders");!s&&(t!=null&&t.orders)&&je(t.orders.length)}catch(t){console.error("Error fetching shipped today:",t)}},la=async()=>{try{const t=await Ea();Un(t)}catch(t){console.error("Failed to fetch product URLs:",t)}},Fr=async()=>{const{data:t}=await j.from("workshop_orders").select("id, web_order_id, status, order_number").eq("source","nettbutikk").not("web_order_id","is",null);if(t){const s=new Map;for(const n of t)s.set(n.web_order_id,{id:n.id,status:n.status,order_number:n.order_number});ys(s)}},ia=async t=>{const{data:{user:s}}=await j.auth.getUser();if(s){Cr(t.order_id);try{const n=t.items.filter(l=>!S(l.article_no)).map(l=>`${l.article_name} (${l.article_no})${l.size_name?" - "+l.size_name:""}${l.color_name?" / "+l.color_name:""} x${l.units}`).join(`
22`),{data:a,error:r}=await j.from("workshop_orders").insert({order_number:String(t.order_id),customer_name:t.delivery_name,customer_phone:t.customer_phone||"",customer_email:t.customer_email||null,device_description:n,problem_description:[t.order_info,t.pl_info].filter(
22Boolean).join(`
23`)||null,status:"levert_inn",source:"nettbutikk",web_order_id:t.order_id,created_by:s.id}).select("id, web_order_id, status, order_number").single();if(r)throw r;a&&(ys(l=>new Map([...l,[t.order_id,{id:a.id,status:a.status,order_number:a.order_number}]])),w.success("Verkstedordre opprettet"))}catch(n){w.error("Kunne ikke opprette verkstedordre: "+(n.message||"Ukjent feil"))}finally{Cr(null)}}};c.useEffect(()=>{Mr(),Yn(),$s(),Qe(),Pr(),Ar(),Gn(),Kr(),aa(),Jn(),la(),Fr()},[]),c.useEffect(()=>{let t=null;const s=j.channel("nettbutikk-realtime").on("postgres_changes",{event:"*",schema:"public",table:"web_order_item_actions"},()=>{if(Date.now()-ut.current<2e3){t&&clearTimeout(t),t=setTimeout(()=>Qe(),2e3);return}Qe()}).on("postgres_changes",{event:"*",schema:"public",table:"web_order_notes"},()=>{$s()}).on("postgres_changes",{event:"*",schema:"public",table:"web_order_shipments"},()=>{Pr()}).subscribe();return()=>{t&&clearTimeout(t),j.removeChannel(s)}},[]),c.useEffect(()=>{const t=j.channel("workshop-orders-nettbutikk").on("postgres_changes",{event:"UPDATE",schema:"public",table:"workshop_orders",filter:"source=eq.nettbutikk"},()=>{Fr()}).subscribe();return()=>{j.removeChannel(t)}},[]);const oa=t=>t.remaining_units===0&&t.delivered_qty>0,A=c.useCallback((t,s)=>oa(s)||Ge(t,s),[Ge]),Ze=c.useCallback(t=>{const s={};for(const a of t.items){if(S(a.article_no)||A(t.order_id,a))continue;const r=O(t.order_id,a),l=r==="Begge"?"Stoa":r;s[l]=(s[l]||0)+1}const n=Object.keys(s);return n.length===0?"Stoa":n.length===1?n[0]:"Blandet"},[S,O,A]),ca=t=>t.toLowerCase().includes("klikk")||t.toLowerCase().includes("hent"),Dr=t=>{const s=(t.shipping_method||"").toLowerCase();return s.includes("klikk")?t.items.some(n=>{if(A(t.order_id,n))return!1;const a=O(t.order_id,n);return a==="Stoa"&&s.includes("sentrum")||a==="Sentrum"&&s.includes("stoa")}):!1},Ur=c.useMemo(()=>{const t=new Set(y.map(n=>n.shipping_method).filter(Boolean)),s=["posten","klikk","hent","elektronisk"];return Array.from(t).sort((n,a)=>{const r=s.findIndex(o=>n.toLowerCase().includes(o)),l=s.findIndex(o=>a.toLowerCase().includes(o));return(r===-1?99:r)-(l===-1?99:l)})},[y]),Qt=c.useCallback((t,s)=>{const n=t.items.filter(l=>!S(l.article_no)&&!A(t.order_id,l));if(n.length===0)return!1;const a=(l,o)=>N.has(v(t.order_id,l.article_no,l.size_name,l.color_name,o));if(!n.every(l=>Ie(t.order_id,l)))return!1;if(s==="Sentrum"||s==="Stoa"){const l=s==="Sentrum"?_.PLUKKET_SENTRUM:_.PLUKKET_STOA;return n.some(o=>a(o,l))}return!0},[S,N,A,Ie]),Te=c.useMemo(()=>{const t=new Set;for(const s of y){const n=new Set(s.items.filter(a=>!S(a.article_no)&&!A(s.order_id,a)).map(a=>O(s.order_id,a)).filter(a=>a==="Stoa"||a==="Sentrum"));n.has("Stoa")&&n.has("Sentrum")&&t.add(s.order_id)}return t},[y,S,O,A]),ht=c.useMemo(()=>{const t=new Set;for(const s of y){const n=new Set(s.items.filter(a=>!S(a.article_no)&&!A(s.order_id,a)).map(a=>{const r=O(s.order_id,a);return r==="Begge"?"Stoa":r}).filter(Boolean));n.has("Stadion")&&n.size>1&&t.add(s.order_id)}return t},[y,S,O,A]);c.useMemo(()=>{const t=[];for(const s of y){const n=s.items.filter(r=>!S(r.article_no)&&!A(s.order_id,r));if(n.some(r=>O(s.order_id,r)==="Stadion"))for(const r of n){const l=O(s.order_id,r),o=Q(s.order_id,r.article_no,r.size_name,r.color_name,_.BESTILT_STADION);t.push({order_id:s.order_id,article_no:r.article_no,article_name:r.article_name,size_name:r.size_name,color_name:r.color_name,qty:r.remaining_units||r.units||1,ordered:o,reason:l==="Stadion"||o?"stadion":"samlefrakt"})}}return t},[y,S,O,Q,A]);const pe=c.useMemo(()=>{let t=y;if(f!=="all"&&(t=t.filter(s=>{const n=(s.shipping_method||"").toLowerCase();if(f==="Stoa"&&n.includes("klikk")&&n.includes("stoa")||f==="Sentrum"&&n.includes("klikk")&&n.includes("sentrum"))return!0;const a=s.items.filter(l=>!S(l.article_no)&&!A(s.order_id,l));if(a.length>0&&a.every(l=>N.has(v(s.order_id,l.article_no,l.size_name,l.color_name,_.PLUKKET_SENTRUM))||N.has(v(s.order_id,l.article_no,l.size_name,l.color_name,_.PLUKKET_STOA)))){const l=f==="Sentrum"?_.PLUKKET_SENTRUM:f==="Stoa"?_.PLUKKET_STOA:null;return l?a.some(o=>N.has(v(s.order_id,o.article_no,o.size_name,o.color_name,l))):!1}return a.some(l=>{if(N.has(v(s.order_id,l.article_no,l.size_name,l.color_name,_.PLUKKET_SENTRUM))||N.has(v(s.order_id,l.article_no,l.size_name,l.color_name,_.PLUKKET_STOA)))return!1;const x=O(s.order_id,l);return x===f||f==="Stoa"&&x==="Begge"||f==="Stoa"&&l.available_stoa>0||f==="Sentrum"&&l.available_sentrum>=1})})),be!=="all"&&(t=t.filter(s=>s.shipping_method===be)),$t==="hide"?t=t.filter(s=>!V.has(s.order_id)):$t==="only"&&(t=t.filter(s=>V.has(s.order_id))),zt==="hide"?t=t.filter(s=>!s.items.some(n=>N.has(v(s.order_id,n.article_no,n.size_name,n.color_name,_.BESTILT_STADION)))):zt==="only"&&(t=t.filter(s=>s.items.some(n=>N.has(v(s.order_id,n.article_no,n.size_name,n.color_name,_.BESTILT_STADION))))),Tt==="hide"?t=t.filter(s=>!Te.has(s.order_id)&&!Dr(s)):Tt==="only"&&(t=t.filter(s=>Te.has(s.order_id)||Dr(s))),Et==="hide"?t=t.filter(s=>!ht.has(s.order_id)):Et==="only"&&(t=t.filter(s=>ht.has(s.order_id))),Lt==="hide"?t=t.filter(s=>!s.items.some(n=>N.has(v(s.order_id,n.article_no,n.size_name,n.color_name,_.IKKE_FUNNET)))):Lt==="only"&&(t=t.filter(s=>s.items.some(n=>N.has(v(s.order_id,n.article_no,n.size_name,n.color_name,_.IKKE_FUNNET))))),Pt==="hide"?t=t.filter(s=>!Qt(s,f)):Pt==="only"&&(t=t.filter(s=>Qt(s,f))),At!=="off"){const s=n=>{const a=n.items.filter(r=>!S(r.article_no));return a.length>0&&a.every(r=>Ge(n.order_id,r))};t=At==="hide"?t.filter(n=>!s(n)):t.filter(s)}if(Ot!=="off"){const s=n=>{const a=n.items.filter(r=>!S(r.article_no));return a.length>0&&a.every(r=>A(n.order_id,r))};t=Ot==="hide"?t.filter(n=>!s(n)):t.filter(s)}if(U.trim()){const s=U.toLowerCase();t=t.filter(n=>{const a=V.get(n.order_id);return n.order_id.toString().includes(s)||(n.external_ref||"").toLowerCase().includes(s)||n.delivery_name.toLowerCase().includes(s)||n.customer_email.toLowerCase().includes(s)||((a==null?void 0:a.note)||"").toLowerCase().includes(s)||((a==null?void 0:a.answer)||"").toLowerCase().includes(s)||n.items.some(r=>r.article_name.toLowerCase().includes(s)||r.article_no.includes(s))})}return t=[...t].sort((s,n)=>{const a=ke==="asc"?1:-1;switch(ve){case"warehouse":return a*Ze(s).localeCompare(Ze(n));case"order":return a*(s.order_id-n.order_id);case"customer":return a*s.delivery_name.localeCompare(n.delivery_name);case"items":{const r=s.items.filter(o=>!S(o.article_no)).length,l=n.items.filter(o=>!S(o.article_no)).length;return a*(r-l)}case"shipping":return a*(s.shipping_method||"").localeCompare(n.shipping_method||"");case"city":return a*(s.delivery_city||"").localeCompare(n.delivery_city||"");case"amount":return a*(s.total_revenue-n.total_revenue);case"date":default:return a*(new Date(s.order_date).getTime()-new Date(n.order_date).getTime())}}),t},[y,f,be,U,ke,ve,S,$t,zt,Tt,Et,Lt,Ot,At,Ge,V,N,Pt,Qt,Ze,O,Te,ht,A]),ce=c.useMemo(()=>{const t=pe.flatMap(a=>a.items.filter(r=>{if(S(r.article_no)||A(a.order_id,r))return!1;if(f!=="all"){const l=O(a.order_id,r),o=l===f||f==="Stoa"&&l==="Begge",x=f==="Stoa"&&r.available_stoa>0||f==="Sentrum"&&r.available_sentrum>=1;if(!o&&!x)return!1}return!(N.has(v(a.order_id,r.article_no,r.size_name,r.color_name,_.BESTILT_STADION))&&!(r.warehouse==="Sentrum"?r.available_sentrum>=1:r.available_stoa>=0)||ds&&Ie(a.order_id,r))}).map(r=>({...r,order_id:a.order_id,order_info:a.order_info,delivery_name:a.delivery_name,shipping_method:a.shipping_method}))),s={};for(const a of t){const r=Pe==="manufacturer"?a.manufacturer_name||"Ukjent produsent":Pe==="order"?`Ordre ${a.order_id} – ${a.delivery_name}`:a.maingroup_name||"Ukategorisert";s[r]||(s[r]=[]),s[r].push(a)}const n=Object.entries(s).sort((a,r)=>a[0].localeCompare(r[0]));for(const[,a]of n)a.sort((r,l)=>r.manufacturer_name.localeCompare(l.manufacturer_name)||r.article_name.localeCompare(l.article_name));return n},[pe,f,N,Pe,ds,S,O,A]),ue=c.useCallback(async t=>{const s=t.filter(a=>!bt.has(a)&&!mt.has(a));if(s.length===0)return;wr(a=>
23{const r=new Set(a);return s.forEach(l=>r.add(l)),r});const n=[];for(let a=0;a<s.length;a+=20)n.push(s.slice(a,a+20));for(const a of n)try{const{data:r,error:l}=await j.functions.invoke("pck-article-image",{body:{article_ids:a}});if(!l&&(r!=null&&r.images)){const o=new Map;for(const[x,d]of Object.entries(r.images))kt.set(x,d),bt.add(x),o.set(x,d);for(const x of a)bt.add(x),kt.has(x)||kt.set(x,"");Rn(x=>{const d=new Map(x);for(const[m,p]of kt)d.set(m,p);return d})}}catch(r){console.error("Failed to fetch article images:",r)}wr(a=>{const r=new Set(a);return s.forEach(l=>r.delete(l)),r})},[mt]);c.useEffect(()=>{if(y.length>0){const s=[...new Set(y.flatMap(n=>n.items.map(a=>a.article_no)))].filter(n=>!bt.has(n));s.length>0&&ue(s)}},[y]),c.useEffect(()=>{if(B.size===0)return;const t=[...B.keys()].filter(s=>!bt.has(s));t.length>0&&ue(t)},[B]),c.useEffect(()=>{const t=Ne.trim();if(t.length<2){pr([]),fs(!1);return}let s=!1;fs(!0);const n=setTimeout(async()=>{const{data:a}=await j.from("pck_product_cache").select("article_no, name, cached_colors").or(`article_no.ilike.%${t}%,name.ilike.%${t}%`).limit(15);s||(pr((a||[]).map(r=>({article_no:r.article_no,name:r.name,colors:r.cached_colors||[]}))),fs(!1))},300);return()=>{s=!0,clearTimeout(n)}},[Ne]);const Br=async(t,s)=>{const{data:{user:n}}=await j.auth.getUser();if(!n)return;const{data:a,error:r}=await j.from("web_order_article_routing").upsert({article_no:t.article_no,article_name:t.name||null,color_name:t.colors.length>0?t.colors.join(", "):null,target_store:s,source:"manual",created_by:n.id},{onConflict:"article_no"}).select().single();if(r){w.error("Kunne ikke lagre fast butikkvalg");return}dt(l=>new Map([...l,[t.article_no,a]])),ue([t.article_no]),w.success(`${t.name||t.article_no} → ${s}`)},da=async(t,s)=>{const n=[...new Set(t.split(/[^0-9]+/).map(m=>m.trim()).filter(m=>m.length>=3))];if(n.length===0){w.error("Fant ingen varenr i listen");return}const{data:{user:a}}=await j.auth.getUser();if(!a)return;_r(!0);const r=new Map;for(let m=0;m<n.length;m+=200){const{data:p}=await j.from("pck_product_cache").select("article_no, name, cached_colors").in("article_no",n.slice(m,m+200));for(const u of p||[])r.set(u.article_no,{name:u.name,colors:u.cached_colors||[]})}const l=n.map(m=>{var p,u;return{article_no:m,article_name:((p=r.get(m))==null?void 0:p.name)||null,color_name:(((u=r.get(m))==null?void 0:u.colors)||[]).length>0?r.get(m).colors.join(", "):null,target_store:s,source:"manual",created_by:a.id}}),{data:o,error:x}=await j.from("web_order_article_routing").upsert(l,{onConflict:"article_no"}).select();if(_r(!1),x){w.error("Kunne ikke lagre varenumrene");return}dt(m=>{const p=new Map(m);for(const u of o||[])p.set(u.article_no,u);return p}),ue(n),hr("");const d=n.filter(m=>!r.has(m)).length;w.success(`${n.length} varenr lagt til på ${s}${d>0?` (${d} uten varenavn)`:""}`)},[xa,Ts]=c.useState(null);c.useEffect(()=>{const t=T.get("search"),s=T.get("from");if(t&&!M&&y.length>0){const n=Number(t.replace(/\D/g,""));if(n){if(s==="returer")Ts(String(n)),Ut(!0);else{const a=y.find(r=>r.order_id===n);a?(qe(r=>new Set(r).add(n)),ue([...new Set(a.items.map(r=>r.article_no))])):(Ts(String(n)),Ut(!0),w.info(`Ordre ${n} er ikke aktiv – søker i ferdigmeldte...`))}Y({},{replace:!0})}}},[M,y,T,ue,Y]);const ma=t=>{qe(s=>{if(s.has(t))return new Set;{const n=y.find(a=>a.order_id===t);if(n){const a=[...new Set(n.items.map(r=>r.article_no))];ue(a)}return new Set([t])}})},Vr=t=>{lt(s=>{const n=new Set(s);return n.has(t)?n.delete(t):n.add(t),n})},pa=()=>{we.size===pe.length?lt(new Set):lt(new Set(pe.map(t=>t.order_id)))},gt=t=>{switch(t){case"Stoa":return"bg-emerald-100 text-emerald-800 dark:bg-emerald-900/30 dark:text-emerald-300";case"Sentrum":return"bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-300";case"Stadion":return"bg-amber-100 text-amber-800 dark:bg-amber-900/30 dark:text-amber-300";default:return"bg-muted text-muted-foreground"}},Zt=t=>t?new Date(t).toLocaleDateString("nb-NO",{day:"2-digit",month:"2-digit",year:"numeric"}):"",ua=t=>{if(!t)return"";const s=new Date(t);return`${s.getDate()}. ${s.toLocaleDateString("nb-NO",{month:"long"})}`},qr=t=>t?new Date(t).toLocaleTimeString("nb-NO",{hour:"2-digit",minute:"2-digit"}):"",ha=c.useCallback(t=>{const s=te.get(t);if(s)return s;for(const n of y)for(const a of n.items)if(a.article_no===t)return a.article_name;return""},[te,y]),Es=(t,s)=>{const n=t??pe.filter(h=>we.has(h.order_id));if(n.length===0){w.error("Velg minst én ordre å skrive ut");return}if(s===void 0){const h=n.filter(k=>{var C;const W=V.get(k.order_id);return W&&((C=W.note)==null?void 0:C.trim())});if(h.length>0){Bt({orders:n,ordersWithNotes:h});return}}const a=f==="all"?"Alle lager":f,r=et.startsWith("http")?et:`${window.location.origin}${et}`,l=window.open("","_blank");if(!l)return;const o=n.map(h=>{var W;const k=V.get(h.order_id);return`
24      <div class="order-page" style="page-break-after: always;">
25        <div style="text-align: center; margin-bottom: 20px;">
26          <img src="${r}" style="height: 50px; max-width: 260px; object-fit: contain;" />
27        </div>
28
29        <div style="display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px;">
30          <div>
31            <p style="margin: 2px 0;">${h.delivery_name}</p>
32            <p style="font-size: 15px; font-weight: bold; margin: 2px 0;">Plukkliste ordrenr. ${h.order_id}</p>
33            <div style="margin: 4px 0 0 0;">${dn(String(h.order_id),{height:34})}</div>
34          </div>
35          <div style="text-align: right;">
36            <p style="font-size: 11px; margin: 2px 0;">Ordredato: ${Zt(h.order_date)}</p>
37            <p style="font-size: 11px; margin: 2px 0;">Kl: ${qr(h.order_date)}</p>
38          </div>
39        </div>
40
41        <div style="margin-bottom: 12px; font-size: 12px;">
42          <p style="margin: 2px 0;">${h.delivery_address}</p>
43          <p style="margin: 2px 0;">${h.delivery_zipcode} ${h.delivery_city}</p>
44          ${h.customer_phone?`<p style="margin: 2px 0;">Tlf: ${h.customer_phone}</p>`:""}
45          ${h.customer_email?`<p style="margin: 2px 0;">${h.customer_email}</p>`:""}
46        </div>
47
48        ${(()=>{const C=(h.shipping_method||"").toLowerCase();return C.includes("klikk")||C.includes("click")?`<div style="text-align: center; margin: 30px 0; padding: 20px 0;">
49              <p style="font-size: 36px; font-weight: 900; color: #000; letter-spacing: 1px; text-transform: uppercase; margin: 0;">KLIKK & HENT</p>
50              <p style="font-size: 18px; font-weight: 700; color: #000; margin: 8px 0 0 0;">${h.shipping_method}</p>
51            </div>`:`<p style="font-size: 12px; margin-bottom: 8px;">Ønsket levering: ${h.shipping_method||"Ikke spesifisert"}</p>`})()}
52        ${h.order_info?`<p style="font-size: 12px; margin-bottom: 8px; color: #c00;">Info: ${Le(h.order_info)}</p>`:""}
53        ${h.pl_info?`<p style="font-size: 12px; margin-bottom: 8px; color: #c00;">📋 Plukkliste: ${Le(h.pl_info)}</p>`:""}
54        ${k!=null&&k.is_pinned?`<div style="font-size: 12px; margin-bottom: 8px; padding: 6px 10px; border: 2px solid #333; border-radius: 4px; background: #f9f9f9;"><strong>📌 Notat:</strong> ${k.note.replace(/\n/g,"<br>")}</div>`:""}
55
56        <table style="width: 100%; border-collapse: collapse; font-size: 12px;">
57          <thead>
58            <tr style="border-bottom: 2px solid #333;">
59              <th style="text-align: left; padding: 4px;">Varenr</th>
60              <th style="text-align: left; padding: 4px;">Strekkode</th>
61              <th style="text-align: left; padding: 4px;">Varenavn</th>
62              <th style="text-align: left; padding: 4px;">Farge</th>
63              <th style="text-align: left; padding: 4px;">Størrelse</th>
64              <th style="text-align: left; padding: 4px;">Lager</th>
65              <th style="text-align: left; padding: 4px;">Plukket</th>
66              <th style="text-align: center; padding: 4px;">Antall</th>
67              <th style="text-align: center; padding: 4px;">Leveres</th>
68            </tr>
69          </thead>
70          <tbody>
71            ${h.items.filter(C=>!A(h.order_id,C)).map(C=>{const de=S(C.article_no);return`
72              <tr style="border-bottom: 1px solid #ddd; ${de?"color: #ccc; font-size: 11px;":""}">
73                <td style="padding: 4px;">${C.article_no}</td>
74                <td style="padding: 4px; ${de?"":"font-size: 11px;"}">${qt(C)}</td>
75                <td style="padding: 4px;">${C.article_name}${C.line_info?'<br><span style="color:#888;font-size:10px;">📋 '+C.line_info+"</span>":""}</td>
76                <td style="padding: 4px;">${C.color_name||""}</td>
77                <td style="padding: 4px;">${C.size_name||""}</td>
78                <td style="padding: 4px;">${de?"":O(h.order_id,C)}${!de&&Wt(h.order_id,C)?' <span style="font-size:9px;color:#d97706;">✎ manuelt</span>':""}</td>
79                <td style="padding: 4px; font-size: 11px;">${de?"":(()=>{const Xe=[];for(const[i,F]of[[_.PLUKKET_SENTRUM,"Sentrum"],[_.PLUKKET_STOA,"Stoa"]]){const D=N.get(v(h.order_id,C.article_no,C.size_name,C.color_name,i));D&&Xe.push(D.picked_qty!=null?`${F} (${D.picked_qty})`:F)}return N.has(v(h.order_id,C.article_no,C.size_name,C.color_name,_.IKKE_FUNNET))&&Xe.push('<strong style="color:#dc2626;">Finner ikke</strong>'),Xe.join("<br>")})()}</td>
80                <td style="text-align: center; padding: 4px;${!de&&(C.delivered_qty>0?C.remaining_units:C.units)>1?" font-weight: bold;":""}">${C.delivered_qty>0?`${C.remaining_units} <span style="font-size:10px;color:#888;">(${C.delivered_qty} levert)</span>`:C.units}</td>
81                <td style="text-align: center; padding: 4px; border: 1px solid ${de?"#ddd":"#999"}; width: 50px;"></td>
82              </tr>`}).join("")}
83          </tbody>
84        </table>
85        ${s&&((W=k==null?void 0:k.note)!=null&&W.trim())?`
86        <div style="margin-top: 24px; padding: 16px 20px; border: 4px solid #000; background: #f5f5f5;">
87          <p style="font-size: 18px; font-weight: 900; margin: 0 0 8px 0; text-transform: uppercase; letter-spacing: 1px;">⚠️ NOTAT:</p>
88          <p style="font-size: 14px; margin: 0; line-height: 1.5; white-space: pre-wrap;">${k.note.replace(/\n/g,"<br>")}</p>
89        </div>`:""}
90        <div style="text-align: center; margin-top: 30px; font-size: 12px; color: #555;">
91          <p style="margin: 2px 0; font-weight: bold;">brekkesport.no</p>
92          <p style="margin: 2px 0;">Den lokale sportsbutikken for alle</p>
93        </div>
94      </div>
95    `}).join("");l.document.write(`
96      <html><head><title>Plukklister - ${a}</title>
97      <style>
98        @page { margin: 15mm; }
99        body { font-family: Arial, sans-serif; margin: 0; }
100        @media print {
101          .order-page:last-child { page-break-after: avoid; }
102        }
103      </style></head>
104      <body>${o}</body></html>
105    `),l.document.close();let x=!1;const d=()=>{x||(x=!0,l.focus(),l.print())},m=Array.from(l.document.images);if(m.length===0){d();return}let p=0;const u=()=>{p+=1,p>=m.length&&d()};m.forEach(h=>{h.complete?u():(h.onload=u,h.onerror=u)}
105),setTimeout(d,900)},ga=()=>{const t=(Oe.size>0?ce.filter(([r])=>Oe.has(r)):ce).map(([r,l])=>{const o=l.filter(x=>{if(Te.has(x.order_id))return!0;const d=(x.shipping_method||"").toLowerCase(),m=O(x.order_id,x);return m==="Stoa"&&d.includes("klikk")&&d.includes("sentrum")||m==="Sentrum"&&d.includes("klikk")&&d.includes("stoa")});return[r,o]}).filter(([,r])=>r.length>0);if(t.length===0){w.info("Ingen splittordre å skrive ut");return}const s=f==="all"?"Alle lager":f,n=window.open("","_blank");if(!n)return;const a=t.map(([r,l])=>{const o=[...new Set(l.map(d=>d.warehouse).filter(Boolean))].sort(),x=o.length>0?o.join(", "):"Alle lager";return`
106      <div style="page-break-inside: avoid; margin-bottom: 24px;">
107        <div style="display: flex; justify-content: space-between; align-items: baseline; border-bottom: 2px solid #333; padding-bottom: 4px; margin-bottom: 8px;">
108          <h2 style="font-size: 16px; font-weight: bold; margin: 0;">${r}</h2>
109          <span style="font-size: 12px; color: #555;">Lager: ${x}</span>
110        </div>
111        <table style="width: 100%; border-collapse: collapse; font-size: 12px;">
112          <thead>
113            <tr style="border-bottom: 2px solid #333; background: #f5f5f5;">
114              <th style="text-align: left; padding: 4px;">Strekkode</th>
115              <th style="text-align: left; padding: 4px;">Vare</th>
116              <th style="text-align: left; padding: 4px;">Farge</th>
117              <th style="text-align: left; padding: 4px;">Størrelse</th>
118              <th style="text-align: center; padding: 4px;">
118Ant</th>
119              <th style="text-align: center; padding: 4px; width: 24px;">&#10003;</th>
120              <th style="text-align: center; padding: 4px; font-size: 10px; color: #888;">Ordre</th>
121              <th style="text-align: left; padding: 4px; font-size: 10px; color: #888;">Varenr</th>
122              ${Ae?'<th style="text-align: left; padding: 4px; font-size: 10px; color: #888;">Lager</th>':""}
123            </tr>
124          </thead>
125          <tbody>
126            ${l.map(d=>{const m=Te.has(d.order_id),p=(d.shipping_method||"").toLowerCase(),u=O(d.order_id,d),k=u==="Stoa"&&p.includes("klikk")&&p.includes("sentrum")||u==="Sentrum"&&p.includes("klikk")&&p.includes("stoa")?'<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="#333" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display:inline-block;vertical-align:middle;"><path d="m2 7 4.41-4.41A2 2 0 0 1 7.83 2h8.34a2 2 0 0 1 1.42.59L22 7"/><path d="M4 12v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8"/><path d="M15 22v-4a2 2 0 0 0-2-2h-2a2 2 0 0 0-2 2v4"/><path d="M2 7h20"/><path d="M22 7v3a2 2 0 0 1-2 2a2.7 2.7 0 0 1-1.59-.63.7.7 0 0 0-.82 0A2.7 2.7 0 0 1 16 12a2.7 2.7 0 0 1-1.59-.63.7.7 0 0 0-.82 0A2.7 2.7 0 0 1 12 12a2.7 2.7 0 0 1-1.59-.63.7.7 0 0 0-.82 0A2.7 2.7 0 0 1 8 12a2.7 2.7 0 0 1-1.59-.63.7.7 0 0 0-.82 0A2.7 2.7 0 0 1 4 12a2 2 0 0 1-2-2V7"/></svg>':m?"⇄":"";return`
127              <tr style="border-bottom: 1px solid #ddd;">
128                <td style="padding: 3px 4px; font-size: 11px;">${qt(d)}</td>
129                <td style="padding: 3px 4px;">${d.article_name}</td>
130                <td style="padding: 3px 4px;">${d.color_name||""}</td>
131                <td style="padding: 3px 4px;">${d.size_name||""}</td>
132                <td style="text-align: center; padding: 3px 4px;${d.units>1?" font-weight: bold;":""}">${d.units}</td>
133                <td style="text-align: center; padding: 3px 4px; border: 1px solid #999; width: 24px; height: 16px;">${k}</td>
134                <td style="text-align: center; padding: 3px 4px; font-size: 10px; color: #888;">${d.order_id}</td>
135                <td style="padding: 3px 4px; font-size: 10px; color: #888;">${d.article_no}</td>
136                ${Ae?`<td style="padding: 3px 4px; font-size: 10px; color: #888;">${O(d.order_id,d)}</td>`:""}
137              </tr>`}).join("")}
138          </tbody>
139        </table>
140      </div>`}).join("");n.document.write(`
141      <html><head><title>Splittordre - ${s}</title>
142      <style>
143        body { font-family: Arial, sans-serif; margin: 20px; }
144        @page { margin: 15mm; }
145      </style></head>
146      <body>${a}</body></html>
147    `),n.document.close(),n.print()},fa=()=>{const t=Oe.size>0?ce.filter(([l])=>Oe.has(l)):ce;if(t.length===0){w.error("Ingen varer i plukklisten");return}const s=f==="all"?"Alle lager":f,n=window.open("","_blank");if(!n)return;const a=t.map(([l,o])=>{const x=[...new Set(o.map(m=>
147m.warehouse).filter(Boolean))].sort(),d=x.length>0?x.join(", "):"Alle lager";return`
148      <div style="page-break-inside: avoid; margin-bottom: 24px;">
149        <div style="display: flex; justify-content: space-between; align-items: baseline; border-bottom: 2px solid #333; padding-bottom: 4px; margin-bottom: 8px;">
150          <h2 style="font-size: 16px; font-weight: bold; margin: 0;">${l}</h2>
151          <span style="font-size: 12px; color: #555;">Lager: ${d}</span>
152        </div>
153        <table style="width: 100%; border-collapse: collapse; font-size: 12px;">
154          <thead>
155             <tr style="border-bottom: 2px solid #333; background: #f5f5f5;">
156              <th style="text-align: left; padding: 4px;">Strekkode</th>
157              <th style="text-align: left; padding: 4px;">Vare</th>
158              <th style="text-align: left; padding: 4px;">Farge</th>
159              <th style="text-align: left; padding: 4px;">Størrelse</th>
160              <th style="text-align: center; padding: 4px;">Ant</th>
161              <th style="text-align: center; padding: 4px; width: 24px;">&#10003;</th>
162              <th style="text-align: center; padding: 4px; font-size: 10px; color: #888;">Ordre</th>
163              <th style="text-align: left; padding: 4px; font-size: 10px; color: #888;">Varenr</th>
164              ${Ae?'<th style="text-align: left; padding: 4px; font-size: 10px; color: #888;">Lager</th>':""}
165            </tr>
166          </thead>
167          <tbody>
168            ${o.map(m=>{const p=Te.has(m.order_id),u=(m.shipping_method||"").toLowerCase(),h=O(m.order_id,m),W=h==="Stoa"&&u.includes("klikk")&&u.includes("sentrum")||h==="Sentrum"&&u.includes("klikk")&&u.includes("stoa")?'<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="#333" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display:inline-block;vertical-align:middle;"><path d="m2 7 4.41-4.41A2 2 0 0 1 7.83 2h8.34a2 2 0 0 1 1.42.59L22 7"/><path d="M4 12v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8"/><path d="M15 22v-4a2 2 0 0 0-2-2h-2a2 2 0 0 0-2 2v4"/><path d="M2 7h20"/><path d="M22 7v3a2 2 0 0 1-2 2a2.7 2.7 0 0 1-1.59-.63.7.7 0 0 0-.82 0A2.7 2.7 0 0 1 16 12a2.7 2.7 0 0 1-1.59-.63.7.7 0 0 0-.82 0A2.7 2.7 0 0 1 12 12a2.7 2.7 0 0 1-1.59-.63.7.7 0 0 0-.82 0A2.7 2.7 0 0 1 8 12a2.7 2.7 0 0 1-1.59-.63.7.7 0 0 0-.82 0A2.7 2.7 0 0 1 4 12a2 2 0 0 1-2-2V7"/></svg>':p?"⇄":"";return`
169              <tr style="border-bottom: 1px solid #ddd;">
170                <td style="padding: 3px 4px; font-size: 11px;">${qt(m)}</td>
171                <td style="padding: 3px 4px;">${m.article_name}</td>
172                <td style="padding: 3px 4px;">${m.color_name||""}</td>
173                <td style="padding: 3px 4px;">${m.size_name||""}</td>
174                <td style="text-align: center; padding: 3px 4px;${m.units>1?" font-weight: bold;":""}">${m.units}</td>
175                <td style="text-align: center; padding: 3px 4px; border: 1px solid #999; width: 24px; height: 16px;">${W}</td>
176                <td style="text-align: center; padding: 3px 4px; font-size: 10px; color: #888;">${m.order_id}</td>
177                <td style="padding: 3px 4px; font-size: 10px; color: #888;">${m.article_no}</td>
178                ${Ae?`<td style="padding: 3px 4px; font-size: 10px; color: #888;">${O(m.order_id,m)}</td>`:""}
179              </tr>`}).join("")}
180          </tbody>
181        </table>
182      </div>
183    `}).join("");n.document.write(`
184      <html><head><title>Plukkliste - ${s}</title>
185      <style>
186        body { font-family: Arial, sans-serif; margin: 20px; }
187        @page { margin: 15mm; }
188      </style></head>
189      <body>${a}</body></html>
190    `),n.document.close(),n.print();const r=new Set;t.forEach(([,l])=>l.forEach(o=>r.add(o.order_id))),r.size>0&&(Pn(r),bs(!0))},_a=()=>{bs(!1);const t=y.filter(p=>ks.has(p.order_id));if(t.length===0)return;const s=f==="all"?"Alle lager":f,n=et.startsWith("http")?et:`${window.location.origin}${et}`,a=window.open("","_blank");if(!a)return;const r=t.map(p=>(V.get(p.order_id),`
191      <div class="order-page" style="page-break-after: always;">
192        <div style="text-align: center; margin-bottom: 20px;">
193          <img src="${n}" style="height: 50px; max-width: 260px; object-fit: contain;" />
194        </div>
195        <div style="display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px;">
196          <div>
197            <p style="margin: 2px 0;">${p.delivery_name}</p>
198            <p style="font-size: 15px; font-weight: bold; margin: 2px 0;">Plukkliste ordrenr. ${p.order_id}</p>
199            <div style="margin: 4px 0 0 0;">${dn(String(p.order_id),{height:34})}</div>
200          </div>
201          <div style="text-align: right;">
202            <p style="font-size: 11px; margin: 2px 0;">Ordredato: ${Zt(p.order_date)}</p>
203            <p style="font-size: 11px; margin: 2px 0;">Kl: ${qr(p.order_date)}</p>
204          </div>
205        </div>
206        <div style="margin-bottom: 12px; font-size: 12px;">
207          <p style="margin: 2px 0;">${p.delivery_address}</p>
208          <p style="margin: 2px 0;">${p.delivery_zipcode} ${p.delivery_city}</p>
209          ${p.customer_phone?`<p style="margin: 2px 0;">Tlf: ${p.customer_phone}</p>`:""}
210          ${p.customer_email?`<p style="margin: 2px 0;">${p.customer_email}</p>`:""}
211        </div>
212        ${(()=>{const u=(p.shipping_method||"").toLowerCase();return u.includes("klikk")||u.includes("click")?`<div style="text-align: center; margin: 30px 0; padding: 20px 0;">
213              <p style="font-size: 36px; font-weight: 900; color: #000; letter-spacing: 1px; text-transform: uppercase; margin: 0;">KLIKK & HENT</p>
214              <p style="font-size: 18px; font-weight: 700; color: #000; margin: 8px 0 0 0;">${p.shipping_method}</p>
215            </div>`:`<p style="font-size: 12px; margin-bottom: 8px;">Ønsket levering: ${p.shipping_method||"Ikke spesifisert"}</p>`})()}
216        ${p.order_info?`<p style="font-size: 12px; margin-bottom: 8px; color: #c00;">Info: ${Le(p.order_info)}</p>`:""}
217        ${p.pl_info?`<p style="font-size: 12px; margin-bottom: 8px; color: #c00;">📋 Plukkliste: ${Le(p.pl_info)}</p>`:""}
218        <table style="width: 100%; border-collapse: collapse; font-size: 12px;">
219          <thead>
220            <tr style="border-bottom: 2px solid #333;">
221              <th style="text-align: left; padding: 4px;">Varenr</th>
222              <th style="text-align: left; padding: 4px;">Strekkode</th>
223              <th style="text-align: left; padding: 4px;">Varenavn</th>
224              <th style="text-align: left; padding: 4px;">Farge</th>
225              <th style="text-align: left; padding: 4px;">Størrelse</th>
226              <th style="text-align: left; padding: 4px;">Lager</th>
227              <th style="text-align: center; padding: 4px;">Antall</th>
228              <th style="text-align: center; padding: 4px;">Leveres</th>
229            </tr>
230          </thead>
231          <tbody>
232            ${p.items.filter(u=>!A(p.order_id,u)).map(u=>{const h=S(u.article_no);return`
233              <tr style="border-bottom: 1px solid #ddd; ${h?"color: #999;":""}">
234                <td style="padding: 4px;">${u.article_no}</td>
235                <td style="padding: 4px; font-size: 11px;">${qt(u)}</td>
236                <td style="padding: 4px;">${u.article_name}${u.line_info?'<br><span style="color:#888;font-size:10px;">📋 '+u.line_info+"</span>":""}</td>
237                <td style="padding: 4px;">${u.color_name||""}</td>
238                <td style="padding: 4px;">${u.size_name||""}</td>
239                <td style="padding: 4px;">${h?"":u.warehouse}</td>
240                <td style="text-align: center; padding: 4px;${(u.delivered_qty>0?u.remaining_units:u.units)>1?" font-weight: bold;":""}">${u.delivered_qty>0?`${u.remaining_units} <span style="font-size:10px;color:#888;">(${u.delivered_qty} levert)</span>`:u.units}</td>
241                <td style="text-align: center; padding: 4px; border: 1px solid #999; width: 50px;"></td>
242              </tr>`}).join("")}
243          </tbody>
244        </table>
245        <div style="text-align: center; margin-top: 30px; font-size: 12px; color: #555;">
246          <p style="margin: 2px 0; font-weight: bold;">brekkesport.no</p>
247          <p style="margin: 2px 0;">Den lokale sportsbutikken for alle</p>
248        </div>
249      </div>`)).join("");a.document.write(`
250      <html><head><title>Ordrer fra plukkliste - ${s}</title>
251      <style>
252        @page { margin: 15mm; }
253        body { font-family: Arial, sans-serif; margin: 0; }
254        @media print { .order-page:last-child { page-break-after: avoid; } }
255      </style></head>
256      <body>${r}</body></html>
257    `),a.document.close();let l=!1;const o=()=>{l||(l=!0,a.focus(),a.print())},x=Array.from(a.document.images);if(x.length===0){o();return}let d=0;const m=()=>{d++,d>=x.length&&o()};x.forEach(p=>{p.complete?m():(p.onload=m,p.onerror=m)}),setTimeout(o,900)},Ee=c.useMemo(()=>{const t={Stoa:0,Sentrum:0,Stadion:0},s={};let n="";const a={},r={Stoa:{picked:0,total:0},Sentrum:{picked:0,total:0}};for(const l of y){(!n||l.order_date<n)&&(n=l.order_date);const o=Ze(l),x=m=>{(!s[m]||l.order_date<s[m])&&(s[m]=l.order_date)};if(o==="Blandet"){const m=new Set;for(const p of l.items)!S(p.article_no)&&!A(l.order_id,p)&&!m.has(p.warehouse)&&(m.add(p.warehouse),t[p.warehouse]=(t[p.warehouse]||0)+1,x(p.warehouse));for(const p of l.items){if(S(p.article_no)||A(l.order_id,p))continue;const u=p.warehouse;if(u==="Stoa"||u==="Sentrum"||u==="Begge"){const h=u==="Begge"?"Stoa":u;r[h].total++,(N.has(v(l.order_id,p.article_no,p.size_name,p.color_name,_.PLUKKET_STOA))||N.has(v(l.order_id,p.article_no,p.size_name,p.color_name,_.PLUKKET_SENTRUM)))&&r[h].picked++}}}else t[o]=(t[o]||0)+1,x(o);if(f==="all"||l.items.some(m=>!S(m.article_no)&&!A(l.order_id,m)&&m.warehouse===f)){const m=l.shipping_method||"Ukjent";a[m]=(a[m]||0)+1}}return{total:y.length,totalItems:y.reduce((l,o)=>l+o.items.filter(x=>!S(x.article_no)).length,0),byWarehouse:t,byShipping:a,oldestByWarehouse:s,oldestAll:n,pickedMixedLines:r}},[y,S,Ze,f,N,A]),Hr=({order:t,item:s,actionType:n,colorClass:a,label:r})=>{const l=me(s),o=N.get(v(t.order_id,s.article_no,s.size_name,s.color_name,n)),x=o?o.picked_qty==null?l:o.picked_qty:0,d=Math.max(0,ze(t.order_id,s)-x),m=Math.max(1,l-d
257),[p,u]=c.useState(x||m),h=Yt(t.order_id,s.article_no,s.size_name,s.color_name,n);return l===1?o?e.jsxs(he,{children:[e.jsx(ge,{asChild:!0,onClick:k=>k.stopPropagation(),children:e.jsx("button",{className:`p-0.5 rounded ${a}`,title:r,children:e.jsx(Re,{className:"h-3.5 w-3.5"})})}),e.jsx(fe,{className:"w-auto p-2",align:"start",onClick:k=>k.stopPropagation(),children:e.jsxs("div",{className:"text-xs space-y-1",children:[e.jsx("p",{className:"font-medium",children:r}),h&&e.jsxs("p",{className:"text-muted-foreground",children:["Av: ",h]}),e.jsx(b,{size:"sm",variant:"ghost",className:"h-6 text-[10px] text-destructive w-full",onClick:k=>{k.stopPropagation(),re(t.order_id,s.article_no,s.size_name,s.color_name,n)},children:"Fjern"})]})})]}):e.jsx("button",{onClick:k=>{k.stopPropagation(),re(t.order_id,s.article_no,s.size_name,s.color_name,n,void 0,1)},className:`p-0.5 rounded text-muted-foreground/40 ${a.replace("text-","hover:text-")} transition-all`,title:r,children:e.jsx(Re,{className:"h-3.5 w-3.5"})}):e.jsxs(he,{children:[e.jsx(ge,{asChild:!0,onClick:k=>k.stopPropagation(),children:e.jsxs("button",{className:`px-0.5 rounded flex items-center gap-0.5 ${o?a:"text-muted-foreground/40"}`,title:`${r} (antall)`,children:[e.jsx(Re,{className:"h-3.5 w-3.5"}),o&&e.jsx("span",{className:"text-[9px] font-semibold tabular-nums",children:x})]})}),e.jsx(fe,{className:"w-52 p-3",align:"start",onClick:k=>k.stopPropagation(),children:e.jsxs("div",{className:"text-xs space-y-2",children:[e.jsx("p",{className:"font-medium",children:r}),e.jsxs("p",{className:"text-muted-foreground text-[11px]",children:["Antall på linjen: ",l,d>0?` · ${d} plukket i annen butikk`:""]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(nn,{value:[Math.min(p,m)],min:1,max:m,step:1,onValueChange:k=>u(k[0]),className:"flex-1"}),e.jsx("span",{className:"w-8 text-center text-sm font-semibold tabular-nums",children:Math.min(p,m)})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs(b,{size:"sm",className:"h-7 text-[11px] flex-1",onClick:k=>{k.stopPropagation();const W=Math.min(p,m);o?Rr(t.order_id,s.article_no,s.size_name,s.color_name,n,W):re(t.order_id,s.article_no,s.size_name,s.color_name,n,void 0,W)},children:[e.jsx(Nt,{className:"h-3 w-3 mr-1"}),"Bekreft"]}),o&&e.jsx(b,{size:"sm",variant:"ghost",className:"h-7 text-[10px] text-destructive",onClick:k=>{k.stopPropagation(),re(t.order_id,s.article_no,s.size_name,s.color_name,n)},children:"Fjern"})]}),h&&e.jsxs("p",{className:"text-[10px] text-muted-foreground",children:["Av: ",h]})]})})]})},Wr=({item:t,actionType:s,size:n})=>{const a=me(t),r=N.get(v(t.order_id,t.article_no,t.size_name,t.color_name,s)),l=r?r.picked_qty==null?a:r.picked_qty:0,o=Math.max(0,ze(t.order_id,t)-l),x=Math.max(1,a-o),[d,m]=c.useState(l||x),p=n==="lg"?"h-8 w-8 shrink-0 mt-0.5 active:scale-95":"h-6 w-6",u=n==="lg"?"h-4 w-4":"h-3.5 w-3.5",h=`${p} rounded border flex items-center justify-center transition-colors touch-manipulation select-none ${r?"bg-emerald-500 border-emerald-500 text-white":"border-border hover:bg-muted"}`;return a<=1?e.jsx("button",{type:"button",className:h,onClick:k=>{k.stopPropagation(),re(t.order_id,t.article_no,t.size_name,t.color_name,s,void 0,1)},children:r&&e.jsx(Nt,{className:u})}):e.jsxs(he,{children:[e.jsx(ge,{asChild:!0,onClick:k=>k.stopPropagation(),children:e.jsx("button",{type:"button",className:h,children:r?e.jsx("span",{className:"text-[10px] font-semibold tabular-nums",children:l}):e.jsx("span",{className:"text-[10px] text-muted-foreground tabular-nums",children:a})})}),e.jsx(fe,{className:"w-52 p-3",align:"start",onClick:k=>k.stopPropagation(),children:e.jsxs("div",{className:"text-xs space-y-2",children:[e.jsx("p",{className:"font-medium",children:"Bekreft antall plukket"}),e.jsxs("p",{className:"text-muted-foreground text-[11px]",children:["Antall på linjen: ",a,o>0?` · ${o} plukket i annen butikk`:""]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(nn,{value:[Math.min(d,x)],min:1,max:x,step:1,onValueChange:k=>m(k[0]),className:"flex-1"}),e.jsx("span",{className:"w-8 text-center text-sm font-semibold tabular-nums",children:Math.min(d,x)})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs(b,{size:"sm",className:"h-7 text-[11px] flex-1",onClick:k=>{k.stopPropagation();const W=Math.min(d,x);r?Rr(t.order_id,t.article_no,t.size_name,t.color_name,s,W):re(t.order_id,t.article_no,t.size_name,t.color_name,s,void 0,W)},children:[e.jsx(Nt,{className:"h-3 w-3 mr-1"}),"Bekreft"]}),r&&e.jsx(b,{size:"sm",variant:"ghost",className:"h-7 text-[10px] text-destructive",onClick:k=>{k.stopPropagation(),re(t.order_id,t.article_no,t.size_name,t.color_name,s)},children:"Fjern"})]})]})})]})},Yr=({order:t,item:s})=>{if(ca(t.shipping_method),O(t.order_id,s),S(s.article_no))return null;Wn(t.order_id,s.article_no,s.size_name,s.color_name),Q(t.order_id,s.article_no,s.size_name,s.color_name,_.BESTILT_STADION)||Q(t.order_id,s.article_no,s.size_name,s.color_name,_.PLUKKET_SENTRUM)||Q(t.order_id,s.article_no,s.size_name,s.color_name,_.PLUKKET_STOA)||Q(t.order_id,s.article_no,s.size_name,s.color_name,_.IKKE_FUNNET);const a=Q(t.order_id,s.article_no,s.size_name,s.color_name,_.BESTILT_STADION);Q(t.order_id,s.article_no,s.size_name,s.color_name,_.PLUKKET_SENTRUM),Q(t.order_id,s.article_no,s.size_name,s.color_name,_.PLUKKET_STOA);const r=Q(t.order_id,s.article_no,s.size_name,s.color_name,_.IKKE_FUNNET);return e.jsxs("div",{className:"flex items-center gap-0.5",children:[a?(()=>{const l=s.warehouse==="Sentrum"?s.available_sentrum>=1:s.available_stoa>=0,o=N.get(v(t.order_id,s.article_no,s.size_name,s.color_name,_.BESTILT_STADION)),x=Yt(t.order_id,s.article_no,s.size_name,s.color_name,_.BESTILT_STADION);return e.jsxs(he,{children:[e.jsx(ge,{asChild:!0,onClick:d=>d.stopPropagation(),children:e.jsx("button",{className:`p-0.5 rounded transition-all ${l?"text-emerald-600 dark:text-emerald-400":"text-amber-600 dar
257k:text-amber-400"}`,title:l?"Kommet fra Stadion":"Bestilt Stadion",children:e.jsx(wt,{className:"h-3.5 w-3.5"})})}),e.jsx(fe,{className:"w-auto p-2",align:"start",onClick:d=>d.stopPropagation(),children:e.jsxs("div",{className:"text-xs space-y-1",children:[e.jsx("p",{className:"font-medium",children:l?"Kommet fra Stadion":"Bestilt Stadion"}),(o==null?void 0:o.action_date)&&e.jsxs("p",{className:"text-muted-foreground",children:["Dato: ",ua(o.action_date)]}),x&&e.jsxs("p",{className:"text-muted-foreground",children:["Av: ",x]}),e.jsx(b,{size:"sm",variant:"ghost",className:"h-6 text-[10px] text-destructive w-full",onClick:d=>{d.stopPropagation(),re(t.order_id,s.article_no,s.size_name,s.color_name,_.BESTILT_STADION)},children:"Fjern"})]})})]})})():e.jsxs(he,{children:[e.jsx(ge,{asChild:!0,onClick:l=>l.stopPropagation(),children:e.jsx("button",{className:"p-0.5 rounded text-muted-foreground/40 hover:text-amber-600 transition-all",title:"Bestill Stadion",children:e.jsx(wt,{className:"h-3.5 w-3.5"})})}),e.jsx(fe,{className:"w-auto p-3",align:"start",onClick:l=>l.stopPropagation(),children:e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("p",{className:"text-xs font-medium",children:"Bestilt fra Stadion"}),e.jsx("input",{type:"date",id:`stadion-date-${t.order_id}-${s.article_no}-${s.size_name}-${s.color_name}`,className:"text-xs border rounded px-2 py-1 bg-background border-border",defaultValue:new Date().toISOString().slice(0,10),onClick:l=>l.stopPropagation()}),e.jsx(b,{size:"sm",className:"h-7 text-xs",onClick:l=>{l.stopPropagation();const o=document.getElementById(`stadion-date-${t.order_id}-${s.article_no}-${s.size_name}-${s.color_name}`);o!=null&&o.value&&re(t.order_id,s.article_no,s.size_name,s.color_name,_.BESTILT_STADION,o.value)},children:"Lagre"})]})})]}),e.jsx(Hr,{order:t,item:s,actionType:_.PLUKKET_SENTRUM,colorClass:"text-blue-600 dark:text-blue-400",label:"Plukket Sentrum"}),e.jsx(Hr,{order:t,item:s,actionType:_.PLUKKET_STOA,colorClass:"text-emerald-600 dark:text-emerald-400",label:"Plukket Stoa"}),r?(()=>{const l=Yt(t.order_id,s.article_no,s.size_name,s.color_name,_.IKKE_FUNNET);return e.jsxs(he,{children:[e.jsx(ge,{asChild:!0,onClick:o=>o.stopPropagation(),children:e.jsx("button",{className:"p-0.5 rounded text-red-600 dark:text-red-400",title:"Finner ikke",children:e.jsx(H,{className:"h-3.5 w-3.5"})})}),e.jsx(fe,{className:"w-auto p-2",align:"start",onClick:o=>o.stopPropagation(),children:e.jsxs("div",{className:"text-xs space-y-1",children:[e.jsx("p",{className:"font-medium",children:"Finner ikke"}),l&&e.jsxs("p",{className:"text-muted-foreground",children:["Av: ",l]}),e.jsx(b,{size:"sm",variant:"ghost",className:"h-6 text-[10px] text-destructive w-full",onClick:o=>{o.stopPropagation(),re(t.order_id,s.article_no,s.size_name,s.color_name,_.IKKE_FUNNET)},children:"Fjern"})]})})]})})():e.jsx("button",{onClick:l=>{l.stopPropagation(),re(t.order_id,s.article_no,s.size_name,s.color_name,_.IKKE_FUNNET)},className:"p-0.5 rounded text-muted-foreground/40 hover:text-red-600 transition-all",title:"Finner ikke",children:e.jsx(H,{className:"h-3.5 w-3.5"})})]})},Ls=({order:t,item:s,compact:n=!1})=>{const a=O(t.order_id,s),r=Wt(t.order_id,s),l=!r&&a!==s.warehouse?Ht(s):null,o=B.has(s.article_no),x=["Sentrum","Stoa","Stadion"];return e.jsxs(he,{children:[e.jsx(ge,{asChild:!0,onClick:d=>d.stopPropagation(),children:e.jsxs("button",{title:r?"Manuelt overstyrt":l?l.label:`Foreslått ut fra lager (${s.warehouse})`,className:`inline-flex items-center gap-0.5 rounded border text-[10px] font-medium transition-all cursor-pointer hover:opacity-80 ${n?"px-1.5 py-0 h-4":"px-2 py-0.5"} ${gt(a)} ${r?"ring-1 ring-primary/50":""}`,children:[a,r&&e.jsx("span",{className:"text-[8px] opacity-60",children:"✎"}),l&&e.jsx("span",{className:"text-[8px] opacity-60",children:"R"})]})}),e.jsx(fe,{className:"w-auto p-2",align:"start",onClick:d=>d.stopPropagation(),children:e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("p",{className:"text-[10px] font-medium text-muted-foreground mb-1",children:"Overstyr lager for denne ordren:"}),l&&e.jsxs("p",{className:"text-[9px] text-muted-foreground max-w-[200px] -mt-1 mb-1",children:[l.label," → ",l.store]}),x.map(d=>e.jsxs("button",{onClick:m=>{m.stopPropagation(),Vn(t.order_id,s,d,or)},className:`text-left text-xs px-2 py-1 rounded transition-colors ${a===d?"bg-primary/10 font-semibold":"hover:bg-muted"}`,children:[d," ",d===s.warehouse&&e.jsx("span",{className:"text-[9px] text-muted-foreground",children:"(original)"})]},d)),e.jsxs("label",{className:"flex items-start gap-1.5 text-[10px] text-muted-foreground cursor-pointer mt-1 border-t pt-1.5 max-w-[200px]",children:[e.jsx("input",{type:"checkbox",checked:or,onChange:d=>{d.stopPropagation(),vn(d.target.checked)},onClick:d=>d.stopPropagation(),className:"rounded border-input accent-primary mt-0.5"}
257),e.jsxs("span",{children:["Husk valget for varenr ",s.article_no," ved senere ordre"]})]}),o&&e.jsx("p",{className:"text-[9px] text-amber-600 dark:text-amber-400 max-w-[200px]",children:"Fast butikkvalg er lagret for denne varen."}),r&&e.jsx("button",{onClick:d=>{d.stopPropagation(),qn(t.order_id,s)},className:"text-left text-xs px-2 py-1 rounded text-destructive hover:bg-destructive/10 transition-colors mt-1 border-t pt-2",children:"Fjern overstyring"})]})})]})},Gr=t=>{var o,x;const s=v(t.order_id,t.article_no,t.size_name,t.color_name,_.IKKE_FUNNET),n=N.get(s),a=V.get(t.order_id);if(!n&&!((o=a==null?void 0:a.note)!=null&&o.trim()))return null;const r=n?Yt(t.order_id,t.article_no,t.size_name,t.color_name,_.IKKE_FUNNET):null,l=n!=null&&n.created_at?new Date(n.created_at).toLocaleString("nb-NO",{day:"2-digit",month:"2-digit",hour:"2-digit",minute:"2-digit"}):null;return e.jsxs("div",{className:"space-y-1 text-[11px] min-w-0",children:[n&&e.jsxs("p",{className:"font-medium text-destructive",children:["❌ Finner ikke",r?` · ${r}`:"",l?` · ${l}`:""]}),((x=a==null?void 0:a.note)==null?void 0:x.trim())&&e.jsxs("div",{className:"rounded border border-border bg-background p-1.5",children:[e.jsx("p",{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:a.is_question?"Spørsmål":"Notat"}),e.jsx("p",{className:"whitespace-pre-wrap",children:a.note}),a.answer&&e.jsxs("p",{className:"mt-1 whitespace-pre-wrap text-muted-foreground",children:["Svar: ",a.answer]})]})]})},Qr=t=>{const s=y.find(r=>r.order_id===t);if(!s)return e.jsxs("div",{className:"px-4 py-3 text-xs text-muted-foreground",children:["Fant ikke ordredetaljer for ",t,"."]});const n=V.get(t),a=vt===t;return e.jsxs("div",{className:"px-4 py-3 bg-primary/5 border-y border-primary/20 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-xs font-semibold",children:["Ordre ",s.order_id]}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:s.shipping_method})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[e.jsxs("div",{className:"text-[11px] text-muted-foreground space-y-0.5",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"Kunde:"})," ",s.delivery_name]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"Adresse:"})," ",s.delivery_address,", ",s.delivery_zipcode," ",s.delivery_city]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"Tlf:"})," ",s.customer_phone?e.jsx("a",{href:`tel:${s.customer_phone}`,className:"hover:underline",children:s.customer_phone}):"-"]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"E-post:"})," ",s.customer_email||"-"]})]}),e.jsxs("div",{className:"sm:col-span-2",children:[e.jsx("p",{className:"text-[10px] uppercase tracking-wide text-muted-foreground mb-1",children:"Varelinjer og lager"}),e.jsx("div",{className:"space-y-0.5",children:s.items.filter(r=>!S(r.article_no)).map((r,l)=>e.jsxs("div",{className:"flex items-center gap-2 text-[11px]",children:[e.jsxs("span",{className:"flex-1 truncate",children:[r.article_name," ",r.color_name," ",r.size_name]}),e.jsxs("span",{className:"font-mono text-muted-foreground shrink-0",children:[r.units," stk"]}),e.jsx("span",{className:"shrink-0",children:e.jsx(Ls,{order:s,item:r,compact:!0})}),e.jsxs("span",{className:"font-mono text-[10px] text-muted-foreground shrink-0",children:["Stoa ",r.available_stoa??"–"," / Sentrum ",r.available_sentrum??"–"]})]},l))})]})]}),e.jsxs("div",{className:"p-2 rounded-md border bg-background",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"text-[11px] font-medium",children:n!=null&&n.is_question?"❓ Spørsmål":"Notat"}),!a&&e.jsx(b,{variant:"ghost",size:"sm",className:"h-5 text-[10px] px-1.5",onClick:()=>{it(t),Ct((n==null?void 0:n.note)||""),ct((n==null?void 0:n.is_question)||!1)},children:n?"Rediger":"Legg til"})]}),a?e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(ts,{value:St,onChange:r=>Ct(r.target.value),placeholder:"Skriv et internt notat...",className:"min-h-[50px] text-xs"}),e.jsxs("label",{className:"flex items-center gap-1.5 text-[10px] cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:It,onChange:r=>ct(r.target.checked),className:"rounded border-input accent-primary"}),"❓ Spørsmål"]}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(b,{size:"sm",className:"h-6 text-[10px]",onClick:()=>Gt(t,St,It),children:"Lagre"}),e.jsx(b,{variant:"ghost",size:"sm",className:"h-6 text-[10px]",onClick:()=>it(null),children:"Avbryt"}),n&&e.jsx(b,{variant:"ghost",size:"sm",className:"h-6 text-[10px] text-destructive",onClick:()=>Gt(t,""),children:"Slett"})]})]}
257):n?e.jsx("p",{className:"text-[11px] whitespace-pre-wrap",children:n.note}):e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Ingen notat."})]})]})};return e.jsxs("div",{className:"min-h-screen bg-background",style:{paddingBottom:at.size>0?"calc(60vh + 2rem)":void 0},children:[e.jsx(wa,{user:Z}),e.jsxs("main",{className:"container mx-auto px-2 sm:px-4 py-4 sm:py-6 max-w-7xl",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 mb-6",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold text-foreground flex items-center gap-2",children:[e.jsx(Na,{className:"h-6 w-6"}),"Nettbutikk"]}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:M?"Laster...":`${y.length} aktive nettordre • ${Ee.totalItems} varelinjer`})]}),e.jsxs("div",{className:"flex gap-1.5 sm:gap-2 flex-wrap",children:[e.jsxs(b,{variant:"outline",size:"sm",onClick:()=>Ut(!0),children:[e.jsx(an,{className:"h-4 w-4 mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"Ferdigmeldte"})]}),e.jsxs(ls,{open:P,onOpenChange:E,children:[e.jsx(Zr,{asChild:!0,children:e.jsxs(b,{variant:"outline",size:"sm",children:[e.jsx(Ba,{className:"h-4 w-4 sm:mr-1"}),e.jsxs("span",{className:"hidden sm:inline",children:["Ekskluder (",te.size,")"]}),e.jsx("span",{className:"sm:hidden text-xs",children:te.size})]})}),e.jsxs(is,{className:"max-w-md",children:[e.jsx(Hs,{children:e.jsx(Ws,{children:"Ekskluderte varenummer"})}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Varer på denne listen ignoreres i lagerfordeling og plukklister."}),e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsx(tt,{placeholder:"Varenummer...",value:se,onChange:t=>$(t.target.value),onKeyDown:t=>{t.key==="Enter"&&se.trim()&&(Ir(se.trim()),$(""))}}),e.jsx(b,{size:"sm",onClick:()=>{se.trim()&&(Ir(se.trim()),$(""))},children:e.jsx(As,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"mt-3 space-y-1 max-h-60 overflow-y-auto",children:[[...te.keys()].sort().map(t=>{const s=ha(t);return e.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 bg-muted/50 rounded text-sm gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"font-mono",children:t}),s&&e.jsx("span",{className:"text-muted-foreground ml-2 truncate",children:s})]}),e.jsx("button",{onClick:()=>sa(t),className:"text-muted-foreground hover:text-destructive shrink-0",children:e.jsx(H,{className:"h-3.5 w-3.5"})})]},t)}),te.size===0&&e.jsx("p",{className:"text-xs text-muted-foreground text-center py-4",children:"Ingen ekskluderte varer"})]})]})]}),e.jsxs(ls,{open:bn,onOpenChange:wn,children:[e.jsx(Zr,{asChild:!0,children:e.jsxs(b,{variant:"outline",size:"sm",children:[e.jsx(es,{className:"h-4 w-4 sm:mr-1"}),e.jsxs("span",{className:"hidden sm:inline",children:["Butikkregler (",We.length+Se.length+B.size,")"]}),e.jsx("span",{className:"sm:hidden text-xs",children:We.length+Se.length+B.size})]})}),e.jsxs(is,{className:"max-w-3xl",children:[e.jsx(Hs,{children:e.jsx(Ws,{children:"Butikkregler for lagerfordeling"})}),e.jsxs(Jr,{value:Sn,onValueChange:t=>Cn(t),children:[e.jsxs(en,{className:"grid w-full grid-cols-2",children:[e.jsxs(ss,{value:"rules",children:["Regler (",We.length+Se.length,")"]}),e.jsxs(ss,{value:"articles",children:["Faste varenr (",B.size,")"]})]}),e.jsxs(rs,{value:"rules",className:"mt-3 space-y-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"Reglene brukes ovenfra og ned. Første treff bestemmer butikk. Manuelt satte varenr (neste fane) overstyrer alltid reglene."}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(Me,{value:ae,onValueChange:t=>{$n(t),Dt("")},children:[e.jsx(Fe,{className:"w-[145px]",children:e.jsx(De,{})}),e.jsxs(Ue,{children:[e.jsx(L,{value:"keyword",children:"Ord i varenavn"}),e.jsx(L,{value:"manufacturer",children:"Produsent"}),e.jsx(L,{value:"maingroup",children:"Hovedgruppe"}),e.jsx(L,{value:"webgroup1",children:"Webgruppe 1"}),e.jsx(L,{value:"webgroup2",children:"Webgruppe 2"}),e.jsx(L,{value:"webgroup3",children:"Webgruppe 3"}),e.jsx(L,{value:"stock_diff",children:"Lagerdifferanse"})]})]}),ae==="stock_diff"?e.jsxs("div",{className:"flex items-center gap-1 flex-1 min-w-[150px]",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Diff ≥"}),e.jsx(tt,{type:"number",min:1,value:dr,onChange:t=>Tn(t.target.value),className:"w-16 h-9"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"→ butikk med mest lager"})]}):e.jsxs(e.Fragment,{children:[ae==="keyword"?e.jsx(tt,{value:Ft,onChange:t=>Dt(t.target.value),placeholder:"f.eks. sykkel",className:"flex-1 min-w-[120px] h-9"}):e.jsx(xn,{options:ar[ae==="manufacturer"?"manufacturer":ae]||[],value:Ft,onChange:Dt,placeholder:ae==="manufacturer"?"Velg produsent...":"Velg verdi...",className:"flex-1 min-w-[150px]"}),e.jsxs(Me,{value:cr,onValueChange:zn,children:[e.jsx(Fe,{className:"w-[110px]",children:e.jsx(De,{})}),e.jsxs(Ue,{children:[e.jsx(L,{value:"Stoa",children:"Stoa"}),e.jsx(L,{value:"Sentrum",children:"Sentrum"}),e.jsx(L,{value:"Stadion",children:"Stadion"})]})]})]}),e.jsx(b,{size:"sm",onClick:Qn,children:e.jsx(As,{className:"h-4 w-4"})})]}),ae!=="stock_diff"&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mt-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Begrens til kategori:"}),e.jsxs(Me,{value:xt,onValueChange:t=>{xr(t),gs("")},children:[e.jsx(Fe,{className:"w-[145px] h-9",children:e.jsx(De,{})}),e.jsxs(Ue,{children:[e.jsx(L,{value:"none",children:"Alle kategorier"}),Za.map(t=>e.jsx(L,{value:t.value,children:t.label},t.value))]})]}),xt!=="none"&&e.jsx(xn,{options:ar[xt]||[],value:hs,onChange:gs,placeholder:"Velg kategori...",className:"flex-1 min-w-[150px]"})]}),e.jsxs("div",{className:"mt-2 space-y-1 max-h-48 overflow-y-auto",children:[Se.map(t=>e.jsxs("div",{className:`flex items-center justify-between px-3 py-1.5 rounded text-sm gap-2 ${t.is_active?"bg-muted/50":"bg-muted/20 opacity-60"}`,children:[e.jsxs("div",{className:"min-w-0 flex items-center gap-2",children:[e.jsx(I,{variant:"secondary",className:"text-[10px] shrink-0",children:t.rule_type==="
257keyword"?"Ord":t.rule_type==="manufacturer"?"Produsent":t.rule_type==="maingroup"?"Hovedgr.":t.rule_type==="webgroup1"?"Webgr. 1":t.rule_type==="webgroup2"?"Webgr. 2":t.rule_type==="webgroup3"?"Webgr. 3":"Lagerdiff"}),e.jsx("span",{className:"truncate",children:t.rule_type==="stock_diff"?`≥ ${t.threshold} stk differanse`:t.match_value}),t.category_value&&e.jsxs(I,{variant:"outline",className:"text-[10px] shrink-0",children:["kun ",t.category_value]}),e.jsx("span",{className:"text-muted-foreground",children:"→"}),e.jsx(I,{variant:"outline",className:t.target_store==="auto"?"":gt(t.target_store),children:t.target_store==="auto"?"Mest lager":t.target_store})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsx(Aa,{checked:t.is_active,onCheckedChange:()=>Zn(t)}),e.jsx("button",{onClick:()=>Xn(t.id),className:"text-muted-foreground hover:text-destructive",children:e.jsx(H,{className:"h-3.5 w-3.5"})})]})]},t.id)),Se.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground text-center py-3",children:"Ingen regler lagt til"})]})]}),e.jsxs("div",{className:"border-t pt-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"Webgruppe → butikk (settes i PcK-uttrekket, gjelder før reglene over)."}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(Me,{value:ps,onValueChange:lr,children:[e.jsx(Fe,{className:"flex-1",children:e.jsx(De,{placeholder:"Velg webgruppe..."})}),e.jsx(Ue,{children:_n.filter(t=>!We.some(s=>s.webgroup1_name===t)).map(t=>e.jsx(L,{value:t,children:t},t))})]}),e.jsxs(Me,{value:ir,onValueChange:Nn,children:[e.jsx(Fe,{className:"w-[110px]",children:e.jsx(De,{})}),e.jsxs(Ue,{children:[e.jsx(L,{value:"Stoa",children:"Stoa"}),e.jsx(L,{value:"Sentrum",children:"Sentrum"}),e.jsx(L,{value:"Stadion",children:"Stadion"})]})]}),e.jsx(b,{size:"sm",onClick:ea,children:e.jsx(As,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"mt-2 space-y-1 max-h-40 overflow-y-auto",children:[We.map(t=>e.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 bg-muted/50 rounded text-sm gap-2",children:[e.jsxs("div",{className:"min-w-0 flex items-center gap-2",children:[e.jsx("span",{className:"truncate",children:t.webgroup1_name}),e.jsx("span",{className:"text-muted-foreground",children:"→"}),e.jsx(I,{variant:"outline",className:gt(t.target_store),children:t.target_store})]}),e.jsx("button",{onClick:()=>ta(t.id),className:"text-muted-foreground hover:text-destructive shrink-0",children:e.jsx(H,{className:"h-3.5 w-3.5"})})]},t.id)),We.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground text-center py-3",children:"Ingen webgruppe-regler"})]})]})]}),e.jsxs(rs,{value:"articles",className:"mt-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"Varenr som er manuelt overstyrt huskes her og rutes automatisk til samme butikk ved neste bestilling. Fjern en linje for å gå tilbake til automatisk fordeling."}),e.jsx(tt,{value:Ne,onChange:t=>En(t.target.value),placeholder:"Søk varenr eller varenavn – velg butikk for å legge til...",className:"h-9 mb-2"}),e.jsxs("div",{className:"mb-2 border border-border rounded p-2 bg-muted/20",children:[e.jsx("p",{className:"text-[11px] text-muted-foreground mb-1",children:"Lim inn flere varenr (ett per linje eller skilt med komma)"}),e.jsx(ts,{value:_s,onChange:t=>hr(t.target.value),placeholder:`1726848
2581807559
2591847403`,className:"text-xs font-mono min-h-[70px] mb-2"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(Me,{value:gr,onValueChange:Ln,children:[e.jsx(Fe,{className:"h-8 w-[130px] text-xs",children:e.jsx(De,{})}),e.jsxs(Ue,{children:[e.jsx(L,{value:"Stoa",children:"Stoa"}),e.jsx(L,{value:"Sentrum",children:"Sentrum"}),e.jsx(L,{value:"Stadion",children:"Stadion"})]})]}),e.jsx(b,{size:"sm",className:"h-8",disabled:fr||!_s.trim(),onClick:()=>da(_s,gr),children:fr?"Lagrer...":"Legg til alle"})]})]}),Ne.trim().length>=2&&e.jsxs("div",{className:"mb-2 border border-border rounded p-2 bg-muted/30",children:[e.jsx("p",{className:"text-[11px] text-muted-foreground mb-1",children:ur?"Søker i varekatalogen...":"Legg til fast butikkvalg"}),e.jsxs("div",{className:"space-y-1 max-h-48 overflow-y-auto",children:[mr.filter(t=>!B.has(t.article_no)).map(t=>e.jsxs("div",{className:"flex items-center justify-between gap-2 px-2 py-1 rounded bg-background text-sm",children:[e.jsxs("div",{className:"min-w-0 flex items-center gap-2",children:[e.jsx("span",{className:"font-mono text-xs shrink-0",children:t.article_no}),e.jsx("span",{className:"truncate",children:t.name}),t.colors.length>0&&e.jsx(I,{variant:"secondary",className:"text-[10px] shrink-0",children:t.colors.join(", ")})]}),e.jsx("div",{className:"flex gap-1 shrink-0",children:["Stoa","Sentrum","Stadion"].map(s=>e.jsx(b,{size:"sm",variant:"outline",className:"h-6 px-2 text-[11px]",onClick:()=>Br(t,s),children:s},s))})]},t.article_no)),!ur&&mr.filter(t=>!B.has(t.article_no)).length===0&&(/^\d{3,}$/.test(Ne.trim())&&!B.has(Ne.trim())?e.jsxs("div",{className:"flex items-center justify-between gap-2 px-2 py-1 rounded bg-background text-sm",children:[e.jsxs("div",{className:"min-w-0 flex items-center gap-2",children:[e.jsx("span",{className:"font-mono text-xs shrink-0",children:Ne.trim()}),e.jsx("span",{className:"truncate text-muted-foreground",children:"Ikke i varekatalogen – legg inn varenr direkte"})]}),e.jsx("div",{className:"flex gap-1 shrink-0",children:["Stoa","Sentrum","Stadion"].map(t=>e.jsx(b,{size:"sm",variant:"outline",className:"h-6 px-2 text-[11px]",onClick:()=>Br({article_no:Ne.trim(),name:null,colors:[]},t),children:t},t))})]}):e.jsx("p",{className:"text-xs text-muted-foreground py-1",children:"Ingen treff i varekatalogen"}))]})]}),e.jsxs("div",{className:"space-y-1 max-h-72 overflow-y-auto",children:[[...B.values()].filter(t=>{const s=Ne.toLowerCase().trim();return s?t.article_no.toLowerCase().includes(s)||(t.article_name||"").toLowerCase().includes(s)||(t.color_name||"").toLowerCase().includes(s):!0}).sort((t,s)=>(t.article_name||t.article_no).localeCompare(s.article_name||s.article_no,"nb")).map(t=>{const s=q.get(t.article_no);return e.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 bg-muted/50 rounded text-sm gap-2",children:[e.jsxs("div",{className:"min-w-0 flex items-center gap-2",children:[s?e.jsx("img",{src:s,alt:t.article_name||t.article_no,className:"h-8 w-8 shrink-0 rounded border border-border object-contain bg-background cursor-zoom-in",onClick:()=>Ce(s)}):e.jsx("div",{className:"h-8 w-8 shrink-0 rounded border border-border bg-muted/40"}),e.jsx("span",{className:"font-mono text-xs shrink-0",children:t.article_no}),e.jsx("span",{className:"truncate",children:t.article_name}),t.color_name&&e.jsx(I,{variant:"secondary",className:"text-[10px] shrink-0",children:t.color_name}),e.jsx("span",{className:"text-muted-foreground",children:"→"}),e.jsx(I,{variant:"outline",className:`shrink-0 ${gt(t.target_store)}`,children:t.target_store})]}),e.jsx("button",{onClick:()=>Cs(t.article_no),className:"text-muted-foreground hover:text-destructive shrink-0",children:e.jsx(H,{className:"h-3.5 w-3.5"})})]},t.id)}),B.size===0&&e.jsx("p",{className:"text-xs text-muted-foreground text-center py-4",children:"Ingen faste varenr ennå"})]})]})]})]})]}),e.jsxs(b,{size:"sm",onClick:()=>{Mr(),Qe(),$s()},disabled:M,children:[e.jsx(ya,{className:`h-4 w-4 mr-1 ${M?"animate-spin":""}`}),"Oppdater"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-2 sm:gap-3 mb-4 sm:mb-6",children:[e.jsx(st,{className:`curs
259or-pointer transition-all border-2 ${f==="all"?"border-primary bg-primary/5 ring-2 ring-primary/20 shadow-md":"border-transparent hover:border-primary/30"}`,onClick:()=>G("all"),children:e.jsxs(jt,{className:"p-3 sm:p-4",children:[e.jsx("p",{className:`text-[11px] sm:text-xs font-medium ${f==="all"?"text-primary":"text-muted-foreground"}`,children:"Totalt"}),e.jsx("p",{className:`text-xl sm:text-2xl font-bold ${f==="all"?"text-primary":""}`,children:Ee.total}),z>0&&e.jsxs("p",{className:"text-[10px] text-emerald-600 dark:text-emerald-400 mt-0.5",children:["📦 ",z," sendt i dag"]})]})}),["Stoa","Sentrum","Stadion"].map(t=>e.jsx(st,{className:`cursor-pointer transition-all border-2 ${f===t?"border-primary bg-primary/5 ring-2 ring-primary/20 shadow-md":"border-transparent hover:border-primary/30"}`,onClick:()=>G(f===t?"all":t),children:e.jsxs(jt,{className:"p-3 sm:p-4",children:[e.jsx("p",{className:`text-[11px] sm:text-xs font-medium ${f===t?"text-primary":"text-muted-foreground"}`,children:t}),e.jsx("p",{className:`text-xl sm:text-2xl font-bold ${f===t?"text-primary":""}`,children:Ee.byWarehouse[t]||0}),Ee.pickedMixedLines[t]&&Ee.pickedMixedLines[t].total>0&&e.jsxs("p",{className:"text-[10px] text-amber-600 dark:text-amber-400 mt-0.5",children:[e.jsx(ye,{className:"h-2.5 w-2.5 inline mr-0.5"}),Ee.pickedMixedLines[t].picked,"/",Ee.pickedMixedLines[t].total," plukket"]})]})},t))]}),(()=>{const t=[{key:"splitButikk",icon:ye,label:"Bl. butikk",state:Tt,setter:Qs},{key:"splitStadion",icon:ye,label:"Bl. Stadion",state:Et,setter:Zs},{key:"noted",icon:qs,label:"Notater",state:$t,setter:Ys},{key:"bestilt",icon:wt,label:"Bestilt",state:zt,setter:Gs},{key:"finnerIkke",icon:H,label:"Finner ikke",state:Lt,setter:Xs},{key:"fullyPicked",icon:an,label:"Ferdig plukket",state:Pt,setter:Js},{key:"levert",icon:Re,label:"Levert",state:Ot,setter:er},{key:"sendt",icon:wt,label:"Sendt eksternt",state:At,setter:tr}],s=t.filter(l=>l.state!=="off"),n=()=>{nt("all"),G("all"),oe(""),Ys("off"),Gs("off"),Qs("off"),Zs("off"),Xs("off"),Js("off"),er("off"),tr("off")},a=s.length+(be!=="all"?1:0)+(f!=="all"?1:0),r=a>0||!!U.trim();return e.jsxs("div",{className:"mb-4 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"relative flex-1 min-w-0",children:[e.jsx(mn,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(tt,{placeholder:"Søk i ordre, kunde, produkt...",value:U,onChange:l=>oe(l.target.value),className:"pl-9 h-9"}),!!U&&e.jsx("button",{onClick:()=>oe(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground","aria-label":"Tøm søk",children:e.jsx(H,{className:"h-3.5 w-3.5"})})]}),e.jsxs(he,{children:[e.jsx(ge,{asChild:!0,children:e.jsxs(b,{variant:"outline",size:"sm",className:`h-9 text-xs gap-1.5 shrink-0 ${a>0?"border-primary text-primary":""}`,children:[e.jsx(Ha,{className:"h-3.5 w-3.5"}),"Filter",a>0&&e.jsx(I,{variant:"secondary",className:"ml-0.5 h-4 px-1.5 text-[10px]",children:a})]})}),e.jsxs(fe,{align:"end",className:"w-[320px] p-2 max-h-[70vh] overflow-y-auto",children:[e.jsxs("div",{className:"flex items-center justify-between px-1 pb-1.5 mb-1 border-b",children:[e.jsx("span",{className:"text-xs font-medium",children:"Filtrer ordre"}),r&&e.jsx("button",{onClick:n,className:"text-[10px] text-destructive hover:underline",children:"Nullstill"})]}),Ur.length>0&&e.jsxs("div",{className:"pb-2 mb-1.5 border-b",children:[e.jsx("p",{className:"text-[10px] uppercase tracking-wide text-muted-foreground px-1 mb-1",children:"Sendingstype"}),e.jsx("div",{className:"flex flex-wrap gap-1",children:Ur.map(l=>{const o=Ee.byShipping[l]||0,x=be===l;return e.jsxs("button",{onClick:()=>nt(x?"all":l),className:`inline-flex items-center gap-1 px-2 py-1 rounded-full text-[10px] font-medium border transition-all ${x?"bg-primary text-primary-foreground border-primary":"bg-muted/50 text-muted-foreground border-border hover:bg-muted hover:text-foreground"}`,children:[l.replace("Klikk & Hent - ","K&H ").replace("Elektronisk Levering","Elektr."),e.jsx("span",{className:`inline-flex items-center justify-center min-w-[16px] h-[16px] rounded-full text-[9px] font-bold ${x?"bg-primary-foreground
259/20 text-primary-foreground":"bg-background text-foreground"}`,children:o})]},l)})})]}),e.jsx("p",{className:"text-[10px] uppercase tracking-wide text-muted-foreground px-1 mb-1",children:"Visning"}),e.jsx("div",{className:"space-y-0.5",children:t.map(({icon:l,label:o,state:x,setter:d,key:m})=>e.jsxs("div",{className:"flex items-center gap-2 rounded-md px-1.5 py-1 hover:bg-muted/40",children:[e.jsx(l,{className:"h-3.5 w-3.5 text-muted-foreground shrink-0"}),e.jsx("span",{className:"text-xs flex-1 truncate",children:o}),e.jsx("div",{className:"flex rounded-md border overflow-hidden shrink-0",children:[{value:"hide",lbl:"Skjul"},{value:"only",lbl:"Kun"}].map(({value:p,lbl:u})=>e.jsx("button",{onClick:()=>d(x===p?"off":p),className:`px-2 py-1 text-[10px] font-medium transition-colors ${x===p?p==="hide"?"bg-destructive/15 text-destructive":"bg-primary/15 text-primary":"text-muted-foreground hover:text-foreground hover:bg-muted/50"}`,children:u},p))})]},m))})]})]}),e.jsxs(b,{variant:"outline",size:"sm",onClick:()=>Ve(l=>l==="asc"?"desc":"asc"),className:"h-9 text-xs shrink-0",title:ke==="asc"?"Eldst først":"Nyest først",children:[e.jsx(ln,{className:"h-3.5 w-3.5 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:ke==="asc"?"Eldst først":"Nyest først"})]})]}),r&&e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[f!=="all"&&e.jsxs("button",{onClick:()=>G("all"),className:"inline-flex items-center gap-1 px-2 py-1 rounded-md text-[10px] font-medium border bg-primary/10 text-primary border-primary/20 hover:bg-primary/20 transition-colors",children:["Lager: ",f,e.jsx(H,{className:"h-3 w-3"})]}),be!=="all"&&e.jsxs("button",{onClick:()=>nt("all"),className:"inline-flex items-center gap-1 px-2 py-1 rounded-md text-[10px] font-medium border bg-primary/10 text-primary border-primary/20 hover:bg-primary/20 transition-colors",children:[be,e.jsx(H,{className:"h-3 w-3"})]}),!!U.trim()&&e.jsxs("button",{onClick:()=>oe(""),className:"inline-flex items-center gap-1 px-2 py-1 rounded-md text-[10px] font-medium border bg-muted text-foreground border-border hover:bg-muted/70 transition-colors",children:["«",U.trim(),"»",e.jsx(H,{className:"h-3 w-3"})]}),s.map(({key:l,label:o,state:x,setter:d})=>e.jsxs("button",{onClick:()=>d("off"),className:`inline-flex items-center gap-1 px-2 py-1 rounded-md text-[10px] font-medium border transition-colors ${x==="hide"?"bg-destructive/10 text-destructive border-destructive/20 hover:bg-destructive/20":"bg-primary/10 text-primary border-primary/20 hover:bg-primary/20"}`,children:[x==="hide"?"Skjul":"Kun",": ",o,e.jsx(H,{className:"h-3 w-3"})]},l)),e.jsxs("button",{onClick:n,className:"inline-flex items-center gap-1 px-2 py-1 rounded-md text-[10px] font-medium text-muted-foreground hover:text-foreground hover:bg-muted transition-colors",children:[e.jsx(H,{className:"h-3 w-3"}),"Fjern alle"]})]})]})})(),e.jsxs(Jr,{value:jr,onValueChange:t=>{if(js(t),t==="picklist"){yr(null);const s=[...new Set(ce.flatMap(([,n])=>n.map(a=>a.article_no)))];ue(s)}},className:"space-y-4",children:[e.jsxs(en,{className:"w-full sm:w-auto",children:[e.jsxs(ss,{value:"orders",className:"flex-1 sm:flex-none",children:["Ordre (",pe.length,")"]}),e.jsxs(ss,{value:"picklist",className:"flex-1 sm:flex-none",children:["Plukkliste (",ce.reduce((t,[,s])=>t+s.length,0)," linjer)"]})]}),e.jsxs(rs,{value:"orders",className:"space-y-3",children:[Nr!==null&&e.jsx("div",{className:"fixed bottom-6 right-6 z-50",children:e.jsxs(b,{size:"sm",variant:"default",className:"shadow-xl flex items-center gap-1.5 rounded-full px-4 py-2 h-auto",onClick:()=>{const t=Nr;yr(null),js("picklist"),setTimeout(()=>window.scrollTo({top:t,behavior:"smooth"}),50)},children:[e.jsx(on,{className:"h-4 w-4"}),"Tilbake til plukkliste"]})}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx(b,{variant:"outline",size:"sm",onClick:pa,children:we.size===pe.length&&pe.length>0?"Fjern alle":"Velg alle"}),e.jsxs(b,{variant:"outline",size:"sm",disabled:at.size===0,onClick:()=>qe(new Set),title:"Lukk åpent ordrepanel",children:[e.jsx(Be,{className:"h-4 w-4 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"Lukk panel"})]}),we.size>0&&e.jsxs(b,{size:"sm",onClick:()=>Es(),children:[e.jsx(ns,{className:"h-4 w-4 mr-1"}),"Skriv ut ",we.size," ordre"]})]}),M?e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx(rt,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):pe.length===0?e.jsx(st,{children:e.jsxs(jt,{className:"py-12 text-center text-muted-foreground",children:[e.jsx(_e,{className:"h-12 w-12 mx-auto mb-3 opacity-50"}),e.jsx("p",{children:"Ingen aktive nettordre funnet"})]})}):e.jsxs("div",{className:"border border-border rounded-md overflow-hidden",children:[(()=>{const t=a=>{ve===a?Ve(r=>r==="asc"?"desc":"asc"):(yt(a),Ve("asc"))},s=({col:a})=>ve===a?e.jsx(ln,{className:"h-3 w-3 inline-block ml-0.5 text-foreground"}):null,n="cursor-pointer select-none hover:text-foreground transition-colors flex items-center gap-0.5";return e.jsxs("div",{className:"hidden sm:grid items-center gap-x-1.5 px-4 py-1.5 bg-muted/50 border-b border-border text-[11px] font-semibold text-muted-foreground uppercase tracking-wide sticky top-0 z-10",style:{gridTemplateColumns:"16px 20px 60px 72px 70px 140px 46px 100px 65px 100px 1fr 1fr 92px"},children:[e.jsx("span",{}),e.jsx("span",{}),e.jsxs("span",{className:n,onClick:()=>t("warehouse"),children:["Lager",e.jsx(s,{col:"warehouse"})]}),e.jsxs("span",{className:n,onClick:()=>t("order"),children:["Ordre",e.jsx(s,{col:"order"})]}),e.jsxs("span",{className:n,onClick:()=>t("date"),children:["Dato",e.jsx(s,{col:"date"})]}),e.jsxs("span",{className:n,onClick:()=>t("customer"),children:["Kunde",e.jsx(s,{col:"customer"})]}),e.jsxs("span",{className:n,onClick:()=>t("items"),children:["Varer",e.jsx(s,{col:"items"})]}),e.jsxs("span",{className:n,onClick:()=>t("shipping"),children:["Levering",e.jsx(s,{col:"shipping"})]}),e.jsxs("span",{className:n,onClick:()=>
259t("city"),children:["By",e.jsx(s,{col:"city"})]}),e.jsx("span",{children:"Status"}),e.jsx("span",{children:"Info"}),e.jsx("span",{children:"Notat"}),e.jsxs("span",{className:`${n} justify-end`,onClick:()=>t("amount"),children:["Beløp",e.jsx(s,{col:"amount"})]})]})})(),pe.map((t,s)=>{var W,C,de,Ps,Xe;const n=at.has(t.order_id),a=we.has(t.order_id),r=Ze(t),l=V.get(t.order_id),x=t.items.filter(i=>N.has(v(t.order_id,i.article_no,i.size_name,i.color_name,_.BESTILT_STADION))).map(i=>({...N.get(v(t.order_id,i.article_no,i.size_name,i.color_name,_.BESTILT_STADION)),hasArrived:i.warehouse==="Sentrum"?i.available_sentrum>=1:i.available_stoa>=0})),d=x.length>0&&x.every(i=>i.hasArrived);x.some(i=>i.hasArrived);const m=t.items.filter(i=>!S(i.article_no)&&!A(t.order_id,i)),p=m.length,u=m.filter(i=>N.has(v(t.order_id,i.article_no,i.size_name,i.color_name,_.PLUKKET_SENTRUM))).length,h=m.filter(i=>N.has(v(t.order_id,i.article_no,i.size_name,i.color_name,_.PLUKKET_STOA))).length,k=Qt(t);return e.jsx("div",{children:e.jsxs("div",{id:`order-${t.order_id}`,className:`${a?"bg-primary/5":""} ${k?"bg-muted/30 order-greyed-out":""} ${n?"border-y border-primary/60 shadow-md ring-1 ring-primary/20":""}`,children:[e.jsx("div",{className:`flex items-start gap-2 sm:gap-0 px-3 sm:px-4 py-2 sm:py-1.5 cursor-pointer hover:bg-muted/40 transition-colors border-b border-border/50 ${n?"bg-primary/10":""}`,onClick:()=>ma(t.order_id),children:e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"sm:hidden",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("input",{type:"checkbox",checked:a,onChange:i=>{i.stopPropagation(),Vr(t.order_id)},onClick:i=>i.stopPropagation(),className:"h-3.5 w-3.5 rounded border-input accent-primary shrink-0 order-exempt"}),e.jsx("div",{className:"order-exempt shrink-0",children:n?e.jsx(Be,{className:"h-3.5 w-3.5 text-muted-foreground"}):e.jsx(pn,{className:"h-3.5 w-3.5 text-muted-foreground"})}),e.jsx("span",{className:`text-[10px] shrink-0 ${r==="Sentrum"||r==="Stoa"?"text-foreground":"text-muted-foreground"}`,children:r==="Sentrum"?"Sent":r==="Stoa"?"Stoa":r}),e.jsx("span",{className:"font-mono text-[11px] shrink-0",children:t.order_id}),e.jsx("span",{className:"text-[11px] truncate flex-1",children:t.delivery_name}),k?e.jsxs("span",{className:"text-[10px] text-emerald-600 dark:text-emerald-400 shrink-0 flex items-center gap-0.5 order-exempt",children:[e.jsx(Re,{className:"h-3 w-3"}),"Plukket"]}):e.jsxs("span",{className:"text-[11px] font-medium shrink-0 tabular-nums",children:[t.total_revenue.toLocaleString("nb-NO",{minimumFractionDigits:0})," kr"]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 ml-[52px] mt-0.5 text-[10px] text-muted-foreground flex-wrap",children:[e.jsx("span",{className:(()=>{const i=Math.floor((Date.now()-new Date(t.order_date).getTime())/864e5);return i>=5?"text-destructive font-medium":i>=3?"font-medium":""})(),children:Zt(t.order_date)}),e.jsx("span",{className:"opacity-40",children:"·"}),e.jsxs(he,{children:[e.jsx(ge,{asChild:!0,children:e.jsxs("span",{className:"underline decoration-dotted cursor-pointer",onClick:i=>i.stopPropagation(),children:[t.items.filter(i=>!S(i.article_no)).length," varer"]})}),e.jsxs(fe,{className:"w-72 p-2 max-h-64 overflow-y-auto",side:"bottom",align:"start",onClick:i=>i.stopPropagation(),children:[e.jsxs("p",{className:"text-xs font-semibold mb-1.5 text-foreground",children:["Varer på ordre ",t.order_id]}),e.jsx("div",{className:"space-y-1",children:t.items.filter(i=>!S(i.article_no)).map((i,F)=>{const D=O(t.order_id,i);return e.jsxs("div",{className:"flex items-start gap-1.5 text-[11px] leading-tight py-0.5 border-b border-border/50 last:border-0",children:[e.jsx("span",{className:"text-[10px] shrink-0 text-muted-foreground",children:D}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-medium truncate",children:i.article_name}),e.jsxs("p",{className:"text-muted-foreground",children:[i.article_no," • ",i.color_name," • ",i.size_name," • ",i.units," stk"]})]})]},F)})})]})]}),e.jsx("span",{className:"opacity-40",children:"·"}),e.jsx("span",{children:t.delivery_city}),t.shipping_method&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"opacity-40",children:"·"}),e.jsx("span",{children:t.shipping_method.replace("Klikk & Hent - ","K&H ").replace("Klikk & Hent","K&H").replace("Elektronisk Levering","Elektr.")})]}),x.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"opacity-40",children:"·"}),e.jsx("span",{className:d?"text-foreground":"",children:d?"Kommet":"Bestilt"})]}),u>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"opacity-40",children:"·"}),e.jsxs("span",{children:["S",u<p?` ${u}/${p}`:"✓"]})]}),h>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"opacity-40",children:"·"}),e.jsxs("span",{children:["St",h<p?` ${h}/${p}`:"✓"]})]}),pt.has(t.order_id)&&(()=>{const i=pt.get(t.order_id),F=i.status==="klar_til_henting"||i.status==="utlevert";return e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"opacity-40",children:"·"}),e.jsx("span",{children:F?"🔧✓":"🔧"})]})})(),(()=>{const i=Le(t.order_info||t.pl_info||"");return i?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"opacity-40",children:"·"}),e.jsx("span",{className:"truncate max-w-[120px]",title:i,children:i.length>15?i.slice(0,15)+"…":i})]}):null})(),l&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"opacity-40",children:"·"}),e.jsxs("span",{className:l.is_question&&!l.answer?"text-destructive":"",children:[l.is_question?l.answer?"✅":"❓":"📝"," ",l.note.length>12?l.note.slice(0,12)+"…":l.note]})]})]})]}),e.jsxs("div",{className:"hidden sm:grid items-center gap-x-1.5",style:{gridTemplateColumns:"16px 20px 60px 72px 70px 140px 46px 100px 65px 100px 1fr 1fr 92px"},children:[e.jsx("input",{type:"checkbox",checked:a,onChange:i=>{i.stopPropagation(),Vr(t.order_id)},onClick:i=>i.stopPropagation(),className:"h-3.5 w-3.5 rounded border-input accent-primary order-exempt"}),e.jsx("button",{onClick:i=>{i.stopPropagation(),navigator.clipboard.writeText(String(t.order_id)),w.success("Ordrenummer kopiert")},className:"text-muted-foreground hover:text-foreground transition-colors",title:"Kopier ordrenummer",children:e.jsx(os,{className:"h-3 w-3"})}
259),e.jsx("span",{className:`text-[11px] truncate ${r==="Sentrum"||r==="Stoa"?"text-foreground":"text-muted-foreground"}`,children:r}),e.jsx("span",{className:"font-mono text-xs truncate",children:t.order_id}),e.jsx("span",{className:`text-[11px] truncate ${(()=>{const i=Math.floor((Date.now()-new Date(t.order_date).getTime())/864e5);return i>=5?"text-destructive":i>=3?"text-muted-foreground font-medium":"text-muted-foreground"})()}`,children:Zt(t.order_date)}),e.jsx("span",{className:"text-xs truncate",children:t.delivery_name}),e.jsxs(La,{openDelay:200,closeDelay:100,children:[e.jsx(Pa,{asChild:!0,children:e.jsxs("span",{className:"text-[11px] text-muted-foreground truncate cursor-pointer hover:text-foreground transition-colors",children:[t.items.filter(i=>!S(i.article_no)).length," stk"]})}),e.jsxs(Oa,{className:"w-80 p-2 max-h-72 overflow-y-auto",side:"bottom",align:"start",children:[e.jsxs("p",{className:"text-xs font-semibold mb-1.5 text-foreground",children:["Varer på ordre ",t.order_id]}),e.jsx("div",{className:"space-y-1",children:t.items.filter(i=>!S(i.article_no)).map((i,F)=>{const D=O(t.order_id,i);return e.jsxs("div",{className:"flex items-start gap-1.5 text-[11px] leading-tight py-0.5 border-b border-border/50 last:border-0",children:[e.jsx("span",{className:"text-[10px] shrink-0 text-muted-foreground",children:D}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-medium truncate",children:i.article_name}),e.jsxs("p",{className:"text-muted-foreground",children:[i.article_no," • ",i.color_name," • ",i.size_name," • ",i.units," stk"]})]})]},F)})})]})]}),e.jsx("span",{className:"text-[11px] text-muted-foreground truncate",children:(W=t.shipping_method)==null?void 0:W.replace("Klikk & Hent - ","K&H ").replace("Klikk & Hent","K&H").replace("Elektronisk Levering","Elektr.")}),e.jsx("span",{className:"text-[11px] text-muted-foreground truncate",children:t.delivery_city}),e.jsxs("div",{className:"flex items-center gap-1 overflow-hidden min-w-0 text-[10px] text-muted-foreground",children:[x.length>0&&e.jsx("span",{className:d?"text-foreground":"",children:d?"Kommet":"Bestilt"}),u>0&&e.jsxs("span",{children:["S",u<p?` ${u}/${p}`:"✓"]}),h>0&&e.jsxs("span",{children:["St",h<p?` ${h}/${p}`:"✓"]}),pt.has(t.order_id)&&(()=>{const i=pt.get(t.order_id),F=i.status==="klar_til_henting"||i.status==="utlevert";return e.jsx("span",{children:F?"🔧✓":"🔧"})})()]}),e.jsx("div",{className:"overflow-hidden min-w-0",children:(()=>{const i=Le(t.order_info||t.pl_info||"");return i?e.jsx("span",{className:"text-[10px] text-muted-foreground truncate block",title:i,children:i.length>20?i.slice(0,20)+"…":i}):null})()}),e.jsx("div",{className:"overflow-hidden min-w-0",children:l&&e.jsxs("span",{className:`text-[10px] truncate block ${l.is_question&&!l.answer?"text-destructive":"text-muted-foreground"}`,title:l.note,children:[l.is_question?l.answer?"✅ ":"❓ ":"",l.note.length>18?l.note.slice(0,18)+"…":l.note]})}),k?e.jsxs("span",{className:"text-[11px] whitespace-nowrap text-right flex items-center justify-end gap-1 text-muted-foreground order-exempt",children:[e.jsx(Nt,{className:"h-3 w-3"}),"Plukket"]}):e.jsxs("span",{className:"text-[11px] whitespace-nowrap text-right tabular-nums",children:[t.total_revenue.toLocaleString("nb-NO",{minimumFractionDigits:0})," kr"]})]})]})}),n&&va.createPortal(e.jsxs("div",{className:"fixed inset-x-0 bottom-0 z-40 bg-background border-t-2 border-primary shadow-2xl flex flex-col",style:{maxHeight:"60vh"},children:[e.jsxs("div",{className:"flex items-center justify-between px-3 sm:px-4 py-2 border-b bg-primary/5 shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsxs("span",{className:"text-xs font-bold text-primary",children:["Ordre #",t.order_id]}),e.jsx("span",{className:"text-xs font-medium truncate",children:t.delivery_name||"—"}),t.shipping_method&&e.jsxs("span",{className:"hidden sm:inline text-[11px] text-muted-foreground truncate",children:["· ",t.shipping_method]})]}),e.jsx(b,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 shrink-0",onClick:i=>{i.stopPropagation(),qe(new Set)},"aria-label":"Lukk",children:e.jsx(H,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"overflow-y-auto px-2 sm:px-4 pb-3 pt-2 order-exempt flex-1 min-h-0",children:[(t.order_info||t.pl_info)&&e.jsxs("div",{className:"mb-2 px-2 py-1.5 text-[11px] text-muted-foreground border-l-2 border-border bg-background",children:[t.order_info&&e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"Ordreinfo:"})," ",Le(t.order_info)]}),t.pl_info&&e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"PL-info:"})," ",Le(t.pl_info)]})]}),e.jsx("div",{className:"sm:hidden divide-y divide-border",children:t.items.map((i,F)=>{var Jt;const D=S(i.article_no),ie=A(t.order_id,i),Xt=Ie(t.order_id,i),ft=Q(t.order_id,i.article_no,i.size_name,i.color_name,_.IKKE_FUNNET),_t=ie||Xt;return e.jsxs("div",{className:`py-2.5 px-1 ${D?"opacity-40":""} ${_t?"opacity-50 bg-muted/30":""} ${ft?"bg-red-50 dark:bg-red-900/10":""}`,children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[(()=>{const xe=q.get(i.article_no);return mt.has(i.article_no)?e.jsx("div",{className:"w-10 h-10 rounded bg-muted animate-pulse shrink-0"}):xe?e.jsx("img",{src:xe,alt:"",className:"w-10 h-10 object-contain rounded shrink-0 cursor-pointer hover:opacity-80 transition-opacity",onClick:Os=>{Os.stopPropagation(),Ce(xe)}}):e.jsx("div",{className:"w-10 h-10 rounded bg-muted/50 flex items-center justify-center shrink-0",children:e.jsx(_e,{className:"w-4 h-4 text-muted-foreground
259/40"})})})(),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:`text-xs leading-snug ${ft?"line-through":""} ${_t?"text-muted-foreground":"font-medium"}`,children:$e.get(i.article_no)?e.jsx("a",{href:$e.get(i.article_no),target:"_blank",rel:"noopener noreferrer",onClick:xe=>xe.stopPropagation(),className:"hover:underline hover:text-primary",children:i.article_name}):i.article_name}),e.jsxs("div",{className:"flex items-center gap-1.5 mt-1",children:[i.color_name&&e.jsx("span",{className:"text-[11px] text-muted-foreground",children:i.color_name}),i.size_name&&e.jsx(I,{variant:"outline",className:"text-[10px] px-1.5 py-0 h-4 font-semibold",children:i.size_name}),!D&&e.jsx(Ls,{order:t,item:i,compact:!0}),Ge(t.order_id,i)?e.jsx("span",{className:"text-[9px] font-medium text-sky-600 dark:text-sky-400 whitespace-nowrap",children:"↗ Sendt eksternt"}):!ie&&!D&&e.jsx(Yr,{order:t,item:i}),ie&&e.jsxs("span",{className:"text-[9px] text-muted-foreground flex items-center gap-0.5",children:[e.jsx(Re,{className:"h-2.5 w-2.5"}),"Levert"]})]})]}),e.jsxs("div",{className:"text-right shrink-0",children:[e.jsxs("p",{className:"text-xs font-semibold",children:[i.gross_amount.toLocaleString("nb-NO",{minimumFractionDigits:0})," kr"]}),e.jsxs("p",{className:"text-[10px] text-muted-foreground",children:[i.delivered_qty>0?`${i.remaining_units} stk (${i.delivered_qty} levert)`:`${i.units} stk`,Lr(t.order_id,i)&&e.jsxs("span",{className:"ml-1 text-amber-600 dark:text-amber-400 font-medium",children:[ze(t.order_id,i),"/",me(i)," plukket"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-1 text-[10px] font-mono text-muted-foreground flex-wrap",children:[e.jsx("span",{children:i.article_no}),(((Jt=i.ean_codes)==null?void 0:Jt.length)>0||i.ean_code)&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"opacity-40",children:"·"}),e.jsx(Vt,{item:i,eanKey:`order-mobile-${t.order_id}-${F}`})]}),e.jsx("span",{className:"opacity-40",children:"·"}),e.jsx("span",{className:"font-sans",children:i.manufacturer_name}),!D&&e.jsxs("span",{className:"font-sans",children:["Stoa: ",i.available_stoa," · Sentrum: ",i.available_sentrum]})]}),i.line_info&&e.jsxs("p",{className:"text-[10px] text-muted-foreground mt-1",children:["📋 ",i.line_info]})]},F)})}),e.jsxs(tn,{className:"hidden sm:table text-[11px]",children:[e.jsx(sn,{children:e.jsxs(Je,{className:"bg-muted/30 border-b border-border",children:[e.jsx(R,{className:"text-[10px] w-10 py-0.5 h-6"}),e.jsx(R,{className:"text-[10px] py-0.5 h-6 w-[62px]",children:"Varenr"}),e.jsx(R,{className:"text-[10px] py-0.5 h-6 w-[260px]",children:"Produkt"}),e.jsx(R,{className:"text-[10px] py-0.5 h-6 w-[110px]",children:"Farge"}),e.jsx(R,{className:"text-[10px] py-0.5 h-6 w-[70px]",children:"Størrelse"}),e.jsx(R,{className:"text-[10px] py-0.5 h-6 w-[110px]",children:"Status"}),e.jsx(R,{className:"text-[10px] py-0.5 h-6",children:"EAN"}),e.jsx(R,{className:"text-[10px] py-0.5 h-6",children:"Lager"}),e.jsx(R,{className:"text-[10px] py-0.5 h-6 text-center",children:"Ant"}),e.jsx(R,{className:"text-[10px] py-0.5 h-6 text-right",children:"Beløp"}),e.jsx(R,{className:"text-[10px] py-0.5 h-6 text-right",children:"DG%"})]})}),e.jsx(rn,{children:t.items.map((i,F)=>{const D=S(i.article_no),ie=A(t.order_id,i);Q(t.order_id,i.article_no,i.size_name,i.color_name,_.PLUKKET_SENTRUM),Q(t.order_id,i.article_no,i.size_name,i.color_name,_.PLUKKET_STOA),Q(t.order_id,i.article_no,i.size_name,i.color_name,_.BESTILT_STADION);const Xt=Q(t.order_id,i.article_no,i.size_name,i.color_name,_.IKKE_FUNNET),ft=Ie(t.order_id,i),_t=ie||ft,Jt=D?"opacity-40":_t?"opacity-50":"";return e.jsxs(Je,{className:`${Jt} ${Xt?"bg-red-50 dark:bg-red-900/10":""} border-b border-border/50 hover:bg-muted/30`,children:[e.jsx(K,{className:"w-10 p-1",children:(()=>{const xe=q.get(i.article_no);return mt.has(i.article_no)?e.jsx("div",{className:"w-7 h-7 rounded bg-muted animate-pulse"}):xe?e.jsx("img",{src:xe,alt:"",className:"w-7 h-7 object-contain rounded cursor-pointer hover:opacity-80 transition-opacity",onClick:Os=>{Os.stopPropagation(),Ce(xe)}}):e.jsx("div",{className:"w-7 h-7 rounded bg-muted/50 flex items-center justify-center",children:e.jsx(_e,{className:"w-3 h-3 text-muted-foreground
259/40"})})})()}),e.jsx(K,{className:"text-[11px] font-mono py-1.5 whitespace-nowrap",children:i.article_no}),e.jsxs(K,{className:"text-[11px] py-1.5 w-[260px] max-w-[260px]",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("span",{className:`truncate min-w-0 ${Xt?"line-through":""} ${_t?"text-muted-foreground":""}`,title:i.article_name,children:$e.get(i.article_no)?e.jsx("a",{href:$e.get(i.article_no),target:"_blank",rel:"noopener noreferrer",onClick:xe=>xe.stopPropagation(),className:"hover:underline hover:text-primary",children:i.article_name}):i.article_name}),ie&&e.jsx("span",{className:"text-[9px] text-emerald-600 dark:text-emerald-400 font-medium shrink-0",children:"✓ Levert"}),!ie&&ft&&e.jsx("span",{className:"text-[9px] text-emerald-600 dark:text-emerald-400 font-medium shrink-0",children:"✓ Plukket"})]}),i.line_info&&e.jsxs("div",{className:"text-muted-foreground text-[10px] mt-0.5 truncate",title:i.line_info,children:["📋 ",i.line_info]})]}),e.jsx(K,{className:"text-[10px] py-1.5 text-muted-foreground w-[110px] max-w-[110px]",children:e.jsx("div",{className:"truncate",title:i.color_name,children:i.color_name})}),e.jsx(K,{className:"text-[10px] py-1.5 text-muted-foreground w-[70px] max-w-[70px]",children:e.jsx("div",{className:"truncate",title:i.size_name,children:i.size_name})}),e.jsx(K,{className:"py-1.5 w-[110px]",children:Ge(t.order_id,i)?e.jsx("span",{className:"text-[9px] font-medium text-sky-600 dark:text-sky-400 whitespace-nowrap",children:"↗ Sendt eksternt"}):!ie&&!D&&e.jsx(Yr,{order:t,item:i})}),e.jsx(K,{className:"text-[11px] font-mono text-muted-foreground py-1.5",children:e.jsx(Vt,{item:i,eanKey:`order-desktop-${t.order_id}-${F}`})}),e.jsx(K,{className:"py-1.5",children:D?e.jsx("span",{className:"text-[10px] text-muted-foreground italic",children:"Ekskludert"}):e.jsxs(e.Fragment,{children:[e.jsx(Ls,{order:t,item:i}),e.jsxs("span",{className:"text-[10px] text-muted-foreground ml-1",children:["St:",i.available_stoa," S:",i.available_sentrum]})]})}),e.jsxs(K,{className:"text-[11px] text-center py-1.5 tabular-nums",children:[i.delivered_qty>0?e.jsxs("span",{children:[i.remaining_units," ",e.jsxs("span",{className:"text-muted-foreground",children:["(",i.delivered_qty,"lev)"]})]}):i.units,Lr(t.order_id,i)&&e.jsxs("span",{className:"ml-1 text-[9px] text-amber-600 dark:text-amber-400 font-semibold",children:[ze(t.order_id,i),"/",me(i)]})]}),e.jsx(K,{className:"text-[11px] text-right py-1.5 tabular-nums",children:i.gross_amount.toLocaleString("nb-NO",{minimumFractionDigits:0})}),e.jsx(K,{className:"text-[11px] text-right py-1.5 tabular-nums text-muted-foreground",children:i.net_amount>0?`${Math.round((i.net_amount-i.cost_amount)/i.net_amount*100)}%`:"–"})]},F)})})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-2 mt-1.5 pt-1.5 border-t border-border/50",children:[e.jsxs("div",{className:"text-[11px] text-muted-foreground space-y-0.5",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"Kunde:"})," ",t.delivery_name]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"Adresse:"})," ",t.delivery_address,", ",t.delivery_zipcode," ",t.delivery_city]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"Tlf:"})," ",t.customer_phone?e.jsx("a",{href:`tel:${t.customer_phone}`,className:"hover:underline",children:t.customer_phone}):"-"]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-foreground",children:"E-post:"})," ",t.customer_email||"-"]})]}),e.jsx("div",{className:"p-2 rounded-md border bg-muted/20 border-border",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-[11px] font-medium flex items-center gap-1 text-foreground",children:[e.jsx(Ks,{className:"h-3 w-3"}),"Verksted"]}),(()=>{const i=pt.get(t.order_id);if(i){const D={levert_inn:{label:"Levert inn",className:"bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-300"},under_arbeid:{label:"Under arbeid",className:"bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-300"},klar_til_henting:{label:"Ferdig",className:"bg-emerald-100 text-emerald-800 dark:bg-emerald-900/30 dark:text-emerald-300"},utlevert:{label:"Ferdig",className:"bg-emerald-100 text-emerald-800 dark:bg-emerald-900/30 dark:text-emerald-300"}}[i.status]||{label:i.status,className:"bg-muted text-muted-foreground"};return e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs(I,{variant:"outline",className:`text-[9px] ${D.className}`,children:[e.jsx(Ks,{className:"h-2.5 w-2.5 mr-0.5"}),D.label]}),e.jsx(b,{variant:"ghost",size:"sm",className:"h-5 text-[10px] px-1.5",onClick:ie=>{ie.stopPropagation(),ne(`/verksted-admin?order=${i.id}`)},children:"Åpne →"}),e.jsx(b,{variant:"ghost",size:"sm",className:"h-5 text-[10px] px-1 text-destructive hover:text-destructive hover:bg-destructive/10",disabled:$r===i.id,onClick:ie=>{ie.stopPropagation(),vs({id:i.id,orderId:t.order_id,orderNumber:i.order_number})},children:$r===i.id?e.jsx(rt,{className:"h-2.5 w-2.5 animate-spin"}):e.jsx(cn,{className:"h-2.5 w-2.5"})})]})}return e.jsxs(b,{variant:"outline",size:"sm",className:"h-6 text-[10px]",disabled:Sr===t.order_id,onClick:F=>{F.stopPropagation(),ia(t)},children:[Sr===t.order_id?e.jsx(rt,{className:"h-3 w-3 mr-1 animate-spin"}):e.jsx(Ks,{className:"h-3 w-3 mr-1"}),"Opprett"]})})()]})}),e.jsxs("div",{className:`p-2 rounded-md border ${l?l.is_question&&l.answer?"bg-green-50 border-green-200 dark:bg-green-900/20 dark:border-green-800":l.is_question?"bg-red-50 border-red-200 dark:bg-red-900/20 dark:border-red-800":"bg-yellow-50 border-yellow-200 dark:bg-yellow-900/20 dark:border-yellow-800":"bg-muted/20 border-border"}`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsxs("span",{className:`text-[11px] font-medium flex items-center gap-1 ${l?l.is_question&&l.answer?"text-green-700 dark:text-green-400":l.is_question?"text-red-700 dark:text-red-400":"text-yellow-700 dark:text-yellow-400":"text-foreground"}`,children:[e.jsx(Sa,{className:"h-3 w-3"}),l!=null&&l.is_question?"❓ Spørsmål":"Notat",(l==null?void 0:l.updated_at)&&e.jsxs("span",{className:"text-[9px] text-muted-foreground font-normal ml-1",children:["(",new Date(l.updated_at).toLocaleDateString("nb-NO",{day:"numeric",month:"short",hour:"2-digit",minute:"2-digit"}),")"]})]}),vt!==t.order_id&&e.jsxs("div",{className:"flex items-center gap-0.5",children:[l&&e.jsx(b,{variant:"ghost",size:"sm",className:`h-5 w-5 p-0 ${l.is_pinned?"text-primary":"text-muted-foreground"}`,title:l.is_pinned?"Fjern fra plukkliste":"Fest til plukkliste",onClick:i=>{i.stopPropagation(),na(t.order_id)},children:l.is_pinned?e.jsx(qa,{className:"h-3 w-3"}):e.jsx(Va,{className:"h-3 w-3"})}),e.jsx(b,{variant:"ghost",size:"sm",className:"h-5 text-[10px] px-1.5",onClick:i=>{i.stopPropagation(),it(t.order_id),Ct((l==null?void 0:l.note)||""),ct((l==null?void 0:l.is_question)||!1)},children:l?"Rediger":"Legg til"})]})]}),vt===t.order_id?e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(ts,{value:St,onChange:i=>Ct(i.target.value),placeholder:"Skriv et internt notat...",className:"min-h-[50px] text-xs",onClick:i=>i.stopPropagation()}),e.jsx("div",{className:"flex items-center gap-3",children:e.jsxs("label",{className:"flex items-center gap-1.5 text-[10px] cursor-pointer",onClick:i=>i.stopPropagation(),children:[e.jsx("input",{type:"checkbox",checked:It,onChange:i=>ct(i.target.checked),className:"rounded border-input accent-primary"}),"❓ Spørsmål"]})}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(b,{size:"sm",className:"h-6 text-[10px]",onClick:i=>{i.stopPropagation(),Gt(t.order_id,St,It)},children:"Lagre"}),e.jsx(b,{variant:"ghost",size:"sm",className:"h-6 text-[10px]",onClick:i=>{i.stopPropagation(),it(null)},children:"Avbryt"}),l&&e.jsx(b,{variant:"ghost",size:"sm",className:"h-6 text-[10px] text-destructive",onClick:i=>{i.stopPropagation(),Gt(t.order_id,"")},children:"Slett"})]})]}):l?e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-[11px] text-foreground whitespace-pre-wrap",children:l.note}),(((C=l.updated_employee)==null?void 0:C.full_name)||((de=l.created_employee)==null?void 0:de.full_name))&&e.jsxs("p",{className:"text-[9px] text-muted-foreground",children:["✏️ ",((Ps=l.updated_employee)==null?void 0:Ps.full_name)||((Xe=l.created_employee)==null?void 0:Xe.full_name)]}),l.is_question&&e.jsxs("div",{className:"mt-1.5 p-1.5 rounded border border-dashed bg-background",children:[e.jsx("span",{className:"text-[9px] font-medium text-muted-foreground uppercase tracking-wider",children:"Svar"}),fn===t.order_id?e.jsxs("div",{className:"space-y-1.5 mt-1",children:[e.jsx(ts,{value:rr,onChange:i=>Mt(i.target.value),placeholder:"Skriv ditt svar...",className:"min-h-[40px] text-xs",onClick:i=>i.stopPropagation()}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(b,{size:"sm",className:"h-5 text-[10px]",onClick:i=>{i.stopPropagation(),ra(t.order_id,rr)},children:"Lagre svar"}),e.jsx(b,{variant:"ghost",size:"sm",className:"h-5 text-[10px]",onClick:i=>{i.stopPropagation(),Rt(null)},children:"Avbryt"})]})]}):l.answer?e.jsxs("div",{className:"mt-0.5",children:[e.jsx("p",{className:"text-[11px] text-foreground whitespace-pre-wrap",children:l.answer}),e.jsx(b,{variant:"ghost",size:"sm",className:"h-4 text-[9px] mt-0.5 px-1",onClick:i=>{i.stopPropagation(),Rt(t.order_id),Mt(l.answer||"")},children:"Rediger svar"})]}):e.jsx(b,{variant:"outline",size:"sm",className:"h-5 text-[10px] mt-1",onClick:i=>{i.stopPropagation(),Rt(t.order_id),Mt("")},children:"Svar på spørsmål"})]})]}):e.jsx("p",{className:"text-[10px] text-muted-foreground italic",children:"Ingen notat"}),vt!==t.order_id&&e.jsx(Ya,{orderId:t.order_id})]})]})]})]}),document.body)]})},t.order_id)})]})]}),e.jsxs(rs,{value:"picklist",className:"space-y-4",children:[e.jsx("div",{className:"flex flex-col gap-2",children:e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3 flex-wrap",children:[e.jsxs(b,{size:"sm",onClick:fa,className:"text-xs sm:text-sm",children:[e.jsx(ns,{className:"h-4 w-4 mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"Skriv ut plukkliste"}),e.jsx("span",{className:"sm:hidden",children:"Skriv ut"}),f!=="all"?` (${f})`:""]}),e.jsxs("div",{className:"flex items-center gap-0.5 sm:gap-1 rounded-md border bg-muted/30 p-0.5",children:[e.jsx(b,{variant:Pe==="category"?"default":"ghost",size:"sm",className:"h-7 text-[11px] sm:text-xs px-2 sm:px-3",onClick:()=>{xs("category"),ot(new Set),Kt(!1)},children:"Kategori"}),e.jsx(b,{variant:Pe==="manufacturer"?"default":"ghost",size:"sm",className:"h-7 text-[11px] sm:text-xs px-2 sm:px-3",onClick:()=>{xs("manufacturer"),ot(new Set),Kt(!1)},children:"Produsent"}),e.jsx(b,{variant:Pe==="order"?"default":"ghost",size:"sm",className:"h-7 text-[11px] sm:text-xs px-2 sm:px-3",onClick:()=>{xs("order"),ot(new Set),Kt(!1)},children:"Ordre"})]}),e.jsxs("label",{className:"hidden sm:flex items-center gap-1.5 text-[11px] sm:text-xs cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:Ae,onChange:t=>gn(t.target.checked),className:"rounded"}),"Vis lager på utskrift"]}),e.jsxs(b,{variant:ds?"default":"outline",size:"sm",className:"h-7 text-[11px] sm:text-xs px-2 sm:px-3",onClick:()=>hn(t=>
259!t),children:[e.jsx(Re,{className:"h-3.5 w-3.5 sm:mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"Skjul ferdig"})]}),f==="all"&&e.jsx("p",{className:"text-[11px] sm:text-xs text-amber-600 dark:text-amber-400 font-medium",children:"⚠ Velg Stoa eller Sentrum for filter eller digital plukk"})]})}),ce.length>0&&Pe!=="order"&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(b,{variant:"outline",size:"sm",className:"h-7 text-xs px-3",onClick:()=>Kt(t=>!t),children:[ms?"Skjul filtre":`Vis filtre (${ce.length})`,e.jsx(Be,{className:`h-3 w-3 ml-1 transition-transform ${ms?"rotate-180":""}`})]}),Oe.size>0&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-xs text-muted-foreground",children:[Oe.size," valgt"]}),e.jsxs(b,{variant:"ghost",size:"sm",className:"h-6 text-xs px-2",onClick:()=>ot(new Set),children:[e.jsx(H,{className:"h-3 w-3 mr-1"}),"Nullstill"]})]})]}),ms&&e.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:ce.map(([t,s])=>{const n=Oe.has(t);return e.jsxs(I,{variant:n?"default":"outline",className:"cursor-pointer text-xs",onClick:()=>{ot(a=>{const r=new Set(a);return r.has(t)?r.delete(t):r.add(t),r})},children:[t," (",s.length,")"]},t)})})]}),e.jsxs("div",{className:"flex items-center gap-2 sm:gap-4 text-[10px] sm:text-[11px] text-muted-foreground flex-wrap",children:[e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(ye,{className:"h-3 w-3 text-amber-500"})," Blandet butikk"]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(ye,{className:"h-3 w-3 text-green-600"})," Blandet m/Stadion"]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(es,{className:"h-3 w-3 text-blue-500"})," K&H annen butikk"]}),e.jsxs(b,{variant:"outline",size:"sm",className:"h-6 text-[10px] sm:text-[11px] px-2 ml-auto",onClick:ga,children:[e.jsx(ns,{className:"h-3 w-3 mr-1"}),e.jsx("span",{className:"hidden sm:inline",children:"Skriv ut kun "}),"Splittordre"]})]}),ce.length===0?e.jsx(st,{children:e.jsxs(jt,{className:"py-12 text-center text-muted-foreground",children:[e.jsx(_e,{className:"h-12 w-12 mx-auto mb-3 opacity-50"}),e.jsx("p",{children:"Ingen varer i plukklisten"})]})}):ce.map(([t,s])=>{const n=f==="Sentrum"?_.PLUKKET_SENTRUM:_.PLUKKET_STOA,a=f!=="all"?s.filter(r=>N.has(v(r.order_id,r.article_no,r.size_name,r.color_name,n))).length:0;return e.jsxs(st,{children:[e.jsx(Ca,{className:"py-3 px-4",children:e.jsxs($a,{className:"text-sm font-bold flex items-center gap-2 flex-wrap",children:[e.jsxs("span",{className:"hidden sm:inline",children:[f!=="all"?`PLUKKLISTE ${f.toUpperCase()}`:"PLUKKLISTE"," - "]}),t,e.jsx(I,{variant:"secondary",className:"text-xs",children:s.length}),f!=="all"&&a>0&&e.jsxs(I,{variant:"default",className:"text-xs bg-emerald-600",children:[a,"/",s.length," plukket"]})]})}),e.jsxs(jt,{className:"px-4 pb-3 pt-0",children:[e.jsx("div",{className:"hidden sm:block",children:e.jsxs(tn,{children:[e.jsx(sn,{children:e.jsxs(Je,{children:[f!=="all"&&e.jsx(R,{className:"text-xs w-8",children:"✓"}),e.jsx(R,{className:"text-xs w-10"}),e.jsx(R,{className:"text-xs",children:"Varenr"}),e.jsx(R,{className:"text-xs",children:"Beskrivelse"}),e.jsx(R,{className:"text-xs",children:"EAN"}),e.jsx(R,{className:"text-xs text-center w-10",children:"Ant"}),e.jsx(R,{className:"text-xs text-center w-14",children:"Ordre"}),e.jsx(R,{className:"text-xs",children:"Sending"}),Ae&&e.jsx(R,{className:"text-xs",children:"Lager"}),e.jsx(R,{className:"text-xs w-8"})]})}),e.jsx(rn,{children:s.map((r,l)=>{const o=f==="Sentrum"?_.PLUKKET_SENTRUM:_.PLUKKET_STOA,x=f!=="all"&&Ie(r.order_id,r),d=N.has(v(r.order_id,r.article_no,r.size_name,r.color_name,_.IKKE_FUNNET)),m=`${r.order_id}|${r.article_no}|${r.size_name}|${r.color_name}|desktop-${l}`,p=kr.has(m);return e.jsxs(za.Fragment,{children:[e.jsxs(Je,{className:`${x?"opacity-40 line-through":""} ${d?"bg-red-50 dark:bg-red-900/10":""}`,children:[f!=="all"&&e.jsx(K,{className:"p-1",children:e.jsx(Wr,{item:r,actionType:o,size:"sm"})}),e.jsx(K,{className:"p-1 w-10",children:q.has(r.article_no)&&q.get(r.article_no)?e.jsx("img",{src:q.get(r.article_no),alt:r.article_name,className:"w-8 h-8 object-contain rounded border border-border 
259cursor-pointer hover:opacity-80 transition-opacity",onClick:()=>Ce(q.get(r.article_no))}):e.jsx("div",{className:"w-8 h-8 rounded border border-border flex items-center justify-center bg-muted",children:e.jsx(_e,{className:"h-3.5 w-3.5 text-muted-foreground"})})}),e.jsx(K,{className:"text-xs font-mono",children:r.article_no}),e.jsx(K,{className:"text-xs",children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[(()=>{const u=(r.shipping_method||"").toLowerCase();return r.warehouse==="Stoa"&&u.includes("klikk")&&u.includes("sentrum")||r.warehouse==="Sentrum"&&u.includes("klikk")&&u.includes("stoa")?e.jsx("span",{title:`Klikk & Hent: Varen hentes på ${u.includes("stoa")?"Stoa":"Sentrum"}, men ligger på ${r.warehouse}`,className:"text-blue-500 shrink-0",children:e.jsx(es,{className:"h-3 w-3"})}):ht.has(r.order_id)?e.jsx("span",{title:"Ordren har varer fra flere avdelinger inkl. Stadion",className:"text-green-600 shrink-0",children:e.jsx(ye,{className:"h-3 w-3"})}):Te.has(r.order_id)?e.jsx("span",{title:"Ordren har varer fra flere avdelinger",className:"text-amber-500 shrink-0",children:e.jsx(ye,{className:"h-3 w-3"})}):null})(),$e.get(r.article_no)?e.jsx("a",{href:$e.get(r.article_no),target:"_blank",rel:"noopener noreferrer",onClick:u=>u.stopPropagation(),className:"hover:underline hover:text-primary",children:r.article_name}):r.article_name,r.color_name?" "+r.color_name:"",r.size_name?" "+r.size_name:"",d&&e.jsx(I,{variant:"destructive",className:"text-[9px] px-1 py-0 h-3.5 shrink-0 ml-1",children:"❌ Ikke funnet"})]})}),e.jsx(K,{className:"text-xs font-mono text-muted-foreground",children:e.jsx(Vt,{item:r,eanKey:`pick-desktop-${l}`})}),e.jsx(K,{className:"text-xs text-center",children:r.units}),e.jsx(K,{className:"text-xs text-center font-mono",children:e.jsx("button",{className:`hover:underline cursor-pointer ${Ns.has(`o-${m}`)?"font-bold text-primary":"text-primary"}`,title:"Vis ordreinfo",onClick:()=>vr(`o-${m}`),children:r.order_id})}),e.jsx(K,{className:"text-xs text-muted-foreground whitespace-nowrap",children:(r.shipping_method||"").replace("Klikk & Hent - ","K&H ").replace("Elektronisk Levering","Elektr.")}),Ae&&e.jsx(K,{children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(I,{variant:"outline",className:`text-[10px] ${gt(O(r.order_id,r))}`,children:O(r.order_id,r)}),Wt(r.order_id,r)&&e.jsx("span",{className:"text-[9px] text-amber-600 dark:text-amber-400 font-medium",title:"Manuelt satt",children:"✎"})]})}),e.jsx(K,{className:"p-1",children:e.jsx("button",{className:"p-1 rounded hover:bg-muted transition-colors",onClick:()=>{Tr(m),p||ue([r.article_no])},children:e.jsx(Be,{className:`h-4 w-4 text-muted-foreground transition-transform ${p?"rotate-180":""}`})})})]}),Ns.has(`o-${m}`)&&e.jsx(Je,{className:"hover:bg-transparent",children:e.jsx(K,{colSpan:99,className:"p-0",children:Qr(r.order_id)})}),p&&e.jsx(Je,{className:"hover:bg-transparent",children:e.jsx(K,{colSpan:99,className:"p-0",children:e.jsxs("div",{className:"px-4 py-3 bg-muted/50 flex gap-6 items-start text-xs",children:[e.jsx("div",{className:"shrink-0",children:q.has(r.article_no)?e.jsx("img",{src:q.get(r.article_no),alt:r.article_name,className:"w-16 h-16 object-contain rounded border border-border cursor-pointer hover:opacity-80 transition-opacity",onClick:()=>Ce(q.get(r.article_no))}):e.jsx("div",{className:"w-16 h-16 rounded border border-border flex items-center justify-center bg-muted",children:e.jsx(_e,{className:"h-6 w-6 text-muted-foreground"})})}),e.jsxs("div",{className:"grid grid-cols-2 gap-x-8 gap-y-1 flex-1",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Saldo Stoa"}),e.jsx("span",{className:"font-mono ml-4",children:r.available_stoa??"–"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Saldo Sentrum"}),e.jsx("span",{className:"font-mono ml-4",children:r.available_sentrum??"–"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Beløp"}),e.jsxs("span",{className:"font-mono ml-4",children:[r.gross_amount.toLocaleStr
259ing("nb-NO",{minimumFractionDigits:0})," kr"]})]}),r.manufacturer_name&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Produsent"}),e.jsx("span",{className:"ml-4",children:r.manufacturer_name})]})]}),e.jsx("div",{className:"flex-1 min-w-0",children:Gr(r)}),e.jsx("div",{className:"shrink-0",children:e.jsxs("button",{onClick:()=>re(r.order_id,r.article_no,r.size_name,r.color_name,_.IKKE_FUNNET),className:`inline-flex items-center gap-1 px-3 py-1.5 rounded text-xs font-medium border transition-all ${d?"bg-red-200 text-red-900 border-red-400 dark:bg-red-900/50 dark:text-red-200 dark:border-red-600":"bg-muted/50 text-muted-foreground border-border hover:bg-red-50 dark:hover:bg-red-900/20"}`,children:[e.jsx(H,{className:"h-3 w-3"}),d?"Fjern «Finner ikke»":"Finner ikke"]})})]})})})]},l)})})]})}),e.jsx("div",{className:"sm:hidden divide-y divide-border",children:s.map((r,l)=>{var u;const o=f==="Sentrum"?_.PLUKKET_SENTRUM:_.PLUKKET_STOA,x=f!=="all"&&Ie(r.order_id,r),d=N.has(v(r.order_id,r.article_no,r.size_name,r.color_name,_.IKKE_FUNNET)),m=`${r.order_id}|${r.article_no}|${r.size_name}|${r.color_name}|${l}`,p=kr.has(m);return e.jsxs("div",{className:`py-2.5 ${x?"opacity-40":""} ${d?"bg-red-50 dark:bg-red-900/10":""}`,children:[e.jsxs("div",{className:"flex items-start gap-2",children:[f!=="all"&&e.jsx(Wr,{item:r,actionType:o,size:"lg"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[(()=>{const h=(r.shipping_method||"").toLowerCase();return r.warehouse==="Stoa"&&h.includes("klikk")&&h.includes("sentrum")||r.warehouse==="Sentrum"&&h.includes("klikk")&&h.includes("stoa")?e.jsx(es,{className:"h-3 w-3 text-blue-500 shrink-0"}):ht.has(r.order_id)?e.jsx(ye,{className:"h-3 w-3 text-green-600 shrink-0"}):Te.has(r.order_id)?e.jsx(ye,{className:"h-3 w-3 text-amber-500 shrink-0"}):null})(),e.jsx("span",{className:`text-xs font-medium truncate ${x?"line-through":""}`,children:$e.get(r.article_no)?e.jsx("a",{href:$e.get(r.article_no),target:"_blank",rel:"noopener noreferrer",onClick:h=>h.stopPropagation(),className:"hover:underline hover:text-primary",children:r.article_name}):r.article_name}),d&&e.jsx(I,{variant:"destructive",className:"text-[9px] px-1 py-0 h-3.5 shrink-0",children:"❌ Ikke funnet"}),Wt(r.order_id,r)&&e.jsx("span",{className:"text-[9px] text-amber-600 dark:text-amber-400 font-medium shrink-0",title:"Manuelt satt lager",children:"✎ manuelt"})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5 text-[11px]",children:[r.color_name&&e.jsx("span",{className:"text-muted-foreground",children:r.color_name}),r.size_name&&e.jsx(I,{variant:"outline",className:"text-[10px] px-1.5 py-0 h-4 font-semibold",children:r.size_name}),e.jsxs("span",{className:`font-bold ${r.units>1?"text-destructive":""}`,children:["×",r.units]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5 text-[10px] font-mono text-muted-foreground",children:[(((u=r.ean_codes)==null?void 0:u.length)>0||r.ean_code)&&e.jsx(Vt,{item:r,eanKey:`pick-mobile-${l}`}),r.shipping_method&&e.jsx("span",{className:"font-sans opacity-70",children:r.shipping_method.replace("Klikk & Hent - ","K&H ").replace("Elektronisk Levering","Elektr.")})]})]}),e.jsx("div",{className:"shrink-0 mt-0.5",children:q.has(r.article_no)&&q.get(r.article_no)?e.jsx("img",{src:q.get(r.article_no),alt:r.article_name,className:"w-10 h-10 object-contain rounded border border-border cursor-pointer hover:opacity-80 transition-opacity",onClick:()=>Ce(q.get(r.article_no))}):mt.has(r.article_no)?e.jsx("div",{className:"w-10 h-10 rounded border border-border flex items-center justify-center bg-muted",children:e.jsx(rt,{className:"h-4 w-4 animate-spin text-muted-foreground"})}):e.jsx("div",{className:"w-10 h-10 rounded border border-border flex items-center justify-center bg-muted",children:e.jsx(_e,{className:"h-4 w-4 text-muted-foreground"})})}),e.jsx("button",{className:"shrink-0 p-1 rounded hover:bg-muted transition-colors mt-0.5",onClick:()=>{Tr(m),p||ue([r.article_no])},children:e.jsx(Be,{className:`h-4 w-4 text-muted-foreground transition-transform ${p?"rotate-180":""}`})})]}),p&&e.jsxs("div",{className:"mt-2 ml-9 space-y-1 text-[11px] bg-muted/50 rounded-md p-2",children:[e.jsx("div",{className:"flex justify-center pb-1",children:q.has(r.article_no)?e.jsx("img",{src:q.get(r.article_no),alt:r.article_name,className:"w-16 h-16 object-contain rounded border border-border 
259cursor-pointer hover:opacity-80 transition-opacity",onClick:()=>Ce(q.get(r.article_no))}):e.jsx("div",{className:"w-16 h-16 rounded border border-border flex items-center justify-center bg-muted",children:e.jsx(_e,{className:"h-6 w-6 text-muted-foreground"})})}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Ordrenr"}),e.jsx("button",{className:"text-primary font-mono hover:underline",onClick:()=>vr(`m-${m}`),children:r.order_id})]}),Ns.has(`m-${m}`)&&e.jsx("div",{className:"-mx-2 mt-1",children:Qr(r.order_id)}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Varenr"}),e.jsx("span",{className:"font-mono",children:r.article_no})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Saldo Stoa"}),e.jsx("span",{className:"font-mono",children:r.available_stoa??"–"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Saldo Sentrum"}),e.jsx("span",{className:"font-mono",children:r.available_sentrum??"–"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Beløp"}),e.jsxs("span",{className:"font-mono",children:[r.gross_amount.toLocaleString("nb-NO",{minimumFractionDigits:0})," kr"]})]}),r.manufacturer_name&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Produsent"}),e.jsx("span",{children:r.manufacturer_name})]}),Gr(r),e.jsx("div",{className:"pt-1 border-t border-border mt-1",children:e.jsxs("button",{onClick:()=>re(r.order_id,r.article_no,r.size_name,r.color_name,_.IKKE_FUNNET),className:`inline-flex items-center gap-1 px-2.5 py-1 rounded text-[11px] font-medium border transition-all w-full justify-center ${d?"bg-red-200 text-red-900 border-red-400 dark:bg-red-900/50 dark:text-red-200 dark:border-red-600":"bg-muted/50 text-muted-foreground border-border hover:bg-red-50 dark:hover:bg-red-900/20"}`,children:[e.jsx(H,{className:"h-3 w-3"}),d?"Fjern «Finner ikke»":"Finner ikke vare"]})})]})]},l)})})]})]},t)})]})]})]}),e.jsx(Is,{open:On,onOpenChange:bs,children:e.jsxs(Rs,{children:[e.jsxs(Ms,{children:[e.jsx(Fs,{children:"Skriv ut tilhørende ordre?"}),e.jsxs(Ds,{children:["Plukklisten inneholder varer fra ",ks.size," ordre. Vil du skrive ut alle ordrene også?"]})]}),e.jsxs(Us,{children:[e.jsx(Bs,{children:"Nei, bare plukkliste"}),e.jsxs(Vs,{onClick:_a,children:[e.jsx(ns,{className:"h-4 w-4 mr-1"}),"Skriv ut ",ks.size," ordre"]})]})]})}),e.jsx(Is,{open:!!le,onOpenChange:t=>!t&&Bt(null),children:e.jsxs(Rs,{children:[e.jsxs(Ms,{children:[e.jsxs(Fs,{className:"flex items-center gap-2",children:[e.jsx(qs,{className:"h-5 w-5"}),"Ordre med internt notat"]}),e.jsx(Ds,{asChild:!0,children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{children:[(le==null?void 0:le.ordersWithNotes.length)===1?"1 ordre har":`${le==null?void 0:le.ordersWithNotes.length} ordre har`," internt notat. Vil du inkludere notatet på utskriften?"]}),e.jsx("div",{className:"max-h-32 overflow-y-auto space-y-1",children:le==null?void 0:le.ordersWithNotes.map(t=>{const s=V.get(t.order_id);return e.jsxs("div",{className:"text-xs bg-muted p-2 rounded",children:[e.jsxs("span",{className:"font-semibold",children:["#",t.order_id,":"]})," ",s==null?void 0:s.note]},t.order_id)})})]})})]}),e.jsxs(Us,{children:[e.jsx(Bs,{onClick:()=>{const t=le;Bt(null),t&&Es(t.orders,!1)},children:"Uten notat"}),e.jsxs(Vs,{onClick:()=>{const t=le;Bt(null),t&&Es(t.orders,!0)},children:[e.jsx(qs,{className:"h-4 w-4 mr-1"}),"Med notat"]})]})]})}),e.jsx(Ga,{open:Kn,onOpenChange:t=>{Ut(t),t||Ts(null)},initialOrderId:xa}),e.jsx(ls,{open:!!ws,onOpenChange:t=>!t&&Ce(null),children:e.jsx(is,{className:"max-w-lg p-2",children:ws&&e.jsx("img",{src:ws,alt:"Produktbilde",className:"w-full h-auto object-contain rounded"})})}),X&&e.jsx("div",{className:"fixed bottom-6 right-6 z-50",children:e.jsxs(b,{size:"sm",variant:"default",className:"shadow-xl flex items-center gap-1.5 rounded-full px-4 py-2 h-auto",onClick:()=>ne(`/support?ticket=${X}`),children:[e.jsx(on,{className:"h-4 w-4"}),"Tilbake til ticket"]})}),e.jsx(Is,{open:!!Ye,onOpenChange:t=>{t||vs(null)},children:e.jsxs(Rs,{children:[e.jsxs(Ms,{children:[e.jsxs(Fs,{className:"flex items-center gap-2",children:[e.jsx(cn,{className:"h-5 w-5 text-destructive"}),"Slett verkstedordre"]}),e.jsxs(Ds,{children:["Er du sikker på at du vil slette verkstedordre ",e.jsxs("strong",{children:["#",Ye==null?void 0:Ye.orderNumber]}),"? Denne handlingen kan ikke angres."]})]}),e.jsxs(Us,{children:[e.jsx(Bs,{children:"Avbryt"}),e.jsx(Vs,{className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",onClick:async()=>
259{if(!Ye)return;const{id:t,orderId:s}=Ye;zr(t),vs(null);const{error:n}=await j.from("workshop_orders").delete().eq("id",t);n?w.error("Kunne ikke slette verkstedordre"):(ys(a=>{const r=new Map(a);return r.delete(s),r}),w.success("Verkstedordre slettet")),zr(null)},children:"Slett"})]})]})})]})}export{bl 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.