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

<div class="page-head">
  <div>
    <h1>{lang key="admin.news_title"}</h1>
    <p class="muted">{lang key="admin.news_total"}: {pagination.total}</p>
  </div>
  <div class="actions">
    <a class="btn btn-secondary" href="/admin/news">{lang key="admin.all"}</a>
    <a class="btn btn-secondary" href="/admin/news?status=published">{lang key="admin.news_published"}</a>
    <a class="btn btn-secondary" href="/admin/news?status=draft">{lang key="admin.news_drafts"}</a>
    <a class="btn btn-primary" href="/admin/news/create">{lang key="admin.news_new"}</a>
  </div>
</div>

[if {news}]
<table class="table">
  <thead>
    <tr>
      <th>#</th>
      <th>{lang key="admin.title"}</th>
      <th>{lang key="admin.category"}</th>
      <th>{lang key="admin.status"}</th>
      <th>{lang key="admin.views"}</th>
      <th>{lang key="admin.date"}</th>
      <th class="actions">{lang key="admin.actions"}</th>
    </tr>
  </thead>
  <tbody>
    [foreach var="news" as="n"]
      <tr>
        <td>{n.id}</td>
        <td>
          <a href="/admin/news/{n.id}/edit" class="row-link"><b>{n.title}</b></a>
        </td>
        <td>
          [if {n.category_title}]
            <a href="/admin/categories/{n.category_id}/edit" class="cat-chip">{n.category_title}</a>
          [else]
            <span class="muted">—</span>
          [/if]
        </td>
        <td>
          [if {n.status}="published"]<span class="badge badge-published">{lang key="admin.published"}</span>[else]<span class="badge badge-draft">{lang key="admin.draft"}</span>[/if]
        </td>
        <td>{n.views}</td>
        <td class="muted">{n.published_at}</td>
        <td class="actions">
          <a href="/news/{n.slug}" target="_blank" title="{lang key="admin.open_site"}">{icon name="external" size="16"}</a>
          <form method="post" action="/admin/news/{n.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>
{include file="_partials/pagination.tpl"}
[else]
<div class="empty-state">
  {icon name="news" size="40"}
  <p>{lang key="admin.news_empty"}</p>
</div>
[/if]

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