<?php
// Set doctype explicitly if it is not `HTML4_LOOSE`, i.e. 'HTML 4.01 Transitional'
$this->doctype('HTML5');

// Load translation data
$this->i18nTheme();

//HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries
$this->js([
    pi::url('static/js/html5shiv.js')   => [
        'conditional' => 'lt IE 9',
    ],
    pi::url('static/js/respond.min.js') => [
        'conditional' => 'lt IE 9',
    ],
]);

// Load jQuery
$this->jquery();

// Load Bootstrap css/js and font-awesome
$this->bootstrap([
    'js/bootstrap.bundle.js',
    'font-awesome/css/all.min.css',
]);

// Load front.css
$this->css($this->assetTheme('css/front.css'));

// Load localization css
$this->css($this->assetLocale('locale.css'));

// Load front.js on footer
$this->footScript()->appendFile($this->assetTheme('js/front.js'));

// Apple icons
// Apple icon for iphone
$this->headLink([
    'rel'  => 'apple-touch-icon',
    'href' => $this->assetTheme('image/touch-icon-iphone.png'),
]);
// Apple icon for ipad
$this->headLink([
    'rel'   => 'apple-touch-icon',
    'sizes' => '72x72',
    'href'  => $this->assetTheme('image/touch-icon-ipad.png'),
]);
// Apple icon for iphone retina
$this->headLink([
    'rel'   => 'apple-touch-icon',
    'sizes' => '114x114',
    'href'  => $this->assetTheme('image/touch-icon-iphone-retina.png'),
]);
// Apple icon for ipad retina
$this->headLink([
    'rel'   => 'apple-touch-icon',
    'sizes' => '114x114',
    'href'  => $this->assetTheme('image/touch-icon-ipad-retina.png'),
]);

// Meta Viewport Tag
$this->headMeta('width=device-width, initial-scale=1', 'viewport');

// Explicitly load favicon
$this->headLink([
    'rel'  => 'shortcut icon',
    'type' => 'image/x-icon',
    'href' => $this->favicon(),
]);
$this->headLink([
    'rel'  => 'shortcut icon',
    'type' => 'image/png',
    'href' => $this->favicon('favicon.png'),
]);

// Load google analytics code
$this->ga();

// Get module name
$module = Pi::service('module')->current();

// Get navigation
$navigation = $this->nav('front');

// Get block
$blocks        = $this->blocks();
$blockTemplate = $this->template('block');

// Get breadcrumbs
$breadcrumbs = $this->breadcrumb(
    ['prefix' => [
        [
            'label' => __('Home'),
            'href'  => Pi::url($this->url('home')),
        ],
    ]]
);
?>
<!DOCTYPE HTML>
<html lang="<?php echo $locale; ?>">
<head>
    <meta charset="<?php echo $charset; ?>">
    <!--[if IE]>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"><![endif]-->
</head>
<body id="pi-<?php echo $module; ?>" class="pi-locale-<?php echo $locale; ?> pi-front">
<!-- Header: brand, slogan, user bar -->
<header class="pi-header">
    <nav class="navbar navbar-expand-md navbar-dark bg-dark">
        <?php if ($module == 'system') { ?>
            <h1 class="navbar-brand">
                <a href="<?php echo Pi::url($this->url('home')); ?>"
                   title="<?php echo _escape($sitename); ?>">
                    <img src="<?php echo $this->assetTheme('image/logo.png'); ?>"
                         alt="<?php echo _escape($sitename); ?>">
                </a>
            </h1>
        <?php } else { ?>
            <h2 class="navbar-brand">
                <a href="<?php echo Pi::url($this->url('home')); ?>"
                   title="<?php echo _escape($sitename); ?>">
                    <img src="<?php echo $this->assetTheme('image/logo.png'); ?>"
                         alt="<?php echo _escape($sitename); ?>">
                </a>
            </h2>
        <?php } ?>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbar-collapse" aria-expanded="false" aria-label="<?php echo _escape($sitename); ?>">
            <i class="fas fa-bars"></i>
        </button>
        <div class="collapse navbar-collapse">
            <?php $class = in_array($locale, ['fa', 'ar']) ? 'navbar-nav ml-auto pi-navbar-nav' : 'navbar-nav mr-auto pi-navbar-nav'; ?>
            <?php echo $navigation->menu()->setUlClass($class); ?>
            <?php echo $this->widget('system-user-bar'); ?>
            <?php echo $this->widget('search-search'); ?>
        </div>
    </nav>
