import{z as T,m as y,at as E,N as M,ae as A,F as W,aL as G,aj as S,aM as j,aR as x,P as n,Q as X,R as m,_ as f,W as F,X as u,e,a1 as a,a2 as O,a0 as C,a7 as H,aP as J}from"./vendor-sJIIH5Cr.js";import{b0 as K,g as Y}from"./index-BGo1APpE.js";import{u as Z}from"./useBreadcrumbs-m4lwMW3p.js";import{a as ee,u as te,U as oe}from"./usePurchaseRequestDocuments-BFwVGc9J.js";import{u as se,_ as ae}from"./quote-line-items.vue_vue_type_style_index_0_lang-BZ5dK_bN.js";import{_ as ne}from"./proceed-to.vue_vue_type_script_setup_true_lang-Ck2o8LGj.js";import{d as ue}from"./index-hI1sfMXz.js";import{_ as ce}from"./back-button-in-header.vue_vue_type_script_setup_true_lang-arbce06Z.js";import{_ as ie}from"./quote-summary.vue_vue_type_script_setup_true_lang-BQV8pijw.js";import"./useFiles-BtMJrn-Y.js";import"./address-type.enum-CGCAFS3X.js";import"./getQuotesQuery-BNo6ikIw.js";import"./configuration-items.vue_vue_type_script_setup_true_lang-CnyzzoEd.js";import"./useCheckout-vKY3Jg1X.js";function re(r){return T(ee,r,{notifyOnNetworkStatusChange:!0,fetchPolicy:"cache-and-network",nextFetchPolicy:"cache-first",keepPreviousResult:!0})}function me(r){const{result:L,refetch:g,loading:l}=re(r),s=y(()=>L?.value?.purchaseRequest),p=y(()=>s.value?.sources??[]),c=y(()=>p.value.map(o=>K(o.name,o.size,o.contentType,o.url))),{files:q,fetchFileOptions:v,fileOptions:_,processing:i,processDocuments:V}=te(c),{mutate:k}=E(oe);async function I(o){return await V(o,async d=>{await k({command:{documentUrls:d,...A(r)}})})}const{fetching:R,quote:w,fetchQuote:b,changeItemQuantity:Q,removeItem:P}=se();async function t(){const{storeId:o,cultureName:d,currencyCode:$,userId:D}=Y;s.value?.quoteId&&await b({storeId:o,cultureName:d,currencyCode:$,userId:D,id:s.value.quoteId})}async function h(o){await Q(s.value.quoteId,o.itemId,o.quantity),await t()}async function B(o){await P(s.value.quoteId,o),await t()}return M(s,async()=>{await t()},{immediate:!0}),{loading:y(()=>l.value||R.value),changing:i,purchaseRequest:s,sources:p,sourceFiles:c,files:q,fileOptions:_,quote:w,refetch:g,fetchFileOptions:v,updatePurchaseRequestByDocuments:I,fetchItems:t,changeQuoteItemQuantity:h,removeQuoteItem:B}}const be=W({__name:"purchase-request",props:{purchaseRequestId:{}},setup(r){const g=G(r),{t:l}=S(),s=j(J),{loading:p,purchaseRequest:c,files:q,fileOptions:v,changing:_,quote:i,fetchFileOptions:V,updatePurchaseRequestByDocuments:k,changeQuoteItemQuantity:I,removeQuoteItem:R}=me(g),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",[c.value?.number])}]),b=s.smaller("lg");async function Q(t){await k(t)}function P(t){t&&t.url&&ue(t.url,t.name)}return x(async()=>{await V()}),(t,h)=>{const B=n("VcBreadcrumbs"),o=n("VcTypography"),d=n("VcButton"),$=n("VcEmptyView"),D=n("VcFileUploader"),U=n("VcWidget"),N=n("VcLayout"),z=n("VcLoaderOverlay");return m(),X("div",null,[e(b)?(m(),f(e(ce),{key:0,onClick:h[0]||(h[0]=le=>t.$router.back())})):F("",!0),u(B,{items:e(w),class:"hidden lg:block"},null,8,["items"]),u(o,{tag:"h1"},{default:a(()=>[O(C(t.$t("purchase_request.title",[e(c)?.number])),1)]),_:1}),!(e(p)||e(_))&&!e(i)?.items?.length?(m(),f($,{key:1,text:t.$t("purchase_request.failed_or_used_description"),icon:"outline-order"},{button:a(()=>[u(d,{to:{name:"BulkOrder"},size:"lg"},{default:a(()=>[O(C(t.$t("purchase_request.try_again")),1)]),_:1})]),_:1},8,["text"])):(m(),f(N,{key:2,"sidebar-position":"right",sticky:""},{sidebar:a(()=>[e(c)?.quoteId&&e(i)?.items?.length?(m(),f(ie,{key:0,quote:e(i)},{footer:a(()=>[u(e(ne),{to:{name:"EditQuote",params:{quoteId:e(c).quoteId}}},{default:a(()=>[O(C(t.$t("purchase_request.go_to_quote")),1)]),_:1},8,["to"])]),_:1},8,["quote"])):F("",!0)]),default:a(()=>[u(U,{title:t.$t("purchase_request.files_section.title"),"prepend-icon":"document-add",size:"lg"},{default:a(()=>[u(D,H({class:"h-full"},e(v),{files:e(q),onAddFiles:Q,onDownload:P}),null,16,["files"])]),_:1},8,["title"]),u(U,{id:"products",title:t.$t("shared.cart.products_section.title"),"prepend-icon":"cube",size:"lg"},{default:a(()=>[e(i)?.items?.length?(m(),f(ae,{key:0,items:e(i).items,"onUpdate:item":e(I),"onRemove:item":e(R)},null,8,["items","onUpdate:item","onRemove:item"])):F("",!0)]),_:1},8,["title"])]),_:1})),u(z,{visible:e(p)||e(_),"fixed-spinning":""},null,8,["visible"])])}}});export{be as default};
//# sourceMappingURL=purchase-request-DH1OeEo-.js.map
