<?php
//select child details
$sql = "SELECT * FROM children_details LEFT JOIN signup_types ON children_details.sign_up_option_id = signup_types.id";
$result = mysqli_query($conn, $sql);
//if row is not empty
if (mysqli_num_rows($result) > 0) {
    echo '<div class="table-holder">';
    echo '<table class="table">';
    echo '<thead>';
    echo '<tr>';
    echo "<th>Child's Name</th>";
    echo "<th>Father's Name</th>";
    echo "<th>Mother's Name</th>";
    echo "<th>Sign Up Option</th>";
    echo "<th>Invoiced?</th>";
    echo "<th>Next Invoice Due</th>";
    echo "<th>Actions</th>";
    echo '</tr>';
    echo '</thead>';
    echo '<tbody>';


    while ($row = mysqli_fetch_assoc($result)) {
        echo '<tr>';
        echo "<td>" . $row['child_name'] . "</td>";
        echo "<td>" . $row['father_name'] . "</td>";
        echo "<td>" . $row['mother_name'] . "</td>";
        echo "<td>" . $row['option_name'] . "</td>";
        echo "<td>";
        if ($row['is_invoiced']) {
            echo '<i class="bi bi-check-circle-fill green"></i>';
        } else {
            echo '<i class="bi bi-x-circle-fill red"></i>';
        }
        echo "</td>";
        echo "<td>";
        if($row['invoice_due'] == '0000-00-00') 
        {  
            echo '-';
        }
        else
        {
           echo  date_create_from_format("Y-m-d", $row['invoice_due'])->format("D, F j, Y");
        }
        echo "</td>";
        echo "<td>";
        echo '<a child-id="' . $row['child_id'] . '" class="btn ci-btn">Create Invoice</a>';
        echo '<span class="action-btn">';
        echo '<a class="menu-icon"><i class="bi bi-three-dots-vertical"></i></a>';
        echo '<div class="nav-btns">';
        echo '<div class="btn-container">';
        echo '<a class="nav-btn" href="index.php?page=edit_child&id=' . $row['child_id'] . '">Edit</a>';
        echo '<a class="nav-btn del" href="">Delete</a>';
        echo '</div>';
        echo '</div>';
        echo '</span>';
        echo '</td>';
        echo '</tr>';
    }
    echo '</tbody>';
    echo '</table>';
    echo '</div>';

} else { ?>
    <div class="nothing-found">
        <h1 class="emoji">🤷</h1>
        <h2>No Children Found!</h2>
    <?php
}
    ?>