import{g as F,s as D,bG as y,bH as _,bF as h,S as b,w,L as A,bI as N,bJ as z}from"./index-B67YzpGs.js";import{D as R,S as E,C as T}from"./orders-D9ZsbCWi.js";import{r as i,m as O,a9 as C,ah as S}from"./vendor-DWvj1jit.js";async function P(r){const{userId:e,cultureName:t}=F,{data:s}=await D.query({query:y,variables:{userId:e,cultureName:t,...r}});return s.orders}async function q(r){const{cultureName:e,organizationId:t}=F,{data:s}=await D.query({query:_,variables:{cultureName:e,organizationId:t,...r}});return s.organizationOrders}const c=S();function M(r){const e=i(r.itemsPerPage??R),{appliedFilterData:t,setFacetsLocalization:s}=h(),n=S([]),a=i(!1),o=i(0),m=i(1),d=i(""),g=i(new b("createdDate",w.Descending));async function f(p="private"){a.value=!0;const $=U(d.value,t.value);try{const u={sort:g.value.toString(),first:e.value,after:String((m.value-1)*e.value),filter:$,facet:p==="organization"?`${E} ${T}`:E},l=p==="organization"?await q(u):await P(u);n.value=l?.items??[],o.value=Math.ceil((l?.totalCount??0)/e.value),c.value=l?.term_facets?.map(v=>({name:v.name,items:v.terms})),s(c.value)}catch(u){throw A.error(`${M.name}.${f.name}`,u),u}finally{a.value=!1}}return{sort:g,fetchOrders:f,loading:C(a),orders:O(()=>n.value),facets:O(()=>c.value),itemsPerPage:e,pages:o,page:m,keyword:d}}function U(r,e){let t="";if(r&&(t+=`${r} `),e.statuses.length){const a=e.statuses.map(o=>`"${o}"`);t+=`status:${a.join(",")} `}if(e.customerNames?.length){const a=e.customerNames.map(o=>`"${o}"`);t+=`customername:${a.join(",")} `}const s=N(e.startDate),n=z(e.endDate);if(s||n){let a="";s&&(a+=`"${s}" `),a+="TO",n&&(a+=` "${n}"`),t+=`createddate:[${a}]`}return t=t.trim(),t}export{M as u};
//# sourceMappingURL=useUserOrders-CCMXKw6M.js.map