</header>
<!-- Page main content: breadcrumb, flash-messenger, blocks and module content -->
<section class="pi-section">
    <div class="container-fluid">
        <div class="pi-main-container">
            <?php if ($breadcrumbs) {
                echo $breadcrumbs;
            } ?>
            <!-- Flash messenger -->
            <?php include $this->template('flash-messenger'); ?>
            <!-- Top head zone -->
            <?php if (!empty($blocks['0'])) { ?>
                <div class="pi-zone-0">
                    <?php foreach ($blocks['0'] as $block) {
                        include $blockTemplate;
                    } ?>
                </div>
            <?php } ?>
            <div class="row">
                <!-- Left zone -->
                <?php if (!empty($blocks['1'])) { ?>
                    <div class="pi-zone-1 col-md-4">
                        <?php foreach ($blocks['1'] as $block) {
                            include $blockTemplate;
                        } ?>
                    </div>
                <?php } ?>
                <div class="<?php
                if (isset($blocks['1']) && isset($blocks['8'])) {
                    echo 'col-md-4';
                } elseif (isset($blocks['1']) || isset($blocks['8'])) {
                    echo 'col-md-8';
                } else {
                    echo 'col-md-12';
                }
                ?>">
                    <!-- Center top zone -->
                    <?php if (isset($blocks['2'])) { ?>
                        <div class="pi-zone-2">
                            <?php foreach ($blocks['2'] as $block) {
                                include $blockTemplate;
                            } ?>
                        </div>
                    <?php } ?>
                    <?php if (isset($blocks['3']) || isset($blocks['4'])) { ?>
                        <div class="row">
                            <div class="col-md-6 pi-zone-3">
                                <?php
                                if (isset($blocks['3'])) {
                                    foreach ($blocks['3'] as $block) {
                                        include $blockTemplate;
                                    }
                                }
                                ?>
                            </div>
                            <div class="col-md-6 pi-zone-4">
                                <?php
                                if (isset($blocks['4'])) {
                                    foreach ($blocks['4'] as $block) {
                                        include $blockTemplate;
                                    }
                                }
                                ?>
                            </div>
                        </div>
                    <?php } ?>
                    <!-- Module content starts -->
                    <?php if (!empty($content)) { ?>
                        <div class="<?php echo $module; ?>">
                            <div class="pi-module-content" data-ng-app="<?php echo $module; ?>">
                                <?php echo $content; ?>
                            </div>
                            <?php echo Pi::service('comment')->load(['options' => ['type' => 'js']]); ?>
                        </div>
                    <?php } ?>
                    <!-- Module content ends -->
                    <?php if (isset($blocks['5']) || isset($blocks['6'])) { ?>
                        <div class="row">
                            <div class="col-md-6 pi-zone-5">
                                <?php
                                if (isset($blocks['5'])) {
                                    foreach ($blocks['5'] as $block) {
                                        include $blockTemplate;
                                    }
                                }
                                ?>
                            </div>
                            <div class="col-md-6 pi-zone-6">
                                <?php
                                if (isset($blocks['6'])) {
                                    foreach ($blocks['6'] as $block) {
                                        include $blockTemplate;
                                    }
                                }
                                ?>
                            </div>
                        </div>
                    <?php } ?>
                    <!-- Center bottom zone -->
                    <?php if (isset($blocks['7'])) { ?>
                        <div class="pi-zone-7">
                            <?php foreach ($blocks['7'] as $block) {
                                include $blockTemplate;
                            } ?>
                        </div>
                    <?php } ?>
                </div>
                <!-- Right zone -->
                <?php if (isset($blocks['8'])) { ?>
                    <div class="col-md-4 pi-zone-8">
                        <?php foreach ($blocks['8'] as $block) {
                            include $blockTemplate;
                        } ?>
                    </div>
                <?php } ?>
            </div>
            <!-- Bottom foot zone -->
            <?php if (isset($blocks['99'])) { ?>
                <div class="pi-zone-99">
                    <?php foreach ($blocks['99'] as $block) {
                        include $blockTemplate;
                    } ?>
                </div>
            <?php } ?>
        </div>
    </div>
</section>
<!-- Footer: sitelink -->
<footer class="pi-footer">
    <?php
    $footer = Pi::config('footer');
    if ($footer) {
        echo $footer;
    } else {
        ?>
        <div class="container-fluid">
            <div class="row">
                <ul class="pi-footer-links muted list-inline">
                    <li class="list-inline-item">
                        <a href="<?php echo Pi::url('www'); ?>" title="<?php echo _escape($sitename); ?>">
                            &copy; <?php echo date('Y') . ' ' . _escape($sitename); ?>
                        </a>
                    </li>
                    <li class="list-inline-item">-</li>
                    <li class="list-inline-item">
                        <a rel="license" href="http://www.piengine.org" title="Pi Engine" target="_blank">
                            Powered by Pi Engine
                        </a>
                    </li>
                </ul>
            </div>
        </div>
    <?php } ?>
</footer>
<?php echo $this->conditions() ?>
</body>
</html>