<div class="breadcrumb">
    <h1>Assign Point To Clinic</h1>
    <ul>
        <li><a href="<?php echo SITE_URL.ADMIN_DIR ?>">Dashboard</a></li>
        <li>Assign Point To Clinic</li>
    </ul>
</div>
<div class="separator-breadcrumb border-top"></div>

<?php if (isset($resStatus)) { ?>
    <div class="alert alert-<?php echo $resStatus['error'] ? 'danger' : 'success'; ?> alert-dismissible fade show" role="alert">
        <?php echo $resStatus['msg']; ?>
        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
            <span aria-hidden="true">&times;</span>
        </button>
    </div>
<?php } ?>

<div class="row">
    <div class="col-md-12">
        <div class="card mb-4">
            <div class="card-body">
                <form action="" method="post" id="assignPointForm" name="assignPointForm">
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="clinic_id">Clinic <span class="text-danger">*</span></label>
                                <select class="form-control" id="clinic_id" name="clinic_id" required>
                                    <option value="">Select Clinic</option>
                                    <?php
                                    if ($clinicData && count($clinicData) > 0) {
                                        foreach ($clinicData as $clinic) {
                                            $selected = (isset($_POST['clinic_id']) && $_POST['clinic_id'] == $clinic->clinic_id) ? 'selected' : '';
                                            echo "<option value='" . $clinic->clinic_id . "' " . $selected . ">" . $clinic->clinic_name . "</option>";
                                        }
                                    }
                                    ?>
                                </select>
                            </div>
                        </div>
                        
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="plan_id">Plan <span class="text-danger">*</span></label>
                                <select class="form-control" id="plan_id" name="plan_id" required>
                                    <option value="">Select Plan</option>
                                    <?php
                                    if (isset($clinicloyaltyPlans) && count($clinicloyaltyPlans) > 0) {
                                        foreach ($clinicloyaltyPlans as $plan) {
                                            $selected = (isset($_POST['plan_id']) && $_POST['plan_id'] == $plan['id']) ? 'selected' : '';
                                            echo "<option value='" . $plan['id'] . "' " . $selected . ">" . $plan['title'] . " - $" . $plan['amount'] . " (" . $plan['totalPoints'] . " points)</option>";
                                        }
                                    }
                                    ?>
                                </select>
                            </div>
                        </div>
                        
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="type">Type</label>
                                <input type="text" class="form-control" id="type" name="type" 
                                       value="Credited" readonly>
                            </div>
                        </div>
                        
                        <div class="col-md-12">
                            <div class="form-group">
                                <label for="description">Description</label>
                                <input type="text" class="form-control" id="description" name="description" 
                                       value="Referral Points From Xcare">
                            </div>
                        </div>
                        
                        <div class="col-md-12">
                            <div class="form-group">
                                <input type="submit" class="btn btn-primary" id="submit" name="submit" value="Submit">
                                <a href="assignPointToClinicList.php" class="btn btn-secondary">Cancel</a>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
$(document).ready(function() {
    // Form validation
    $('#assignPointForm').on('submit', function(e) {
        var clinicId = $('#clinic_id').val();
        var planId = $('#plan_id').val();
        
        if (!clinicId || !planId) {
            e.preventDefault();
            alert('Please fill all required fields.');
            return false;
        }
    });
});
</script>
