import{z as A,m as h,aq as E,N as G,B as U,F as M,aK as W,ag as S,aL as x,aQ as K,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,aO as H}from"./vendor-CB-jpi5M.js";import{b1 as J,a5 as Y}from"./index--7FqiOc7.js";import{u as Z}from"./useBreadcrumbs-C3iwaFYZ.js";import{a as ee,u as te,U as oe}from"./usePurchaseRequestDocuments-CP1H85CC.js";import{u as se,_ as ae}from"./quote-line-items.vue_vue_type_style_index_0_lang-Dp13lgcY.js";import{_ as ne}from"./proceed-to.vue_vue_type_script_setup_true_lang-hgdPXC6P.js";import{d as ue}from"./index-DsoMUsD6.js";import{_ as ie}from"./back-button-in-header.vue_vue_type_script_setup_true_lang-Cgi0O5Dc.js";import{_ as ce}from"./quote-summary.vue_vue_type_script_setup_true_lang-B4arSEck.js";import"./useFiles-ChFaqSI4.js";import"./address-type.enum-CGCAFS3X.js";import"./getQuotesQuery-DjtNNt-O.js";import"./configuration-items.vue_vue_type_script_setup_true_lang-CtYyuyX1.js";import"./useCheckout-D_ybfVaT.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=>J(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 G(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 Ie=M({__name:"purchase-request",props:{purchaseRequestId:{}},setup(r){const y=W(r),{t:l}=S(),s=x(H),{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 K(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(),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(N,{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(z,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{Ie as default};
//# sourceMappingURL=purchase-request-C7FpxYM8.js.map
