<?php 
/**
 * v3.1.0
 * status: completed
 */
class Gov {
    public $post_id                 = null;
    public $quiz                    = [];
    public $category                = '';
    public $_id                     = '';
    public $result_id               = '';
    public $student_id              = null;
    public $sections                = [];
    public $questions               = [];
    public $sectionsViseQuestions   = [];
    public $seconds                 = 60;
    public $default                 = 3600;
    public $resume                  = false;
    public $result                  = false;
    public $solution                = false;
    public $session                 = [];
    public $user_data               = null;
    public $_q                      = [];
    public static $sections_html    = '';
    public static $questions_html   = '';
    public static $current_p_index  = 0;
    public static $current_q_index  = 0;
    public static $p_counter        = 0;
    public static $rq_c             = 0;
    public static $q_counter        = 0;
    public $attempt_url             = '';
    public static $questions_arr    = [];
    public static $sections_arr     = [];
    public static $questions_report = [];
    public static $sections_report  = [];

    public $user_response           = null;
    public $is_resume               = false;
    public $is_result               = false;

    public static $total_correct    = 0;
    public static $total_wrong      = 0;
    public static $total_attempt    = 0;
    public static $total_unattempt  = 0;
    public static $question_types   = [];
    public $page_type               = 'analytics';
    public $default_points_settings = null;


    public function __construct($params = []) {
        if(isset($_GET['type']) && !empty($_GET['type'])){
            if($_GET['type'] == "solution"){
                $this->page_type = "solution";
            }
        }
        $params = (object) $params;
        $this->category     = isset($params->category) ? (string) $params->category : '';
        $this->_id          = isset($params->_id) ? (string) $params->_id : '';
        $this->sections     = isset($params->sections) ? (array) $params->sections : [];
        $this->questions    = isset($params->questions) ? (array) $params->questions : [];
        $this->quiz         = isset($params->quiz) ? (object) $params->quiz : (object) [];
        $time               = isset($this->quiz->time)? (object) $this->quiz->time : null;
        $quiz_settings              = isset($this->quiz->settings)? (object) $this->quiz->settings : null;
        $this->default_points_settings  = isset($quiz_settings->points)? (object) $quiz_settings->points : [
            "correct"       => 1,
            "negative"      => 0,
            "negativeType"  => "value"
        ];

        


        $this->resume       = isset($params->resume) ? (bool) $params->resume : false;
        $this->result       = isset($params->result) ? (bool) $params->result : false;
        $this->solution     = isset($params->solution) ? (bool) $params->solution : false;
        $this->session      = isset($params->session)? (object) $params->session : [];
        $this->user_data    = isset($params->user_data)? (object) $params->user_data : null;
        $this->result_id    = isset($params->result_id)? (int) $params->result_id : null;  
        $this->_q           = isset($params->_q)? (object) $params->_q : (object) [];
        $this->attempt_url  = isset($params->attempt_url)? (string) $params->attempt_url : '';
        $this->student_id   = isset($params->student_id)? (int) $params->student_id : null;

        if( count($this->sections) > 0 ) {
            foreach( $this->sections as $skey => $section ) {
                $section = (object) $section;
                $section_id = $section->_id;
                
                $filteredQuestions = (array) array_filter($this->questions, function ($obj) use ($section_id) {
                    $question = (object) $obj;
                    return ($question->_postId == $section_id);
                });

                $this->sectionsViseQuestions[$section_id] = $filteredQuestions;
            }
        }
        
        
        if($time !== null){
            $minuts = isset($time->mm)? (int) $time->mm : 60;
            $this->default = $minuts * 60;
        }

        if( $this->resume ) {
            $this->seconds      = isset($params->seconds)? (int) $params->seconds : $this->default;
            $this->set_user_data($this->user_data, $this->resume);
        } else if( $this->result ) {
            $this->seconds      = isset($params->seconds)? (int) $params->seconds : $this->default;
            $this->set_user_data($this->user_data, false, $this->result);
        } else {
            $this->seconds      = $this->default;
        }

        
    }  

    public function get_sections_html() {
        if (count($this->sections) > 0) {
            foreach ($this->sections as $skey => $section) {
                # main section object
                $section = (object) $section;
                $title   = (string) $section->title;
                $content = (string) $section->content;

                # section html buffer module
                ob_start(); ?>
                <section 
                    id="part-<?php echo $skey+1; ?>" 
                    class='<?php echo $skey === 0 ? "test-contents ckeditor-wrapper -show" : "test-contents ckeditor-wrapper"; ?>' 
                    style="overflow-y:scroll;outline:none;display:none"
                >
                    <div class="test-contents__paragragh">
                        <?php echo $content; ?>
                    </div>
                </section>
                <?php 
                self::$sections_html .= ob_get_clean();
                # clean and store the buffer and increment it
            }

            return self::$sections_html;
        }
    }

    public function get_gov_styles(){
        ob_start(); ?>
        <?php if( $this->result ){ ?>
        <style>
            .actual-exam-ui .marks-action {
                padding: 8px 16px 0px !important;
            }
            .actual-exam-ui .questions-number-holder {
                top: 175px !important;
            }

            .qns-view-box.correct-box {
                padding: 10px;
                border: 1px dashed #27ae60;
                margin-top: 50px;
            }

            .qns-view-box.correct-box input[type="text"] {
                color: #27ae60;
            }

            .qns-view-box.correct-box {
                display: none;
            }

            .reattempt-mode .qns-view-box.correct-box {
                display: block !important;
            }

            .actual-exam-ui .correct-option, .actual-exam-ui .reattempt-correct-option,
            .actual-exam-ui .incorrect-option, .actual-exam-ui .reattempt-incorrect-option{
                background: inherit  !important;
                color: inherit !important;
            }


            .actual-exam-ui .incorrect-icon::before, .actual-exam-ui .correct-icon::before,
            .actual-exam-ui .incorrect-icon::after, .actual-exam-ui .correct-icon:after{
                display:none !important;
            }

            .reattempt-mode.actual-exam-ui input[type="radio"],.reattempt-mode.actual-exam-ui input[type="checkbox"]{
                display:none;
            }

            .reattempt-mode.actual-exam-ui label{
                pointer-events: none;
            }

            .reattempt-mode.actual-exam-ui .incorrect-icon::before, .reattempt-mode.actual-exam-ui .correct-icon::before,
            .reattempt-mode.actual-exam-ui .incorrect-icon::after, .actual-exam-ui.correct-icon:after{
                display:block !important;
            }


            .reattempt-mode.actual-exam-ui .correct-option, .reattempt-mode.actual-exam-ui .reattempt-correct-option{
                background: #27ae60 !important;
                color: white !important;
            }

            .reattempt-mode.actual-exam-ui .incorrect-option, .reattempt-mode.actual-exam-ui .reattempt-incorrect-option{
                background: #c0392b !important;
                color: white !important;
            }


            .reattempt-mode label:hover {
                background:inherit !important;
            }

            .solution-container {
                display: none;
            }

            .reattempt-mode .solution-container {
                display: block !important;
            }
        </style>    
        <?php } ?>

        <style>
            
            .-hold .test-page-timer {
                display: none;
            }

            .-hold .calc-pause {
                display: none;
            }
            .tb-main-header {
                position: fixed;
                top: 0;
                left: 0;
                right: 0;
                width: 100%;
                height: 52px;
                padding: 0 16px;
                background: #fff;
                z-index: 41;
                opacity: 1;
                -webkit-transition: all .3s cubic-bezier(.165,.84,.44,1);
                -o-transition: all .3s cubic-bezier(.165, .84, .44, 1);
                transition: all .3s cubic-bezier(.165,.84,.44,1);
                -webkit-box-shadow: 0 2px 4px rgba(0, 0, 0, .1);
                box-shadow: 0 2px 4px rgba(0, 0, 0, .1);
            }

            .tb-main-header {
                display: flex;
                flex-direction: row;
                justify-content: space-between;
                align-items: center;
            }

            .tb-main-header .header__container{
                display: flex;
                flex-direction: row;
                align-items: center;
                justify-content: flex-start;
            }

            .tb-main-header .tb-logo>img {
                height: 30px;
                margin: 3px 0;
            }

            .hover-accept-tooltip[disabled]:hover ~ #accept-tooltip{
                display:block !important;
            }

            [data-gov-section-switch="false"] {
                cursor: no-drop !important;
                opacity: 0.6;
            }

            .active [data-gov-section-switch="false"] {
                cursor: no-drop !important;
                opacity: 1;
            }

            input.gov-fillup_input {
                border: 0;
                border-bottom: 1px dashed #9b9a9a;
                padding: 0 15px;
                margin: 0 5px;
                font-style: italic;
            }

            input.gov-fillup_input:focus {
                outline: none;
            }

