import{z as E,m as y,as as T,N as M,ad as A,F as W,aM as G,ai as S,aN as x,aE as X,P as n,Q as j,R as m,_ as f,W as F,X as u,e,a1 as a,a2 as O,a0 as C,a7 as H,aQ as J}from"./vendor-BmRNukEL.js";import{b4 as K,g as Y}from"./index-PU-0vjEQ.js";import{u as Z}from"./useBreadcrumbs-CNUnnd1u.js";import{a as ee,u as te,U as oe}from"./usePurchaseRequestDocuments-CM6-y_wY.js";import{u as se,_ as ae}from"./quote-line-items.vue_vue_type_style_index_0_lang-CBbi8Gip.js";import{_ as ne}from"./proceed-to.vue_vue_type_script_setup_true_lang-BaX2fUs6.js";import{d as ue}from"./index-CmFOQbCo.js";import{_ as ce}from"./back-button-in-header.vue_vue_type_script_setup_true_lang-D-ZEvtQc.js";import{_ as ie}from"./quote-summary.vue_vue_type_script_setup_true_lang-CiMMT--O.js";import"./useFiles-Dkx1H-dj.js";import"./address-type.enum-CGCAFS3X.js";import"./getQuotesQuery-CdrG_ktn.js";import"./configuration-items.vue_vue_type_script_setup_true_lang-Iua3UIti.js";import"./useCheckout-By_AA4n3.js";function re(r){return E(ee,r,{notifyOnNetworkStatusChange:!0,fetchPolicy:"cache-and-network",nextFetchPolicy:"cache-first",keepPreviousResult:!0})}function me(r){const{result:N,refetch:g,loading:l}=re(r),s=y(()=>N?.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}=T(oe);async function I(o){return await V(o,async d=>{await k({command:{documentUrls:d,...A(r)}})})}const{fetching:w,quote:R,fetchQuote:b,changeItemQuantity:Q,removeItem:B}=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 P(o){await B(s.value.quoteId,o),await t()}return M(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:P}}const be=W({__name:"purchase-request",props:{purchaseRequestId:{}},setup(r){const g=G(r),{t:l}=S(),s=x(J),{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 B(t){t&&t.url&&ue(t.url,t.name)}return X(async()=>{await V()}),(t,h)=>{const P=n("VcBreadcrumbs"),o=n("VcTypography"),d=n("VcButton"),$=n("VcEmptyView"),D=n("VcFileUploader"),U=n("VcWidget"),L=n("VcLayout"),z=n("VcLoaderOverlay");return m(),j("div",null,[e(b)?(m(),f(e(ce),{key:0,onClick:h[0]||(h[0]=le=>t.$router.back())})):F("",!0),u(P,{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($,{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(L,{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:B}),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(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-BOJk8pLy.js.map
