var h=(D,g,r)=>new Promise((x,u)=>{var v=t=>{try{o(r.next(t))}catch(s){u(s)}},f=t=>{try{o(r.throw(t))}catch(s){u(s)}},o=t=>t.done?x(t.value):Promise.resolve(t.value).then(v,f);o((r=r.apply(D,g)).next())});import{b6 as a,c0 as y}from"./bootstrap-Bqxdt4iG.js";import{u as j}from"./data-refresh-BZ1_-6mk.js";import{u as S}from"./inventory-details-CyykCtw9.js";import I from"./index-CQpOWOLD.js";import{Textarea as R}from"./index-BfzlM1cI.js";import{a1 as b,L as i,ai as C,aj as Q,ak as N,az as n,ap as q,an as B,ay as m,a9 as l,p as k}from"../jse/index-index-BUJ_4tQs.js";import{u as L}from"./use-modal-DEbgLiDZ.js";const V={class:"flex flex-col gap-4 py-2"},z={class:"grid grid-cols-2 gap-4"},O={class:"flex flex-col gap-1"},A={class:"text-xs font-medium text-gray-500"},E={class:"rounded bg-gray-50 p-2 font-mono text-lg"},M={class:"flex flex-col gap-1"},T={class:"text-xs font-medium text-blue-500"},U={key:0,class:"text-xs text-orange-500"},F={class:"flex flex-col gap-1"},P={class:"text-xs font-medium text-gray-500"},Z=b({__name:"inventory-adjustment-modal",emits:["success"],setup(D,{emit:g}){const r=g,x=S(),u=j(),v=i(""),f=i(0),o=i(0),t=i(""),s=i(0),c=i(0),[w,p]=L({title:a("page.inventoryDetails.actions.adjustQty"),onOpenChange:d=>{if(d){const e=p.getData();e&&(v.value=e.id,f.value=e.stockInQty,o.value=e.stockInQty,s.value=e.packedQty||0,c.value=e.stockOutQty||0,t.value="")}},onConfirm:()=>h(null,null,function*(){if(!t.value.trim()){y.warning(a("page.inventoryDetails.form.reasonRequired"));return}const d=s.value+c.value;if(o.value<d){y.error(a("page.inventoryDetails.form.qtyTooLow",{min:d}));return}try{p.setState({confirmLoading:!0}),yield x.adjustQuantity(v.value,o.value,t.value),y.success(a("page.inventoryDetails.form.adjustSuccess")),u.invalidateInventories(),u.invalidateInventoryDetails(),p.close(),r("success")}catch(e){console.error("Failed to adjust quantity:",e),y.error(e.message||a("page.inventoryDetails.form.adjustError"))}finally{p.setState({confirmLoading:!1})}})});return(d,e)=>(Q(),C(l(w),null,{default:N(()=>[n("div",V,[n("div",z,[n("div",O,[n("span",A,m(l(a)("page.inventoryDetails.form.currentQty")),1),n("div",E,m(f.value),1)]),n("div",M,[n("span",T,m(l(a)("page.inventoryDetails.form.newQty")),1),k(l(I),{value:o.value,"onUpdate:value":e[0]||(e[0]=_=>o.value=_),min:s.value+c.value,class:"w-full",size:"large",autofocus:""},null,8,["value","min"])])]),s.value>0||c.value>0?(Q(),q("div",U," * "+m(l(a)("page.inventoryDetails.form.minQtyNote",{qty:s.value+c.value})),1)):B("",!0),n("div",F,[n("span",P,m(l(a)("page.inventoryDetails.form.adjustmentReason")),1),k(l(R),{value:t.value,"onUpdate:value":e[1]||(e[1]=_=>t.value=_),"auto-size":{minRows:2,maxRows:6},placeholder:l(a)("page.inventoryDetails.form.reasonPlaceholder")},null,8,["value","placeholder"])])])]),_:1}))}});export{Z as _};
