<?php
/**
 * YAWIK
 *
 * @filesource
 * @copyright https://yawik.org/COPYRIGHT.php
 * @license   MIT
 */

$this->headScript()->appendFile($this->basepath('modules/Core/js/core.pagination.js'));
?>
<?php if (!$this->isAjaxRequest): ?>
<div class="panel panel-default pagination-container">
<?php endif ?>
<div class="panel-heading">
 <a style="text-decoration: none;" href="<?=$this->url('lang/applications', array(), array('query' => ""), true)?>">
  <?php if ($this->acl()->isRole('recruiter')):?>
    <?=$this->translate('Received Applications')?>
  <?php else:?>
    <?=$this->translate('Sent Applications')?>
  <?php endif;?>
 </a>
 <small>
 <?php #if ($hasJobs): ?>
 <?php
      #$countTmpl = '<span style="font-size:16px; font-weight:bold;">%s</span>';
      #$newCount = $appRepo->countBy($this->auth('id'), /* unread */ true);
      #$totalCount = $appRepo->countBy($this->auth('id'));
      #echo sprintf($this->translate('%1$s new from %2$s total applications'),
      #             sprintf('<span class="badge">'.$countTmpl.'</span>', $newCount),
      #             sprintf('<span class="badge">'.$countTmpl.'</span>', $totalCount))?>
 <?php #endif ?>
 </small>
 <i class="pagination-loading yk-icon yk-icon-spinner fa-spin pull-right"></i>
</div>
<table class="table table-striped table-bordered table-hover" id="cam-application-list">
<thead>
 <tr>
  <th><?=$this->translate('Applicant')?></th>
  <th><?=$this->translate('Job')?></th>
  <th><?=$this->translate('Date')?></th>
 </tr>
</thead>
<?php foreach ($this->applications as $app): /* @var \Applications\Entity\Application $app */?>
    <tr<?=($app->isUnreadBy($this->auth('id'))?' class="yk-new"':'')?>>
      <td>
        <div class="portrait">
          <?php if ($app->getContact()->getImage()):?>
            <img src="<?=$this->basePath($app->getContact()->getImage()->getUri()) ?>" />
          <?php else:?>
            <span class="yk-icon yk-icon-portrait fa-3x"></span>
          <?php endif?>
        </div>
        <a href="<?=$this->url('lang/applications/detail', array('id' => $app->getId()), true)?>">
          <?=$this->translate($this->salutation($app->getContact()->getGender()))?>
          <?=$app->getContact()->getDisplayName()?><br>
          <?=$app->getContact()->getCity()?>
        </a>
      </td>
      <td>
          <a target="_blank" href="<?= $app->getJob()->getLink() ? $app->getJob()->getLink() : $this->jobUrl($app->getJob(), ['linkOnly' => true ]) ; ?>">
              <?=$app->getJob()->getTitle()?>
          </a>
      </td>
      <td><?=$this->dateFormat($app->getDateCreated(), 'short', 'none') ?></td>
    </tr>
<?php endforeach ?>
</table>
<div class="yk-panel-foot">
<?=$this->paginationControl(
    $this->applications,
    'Sliding',
    'pagination-control',
    [
        'lang' => $this->params('lang'),
        'route' => 'lang/applications-dashboard'
    ]);?>
</div>
<?php if (!$this->isAjaxRequest): ?>
</div>
<?php endif ?>