<?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-indigo text-light">
        <div class="card-body">
            <h4 class="card-title"><?php $Strings->get("Families") ?></h4>
            <h1><i class="fas fa-fw fa-users"></i> <?php echo $database->count('families'); ?></h1>
        </div>
        <div class="card-footer">
            <a href="app.php?page=families" class="text-light"><i class="fas fa-arrow-right"></i> <?php $Strings->get("View Families"); ?></a>
        </div>
    </div>

    <div class="card bg-green text-light">
        <div class="card-body">
            <h4 class="card-title"><?php $Strings->get("Recent Payments") ?></h4>
            <h1><i class="fas fa-fw fa-dollar-sign"></i> <?php
                $amounts = $database->select("payments", "amount", ["AND" => ["paid" => 1, "date[>]" => date("Y-m-d H:i:s", strtotime("-30 days"))]]);
                $total = 0.0;
                foreach ($amounts as $amt) {
                    $total += $amt;
                }
                echo number_format($total, 2);
                ?></h1>
        </div>
        <div class="card-footer">
            <a href="app.php?page=payments" class="text-light"><i class="fas fa-arrow-right"></i> <?php $Strings->get("View Payments"); ?></a>
        </div>
    </div>

    <?php
    $expiring = $database->count('families', ["expires[<]" => date("Y-m-d", strtotime("+1 month"))]);
    ?>
    <div class="card bg-<?php echo ($expiring > 0 ? "purple" : "blue"); ?> text-light">
        <div class="card-body">
            <h4 class="card-title"><?php $Strings->get("Expiring Memberships") ?></h4>
            <h1><i class="fas fa-fw fa-user-clock"></i> <?php echo $expiring; ?></h1>
        </div>
        <div class="card-footer">
            <a href="app.php?page=families&filter=expiring" class="text-light"><i class="fas fa-arrow-right"></i> <?php $Strings->get("View Expiring"); ?></a>
        </div>
    </div>
</div>
