import{y as N,E as _,aa as T,ax as A,z as L,M as G,aK as S,$ as x,aL as W,aM as K,N as X,R as d,a8 as $,X as n,e,U as u,V as a,Z as D,Y as F,S as Y,bG as Z,O as m}from"./vendor-CsGITfgk.js";import{aS as j,a6 as H}from"./index-GCDRvGOr.js";import{u as J}from"./useBreadcrumbs-CLanN9FL.js";import{a as ee,u as te,U as oe}from"./usePurchaseRequestDocuments-CMUTXdpw.js";import{u as se,_ as ae}from"./quote-line-items.vue_vue_type_style_index_0_lang-C3LLIqc9.js";import{_ as ne}from"./proceed-to.vue_vue_type_script_setup_true_lang-BTpeTbxU.js";import{d as ue}from"./index-yOwfcyfN.js";import{_ as ie}from"./back-button-in-header.vue_vue_type_script_setup_true_lang-DGvqlgsM.js";import{_ as ce}from"./quote-summary.vue_vue_type_script_setup_true_lang-Bj5mqbyo.js";import"./useFiles-CuSIKmAK.js";import"./address-type.enum-CGCAFS3X.js";import"./getQuotesQuery-B5J9JsS9.js";import"./configuration-items.vue_vue_type_script_setup_true_lang-C3vgTvzN.js";import"./useCheckout-BIeRS8rr.js";function re(r){return N(ee,r,{notifyOnNetworkStatusChange:!0,fetchPolicy:"cache-and-network",nextFetchPolicy:"cache-first",keepPreviousResult:!0})}function me(r){const{result:O,refetch:y,loading:l}=re(r),s=_(()=>O?.value?.purchaseRequest),p=_(()=>s.value?.sources??[]),i=_(()=>p.value.map(o=>j(o.name,o.size,o.contentType,o.url))),{files:q,fetchFileOptions:g,fileOptions:f,processing:c,processDocuments:V}=te(i),{mutate:v}=T(oe);async function b(o){return await V(o,async P=>{await v({command:{documentUrls:P,...L(r)}})})}const{fetching:k,quote:w,fetchQuote:R,changeItemQuantity:I,removeItem:Q}=se();async function t(){s.value?.quoteId&&await R({id:s.value.quoteId,...L(H())})}async function h(o){await I(s.value.quoteId,o.itemId,o.quantity),await t()}async function B(o){await Q(s.value.quoteId,o),await t()}return A(s,async()=>{await t()},{immediate:!0}),{loading:_(()=>l.value||k.value),changing:c,purchaseRequest:s,sources:p,sourceFiles:i,files:q,fileOptions:f,quote:w,refetch:y,fetchFileOptions:g,updatePurchaseRequestByDocuments:b,fetchItems:t,changeQuoteItemQuantity:h,removeQuoteItem:B}}const Ie=G({__name:"purchase-request",props:{purchaseRequestId:{}},setup(r){const y=S(r),{t:l}=x(),s=W(Z),{loading:p,purchaseRequest:i,files:q,fileOptions:g,changing:f,quote:c,fetchFileOptions:V,updatePurchaseRequestByDocuments:v,changeQuoteItemQuantity:b,removeQuoteItem:k}=me(y),w=J(()=>[{title:l("common.links.account"),route:{name:"Account"}},{title:l("purchase_requests.menu.link.title"),route:{name:"PurchaseRequests"}},{title:l("purchase_request.title",[i.value?.number])}]),R=s.smaller("lg");async function I(t){await v(t)}function Q(t){t&&t.url&&ue(t.url,t.name)}return K(async()=>{await V()}),(t,h)=>{const B=u("VcBreadcrumbs"),o=u("VcTypography"),P=u("VcButton"),C=u("VcEmptyView"),z=u("VcFileUploader"),U=u("VcWidget"),E=u("VcLayout"),M=u("VcLoaderOverlay");return m(),X("div",null,[e(R)?(m(),d(e(ie),{key:0,onClick:h[0]||(h[0]=le=>t.$router.back())})):$("",!0),n(B,{items:e(w),class:"hidden lg:block"},null,8,["items"]),n(o,{tag:"h1"},{default:a(()=>[D(F(t.$t("purchase_request.title",[e(i)?.number])),1)]),_:1}),!(e(p)||e(f))&&!e(c)?.items?.length?(m(),d(C,{key:1,text:t.$t("purchase_request.failed_or_used_description"),icon:"outline-order"},{button:a(()=>[n(P,{to:{name:"BulkOrder"},size:"lg"},{default:a(()=>[D(F(t.$t("purchase_request.try_again")),1)]),_:1})]),_:1},8,["text"])):(m(),d(E,{key:2,"sidebar-position":"right","sticky-sidebar":""},{sidebar:a(()=>[e(i)?.quoteId&&e(c)?.items?.length?(m(),d(ce,{key:0,quote:e(c)},{footer:a(()=>[n(e(ne),{to:{name:"EditQuote",params:{quoteId:e(i).quoteId}}},{default:a(()=>[D(F(t.$t("purchase_request.go_to_quote")),1)]),_:1},8,["to"])]),_:1},8,["quote"])):$("",!0)]),default:a(()=>[n(U,{title:t.$t("purchase_request.files_section.title"),"prepend-icon":"document-add",size:"lg"},{default:a(()=>[n(z,Y({class:"h-full"},e(g),{files:e(q),onAddFiles:I,onDownload:Q}),null,16,["files"])]),_:1},8,["title"]),n(U,{id:"products",title:t.$t("shared.cart.products_section.title"),"prepend-icon":"cube",size:"lg"},{default:a(()=>[e(c)?.items?.length?(m(),d(ae,{key:0,items:e(c).items,"onUpdate:item":e(b),"onRemove:item":e(k)},null,8,["items","onUpdate:item","onRemove:item"])):$("",!0)]),_:1},8,["title"])]),_:1})),n(M,{visible:e(p)||e(f),"fixed-spinning":""},null,8,["visible"])])}}});export{Ie as default};
//# sourceMappingURL=purchase-request-T9w4EfZY.js.map
