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

<div class="page-head">
  <div><h1>Заявки с сайта <span class="muted" style="font-weight:400">· {pagination.total}</span></h1></div>
</div>

<div class="tabs-bar">
  <a href="/admin/leads" class="tab [if {current_filter}=""]is-active[/if]">Все</a>
  <a href="/admin/leads?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/leads?status=done" class="tab [if {current_filter}="done"]is-active[/if]"><span class="tab-dot tab-dot-approved"></span>Обработанные</a>
</div>

[if {leads}]
<div class="prod-table-wrap">
<table class="table prod-table">
  <thead>
    <tr>
      <th>Дата</th>
      <th>Имя</th>
      <th>Контакты</th>
      <th>Услуга</th>
      <th>Сообщение</th>
      <th>Статус</th>
      <th class="actions"></th>
    </tr>
  </thead>
  <tbody>
    [foreach var="leads" as="l"]
      <tr>
        <td class="muted"><small>{l.created_at}</small>[if {l.source_label}]<br><small class="muted" style="opacity:.7">{l.source_label}</small>[/if]</td>
        <td><b>{l.name}</b></td>
        <td><a href="tel:{l.phone}">{l.phone}</a>[if {l.email}]<br><small class="muted">{l.email}</small>[/if]</td>
        <td><small>{l.service}</small></td>
        <td class="cmt-body-cell">{l.message}</td>
        <td><span class="badge badge-{l.status}">{l.status}</span></td>
        <td class="actions cmt-actions">
          [if {l.status}="new"]
            <form method="post" action="{l.status_action}" 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="{l.status_action}" 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="{l.delete_action}" class="cmt-act" data-confirm="Удалить заявку безвозвратно?" data-confirm-danger="1">{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"}
[else]
<div class="empty-state">
  {icon name="mail" size="42"}
  <p>Заявок пока нет. Они появятся здесь после отправки формы на сайте.</p>
</div>
[/if]

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