<?php
include_once './dbconn.php';

if(isset($_GET['id'])) {
    $id = $_GET['id'];

    $sql = "SELECT * FROM  web_app_enrollee_data WHERE id = '$id'";
    $result = mysqli_query($conn, $sql);
    $result_checker = mysqli_num_rows($result);
    if ($result_checker > 0) {
        while ($data = mysqli_fetch_assoc($result)) {
            $enrollment_serial_no = $data['enrollment_serial_no'];
            $company_name = $data['company_name'];
            $surname = $data['surname'];
            $first_name = $data['first_name'];
            $hmo_id = $data['hmo_id'];
            $address_street = $data['address_street'];
            $address_state = $data['address_state'];
            $address_city = $data['address_city'];
            $hospitals = $data['hospitals'];
            $email_address = $data['email_address'];
        }
    }

    $sql = "SELECT company, link, company_code, groupplan FROM web_app_enrollment_form Where company = '$company_name'";
        $result = $conn->query($sql);
        
        
        // Check if there are any rows returned
        if ($result->num_rows > 0) {
            // Output data of each row
            while($row = $result->fetch_assoc()) {
                $company=$row["company"];
                $link=$row["link"];
                $company_code= $row["company_code"];
                $groupplan=$row["groupplan"];
                
            }
        } 
                    

} else {
    // header("Location: ./index.php");
    die();
}

?>


<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Add Dependant</title>
    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome CSS -->
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" rel="stylesheet">

</head>

