<%- include('partials/header', { title, flash, session, csrf }) %>
<section class="card">
  <div class="section-head">
    <div>
      <h2>طلبات الإلغاء المحفوظة</h2>
      <p class="muted">يتم فحص حالة الطلب وإرسال تذكير للمزود في الموعد المحدد. عند وصول الحالة إلى canceled يتم حذف السجل أو أرشفته حسب الإعدادات.</p>
    </div>
    <form method="post" action="/cancel/run">
      <input type="hidden" name="_csrf" value="<%= csrf %>">
      <button class="button primary">تشغيل الفحص الآن</button>
    </form>
  </div>
  <div class="table-wrap"><table><thead><tr><th>طلب الموقع</th><th>طلب المزود</th><th>العميل</th><th>المزود</th><th>حالة المتابعة</th><th>آخر حالة</th><th>التذكيرات</th><th>الفحص القادم</th><th></th></tr></thead><tbody>
  <% rows.forEach(row => { %>
    <tr>
      <td><%= row.order_id %></td>
      <td><%= row.provider_order_id || '-' %></td>
      <td><%= row.linked_username || '-' %></td>
      <td><%= row.provider_key || '-' %></td>
      <td><%= row.status %></td>
      <td><%= row.last_order_status || '-' %></td>
      <td><%= row.reminder_count %></td>
      <td><%= row.next_check_at %></td>
      <td><% if (row.status === 'active') { %><form method="post" action="/cancel/<%= row.id %>/stop"><input type="hidden" name="_csrf" value="<%= csrf %>"><button class="button danger small">إيقاف</button></form><% } %></td>
    </tr>
  <% }) %>
  <% if (!rows.length) { %><tr><td colspan="9">لا توجد طلبات إلغاء تحت المتابعة.</td></tr><% } %>
  </tbody></table></div>
</section>
<%- include('partials/footer') %>
