import{aj as E,r as c,y as o,z as a,W as M}from"./index-Bb2UEb_P.js";const w=E("EDesks",()=>{const l=c(null),n=c(null),u=c(null),f=c({});async function k(){let e="error";try{const s=await o.post(a.eDesks);l.value=s?.data,e="success"}catch(s){console.error(s)}return e}async function d(e){let s="error";try{const t=await o.get(a.eDeskMessages+`?EdeskID=${e}`);n.value=t?.data;const r=new Set(Object.values(n.value).map(i=>i.UserID));for(const i of r)await D(i);s="success"}catch(t){console.error(t)}return s}function p(e){let s=new FormData;for(let t in e)s.append(t,e[t]);return s}async function g(e){let s="error",t=p(e);e?.TicketMessageFile&&e?.TicketMessageFile.forEach(r=>{t.append("TicketMessageFile[]",r)});try{await o.post(a.sendTicketMessage,t),s="success"}catch(r){console.error(r),s="error"}return s}async function h(){let e="error";try{const s=await o.post(a.ticketGroups);u.value=s?.data,e="success"}catch(s){console.error(s)}return e}async function y(e){let s="error",t=p(e);e?.TicketMessageFile&&e?.TicketMessageFile.forEach(r=>{t.append("TicketMessageFile[]",r)});try{const r=await o.post(a.ticketEdit,t);r?.data.Status==="Ok"&&(u.value=r.data,s="success")}catch(r){console.error(r)}return s}async function D(e){try{const t=(await o.get(a.user,{params:{UserID:e}})).data?.[e]?.Name;f.value[e]={name:t,avatarUrl:M+a.userPhoto+`?UserID=${e}`}}catch(s){console.error("Error fetching user data:",s)}return""}return{tickets:l,messages:n,groups:u,users:f,fetchTickets:k,fetchMessages:d,sendMessage:g,fetchGroups:h,ticketEdit:y}});export{w as u};
