{include file="_partials/head.tpl"}

<div class="page-head">
  <div>
    <h1>Заявки: {form_title}</h1>
    <p class="muted"><a href="/admin/forms">← К формам</a> · <a href="/admin/forms/{form_id}/edit">Редактировать форму</a></p>
  </div>
  <div><a href="/admin/forms/{form_id}/export" class="btn btn-secondary">{icon name="download" size="16"} CSV</a></div>
</div>

<div class="tabs-bar">
  <a href="/admin/forms/{form_id}/submissions" class="tab [if {current_filter}=""]is-active[/if]">Все</a>
  <a href="/admin/forms/{form_id}/submissions?status=new" class="tab [if {current_filter}="new"]is-active[/if]"><span class="tab-dot tab-dot-pending"></span>Новые ({new_count})</a>
  <a href="/admin/forms/{form_id}/submissions?status=done" class="tab [if {current_filter}="done"]is-active[/if]"><span class="tab-dot tab-dot-approved"></span>Обработанные</a>
</div>

[if {is_empty}="1"]
<div class="empty-state">{icon name="mail" size="42"}<p>Заявок по этой форме пока нет.</p></div>
[else]
<div class="prod-table-wrap">
<table class="table prod-table">
  <thead>
    <tr>
      <th>Дата</th>
      [foreach var="cols" as="c"]<th>{c.label}</th>[/foreach]
      <th>Статус</th>
      <th class="actions"></th>
    </tr>
  </thead>
  <tbody>
    [foreach var="rows" as="r"]
      <tr>
        <td class="muted"><small>{r.created_at}</small></td>
        [foreach var="r.cells" as="cell"]<td><small>{cell.v}</small></td>[/foreach]
        <td><span class="badge badge-{r.status}">{r.status}</span></td>
        <td class="actions cmt-actions">
          [if {r.status}="new"]
            <form method="post" action="/admin/forms/sub/{r.id}/status" class="cmt-act">{csrf}<input type="hidden" name="status" value="done"><button type="submit" class="btn btn-primary btn-sm">{icon name="check" size="14"} Готово</button></form>
          [else]
            <form method="post" action="/admin/forms/sub/{r.id}/status" class="cmt-act">{csrf}<input type="hidden" name="status" value="new"><button type="submit" class="btn btn-ghost btn-sm">{icon name="arrow_left" size="14"} В новые</button></form>
          [/if]
          <form method="post" action="/admin/forms/sub/{r.id}/delete" class="cmt-act" onsubmit="return confirm('Удалить заявку?')">{csrf}<button type="submit" class="row-icon-btn row-icon-danger" title="Удалить">{icon name="trash" size="14"}</button></form>
        </td>
      </tr>
    [/foreach]
  </tbody>
</table>
</div>
{include file="_partials/pagination.tpl"}
[/if]

{include file="_partials/foot.tpl"}
