<?php use PHPCI\Helper\Lang; ?>
<div class="row">

    <div class="col-sm-5">
        <?php print $summary; ?>
    </div>

    <div class="col-sm-7 pull-left">
        <div class="box box-primary">
            <div class="box-header">
                <h3 class="box-title"><?php Lang::out('latest_builds'); ?></h3>
            </div>

            <div class="box-body">
                <ul class="timeline">
                    <?php $last = new \DateTime('-1 Year'); ?>

                    <?php
                    foreach ($builds as $build):
                        switch ($build->getStatus()) {
                            case \PHPCI\Model\Build::STATUS_NEW:
                                $updated = $build->getCreated();
                                $label = Lang::get('pending');
                                $color = 'blue';
                                break;

                            case \PHPCI\Model\Build::STATUS_RUNNING:
                                $updated = $build->getStarted();
                                $label = Lang::get('running');
                                $color = 'yellow';
                                break;

                            case \PHPCI\Model\Build::STATUS_SUCCESS:
                                $updated = $build->getFinished();
                                $label = Lang::get('successful');
                                $color = 'green';
                                break;

                            case \PHPCI\Model\Build::STATUS_FAILED:
                                $updated = $build->getFinished();
                                $label = Lang::get('failed');
                                $color = 'red';
                                break;
                        }

                        if (!$updated) {
                            $updated = $build->getCreated();
                        }

                        if ($updated->format('Y-m-d') != $last->format('Y-m-d')): $last = $updated;
                            ?>
                            <li class="time-label">
                    <span class="bg-gray">
                        <?php print Lang::formatDateTime($last, 'll'); ?>
                    </span>
                            </li>
                        <?php endif; ?>

                        <!-- /.timeline-label -->
                        <!-- timeline item -->
                        <li>
                            <i class="fa fa-<?php print $build->getProject()->getIcon(); ?> bg-<?php print $color; ?>"></i>
                            <div class="timeline-item">
                                <span class="time"><i class="fa fa-clock-o"></i> <?php print Lang::formatDateTime($updated, 'LT'); ?></span>
                                <h3 class="timeline-header">
                                    <a href="<?php print PHPCI_URL; ?>project/view/<?php print $build->getProjectId(); ?>">
                                        <?php print $build->getProject()->getTitle(); ?>
                                    </a>
                                    -
                                    <a href="<?php print PHPCI_URL; ?>build/view/<?php print $build->getId(); ?>">
                                        Build #<?php print $build->getId(); ?>
                                    </a>
                                    -
                                    <?php print $label; ?>
                                </h3>

                                <div class="timeline-body">
                                    <?php
                                    if ($build->getCommitId() !== 'Manual') {
                                        print sprintf(
                                            '<a href="%s" target="_blank">%s (%s)</a>',
                                            $build->getCommitLink(),
                                            substr($build->getCommitId(), 0, 7),
                                            $build->getCommitterEmail()
                                        );
                                    } else {
                                        print Lang::get('manual_build');
                                    }
                                    ?>
                                    - <?php print $build->getCommitMessage(); ?>
                                </div>
                            </div>
                        </li>
                        <!-- END timeline item -->

                    <?php endforeach; ?>

                    <li>
                        <i class="fa fa-clock-o"></i>
                    </li>
                </ul>
            </div>
        </div>
    </div>

</div>
