var f=(_,s,o)=>new Promise((v,i)=>{var h=a=>{try{l(o.next(a))}catch(c){i(c)}},d=a=>{try{l(o.throw(a))}catch(c){i(c)}},l=a=>a.done?v(a.value):Promise.resolve(a.value).then(h,d);l((o=o.apply(_,s)).next())});import{u as x}from"./useEditDrawer-JG4PTzvo.js";import{b6 as w,cc as S}from"./bootstrap-Bqxdt4iG.js";import{u as b}from"./data-refresh-BZ1_-6mk.js";import{u as k}from"./inventories-FA5wVZqN.js";import{_ as D}from"./inventory-form.vue_vue_type_script_setup_true_lang-B7Mk7j6o.js";import"./index-nmF6dqm7.js";import y from"./index-WBiU7Ubm.js";import{a1 as $,L as g,ai as I,aj as R,ak as T,p as U,a9 as p,f as n}from"../jse/index-index-BUJ_4tQs.js";const G=$({__name:"inventory-edit-drawer",setup(_){const s=k(),o=b(),v=(e,t)=>f(null,null,function*(){return new Promise(u=>{const r=g("all");S.confirm({title:"Update Multiple Warehouses?",width:480,content:()=>n("div",[n("p",{class:"mb-3"},`This SKU "${t}" exists in ${e} other warehouse${e>1?"s":""}.`),n(y.Group,{value:r.value,"onUpdate:value":m=>{r.value=m}},()=>[n("div",{class:"mb-2"},[n(y,{value:"all"},()=>`All warehouses (${e+1} items total)`)]),n("div",[n(y,{value:"single"},()=>"This warehouse only")])])]),okText:"Update",cancelText:"Cancel",onOk:()=>u(r.value==="all"),onCancel:()=>u(null)})})}),i=g(!1),{Drawer:h,entity:d,formRef:l,handleSubmit:a}=x({getDetailApi:e=>f(null,null,function*(){const t=yield s.getDetail(e);if(!t)throw new Error("Inventory not found");return t}),updateApi:(e,t)=>f(null,null,function*(){return s.update(e,t,i.value)}),invalidateData:()=>o.invalidateInventories(),title:w("page.inventories.drawer.editTitle"),idKey:"inventoryId"}),c=e=>f(null,null,function*(){var u;const t=(u=d.value)==null?void 0:u.id;if(t){if(i.value=!1,e.originalSku){const r=yield s.findSiblings(t);if(r.length>0){const m=yield v(r.length,e.originalSku);if(m===null)return;i.value=m}}yield a(e)}});return(e,t)=>(R(),I(p(h),{class:"w-[700px]","confirm-text":p(w)("page.table.button.save"),"cancel-text":p(w)("page.table.button.cancel")},{default:T(()=>[U(D,{ref_key:"formRef",ref:l,inventory:p(d),mode:"edit",onSubmit:c},null,8,["inventory"])]),_:1},8,["confirm-text","cancel-text"]))}});export{G as _};
