<style>
    .checkBox input:checked~.checkmark {
        background-color: #032da1;
    }

    .checkmark {
        position: absolute;
        top: 6px;
        left: 0;
        height: 15px;
        width: 15px;
        border: 1px solid #ced4da;
        border-radius: 0.25rem;
    }

    .small,
    small {
        font-size: 75%;
        font-weight: 500;
    }
</style>

<div class="wraper responsive-width">
    <main class="long-tbl-main students_list_table" id="main">
        <div class="from-group">
            <a href="javascript:history.back()"><button type="button" class="btn btn-success btn-sm btn-dark">Back</button></a>
        </div>

        <!-- admin template section -->
        <div class="admin_tempblock">
            <div class="admin_tempsec">
                <div class="admin_sec">
                    <?php
                    if (!empty($this->session->flashdata('success'))) { ?>
                        <div class="alert alert-success">
                            <a href="#" class="close" data-dismiss="alert">&times;</a>
                            <strong>Success!</strong> <?php echo $this->session->flashdata('success'); ?>
                        </div>
                    <?php
                    }
                    if (!empty($this->session->flashdata('danger'))) {
                    ?>
                        <div class="alert alert-danger">
                            <a href="#" class="close" data-dismiss="alert">&times;</a>
                            <strong>Failed!</strong> <?php echo $this->session->flashdata('danger'); ?>
                        </div>
                    <?php } ?>
                    <div class="subsec_sec">
                        <div class="subject_r">
                            <div class="subject_lsec">
                                <?php if (!empty($theStudentInfo)) { ?>
                                    <!-- <div class="subject_lhead"> -->

                                    <?php
                                    if (empty($theStudentInfo['photo'])) {

                                        $profileimg = base_url() . "common_assets/user.png";
                                    } else if (file_exists('assets_student/application/' . $theStudentInfo['photo'])) {

                                        $profileimg = base_url() . "assets_student/application/" . $theStudentInfo['photo'];
                                    } else {
                                        if ($theStudentInfo['gender'] == 'Male')
                                            $profileimg = base_url() . "common_assets/male_image.jpg";
                                        else
                                            $profileimg = base_url() . "common_assets/female_image.jpg";
                                    }
                                    // print_r($theStudentInfo);
                                    ?>
                                    <div class="card">

                                        <div class="card-body py-3">
                                            <div class="row align-items-center px-3">

                                                <img src="<?= $profileimg; ?>" class="img-thumbnail img-fluid border-primary  rounded-circle applicant-img" style="width: 80px; height: auto !important;">

                                                <div class="px-3">
                                                    <label style="font-size: 18px; font-weight: 600;" class="my-0 h6"> <?= $theStudentInfo['name']  ?></label>
                                                    <h6 style="font-size: 12px">
                                                        <?= $theStudentInfo['studentId']  ?>
                                                    </h6>
                                                    <h6 style="font-size: 14px; font-weight: 600; ">
                                                        <?= $theStudentInfo['classroom_name']  ?>
                                                    </h6>
                                                    <h6 style="font-size: 13px; font-style: italic; font-weight: 500; ">
                                                        <?= $theStudentInfo['b_name']  ?>
                                                    </h6>


                                                </div>
                                                <div style="font-size: 14px; font-weight: 600; " class="col text-right">
                                                    <div>
                                                        <i class="fa fa-phone mx-1" aria-hidden="true" style="-webkit-transform: rotate(90deg); -moz-transform: rotate(90deg); "></i>
                                                        <?= $theStudentInfo['emergency_contact_number']  ?>
                                                    </div>

                                                </div>
                                            </div>
                                        </div>
                                    </div>

                                    <hr>

                                    <form method="post" action="<?= base_url(); ?>admin/student-fees/<?= $url_params ?>">
                                        <input type="hidden" name="student_id" value="<?= $theStudentInfo['student_id']; ?>">
                                        <input type="hidden" name="batch_id" value="<?= $theStudentInfo['batch_id']; ?>">
                                        <input type="hidden" name="course_id" value="<?= $theStudentInfo['course_id']; ?>">
                                        <?php

                                        // dd($theStudentInfo);
                                        $course_fees = $theStudentInfo['course_fees'];

                                        foreach ($course_fees as $cf_key => $course_fee) {

                                            $feeTitle = $course_fee['fee_title'];
                                            $fees = $course_fee['fees'];
                                        ?>

                                            <div class="card mb-3">
                                                <div class="card-body">
                                                    <h5 class="card-title mb-2"><?= $feeTitle ?></h5>


                                                    <p class="card-text">
                                                        <?php
                                                        // echo '<pre>';
                                                        // print_r($fees);
                                                        ?>
                                                    </p>
                                                    <div class="row px-3 align-items-center">
                                                        <?php
                                                        foreach ($fees as $f_key => $f_value) {
                                                            $check_status = ($f_value['fee_assigned_id'] > 0) ? "checked" : "";
                                                            if ($f_value['sop_id'] > 0) {
                                                                $className = "";
                                                                $checkbxinput = "";
                                                                $disable_attr = 'style="background-color: #28a745 !important;" disabled="disabled" data-toggle="tooltip" title="Fees Partialy paid" readonly="readonly"';
                                                                $partial_payment_checkbox = " style='background-color: green !important;'";
                                                            } else {
                                                                $checkbxinput = "stud_check_inputs feestype_childerns_" . $f_value['id'] . " childschkBx" . $theStudentInfo['student_id'];
                                                                $className = "fes_child_checkbox fees_type_" . $f_value['id'] . " student_checkid_" . $theStudentInfo['student_id'];
                                                                $disable_attr = '';
                                                                $partial_payment_checkbox = "";
                                                            }
                                                        ?>
                                                            <div class="col-md-3 py-0 my-auto align-items-center justify-content-center">
                                                                <!-- <div class="row px-3 mb-2 align-items-center">
                                                                <input type="checkbox" id="checkBx_<?= $f_value['id']; ?>_<?= $theStudentInfo['student_id']; ?>" class="checkmark <?= $className; ?>" name="fees_<?= $f_key; ?>_<?= $f_value['id']; ?>[]" onclick="fees_type_check(this,<?= $f_value['id']; ?>,<?php echo $theStudentInfo['student_id']; ?>)" <?= $check_status; ?> value="<?php echo ($f_value['fee_assigned_id'] > 0) ? "on" : "off"; ?>" <?= $disable_attr; ?>>
                                                                <h6 class="px-3"><?= $f_value['fee_values'] ?></h6>
                                                            </div> -->
                                                                <div class="checkbox">
                                                                    <label>
                                                                        <input type="hidden" name="course_fees_id[]" value="<?= $f_value['id']; ?>">
                                                                        <input type="hidden" name="course_fees_assigned_id[<?= $f_value['id']; ?>]" value="<?= $f_value['fee_assigned_id']; ?>">
                                                                        <input type="hidden" name="course_fees_payment_status[<?= $f_value['id']; ?>]" value="<?= $f_value['payment']; ?>">
                                                                        <input type="checkbox" id="checkBx_<?= $f_value['id']; ?>_<?= $theStudentInfo['student_id']; ?>" class="checkmark <?= $className; ?>" name="fees[<?= $f_value['id']; ?>]" onclick="fees_type_check(this,<?= $f_value['id']; ?>,<?php echo $theStudentInfo['student_id']; ?>)" <?= $check_status; ?> <?= $disable_attr; ?>>
                                                                        <h6 class="px-3" style="font-size: 14px;"><?= $f_value['fee_values'] ?> <br> <small>(<?= $school_info['currency_symbol'] . '. ' . $f_value['amount'] ?>)</small></h6>
                                                                    </label>
                                                                </div>
                                                            </div>
                                                        <?php
                                                        }
                                                        ?>
                                                    </div>
                                                </div>
                                            </div>


                                        <?php
                                        }

                                        ?>
                                    <?php } ?>

                                    <input type="submit" class=" w-100 btn btn-sm mb-2" style="background-color:#032da1;color:#fff;" name="assigntostudents" value="Update">
                                    </form>

                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
        <!-- admin template section end -->
    </main>
    <!--End right-top side-->
