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

<div class="page-head">
  <div>
    <h1>{lang key="shop.promocodes_list.title"} <span class="muted" style="font-weight:400">· {total}</span></h1>
    <p class="muted">{lang key="shop.promocodes_list.subtitle"}</p>
  </div>
  <div class="actions">
    <a class="btn btn-primary" href="/admin/shop/promocodes/create">+ {lang key="shop.promocodes_list.new"}</a>
  </div>
</div>

[if {codes}]
<div class="prod-table-wrap">
<table class="table prod-table">
  <thead>
    <tr>
      <th>{lang key="shop.promocode.code"}</th>
      <th>{lang key="shop.attribute.type"}</th>
      <th>{lang key="shop.promocodes_list.col.value"}</th>
      <th>{lang key="shop.promocodes_list.col.min_amount"}</th>
      <th>{lang key="shop.promocodes_list.col.uses"}</th>
      <th>{lang key="shop.promocodes_list.col.period"}</th>
      <th>{lang key="shop.common.yes"}</th>
      <th class="actions"></th>
    </tr>
  </thead>
  <tbody>
    [foreach var="codes" as="c"]
      <tr>
        <td><a href="/admin/shop/promocodes/{c.id}/edit" class="prod-title"><code>{c.code}</code></a></td>
        <td><span class="prod-chip-cat">[if {c.type}="percent"]Процент[/if][if {c.type}="fixed"]Фикс. сумма[/if][if {c.type}="free_shipping"]Бесплатная доставка[/if]</span></td>
        <td>[if {c.type}="percent"]{c.value}%[else][if {c.type}="fixed"]{price amount="{c.value}"}[else]—[/if][/if]</td>
        <td>[if {c.min_amount}]{price amount="{c.min_amount}"}[else]<span class="muted">—</span>[/if]</td>
        <td>{c.usage_count}[if {c.usage_limit}] / {c.usage_limit}[/if]</td>
        <td><small class="muted">[if {c.starts_at}]{c.starts_at}[else]—[/if] → [if {c.ends_at}]{c.ends_at}[else]∞[/if]</small></td>
        <td>[if {c.is_active}]<span class="badge badge-published">{lang key="shop.common.yes"}</span>[else]<span class="badge badge-draft">{lang key="shop.common.no"}</span>[/if]</td>
        <td class="actions prod-row-actions">
          <a href="/admin/shop/promocodes/{c.id}/edit" class="btn btn-ghost btn-sm">{lang key="shop.common.edit_short"}</a>
          <form method="post" action="/admin/shop/promocodes/{c.id}/delete" style="display:inline" data-confirm="Удалить промокод?" data-confirm-danger="1">
            {csrf}<button type="submit" class="row-icon-btn row-icon-danger" title="{lang key="shop.common.delete_title"}">{icon name="close" size="14"}</button>
          </form>
        </td>
      </tr>
    [/foreach]
  </tbody>
</table>
</div>
{include file="_partials/pagination.tpl"}
[else]
<div class="empty-state">
  <div class="icon">{icon name="tag" size="42"}</div>
  <p>{lang key="shop.promocodes_list.empty_title"}</p>
  <a href="/admin/shop/promocodes/create" class="btn btn-primary">{lang key="shop.common.create_first"}</a>
</div>
[/if]

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