<?php
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
?>
<div class="card-deck">
    <div class="card bg-blue text-light">
        <div class="card-body">
            <h4 class="card-title"><?php $Strings->get("Campers") ?></h4>
            <h1><i class="fas fa-fw fa-users"></i> <?php echo $database->count('campers'); ?></h1>
        </div>
        <div class="card-footer">
            <a href="app.php?page=people&filter=camper" class="text-light"><i class="fas fa-arrow-right"></i> <?php $Strings->get("View Campers"); ?></a>
        </div>
    </div>

    <div class="card bg-indigo text-light">
        <div class="card-body">
            <h4 class="card-title"><?php $Strings->get("Adults") ?></h4>
            <h1><i class="fas fa-fw fa-users"></i> <?php echo $database->count('adults'); ?></h1>
        </div>
        <div class="card-footer">
            <a href="app.php?page=people&filter=adult" class="text-light"><i class="fas fa-arrow-right"></i> <?php $Strings->get("View Adults"); ?></a>
        </div>
    </div>

    <div class="card bg-indigo text-light">
        <div class="card-body">
            <h4 class="card-title"><?php $Strings->get("Youth") ?></h4>
            <h1><i class="fas fa-fw fa-users"></i> <?php echo $database->count('youth'); ?></h1>
        </div>
        <div class="card-footer">
            <a href="app.php?page=people&filter=youth" class="text-light"><i class="fas fa-arrow-right"></i> <?php $Strings->get("View Youth"); ?></a>
        </div>
    </div>
</div>

<div class="card-deck mt-sm-4">
    <div class="card bg-purple text-light">
        <div class="card-body">
            <h4 class="card-title"><?php $Strings->get("Adults") ?></h4>
            <h1 class="d-inline mr-2"><i class="fas fa-calendar-alt"></i></h1>
            <h2 class="d-inline">
                <?php
                $daystrs = $database->select("adults", "days");
                $days = ["Tu" => 0, "We" => 0, "Th" => 0, "Fr" => 0];
                foreach ($daystrs as $str) {
                    if ($str == "") {
                        continue;
                    }
                    $arr = str_split($str, 2);
                    foreach ($arr as $day) {
                        $days[$day] += 1;
                    }
                }

                foreach ($days as $day => $count) {
                    ?>
                    <span class="mr-3 text-nowrap"><?php echo $day; ?> <?php echo $count; ?></span>
                <?php } ?>
            </h2>
        </div>
    </div>

    <div class="card bg-purple text-light">
        <div class="card-body">
            <h4 class="card-title"><?php $Strings->get("Youth") ?></h4>
            <h1 class="d-inline mr-2"><i class="fas fa-calendar-alt"></i></h1>
            <h2 class="d-inline">
                <?php
                $daystrs = $database->select("youth", "days");
                $days = ["Tu" => 0, "We" => 0, "Th" => 0, "Fr" => 0];
                foreach ($daystrs as $str) {
                    if ($str == "") {
                        continue;
                    }
                    $arr = str_split($str, 2);
                    foreach ($arr as $day) {
                        $days[$day] += 1;
                    }
                }

                foreach ($days as $day => $count) {
                    ?>
                    <span class="mr-3 text-nowrap"><?php echo $day; ?> <?php echo $count; ?></span>
                <?php } ?>
            </h2>
        </div>
    </div>
</div>

<div class="card-deck mt-sm-4">
    <div class="card bg-blue-grey text-light">
        <div class="card-body">
            <h4 class="card-title"><?php $Strings->get("Shirts") ?></h4>
            <h1 class="d-inline mr-2"><i class="fas fa-tshirt"></i></h1>
            <h2 class="d-inline">
                <?php
                $shirtcount = $database->select("people", "shirt");
                $shirts = ["YS" => 0, "YM" => 0, "YL" => 0, "AS" => 0, "AM" => 0, "AL" => 0, "AX" => 0, "A2" => 0];
                foreach ($shirtcount as $str) {
                    if ($str == "NO") {
                        continue;
                    }
                    $shirts[$str] += 1;
                }

                foreach ($shirts as $shirt => $count) {
                    ?>
                    <span class="mr-3 text-nowrap"><?php
                        if ($shirt == "AX") {
                            echo "AXL";
                        } else if ($shirt == "A2") {
                            echo "AXXL";
                        } else {
                            echo $shirt;
                        }
                        ?> <?php echo $count; ?></span>
                <?php } ?>
            </h2>
        </div>
    </div>
</div>

<div class="card-deck mt-sm-4">
    <div class="card bg-green text-light">
        <div class="card-body">
            <h4 class="card-title"><?php $Strings->get("Total Income") ?></h4>
            <h1><i class="fas fa-fw fa-money-bill-alt"></i> $<?php
                $amounts = $database->select("payments", "amount");
                $total = 0.0;
                foreach ($amounts as $amt) {
                    $total += $amt;
                }
                echo number_format($total, 2);
                ?></h1>
        </div>
    </div>

    <div class="card bg-green text-light">
        <div class="card-body">
            <h4 class="card-title"><?php $Strings->get("Card Payments") ?></h4>
            <h1><i class="fas fa-fw fa-credit-card"></i> $<?php
                $amounts = $database->select("payments", "amountpaid");
                $total = 0.0;
                foreach ($amounts as $amt) {
                    $total += $amt;
                }
                echo number_format($total, 2);
                ?></h1>
        </div>
    </div>
</div>