</div>

<script defer src="<?php echo base_url(); ?>assets_admin/js/bootstrap-select.min.js"></script>

<script>
    jQuery(document).ready(function() {
        jQuery(".custom_tble").clone(true).appendTo('.table_div_cover').addClass('clone');
    });

    function fees_type_check(ele, fee_id, student_id) {
        var act_val = parseInt($('#cb_' + fee_id + '_' + student_id).val());
        var isChecked = $('#' + ele.id).prop("checked");
        //  alert('#'+ele.id);
        // if (isChecked)
        //     $('#chkBx_' + fee_id + '_' + student_id).val("on");
        // else
        //     $('#chkBx_' + fee_id + '_' + student_id).val("off");

        // var read_val = (isChecked === true) ? 1 : 0;
        // var rowcounter = parseInt($('#rowcounter_' + student_id).val());
        // if (parseInt(read_val) != act_val) {
        //     rowcounter = rowcounter + 1;
        // } else {
        //     rowcounter = rowcounter - 1;
        // }
        // if (rowcounter === 0) {
        //     $('#student-checkbox_' + student_id).prop('checked', false);
        // } else {
        //     $('#student-checkbox_' + student_id).prop('checked', true);
        // }
        // $('#rowcounter_' + student_id).val(rowcounter);

        console.log(ele + ' ======> ' + fee_id + ' ====> ' + student_id);

        console.log($(ele).prop('checked'));
        $(ele).attr('checked', true);

    }
</script>

</body>

</html>