<link href="https://cdn.jsdelivr.net/npm/summernote@0.8.18/dist/summernote.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/summernote@0.8.18/dist/summernote.min.js"></script>
<div class="row align-items-center">
    <div class="col-sm-6">
        <div class="page-title-box">
            <!--   <h4 class="font-size-18">Pages</h4> -->

        </div>
    </div>

    <div class="col-sm-6">
        <div class="float-right d-none d-md-block">

            <!-- <a class="btn btn-primary waves-effect waves-light" href="<?php echo base_url(); ?>Pages/get_pages">
                <i class="mdi mdi-plus mr-2"></i> 
            </a> -->
        </div>
    </div>
</div>
<br>
<?php
if (validation_errors()) {
?>
    <div class="alert alert-danger alert-dismissible fade show" role="alert">
        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
            <span aria-hidden="true">×</span>
        </button>
        <?php echo validation_errors(); ?>
    </div>
<?php
}
?>
<?php if ($this->session->flashdata('check_email_alert_danger')) { ?>
    <div class="alert alert-danger alert-dismissible fade show" role="alert">
        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
            <span aria-hidden="true">×</span>
        </button>
        <strong>Success!</strong> <?php echo $this->session->flashdata('check_email_alert_danger'); ?>
    </div>
<?php } ?>
<div class="row">
    <div class="col-lg-12">
        <div class="card">
            <div class="card-body">
                <h4 class="card-title">Add Question</h4><bR>
                <form action="<?php echo base_url(); ?>ApplicationController/questionEdit/<?=$default['id']?>" method="post" enctype="multipart/form-data" id="registration_form">

                    <div class="row">
                        <div class="form-group col-md-4">
                            <label class="tx-medium">Academic Year<span class="text-danger">*</span> </label>

                            <select name="academic" id="academic" class="form-control select2 modal-select">
                                <option value="">--Select--</option>
                                <?php foreach ($academic_year as $row) { ?>
                                    <option <?= $_POST['academic'] ==  $row->id ? 'selected' : ($default['academic'] == $row->id ? 'selected'  :'') ?> value="<?php echo $row->id ?>"> <?php echo $row->year ?></option>

                                <?php } ?>
                            </select>

                        </div>
                        <div class="form-group col-md-4">
                            <label class="tx-medium">Exam Type<span class="text-danger">*</span> </label>

                            <select name="exam_type" id="exam_type" class="form-control select2 modal-select">
                                <option value="">--Select--</option>
                                <?php foreach ($exam_type as $row) { ?>
                                    <option  <?= $_POST['exam_type'] ==  $row->id ? 'selected' : ($default['exam_type'] == $row->id ? 'selected'  :'') ?>  value="<?php echo $row->id ?>"> <?php echo $row->exam_type_name ?></option>

                                <?php } ?>
                            </select>

                        </div>

                        <div class="form-group col-md-4">
                            <label class="tx-medium">Exam Type<span class="text-danger">*</span> </label>

                            <select name="category" id="category" class="form-control select2 modal-select">
                                <option value="">--Select--</option>
                                <?php foreach ($category as $row) { ?>
                                    <option <?= $_POST['category'] ==  $row->id ? 'selected' : ($default['category'] == $row->id ? 'selected'  :'') ?> value="<?php echo $row->id ?>"> <?php echo $row->category ?></option>

                                <?php } ?>
                            </select>

                        </div>


                        <div class="form-group col-md-12">
                            <label class="required">Question</label>
                            <textarea  name="question" id="summernote" autocomplete="off" class="form-control" placeholder="Question"> <?= (isset($_POST['question']))?$_POST['question']:$default['question']; ?></textarea>
                            <?php if (form_error('question')) { ?>
                                <div class="text-danger alert-dismissible fade show mt-1" role="alert">
                                    <?php echo form_error('question'); ?>
                                </div>
                            <?php } ?>



                        </div>

                        <div class="form-group col-md-3">
                            <label class="required">Option A</label>
                            <input name="option_a" id="option_a" type="text" class="form-control" placeholder="Option A" value="<?= (isset($_POST['option_a']))?$_POST['option_a']:$default['option_a']; ?>">

                            <?php if (form_error('option_a')) { ?>
                                <div class="text-danger alert-dismissible fade show mt-1" role="alert">
                                    <?php echo form_error('option_a'); ?>
                                </div>
                            <?php } ?>
                        </div>
                        <div class="form-group col-md-3">
                            <label class="required">Option B</label>
                            <input name="option_b" id="option_b" type="text" class="form-control" placeholder="Option B" value="<?= (isset($_POST['option_b']))?$_POST['option_b']:$default['option_b']; ?>">

                            <?php if (form_error('option_b')) { ?>
                                <div class="text-danger alert-dismissible fade show mt-1" role="alert">
                                    <?php echo form_error('option_b'); ?>
                                </div>
                            <?php } ?>
                        </div>
                        <div class="form-group col-md-3">
                            <label class="required">Option C</label>
                            <input name="option_c" id="option_c" type="text" class="form-control" placeholder="Option C" value="<?= (isset($_POST['option_c']))?$_POST['option_c']:$default['option_c']; ?>">

                            <?php if (form_error('option_c')) { ?>
                                <div class="text-danger alert-dismissible fade show mt-1" role="alert">
                                    <?php echo form_error('option_c'); ?>
                                </div>
                            <?php } ?>
                        </div>
                        <div class="form-group col-md-3">
                            <label class="required">Option D</label>
                            <input name="option_d" id="option_d" type="text" class="form-control" placeholder="Option D" value="<?= (isset($_POST['option_d']))?$_POST['option_d']:$default['option_d']; ?>">
                            <?php if (form_error('option_d')) { ?>
                                <div class="text-danger alert-dismissible fade show mt-1" role="alert">
                                    <?php echo form_error('option_d'); ?>
                                </div>
                            <?php } ?>
                        </div>

                        <div class="form-group col-md-3">
                            <label class="tx-medium">Answer<span class="text-danger">*</span> </label>

                            <select  name="answer" id="answer" class="form-control select2 modal-select">
                                <option value="">--Select Answer--</option>
                                <option <?= $_POST['answer'] ==  'a' ? 'selected' : ($default['answer'] == 'a' ? 'selected'  :'') ?>  value="a">A</option>
                                <option <?= $_POST['answer'] == 'b' ? 'selected' : ($default['answer'] == 'b' ? 'selected'  :'') ?>  value="b">B</option>
                                <option  <?= $_POST['answer'] == 'c' ? 'selected' : ($default['answer'] == 'c' ? 'selected'  :'') ?>  value="c">C</option>
                                <option <?= $_POST['answer'] ==  'd' ? 'selected' : ($default['answer'] == 'd' ? 'selected'  :'') ?>  value="d">D</option>
                               
                            </select>

                        </div>



                    </div>

                    <div class="form-group mt-3 col-md-4">
                        <div class="">
                            <button name="submit" type="submit" class="btn btn-primary waves-effect waves-light mr-1">
                                Submit
                            </button>
                            <a href="<?php echo base_url('ApplicationController/faculty'); ?>" class="btn btn-secondary waves-effect">Cancel </a>
                        </div>
                    </div>
            </div>

            </form>

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

