import{z as A,m as h,as as E,N as M,B as U,F as G,aL as W,ai as S,aM as x,aR as X,P as n,Q as j,R as m,_ as d,W as $,X as u,e,a1 as a,a2 as D,a0 as F,a7 as H,aP as J}from"./vendor-DtjVbdLs.js";import{b1 as K,a5 as Y}from"./index-D5bkQlXq.js";import{u as Z}from"./useBreadcrumbs-Cz9PK6XQ.js";import{a as ee,u as te,U as oe}from"./usePurchaseRequestDocuments-BH6ch7Zk.js";import{u as se,_ as ae}from"./quote-line-items.vue_vue_type_style_index_0_lang-T0YS_bCq.js";import{_ as ne}from"./proceed-to.vue_vue_type_script_setup_true_lang-C_RnHZuM.js";import{d as ue}from"./index-DWK19vdO.js";import{_ as ie}from"./back-button-in-header.vue_vue_type_script_setup_true_lang-CSwnHnPL.js";import{_ as ce}from"./quote-summary.vue_vue_type_script_setup_true_lang-BLIheOuU.js";import"./useFiles-CqpDzCl1.js";import"./address-type.enum-CGCAFS3X.js";import"./getQuotesQuery-BLoHk01a.js";import"./configuration-items.vue_vue_type_script_setup_true_lang-CrN-nj19.js";import"./useCheckout-DXq_AIxC.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 k(o){return await v(o,async P=>{await V({command:{documentUrls:P,...U(r)}})})}const{fetching:R,quote:b,fetchQuote:w,changeItemQuantity:I,removeItem:Q}=se();async function t(){s.value?.quoteId&&await w({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||R.value),changing:c,purchaseRequest:s,sources:p,sourceFiles:i,files:q,fileOptions:f,quote:b,refetch:y,fetchFileOptions:g,updatePurchaseRequestByDocuments:k,fetchItems:t,changeQuoteItemQuantity:_,removeQuoteItem:B}}const Ie=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:k,removeQuoteItem:R}=me(y),b=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])}]),w=s.smaller("lg");async function I(t){await V(t)}function Q(t){t&&t.url&&ue(t.url,t.name)}return X(async()=>{await v()}),(t,_)=>{const B=n("VcBreadcrumbs"),o=n("VcTypography"),P=n("VcButton"),C=n("VcEmptyView"),z=n("VcFileUploader"),L=n("VcWidget"),N=n("VcLayout"),T=n("VcLoaderOverlay");return m(),j("div",null,[e(w)?(m(),d(e(ie),{key:0,onClick:_[0]||(_[0]=le=>t.$router.back())})):$("",!0),u(B,{items:e(b),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(N,{key:2,"sidebar-position":"right",sticky:""},{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(z,H({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(k),"onRemove:item":e(R)},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{Ie as default};
//# sourceMappingURL=purchase-request-Cnz2ezoP.js.map
