1import{cc as pt,E as ft,i as jt,r as l,d as ee,k as te,j as e,Q as _,cs as se,$ as E,L as Xe,B as u,g as ae,an as yt,X as gt,al as vt,F as Nt,G as bt,H as wt,ap as kt,I as h,a2 as St,a3 as Ct,a4 as It,a5 as At,a6 as Qe,bD as Ke,J as v,a0 as Pt,T as Tt,A as He,p as Me,q as ze,s as Ue,t as Ge,v as We,w as Ot,z as ie,y as N,aq as $t}from"./index-bciIWLG1.js";import{C as k,d as S,a as P,b as T,c as ne,e as Dt}from"./card-DTK7dWeM.js";import{A as X,a as re,b as Ve}from"./alert-BI7vdOL0.js";import{T as qt,a as Lt,b as Je,c as O,d as Bt,e as $}from"./table-D9fehyv1.js";import{R as Rt,a as Ye}from"./radio-group-CIku3Aol.js";import{C as Ft,a as _t,b as Et,c as Xt,d as Qt,e as Kt}from"./command-D67Cj6NB.js";import{C as Ze}from"./checkbox-DGC0w7r0.js";import{H as Ht}from"./history-03mYw9qe.js";import{C as Mt}from"./chevron-left-D1VXNzOx.js";import{L as zt}from"./languages-DvKvd4ou.js";import{C as et}from"./circle-check-COMaVQbo.js";import{S as tt}from"./sparkles-RJSVg2WT.js";import{P as st}from"./plus-U5Z5nz4N.js";import{M as Ut}from"./minus-CVhFC0Oq.js";import{T as Gt}from"./trash-2-D3zE-Sp8.js";import{S as Wt}from"./save-MlEML8AI.js";import{S as at}from"./send-DzPr_O9y.js";import{S as Vt}from"./skip-forward-COthT-F7.js";const Jt={en:{back:"All Submissions",of:"of",invoice:"Invoice",items:"Order Items",addItem:"Add Item",addItemDesc:"Search by product name, SKU code, or barcode",searchPlaceholder:"Search inventory...",noItems:"No items found",quantity:"Quantity",unitPrice:"Unit Price",subtotal:"Subtotal",total:"Order Total",delivery:"Delivery Details",fulfillment:"Fulfillment Type",deliveryOption:"Home Delivery",collection:"Collection from Warehouse",payment:"Payment Method",prepaid:"Prepaid",cod:"Cash on Delivery",recipientName:"Recipient Name",recipientPhone:"Phone",recipientEmail:"Email",address:"Address",city:"City",country:"Country",reference:"Reference",invoiceNumber:"Invoice Number",instructions:"Special Instructions",save:"Save Draft",confirm:"Confirm & Submit",confirmNext:"Confirm & Next",confirmFinish:"Confirm & Finish",cancel:"Skip This Page",cancelDesc:"If this page isn't a real order, skip it.",saved:"Draft saved",confirmed:"Order confirmed",confirmFailed:"Could not confirm order",submittedProcessing:"Submitted â still processing",submittedProcessingDesc:"We received your order and it's being sent to our warehouse. Check âMy submissionsâ in a moment â please don't re-upload it.",notFound:"This draft is no longer available.",languageToggle:"Ø§ÙØ¹Ø±Ø¨ÙØ©",history:"My Submissions",page:"Page",skipNotice:"This invoice was skipped â it won't be submitted.",syncedNotice:"This order has already been confirmed and sent to the warehouse.",progressLabel:(c,r)=>`Reviewed ${c} of ${r}`,confirmSummaryTitle:"Ready to confirm",confirmSummary:c=>`${c} item${c===1?"":"s"} will be sent to the warehouse.`,addedHint:"Tip: tap a product to adjust quantity below.",prevPending:"Previous pending",nextPending:"Next pending",extractionTitle:"What NBOX AI read from your document",totalExtracted:"Items found",matched:"Matched",unmatched:"Not in inventory",notes:"Notes from NBOX AI",unmatchedTitle:"Items NBOX AI couldn't match",unmatchedDesc:"These products were on the document but aren't in our warehouse inventory. If you need them, please add them manually below.",code:"Code",description:"Description",poweredBy:"Powered by NBOX Logistics",orderLabel:"Order",shortfallTitle:"This order may be placed on hold",shortfallIntro:"Your LPO orders are sent to the warehouse one after another, and earlier orders use up the available stock first. There isn't enough inventory left for these items on this order:",shortfallItemLine:(c,r,m)=>`need ${c}, only ${r} left in stock (short by ${m})`,shortfallRecommend:"The order with short quantities will be placed ON HOLD. We highly recommend you remove the SKU with the short quantity to avoid delaying the preparation of the rest of the items in the order, or cancel that order.",shortfallUnknown:c=>`We couldn't verify warehouse stock for: ${c}
1. Our team will confirm availability for these.`,shortfallAck:"I understand this order may be placed on hold for insufficient stock, and I want to send it anyway.",shortfallSendAnyway:"Send anyway",shortfallGoBack:"Go back & edit",aiDisclaimerTitle:"Please check every order before confirming",aiDisclaimerBody:"NBOX AI Scanning has read the items on your document automatically. It is your responsibility to check that every item and quantity was captured correctly before reviewing and confirming each order. NBOX will not be held responsible for any items that have been wrongly scanned and then confirmed by you through this flow.",aiDisclaimerAgree:"I understand â start reviewing",aiAckLabel:"I have checked that the items and quantities scanned by NBOX AI on this order are correct. I understand NBOX is not responsible for wrongly scanned items that I confirm.",aiAckRequiredHint:"Tick the box above to enable confirmation."},ar:{back:"جÙ
ÙØ¹ Ø§ÙØ·Ùبات",of:"Ù
Ù",invoice:"ÙØ§ØªÙرة",items:"بÙÙØ¯ Ø§ÙØ·Ùب",addItem:"Ø¥Ø¶Ø§ÙØ© Ø¨ÙØ¯",addItemDesc:"Ø§Ø¨ØØ« باسÙ
اÙÙ
ÙØªØ¬ أ٠رÙ
ز SKU Ø£Ù Ø§ÙØ¨Ø§Ø±ÙÙØ¯",searchPlaceholder:"Ø§Ø¨ØØ« Ù٠اÙÙ
خزÙÙ...",noItems:"ÙØ§ ØªÙØ¬Ø¯ Ù
ÙØªØ¬Ø§Øª",quantity:"اÙÙÙ
ÙØ©",unitPrice:"سعر اÙÙØØ¯Ø©",subtotal:"اÙÙ
جÙ
ÙØ¹ اÙÙØ±Ø¹Ù",total:"إجÙ
اÙÙ Ø§ÙØ·Ùب",delivery:"ØªÙØ§ØµÙÙ Ø§ÙØªØ³ÙÙÙ
",fulfillment:"ÙÙØ¹ Ø§ÙØªØ³ÙÙÙ
",deliveryOption:"ØªÙØµÙÙ ÙÙÙ
ÙØ²Ù",collection:"Ø§Ø³ØªÙØ§Ù
Ù
٠اÙÙ
Ø³ØªÙØ¯Ø¹",payment:"طرÙÙØ© Ø§ÙØ¯Ùع",prepaid:"Ù
دÙÙØ¹ Ù
Ø³Ø¨ÙØ§Ù",cod:"Ø§ÙØ¯Ùع Ø¹ÙØ¯ Ø§ÙØ§Ø³ØªÙاÙ
",recipientName:"اسÙ
اÙÙ
ستÙÙ
",recipientPhone:"اÙÙØ§ØªÙ",recipientEmail:"Ø§ÙØ¨Ø±Ùد Ø§ÙØ¥ÙÙØªØ±ÙÙÙ",address:"Ø§ÙØ¹ÙÙØ§Ù",city:"اÙÙ
دÙÙØ©",country:"Ø§ÙØ¯ÙÙØ©",reference:"اÙÙ
رجع",invoiceNumber:"رÙÙ
اÙÙØ§ØªÙرة",instructions:"تعÙÙÙ
ات خاصة",save:"ØÙظ ÙÙ
Ø³ÙØ¯Ø©",confirm:"تأÙÙØ¯ ÙØ¥Ø±Ø³Ø§Ù",confirmNext:"تأÙÙØ¯ ÙØ§ÙتاÙÙ",confirmFinish:"تأÙÙØ¯ ÙØ¥ÙÙØ§Ø¡",cancel:"ØªØ®Ø·Ù ÙØ°Ù Ø§ÙØµÙØØ©",cancelDesc:"إذا ÙÙ
تÙÙ ÙØ°Ù Ø§ÙØµÙØØ© Ø·ÙØ¨Ø§Ù ØÙÙÙÙØ§ÙØ ÙÙ
ÙÙ٠تخطÙÙØ§.",saved:"تÙ
ØÙظ اÙÙ
Ø³ÙØ¯Ø©",confirmed:"تÙ
تأÙÙØ¯ Ø§ÙØ·Ùب",confirmFailed:"تعذر تأÙÙØ¯ Ø§ÙØ·Ùب",submittedProcessing:"تÙ
Ø§ÙØ¥Ø±Ø³Ø§Ù â ÙÙØ¯ اÙÙ
Ø¹Ø§ÙØ¬Ø©",submittedProcessingDesc:"ÙÙØ¯ استÙÙ
ÙØ§ Ø·ÙØ¨Ù ÙÙØ¬Ø±Ù إرساÙ٠إÙÙ Ù
Ø³ØªÙØ¯Ø¹Ùا. تØÙÙ Ù
Ù âØ·ÙØ¨Ø§ØªÙ اÙÙ
ÙØ±Ø³ÙÙØ©â بعد ÙØØ¸Ø§Øª â ÙØ±Ø¬Ù عدÙ
إعادة Ø±ÙØ¹Ù.",notFound:"ÙØ°Ù اÙÙ
Ø³ÙØ¯Ø© ÙÙ
تعد Ù
ØªØ§ØØ©.",languageToggle:"English",history:"Ø·ÙØ¨Ø§ØªÙ Ø§ÙØ³Ø§Ø¨ÙØ©",page:"Ø§ÙØµÙØØ©",skipNotice:"تÙ
ØªØ®Ø·Ù ÙØ°Ù اÙÙØ§ØªÙرة â ÙÙ ÙØªÙ
إرساÙÙØ§.",syncedNotice:"تÙ
تأÙÙØ¯ ÙØ°Ø§ Ø§ÙØ·Ùب ÙØ¥Ø±Ø³Ø§ÙÙ ÙÙÙ
Ø³ØªÙØ¯Ø¹.",progressLabel:(c,r)=>`تÙ
ت Ù
راجعة ${c} Ù
Ù ${r}`,confirmSummaryTitle:"Ø¬Ø§ÙØ² ÙÙØªØ£ÙÙØ¯",confirmSummary:c=>`Ø³ÙØªÙ
إرسا٠${c} Ø¨ÙØ¯ Ø¥Ù٠اÙÙ
Ø³ØªÙØ¯Ø¹.`,addedHint:"ÙØµÙØØ©: اضغط عÙ٠اÙÙ
ÙØªØ¬ ÙØªØ¹Ø¯Ù٠اÙÙÙ
ÙØ© Ø¨Ø§ÙØ£Ø³ÙÙ.",prevPending:"Ø§ÙØ³Ø§Ø¨Ù",nextPending:"Ø§ÙØªØ§ÙÙ",extractionTitle:"Ù
ا ÙØ±Ø£Ù NBOX AI Ù
٠اÙÙ
Ø³ØªÙØ¯",totalExtracted:"Ø§ÙØ¨ÙÙØ¯ اÙÙ
ستخرجة",matched:"تÙ
اÙÙ
Ø·Ø§Ø¨ÙØ©",unmatched:"ØºÙØ± Ù
ÙØ¬Ùد Ù٠اÙÙ
خزÙÙ",notes:"Ù
ÙØ§ØØ¸Ø§Øª NBOX AI",unmatchedTitle:"بÙÙØ¯ ÙÙ
ÙØªÙ
ÙÙ NBOX AI Ù
Ù Ù
Ø·Ø§Ø¨ÙØªÙا",unmatchedDesc:"ÙØ°Ù اÙÙ
ÙØªØ¬Ø§Øª ÙØ±Ø¯Øª Ù٠اÙÙ
Ø³ØªÙØ¯ ÙÙÙÙØ§ ØºÙØ± Ù
تÙÙØ±Ø© ÙÙ Ù
خزÙ٠اÙÙ
Ø³ØªÙØ¯Ø¹. إذا ÙÙØª Ø¨ØØ§Ø¬Ø© Ø¥ÙÙÙØ§Ø ÙÙ
ÙÙÙ Ø¥Ø¶Ø§ÙØªÙا ÙØ¯ÙÙØ§Ù Ø¨Ø§ÙØ£Ø³ÙÙ.",code:"Ø§ÙØ±Ù
ز",description:"اÙÙØµÙ",poweredBy:"Ù
شغÙÙ Ø¨ÙØ§Ø³Ø·Ø© NBOX Logistics",orderLabel:"Ø·ÙØ¨",shortfallTitle:"ÙØ¯ ÙÙØ¶Ø¹ ÙØ°Ø§ Ø§ÙØ·Ùب ÙÙØ¯ Ø§ÙØ§Ùتظار",shortfallIntro:"ØªÙØ±Ø³ÙÙ Ø·ÙØ¨Ø§Øª Ø£Ù
ر Ø§ÙØ´Ø±Ø§Ø¡ Ø¥Ù٠اÙÙ
Ø³ØªÙØ¯Ø¹ ÙØ§ØØ¯Ø§Ù تÙÙ Ø§ÙØ¢Ø®Ø±Ø ÙØªØ³ØªÙÙÙ Ø§ÙØ·Ùبات Ø§ÙØ£ÙÙ٠اÙÙ
خزÙ٠اÙÙ
ØªØ§Ø Ø£ÙÙØ§Ù. ÙØ§ ÙØªØ¨ÙÙÙ Ù
خزÙÙ ÙØ§ÙÙ ÙÙØ°Ù Ø§ÙØ£ØµÙا٠ÙÙ ÙØ°Ø§ Ø§ÙØ·Ùب:",shortfallItemLine:(c,r,m)=>`اÙÙ
Ø·ÙÙØ¨ ${c}Ø Ø§ÙÙ
تبÙÙÙ ${r} ÙÙØ· Ù٠اÙÙ
خزÙÙ (ÙÙØµ ${m})`,shortfallRecommend:"Ø³ÙØªÙ
ÙØ¶Ø¹ Ø§ÙØ·Ùب Ø§ÙØ°Ù ÙØØªÙ٠عÙÙ ÙÙ
ÙØ§Øª ÙØ§Ùصة ÙÙØ¯ Ø§ÙØ§Ùتظار. ÙÙØµÙ بشدة Ø¨Ø¥Ø²Ø§ÙØ© Ø§ÙØµÙ٠ذ٠اÙÙÙ
ÙØ© اÙÙØ§Ùصة ÙØªØ¬ÙÙØ¨ ØªØ£Ø®ÙØ± تجÙÙØ² باÙÙ Ø£ØµÙØ§Ù Ø§ÙØ·ÙØ¨Ø Ø£Ù Ø¥ÙØºØ§Ø¡ ذÙÙ Ø§ÙØ·Ùب.",shortfallUnknown:c=>`ØªØ¹Ø°ÙØ± Ø§ÙØªØÙÙ Ù
Ù Ù
خزÙ٠اÙÙ
Ø³ØªÙØ¯Ø¹ ÙÙ: ${c}. Ø³ÙØ¤Ùد ÙØ±ÙÙÙØ§ تÙÙÙØ±Ùا.`,shortfallAck:"Ø£ÙÙÙ
Ø£Ù ÙØ°Ø§ Ø§ÙØ·Ùب ÙØ¯ ÙÙØ¶Ø¹ ÙÙØ¯ Ø§ÙØ§Ùتظار بسبب ÙÙØµ اÙÙ
خزÙÙØ ÙØ£Ø±ØºØ¨ Ù٠إرساÙ٠عÙÙ Ø£Ù ØØ§Ù.",shortfallSendAnyway:"إرسا٠عÙÙ Ø£Ù ØØ§Ù",shortfallGoBack:"Ø§ÙØ¹Ùدة ÙØ§ÙتعدÙÙ",aiDisclaimerTitle:"ÙØ±Ø¬Ù Ø§ÙØªØÙÙ Ù
Ù ÙÙ Ø·ÙØ¨ ÙØ¨Ù Ø§ÙØªØ£ÙÙØ¯",aiDisclaimerBody:"ÙØ§Ù
NBOX AI Ø¨ÙØ±Ø§Ø¡Ø© بÙÙØ¯ Ù
Ø³ØªÙØ¯Ù تÙÙØ§Ø¦ÙاÙ. ØªÙØ¹ عÙ٠عاتÙÙ Ù
سؤÙÙÙØ© Ø§ÙØªØÙÙ Ù
٠أ٠جÙ
ÙØ¹ Ø§ÙØ¨ÙÙØ¯ ÙØ§ÙÙÙ
ÙØ§Øª ÙØ¯ تÙ
Ø§ÙØªÙØ§Ø·ÙØ§ بشÙ٠صØÙØ ÙØ¨Ù Ù
راجعة ÙØªØ£ÙÙØ¯ ÙÙ Ø·ÙØ¨. Ù٠تتØÙ
Ù NBOX Ø£Ù Ù
سؤÙÙÙØ© ع٠أ٠بÙÙØ¯ تÙ
Ù
سØÙا بشÙ٠خاطئ Ø«Ù
تأÙÙØ¯Ùا Ù
Ù ÙØ¨Ù٠عبر ÙØ°Ù Ø§ÙØ®Ø·Ùات.",aiDisclaimerAgree:"Ø£ÙÙÙ
ذÙÙ â Ø§Ø¨Ø¯Ø£ اÙÙ
راجعة",aiAckLabel:"ÙÙØ¯ تØÙÙØª Ù
Ù ØµØØ© Ø§ÙØ¨ÙÙØ¯ ÙØ§ÙÙÙ
ÙØ§Øª Ø§ÙØªÙ ÙØ±Ø£Ùا NBOX AI ÙÙ ÙØ°Ø§ Ø§ÙØ·Ùب. Ø£ÙÙÙ
Ø£Ù NBOX ØºÙØ± Ù
سؤÙÙØ© Ø¹Ù Ø§ÙØ¨ÙÙØ¯ اÙÙ
Ù
سÙ
1ØØ© بشÙ٠خاطئ Ø§ÙØªÙ Ø£ÙÙÙ
بتأÙÙØ¯Ùا.",aiAckRequiredHint:"ضع Ø¹ÙØ§Ù
Ø© Ù٠اÙÙ
ربع Ø£Ø¹ÙØ§Ù ÙØªÙعÙÙ Ø§ÙØªØ£ÙÙØ¯."}};function js(){var _e;const c=pt(),r=c.token,m=c.uploadBatchId,Q=c.lpoOrderId,[,b]=ft(),{toast:C}=jt(),[K,it]=l.useState("en"),s=Jt[K],H=K==="ar"?"rtl":"ltr",[nt,M]=l.useState(!1),[z,le]=l.useState(""),[j,D]=l.useState([]),[f,ce]=l.useState("collection"),[de,oe]=l.useState("prepaid"),[me,ue]=l.useState(""),[he,xe]=l.useState(""),[pe,fe]=l.useState(""),[je,ye]=l.useState(""),[ge,ve]=l.useState(""),[Ne,be]=l.useState("Qatar"),[we,ke]=l.useState(""),[Se,Ce]=l.useState(""),[g,U]=l.useState(null),[Ie,q]=l.useState(!1),[rt,Ae]=l.useState(!1),[G,Pe]=l.useState(!1),{data:i}=ee({queryKey:["/api/client-lpo",r,"batches",m]});l.useEffect(()=>{if(!i||!m||!i.orders.some(d=>(d.status==="draft"||d.status==="failed")&&d.clientReviewStatus!=="cancelled"))return;let a=!1;try{a=sessionStorage.getItem(`nbox-lpo-ai-disclaimer-${m}`)==="1"}catch{}a||Ae(!0)},[i,m]);function lt(){try{sessionStorage.setItem(`nbox-lpo-ai-disclaimer-${m}`,"1")}catch{}Ae(!1)}const x=Q||(i==null?void 0:i.nextPendingOrderId)||void 0;l.useEffect(()=>{!i||Q||(i.nextPendingOrderId?b(`/client-lpo/${r}/batch/${m}/${i.nextPendingOrderId}`,{replace:!0}):b(`/client-lpo/${r}/submissions`,{replace:!0}))},[i,Q,b,r,m]);const{data:n,isLoading:Te}=ee({queryKey:["/api/client-lpo",r,"batches",m,"orders",x],enabled:!!x}),{data:ct=[]}=ee({queryKey:["/api/client-lpo",r,"skus"]});l.useEffect(()=>{n&&(D(n.selectedSkus||[]),ce(n.fulfillmentType||"collection"),oe(n.paymentMethod||"prepaid"),ue(n.recipientName||""),xe(n.recipientPhone||""),fe(n.recipientEmail||""),ye(n.deliveryAddress1||""),ve(n.deliveryCity||""),be(n.deliveryCountry||"Qatar"),ke(n.clientReference||""),Ce(n.detailedInstructions||""),Pe(!1))},[n==null?void 0:n.id]);const W=l.useMemo(()=>j.reduce((t,a)=>t+a.subtotal,0),[j]);function Oe(){return{selectedSkus:j,fulfillmentType:f,paymentMethod:de,recipientName:f==="delivery"?me:void 0,recipientPhone:f==="delivery"?he:void 0,recipientEmail:f==="delivery"?pe:void 0,deliveryAddress1:f==="delivery"?je:void 0,deliveryCity:f==="delivery"?ge:void 0,deliveryCountry:f==="delivery"?Ne:void 0,clientReference:we,detailedInstructions:Se,orderSubtotal:W.toString(),orderTotal:W.toString()}}const V=`/api/client-lpo/${r}/batches/${m}/orders`,J=["/api/client-lpo",r,"batches",m,"orders",x],Y=["/api/client-lpo",r,"batches",m],Z=te({mutationFn:async()=>{if(!x)throw new Error("No order");return await ie("PATCH",`${V}/${x}`,Oe())},onSuccess:()=>{C({title:s.saved}),N.invalidateQueries({queryKey:J}),N.invalidateQueries({queryKey:Y})},onError:t=>C({title:s.confirmFailed,description:t.message,variant:"destructive"})}),$e=te({mutationFn:async()=>{if(!x)throw new Error("No order");return await ie("POST",`${V}/${x}/cancel`)},onSuccess:()=>{N.invalidateQueries({queryKey:J}),N.invalidateQueries({queryKey:Y}),De()}}),w=te({mutationFn:async t=>{if(!x)throw new Error("No order");return await ie("POST",`${V}/${x}/confirm`,{...Oe(),aiScanAcknowledged:!0,acknowledgeStockShortfalls:(t==null?void 0:t.acknowledge)===!0})},onSuccess:t=>{t!=null&&t.pending?C({title:s.submittedProcessing,description:s.submittedProcessingDesc}):C({title:s.confirmed}),U(null),q(!1),N.invalidateQueries({queryKey:J}),N.invalidateQueries({queryKey:Y}),N.invalidateQueries({queryKey:["/api/client-lpo",r,"submissions"]}),De()},onError:t=>{var a;if(t instanceof $t&&t.status===409&&((a=t.data)!=null&&a.hasShortfalls)){q(!1),U(t.data);return}C({title:s.confirmFailed,description:t instanceof Error?t.message:String(t),variant:"destructive"})}});function De(){const t=(i==null?void 0:i.orders.filter(a=>a.id!==x&&a.status!=="synced"&&a.clientReviewStatus!=="cancelled"))||[];t.length>0?b(`/client-lpo/${r}/batch/${m}/${t[0].id}`):b(`/client-lpo/${r}/submissions`)}function dt(t){if(j.some(d=>d.sku_code===t.sku_code)){M(!1);return}const a=t.unit_price||0;D(d=>[...d,{sku_code:t.sku_code,sku_id:t.sku_id,name:t.name,quantity:1,unit_price:a,subtotal:a,available_quantity:t.available_quantity}]),M(!1),le("")}function qe(t,a){D(d=>d.map(p=>{if(p.sku_code!==t)return p;const y=Math.max(1,p.quantity+a);return{...p,quantity:y,subtotal:p.unit_price*y}}))}function ot(t){D(a=>a.filter(d=>d.sku_code!==t))}if(Te||!n)return e.jsx("div",{className:"min-h-screen flex items-center justify-center",children:Te?e.jsx(_,{className:"h-8 w-8 animate-spin text-muted-foreground"}):e.jsx(k,{className:"max-w-md w-full m-4",children:e.jsxs(S,{className:"py-8 text-center space-y-3",children:[e.jsx("img",{src:se,alt:"NBOX Logistics",className:"h-10 w-auto mx-auto","data-testid":"img-nbox-logo-notfound"}),e.jsx(E,{className:"h-10 w-10 text-destructive mx-auto"}),e.jsx("p",{children:s.notFound}),e.jsx(Xe,{href:`/client-lpo/${r}/submissions`,children:e.jsx(u,{variant:"outline",className:"mt-2",children:s.history})})]})})});const Le=n.clientReviewStatus==="cancelled",Be=n.status==="synced",o=Le||Be,Re=(i==null?void 0:i.orderCount)||1,mt=(i==null?void 0:i.orders.filter(t=>t.status==="synced"||t.clientReviewStatus==="cancelled").length)||0,ut=(i==null?void 0:i.orders.findIndex(t=>t.id===n.id))??0,ht=((i==null?void 0:i.orders.filter(t=>
1t.id!==n.id&&t.status!=="synced"&&t.clientReviewStatus!=="cancelled"))||[]).length===0,L=(i==null?void 0:i.orders.filter(t=>t.status!=="synced"&&t.clientReviewStatus!=="cancelled"))||[],I=L.findIndex(t=>t.id===n.id),B=I>0?L[I-1].id:void 0,R=I>=0&&I<L.length-1?L[I+1].id:void 0;function Fe(t){b(`/client-lpo/${r}/batch/${m}/${t}`)}const xt=ct.filter(t=>{var d,p,y;if(!z.trim())return!0;const a=z.toLowerCase();return((d=t.sku_code)==null?void 0:d.toLowerCase().includes(a))||((p=t.name)==null?void 0:p.toLowerCase().includes(a))||((y=t.barcode)==null?void 0:y.toLowerCase().includes(a))}).slice(0,100);return e.jsx("div",{dir:H,className:"min-h-screen bg-background",children:e.jsxs("div",{className:"mx-auto max-w-5xl p-4 sm:p-6 space-y-6",children:[e.jsx("div",{className:"flex items-center justify-center pt-2 pb-1",children:e.jsx("img",{src:se,alt:"NBOX Logistics",className:"h-10 sm:h-12 w-auto","data-testid":"img-nbox-logo"})}),e.jsxs("div",{className:"flex items-start justify-between gap-3 flex-wrap",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1 flex-wrap",children:[e.jsx(Xe,{href:`/client-lpo/${r}/submissions`,children:e.jsxs(u,{variant:"ghost",size:"sm","data-testid":"link-back",children:[e.jsx(Ht,{className:"h-4 w-4 mr-1.5"}),s.back]})}),e.jsxs(ae,{variant:"secondary","data-testid":"badge-progress",children:[s.page," ",ut+1," ",s.of," ",Re]}),e.jsx(ae,{variant:"outline",children:s.progressLabel(mt,Re)}),(B||R)&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(u,{variant:"outline",size:"sm",disabled:!B,onClick:()=>B&&Fe(B),"data-testid":"button-prev-pending",title:s.prevPending,children:e.jsx(Mt,{className:"h-4 w-4"})}),e.jsx(u,{variant:"outline",size:"sm",disabled:!R,onClick:()=>R&&Fe(R),"data-testid":"button-next-pending",title:s.nextPending,children:e.jsx(yt,{className:"h-4 w-4"})})]})]}),e.jsx("h1",{className:"text-xl sm:text-2xl font-bold tracking-tight","data-testid":"text-order-id",children:n.lpoOrderId}),((_e=n.client)==null?void 0:_e.companyName)&&e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:n.client.companyName})]}),e.jsxs(u,{variant:"outline",size:"sm",onClick:()=>it(K==="en"?"ar":"en"),"data-testid":"button-toggle-language",children:[e.jsx(zt,{className:"h-4 w-4 mr-1.5"}),s.languageToggle]})]}),Le&&e.jsxs(X,{variant:"destructive",children:[e.jsx(gt,{className:"h-4 w-4"}),e.jsx(re,{children:s.skipNotice})]}),Be&&e.jsxs(X,{children:[e.jsx(et,{className:"h-4 w-4"}),e.jsx(re,{children:s.syncedNotice})]}),(()=>{const t=n.extractedData;if(!t)return null;const a=n.matchedSkuCount??0,d=t.unmatchedSKUs??[],p=typeof t.totalExtracted=="number"?t.totalExtracted:a+d.length,y=t.customerName||n.extractedCustomerName,Ee=(t.issues??[]).filter(Boolean);return e.jsxs(k,{"data-testid":"card-extraction-summary",children:[e.jsxs(P,{children:[e.jsxs(T,{className:"flex items-center gap-2",children:[e.jsx(tt,{className:"h-5 w-5 text-primary"}),s.extractionTitle]}),y&&e.jsx(ne,{"data-testid":"text-extracted-customer",children:y})]}),e.jsxs(S,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{className:"rounded-md border p-3",children:[e.jsx("div",{className:"text-2xl font-bold","data-testid":"stat-total-extracted",children:p}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s.totalExtracted})]}),e.jsxs("div",{className:"rounded-md border p-3",children:[e.jsx("div",{className:"text-2xl font-bold text-green-600 dark:text-green-500","data-testid":"stat-matched",children:a}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s.matched})]}),e.jsxs("div",{className:"rounded-md border p-3",children:[e.jsx("div",{className:`text-2xl font-bold ${d.length>0?"text-amber-600 dark:text-amber-500":""}`,"data-testid":"stat-unmatched",children:d.length}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s.unmatched})]})]}),Ee.length>0&&e.jsxs("div",{className:"text-xs text-muted-foreground","data-testid":"text-extraction-notes",children:[e.jsx("div",{className:"font-medium mb-1",children:s.notes}),e.jsx("ul",{className:"list-disc ps-4 space-y-0.5",children:Ee.map((A,F)=>e.jsx("li",{children:A},F))})]}),d.length>0&&e.jsxs("div",{className:"space-y-2","data-testid":"section-unmatched-skus",children:[e.jsxs(X,{children:[e.jsx(E,{className:"h-4 w-4"}),e.jsx(re,{children:s.unmatchedTitle}),e.jsx(Ve,{children:s.unmatchedDesc})]}),e.jsx("div",{className:"rounded-md border overflow-hidden",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-start p-2 font-medium",children:s.code}),e.jsx("th",{className:"text-start p-2 font-medium",children:s.description}),e.jsx("th",{className:"text-end p-2 font-medium w-16",children:s.quantity})]})}),e.jsx("tbody",{children:d.map((A,F)=>e.jsxs("tr",{className:"border-t","data-testid":`row-unmatched-${F}`,children:[e.jsx("td",{className:"p-2 font-mono text-xs",children:A.extractedCode||"â"}),e.jsx("td",{className:"p-2",children:A.extractedDescription||"â"}),e.jsx("td",{className:"p-2 text-end",children:A.quantity})]},F))})]})})]})]})]})})(),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-3",children:[e.jsxs("div",{className:"lg:col-span-2 space-y-6",children:[e.jsxs(k,{children:[e.jsxs(P,{children:[e.jsxs(T,{className:"flex items-center gap-2",children:[e.jsx(vt,{className:"h-5 w-5"}),s.items]}),e.jsx(ne,{children:s.addItemDesc})]}
1),e.jsxs(S,{className:"space-y-4",children:[!o&&e.jsxs(Nt,{open:nt,onOpenChange:M,children:[e.jsx(bt,{asChild:!0,children:e.jsxs(u,{variant:"outline",className:"w-full justify-start","data-testid":"button-add-sku",children:[e.jsx(st,{className:"h-4 w-4 mr-2"}),s.addItem]})}),e.jsx(wt,{className:"w-[--radix-popover-trigger-width] p-0",align:"start",children:e.jsxs(Ft,{shouldFilter:!1,children:[e.jsx(_t,{placeholder:s.searchPlaceholder,value:z,onValueChange:le,"data-testid":"input-sku-search"}),e.jsxs(Et,{children:[e.jsx(Xt,{children:s.noItems}),e.jsx(Qt,{children:xt.map(t=>e.jsxs(Kt,{value:t.sku_code,onSelect:()=>dt(t),"data-testid":`option-sku-${t.sku_code}`,children:[e.jsxs("div",{className:"flex flex-col flex-1 min-w-0",children:[e.jsx("span",{className:"truncate font-medium",children:t.name}),e.jsxs("span",{className:"text-xs text-muted-foreground font-mono",children:[t.sku_code,t.barcode?` · ${t.barcode}`:""]})]}),e.jsx(ae,{variant:"secondary",className:"ml-2 shrink-0",children:t.available_quantity})]},t.sku_code))})]})]})})]}),j.length===0?e.jsx("p",{className:"text-center text-sm text-muted-foreground py-6",children:s.noItems}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(qt,{children:[e.jsx(Lt,{children:e.jsxs(Je,{children:[e.jsx(O,{children:s.items}),e.jsx(O,{className:"text-center",children:s.quantity}),e.jsx(O,{className:"text-right",children:s.unitPrice}),e.jsx(O,{className:"text-right",children:s.subtotal}),!o&&e.jsx(O,{})]})}),e.jsx(Bt,{children:j.map(t=>e.jsxs(Je,{children:[e.jsx($,{children:e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:t.name}),e.jsx("div",{className:"text-xs text-muted-foreground font-mono",children:t.sku_code})]})}),e.jsx($,{children:e.jsxs("div",{className:"flex items-center justify-center gap-2",children:[e.jsx(u,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>qe(t.sku_code,-1),disabled:o||t.quantity<=1,"data-testid":`button-qty-down-${t.sku_code}`,children:e.jsx(Ut,{className:"h-3 w-3"})}),e.jsx("span",{className:"w-12 text-center font-medium",children:t.quantity}),e.jsx(u,{variant:"outline",size:"icon",className:"h-8 w-8",onClick:()=>qe(t.sku_code,1),disabled:o||t.available_quantity!=null&&t.quantity>=t.available_quantity,"data-testid":`button-qty-up-${t.sku_code}`,children:e.jsx(st,{className:"h-3 w-3"})})]})}),e.jsxs($,{className:"text-right",children:[t.unit_price.toFixed(2)," QAR"]}),e.jsxs($,{className:"text-right font-medium",children:[t.subtotal.toFixed(2)," QAR"]}),!o&&e.jsx($,{children:e.jsx(u,{variant:"ghost",size:"icon",className:"h-8 w-8 text-destructive",onClick:()=>ot(t.sku_code),"data-testid":`button-remove-${t.sku_code}`,children:e.jsx(Gt,{className:"h-4 w-4"})})})]},t.sku_code))})]})})]}),e.jsx(Dt,{className:"justify-end border-t pt-4",children:e.jsxs("div",{className:"text-right",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:s.total}),e.jsxs("div",{className:"text-2xl font-bold","data-testid":"text-order-total",children:[W.toFixed(2)," QAR"]})]})})]}),e.jsxs(k,{children:[e.jsx(P,{children:e.jsxs(T,{className:"flex items-center gap-2",children:[e.jsx(kt,{className:"h-5 w-5"}),s.delivery]})}),e.jsxs(S,{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{children:s.fulfillment}),e.jsxs(Rt,{value:f,onValueChange:t=>!o&&ce(t),children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ye,{value:"delivery",id:"ff-delivery",disabled:o}),e.jsx(h,{htmlFor:"ff-delivery",children:s.deliveryOption})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ye,{value:"collection",id:"ff-collection",disabled:o}),e.jsx(h,{htmlFor:"ff-collection",children:s.collection})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{children:s.payment}),e.jsxs(St,{value:de,onValueChange:t=>!o&&oe(t),disabled:o,children:[e.jsx(Ct,{"data-testid":"select-payment",children:e.jsx(It,{})}),e.jsxs(At,{children:[e.jsx(Qe,{value:"prepaid",children:s.prepaid}),e.jsx(Qe,{value:"cod",children:s.cod})]})]})]})]}),f==="delivery"&&e.jsxs(e.Fragment,{children:[e.jsx(Ke,{}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{htmlFor:"rcp-name",children:s.recipientName}),e.jsx(v,{id:"rcp-name",value:me,onChange:t=>ue(t.target.value),disabled:o,"data-testid":"input-recipient-name"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{htmlFor:"rcp-phone",children:s.recipientPhone}
1),e.jsx(v,{id:"rcp-phone",value:he,onChange:t=>xe(t.target.value),disabled:o,"data-testid":"input-recipient-phone"})]}),e.jsxs("div",{className:"space-y-2 sm:col-span-2",children:[e.jsx(h,{htmlFor:"rcp-email",children:s.recipientEmail}),e.jsx(v,{id:"rcp-email",type:"email",value:pe,onChange:t=>fe(t.target.value),disabled:o,"data-testid":"input-recipient-email"})]}),e.jsxs("div",{className:"space-y-2 sm:col-span-2",children:[e.jsx(h,{htmlFor:"addr1",children:s.address}),e.jsx(v,{id:"addr1",value:je,onChange:t=>ye(t.target.value),disabled:o,"data-testid":"input-address"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{htmlFor:"city",children:s.city}),e.jsx(v,{id:"city",value:ge,onChange:t=>ve(t.target.value),disabled:o,"data-testid":"input-city"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{htmlFor:"country",children:s.country}),e.jsx(v,{id:"country",value:Ne,onChange:t=>be(t.target.value),disabled:o,"data-testid":"input-country"})]})]})]})]})]})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs(k,{children:[e.jsx(P,{children:e.jsxs(T,{className:"flex items-center gap-2",children:[e.jsx(Pt,{className:"h-5 w-5"}),s.reference]})}),e.jsxs(S,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{htmlFor:"ref",children:s.invoiceNumber}),e.jsx(v,{id:"ref",value:we,onChange:t=>ke(t.target.value),disabled:o,"data-testid":"input-reference"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{htmlFor:"instr",children:s.instructions}),e.jsx(Tt,{id:"instr",rows:4,value:Se,onChange:t=>Ce(t.target.value),disabled:o,"data-testid":"input-instructions"})]})]})]}),!o&&e.jsxs(k,{children:[e.jsxs(P,{children:[e.jsx(T,{children:s.confirmSummaryTitle}),e.jsx(ne,{children:s.confirmSummary(j.length)})]}),e.jsxs(S,{className:"space-y-3",children:[e.jsxs(u,{variant:"outline",className:"w-full",onClick:()=>Z.mutate(),disabled:Z.isPending,"data-testid":"button-save",children:[Z.isPending?e.jsx(_,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(Wt,{className:"mr-2 h-4 w-4"}),s.save]}),e.jsxs("label",{className:"flex items-start gap-2 cursor-pointer text-sm","data-testid":"label-ai-ack",children:[e.jsx(Ze,{checked:G,onCheckedChange:t=>Pe(t===!0),className:"mt-0.5","data-testid":"checkbox-ai-ack"}),e.jsx("span",{children:s.aiAckLabel})]}),!G&&e.jsx("p",{className:"text-xs text-muted-foreground","data-testid":"text-ai-ack-hint",children:s.aiAckRequiredHint}),e.jsxs(u,{className:"w-full",size:"lg",onClick:()=>w.mutate({}),disabled:!G||j.length===0||w.isPending,"data-testid":"button-confirm",children:[w.isPending?e.jsx(_,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(at,{className:"mr-2 h-4 w-4"}
1),ht?s.confirmFinish:s.confirmNext]}),e.jsx(Ke,{}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s.cancelDesc}),e.jsxs(u,{variant:"ghost",className:"w-full text-destructive",onClick:()=>$e.mutate(),disabled:$e.isPending,"data-testid":"button-cancel",children:[e.jsx(Vt,{className:"mr-2 h-4 w-4"}),s.cancel]})]})]})]})]}),e.jsx(He,{open:rt,children:e.jsxs(Me,{dir:H,className:"max-w-lg",children:[e.jsxs(ze,{children:[e.jsxs(Ue,{className:"flex items-center gap-2",children:[e.jsx(tt,{className:"h-5 w-5 shrink-0"}),s.aiDisclaimerTitle]}),e.jsx(Ge,{"data-testid":"text-ai-disclaimer-body",children:s.aiDisclaimerBody})]}),e.jsx(We,{children:e.jsxs(u,{onClick:lt,"data-testid":"button-ai-disclaimer-agree",children:[e.jsx(et,{className:"mr-2 h-4 w-4"}),s.aiDisclaimerAgree]})})]})}),e.jsx(He,{open:!!g,onOpenChange:t=>{t||(U(null),q(!1))},children:e.jsxs(Me,{dir:H,className:"max-w-lg",children:[e.jsxs(ze,{children:[e.jsxs(Ue,{className:"flex items-center gap-2",children:[e.jsx(E,{className:"h-5 w-5 text-destructive shrink-0"}),s.shortfallTitle]}),e.jsx(Ge,{children:s.shortfallIntro})]}),e.jsx("div",{className:"max-h-[40vh] overflow-y-auto space-y-3",children:g==null?void 0:g.orders.map(t=>e.jsxs("div",{className:"rounded-md border p-3","data-testid":`shortfall-order-${t.lpoOrderId}`,children:[e.jsx("div",{className:"text-sm font-medium",children:t.clientReference?`${s.invoice} ${t.clientReference}`:`${s.orderLabel} ${t.displayId??""}`}),e.jsx("ul",{className:"mt-1 space-y-1",children:t.shortItems.map(a=>e.jsxs("li",{className:"text-sm text-muted-foreground","data-testid":`shortfall-item-${t.lpoOrderId}-${a.sku_code}`,children:[e.jsx("span",{className:"font-medium text-foreground",children:a.name})," ",e.jsxs("span",{className:"font-mono text-xs",children:["(",a.sku_code,")"]})," â ",s.shortfallItemLine(a.requested,a.available,a.shortBy)]},a.sku_code))})]},t.lpoOrderId))}),e.jsxs(X,{variant:"destructive",children:[e.jsx(E,{className:"h-4 w-4"}),e.jsx(Ve,{children:s.shortfallRecommend})]}),g&&g.unknownItems.length>0&&e.jsx("p",{className:"text-xs text-muted-foreground","data-testid":"text-shortfall-unknown",children:s.shortfallUnknown(g.unknownItems.map(t=>t.sku_code).join(", "))}),e.jsxs("label",{className:"flex items-start gap-2 cursor-pointer text-sm",children:[e.jsx(Ze,{checked:Ie,onCheckedChange:t=>q(t===!0),className:"mt-0.5","data-testid":"checkbox-shortfall-ack"}),e.jsx("span",{children:s.shortfallAck})]}),e.jsxs(We,{children:[e.jsx(Ot,{"data-testid":"button-shortfall-cancel",children:s.shortfallGoBack}),e.jsxs(u,{onClick:()=>w.mutate({acknowledge:!0}),disabled:!Ie||w.isPending,"data-testid":"button-shortfall-send-anyway",children:[w.isPending?e.jsx(_,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(at,{className:"mr-2 h-4 w-4"}),s.shortfallSendAnyway]})]})]})}),e.jsxs("div",{className:"flex flex-col items-center gap-1 pt-4 pb-1",children:[e.jsx("img",{src:se,alt:"NBOX Logistics",className:"h-6 w-auto opacity-70"}),e.jsx("p",{className:"text-[11px] text-muted-foreground","data-testid":"text-powered-by",children:s.poweredBy})]})]})})}export{js 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.