import{g as D,s as F,bI as y,bJ as _,bH as h,S as b,w,L as A,bK as N,bL as z}from"./index-Vd7lvnU9.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-Dd8T34zR.js";async function P(r){const{userId:e,cultureName:t}=D,{data:s}=await F.query({query:y,variables:{userId:e,cultureName:t,...r}});return s.orders}async function q(r){const{cultureName:e,organizationId:t}=D,{data:s}=await F.query({query:_,variables:{cultureName:e,organizationId:t,...r}});return s.organizationOrders}const c=S();function L(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 $=M(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(`${L.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 M(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{L as u};
//# sourceMappingURL=useUserOrders-BqAK7VVI.js.map
