1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/useEANCodeGenerator-_Y0Gajv4.js","assets/react-vendor-CShGlGts.js","assets/index-BYC0bmF9.js","assets/query-BUBuIGkW.js","assets/shared-utils--gW9Kwo0.js","assets/supabase-C0joAID3.js","assets/index-DU5zMUe_.css","assets/JsBarcode-dS2ZyPj7.js"])))=>i.map(i=>d[i]); 2import{b as Fs}from"./shared-utils--gW9Kwo0.js";import{r as c,j as e,n as Ls,u as Ws}from"./react-vendor-CShGlGts.js";import{I as P,B as j,L as he,z as oe,aM as Ts,aN as Bs,aQ as Yt,aP as Ms,a9 as Os,s as N,au as it,aw as at,ax as ot,ay as lt,bL as us,D as Xt,ao as Vs,bl as ct,aY as Gs,aa as es,S as Y,m as X,n as ee,o as te,p as q,bq as tt,da as je,a_ as ts,cd as st,bt as ss,Y as ns,aI as nt,aJ as Fe,bo as Ks,dQ as Le,h as Rs,i as Us,j as rs,a7 as me,k as is,T as as,b as os,c as We,d as I,e as ls,f as F,C as Zs,a as Qs,E as O,A as Hs,$ as Js,a0 as Ys,a1 as Xs,a2 as en,a3 as tn,a4 as sn,a5 as nn,a6 as rn}from"./index-BYC0bmF9.js";import{r as an,l as on}from"./scanCodes-DXzQqdk2.js";import{S as ln}from"./scan-line-UtGIi4fW.js";import{I as cn}from"./InventoryItemCombobox-BbiokzfZ.js";import{f as V}from"./numberFormatting-DAd5U-rK.js";import{u as dn}from"./useEANCodeGenerator-_Y0Gajv4.js";import{i as un}from"./inventoryService-C2zEDV-P.js";import{M as cs}from"./minus-BYpLvWa3.js";import{T as mn}from"./trending-up-D5t3w5te.js";import{T as hn}from"./trending-down-CxFpQLrE.js";import{C as xn}from"./CreateItemTabDialog-BEyo7hvT.js";import{S as rt}from"./square-pen-C1ki5aDA.js";import{S as Te}from"./square-check-big-D8AY_Ej2.js";import{B as pn}from"./barcode-DCqEiE4r.js";import"./query-BUBuIGkW.js";import"./supabase-C0joAID3.js";import"./slaughterService-BQrS1Jze.js";import"./JsBarcode-dS2ZyPj7.js";import"./units-ByzP6LLv.js";import"./inventoryItemAvailableUnitsService-LPpIyqFp.js";function gn({onResolved:p,placeholder:y,className:f}){const[v,E]=c.useState(""),[b,u]=c.useState(!1),C=c.useRef(null),w=async()=>{const _=v.trim();if(!(!_||b)){u(!0);try{const g=await an(_);g?p(g,_):oe.error(`Code ${_} ist nicht hinterlegt.`)}catch(g){oe.error(g instanceof Error?g.message:"Code konnte nicht geprüft werden.")}finally{u(!1),E(""),C.current?.focus()}}};return e.jsxs("div",{className:`relative ${f??""}`,children:[e.jsx(ln,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(P,{ref:C,value:v,onChange:_=>E(_.target.value),onKeyDown:_=>{_.key==="Enter"&&(_.preventDefault(),w())},placeholder:y??"Code scannen (ARâ¦, SLâ¦, EAN)",className:"pl-10 pr-24 font-mono",inputMode:"text",autoComplete:"off"}),e.jsx(j,{type:"button",size:"sm",variant:"secondary",className:"absolute right-1 top-1/2 -translate-y-1/2",disabled:b||!v.trim(),onClick:()=>void w(),children:b?e.jsx(he,{className:"h-4 w-4 animate-spin"}):"Suchen"})]})}function se(p,y,f,v,E){if(!y||y<=0||!p||p<=0)return 0;const b=E?.toLowerCase()||"",u=v?.toLowerCase()||"";if(["flasche","stk","stück","stueck","pkg","packung","dose","karton","kiste"].includes(b))return p*y;if(f&&f>0){let w=p,_=f;return b==="g"&&u==="kg"?_=f*1e3:b==="kg"&&u==="g"&&(w=p*1e3),b==="ml"&&u==="l"?_=f*1e3:b==="l"&&u==="ml"&&(w=p*1e3),w/_*y}return p*y}function ds(p,y,f,v,E){const b=se(p,y,f,v,E);return b<=0?"-":`${b.toFixed(2)} â¬`}function _n(p,y,f,v,E,b){const u=f||0,C=b||"Stk",w=!!(v&&v>0);let _=y,g="direct";const A=b?.toLowerCase()||"",L=E?.toLowerCase()||"";if(!["flasche","stk","stück","stueck","pkg","packung","dose","karton","kiste"].includes(A)&&w&&v&&v>0){let m=y,S=v;A==="g"&&L==="kg"?S=v*1e3:A==="kg"&&L==="g"&&(m=y*1e3),A==="ml"&&L==="l"?S=v*1e3:A==="l"&&L==="ml"&&(m=y*1e3),_=m/S,g="container"}const K=se(y,f,v,E,b);return{itemName:p,quantity:y,unit:C,pricePerQuantity:v||null,pricePerUnit:E||null,unitPrice:u,containerCount:_,totalValue:K,formula:g,hasPriceReference:w}}function fn({itemName:p,quantity:y,currentPrice:f,pricePerQuantity:v,pricePerUnit:E,itemUnit:b,category:u,storageLocation:C,barcode:w,eanCode:_}){const g=_n(p,y,f,v,E,b);return e.jsxs(Ts,{children:[e.jsx(Bs,{asChild:!0,children:e.jsx(j,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 hover:bg-primary/10",children:e.jsx(Yt,{className:"h-4 w-4 text-muted-foreground"})})}),e.jsx(Ms,{className:"w-80",align:"end",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 font-medium text-sm",children:[e.jsx(Yt,{className:"h-4 w-4 text-primary"}),"Berechnungsdetails"]}
2),e.jsx("div",{className:"text-sm font-medium text-foreground truncate",title:g.itemName,children:g.itemName}),e.jsx("div",{className:"bg-muted/50 rounded-md p-3 space-y-2 text-sm font-mono",children:g.hasPriceReference?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Menge"}),e.jsxs("span",{children:[g.quantity," ",g.unit]})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"÷ Preis-Bezug"}),e.jsxs("span",{children:[g.pricePerQuantity," ",g.pricePerUnit]})]}),e.jsxs("div",{className:"flex justify-between border-t pt-2",children:[e.jsx("span",{className:"text-muted-foreground",children:"= Anzahl"}),e.jsxs("span",{children:[g.containerCount.toFixed(2)," Einh."]})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"à Einzelpreis"}),e.jsxs("span",{children:[g.unitPrice.toFixed(2)," â¬"]})]}),e.jsxs("div",{className:"flex justify-between border-t pt-2 font-bold text-foreground",children:[e.jsx("span",{children:"= Gesamtwert"}),e.jsxs("span",{children:[g.totalValue.toFixed(2)," â¬"]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 text-amber-600 dark:text-amber-400 mb-2",children:[e.jsx(Os,{className:"h-4 w-4"}),e.jsx("span",{className:"text-xs",children:"Kein Preis-Bezug definiert"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Menge"}),e.jsxs("span",{children:[g.quantity," ",g.unit]})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"à Einzelpreis"}),e.jsxs("span",{children:[g.unitPrice.toFixed(2)," â¬"]})]}),e.jsxs("div",{className:"flex justify-between border-t pt-2 font-bold text-foreground",children:[e.jsx("span",{children:"= Gesamtwert"}),e.jsxs("span",{children:[g.totalValue.toFixed(2)," â¬"]})]})]})}),e.jsxs("div",{className:"border-t pt-3 space-y-1.5 text-xs text-muted-foreground",children:[e.jsx("div",{className:"font-medium text-foreground mb-2",children:"Weitere Felder:"}),u&&e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:"Kategorie"}),e.jsx("span",{className:"text-foreground",children:u})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:"Lagerort"}
2),e.jsx("span",{className:"text-foreground",children:C||"-"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:"Barcode"}),e.jsx("span",{className:"text-foreground font-mono",children:w||"-"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:"EAN-Code"}),e.jsx("span",{className:"text-foreground font-mono",children:_||"-"})]})]})]})})]})}const jn=()=>{const[p,y]=c.useState(!1),[f,v]=c.useState([]);return{isLoading:p,matches:f,matchPrices:async(u,C)=>{y(!0);try{let w=N.from("inventory_items").select("id, name, current_price, unit, department_tags");u&&(w=w.contains("department_tags",[u]));const{data:_,error:g}=await w;if(g)throw g;let A=N.from("historical_inventory_data").select("article_name, unit_price, unit, source_file").not("unit_price","is",null).gt("unit_price",0);C&&(A=A.eq("source_file",C));const{data:L,error:ne}=await A;if(ne)throw ne;const W=[];return _?.forEach(K=>{const m=K.name.toLowerCase().trim(),S=L?.find(Q=>Q.article_name.toLowerCase().trim()===m);S&&W.push({itemId:K.id,currentName:K.name,oldPrice:K.current_price,historicalName:S.article_name,newPrice:S.unit_price,unit:S.unit||K.unit})}),v(W),oe.success(`${W.length} Artikel mit Preisen gefunden`),W}catch(w){return console.error("Error matching prices:",w),oe.error("Fehler beim Abgleichen der Preise"),[]}finally{y(!1)}},importPrices:async u=>{y(!0);try{const C=u.map(g=>({id:g.itemId,current_price:g.newPrice}));let w=0,_=0;for(const g of C){const{error:A}=await N.from("inventory_items").update({current_price:g.current_price}).eq("id",g.id);A?(console.error("Error updating item:",A),_++):w++}return w>0&&oe.success(`${w} Preise erfolgreich importiert`),_>0&&oe.error(`${_} Fehler beim Importieren`),{successCount:w,errorCount:_}}catch(C){return console.error("Error importing prices:",C),oe.error("Fehler beim Importieren der Preise"),{successCount:0,errorCount:u.length}}finally{y(!1)}}}},vn=({open:p,onOpenChange:y,departmentTag:f,sourceFile:v,onImportComplete:E})=>{const{isLoading:b,matches:u,matchPrices:C,importPrices:w}=jn(),[_,g]=c.useState(new Set);c.useEffect(()=>{p&&C(f,v)},[p,f,v]),c.useEffect(()=>{u.length>0&&g(new Set(u.map(m=>m.itemId)))},[u]);const A=m=>{const S=new Set(_);S.has(m)?S.delete(m):S.add(m),g(S)},L=()=>{_.size===u.length?g(new Set):g(new Set(u.map(m=>m.itemId)))},ne=async()=>{const m=u.filter(Q=>_.has(Q.itemId));(await w(m)).successCount>0&&(y(!1),E?.())},W=(m,S)=>m===null||m===0?e.jsx(cs,{className:"h-4 w-4 text-muted-foreground"}):S>m?e.jsx(mn,{className:"h-4 w-4 text-green-600"}):S<m?e.jsx(hn,{className:"h-4 w-4 text-red-600"}):e.jsx(cs,{className:"h-4 w-4 text-muted-foreground"}),K=(m,S)=>{if(m===null||m===0)return"Neu";const Q=S-m;return`${Q>0?"+":""}${V(Q)} â¬`};return e.jsx(it,{open:p,onOpenChange:y,children:e.jsxs(at,{className:"max-w-4xl max-h-[80vh]",children:[e.jsxs(ot,{children:[e.jsx(lt,{children:"Preise aus Historie importieren"}),e.jsx(us,{children:b?"Suche nach Preisen...":`${u.length} Artikel mit historischen Preisen gefunden. Wählen Sie die Artikel aus, deren Preise aktualisiert werden sollen.`})]}),b?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(he,{className:"h-8 w-8 animate-spin text-primary"})}):u.length===0?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"Keine Artikel mit historischen Preisen gefunden."}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 pb-4 border-b",children:[e.jsx(Xt,{id:"select-all",checked:_.size===u.length,onCheckedChange:L}),e.jsxs("label",{htmlFor:"select-all",className:"text-sm font-medium cursor-pointer",children:["Alle auswählen (",_.size," von ",u.length,")"]})]}),e.jsx(Vs,{className:"h-[400px] pr-4",children:e.jsx("div",{className:"space-y-2",children:u.map(m=>e.jsxs("div",{className:"flex items-center gap-4 p-3 rounded-lg border bg-card hover:bg-accent/50 transition-colors",children:[e.jsx(Xt,{id:m.itemId,checked:_.has(m.itemId),onCheckedChange:()=>A(m.itemId)}),e.jsxs("div",{className:"flex-1 grid grid-cols-4 gap-4 items-center",children:[e.jsxs("div",{className:"col-span-2",children:[e.jsx("label",{htmlFor:m.itemId,className:"font-medium cursor-pointer",children:m.currentName}),e.jsx("p",{className:"text-xs text-muted-foreground",children:m.unit})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:m.oldPrice?`${V(m.oldPrice)} â¬`:"-"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Alt"})]}),e.jsxs("div",{className:"text-right",children:[e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[W(m.oldPrice,m.newPrice),e.jsxs("p",{className:"font-semibold text-primary",children:[V(m.newPrice)," â¬"]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:K(m.oldPrice,m.newPrice)})]})]})]},m.itemId))})})]}),e.jsxs(ct,{children:[e.jsx(j,{variant:"outline",onClick:()=>y(!1),children:"Abbrechen"}),e.jsx(j,{onClick:ne,disabled:b||_.size===0,children:b?e.jsxs(e.Fragment,{children:[e.jsx(he,{className:"mr-2 h-4 w-4 animate-spin"}),"Importiere..."]}):`${_.size} Preise importieren`})]})]})})};function Gn(){const{sessionId:p}=Ls(),y=Ws(),[f,v]=c.useState([]),[E,b]=c.useState([]),[u,C]=c.useState([]),[w,_]=c.useState([]),[g,A]=c.useState(!1),[L,ne]=c.useState(""),[W,K]=c.useState(""),[m,S]=c.useState(""),[Q,ve]=c.useState(!1),[Be,ms]=c.useState(""),[T,hs]=c.useState(null),[$,xs]=c.useState(null),[ps,xe]=c.useState(!1),[R,ye]=c.useState(null),[pe,be]=c.useState(null),[gs,Me]=c.useState(!1),[Ne,we]=c.useState(0),[B,Oe]=c.useState(""),[Ve,Ge]=c.useState(""),[Ce,ke]=c.useState(""),[dt,ut]=c.useState(""),[mt,Ke]=c.useState(""),[Se,Re]=c.useState(null),[ht,xt]=c.useState(null),[pt,gt]=c.useState(""),[_t,ft]=c.useState(""),[jt,vt]=c.useState(""),[U,yt]=c.useState("counted_at"),[qe,yn]=c.useState("desc");c.useState(!1);const{generateCode:_s,printLabel:fs,isPrinting:bt,canvasRef:js}=dn(),{toast:k}=Gs(),[z,vs]=c.useState(!1),[d,Ue]=c.useState({}),[H,Ze]=c.useState({}),[Qe,Ee]=c.useState(null),[Nt,wt]=c.useState({}),[Pe,ys]=c.useState([]),[le,bs]=c.useState(!1),[ce,Ns]=c.useState(!1),[ws,$e]=c.useState(!1),Z=50,[re,He]=c.useState(1),[ie,Je]=c.useState(1),[de,Cs]=c.useState("wine"),[ge,Ct]=c.useState(!1),[_e,kt]=c.useState(!1),[St,qt]=c.useState(!1),[Et,Pt]=c.useState(!1),[$t,ks]=c.useState(!1),[At,zt]=c.useState(null),[Dt,It]=c.useState(null),Ae=c.useMemo(()=>{const t=Be;return["kitchen","service","housekeeping","reception"].includes(t)?t:null},[Be]);c.useEffect(()=>{p&&Ft()}
2,[p]),c.useEffect(()=>{!$t||!p||(de==="wine"&&!_e&&!Et?qs():de==="items"&&!ge&&!St&&Ss())},[de,$t,_e,ge,p]),c.useEffect(()=>{let t=f,s=u;if(le&&(t=f.filter(i=>!i.is_processed),s=u.filter(i=>!i.is_processed)),ce&&(t=t.filter(i=>!i.inventory_items?.current_price||i.inventory_items.current_price===0),s=s.filter(i=>!i.wine_menu?.current_purchase_price||i.wine_menu.current_purchase_price===0)),m.trim()){const i=m.toLowerCase(),l=t.map(n=>{let r=0;const o=n.inventory_items?.name?.toLowerCase()||"",a=n.inventory_items?.barcode?.toLowerCase()||"",x=n.inventory_items?.ean_code?.toLowerCase()||"",J=n.inventory_items?.internal_barcode?.toLowerCase()||"",ue=n.notes?.toLowerCase()||"";return o===i&&(r+=100),a===i&&(r+=100),x===i&&(r+=100),J===i&&(r+=100),o.startsWith(i)&&(r+=50),a.startsWith(i)&&(r+=40),x.startsWith(i)&&(r+=40),J.startsWith(i)&&(r+=40),o.includes(i)&&(r+=20),a.includes(i)&&(r+=10),x.includes(i)&&(r+=10),J.includes(i)&&(r+=10),ue.includes(i)&&(r+=5),{item:n,score:r}}).filter(({score:n})=>n>0).sort((n,r)=>r.score-n.score).map(({item:n})=>n);b(l);const h=s.map(n=>{let r=0;const o=n.wine_menu?.name_de?.toLowerCase()||"",a=n.wine_menu?.producer?.toLowerCase()||"",x=n.wine_menu?.ean_code?.toLowerCase()||"",J=n.wine_menu?.wine_type?.toLowerCase()||"",ue=n.storage_areas?.code?.toLowerCase()||"",Is=n.notes?.toLowerCase()||"";return o===i&&(r+=100),a===i&&(r+=100),x===i&&(r+=100),o.startsWith(i)&&(r+=50),a.startsWith(i)&&(r+=45),x.startsWith(i)&&(r+=45),ue.startsWith(i)&&(r+=40),o.includes(i)&&(r+=20),a.includes(i)&&(r+=18),x.includes(i)&&(r+=18),J.includes(i)&&(r+=15),ue.includes(i)&&(r+=10),Is.includes(i)&&(r+=5),{item:n,score:r}}).filter(({score:n})=>n>0).sort((n,r)=>r.score-n.score).map(({item:n})=>n);_(h)}else b(t),_(s)},[m,f,u,le,ce]);const Ft=async()=>{if(!p)return;A(!0);const{data:t}=await N.from("count_sessions").select("date, department").eq("id",p).maybeSingle();t&&(ne(new Date(t.date).toLocaleDateString("de-DE")),K(`Inventur ${new Date(t.date).toLocaleDateString("de-DE")}`),ms(t.department||""));const[s,i]=await Promise.all([N.from("inventory_session_items").select("id",{count:"exact",head:!0}).eq("session_id",p),N.from("wine_inventory_items").select("id",{count:"exact",head:!0}).eq("session_id",p)]);It(s.count??0),zt(i.count??0);const{data:l}=await N.from("storage_areas").select("id, code, display_name").eq("is_active",!0).eq("building_code","W").order("sort_order");ys(l||[]),ks(!0),A(!1)},Ss=async()=>{if(!p||ge)return;qt(!0);const{data:t,error:s}=await N.from("inventory_session_items").select(` 3 id, 4 item_id, 5 quantity, 6 unit, 7 notes, 8 counted_at, 9 storage_location, 10 is_processed, 11 inventory_items ( 12 name, 13 category, 14 barcode, 15 ean_code, 16 internal_barcode, 17 unit, 18 current_price, 19 price_per_quantity, 20 price_per_unit 21 ) 22 `).eq("session_id",p).order("counted_at",{ascending:!1});if(s)k({title:"Fehler",description:"Artikel konnten nicht geladen werden",variant:"destructive"}),console.error(s);else{const i=(t||[]).filter(l=>l.inventory_items&&l.inventory_items.name);if(v(i),b(i),It(i.length),i.length>0){const l=i.map(r=>r.id),{data:h}=await N.from("inventory_count_details").select("*").in("session_item_id",l).order("counted_at",{ascending:!0}),n={};(h||[]).forEach(r=>{n[r.session_item_id]||(n[r.session_item_id]=[]),n[r.session_item_id].push(r)}),wt(n)}else wt({})}Ct(!0),qt(!1)},qs=async()=>{if(!p||_e)return;Pt(!0);const{data:t,error:s}=await N.from("wine_inventory_items").select(` 23 id, 24 wine_id, 25 counted_quantity, 26 storage_area_id, 27 notes, 28 created_at, 29 is_processed, 30 wine_menu ( 31 name_de, 32 wine_type, 33 producer, 34 ean_code, 35 vintage_year, 36 current_purchase_price, 37 grape_variety, 38 bottle_size 39 ), 40 storage_areas ( 41 code, 42 display_name 43 ) 44 `).eq("session_id",p).order("created_at",{ascending:!1});s?(console.error("Error loading wine items:",s),k({title:"Fehler",description:"Weine konnten nicht geladen werden",variant:"destructive"})):(C(t||[]),_(t||[]),zt((t||[]).length)),kt(!0),Pt(!1)},fe=async()=>{Ct(!1),kt(!1),await Ft()},Ye=async(t,s,i)=>{const l=s?"wine_inventory_items":"inventory_session_items",{error:h}=await N.from(l).update({is_processed:!i}).eq("id",t);if(h){k({title:"Fehler",description:"Status konnte nicht geändert werden",variant:"destructive"});return}s?(C(n=>n.map(r=>r.id===t?{...r,is_processed:!i}:r)),_(n=>n.map(r=>r.id===t?{...r,is_processed:!i}:r))):(v(n=>n.map(r=>r.id===t?{...r,is_processed:!i}:r)),b(n=>n.map(r=>r.id===t?{...r,is_processed:!i}:r)))},Lt=async()=>
44{if(!(!p||!window.confirm(`â ï¸ Session abschlieÃen? 45 46Danach können keine Artikel mehr hinzugefügt werden. 47Diese Aktion kann nicht rückgängig gemacht werden.`)))try{const{error:s}=await un.updateSessionStatus(p,"locked");if(s)throw s;k({title:"Session abgeschlossen",description:"Die Session wurde erfolgreich gesperrt."}),y("/inventory")}catch(s){k({title:"Fehler beim AbschlieÃen",description:s.message,variant:"destructive"})}},Wt=()=>{if(f.length===0&&u.length===0)return;let t="";if(f.length>0){const l=["Artikel","Lagerort","Barcode","Menge","Einheit","Einzelpreis","Gesamtwert","Notizen","Erfasst am"],h=f.map(n=>[n.inventory_items?.name||"",n.storage_location||"",n.inventory_items?.barcode||"",n.quantity.toString(),n.inventory_items?.unit||"",n.inventory_items?.current_price?.toFixed(2)||"",n.inventory_items?.current_price?se(n.quantity,n.inventory_items.current_price,n.inventory_items.price_per_quantity,n.inventory_items.price_per_unit,n.inventory_items.unit).toFixed(2):"",n.notes||"",new Date(n.counted_at).toLocaleString("de-DE")]);t+=[l.join(","),...h.map(n=>n.map(r=>`"${r}"`).join(","))].join(` 48`)}if(u.length>0){t&&(t+=` 49 50`);const l=["Wein","Produzent","EAN-Code","Jahrgang","Regal","Anzahl Flaschen","EK Preis","Gesamtwert","Notizen","Erfasst am"],h=u.map(n=>[n.wine_menu?.name_de||"",n.wine_menu?.producer||"",n.wine_menu?.ean_code||"",n.wine_menu?.vintage_year?.toString()||"",n.storage_areas?.code||"",n.counted_quantity.toString(),n.wine_menu?.current_purchase_price?.toFixed(2)||"",n.wine_menu?.current_purchase_price?(n.wine_menu.current_purchase_price*n.counted_quantity).toFixed(2):"",n.notes||"",new Date(n.created_at).toLocaleString("de-DE")]);t+=[l.join(","),...h.map(n=>n.map(r=>`"${r}"`).join(","))].join(` 51`)}const s=new Blob([t],{type:"text/csv;charset=utf-8;"}),i=document.createElement("a");i.href=URL.createObjectURL(s),i.download=`inventur_${L.replace(/\./g,"-")}.csv`,i.click(),k({title:"Export erfolgreich",description:"CSV-Datei wurde heruntergeladen"})},M=c.useMemo(()=>[...E].sort((s,i)=>{let l=0;if(U==="storage"){const h=s.storage_location||"zzz",n=i.storage_location||"zzz";l=h.localeCompare(n)}else if(U==="name"){const h=s.inventory_items?.name||"",n=i.inventory_items?.name||"";l=h.localeCompare(n)}else U==="counted_at"&&(l=new Date(s.counted_at).getTime()-new Date(i.counted_at).getTime());return qe==="asc"?l:-l}),[E,U,qe]),D=c.useMemo(()=>[...w].sort((s,i)=>{let l=0;if(U==="storage"){const h=s.storage_areas?.code||"zzz",n=i.storage_areas?.code||"zzz";l=h.localeCompare(n)}else if(U==="name"){const h=s.wine_menu?.name_de||"",n=i.wine_menu?.name_de||"";l=h.localeCompare(n)}else U==="counted_at"&&(l=new Date(s.created_at).getTime()-new Date(i.created_at).getTime());return qe==="asc"?l:-l}),[w,U,qe]),ze=Math.ceil(D.length/Z),Tt=c.useMemo(()=>{const t=(re-1)*Z;return D.slice(t,t+Z)},[D,re]),De=Math.ceil(M.length/Z),Bt=c.useMemo(()=>{const t=(ie-1)*Z;return M.slice(t,t+Z)},[M,ie]);c.useEffect(()=>{He(1),Je(1)},[m,le,ce]),c.useMemo(()=>{const t={};return M.forEach(s=>{const i=s.storage_location||"Ohne Lagerort";t[i]||(t[i]=[]),t[i].push(s)}),Object.entries(t).sort(([s],[i])=>s.localeCompare(i))},[M]),c.useMemo(()=>{const t={};return D.forEach(s=>{const i=s.storage_areas?.code||"Ohne Lagerort";t[i]||(t[i]=[]),t[i].push(s)}),Object.entries(t).sort(([s],[i])=>s.localeCompare(i))},[D]);const Mt=()=>{const t=window.open("","_blank");if(!t)return;let s=` 52 <!DOCTYPE html> 53 <html> 54 <head> 55 <title>${W} - Inventurliste</title> 56 <style> 57 body { font-family: 'Jost', sans-serif; padding: 20px; font-size: 12px; } 58 h1 { font-size: 24px; margin-bottom: 5px; } 59 h2 { font-size: 18px; margin-bottom: 10px; margin-top: 20px; } 60 .meta { color: #666; margin-bottom: 15px; } 61 table { width: 100%; border-collapse: collapse; margin-bottom: 16px; } 62 th { text-align: left; border-bottom: 2px solid #333; padding: 4px 6px; } 63 td { padding: 3px 6px; border-bottom: 1px solid #ddd; } 64 .right { text-align: right; } 65 .center { text-align: center; } 66 tfoot td { font-weight: bold; border-top: 2px solid #333; padding: 4px 6px; } 67 @media print { body { padding: 10px; } } 68 </style> 69 </head> 70 <body> 71 <h1>${W}</h1> 72 <div class="meta">${L} - Inventurliste</div> 73 `;M.length>0&&(s+="<h2>Artikel</h2>",s+=`<table><thead><tr> 74 <th>Artikel</th> 75 <th class="right">Menge</th> 76 <th class="center">Einheit</th> 77 <th class="right">Preis</th> 78 <th class="right">Gesamtwert</th> 79 </tr></thead><tbody>`,M.forEach(n=>{const r=n.inventory_items,o=se(n.quantity,r?.current_price,r?.price_per_quantity,r?.price_per_unit,r?.unit);s+=`<tr> 80 <td>${r?.name||"-"}</td> 81 <td class="right">${n.quantity}</td> 82 <td class="center">${n.unit||"-"}</td> 83 <td class="right">
83${r?.current_price?V(r.current_price)+" â¬":"-"}</td> 84 <td class="right">${o>0?V(o)+" â¬":"-"}</td> 85 </tr>`}),s+="</tbody></table>"),D.length>0&&(D.reduce((n,r)=>n+r.counted_quantity,0),D.reduce((n,r)=>n+(r.wine_menu?.current_purchase_price||0)*r.counted_quantity,0),s+="<h2>Wein-Inventur</h2>",s+=`<table style="width:100%;border-collapse:collapse;margin-bottom:8px;"><thead><tr> 86 <th style="text-align:left;border-bottom:2px solid #333;padding:4px 6px;">Wein / Produzent</th> 87 <th style="text-align:left;border-bottom:2px solid #333;padding:4px 6px;">Rebsorte</th> 88 <th style="text-align:center;border-bottom:2px solid #333;padding:4px 6px;">Einheit</th> 89 <th style="text-align:left;border-bottom:2px solid #333;padding:4px 6px;">Regal</th> 90 <th style="text-align:right;border-bottom:2px solid #333;padding:4px 6px;">Flaschen</th> 91 <th style="text-align:right;border-bottom:2px solid #333;padding:4px 6px;">EK Preis</th> 92 <th style="text-align:right;border-bottom:2px solid #333;padding:4px 6px;">Gesamtwert</th> 93 </tr></thead><tbody>`,D.forEach(n=>{const r=n.wine_menu?.bottle_size?`${n.wine_menu.bottle_size}L`:"-",o=n.wine_menu?.producer||"",a=n.wine_menu?.name_de||"-",x=n.wine_menu?.current_purchase_price||0,J=x*n.counted_quantity,ue=n.storage_areas?.code||"-";s+=`<tr> 94 <td style="padding:3px 6px;border-bottom:1px solid #ddd;"><strong>${a}</strong>${o?`<br><span style="font-size:9px;color:#666;">${o}</span>`:""}</td> 95 <td style="padding:3px 6px;border-bottom:1px solid #ddd;">${n.wine_menu?.grape_variety||"-"}</td> 96 <td style="padding:3px 6px;border-bottom:1px solid #ddd;text-align:center;">${r}</td> 97 <td style="padding:3px 6px;border-bottom:1px solid #ddd;">${ue}</td> 98 <td style="padding:3px 6px;border-bottom:1px solid #ddd;text-align:right;">${n.counted_quantity}</td> 99 <td style="padding:3px 6px;border-bottom:1px solid #ddd;text-align:right;">${x>0?V(x)+" â¬":"-"}</td> 100 <td style="padding:3px 6px;border-bottom:1px solid #ddd;text-align:right;">${J>0?V(J)+" â¬":"-"}</td> 101 </tr>`}),s+="</tbody></table>");const i=M.reduce((n,r)=>{const o=r.inventory_items;return n+se(r.quantity,o?.current_price,o?.price_per_quantity,o?.price_per_unit,o?.unit)},0),l=D.reduce((n,r)=>n+(r.wine_menu?.current_purchase_price||0)*r.counted_quantity,0),h=i+l;s+=`<div style="margin-top:20px;padding-top:10px;border-top:3px solid #333;font-size:16px;font-weight:bold;text-align:right;">Gesamtsumme: ${V(h)} â¬</div>`,s+="</body></html>",t.document.write(s),t.document.close(),t.focus(),setTimeout(()=>{t.print(),t.close()},250)},Ot=()=>{const t=window.open("","_blank");if(!t)return;let s=` 102 <!DOCTYPE html> 103 <html> 104 <head> 105 <title>${W} - Detaillierte Inventurliste</title> 106 <style> 107 body { font-family: 'Jost', sans-serif; padding: 20px; font-size: 11px; } 108 h1 { font-size: 20px; margin-bottom: 5px; } 109 h2 { font-size: 16px; margin-bottom: 10px; margin-top: 20px; } 110 .meta { color: #666; margin-bottom: 15px; } 111 table { width: 100%; border-collapse: collapse; margin-bottom: 16px; } 112 th { text-align: left; border-bottom: 2px solid #333; padding: 4px 6px; font-size: 10px; } 113 td { padding: 3px 6px; border-bottom: 1px solid #ddd; } 114 .right { text-align: right; } 115 .center { text-align: center; } 116 tfoot td { font-weight: bold; border-top: 2px solid #333; padding: 4px 6px; } 117 @media print { body { padding: 10px; } } 118 </style> 119 </head> 120 <body> 121 <h1>${W}</h1> 122 <div class="meta">${L} - Detaillierte Inventurliste</div> 123 `;M.length>0&&(s+="<h2>Artikel</h2>",s+=`<table><thead><tr> 124 <th>Artikel</th> 125 <th class="right">Menge</th> 126 <th class="center">Einheit</th> 127 <th class="right">Preis</th> 128 <th class="right">Gesamtwert</th> 129 </tr></thead><tbody>`,M.forEach(h=>{const n=h.inventory_items,r=se(h.quantity,n?.current_price,n?.price_per_quantity,n?.price_per_unit,n?.unit);s+=`<tr> 130 <td>${n?.name||"-"}</td> 131 <td class="right">${h.quantity}</td> 132 <td class="center">${h.unit||"-"}</td> 133 <td class="right">
133${n?.current_price?V(n.current_price)+" â¬":"-"}</td> 134 <td class="right">${r>0?V(r)+" â¬":"-"}</td> 135 </tr>`}),s+="</tbody></table>"),D.length>0&&(s+="<h2>Wein</h2>",s+=`<table><thead><tr> 136 <th>Artikel</th> 137 <th class="right">Menge</th> 138 <th class="center">Einheit</th> 139 <th class="right">Preis</th> 140 <th class="right">Gesamtwert</th> 141 </tr></thead><tbody>`,D.forEach(h=>{const n=h.wine_menu,r=n?.current_purchase_price||0,o=r*h.counted_quantity,a=n?.bottle_size?`${n.bottle_size}L`:"-",x=[n?.producer,n?.name_de].filter(Boolean).join(" - ")||"-";s+=`<tr> 142 <td>${x}</td> 143 <td class="right">${h.counted_quantity}</td> 144 <td class="center">${a}</td> 145 <td class="right">${r>0?V(r)+" â¬":"-"}</td> 146 <td class="right">${o>0?V(o)+" â¬":"-"}</td> 147 </tr>`}),s+="</tbody></table>");const i=M.reduce((h,n)=>{const r=n.inventory_items;return h+se(n.quantity,r?.current_price,r?.price_per_quantity,r?.price_per_unit,r?.unit)},0),l=D.reduce((h,n)=>h+(n.wine_menu?.current_purchase_price||0)*n.counted_quantity,0);s+=`<div style="margin-top:20px;font-size:14px;font-weight:bold;border-top:3px solid #000;padding-top:8px;"> 148 Gesamtsumme: ${V(i+l)} ⬠149 </div>`,s+="</body></html>",t.document.write(s),t.document.close(),t.focus(),setTimeout(()=>{t.print(),t.close()},250)},Vt=f.length,Es=f.reduce((t,s)=>t+s.quantity,0),Gt=f.reduce((t,s)=>s.inventory_items?t+se(s.quantity,s.inventory_items.current_price,s.inventory_items.price_per_quantity,s.inventory_items.price_per_unit,s.inventory_items.unit):t,0),Xe=f.filter(t=>t.inventory_items?.current_price),Kt=Xe.length>0?Xe.reduce((t,s)=>s.inventory_items?t+(s.inventory_items.current_price||0):t,0)/Xe.length:0,Rt=u.length,Ps=u.reduce((t,s)=>t+s.counted_quantity,0),Ut=u.reduce((t,s)=>{if(!s.wine_menu)return t;const i=s.wine_menu.current_purchase_price||0;return t+i*s.counted_quantity},0),Zt=(t,s)=>{t&&(hs(t),xs(null),we(t.quantity),Oe(t.inventory_items?.ean_code||""),Ge(t.notes||""),ut(t.inventory_items?.name||""),Ke(t.unit||t.inventory_items?.unit||""),Re(t.inventory_items?.current_price??null),xt(t.inventory_items?.price_per_quantity??null),gt(t.inventory_items?.price_per_unit||""),ft(t.storage_location||""),vt("")),xe(!0)},Qt=(t,s)=>{if(t.kind==="inventory_item"&&t.item_name){S(t.item_name),k({title:"Artikel gefunden",description:`${s} â ${t.item_name}`});return}if(t.kind==="slaughter_allocation"){if(!t.item_id){ye({allocationId:t.allocation_id??"",lotCode:t.lot_code??s,label:t.allocation_label??null,quantity:t.allocation_quantity??null,unit:t.allocation_unit??null});return}const i=f.find(l=>l.item_id===t.item_id);i?(Zt(i),t.allocation_quantity!=null&&we(t.allocation_quantity),t.allocation_unit&&Ke(t.allocation_unit),Ge([i.notes,`Charge ${t.lot_code??s}`].filter(Boolean).join(" · ")),k({title:"Schlachtcharge erkannt",description:`${t.lot_code??s} â ${t.item_name??""} â Menge prüfen und bestätigen.`})):(t.item_name&&S(t.item_name),k({title:"Schlachtcharge erkannt",description:`${t.lot_code??s} â ${t.item_name??"Artikel"}. Artikel zur Zählung hinzufügen.`}));return}k({title:"Schlacht-Charge",description:`${s}${t.lot_code?` · ${t.lot_code}`:""}`})},Ie=c.useCallback(async(t,s,i,l)=>{const h=`${t}-${s}`;Ze(n=>({...n,[h]:!0}));try{if(l){const n=u.find(r=>r.id===t);if(!n)return;if(s==="counted_quantity"){const r=parseInt(i)||0,{error:o}=await N.from("wine_inventory_items").update({counted_quantity:r}).eq("id",t);if(o)throw o;C(a=>a.map(x=>x.id===t?{...x,counted_quantity:r}:x))}else if(s==="notes"){const{error:r}=await N.from("wine_inventory_items").update({notes:i||null}).eq("id",t);if(r)throw r;C(o=>o.map(a=>a.id===t?{...a,notes:i||null}:a))}else if(s==="current_purchase_price"){const r=parseFloat(i)||null,{error:o}=await N.from("wine_menu").update({current_purchase_price:r}).eq("id",n.wine_id);if(o)throw o;C(a=>a.map(x=>x.id===t?{...x,wine_menu:x.wine_menu?{...x.wine_menu,current_purchase_price:r}:null}:x))}else if(s==="ean_code"){const{error:r}=await N.from("wine_menu").update({ean_code:i||null}).eq("id",n.wine_id);if(r)throw r;C(o=>o.map(a=>a.id===t?{...a,wine_menu:a.wine_menu?{...a.wine_menu,ean_code:i||null}:null}:a))}else if(s==="storage_area_id"){const{error:r}=await N.from("wine_inventory_items").update({storage_area_id:i||null}).eq("id",t);if(r)throw r;const o=Pe.find(a=>a.id===i);C(a=>a.map(x=>x.id===t?{...x,storage_area_id:i||null,storage_areas:o?{code:o.code,display_name:o.display_name}:null}:x))}}else{const n=f.find(r=>r.id===t);if(!n)return;if(s==="quantity"){const r=parseFloat(i)||0,{error:o}=await N.from("inventory_session_items").update({quantity:r}).eq("id",t);if(o)throw o;v(a=>a.map(x=>x.id===t?{...x,quantity:r}:x))}else if(s==="notes"){const{error:r}=await N.from("inventory_session_items").update({notes:i||null}).eq("id",t);if(r)throw r;v(o=>o.map(a=>a.id===t?{...a,notes:i||null}:a))}else if(s==="current_price"){const r=parseFloat(i)||null,{error:o}=await N.from("inventory_items").update({current_price:r}).eq("id",n.item_id);if(o)throw o;v(a=>a.map(x=>x.id===t?{...x,inventory_items:{...x.inventory_items,current_price:r}}:x))}else if(s==="ean_code"){const{error:r}=await N.from("inventory_items").update({ean_code:i||null}).eq("id",n.item_id);if(r)throw r;v(o=>o.map(a=>a.id===t?{...a,inventory_items:{...a.inventory_items,ean_code:i||null}}:a))}else if(s==="price_per_quantity"){const r=parseFloat(i)||null,{error:o}=await N.from("inventory_items").update({price_per_quantity:r}).eq("id",n.item_id);if(o)throw o;v(a=>a.map(x=>x.id===t?{...x,inventory_items:{...x.inventory_items,price_per_quantity:r}}:x))}else if(s==="price_per_unit"){const{error:r}=await N.from("inventory_items").update({price_per_unit:i||null}).eq("id",n.item_id);if(r)throw r;v(o=>o.map(a=>a.id===t?{...a,inventory_items:{...a.inventory_items,price_per_unit:i||null}}:a))}else if(s==="name"){const{error:r}=await N.from("inventory_items").update({name:i}).eq("id",n.item_id);if(r)throw r;v(o=>o.map(a=>a.id===t?{...a,inventory_items:{...a.inventory_items,name:i}}:a)),b(o=>o.map(a=>a.id===t?{...a,inventory_items:{...a.inventory_items,name:i}}:a))}else if(s==="unit"){const{error:r}=await N.from("inventory_session_items").update({unit:i}).eq("id",t);if(r)throw r;v(o=>o.map(a=>a.id===t?{...a,unit:i}:a)),b(o=>o.map(a=>a.id===t?{...a,unit:i}:a))}}Ue(n=>{const r={...n};return r[t]&&(delete r[t][s],Object.keys(r[t]).length===0&&delete r[t]),r}),k({title:"â Gespeichert"})}catch(n){k({title:"Fehler beim Speichern",description:n.message,variant:"destructive"})}finally{Ze(n=>({...n,[h]:!1}))}},[f,u,k]),G=c.useCallback((t,s,i)=>{Ue(l=>({...l,[t]:{...l[t],[s]:i}}))},[]),ae=c.useCallback((t,s,i,l)=>{const h=d[t]?.[s];h!==void 0&&String(h)!==String(l??"")&&Ie(t,s,h,i)},[d,Ie]),Ht=c.useCallback(()=>{z&&(Ue({}),Ze({}),fe()),vs(!z)},[z]),et=c.useCallback(async()=>{const t=[];if(Object.values(d).reduce((i,l)=>i+Object.keys(l).length,0)===0){k({title:"Keine Ãnderungen vorhanden"});return}for(const[i,l]of Object.entries(d)){const h=u.some(n=>n.id===i);for(const[n,r]of Object.entries(l)){let o;if(h){const a=u.find(x=>x.id===i);n==="counted_quantity"?o=a?.counted_quantity:n==="notes"?o=a?.notes:n==="current_purchase_price"?o=a?.wine_menu?.current_purchase_price:n==="ean_code"?o=a?.wine_menu?.ean_code:n==="storage_area_id"&&(o=a?.storage_area_id)}else{const a=f.find(x=>x.id===i);n==="quantity"?o=a?.quantity:n==="notes"?o=a?.notes:n==="current_price"?o=a?.inventory_items?.current_price:n==="ean_code"?o=a?.inventory_items?.ean_code:n==="price_per_quantity"?o=a?.inventory_items?.price_per_quantity:n==="price_per_unit"?o=a?.inventory_items?.price_per_unit:n==="name"?o=a?.inventory_items?.name:n==="unit"&&(o=a?.unit)}String(r)!==String(o??"")&&t.push(Ie(i,n,r,h))}}t.length>0?(await Promise.all(t),k({title:"â Alle Ãnderungen gespeichert",description:`${t.length} ${t.length===1?"Ãnderung":"Ãnderungen"} gespeichert`})):k({title:"Keine Ãnderungen zu speichern"})},[d,f,u,Ie,k]),Jt=c.useMemo(()=>Object.keys(d).length>0,[d]),$s=async()=>
149{if(B){const{validateEANCode:t,checkDuplicateCode:s,getItemByEANCode:i}=await Fs(async()=>{const{validateEANCode:h,checkDuplicateCode:n,getItemByEANCode:r}=await import("./useEANCodeGenerator-_Y0Gajv4.js").then(o=>o.e);return{validateEANCode:h,checkDuplicateCode:n,getItemByEANCode:r}},__vite__mapDeps([0,1,2,3,4,5,6,7]));if(!t(B)){ke("Code muss 4-13 Ziffern enthalten (nur Zahlen)");return}const l=T?.inventory_items?.ean_code||$?.wine_menu?.ean_code||"";if(B!==l&&await s(B)){const n=await i(B);if(!window.confirm(`â ï¸ Code bereits vergeben 150 151Der Code "${B}" wird bereits verwendet bei: 152"${n}" 153 154Trotzdem speichern?`))return}}ke("");try{if(T){const{error:t}=await N.from("inventory_items").update({name:dt,ean_code:B||null,current_price:Se,price_per_quantity:ht,price_per_unit:pt||null}).eq("id",T.item_id);if(t)throw t;const{error:s}=await N.from("inventory_session_items").update({quantity:Ne,unit:mt,notes:Ve||null,storage_location:_t||null}).eq("id",T.id);if(s)throw s;k({title:"Erfolgreich",description:"Artikel wurde aktualisiert"})}else if($){const{error:t}=await N.from("wine_menu").update({ean_code:B||null,current_purchase_price:Se}).eq("id",$.wine_id);if(t)throw t;const{error:s}=await N.from("wine_inventory_items").update({counted_quantity:Ne,notes:Ve||null,storage_area_id:jt||null}).eq("id",$.id);if(s)throw s;k({title:"Erfolgreich",description:"Wein wurde aktualisiert"})}xe(!1),await fe()}catch(t){k({title:"Fehler",description:t.message,variant:"destructive"})}},As=async()=>{const t=await _s();Oe(t),ke("")},zs=()=>{const t=T?.inventory_items?.name||$?.wine_menu?.name_de||"";fs(B,t)},Ds=async()=>{try{if(T){const{error:t}=await N.from("inventory_session_items").delete().eq("id",T.id);if(t)throw t;k({title:"Erfolgreich",description:"Artikel wurde gelöscht"})}else if($){const{error:t}=await N.from("wine_inventory_items").delete().eq("id",$.id);if(t)throw t;k({title:"Erfolgreich",description:"Wein wurde gelöscht"})}Me(!1),xe(!1),await fe()}catch(t){k({title:"Fehler",description:t.message,variant:"destructive"})}};return e.jsxs("div",{className:"container mx-auto py-6 space-y-6",children:[e.jsxs("div",{className:"flex flex-col gap-3 md:gap-4",children:[e.jsxs("div",{className:"md:hidden space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(j,{variant:"ghost",onClick:()=>y("/inventory"),className:"min-h-[44px]",children:[e.jsx(es,{className:"h-4 w-4 mr-2"}),"Zurück"]}),e.jsxs("div",{className:"flex gap-2 ml-auto",children:[e.jsxs(Y,{value:U,onValueChange:t=>yt(t),children:[e.jsx(X,{className:"w-[44px] h-[44px] p-0",children:e.jsx(ee,{})}),e.jsxs(te,{children:[e.jsx(q,{value:"counted_at",children:"Nach Datum"}),e.jsx(q,{value:"name",children:"Nach Name"})]})]}),e.jsx(j,{onClick:Mt,variant:"outline",size:"icon",className:"min-h-[44px] min-w-[44px]",title:"Einfach drucken",children:e.jsx(tt,{className:"h-4 w-4"})}),e.jsx(j,{onClick:Ot,variant:"outline",size:"icon",className:"min-h-[44px] min-w-[44px]",title:"Detailliert drucken",children:e.jsx(je,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg font-bold",children:W}),e.jsx("p",{className:"text-xs text-muted-foreground",children:L})]}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.jsxs(j,{onClick:()=>$e(!0),className:"flex-1 min-h-[44px]",disabled:!Ae||!p,children:[e.jsx(ts,{className:"mr-2 h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Neuer Artikel"}),e.jsx("span",{className:"sm:hidden",children:"Neu"})]}),e.jsxs(j,{onClick:Ht,variant:z?"default":"outline",size:"sm",className:"flex-1 min-h-[44px]",children:[e.jsx(rt,{className:"mr-2 h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:z?"Fertig":"Bearbeiten"})]}),z&&Jt&&e.jsxs(j,{onClick:et,variant:"default",size:"sm",className:"flex-1 min-h-[44px] bg-green-600 hover:bg-green-700",disabled:Object.values(H).some(Boolean),children:[e.jsx(st,{className:"mr-2 h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Speichern"})]}),e.jsxs(j,{onClick:()=>ve(!0),variant:"outline",size:"sm",className:"flex-1 min-h-[44px]",children:[e.jsx(je,{className:"mr-2 h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Preise"})]}),e.jsxs(j,{onClick:Wt,variant:"outline",size:"sm",className:"flex-1 min-h-[44px]",children:[e.jsx(ss,{className:"mr-2 h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"CSV"})]}),e.jsxs(j,{onClick:Lt,variant:"destructive",size:"sm",className:"flex-1 min-h-[44px]",children:[e.jsx(ns,{className:"mr-2 h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Sperren"})]})]})]}),e.jsxs("div",{className:"hidden md:flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(j,{variant:"ghost",size:"icon",onClick:()=>y("/inventory"),className:"min-h-[44px] min-w-[44px]",children:e.jsx(es,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold",children:W}),e.jsx("p",{className:"text-muted-foreground",children:L})]})]}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.jsxs(j,{onClick:()=>$e(!0),disabled:!Ae||!p,children:[e.jsx(ts,{className:"mr-2 h-4 w-4"}),"Neuer Artikel"]}),e.jsxs(j,{onClick:Ht,variant:z?"default":"outline",children:[e.jsx(rt,{className:"mr-2 h-4 w-4"}),z?"Bearbeitung beenden":"Tabelle bearbeiten"]}),z&&Jt&&e.jsxs(j,{onClick:et,className:"bg-green-600 hover:bg-green-700",disabled:Object.values(H).some(Boolean),children:[e.jsx(st,{className:"mr-2 h-4 w-4"}),"Ãnderungen speichern (",Object.values(d).reduce((t,s)=>t+Object.keys(s).length,0),")"]}),e.jsxs(Y,{value:U,onValueChange:t=>yt(t),children:[e.jsx(X,{className:"w-[180px]",children:e.jsx(ee,{placeholder:"Sortieren nach"})}),e.jsxs(te,{children:[e.jsx(q,{value:"counted_at",children:"Nach Datum"}),e.jsx(q,{value:"name",children:"Nach Name"})]})]}),e.jsxs(j,{onClick:Mt,variant:"outline",children:[e.jsx(tt,{className:"mr-2 h-4 w-4"}),"Drucken"]}),e.jsxs(j,{onClick:Ot,variant:"outline",children:[e.jsx(je,{className:"mr-2 h-4 w-4"}),"Inventurliste"]}),e.jsxs(j,{onClick:()=>ve(!0),variant:"outline",children:[e.jsx(je,{className:"mr-2 h-4 w-4"}),"Preise importieren"]}),e.jsxs(j,{onClick:Wt,variant:"outline",children:[e.jsx(ss,{className:"mr-2 h-4 w-4"}),"CSV Export"]}),e.jsxs(j,{onClick:Lt,variant:"destructive",children:[e.jsx(ns,{className:"mr-2 h-4 w-4"}),"Session abschlieÃen"]})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[de==="items"&&ge&&Vt>0&&e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-medium mb-2 flex items-center gap-2",children:[e.jsx(nt,{className:"h-4 w-4"}),"Normale Artikel"]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3 md:gap-4",children:[e.jsxs("div",{className:"bg-card border rounded-lg p-3 md:p-4",children:[e.jsx("div",{className:"text-xs md:text-sm text-muted-foreground",children:"Artikel"}),e.jsx("div",{className:"text-lg md:text-2xl font-bold",children:Vt})]}),e.jsxs("div",{className:"bg-card border rounded-lg p-3 md:p-4",children:[e.jsx("div",{className:"text-xs md:text-sm text-muted-foreground",children:"Gesamtmenge"}),e.jsx("div",{className:"text-lg md:text-2xl font-bold",children:Es})]}),Kt>0&&e.jsxs("div",{className:"bg-card border rounded-lg p-3 md:p-4",children:[e.jsx("div",{className:"text-xs md:text-sm text-muted-foreground",children:"à Einzelpreis"}),e.jsxs("div",{className:"text-lg md:text-2xl font-bold",children:[Kt.toFixed(2)," â¬"]})]}),Gt>0&&e.jsxs("div",{className:"bg-card border rounded-lg p-3 md:p-4",children:[e.jsx("div",{className:"text-xs md:text-sm text-muted-foreground",children:"Gesamtwert"}),e.jsxs("div",{className:"text-lg md:text-2xl font-bold",children:[Gt.toFixed(2)," â¬"]})]})]})]}),de==="wine"&&_e&&Rt>0&&e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-medium mb-2 flex items-center gap-2",children:[e.jsx(Fe,{className:"h-4 w-4"}),"Wein-Inventur"]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3 md:gap-4",children:[e.jsxs("div",{className:"bg-card border rounded-lg p-3 md:p-4",children:[e.jsx("div",{className:"text-xs md:text-sm text-muted-foreground",children:"Weine"}),e.jsx("div",{className:"text-lg md:text-2xl font-bold",children:Rt})]}),e.jsxs("div",{className:"bg-card border rounded-lg p-3 md:p-4",children:[e.jsx("div",{className:"text-xs md:text-sm text-muted-foreground",children:"Flaschen"}),e.jsx("div",{className:"text-lg md:text-2xl font-bold",children:Ps})]}),Ut>0&&e.jsxs("div",{className:"bg-card border rounded-lg p-3 md:p-4",children:[e.jsx("div",{className:"text-xs md:text-sm text-muted-foreground",children:"Gesamtwert"}),e.jsxs("div",{className:"text-lg md:text-2xl font-bold",children:[Ut.toFixed(2)," â¬"]})]})]})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[e.jsx(gn,{className:"sm:w-72",onResolved:Qt}),e.jsxs("div",{className:"relative flex-1",children:[e.jsx(Ks,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(P,{placeholder:"Artikel suchen (Name, Barcode, EAN, Produzent, Notizen)...",value:m,onChange:t=>S(t.target.value),className:"pl-10"})]}),e.jsx(j,{variant:le?"default":"outline",onClick:()=>bs(!le),className:"whitespace-nowrap",children:le?e.jsxs(e.Fragment,{children:[e.jsx(Le,{className:"h-4 w-4 mr-2"}),"Nur offene (",f.filter(t=>!t.is_processed).length+u.filter(t=>!t.is_processed).length,")"]}):e.jsxs(e.Fragment,{children:[e.jsx(Te,{className:"h-4 w-4 mr-2"}),"Alle anzeigen (",f.length+u.length,")"]})}),e.jsxs(j,{variant:ce?"default":"outline",onClick:()=>Ns(!ce),className:"whitespace-nowrap",children:[e.jsx(je,{className:"h-4 w-4 mr-2"}),ce?e.jsxs(e.Fragment,{children:["Ohne Preis (",f.filter(t=>!t.inventory_items?.current_price||t.inventory_items.current_price===0).length+u.filter(t=>!t.wine_menu?.current_purchase_price||t.wine_menu.current_purchase_price===0).length,")"]}):e.jsx(e.Fragment,{children:"Ohne Preis"})]})]}),g?e.jsxs("div",{className:"text-center py-12",children:[e.jsx(he,{className:"h-8 w-8 animate-spin mx-auto mb-2 text-muted-foreground"}),e.jsx("p",{className:"text-muted-foreground",children:"Lade Session-Details..."})]}):e.jsxs(Rs,{value:de,onValueChange:t=>Cs(t),className:"w-full",children:[e.jsxs(Us,{className:"mb-4",children:[e.jsxs(rs,{value:"wine",className:"px-6 py-2.5 text-base",children:[e.jsx(Fe,{className:"h-4 w-4 mr-2"}),"Weine",At!==null&&e.jsx(me,{variant:"secondary",className:"ml-2",children:At})]}),e.jsxs(rs,{value:"items",className:"px-6 py-2.5 text-base",children:[e.jsx(nt,{className:"h-4 w-4 mr-2"}),"Artikel",Dt!==null&&e.jsx(me,{variant:"secondary",className:"ml-2",children:Dt})]})]}),e.jsx(is,{value:"wine",children:Et?e.jsxs("div",{className:"text-center py-12",children:[e.jsx(he,{className:"h-8 w-8 animate-spin mx-auto mb-2 text-muted-foreground"}),e.jsx("p",{className:"text-muted-foreground",children:"Lade Weine..."})]}):_e?w.length===0?e.jsx("div",{className:"text-center py-12 text-muted-foreground",children:m?"Keine Weine gefunden":"Keine Weine in dieser Session erfasst"}):e.jsxs("div",{className:"border rounded-lg overflow-hidden bg-background",children:[e.jsxs("div",{className:"px-4 py-3 bg-muted/50 border-b flex flex-col sm:flex-row justify-between items-start sm:items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Fe,{className:"h-5 w-5 text-purple-600"}),e.jsx("span",{className:"font-semibold",children:"Wein-Inventur"}),e.jsxs(me,{variant:"outline",children:[w.length," Weine"]}),e.jsxs(me,{variant:"secondary",children:[u.reduce((t,s)=>t+(d[s.id]?.counted_quantity!==void 0?parseInt(d[s.id].counted_quantity)||0:s.counted_quantity),0)," Flaschen"]})]}),(()=>{const t=Object.entries(d).filter(([i])=>u.some(l=>l.id===i));if(t.length===0)return null;const s=t.reduce((i,[,l])=>i+Object.keys(l).length,0);return e.jsxs(j,{onClick:et,className:"bg-green-600 hover:bg-green-700",disabled:Object.values(H).some(Boolean),children:[e.jsx(st,{className:"mr-2 h-4 w-4"}),"Speichern (",s,")"]})})()]}),e.jsx("div",{className:"md:hidden divide-y",children:Tt.map(t=>e.jsxs("div",{className:`p-4 space-y-3 ${t.is_processed?"bg-muted/30":""}`,children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx("button",{onClick:()=>Ye(t.id,!0,t.is_processed),className:"p-1 hover:bg-muted rounded transition-colors flex-shrink-0",children:t.is_processed?e.jsx(Te,{className:"h-5 w-5 text-primary"}):e.jsx(Le,{className:"h-5 w-5 text-muted-foreground"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"font-medium text-base",children:t.wine_menu?.name_de||"-"}),t.wine_menu?.producer&&e.jsx("div",{className:"text-sm text-muted-foreground",children:t.wine_menu.producer})]}),e.jsx(Fe,{className:"w-5 h-5 text-purple-600 flex-shrink-0"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 text-sm",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Regal"}),e.jsxs(Y,{value:d[t.id]?.storage_area_id??t.storage_area_id??"",onValueChange:s=>G(t.id,"storage_area_id",s),children:[e.jsx(X,{className:`h-8 text-xs ${d[t.id]?.storage_area_id!==void 0?"border-amber-500":""}`,children:e.jsx(ee,{placeholder:"Regal..."})}),e.jsx(te,{children:Pe.map(s=>e.jsx(q,{value:s.id,children:s.code},s.id))})]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Flaschen"}),e.jsx(P,{type:"number",min:"0",value:d[t.id]?.counted_quantity??t.counted_quantity,onChange:s=>G(t.id,"counted_quantity",s.target.value),className:`h-8 text-xs ${d[t.id]?.counted_quantity!==void 0?"border-amber-500":""}`})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"EK Preis"}),e.jsx(P,{type:"number",step:"0.01",value:d[t.id]?.current_purchase_price??t.wine_menu?.current_purchase_price??"",onChange:s=>G(t.id,"current_purchase_price",s.target.value),className:`h-8 text-xs ${d[t.id]?.current_purchase_price!==void 0?"border-amber-500":""}`,placeholder:"0.00"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Gesamtwert"}),e.jsx("div",{className:"font-medium",children:(()=>{const s=d[t.id]?.current_purchase_price!==void 0?parseFloat(d[t.id].current_purchase_price)||0:t.wine_menu?.current_purchase_price||0,i=d[t.id]?.counted_quantity!==void 0?parseInt(d[t.id].counted_quantity)||0:t.counted_quantity;return s>0?`${(s*i).toFixed(2)} â¬`:"-"})()})]})]}),e.jsx(P,{value:d[t.id]?.notes??t.notes??"",onChange:s=>G(t.id,"notes",s.target.value),className:`text-xs ${d[t.id]?.notes!==void 0?"border-amber-500":""}`,placeholder:"Notizen..."})]},t.id))}),e.jsx("div",{className:"hidden md:block overflow-x-auto",children:e.jsxs(as,{children:[e.jsx(os,{children:e.jsxs(We,{className:"bg-muted/30",children:[e.jsx(I,{className:"w-10 p-2",children:"â"}),e.jsx(I,{className:"min-w-[250px] p-2",children:"Wein / Produzent"}),e.jsx(I,{className:"w-28 p-2",children:"Rebsorte"}),e.jsx(I,{className:"w-16 p-2",children:"Einheit"}),e.jsx(I,{className:"w-20 p-2",children:"Regal"}),e.jsx(I,{className:"w-20 text-right p-2",children:"Flaschen"}),e.jsx(I,{className:"w-24 text-right p-2",children:"EK Preis"}),e.jsx(I,{className:"w-24 text-right p-2",children:"Gesamtwert"}),e.jsx(I,{className:"min-w-[150px] p-2",children:"Notizen"})]})}),e.jsx(ls,{children:Tt.map(t=>e.jsxs(We,{className:`hover:bg-muted/30 ${t.is_processed?"bg-muted/50":""}`,children:[e.jsx(F,{className:"p-1",children:e.jsx(j,{type:"button",variant:"ghost",size:"sm",onClick:s=>{s.stopPropagation(),Ye(t.id,!0,t.is_processed)},className:"h-8 w-8 p-0",children:t.is_processed?e.jsx(Te,{className:"h-5 w-5 text-primary"}):e.jsx(Le,{className:"h-5 w-5 text-muted-foreground"})})}),e.jsxs(F,{className:"py-1",children:[e.jsx("div",{className:"font-medium text-sm",children:t.wine_menu?.name_de||"-"}),t.wine_menu?.producer&&e.jsx("div",{className:"text-xs text-muted-foreground",children:t.wine_menu.producer}),t.wine_menu?.vintage_year&&e.jsx(me,{variant:"outline",className:"text-xs mt-1",children:t.wine_menu.vintage_year})]}),e.jsx(F,{className:"p-1",children:e.jsx("span",{className:"text-xs",children:t.wine_menu?.grape_variety||"-"})}),e.jsx(F,{className:"p-1",children:e.jsx("span",{className:"text-xs",children:t.wine_menu?.bottle_size?`${t.wine_menu.bottle_size}L`:"-"})}),e.jsx(F,{className:"p-1",children:e.jsxs(Y,{v
154alue:d[t.id]?.storage_area_id??t.storage_area_id??"",onValueChange:s=>G(t.id,"storage_area_id",s),children:[e.jsx(X,{className:`h-8 text-xs border-transparent hover:border-input focus:border-primary w-full ${d[t.id]?.storage_area_id!==void 0?"border-amber-500 bg-amber-50 dark:bg-amber-950/30":""}`,children:e.jsx(ee,{placeholder:"..."})}),e.jsx(te,{children:Pe.map(s=>e.jsx(q,{value:s.id,children:s.code},s.id))})]})}),e.jsx(F,{className:"text-right p-1",children:e.jsx(P,{type:"number",min:"0",value:d[t.id]?.counted_quantity??t.counted_quantity,onChange:s=>G(t.id,"counted_quantity",s.target.value),onKeyDown:s=>s.key==="Enter"&&ae(t.id,"counted_quantity",!0,t.counted_quantity),className:`h-8 text-xs text-right w-16 border-transparent hover:border-input focus:border-primary ${H[`${t.id}-counted_quantity`]?"opacity-50":""} ${d[t.id]?.counted_quantity!==void 0?"border-amber-500 bg-amber-50 dark:bg-amber-950/30":""}`})}),e.jsx(F,{className:"text-right p-1",children:e.jsx(P,{type:"number",step:"0.01",value:d[t.id]?.current_purchase_price??t.wine_menu?.current_purchase_price??"",onChange:s=>G(t.id,"current_purchase_price",s.target.value),onKeyDown:s=>s.key==="Enter"&&ae(t.id,"current_purchase_price",!0,t.wine_menu?.current_purchase_price),className:`h-8 text-xs text-right border-transparent hover:border-input focus:border-primary ${H[`${t.id}-current_purchase_price`]?"opacity-50":""} ${d[t.id]?.current_purchase_price!==void 0?"border-amber-500 bg-amber-50 dark:bg-amber-950/30":""}`,placeholder:"0.00"})}),e.jsx(F,{className:"text-right font-semibold tabular-nums py-1",children:(()=>{const s=d[t.id]?.current_purchase_price!==void 0?parseFloat(d[t.id].current_purchase_price)||0:t.wine_menu?.current_purchase_price||0,i=d[t.id]?.counted_quantity!==void 0?parseInt(d[t.id].counted_quantity)||0:t.counted_quantity;return s>0?`${(s*i).toFixed(2)} â¬`:"-"})()}),e.jsx(F,{className:"p-1",children:e.jsx(P,{value:d[t.id]?.notes??t.notes??"",onChange:s=>G(t.id,"notes",s.target.value),onKeyDown:s=>s.key==="Enter"&&ae(t.id,"notes",!0,t.notes),className:`h-8 text-xs border-transparent hover:border-input focus:border-primary ${H[`${t.id}-notes`]?"opacity-50":""} ${d[t.id]?.notes!==void 0?"border-amber-500 bg-amber-50 dark:bg-amber-950/30":""}`,placeholder:"Notizen..."})})]},t.id))})]})}),ze>1&&e.jsxs("div",{className:"px-4 py-3 border-t flex flex-col sm:flex-row items-center justify-between gap-3 bg-muted/30",children:[e.jsxs("span",{className:"text-sm text-muted-foreground",children:["Zeige ",(re-1)*Z+1," - ",Math.min(re*Z,D.length)," von ",D.length," Weinen"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(j,{variant:"outline",size:"sm",onClick:()=>He(t=>Math.max(1,t-1)),disabled:re===1,children:"â Zurück"}),e.jsxs("span",{className:"text-sm font-medium px-2",children:["Seite ",re," / ",ze]}),e.jsx(j,{variant:"outline",size:"sm",onClick:()=>He(t=>Math.min(ze,t+1)),disabled:re===ze,children:"Weiter â"})]})]}),e.jsxs("div",{className:"px-4 py-3 bg-muted/30 border-t flex justify-end gap-6 text-sm font-semibold",children:[e.jsxs("span",{children:["Gesamt: ",u.reduce((t,s)=>t+(d[s.id]?.counted_quantity!==void 0?parseInt(d[s.id].counted_quantity)||0:s.counted_quantity),0)," Flaschen"]}),e.jsxs("span",{className:"text-primary",children:["Gesamtwert: ",u.reduce((t,s)=>{const i=d[s.id]?.current_purchase_price!==void 0?parseFloat(d[s.id].current_purchase_price)||0:s.wine_menu?.current_purchase_price||0,l=d[s.id]?.counted_quantity!==void 0?parseInt(d[s.id].counted_quantity)||0:s.counted_quantity;return t+i*l},0).toFixed(2)," â¬"]})]})]}):e.jsx("div",{className:"text-center py-12 text-muted-foreground",children:"Weine werden geladen..."})}),e.jsx(is,{value:"items",children:St?e.jsxs("div",{className:"text-center py-12",children:[e.jsx(he,{className:"h-8 w-8 animate-spin mx-auto mb-2 text-muted-foreground"}),e.jsx("p",{className:"text-muted-foreground",children:"Lade Artikel..."})]}):ge?E.length===0?e.jsx("div",{className:"text-center py-12 text-muted-foreground",children:m?"Keine Artikel gefunden":"Keine Artikel in dieser Session erfasst"}):e.jsxs("div",{children:[e.jsx("div",{className:"md:hidden space-y-3",children:Bt.map(t=>e.jsx(Zs,{className:t.is_processed?"bg-muted/50":"",children:e.jsxs(Qs,{className:"p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx("button",{onClick:()=>Ye(t.id,!1,t.is_processed),className:"p-1 hover:bg-muted rounded transition-colors flex-shrink-0",children:t.is_processed?e.jsx(Te,{className:"h-5 w-5 text-primary"}):e.jsx(Le,{className:"h-5 w-5 text-muted-foreground"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"font-medium text-base",children:t.inventory_items?.name||"-"}),t.inventory_items?.barcode&&e.jsxs("div",{className:"text-xs text-muted-foreground font-mono mt-1",children:["Barcode: ",t.inventory_items.barcode]}),t.inventory_items?.ean_code&&e.jsxs("div",{className:"text-xs text-muted-foreground font-mono mt-1",children:["EAN: ",t.inventory_items.ean_code]})]}),e.jsx(nt,{className:"w-5 h-5 text-muted-foreground flex-shrink-0"})]}),t.storage_location&&e.jsxs("div",{className:"text-sm",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Lagerort"}),e.jsx("div",{className:"font-medium",children:t.storage_location})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 text-sm",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Menge"}),e.jsx("div",{className:"font-medium",children:t.quantity})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Einheit"}),e.jsx("div",{className:"font-medium",children:t.unit||"-"})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Gesamtwert"}),e.jsx("div",{className:"font-semibold",children:ds(t.quantity,t.inventory_items?.current_price,t.inventory_items?.price_per_quantity,t.inventory_items?.price_per_unit,t.inventory_items?.unit)})]})]}),t.notes&&e.jsx("div",{className:"text-xs text-muted-foreground pt-2 border-t",children:t.notes}),e.jsx(j,{size:"sm",variant:"outline",className:"w-full",onClick:()=>Zt(t),children:"Bearbeiten"})]})},t.id))}),e.jsxs("div",{className:`hidden md:block border rounded-lg ${z?"ring-2 ring-primary/50 bg-primary/5":""}`,children:[z&&e.jsxs("div",{className:"px-4 py-2 bg-primary/10 border-b text-sm font-medium text-primary flex items-center gap-2",children:[e.jsx(rt,{className:"h-4 w-4"}),"Bearbeitungsmodus aktiv - Werte direkt in der Tabelle ändern"]}),e.jsxs(as,{children:[e.jsx(os,{children:e.jsxs(We,{children:[e.jsx(I,{className:"min-w-[250px]",children:"Artikel"}),e.jsx(I,{className:"text-right",children:"Menge"}),e.jsx(I,{children:"Einheit"}),e.jsx(I,{className:"text-right",children:"Preis"}),e.jsx(I,{className:"text-right",children:"Gesamtwert"}),e.jsx(I,{className:"w-10"})]})}),e.jsx(ls,{children:Bt.map(t=>{const s=d[t.id]?.current_price!==void 0?parseFloat(d[t.id].current_price)||0:t.inventory_items?.current_price||0,i=d[t.id]?.quantity!==void 0?parseFloat(d[t.id].quantity)||0:t.quantity;return e.jsxs(We,{className:`${z?"hover:bg-primary/5":""} ${t.is_processed?"bg-muted/50":""}`,children:[e.jsxs(F,{className:"font-medium",children:[z?e.jsx(P,{type:"text",value:d[t.id]?.n
154ame??t.inventory_items?.name??"",onChange:l=>G(t.id,"name",l.target.value),onKeyDown:l=>l.key==="Enter"&&ae(t.id,"name",!1,t.inventory_items?.name),className:`h-8 text-xs w-full min-w-[200px] ${d[t.id]?.name!==void 0?"border-amber-500 bg-amber-50":""}`}):e.jsx("div",{children:t.inventory_items?.name||"-"}),Nt[t.id]?.length>0&&e.jsxs("div",{className:"ml-0 mt-2 space-y-1",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground mb-1",children:"Zähl-Details:"}),Nt[t.id].map(l=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(me,{variant:"secondary",className:"text-xs font-mono",children:[l.count,"à ",l.unit_name]}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["= ",l.converted_quantity," ",l.converted_unit]})]},l.id))]})]}),e.jsx(F,{className:"text-right",children:z?e.jsx(P,{type:"number",step:"0.1",value:d[t.id]?.quantity??t.quantity,onChange:l=>G(t.id,"quantity",l.target.value),onKeyDown:l=>l.key==="Enter"&&ae(t.id,"quantity",!1,t.quantity),className:`h-8 text-xs w-20 text-right ${H[`${t.id}-quantity`]?"opacity-50":""} ${d[t.id]?.quantity!==void 0?"border-amber-500 bg-amber-50 dark:bg-amber-950/30":""}`}):t.quantity}),e.jsx(F,{children:z?e.jsxs(Y,{value:d[t.id]?.unit??t.unit??"",onValueChange:l=>G(t.id,"unit",l),children:[e.jsx(X,{className:`h-8 text-xs w-16 ${d[t.id]?.unit!==void 0?"border-amber-500 bg-amber-50 dark:bg-amber-950/30":""}`,children:e.jsx(ee,{placeholder:"..."})}),e.jsxs(te,{children:[e.jsx(q,{value:"g",children:"g"}),e.jsx(q,{value:"kg",children:"kg"}),e.jsx(q,{value:"ml",children:"ml"}),e.jsx(q,{value:"l",children:"l"}),e.jsx(q,{value:"Stk",children:"Stk"})]})]}):t.unit||"-"}),e.jsx(F,{className:"text-right cursor-pointer hover:bg-muted/50",onDoubleClick:()=>Ee(`${t.id}-current_price`),children:z||Qe===`${t.id}-current_price`?e.jsx(P,{type:"number",step:"0.01",autoFocus:Qe===`${t.id}-current_price`,value:d[t.id]?.current_price??t.inventory_items?.current_price??"",onChange:l=>G(t.id,"current_price",l.target.value),onKeyDown:l=>{l.key==="Enter"?(ae(t.id,"current_price",!1,t.inventory_items?.current_price),Ee(null)):l.key==="Escape"&&Ee(null)},onBlur:()=>{Qe===`${t.id}-current_price`&&(ae(t.id,"current_price",!1,t.inventory_items?.current_price),Ee(null))},className:`h-8 text-xs w-24 text-right ${H[`${t.id}-current_price`]?"opacity-50":""} ${d[t.id]?.current_price!==void 0?"border-amber-500 bg-amber-50 dark:bg-amber-950/30":""}`,placeholder:"0.00"}):e.jsx("span",{className:"text-muted-foreground",children:t.inventory_items?.current_price?`${t.inventory_items.current_price.toFixed(2)} â¬`:"-"})}),e.jsx(F,{className:"text-right font-semibold",children:(()=>{const l=d[t.id]?.price_per_quantity!==void 0?parseFloat(d[t.id].price_per_quantity)||null:t.inventory_items?.price_per_quantity,h=d[t.id]?.price_per_unit!==void 0?d[t.id].price_per_unit:t.inventory_items?.price_per_unit;return ds(i,s,l,h,t.inventory_items?.unit)})()}),e.jsx(F,{children:e.jsx(fn,{itemName:t.inventory_items?.name||"-",quantity:i,currentPrice:s,pricePerQuantity:t.inventory_items?.price_per_quantity,pricePerUnit:t.inventory_items?.price_per_unit,itemUnit:t.inventory_items?.unit,category:t.inventory_items?.category,storageLocation:t.storage_location,barcode:t.inventory_items?.barcode,eanCode:t.inventory_items?.ean_code})})]},t.id)})})]}),De>1&&e.jsxs("div",{className:"px-4 py-3 border-t flex items-center justify-between bg-muted/30",children:[e.jsxs("span",{className:"text-sm text-muted-foreground",children:["Zeige ",(ie-1)*Z+1," - ",Math.min(ie*Z,M.length)," von ",M.length]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(j,{variant:"outline",size:"sm",onClick:()=>Je(t=>Math.max(1,t-1)),disabled:ie===1,children:"â Zurück"}),e.jsxs("span",{className:"text-sm font-medium px-2",children:["Seite ",ie," / ",De]}),e.jsx(j,{variant:"outline",size:"sm",onClick:()=>Je(t=>Math.min(De,t+1)),disabled:ie===De,children:"Weiter â"})]})]})]})]}):e.jsx("div",{className:"text-center py-12 text-muted-foreground",children:"Artikel werden geladen..."})})]}),e.jsx(vn,{open:Q,onOpenChange:ve,departmentTag:Be,sourceFile:"Inventur Küche 2024.csv",onImportComplete:()=>{fe()}}),Ae&&p&&e.jsx(xn,{open:ws,onOpenChange:$e,department:Ae,sessionId:p,onItemCreated:()=>{$e(!1),fe()}}),e.jsx(it,{open:ps,onOpenChange:xe,children:e.jsxs(at,{className:"sm:max-w-[600px]",children:[e.jsxs(ot,{children:[e.jsx(lt,{children:T?"Artikel bearbeiten":"Wein bearbeiten"}),e.jsx(us,{children:"Alle Felder können bearbeitet werden"})]}),e.jsxs("div",{className:"space-y-4 py-4 max-h-[60vh] overflow-y-auto",children:[T&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{htmlFor:"editName",children:"Artikelname"}),e.jsx(P,{id:"editName",value:dt,onChange:t=>ut(t.target.value),placeholder:"Artikelname eingeben..."})]}),$&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{children:"Wein"}),e.jsxs("div",{className:"text-sm p-2 bg-muted rounded-md",children:[e.jsx("div",{className:"font-medium",children:$.
154wine_menu?.name_de}),$.wine_menu?.producer&&e.jsx("div",{className:"text-muted-foreground",children:$.wine_menu.producer}),$.wine_menu?.vintage_year&&e.jsxs("div",{className:"text-muted-foreground",children:["Jahrgang: ",$.wine_menu.vintage_year]})]})]}),T&&e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{htmlFor:"quantity",children:"Menge"}),e.jsx(P,{id:"quantity",type:"number",min:"0",step:"0.1",value:Ne,onChange:t=>we(parseFloat(t.target.value)||0)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{htmlFor:"editUnit",children:"Einheit"}),e.jsxs(Y,{value:mt,onValueChange:Ke,children:[e.jsx(X,{children:e.jsx(ee,{placeholder:"Einheit wählen"})}),e.jsxs(te,{className:"z-[100000]",children:[e.jsx(q,{value:"Stk",children:"Stück"}),e.jsx(q,{value:"kg",children:"Kilogramm (kg)"}),e.jsx(q,{value:"g",children:"Gramm (g)"}),e.jsx(q,{value:"l",children:"Liter (l)"}),e.jsx(q,{value:"ml",children:"Milliliter (ml)"})]})]})]})]}),$&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{htmlFor:"quantity",children:"Anzahl Flaschen"}),e.jsx(P,{id:"quantity",type:"number",min:"0",step:"1",value:Ne,onChange:t=>we(parseFloat(t.target.value)||0)})]}),T&&e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{htmlFor:"editPrice",children:"EK-Preis (â¬)"}),e.jsx(P,{id:"editPrice",type:"number",min:"0",step:"0.01",value:Se??"",onChange:t=>Re(t.target.value?parseFloat(t.target.value):null),placeholder:"0.00"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{htmlFor:"editPricePerQuantity",children:"Pro Menge"}),e.jsx(P,{id:"editPricePerQuantity",type:"number",min:"0",step:"1",value:ht??"",onChange:t=>xt(t.target.value?parseFloat(t.target.value):null),placeholder:"z.B. 1"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{htmlFor:"editPricePerUnit",children:"Einheit"}),e.jsxs(Y,{value:pt,onValueChange:gt,children:[e.jsx(X,{children:e.jsx(ee,{placeholder:"Wählen"})}),e.jsxs(te,{className:"z-[100000]",children:[e.jsx(q,{value:"Stk",children:"Stück"}),e.jsx(q,{value:"kg",children:"kg"}),e.jsx(q,{value:"l",children:"Liter"})]})]})]})]}),$&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{htmlFor:"editWinePrice",children:"EK-Preis (â¬)"}),e.jsx(P,{id:"editWinePrice",type:"number",min:"0",step:"0.01",value:Se??"",onChange:t=>Re(t.target.value?parseFloat(t.target.value):null),placeholder:"0.00"})]}),T&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{htmlFor:"editStorageLocation",children:"Lagerort"}),e.jsx(P,{id:"editStorageLocation",value:_t,onChange:t=>ft(t.target.value),placeholder:"z.B. Kühlhaus, Lager A..."})]}),$&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{htmlFor:"editStorageAreaId",children:"Regal"}),e.jsxs(Y,{value:jt,onValueChange:vt,children:[e.jsx(X,{children:e.jsx(ee,{placeholder:"Regal wählen"})}),e.jsx(te,{className:"z-[100000]",children:Pe.map(t=>e.jsxs(q,{value:t.id,children:[t.code," - ",t.display_name]},t.id))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{htmlFor:"ean",children:"EAN-Code"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(P,{id:"ean",type:"text",value:B,onChange:t=>{Oe(t.target.value),ke("")},placeholder:"mind. 4 Ziffern (z.B. 1234)",className:`flex-1 ${Ce?"border-destructive":""}`}),e.jsxs(j,{type:"button",variant:"outline",onClick:As,className:"whitespace-nowrap",children:[e.jsx(pn,{className:"h-4 w-4 mr-2"}),"Generieren"]})]}),Ce&&e.jsx("p",{className:"text-sm text-destructive",children:Ce}),B&&!Ce&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[B.length,"/13 Zeichen"]}),B&&e.jsxs(j,{type:"button",variant:"secondary",onClick:zs,disabled:bt,className:"w-full",children:[e.jsx(tt,{className:"h-4 w-4 mr-2"}),bt?"Drucke...":"Code drucken (Brother P-touch)"]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{htmlFor:"notes",children:"Notizen"}),e.jsx(Hs,{id:"notes",value:Ve,onChange:t=>Ge(t.target.value),placeholder:"Notizen eingeben...",rows:3})]})]}),e.jsxs(ct,{className:"gap-2",children:[e.jsx(j,{variant:"destructive",onClick:()=>Me(!0),children:"Löschen"}),e.jsx(j,{variant:"outline",onClick:()=>xe(!1),children:"Abbrechen"}),e.jsx(j,{onClick:$s,children:"Speichern"})]})]})}),e.jsx("canvas",{ref:js,style:{display:"none"}}),e.jsx(Js,{open:gs,onOpenChange:Me,children:e.jsxs(Ys,{className:"z-[100000]",children:[e.jsxs(Xs,{children:[e.jsx(en,{children:"Wirklic
154h löschen?"}),e.jsxs(tn,{children:[T?`Möchten Sie "${T.inventory_items?.name}" wirklich aus dieser Inventur löschen?`:$?`Möchten Sie "${$.wine_menu?.name_de}" wirklich aus dieser Inventur löschen?`:"",e.jsx("br",{}),"Diese Aktion kann nicht rückgängig gemacht werden."]})]}),e.jsxs(sn,{children:[e.jsx(nn,{children:"Abbrechen"}),e.jsx(rn,{onClick:Ds,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Löschen"})]})]})}),e.jsx(it,{open:!!R,onOpenChange:t=>{t||(ye(null),be(null))},children:e.jsxs(at,{children:[e.jsx(ot,{children:e.jsx(lt,{children:"Diesem Schlachtcharge ist noch kein Inventurartikel zugeordnet."})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Charge ",e.jsx("span",{className:"font-mono",children:R?.lotCode}),R?.label?` · ${R.label}`:"",R?.quantity?` · ${R.quantity} ${R.unit??""}`:""]}),e.jsx(cn,{value:pe,placeholder:"Inventurartikel suchen â¦",onChange:t=>be(t)})]}),e.jsxs(ct,{children:[e.jsx(j,{variant:"outline",onClick:()=>{ye(null),be(null)},children:"Abbrechen"}),e.jsx(j,{disabled:!pe||!R?.allocationId,onClick:async()=>{if(!(!R||!pe))try{await on(R.allocationId,pe);const t=R,s=pe;ye(null),be(null),Qt({kind:"slaughter_allocation",item_id:s,item_name:null,batch_id:null,allocation_id:t.allocationId,lot_code:t.lotCode,allocation_label:t.label,allocation_quantity:t.quantity,allocation_unit:t.unit},t.lotCode)}catch(t){k({title:"Zuordnung fehlgeschlagen",description:t instanceof Error?t.message:"Unbekannter Fehler",variant:"destructive"})}},children:"Zuordnen und weiter"})]})]})})]})}export{Gn 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.