<?php

use lim\_shared\models\wpPost;

$main = array_slice($_view["titleStories"], 0, 1)[0];
$subMain = array_slice($_view["titleStories"], 1, 1)[0];
$titles = array_slice($_view["titleStories"], 2);

?>

<div class="main-container">
    <section>
        <h1 class="headline hero space-mb-lg text-center text-lg-start">Das 2bgood Magazin</h1>
        <div class="row g-c">
            <div class="col-xl-8 col-lg-6">
                <?= $_con->getRenderedView("magazine/indexCardMain.partial", $main); ?>
            </div>
            <?php if ($_view["widgetData"] ?? null) { ?>
            <div class="col-xl-4 col-lg-6">
                <div class="bg-lightpink space-py-md space-px-sm mobile-space-py-xl mobile-w-100">
                    <div class="row g-4 g-lg-0">
                        <div class="col-7 col-lg-12 space-px-md space-mb-sm d-flex align-items-center"> 
                            <img class="w-100 h-100" width="320" height="296" 
                                src="<?= $_con->getLink(["media", "image", "magazine", "0", "abo-magazin-digital.webp", "320", "0", "60"]); ?>" 
                                alt="2bgood-Magazin aktuelle Ausgabe">
                        </div>
                        <div class="col-5 col-lg-12 d-flex align-items-center">
                            <div>
                                <h3 class="headline small">Aktuelle Ausgabe <?= $_view["widgetData"]["month"] ?>/<?= $_view["widgetData"]["year"]; ?></h3>
                                <p class="space-mb-sm"><b>
                                        <nobr>Print & Digital</nobr> • <nobr><?= $_view["widgetData"]["pages"]; ?> Seiten</nobr>
                                    </b></p>
                            </div>
                        </div>
                    </div>
                    <ul class="pink space-mb-md d-none d-lg-block">
                        <?php foreach ($_view["widgetData"]["facts"] as $fact) { ?>
                            <li><?= $fact; ?></li>
                        <?php } ?>
                    </ul>
                    <div class="text-center"> 
                        <a href="<?= $_con->getLink(["magazine", "subscribe"]); ?>" class="btn lg btn-primary magazin ico left mb-2">
                            <span class="icon"></span>Magazin abonnieren
                        </a>
                        <p class="mb-0 txt-small">4 Ausgaben/Jahr · 39€ · Jederzeit kündbar</p>
                    </div>
                </div>
            </div>
            <?php } ?>
        </div>
    </section>
    <section>
        <div class="row g-c">
            <?php foreach ($_view["magazineStories"] as $row) { ?>
            <div class="col-xl-6 col-lg-12">
                <?= $_con->getRenderedView("magazine/indexCardMedium.partial", $row); ?>
            </div>
            <?php } ?>
        </div>
    </section>
    <?php if ($_view["recommendedStories"] ?? null) { ?>
    <section>
        <h2 class="headline medium">Leseempfehlung</h2>
        <div class="spacer-lg lightgray mobile-w-100"></div>
        <div class="row g-c">
            <?php foreach ($_view["recommendedStories"] as $row) { ?>
                <div class="col-lg-4">
                    <?= $_con->getRenderedView("magazine/articleCard.partial", $row); ?>
                </div>
            <?php } ?>
        </div>
    </section>
    <?php } ?>
    <section>
        <h2 class="headline medium">Wissen</h2>
        <div class="spacer-lg lightgray mobile-w-100"></div>
        <?php
        $categories = wpPost::getValidCategories();
        foreach ($categories as $category) {
            if ($category !== reset($categories)) { ?>
                <div class="spacer-sm lightgray d-none d-lg-block"></div>
            <?php } ?>
            <?= $_con->getRenderedView(
                "magazine/indexOverviewCategory.partial",
                [ "category" => $category, "articles" => $_view["categories"][$category], "categoryDescriptions" => $_view["categoryDescriptions"]]
            ); ?>
        <?php } ?>
    </section>
    <section>
        <div class="row">
            <div class="col">
                <h2 class="headline medium">Die Vorreiter aus dem Mittelstand</h2>
            </div>
            <div class="col-auto d-none d-lg-block">
                <a href="<?= $_con->getLink(["magazine", "overview"]); ?>" class="btn md btn-secondary ico right mb-2">Alle Erfolgsgeschichten<span class="icon"></span></a>
            </div>
        </div>
        <div class="spacer-lg darkpink mobile-w-100"></div>
        <div class="row g-c">
            <?php foreach (array_slice($_view["companyStories"], 0, 2) as $row) { ?>
            <div class="col-xl-4 col-lg-6">
                <?= $_con->getRenderedView("magazine/articleCard.partial", $row); ?>
            </div>
            <?php } ?>
            <div class="col-xl-4 col-lg-12">
                <div class="row g-c">
                    <?php foreach (array_slice($_view["companyStories"], 2, 3) as $row) { ?>
                        <div class="col-12">
                            <?= $_con->getRenderedView("magazine/indexCardSmall.partial", $row); ?>
                        </div>
                    <?php } ?>
                </div>
            </div>
        </div>
    </section>
    <section>
        <?= $_con->getRenderedView("index/newsletter.partial"); ?>
    </section>
    <section>
        <h2 class="headline medium">Titelstories</h2>
        <div class="spacer-lg lightgray mobile-w-100"></div>
        <div class="row g-c">
            <div class="col-xl-6 col-lg-12">
                <?= $_con->getRenderedView("magazine/articleCard.partial", $subMain); ?>
            </div>
            <div class="col-xl-6 col-lg-12">
                <div class="row g-c">
                    <?php foreach ($titles as $row) { ?>
                    <div class="col-12">
                        <?= $_con->getRenderedView("magazine/indexCardMedium.partial", $row); ?>
                    </div>
                    <?php } ?>
                </div>
            </div>
        </div>
    </section>
</div>

<?= $_con->getRenderedView("magazine/ctaMagazine.partial"); ?>