<?php
include_once "global.php";

$pageTitle = 'Manage Alternative Saturdays - ';
include_once 'header.php';
?>

<!--breadcrumb-->
<div class="page-breadcrumb d-none d-sm-flex align-items-center mb-3">
    <div class="breadcrumb-title pe-3">Custom Settings</div>
    <div class="ps-3">
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb mb-0 p-0">
                <li class="breadcrumb-item"><a href="javascript:;"></a>
                </li>
                <li class="breadcrumb-item active" aria-current="page">Alternative Saturdays</li>
            </ol>
        </nav>
    </div>
</div>
<!--end breadcrumb-->
<h6 class="mb-0 text-uppercase">Manage Alternative Saturdays</h6>
<hr>
<div class="card">
    <div class="card-body">
        <ul class="nav nav-tabs nav-success" role="tablist">
            <li class="nav-item" role="presentation">
                <a class="nav-link active" data-bs-toggle="tab" href="#successhome" role="tab" aria-selected="true">
                    <div class="tab-title">Off Saturdays</div>
                </a>
            </li>
            <li class="nav-item" role="presentation">
                <a class="nav-link" data-bs-toggle="tab" href="#successcontact" role="tab" aria-selected="false">
                    <div class="tab-title">Add New</div>
                </a>
            </li>
        </ul>
        <div class="tab-content py-3">
            <div class="tab-pane fade show active" id="successhome" role="tabpanel">
                <?php $crm->saturdaysView(); ?>
            </div>
            <div class="tab-pane fade" id="successcontact" role="tabpanel">
                <form id="saturdayAddForm" class="row g-3" method="post">
                    <div class="row mb-3">
                        <label class="col-sm-3 col-form-label">Select Off Saturdays</label>
                        <div class="col-sm-9">
                            <div class="row">
                                <?php
                                $today = new DateTime();
                                $offSaturdays = $dbF->getRows("SELECT `date` FROM `saturday_off`");
                                $offDates = array_column($offSaturdays, 'date');
                                for ($i = 0; $i < 12; $i++) {
                                    $saturday = clone $today;
                                    $saturday->modify("next saturday +{$i} weeks");
                                    $dateStr = $saturday->format('Y-m-d');
                                    $dateStr2 = $saturday->format('d-M-Y');

                                    $checked = in_array($dateStr, $offDates) ? 'checked' : '';

                                    echo "<div class='col-md-4 mb-2'>
                                        <div class='form-check'>
                                            <input class='form-check-input' type='checkbox' name='date[]' value='{$dateStr}' id='sat_{$i}' {$checked}>
                                            <label class='form-check-label' for='sat_{$i}'>
                                                {$dateStr2}
                                            </label>
                                        </div>
                                    </div>";
                                }
                                ?>
                            </div>
                        </div>

                    </div>
                    <div class="col-md-12">
                        <button type="submit" class="btn btn-grd-primary px-4">Submit</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<?php
include_once 'footer.php';
?>