<body>

    <style>
    .content {
        width: 80%;
        padding: 50px 5%;
        /* border: 1px solid gray; */
        border-radius: 10px;
        margin: 50px auto;
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    }
    </style>
    <div class="content">
        <a href="index.php" class="btn btn-secondary mb-3">Go Back</a>
        <!-- Modal content -->
        <div class="modal-content">
            <h2 class='text-center text-primary'>Add New Dependant</h2>
            <form id="modalForm" action="./addnew/adddependant.php" method="post" enctype="multipart/form-data">
                <div class="form-row row py-2">
                    <div class="form-group col-md-6  py-2">
                        <label for="group">Principal</label>
                        <input type="text" class="form-control" name="principal" value="<?=$first_name. ' '. $surname?>"
                           >
                    </div>
                    <div class="form-group col-md-6  py-2">
                        <label for="group">Group</label>
                        <input type="text" class="form-control" name="group" value="<?=$company_name?>">
                    </div>
                    <!-- hidden  -->
                    <input type="hidden" name="company_code" value="<?=$company_code?>">
                     <input type="hidden" name="principalid" value="<?=$hmo_id?>">
                    <div class="form-group col-md-6">
                        <label for="firstName">First Name</label>
                        <input type="text" class="form-control" id="firstName" name="firstname" required
                            placeholder="First Name">
                    </div>
                    <div class="form-group col-md-6">
                        <label for="lastName">Last Name</label>
                        <input type="text" class="form-control" id="lastName" name="lastname" value="<?= $surname?>"
                            required placeholder="Last Name">
                    </div>
                </div>
                <div class="form-row row py-2">
                    <div class="form-group col-md-6">
                        <label for="middlename">Middle Name</label>
                        <input type="text" class="form-control" id="lastName" name="middlename" 
                            placeholder="Last Name">
                    </div>
                    <div class="form-group col-md-6">
                        <label for="phoneNumber">Phone Number</label>
                        <input type="tel" class="form-control" id="phoneNumber" name="phonenumber" 
                            placeholder="Phone Number">
                    </div>

                </div>
                <div class="form-row row py-2">
                    <div class="form-group col-md-6">
                        <label for="email">Email</label>
                        <input type="email" class="form-control" id="email" name="email"  value="<?= $email_address?>" placeholder="Email">
                    </div>
                    <div class="form-group col-md-6">
                        <label for="dependant">Dependant Type</label>
                        <select id="dependant" class="form-control" name="dependant" required>
                            <option selected>Choose...</option>
                            <option value='B'>Spouse</option>
                            <option value='C'>First Dependant</option>
                            <option value='D'>Second Dependant</option>
                            <option value='E'>Third Dependant</option>
                            <option value='F'>Fourth Dependant</option>
                            <option value='G'>Fifth Dependant</option>
                            <option value='H'>Sixth Dependant</option>
                            <option value='I'>Seventh Dependant</option>
                            <option value='J'>Eighth Dependant</option>
                        </select>
                    </div>
                </div>
                <div class="form-row row py-2">
                    <div class="form-group col-md-6">
                        <label for="gender">Gender</label>
                        <select id="gender" class="form-control" name="gender" required>
                            <option selected>Choose...</option>
                            <option>Male</option>
                            <option>Female</option>
                        </select>
                    </div>
                    <div class="form-group col-md-6">
                        <label for="dob">Date Of Birth</label>
                        <input type="date" class="form-control" id="dob" name="dob" required>
                    </div>


                </div>
                <div class="form-row row py-2">
                    <div class="form-group col-md-6">
                        <label for="state">State</label>
                        <select class="form-control" id="state" onchange="populateLocalGovernments()" name="state"
                            required>
                            <option selected><?= $address_state?></option>
                            <option value="Abia">Abia</option>
                            <option value="Adamawa">Adamawa</option>
                            <option value="Abuja">Abuja</option>
                            <option value="AkwaIbom">Akwa Ibom</option>
                            <option value="Anambra">Anambra</option>
                            <option value="Bauchi">Bauchi</option>
                            <option value="Bayelsa">Bayelsa</option>
                            <option value="Benue">Benue</option>
                            <option value="Borno">Borno</option>
                            <option value="CrossRiver">Cross River</option>
                            <option value="Delta">Delta</option>
                            <option value="Ebonyi">Ebonyi</option>
                            <option value="Edo">Edo</option>
                            <option value="Ekiti">Ekiti</option>
                            <option value="Enugu">Enugu</option>
                            <option value="Gombe">Gombe</option>
                            <option value="Imo">Imo</option>
                            <option value="Jigawa">Jigawa</option>
                            <option value="Kaduna">Kaduna</option>
                            <option value="Kano">Kano</option>
                            <option value="Katsina">Katsina</option>
                            <option value="Kebbi">Kebbi</option>
                            <option value="Kogi">Kogi</option>
                            <option value="Kwara">Kwara</option>
                            <option value="Lagos">Lagos</option>
                            <option value="Nassarawa">Nassarawa</option>
                            <option value="Niger">Niger</option>
                            <option value="Ogun">Ogun</option>
                            <option value="Ondo">Ondo</option>
                            <option value="Osun">Osun</option>
                            <option value="Oyo">Oyo</option>
                            <option value="Plateau">Plateau</option>
                            <option value="Rivers">Rivers</option>
                            <option value="Sokoto">Sokoto</option>
                            <option value="Taraba">Taraba</option>
                            <option value="Yobe">Yobe</option>
                            <option value="Zamfara">Zamfara</option>
                        </select>
                    </div>
                    <div class="form-group col-md-6">
                        <label for="lga">Local Government</label>
                        <select class="form-control" name="lga" id="local-government">
                            <option selected disabled>Select Local Government</option>
                        </select>
                        <script src="./statelga.js"></script>
                    </div>
                </div>
                <div class="form-row row py-2">
                    <div class="form-group col-md-6">
                        <label for="City">City</label>
                        <input type="text" class="form-control" id="city" name="city" value="<?= $address_city?>" required placeholder="City">
                    </div>
                    <div class="form-group col-md-6">
                        <label for="address">Address</label>
                        <input type="text" class="form-control" id="address" name="address" value="<?= $address_street?>" required
                            placeholder="Address">
                    </div>

                </div>
                <div class="form-row row py-2">
                    <div class="form-group col-md-6">
                        <label for="planType">Plan Type</label>
                        <select class="form-control" class="form-control" id="planType" name="plantype" required>
                            <option selected disabled>Select Plan</option>
                            <option value="Flex Plan"> Flex Plan </option>
            				<option value="Executive Plan"> Executive Plan </option>
            				<option value="Upper Plan"> Upper Plan </option>
            				<option value="Business Plan"> Business Plan </option>
            				<option value="Club Plan"> Club Plan </option>
            				<option value="Social Plan"> Social Plan </option>
                        </select>
                    </div>
                    <div class="form-group col-md-6">
                        <label for="roup Type">Plan Category</label>
                        <select class="form-control" class="form-control" id="groupType" name="grouptype" required>
                            <option selected disabled>Select Plan</option>
                            <option value="Individual">Individual</option>
                            <option value="Family">Family</option>
                        </select>
                    </div>
                </div>
                <div class="form-row row py-2">
                    <div class="form-group col-md-12">
                        <label for="selectedProvider">Selected Provider</label>
                        <select class="form-control" class="form-control" id="provider" name="provider" required>
                            <option selected ><?= $hospitals?></option>
                            <?php
                                // Fetch data from the table
                                $sql = "SELECT provider_name FROM web_app_provider_list";
                                $result = $conn->query($sql);
                                
                                
                                // Check if there are any rows returned
                                if ($result->num_rows > 0) {
                                    // Output data of each row
                                    while($row = $result->fetch_assoc()) {
                                        $provider=$row["provider_name"];
                                        echo "<option value='" . $provider . "'>" . $provider . "</option>";
                                        
                                    }
                                } else {
                                    echo "<option value=''>No data available</option>";
                                }
                                                    
                            ?>
                        </select>
                    </div>
                </div>



                <div class="form-row row py-2">
                    <div class="form-group col-md-6">
                        <label for="status">Status</label>
                        <select class="form-control" class="form-control" id="status" name="status" required>
                            <option selected disabled>Status</option>
                            <option value="Approved">Approved</option>
                            <option value="Pending">Pending</option>
                            <option value="Denied">Denied</option>
                        </select>
                    </div>
                    <div class="form-group col-md-6">
                        <label for="passport">Passport</label>
                        <input type="file" class="form-control form-control-file" id="passport" name="passport">
                    </div>
                </div>

                <div class="form-row row py-2">
                    <div class="form-group col-md-6">
                        <label for="Genotype">Genotype</label>
                        <select class="form-control" class="form-control" id="Genotype" name="genotype" required>
                            <option selected disabled>Select Genotype</option>
                            <option value="AA">AA</option>
                            <option value="AS">AS</option>
                            <option value="SS">SS</option>
                            <option value="AC">AC</option>
                            <option value="SC">SC</option>
                            <option value="CC">CC</option>
                        </select>
                    </div>
                    <div class="form-group col-md-6">
                        <label for="bloodgroup">Blood Group</label>
                        <select class="form-control" class="form-control" id="bloodgroup" name="bloodgroup" required>
                            <option selected disabled>Select Blood Group</option>
                            <option value="A+">A+</option>
                            <option value="A-">A-</option>
                            <option value="B+">B+</option>
                            <option value="B-">B-</option>
                            <option value="AB+">AB+</option>
                            <option value="AB-">AB-</option>
                            <option value="O+">O+</option>
                            <option value="O-">O-</option>
                        </select>
                    </div>
                </div>

                <div class="form-row row py-2">
                    <div class="form-group col-md-12">
                        <label for="allergies">Allergies</label>
                        <input type="text" class="form-control" id="allergies" name="allergies" 
                            placeholder="Any Allergies">
                    </div>
                </div>

                <div class="form-row row py-2">
                    <div class="form-group col-md-6">
                        <label for="pre-existing">Has Pre-Existing Condition</label>
                        <select class="form-control" class="form-control" id="has-pre-existing" name="haspreexisting"
                            required>
                            <option selected disabled>Select...</option>
                            <option value="Yes">Yes</option>
                            <option value="No">No</option>
                        </select>
                    </div>
                    <div class="form-group col-md-6">
                        <label for="pre-existing">Pre-Existing Condition</label>
                        <input type="text" class="form-control" id="pre-existing" name="preexisting" 
                            placeholder="Pre-Existing Condition">
                    </div>
                </div>

                <div class="form-row row py-2">
                    <div class="form-group col-md-6">
                        <label for="surgicalhist">Has Surgical History</label>
                        <select class="form-control" class="form-control" id="hassurgicalhist" name="hassurgicalhist"
                            required>
                            <option selected disabled>Select...</option>
                            <option value="Yes">Yes</option>
                            <option value="No">No</option>
                        </select>
                    </div>
                    <div class="form-group col-md-6">
                        <label for="Surgical-History">Surgical History</label>
                        <input type="text" class="form-control" id="SurgicalHistory" name="surgicalhist"
                            placeholder="Surgical History">
                    </div>
                </div>


                <button type="submit" class="btn btn-primary px-4 mt-4" name="add">Add</button>
            </form>
        </div>
    </div>
    <!-- Bootstrap JS -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
    <!-- jQuery Library -->
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <!-- Font Awesome JS -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/js/all.min.js"></script>
</body>

</html>