import{x as S,B as q,aa as W,av as K,y as E,K as X,ao as Z,Z as j,aI as H,bz as J,ap as Y,S as u,L as ee,M as m,P as h,a7 as O,V as c,b as o,T as n,X as L,W as U,Q as te}from"./vendor-bSWkQivH.js";import{ax as oe,V as se}from"./index-Dqv5IkpS.js";import{u as ae}from"./useBreadcrumbs-Bvh8-Tkx.js";import{a as ne,u as ue,U as ce}from"./usePurchaseRequestDocuments-BbQkBP-v.js";import{u as ie,_ as re}from"./quote-line-items.vue_vue_type_style_index_0_lang-BwdflVss.js";import{_ as le}from"./proceed-to.vue_vue_type_script_setup_true_lang-CzPN8rQE.js";import{d as me}from"./index-D-4abmdp.js";import{_ as pe}from"./back-button-in-header.vue_vue_type_script_setup_true_lang-DPNGg6Wd.js";import{_ as de}from"./quote-summary.vue_vue_type_script_setup_true_lang-C9wjg8iU.js";import"./getQuotesQuery-C9NfC5i7.js";function fe(l){return S(ne,l,{notifyOnNetworkStatusChange:!0,fetchPolicy:"cache-and-network",nextFetchPolicy:"cache-first",keepPreviousResult:!0})}function he(l){const{result:_,refetch:V,loading:p}=fe(l),s=q(()=>{var t;return(t=_==null?void 0:_.value)==null?void 0:t.purchaseRequest}),d=q(()=>{var t;return((t=s.value)==null?void 0:t.sources)??[]}),i=q(()=>d.value.map(t=>oe(t.name,t.size,t.contentType,t.url))),{files:v,fetchFileOptions:b,fileOptions:y,processing:r,processDocuments:k}=ue(i),{mutate:w}=W(ce);async function I(t){return await k(t,async F=>{await w({command:{documentUrls:F,...E(l)}})})}const{fetching:R,quote:Q,fetchQuote:B,changeItemQuantity:P,removeItem:$}=ie();async function e(){var t;(t=s.value)!=null&&t.quoteId&&await B({id:s.value.quoteId,...E(se())})}async function g(t){await P(s.value.quoteId,t.itemId,t.quantity),await e()}async function D(t){await $(s.value.quoteId,t),await e()}return K(s,async()=>{await e()},{immediate:!0}),{loading:q(()=>p.value||R.value),changing:r,purchaseRequest:s,sources:d,sourceFiles:i,files:v,fileOptions:y,quote:Q,refetch:V,fetchFileOptions:b,updatePurchaseRequestByDocuments:I,fetchItems:e,changeQuoteItemQuantity:g,removeQuoteItem:D}}const Re=X({__name:"purchase-request",props:{purchaseRequestId:{}},setup(l){const V=Z(l),{t:p}=j(),s=H(J),{loading:d,purchaseRequest:i,files:v,fileOptions:b,changing:y,quote:r,fetchFileOptions:k,updatePurchaseRequestByDocuments:w,changeQuoteItemQuantity:I,removeQuoteItem:R}=he(V),Q=ae(()=>{var e;return[{title:p("common.links.account"),route:{name:"Account"}},{title:p("purchase_requests.menu.link.title"),route:{name:"PurchaseRequests"}},{title:p("purchase_request.title",[(e=i.value)==null?void 0:e.number])}]}),B=s.smaller("lg");async function P(e){await w(e)}function $(e){e&&e.url&&me(e.url,e.name)}return Y(async()=>{await k()}),(e,g)=>{var T,z;const D=u("VcBreadcrumbs"),t=u("VcTypography"),F=u("VcButton"),M=u("VcEmptyView"),N=u("VcFileUploader"),C=u("VcWidget"),x=u("VcLayout"),G=u("VcLoaderOverlay");return m(),ee("div",null,[o(B)?(m(),h(o(pe),{key:0,onClick:g[0]||(g[0]=a=>e.$router.back())})):O("",!0),c(D,{items:o(Q),class:"hidden lg:block"},null,8,["items"]),c(t,{tag:"h1"},{default:n(()=>{var a;return[L(U(e.$t("purchase_request.title",[(a=o(i))==null?void 0:a.number])),1)]}),_:1}),!(o(d)||o(y))&&!((z=(T=o(r))==null?void 0:T.items)!=null&&z.length)?(m(),h(M,{key:1,text:e.$t("purchase_request.failed_or_used_description"),icon:"outline-order"},{button:n(()=>[c(F,{to:{name:"BulkOrder"},size:"lg"},{default:n(()=>[L(U(e.$t("purchase_request.try_again")),1)]),_:1})]),_:1},8,["text"])):(m(),h(x,{key:2,"sidebar-position":"right","sticky-sidebar":""},{sidebar:n(()=>{var a,f,A;return[(a=o(i))!=null&&a.quoteId&&((A=(f=o(r))==null?void 0:f.items)!=null&&A.length)?(m(),h(de,{key:0,quote:o(r)},{footer:n(()=>[c(o(le),{to:{name:"EditQuote",params:{quoteId:o(i).quoteId}}},{default:n(()=>[L(U(e.$t("purchase_request.go_to_quote")),1)]),_:1},8,["to"])]),_:1},8,["quote"])):O("",!0)]}),default:n(()=>[c(C,{title:e.$t("purchase_request.files_section.title"),"prepend-icon":"document-add",size:"lg"},{default:n(()=>[c(N,te({class:"h-full"},o(b),{files:o(v),onAddFiles:P,onDownload:$}),null,16,["files"])]),_:1},8,["title"]),c(C,{id:"products",title:e.$t("shared.cart.products_section.title"),"prepend-icon":"cube",size:"lg"},{default:n(()=>{var a,f;return[(f=(a=o(r))==null?void 0:a.items)!=null&&f.length?(m(),h(re,{key:0,items:o(r).items,"onUpdate:item":o(I),"onRemove:item":o(R)},null,8,["items","onUpdate:item","onRemove:item"])):O("",!0)]}),_:1},8,["title"])]),_:1})),c(G,{visible:o(d)||o(y),"fixed-spinning":""},null,8,["visible"])])}}});export{Re as default};
//# sourceMappingURL=purchase-request-6MpQ6zr8.js.map
