import{u as j,L as M,x as O,a as v,c as d,ah as f,y as S,ad as T,b as k,e as g,w as r,f as s,G as U,S as $,g as i,i as L,O as w,h as m,a8 as E,j as R,H as z,t as F,D as H,T as I,r as X}from"./index-OSKNspXo.js";import{Q as G}from"./QForm-PGP8CIo6.js";import{_ as V}from"./equipmentItemComponent-C0ywyT2d.js";const P={class:"q-pr-sm q-pl-sm"},J={class:"form-group"},K={key:1,style:{"font-size":"large"},class:"text-negative"},W={class:"row justify-center"},te={__name:"externalMoveContainerModal",props:{open:{type:Boolean},mag:{type:String},reference:{type:Object},location:{type:String},container:{type:Object},function:{type:Function}},emits:["update:open"],setup(h,{emit:x}){const{t:n}=j(),y=M(),p=O(),C=new T,c=v([]),o=h,_=v(null),q=d(()=>t.value.store),t=v({store:null,location:null}),D=x,u=d({get:()=>o.open,set:function(a){D("update:open",a)}}),B=d(()=>y.state.global.stores.find(a=>a.mag===o.mag)),Q=d(()=>y.state.global.stores.filter(a=>a.eco_type===f.ACCED||a.eco_type===f.EXTERNAL));S(u,()=>{u.value&&(t.value={store:null,location:null})}),S(q,async a=>{if(t.value.location=null,a)try{c.value=await C.getAvailabelAdressesContainer(o.reference.reference,a.mag,B.value.eco_type===f.EXTERNAL?"-":o.location,o.reference.fraction,"BOITE PASS")}catch(l){console.error(l),p.notify({message:n("ui.generic.error"),type:"negative"})}});function A(){u.value=!1}async function N(){var a,l;try{let e={move_container_is_empty:"yes",magasin:t.value.store.mag,adresse:(a=t.value.location)==null?void 0:a.adresse,origin_adresse:o.location.replace(/ /g,""),lot:o.container.batchNumber,date_peremption:o.reference.date_peremption,ucd:o.container.ucd,fraction:o.container.fraction,reference:o.reference.reference},b=await X.put(`/api/external/stock/${o.container.pk}/move`,e);u.value=!1,p.notify({message:n("drugs.moveconainer.success"),type:"positive"}),await o.function((l=t.value.location)==null?void 0:l.adresse)}catch(e){console.error(e),p.notify({message:n("drugs.moveconainer.error"),type:"negative"})}}return(a,l)=>(g(),k(I,{modelValue:u.value,"onUpdate:modelValue":l[3]||(l[3]=e=>u.value=e)},{default:r(()=>[s(U,{style:{width:"500px","max-width":"80vw"}},{default:r(()=>[s($,{click:A,title:i(n)("reference.drugs.movecontainer.title")},null,8,["title"]),s(G,{onSubmit:L(N,["prevent"]),greedy:""},{default:r(()=>[s(w,null,{default:r(()=>[m("div",P,[m("div",J,[s(E,{label:i(n)("drugs.movecontainer.address"),ref_key:"selectedEquipment",ref:_,rules:[e=>e!==null||i(n)("drugs.movecontainer.address.empty")],options:Q.value,"option-value":"pk","option-label":"libelle",modelValue:t.value.store,"onUpdate:modelValue":l[1]||(l[1]=e=>t.value.store=e)},{"selected-item":r(e=>[s(V,{item:e.opt},null,8,["item"])]),option:r(e=>[s(V,{selectedEquipment:_.value,item:e.opt,selected:t.value.store,"onUpdate:selected":l[0]||(l[0]=b=>t.value.store=b)},null,8,["selectedEquipment","item","selected"])]),_:1},8,["label","rules","options","modelValue"])]),m("div",null,[t.value.store&&c.value.length>0?(g(),k(E,{key:0,label:i(n)("drugs.movecontainer.location"),rules:[e=>e!==null||i(n)("drugs.movecontainer.location.empty")],options:c.value,"lazy-rules":"","option-value":"id","option-label":"adresse",modelValue:t.value.location,"onUpdate:modelValue":l[2]||(l[2]=e=>t.value.location=e)},null,8,["label","rules","options","modelValue"])):t.value.store?(g(),R("label",K,F(i(n)("drugs.movecontainer.nolocation")),1)):z("",!0)])])]),_:1}),s(w,null,{default:r(()=>[m("div",W,[s(H,{type:"submit",disable:!c.value||c.value.length===0,icon:"save",label:i(n)("ui.button.save")},null,8,["disable","label"])])]),_:1})]),_:1})]),_:1})]),_:1},8,["modelValue"]))}};export{te as _};
//# sourceMappingURL=externalMoveContainerModal-BqFfbYux.js.map
