const s="/api/log";class c{static async log(t){try{const o=await fetch(`${s}/write`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!o.ok)throw new Error("Failed to record log entry");return(await o.json()).id}catch(o){console.error("Error while sending log to server:",o)}}static async exportToJson(t,o){try{const r=new URLSearchParams;t&&r.append("dateFrom",t.toISOString()),o&&r.append("dateTo",o.toISOString());const e=await fetch(`${s}/export/json?${r.toString()}`);if(!e.ok)throw new Error("Failed to export logs to JSON");const a=await e.json();console.log(a.message)}catch(r){console.error("Error while exporting logs to JSON:",r)}}static async exportToExcel(t,o,r){try{const e=new URLSearchParams;t&&e.append("dateFrom",t.toISOString()),o&&e.append("dateTo",o.toISOString()),r&&r.length>0&&e.append("fields",r.join(","));const a=await fetch(`${s}/export/excel?${e.toString()}`);if(!a.ok)throw new Error("Failed to export logs to Excel");return await a.blob()}catch(e){console.error("Error while exporting logs to Excel:",e)}return null}static async logUserScore(t,o,r){const e=await fetch("/api/log/write/userScore",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:t,score:o,comment:r})});if(!e.ok)throw new Error("Failed to update user score");if((await e.json()).message!=="User score updated successfully")throw new Error("User score update failed")}}export{c as L};