<?php
// Set Open Graph tags for meta
$this->doctype('HTML5');
$this->headMeta($title, 'og:title', 'property');
$this->headMeta($this->escape($url), 'og:url', 'property');
$this->headMeta($shearContent, 'og:description', 'property');
// Set twitter for meta
$this->headMeta($this->escape($url), 'twitter:url');
$this->headMeta($title, 'twitter:title');
$this->headMeta($shearContent, 'twitter:description');

// Set for media
if (isset($galleryImages) && !empty($galleryImages) && isset($galleryImagesBig) && !empty($galleryImagesBig)) {
    $script
        = <<<'EOT'
window.addEventListener('DOMContentLoaded', function() {
    $('.gallery').each(function() {
        $(this).magnificPopup({
            delegate: 'a',
            type: 'image',
            gallery: {
                enabled:true
            }
        });
    });
});
EOT;
    $this->jQuery(['extension/jquery.magnific-popup.min.js' => ['defer' => 'defer']]);
    $this->jQuery('extension/magnific-popup.min.css', ['defer' => 'defer']);
    $this->footScript()->appendScript($script);
    $this->js(Pi::url('static/vendor/lazysizes/lazysizes.min.js'), ['async' => 'async']);
}
?>
<div class="clearfix">
    <?php if (!empty($nav)) { ?>
    <div class="col-md-2">
        <ul class="nav nav-pills bg-light mb-3 p-3">
            <?php foreach ($nav as $id => $item) { ?>
                <li class="nav-item">
                    <a class="nav-link <?php if (!empty($item['active'])) {
                        echo 'active';
                    } ?>" href="<?php echo $item['url']; ?>"><?php echo _escape($item['title']); ?></a>
                </li>
            <?php } ?>
        </ul>
    </div>
    <div class="col-md-10">
        <?php } ?>
        <div class="card mb-3">
            <?php if (isset($mainImage) && !empty($mainImage)) { ?>
                <img class="card-img-top" src="<?php echo $this->escape($mainImage['resized_url']); ?>"
                     alt="<?php echo $this->escape($mainImage['title']); ?><?php if ($mainImage['copyright']) echo ' - ' . $mainImage['copyright'] ?>">
            <?php } ?>
            <div class="card-body clearfix">
                <h1 class="card-title">
                    <?php echo $this->escape($title); ?>
                </h1>
                <div class="clearfix card-text">
                    <?php if ('phtml' == $markup && $content) { ?>
                        <?php
                        $file = sprintf(
                            '%s/' . Pi::config('theme') . '/custom/page/%s.phtml',
                            Pi::path('theme'),
                            $content
                        );

                        /**
                         * Check if theme has parent
                         */
                        $parentTheme = Pi::service('theme')->getParent(Pi::config('theme'));
                        if (!is_file($file) && $parentTheme) {
                            $file = sprintf(
                                '%s/' . $parentTheme . '/custom/page/%s.phtml',
                                Pi::path('theme'),
                                $content
                            );
                        }

                        if (!is_file($file)) {
                            $file = sprintf(
                                '%s/module/page/template/front/%s.phtml',
                                Pi::path('custom'),
                                $content
                            );
                        }

                        ?>
                        <?php if ($file) : ?>
                            <?php include $this->template($file); ?>
                        <?php else : ?>
                            <?php include $this->template('./' . $content); ?>
                        <?php endif; ?>
                    <?php } else { ?>
                        <?php echo $content; ?>
                    <?php } ?>
                    <?php if (isset($galleryImages) && !empty($galleryImages) && isset($galleryImagesBig) && !empty($galleryImagesBig)) { ?>
                        <div class="row clearfix gallery">
                            <?php foreach ($galleryImages as $key => $galleryImage) { ?>
                                <div class="u-photo col-lg-3 col-md-4 col-6 thumb mb-3">
                                    <a class="thumbnail" href="<?php echo $galleryImagesBig[$key]['resized_url']; ?>"
                                       title="<?php echo $this->escape($galleryImage['title']); ?><?php if ($galleryImage['copyright']) echo ' - ' . $galleryImage['copyright'] ?>">
                                        <img itemprop="image" class="img-fluid img-thumbnail lazyload"
                                             src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
                                             data-src="<?php echo $galleryImage['resized_url']; ?>"
                                             alt="<?php echo $this->escape($galleryImage['title']); ?>"/>
                                    </a>
                                </div>
                            <?php } ?>
                        </div>
                    <?php } ?>
                </div>
            </div>
            <?php if ($config['social_sharing']) { ?>
                <div class="article-footer clearfix">
                    <div class="col-md-5 col-sm-10 col-12">
                        <?php echo $this->socialSharing($config['social_sharing'], $title, $url); ?>
                    </div>
                </div>
            <?php } ?>
        </div>
        <?php if (!empty($nav)) { ?>
    </div>
<?php } ?>
</div>
