import"./chunks/modulepreload-polyfill-B5Qt9EMX.js";import{c as p,g as y}from"./chunks/error-log-iDKIFPsV.js";import"./chunks/idb-kv-Dhbo4CRD.js";const i=document.getElementById("logs-body"),a=document.getElementById("logs-status"),b=document.getElementById("btn-back"),$=document.getElementById("btn-copy"),h=document.getElementById("btn-export"),v=document.getElementById("btn-clear");let r=[];chrome.storage.sync.get({fontSize:13},t=>{const e=t.fontSize||13,o=Math.max(.8,e/13),n=document.querySelector(".logs-container");n&&(n.style.zoom=String(o))});function l(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function d(t){try{const e=new Date(t),o=n=>String(n).padStart(2,"0");return`${e.getFullYear()}-${o(e.getMonth()+1)}-${o(e.getDate())} ${o(e.getHours())}:${o(e.getMinutes())}:${o(e.getSeconds())}`}catch{return t}}function m(t){if(t.length===0){i.innerHTML='<div class="empty-msg">에러 로그가 없습니다.</div>';return}const e=[...t].reverse(),o=`<div class="log-count">${t.length}개 항목</div>`,n=e.map(c=>{const u=c.msg.includes("실패")||c.msg.includes("error")||c.msg.includes("Error")||c.msg.includes("Fatal");return`<div class="log-entry">
        <span class="log-ts">${l(d(c.ts))}</span>
        <span class="log-msg${u?" error":""}">${l(c.msg)}</span>
      </div>`}).join("");i.innerHTML=o+n}function g(t){if(t.length===0)return"No error logs.";const e=`VibeFilter Error Log — exported ${new Date().toISOString()}
${"=".repeat(60)}

`,o=t.map(n=>`[${d(n.ts)}] ${n.msg}`).join(`
`);return e+o+`
`}function s(t,e){a.textContent=t,a.style.color=e,setTimeout(()=>{a.textContent=""},3e3)}async function f(){try{r=await y(),m(r)}catch(t){i.innerHTML=`<div class="empty-msg" style="color:#e94560;">로그를 불러오지 못했습니다: ${l(String(t))}</div>`}}f();b.addEventListener("click",()=>{window.location.href=chrome.runtime.getURL("src/options/index.html")});$.addEventListener("click",async()=>{const t=g(r);try{await navigator.clipboard.writeText(t),s("클립보드에 복사되었습니다!","#2ecc71")}catch{const e=document.createElement("textarea");e.value=t,document.body.appendChild(e),e.select(),document.execCommand("copy"),document.body.removeChild(e),s("클립보드에 복사되었습니다!","#2ecc71")}});h.addEventListener("click",()=>{const t=g(r),e=new Blob([t],{type:"text/plain"}),o=URL.createObjectURL(e),n=document.createElement("a"),c=new Date().toISOString().slice(0,10);n.href=o,n.download=`vibefilter-error-log-${c}.txt`,document.body.appendChild(n),n.click(),document.body.removeChild(n),URL.revokeObjectURL(o),s("로그 파일을 다운로드했습니다!","#2ecc71")});v.addEventListener("click",async()=>{if(confirm("에러 로그를 모두 삭제하시겠습니까?"))try{await p(),r=[],m(r),s("로그가 삭제되었습니다.","#2ecc71")}catch{s("삭제에 실패했습니다.","#e94560")}});
