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

<div class="page-head">
  <div>
    <h1>{lang key="admin.categories_title"}</h1>
  </div>
  <div class="actions">
    <a class="btn btn-secondary [if {current_entity}][else]is-active[/if]" href="/admin/categories">Все</a>
    [foreach var="entities" as="e"]
      <a class="btn btn-secondary [if {current_entity}={e.slug}]is-active[/if]" href="/admin/categories?entity={e.slug}">{e.label}</a>
    [/foreach]
    <a class="btn btn-primary" href="/admin/categories/create[if {current_entity}]?entity={current_entity}[/if]">{lang key="admin.categories_new"}</a>
  </div>
</div>

[if {categories}]
<table class="table">
  <thead>
    <tr>
      <th>#</th>
      <th>{lang key="admin.name"}</th>
      <th>Применяется к</th>
      <th>{lang key="admin.slug"}</th>
      <th>{lang key="admin.sort_order"}</th>
      <th class="actions">{lang key="admin.actions"}</th>
    </tr>
  </thead>
  <tbody>
    [foreach var="categories" as="c"]
      <tr class="cat-depth-{c.depth}">
        <td>{c.id}</td>
        <td>
          <span class="cat-tree-prefix">{c.prefix}</span>
          <a href="/admin/categories/{c.id}/edit" class="row-link">{c.title}</a>
        </td>
        <td><span class="cat-chip">{c.entity_label}</span></td>
        <td><code>{c.slug}</code></td>
        <td>{c.sort_order}</td>
        <td class="actions">
          <a href="/category/{c.slug}" target="_blank" title="{lang key="admin.open_site"}">{icon name="external" size="16"}</a>
          <form method="post" action="/admin/categories/{c.id}/delete" style="display:inline" data-confirm="{lang key=&quot;admin.delete_confirm&quot;}">
            {csrf}
            <button type="submit" class="danger" title="{lang key="admin.delete"}">{icon name="trash" size="16"}</button>
          </form>
        </td>
      </tr>
    [/foreach]
  </tbody>
</table>
[else]
<div class="empty-state">
  {icon name="categories" size="40"}
  <p>{lang key="admin.categories_empty"}</p>
</div>
[/if]

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