<body>
    <script>
        $(document).ready(function() {
            $('#summernote').summernote();

        });
        $(document).ready(function() {
            $('#registration_form').validate({
                rules: {
                    facultyname: {
                        required: true
                    },
                    mobile: {
                        required: true,
                        number: true
                    },
                    email: {
                        required: true,
                        email: true
                    },
                    Password: {
                        required: true
                    },
                    confirm_password: {
                        required: true,
                        equalTo: "#Password" // Ensure it matches the password field
                    }
                },
                messages: {
                    facultyname: {
                        required: "Please enter your name"
                    },
                    mobile: {
                        required: "Please enter your mobile number",
                        number: "Please enter a valid mobile number"
                    },
                    email: {
                        required: "Please enter your email address",
                        email: "Please enter a valid email address"
                    },
                    Password: {
                        required: "Please enter a password"
                    },
                    confirm_password: {
                        required: "Please confirm your password",
                        equalTo: "Passwords do not match"
                    }
                },
                errorElement: 'span',
                errorPlacement: function(error, element) {
                    error.addClass('invalid-feedback');
                    element.closest('.form-group').append(error);
                },
                highlight: function(element, errorClass, validClass) {
                    $(element).addClass('is-invalid');
                },
                unhighlight: function(element, errorClass, validClass) {
                    $(element).removeClass('is-invalid');
                }
            });
        });


        let pwd1 = document.getElementById('login_pass'),
            eye1 = document.querySelector('.showPwd1');

        eye1.addEventListener('click', function() {
            toggleType1();
        })


        function toggleType1() {

            if (eye1.classList.contains('closed')) {
                pwd1.type = 'password';
            } else {
                pwd1.type = 'text';
            }
            eye1.classList.toggle('closed');
        }
        //end of password toggle


        //start of confirm password toggle
        let pwd2 = document.getElementById('login_pass2');
        eye2 = document.querySelector('.showPwd2');

        eye2.addEventListener('click', function() {
            toggleType2();
        })


        function toggleType2() {

            if (eye2.classList.contains('closed')) {
                pwd2.type = 'password';
            } else {
                pwd2.type = 'text';
            }
            eye2.classList.toggle('closed');
        }
    </script>
</body>
<style type="text/css">
    .required:after {
        content: " *" !important;
        color: red !important;
    }
</style>