<?php
    // initialize the framework
    require "../../../framework.php";

    // define some typehints for stan to work more precesely
    /** @var lim\sess $_sess */
    /** @var lim\req $_req */
    /** @var lim\portal\controllers\moduleController $_con */

    // get and the view and view data from the controller and put a likely type to it for stan
    $_view = $_con->getView();
    $_viewData = $_con->getViewData();
    /** @var array<int|float|string|bool|null> $_viewData */

    // determine if "viewOnly" is set in the viewdata, which we'll use as flag to skip the layout and only render the view
    $viewOnly = ($_viewData["viewOnly"] ?? false) === true;

    // record a visit the the page for
    lim\models\stats::record("visit");

    // import the resource controller as it is used for minifying
    use lim\controllers\resourceController;

    // if we minify the code per feature flag and gzip is supported, we invoke it explictly to compress the output - in any case buffer the output
    $_conf->getFeature("enableMinify") && is_string($_SERVER['HTTP_ACCEPT_ENCODING']) && stristr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') ? ob_start("ob_gzhandler") : ob_start();
?>
<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title><?= $_con->page->getTitle(); ?></title>
<?php foreach ($_con->page->getMeta() as $name => $content) { ?>
        <meta name="<?= $name; ?>" content="<?= $content; ?>" />
<?php } foreach ($_con->page->getGraph() as $property => $content) { ?>
        <meta property="<?= $property; ?>" content="<?= $content; ?>" />
<?php } foreach ($_con->page->getCanonical() as $url) { ?>
        <link rel="canonical" href="<?= $url; ?>" />
<?php } foreach ($_con->page->getPreload() as $preload) { ?>
        <link rel="preload" <?= trim(implode(" ", array_map(fn ($val, $key) => "$key=\"$val\"", $preload, array_keys($preload)))); ?>>
<?php } ?>
        <link href="###CSS_RESOURCE_LINK_PLACEHOLDER###" rel="stylesheet" />
        <link rel="icon" href="<?= $_con->getLink(["assets", "images", "favicon-32x32.png"]); ?>" sizes="32x32" />
        <link rel="icon" href="<?= $_con->getLink(["assets", "images", "favicon-192x192.png"]); ?>" sizes="192x192" />
        <link rel="apple-touch-icon" href="<?= $_con->getLink(["assets", "images", "favicon-180x180.png"]); ?>" />
    </head>
