<%
  const auditItems = Array.isArray(reports) ? reports : [];
  const auditLocale = typeof lang === 'string' && lang.toLowerCase().startsWith('en') ? 'en' : 'ar';
  const auditEnglish = auditLocale === 'en';
  const auditTotal = Number(reportsCount) || 0;
  const auditCopy = auditEnglish ? {
    emptyTitle: 'No audit events yet',
    emptyDescription: 'Administrative actions will appear here automatically when they occur.',
    action: 'Activity',
    admin: 'Administrator',
    request: 'Request',
    time: 'Timestamp',
    details: 'Details',
    total: 'Total events',
    helper: 'Read-only administrative record',
    pagesTitle: 'Audit pages',
    pagesHint: 'Navigate the activity record'
  } : {
    emptyTitle: 'لا توجد أحداث تدقيق حتى الآن',
    emptyDescription: 'ستظهر الإجراءات الإدارية هنا تلقائيًا فور تنفيذها.',
    action: 'النشاط',
    admin: 'المشرف',
    request: 'الطلب',
    time: 'التوقيت',
    details: 'التفاصيل',
    total: 'إجمالي الأحداث',
    helper: 'سجل إداري للقراءة فقط',
    pagesTitle: 'صفحات السجل',
    pagesHint: 'تنقّل داخل سجل النشاط'
  };
%>

<div class="kt-reports-fragment" data-reports-fragment>
  <% if (!auditItems.length) { %>
    <div class="kt-reports-empty" data-reports-empty>
      <span aria-hidden="true"><i class="ti ti-shield-off"></i></span>
      <div>
        <h3><%= auditCopy.emptyTitle %></h3>
        <p><%= auditCopy.emptyDescription %></p>
      </div>
    </div>
  <% } else { %>
    <div class="kt-reports-table-scroll">
      <table class="kt-reports-table">
        <caption class="kt-reports-visually-hidden"><%= auditCopy.helper %></caption>
        <colgroup>
          <col class="kt-reports-col--action">
          <col class="kt-reports-col--admin">
          <col class="kt-reports-col--request">
          <col class="kt-reports-col--time">
          <col class="kt-reports-col--details">
        </colgroup>
        <thead>
          <tr>
            <th><%= auditCopy.action %></th>
            <th><%= auditCopy.admin %></th>
            <th><%= auditCopy.request %></th>
            <th><%= auditCopy.time %></th>
            <th><%= auditCopy.details %></th>
          </tr>
        </thead>
        <tbody>
          <%- include('./tds.ejs', { reports: auditItems, lang: auditLocale, i18n }) %>
        </tbody>
      </table>
    </div>
  <% } %>

  <footer class="kt-reports-footer">
    <span><small><%= auditCopy.total %></small><strong><%= auditTotal %></strong></span>
    <p><%= auditCopy.helper %></p>
  </footer>

  <% if (typeof paginationHtml === 'string' && paginationHtml.trim()) { %>
    <nav
      class="kt-reports-pagination"
      data-reports-pagination
      aria-label="<%= auditEnglish ? 'Audit log pages' : 'صفحات سجل التدقيق' %>"
    >
      <div class="kt-reports-pagination__shell">
        <div class="kt-reports-pagination__context" aria-hidden="true">
          <span class="kt-reports-pagination__mark"></span>
          <span>
            <strong><%= auditCopy.pagesTitle %></strong>
            <small><%= auditCopy.pagesHint %></small>
          </span>
        </div>
        <div class="kt-reports-pagination__links" data-reports-pagination-links>
          <%- paginationHtml %>
        </div>
      </div>
    </nav>
  <% } %>
</div>
