<h1 class="title"><?= __('Achievements') ?></h1>

<div class="grid achievements">
    <?php $total = count($achievements) ?>
    <div class="grid-6">
        <?php foreach ($achievements as $index => $achievement): ?>
            <div class="box-panel margin-bottom">
                <div class="box-panel-title"><?= $achievement['name'] ?></div>
                <div class="box-panel-content">
                    <div class="description">
                        <?= $achievement['description'] ?>
                    </div>
                    <div class="requirements">
                        <div class="title"><?= __('Requirements') ?></div>
                        <?php foreach ($achievement['requirements'] as $requirement): ?>
                            <div class="requirement">
                                <?= $requirement['title'] ?>
                                <span style="float:right"><?= $requirement['current'] ?>/<?= $requirement['total'] ?></span>
                                <div class="progress">
                                    <div class="bar" style="width:<?= $requirement['percentage'] ?>%"><?= $requirement['percentage'] ?>%</div>
                                </div>
                            </div>
                        <?php endforeach ?>
                        <?php if ($achievement['require_achievement']): ?>
                            <div class="requirement">
                                <?= __('Require') ?> <?= $achievement['require_achievement'] ?>
                                <span style="float:right"><?= $achievement['require_achievement_ok'] ? 1 : 0 ?>/1</span>
                                <div class="progress">
                                    <div class="bar" style="width:<?= $achievement['require_achievement_ok'] ? 100 : 0 ?>%"><?= $achievement['require_achievement_ok'] ? 100 : 0 ?>%</div>
                                </div>
                            </div>
                        <?php endif ?>
                        <div class="title"><?= __('Rewards') ?></div>
                        <ul class="rewards">
                            <?php foreach ($achievement['rewards'] as $reward): ?>
                                <li><?= $reward['title'] ?></li>
                            <?php endforeach ?>
                        </ul>
                    </div>

                    <?php if ($achievement['available']): ?>
                        <div class="actions">
                            <a data-ajax-action href="<?= url_to('/achievements/rescue/' . $achievement['id']) ?>" class="btn"><?= __('Rescue') ?></a>
                        </div>
                    <?php endif ?>
                </div>
            </div>
            <?php if (($index + 1) >= $total / 2): ?>
                </div><div class="grid-6">
            <?php endif ?>
        <?php endforeach ?>
    </div>
</div>