<?php

use WoWPress\Models\Raid;

global $widget_area;

global $year;
global $month;
set_sidebar_status('top', false);



$raids = Raid::where("start", ">", "$year-$month-01 00:00:00")->get();

get_header();
?>
<div class="top-title flex flex-row gap-2" style="margin-top:calc(-1 * var(--wowp-gap))">
<div class="text-3xl font-bold bg-glass shadow p-3 text-center w-full">
    <?= $GLOBALS['wowpress']['page_title'] ?>
</div>
</div>

<section id="primary">
    <main id="main">
        <div class="bg-glass shadow p-auto">
            <div class="text-xl font-bold bg-glass text-white text-center"><?= format_date("$year-$month-1", 'MMMM') ?></div>
            <div class="grid grid-cols-7 gap-1 pt-1" style="grid-auto-rows: 1fr">
                <?php
                for ($i = 1; $i <= date("t", strtotime("$year-$month-01")); $i++) {
                    $has_raid = [];
                    foreach ($raids as $raid) {
                        if (format_date($raid->start) == format_date("$year-$month-$i")) {
                            $has_raid[] = $raid;
                        }
                    }
                ?>
                    <div class="bg-glass p-auto text-center <?php if (count($has_raid) > 0) { ?> glow shadow-<?=$has_raid[0]->color?> <?php } ?> grid grid-cols-2 grid-rows-2">
                        <div class="text-left"><?= date('d', strtotime("$year-$month-$i")) ?></div>
                        <div class="text-right"><?= format_date("$year-$month-$i", 'E') ?></div>

                        <?php
                        foreach($has_raid as $raid){
                        ?>

                                <a href="<?=$raid->link?>" class="group" style="grid-area: 2 / 1 / 3 / 3;">
                                    <div class="group-hover:text-<?=$raid->color?> bg-<?=$raid->color?>-200"><?=$raid->title?></div>
                                    <?php if($raid->difficulty): ?><div class="text-sm text-slate-500">(<?=$raid->difficulty?>)</div><?php endif; ?>
                                </a>
                        <?php
                            
                        }
                        ?>
                    </div>
                <?php
                }
                ?>
            </div>
        </div>
    </main>
</section>

<?php
get_footer();
