<?php
require_once('__header.php');

$directions = $pages->findOne('template=directions');
$industries = $pages->findOne('template=industries');

$filter = $sanitizer->text($input->get('filter'));
if ($filter == "directions"):
    $id = $sanitizer->int($input->get('id'));
    $subitems = $directions->children();
    $projects = $page->children('direction.parent=' . $id);
elseif ($filter == "industries"):
    $id = $sanitizer->int($input->get('id'));
    $subitems = $industries->children();
    $projects = $page->children('industry=' . $id);
else:
    $filter = '';
    $projects = $page->children();
endif;
?>
    <div class="wrap">
        <div class="grid"></div>
        <h1 class="title"><?php echo $page->title; ?></h1>
        <ul class="inner-cat">
            <li <?php echo in_array($filter, array('directions', 'industries')) ? '' : 'class="active"'; ?>><a
                    href="<?php echo $page->url; ?>"><?php echo _x('All projects', '-'); ?></a></li>
            <li <?php echo $filter == 'directions' ? 'class="active"' : ''; ?>><a
                    href="<?php echo $page->url; ?>?filter=directions"><?php echo $directions->title; ?></a></li>
            <li <?php echo $filter == 'industries' ? 'class="active"' : ''; ?>><a
                    href="<?php echo $page->url; ?>?filter=industries"><?php echo $industries->title; ?></a></li>
        </ul>
        <div class="inner-sub-cat">
            <ul>
                <?php
                foreach ($subitems as $item):
                    echo '<li'
                        . ($item->id == $id ? ' class="active"' : '')
                        . '><a href="' . $page->url . '?filter=' . $filter . '&id=' . $item->id . '">' . $item->title . '</a></li>';
                endforeach;
                ?>
            </ul>
        </div>
        <ul class="projects">
            <?php
            foreach ($projects as $item):
                echo '<li><a href="' . $item->url . '"><img src="' . $item->image->url . '">'
                    . '<div class="lib-footer"><a href="' . $item->url . '">'
                    . '<span>' . $item->title . '</span><small>' . $item->headline . '</small>'
                    . '</a></div></a></li>';
            endforeach;
            ?>
        </ul>
    </div>
    <script>
        var swiper = new Swiper('.swiper-container', {
            pagination: '.swiper-pagination',
            slidesPerView: 3,
            centeredSlides: true,
            paginationClickable: true,
            spaceBetween: 0,
            grabCursor: true,
            nextButton: '.swiper-button-next',
            prevButton: '.swiper-button-prev'
        });
    </script>
<?php require_once('__footer.php'); ?>