<%- include('../partials/admin-header') %>
<h1>Telegram 频道配置</h1>

<div class="form-card">
  <h2>添加频道</h2>
  <form method="POST" action="/admin/channels">
    <div class="form-row">
      <label>频道名称 <input name="name" required></label>
      <label>Chat ID <input name="chat_id" required placeholder="-100..."></label>
      <label>备注 <input name="notes"></label>
      <button type="submit" class="btn btn-primary">添加</button>
    </div>
  </form>
</div>

<table>
  <thead><tr><th>ID</th><th>名称</th><th>Chat ID</th><th>状态</th><th>备注</th><th>操作</th></tr></thead>
  <tbody>
    <% channels.forEach(c => { %>
    <tr>
      <td><%= c.id %></td>
      <td><%= c.name %></td>
      <td><code><%= c.chat_id %></code></td>
      <td>
        <span class="badge <%= c.enabled ? 'badge-on' : 'badge-off' %>"><%= c.enabled ? '启用' : '禁用' %></span>
      </td>
      <td><%= c.notes || '-' %></td>
      <td>
        <form class="inline" method="POST" action="/admin/channels/<%= c.id %>/toggle">
          <button class="btn btn-sm btn-primary"><%= c.enabled ? '禁用' : '启用' %></button>
        </form>
        <form class="inline" method="POST" action="/admin/channels/<%= c.id %>/delete" onsubmit="return confirm('确定删除?')">
          <button class="btn btn-danger btn-sm">删除</button>
        </form>
      </td>
    </tr>
    <% }) %>
  </tbody>
</table>
<%- include('../partials/footer') %>
