const L=(function(){const c={newsSearchDelay:500,apiEndpoint:"/api/legal-news/search"},o={activeTaskTab:"daily",searchTimeout:null,lastSearchQuery:""};function p(a={}){f(),b(),g(),T(a),E(),A()}function f(){document.querySelectorAll(".task-tab").forEach(e=>{e.addEventListener("click",y),e.addEventListener("keydown",m)})}function y(a){const t=a.currentTarget.dataset.tab;l(t)}function m(a){const e=a.currentTarget,t=Array.from(document.querySelectorAll(".task-tab")),n=t.indexOf(e);let s;switch(a.key){case"ArrowLeft":a.preventDefault(),s=n>0?n-1:t.length-1,t[s].focus(),t[s].click();break;case"ArrowRight":a.preventDefault(),s=n<t.length-1?n+1:0,t[s].focus(),t[s].click();break;case"Home":a.preventDefault(),t[0].focus(),t[0].click();break;case"End":a.preventDefault(),t[t.length-1].focus(),t[t.length-1].click();break}}function l(a){const e=document.querySelectorAll(".task-tab"),t={daily:document.getElementById("daily-tasks"),overdue:document.getElementById("overdue-tasks")};e.forEach(n=>{const s=n.dataset.tab===a;n.classList.toggle("active",s),n.setAttribute("aria-selected",s)}),Object.keys(t).forEach(n=>{const s=t[n];if(!s)return;n===a?(s.removeAttribute("hidden"),s.style.display="block"):(s.setAttribute("hidden",""),s.style.display="none")}),o.activeTaskTab=a}function b(){document.querySelectorAll(".task-checkbox").forEach(e=>{e.addEventListener("change",k)})}function k(a){const e=a.target,t=e.closest(".task-item"),n=t.querySelector(".task-title");e.checked?(t.style.opacity="0.5",n.style.textDecoration="line-through",i("Task marked as complete")):(t.style.opacity="1",n.style.textDecoration="none",i("Task marked as incomplete"))}function g(){const a=document.getElementById("newsSearch");a&&(a.addEventListener("keypress",e=>{e.key==="Enter"&&(e.preventDefault(),d())}),a.addEventListener("input",e=>{clearTimeout(o.searchTimeout),e.target.value.trim().length>=3&&(o.searchTimeout=setTimeout(()=>{},c.newsSearchDelay))}))}async function d(){const a=document.getElementById("newsSearch"),e=document.getElementById("newsResults");if(!a||!e)return;const t=a.value.trim();if(!t){u(e,"empty");return}if(t!==o.lastSearchQuery){o.lastSearchQuery=t,w(e);try{const n=await fetch(`${c.apiEndpoint}?q=${encodeURIComponent(t)}`);if(!n.ok)throw new Error("Search failed");const s=await n.json();s.articles&&s.articles.length>0?(h(e,s.articles),i(`Found ${s.articles.length} results for ${t}`)):(u(e,"no-results"),i(`No results found for ${t}`))}catch(n){console.error("News search error:",n),v(e),i("Displaying sample results")}}}function w(a){a.innerHTML=`
            <div class="loading-spinner" role="status" aria-live="polite">
                <div class="spinner" aria-hidden="true"></div>
                <p style="margin-top: 16px; font-weight: 600;">Searching legal databases...</p>
                <span class="sr-only">Loading search results</span>
            </div>
        `}function u(a,e="empty"){const t={empty:{icon:"fa-search",title:"Search for legal news and articles",subtitle:"Enter keywords to find relevant legal updates, case law, and industry news"},"no-results":{icon:"fa-search-minus",title:"No results found",subtitle:"Try different keywords or check your spelling"}},n=t[e]||t.empty;a.innerHTML=`
            <div class="empty-state">
                <i class="fas ${n.icon}" aria-hidden="true"></i>
                <p class="empty-state-title">${n.title}</p>
                <p class="empty-state-subtitle">${n.subtitle}</p>
            </div>
        `}function h(a,e){a.innerHTML=e.map(t=>`
            <article class="news-item" 
                     onclick="window.open('${r(t.url)}', '_blank')"
                     role="button"
                     tabindex="0"
                     onkeydown="if(event.key==='Enter'||event.key===' ') window.open('${r(t.url)}', '_blank')"
                     aria-label="Open article: ${r(t.title)}">
                <h3 class="news-item-title">${r(t.title)}</h3>
                <div class="news-item-meta">
                    <span><i class="fas fa-newspaper" aria-hidden="true"></i> ${r(t.source)}</span>
                    <span><i class="fas fa-calendar" aria-hidden="true"></i> ${r(t.publishedAt)}</span>
                    ${t.category?`<span><i class="fas fa-tag" aria-hidden="true"></i> ${r(t.category)}</span>`:""}
                </div>
                <p class="news-item-excerpt">${r(t.description||t.excerpt)}</p>
            </article>
        `).join("")}function v(a){h(a,[{title:"Supreme Court Rules on Corporate Liability Standards",source:"Legal Times",publishedAt:"January 15, 2026",category:"Corporate Law",description:"In a landmark decision, the Supreme Court has established new precedents for corporate liability in cases involving environmental violations and stakeholder responsibilities.",url:"#"},{title:"New Data Privacy Regulations Take Effect Next Month",source:"Law Journal",publishedAt:"January 14, 2026",category:"Privacy Law",description:"Businesses must prepare for comprehensive data privacy requirements as new federal regulations come into force, imposing stricter compliance obligations across all industries.",url:"#"},{title:"International Arbitration Trends in Commercial Disputes",source:"Global Legal Review",publishedAt:"January 13, 2026",category:"Arbitration",description:"Analysis of emerging trends in international commercial arbitration reveals shifting preferences toward hybrid resolution mechanisms and accelerated proceedings.",url:"#"}])}function T(a){const e=a.timeTrackingData,t=a.financialData;DashboardCharts.init(e,t)}function E(){document.addEventListener("keydown",a=>{const e=a.target;(a.key==="Enter"||a.key===" ")&&e.hasAttribute("onclick")&&!e.matches("button, a, input")&&(a.preventDefault(),e.click())})}function i(a){const e=document.createElement("div");e.setAttribute("role","status"),e.setAttribute("aria-live","polite"),e.className="sr-only",e.textContent=a,document.body.appendChild(e),setTimeout(()=>{document.body.removeChild(e)},1e3)}function A(){i("Dashboard loaded. Press Tab to navigate through sections.")}function r(a){const e=document.createElement("div");return e.textContent=a,e.innerHTML}async function D(){try{const e=await(await fetch("/api/dashboard/refresh")).json();e.charts&&Object.keys(e.charts).forEach(t=>{DashboardCharts.update(t,e.charts[t])}),i("Dashboard data refreshed")}catch(a){console.error("Failed to refresh dashboard:",a),i("Failed to refresh dashboard data")}}function S(){window.print()}return{init:p,searchNews:d,switchTaskTab:l,refreshData:D,exportToPDF:S}})();window.DashboardApp=L;document.readyState==="loading"&&document.addEventListener("DOMContentLoaded",()=>{});
