<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title><%= title %> - IPTV Panel</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="/css/style.css">
</head>
<body>

<%- include('../partials/header') %>

<div class="app-shell">
  <%- include('../partials/sidebar') %>

  <main class="main-content">
    <div class="page-header">
      <h1>Mailers</h1>
      <p>Add, edit, deactivate, or reactivate mailers.</p>
    </div>

    <% if (error) { %>
      <div class="alert alert-error"><%= error %></div>
    <% } %>

    <div class="panel-card">
      <h2>Add Mailer</h2>

      <form method="POST" action="/admin/mailers" class="inline-form">
        <input type="number" name="id" placeholder="Mailer ID" required>
        <input type="text" name="name" placeholder="Mailer name" required>
        <input type="email" name="email" placeholder="Email optional">
        <input type="number" step="0.01" name="commission_rate" placeholder="Commission %" value="5">
        <button type="submit" class="btn-primary small-btn">Add</button>
      </form>
    </div>

    <div class="panel-card">
      <h2>Mailers List</h2>

      <table class="data-table">
        <thead>
          <tr>
            <th>ID</th>
            <th>Name</th>
            <th>Email</th>
            <th>Commission</th>
            <th>Status</th>
            <th class="actions-col">Actions</th>
          </tr>
        </thead>

        <tbody>
          <% mailers.forEach(function(mailer) { %>
            <tr>
              <td><%= mailer.id %></td>
              <td><%= mailer.name %></td>
              <td><%= mailer.email || '-' %></td>
              <td><%= Number(mailer.commission_rate).toFixed(2) %>%</td>
              <td>
                <% if (mailer.is_active) { %>
                  <span class="badge badge-success">Active</span>
                <% } else { %>
                  <span class="badge badge-danger">Inactive</span>
                <% } %>
              </td>
              <td>
                <a class="btn-link" href="/admin/mailers/<%= mailer.id %>/edit">Edit</a>

                <% if (mailer.is_active) { %>
                  <form method="POST" action="/admin/mailers/<%= mailer.id %>/deactivate" class="inline-action">
                    <button type="submit" class="btn-danger">Deactivate</button>
                  </form>
                <% } else { %>
                  <form method="POST" action="/admin/mailers/<%= mailer.id %>/reactivate" class="inline-action">
                    <button type="submit" class="btn-success">Reactivate</button>
                  </form>
                <% } %>
              </td>
            </tr>
          <% }) %>
        </tbody>
      </table>
    </div>
  </main>
</div>

</body>
</html>
