import{z as A,m as h,aq as E,N as M,B as U,F as G,aL as W,ag as S,aM as x,aN as H,P as n,Q as X,R as m,_ as d,W as $,X as u,e,a1 as a,a2 as D,a0 as F,a8 as j,bH as J}from"./vendor-BMB8ItLC.js";import{b1 as K,a5 as Y}from"./index-EAGRne_f.js";import{u as Z}from"./useBreadcrumbs-Dvqw9dNT.js";import{a as ee,u as te,U as oe}from"./usePurchaseRequestDocuments-BaSzD3HV.js";import{u as se,_ as ae}from"./quote-line-items.vue_vue_type_style_index_0_lang-DKMeygx-.js";/* empty css                                                                     *//* empty css                                                                      */import{_ as ne}from"./proceed-to.vue_vue_type_script_setup_true_lang-DtLcBi7A.js";import{d as ue}from"./index-DbRYwbuO.js";import{_ as ie}from"./back-button-in-header.vue_vue_type_script_setup_true_lang-B79j4Zv1.js";import{_ as ce}from"./quote-summary.vue_vue_type_script_setup_true_lang-81hhG51d.js";import"./useFiles-C5nKMtnZ.js";import"./address-type.enum-CGCAFS3X.js";import"./getQuotesQuery-gD2NC3yW.js";import"./configuration-items.vue_vue_type_script_setup_true_lang-DmBfjyGP.js";import"./useCheckout-BP67mh_t.js";function re(r){return A(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=h(()=>O?.value?.purchaseRequest),p=h(()=>s.value?.sources??[]),i=h(()=>p.value.map(o=>K(o.name,o.size,o.contentType,o.url))),{files:q,fetchFileOptions:g,fileOptions:f,processing:c,processDocuments:v}=te(i),{mutate:V}=E(oe);async function b(o){return await v(o,async P=>{await V({command:{documentUrls:P,...U(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,...U(Y())})}async function _(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 M(s,async()=>{await t()},{immediate:!0}),{loading:h(()=>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:_,removeQuoteItem:B}}const Be=G({__name:"purchase-request",props:{purchaseRequestId:{}},setup(r){const y=W(r),{t:l}=S(),s=x(J),{loading:p,purchaseRequest:i,files:q,fileOptions:g,changing:f,quote:c,fetchFileOptions:v,updatePurchaseRequestByDocuments:V,changeQuoteItemQuantity:b,removeQuoteItem:k}=me(y),w=Z(()=>[{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 H(async()=>{await v()}),(t,_)=>{const B=n("VcBreadcrumbs"),o=n("VcTypography"),P=n("VcButton"),C=n("VcEmptyView"),N=n("VcFileUploader"),L=n("VcWidget"),z=n("VcLayout"),T=n("VcLoaderOverlay");return m(),X("div",null,[e(R)?(m(),d(e(ie),{key:0,onClick:_[0]||(_[0]=le=>t.$router.back())})):$("",!0),u(B,{items:e(w),class:"hidden lg:block"},null,8,["items"]),u(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(()=>[u(P,{to:{name:"BulkOrder"},size:"lg"},{default:a(()=>[D(F(t.$t("purchase_request.try_again")),1)]),_:1})]),_:1},8,["text"])):(m(),d(z,{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(()=>[u(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(()=>[u(L,{title:t.$t("purchase_request.files_section.title"),"prepend-icon":"document-add",size:"lg"},{default:a(()=>[u(N,j({class:"h-full"},e(g),{files:e(q),onAddFiles:I,onDownload:Q}),null,16,["files"])]),_:1},8,["title"]),u(L,{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})),u(T,{visible:e(p)||e(f),"fixed-spinning":""},null,8,["visible"])])}}});export{Be as default};
//# sourceMappingURL=purchase-request-DTeFf8wk.js.map