<?php if ($viewOnly) { ?>
    <body class="pt-0">
<?php } else { ?>
    <body>
<?php } ?>
        <?php
            if ($data = $_sess->getOnce("_limTempMessage")) {
                /** @var array<string> $data */
                echo $_con->getRenderedView("_common/tempMessage.partial", $data);
            }

            if (!$viewOnly) {
                echo $_con->getRenderedView("_common/navigation.partial", ["nav" => $_con->nav]);
            }

            // if the "viewOnly" flag is set in the view data, display only the content - no nav, temp message etc.
            if ($_req->_limRouting["controller"] == "company" && $_con->userLoggedIn() && ($user = $_con->getAuthUser()) && $user->emailConfirmed != 1) {
                echo $_con->getRenderedView("company/emailConfirmation.partial");
            }

            if ($_con->viewIsSet()) {
                echo '<main role="main">';
                $_con->renderView();
                echo '</main>';
            }
        ?>
        <?php if (!$viewOnly) { ?>
        <footer role="contentinfo">
            <div class="container">
                <div class="row">
                    <div class="col text-center text-lg-start"> <img src="<?= $_con->getLink(["assets", "images" ,"logo.svg"]);?>" 
                        width="185" height="67" alt="2bgood-Logo" class="logo-nav">
                        <p class="txt-big text-center text-lg-start mt-2 d-block d-lg-none">Gute Unternehmen erkennt man am <img
                                src="<?= $_con->getLink(["assets", "images" ,"logo.svg"]);?>" class="logo-headline" width="90" height="33" alt="2bgood">-Siegel.</p>
                    </div>
                    <div class="col-lg-auto">
                        <div class="social">
                            <div class="d-block d-lg-flex align-items-center ">
                                <p class="txt-big d-inline-block mt-3">Folgen Sie uns auf:</p>
                                <div class="social-icons">
                                    <a href="https://www.facebook.com/2bgood.de" target="_blank"><span class="icon"></span></a>
                                    <a href="https://www.instagram.com/2bgood.de" target="_blank"><span class="icon"></span></a>
                                    <a href="https://www.linkedin.com/company/104873414/" target="_blank"><span class="icon"></span></a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <p class="txt-big text-center text-lg-start mt-2 d-none d-lg-block">Gute Unternehmen erkennt man am <img
                        src="<?= $_con->getLink(["assets", "images" ,"logo.svg"]);?>" class="logo-headline" width="90" height="33" alt="2bgood">-Siegel.</p>
                <form method="POST" id="newsletterForm" action="<?= $_con->getLink(["newsletter", "registerForm"]); ?>" class="validateForm">
                    <div class="row space-mb-lg mb-lg-0">
                        <div class="col-xl-5 col-lg-6 col-md-12">
                            <p class="txt-big  text-center text-lg-start">Newsletter</p>
                            <div class="input-group mb-3 d-flex justify-content-center">
                                <input type="text" name="email" class="form-control newsletter required requiredEmail" 
                                    placeholder="E-Mailadresse eingeben" aria-label="E-Mail Adresse" aria-describedby="button-newsletter">
                                <input type="submit" class="btn btn-primary newsletter" id="button-newsletter" value="Newsletter abonnieren" />
                            </div>
                            <div class="form-check">
                                <input class="form-check-input newsletter required" type="checkbox" name="dppConfirmation" value="1" id="checkNewsletterfooter">
                                <label class="form-check-label" for="checkNewsletterfooter">
                                    Einwilligung zur <a href="<?= $_con->getLink(["index", "content", "datenschutzerklaerung"]); ?>" target="_blank">Datenschutzerklärung</a>
                                </label>
                            </div>
                        </div>
                    </div>
                </form>
                <div class="row">
                    <div class="col-lg-3 text-center text-lg-start">
                        <p class="txt-big"><img src="<?= $_con->getLink(["assets", "images" ,"logo.svg"]);?>" width="90" height="33" class="logo-headline" alt="2bgood"> Score</p>
                        <a href="<?= $_con->getLink(["interview"]); ?>" class="footer-link">Jetzt Score berechnen</a><br>
                        <a href="<?= $_con->getLink(["auth", "login"]); ?>" class="footer-link">Login</a><br>
                        <a href="<?= $_con->getLink(["assets", "downloads", "2bgood_Nachhaltigkeitsbericht_Muster.pdf"]); ?>" class="footer-link">Beispiel ansehen</a><br>
                        <a href="<?= $_con->getLink(["profile"]); ?>" class="footer-link">Rankings</a><br>
                    </div>
                    <div class="col-lg-3 text-center text-lg-start">
                        <p class="txt-big">Magazin</p>
                        <a href="<?= $_con->getLink(["magazine"]); ?>" class="footer-link">Stories</a><br>
                        <a href="<?= $_con->getLink(["magazine", "overview", "menschen"]); ?>" class="footer-link">Menschen</a><br>
                        <a href="<?= $_con->getLink(["magazine", "overview", "ressourcen"]); ?>" class="footer-link">Ressourcen</a><br>
                        <a href="<?= $_con->getLink(["magazine", "overview", "zukunft"]); ?>" class="footer-link">Zukunft</a><br>
                        <a href="<?= $_con->getLink(["magazine", "subscribe"]); ?>" class="footer-link">Abo</a>
                    </div>
                    <div class="col-lg-3 text-center text-lg-start">
                        <p class="txt-big"><img src="<?= $_con->getLink(["assets", "images" ,"logo.svg"]);?>" width="90" height="33" class="logo-headline" alt="2bgood"></p>
                        <a href="<?= $_con->getLink(["index", "aboutUs"]); ?>" class="footer-link">Über uns</a><br>
                        <a href="<?= $_con->getLink(["index", "method"]);?>" class="footer-link">Methodik</a>
                    </div>
                    <div class="col-lg-3 text-center text-lg-start">
                        <p class="txt-big">Legal</p>
                        <a href="<?= $_con->getLink(["index", "content", "impressum"]); ?>" class="footer-link">Impressum</a><br>
                        <a href="<?= $_con->getLink(["index", "content", "datenschutzerklaerung"]); ?>" class="footer-link">Datenschutz</a><br>
                        <a href="<?= $_con->getLink(["index", "content", "kontakt"]); ?>" class="footer-link">Kontakt</a><br>
                        <a href="<?= $_con->getLink(["complaint"]); ?>" class="footer-link">Beschwerdestelle</a>
                    </div>
                    <div class="col-lg-12 text-center text-lg-start space-mt-lg">
                        <p>© <?= date("Y"); ?> 2bgood GmbH. Alle Rechte vorbehalten.</p>
                    </div>
                </div>
            </div>
        </footer>
        <?php } ?>
        <script language="javascript"><?php $_con->renderGvcContent(); ?></script>
        <script src="<?=$_con->getLink(["resource", "render", "js"], ["view" => $_view ]); ?>" async defer></script>
<?php
    $_con->addBreadcrumbToSchema();
    if ($schema = $_con->page->getSchema()) {
?>        <script type="application/ld+json"><?php
            if ($schema = json_encode($schema)) {
                echo $_conf->getFeature("enableMinify") ? resourceController::minifyJs($schema) : $schema;
            }
?></script>
    <?php } ?>
    </body>
</html>
<?php
    // gather the output and clean the buffer
    if (!$content = ob_get_contents()) {
        throw new \Exception("content could not be loaded");
    }
    ob_end_clean();

    // the css link is generated after the page is rendered as we may need to know which views were rendered in the meanwhile to purge the css
    // we need to get the parameters first, which always includes the view
    $cssResourceParams = ["view" => $_view];

    // the view stack needs to be included as well if present as it is passed to the purge script to look for classes in
    if ($_conf->getFeature("enablePurgeCss")) {
        $cssResourceParams["viewStack"] = $_con->getViewStack();
    }

    // the css link is a placeholder in the dom, which we need to replace with the actual resource controller link before rendering
    $content = str_replace("###CSS_RESOURCE_LINK_PLACEHOLDER###", $_con->getLink(["resource", "render", "css"], $cssResourceParams), $content);

    // lastly, render the actualy content, minified if so requested
    echo $_conf->getFeature("enableMinify") ? resourceController::minifyHtml($content) : $content;
?>