1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[89239],{11620:(e,t,a)=>{a.r(t),a.d(t,{default:()=>o});var r=a(95155),s=a(12115),l=a(81477),n=a(60529),i=a(89239),d=a(20280),c=a(93089),m=a(9005);function u(e){return e&&"string"==typeof e?Array.from(new Set(e.split(",").map(e=>e.trim()).filter(e=>e.length>0))):[]}function o({value:e,onChange:t,currentProductArtikelnummer:a,currentProductUuid:h,onFieldTouched:p}){let[x,f]=(0,s.useState)(()=>u(e)),[k,g]=(0,s.useState)(""),[j,N]=(0,s.useState)([]),[v,b]=(0,s.useState)(!1),[y,w]=(0,s.useState)({}),{toast:S}=(0,d.dj)();(0,s.useEffect)(()=>{let a=u(e);f(a);let r=a.join(",");r!==e.trim()&&t(r)},[e,t]),(0,s.useEffect)(()=>{let e=x.filter(e=>!y[e]);if(0===e.length)return;let t=!1;return Promise.all(e.map(e=>fetch(`/api/admin/products/search?q=${encodeURIComponent(e)}&limit=1&showAll=true`).then(e=>e.json()).then(t=>({art:e,name:t.products?.[0]?.name})))).then(e=>{t||w(t=>({...t,...Object.fromEntries(e.filter(e=>null!=e.name).map(e=>[e.art,e.name]))}))}),()=>{t=!0}},[x.join(",")]);let C=(0,s.useCallback)(e=>{t(e.join(","))},[t]),E=(0,s.useCallback)(async()=>{let e=k.trim();if(!e)return void N([]);b(!0);try{let t=await fetch(`/api/admin/products/search?q=${encodeURIComponent(e)}&limit=20&showAll=true`),a=await t.json();if(!t.ok)throw Error(a.error||"S\xf6kning misslyckades");let r=a.products||[];N(r)}catch(e){console.error("Search error:",e),S({title:"S\xf6kning misslyckades",variant:"destructive"}),N([])}finally{b(!1)}},[k,S]);return(0,s.useEffect)(()=>{let e=setTimeout(()=>{E()},300);return()=>clearTimeout(e)},[k,E]),(0,r.jsxs)(l.Zp,{className:"admin-card",children:[(0,r.jsxs)(l.aR,{className:"admin-card-header",children:[(0,r.jsxs)(l.ZB,{className:"admin-card-title",children:[(0,r.jsx)("div",{className:"admin-card-indicator admin-card-indicator-blue"}),"Passar bra till"]}),(0,r.jsx)(l.BT,{className:"admin-card-description",children:"Merk\xf6psprodukter (tillbeh\xf6r) som visas p\xe5 produktsidan"})]}),(0,r.jsxs)(l.Wu,{className:"admin-card-content space-y-4",children:[(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)("label",{className:"text-sm font-medium",children:"S\xf6k och l\xe4gg till produkt"}),(0,r.jsx)("div",{className:"flex gap-2",children:(0,r.jsx)(n.p,{placeholder:"S\xf6k p\xe5 namn eller artikelnummer...",value:k,onChange:e=>g(e.target.value),className:"admin-input flex-1"})}),k.trim()&&(0,r.jsx)("div",{className:"border rounded-md p-2 max-h-48 overflow-y-auto space-y-1",children:v?(0,r.jsx)("p",{className:"text-sm text-muted-foreground",children:"S\xf6ker..."}):0===j.length?(0,r.jsx)("p",{className:"text-sm text-muted-foreground",children:"Inga produkter hittades"}):j.map(e=>{let t=a&&e.artikelnummer===a||h&&e.product_uuid===h,s=x.includes(e.artikelnummer);return(0,r.jsxs)("div",{className:"flex items-center justify-between gap-2 py-1.5 px-2 rounded hover:bg-muted/50 text-sm",children:[(0,r.jsxs)("span",{className:"truncate flex-1",children:[e.name," (",e.artikelnummer,")"]}),(0,r.jsx)(i.$,{type:"button",size:"sm",variant:"outline",className:"shrink-0 h-7",disabled:t||s,onClick:()=>((e,t)=>{if(x.includes(e))return;if(a&&e===a)return void S({title:"Kan inte l\xe4gga till",description:"Du kan inte l\xe4gga till den aktuella produkten som tillbeh\xf6r.",variant:"destructive"});let r=[...x,e];f(r),w(a=>({...a,[e]:t})),C(r),p?.()})(e.artikelnummer,e.name),children:s?"Tillagd":t?"Denna produkt":"L\xe4gg till"})]},e.product_uuid)})})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)("label",{className:"text-sm font-medium",children:["Valda tillbeh\xf6r (",x.length,")"]}),0===x.length?(0,r.jsx)("p",{className:"text-sm text-muted-foreground",children:"Inga tillbeh\xf6r valda. S\xf6k och l\xe4gg till produkter ovan."}):(0,r.jsx)("ul",{className:"border rounded-md divide-y max-h-40 overflow-y-auto",children:x.map(e=>(0,r.jsxs)("li",{className:"flex items-center justify-between gap-2 py-2 px-3 text-sm",children:[(0,r.jsxs)("span",{className:"flex items-center gap-2 truncate",children:[(0,r.jsx)(c.A,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),y[e]?`${e} â ${y[e]}`:e]}),(0,r.jsx)(i.$,{type:"button",size:"sm",variant:"ghost",className:"shrink-0 h-7 w-7 p-0 text-muted-foreground hover:text-destructive",onClick:()=>{let t;f(t=x.filter(t=>t!==e)),C(t),p?.()},"aria-label":"Ta bort",children:(0,r.jsx)(m.A,{className:"h-4 w-4"})})]},e))})]})]})]})}}}]);
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.