import{k as W,q as g,a6 as x,as as K,m as T,C as j,ak as H,V as J,aA as X,bt as Y,al as Z,N as u,D as ee,E as l,K as h,a3 as O,Q as i,u as o,O as n,S as C,R as L,L as te}from"./vendor-BGtMsOoo.js";import{aM as oe,V as se}from"./index-CRze-aDK.js";import{u as ae}from"./useBreadcrumbs-DdGLvHNR.js";import{a as ne,u as ue,U as ie}from"./usePurchaseRequestDocuments-Ccsx5AI0.js";import{u as ce,_ as re,d as me}from"./quote-line-items.vue_vue_type_style_index_0_lang-DO8jHetc.js";import"./order-summary.vue_vue_type_style_index_0_scoped_471240a6_lang-DB8A0s2y.js";import{_ as le}from"./proceed-to.vue_vue_type_script_setup_true_lang-BpsSeiLK.js";import{_ as pe}from"./back-button-in-header.vue_vue_type_script_setup_true_lang-BcrVbDMo.js";import{_ as de}from"./quote-summary.vue_vue_type_script_setup_true_lang-GPtJ755r.js";import"./useFiles-DW9DMZJb.js";import"./constants-55usBUX1.js";import"./address-type.enum-CGCAFS3X.js";import"./getQuotesQuery-cLyGE1OM.js";import"./useUserCheckoutDefaults-BlmbrerI.js";import"./useOrganizationAddresses-DFhlvSxC.js";import"./payment-policies.vue_vue_type_style_index_0_lang-BQUPSUyI.js";import"./add-or-update-address-modal.vue_vue_type_script_setup_true_lang-EfEQeCT4.js";import"./address-form.vue_vue_type_script_setup_true_lang-OQrHDDSp.js";function fe(m){return W(ne,m,{notifyOnNetworkStatusChange:!0,fetchPolicy:"cache-and-network",nextFetchPolicy:"cache-first",keepPreviousResult:!0})}function he(m){const{result:_,refetch:V,loading:p}=fe(m),s=g(()=>{var t;return(t=_==null?void 0:_.value)==null?void 0:t.purchaseRequest}),d=g(()=>{var t;return((t=s.value)==null?void 0:t.sources)??[]}),c=g(()=>d.value.map(t=>oe(t.name,t.size,t.contentType,t.url))),{files:k,fetchFileOptions:v,fileOptions:y,processing:r,processDocuments:b}=ue(c),{mutate:w}=x(ie);async function R(t){return await b(t,async F=>{await w({command:{documentUrls:F,...T(m)}})})}const{fetching:I,quote:Q,fetchQuote:B,changeItemQuantity:P,removeItem:D}=ce();async function e(){var t;(t=s.value)!=null&&t.quoteId&&await B({id:s.value.quoteId,...T(se())})}async function q(t){await P(s.value.quoteId,t.itemId,t.quantity),await e()}async function $(t){await D(s.value.quoteId,t),await e()}return K(s,async()=>{await e()},{immediate:!0}),{loading:g(()=>p.value||I.value),changing:r,purchaseRequest:s,sources:d,sourceFiles:c,files:k,fileOptions:y,quote:Q,refetch:V,fetchFileOptions:v,updatePurchaseRequestByDocuments:R,fetchItems:e,changeQuoteItemQuantity:q,removeQuoteItem:$}}const Ce=j({__name:"purchase-request",props:{purchaseRequestId:{}},setup(m){const V=H(m),{t:p}=J(),s=X(Y),{loading:d,purchaseRequest:c,files:k,fileOptions:v,changing:y,quote:r,fetchFileOptions:b,updatePurchaseRequestByDocuments:w,changeQuoteItemQuantity:R,removeQuoteItem:I}=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=c.value)==null?void 0:e.number])}]}),B=s.smaller("lg");async function P(e){await w(e)}function D(e){e&&e.url&&me(e.url,e.name)}return Z(async()=>{await b()}),(e,q)=>{var A,E;const $=u("VcBreadcrumbs"),t=u("VcTypography"),F=u("VcButton"),z=u("VcEmptyView"),M=u("VcFileUploader"),U=u("VcWidget"),G=u("VcLayout"),S=u("VcLoaderOverlay");return l(),ee("div",null,[o(B)?(l(),h(o(pe),{key:0,onClick:q[0]||(q[0]=a=>e.$router.back())})):O("",!0),i($,{items:o(Q),class:"hidden lg:block"},null,8,["items"]),i(t,{tag:"h1"},{default:n(()=>{var a;return[C(L(e.$t("purchase_request.title",[(a=o(c))==null?void 0:a.number])),1)]}),_:1}),!(o(d)||o(y))&&!((E=(A=o(r))==null?void 0:A.items)!=null&&E.length)?(l(),h(z,{key:1,text:e.$t("purchase_request.failed_or_used_description"),icon:"outline-order"},{button:n(()=>[i(F,{to:{name:"BulkOrder"},size:"lg"},{default:n(()=>[C(L(e.$t("purchase_request.try_again")),1)]),_:1})]),_:1},8,["text"])):(l(),h(G,{key:2,"sidebar-position":"right","sticky-sidebar":""},{sidebar:n(()=>{var a,f,N;return[(a=o(c))!=null&&a.quoteId&&((N=(f=o(r))==null?void 0:f.items)!=null&&N.length)?(l(),h(de,{key:0,quote:o(r)},{footer:n(()=>[i(o(le),{to:{name:"EditQuote",params:{quoteId:o(c).quoteId}}},{default:n(()=>[C(L(e.$t("purchase_request.go_to_quote")),1)]),_:1},8,["to"])]),_:1},8,["quote"])):O("",!0)]}),default:n(()=>[i(U,{title:e.$t("purchase_request.files_section.title"),"prepend-icon":"document-add",size:"lg"},{default:n(()=>[i(M,te({class:"h-full"},o(v),{files:o(k),onAddFiles:P,onDownload:D}),null,16,["files"])]),_:1},8,["title"]),i(U,{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?(l(),h(re,{key:0,items:o(r).items,"onUpdate:item":o(R),"onRemove:item":o(I)},null,8,["items","onUpdate:item","onRemove:item"])):O("",!0)]}),_:1},8,["title"])]),_:1})),i(S,{visible:o(d)||o(y),"fixed-spinning":""},null,8,["visible"])])}}});export{Ce as default};
//# sourceMappingURL=purchase-request-HlqbZJ-_.js.map
