import{z as T,as as E,N as A,m as y,ad as M,F as W,ai as G,aL as S,aD 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 j,aP as H,aN as J}from"./vendor-Di1tOLi3.js";import{g as K,b3 as Y}from"./index-BrdDZgk2.js";import{u as Z}from"./useBreadcrumbs-BjNgYg8O.js";import{a as ee,u as te,U as oe}from"./usePurchaseRequestDocuments-BnbQ9zHs.js";import{u as se,_ as ae}from"./quote-line-items.vue_vue_type_style_index_0_lang-C-rWDaSE.js";import{_ as ne}from"./proceed-to.vue_vue_type_script_setup_true_lang-BtFPhDRB.js";import{d as ue}from"./index-A7nVgOjB.js";import{_ as ce}from"./back-button-in-header.vue_vue_type_script_setup_true_lang-C8TzrYsz.js";import{_ as ie}from"./quote-summary.vue_vue_type_script_setup_true_lang-C6cdSKU5.js";import"./useFiles-D1XpX-Pv.js";import"./address-type.enum-CGCAFS3X.js";import"./getQuotesQuery-CPIkBavz.js";import"./configuration-items.vue_vue_type_script_setup_true_lang-DQFfVJJ9.js";import"./useCheckout-BO4s3xj7.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=>Y(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,...M(r)}})})}const{fetching:w,quote:R,fetchQuote:b,changeItemQuantity:Q,removeItem:P}=se();async function t(){const{storeId:o,cultureName:d,currencyCode:D,userId:$}=K;s.value?.quoteId&&await b({storeId:o,cultureName:d,currencyCode:D,userId:$,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 A(s,async()=>{await t()},{immediate:!0}),{loading:y(()=>l.value||w.value),changing:i,purchaseRequest:s,sources:p,sourceFiles:c,files:q,fileOptions:_,quote:R,refetch:g,fetchFileOptions:v,updatePurchaseRequestByDocuments:I,fetchItems:t,changeQuoteItemQuantity:h,removeQuoteItem:B}}const be=W({__name:"purchase-request",props:{purchaseRequestId:{}},setup(r){const g=J(r),{t:l}=G(),s=S(H),{loading:p,purchaseRequest:c,files:q,fileOptions:v,changing:_,quote:i,fetchFileOptions:V,updatePurchaseRequestByDocuments:k,changeQuoteItemQuantity:I,removeQuoteItem:w}=me(g),R=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"),D=n("VcEmptyView"),$=n("VcFileUploader"),N=n("VcWidget"),U=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(R),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(D,{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(U,{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(N,{title:t.$t("purchase_request.files_section.title"),"prepend-icon":"document-add",size:"lg"},{default:a(()=>[u($,j({class:"h-full"},e(v),{files:e(q),onAddFiles:Q,onDownload:P}),null,16,["files"])]),_:1},8,["title"]),u(N,{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(w)},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-Ct7inLgj.js.map
