<?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/. */

require_once __DIR__ . "/../required.php";

redirectifnotloggedin();

if (!is_empty($VARS['id'])) {
    if ($database->has('families', ['familyid' => $VARS['id']])) {
        $family = (new Family())->load($VARS['id']);
    } else {
        header('Location: app.php?page=families&msg=family_doesnt_exists');
        die();
    }
} else {
    header('Location: app.php?page=families&msg=family_doesnt_exists');
    die();
}
?>
<div class="row justify-content-center">
    <div class="col-12 col-sm-6 col-sm-offset-3">
        <div class="card border-red text-center">
            <h3 class="card-header text-red">
                <?php $Strings->get("Delete Family"); ?>
            </h3>
            <div class="card-body">
                <p><i class="fas fa-exclamation-triangle fa-10x"></i></p>
                <h4><?php $Strings->get("Are you sure you want to delete this family?") ?></h4>
                <h5><?php $Strings->get("This action cannot be undone!  All information about this family, including payment history, will be purged forever."); ?></h5>
                <div class="list-group">
                    <div class="list-group-item">
                        <i class="fas fa-fw fa-users"></i> <?php echo $family->getName(); ?>
                    </div>
                    <div class="list-group-item">
                        <i class="fas fa-fw fa-male"></i> <?php echo $family->getFather(); ?>
                    </div>
                    <div class="list-group-item">
                        <i class="fas fa-fw fa-female"></i> <?php echo $family->getMother(); ?>
                    </div>
                    <?php
                    foreach ($family->getChildren() as $child) {
                        ?>
                    <div class="list-group-item">
                        <i class="fas fa-fw fa-user-graduate"></i> <?php echo $child->getName(); ?>
                    </div>
                    <?php
                    }
                    ?>
                </div>
            </div>
            <div class="card-footer d-flex">
                <a href="app.php?page=families" class="btn btn-primary mr-auto"><i class="fas fa-arrow-left"></i> <?php $Strings->get('Cancel'); ?></a>
                <a href="action.php?action=deletefamily&source=families&familyid=<?php echo htmlspecialchars($VARS['id']); ?>" class="btn btn-danger"><i class="fas fa-times"></i> <?php $Strings->get('Delete'); ?></a>
            </div>
        </div>
    </div>
</div>