{layout @admin.html}
{block content}
{var $pageClass = models\Page::class}
<div class="column-group horizontal-gutters top-space">
  <div class="xlarge-75 large-75 medium-75 small-100 tiny-100">
    <h1>{_'pages'}</h1>
  </div>
  <div class="xlarge-25 large-25 medium-25 small-100 tiny-100 bottom-space">
    <a class="ink-button green" href="{=BASE_URL . 'page/add'}">{_'new_page'}</a>
  </div>
</div>
<div class ="column-group horizontal-gutters">
  <div class="xlarge-75 large-75 medium-100 small-100 tiny-100">
    <form action="{=BASE_URL}page/search" method="POST" class="ink-form half-bottom-space">
      <input type="search" name="keywords" placeholder="{_}keywords{/_}">
      <input type="submit" class="ink-button blue" value="{_}search{/_}">
    </form>
    {if $pages}
    {var $statuses = ['draft', 'published', 'hidden']}
    <table class="ink-table alternating hover medium">
      <thead>
	<tr>
	  <th class="align-left">{_'title'}</th>
	  <th class="align-left">{_'created_at'}</th>
	  <th class="align-left">{_'updated_at'}</th>
	  <th class="align-left">{_'status'}</th>
	  <th colspan="3"></th>
	</tr>
      </thead>
      <tbody>
	{foreach $pages as $page}
	<tr>
	  <td>{$page->title}</td>
	  <td>{$page->created_at|date:$mediumDate}</td>
	  <td>{$page->updated_at|date:$mediumDate}</td>
	  <td><span class="ink-label {switch (intval( $page->status ))}{case $pageClass::DRAFT}blue{case $pageClass::PUBLISHED}green{case $pageClass::HIDDEN}grey{/switch}">{_$statuses[$page->status]}</span></td>
	  <td><a href="{=BASE_URL}page/update/{$page->page_id}"><img alt="{_'update'}" src="public/images/edit_24.png"></a></td>
	  <td><a href="{=BASE_URL}page/add/{$page->page_id}"><img src="public/images/add_blue_24.png" alt="{_'add_child'}" title="{_'add_child'}"></a></td>
	  {var $confirm = ('confirm_delete_page'|translate:$page->title)}
	  <td><a href="{=BASE_URL}page/delete/{$page->page_id}"><img src="public/images/delete_24.png" alt="{_'remove_page'}" title="{_'remove_page'}" onclick="return confirm('{$confirm|noescape}');"></a></td>
	</tr>
	{/foreach}
      </tbody>
    </table>
    {include 'pagination/ink.html', url: BASE_URL . 'page/list?page=%d'}
    {else}
    <p class="align-center">{_}no_result_found{/_}</p>
    {/if}
  </div>
  <div class="xlarge-25 large-25 medium-100 small-100 tiny-100">
    <div>
      <header>
	<h2 class="medium">{_}last_modified_pages{/_}</h2>
      </header>
      <hr>
      <div class="small">
	<ul>
	  {foreach $pageClass::findLastModifiedPages() as $page}
	  <li>#{$page->page_id} <a href="{=BASE_URL}page/update/{$page->page_id}">{$page->title}</a> <span class="small-date">({$page->updated_at|date:$mediumDate})</span></li>
	  {/foreach}
	</ul>
      </div>
    </div>
    <div class="top-space">
      <header>
	<h2 class="medium">{_}last_created_pages{/_}</h2>
      </header>
      <hr>
      <div class="small">
	<ul>
	  {foreach $pageClass::findLastCreatedPages() as $page}
	  <li>#{$page->page_id} <a href="{=BASE_URL}page/update/{$page->page_id}">{$page->title}</a> <span class="small-date">({$page->created_at|date:$mediumDate})</span></li>
	  {/foreach}
	</ul>
      </div>
    </div>
  </div>
</div>
{/block}