            .gov-show-block{ display: block !important; }
            .gov-hide{ display: none !important; }
        </style>
        <?php echo ob_get_clean();
    }

    public function header(){
        if( $this->result ) {
            ob_start(); ?>
            <head>
                <meta charset="<?php bloginfo('charset'); ?>" />    
                <meta name="viewport" content="width=device-width, initial-scale=1.0" />
                <link rel="stylesheet" href="<?php echo site_url() . '/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/css/polyfixes.css'; ?>" />
                <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.1/css/all.min.css" integrity="sha512-SUwyLkI1Wgm4aEZkDkwwigXaOI2HFLy1/YW73asun4sfvlkB9Ecl99+PHfCnfWD0FJjIuFTvWMM7BZPXCckpAA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
                <?php if($this->page_type == "analytics"){ ?>
                <link rel="stylesheet" href="<?php echo site_url() . '/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/css/gov/gov-test-analysis.css'; ?>" />
                <link rel="stylesheet" href="<?php echo site_url() . '/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/css/gov/gov-style.css'; ?>" />
                <?php } ?>
                <?php if($this->page_type == "solution"){ ?>
                <link rel="stylesheet" href="<?php echo site_url() . '/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/css/gov/test-style.css'; ?>" />
                <?php } ?>
                <script defer type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
                <script type="text/x-mathjax-config">
                    
                    MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]} });

                </script>
                <?php echo $this->get_gov_styles(); ?>
            </head>
            <?php return ob_get_clean();
        } else {
            ob_start(); ?>
            <head>
                <meta charset="<?php bloginfo('charset'); ?>" />    
                <meta name="viewport" content="width=device-width, initial-scale=1.0" />
                <link rel="stylesheet" href="<?php echo site_url() . '/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/css/polyfixes.css'; ?>" />
                <link rel="stylesheet" href="<?php echo site_url() . '/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/css/gov/gov-exam-ui.css'; ?>" />
                <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css" />
                <script defer type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
                <script type="text/x-mathjax-config">
                    
                    MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]} });

                </script>
                <?php echo $this->get_gov_styles(); ?>

            </head>
            <?php return ob_get_clean();
        }

    }

    public function footer(){
        ob_start(); ?>
        <script id="session-details" type="application/json">
            <?php 
                echo json_encode( (object) [
                    "_id"           => $this->_id,
                    "category"      => $this->category,
                    "time"          => $this->default,
                    "session"       => $this->session
                ]); 
            ?>
        </script>
        <script id="quiz-json" type="application/json">
            <?php echo json_encode( (object) $this->_q); ?>
        </script>
        <script id="quiz-global-json" type="application/json">
            <?php echo json_encode((array) self::$questions_arr); ?>
        </script>
        <script id="quiz-global-sections-json" type="application/json">
            <?php echo json_encode((array) self::$sections_arr); ?>
        </script>
        <?php if( $this->resume && $this->user_data !== null ) { 
            $answers = isset($this->user_data->answers)? (object) $this->user_data->answers : [];
            ?>
            <script id="user-responses" type="application/json">
                <?php 
                    echo json_encode( (object) [
                        "answers"   => $answers
                    ]); 
                ?>
            </script>
        <?php } ?>
        <script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
        <script src="//code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
        <script>
            jQuery(document).ready(function($){
                var questions, sections, cq, sq, cix, six;
                var question_timeInterval;
                var section_timeInterval;
                var main_timeInterval;
                var finishAjax = null;
                var pause = false;

                const formatTime = (seconds) => {
                    var hours = Math.floor(seconds / 3600);
                    var minutes = Math.floor((seconds % 3600) / 60);
                    var remainingSeconds = seconds % 60;
                    
                    var formattedTime = '';
                    
                    if (hours > 0) {
                        formattedTime += hours.toString().padStart(2, '0') + ':';
                    }
                    
                    if (hours > 0 || minutes > 0) {
                        formattedTime += minutes.toString().padStart(2, '0') + ':';
                    } else {
                        formattedTime += '00:';
                    }
                    
                    formattedTime += remainingSeconds.toString().padStart(2, '0');
                    
                    return formattedTime;
                };

                const formatTimeV = (seconds) => {
                    var hours = Math.floor(seconds / 3600);
                    var minutes = Math.floor((seconds % 3600) / 60);
                    var remainingSeconds = seconds % 60;
                    
                    var timeObject = {};
                    
                    timeObject.hh = hours.toString().padStart(2, '0');
                    timeObject.mm = minutes.toString().padStart(2, '0');
                    timeObject.ss = remainingSeconds.toString().padStart(2, '0');
                    
                    return timeObject;
                };
            
                const findIndexByQid = (qid) => {
                    return questions.findIndex(function(obj) {
                        return obj.qid === qid;
                    });
                };

                function filterObjectsByKeyValue(array, key, value) {
                    return array.filter(function(object) {
                        return object[key] === value;
                    });
                }

                // question timer
                const initQuestionTimer = () => {

                    question_timeInterval = setInterval(() => {
                        if(questions.length > 0){
                            if(questions[cix]){
                                if(!pause){
                                    questions[cix].visit++;
                                    $('#q-time').html(formatTime(questions[cix].visit));
                                }
                            }
                        }
                    }, 1000);
                };

                // section timer
                const initSectionTimer = () => {
                    if(sections.length > 0){
                        let sw = $(`[data-gov-section]`).data('gov-section-switch');
                        section_timeInterval = setInterval(() => {
                            if(sections[six]){
                                let sid = sections[six];
                                let stime = $(`[data-gov-section-indicator='${sid}'] #section-time-value`).val();
                                $(`[data-gov-section-indicator='${sid}'] #section-time-counter`).html(formatTime(+stime));

                                if(sw){} else {
                                    const { hh, mm , ss } = formatTimeV(+stime);
                                    $(`.test-page-timer .timer-hh`).text(hh);
                                    $(`.test-page-timer .timer-mm`).text(mm);
                                    $(`.test-page-timer .timer-ss`).text(ss);

                                    $(`.sectional-summary-modal .timer-hh`).text(hh);
                                    $(`.sectional-summary-modal .timer-mm`).text(mm);
                                    $(`.sectional-summary-modal .timer-ss`).text(ss);
                                    
                                }

                                if(sw){
                                    if(!pause){
                                        $('.x-close-btn').css('display','initial');
                                        $('.x-timesup').addClass('gov-hide');
                                        +stime++;
                                        $(`[data-gov-section-indicator='${sid}'] #section-time-value`).val(stime);
                                    }
                                } else {
                                    
                                    if(+stime <= 0){
                                        pause = true;
                                        console.log('timesup section');
                                        $('.x-close-btn').css('display','none');
                                        $('.x-timesup').removeClass('gov-hide');
                                        $(`[data-gov-section-summary-modal="${sid}"]`).modal('show');
                                    }else {
                                        if(!pause){
                                            $('.x-close-btn').css('display','initial');
                                            $('.x-timesup').addClass('gov-hide');
                                            +stime--;
                                            $(`[data-gov-section-indicator='${sid}'] #section-time-value`).val(stime);
                                        }
                                    }
                                }
                                
                            }
                            
                        }, 1000);
                    }
                };

                // const initTimer
                const initTimer = () => {
                    if(sections.length > 0){
                        let sw = $(`[data-gov-section]`).data('gov-section-switch');
                        if(sw){
                            main_timeInterval = setInterval(() => {
                            
                                let time = $(`[data-gov-main-timer="true"]`).val();
                                const { hh, mm , ss } = formatTimeV(+time);
                                $(`.test-page-timer .timer-hh`).text(hh);
                                $(`.test-page-timer .timer-mm`).text(mm);
                                $(`.test-page-timer .timer-ss`).text(ss);

                                if(+time <= 0){
                                    pause = true;
                                    console.log('timesup overall');
                                    if(sections.length > 0 ){
                                        sections.forEach(section => {
                                            govAnalyizeReport(section);
                                        });
                                    }
                                    $('.x-close-btn').css('display','none');
                                    $('.x-timesup').removeClass('gov-hide');
                                    $('#submit-test-modal').modal('show');
                                    
                                }else {
                                    +time--;
                                    $(`[data-gov-main-timer="true"]`).val(time);
                                }
                            },1000);
                        }
                    }
                };

                const initClassCollector = () => {
                    if(sections.length > 0){
                        if(sections[six]){
                            //let attempted = $(`[data-gov-section-question='${sections[six]}'] `);
                            // attempted
                            //$(`.u-legend-indicator.attempted `).text();
                            //$(`.u-legend-indicator.bookmarked `).text();
                            //$(`.u-legend-indicator.bookmarked.attempted`).text();
                            //$(`.u-legend-indicator.skipped`).text();
                        }
                    }
                };

                // init
                const initGov = () => {
                    let questions_txt       = $('#quiz-global-json').text();
                    let sections_txt        = $('#quiz-global-sections-json').text();
                        questions           = JSON.parse(questions_txt);
                        sections            = JSON.parse(sections_txt);

                        window.questions    = questions;
                        window.sections     = sections;
                        cix = 0;
                        sq = 0;

                        $('body').addClass('-start').removeClass('-hold');
                        showQuestion(0);
                        initQuestionTimer();
                        initSectionTimer();
                        initTimer();
                        initClassCollector();

                };

            

                const showQuestion = (qinx) => {
                    if(questions && questions.length > 0){
                        let qix = +qinx;
                        if(questions[qix]){
                            let cq = questions[qix];
                            // hide all sections with id
                            questions[qix].visited = true;
                            // 1.) hide indicators
                            $(`[data-gov-section-indicator]`).addClass('gov-hide');
                            // 2.) deactivate sections tabs
                            $(`[data-gov-section]`).parent().removeClass('active');
                            // 3.) hide questions
                            $(`[data-gov-question-section]`).addClass('gov-hide');
                            // 4.) section questions palletes
                            $(`[data-gov-section-question]`).addClass('gov-hide');
                            // 5.) deactivate question for make current-question
                            $(`[data-gov-question-pallete]`).removeClass('current-question');
                            // 6.) hide all footer buttons
                            $(`[data-gov-question-control]`).addClass('gov-hide');
                            // 7.) hide all sections submit buttons
                            $(`[data-gov-section-submit]`).addClass('gov-hide');

                            // active classes
                            $(`[data-gov-section-indicator='${cq.pid}']`).removeClass('gov-hide');   // sections indicators
                            $(`[data-gov-section='${cq.pid}']`).parent().addClass('active');        // sections tabs
                            $(`[data-gov-question-section='${cq.pid}'][data-gov-question='${cq.qid}']`).removeClass('gov-hide');  // questions 
                            $(`[data-gov-section-question='${cq.pid}']`).removeClass('gov-hide'); // palletes
                            $(`[data-gov-question-control='${cq.qid}']`).removeClass('gov-hide');
                            $(`[data-gov-section-submit='${cq.pid}']`).removeClass('gov-hide');
                            let QUS = $(`[data-gov-question-section='${cq.pid}'][data-gov-question='${cq.qid}']`);
                            $(`#qxs-no`).text(`Question: ${+cq.pqi}.`);
                            $(`#qlg-no`).text(`${+cq.pqi}.`);
                            $(`.marks-correct`).text(`+${QUS.data('gov-question-correct-points')}`);
                            $(`.marks-negative`).text(`-${QUS.data('gov-question-negative-points')}`);
                            $(`[data-gov-section-indicator='${cq.pid}'] #section-current-question`).val(qix);
                            $(`[data-gov-question-pallete='${cq.qid}']`).addClass('current-question skipped');
                            $('#q-time').html(formatTime(cq.visit));
                            cix = qix;
                            six = sections.indexOf(cq.pid);
                            
                            // init question time


                        }
                    }
                };

                // finish quiz only alert
                const govAlertFinishQuiz = () => {
                    console.log('finish quiz alert modal');
                };

                // last question alert
                const govLastQuestion = () => {
                    $('#last-question-modal').modal('show');
                };

                // finish current section and save
                const govShowAlertFinishSection = (sid) => {
                    govAnalyizeReport(sid);
                    $('#last-section-question-modal').modal('show');
                    //$(`[data-gov-section-modal="${sid}"]`).modal('show');
                };

                // analyize report data
                const govAnalyizeReport = (sid) => {
                    const quss = filterObjectsByKeyValue(questions,'pid',sid);
                    if(quss.length > 0 ){
                        $(`[data-gov-section-table='${sid}'] .label-total`).text(quss.length);
                        $(`[data-gov-section-summary-modal="${sid}"] .label-total`).text(quss.length);

                        let totalAttempted = quss.filter(function(object) {
                            return object['classes'].includes('attempted');
                        });
                        let totalBookmarked = quss.filter(function(object) {
                            return object['classes'].includes('bookmarked');
                        });
                        let totalUnattempted = quss.filter(function(object) {
                            return object['classes'].includes('skipped');
                        });
                        let totalUnvisited = quss.filter(function(object) {
                            return !object['visited'];
                        });

                        $(`[data-gov-section-table='${sid}'] .label-attempted`).text(totalAttempted.length);
                        $(`[data-gov-section-table='${sid}'] .label-unattempted`).text(totalUnattempted.length);
                        $(`[data-gov-section-table='${sid}'] .label-bookmarked`).text(totalBookmarked.length);
                        $(`[data-gov-section-table='${sid}'] .label-skipped`).text(totalUnvisited.length);

                        $(`[data-gov-section-summary-modal="${sid}"] .label-attempted`).text(totalAttempted.length);
                        $(`[data-gov-section-summary-modal="${sid}"] .label-unattempted`).text(totalUnattempted.length);
                        $(`[data-gov-section-summary-modal="${sid}"] .label-bookmarked`).text(totalBookmarked.length);
                        $(`[data-gov-section-summary-modal="${sid}"] .label-skipped`).text(totalUnvisited.length);
                    }
                };

                // show submit test modal
                const showSubmitTestModal = () => {
                    if(sections.length > 0 ){
                        sections.forEach(section => {
                            govAnalyizeReport(section);
                        });
                    }
                    $('#submit-test-modal').modal('show');
                }

                $('.test-instructions').on('click','.i-agree-checkbox', function(){
                    if($(this).is(":checked")){
                        $('.test-instructions #i-agree-btn').attr('disabled',false);
                    } else {
                        $('.test-instructions #i-agree-btn').attr('disabled',true);
                    }
                    
                });

                $('.test-instructions').on('click','#i-agree-btn', function(){
                    if($('.test-instructions .i-agree-checkbox').is(":checked")){
                        let tmpHtml = $('#i-agree-btn').html();
                        $.ajax({
                            type: "POST",
                            url: '/wp-admin/admin-ajax.php',
                            data: {
                                "action": "proqyz_basic-check-auth",
                            },
                            beforeSend: function () {
                                $('.test-instructions #i-agree-btn').attr('disabled',true);
                                $('#i-agree-btn').html('processing...');

                            },
                            success: function (response) {
                                if(response.success){
                                    $('.test-instructions-assets').addClass('gov-hide');
                                    $('#page').removeClass('gov-hide');
                                    // make question
                                    initGov();
                                }

                                if(response.error){
                                    // alert("user is not logged in");
                                    $('#login-modal').modal('show');
                                    $('#i-agree-btn').html('Login');

                                }
                            },
                            error: function (err) {
                                $('#i-agree-btn').html(tmpHtml);
                                if (err.status == 404) {
                                    console.warn("404 Auth location !");
                                } else if (err.status == 0) {
                                    alert("Network Error");
                                } else {
                                    
                                }
                            }
                        });

                    
                    } else {
                        
                    }
                    
                });

               

                // instructions pagination controller
                $('.test-instructions').on('click','.instructions__btn-previous', function(){
                    // hide all btns
                    $('.test-instructions .instructions__btn').addClass('gov-hide');
                    // hide all contents
                    $('.test-instructions .dynamic-instructions').addClass('gov-hide');
                    $('.test-instructions .di-content').addClass('gov-hide');
                    // enable next btn
                    $('.test-instructions .instructions__btn-next').removeClass('gov-hide');
                    // show first page content
                    $('.test-instructions .basic-instructions').removeClass('gov-hide');
                });

                $('.test-instructions').on('click','.instructions__btn-next', function(){
                    // hide all btns
                    $('.test-instructions .instructions__btn').addClass('gov-hide');
                
                    // hide first page content
                    $('.test-instructions .basic-instructions').addClass('gov-hide');

                    // show all contents
                    $('.test-instructions .dynamic-instructions').removeClass('gov-hide');
                    $('.test-instructions .di-content').removeClass('gov-hide');
                    $('.test-instructions .instructions__btn-previous').removeClass('gov-hide');
                    $('.test-instructions .instructions__btn-i-agree').removeClass('gov-hide');
                });

                // quiz main
                $('#page').on('click','.js-trigger-toggle-sidebar', function(){
                    $('#page .tp-left-box').toggleClass('active');
                    $('#page .js-trigger-toggle-sidebar').toggleClass('active');
                    $('#page .tp-right-box').toggleClass('active');
                });

                $('#page').on('click','.js-toggle-sidebar-btn', function(){
                    $('#page .tp-left-box').toggleClass('expanded');
                    $('#page .tp-right-box').toggleClass('closed');
                    $('#page .js-toggle-sidebar-btn').toggleClass('closed');
                });

                // mark for review & next
                $('#page').on('click', '[data-gov-control]', function(){
                    if(questions && questions.length > 0){
                        let controlType = $(this).data('gov-control-type');
                        let questionId  = $(this).data('gov-question-control');
                        let sectionId   = $(this).data('gov-section-question-control');
                        let currentQuestionId = questionId;
                        let currentSectionId  = sectionId;

                        let cindex      = findIndexByQid(currentQuestionId);
                        if( cindex != -1 ){
                            let question    = questions[cindex];
                            let qus         = $(`[data-gov-question='${currentQuestionId}']`);
                            if(question){
                                let classes = [];
                                if(qus.data('gov-question-input-type') == "radio" || qus.data('gov-question-input-type') == "checkbox" || qus.data('gov-question-input-type') == "fillup"){
                                    if($(`[data-gov-question='${currentQuestionId}'] [type='radio']`).length > 0 || $(`[data-gov-question='${currentQuestionId}'] [type='checkbox']`).length > 0 || $(`[data-gov-question='${currentQuestionId}'] [type='text']`).length > 0){

                                        if(controlType == "save-and-next-question"){ // done
                                            let ans = [];

                                            if(qus.data('gov-question-input-type') == "radio" || qus.data('gov-question-input-type') == "checkbox"){
                                                console.log(qus.data('gov-question-input-type'));
                                                if(qus.data('gov-question-input-type') == "radio"){
                                                    ans = $(`[data-gov-question='${currentQuestionId}'] [type='radio']`).map(function() {
                                                        return $(this).is(':checked');
                                                    }).get();
                                                } else if(qus.data('gov-question-input-type') == "checkbox"){
                                                    ans = $(`[data-gov-question='${currentQuestionId}'] [type='checkbox']`).map(function() {
                                                        return $(this).is(':checked');
                                                    }).get();

                                                    console.log(ans);
                                                } 

                                                if(ans.includes(true)){
                                                    classes.push('attempted');
                                                    $(`[data-gov-question-pallete='${currentQuestionId}']`).addClass('attempted').removeClass('skipped bookmarked');
                                                } else {
                                                    classes.push('skipped');
                                                    $(`[data-gov-question-pallete='${currentQuestionId}']`).removeClass('attempted bookmarked').addClass('skipped');
                                                }
                                            } else if(qus.data('gov-question-input-type') == "fillup"){
                                                ans = $(`[data-gov-question='${currentQuestionId}'] [type='text']`).map(function() {
                                                    return $(this).val();
                                                }).get();

                                                if (ans.some(value => value.length > 0)) {
                                                    classes.push('attempted');
                                                    $(`[data-gov-question-pallete='${currentQuestionId}']`).addClass('attempted').removeClass('skipped bookmarked');
                                                } else {
                                                    classes.push('skipped');
                                                    $(`[data-gov-question-pallete='${currentQuestionId}']`).removeClass('attempted bookmarked').addClass('skipped');
                                                }
                                            }

                                            // save for response and next question same section
                                            // 1.) check user answere or not
                                            
                                            questions[cindex].classes = classes;
                                            questions[cindex].answers = ans;
                                            showQuestion(cindex+1);

                                        } else if(controlType == "clear"){ // done
                                            let ans = [];
                                            if(qus.data('gov-question-input-type') == "radio" || qus.data('gov-question-input-type') == "checkbox"){
                                                
                                                if(qus.data('gov-question-input-type') == "radio"){
                                                    $(`[data-gov-question='${currentQuestionId}'] [type='radio']`).prop('checked',false);
                                                    ans = $(`[data-gov-question='${currentQuestionId}'] [type='radio']`).map(function() {
                                                        return $(this).is(':checked');
                                                    }).get();
                                                } else if(qus.data('gov-question-input-type') == "checkbox"){
                                                    $(`[data-gov-question='${currentQuestionId}'] [type='checkbox']`).prop('checked',false);
                                                    ans = $(`[data-gov-question='${currentQuestionId}'] [type='checkbox']`).map(function() {
                                                        return $(this).is(':checked');
                                                    }).get();
                                                } 


                                                
                                            } else if(qus.data('gov-question-input-type') == "fillup"){
                                                $(`[data-gov-question='${currentQuestionId}'] [type='text']`).val("");
                                                ans = $(`[data-gov-question='${currentQuestionId}'] [type='text']`).map(function() {
                                                    return $(this).val();
                                                }).get();
                                            }


                                            classes.push('skipped');
                                            if(question.classes.length > 0 && question.classes.includes('bookmarked')){
                                                $(`[data-gov-question-pallete='${currentQuestionId}']`).removeClass('attempted').addClass('skipped bookmarked');
                                                classes.push('bookmarked');
                                            } else {
                                                $(`[data-gov-question-pallete='${currentQuestionId}']`).removeClass('attempted bookmarked').addClass('skipped');
                                            }

                                            questions[cindex].classes = classes;
                                            questions[cindex].answers = ans;
                                            
                                            
                                        } else if(controlType == "mark-for-review-and-next-question"){ // done
                                            let ans = [];
                                            classes.push('bookmarked');
                                            // next question same section
                                            // 1.) check user answere or not - if answer given then bookmarked it with attempted status
                                            if(qus.data('gov-question-input-type') == "radio" || qus.data('gov-question-input-type') == "checkbox"){

                                                if(qus.data('gov-question-input-type') == "radio"){
                                                    
                                                    ans = $(`[data-gov-question='${currentQuestionId}'] [type='radio']`).map(function() {
                                                        return $(this).is(':checked');
                                                    }).get();
                                                } else if(qus.data('gov-question-input-type') == "checkbox"){
                                                    
                                                    ans = $(`[data-gov-question='${currentQuestionId}'] [type='checkbox']`).map(function() {
                                                        return $(this).is(':checked');
                                                    }).get();
                                                } 

                                                if(ans.includes(true)){
                                                    classes.push('attempted');
                                                    $(`[data-gov-question-pallete='${currentQuestionId}']`).addClass('attempted bookmarked').removeClass('skipped');
                                                } else {

                                                    classes.push('skipped');
                                                    $(`[data-gov-question-pallete='${currentQuestionId}']`).addClass('skipped bookmarked').removeClass('attempted');
                                                }
                                            } else if(qus.data('gov-question-input-type') == "fillup"){
                                                ans = $(`[data-gov-question='${currentQuestionId}'] [type='text']`).map(function() {
                                                    return $(this).val();
                                                }).get();

                                                if (ans.some(value => value.length > 0)) {
                                                    classes.push('attempted');
                                                    $(`[data-gov-question-pallete='${currentQuestionId}']`).addClass('attempted bookmarked').removeClass('skipped');
                                                } else {

                                                    classes.push('skipped');
                                                    $(`[data-gov-question-pallete='${currentQuestionId}']`).addClass('skipped bookmarked').removeClass('attempted');
                                                }
                                            }
                                            // save for response and next question same section
                                            // 1.) check user answere or not
                                            questions[cindex].classes = classes;
                                            questions[cindex].answers = ans;
                                            showQuestion(cindex+1);
                                        } else if(controlType == "save-and-next-section"){ // done
                                            let ans = [];
                                            // next question next section
                                            // 1.) check user answere or not - if answer given then attempted status
                                            if(qus.data('gov-question-input-type') == "radio" || qus.data('gov-question-input-type') == "checkbox"){
                                            
                                                if(qus.data('gov-question-input-type') == "radio"){
                                                    
                                                    ans = $(`[data-gov-question='${currentQuestionId}'] [type='radio']`).map(function() {
                                                        return $(this).is(':checked');
                                                    }).get();
                                                } else if(qus.data('gov-question-input-type') == "checkbox"){
                                                    
                                                    ans = $(`[data-gov-question='${currentQuestionId}'] [type='checkbox']`).map(function() {
                                                        return $(this).is(':checked');
                                                    }).get();
                                                } 

                                                if(ans.includes(true)){
                                                    classes.push('attempted');
                                                    $(`[data-gov-question-pallete='${currentQuestionId}']`).addClass('attempted').removeClass('skipped bookmarked');
                                                } else {
                                                    classes.push('skipped');
                                                    $(`[data-gov-question-pallete='${currentQuestionId}']`).removeClass('attempted bookmarked').addClass('skipped');
                                                }
                                            } else if(qus.data('gov-question-input-type') == "fillup"){

                                                ans = $(`[data-gov-question='${currentQuestionId}'] [type='text']`).map(function() {
                                                    return $(this).val();
                                                }).get();

                                                if (ans.some(value => value.length > 0)) {
                                                    classes.push('attempted');
                                                    $(`[data-gov-question-pallete='${currentQuestionId}']`).addClass('attempted').removeClass('skipped bookmarked');
                                                } else {
                                                    classes.push('skipped');
                                                    $(`[data-gov-question-pallete='${currentQuestionId}']`).removeClass('attempted bookmarked').addClass('skipped');
                                                }

                                            }
                                            // save for response and next question same section
                                            // 1.) check user answere or not
                                            
                                            questions[cindex].classes = classes;
                                            questions[cindex].answers = ans;

                                            if(questions[cindex + 1]){
                                                let nextSectionId = questions[cindex + 1].pid;
                                                let sw = $(`[data-gov-section="${nextSectionId}"]`).data('gov-section-switch');
                                                if(sw){
                                                    showQuestion(cindex+1);
                                                } else {
                                                    //window.nextSectionId = nextSectionId;
                                                    govShowAlertFinishSection(currentSectionId); 
                                                }
                                            } else {
                                                console.log('question next not found');
                                                if(sections.length > 0 ){
                                                    sections.forEach(sid => {
                                                        const quss = filterObjectsByKeyValue(questions,'pid',sid);
                                                        $(`[data-gov-section-table='${sid}'] .label-total`).text(quss.length);
                                                    });
                                                    $('#modal-error').modal('show');
                                                    $('#modal-error .modal-body .bootbox-body').html('<b>Looks like there is quiz valiation error, it seems like, there is no questions in next section</b><br />');
                                                } else {
                                                    $('#modal-error').modal('show');
                                                    $('#modal-error .modal-body .bootbox-body').html('Looks like there is quiz valiation error, 0 Sections found');
                                                }

                                            }

                                            
                                        } else if(controlType == "mark-for-review-and-next-section"){ // done
                                            let ans = [];
                                            classes.push('bookmarked');
                                            // next question next section
                                            // 1.) check user answere or not - if answer given then bookmarked with attempted status
                                            if(qus.data('gov-question-input-type') == "radio" || qus.data('gov-question-input-type') == "checkbox"){

                                                if(qus.data('gov-question-input-type') == "radio"){
                                                    
                                                    ans = $(`[data-gov-question='${currentQuestionId}'] [type='radio']`).map(function() {
                                                        return $(this).is(':checked');
                                                    }).get();
                                                } else if(qus.data('gov-question-input-type') == "checkbox"){
                                                    
                                                    ans = $(`[data-gov-question='${currentQuestionId}'] [type='checkbox']`).map(function() {
                                                        return $(this).is(':checked');
                                                    }).get();
                                                } 

                                                if(ans.includes(true)){
                                                    classes.push('attempted');
                                                    $(`[data-gov-question-pallete='${currentQuestionId}']`).addClass('attempted bookmarked').removeClass('skipped');
                                                } else {
                                                    classes.push('skipped');
                                                    $(`[data-gov-question-pallete='${currentQuestionId}']`).addClass('skipped bookmarked').removeClass('attempted');
                                                }
                                            } else if(qus.data('gov-question-input-type') == "fillup"){

                                                ans = $(`[data-gov-question='${currentQuestionId}'] [type='text']`).map(function() {
                                                    return $(this).val();
                                                }).get();

                                                if (ans.some(value => value.length > 0)) {
                                                    classes.push('attempted');
                                                    $(`[data-gov-question-pallete='${currentQuestionId}']`).addClass('attempted bookmarked').removeClass('skipped');
                                                } else {
                                                    classes.push('skipped');
                                                    $(`[data-gov-question-pallete='${currentQuestionId}']`).addClass('skipped bookmarked').removeClass('attempted');
                                                }

                                            }
                                            // save for response and next question same section
                                            // 1.) check user answere or not
    
                                            questions[cindex].classes = classes;
                                            questions[cindex].answers = ans;

                                            let nextSectionId = questions[cindex + 1].pid;
                                            let sw = $(`[data-gov-section="${nextSectionId}"]`).data('gov-section-switch');
                                            if(sw){
                                                showQuestion(cindex+1);
                                            } else {
                                                window.nextSectionId = nextSectionId;
                                                govShowAlertFinishSection(currentSectionId); 
                                            }

                                        } else if(controlType == "mark-for-review-only"){ // done
                                            let ans = [];
                                            // next question next section
                                            // 1.) check user answere or not - if answer given then bookmarked with attempted status
                                            classes.push('bookmarked');
                                            // next question next section
                                            // 1.) check user answere or not - if answer given then bookmarked with attempted status
                                            if(qus.data('gov-question-input-type') == "radio" || qus.data('gov-question-input-type') == "checkbox"){

                                                if(qus.data('gov-question-input-type') == "radio"){
                                                    
                                                    ans = $(`[data-gov-question='${currentQuestionId}'] [type='radio']`).map(function() {
                                                        return $(this).is(':checked');
                                                    }).get();
                                                } else if(qus.data('gov-question-input-type') == "checkbox"){
                                                    
                                                    ans = $(`[data-gov-question='${currentQuestionId}'] [type='checkbox']`).map(function() {
                                                        return $(this).is(':checked');
                                                    }).get();
                                                } 

                                                if(ans.includes(true)){
                                                    classes.push('attempted');
                                                    $(`[data-gov-question-pallete='${currentQuestionId}']`).addClass('attempted bookmarked').removeClass('skipped');
                                                } else {
                                                    classes.push('skipped');
                                                    $(`[data-gov-question-pallete='${currentQuestionId}']`).addClass('skipped bookmarked').removeClass('attempted');
                                                }
                                            } else if(qus.data('gov-question-input-type') == "fillup"){

                                                ans = $(`[data-gov-question='${currentQuestionId}'] [type='text']`).map(function() {
                                                    return $(this).val();
                                                }).get();

                                                if (ans.some(value => value.length > 0)) {
                                                    classes.push('attempted');
                                                    $(`[data-gov-question-pallete='${currentQuestionId}']`).addClass('attempted bookmarked').removeClass('skipped');
                                                } else {
                                                    classes.push('skipped');
                                                    $(`[data-gov-question-pallete='${currentQuestionId}']`).addClass('skipped bookmarked').removeClass('attempted');
                                                }

                                            }
                                            // save for response and next question same section
                                            // 1.) check user answere or not
    
                                            questions[cindex].classes = classes;
                                            questions[cindex].answers = ans;

                                        } else if(controlType == "save-and-finish-quiz"){ // done
                                            let ans = [];

                                            if(qus.data('gov-question-input-type') == "radio" || qus.data('gov-question-input-type') == "checkbox"){
                                                if(qus.data('gov-question-input-type') == "radio"){
                                                    
                                                    ans = $(`[data-gov-question='${currentQuestionId}'] [type='radio']`).map(function() {
                                                        return $(this).is(':checked');
                                                    }).get();
                                                } else if(qus.data('gov-question-input-type') == "checkbox"){
                                                    
                                                    ans = $(`[data-gov-question='${currentQuestionId}'] [type='checkbox']`).map(function() {
                                                        return $(this).is(':checked');
                                                    }).get();
                                                } 

                                                if(ans.includes(true)){
                                                    classes.push('attempted');
                                                    $(`[data-gov-question-pallete='${currentQuestionId}']`).addClass('attempted').removeClass('skipped bookmarked');
                                                } else {
                                                    classes.push('skipped');
                                                    $(`[data-gov-question-pallete='${currentQuestionId}']`).removeClass('attempted bookmarked').addClass('skipped');
                                                }
                                            } else if(qus.data('gov-question-input-type') == "fillup"){

                                                ans = $(`[data-gov-question='${currentQuestionId}'] [type='text']`).map(function() {
                                                    return $(this).val();
                                                }).get();

                                                if (ans.some(value => value.length > 0)) {
                                                    classes.push('attempted');
                                                    $(`[data-gov-question-pallete='${currentQuestionId}']`).addClass('attempted').removeClass('skipped bookmarked');
                                                } else {
                                                    classes.push('skipped');
                                                    $(`[data-gov-question-pallete='${currentQuestionId}']`).removeClass('attempted bookmarked').addClass('skipped');
                                                }

                                            }
                                    
                                            // save for response and next question same section
                                            // 1.) check user answere or not
                                            questions[cindex].classes = classes;
                                            questions[cindex].answers = ans;

                                            let nextSectionId = questions[0].pid;
                                            let sw = $(`[data-gov-section="${nextSectionId}"]`).data('gov-section-switch');
                                            if(sw){
                                                govLastQuestion();
                                            } else {
                                                //govShowAlertFinishSection(currentSectionId); 
                                                //showSubmitTestModal();
                                                govShowAlertFinishSection(currentSectionId);
                                            } 
                                        }
                                    }
                                }
                            } else {
                                console.log(currentQuestionId);
                            }
                        }
                    }
                });


                // section switch
                $('#page').on('click', '[data-gov-section-switch="true"]', function(){
                    let sid = $(this).data(`gov-section`);
                    let qix = $(`[data-gov-section-indicator='${sid}'] #section-current-question`).val();
                    // check for current question activity
                    let qus = questions[cix];
                    
                    if(qus){

                        let currentQuestionId   = qus.qid;
                        let controlType         = $(`[data-gov-question='${currentQuestionId}']`).data('gov-question-input-type');

                        if(qus.classes.includes('attempted')){

                        } else {
                            let ans = [];
                            let classes = [];

                            if(controlType == "radio" || controlType == "checkbox"){

                                
                                // 1.) check user answere or not - if answer given then bookmarked with attempted status
                                if(controlType == "radio"){
                                    $(`[data-gov-question='${currentQuestionId}'] [type='radio']`).prop('checked',false);
                                    ans = $(`[data-gov-question='${currentQuestionId}'] [type='radio']`).map(function() {
                                        return $(this).is(':checked');
                                    }).get();
                                } else if(controlType == "checkbox"){
                                    $(`[data-gov-question='${currentQuestionId}'] [type='checkbox']`).prop('checked',false);
                                    ans = $(`[data-gov-question='${currentQuestionId}'] [type='checkbox']`).map(function() {
                                        return $(this).is(':checked');
                                    }).get();
                                } 
                            
                                if(ans.includes(true)){ } else {
                                    if(qus.classes.includes('bookmarked')){
                                        classes.push('skipped');
                                        classes.push('bookmarked');
                                        $(`[data-gov-question-pallete='${currentQuestionId}']`).addClass('skipped bookmarked').removeClass('attempted');
                                    } else {
                                        classes.push('skipped');
                                        $(`[data-gov-question-pallete='${currentQuestionId}']`).addClass('skipped').removeClass('attempted bookmarked');
                                    }
                                    
                                }

                            } else if(controlType == "fillup"){
                                $(`[data-gov-question='${currentQuestionId}'] [type='text']`).val("");
                                ans = $(`[data-gov-question='${currentQuestionId}'] [type='text']`).map(function() {
                                    return $(this).val();
                                }).get();

                                if (ans.some(value => value.length > 0)) { } else {
                                    if(qus.classes.includes('bookmarked')){
                                        classes.push('skipped');
                                        classes.push('bookmarked');
                                        $(`[data-gov-question-pallete='${currentQuestionId}']`).addClass('skipped bookmarked').removeClass('attempted');
                                    } else {
                                        classes.push('skipped');
                                        $(`[data-gov-question-pallete='${currentQuestionId}']`).addClass('skipped').removeClass('attempted bookmarked');
                                    }
                                }
                            }

                            questions[cix].classes = classes;
                            questions[cix].answers = ans;
                                            
                        }

                        

                    }
                    showQuestion(+qix);
                });

                // question pallete switch
                $('#page').on('click', '[data-gov-question-pallete]', function(){
                    let qid = $(this).data('gov-question-pallete');
                    //showQuestion()
                    let qix = findIndexByQid(qid);
                    
                    if( questions[qix] && qix != -1 ){
                        // check and make status
                        let qus                 = questions[cix];
                        if(qus){
                            let currentQuestionId   = qus.qid;
                            let controlType         = $(`[data-gov-question='${currentQuestionId}']`).data('gov-question-input-type');
                            console.log(controlType);
                            if(qus.classes.includes('attempted')){ } else {
                                let ans = [];
                                let classes = [];

                                if(controlType == "radio" || controlType == "checkbox"){

                                
                                    // 1.) check user answere or not - if answer given then bookmarked with attempted status
                                    if(controlType == "radio"){
                                        $(`[data-gov-question='${currentQuestionId}'] [type='radio']`).prop('checked',false);
                                        ans = $(`[data-gov-question='${currentQuestionId}'] [type='radio']`).map(function() {
                                            return $(this).is(':checked');
                                        }).get();
                                    } else if(controlType == "checkbox"){
                                        $(`[data-gov-question='${currentQuestionId}'] [type='checkbox']`).prop('checked',false);
                                        ans = $(`[data-gov-question='${currentQuestionId}'] [type='checkbox']`).map(function() {
                                            return $(this).is(':checked');
                                        }).get();
                                    } 

                                    if(ans.includes(true)){ } else {
                                        if(qus.classes.includes('bookmarked')){
                                            classes.push('skipped');
                                            classes.push('bookmarked');
                                            $(`[data-gov-question-pallete='${currentQuestionId}']`).addClass('skipped bookmarked').removeClass('attempted');
                                        } else {
                                            classes.push('skipped');
                                            $(`[data-gov-question-pallete='${currentQuestionId}']`).addClass('skipped').removeClass('attempted bookmarked');
                                        }
                                        
                                    }

                                } else if(controlType == "fillup"){
                                    $(`[data-gov-question='${currentQuestionId}'] [type='text']`).val("");
                                    ans = $(`[data-gov-question='${currentQuestionId}'] [type='text']`).map(function() {
                                        return $(this).val();
                                    }).get();

                                    if (ans.some(value => value.length > 0)) { } else {
                                        if(qus.classes.includes('bookmarked')){
                                            classes.push('skipped');
                                            classes.push('bookmarked');
                                            $(`[data-gov-question-pallete='${currentQuestionId}']`).addClass('skipped bookmarked').removeClass('attempted');
                                        } else {
                                            classes.push('skipped');
                                            $(`[data-gov-question-pallete='${currentQuestionId}']`).addClass('skipped').removeClass('attempted bookmarked');
                                        }
                                        
                                    }
                                }

                                questions[cix].classes = classes;
                                questions[cix].answers = ans;
                                                
                            }
                        }


                        showQuestion(qix);
                    }
                });



                // modals
                $(document).on('click', '#last-question-modal [data-gov-modal-control="confirm"]', function(){
                    $('#last-question-modal').modal('hide');
                    showQuestion(0);
                });

                $(document).on('click', '[data-gov-modal-control="submit-and-next-section"]', function(){
                    let nextSectionId = $(this).data('gov-next-section');
                    let qix = $(`[data-gov-section-indicator='${nextSectionId}'] #section-current-question`).val();
                    $(`[data-gov-section-modal]`).modal('hide');
                    $(`[data-gov-section-summary-modal]`).modal('hide');
                    pause = false;
                    showQuestion(+qix);
                });

                $(document).on('click', '[data-gov-modal-control="finish-quiz"]', function(){
                    let json    = JSON.parse(jQuery('#session-details[type="application/json"]').text());
                    let quiz    = JSON.parse(jQuery('#quiz-json[type="application/json"]').text());

                    let ss = [];
                    if(sections && sections.length > 0){
                        sections.forEach((section, index ) => {
                            let sTime = $(`[data-gov-section-indicator='${section}'] #section-time-value`);
                            ss.push({
                                _id: section,
                                index: index,
                                time: +sTime.data('gov-section-default-time'),
                                visit: +sTime.val() 
                            });
                        });
                    }

                    $(`[data-gov-main-timer="true"]`).val();
                    
                    let btn = $(this);
                    let tmpHtml = btn.html();
                    let allBtns = $(`#submit-test-modal button`);

                    let data = {
                        time: $(`[data-gov-main-timer="true"]`).data('gov-main-timer-value'),
                        diff: $(`[data-gov-main-timer="true"]`).val(),
                        json: json,
                        quiz: JSON.stringify(quiz),
                        answers: JSON.stringify({
                            quiz:{
                                time: $(`[data-gov-main-timer="true"]`).data('gov-main-timer-value'),
                                diff: $(`[data-gov-main-timer="true"]`).val()
                            },
                            sections: ss,
                            questions: questions
                        }),
                        finish: 1
                    };
                    btn.html(`<i class="fa fa-spin fa-spinner"></i> Processing`);
                    allBtns.attr('disabled', true);
                    // on quiz submit
                    finishAjax = $.ajax({
                        type: "POST",
                        url: '/wp-admin/admin-ajax.php',
                        data: {
                            "action": "proqyz-save-quiz-progress",
                            "data": data
                        },
                        beforeSend: function () {
                            if (finishAjax != null) {
                                finishAjax.abort();
                            }
                            console.log('[RES]: Saving...');
                        },
                        success: function (response) {
                            if (response.success) {
                                if (response.redirect) {
                                    window.location.href = response.url;
                                }
                            }
                        },
                        error: function (err) {
                            if (err.status == 404) {
                                console.warn("404 Auth location !");
                            } else if (err.status == 0) {
                                alert("Network Error");
                            } else {
                                console.warn(err.message);
                            }
                            btn.html(tmpHtml);
                            allBtns.attr('disabled', false);
                        }
                    });
                });

                $(document).on('click','[data-gov-action="submit-test"]', function(){
                    let sw = $(`[data-gov-section]`).data('gov-section-switch');
                    if(sw){
                        showSubmitTestModal();
                    } else {
                        
                        if(sections[six]){
                            govAnalyizeReport(sections[six]);
                            $(`[data-gov-section-summary-modal="${sections[six]}"]`).modal('show');
                        }
                        
                    }
                    
                });

                $(document).on('click','[data-gov-action="login"]', function(){
                    $(`#modal-auth`).modal('show');
                });

                $(document).on('click', '[data-gov-section-submit-modal-btn]', function(){
                    let sid = $(this).data('gov-section-submit-modal-btn');
                    govAnalyizeReport(sid);
                    $(`[data-gov-section-summary-modal="${sid}"]`).modal('show');
                });



                window.initGov = initGov;


                // result
                const showQuestionResult = (qinx) => {
                    if(questions && questions.length > 0){
                        let qix = +qinx;
                        if(questions[qix]){
                            let cq = questions[qix];
                            // hide all sections with id
                            questions[qix].visited = true;
                            // 1.) hide indicators - section time           - checked
                            $(`[data-gov-result-section-indicator]`).addClass('gov-hide');
                            // 2.) deactivate sections tabs                 - checked
                            $(`[data-gov-result-section]`).parent().removeClass('active');

                            // 3.) hide questions - main                    - checked
                            $(`[data-gov-result-question]`).addClass('gov-hide');
                            // 4.) section questions palletes               - checked
                            $(`[data-gov-result-section-question]`).addClass('gov-hide');

                            // 5.) deactivate question for make current-question - optional - checked
                            $(`[data-gov-result-question-pallete]`).removeClass('current-question');

                            // 6.) hide all footer buttons                  - checked
                            $(`[data-gov-result-question-control]`).addClass('gov-hide');
                            // 7.) hide section states
                            $(`[data-gov-result-section-states]`).addClass('gov-hide');
                            // 8.) hide all questions headers
                            $(`[data-gov-result-question-header]`).addClass('gov-hide');

                            // 7.) hide all sections submit buttons
                            //$(`[data-gov-result-section-submit]`).addClass('gov-hide');

                            // active classes
                            $(`[data-gov-result-section-indicator='${cq.pid}']`).removeClass('gov-hide');   // sections indicators  - checked
                            $(`[data-gov-result-section='${cq.pid}']`).parent().addClass('active');        // sections tabs         - checked
                            $(`[data-gov-result-question-section='${cq.pid}'][data-gov-result-question='${cq.qid}']`).removeClass('gov-hide');  // questions - checked
                            $(`[data-gov-result-section-question='${cq.pid}']`).removeClass('gov-hide'); // palletes - checked
                            // section states show
                            $(`[data-gov-result-section-states='${cq.pid}']`).removeClass('gov-hide');

                            $(`[data-gov-result-question-control='${cq.qid}']`).removeClass('gov-hide'); 
                            //$(`[data-gov-result-section-submit='${cq.pid}']`).removeClass('gov-hide');
                            $(`[data-gov-result-question-header='${cq.qid}']`).removeClass('gov-hide');

                            $(`[data-gov-result-question-pallete='${cq.qid}']`).addClass('current-question');
                            
                            cix = qix;
                            six = sections.indexOf(cq.pid);
                            
                            // init question time


                        }
                    }
                };

                const initGovResult = () => {
                    let questions_txt       = $('#quiz-global-json').text();
                    let sections_txt        = $('#quiz-global-sections-json').text();
                        questions           = JSON.parse(questions_txt);
                        sections            = JSON.parse(sections_txt);

                        window.questions    = questions;
                        window.sections     = sections;
                        cix = 0;
                        sq = 0;
                        showQuestionResult(0);
                };


                $('#page-solution').on('click', '[data-gov-result-section-switch="true"]', function(){
                    let sid = $(this).data(`gov-result-section`);
                    let qix = $(`[data-gov-result-section-indicator='${sid}'] #section-current-question`).val();
                    // check for current question activity
                    let qus = questions[cix];
                    showQuestionResult(+qix);
                });

                // question pallete switch
                $('#page-solution').on('click', '[data-gov-result-question-pallete]', function(){
                    let qid = $(this).data('gov-result-question-pallete');
                    //showQuestion()
                    let qix = findIndexByQid(qid);
                    if( questions[qix] && qix != -1 ){
                        showQuestionResult(qix);
                    }
                });

                // footer controls
                $('#page-solution').on('click', '[data-gov-result-control]', function(){
                    if(questions && questions.length > 0){
                        let controlType = $(this).data('gov-result-control-type');
                        let questionId  = $(this).data('gov-result-question-control');
                        let sectionId   = $(this).data('gov-result-section-question-control');
                        let currentQuestionId = questionId;
                        let currentSectionId  = sectionId;

                        let cindex      = findIndexByQid(currentQuestionId);
                        if( cindex != -1 ){
                            if(controlType == "next-question" || controlType == "next-section"){
                                showQuestionResult(cindex+1);
                            } else if(controlType == "previous-question"){
                                showQuestionResult(cindex-1);
                            } else if(controlType == "go-to-first-question"){
                                $('#result-last-question-modal').modal('show');
                            }
                        }
                    }
                });

                // modals
                $(document).on('click', '#result-last-question-modal [data-gov-modal-control="confirm"]', function(){
                    $('#result-last-question-modal').modal('hide');
                    showQuestionResult(0);
                });

                $(document).on('click', '[data-gov-result-modal="modal"]', function(){
                    let targetId = $(this).data('gov-result-modal-target');
                    $(targetId).modal('show');
                });

                // expalantion revise mode
                $(document).on('click', '[data-gov-result-toggle-solution="true"]', function(){
                    $("body").toggleClass("reattempt-mode");
                });

                $('#page-solution').on('click','.js-trigger-toggle-sidebar', function(){
                    $('#page-solution .tp-left-box').toggleClass('active');
                    $('#page-solution .js-trigger-toggle-sidebar').toggleClass('active');
                    $('#page-solution .tp-right-box').toggleClass('active');
                });

                $('#page-solution').on('click','.js-toggle-sidebar-btn', function(){
                    $('#page-solution .tp-left-box').toggleClass('expanded');
                    $('#page-solution .tp-right-box').toggleClass('closed');
                    $('#page-solution .js-toggle-sidebar-btn').toggleClass('closed');
                });


                
                <?php if($this->result && $this->page_type == "solution"){  ?>
                    initGovResult();
                <?php } ?>

            });
        </script>
        <script id="js-drag-calculator">
            jQuery(document).ready(function($){
                $(`[data-gov-calculator="true"]`).on('click', function(){
                    $(`#drag-calculator`).css('top','54px').css('left','1px');
                    $(`#drag-calculator`).toggleClass('gov-hide');
                });

                $(`#drag-calculator [data-gov-calculator-btn="close"]`).on('click', function(){
                    $(`#drag-calculator`).toggleClass('gov-hide');
                    $(`#drag-calculator`).css('top','54px').css('left','1px');
                });

                $("#drag-calculator").draggable({});
            });
        </script>
        <?php return ob_get_clean();
    }

    public function get_layout(){
        $class_body = '';
        if(is_user_logged_in()){
            $class_body = '-hold';
            $class_body .= ' user-logged-in ';
        } else {
            $class_body .= ' anonymous-user';
        }

        # make section boxes for each
        $section_tabs               = "";
        $section_time_indicators    = "";
        $questions_pallete_holder   = "";
        $questions_boxes            = "";
        $questions_footer           = "";
        $dynamic_modals             = '';
        $section_submit_controls    = "";

        if( count($this->sections) > 0 ){
            foreach( $this->sections as $skey => $section ) {
                $section = (object) $section;
                $section_id         = $section->_id;
                $section_type       = $section->_postType;
                $section_title      = $section->title;
                $section_time_main  = isset($section->time)? (object) $section->time : null;
                $section_time       = isset($section_time_main->sectionTime)? (object) $section_time_main->sectionTime : null;
                $section_timer      = isset($section_time->timer)? (bool) $section_time->timer : false;
                $section_time_hh    = isset($section_time->hh)? (int) $section_time->hh : 0;
                $section_time_mm    = isset($section_time->mm)? (int) $section_time->mm : 0;
                $section_time_ss    = isset($section_time->ss)? (int) $section_time->ss : 0;
                $section_time_value = 0;

                # add sections to an array
                self::$sections_arr[$skey] = $section_id;

                $filteredQuestions = (array) array_filter($this->questions, function ($obj) use ($section_id) {
                    $question = (object) $obj;
                    return ($question->_postId == $section_id);
                });

                $questions_palltetes = "";
                
                self::$current_q_index = 0;
                $before_q_counter = self::$q_counter;
                $qindex = 0;
                if( count($filteredQuestions) > 0 ) {
                    foreach( $filteredQuestions as $qkey => $question ) {
                        $question = (object) $question;
                        self::$current_q_index++;

                        # question palletes
                        ob_start(); ?>
                        <li 
                            data-gov-question-pallete="<?php echo $question->_id; ?>"
                            data-gov-section-question-pallete="<?php echo $question->_postId; ?>"
                            class="label <?php echo self::$q_counter == 0? 'current-question' : ''; ?>" 
                            ng-class="{'bookmarked','attempted','skipped','current-question'}"
                        >
                            <?php echo self::$current_q_index; ?>
                        </li>
                        <?php $questions_palltetes .= ob_get_clean();

                        # question content boxes
                        $questions_boxes .= $this->get_question_html($question);

                        # questions footer
                        ob_start(); ?>
                        <div 
                            class="footer-inner hide-on-railway gov-hide" 
                            data-gov-question-control="<?php echo $question->_id; ?>"
                            data-gov-section-question-control="<?php echo $question->_postId; ?>"
                        >
                            
                            

                            <button 
                                data-gov-control="cr" 
                                data-gov-control-type="clear" 
                                data-gov-question-control="<?php echo $question->_id; ?>"
                                data-gov-section-question-control="<?php echo $question->_postId; ?>"
                                type="button" 
                                class="btn btn-info-test mar-t0"
                            >
                                Clear <span class="temp-text">Response</span>
                            </button>

                            <?php if($skey + 1 == count($this->sections)){ ?>  
                                <!--no more sections - no next-->
                                <?php if($qindex + 1 == count($filteredQuestions)){ ?>
                                    <!--last question - finish quiz-->
                                    <button 
                                        data-gov-control="sn" 
                                        data-gov-control-type="save-and-finish-quiz"
                                        data-gov-question-control="<?php echo $question->_id; ?>"
                                        data-gov-section-question-control="<?php echo $question->_postId; ?>" 
                                        type="button" 
                                        class="btn btn-theme pull-right mar-t0"
                                    >
                                        Save <span>&amp; Finish</span>
                                        <span class="icon">→</span>
                                    </button>
                                    <button 
                                        data-gov-control="mrn" 
                                        type="button" 
                                        data-gov-control-type="mark-for-review-only" 
                                        data-gov-question-control="<?php echo $question->_id; ?>"
                                        data-gov-section-question-control="<?php echo $question->_postId; ?>"
                                        class="btn btn-info-test mar-t0"
                                    >
                                        Mark for Review
                                        <span class="icon"></span>
                                    </button>
                                <?php } ?>
                                <?php if($qindex + 1 < count($filteredQuestions)){ ?>
                                    <!--next question - finish quiz-->
                                    <button 
                                        data-gov-control="sn" 
                                        data-gov-control-type="save-and-next-question" 
                                        data-gov-question-control="<?php echo $question->_id; ?>"
                                        data-gov-section-question-control="<?php echo $question->_postId; ?>"
                                        type="button" 
                                        class="btn btn-theme pull-right mar-t0 "
                                    >
                                        Save <span>&amp; Next</span>
                                        <span class="icon">→</span>
                                    </button>
                                    <button 
                                        data-gov-control="mrn" 
                                        type="button" 
                                        data-gov-control-type="mark-for-review-and-next-question"
                                        data-gov-question-control="<?php echo $question->_id; ?>"
                                        data-gov-section-question-control="<?php echo $question->_postId; ?>" 
                                        class="btn btn-info-test mar-t0"
                                    >
                                        Mark for Review <span>&amp; Next</span>
                                        <span class="icon"></span>
                                    </button>
                                <?php } ?>
                                

                            <?php } ?>

                            <?php if($skey + 1 < count($this->sections)){ ?>  
                                <!--next sections-->
                                <?php if($qindex + 1 == count($filteredQuestions)){ ?>
                                    <!--last question - next-section-->
                                    <button 
                                        data-gov-control="sn" 
                                        data-gov-control-type="save-and-next-section"
                                        data-gov-question-control="<?php echo $question->_id; ?>"
                                        data-gov-section-question-control="<?php echo $question->_postId; ?>" 
                                        type="button" 
                                        class="btn btn-theme pull-right mar-t0 "
                                    >
                                        Save <span>&amp; Next</span>
                                        <span class="icon">→</span>
                                    </button>
                                    <button 
                                        data-gov-control="mrn" 
                                        type="button" 
                                        data-gov-control-type="mark-for-review-and-next-section"
                                        data-gov-question-control="<?php echo $question->_id; ?>"
                                        data-gov-section-question-control="<?php echo $question->_postId; ?>" 
                                        class="btn btn-info-test mar-t0"
                                    >
                                        Mark for Review <span>&amp; Next</span>
                                        <span class="icon"></span>
                                    </button>

                                <?php } ?>
                                <?php if($qindex + 1 < count($filteredQuestions)){ ?>
                                    <!--next question - same-section-->
                                    <button 
                                        data-gov-control="sn" 
                                        data-gov-control-type="save-and-next-question"
                                        data-gov-question-control="<?php echo $question->_id; ?>"
                                        data-gov-section-question-control="<?php echo $question->_postId; ?>" 
                                        type="button" 
                                        class="btn btn-theme pull-right mar-t0 "
                                    >
                                        Save <span>&amp; Next</span>
                                        <span class="icon">→</span>
                                    </button>
                                    <button 
                                        data-gov-control="mrn" 
                                        type="button" 
                                        data-gov-control-type="mark-for-review-and-next-question"
                                        data-gov-question-control="<?php echo $question->_id; ?>"
                                        data-gov-section-question-control="<?php echo $question->_postId; ?>" 
                                        class="btn btn-info-test mar-t0"
                                    >
                                        Mark for Review <span>&amp; Next</span>
                                        <span class="icon"></span>
                                    </button>
                                <?php } ?>


                            <?php } ?>

                            

                        </div>
                        <?php $questions_footer .= ob_get_clean();
                        $qindex++;
                        self::$q_counter++;
                        

                    }
                }


                if($section_timer && $section_type == "sectional-timing-section"){
                    $section_time_value = ($section_time_hh*3600) + ($section_time_mm*60) + ($section_time_ss);
                    ob_start(); ?>
                    <div data-gov-section-modal="<?php echo $section_id; ?>" class="modal in" id="submit-section-<?php echo $section_id; ?>" tabindex="-1" role="dialog" aria-labelledby="summaryLabel" aria-hidden="true" data-backdrop="static" style="display: none;">
                        <div class="modal-dialog modal-lg">
                            <div class="modal-content">
                                <div class="modal-body">
                                    <h4 class="text-center ng-hide">
                                        <small>Submit Section</small>
                                    </h4>
                                    <div class="table-responsive">
                                        <table class="table table-bordered">
                                            <thead>
                                                <tr>
                                                    <th translate="" class="ng-scope">Section</th>
                                                    <th translate="" class="ng-scope">No. of questions</th>
                                                    <th translate="" class="ng-scope">Answered</th>
                                                    <th translate="" class="ng-scope">Not Answered</th>
                                                    <th translate="" class="ng-scope">Marked for Review</th>
                                                    <th translate="" class="ng-scope">Not Visited</th>
                                                    <!-- ngIf: hasSkipOptionSupport -->
                                                </tr>
                                            </thead>
                                            <tbody>

                                                <?php if($skey + 1 < count($this->sections)){ ?>
                                                    <tr class="ng-scope" data-gov-section-table="<?php echo $section_id; ?>">
                                                        <td data-prompt="Section" class="ng-binding"><?php echo $section_title; ?></td>
                                                        <td data-prompt="No. of questions" class="ng-binding label-total">0</td>
                                                        <td data-prompt="Answered" class="ng-binding label-attempted">0</td>
                                                        <td data-prompt="Not Answered" class="ng-binding label-unattempted">0</td>
                                                        <td data-prompt="Marked for Review" class="ng-binding label-bookmarked">0</td>
                                                        <td data-prompt="Not Visited" class="ng-binding label-skipped">0</td>
                                                        
                                                    </tr>
                                                <?php } ?>

                                                <?php if($skey + 1 == count($this->sections)){ ?>
                                                    <?php foreach( $this->sections as $sskey => $ssection ) { 
                                                        $ssection = (object) $ssection;
                                                        ?>
                                                        <tr class="ng-scope" data-gov-section-table="<?php echo $ssection->_id; ?>">
                                                            <td data-prompt="Section" class="ng-binding"><?php echo $ssection->title; ?></td>
                                                            <td data-prompt="No. of questions" class="ng-binding label-total">0</td>
                                                            <td data-prompt="Answered" class="ng-binding label-attempted">0</td>
                                                            <td data-prompt="Not Answered" class="ng-binding label-unattempted">0</td>
                                                            <td data-prompt="Marked for Review" class="ng-binding label-bookmarked">0</td>
                                                            <td data-prompt="Not Visited" class="ng-binding label-skipped">0</td>
                                                        </tr>
                                                    <?php } ?>
                                                <?php } ?>
                                        

                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-theme mar-t0 ng-hide" data-dismiss="modal">Close</button>
                                    <?php if($skey + 1 < count($this->sections)){ 
                                        $next_section = isset($this->sections[$skey+1])? (object) $this->sections[$skey+1] : null;
                                        
                                        ?>
                                        <!--submit and next section-->
                                        <button data-gov-modal-control="submit-and-next-section" data-gov-next-section="<?php echo ($next_section !== null)? $next_section->_id : ''; ?>" type="button" class="btn btn-primary outline-none">
                                            Submit & Next Section
                                        </button>
                                    <?php } ?>
                                    <?php if($skey + 1 == count($this->sections)){ ?>
                                        <!--submit and next section-->
                                        <button data-gov-modal-control="finish-quiz" type="button" class="btn btn-primary outline-none">
                                            Submit Test
                                        </button>
                                    <?php } ?>

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

                    <div data-gov-section-summary-modal="<?php echo $section_id; ?>" class="modal sectional-summary-modal" tabindex="-1" role="dialog" aria-labelledby="summaryLabel" aria-hidden="true" data-backdrop="static" style="display: none;">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header x-timesup gov-hide">
                                    <div class="alert alert-warning d-flex align-items-center" role="alert">
                                        <i class="tb-icon tb-sad font-size-medium text-warning mar-b4"></i> &nbsp;
                                        <div>
                                            <?php if(count($this->sections) == $skey+1){ ?>   
                                                Timesup, Please submit test for Review
                                            <?php } else { ?>
                                                Timesup, Please submit section to visit next section
                                            <?php } ?>
                                        </div>
                                    </div>
                                </div>
                                <div class="modal-body">
                                    <h4 class="text-center ng-binding">Summary of <?php echo $section_title; ?></h4>
                                    <div class="table-responsive">
                                        <table class="table mar-b0 mar-t24">
                                            <tbody>
                                                <tr>
                                                    <td data-prompt="Sectional Time Left" text-align="left" class="summary-header">
                                                        <svg width="15" height="15" viewBox="0 0 18 18">
                                                            <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
                                                                <g id="web---submit-test" transform="translate(-571 -341)" fill="#89959B">
                                                                    <g id="access-alarms" transform="translate(571 341)">
                                                                    <path d="M18 3.475L13.86 0l-1.17 1.337 4.14 3.475L18 3.475zM5.31 1.425L4.14.09 0 3.475l1.17 1.337 4.14-3.386zm4.14 4.1H8.1v5.346l4.23 2.584.72-1.069-3.6-2.138V5.525zM9 1.96C4.5 1.96.9 5.525.9 9.98.9 14.436 4.5 18 9 18s8.1-3.564 8.1-8.02c0-4.455-3.6-8.02-8.1-8.02zm0 14.258c-3.51 0-6.3-2.763-6.3-6.238 0-3.475 2.79-6.237 6.3-6.237s6.3 2.762 6.3 6.237-2.79 6.238-6.3 6.238z" id="Shape"></path>
                                                                    </g>
                                                                </g>
                                                            </g>
                                                        </svg>
                                                        <span>Sectional Time Left:</span>
                                                    </td>
                                                    <td data-prompt="Timer" class="summary-text">
                                                        <!-- ngIf: !test.sectionTimeSharedFlag -->
                                                        <livetest-timer 
                                                            ng-if="!test.sectionTimeSharedFlag" 
                                                            test-duration="1219" 
                                                            is-test-submitted="false" 
                                                            is-timer-paused="false" 
                                                            active-section-index="1" 
                                                            skip-duration="0" hide-zero="n" 
                                                            class="ng-scope ng-isolate-scope"
                                                        >
                                                            <span class="timer">
                                                                <span class="label label-default ng-binding timer-hh">00</span> : 
                                                                <span class="label label-default ng-binding timer-mm">00</span> : 
                                                                <span class="label label-default ng-binding timer-ss">00</span>
                                                            </span>
                                                        </livetest-timer>
                                                        <!-- end ngIf: !test.sectionTimeSharedFlag -->
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td data-prompt="Attempted" class="summary-header">
                                                    <svg width="15" height="15" viewBox="0 0 18 18">
                                                        <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
                                                            <g id="web---submit-test" transform="translate(-571 -399)" fill="#89959B">
                                                                <g id="check-circle-outline" transform="translate(571 399)">
                                                                <path d="M5.31 7.29L4.05 8.55 8.1 12.6l9-9-1.26-1.26-7.74 7.74-2.79-2.79zM9 16.2c-3.96 0-7.2-3.24-7.2-7.2S5.04 1.8 9 1.8c.72 0 1.35.09 1.98.27L12.42.63C11.34.27 10.17 0 9 0 4.05 0 0 4.05 0 9s4.05 9 9 9 9-4.05 9-9h-1.8c0 3.96-3.24 7.2-7.2 7.2z" id="Shape"></path>
                                                                </g>
                                                            </g>
                                                        </g>
                                                    </svg>
                                                    Attempted
                                                    </td>
                                                    <td data-prompt="Attempted Count" class="summary-text"><span class="summary-text ng-binding label-attempted">0</span></td>
                                                </tr>
                                                <tr>
                                                    <td data-prompt="Unattempted" class="summary-header">
                                                    <svg width="15" height="15" viewBox="0 0 18 18">
                                                        <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
                                                            <g id="web---submit-test" transform="translate(-571 -458)" fill="#89959B">
                                                                <g id="unknown-4" transform="translate(571 458)">
                                                                <path d="M9 0C4.05 0 0 4.05 0 9s4.05 9 9 9 9-4.05 9-9-4.05-9-9-9zm0 16.2c-3.96 0-7.2-3.24-7.2-7.2S5.04 1.8 9 1.8s7.2 3.24 7.2 7.2-3.24 7.2-7.2 7.2zM5.4 9.9h7.2V8.1H5.4v1.8z" id="Shape"></path>
                                                                </g>
                                                            </g>
                                                        </g>
                                                    </svg>
                                                    Unattempted
                                                    </td>
                                                    <td data-prompt="Unattempted Count" class="summary-text ng-binding label-unattempted">25</td>
                                                </tr>
                                                <tr>
                                                    <td data-prompt="Marked for Review" class="summary-header">
                                                    <svg width="15" height="15" viewBox="0 0 14 18">
                                                        <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
                                                            <g id="web---submit-test" transform="translate(-573 -517)" fill="#89959B">
                                                                <g id="bookmark-outline" transform="translate(573 517)">
                                                                <path d="M12 0H2C.9 0 0 .9 0 2v16l7-3 7 3V2c0-1.1-.9-2-2-2zm0 15l-5-2.2L2 15V2h10v13z" id="Shape"></path>
                                                                </g>
                                                            </g>
                                                        </g>
                                                    </svg>
                                                    Marked
                                                    </td>
                                                    <td data-prompt="Marked for Review Count" class="summary-text ng-binding label-bookmarked">0</td>
                                                </tr>
                                                <!-- ngIf: hasSkipOptionSupport -->
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                                <div class="modal-footer pad-b24">
                                    <h4 class="text-left ng-binding">
                                        <?php if($skey + 1 < count($this->sections)){ ?>
                                            Are you sure you want to submit this Section?
                                        <?php } ?>
                                        <?php if($skey + 1 == count($this->sections)){ ?>
                                            Are you sure you want to submit this test?
                                        <?php } ?>
                                    </h4>
                                    <?php if($skey + 1 < count($this->sections)){
                                        $next_section = isset($this->sections[$skey+1])? (object) $this->sections[$skey+1] : null;
                                        ?>
                                        <button 
                                            type="button" 
                                            class="btn btn-primary" 
                                            data-gov-modal-control="submit-and-next-section" 
                                            data-gov-next-section="<?php echo ($next_section !== null)? $next_section->_id : ''; ?>"
                                        >
                                            Yes
                                        </button> 
                                    <?php } ?>

                                    <?php if($skey + 1 == count($this->sections)){ ?>
                                        <!--submit and next section-->
                                        <button data-gov-modal-control="finish-quiz" type="button" class="btn btn-primary">
                                            Yes
                                        </button>
                                    <?php } ?>

                                    <button type="button" data-dismiss="modal" class="x-close-btn btn btn-primary btn-gray-1">No</button>
                                </div>
                            </div>
                        </div>
                    </div>
                    <?php $dynamic_modals .= ob_get_clean();

                    if($skey + 1 < count($this->sections)){
                        ob_start(); ?>
                        <div data-gov-section-submit="<?php echo $section_id; ?>" class="gov-hide" style="padding: 0 15px;">
                            <button class="btn btn-primary" data-gov-section-submit-modal-btn="<?php echo $section_id; ?>">Submit Section</button>                
                        </div>
                        <?php $section_submit_controls .= ob_get_clean();   
                    }                
                }

                # sections tabs pills
                ob_start(); ?>
                <li class="dropdown <?php echo $skey == 0? 'active' : ''; ?>">
                    <a 
                        data-gov-section="<?php echo $section->_id; ?>"
                        class="question-attempted"
                        data-gov-section-switch="<?php echo $section_type == 'sectional-timing-section'? 'false' : 'true'; ?>"
                    >
                        <span class="hidden-xs ">
                            <?php echo $section->title; ?>
                        </span> 
                        <span class="visible-xs ">
                            <?php echo substr($section->title, 0, 3); ?>
                        </span> 
                    </a>
                </li>
                <?php $section_tabs .= ob_get_clean();

                # sections time indicators
                ob_start(); ?>
                <div data-gov-section-indicator="<?php echo $section->_id; ?>" class="<?php echo $skey == 0? '' : 'gov-hide'; ?>" style="display: flex;align-items: center;flex-direction: column;justify-content: center;align-content: center;">
                    <span class="font-size-small font-weight-semibold text-uppercase">
                        Section time 
                        <i class="tb-icon tb-happy font-size-medium text-success mar-b4"></i> 
                        <div id="section-time-counter" class="section-timer" style="display: inline-block;margin-left: 10px;font-size: 18px;position: relative;top: 2px;">
                            00:00:00
                        </div>
                        <input id="section-time-value" data-gov-section-default-time="<?php echo $section_time_value; ?>" class="each-section-time-value" type="hidden" value="<?php echo $section_time_value; ?>" />
                        <input id="section-current-question" class="each-section-time-value" type="hidden" value="<?php echo $before_q_counter; ?>" />
                    </span>
                </div>
                <?php $section_time_indicators .= ob_get_clean();

                ob_start(); ?>
                <div class="qnh-inner slim-scrollbar <?php echo $skey == 0? '' : 'gov-hide'; ?>" data-gov-section-question="<?php echo $section->_id; ?>">
                    <!--begin::section title--> 
                    <div class="mob-sidebar-section">
                        <span class="">Section : <?php echo $section->title; ?></span>
                    </div>
                    <!--end::section title--> 

                    <!--begin::pallete-->
                    <ul class="questionList slim-scrollbar hide-on-railway">
                        <?php echo $questions_palltetes; ?>
                    </ul>
                    <!--end::pallete--> 
                </div>
                <?php $questions_pallete_holder .= ob_get_clean();

            }
        }



        ob_start(); ?>
        <!DOCTYPE html>
        <html <?php language_attributes(); ?>>
        <?php echo $this->header(); ?>
        <body class="is-windows actual-exam-ui <?php echo $class_body; ?>">
        <!--body::begins-->
        <div class="scaffold">

            <!--begin::header-->
            <div class="tb-main-header">
                <div class="header__container">
                    <a href="#" class="tb-logo" target="_self">
                        <img class="logo-full" src="<?php echo site_url(); ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/shortcodes/course/default/dist/svgs/quiz.svg" alt="GOV Logo" />    
                    </a>
                    <p class="test-title hidden-xs mar-l16 mar-0">
                        <?php echo $this->quiz->title; ?>
                    </p>
                </div>
            </div>
            <!--end::header-->

            <!--begin::sidebar-profile--> 
            <div class="student-profile test-instructions-assets">
                <?php if (is_user_logged_in()) { 
                    // Get the current user's information
                    $current_user = wp_get_current_user();
                    $user_avatar = get_avatar_url($current_user->ID); // Get the avatar URL
                    $user_name = $current_user->display_name; // Get the user's display name
                } else {
                    // If not logged in, set the name to "Guest User" and use a placeholder avatar
                    $user_avatar = "https://example.com/placeholder-avatar.jpg"; // Replace with your placeholder avatar URL
                    $user_name = "Guest User";
                } ?>

                <img src="<?php echo $user_avatar; ?>" alt="<?php echo $user_name; ?>" style="width: 80px; height: 80px; border-radius: 50%;">
                <h3><?php echo $user_name; ?></h3>
            </div>
            <!--end::sidebar-profile--> 

            <!--begin::main-container--> 

            <!--begin::instructions-loop--> 
            <?php echo $this->instructions(); ?>
            <!--end::instructions-loop-->

            <!--begin::main-->
            <div id="page" class="u-mob-sidebar gov-hide">

                <div class="tp-left-box">
                    <!--begin::sections--> 
                    <div class="test-sections-list">
                        <h5 class="sl-title">Sections</h5>
                        <div class="sl-inner">
                            <div>
                                <ul id="sectionNavTabs" class="nav nav-pills sections-list">
                                    <?php echo $section_tabs; ?>
                                </ul>

                            </div>
                        </div>
                    </div>
                    <!--end::sections-->

                    <!--begin::questions-->
                    <div class="mob-question-holder">
                        <div id="mainBox" class="test-qpip-holder">
                            <div class="qpip-inner ng-scope" id="questions">
                                <!--begin::question-main--> 

                                <!--begin::question header--> 
                                <div class="header">
                                    <div class="header-inner">
                                        <div class="row">
                                            <div class="col-xs-3 tp-ques-number pad-r0 pad-t16">
                                                <div class="hidden-xs" id="qxs-no">Question No. 1</div>
                                                <div class="hidden-lg" id="qlg-no">1.</div>
                                            </div>
                                            <div class="col-xs-9 d-flex tp-pos-neg-marks pad-l0">
                                                <div class="text-left mar-r8 pad-md-r8">
                                                    <div class="font-size-base-1">Marks</div>
                                                    <span class="badge bg-attempted d-inline-block marks-correct" style="min-width:35px;">+0</span>
                                                    <span class="badge bg-skipped d-inline-block marks-negative" style="min-width:35px;">-0</span>
                                                </div>
                                                <div class="text-left mar-r4 pad-md-r8">
                                                    <div class="font-size-base-1">
                                                        Time
                                                        <div class="pad-h0" id="q-time">
                                                            00:00
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <!--end::question header--> 
                                
                                <!--begin::Question box--> 
                                <div id="question-box" class="slim-scrollbar body detailed-question js-detailed-question">
                                    <!--begin::question-answer loop-->
                                    <?php echo $questions_boxes; ?>
                                    <!--end::question-answer loop-->
                                </div>
                                <!--end::Question box--> 

                                <!--begin::question footer-->
                                <div class="footer mob-button-footer on-test-page">
                                    <?php echo $questions_footer; ?>
                                </div> 
                                <!--end::question footer-->     

                                <!--end::question-main-->  

                            </div>
                        </div>
                    </div>
                    <!--end::questions-->

                    <div class="sidebar-open-bg"></div>
                    <button type="button" class="btn btn-theme navbar-toggle js-trigger-toggle-sidebar">
                        <span class="tb-icon tb-menu"></span> 
                        <span class="tb-icon tb-clear"></span>
                    </button>
                </div>

                <div id="sidebar" class="tp-right-box">
                    <button type="button" class="toggle-sidebar-btn js-toggle-sidebar-btn">
                        <i class="tb-icon tb-arrow-left-thin"></i> 
                        <i class="tb-icon tb-arrow-right-thin"></i>
                    </button>
                    <div class="sidebar-content">
                        <!--begin::student details--> 
                        <div class="student-details">
                            <?php if (is_user_logged_in()) { 
                                // Get the current user's information
                                $current_user = wp_get_current_user();
                                $user_avatar = get_avatar_url($current_user->ID); // Get the avatar URL
                                $user_name = $current_user->display_name; // Get the user's display name
                            } else {
                                // If not logged in, set the name to "Guest User" and use a placeholder avatar
                                $user_avatar = "https://example.com/placeholder-avatar.jpg"; // Replace with your placeholder avatar URL
                                $user_name = "Guest User";
                            } ?>
                            <span class="img" style="background-image: url('<?php echo $user_avatar; ?>');"></span> 
                            <span class=""><?php echo $user_name; ?></span>
                        </div>
                        <!--end::student details--> 
                        <!--begin::questions states-->
                        <div class="q-possible-states hide-on-railway">
                            <div class="col-xs-4 pad-r0"><span class="u-legend-indicator attempted ">0</span> <span class="qps-state"><span>Answered</span><span>Attempted</span></span></div>
                            <div class="col-xs-4"><span class="u-legend-indicator bookmarked ">0</span> <span class="qps-state"><span>Marked</span><span>Tagged</span></span></div>
                            <div class="col-xs-4 pad-l0"><span class="u-legend-indicator ">48</span> <span class="qps-state">Not Visited</span></div>
                            <div class="col-xs-7 pad-r0"><span class="u-legend-indicator bookmarked attempted ">0</span> <span class="qps-state"><span>Marked and answered</span><span>Attempted &amp; Tagged</span></span></div>
                            <div class="col-xs-5 pad-l0"><span class="u-legend-indicator skipped ">2</span> <span class="qps-state"><span>Not Answered</span><span>Unattempted</span></span></div>
                        </div> 
                        <!--end::questions states--> 

                        <div class="section-time-indicators time-indicators" style="line-height: 25px;padding:10px 0;">
                            <?php echo $section_time_indicators; ?>
                        </div>

                        <!--begin::questions numbers holder--> 
                        <div class="questions-number-holder questions-number-section">
                            <!--begin::loop--> 
                            <?php echo $questions_pallete_holder; ?>
                            <!--end::loop--> 

                            <!--section submit controls--> 
                            <?php echo $section_submit_controls; ?>
                            <!--/section submit controls--> 
                        </div>
                        <!--end::questions numbers holder--> 

                        

                        <!--begin::actions--> 
                        <div class="marks-action">
                            <!--ul id="mainBtnBox" class="main-btn-box" role="tablist">
                                <li>
                                    <button type="button" class="btn btn-info-test btn-block">Question Paper</button>
                                </li>
                                <li>
                                    <button type="button" class="btn btn-info-test btn-block">Instructions</button>
                                </li>
                            </ul-->
                            <?php if(is_user_logged_in()){ ?>
                            <button type="button" class="btn btn-theme btn-block for-all-exams" data-gov-action="submit-test">Submit Test</button> 
                            <button type="button" class="btn btn-yellow-green btn-block for-ssc" data-gov-action="submit-test">Submit Test</button>
                            <?php } else { ?>
                            <button type="button" class="btn btn-theme btn-block for-all-exams" data-gov-action="login">Signin</button> 
                            <button type="button" class="btn btn-yellow-green btn-block for-ssc" data-gov-action="login">Signin</button>
                            <?php } ?>    
                        </div>
                        <!--end::actions--> 

                    </div>
                </div>

            </div> 
            <!--end::main--> 

            <!--timer--> 
            <div class="test-page-timer">
                <h4 class="mar-0 text-nowrap">
                    <span class="hidden-xs hidden-sm mar-r8 align-middle">
                        <?php if($this->category == "gov-non-sectional-timing"){ ?>
                            Time Left
                        <?php } else if($this->category == "gov-sectional-timing"){ ?>
                            Section Time
                        <?php } ?>
                        
                    </span>
                    <livetest-timer
                        
                        test-duration="4973" 
                        is-test-submitted="false" 
                        is-timer-paused="false" 
                        test-time-over-ptr="testTimeOver" 
                        resume-ptr="resumeTimerCB" 
                        hide-zero="n" 
                        skip-duration="0" 
                        show-alert="$parent.showTimerAlert" 
                        class="">
                            <span class="timer">
                                <span class="label label-default timer-hh">00</span> : 
                                <span class="label label-default ng-binding timer-mm">00</span> : 
                                <span class="label label-default ng-binding timer-ss">00</span>
                            </span>
                            <input 
                                type="hidden" 
                                data-gov-main-timer="true" 
                                data-gov-main-timer-value="<?php echo $this->default; ?>" 
                                value="<?php echo $this->default; ?>" 
                            />
                    </livetest-timer>
                </h4>
            </div>
            <!--/timer--> 

            <div class="calc-pause">
                <button data-gov-calculator="true" class="btn btn-outline-primary" type="button" style="border: 1px solid;">
                    Calculator
                </button>
                <!--button type="button" id="testFullScreenToggle" class="btn btn-default hidden-xs">Switch Full Screen</button> 
                <button type="button" class="btn">Pause</button-->
            </div>
    
            <!--end::main-container--> 
            

        </div>
        <!--modals--> 
        <?php echo $this->modals(); ?>
        <?php echo $dynamic_modals; ?>
        <!--body::ends-->
        <?php echo $this->footer(); ?>
        </body>
        </html>
        <?php return ob_get_clean();
    }

    public function get_result_layout(){
        
        $currentURL = 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
        $class_body = 'is-windows ng-scope actual-exam-ui';
        if(is_user_logged_in()){
            $class_body .= $this->result? ' -result' : ' -unknow';
            $class_body .= ' logged-in ';
        } else {
            $class_body .= ' anonymous-user';
        }

        $questions_headers          = "";
        $sections_states            = "";
        $section_tabs               = "";
        $section_time_indicators    = "";
        $questions_pallete_holder   = "";
        $questions_boxes            = "";
        $questions_footer           = "";
        $dynamic_modals             = '';
        $section_submit_controls    = "";
        $summary_sections           = "";
        $total_test_marks           = 0;
        $total_test_scores          = 0;
        $total_test_questions       = 0;
        $total_test_attempted       = 0;


        if( count($this->sections) > 0 ){
            foreach( $this->sections as $skey => $section ) {
                $section = (object) $section;
                $section_id         = $section->_id;
                $section_type       = $section->_postType;
                $section_title      = $section->title;
                $section_time_main  = isset($section->time)? (object) $section->time : null;
                $section_time       = isset($section_time_main->sectionTime)? (object) $section_time_main->sectionTime : null;
                $section_timer      = isset($section_time->timer)? (bool) $section_time->timer : false;
                $section_time_hh    = isset($section_time->hh)? (int) $section_time->hh : 0;
                $section_time_mm    = isset($section_time->mm)? (int) $section_time->mm : 0;
                $section_time_ss    = isset($section_time->ss)? (int) $section_time->ss : 0;
                $section_time_value = 0;

                $user_answers_obj       = isset($this->user_response->answers)? (object) $this->user_response->answers : (object) [];
                $user_sections          = isset($user_answers_obj->sections)? (array) $user_answers_obj->sections : (array) [];

                # for section indicators report 
                $section_total_questions = 0;
                $section_total_correct   = 0;
                $section_total_incorrect = 0;
                $section_total_pcorrect  = 0;
                $section_total_skipped    = 0;

                $section_summary_total_correct_points = 0;
                $section_summary_total_negative_points = 0;

                # add sections to an array
                self::$sections_arr[$skey] = $section_id;
                
                $filteredQuestions = (array) array_filter($this->questions, function ($obj) use ($section_id) {
                    $question = (object) $obj;
                    return ($question->_postId == $section_id);
                });

                self::$current_q_index = 0;
                $before_q_counter = self::$q_counter;
                $qindex = 0;

                $questions_palltetes = "";
                $total_marks = 0;

                if( count($filteredQuestions) > 0 ) {
                    foreach( $filteredQuestions as $qkey => $question ) {
                        $question = (object) $question;

                        $_questionSettings          = isset($question->_questionSettings)? (object) $question->_questionSettings : (object) [];
                        $question_points            = isset($_questionSettings->points)? (object) $_questionSettings->points : null;
                        $question_points_custom     = isset($question_points->custom)? $question_points->custom : false;
                        if($question_points_custom == true || $question_points_custom == 'true'){
                            
                            $question_correct_points    = isset($question_points->correct)? floatval($question_points->correct) : 1;
                            $question_negative_points   = isset($question_points->negative)? floatval($question_points->negative) : 0;
                            $question_negative_type     = isset($question_points->negativeType)? (string) $question_points->negativeType : 'value';
                        } else {
                            // here is -------------------------------------->
                            # $default_points_settings
                            $question_correct_points    = $this->default_points_settings->correct;
                            $question_negative_points   = $this->default_points_settings->negative;
                            $question_negative_type     = $this->default_points_settings->negativeType;
                        }
                        
                        $section_summary_total_correct_points += $question_correct_points;
                        if($question_negative_type == "value"){
                            $section_summary_total_negative_points += floatval($question_negative_points);
                        } else if($question_negative_type == "percentage"){
                            $section_summary_total_negative_points += floatval(($question_correct_points/$question_negative_points)*100);
                        }


                        self::$current_q_index++;

                        # question content boxes
                        $questions_boxes .= $this->get_question_result_html($question);

                        # report analyize
                        $self_classes = '';
                        $header_badge_class = '';
                        $header_badge_txt   = "";
                        $q_time             = "00:00";
                        $q_marks            = 0;


                        if(self::$questions_report[self::$q_counter]){
                            $rq = (object) self::$questions_report[self::$q_counter];
                            $q_time = $this->formatTime((int) $rq->time);
                            if($rq->status == "attempted-bookmarked" || $rq->status == "attempted"){
                                
                                if($rq->correct){
                                    $self_classes = 'correct-answer';
                                    $section_total_correct++;
                                    $header_badge_class = 'correct-answer';
                                    $header_badge_txt = "Correct";
                                    $q_marks = "+".$rq->correct_points;
                                    $total_marks += $rq->correct_points;
                                }
                                if($rq->wrong){
                                    $self_classes = 'wrong-answer';
                                    $section_total_incorrect++;
                                    $header_badge_class = 'wrong-answer';
                                    $header_badge_txt = "Wrong";

                                    if($rq->negative_type == "value"){
                                        $q_marks = "-".floatval($rq->negative_points);
                                        $total_marks -= floatval($rq->negative_points);
                                    } else if($rq->negative_type == "percentage"){
                                        $q_marks = "-".floatval(($rq->correct_points/$rq->negative_points)*100);
                                        $total_marks -= floatval($rq->negative_points);
                                    }
                                }

                                if($rq->pcorrect){
                                    //$self_classes = 'partial-correct';
                                    $section_total_pcorrect++;
                                }

                                

                            } else {
                                $section_total_skipped++;
                                $header_badge_class = '';
                                $header_badge_txt = "Skipped";
                            }
                        }

                        # question palletes
                        ob_start(); ?>
                        <li 
                            data-gov-result-question-pallete="<?php echo $question->_id; ?>"
                            data-gov-result-section-question-pallete="<?php echo $question->_postId; ?>"
                            class="label <?php echo self::$q_counter == 0? 'current-question' : ''; ?> <?php echo $self_classes; ?>" 
                            ng-class="{'bookmarked','attempted','skipped','current-question'}"
                        >
                            <?php echo self::$current_q_index; ?>
                        </li>
                        <?php $questions_palltetes .= ob_get_clean();

                        # questions footer
                        ob_start(); ?>
                        <div 
                            class="footer-inner gov-hide" 
                            data-gov-result-question-control="<?php echo $question->_id; ?>"
                            data-gov-result-section-question-control="<?php echo $question->_postId; ?>"
                        >
                            
                            <?php if($skey + 1 == count($this->sections)){ ?> 

                                <!--no more sections - no next-->
                                <?php if($qindex + 1 == count($filteredQuestions)){ ?>
                                    <!--last question - go-to-first-question-->

                                    <?php if(self::$q_counter == 0){ ?>
                                        <button type="button" class="btn btn-info-test mar-t0" disabled="disabled">
                                            Previous
                                        </button>
                                    <?php } else { ?>
                                        <button 
                                            data-gov-result-control="sn" 
                                            data-gov-result-control-type="previous-question"
                                            data-gov-result-question-control="<?php echo $question->_id; ?>"
                                            data-gov-result-section-question-control="<?php echo $question->_postId; ?>" 
                                            type="button" 
                                            class="btn btn-info-test mar-t0"
                                        >
                                            Previous
                                        </button>
                                    <?php } ?>

                                    <button 
                                        data-gov-result-control="sn" 
                                        data-gov-result-control-type="go-to-first-question"
                                        data-gov-result-question-control="<?php echo $question->_id; ?>"
                                        data-gov-result-section-question-control="<?php echo $question->_postId; ?>" 
                                        type="button" 
                                        class="btn btn-info-test pull-right mar-t0 ng-binding"
                                    >
                                        Next
                                    </button>
                                    
                                <?php } ?>

                                <?php if($qindex + 1 < count($filteredQuestions)){ ?>

                                    <?php if(self::$q_counter == 0){ ?>
                                        <button type="button" class="btn btn-info-test mar-t0" disabled="disabled">
                                            Previous
                                        </button>
                                    <?php } else { ?>
                                        <button 
                                            data-gov-result-control="sn" 
                                            data-gov-result-control-type="previous-question"
                                            data-gov-result-question-control="<?php echo $question->_id; ?>"
                                            data-gov-result-section-question-control="<?php echo $question->_postId; ?>" 
                                            type="button" 
                                            class="btn btn-info-test mar-t0"
                                        >
                                            Previous
                                        </button>
                                    <?php } ?>

                                    <!--next question - no more sections - go to first-->
                                    <button 
                                        data-gov-result-control="sn" 
                                        data-gov-result-control-type="next-question" 
                                        data-gov-result-question-control="<?php echo $question->_id; ?>"
                                        data-gov-result-section-question-control="<?php echo $question->_postId; ?>"
                                        type="button" 
                                        class="btn btn-info-test pull-right mar-t0 ng-binding"
                                    >
                                        Next
                                    </button>
                                    
                                <?php } ?>
                                

                            <?php } ?>

                            <?php if($skey + 1 < count($this->sections)){ ?>  
                                <!--next sections-->
                                <?php if($qindex + 1 == count($filteredQuestions)){ ?>
                                    <?php if(self::$q_counter == 0){ ?>
                                        <button type="button" class="btn btn-info-test mar-t0" disabled="disabled">
                                            Previous
                                        </button>
                                    <?php } else { ?>
                                        <button 
                                            data-gov-result-control="sn" 
                                            data-gov-result-control-type="previous-question"
                                            data-gov-result-question-control="<?php echo $question->_id; ?>"
                                            data-gov-result-section-question-control="<?php echo $question->_postId; ?>" 
                                            type="button" 
                                            class="btn btn-info-test mar-t0"
                                        >
                                            Previous
                                        </button>
                                    <?php } ?>

                                    <!--last question - next-section-->
                                    <button 
                                        data-gov-result-control="sn" 
                                        data-gov-result-control-type="next-section"
                                        data-gov-result-question-control="<?php echo $question->_id; ?>"
                                        data-gov-result-section-question-control="<?php echo $question->_postId; ?>" 
                                        type="button" 
                                        class="btn btn-info-test pull-right mar-t0 ng-binding"
                                    >
                                        Next
                                    </button>
                                    

                                <?php } ?>
                                <?php if($qindex + 1 < count($filteredQuestions)){ ?>
                                    <?php if(self::$q_counter == 0){ ?>
                                        <button type="button" class="btn btn-info-test mar-t0" disabled="disabled">
                                            Previous
                                        </button>
                                    <?php } else { ?>
                                        <button 
                                            data-gov-result-control="sn" 
                                            data-gov-result-control-type="previous-question"
                                            data-gov-result-question-control="<?php echo $question->_id; ?>"
                                            data-gov-result-section-question-control="<?php echo $question->_postId; ?>" 
                                            type="button" 
                                            class="btn btn-info-test mar-t0"
                                        >
                                            Previous
                                        </button>
                                    <?php } ?>

                                    <!--next question - same-section-->
                                    <button 
                                        data-gov-result-control="sn" 
                                        data-gov-result-control-type="next-question"
                                        data-gov-result-question-control="<?php echo $question->_id; ?>"
                                        data-gov-result-section-question-control="<?php echo $question->_postId; ?>" 
                                        type="button" 
                                        class="btn btn-info-test pull-right mar-t0 ng-binding"
                                    >
                                        Next
                                    </button>
                                    
                                <?php } ?>


                            <?php } ?>    






                            
                        </div>
                        <?php $questions_footer .= ob_get_clean();

                        # header info question
                        ob_start(); ?>
                        <div class="col-xs-9 pad-t12 mar-t2 tp-info gov-hide" data-gov-result-question-header="<?php echo $question->_id; ?>" data-gov-result-section-question-header="<?php echo $question->_postId; ?>">
                            <div class="tp-ques-number d-inline-block border-r1 border-color-gray-10 pad-lg-r8 pad-r4 ng-binding">
                                <span class="hidden-xs">Question No.</span>
                                <?php echo self::$current_q_index; ?>
                            </div>
                            <div class="d-inline-block">

                                <span class="badge pad-h8 pad-v4 ng-binding <?php echo $header_badge_class; ?>">
                                    <?php echo $header_badge_txt; ?>
                                </span>
                            </div>
                            
                            <div class="d-inline-block pad-md-r8 ng-scope">
                                <span class="font-size-small ng-binding">You:</span> 
                                <span class="font-size-small text-gray-4 pad-0 ng-binding">
                                    <?php echo $q_time; ?>
                                </span>
                            </div>
                            
                            <div class="d-inline-block pad-lg-l8 pad-l4 border-l1 border-color-gray-10">
                                <span class="font-size-small ng-binding">Marks</span> 
                                <span class="badge ng-binding <?php echo $header_badge_class; ?>">
                                    <?php echo $q_marks; ?>
                                </span>
                            </div>
                        </div>
                        <?php $questions_headers .= ob_get_clean();


                        $qindex++;
                        self::$q_counter++;
                        

                    }
                }

                $section_total_questions = count($filteredQuestions);

                $pQuestions = (array) array_filter(self::$questions_report, function ($obj) use ($section_id) {
                    $question = (object) $obj;
                    return ($question->pid == $section_id);
                });

                self::$sections_report[$skey] = (object) [
                    "_id"       => $section_id,
                    "title"     => $section_title,
                    "correct"   => $section_total_correct,
                    "incorrect" => $section_total_incorrect,
                    "total"     => $section_total_questions,
                    "pcorrect"  => $section_total_pcorrect,
                    "skipped"   => $section_total_skipped,
                    "questions" => $pQuestions,
                    "marks"     => $total_marks,
                    "total_correct_points"  => $section_summary_total_correct_points,
                    "total_negative_points" => $section_summary_total_negative_points,
                    "more"    => $user_sections[$skey]
                ];

                $total_test_marks += $total_marks;
                $total_test_scores += $section_summary_total_correct_points;
                $total_test_questions += $section_total_questions;
                $total_test_attempted += ($section_total_correct + $section_total_incorrect);
                

                # sections tabs pills
                ob_start(); ?>
                <li class="dropdown <?php echo $skey == 0? 'active' : ''; ?>">
                    <a 
                        data-gov-result-section="<?php echo $section->_id; ?>"
                        class="question-attempted"
                        data-gov-result-section-switch="true"
                    >
                        <span class="hidden-xs ">
                            <?php echo $section->title; ?>
                        </span> 
                        <span class="visible-xs ">
                            <?php echo substr($section->title, 0, 3); ?>
                        </span> 
                    </a>
                </li>
                <?php $section_tabs .= ob_get_clean();

                # sections time indicators
                ob_start(); ?>
                <div data-gov-result-section-indicator="<?php echo $section->_id; ?>" class="<?php echo $skey == 0? '' : 'gov-hide'; ?>" style="display: flex;align-items: center;flex-direction: column;justify-content: center;align-content: center;">
                    <span class="font-size-small font-weight-semibold text-uppercase">
                        Section time 
                        <i class="tb-icon tb-happy font-size-medium text-success mar-b4"></i> 
                        <div id="section-time-counter" class="section-timer" style="display: inline-block;margin-left: 10px;font-size: 18px;position: relative;top: 2px;">
                            00:00:00
                        </div>
                        <input id="section-time-value" class="each-section-time-value" type="hidden" value="<?php echo $section_time_value; ?>" />
                        <input id="section-current-question" class="each-section-time-value" type="hidden" value="<?php echo $before_q_counter; ?>" />
                    </span>
                </div>
                <?php $section_time_indicators .= ob_get_clean();

                # right box - questions pallete holder
                ob_start(); ?>
                <div class="qnh-inner slim-scrollbar <?php echo $skey == 0? '' : 'gov-hide'; ?>" data-gov-result-section-question="<?php echo $section->_id; ?>">
                    <!--begin::section title--> 
                    <div class="mob-sidebar-section">
                        <span class="">Section : <?php echo $section->title; ?></span>
                    </div>
                    <!--end::section title--> 

                    <!--begin::pallete-->
                    <ul class="questionList slim-scrollbar hide-on-railway">
                        <?php echo $questions_palltetes; ?>
                    </ul>
                    <!--end::pallete--> 
                </div>
                <?php $questions_pallete_holder .= ob_get_clean();

                # section states 
                ob_start(); ?>
                <div class="q-possible-states gov-hide" data-gov-result-section-states="<?php echo $section->_id; ?>">
                    <div class="col-xs-4 pad-r0">
                        <span class="label correct-answer u-legend-indicator ng-binding">
                            <?php echo $section_total_correct; ?>
                        </span> 
                        <span class="qps-state">Correct</span>
                    </div>
                    <div class="col-xs-4 pad-l0 pad-r0">
                        <span class="label u-legend-indicator ng-binding">
                            <?php echo $section_total_skipped; ?>
                        </span> 
                        <span class="qps-state">Unattempted</span>
                    </div>
                    <div class="col-xs-4 pad-l0">
                        <span class="label wrong-answer u-legend-indicator ng-binding">
                            <?php echo $section_total_incorrect; ?>
                        </span> 
                        <span class="qps-state">Incorrect</span>
                    </div>
                    <div class="col-xs-4 pad-r0">
                        <span class="label partial-correct u-legend-indicator ng-binding">
                            <?php echo $section_total_pcorrect; ?>
                        </span> 
                        <span class="qps-state">Partially Correct</span>
                    </div>
                </div>
                <?php $sections_states .= ob_get_clean();


                # modal 
                ob_start(); ?>
                <tr ng-repeat="section in test.sections track by $index" class="ng-scope">
                    <td data-prompt="Section" class="ng-binding">
                        <?php echo $section_title; ?>
                    </td>
                    <td data-prompt="No. of questions" class="ng-binding">
                        <?php echo self::$sections_report[$skey]->total; ?>
                    </td>
                    <td data-prompt="Correct" class="ng-binding">
                        <?php echo self::$sections_report[$skey]->correct; ?>
                    </td>
                    <td data-prompt="Incorrect" class="ng-binding">
                    <?php echo self::$sections_report[$skey]->incorrect; ?>
                    </td>
                    <td data-prompt="Skipped" class="ng-binding">
                    <?php echo self::$sections_report[$skey]->skipped; ?>
                    </td>
                    <td data-prompt="Marks" class="ng-binding">
                        <?php echo self::$sections_report[$skey]->marks; ?>
                    </td>
                </tr>
                <?php $summary_sections .= ob_get_clean();


            
            }
        }

        ob_start(); ?>
        <div class="modal fade" id="result-summaryModal" tabindex="-1" role="dialog" aria-labelledby="summaryLabel" aria-hidden="true" data-backdrop="static" style="display: none;">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true"><i class="tb-icon tb-clear"></i></span></button>
                        <h3 class="modal-title" id="summaryLabel">Summary</h3>
                    </div>
                    <div class="modal-body">
                        <h4 class="text-center mar-t0 ng-binding">Total Marks: <?php echo $total_test_marks; ?></h4>
                        <div class="table-responsive">
                            <table class="table table-bordered">
                                <thead>
                                    <tr>
                                        <th>Section</th>
                                        <th>No. of questions</th>
                                        <th>Correct</th>
                                        <th>Incorrect</th>
                                        <th>Skipped</th>
                                        <!-- ngIf: hasSkipOptionSupport -->
                                        <th>Marks</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <!-- ngRepeat: section in test.sections track by $index -->
                                    <?php echo $summary_sections; ?>
                                    
                                </tbody>
                            </table>
                        </div>
                        
                    </div>
                    
                    <!-- ngIf: !hideAnalysis && isAnalysisAvailable || !checkSdkModeActive -->
                    <div class="modal-footer ng-scope" ng-if="!hideAnalysis &amp;&amp; isAnalysisAvailable || !checkSdkModeActive">
                        <a 
                            href="<?php echo str_replace('?type=solution','',$currentURL); ?>" 
                            class="btn btn-theme test-analysis-btn"
                        >
                            Continue to Test Analysis
                        </a>
                    </div>
                    <!-- end ngIf: !hideAnalysis && isAnalysisAvailable || !checkSdkModeActive -->
                </div>
            </div>
        </div>
        <?php $dynamic_modals .= ob_get_clean();

        $analyize_report = (object) [
            "sections"  => self::$sections_report,
            "questions" => self::$questions_report,
            "total_test_marks" => $total_test_scores,
            "total_user_marks" => $total_test_marks,
            "total_questions"  => $total_test_questions,
            "total_attempted"  => $total_test_attempted
        ];


        // upadte score
        // upadte score
        global $wpdb, $table_proqyz_v3_progress_submissions_meta, $table_proqyz_v3_progress_submissions_score;
        $resultId = $this->result_id;
        if ( $result_id ) {
            // check if meta exists if not then update it
            $get_score = $wpdb->get_row("SELECT `ID` FROM `$table_proqyz_v3_progress_submissions_score` WHERE `submission_id` = '$this->result_id' LIMIT 1");
            if( !$get_score ) {
                $wpdb->insert($table_proqyz_v3_progress_submissions_score, [
                    "user_id" => $this->student_id,
                    "submission_id" => $this->result_id,
                    "score_data" => json_encode($analyize_report),
                    "created_at" => time(),
                ]);
            } else {
                $wpdb->update($table_proqyz_v3_progress_submissions_score, [ 
                    "score_data" => json_encode($analyize_report),
                    "updated_at" => time(), 
                ], [ "submission_id" => $this->result_id, "user_id" => $this->student_id ]);
            }
        }
        
        $currentURL = 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

        $custom_logo_id = get_theme_mod('custom_logo');
        $site_logo = wp_get_attachment_image_url($custom_logo_id , 'full');

        ob_start(); ?>
        <!DOCTYPE html>
        <html <?php language_attributes(); ?>>
        <?php echo $this->header(); ?>
        <body class="<?php echo $class_body; ?>">
            <!--anaylic page-->
            <?php if($this->page_type == "analytics"){ ?>
            <div class="flex-container">

                <div class="sticky-header">
                    <div class="notify-panel-box js-notify-panel-box js-banner-height-offset">
                    </div>
                    <div class="sticky-header__logo flexing" ng-class="">
                        
                        <a href="/" ng-if="" class="logo d-md-block ng-scope" style="width:35px;">
                            <img class="logo-full" src="<?php echo site_url(); ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/shortcodes/course/default/dist/svgs/quiz.svg" alt="Gov Logo" />
                        </a>
                        
                        <div class="fake-wrapper ng-scope" ng-if="">
                            <div class="sticky-header__title width-feedback" ng-class="" style="margin-left: 10px;">
                            <div class="d-block d-md-none">
                                <a href="#" class="tb-text-grey ng-scope">
                                    <span class="chevron"></span>
                                    <div class="max-width-150 text-truncate ng-binding">
                                    <?php echo $this->quiz->title; ?>
                                    </div>
                                </a>
                            </div>
                            <div class="d-none d-md-block text-truncate ng-binding">
                                <?php echo $this->quiz->title; ?>
                            </div>
                            </div>
                        </div>
                    </div>
                    <div class="sticky-header__nav">
                        <nav>
                            <ul>
                            <li ng-if="" class="ng-scope">
                                <a href="<?php echo $currentURL; ?>?type=solution" class="btn btn-outline-primary">Solutions</a>
                            </li>
                            </ul>
                        </nav>
                    </div>
                </div>

                <div class="sticky-container top-header">
                    <div class="wrapper px-0 px-md-3 ng-scope">
                        <h3 class="">Overall Performance Summary</h3>
                        <!--analysis report icons--> 
                        <?php echo $this->result_analysis_report_header((object) [
                            "total_test_marks" => $total_test_scores,
                            "total_user_marks" => $total_test_marks,
                            "total_questions"  => $total_test_questions,
                            "total_attempted"  => $total_test_attempted
                        ]); ?>
                        <!--category report--> 
                        <div class="select-category ng-scope">
                            <h3>Sectional Summary</h3>
                        </div>
                        <div class="tb-card tb-card--main-content ng-scope">
                            <div class="table-responsive">


                                <table class="table-grid table-grid--summary">
                                    <thead>
                                        <tr>
                                            <th>Section Name</th>
                                            <th>Score</th>
                                            <th>Attempted</th>
                                            <!-- <th>Accuracy</th> -->
                                            <th ng-if="isTimeDisplay" class="ng-scope">Time Spended</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php if(count(self::$sections_report) > 0){ 
                                            foreach( self::$sections_report as $skey => $section ) {
                                                $section = (object) $section;
                                                $more    = (object) $section->more;
                                                $time_indicator = "";
                                                if($this->quiz->_category == "non-sectional-timing"){
                                                    $time_width_pct = (isset($this->default) && $this->default > 0) ? (($this->default - $more->visit) / $this->default) * 100 : 0;
                                                    ob_start(); ?>
                                                    <div class="indicator__progress indicator--time" style="width:<?php echo $time_width_pct; ?>%"></div>
                                                    <div class="ng-binding">
                                                        
                                                        <?php echo $this->formatTime($more->visit); ?>
                                                    </div>
                                                    <?php $time_indicator = ob_get_clean();
                                                } else {
                                                    $time_width_pct = (isset($more->time) && $more->time > 0) ? (($more->time - $more->visit) / $more->time) * 100 : 0;
                                                    ob_start(); ?>
                                                    <div class="indicator__progress indicator--time" style="width:<?php echo $time_width_pct; ?>%"></div>
                                                    <div class="ng-binding">
                                                        <?php echo $this->formatTime($more->time - $more->visit); ?><span class="help-text ng-binding"> / 
                                                        <?php echo $this->formatTime($more->time); ?></span>
                                                    </div>
                                                    <?php $time_indicator = ob_get_clean();
                                                }

                                                $marks_percentage = 0;
                                                $total_correct_points = isset($section->total_correct_points) ? (float) $section->total_correct_points : 0;
                                                if ($total_correct_points > 0) {
                                                    $marks_percentage = ((float) $section->marks / $total_correct_points) * 100;
                                                }

                                                $qus_percentage = 0;
                                                $totalAttempts = (int) $section->correct + (int) $section->incorrect;
                                                $section_total = isset($section->total) ? (float) $section->total : 0;
                                                if ($section_total > 0) {
                                                    $qus_percentage = ($totalAttempts / $section_total) * 100;
                                                }

                                                ?>
                                                <tr>
                                                    <td>
                                                        <?php echo $section->title; ?>
                                                    </td>
                                                    <td>
                                                        <div class="indicator__progress indicator--score" style="width: <?php echo $marks_percentage; ?>%"></div>
                                                        <div class="ng-binding">
                                                            <?php echo $section->marks; ?>
                                                            <span class="help-text ng-binding"> / <?php echo $section->total_correct_points; ?></span>
                                                        </div>
                                                    </td>
                                                    <td class="ng-scope">
                                                        <div class="indicator__progress indicator--attempted" style="width: <?php echo $qus_percentage; ?>%"></div>
                                                        <div class="ng-binding"> 
                                                            <?php echo ((int) $section->correct + (int) $section->incorrect); ?> <span class="help-text ng-binding"> / <?php echo $section->total; ?></span>
                                                        </div>
                                                    </td>
                                                    <!-- <td></td> -->
                                                    <td>
                                                        <?php echo $time_indicator; ?>
                                                    </td>
                                                </tr>
                                                <?php 
                                            }
                                        } ?>
                                    </tbody>
                                </table>



                            
                            </div>    
                        </div>

                    </div>
                </div>

            </div>
            
            <?php } ?>

            <?php if($this->page_type == "solution"){ ?>
            <div class="test-top-bar ng-scope">

                <div class="left-box back-to-mytests top-header ng-scope">
                    <div class="d-inline-block align-middle">
                        <a ng-if="fromTestSeries" href="<?php echo str_replace('?type=solution','',$currentURL); ?>" class="test-btn-style ng-scope"><i class="tb-icon tb-arrow-left"></i></a>
                    </div>
                    <div class="d-inline-block">
                        <h4 class="mar-t0 mar-b8">Tests</h4>
                        <h6 class="mar-v0 text-ellipsis ng-binding"><?php echo $this->quiz->title; ?></h6>
                    </div>
                </div> 
                
                <div class="right-box ng-scope">
                    <a href="<?php echo str_replace('?type=solution','',$currentURL); ?>" class="btn rb-btn test-btn-style ng-scope" translate="">ANALYTICS</a>
                </div>
                
                



            </div>  
            <div id="page-solution" class="u-mob-sidebar solutions-page ng-scope">

                <div class="tp-left-box">

                    <div class="test-sections-list d-flex">
                        <h5 class="sl-title ng-scope" translate="">Sections</h5>
                        <div class="sl-inner test-sections-scroll sl-solution">
                            <ul id="sectionNavTabs" class="nav nav-pills sections-list">
                                <?php echo $section_tabs; ?>
                            </ul>
                        </div>
                    </div>

                    <!--begin::questions-->
                    <div class="mob-question-holder">
                        <div id="mainBox" class="test-qpip-holder">
                            <div class="qpip-inner ng-scope" id="questions">
                                <!--begin::question-main--> 

                                <!--begin::question header--> 
                                <div class="header">
                                    <div class="header-inner">
                                        <div class="row">
                                            <!--question headers loops--> 
                                            <?php echo $questions_headers; ?>
                                        </div>
                                    </div>
                                </div>
                                <!--end::question header--> 
                                    
                                <!--begin::Question box--> 
                                <div id="question-box" class="slim-scrollbar body detailed-question js-detailed-question">
                                    <!--begin::question-answer loop-->
                                    <?php echo $questions_boxes; ?>
                                    <!--end::question-answer loop-->

                                    
                                </div>
                                <!--end::Question box--> 

                                <!--begin::question footer-->
                                <div class="footer mob-button-footer">
                                    <?php echo $questions_footer; ?>
                                    <div class="toggle-reattempt-state">
                                        <span class="text-gray-4">
                                            Re-attempt Ques<span class="hidden-xs">tions</span>
                                        </span> 
                                        <label class="tb-checkbox-switch">
                                            <input type="checkbox" checked="checked" /> 
                                            <span class="tb-checkbox-switch-slider"></span> 
                                            <span class="tb-popover top min-width-300 ng-hide gov-hide">
                                                <button type="button" class="cancel-po">
                                                    <i class="tb-icon tb-clear font-sm"></i>
                                                </button> 
                                                <span class="po-content text-left ng-scope" translate="">
                                                    Re-attempt mode is on. You can re-attempt the question or click on View Solution to see the answer and detailed solution
                                                </span>
                                            </span>
                                        </label>
                                    </div>
                                </div> 
                                <!--end::question footer-->     

                                <!--end::question-main-->  

                            </div>
                        </div>
                    </div>
                    <!--end::questions-->

                    <div class="sidebar-open-bg"></div>
                    <button type="button" class="btn btn-theme navbar-toggle js-trigger-toggle-sidebar">
                        <span class="tb-icon tb-menu"></span> 
                        <span class="tb-icon tb-clear"></span>
                    </button>

                </div>


                <div id="sidebar" class="tp-right-box">
                    <button type="button" class="toggle-sidebar-btn js-toggle-sidebar-btn">
                        <i class="tb-icon tb-arrow-left-thin"></i> 
                        <i class="tb-icon tb-arrow-right-thin"></i>
                    </button>
                    <div class="sidebar-content">
                        <!--begin::student details--> 
                        <div class="student-details">
                            <span class="img" style="background-image: url(&quot;//cdn.testbook.com/static/assets/assets/img/utility/tb-avatar.svg&quot;);"></span> 
                            <span class="">Student Name</span>
                        </div>
                        <!--end::student details--> 
                        <!--begin::questions states-->
                        <div class="q-possible-states hide-on-railway">
                            <?php echo $sections_states; ?>
                        </div> 
                        <!--end::questions states--> 

                        <div class="section-time-indicators time-indicators" style="line-height: 25px;padding:10px 0;">
                            <?php echo $section_time_indicators; ?>
                        </div>

                        <!--begin::questions numbers holder--> 
                        <div class="questions-number-holder questions-number-section">
                            <!--begin::loop--> 
                            <?php echo $questions_pallete_holder; ?>
                            <!--end::loop--> 
                        </div>
                        <!--end::questions numbers holder--> 

                        

                        <!--begin::actions--> 
                        <div class="marks-action">
                            <ul id="mainBtnBox" class="main-btn-box" role="tablist">
                                <li>
                                    <button type="button" class="btn btn-info-test btn-block">Question Paper</button>
                                </li>
                                <li>
                                    <button type="button" class="btn btn-info-test btn-block" data-gov-result-modal-target="#result-summaryModal" data-gov-result-modal="modal">Summary</button>
                                </li>
                            </ul>
                            
                        </div>
                        <!--end::actions--> 

                    </div>
                </div>



            </div>  
            <?php } ?> 

            <?php echo $this->modals(); ?>
            <?php echo $dynamic_modals; ?>
            <?php echo $this->footer(); ?>
        </body>
        </html>
        <?php return ob_get_clean();


    }

    public function get_question_html($question = []){
        $question               = (object) $question;
        $_questionSettings      = isset($question->_questionSettings)? (object) $question->_questionSettings : (object) [];
        
        # pointing system
        $question_points                = isset($_questionSettings->points)? (object) $_questionSettings->points : null;
        $custom_points                  = isset($question_points->custom)? $question_points->custom : false;

        if( $custom_points ) {
            $question_correct_points    = isset($question_points->correct)? floatval($question_points->correct) : 0;
            $question_negative_points   = isset($question_points->negative)? floatval($question_points->negative) : 0;
            $question_negative_type     = isset($question_points->negativeType)? (string) $question_points->negativeType : 'value';
        } else {

            $quiz_settings              = isset($this->quiz->settings)? (object) $this->quiz->settings : null;
            $points_settings            = isset($quiz_settings->points)? (object) $quiz_settings->points : null;
            $question_correct_points    = isset($points_settings->correct)? floatval($points_settings->correct) : 0;
            $question_negative_points   = isset($points_settings->negative)? floatval($points_settings->negative) : 0;
            $question_negative_type     = isset($points_settings->negativeType)? (string) $points_settings->negativeType : 'value';
        }

        

        
        $input_type             = isset($_questionSettings->inputType)? (string) $_questionSettings->inputType : null;
        $_answerSettings        = isset($question->_answerSettings)? (object) $question->_answerSettings : (object) [];
        $number_of_options      = isset($_answerSettings->numberOfOptions)? (int) $_answerSettings->numberOfOptions : 0;
        $answerType             = isset($_answerSettings->answerType)? (string) $_answerSettings->answerType : null;
        $answerTypes            = isset($_answerSettings->answerTypes)? (array) $_answerSettings->answerTypes : (array) [];
        $questions              = isset($question->questions)? (array) $question->questions : [];
        $question_content       = isset($question->content)? (object) $question->content : (object) [];
        $html                   = isset($question_content->html)? (string) $question_content->html : "empty";
        $question_options       = isset($question->options)? (array) $question->options : [];
        $my_negative_points     = 0;

        $classes = [];
        if(self::$q_counter == 0){
            $classes[] = "current-question";
            $classes[] = "skipped";
        }

        

        if($question_negative_type == "value"){
            $my_negative_points = floatval($question_negative_points);
        } else if($question_negative_type == "percentage"){
            $my_negative_points = floatval(($question_correct_points/$question_negative_points)*100);
        }

        self::$questions_arr[self::$q_counter] = (object) [
            "qindex"    => self::$q_counter,
            "pid"       => $question->_postId,
            "qid"       => $question->_id,
            "pqi"       => self::$current_q_index,
            "classes"   => $classes,
            "visit"     => self::$q_counter == 0? 0 : 0,
            "time"      => 0,
            "question"  => (object) [
                "input_type"  => $input_type,
            ],
            "answers"   => (array) [],
            "visited"   => self::$q_counter == 0? true : false,
            "correct_points"    => $question_correct_points,
            "negative_points"   => $question_negative_points,
            "negative_type"     => $question_negative_type
        ];

        if($input_type == "radio" || $input_type == "checkbox"){
            ob_start(); ?>
            <div 
                class="que-ans-box slim-scrollbar <?php echo self::$q_counter == 0? '' : 'gov-hide'; ?>" 
                data-gov-question="<?php echo $question->_id; ?>" 
                data-gov-question-section="<?php echo $question->_postId; ?>"
                data-gov-question-input-type="<?php echo $input_type; ?>"
                data-gov-question-correct-points="<?php echo $question_correct_points; ?>"
                data-gov-question-negative-points="<?php echo $my_negative_points; ?>"
                data-gov-question-negative-type="<?php echo $question_negative_type; ?>"
            >
                <div>
                    <b class="ng-hide">
                        <u>
                            <i>Question: <?php echo self::$current_q_index; ?></i>
                        </u>
                    </b>
                    <div class="qns-view-box"><?php echo $html; ?></div>
                    <?php if($input_type == "radio"){ ?>
                        <?php if(count($questions) == 1){ ?>
                            <ul class="q-multiple-choices">
                            <?php foreach( $questions as $qkey => $qus ){
                                $qus = (object) $qus;
                                $options = (array) $qus->options;
                                foreach( $options as $okey => $option ) {
                                    $option = (object) $option;
                                    ?><li>
                                        <label for="qus-<?php echo $question->_id; ?>-<?php echo $okey; ?>">
                                            <input 
                                                type="<?php echo $input_type; ?>" 
                                                name="qus-<?php echo $question->_id; ?>" 
                                                id="qus-<?php echo $question->_id; ?>-<?php echo $okey; ?>" 
                                                value="<?php echo $okey; ?>"
                                            />
                                            <div class="mar-l24 qns-view-box">
                                                <?php echo $option->content; ?>
                                            </div>
                                        </label>
                                    </li><?php
                                }
                            } ?>
                            </ul>
                        <?php } ?>
                    <?php } ?>
                    <?php if($input_type == "checkbox"){ ?>
                        <ul class="q-multiple-choices">

                        <?php if( count($question_options) > 0 ) {
                            foreach( $question_options as $okey => $option ) {
                                $option = (object) $option;
                                ?><li>
                                    <label for="qus-<?php echo $question->_id; ?>-<?php echo $okey; ?>">
                                        <input 
                                            type="<?php echo $input_type; ?>" 
                                            name="qus-<?php echo $question->_id; ?>" 
                                            id="qus-<?php echo $question->_id; ?>-<?php echo $okey; ?>" 
                                            value="<?php echo $okey; ?>"
                                        />
                                        <div class="mar-l24 qns-view-box">
                                            <?php echo $option->content; ?>
                                        </div>
                                    </label>
                                </li><?php
                            }
                        } ?>
                        </ul>
                    <?php } ?>


                </div>
            </div>
            <?php return ob_get_clean();
        } else if($input_type == 'fillup'){

            if(preg_match_all( '/\{([^{}]+)\}/', $html, $multiTextMatches)){
                // {}
                $matches        = $multiTextMatches[0];
                $inner_values   = $multiTextMatches[1];

                for($i = 0; $i < count($matches); $i++ ) {
                    $expression     = $matches[$i];
                    $inner_value    = $inner_values[$i];
                    $inner_arr      = (array) explode("|", $inner_value );

                    // Apply the same transformations to each element in the array
                    $inner_arr = array_map(function($value) {
                        return trim(strtolower($value));
                    }, $inner_arr);

                    // main select input
                    ob_start(); ?>
                    <input 
                        type="text" 
                        data-gov-fillup="<?php echo $i; ?>"
                        placeholder="<?php echo $i+1; ?>" 
                        class="gov-fillup_input" 
                        value=""
                    />
                    <?php $input_fillup = ob_get_clean();
                    $html = $this->str_replace_first($expression,$input_fillup,$html);
                }
            }

            ob_start(); ?>
            <div 
                class="que-ans-box slim-scrollbar <?php echo self::$q_counter == 0? '' : 'gov-hide'; ?>" 
                data-gov-question="<?php echo $question->_id; ?>" 
                data-gov-question-section="<?php echo $question->_postId; ?>"
                data-gov-question-input-type="fillup"
                data-gov-question-correct-points="<?php echo $question_correct_points; ?>"
                data-gov-question-negative-points="<?php echo $question_negative_points; ?>"
                data-gov-question-negative-type="<?php echo $question_negative_type; ?>"
            >
                <div>
                    <b class="ng-hide">
                        <u>
                            <i>Question: <?php echo self::$current_q_index; ?></i>
                        </u>
                    </b>
                    <div class="qns-view-box">
                        <?php 
                            echo $html; 
                        ?>
                    </div>
                </div>
            </div>
            <?php return ob_get_clean();
        }


    }

    public function get_question_result_html($question = []){
        $question               = (object) $question;
        $_questionSettings      = isset($question->_questionSettings)? (object) $question->_questionSettings : (object) [];
        $input_type             = isset($_questionSettings->inputType)? (string) $_questionSettings->inputType : null;
        
        # pointing system
        $question_points            = isset($_questionSettings->points)? (object) $_questionSettings->points : null;
        $custom_points              = isset($question_points->custom)? $question_points->custom : false;

        if( $custom_points ) {
            $question_correct_points    = isset($question_points->correct)? floatval($question_points->correct) : 0;
            $question_negative_points   = isset($question_points->negative)? floatval($question_points->negative) : 0;
            $question_negative_type     = isset($question_points->negativeType)? (string) $question_points->negativeType : 'value';
        } else {
            $quiz_settings              = isset($this->quiz->settings)? (object) $this->quiz->settings : null;
            $points_settings            = isset($quiz_settings->points)? (object) $quiz_settings->points : null;
            $question_correct_points    = isset($points_settings->correct)? floatval($points_settings->correct) : 0;
            $question_negative_points   = isset($points_settings->negative)? floatval($points_settings->negative) : 0;
            $question_negative_type     = isset($points_settings->negativeType)? (string) $points_settings->negativeType : 'value';
        }
        
        
        $_answerSettings        = isset($question->_answerSettings)? (object) $question->_answerSettings : (object) [];
        $number_of_options      = isset($_answerSettings->numberOfOptions)? (int) $_answerSettings->numberOfOptions : 0;
        $answerType             = isset($_answerSettings->answerType)? (string) $_answerSettings->answerType : null;
        $answerTypes            = isset($_answerSettings->answerTypes)? (array) $_answerSettings->answerTypes : (array) [];
        $questions              = isset($question->questions)? (array) $question->questions : [];
        $question_content       = isset($question->content)? (object) $question->content : (object) [];
        $html                   = isset($question_content->html)? (string) $question_content->html : "empty";
        $rhtml                  = isset($question_content->html)? (string) $question_content->html : "empty";
        $question_options       = isset($question->options)? (array) $question->options : [];
        $explanations           = isset($question->explanations)? (array) $question->explanations : (array) [];

        $user_response          = $this->user_data;
        $user_answers_obj       = isset($user_response->answers)? (object) $user_response->answers : (object) [];
        $user_answers           = isset($user_answers_obj->questions)? (array) $user_answers_obj->questions : (array) [];


        $result_question            = $this->getObjectByKeyValue($user_answers,'qid',$question->_id);
        $result_question_classes    = isset($result_question->classes)? (array) $result_question->classes : [];
        $result_question_answers    = isset($result_question->answers)? (array) $result_question->answers : [];
        $result_question_visit      = isset($result_question->visit)? (int) $result_question->visit : 0;
        $result_question_visited    = isset($result_question->visited)? (int) $result_question->visited : 0;


        $my_points = 0;
        $my_negative_points = 0;
        $is_correct = 0;
        $is_wrong   = 0;
        $is_pcorrect = 0;
        $q_total_correct = 0;

        $return_html = "";

        $result_question_status     = 'unattempted';
        if(in_array('attempted', $result_question_classes) && in_array('bookmarked', $result_question_classes)){
            $result_question_status = 'attempted-bookmarked';
        } else if(in_array('attempted', $result_question_classes) && !in_array('bookmarked', $result_question_classes)) {
            $result_question_status = 'attempted';
        } else if(!in_array('attempted', $result_question_classes) && in_array('bookmarked', $result_question_classes)) {
            $result_question_status = 'unattempted-bookmarked';
        } else if(!in_array('attempted', $result_question_classes) && !in_array('bookmarked', $result_question_classes)){
            $result_question_status = 'unattempted';
        }

        



        $classes = [];
        if(self::$q_counter == 0){
            $classes[] = "current-question";
            $classes[] = "";
        }

        self::$questions_arr[self::$q_counter] = (object) [
            "qindex"    => self::$q_counter,
            "pid"       => $question->_postId,
            "qid"       => $question->_id,
            "pqi"       => self::$current_q_index,
            "classes"   => $classes,
            "visit"     => self::$q_counter == 0? 0 : 0,
            "time"      => 0,
            "question"  => (object) [
                "input_type"  => $input_type,
            ],
            "answers"   => (array) [],
            "visited"   => self::$q_counter == 0? true : false,
            "correct_points"    => $question_correct_points,
            "negative_points"   => $question_negative_points,
            "negative_type"     => $question_negative_type
        ];

        

        if($input_type == "radio" || $input_type == "checkbox"){
            ob_start(); ?>
            <div 
                class="que-ans-box slim-scrollbar <?php echo self::$q_counter == 0? '' : 'gov-hide'; ?>" 
                data-gov-result-question="<?php echo $question->_id; ?>" 
                data-gov-result-question-section="<?php echo $question->_postId; ?>"
                data-gov-result-question-input-type="<?php echo $input_type; ?>"
            >
                <div>
                    <b class="ng-hide">
                        <u>
                            <i>Question: <?php echo self::$current_q_index; ?></i>
                        </u>
                    </b>
                    <div class="qns-view-box"><?php echo $html; ?></div>
                    <?php if($input_type == "radio"){ ?>
                    <?php if(count($questions) == 1){ ?>
                        <ul class="q-multiple-choices">
                        <?php foreach( $questions as $qkey => $qus ){
                            $qus = (object) $qus;
                            $options = (array) $qus->options;
                            foreach( $options as $okey => $option ) {
                                $option             = (object) $option;
                                $oCorrect           = isset($option->correct)? $option->correct : false;
                                $is_user_checked    = '';
                                $input_classes      = '';
                                $user_classes       = '';

                                if($oCorrect){ $input_classes = 'option ng-scope stat-available correct-option correct-icon'; }

                                if($result_question_status == "attempted" || $result_question_status == "attempted-bookmarked"){
                                    if(in_array($oCorrect, $result_question_answers)){
                                        $is_user_checked = $result_question_answers[$okey];

                                        if( $is_user_checked ) {
                                            $user_classes = ' user-checked ';
                                            if($oCorrect){
                                                $user_classes .= ' user-correct ';
                                                $is_correct = true;
                                                $my_points += $question_correct_points;
                                            } else {
                                                $is_wrong   = true;
                                                $user_classes .= ' user-incorrect ';
                                                $input_classes = 'option ng-scope stat-available incorrect-option incorrect-icon';
                                                if($question_negative_type == "value"){
                                                    $my_negative_points += $question_negative_points;
                                                } else if($question_negative_type == "percentage"){
                                                    
                                                    $my_negative_points += floatval(($question_correct_points/$question_negative_points)*100);
                                                }
                                            }
                                        } else{
                                            $user_classes = ' user-unchecked ';
                                        }

                                        
                                    }
                                }


                                ?><li class="<?php echo $input_classes; ?> <?php echo $user_classes; ?>">
                                    <label for="qus-<?php echo $question->_id; ?>-<?php echo $okey; ?>">
                                        <input 
                                            data-gov-user="<?php echo $is_user_checked; ?>"
                                            data-gov-correct="<?php echo $oCorrect; ?>"
                                            type="<?php echo $input_type; ?>" 
                                            name="qus-<?php echo $question->_id; ?>" 
                                            id="qus-<?php echo $question->_id; ?>-<?php echo $okey; ?>" 
                                            value="<?php echo $okey; ?>"
                                            <?php echo ($is_user_checked)? 'checked' : ''; ?>
                                        />
                                        <div class="mar-l24 qns-view-box">
                                            <?php echo $option->content; ?>
                                        </div>
                                    </label>
                                </li><?php
                            }
                        } ?>
                        </ul>
                    <?php } ?>
                    <?php } ?>

                    <?php if($input_type == "checkbox"){ 
                        $is_checkbox_correct = true; ?>
                        <ul class="q-multiple-choices">
                        <?php if( count($question_options) > 0 ) {
                            foreach( $question_options as $okey => $option ) {
                                $option             = (object) $option;
                                $oCorrect           = isset($option->correct)? $option->correct : false;
                                $is_user_checked    = '';
                                $input_classes      = '';
                                $user_classes       = '';

                                if($oCorrect){ $input_classes = 'option ng-scope stat-available correct-option correct-icon'; $q_total_correct++; }

                                if($result_question_status == "attempted" || $result_question_status == "attempted-bookmarked"){
                                    if(in_array($oCorrect, $result_question_answers)){
                                        $is_user_checked = $result_question_answers[$okey];

                                        if( $is_user_checked ) {
                                            $user_classes = ' user-checked ';
                                            if($oCorrect){
                                                $user_classes .= ' user-correct ';
                                                
                                                $is_pcorrect++;
                                            } else {
                                                $is_checkbox_correct = false;
                                                $user_classes .= ' user-incorrect ';
                                                $input_classes = 'option ng-scope stat-available incorrect-option incorrect-icon';
                                            }
                                        } else{
                                            $user_classes = ' user-unchecked ';
                                        }

                                        
                                    }
                                }


                                ?><li class="<?php echo $input_classes; ?> <?php echo $user_classes; ?>">
                                    <label for="qus-<?php echo $question->_id; ?>-<?php echo $okey; ?>">
                                        <input 
                                            data-gov-user="<?php echo $is_user_checked; ?>"
                                            data-gov-correct="<?php echo $oCorrect; ?>"
                                            type="<?php echo $input_type; ?>" 
                                            name="qus-<?php echo $question->_id; ?>" 
                                            id="qus-<?php echo $question->_id; ?>-<?php echo $okey; ?>" 
                                            value="<?php echo $okey; ?>"
                                            <?php echo ($is_user_checked)? 'checked' : ''; ?>
                                        />
                                        <div class="mar-l24 qns-view-box">
                                            <?php echo $option->content; ?>
                                        </div>
                                    </label>
                                </li><?php
                            }
                        } ?>
                        </ul>
                        <?php 

                        if($result_question_status == "attempted" || $result_question_status == "attempted-bookmarked"){
                            if($is_checkbox_correct){
                                $is_correct = true;
                                $my_points += $question_correct_points;
                            } else {
                                $is_wrong = true;
                                if($question_negative_type == "value"){
                                    $my_negative_points += $question_negative_points;
                                } else if($question_negative_type == "percentage"){
                                    
                                    $my_negative_points += floatval(($question_correct_points/$question_negative_points)*100);
                                }
                            }
                        }
                
                    } ?>

                    <div class="mar-t24">
                        <!-- ngIf: reattemptEnabled -->
                        <div class="alert alert-warning max-width-300 ng-scope gov-hide">
                            <div class="font-weight-semibold text-gray-9 ng-scope" translate="">Re-attempt mode: ON</div>
                            <div class="text-gray-4 font-size-base-1 font-italic ng-scope" translate="">Now You can re-attempt the question</div>
                        </div>
                        <!-- end ngIf: reattemptEnabled -->
                        <div>
                            <button type="button" class="btn btn-sm btn-outline-theme mar-r4" data-gov-result-toggle-solution="true">
                                <i class="tb-icon tb-view-eye mar-r2"></i> 
                                <span class="font-size-small ng-scope ng-binding" translate="">View Solution</span>
                            </button> 
                            <span class="font-size-small text-gray-4 ng-scope" translate="">Click here to see the answer now</span>
                        </div>
                    </div>

                    <?php if(count($explanations) > 0){ ?>
                    <div ng-show="" class="solution-container mar-t24">
                        <div class="btn-group btn-underline-group btn-group--tab">
                            <div class="btn btn-underline-primary nav-spacing py-0 active" ng-click="" ng-class="">Solution</div>
                        </div>
                        <div ng-show="isSet(1)">
                            <div class="qns-view-box ng-binding" ng-bind-html="">
                                <?php 
                                    $exp = (object) $explanations[0];
                                    echo $exp->html; 
                                ?>
                            </div>
                        </div>
                    </div>
                    <?php } ?>

                    
                </div>
            </div>
            <?php $return_html = ob_get_clean();
        } else if($input_type == 'fillup'){
            $fill_correct = true;

            if(preg_match_all( '/\{([^{}]+)\}/', $html, $multiTextMatches)){
                // {}
                $matches        = $multiTextMatches[0];
                $inner_values   = $multiTextMatches[1];

                for($i = 0; $i < count($matches); $i++ ) {
                    $expression     = $matches[$i];
                    $inner_value    = $inner_values[$i];
                    $inner_arr      = (array) explode("|", $inner_value );
                    $q_total_correct++;

                    $user_input         = '';
                    $input_classes      = '';
                    $user_classes       = '';

                    if($result_question_status == "attempted" || $result_question_status == "attempted-bookmarked"){
                        $user_input = $result_question_answers[$i];

                        if(in_array($user_input, $inner_arr)){
                            $user_classes = 'input-correct';
                            $is_pcorrect++;

                        } else {
                            $user_classes = 'input-incorrect';
                            $fill_correct = false;
                        }
                    }


                    // Apply the same transformations to each element in the array
                    $inner_arr = array_map(function($value) {
                        return trim(strtolower($value));
                    }, $inner_arr);

                    // main select input
                    ob_start(); ?>
                    <input 
                        type="text" 
                        data-gov-fillup="<?php echo $i; ?>"
                        placeholder="<?php echo $i+1; ?>" 
                        class="gov-fillup_input <?php echo $user_classes; ?>" 
                        value="<?php echo $user_input; ?>"
                    />
                    <?php $input_fillup = ob_get_clean();
                    $html = $this->str_replace_first($expression,$input_fillup,$html);
                }
            }

            if($result_question_status == "attempted" || $result_question_status == "attempted-bookmarked"){
                if($fill_correct){
                    $is_correct = true;
                    $my_points += $question_correct_points;
                } else {
                    $is_wrong = true;
                    if($question_negative_type == "value"){
                        $my_negative_points += $question_negative_points;
                    } else if($question_negative_type == "percentage"){
                        $my_negative_points += floatval(($question_correct_points/$question_negative_points)*100);
                    }
                }
            }

            if(preg_match_all( '/\{([^{}]+)\}/', $rhtml, $multiTextMatches)){
                // {}
                $matches        = $multiTextMatches[0];
                $inner_values   = $multiTextMatches[1];

                for($i = 0; $i < count($matches); $i++ ) {
                    $expression     = $matches[$i];
                    $inner_value    = $inner_values[$i];
                    $inner_arr      = (array) explode("|", $inner_value );

                    // Apply the same transformations to each element in the array
                    $inner_arr = array_map(function($value) {
                        return trim(strtolower($value));
                    }, $inner_arr);

                    // main select input
                    ob_start(); ?>
                    <input 
                        type="text" 
                        data-gov-fillup="<?php echo $i; ?>"
                        placeholder="<?php echo $i+1; ?>" 
                        class="gov-fillup_input" 
                        value="<?php echo $inner_value; ?>"
                        readonly
                    />
                    <?php $input_fillup = ob_get_clean();
                    $rhtml = $this->str_replace_first($expression,$input_fillup,$rhtml);
                }
            }

            ob_start(); ?>
            <div 
                class="que-ans-box slim-scrollbar <?php echo self::$q_counter == 0? '' : 'gov-hide'; ?>" 
                data-gov-result-question="<?php echo $question->_id; ?>" 
                data-gov-result-question-section="<?php echo $question->_postId; ?>"
                data-gov-result-question-input-type="fillup"
            >
                <div>
                    <b class="ng-hide">
                        <u>
                            <i>Question: <?php echo self::$current_q_index; ?></i>
                        </u>
                    </b>
                    <div class="qns-view-box">
                        <?php 
                            echo $html; 
                        ?>
                    </div>
                    <div class="qns-view-box correct-box">
                        <?php 
                            echo $rhtml; 
                        ?>
                    </div>

                    <div class="mar-t24">
                        <!-- ngIf: reattemptEnabled -->
                        <div class="alert alert-warning max-width-300 ng-scope gov-hide">
                            <div class="font-weight-semibold text-gray-9 ng-scope" translate="">Re-attempt mode: ON</div>
                            <div class="text-gray-4 font-size-base-1 font-italic ng-scope" translate="">Now You can re-attempt the question</div>
                        </div>
                        <!-- end ngIf: reattemptEnabled -->
                        <div>
                            <button type="button" class="btn btn-sm btn-outline-theme mar-r4" data-gov-result-toggle-solution="true">
                                <i class="tb-icon tb-view-eye mar-r2"></i> 
                                <span class="font-size-small ng-scope ng-binding" translate="">View Solution</span>
                            </button> 
                            <span class="font-size-small text-gray-4 ng-scope" translate="">Click here to see the answer now</span>
                        </div>
                    </div>

                    <?php if(count($explanations) > 0){ ?>
                    <div ng-show="" class="solution-container mar-t24">
                        <div class="btn-group btn-underline-group btn-group--tab">
                            <div class="btn btn-underline-primary nav-spacing py-0 active" ng-click="" ng-class="">Solution</div>
                        </div>
                        <div ng-show="isSet(1)">
                            <div class="qns-view-box ng-binding" ng-bind-html="">
                                <?php 
                                    $exp = (object) $explanations[0];
                                    echo $exp->html; 
                                ?>
                            </div>
                        </div>
                    </div>
                    <?php } ?>

                </div>
            </div>
            <?php $return_html = ob_get_clean();
        }


        self::$questions_report[self::$q_counter] = (object) [
            "qindex"    => self::$q_counter,
            "pid"       => $question->_postId,
            "qid"       => $question->_id,
            "pqi"       => self::$current_q_index,
            "status"    => $result_question_status,
            "correct"   => $is_correct,
            "wrong"     => $is_wrong,
            "pcorrect"  => $is_pcorrect,
            "totalp"    => $q_total_correct,
            "points"    => $my_points,
            "negative"  => $my_negative_points,
            "time"      => $result_question_visit,
            "correct_points"    => $question_correct_points,
            "negative_points"   => $question_negative_points,
            "negative_type"     => $question_negative_type    

        ];

        return $return_html;

    }

    public function str_replace_first($search, $replace, $subject){
        $search = '/'.preg_quote($search, '/').'/';
        return preg_replace($search, $replace, $subject, 1);
    }

    public function login_notice() {
        if(!is_user_logged_in()) {
            global 
			$ST_OPTION_st_proqyz__auth_redirect_enable_key,
			$ST_OPTION_st_proqyz__auth_signup_url_key,
			$ST_OPTION_st_proqyz__auth_signin_url_key;



            $redirect_url           = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
            
            $enable_auth_redirect   = get_option($ST_OPTION_st_proqyz__auth_redirect_enable_key,0);
            $auth_signin_url        = get_option($ST_OPTION_st_proqyz__auth_signin_url_key,"/wp-login.php");
            $auth_signup_url        = get_option($ST_OPTION_st_proqyz__auth_signup_url_key,"/wp-login.php");
            $url                    = $auth_signin_url;
            $url                    .= $enable_auth_redirect == 1? '?redirect_to='.$redirect_url : '';
            

            ob_start(); ?>
            <div class="modal-body">
                <div class="test-notice modal-test-notice"> 
                    Please login to take the test. Click 
                    <a class="test-notice__link" href="<?php echo $url; ?>">Here</a> 
                    or the button below to login now. 
                    
                </div>
            </div>
            <div class="modal-footer">
                <a href="<?php echo $url; ?>" class="btn btn-theme">
                    Log in
                </a>
            </div>
            <?php return ob_get_clean();
        }
    }

    public function modals(){ 
        ob_start(); ?>
        <div id="login-modal" class="bootbox modal fade bootbox-confirm" tabindex="-1" role="dialog" style="display: none;" data-backdrop="static" data-keyboard="false">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header x-timesup gov-hide">
                        <div class="alert alert-warning d-flex align-items-center" role="alert">
                            <i class="tb-icon tb-sad font-size-medium text-warning mar-b4"></i> &nbsp;
                            <div>
                                Alert
                            </div>
                        </div>
                    </div>
                    <?php echo $this->login_notice(); ?>
                </div>
            </div>

        </div>


        <div id="drag-calculator" style="height: 447px;width: 447px;z-index:9999;" class="gov-hide">

                <div id="drag-calculator-btn" class="test-calculator-header">
                    <button data-gov-calculator-btn="close" type="button" class="btn btn-sm text-white pull-right">X</button> 
                    <!--button type="button" class="btn btn-sm text-white pull-right icon-min" id="calc-min-max">
                        <span class="ico-min">_</span>
                        <span class="ico-max">🗖</span>
                    </button--> 
                    <span class="d-inline-block mar-4 text-white ng-binding">Scientific Calculator</span>
                </div>
                <div class="overflow-hidden" style="height: 447px; width: 447px;" id="box-calculator-min-max">
                    <iframe src="<?php echo plugin_dir_url(ST_PROQYZ_PLUGIN_FILE) . '/includes/libs/lms/gov/calculator'; ?>" frameborder="0" style="width:500px;height:312px;background-color:#f9f9f9;position: relative;left:-15px;top:-10px;">
                    </iframe>
                </div>

            </div>



        <!--last question modal--> 
        <div id="last-question-modal" class="bootbox modal fade bootbox-confirm" tabindex="-1" role="dialog" style="display: none;" data-backdrop="static" data-keyboard="false">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-body">
                        <button type="button" class="bootbox-close-button close" data-dismiss="modal" aria-hidden="true" style="margin-top: -10px;">×</button>
                        <div class="bootbox-body">
                            You have reached the last question of the exam. Do you want to go to the first question ?
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button data-dismiss="modal" data-bb-handler="cancel" type="button" class="btn tb-btn-secondary outline-none">No</button>
                        <button data-gov-modal-control="confirm" type="button" class="btn btn-primary outline-none">Yes</button>
                    </div>
                </div>
            </div>
        </div>
        <!--end::last question modal--> 
        <div id="modal-error" class="bootbox modal fade bootbox-confirm" tabindex="-1" role="dialog" style="display: none;" data-backdrop="static" data-keyboard="false">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-body">
                        <button type="button" class="bootbox-close-button close" data-dismiss="modal" aria-hidden="true" style="margin-top: -10px;">×</button>
                        <div class="bootbox-body">
                            
                        </div>
                        <div class="bootbox-summary">
                            <div class="table-responsive">
                                <table class="table table-bordered">
                                    <thead>
                                        <tr>
                                            <th translate="" class="ng-scope">Section</th>
                                            <th translate="" class="ng-scope">No. of questions</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                    <?php if(count($this->sections) > 0){ ?>
                                        <?php foreach( $this->sections as $sskey => $ssection ) { 
                                            $ssection = (object) $ssection;
                                            ?>
                                            <tr class="ng-scope" data-gov-section-table="<?php echo $ssection->_id; ?>">
                                                <td data-prompt="Section" class="ng-binding"><?php echo $ssection->title; ?></td>
                                                <td data-prompt="No. of questions" class="ng-binding label-total">0</td>
                                            </tr>
                                        <?php } ?>
                                    <?php } ?>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-danger outline-none">Yes</button>
                    </div>
                </div>
            </div>
        </div>
        <!--modal submit test--> 
        <div id="submit-test-modal" class="bootbox modal fade bootbox-confirm" tabindex="-1" role="dialog" style="display: none;" data-backdrop="static" data-keyboard="false">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header x-timesup gov-hide">
                        <div class="alert alert-warning d-flex align-items-center" role="alert">
                            <i class="tb-icon tb-sad font-size-medium text-warning mar-b4"></i> &nbsp;
                            <div>
                                Timesup, Please submit test for Review
                            </div>
                        </div>
                    </div>
                    <div class="modal-body">
                        <button type="button" class="bootbox-close-button close x-close-btn" data-dismiss="modal" aria-hidden="true" style="margin-top: -10px;">×</button>
                        <div class="bootbox-body">
                            Submit Test & Review Result
                        </div>
                        <div class="bootbox-summary">
                            <div class="table-responsive">
                                <table class="table table-bordered">
                                    <thead>
                                        <tr>
                                            <th translate="" class="ng-scope">Section</th>
                                            <th translate="" class="ng-scope">No. of questions</th>
                                            <th translate="" class="ng-scope">Answered</th>
                                            <th translate="" class="ng-scope">Not Answered</th>
                                            <th translate="" class="ng-scope">Marked for Review</th>
                                            <th translate="" class="ng-scope">Not Visited</th>
                                            <!-- ngIf: hasSkipOptionSupport -->
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php if(count($this->sections) > 0){ ?>
                                        <?php foreach( $this->sections as $sskey => $ssection ) { 
                                            $ssection = (object) $ssection;
                                            ?>
                                            <tr class="ng-scope" data-gov-section-table="<?php echo $ssection->_id; ?>">
                                                <td data-prompt="Section" class="ng-binding"><?php echo $ssection->title; ?></td>
                                                <td data-prompt="No. of questions" class="ng-binding label-total">0</td>
                                                <td data-prompt="Answered" class="ng-binding label-attempted">0</td>
                                                <td data-prompt="Not Answered" class="ng-binding label-unattempted">0</td>
                                                <td data-prompt="Marked for Review" class="ng-binding label-bookmarked">0</td>
                                                <td data-prompt="Not Visited" class="ng-binding label-skipped">0</td>
                                            </tr>
                                        <?php } ?>
                                        <?php } ?>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-theme mar-t0 ng-hide x-close-btn" data-dismiss="modal">Close</button>
                        <button data-gov-modal-control="finish-quiz" type="button" class="btn btn-primary outline-none">
                            Submit Test
                        </button>
                    </div>
                </div>
            </div>

        </div>

        <!--modal last question for section--> 
        <div id="last-section-question-modal" class="bootbox modal fade bootbox-alert" tabindex="-1" role="dialog" style="display: none;" data-backdrop="static" data-keyboard="false">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-body">
                        <button type="button" class="bootbox-close-button close" data-dismiss="modal" aria-hidden="true" style="margin-top: -10px;">×</button>
                        <div class="bootbox-body">
                            You have reached the last question of this section. Please wait till the time allotted for this section is over or submit the test
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button data-dismiss="modal" type="button" class="btn btn-primary  outline-none">Ok</button>
                    </div>
                </div>
            </div
        ></div>

        <div id="result-last-question-modal" class="bootbox modal fade bootbox-confirm" tabindex="-1" role="dialog" style="display: none;" data-backdrop="static" data-keyboard="false">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-body">
                        <button type="button" class="bootbox-close-button close" data-dismiss="modal" aria-hidden="true" style="margin-top: -10px;">×</button>
                        <div class="bootbox-body">
                            You have reached the last question of the exam. Do you want to go to the first question ?
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button data-dismiss="modal" data-bb-handler="cancel" type="button" class="btn tb-btn-secondary outline-none">No</button>
                        <button data-gov-modal-control="confirm" type="button" class="btn btn-primary outline-none">Yes</button>
                    </div>
                </div>
            </div>
        </div>

        <div id="modal-auth" class="bootbox modal fade bootbox-confirm" tabindex="-1" role="dialog" style="display: none;" data-backdrop="static" data-keyboard="false">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-body">
                        <button type="button" class="bootbox-close-button close" data-dismiss="modal" aria-hidden="true" style="margin-top: -10px;">×</button>
                        <div class="bootbox-body">
                            You need to login
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-danger outline-none">Yes</button>
                    </div>
                </div>
            </div>
        </div>                                    


        <?php return ob_get_clean();
    }

    public function seconds_to_hms( $seconds ) {
        // Format the seconds into an H:i:s string
        $formatted_time = gmdate('H:i:s', $seconds);
    
        // If the formatted time starts with "00:", remove it
        if (strpos($formatted_time, '00:') === 0) {
            $formatted_time = substr($formatted_time, 3);
        }
    
        return $formatted_time;
    }

    public function instructions(){
        $instructions = isset($this->quiz->instructions)? (object) $this->quiz->instructions : (object) [
            "html" => "List of Dynamic instructions"
        ];
        $instructions_html = isset($instructions->html)? $instructions->html : "List of Dynamic instructions";
        ob_start(); ?>
        <div class="container-fluid u-mob-sidebar test-instructions test-instructions-assets slim-scrollbar">
            <div class="row">
                <div class="col-xs-12 c-test-instructions basic-instructions" id="bank-instructions">
                    <h4>General Instructions:</h4>
                    <ol start="1"><li><p>The clock will be set at the server. The countdown timer at the top right corner of screen will display the remaining time available for you to complete the examination. When the timer reaches zero, the examination will end by itself. You need not terminate the examination or submit your paper.</p></li><li><p>The Question Palette displayed on the right side of screen will show the status of each question using one of the following symbols:</p><ul class="que-ans-states hide-on-railway"><li><span class="label"></span> You have not visited the question yet.</li><li><span class="label skipped"></span> You have not answered the question.</li><li><span class="label attempted"></span> You have answered the question.</li><li><span class="label bookmarked"></span> You have NOT answered the question, but have marked the question for review.</li><li><span class="label attempted bookmarked"></span> You have answered the question, but marked it for review.</li><!-- ngIf: hasSkipOptionSupport --></ul><ul class="railway-instructions-legend show-on-railway"><li><span class="new-legend not-answered"></span> You have not answered the question.</li><li><span class="new-legend answered"></span> You have answered the question.</li><li><span class="new-legend reviewed"></span> You have NOT answered the question, but have marked the question for review.</li><li><span class="new-legend reviewed-answered"></span> You answered the question also marked the question for review.</li><!-- ngIf: hasSkipOptionSupport --></ul></li></ol><p>The <b>Mark For Review</b> status for a question simply indicates that you would like to look at that question again. If a question is answered, but marked for review, then the answer will be considered for evaluation unless the status is modified by the candidate.</p><b>Navigating to a Question :</b><ol start="3"><li><p>To answer a question, do the following:</p><ol><li>Click on the question number in the Question Palette at the right of your screen to go to that numbered question directly. Note that using this option does NOT save your answer to the current question.</li><li>Click on <b>Save &amp; Next</b> to save your answer for the current question and then go to the next question.</li><li>Click on <b>Mark for Review <span class="hide-on-railway">&amp; Next</span></b> to save your answer for the current question and also mark it for review <span class="hide-on-railway">, and then go to the next question.</span></li></ol></li></ol><p>Note that your answer for the current question will not be saved, if you navigate to another question directly by clicking on a question number <span>without saving</span> the answer to the previous question.</p><p>You can view all the questions by clicking on the <b>Question Paper</b> button. <span style="color:#ff0000">This feature is provided, so that if you want you can just see the entire question paper at a glance.</span></p><h4>Answering a Question :</h4><ol start="4"><li><p>Procedure for answering a multiple choice (MCQ) type question:</p><ol><li>Choose one answer from the 4 options (A,B,C,D) given below the question<span class="hide-on-railway">, click on the bubble placed before the chosen option.</span></li><li class="hide-on-railway">To deselect your chosen answer, click on the bubble of the chosen option again or click on the <b><span class="hide-on-railway">Clear Response</span> <span class="show-on-railway">Erase Answer</span></b> button</li><li>To change your chosen answer, click on the bubble of another option.</li><li>To save your answer, you MUST click on the <b>Save &amp; Next</b></li></ol></li><li><p>Procedure for answering a numerical answer type question :</p><ol><li>To enter a number as your answer, use the virtual numerical keypad.</li><li>A fraction (e.g. -0.3 or -.3) can be entered as an answer with or without "0" before the decimal point. <span style="color: red">As many as four decimal points, e.g. 12.5435 or 0.003 or -932.6711 or 12.82 can be entered.</span></li><li>To clear your answer, click on the <b>Clear Response</b> button</li><li>To save your answer, you MUST click on the <b>Save &amp; Next</b></li></ol></li><li ng-show="isJeeTestInterfaceUsed" class="ng-hide"><p>Procedure for answering a multiple correct answers (MCAQ) type question</p><ol><li>Choose one or more answers from the 4 options (A,B,C,D) given below the question, click on the bubble placed before the chosen option.</li><li>To deselect your chosen answer, click on the checkbox of the chosen option again</li><li>To clear your marked responses, click on the <b>Clear Response</b> button</li><li>To save your answer, you MUST click on the <b>Save &amp; Next</b> button</li></ol></li><li><p>To mark a question for review, click on the <b>Mark for Review <span class="hide-on-railway">&amp; Next</span></b> button. If an answer is selected (for MCQ/MCAQ) entered (for numerical answer type) for a question that is <b>Marked for Review</b> , that answer will be considered in the evaluation unless the status is modified by the candidate.</p></li><li><p>To change your answer to a question that has already been answered, first select that question for answering and then follow the procedure for answering that type of question.</p></li><li><p>Note that ONLY Questions for which answers are <b>saved</b> or <b>marked for review after answering</b> will be considered for evaluation.</p></li><li><p>Sections in this question paper are displayed on the top bar of the screen. Questions in a Section can be viewed by clicking on the name of that Section. The Section you are currently viewing will be highlighted.</p></li><li><p>After clicking the <b>Save &amp; Next</b> button for the last question in a Section, you will automatically be taken to the first question of the next Section in sequence.</p></li><li><p>You can move the mouse cursor over the name of a Section to view the answering status for that Section.</p></li></ol>
                </div>

                <div class="col-xs-12 dynamic-instructions gov-hide">
                    <div class="row">
                        <div class="col-xs-12 col-sm-12 di-heading">
                            <h2 class="text-center">
                                <?php echo $this->quiz->title; ?>
                            </h2>
                        </div>
                        <div class="col-xs-12 col-sm-6">
                            <b class="duration-text">Duration: 10 min</b>
                        </div>
                        <div class="col-xs-12 col-sm-6">
                            <b class="pull-right">
                                Maximun Marks: 50
                            </b>
                        </div>
                    </div>
                </div>

                <div class="col-xs-12 col-sm-12 di-content gov-hide">
                    <div class="instructions__dynamic">
                        <?php echo $instructions_html; ?>
                    </div>

                    <div class="ng-scope">
                        <div class="js-dummy-height-creater" style="height: 230px;"></div>
                        <div class="test-start-acceptance js-test-start-acceptance">
                            
                            <!-- end ngIf: !isUISSCCGL() -->
                            <p>
                                <b class="">Declaration:</b>
                            </p>
                            <label fpr="i-agree-checkbox" class="test-instructions-declaration ">
                                <input type="checkbox" id="i-agree-checkbox" name="instructions" class="i-agree-checkbox ng-pristine ng-untouched ng-valid ng-empty" /> 
                                I have read all the instructions carefully and have understood them. I agree not to cheat or use unfair means in this examination. I understand that using unfair means of any sort for my own or someone else’s advantage will lead to my immediate disqualification.
                                <span class=" ng-scope">
                                    The decision of Exams will be final in these matters and cannot be appealed.
                                </span>
                            </label>
                        </div>
                    </div>

                </div>

                <div class="ti-control text-center for-all-exams">
                    <button class="btn btn-info-test pull-left instructions__btn instructions__btn-previous gov-hide" type="button">
                        Previous
                    </button>
                    <button class="btn btn-theme hover-accept-tooltip instructions__btn instructions__btn-i-agree gov-hide" id="i-agree-btn" type="button" disabled>
                        I am ready to begin
                    </button>
                    <div class="tb-tooltip top" id="accept-tooltip" style="display:none;">
                        <div class="po-content">Please accept terms and condition before proceeding</div>
                    </div>
                    <button class="btn btn-info-test pull-right instructions__btn instructions__btn-next" type="button">
                        Next
                    </button>
                </div>
                    
                    
            </div>
        </div>            
        <?php return ob_get_clean();
    }

    // result analysis
    public function result_analysis_report_header($params = []){
        $params = (object) $params;
        $total_test_marks = $params->total_test_marks;
        $total_user_marks = $params->total_user_marks;
        $total_questions  = $params->total_questions;
        $total_attempted  = $params->total_attempted;


        ob_start(); ?>
        <div class="tb-card tb-card--main-content ng-scope" ng-if="">
        <div class="tb-card__body analysis-summary">
            <!-- ngIf: !hideRank -->
            <div ng-if="" class="analysis-summary__container analysis-summary--rank ng-scope">
                <div class="analysis-summary__icon">
                    <svg width="12px" height="19px" viewBox="0 0 12 19">
                    <g id="Analytics" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
                        <g id="Analytics---Main-Page" transform="translate(-273 -181)" stroke="#FFF">
                            <g id="Quick" transform="translate(232 89)">
                                <g id="Group" transform="translate(26 80)">
                                <g id="Group-13" transform="translate(15 12)">
                                    <path id="Stroke-1" d="M5.89 7.638l1.551 4.035h3.724l-3.104 2.793.932 4.034-3.104-2.793L2.475 18.5l.931-4.034-3.103-2.793h3.724z"></path>
                                    <path d="M4.027.5v5.478" id="Stroke-3"></path>
                                    <path d="M7.751.5v5.478" id="Stroke-5"></path>
                                    <path d="M5.89.5v5.478" id="Stroke-7"></path>
                                    <path id="Stroke-9" d="M5.89.5H.922v1.862l2.173 7.449"></path>
                                    <path id="Stroke-11" d="M5.781.5h5.073v1.862L8.372 9.811"></path>
                                </g>
                                </g>
                            </g>
                        </g>
                    </g>
                    </svg>
                </div>
                <div class="analysis-summary__content">
                    <h4 class="ng-binding">
                        0 <span class="help-label ng-binding"> / 0</span>
                    </h4>
                    <div class="help-text">Rank</div>
                </div>
            </div>
            <!-- end ngIf: !hideRank -->
            <!-- ngIf: isTScoreVisible && isASM -->
            <div class="analysis-summary__container analysis-summary--score">
                <div class="analysis-summary__icon analysis-summary--score">
                    <svg width="22px" height="19px" viewBox="0 0 22 19">
                    <g id="Analytics" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
                        <g id="Analytics---Main-Page" transform="translate(-655 -181)" stroke="#FFF">
                            <g id="Quick" transform="translate(232 89)">
                                <g id="Group-Copy" transform="translate(413 80)">
                                <g id="Group-7" transform="translate(10 12)">
                                    <path d="M5.071 8.259c-3.913 0-4.57-5.113-4.57-6.518h2.984" id="Stroke-1"></path>
                                    <path d="M16.91 8.259c3.913 0 4.59-5.437 4.59-6.518h-2.975" id="Stroke-3"></path>
                                    <path d="M18.549.5H3.462c0 12.079 6.233 8.651 6.233 12.913-.048 2.739-1.068 3.535-3.23 3.535V18.5h9.07v-1.552c-1.851 0-3.274-.796-3.274-3.535 0-4.267 6.288-.884 6.288-12.913z" id="Stroke-5"></path>
                                </g>
                                </g>
                            </g>
                        </g>
                    </g>
                    </svg>
                </div>
                <div class="analysis-summary__content">
                    <h4 class="ng-binding">
                        <?php echo $total_user_marks; ?><span class="help-label ng-binding"> / <?php echo $total_test_marks; ?></span>
                    </h4>
                    <div class="help-text">Score</div>
                </div>
            </div>
            <div class="analysis-summary__container analysis-summary--attempted">
                <div class="analysis-summary__icon">
                    <svg width="16px" height="20px" viewBox="0 0 16 20">
                    <g id="Analytics" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
                        <g id="Analytics---Main-Page" transform="translate(-1040 -180)" stroke="#FFF">
                            <g id="Quick" transform="translate(232 89)">
                                <g id="Group-Copy-4" transform="translate(794 80)">
                                <g id="Group-10" transform="translate(14 12)">
                                    <path id="Stroke-1" d="M2.982 18.5h9.311V5.465H2.982z"></path>
                                    <path d="M2.983 12.914H.5V2.983C.5 1.686 1.55.5 2.848.5s2.307 1.186 2.307 2.483c0 1.297-.875 2.483-2.172 2.483V3.604h2.1" id="Stroke-3"></path>
                                    <path d="M12.293 5.465c1.297 0 2.483-1.186 2.483-2.482C14.776 1.684 13.59.5 12.293.5h-9.31" id="Stroke-4"></path>
                                    <path d="M7.638 8.569h3.104" id="Stroke-5"></path>
                                    <path d="M7.638 11.672h3.104" id="Stroke-6"></path>
                                    <path d="M7.638 14.776h3.104" id="Stroke-7"></path>
                                    <path id="Stroke-8" d="M4.534 7.948l.311.31 1.551-1.552"></path>
                                    <path id="Stroke-9" d="M4.534 11.052l.311.31L6.396 9.81"></path>
                                </g>
                                </g>
                            </g>
                        </g>
                    </g>
                    </svg>
                </div>
                <div class="analysis-summary__content">
                    <!-- ngIf: !optionalQuesPresent -->
                    <h4 ng-if="!optionalQuesPresent" class="ng-binding ng-scope">
                    <?php echo $total_attempted; ?><span class="help-label ng-binding"> / <?php echo $total_questions; ?></span>
                    </h4>
                    <!-- end ngIf: !optionalQuesPresent -->
                    <!-- ngIf: optionalQuesPresent -->
                    <div class="help-text">Attempted</div>
                </div>
            </div>
            <!-- <div class="analysis-summary__container analysis-summary--accuracy">
                <div class="analysis-summary__icon">
                    <svg width="20px" height="19px" viewBox="0 0 20 19">
                    <g id="Analytics" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
                        <g id="Analytics---Main-Page" transform="translate(-469 -180)">
                            <g id="Quick" transform="translate(232 89)">
                                <g id="Group-Copy-3" transform="translate(225.5 80)">
                                <g id="Group-17" transform="translate(12 11)">
                                    <path d="M7.181 11.863l9.311-9.311" id="Stroke-1" stroke="#FFF"></path>
                                    <g id="Group-16" transform="translate(0 .044)">
                                        <path d="M16.492 2.508h1.862s-2.145 6.544-5.276 3.414C9.948 2.792 16.492.646 16.492.646v1.862z" id="Stroke-2" stroke="#FFF"></path>
                                        <path d="M14.63 4.37V1.468" id="Stroke-4" stroke="#FFF"></path>
                                        <path d="M.353 18.646l2-2" id="Stroke-6" stroke="#FFF"></path>
                                        <path d="M12.009 16.647l2 2" id="Stroke-8" stroke="#FFF"></path>
                                        <path d="M7.181 4.991a6.828 6.828 0 1 0 0 13.656 6.828 6.828 0 0 0 0-13.656m0 1a5.835 5.835 0 0 1 5.828 5.828 5.834 5.834 0 0 1-5.828 5.827 5.834 5.834 0 0 1-5.828-5.827 5.835 5.835 0 0 1 5.828-5.828" id="Fill-10" fill="#FFF"></path>
                                        <path d="M10.556 11.819a3.375 3.375 0 1 1-6.75 0 3.375 3.375 0 0 1 6.75 0z" id="Stroke-12" stroke="#FFF"></path>
                                        <path d="M7.492 11.819a.311.311 0 1 1 0 0z" id="Stroke-14" stroke="#FFF"></path>
                                    </g>
                                </g>
                                </g>
                            </g>
                        </g>
                    </g>
                    </svg>
                </div>
                <div class="analysis-summary__content">
                    <h4 class="ng-binding">
                    0<span class="help-label">%</span>
                    </h4>
                    <div class="help-text">Accuracy</div>
                </div>
            </div> -->
            <div class="analysis-summary__container analysis-summary--percentile">
                <div class="analysis-summary__icon">
                    <svg width="20px" height="20px" viewBox="0 0 20 20">
                    <g id="Analytics" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
                        <g id="Analytics---Main-Page" transform="translate(-847 -180)" stroke="#FFF">
                            <g id="Quick" transform="translate(232 89)">
                                <g id="Group-Copy-2" transform="translate(603.5 80)">
                                <g id="Group-29" transform="translate(12 12)">
                                    <path d="M3.342 5.408V6.5l-2.077.55C.845 7.17.5 7.627.5 8.065v.33h4.696" id="Stroke-1"></path>
                                    <path d="M5.553 5.436V6.5l2.145.55c.42.12.697.591.697 1.03v.315H4.4" id="Stroke-3"></path>
                                    <path d="M6.87 3.105c0 1.438-1.07 2.605-2.388 2.605-1.32 0-2.39-1.167-2.39-2.605S3.163.5 4.483.5C5.8.5 6.87 1.667 6.87 3.105z" id="Stroke-5"></path>
                                    <path d="M6.846 2.649c-.398.398-1.537.379-1.966-.42-.796.796-2.091.796-2.734.34" id="Stroke-7"></path>
                                    <path d="M13.447 5.402V6.5l-2.077.55c-.42.12-.765.578-.765 1.016v.329h4.696" id="Stroke-9"></path>
                                    <path d="M15.658 5.433V6.5l2.145.55c.42.12.697.59.697 1.029v.316h-3.995" id="Stroke-11"></path>
                                    <path d="M16.976 3.105c0 1.438-1.07 2.605-2.389 2.605-1.32 0-2.389-1.167-2.389-2.605S13.267.5 14.587.5c1.319 0 2.389 1.167 2.389 2.605z" id="Stroke-13"></path>
                                    <path d="M16.951 2.649c-.398.398-1.537.379-1.966-.42-.796.796-2.09.796-2.735.34" id="Stroke-15"></path>
                                    <path d="M8.147 15.398v1.111l-2.022.577c-.42.121-.765.578-.765 1.016v.398h4.38" id="Stroke-17"></path>
                                    <path d="M10.537 15.398v1.11l2.02.579c.423.12.767.577.767 1.015v.398h-4.38" id="Stroke-19"></path>
                                    <path d="M11.731 13.142c0 1.438-1.07 2.604-2.389 2.604-1.32 0-2.389-1.167-2.389-2.604 0-1.438 1.07-2.605 2.39-2.605 1.318 0 2.388 1.166 2.388 2.604z" id="Stroke-21"></path>
                                    <path d="M11.694 12.663c-.398.398-1.524.401-1.954-.398-.796.796-2.09.796-2.734.342" id="Stroke-23"></path>
                                    <path d="M2.972 9.74l1.99 1.991" id="Stroke-25"></path>
                                    <path d="M15.713 9.74l-1.991 1.991" id="Stroke-27"></path>
                                </g>
                                </g>
                            </g>
                        </g>
                    </g>
                    </svg>
                </div>
                <div class="analysis-summary__content">
                    <h4 class="ng-binding">
                    0<span class="help-label">%</span>
                    </h4>
                    <div class="help-text">Percentile</div>
                </div>
            </div>
        </div>
        </div>
        <?php return ob_get_clean();
    }

    public function set_user_data( $user_data = [], $resume = false, $result = false ) {
        $this->user_response = (object) $user_data;
        $this->is_resume = $resume;
        $this->is_result = $result;
    }

    public function get_report(){
        return (object) [
            "types"         => (array) self::$question_types,
            "total"         => self::$q_counter,
            "correct"       => self::$total_correct,
            "wrong"         => self::$total_wrong,
            "attempt"       => self::$total_attempt,
            "unattempt"     => self::$total_unattempt
        ];
    }

    function getObjectByKeyValue($array, $key, $value) {
        foreach ($array as $object) {
            $object = (object) $object;
            if (isset($object->$key) && $object->$key === $value) {
                return $object;
            }
        }
        return null; // If no object with the given key-value pair is found
    }

    function formatTime($seconds) {
        $hours = floor($seconds / 3600);
        $minutes = floor(($seconds % 3600) / 60);
        $remainingSeconds = $seconds % 60;
        
        $formattedTime = '';
        
        if ($hours > 0) {
            $formattedTime .= str_pad($hours, 2, '0', STR_PAD_LEFT) . ':';
        }
        
        if ($hours > 0 || $minutes > 0) {
            $formattedTime .= str_pad($minutes, 2, '0', STR_PAD_LEFT) . ':';
        } else {
            $formattedTime .= '00:';
        }
        
        $formattedTime .= str_pad($remainingSeconds, 2, '0', STR_PAD_LEFT);
        
        return $formattedTime;
    }


}