<?php 
/**
 * v3.1.0
 * Class Speaking
 * status: completed
 */


class Speaking {
    public $post_id                 = null;
    public $student_id              = null;
    public $quiz                    = [];
    public $category                = '';
    public $_id                     = '';
    public $result_id               = '';
    public $review_id               = null;
    public $sections                = [];
    public $questions               = [];
    public $seconds                 = 60;
    public $default                 = 3600;
    public $resume                  = false;
    public $result                  = false;
    public $review                  = false;
    public $solution                = false;
    public $session                 = [];
    public $user_data               = null;
    public $student_info            = null;
    public $_q                      = [];
    public $course_info             = null;
    public $ai_audio_sections       = [];

    public static $sections_html    = '';
    public static $questions_html   = '';
    public static $pallete          = '';
    public static $current_p_index  = 0;
    public static $p_counter        = 0;
    public static $review_boxes     = '';
    public static $rq_c             = 0;
    public $ielts_url               = '/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist';
    public $dist_url                    = '/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist';
    public static $json_obj         = []; 
    public static $reviews          = [];
    public $reviewed                = false;
    public $show_ai_evaluation_if_available = false;


    # evaluation status
    public $PROQYZ_EVALUATION = false; // overall - course - plan
    public $INSTRUCTOR_PROQYZ_EVALUATION   = false; // evaluation setting - wp-admin
    public $AI_PROQYZ_EVALUATION_AVAILABLE = false; // evaluation setting - ai - wp-admin

    # ai speaking evaluation
    public $AI_task_plan            = false;
    public $AI_task_plan_details    = null;

    # instructor speaking evaluation
    public $instructor_task_plan    = false;
    public $instructor_task_plan_details = null;

    # enrolled for
    public $is_enrolled             = true;
    public $enrolled_for            = 'default'; // instructor | ai | free | course-free
    public $enrolled_reason         = 'default';

    # layout shifts
    public $full_width              = false;

    # current user role
    public $current_user_role       = '';


    public $S_Pronunciation_lines = array(
        1 => "No communication possible",
        2 => "Speech is often unintelligible",
        3 => "Rarely uses clear  pronunciation features",
        4 => "Uses a very limited range of pronunciation features ",
        5 => "Uses a limited range of pronunciation features",
        6 => "Uses a range of pronunciation features with mixed control",
        7 => "Uses a range of pronunciation features with some control",
        8 => "Uses a wide range of pronunciation features",
        9 => "Uses a full range of pronunciation features with precision"
    );
    
    public $S_Grammatical_lines = array(
        1 => "No communication possible",
        2 => "Cannot produce basic sentence forms",
        3 => "Makes numerous errors",
        4 => "Produces basic sentence forms; errors are frequent",
        5 => "Produces basic sentence forms with reasonable accuracy",
        6 => "Uses a mix of simple and complex structures, limited flexibility",
        7 => "Uses a range of complex structures with some flexibility",
        8 => "Uses a wide range of structures flexibly ",
        9 => "Uses a full range of structures naturally and appropriately "
    );
    
    public $S_Lexical_lines = array(
        1 => "No communication possible",
        2 => "Only produces isolated words",
        3 => "Uses simple vocabulary; insufficient vocabulary",
        4 => "Can only convey basic meaning on unfamiliar topics",
        5 => "Manages to talk about familiar topics with limited flexibility",
        6 => "Has a wide enough vocabulary to discuss topics in spite of inappropriacies",
        7 => "Uses vocabulary resources flexibly",
        8 => "Uses a wide vocabulary resource readily and flexibly",
        9 => "Uses vocabulary with full flexibility and precision in all topics"
    );
    
    public $S_Fluency_lines = array(
        1 => "No communication possible",
        2 => "Little communication possible",
        3 => "Speaks with long pauses; simple responses",
        4 => "Cannot respond without noticeable pauses and may speak slowly",
        5 => "Usually maintains flow of speech but uses repetition to keep going",
        6 => "Is willing to speak at length, though may lose coherence at times",
        7 => "Speaks at length; may demonstrate language-related hesitation at times",
        8 => "Speaks almost fluently with only occasional errors",
        9 => "Speaks fluently; develops topics fully and appropriately"
    );


    public function __construct($params = []) {
        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 : '';

            wp_safe_redirect($url);
        }

        $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) [];
        $this->course       = isset($params->course) ? (object) $params->course : null;
        $this->student_id   = isset($params->student_id)? (int) $params->student_id : null;
        $time               = isset($this->quiz->time)? (object) $this->quiz->time : null;
        $this->resume       = isset($params->resume) ? (bool) $params->resume : false;
        $this->result       = isset($params->result) ? (bool) $params->result : false;
        $this->review       = isset($params->review) ? (bool) $params->review : false;
        $this->solution     = isset($params->solution) ? (bool) $params->solution : false;
        $this->post_id      = isset($params->post_id) ? $params->post_id : null;
        $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) [];  

        $wp_user = get_userdata( get_current_user_id() );
        if( $wp_user ){
            $this->current_user_role = $this->normalize_user_role( $wp_user->roles );
        }

        if(defined('ST_PROQYZ_SPEAKING_AI_EVALUAION') && ST_PROQYZ_SPEAKING_AI_EVALUAION == 'true'){
            $this->show_ai_evaluation_if_available = true;
        }

        
        if($this->result || $this->review){
            $this->__quiz_result_constructor();
        } else {
            $this->__quiz_attempt_constructor();
        }

    } 
    
    /**
     * quiz attempt - constructor
     */
    public function __quiz_attempt_constructor(){
        if( count($this->sections) > 0 && count($this->questions) ) {
            $quiz_sections = $this->sections;
            $quiz_questions = $this->questions;
            $section_questions = [];
            $parts = [];

            foreach ($quiz_sections as $section_index => $section) {
                $section = (array) $section;
                $section_questions = [];
                $section_data = [
                    "_id"      => $section["_id"],
                    "title"    => $section["title"],
                    "time"     => 0, // Initialize sectionTime
                    "status"   => $section["status"],
                    "content"  => $section["content"],
                    "questions"=> $section_questions
                ];

                if (isset($section["time"]["sectionTime"]) && isset($section["time"]["sectionTime"]["timer"])) {
                    $section_data["time"] = (int)$section["time"]["sectionTime"]["hh"] * 3600 +
                                            (int)$section["time"]["sectionTime"]["mm"] * 60 +
                                            (int)$section["time"]["sectionTime"]["ss"];
                }

                $filtered_questions = array_filter($quiz_questions, function($obj) use ($section) {
                    return $obj["_postId"] === $section["_id"];
                });

                foreach ($filtered_questions as $qus) {
                    $qTime = 0;

                    $narration = isset($qus['narration'])? (object) $qus['narration'] : (object) [
                        "status" => false
                    ];

                    $is_recording   = isset($narration->status)? $narration->status : false;
                    $recording_url  = isset($narration->data)? $narration->data : '';

                    if (
                        isset($qus['_questionSettings']) &&
                        isset($qus['_questionSettings']["time"]["questionTimeToThink"]) && 
                        isset($qus['_questionSettings']["time"]["questionTimeToThink"]["timer"])
                    ) {
                        $qTime = (int) $qus['_questionSettings']["time"]["questionTimeToThink"]["hh"] * 3600 +
                                (int) $qus['_questionSettings']["time"]["questionTimeToThink"]["mm"] * 60 +
                                (int) $qus['_questionSettings']["time"]["questionTimeToThink"]["ss"];
                    }

                    $section_questions[] = [
                        "text_question"      => $qus['title'],
                        "suggestion_text"    => $qus["content"]["html"],
                        "question_video"     => null,
                        "question_recording" => $is_recording,
                        "recording_url"      => $recording_url,
                        "id"                 => $qus["_id"],
                        "time_to_think_qs"   => $qTime
                    ];
                }

                $parts[] = [
                    "id"           => $section["_id"],
                    "title"        => $section["title"],
                    "instructions" => $section["content"],
                    "time"         => ["total_answer_time" => $section_data["time"]],
                    "questions"    => $section_questions
                ];
            }

            self::$json_obj = (object) [
                "sot_questions" => (object) [
                    "part" =>  $parts
                ]
            ];
        }
    }

    /**
     * quiz result - constructor
     */
    public function __quiz_result_constructor(){
        global $ST_OPTION_st_proqyz_IELTS_LMS_enable_evaluation, // root option for evaluation
        $ST_OPTION_st_proqyz_IELTS_LMS_enable_ai_evaluation, // root option for ai evaluation

        // ai speaking evaluation
        $ST_OPTION_st_proqyz_IELTS_LMS_ai_speaking_evaluation_enable, // ai speaking evaluation enable
        $ST_OPTION_st_proqyz_IELTS_LMS_ai_speaking_evaluation_plan_id, // ai speaking evaluation plan id
        
        // instructor speaking evaluation
        $ST_OPTION_st_proqyz_IELTS_LMS_speaking_evaluation_enable, // instructor speaking evaluation enable
        $ST_OPTION_st_proqyz_IELTS_LMS_speaking_evaluation_plan_id, // instructor speaking evaluation plan id
        
        // db tables review
        $wpdb, $table_proqyz_v3_submissions_review, $table_proqyz_v3_submissions_review_meta;



        
        $db_result_id       = $this->result_id;
        $db_student_id      = $this->student_id;

        $student_details = get_user_by('id', $db_student_id);
        if($student_details){
            $this->student_info = (object) [
                "name" => $student_details->display_name,
                "email" => $student_details->user_email,
                "phone" => $student_details->phone,
            ];
        }


        # check if review is given or not 
        $get_review = $wpdb->get_row("SELECT `ID` FROM {$table_proqyz_v3_submissions_review} WHERE `result_id` = '$db_result_id' AND `user_id` = '$db_student_id' AND `status` = 1 LIMIT 1");
        if($get_review){
            $this->reviewed = true;
            $this->review_id = $get_review->ID;
        }

        $has_course_free = true;
        # first check if its course session 
        if(isset($this->course)){

            $course_q = (object) $this->course;
            $main_course = isset($course_q->course) ? (object) $course_q->course : null;
            $evaluation = isset($main_course->_evaluation)? (object) $main_course->_evaluation : null;

            if($main_course !== null){
                $this->course_info = (object) [
                    "title" => $main_course->title,
                    "_id" => $main_course->_id,
                ];
            }
            
            if($evaluation !== null){
                if( isset($evaluation->status) && ($evaluation->status == 1 || $evaluation->status == 'true' || $evaluation->status == true)) {
                    if(isset($evaluation->speaking) && ($evaluation->speaking == 1 || $evaluation->speaking == 'true' || $evaluation->speaking == true)){
                        # if course has evaluation for speaking
                        $this->PROQYZ_EVALUATION = true;
                        $has_course_free = false;
                    }
                }
            }
        }

        # if course is free|paid
        if( $has_course_free ) {
            $this->enrolled_for = "free";
            $this->is_enrolled = true; 
            $this->enrolled_reason = "course-free";
        } else {
            $this->enrolled_for = 'default';
            $this->is_enrolled = false;
            $this->enrolled_reason = 'course-paid';
        }

        # if evaluation is enabled - and woocommer is active
        if(class_exists('woocommerce')){
            if($this->PROQYZ_EVALUATION){
                # check if wp-admin evaluation is enabled - intructor
                $enable_evaluation = get_option($ST_OPTION_st_proqyz_IELTS_LMS_enable_evaluation,false);
                # check if wp-admin evaluation is enabled - ai
                $enable_ai_evaluation = get_option($ST_OPTION_st_proqyz_IELTS_LMS_enable_ai_evaluation,false);

                if( $enable_evaluation || $enable_ai_evaluation ){ 
                    $currency_code          = get_woocommerce_currency();
                    // Get the currency symbol for the current currency code
                    $sign                   = get_woocommerce_currency_symbol( $currency_code );
                    $this->is_evaluation_enable = true;
                    $enrolled_for = [];
                    $check_payment_for_tasks = st_proqyz_get_submission_evaluation_meta($db_result_id, "enrolled_for", $db_student_id, true);
                    //$check_payment_for_tasks = get_user_meta($db_student_id,"st_proqyz__evaluation-".$db_result_id, true);
                    if( $check_payment_for_tasks ) {
                        $enrolled_for = (array) json_decode( $check_payment_for_tasks );
                        if( array_key_exists('speaking-ai', (array) $enrolled_for) ) {
                            
                            $this->is_enrolled = true;
                            $this->enrolled_for = "ai";
                            $this->enrolled_reason = 'enrolled';
                        }
                        if( array_key_exists('speaking-tasks', (array) $enrolled_for) ) {
                            
                            $this->is_enrolled = true;
                            $this->enrolled_for = "instructor";
                            $this->enrolled_reason = 'enrolled';
                        }
                    }

                    if($this->is_enrolled){
                        // $this->task_paid = true;
                    } else {
                        # check if ai plan enable
                        $ai_speaking_evaluation_enable = get_option($ST_OPTION_st_proqyz_IELTS_LMS_ai_speaking_evaluation_enable,false);
                        # check if instructor plan enable
                        $speaking_evaluation_enable = get_option($ST_OPTION_st_proqyz_IELTS_LMS_speaking_evaluation_enable,false);

                        if($this->show_ai_evaluation_if_available){
                            # get ai plan and pricing
                            if( $ai_speaking_evaluation_enable == 1 || $ai_speaking_evaluation_enable == 'true' || $ai_speaking_evaluation_enable == true){
                                $AI_SPEAKING_task_product_id = get_option($ST_OPTION_st_proqyz_IELTS_LMS_ai_speaking_evaluation_plan_id,false);
                                if ( $AI_SPEAKING_task_product_id ) {
                                    $AI_SPEAKING_task_product = wc_get_product( $AI_SPEAKING_task_product_id );
                                    if( $AI_SPEAKING_task_product ){

                                        if( $AI_SPEAKING_task_product->get_price() > 0 ){
                                            $this->is_enrolled = false; // user need to enroll first
                                            $this->AI_task_plan = true;
                                            $this->AI_task_plan_details = (object) [
                                                "title"     => esc_html($AI_SPEAKING_task_product->get_title()),
                                                "price"     => wc_price($AI_SPEAKING_task_product->get_price())
                                            ];
                                        }
                                    }
                                }
                            }
                        }
                        # get instructor plan and pricing
                        if($speaking_evaluation_enable == 1 || $speaking_evaluation_enable == 'true' || $speaking_evaluation_enable == true){
                            # GET PRODUCT
                            $SPEAKING_task_product_id = get_option($ST_OPTION_st_proqyz_IELTS_LMS_speaking_evaluation_plan_id,false);
                            if ( $SPEAKING_task_product_id ) {
                                $SPEAKING_task_product = wc_get_product( $SPEAKING_task_product_id );
                                if( $SPEAKING_task_product ){
                                    if( $SPEAKING_task_product->get_price() > 0 ) {
                                        $this->is_enrolled = false; // user need to enroll first

                                        $this->instructor_task_plan = true;
                                        $this->instructor_task_plan_details = (object) [
                                            "title"     => esc_html($SPEAKING_task_product->get_title()),
                                            "price"     => wc_price($SPEAKING_task_product->get_price())
                                        ];
                                    }
                                }
                            } 
                        }

                        # if both plans are not avaible then mark as free - plan-unaviable
                        if(!$this->AI_task_plan && !$this->instructor_task_plan){
                            $this->is_enrolled = true; // mark is enrolled, because its free now
                            $this->enrolled_for = "free"; // mark as default, because its free now
                            $this->enrolled_reason = 'plan-unavailable';
                        }
                    }

                } else {
                    $this->is_enrolled = true;
                    $this->enrolled_for = "free";
                    $this->enrolled_reason = 'wp-evaluation-off';
                }
            } else {
                $this->enrolled_for = "free";
                $this->is_enrolled = true;
                $this->enrolled_reason = "course-free";
            }
        } else {
            $this->is_enrolled = true;
            $this->enrolled_for = "free";
            $this->enrolled_reason = "woocommerce-disabled";
        }

        # full width logic
        if( $this->review || $this->result ) {
            # teacher side
            if($this->review){
                $this->full_width = true;
            } else {
                if(!$this->reviewed && $this->is_enrolled){
                    $this->full_width = false;
                }

                if($this->reviewed){
                    $this->full_width = true;
                }
            }
        }
    }


    /**
     * status: completed
     */
    public function get_instructions_page(){
        ob_start(); ?>
        <div class="speaking-test taking-test-page">

            <div id="step-general-instructions" class="fade hide">
                <div class="instruction">

                    <h1 class="instruction__title">General instructions</h1>
                    <ul class="instruction__list">
                        <li class="instruction__item">The exam is divided into 3 parts. The name of each part is mentioned on the top of the page.</li>
                        <li class="instruction__item">There will be an active timer to remind you of how much time is left.</li>
                        <li class="instruction__item">You will use a computer and headset to read and respond to questions.</li>
                        <li class="instruction__item">Submit your test after you finish by clicking on "SUBMIT TEST". Make sure you have attempt maximum number of questions.</li>
                        <li class="instruction__item">You can also review your recording and record again to change your responses after completing and before submission.</li>
                        <li class="instruction__item">You can check required browser settings for recording. Click here <a class="instruction__link" href="#pdf">Instructions</a>.</li>
                    </ul>
                    <div class="mic-box__btn-group">
                        <?php if(is_user_logged_in()){ ?>
                        <button class="iot-bt -pink js-check-ios2 mic-box__btn-primary mic-box__btn-instruction" data-drupal-selector="change-screen">
                            Next Step <span class="ioticon-forward-fast"></span>
                        </button>
                        <?php } else { ?>
                            <button class="iot-bt -pink js-check-ios2 mic-box__btn-primary mic-box__btn-instruction" data-toggle="modal" href="#ielts-login-modal">
                                Login here
                            </button>   
                        <?php } ?>
                    </div>
                </div>
            </div>

            <div id="step-test-mic" class="fade hide">
                <div class="mic-box">
                    <div class="mic-box__contents">
                        <h1 class="title">TEST YOUR MICROPHONE</h1>
                        <div class="mic-box__record-part">
                            <div class="mic-box__radial-timer">
                                <div class="mic-box__icon-wrap text-center">
                                    <div style="display: inline; width: 60px; height: 60px;">
                                        <input type="hidden" value="0" class="mic-box__speaker-radial js-second js-speaker-radial"
                                            data-min="0" data-max="0" id="js-speaker-radial"
                                            style="display: none; width: 0px; visibility: hidden;">
                                    </div>
                                    <img src="<?php echo site_url(); ?><?php echo $this->ielts_url; ?>/img/ielts/speaking/icon_speaking.svg" alt="" class="mic-box__image">
                                </div>
                                <div id="waveform" class="mic-box__wave-line thinking"></div>
                            </div>
                            <div class="mic-box__note" id="js-time-note" data-time-note="You have 20 seconds to speak…">
                                <p>You have 20 seconds to speak…</p>
                                <p>To complete this activity, you must allow access to your system's microphone. Click <span
                                        class="ioticon-circle-play"></span> the button below to Start.</p>
                            </div>
                        </div>
                        <div class="mic-box__result-part">
                            <audio id="js-player" controls="">
                                <source id="player-source" src="">
                            </audio>
                            <p class="mic-box__audio-note">Click <i class="ioticon-circle-play"></i> to play your test
                                recording.<br>If your microphone works properly please click <strong>Start Exam</strong> button</p>
                        </div>
                        <div class="mic-box__btn-group -static"> 
                            <button id="js-reset-exam" class="iot-bt mic-box__btn-reset -test-again">
                                Test Mic Again <span class="ioticon-arrow-rotate-left"></span>
                            </button> 
                            <button id="js-record" class="iot-bt mic-box__btn-main -pink test-btn" data-time-record="20"> 
                                Test Microphone <span class="ioticon-play-circle"></span>
                            </button> 
                            <a id="js-next-part" class="iot-bt mic-box__btn-next-part -pink iot-bt -next-part" href="?quiz">
                                Start Exam
                                <span class="ioticon-forward-fast"></span>
                            </a> 
                            <button id="js-skip-test-mic" class="iot-bt mic-box__btn-skip" data-toggle="modal" data-target="#modal-reset-record">
                                Skip <span class="ioticon-arrow-right-to-line"></span>
                            </button>
                        </div>
                    </div>
                </div>
                <div class="modal modal-iot fade" id="modal-reset-record" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
                    <div class="modal-dialog modal-auto modal-reset-record">
                        <div class="">
                            <i class="ion-android-close close-modal" data-dismiss="modal" aria-label="Close"></i>
                            <h2 class="modal-caption">Do you want to skip the Microphone test and start the exam now?</h2>
                            <div class="modal__button-wrap">
                                <a href="?quiz" class="modal__button -no" data-drupal-selector1="change-screen">Yes</a>
                                <a class="modal__button -yes" data-dismiss="modal" aria-label="Close">No</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>


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


    /**
     * status: completed
     */
    public function get_speaking_details() {
        ob_start(); ?>
        <div class="speaking-test taking-test-page">
        <div id="sot-test-step" class="container">
            <div class="mic-box" class="fade in show">
                <div class="mic-box__contents -question">
                    <div class="mic-box__top">
                    <h1 class="mic-box__part-title" id="js-part-title">
                        <div class="speaker--container hidden">

                            <div class="slide__audio js-audio">
                                <audio class="slide__audio-player" controls="">
                                    <source src="" type="audio/mpeg"/>
                                </audio>
                                <div class="audio__controls">
                                    <svg version="1.1" id="circle" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 100 100">
                                        <path id="seekbar" fill="none" stroke-meterlimit="10" d="M50,2.9L50,2.9C76,2.9,97.1,24,97.1,50v0C97.1,76,76,97.1,50,97.1h0C24,97.1,2.9,76,2.9,50v0C2.9,24,24,2.9,50,2.9z"/>
                                    </svg>
                                    <svg xmlns="http://www.w3.org/2000/svg" class="equalizer" viewBox="0 0 100 100">
                                        <g class="equalizer-group">
                                            <rect class="bar"></rect>
                                            <rect class="bar"></rect>
                                            <rect class="bar"></rect>
                                            <rect class="bar"></rect>
                                            <rect class="bar"></rect>
                                        </g>
                                    </svg>
                                    <div class="audio__slider"></div>
                                    <button class="play-pause"></button>
                                </div>
                            </div>                        



                        </div>
                        <span class="mic-box__part-num"></span>
                        <span class="mic-box__part-name" data-drupal-selector="part-title"></span>
                    </h1>
                    <div class="mic-box__btn-group">
                        <button id="js-start-part" class="iot-bt -pink mic-box__btn-start-now hide"> Start Now <span class="ioticon-play-circle"></span></button>
                        <div class="mic-box__btn-group-action hide"> 
                            <button id="js-reset-exam" class="iot-bt -pink mic-box__btn-reset">
                                Reset This Part<span class="ioticon-arrow-rotate-left"></span>
                            </button> 
                            <button id="js-record" class="iot-bt -pink mic-box__btn-main" data-time-record="" data-thinking-time="">
                                Next Question <i class="fa fa-step-forward"></i>
                            </button> 
                            <button id="js-next-part" class="iot-bt -pink mic-box__btn-next-part">
                                Next Part <span class="ioticon-forward-fast"></span>
                            </button>
                        </div>
                    </div>
                    </div>
                    <div class="mic-box__indicator" id="recording-indicator" style="display: none;">recording...</div>
                    <div class="part-caption">
                    <h2 class="part-caption__title" data-drupal-selector="end-part-title"></h2>
                    <div class="part-caption__note"></div>
                    </div>
                    <div class="mic-box__record-part">
                    <div id="part-question-content" class="hide">
                        <div class="mic-box__test-content">
                            <h2 class="mic-box__question">
                                
                                <span class="question-number mic-box__question-number" id="question-number"></span>
                                <div data-drupal-selector="question" class="mic-box__question-title"></div>
                            </h2>
                            <div class="mic-box__test-suggest" data-drupal-selector="question-desc"></div>
                        </div>
                        <div class="mic-box__radial-timer">
                            <div class="mic-box__icon-wrap text-center">
                                <div style="display: inline; width: 60px; height: 60px;">
                                <input type="hidden" value="0" class="mic-box__speaker-radial js-second js-speaker-radial" data-min="0" data-max="300" id="js-speaker-radial" style="display: none; width: 0px; visibility: hidden;" />
                                </div>
                                <img src="<?php echo site_url(); ?><?php echo $this->ielts_url; ?>/img/ielts/icons/icon_speaking.svg" alt="" class="mic-box__image" />
                            </div>
                            <div id="waveform" class="mic-box__wave-line thinking" style="visibility: visible; opacity: 1;"></div>
                        </div>
                        <div class="mic-box__note" id="js-time-note" data-time-note=""></div>
                    </div>
                    <div class="mic-box__test-content" id="part-instruction-content">
                        <h2 class="mic-box__instruction-title"></h2>
                        <div class="mic-box__instruction-desc"></div>
                    </div>
                    </div>
                    <div class="mic-box__result-part">
                    <h2 id="js-player__audio-question" class="hide mic-box__question mic-box__audio-question">
                        <span class="question-number question-number mic-box__question-number"></span>
                        <div class="question-content mic-box__question-title"></div>
                    </h2>
                    <div id="js-player__audio-question__suggestion" class="hide mic-box__test-suggest">
                    </div>
                    <audio id="js-player" controls="">
                        <source id="player-source" src="" />
                    </audio>
                    <p class="part-caption__content" data-drupal-selector="end-part-desc"></p>
                    <div class="part-caption__note"></div>
                    </div>
                </div>
            </div>
        </div>
        <div class="recording-mess">Speak</div>
        <div id="real-form-date" class="hide">
            <form class="take-test-form" data-drupal-selector="take-test-form" action="<?php echo $site_url; ?>/ielts/quiz/speaking/results.php" method="post" id="take-test-form" accept-charset="UTF-8">
                <textarea data-drupal-selector="edit-field-part-1-questions" class="" id="edit-field-part-1-questions" name="field_part_1_questions" rows="5" cols="60"></textarea>
                <textarea data-drupal-selector="edit-field-part-2-questions" class="" id="edit-field-part-2-questions" name="field_part_2_questions" rows="5" cols="60"></textarea>
                <textarea data-drupal-selector="edit-field-part-3-questions" class="" id="edit-field-part-3-questions" name="field_part_3_questions" rows="5" cols="60"></textarea>
                <textarea data-drupal-selector="edit-field-part-4-questions" class="" id="edit-field-part-4-questions" name="field_part_4_questions" rows="5" cols="60"></textarea>
            </form>
        </div>
        </div>
        <?php return ob_get_clean();
    }


    /**
     * status: completed
     */
    public function get_layout(){
            
            $instructions = isset($_GET['instuctions'])? true : false;
            $quiz_page = isset($_GET['quiz'])? true : false;

            if( !$instructions && !$quiz_page ) {
                $instructions = true;
            }


            $class_body = 'speaking-test-page user-logged-in path-node page-node-type-quiz has-glyphicons';
            ob_start(); ?>


            <!DOCTYPE html>
            <html <?php language_attributes(); ?>>
            <?php echo $this->header(); ?>
            <body class="speaking-test-page user-logged-in path-node page-node-type-quiz has-glyphicons">

                <div id="overlay-region" class="">&nbsp;</div>
                <div id="overlay-menu"></div>

                <div class="dialog-off-canvas-main-canvas" data-off-canvas-main-canvas="">
                    <div class="region region-header-question">
                        <section id="block-headerquestion" class="block block-iot-ielts block-headerquestion clearfix">
                            <header class="test-header -speaking">
                            <div class="container">
                                <div class="test-header__wrapper">
                                    <div class="test-header__time-wrapper">
                                        <span class="ioticon-clock"></span>
                                        <div class="test-header__time-duration -pink" id="js-time-duration">--:--</div>
                                    </div>
                                </div>
                            </div>
                            </header>  
                        </section>
                    </div>

                    <div class="region region-content">
                        <div data-drupal-messages-fallback="" class="hidden"></div>
                        <?php if( $instructions ){ echo $this->get_instructions_page(); } ?>
                        <?php if( $quiz_page ) { echo $this->get_speaking_details(); } ?>
                    </div>
                </div>
                <?php echo $this->modals(); ?>
                <?php if( $quiz_page ) { ?>
                <script data-drupal-selector="drupal-json-settings" type="application/json">
                    <?php echo json_encode(self::$json_obj); ?>
                </script>       
                <?php } ?>
                <?php echo $this->footer(); ?>
            </body>
            </html>
            <?php return ob_get_clean();
        
    }



    /**
     * status: pending
     * speaking result layout
     */
    public function get_result_layout(){
        $class_body         = '-result';
        $current_url        = home_url($_SERVER['REQUEST_URI']);
        $review_url         = str_replace('result','review', $current_url);
        $result_url         = str_replace('review','result', $current_url);
        $student_id         = $this->student_id;
        $c_user_id          = get_current_user_id();
        $im_role            = "student";
        $c_user             = get_userdata($c_user_id);
        if (!$c_user) { return null; }
        $user_roles = $c_user->roles;
        if (in_array("administrator", $user_roles)) {
            $im_role = "admin";                    
        } elseif (in_array("teacher", $user_roles)) {
            $im_role = "teacher";                    
        } else {
            $im_role = "student";
        }

        



        ob_start(); ?>
        <!DOCTYPE html>
        <html <?php language_attributes(); ?>>
        <?php echo $this->header(); ?>
        <body style="padding-top:0;" class="speaking-test-page user-logged-in path-node page-node-type-quiz has-glyphicons speaking-test speaking-test-result <?php echo $class_body; ?>">
            <div class="dialog-off-canvas-main-canvas js-attempt-only-speaking">
                <!-- begin::header -->
                <header class="realtest-header ">
                    <span class="realtest-header__logo practice-item__icon -speaking "></span>
                    <?php if(isset($this->quiz->title)) { ?>
                        <div class=""><?php echo $this->quiz->title; ?></div>
                    <?php } ?>

                    <div class="realtest-header__time " style="display:none;">
                        <span class="realtest-header__time-clock" data-current-time="" data-time="<?php echo $this->seconds; ?>" data-duration-default="<?php echo $this->default; ?>" id="time-clock">
                            <span class="realtest-header__time-val">-:-</span>
                            <span class="realtest-header__time-text">minutes remaining</span>
                        </span>
                    </div>

                    <div class="realtest-header__btn-group">
                        <?php if($this->review){ ?>
                            <a class="realtest-header__bt-submit" href="<?php echo $result_url; ?>">
                                View as Student
                            </a>
                        <?php } ?>
                        <?php if(!$this->review && $this->result){ 
                            if($im_role == "admin" || $im_role == "teacher"){ ?>
                                <a class="realtest-header__bt-submit" href="<?php echo $review_url; ?>">
                                    View as Instructor
                                </a>
                            <?php } else { ?>
                                <button class="realtest-header__bt-submit -speaking--btn" onClick="window.close()" style="display:flex;">
                                    close
                                </button>
                            <?php }    
                        } ?>

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

                <!-- begin::content -->
                <div class="page" style="margin-top:65px;">
                    <div class="take-test__body">
                        <!-- begin::container -->
                        <div class="container">
                            <div class="region region-content">
                                <div class="speaking-review-page" id="sot-result-<?php echo $this->result_id; ?>">
                                    <!-- begin::page contents -->
                                    <div class="page-contents">
                                        <div class="row mb-4">
                                            <!-- begin::left column -->
                                            <div class="<?php echo ($this->full_width)? 'col-sm-12 col-xs-12 col-md-12 col-left' : 'col-xs-12 col-sm-8 col-left'; ?>">
                                                <!-- begin::breadcrumb -->
                                                <div class="region region-breadcrumb">
                                                    <div class="sitemap"> 
                                                        <a href="/">Home</a> 
                                                        <?php if($this->course_info){ ?>
                                                            <span>/</span> 
                                                            <a href="<?php echo st_proqyz_get_course_url($this->course_info->_id); ?>"><?php echo $this->course_info->title; ?></a>
                                                        <?php } ?>
                                                        <span>/</span> 
                                                        <a>Speaking</a>
                                                        <span>/</span> 
                                                        <a><?php echo $this->quiz->title; ?></a>
                                                    </div>
                                                </div>
                                                <!-- end::breadcrumb -->

                                                <!-- begin::page title -->
                                                <h1 id="page-title">
                                                    [<?php echo $this->student_info->name; ?>] <?php echo $this->quiz->title; ?> 
                                                </h1>
                                                <!-- end::page title -->

                                                <!-- begin::recordings panel -->
                                                <div class="panel-group recordings-panel" id="recording-accordion-<?php echo $this->result_id; ?>">
                                                    <!-- begin::recordings panel title -->
                                                    <h2 class="recordings-panel__title" style="display: flex;flex-direction: row;align-items: center;justify-content: space-between;"> 
                                                        My Recordings
                                                    </h2>
                                                    <!-- end::recordings panel title -->

                                                    <!-- begin::recordings panel content -->
                                                    <?php echo $this->get_result_sections(); ?>
                                                    <!-- end::recordings panel content -->

                                                    <!-- begin::review box - old-location -->
                                                    <!-- end::review box - old-location -->



                                                </div>
                                                <!-- end::recordings panel -->

                                                <!--begin::review box--> 
                                                <?php 
                                                    # shows review for AI/Instructor
                                                    echo $this->get_results_review_box(); 
                                                ?>
                                                <!--end::review box-->
                                                
                                            </div>
                                            <!-- end::left column -->


                                            <!-- begin::right column -->

                                            <!-- begin::sidebar -->
                                            <?php if(!$this->full_width){ echo $this->get_result_sidebar(); } ?>
                                            <!-- end::sidebar -->

                                            <!-- end::right column -->
                                        </div>
                                        <!-- begin::result page -->
                                        <?php if(!$this->review) { ?>
                                            <div class="row">
                                                <div class="col-12">
                                                    <?php echo do_shortcode("[proqyz-result-page result_id='$this->result_id']"); ?>
                                                </div>
                                            </div>
                                        <?php } ?>
                                        <!-- end::result page -->
                                        <!-- begin::back to course -->
                                        <div class="row">
                                            <!-- end::this according will infrom the admin/reviewer about review status -->
                                            <div class="col-xs-12 col-sm-12 col-md-12 col-left">
                                                <?php if(isset($this->session->session_category)){
                                                    if($this->session->session_category == "course" && $this->session->course_category !== "sfwd-course"){
                                                        $course_id = $this->session->course_id;
                                                        $course_url = st_proqyz_get_course_url( $course_id );
                                                        ?>
                                                        <a href="<?php echo $course_url; ?>">
                                                            <button class="ielts-lms-result-show-button" type="button" role="button">Back to the course</button>
                                                        </a>
                                                    <?php }
                                                } ?>
                                            </div>
                                        </div>
                                        <!-- end::back to course -->

                                    </div>
                                    <!-- end::page contents -->
                                </div>
                            </div>
                        </div>
                        <!-- end::container -->
                    </div>
                </div>
                <!-- end::content -->
            </div>

        <!--begin::paymet processing-->
        <div 
            class="modal fade modal-iot" 
            id="modal-notification-payment" 
            data-backdrop="static" 
            tabindex="-1" 
            role="dialog" 
            aria-labelledby="mySmallModalLabel" 
            style=""
        >
            <div class="modal-dialog modal-auto">
                <div class="modal-detail"> 
                    <img src="<?php echo site_url().($this->dist_url); ?>/img/loading.gif" alt="loading..." />
                    <h3 class="modal-caption">
                        Please wait, <br> We are processing your purchase request
                    </h3>
                    <p class="modal-des">
                        Please do not refresh the page to avoid double charges!
                    </p>
                    <div class="modal-action">
                        <button data-dismiss="modal" class="cancel-ajax-cart">Cancel</button>
                    </div>
                </div>
                <div class="modal-detail error_detail d-none"> 
                        
                </div>
            </div>
        </div>
        <!--end::paymet processing-->
        <!--begin::wallet payment modal-->
        <div 
            class="modal fade modal-iot modal-wallet-payment" 
            id="modal-wallet-payment" 
            data-backdrop="static" 
            tabindex="-1" 
            role="dialog" 
            aria-labelledby="walletPaymentModalLabel" 
            style=""
        >
            <div class="modal-dialog modal-auto">
                <div class="modal-detail"> 
                    <h3 class="modal-caption">
                        Pay with Wallet
                    </h3>
                    <div class="wallet-payment-details" style="text-align: left; margin: 20px 0;">
                        <p><strong>Product:</strong> <span class="product-name"></span></p>
                        <p><strong>Price:</strong> <span class="product-price"></span></p>
                        <p><strong>Your Wallet Balance:</strong> <span class="wallet-balance"></span></p>
                        <p class="insufficient-balance-msg" style="color: #dc3232; display: none;">
                            <i class="fa fa-exclamation-triangle" aria-hidden="true"></i> Insufficient wallet balance. Please go to checkout to add funds.
                        </p>
                    </div>
                    <div class="modal-action" style="display: flex; gap: 10px; justify-content: center;">
                        <button class="btn-pay-wallet" style="padding: 10px 20px; background: #28a745; color: white; border: none; border-radius: 4px; cursor: pointer;">Pay with Wallet</button>
                        <button class="btn-go-checkout" style="padding: 10px 20px; background: #0073aa; color: white; border: none; border-radius: 4px; cursor: pointer;">Go to Checkout</button>
                        <button data-dismiss="modal" class="cancel-ajax-cart" style="padding: 10px 20px; background: #ccc; color: #333; border: none; border-radius: 4px; cursor: pointer;">Cancel</button>
                    </div>
                </div>
                <div class="modal-detail error_detail d-none" style="text-align: center;"> 
                    <i class="fa fa-exclamation-triangle fa-2x" aria-hidden="true"></i>
                    <h3 class="modal-caption" style="margin-top: 15px;">
                        Error
                    </h3>
                    <p class="wallet-error-message" style="margin: 15px 0;"></p>
                    <div class="modal-action">
                        <button data-dismiss="modal" class="cancel-ajax-cart" style="padding: 10px 20px; background: #ccc; color: #333; border: none; border-radius: 4px; cursor: pointer;">Close</button>
                    </div>
                </div>
            </div>
        </div>
        <!--end::wallet payment modal-->

        <!--begin::footer-->
        <?php echo $this->footer(); ?>
        <!--end::footer-->
        </body>
        </html>
        <?php return ob_get_clean();
    }

    /**
     * status: completed
     * sections result [given answer and recording sections only]
     */
    public function get_result_sections(){
        global $wpdb, $table_proqyz_v3_progress_meta_submissions;	

        # result id
        $session_id         = $this->result_id;
        $session_quiz_id    = $this->_id;
        $sections_html      = "";
        $scount             = 0;

        if( count($this->sections) > 0 ) {
            foreach( $this->sections as $skey => $section ) {
                $section = (object) $section;
                $section_id = $section->_id;

                $get_session = $wpdb->get_row("SELECT * FROM {$table_proqyz_v3_progress_meta_submissions} WHERE `quiz_id` = '$session_quiz_id' AND `section_id` = '$section_id' AND `session_id` = '$session_id' AND `status` = 1 ");
                if( $get_session ) {
                    $scount++;
                    $question_ids           = $get_session->question_ids; // display as 1,2,3,4,5,6,7,8,9,10
                    $question_intervals     = $get_session->question_intervals; // display as 0,1,2,3,4,5,6,7,8,9,10
                    $question_ids_arr       = explode(",",$question_ids);
                    
                    $question_intervals_arr = explode(",", $question_intervals);
                    $idsArrayWithQuotes = array_map(function($item) {
                        return ''.$item.'';
                    }, $question_ids_arr);

                    # file-management
                    $audio_json             = (object) unserialize($get_session->json);
                    $audio_loc              = $audio_json->location;
                    $audio_file             = $audio_json->filename;
                    $audio_url              = "/".$audio_loc."/".$audio_file;
                    $this->ai_audio_sections[$skey] = [
                        'audio_url' => $audio_url,
                        'question_ids' => $idsArrayWithQuotes,
                        'question_intervals' => $question_intervals_arr,
                    ];
                    $total_interval         = 0;
                    if( count($question_intervals_arr) > 0 ) {
                        $total_interval = $question_intervals_arr[count($question_intervals_arr) - 1];
                    }
                    


                    ob_start(); ?>
                    <div class="panel panel-default recording ">
                        <div class="panel-heading">
                            <h4 class="panel-title clearfix"> 
                                <a class="recording__collapse clearfix" aria-expanded="<?php echo ($scount == 1)? 'true' : 'false'; ?>" data-toggle="collapse" data-parent="#recording-accordion-<?php echo $this->result_id; ?>" href="#panel-part_<?php echo $scount; ?>"> 
                                    <span class="recording__header-item -part-no">PART <?php echo $scount; ?></span> 
                                    <span class="recording__header-item -part-name"><?php echo $section->title; ?></span> 
                                    <span class="recording__header-item -part-time" data-drupal-selector="part-total-time">
                                        <?php echo gmdate("i:s", (int) $total_interval); ?>
                                    </span> 
                                </a>
                            </h4>
                        </div>
                        <div id="panel-part_<?php echo $scount; ?>" class="panel-collapse collapse <?php echo ($scount == 1)? 'in' : ''; ?>">
                            <div class="panel-body" data-audio-item="0">
                                <audio 
                                    id="audio-player-<?php echo $scount; ?>" 
                                    class="audio-player" 
                                    src="<?php echo $audio_url; ?>"
                                    data-intervals="[<?php echo $question_intervals; ?>]"
                                    data-qus-ids="#audio-player-json-<?php echo $scount; ?>"
                                >
                                </audio>
                                <script id="audio-player-json-<?php echo $scount; ?>" type="application/json">
                                    <?php echo json_encode($idsArrayWithQuotes); ?>
                                </script>


                                <?php if( count($question_ids_arr) > 0 && count($this->questions) > 0 ) {
                                    $qcount = 0;
                                    foreach( $question_ids_arr as $qkey => $qid ){
                                        $current_question = $this->filter_question($this->questions, $qid, $section_id);
                                        if( $current_question ) {
                                            $qus_start_interval     = isset($question_intervals_arr[$qkey])? $question_intervals_arr[$qkey] : 0;
                                            $qus_end_interval       = isset($question_intervals_arr[$qkey+1])? $question_intervals_arr[$qkey+1] : 0;
                                            $cu_qus                 = (object) $current_question;
                                            $content                = isset($cu_qus->content)? (object) $cu_qus->content : null;
                                            $qus_title              = $cu_qus->title;
                                            $html                   = isset($content)? $content->html : 'no content';
                                            $start_time             = gmdate("i:s", (int) $qus_start_interval);
                                            ?>
                                            <div class="recording__question -enabled" data-q_id="<?php echo $qid; ?>">
                                                <h5 
                                                    class="recording__question-title -enabled" 
                                                    data-plyr="true"
                                                    data-index="<?php echo $scount; ?>"
                                                    data-current-time="<?php echo $qus_start_interval; ?>" 
                                                    data-current-time-end="<?php echo $qus_end_interval; ?>"
                                                >
                                                    <div class="sound-bars">
                                                        <div class="sound-bars__item"></div>
                                                        <div class="sound-bars__item"></div>
                                                        <div class="sound-bars__item"></div>
                                                    </div>
                                                    <?php echo $qus_title; ?>
                                                    <span class="recording__question-time"><?php echo $start_time; ?></span>
                                                </h5>
                                                <div class="recording__question-body">
                                                    <div class="recording__question-content">
                                                        <?php echo $html; ?>
                                                    </div>
                                                </div>
                                            </div>
                                            <?php 
                                        }
                                    }
                                } ?>
                                
                            </div>
                        </div>
                    </div>
                    <?php $sections_html .= ob_get_clean();
                }
            }
        }
        return $sections_html;
    }


    /**
     * status: pending
     * v2.1.0
     * sidebar result
     * @var get_evalution_plans_layout() - for displat evaluation plans
     * @var review_box_by_task($skey) - get task review tabs for admin/teacher
     */
    public function get_result_sidebar() {
        # student side
        if(!$this->review){
            ob_start();
            # if evaluation is completed then show the evaluation completed message and no need to show plans and etc
            if($this->reviewed){
                return '';
            }

            # if its not reviewed then show status , generate button, waiting for evaluation notice, plans etc
            if(!$this->reviewed){ ?>
                <div class="col-xs-12 col-sm-4 col-right">
                <?php
                if($this->is_enrolled){
                    # if task is paid then show the evaluation status, generate button, waiting for evaluation notice. etc
                    # if  task is paid for intructor review then show the waiting for evaluation noitce 

                    if($this->enrolled_for == "instructor" || $this->enrolled_for == "free" || $this->enrolled_for == "default"){
                        echo $this->get_evaluation_status('default');
                    }

                    # if task is paid for AI review then show the generate ai evaluation button
                    if($this->enrolled_for == "ai" && $this->show_ai_evaluation_if_available){
                        echo $this->get_evaluation_status('ai');
                    }

                } else {
                    # if task is not paid and if evaluation is enabled then show the evaluation plans
                    $plan_selector  = "";
                    $plans          = $this->get_evalution_plans_layout();
                    if( $plans ){   $plan_selector = $plans->plans_selector; }
                    if( $plan_selector ){
                        ?>
                        <?php echo $plan_selector; ?>
                        <?php
                    } 

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


        # teacher side - show nothing inside sidebar
        if($this->review){
            return '';
        }
    }

    /**
     * v2.1.0 
     * get results review box
     * status: pending - in queue -----------------------------
     */
    public function get_results_review_box() {
        global $wpdb, $table_proqyz_v3_submissions_review_meta;
        $reviewer = '1'; 
        $reviewer_status = 'completed';
        # admin - teacher
        if($this->reviewed){
            # review id 
            $review_id = $this->review_id;
            // get review meta where meta_key = reviewer
            $review_meta = $wpdb->get_row("SELECT `meta_value` FROM {$table_proqyz_v3_submissions_review_meta} WHERE `meta_key` = 'reviewer' AND `review_id` = '$review_id' AND `meta_status` = 1 LIMIT 1");
            if($review_meta){
                $reviewer = $review_meta->meta_value;
                # if review is given by an AI - check for its status
                if($reviwer == "-1"){
                    # get status meta
                    $review_status_key = $wpdb->get_row("SELECT `meta_value` FROM {$table_proqyz_v3_submissions_review_meta} WHERE `meta_key` = 'review-status' AND `review_id` = '$review_id' AND `meta_status` = 1 LIMIT 1");
                    if( $review_status_key ) { 
                        $reviewer_status = trim($review_status_key->meta_value); 
                    }
                }
            }
        }

        # student side review box 
        if(!$this->review){
            ob_start(); 
            if($this->reviewed){
                # if review is given and its by instructor
                if($reviewer !== "-1" ) {
                    echo $this->display_evaluated_report_for_student_by_evaluator([
                        "student_id" => $this->student_id,
                        "result_id" => $this->result_id,
                    ]);
                }
                
                # if review is given and its by AI
                if($reviewer == "-1"){ ?>
                    <div class="ai-speaking-evaluation-page evaluate__anyway sm-hide--evaluation-away">
                        <?php echo $this->ai_review_for_both_teacher_and_student_view(); ?>
                    </div>
                <?php }
            }

            if(!$this->reviewed){
                # student if not reviewed then it will show sidebar to generate review logic or notice to show under evaluation
                return '';
            }

            return ob_get_clean();
        }

        # teacher side review box
        if($this->review){
            # review panel for teacher evaluation and its controls
            # first we need tabs for both AI , Teacher, where in teachee tab this below data show
            # then in teacher tab we need to show the teacher evaluation data
            ob_start();  ?> 
            <!--begin::container for eveything-->
            <div class="row">
                <div class="col-md-12 mb-2">
                    <?php echo $this->get_evaluation_notice(); ?>
                </div>
                <div class="col-xs-12 col-sm-12 evaluation-tabs-content" id="evaluate__anyway-<?php echo $this->result_id; ?>">

                    <div class="evaluate__anyway evaluation-tabs d-flex flex-row sm:flex-column align-items-center justify-content-between" style="padding:10px;border:none;">
                        <ul class="nav nav-tabs" role="tablist" style="margin:0;">
                            
                            <li data-evaluator-category="evaluator" data-ajax-review="1" role="presentation" class="<?php echo ($reviewer == "1")? 'active' : ''; ?>"> 
                                <button class="my-purchase__btn -completed" role="tab">
                                    Teacher
                                </button>
                            </li>
                            <?php if($this->show_ai_evaluation_if_available){ ?>
                            <li data-evaluator-category="ai" data-ajax-review="0" role="presentation" class="<?php echo ($reviewer == "-1")? 'active' : ''; ?>"> 
                                <button class="my-purchase__btn -inprogress" role="tab">
                                    AI
                                </button>
                            </li>
                            <?php } ?>
                        </ul>
                        <?php if($this->reviewed){ ?>
                        <form class="d-none--1" id="speaking-ajax--set-primary-evaluation">
                            <div class="input-group mb-3 d-flex flex-row align-items-center justify-content-between">
                                <select id="primary-evaluation" name="primary-evaluation" class="form-control">
                                    <option value="1" <?php echo ($reviewer == "1")? 'selected' : ''; ?>>Instructor</option>
                                    <?php if($this->show_ai_evaluation_if_available){ ?>
                                    <option value="-1" <?php echo ($reviewer == "-1")? 'selected' : ''; ?>>AI</option>
                                    <?php } ?>
                                </select>
                                <div class="input-group-append">
                                    <input type="hidden" name="result-id" value="<?php echo $this->result_id; ?>" />
                                    <button class="btn btn-outline-secondary" type="submit">Set Evaluation </button>
                                </div>
                            </div>
                            <p class="text-muted small">Set the primary evaluation for the students</p>
                        </form>
                        <?php } ?>

                    </div>

                    <div class="evaluate__anyway sm-hide--evaluation-away" style="padding:0;">
                        <div id="ai-tab" class="tab__content ai-speaking-evaluation-page <?php echo ($reviewer == "-1")? '--show-contents' : ''; ?>" style="display:none;padding: 24px;">
                            <?php if($this->show_ai_evaluation_if_available){ ?>
                                <?php echo $this->ai_review_for_both_teacher_and_student_view(); ?>
                            <?php } else {
                                
                            } ?>
                        </div>
                        <div id="evaluator-tab" class="tab__content <?php echo ($reviewer == "1")? '--show-contents' : ''; ?>" style="display:none;padding: 0 15px;">
                            
                            <?php 
                                echo $this->review_panel_for_teachers();
                            ?>
                        </div>
                    </div>

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


    /**
     * v2.1.0
     * @var given_review_by_teacher_panel
     */
    public function review_panel_for_teachers() {
        global $wpdb, $table_proqyz_v3_submissions_review, $table_proqyz_v3_submissions_review_meta;
        # default data for review
        $review_feedback_status = 1;
        $review_feedback_content = "Please manual evaluate";
        $review_scores = [1,1,1,1];

        if($this->reviewed){
            $review_id = $this->review_id;
            $get_review  = $wpdb->get_row("SELECT `ID` FROM {$table_proqyz_v3_submissions_review} WHERE `status` = 1 AND `ID` = '$review_id' LIMIT 1");
            # evaluated
            if( $get_review ) {
                $review_meta_id = $get_review->ID;

                # 1.) review content
                $review_feedback_content_key = $wpdb->get_row("SELECT `meta_value` FROM {$table_proqyz_v3_submissions_review_meta} WHERE `meta_key` = 'review-feedback-content' AND `review_id` = '$review_meta_id' AND `meta_status` = 1 LIMIT 1");
                if( $review_feedback_content_key ) { $review_feedback_content = stripslashes($review_feedback_content_key->meta_value); }
                

                # 2.) review scores
                $review_scores_key = $wpdb->get_row("SELECT `meta_value` FROM {$table_proqyz_v3_submissions_review_meta} WHERE `meta_key` = 'review-scores' AND `review_id` = '$review_meta_id' AND `meta_status` = 1 LIMIT 1");
                if( $review_scores_key ) { 
                    $review_scores = (array) json_decode($review_scores_key->meta_value); 
                }
            }
        }
        

        ob_start(); ?>
        <form class="proqyz__post-evaluation-form" style="display:contents;">
            <div class="row">
                <!--begin::overall feedback -->
                <div class="col-xs-12 col-sm-12 mb-2">
                    <div class="form-group evaluation__item-card"> 
                        <label for="textarea" class="evaluation__item-title">Overall Feedback</label>
                        <div class="evaluation__score" style="display:none;"></div>
                        <div class="form-control evaluation__item-comment --review" disabled="disabled" style="padding:0;height:100%;">
                            <div style="max-height: 100%; overflow: auto">
                                <textarea id="feedback-content" name="feedback-content" class="summernote"><?php echo $review_feedback_content; ?></textarea>
                            </div>
                        </div>
                    </div>
                </div>
                <!--end::overall feedback -->

                <!-- begin::Fluency and Coherence -->
                <div class="col-xs-12 col-sm-6">
                    <div class="form-group evaluation__item-card"> 
                        <label for="textarea" class="evaluation__item-title">Fluency and Coherence</label>
                        <div class="evaluation__score" style="display:none;">
                            <!--begin::band score selector--> 
                            <!--end::band score selector-->
                        </div>
                        <div class="form-control evaluation__item-comment --review" disabled="disabled" style="height:100%;">
                            <div style="max-height: 100%; overflow: auto">
                                <select id="score-1" name="score-1" class="iot-opselect band-scored form-select form-control">
                                    <?php foreach( array_reverse($this->S_Fluency_lines, true) as $findex => $fkey  ) { ?>
                                        <option <?php echo (int) $review_scores[0] == (int) $findex? 'selected' : ''; ?> value="<?php echo $findex; ?>"><?php echo $findex; ?> - <?php echo $fkey; ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- end::Fluency and Coherence -->

                <!-- begin::Lexical Resource -->
                <div class="col-xs-12 col-sm-6">
                    <div class="form-group evaluation__item-card"> 
                        <label for="textarea" class="evaluation__item-title">Lexical Resource</label>
                        <div class="evaluation__score" style="display:none;">
                            <!--begin::band score selector--> 
                            <!--end::band score selector-->
                        </div>
                        <div class="form-control evaluation__item-comment --review" disabled="disabled" style="height:100%;">
                            <div style="max-height: 100%; overflow: auto">
                                <select id="score-2" name="score-2" class="iot-opselect band-scored form-select form-control">
                                    <?php foreach( array_reverse($this->S_Lexical_lines, true) as $cindex => $ckey  ) { ?>
                                        <option <?php echo (int) $review_scores[1] == (int) $cindex? 'selected' : ''; ?> value="<?php echo $cindex; ?>"><?php echo $cindex; ?> - <?php echo $ckey; ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- end::Lexical Resource -->

                <!-- begin::Grammatical Range and Accuracy -->
                <div class="col-xs-12 col-sm-6">
                    <div class="form-group evaluation__item-card"> 
                        <label for="textarea" class="evaluation__item-title">Grammatical Range and Accuracy</label>
                        <div class="evaluation__score" style="display:none;">
                            <!--begin::band score selector--> 
                            <!--end::band score selector-->
                        </div>
                        <div class="form-control evaluation__item-comment --review" disabled="disabled" style="height:100%;">
                            <div style="max-height: 100%; overflow: auto">
                                <select id="score-3" name="score-3" class="iot-opselect band-scored form-select form-control">
                                    <?php foreach( array_reverse($this->S_Grammatical_lines, true) as $lindex => $lkey  ) { ?>
                                        <option <?php echo (int) $review_scores[2] == (int) $lindex? 'selected' : ''; ?> value="<?php echo $lindex; ?>"><?php echo $lindex; ?> - <?php echo $lkey; ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- end::Grammatical Range and Accuracy -->

                <!-- begin::Pronunciation -->
                <div class="col-xs-12 col-sm-6">
                    <div class="form-group evaluation__item-card"> 
                        <label for="textarea" class="evaluation__item-title">Pronunciation</label>
                        <div class="evaluation__score" style="display:none;">
                            <!--begin::band score selector--> 
                            <!--end::band score selector-->
                        </div>
                        <div class="form-control evaluation__item-comment --review" disabled="disabled" style="height:100%;">
                            <div style="max-height: 100%; overflow: auto">
                                <select id="score-4" name="score-4" class="iot-opselect band-scored form-select form-control">
                                    <?php foreach( array_reverse($this->S_Pronunciation_lines, true) as $gindex => $gkey  ) { ?>
                                        <option <?php echo (int) $review_scores[3] == (int) $gindex? 'selected' : ''; ?> value="<?php echo $gindex; ?>"><?php echo $gindex; ?> - <?php echo $gkey; ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                        </div>
                    </div>
                </div>                        
                <!-- end::Pronunciation --> 

                <!-- begin::Footer -->
                <div class="col-xs-12 col-sm-12">
                    <div class="form-group evaluation__item-card">
                        <div class="form-group evaluation__item-card--footer">
                            <div class="notice__area"></div>
                            <div class="d-flex flex-row align-items-center">
                                <button type="submit" class="btn btn-primary">Post Review</button> 
                            </div>
                            <p class="text-muted small">Posting review will be mark as instructor evaluation</p>
                        </div>
                    </div>
                </div>
                <div class="d-none" style="display:none;">
                    <input type="hidden" id="result-id" name="result-id" value="<?php echo $this->result_id; ?>" />                       
                </div>
                <!-- begin::Footer -->

            </div>
        </form>
        <?php return ob_get_clean();

    }

    /**
     * @var display_evaluated_report_for_student_by_evaluator
     */
    public function display_evaluated_report_for_student_by_evaluator( $params = [] ) {
        global $wpdb, $table_proqyz_v3_submissions_review, $table_proqyz_v3_submissions_review_meta;
        $params = (object) $params;
        $student_id     = $params->student_id;
        $result_id       = $params->result_id;

        # default data for review
        $review_feedback_status = 1;
        $review_feedback_content = "";
        $review_scores = [1,1,1,1];

        $get_review  = $wpdb->get_row("SELECT `ID` FROM {$table_proqyz_v3_submissions_review} WHERE `result_id` = '$result_id' AND `user_id` = '$student_id' AND `status` = 1 LIMIT 1");
        # evaluated
        if( $get_review ) {
            $review_meta_id = $get_review->ID;

            # review feedback content
            $review_feedback_content_key = $wpdb->get_row("SELECT `meta_value` FROM {$table_proqyz_v3_submissions_review_meta} WHERE `meta_key` = 'review-feedback-content' AND `review_id` = '$review_meta_id' AND `meta_status` = 1 LIMIT 1");
            if( $review_feedback_content_key ) { $review_feedback_content = stripslashes($review_feedback_content_key->meta_value); }
            

            # 2.) review scores
            $review_scores_key = $wpdb->get_row("SELECT `meta_value` FROM {$table_proqyz_v3_submissions_review_meta} WHERE `meta_key` = 'review-scores' AND `review_id` = '$review_meta_id' AND `meta_status` = 1 LIMIT 1");
            if( $review_scores_key ) { 
                $review_scores = (array) json_decode($review_scores_key->meta_value); 
            }
        }

        # get overall band score for this section
        $overall_sum = array_sum($review_scores);
        $count = count($review_scores);
        # Calculate the average
        $average = $overall_sum / $count;
        # Round the average to the nearest half band or whole band
        $overall_band = round($average * 2) / 2;

        ob_start(); ?>
        <div class="ai-speaking-evaluation-page evaluate__anyway">
            <div class="part-score"> 
                <span class="part-score__text">Task <?php echo $section_order; ?> Overall score:</span> 
                <span class="part-score__val"><?php echo number_format(floatval($overall_band), 1); ?></span>
            </div>
            <div class="row">
                <!--begin::overall feedback -->
                <div class="col-xs-12 col-sm-12 mb-2">
                    <div class="form-group evaluation__item-card"> 
                        <label for="textarea" class="evaluation__item-title">Overall Feedback</label>
                        <div class="evaluation__score" style="display:none;">

                        </div>
                        <div class="form-control evaluation__item-comment" disabled="disabled" style="height:100%;">
                            <div style="max-height: 100%; overflow: auto">
                                <?php echo $review_feedback_content; ?>
                            </div>
                        </div>
                    </div>
                </div>
                <!--end::overall feedback -->

                <!-- begin::fluency and coherence -->
                <div class="col-xs-12 col-sm-6">
                    <div class="form-group evaluation__item-card"> 
                        <label for="textarea" class="evaluation__item-title">Fluency and Coherence</label>
                        <div class="evaluation__score">
                            <!--begin::band score selector-->
                            <?php echo isset($review_scores[0])? number_format(floatval($review_scores[0]), 1) : '0'; ?>
                            <!--end::band score selector-->
                        </div>
                        <div class="form-control evaluation__item-comment --review" disabled="disabled" style="height:100%;">
                            <div style="max-height: 100%; overflow: auto">
                                <?php echo isset($this->S_Fluency_lines[$review_scores[0]])?  $this->S_Fluency_lines[$review_scores[0]] : ''; ?>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- end::fluency and coherence -->

                <!-- begin::lexical resource -->
                <div class="col-xs-12 col-sm-6">
                    <div class="form-group evaluation__item-card"> 
                        <label for="textarea" class="evaluation__item-title">Lexical Resource</label>
                        <div class="evaluation__score">
                            <!--begin::band score selector--> 
                            <?php echo isset($review_scores[1])? number_format(floatval($review_scores[1]), 1) : '0'; ?>
                            <!--end::band score selector-->
                        </div>
                        <div class="form-control evaluation__item-comment" disabled="disabled" style="height:100%;">
                            <div style="max-height: 100%; overflow: auto">
                                <?php echo isset($this->S_Lexical_lines[$review_scores[1]])?  $this->S_Lexical_lines[$review_scores[1]] : ''; ?>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- end::lexical resource -->

                <!-- begin::grammatical range and accuracy -->
                <div class="col-xs-12 col-sm-6">
                    <div class="form-group evaluation__item-card"> 
                        <label for="textarea" class="evaluation__item-title">Grammatical Range and Accuracy</label>
                        <div class="evaluation__score">
                            <!--begin::band score selector--> 
                            <?php echo isset($review_scores[2])? number_format(floatval($review_scores[2]), 1) : '0'; ?>
                            <!--end::band score selector-->
                        </div>
                        <div class="form-control evaluation__item-comment" disabled="disabled" style="height:100%;">
                            <div style="max-height: 100%; overflow: auto">
                                <?php echo isset($this->S_Grammatical_lines[$review_scores[2]])?  $this->S_Grammatical_lines[$review_scores[2]] : ''; ?>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- end::grammatical range and accuracy -->

                <!-- begin::pronunciation -->   
                <div class="col-xs-12 col-sm-6">
                    <div class="form-group evaluation__item-card"> 
                        <label for="textarea" class="evaluation__item-title">Pronunciation</label>
                        <div class="evaluation__score">
                            <!--begin::band score selector-->
                            <?php echo isset($review_scores[3])? number_format(floatval($review_scores[3]), 1) : '0'; ?>
                            <!--end::band score selector-->
                        </div>
                        <div class="form-control evaluation__item-comment" disabled="disabled" style="height:100%;">
                            <div style="max-height: 100%; overflow: auto">
                                <?php echo isset($this->S_Pronunciation_lines[$review_scores[3]])?  $this->S_Pronunciation_lines[$review_scores[3]] : ''; ?>
                            </div>
                        </div>
                    </div>
                </div>                        
                <!-- end::pronunciation -->            
            </div>
        </div>
        <?php return ob_get_clean();
    }


    /**
     * v2.1.0
     * @var ai_review_for_both_teacher_and_student_view
     */
    public function ai_review_for_both_teacher_and_student_view() {
        # if ai evaluation is not started so there is no point to show it - teacher side
        if(!$this->reviewed && $this->review){
            ob_start();
            echo $this->ai_evaluation_not_started_panel();
            return ob_get_clean();
        }

        global $wpdb, $table_proqyz_v3_submissions_review_meta;
        $review_id = $this->review_id;

        $score_type = array(
            array(
                    "order" => 1,
                    "title" => "Fluency ",
                    "data"  => $this->S_Fluency_lines,
                    "prefix" => "score-1"
            ),   
            array(
                    "order" => 2,
                    "title" => "Lexical resource",
                    "data"  => $this->S_Lexical_lines,
                    "prefix" => "score-2"
            ),
            array(
                    "order" => 3,
                    "title" => "Grammatical range and accuracy",
                    "data"  => $this->S_Grammatical_lines,
                    "prefix" => "score-3"
            ),
            array(
                    "order" => 4,
                    "title" => "Pronunciation",
                    "data"  => $this->S_Pronunciation_lines,
                    "prefix" => "score-4"
            )
        );

        # 2.) review scores
        $review_scores = [1,1,1,1];
        $review_scores_key = $wpdb->get_row("SELECT `meta_value` FROM {$table_proqyz_v3_submissions_review_meta} WHERE `meta_key` = 'review-scores' AND `review_id` = '$review_id' AND `meta_status` = 1 LIMIT 1");
        if( $review_scores_key ) { $review_scores = (array) json_decode($review_scores_key->meta_value); }

        $review_status_key = $wpdb->get_row("SELECT `meta_value` FROM {$table_proqyz_v3_submissions_review_meta} WHERE `meta_key` = 'review-status' AND `review_id` = '$review_id' AND `meta_status` = 1 LIMIT 1");
        if( $review_status_key ) { $review_status_value = trim($review_status_key->meta_value); }

        $review_log_key = $wpdb->get_row("SELECT `meta_value` FROM {$table_proqyz_v3_submissions_review_meta} WHERE `meta_key` = 'review-log' AND `review_id` = '$review_id' AND `meta_status` = 1 LIMIT 1");
        if( $review_log_key ) { $review_log_entry = maybe_unserialize($review_log_key->meta_value); }

        $ai_schema_payload = [];
        $ai_review_content_key = $wpdb->get_row("SELECT `meta_value` FROM {$table_proqyz_v3_submissions_review_meta} WHERE `meta_key` = 'ai-review-content' AND `review_id` = '$review_id' AND `meta_status` = 1 LIMIT 1");
        if( $ai_review_content_key ) {
            $ai_review_content_raw = $ai_review_content_key->meta_value;
            $decoded_ai_content = json_decode($ai_review_content_raw, true);
            if( isset($decoded_ai_content['success']) ) {
                $ai_review_payload = (object) $decoded_ai_content['success'];
            }
        }

        $ai_schema_content_key = $wpdb->get_row("SELECT `meta_value` FROM {$table_proqyz_v3_submissions_review_meta} WHERE `meta_key` = 'ai-review-schema' AND `review_id` = '$review_id' AND `meta_status` = 1 LIMIT 1");
        if( $ai_schema_content_key ) {
            $decoded_schema = json_decode($ai_schema_content_key->meta_value, true);
            if(is_array($decoded_schema)){
                $ai_schema_payload = $decoded_schema;
            }
        }

        $ai_response_data = [];
        if( $ai_review_payload && isset($ai_review_payload->response) ) {
            $ai_response_data = (array) $ai_review_payload->response;
        }

        $ai_categories = [
            'fluency-coherence'              => ['label' => 'Fluency & Coherence', 'icon' => '🗣️', 'color' => '#0ea5e9'],
            'lexical-resource'               => ['label' => 'Lexical Resource', 'icon' => '📚', 'color' => '#f97316'],
            'grammatical-range-and-accuracy' => ['label' => 'Grammar & Accuracy', 'icon' => '✔️', 'color' => '#14b8a6'],
            'pronunciation'                  => ['label' => 'Pronunciation', 'icon' => '🎧', 'color' => '#a855f7'],
        ];


        # this tab only shows its content when below things are true:
        # reviewed is true 
        # enrolled for: ai
        ob_start(); ?>
        <?php if( $this->reviewed ) { ?>
            <!--begin::if AI - no status-->
            <?php if( empty($review_status_value) ) { ?>
                <?php echo $this->ai_evaluation_not_started_panel(); ?>
            <?php } ?>
            <!--end::if AI - no status-->


            <!--begin::if AI - pending (show evaluation button to retry) -->
            <?php if( $review_status_value === 'pending' ) { ?>
                <div class="no-answer">
                    <img src="https://cdn.ieltslms.com/cdn/ielts/assets/img/icon-add-answer.svg" alt="" class="no-answer__img">
                    <h5 class="no-answer__title">AI Evaluation pending</h5>
                    <p>The AI evaluation is pending. Please check back in a few minutes.</p>
                </div>
            <?php } ?>
            <!--end::if AI - pending -->


            <!--begin::if AI - processing/started -->
            <?php if( in_array($review_status_value, array('processing','started'), true) ){ ?>
                <div class="no-answer">
                    <img src="https://cdn.ieltslms.com/cdn/ielts/assets/img/icon-add-answer.svg" alt="" class="no-answer__img">
                    <h5 class="no-answer__title">Evaluation in progress</h5>
                    <p>The AI evaluation is currently processing. Please check back in a few minutes.</p>
                </div>
            <?php } ?>
            <!--end::if AI - processing/started -->

            <!--begin::if AI - failed -->
            <?php if( $review_status_value === 'failed' ) { 
                $log_message = '';
                if( is_array($review_log_entry) && isset($review_log_entry['message']) ){
                    $log_message = $review_log_entry['message'];
                }
                ?>
                <div class="no-answer">
                    <img src="https://cdn.ieltslms.com/cdn/ielts/assets/img/icon-add-answer.svg" alt="" class="no-answer__img">
                    <h5 class="no-answer__title">Evaluation failed</h5>
                    <p><?php echo esc_html($log_message ?: 'AI evaluation failed. Please try again.'); ?></p>
                    <?php if($this->review){ ?>
                        <form class="generate-speaking-ai-evaluation" data-context="<?php echo esc_attr($evaluation_context); ?>">
                            <div class="notice__area"></div>
                            <input type="hidden" id="result-id" name="result-id" value="<?php echo esc_attr($this->result_id); ?>" />
                            <input type="hidden" name="context" value="<?php echo esc_attr($evaluation_context); ?>" />
                            <button 
                                style="max-width:100%;" 
                                class="service-price-box__btn iot-grbt -pink" 
                                type="submit"
                            >
                                Retry Evaluation
                            </button>
                        </form>
                    <?php } ?>
                </div>
            <?php } ?>    
            <!--end::if AI - failed -->

            <!--begin::if AI - completed -->
            <?php
            if( $review_status_value === 'completed' ) { 
                if(!empty($ai_response_data)){
                    
                    $ai_response_data = (array) $ai_response_data;
                    $transcript_schema = isset($ai_schema_payload) && is_array($ai_schema_payload)? $ai_schema_payload : [];
                    $transcript_issue_lookup = [];
                    if(!empty($ai_response_data['transcript-issues']) && is_array($ai_response_data['transcript-issues'])){
                        foreach($ai_response_data['transcript-issues'] as $issue){
                            $normalized_issue = $this->normalize_ai_transcript_issue($issue);
                            if(!$normalized_issue){
                                continue;
                            }
                            $qid = $normalized_issue['question_id'];
                            if(empty($transcript_issue_lookup[$qid])){
                                $transcript_issue_lookup[$qid] = [];
                            }
                            $transcript_issue_lookup[$qid][] = $normalized_issue;
                        }
                    }
                    $cards = [];
                    if(!empty($ai_response_data['overall'])){ $cards[] = 'overall'; }
                    if(!empty($ai_response_data['per-part'])){ /* $cards[] = 'per-part'; */ }
                    if(!empty($ai_response_data['highlights'])){ /* $cards[] = 'highlights'; */ }
                    foreach($ai_categories as $key => $_label){
                        if(!empty($ai_response_data[$key])){ $cards[] = $key; }
                    }

                    /**
                     * 
                     */
                    if (is_array($this->sections) && count($this->sections) > 0) {
                        foreach ($this->sections as $i => $s) {
                            $s = (object) $s;
                            $parts[] = [
                                'index' => $i,
                                'label' => 'Part '.($i+1),
                                'subtitle' => isset($s->title)? $s->title : '',
                                'band' => isset($bands_by_index[$i]) ? $bands_by_index[$i] : null
                            ];
                        }
                    }

                    $pre_part_summary = [];
                    $transcript_allowed_tags = [
                        'mark' => [
                            'class' => [],
                            'title' => [],
                            'data-duration' => [],
                        ]
                    ];
                    if(!empty($ai_response_data['per-part']) && is_array($this->sections) && count($this->sections) > 0){
                        $per_part_summary_ai = (array) $ai_response_data['per-part'];
                        foreach($per_part_summary_ai as $part_index => $part_summary){
                            if(isset($this->sections[$part_index])){
                                $part_title = $this->sections[$part_index]->title;
                                $part_summary = (array) $part_summary;
                                $pre_part_summary[$part_index] = [
                                    'part' => $part_index + 1,
                                    'summary' => $part_summary['summary'],
                                    'band' => $part_summary['band'],
                                    'title' => $part_title,
                                    'audio_url' => isset($this->ai_audio_sections[$part_index]) ? $this->ai_audio_sections[$part_index]['audio_url'] : '',
                                    'icon' => site_url() . '/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/img/ielts/speaking/part/'.($part_index + 1).'.png',
                                ];
                                $part_questions = [];
                                if(!empty($transcript_schema[$part_index]['questions']) && is_array($transcript_schema[$part_index]['questions'])){
                                    foreach($transcript_schema[$part_index]['questions'] as $q_index => $q_summary){
                                        $q_summary = (array) $q_summary;
                                        $qid = isset($q_summary['question_id']) ? (string) $q_summary['question_id'] : '';
                                        $question_label = trim(($q_index + 1).'. '.($q_summary['question'] ?? ''));
                                        $transcript_text = $q_summary['transcript'] ?? '';
                                        $question_issues = $qid && !empty($transcript_issue_lookup[$qid]) ? (array) $transcript_issue_lookup[$qid] : [];

                                        if(!empty($question_issues)){
                                            foreach($question_issues as &$issue_item){
                                                $issue_item['type_slug'] = !empty($issue_item['type_slug']) ? $issue_item['type_slug'] : 'general';
                                                $issue_item['type_label'] = !empty($issue_item['type_label']) ? (string) $issue_item['type_label'] : __('General','spacetree');
                                            }
                                            unset($issue_item);
                                        }

                                        if(!empty($transcript_text) && !empty($question_issues)){
                                            $highlighted_transcript = $transcript_text;
                                            foreach($question_issues as $issue_item){
                                                $snippet = isset($issue_item['text']) ? trim($issue_item['text']) : '';
                                                if(!$snippet){ continue; }
                                                $pattern = '/' . preg_quote($snippet, '/') . '/iu';
                                                $mark_classes = 'issue-mark issue-type-'.sanitize_html_class($issue_item['type_slug'] ?? 'general');
                                                $tooltip_text = trim((string) ($issue_item['issue'] ?? ''));
                                                if(!empty($issue_item['suggestions_text'])){
                                                    $tooltip_suffix = trim((string) $issue_item['suggestions_text']);
                                                    $tooltip_text = $tooltip_text ? $tooltip_text . ' → ' . $tooltip_suffix : $tooltip_suffix;
                                                }
                                                $replacement = sprintf('<mark class="%s" title="%s">$0</mark>', esc_attr($mark_classes), esc_attr(trim($tooltip_text)));
                                                $highlighted_transcript = preg_replace($pattern, $replacement, $highlighted_transcript, 1);
                                            }
                                            $transcript_text = $highlighted_transcript;
                                        }

                                        $part_questions[] = [
                                            'question_label' => $question_label,
                                            'question' => $q_summary['question'] ?? '',
                                            'transcript' => $transcript_text,
                                            'transcript_html' => $q_summary['transcript_html'] ?? '',
                                            'timing' => isset($q_summary['timing']) ? (array) $q_summary['timing'] : [],
                                            'issues' => $question_issues,
                                        ];
                                    }
                                }
                                if(!empty($part_questions)){
                                    $pre_part_summary[$part_index]['questions_display'] = $part_questions;
                                }
                            }
                            
                        }
                    }

                    # displays overall band score and overview feedback
                    if(!empty($ai_response_data['overall'])){
                        $overall = (array) $ai_response_data['overall'];
                        $overall_band = max(0, min(9, (float) ($overall['band'] ?? 0)));
                        $overall_percent = ($overall_band / 9) * 100;
                        $dash_offset = 314 - (314 * $overall_percent / 100);

                        # we also have fluency & coherence score, lexical resource score, grammatical range and accuracy score, and pronunciation score
                        ?>
                        <div class="part-score"> 
                            <span class="part-score__text">Overall score:</span> 
                            <span class="part-score__val"><?php echo esc_html($overall['band'] ?? '-'); ?></span>
                        </div>
                        <!--begin::overall feedback-->
                        <div class="row">
                            <div class="col-xs-12 col-sm-12">
                                <div class="form-group evaluation__item-card"> 
                                    <label for="textarea" class="evaluation__item-title">Overall Feedback</label>
                                    <div class="evaluation__score" style="display:none;"></div>
                                    <div class="form-control evaluation__item-comment" disabled="disabled" style="height:100%;">
                                        <div style="max-height: 100%; overflow: auto">
                                            <?php echo esc_html($overall['feedback']); ?>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            

                            <!--begin::highlights-->
                            <?php if(!empty($ai_response_data['highlights'])){ ?>
                                <div class="col-xs-12 col-sm-12">
                                    <div class="form-group evaluation__item-card"> 
                                        <label for="textarea" class="evaluation__item-title">Highlights</label>
                                        <div class="form-control evaluation__item-comment" disabled="disabled" style="height:100%;">
                                            <div style="max-height: 100%; overflow: auto">
                                                <?php foreach($ai_response_data['highlights'] as $highlight){ ?>
                                                    <li><?php echo esc_html($highlight); ?></li>
                                                <?php } ?>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            <?php } ?>
                            <!--end::highlights-->
                        </div>
                        <div class="row d-flex flex-row" style="flex-wrap:wrap;">

                            <!--begin::[fluency/lexical/grammatical/pronunciation] scores and feedback-->
                            <?php foreach($ai_categories as $key => $_label){ ?>
                            <div class="col-xs-12 col-sm-6">
                                <div class="form-group evaluation__item-card"> 
                                    <label for="textarea" class="evaluation__item-title"><?php echo esc_html($_label['label']); ?></label>
                                    <div class="evaluation__score"><?php echo isset($ai_response_data[$key]['band'])? number_format(floatval($ai_response_data[$key]['band']), 1) : 0; ?></div>
                                    <div class="form-control evaluation__item-comment" disabled="disabled" style="height:100%;">
                                        <div style="max-height: 100%; overflow: auto">
                                            <?php echo isset($ai_response_data[$key]['feedback'])? esc_html($ai_response_data[$key]['feedback']) : ''; ?>
                                            <?php if(count($ai_response_data[$key]['strengths']) > 0){ ?><div class="ai-feedback-strengths" style="margin-top:10px;">
                                                <strong>Strengths:</strong>
                                                <ul class="ai-feedback-strengths-list">
                                                    <?php foreach($ai_response_data[$key]['strengths'] as $strength){ ?>
                                                        <li><?php echo esc_html($strength); ?></li>
                                                    <?php } ?>
                                                </ul>
                                            </div><?php } ?>
                                            <?php if(count($ai_response_data[$key]['weaknesses']) > 0){ ?><div class="ai-feedback-weaknesses" style="margin-top:10px;">
                                                <strong>Weaknesses:</strong>
                                                <ul class="ai-feedback-weaknesses-list">
                                                    <?php foreach($ai_response_data[$key]['weaknesses'] as $weakness){ ?>
                                                        <li><?php echo esc_html($weakness); ?></li>
                                                    <?php } ?>
                                                </ul>
                                            </div><?php } ?>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <?php } ?>
                            <!--end::[fluency/lexical/grammatical/pronunciation] scores and feedback-->

                        </div>
                        <!--end::overall feedback-->
                        
                        <?php 

                    } ?>

                    <!--begin::pre part summary custom design--> 
                    <?php if(!empty($pre_part_summary)){ ?>
                        <div style="margin: 20px auto;">
                            <div class="visible-lg visible-md">
                                <!--begin::desktop view-->
                                <ul class="nav nav-tabs speaking-tabs" role="tablist" aria-label="IELTS Speaking Parts">
                                    <?php foreach($pre_part_summary as $part_index => $part_summary){ ?>
                                        <li class="<?php echo $part_index == 0? 'active' : ''; ?>" role="presentation">
                                            <a data-toggle="tab" href="#p<?php echo esc_attr($part_summary['part']); ?>" role="tab" aria-controls="p<?php echo esc_attr($part_summary['part']); ?>" aria-selected="true">
                                                <div class="tab-box">
                                                    <img src="<?php echo esc_attr($part_summary['icon']); ?>" class="tab-icon" alt="Part <?php echo esc_attr($part_summary['part']); ?> icon" />
                                                    <div class="tab-text">
                                                        <span class="tab-title">Part <?php echo esc_attr($part_index + 1); ?></span>
                                                        <span class="tab-subtitle"><?php echo esc_html($part_summary['title']); ?></span>
                                                    </div>
                                                </div>
                                            </a>
                                        </li>
                                    <?php } ?>
                                </ul>
                                <div class="tab-content">
                                    <?php foreach($pre_part_summary as $part_index => $part_summary){ ?>
                                        <div id="p<?php echo esc_attr($part_summary['part']); ?>" class="tab-pane fade <?php echo $part_index == 0? 'in active' : ''; ?>">
                                            <div class="form-control evaluation__item-comment" disabled="disabled" style="height:100%;">
                                                <div style="max-height: 100%; overflow: auto">
                                                    <?php echo esc_html($part_summary['summary']); ?>
                                                </div>
                                            </div>
                                            <!--begin::part wise transcripts with issues--> 
                                            <?php if(!empty($part_summary['questions_display']) && is_array($part_summary['questions_display'])){ ?>
                                                <div class="form-group evaluation__item-card">
                                                    <label class="evaluation__item-title" style="margin-top:15px;">
                                                        <?php esc_html_e('Questions Transcript details','spacetree'); ?>
                                                    </label>
                                                    
                                                    <div class="form-control evaluation__item-comment" disabled="disabled" style="height:100%;">
                                                        <div class="part__audio-player">
                                                            <audio 
                                                                data-audio-url="<?php echo esc_url($part_summary['audio_url']); ?>"
                                                                data-part-index="<?php echo $part_index; ?>"  
                                                                id="ai-audio-player-<?php echo $part_index; ?>"  
                                                                class="part__audio-player__audio ai-audio-player" 
                                                                src="<?php echo esc_url($part_summary['audio_url']); ?>" 
                                                                controls
                                                            ></audio>
                                                        </div>
                                                        <div style="max-height: 100%; overflow: auto">
                                                            <?php foreach($part_summary['questions_display'] as $question_block){ ?>
                                                                <div class="ai-question-block" style="padding:0;">
                                                                    <?php if(!empty($question_block['question_label'])){ ?>
                                                                        <div class="ai-question-title" style="border-bottom:1px solid #e5e7f0;padding:10px 10px 10px;">
                                                                            <?php echo esc_html($question_block['question_label']); ?>
                                                                        </div>
                                                                    <?php } ?>
                                                                    <!-- <?php if(!empty($question_block['question'])){ ?>
                                                                        <div class="ai-question-text"><?php echo esc_html($question_block['question']); ?></div>
                                                                    <?php } ?> -->
                                                                    <?php
                                                                        $transcript_render = '';
                                                                        if(!empty($question_block['transcript_html'])){
                                                                            $transcript_render = $question_block['transcript_html'];
                                                                        } elseif(!empty($question_block['transcript'])){
                                                                            $transcript_render = $question_block['transcript'];
                                                                        }
                                                                    ?>
                                                                    <?php if($transcript_render !== ''){ ?>
                                                                        <p class="ai-eval__transcript-text" style="margin:6px 0 0; padding:10px 10px;">
                                                                            <strong>Answer:</strong>
                                                                            <?php echo wp_kses($transcript_render, $transcript_allowed_tags); ?>
                                                                        </p>
                                                                    <?php } else { ?>
                                                                        
                                                                        <p class="ai-eval__transcript-text" style="margin:6px 0 0; padding:10px 10px;">
                                                                            <strong>Answer:</strong>
                                                                            <?php echo esc_html__('No answer provided','spacetree'); ?>
                                                                        </p>
                                                                        <?php
                                                                    } ?>
                                                                    <?php if(!empty($question_block['timing'])){ 
                                                                        $timing = (object) $question_block['timing'];
                                                                    ?>
                                                                        <div class="ai-question-timing" style="padding:0px 10px;">
                                                                            <?php if(isset($timing->pre_response_pause)){ ?>
                                                                                <span class="ai-question-timing__item"><?php printf(__('Prep pause: %ss','spacetree'), number_format((float) $timing->pre_response_pause, 2)); ?></span>
                                                                            <?php } ?>
                                                                            <?php if(isset($timing->response_duration)){ ?>
                                                                                <span class="ai-question-timing__item"><?php printf(__('Answer length: %ss','spacetree'), number_format((float) $timing->response_duration, 2)); ?></span>
                                                                            <?php } ?>
                                                                        </div>
                                                                        <?php if(!empty($timing->hesitations) && is_array($timing->hesitations)){ ?>
                                                                            <div class="ai-question-hesitations" style="padding:0px 10px;">
                                                                                <strong>Hesitations:</strong>
                                                                                <ul class="ai-question-hesitations">
                                                                                    <?php foreach($timing->hesitations as $hesitation){ 
                                                                                        $duration = isset($hesitation['duration']) ? (float) $hesitation['duration'] : null;
                                                                                        $after_word = isset($hesitation['after_word']) ? $hesitation['after_word'] : '';
                                                                                    ?>
                                                                                        <li>
                                                                                            <?php
                                                                                                if($duration){
                                                                                                    printf(__('Pause <b class="text-danger">%ss</b>','spacetree'), number_format($duration, 2));
                                                                                                } else {
                                                                                                    esc_html_e('Pause <b class="text-success">0s</b>','spacetree');
                                                                                                }
                                                                                            ?>
                                                                                            <?php if(!empty($after_word)){ ?>
                                                                                                <span><?php printf(__('before <b class="text-danger">"%s"</b>','spacetree'), esc_html($after_word)); ?></span>
                                                                                            <?php } ?>
                                                                                        </li>
                                                                                    <?php } ?>
                                                                                </ul>
                                                                            </div>
                                                                        <?php } ?>
                                                                    <?php } ?>

                                                                    <?php if(!empty($question_block['issues'])){ ?>
                                                                        <div class="ai-question-fixes" style="background:#edffd7;padding:10px 10px 10px;">
                                                                            <?php foreach($question_block['issues'] as $issue){
                                                                                $issue_types = !empty($issue['issue_types']) && is_array($issue['issue_types']) ? $issue['issue_types'] : [];
                                                                                foreach($issue_types as $type_entry){
                                                                                    $issue_label = !empty($type_entry['label']) ? $type_entry['label'] : (!empty($issue['type_label']) ? $issue['type_label'] : __('General','spacetree'));
                                                                                    $suggestions = !empty($type_entry['suggestions']) ? (array) $type_entry['suggestions'] : [];
                                                                                    foreach($suggestions as $suggestion_text){
                                                                                        $suggestion_text = trim((string) $suggestion_text);
                                                                                        if($suggestion_text === ''){
                                                                                            continue;
                                                                                        }
                                                                            ?>
                                                                                        <div class="ai-question-fix">
                                                                                            <strong><?php echo esc_html($issue_label); ?>:</strong>
                                                                                            <?php echo esc_html($suggestion_text); ?>
                                                                                        </div>
                                                                            <?php
                                                                                    }
                                                                                }
                                                                            } ?>
                                                                        </div>
                                                                    <?php } ?>
                                                                </div>
                                                                <?php if(!empty($question_block['issues'])){ ?>
                                                                    <div class="ai-issue-block ">
                                                                    
                                                                            <?php foreach($question_block['issues'] as $issue){
                                                                                $issue_types = !empty($issue['issue_types']) && is_array($issue['issue_types']) ? $issue['issue_types'] : [];
                                                                                foreach($issue_types as $type_entry){
                                                                                    $issue_slug = !empty($type_entry['slug']) ? sanitize_html_class($type_entry['slug']) : sanitize_html_class($issue['type_slug'] ?? 'general');
                                                                                    $issue_label = !empty($type_entry['label']) ? $type_entry['label'] : (!empty($issue['type_label']) ? $issue['type_label'] : __('General','spacetree'));
                                                                                    $suggestion_values = [];
                                                                                    if(!empty($type_entry['suggestions'])){
                                                                                        foreach((array) $type_entry['suggestions'] as $suggestion_value){
                                                                                            $suggestion_value = trim((string) $suggestion_value);
                                                                                            if($suggestion_value !== ''){
                                                                                                $suggestion_values[] = $suggestion_value;
                                                                                            }
                                                                                        }
                                                                                    }
                                                                                    $suggestions = !empty($suggestion_values) ? implode(' | ', $suggestion_values) : '';
                                                                                    $tooltip = trim(($issue['issue']));
                                                                            ?>
                                                                            <div class="ai-question-issues">
                                                                                <div class="d-flex flex-row flex-start align-items-center">
                                                                                    <span class="issue-pill issue-type-<?php echo esc_attr($issue_slug); ?>" title="<?php echo esc_attr($tooltip); ?>">
                                                                                        <?php echo esc_html($issue_label); ?>
                                                                                    </span>
                                                                                    <div class="isssue-reason" style="margin-left:10px;"><?php echo esc_html($issue['issue']); ?></div>
                                                                                </div>
                                                                            </div>
                                                                                    <!-- <span class="issue-pill issue-type-<?php echo esc_attr($issue_slug); ?>" title="<?php echo esc_attr($tooltip); ?>">
                                                                                        <?php echo esc_html($issue_label); ?>
                                                                                    </span> -->
                                                                            <?php
                                                                                }
                                                                            } ?>
                                                                    </div>
                                                                <?php } ?>
                                                            <?php } ?>
                                                        </div>
                                                    </div>
                                                </div>
                                            <?php } ?>
                                            <!--end::part wise transcripts with issues-->
                                        </div>
                                    <?php } ?>
                                </div>
                                <!--end::desktop view-->
                            </div>
                            <!--begin::mobile view-->
                            <div class="visible-sm visible-xs" style="border-top:1px solid;">
                                <h3 style="text-align:center;margin-bottom:20px;">Part Summary</h3>
                                <div class="panel-group" id="mobileAccordion">
                                    <?php foreach($pre_part_summary as $part_index => $part_summary){ ?>
                                        <div class="panel panel-default">
                                            <div class="panel-heading">
                                                <h4 class="panel-title">
                                                    <a data-toggle="collapse" data-parent="#mobileAccordion" href="#m-tab-<?php echo $part_index; ?>" style="display:flex;align-items:center;gap:15px;">
                                                        <img src="<?php echo esc_attr($part_summary['icon']); ?>" class="tab-icon" alt="Part <?php echo esc_attr($part_summary['part']); ?> icon" />
                                                        <div class="tab-text">
                                                            <span class="tab-title">Part <?php echo esc_attr($part_summary['part']); ?></span>
                                                            <span class="tab-subtitle"><?php echo esc_html($part_summary['title']); ?></span>
                                                        </div>
                                                    </a>
                                                </h4>
                                            </div>
                                            <div id="m-tab-<?php echo esc_attr($part_index); ?>" class="panel-collapse collapse <?php echo $part_index == 0? 'in' : ''; ?>">
                                                <div class="panel-body" id="content-mobile-<?php echo esc_attr($part_summary['part']); ?>">
                                                    <?php echo esc_html($part_summary['summary']); ?>
                                                    <?php if(!empty($part_summary['questions_display']) && is_array($part_summary['questions_display'])){ ?>
                                                        <div class="form-group evaluation__item-card">
                                                            <label class="evaluation__item-title" style="margin-top:15px;">
                                                                <?php esc_html_e('Questions Transcript details','spacetree'); ?>
                                                            </label>
                                                            
                                                            <div class="form-control evaluation__item-comment" disabled="disabled" style="height:100%;">
                                                                <div class="part__audio-player">
                                                                    <audio 
                                                                        data-audio-url="<?php echo esc_url($part_summary['audio_url']); ?>"
                                                                        data-part-index="<?php echo $part_index; ?>"  
                                                                        id="ai-audio-player-<?php echo $part_index; ?>"  
                                                                        class="part__audio-player__audio ai-audio-player" 
                                                                        src="<?php echo esc_url($part_summary['audio_url']); ?>" 
                                                                        controls
                                                                    ></audio>
                                                                </div>
                                                                <div style="max-height: 100%; overflow: auto">
                                                                    <?php foreach($part_summary['questions_display'] as $question_block){ ?>
                                                                        <div class="ai-question-block" style="padding:0;">
                                                                            <?php if(!empty($question_block['question_label'])){ ?>
                                                                                <div class="ai-question-title" style="border-bottom:1px solid #e5e7f0;padding:8px 8px 8px;">
                                                                                    <?php echo esc_html($question_block['question_label']); ?>
                                                                                </div>
                                                                            <?php } ?>
                                                                            <?php
                                                                                $transcript_render = '';
                                                                                if(!empty($question_block['transcript_html'])){
                                                                                    $transcript_render = $question_block['transcript_html'];
                                                                                } elseif(!empty($question_block['transcript'])){
                                                                                    $transcript_render = $question_block['transcript'];
                                                                                }
                                                                            ?>
                                                                            <?php if($transcript_render !== ''){ ?>
                                                                                <p class="ai-eval__transcript-text" style="margin:6px 0 0; padding:8px 8px;">
                                                                                    <strong>Answer:</strong> <?php echo wp_kses($transcript_render, $transcript_allowed_tags); ?>
                                                                                </p>
                                                                            <?php } else { ?>
                                                                                <p class="ai-eval__transcript-text" style="margin:6px 0 0;">
                                                                                    <strong>Answer:</strong> <?php echo esc_html__('No answer provided','spacetree'); ?>
                                                                                </p>
                                                                            <?php } ?>

                                                                            <?php if(!empty($question_block['timing'])){ 
                                                                                $timing = (object) $question_block['timing'];
                                                                            ?>
                                                                                <div class="ai-question-timing">
                                                                                    <?php if(isset($timing->pre_response_pause)){ ?>
                                                                                        <span class="ai-question-timing__item"><?php printf(__('Prep pause: %ss','spacetree'), number_format((float) $timing->pre_response_pause, 2)); ?></span>
                                                                                    <?php } ?>
                                                                                    <?php if(isset($timing->response_duration)){ ?>
                                                                                        <span class="ai-question-timing__item"><?php printf(__('Answer length: %ss','spacetree'), number_format((float) $timing->response_duration, 2)); ?></span>
                                                                                    <?php } ?>
                                                                                </div>
                                                                                <?php if(!empty($timing->hesitations) && is_array($timing->hesitations)){ ?>
                                                                                    <ul class="ai-question-hesitations">
                                                                                        <?php foreach($timing->hesitations as $hesitation){ 
                                                                                            $duration = isset($hesitation['duration']) ? (float) $hesitation['duration'] : null;
                                                                                            $after_word = isset($hesitation['after_word']) ? $hesitation['after_word'] : '';
                                                                                        ?>
                                                                                            <li>
                                                                                                <?php
                                                                                                    if($duration){
                                                                                                        printf(__('Pause %ss','spacetree'), number_format($duration, 2));
                                                                                                    } else {
                                                                                                        esc_html_e('Pause','spacetree');
                                                                                                    }
                                                                                                ?>
                                                                                                <?php if(!empty($after_word)){ ?>
                                                                                                    <span><?php printf(__('before "%s"','spacetree'), esc_html($after_word)); ?></span>
                                                                                                <?php } ?>
                                                                                            </li>
                                                                                        <?php } ?>
                                                                                    </ul>
                                                                                <?php } ?>
                                                                            <?php } ?>

                                                                            <?php if(!empty($question_block['issues'])){ ?>
                                                                                <div class="ai-question-fixes" style="background:#edffd7;padding:8px 8px 8px;">
                                                                                    <?php foreach($question_block['issues'] as $issue){
                                                                                        $issue_types = !empty($issue['issue_types']) && is_array($issue['issue_types']) ? $issue['issue_types'] : [];
                                                                                        foreach($issue_types as $type_entry){
                                                                                            $issue_label = !empty($type_entry['label']) ? $type_entry['label'] : (!empty($issue['type_label']) ? $issue['type_label'] : __('General','spacetree'));
                                                                                            $suggestions = !empty($type_entry['suggestions']) ? (array) $type_entry['suggestions'] : [];
                                                                                            foreach($suggestions as $suggestion_text){
                                                                                                $suggestion_text = trim((string) $suggestion_text);
                                                                                                if($suggestion_text === ''){
                                                                                                    continue;
                                                                                                }
                                                                                    ?>
                                                                                                <div class="ai-question-fix">
                                                                                                    <strong><?php echo esc_html($issue_label); ?>:</strong>
                                                                                                    <?php echo esc_html($suggestion_text); ?>
                                                                                                </div>
                                                                                    <?php
                                                                                            }
                                                                                        }
                                                                                    } ?>
                                                                                </div>
                                                                                <?php if(!empty($question_block['issues'])){ ?>
                                                                                    <div class="ai-issue-block ">
                                                                                        <?php foreach($question_block['issues'] as $issue){
                                                                                            $issue_types = !empty($issue['issue_types']) && is_array($issue['issue_types']) ? $issue['issue_types'] : [];
                                                                                            foreach($issue_types as $type_entry){
                                                                                                $issue_slug = !empty($type_entry['slug']) ? sanitize_html_class($type_entry['slug']) : sanitize_html_class($issue['type_slug'] ?? 'general');
                                                                                                $issue_label = !empty($type_entry['label']) ? $type_entry['label'] : (!empty($issue['type_label']) ? $issue['type_label'] : __('General','spacetree'));
                                                                                                $suggestion_values = [];
                                                                                                if(!empty($type_entry['suggestions'])){
                                                                                                    foreach((array) $type_entry['suggestions'] as $suggestion_value){
                                                                                                        $suggestion_value = trim((string) $suggestion_value);
                                                                                                        if($suggestion_value !== ''){
                                                                                                            $suggestion_values[] = $suggestion_value;
                                                                                                        }
                                                                                                    }
                                                                                                }
                                                                                                $suggestions = !empty($suggestion_values) ? implode(' | ', $suggestion_values) : '';
                                                                                                $tooltip = trim(($issue['issue'] ?? '').($suggestions ? ' | '.sprintf(__('Fix: %s','spacetree'), $suggestions) : ''));
                                                                                                ?>
                                                                                                <div class="ai-question-issues">
                                                                                                    <div class="d-flex flex-row flex-start align-items-center">
                                                                                                        <span class="issue-pill issue-type-<?php echo esc_attr($issue_slug); ?>" title="<?php echo esc_attr($tooltip); ?>">
                                                                                                            <?php echo esc_html($issue_label); ?>
                                                                                                        </span>
                                                                                                        <div class="isssue-reason" style="margin-left:10px;"><?php echo esc_html($issue['issue']); ?></div>
                                                                                                    </div>
                                                                                                </div>
                                                                                                <?php 
                                                                                            }
                                                                                        } ?>
                                                                                    </div>
                                                                                <?php } ?>
                                                                            <?php } ?>
                                                                        </div>
                                                                    <?php } ?>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    <?php } ?>
                                                </div>
                                            </div>
                                        </div>
                                    <?php } ?>
                                </div>
                            </div>
                            <!--end::mobile view-->

                        </div>
                    <?php } ?>
                    <!--end::pre part summary custom design-->
                    
                <?php }
            }

            # only visible to teacher or admin - ai controls
            if( $review_status_value === 'completed' && $this->review) { ?>
            <div class="d-flex md:flex-row align-items-center justify-content-center sm:flex-column" style="">
                
                <div class="retry--ai-evaluation-card card w-100" style="width:100%;text-align:center;">
                    <div class="card-body">
                        <h5 class="card-title">Retry AI Evaluation</h5>
                        <p class="card-text">This option will retry the AI evaluation, allowing students to review the AI evaluation again.</p>
                        <form class="generate-speaking-ai-evaluation">
                            <input type="hidden" name="result-id" value="<?php echo esc_attr($this->result_id); ?>" />
                            <input type="hidden" name="context" value="<?php echo $this->review? "teacher" : "student"; ?>" />
                            <button 
                                style="max-width:100%;" 
                                class="service-price-box__btn iot-grbt -pink" 
                                type="submit"
                            >
                                Retry Evaluation
                            </button>
                        </form>
                    </div>
                </div>
                
            </div>
            
            <?php } ?>
            <?php if( $review_status_value === 'completed' || $review_status_value === 'failed'){ 
                echo $this->get_speaking_review_reason_panel(); 
            } ?>
            
            
            <!--end::if AI - completed -->

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

    
    /**
     * status: completed
     * v2.1.0
     * speaking review reason panel
     */
    public function get_speaking_review_reason_panel(){
        global $wpdb,$table_proqyz_v3_submissions_review_meta;
        $review_id = $this->review_id;
        $result_id = $this->result_id;
        $reason_data = (object) [
            "status" => false,
            "reason" => ""
        ];

        if($review_id){
            $reason_key = $wpdb->get_row("SELECT `meta_value` FROM {$table_proqyz_v3_submissions_review_meta} WHERE `meta_key` = 're-evaluation' AND `review_id` = '$review_id' AND `meta_status` = 1 LIMIT 1");
            if( $reason_key ) {
                $reason_data = (object) maybe_unserialize($reason_key->meta_value);
            }
        }

        # if its student then show submittion form for reset evaluation request and reason for re-evaluation
        if(!$this->review){ 
            ob_start(); ?>
            <div class="row" style="margin-top:5px;">
                <div class="col-md-12">
                    <form class="proqyz-student--submit-reevaluation-request-speaking" style="">
                        
                        <div class="alert alert-info row" style="margin:0 auto 10px;">
                            <p style="margin:0;">Request for <b>Re-Evaluation</b> (When you submit a re-evaluation request, the instructor will review it and remove the current evaluation if needed.)</p>
                        </div>
                        <div class="notice__area"></div>
                        <div class="form-group">
                            <label for="reason">Reason of Re-Evaluation</label>
                            <textarea required class="form-control" id="reason" rows="3" placeholder="Explanation or reason here"><?php echo $reason_data->reason; ?></textarea>
                        </div>
                        <div class="form-group">
                            <input type="hidden" name="section-id" id="section-id" value="<?php echo $section_id; ?>" />
                            <input type="hidden" name="result-id" id="result-id" value="<?php echo $result_id; ?>" />
                            <button class="btn btn-primary btn-sumit"  type="submit">
                            <?php echo $reason_data->status? 'Re-Send Request' : 'Send Request'; ?>
                            </button>
                        </div>
                    </form>
                </div>
            </div>
            <?php return ob_get_clean();
        }

        # if its teacher then show reset evaluation button and reason for re-evaluation
        if($this->review){
            ob_start(); ?>
            
            <?php if($reason_data->status){ ?>
            <div class="d-block" style="margin: 10px 0;">    
                <div class="alert alert-warning" style="width:100%;margin:0 auto;">
                    <p><b>Reason by Student (for Re-Evaluation)</b>: <?php echo $reason_data->reason; ?></p>
                </div>
            </div>
            <?php } ?>
            
            <?php return ob_get_clean();
        }
    }



    /**
     * v2.1.0
     * description: show ai evaluation not started panel
     */
    public function ai_evaluation_not_started_panel() {
        ob_start();
        ?>
        <div class="evaluation-widget -recommended ">
                            <div class="evaluation-widget__label">Most popular</div>
                            <div class="evaluation-widget__discount" style="display: none;">SAVE 0%</div>
                            <div class="evaluation-widget__img-wrap"> 
                                <img 
                                    class="lazy evaluation-widget__img loaded" 
                                    src="<?php echo site_url(); ?><?php echo $this->ielts_url; ?>/img/ielts/icons/ai-icon.svg" 
                                    alt="" 
                                    data-ll-status="loaded"
                                />
                            </div>
                            <div class="evaluation-widget__cap">IELTS SPEAKING</div>
                            <h2 class="evaluation-widget__title">AI Evaluation</h2>
                            <div class="evaluation-widget__desc">Get your band score instantly using AI.</div>
                            <form class="generate-speaking-ai-evaluation" style="margin-top: 10px;">
                                <input type="hidden" name="context" value="student" /> 
                                <input type="hidden" name="result-id" value="<?php echo esc_attr($this->result_id); ?>" />
                                <button 
                                    style="max-width:100%;" 
                                    class="service-price-box__btn iot-grbt -pink" 
                                    type="submit"
                                >
                                    Generate now
                                </button>
                                <div class="notice__area" style="margin-top: 10px;"></div>
                            </form>
                        </div>
        <?php
        return ob_get_clean();
    }



    /**
     * v2.1.0
     * type: evaluation cards by type
     * param: default, ai, instructor etc
     */
    public function get_evaluation_status($for = 'default') {
        ob_start();
        if($for == 'default' || $for == 'instructor') { ?>
            <div class="evaluation-widget -recommended ">
                <div class="evaluation-widget__label">Most popular</div>
                <div class="evaluation-widget__discount" style="display: none;">SAVE 0%</div>
                <div class="evaluation-widget__img-wrap"> 
                    <img 
                        class="lazy evaluation-widget__img loaded" 
                        src="<?php echo site_url(); ?><?php echo $this->ielts_url; ?>/img/ielts/icons/teacher-icon.svg" 
                        alt="" 
                        data-ll-status="loaded"
                    />
                </div>
                <div class="evaluation-widget__cap">IELTS SPEAKING</div>
                <h2 class="evaluation-widget__title">Examiner Evaluation</h2>
                <div class="evaluation-widget__desc">Your task is under evaluation. You will be informed by email when the evaluation is completed.</div>
            </div>
        <?php } else if($for == 'ai') { ?>
            <div class="evaluation-widget -recommended ">
                <div class="evaluation-widget__label">Most popular</div>
                <div class="evaluation-widget__discount" style="display: none;">SAVE 0%</div>
                <div class="evaluation-widget__img-wrap"> 
                    <img 
                        class="lazy evaluation-widget__img loaded" 
                        src="<?php echo site_url(); ?><?php echo $this->ielts_url; ?>/img/ielts/icons/ai-icon.svg" 
                        alt="" 
                        data-ll-status="loaded"
                    />
                </div>
                <div class="evaluation-widget__cap">IELTS SPEAKING</div>
                <h2 class="evaluation-widget__title">AI Evaluation</h2>
                <div class="evaluation-widget__desc">Get your band score instantly using AI.</div>
                <form class="generate-speaking-ai-evaluation" style="margin-top: 10px;">
                    <input type="hidden" name="context" value="student" /> 
                    <input type="hidden" name="result-id" value="<?php echo esc_attr($this->result_id); ?>" />
                    <button 
                        style="max-width:100%;" 
                        class="service-price-box__btn iot-grbt -pink" 
                        type="submit"
                    >
                        Generate now
                    </button>
                    <div class="notice__area" style="margin-top: 10px;"></div>
                </form>
            </div>
        <?php }
        return ob_get_clean();
    }

    /**
     * v2.1.0 
     * type: evaluation notice for admin/teacher 
     */
    public function get_evaluation_notice() {
        ob_start();
        if($this->enrolled_reason === "woocommerce-disabled"){
            ?>
            <div class="alert alert-warning">
                <b>Evaluation:</b> Disabled, due to woocommerce plugin is disabled, so student can't enroll for this test
            </div>
            <?php
        } else if($this->enrolled_reason === "wp-evaluation-off"){
            ?>
            <div class="alert alert-warning">
                <b>Evaluation:</b> Disabled, due to ProQyz Evaluation setting is off, so student can't enroll for this test
            </div>
            <?php
        } else if($this->enrolled_reason === "plan-unavailable"){
            ?>
            <div class="alert alert-warning">
                <b>Evaluation:</b> Disabled, due to ProQyz Evaluation plans are unavailable or cost is 0, so student can't enroll for this test
            </div>
            <?php
        } else if($this->enrolled_reason === "course-free"){
            ?>
            <div class="alert alert-success">
                <b>Enrolled:</b> Student(s) enrolled for free (course is free)
            </div>
            <?php
        } else {
            if($this->is_enrolled && $this->enrolled_for == 'ai'){ ?>
                <div class="alert alert-success">
                    <b>Enrolled:</b> Student(s) purchased for AI Evaluation
                </div>
            <?php } else if($this->is_enrolled && $this->enrolled_for == 'instructor'){ ?>
                <div class="alert alert-success">
                    <b>Enrolled:</b> Student(s) purchased for Instructor Evaluation
                </div>
            <?php } else if(!$this->is_enrolled) { ?>
                <div class="alert alert-warning">
                    <b>Not Enroll:</b> Student(s) haven't enroll for this test yet
                </div>
            <?php }
        }
        return ob_get_clean();
    }





    /**
     * get plans sidebar
     */
    public function get_evalution_plans_layout() {
        global $wpdb, $ST_OPTION_st_proqyz_IELTS_LMS_speaking_evaluation_instructions, $ST_OPTION_st_proqyz_IELTS_LMS_ai_speaking_evaluation_instructions;

        $speaking_instructions      = get_option($ST_OPTION_st_proqyz_IELTS_LMS_speaking_evaluation_instructions,'');
        $ai_speaking_instructions   = get_option($ST_OPTION_st_proqyz_IELTS_LMS_ai_speaking_evaluation_instructions,'');
        $plan_selector              = "";
        
        ob_start();
        if( $this->instructor_task_plan || $this->AI_task_plan ){

            
            if( $this->instructor_task_plan ) { ?>
                <div class="card-successful__col">
                    <div class="card-successful__box service-price-box">
                        <div class="service-price-box__contents">
                            <img class="card-successful__img-icon" src="<?php echo site_url(); ?><?php echo $this->ielts_url; ?>/img/ielts/icons/teacher-icon.svg" alt="">
                            
                            <?php echo wp_kses_post(stripslashes($speaking_instructions)); ?>

                            <div class="service-price-box__price">
                                <div class="service-price-box__col-name">
                                    <div class="service-price-box__service-name">
                                        <?php echo $this->instructor_task_plan_details->title; ?>
                                    </div>
                                </div>
                            </div>
                            <div class="card-successful__price-wrap">
                                <div class="card-successful__price">
                                    <?php echo wp_kses_post($this->instructor_task_plan_details->price); ?>
                                </div>
                            </div>
                            <div class="service-price-box__btn-wrap clearfix"> 
                                <?php if( !$this->is_enrolled ){ ?>
                                    <form id="st-proqyz-ieltslms-evaluation-cart-form--speaking-instructor" class="st-proqyz-ieltslms-evaluation-cart-form">
                                        <input type="hidden" name="selected-task" value="speaking-tasks" /> 
                                        <input type="hidden" name="selected-result-id" value="<?php echo esc_attr($this->result_id); ?>" />
                                        <button 
                                            style="max-width:100%;" 
                                            class="service-price-box__btn iot-grbt -pink" 
                                            type="submit"
                                        >
                                            Buy Now <span class="ioticon-cart"></span>
                                        </button>
                                    </form>
                                    <?php echo apply_filters('st_proqyz_payment_addons', '', ['result_id' => $this->result_id, 'user_id' => $this->student_id, 'type' => 'speaking-instructor', 'form_id' => "st-proqyz-ieltslms-evaluation-cart-form--speaking-instructor" ]); ?>
                                <?php } else { ?>
                                    <div class="alert alert-success" style="margin-top:10px;">
                                        Instructor review already unlocked.
                                    </div>
                                <?php } ?>
                            </div>
                        </div>
                    </div>
                </div>
            <?php } ?>

            <?php if( $this->AI_task_plan ) { ?>
                <div class="card-successful__col">
                    <div class="card-successful__box service-price-box">
                        <div class="service-price-box__contents">
                            <img class="card-successful__img-icon" src="<?php echo site_url(); ?><?php echo $this->ielts_url; ?>/img/ielts/icons/ai-icon.svg" alt="">

                            <?php echo wp_kses_post(stripslashes($ai_speaking_instructions)); ?>

                            <div class="service-price-box__price">
                                <div class="service-price-box__col-name">
                                    <div class="service-price-box__service-name">
                                        <?php echo esc_html($this->AI_task_plan_details ? $this->AI_task_plan_details->title : 'AI Speaking Evaluation'); ?>
                                    </div>
                                </div>
                            </div>
                            <div class="card-successful__price-wrap">
                                <div class="card-successful__price">
                                    <?php echo wp_kses_post($this->AI_task_plan_details ? $this->AI_task_plan_details->price : ''); ?>
                                </div>
                            </div>
                            <div class="service-price-box__btn-wrap clearfix">
                                <?php if( !$this->is_enrolled ){ ?>
                                    <form id="st-proqyz-ieltslms-evaluation-cart-form--speaking-ai" class="st-proqyz-ieltslms-evaluation-cart-form">
                                        <input type="hidden" name="selected-task" value="speaking-ai" />
                                        <input type="hidden" name="selected-result-id" value="<?php echo esc_attr($this->result_id); ?>" />
                                        <button 
                                            style="max-width:100%;" 
                                            class="service-price-box__btn iot-grbt" 
                                            type="submit"
                                        >
                                            Buy AI Evaluation <span class="ioticon-cart"></span>
                                        </button>
                                    </form>
                                    <?php echo apply_filters('st_proqyz_payment_addons', '', ['result_id' => $this->result_id, 'user_id' => $this->student_id, 'type' => 'speaking-ai', 'form_id' => "st-proqyz-ieltslms-evaluation-cart-form--speaking-ai" ]); ?>
                                <?php } else { ?>
                                    <div class="alert alert-success" style="margin-top:10px;">
                                        AI speaking evaluation already unlocked.
                                    </div>
                                <?php } ?>
                            </div>
                        </div>
                    </div>
                </div>
            <?php }
        }
        $plan_selector = ob_get_clean();

        return (object) [
            "plans_selector" => $plan_selector
        ];
    }


    public function modals(){
        if($this->result){
            ob_start(); ?>

            <?php return ob_get_clean();
        } else {
            ob_start(); ?>

            <!--begin::modals-->
            <div id="modal-upload-error" class="modal fade" tabindex="-1" role="dialog">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" data-dismiss="modal" aria-label="Close"
                            class="close">×</button>
                            <h4 class="modal-title">Error</h4>
                        </div>
                        <div class="modal-body" data-drupal-selector="message">
                        </div>
                        <div class="modal-footer"> <span class="download-btn" data-drupal-selector="download"></span>
                            <button type="button" data-dismiss="modal" aria-label="Close"
                            class="btn iot-bt btn-primary">Close</button>
                        </div>
                    </div>
                </div>
            </div>

            <div class="modal fade" id="modal-no-support" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
                <div class="modal-dialog modal-auto modal-no-support">
                    <div class="modal-content-wp">
                        <div class="modal-no-support__contents clearfix">
                            <div class="modal-no-support__icon-wrap"> <i
                            class="fa fa-exclamation-triangle modal-no-support__icon" aria-hidden="true"></i>
                            </div>
                            <p class="modal-no-support__caption"> We currently <strong>DO NOT</strong> support recording
                            on <strong>this browser</strong>. Please use Chrome/Safari/Firefox/Edge/Opera browser to
                            take the test.
                            </p>
                            <p></p>
                        </div>
                        <div class="modal-no-support_btn-wrap clearfix"> <a
                            href="https://ieltsonlinetests.com/ielts-mock-test-2023-january-speaking-practice-test-1/test/start"
                            class="iot-bt">Okay, I understand</a></div>
                    </div>
                </div>
            </div>
            <div class="modal fade" id="modal-reset-record" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
                <div class="modal-dialog modal-auto modal-reset-record">
                    <div class="">
                        <i class="ion-android-close close-modal" data-dismiss="modal" aria-label="Close">
                        </i>
                        <h2 class="modal__title">Are you sure to exist the test?</h2>
                        <p class="modal__desc">Your recording of this part will not be saved when reset</p>
                        <div class="modal__button-wrap"> <a class="modal__button -no" data-dismiss="modal"
                            aria-label="Close">No</a> <a id="js-button-yes" class="modal__button -yes" data-dismiss="modal"
                            aria-label="Close">Yes</a></div>
                    </div>
                </div>
            </div>

            <div class="modal fade modal-timeup-wrapper" id="modal-time-up" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
                <div class="modal-dialog modal-auto modal-time-up">
                    <div class="">
                        <div class="modal__countdown-imgwrap">
                            <img src="<?php echo site_url(); ?><?php echo $this->ielts_url; ?>/img/ielts/speaking/count-down.svg" alt="" class="modal__countdown-img" />
                            <div class="modal__countdown-time">
                            <div class="modal__countdown-num" id="js-countdown-number">5</div>
                            <div class="modal__countdown-text" id="js-countdown-text">secs</div>
                            </div>
                        </div>
                        <h2 class="modal__title">Time's up!</h2>
                        <p class="modal__desc">You have reached the assessment time limit. Click to go to next part
                            or it will now continue automatically within 5 seconds.
                        </p>
                        <div class="modal__button-wrap"> 
                            <a href="#" id="js-finish-part" class="modal__button -no" data-dismiss="modal">
                            Next Part<i class="fa fa-play"></i>
                            </a>
                        </div>
                    </div>
                </div>
            </div>

            <div class="modal fade modal-timeup-wrapper" id="modal-finish" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
                <div class="modal-dialog modal-auto modal-time-up">
                    <div class="">
                        <div class="modal__countdown-imgwrap">
                            <img src="<?php echo site_url(); ?><?php echo $this->ielts_url; ?>/img/ielts/speaking/count-down.svg" alt="" class="modal__countdown-img" />
                            <div class="modal__countdown-time">
                            <div class="modal__countdown-num" id="js-countdown-finished" data-time="5">5</div>
                            <div class="modal__countdown-text" id="js-countdown-text">secs</div>
                            </div>
                        </div>
                        <h2 class="modal__title">Test finished!</h2>
                        <p class="modal__desc">You have answered all questions of this part. Click to go to next
                            part or it will now continue automatically within 5 seconds.
                        </p>
                        <div class="modal__button-wrap"> 
                            <a href="#" id="js-finish-test" class="modal__button -no" data-dismiss="modal">
                            Next Part<i class="fa fa-play"></i>
                            </a>
                        </div>
                    </div>
                </div>
            </div>

            <div class="uploading-overlay" id="js-uploading-overlay">
                <div class="line-scale-pulse-out">
                    <p class="uploading-text">Please wait, we are uploading your test to server...(<span
                        id="progress-upload">0%</span>)</p>
                    <div></div>
                    <div></div>
                    <div></div>
                    <div></div>
                    <div></div>
                </div>
            </div>

            <div class="modal fade" id="modal-exit-test" tabindex="-1" role="dialog">
                <div class="modal-dialog modal-auto modal-exit-test">
                    <div class="iot-modal-wrapper">
                        <i class="ion-android-close close-modal" data-dismiss="modal" aria-label="Close"> </i>
                        <h2 class="modal-caption"> Are you sure to exist the test?</h2>
                        <div class="modal-body"> Your essay will not be saved when exist. You might need to save draft first
                        </div>
                        <div class="modal-footer"> 
                            <a class="modal--no" data-dismiss="modal">No</a> 
                            <a href="#yes" class="modal--yes">Yes</a>
                        </div>
                    </div>
                </div>
            </div>

            <div class="modal fade" id="modal-exit-test-speaking" tabindex="-1" role="dialog">
                <div class="modal-dialog modal-auto modal-exit-test">
                    <div class="iot-modal-wrapper">
                        <i class="ion-android-close close-modal" data-dismiss="modal" aria-label="Close"> </i>
                        <h2 class="modal-caption"> Are you sure to exist this part?</h2>
                        <div class="modal-body"> Your recording will not be saved when exist</div>
                        <div class="modal-footer"> 
                            <a class="modal--no" data-dismiss="modal">No</a> 
                            <a href="/" class="modal--yes">Yes</a>
                        </div>
                    </div>
                </div>
            </div>
            <!--end::modals-->
            <?php return ob_get_clean();
        }
    }

    /**
     * changes @1.2.1.2
     */
    public function get_speaking_styles(){
        $site_url = site_url();
        ob_start(); ?>
        <?php if( $this->result ){ ?>
            <style>
                .speaking-review-page .recording__question-body{ padding: 0 !important; }
                .plyr--audio .plyr__controls {color: #4a5764;}

                .d-flex {
                    display: flex !important;
                }

                .flex-row {
                    flex-direction: row !important;
                }

                .align-items-center {
                    align-items: center !important;
                }

                .justify-content-between {
                    justify-content: space-between;
                }

                .sp_col-2 {
                    display: none;
                }

                .aside-enable .sp_col-auto.sp_col-1 {
                    width: calc(100% - 390px);
                }

                .col-xs-12.sp_col-auto.sp_col-1 {}

                .aside-enable .sp_col-2 {
                    display: block;
                    width: 390px;
                }

                .aside-enable .container {
                    
                }

                .review__container {
                    height: calc(100vh - 62px);
                }

                li.nav-item.active button {color: white;background: #eea155;}

                .show-notepad span.hide-notepad-text {
                    display: inline-flex;
                }
                .show-notepad span.hide-notepad-text {
                    display: none;
                }

                .note-fontname {
                    display: none;
                }

                .note-btn-group.note-insert button:nth-child(2) {
                    display: none;
                }

                .note-btn-group.note-view button:nth-child(3) {
                    display: none;
                }

                a.answer__title[aria-expanded="true"] .review_btn {
                    background: orange;
                    color: white;
                }


                .accordion-parent .accordion-card__header {
                    background: #284664;
                    color: #fff;
                    padding: 10px 10px 15px;
                    border-radius: 5px;
                    cursor: pointer;
                    display: flex;
                    justify-content: space-between;
                    align-items: center;
                }

                .accordion-card__header {
                   
                }

                .accordion-card__header h5{
                    color: #fff;
                    font-size: 12px;
                    font-weight: 400;
                    padding-left: 10px;
                    padding-right: 10px;
                    height: 40px;
                    margin: 0;
                }


                label.checkbox {
                    font-weight: 500;
                    font-size: 15px;
                    margin: 2px 0 3px;
                }

                .checkbox-inline {
                    width: 100%;
                }

                .checkbox-inline {
                    padding: 0;
                }


                .btn-primary {
                    color: #fff;
                    background-color: #284664;
                    border-color: #284664;
                }

                span.show-notepad-text {
                    display: none;
                }

                .show-notepad span.show-notepad-text {
                    display: inline-block !important;
                }

                .btn-custom__speaking {
                    background: linear-gradient(180deg, #c86478 0, #954b5a 100%);
                    margin-right: 15px;
                    color: #fff;
                }

                .btn-custom__speaking:hover{
                    color: #fff;
                }

                .sp_center-aside {
                    margin: 0 auto !important;
                }

                .review__container {
                    display: none !important;
                }

                .aside-enable .review__container {
                    display: block !important;
                }

                a.realtest-header__bt-submit {
                    display: flex !important;
                    background: linear-gradient(180deg, #c86478 0%, #954b5a 100%);
                }

                button:disabled {
                    opacity: 0.6;
                    cursor: no-drop;
                }

            </style>
            <style id="speaking-evaluation-css--dynamic">
                .speaking-review-page .evaluation-widget__label:after, .speaking-review-page .evaluation-widget__label:before {
                    background: url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/img/ielts/speaking/corner-pink-shadow-right.svg) center no-repeat;
                }
                .speaking-review-page .evaluation-widget__label:before {
                    background-image: url(<?php echo $site_url; ?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/img/ielts/speaking/corner-pink-shadow-left.svg);
                }
            </style>
        <?php } ?>
        <style>
            .speaker--container {
                position: absolute;
                left: 10px;
            }


            .rs-readonly .rs-handle.rs-move,.rs-tooltip{cursor:default}
            .play-pause:focus,.rs-control{outline:0}
            .rs-tooltip,.text{text-align:center}
            .text,.text a{color:#fff}
            .slide__audio {
                position: relative;
                background: #c7637800;
                width: 29px;
                top: 20%;
                margin: 0 auto;
            }
            .audio__controls {
                height: 28px;
                width: 28px;
                position: relative;
                border: 1px solid #c7637880;
                border-radius: 50%;
            }
            .slide__audio .slide__audio-player{display:none}
            .audio__slider{position:absolute;z-index:3}
            .audio__slider::before{content:"";display:block;width:100%;height:100%;border:5px solid rgba(255, 255, 255, 0);border-radius:100%;position:absolute;margin:0;padding:0;box-sizing:border-box}
            .audio__slider .rs-container,.rs-block .rs-inner,.rs-container,.rs-control{position:relative}
            .audio__slider .rs-bar,.full .rs-bar,.half.left .rs-bar,.half.right .rs-bar{top:50%}
            .audio__slider .rs-tooltip{display:none}.rs-control *,.rs-control :after,.rs-control :before{box-sizing:border-box}
            .rs-animation .rs-transition{transition:.5s linear}.rs-control .rs-overlay1,.rs-control .rs-overlay2,.rs-control .rs-split .rs-path{transform-origin:50% 100%}
            .rs-control .rs-overlay{transform-origin:100% 100%}.rs-control.rs-error{border:1px dotted;text-align:center}
            .rs-inner-container{height:100%;width:100%;position:relative;overflow:hidden}.rs-bar,.rs-block{position:absolute}
            .rs-block{height:100%;width:100%;display:block;top:0;overflow:hidden;z-index:3}.rs-block .rs-inner{border-radius:1000px;display:block;height:100%;width:100%}
            .rs-bar{transform-origin:100% 50%;height:0;z-index:10}.play-pause,.slide__audio #circle{left:50px;top:50px;transform:translate(-50%,-50%)}
            .rs-bar .rs-seperator{height:0;border-bottom:none;display:block;float:left}.full .rs-bar,.half .rs-bar{width:50%}.bottom .rs-bar{top:0}
            .half.right .rs-bar,.quarter.right .rs-bar{right:100%}.rs-handle.rs-move{cursor:move}.rs-path{display:block;height:100%;width:100%}
            .equalizer,.play-pause{width:50px;position:absolute}.rs-split .rs-path{border-radius:1000px 1000px 0 0;overflow:hidden;height:50%;position:absolute;top:0;z-index:2}
            .rs-tooltip{position:absolute;border:1px solid transparent;z-index:10}.rs-handle{border-radius:1000px;outline:0;float:left;background-color:#838383}
            .rs-handle.rs-handle-square{border-radius:0}.active .rs-handle,.paused .rs-handle,.playing .rs-handle{background-color:#c76378}
            .slide__audio #circle {
                position: absolute;
                top: 14px;
                left: 14px;
                bottom: 0;
                stroke: #c76378;
                width: 28px;
                height: 28px;
                border-radius: 100%;
                transform: translate(-50%, -50%);
                pointer-events: none;
                z-index: 4;
            }
            .play-pause {
                position: absolute;
                left: 14px;
                top: 14px;
                z-index: 3;
                width: 15px;
                background: transparent !important;
                height: 15px;
                cursor: pointer;
                transform: translate(-50%, -50%);
                border: 0;
                padding: 0;
                margin: 0;
            }
            .play-pause::after{content:"";position:absolute;top:0;left:0;width:100%;height:100%;background-image:url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAZdJREFUeNrs29FNQjEYBlAgDuAIuAFugBvgBrABTiBOgE4AGzgCbCAbwAayAbZJb0KMT77wt/ecpO/39qP9CqGDAQAAAAAAAAAAAAAA8A+Xy2WWxr2ZiBPILo1jGlOzESeQzmcaY7MSJ5DsO42lmYkTSOcrjYkZihNIZ630YwVyKaU/M1txAunsWir9UQPvkI/GuVtWPsoxVsjv0p9aIXHkE9iu5tIfNbrI8neWXPpzgcSRV8imttJvOZDr0j/WUvp9CKTzWsMPln0KJBuX0t9ELf2+BdKZl21sKZBYpb8upT8RSMBv+hG2MYFclX4JZioQBPKHtzQeh8Ph/pYPcSeHQQ7gJQVxsEJu61yCeIoSRp9XyLaEcY72YH0L5JTG4tY9YcsqpZ2CeIgcRl9WyL6sipNj7+1Le1FK+1TLQ7cayHsaeXva1vbgrW1Zh3J62tf6Aq0EkrenjxTEqvYXaSGQqkq75Q7JATzXVtpV8mfregJxHSFIIC7sBArElbYggbj0GSgQ16IBAAAAAAAAAAAAACCsHwEGACfr+SLf7BaJAAAAAElFTkSuQmCC");background-size:150%;background-position:50% 50%;background-repeat:no-repeat}
            #seekbar{stroke-width:6}.playing #seekbar{visibility:visible}.playing .play-pause::after{content:none}.playing .equalizer,.playing .play-pause::before{opacity:1}
            .equalizer {
                height: 14px;
                width: 14px;
                transform: rotate(180deg);
                left: 7px;
                top: 9px;
                position: absolute;
                transform-origin: center;
                opacity: 0;
            }
            .bar,.equalizer-group{transform-origin:center}.equalizer-group{width:100%;height:100%;display:block}
            .bar{fill:#c76378;width:5px;-webkit-animation:1.25s steps(25,end) infinite equalize;animation:1.25s steps(25,end) infinite equalize;position:relative;margin-top:-50px}
            .bar:first-child{-webkit-animation-duration:1.9s;animation-duration:1.9s;transform:translate(5px,50%)}.bar:nth-child(2){-webkit-animation-duration:2s;animation-duration:2s;transform:translate(25%,50%)}.bar:nth-child(3){-webkit-animation-duration:2.3s;animation-duration:2.3s;transform:translate(50%,50%)}.bar:nth-child(4){-webkit-animation-duration:2.4s;animation-duration:2.4s;transform:translate(75%,50%)}.bar:nth-child(5){-webkit-animation-duration:2.1s;animation-duration:2.1s;transform:translate(95%,50%)}@-webkit-keyframes equalize{0%,28%,36%,56%{height:10px;margin-top:-10px}4%,72%,84%{height:5px;margin-top:-5px}24%,32%,44%,8%{height:40px;margin-top:-40px}12%,20%,52%,60%,92%{height:30px;margin-top:-30px}16%,40%{height:20px;margin-top:-20px}48%,68%{height:15px;margin-top:-15px}64%{height:35px;margin-top:-35px}76%{height:45px;margin-top:-45px}100%,80%{height:25px;margin-top:-25px}88%,96%{height:50px;margin-top:-50px}}@keyframes equalize{0%,28%,36%,56%{height:10px;margin-top:-10px}4%,72%,84%{height:5px;margin-top:-5px}24%,32%,44%,8%{height:40px;margin-top:-40px}12%,20%,52%,60%,92%{height:30px;margin-top:-30px}16%,40%{height:20px;margin-top:-20px}48%,68%{height:15px;margin-top:-15px}64%{height:35px;margin-top:-35px}76%{height:45px;margin-top:-45px}100%,80%{height:25px;margin-top:-25px}88%,96%{height:50px;margin-top:-50px}}
            .audio__slider {
                height: 28px;
                width: 28px;
            }

            .next--disabled {
                opacity: 0.5 !important;
                cursor: no-drop !important;
            }

            
        </style>
        <?php echo ob_get_clean();
    }


    /**
     * changes @1.2.1.2
     */
    public function header(){
        if( $this->result ) {
            ob_start(); ?>
            <head>
                <?php if(isset($this->quiz->title)) { ?>
                <title><?php echo $this->quiz->title; ?> | Result</title>    
                <?php } ?>
                <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" />
                <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/plyr/3.6.9/plyr.min.css" integrity="sha512-9NS6wyLGVddfu8MvjH2muvHT+3lPxYifn5SDMigU+cgsQY91MTP72x8OpbnK9ucbjfZc6TMP3hajTCFrvFWxxg==" crossorigin="anonymous" referrerpolicy="no-referrer" />
                <?php echo $this->dynamic_css_imports(); ?>
                <?php echo $this->dynamic_js_imports_header(); ?>
                <link rel="stylesheet" href="<?php echo site_url();?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/css/proqyz-quiz.css" />
                <link rel="stylesheet" href="<?php echo site_url();?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/css/iot-speaking.css" />
                <link rel="stylesheet" href="<?php echo site_url();?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/css/speaking-evaluation.css" />
                <link href="https://cdn.jsdelivr.net/npm/summernote@0.8.18/dist/summernote-lite.min.css" rel="stylesheet" />
                <?php echo $this->get_speaking_styles(); ?>
                <style>
                    @media (max-width: 1025px){
                        .container {
                            width: 100% !important;
                        }
                    }

                    .badge-warning.-speaking {
                        background: #FAAA5A !important;
                    }

                    .ajax-cart-loading .ajax-cart-loading-overlay {
                        display: flex !important;
                        position: fixed;
                        z-index: 9999;
                        background: #00000080;
                        top: 0;
                        bottom: 0;
                        left: 0;
                        right: 0;
                        flex-direction: column;
                        flex-wrap: nowrap;
                        align-content: center;
                        justify-content: center;
                        align-items: center;
                    }

                    .ajax-cart-loading {
                        overflow: hidden;
                    }

                    .spanner {
                        position: relative;
                        left: 0;
                        display: block;
                        text-align: center;
                        color: #FFF;
                    }

                    .loader,
                    .loader:before,
                    .loader:after {
                        border-radius: 50%;
                        width: 2.5em;
                        height: 2.5em;
                        -webkit-animation-fill-mode: both;
                        animation-fill-mode: both;
                        -webkit-animation: load7 1.8s infinite ease-in-out;
                        animation: load7 1.8s infinite ease-in-out;
                    }

                    .loader {
                        color: #ffffff;
                        font-size: 5px;
                        position: relative;
                        text-indent: -9999em;
                        -webkit-transform: translateZ(0);
                        -ms-transform: translateZ(0);
                        transform: translateZ(0);
                        -webkit-animation-delay: -0.16s;
                        animation-delay: -0.16s;
                    }

                    .loader:before,
                    .loader:after {
                        content: '';
                        position: absolute;
                        top: 0;
                    }

                    .loader:before {
                        left: -3.5em;
                        -webkit-animation-delay: -0.32s;
                        animation-delay: -0.32s;
                    }
                    .loader:after {
                        left: 3.5em;
                    }

                    @-webkit-keyframes load7 {
                        0%,
                        80%,
                        100% {
                            box-shadow: 0 2.5em 0 -1.3em;
                        }
                        40% {
                            box-shadow: 0 2.5em 0 0;
                        }
                    }

                    @keyframes load7 {
                        0%,
                        80%,
                        100% {
                            box-shadow: 0 2.5em 0 -1.3em;
                        }
                        40% {
                            box-shadow: 0 2.5em 0 0;
                        }
                    }


                    .ajax-spinner-inner {
                        display: flex;
                        flex-direction: column;
                        flex-wrap: nowrap;
                        align-content: center;
                        justify-content: center;
                        align-items: center;
                    }

                    button.cancel-ajax-cart {
                        background: white;
                        border: 0;
                        width: 100px;
                        margin-top: 10px;
                    }


                    .modal-task-pay__item.disabled {
                        cursor: no-drop;
                        opacity: 0.6;
                    }

                    button.service-price-box__btn[disabled] {
                        opacity: 0.8;
                        cursor: no-drop;
                    }

                    .badge.badge-success {
                        background: #8BC34A !important;
                    }

                    .col-left {
                        margin: 0 auto !important;
                    }

                    .-speaking--btn {
                        background: var(--gradient-writing, linear-gradient(180deg, #c76378 0%, #83293c 100%)) !important;
                    }

                    .-speaking--btn::after {
                        content: '' !important;
                    }

                    .white-space__pre-wrap {
                        white-space: pre-wrap;
                    }

                    button.ielts-lms-result-show-button {
                        width: 100%;
                        margin: 10px auto;
                        height: 45px;
                        font-size: 16px;
                        border: 1px solid #c76378;
                        color: #c76378;
                    }

                    

                </style>
            </head>
            <?php return ob_get_clean();
        } else {
            ob_start(); ?>
            <head>
                <?php if(isset($this->quiz->title)) { ?>
                <title><?php echo $this->quiz->title; ?> | Quiz</title>    
                <?php } ?>
                <meta charset="<?php bloginfo('charset'); ?>" />    
                <meta name="viewport" content="width=device-width, initial-scale=1.0" />
                <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/plyr/3.6.9/plyr.min.css" integrity="sha512-9NS6wyLGVddfu8MvjH2muvHT+3lPxYifn5SDMigU+cgsQY91MTP72x8OpbnK9ucbjfZc6TMP3hajTCFrvFWxxg==" crossorigin="anonymous" referrerpolicy="no-referrer" />
                <?php echo $this->dynamic_css_imports(); ?>
                <?php echo $this->dynamic_js_imports_header(); ?>
                <link rel="stylesheet" href="<?php echo site_url();?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/css/proqyz-quiz.css"  />
                <script>
                    const fullMockTest  = `<?php echo $this->is_fullmock_test? 'true' : 'false'; ?>`;
                </script>
                <?php echo $this->get_speaking_styles(); ?>
            </head>
            <?php return ob_get_clean();
        }

    }

    public function footer(){

        if( $this->result ) {
            ob_start(); ?>
            <script id="quiz-json" type="application/json">
                <?php echo json_encode( (object) $this->_q); ?>
            </script>
            <script id="session-details" type="application/json">
                <?php 
                    echo json_encode( (object) [
                        "_id"           => $this->_id,
                        "category"      => $this->category,
                        "time"          => $this->default,
                        "post_id"       => $this->post_id,
                        "session"       => $this->session
                    ]); 
                ?>
            </script>
            <script id="sot-details" type="application/json"></script>

            <script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
            <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.4.1/dist/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>
            <script src="https://cdnjs.cloudflare.com/ajax/libs/plyr/3.6.9/plyr.min.js" integrity="sha512-Wt3CCBrK4mMw9PUEzDpKPMN7cLCq7/Uu7vxRtG+EQv+DO9Yae/LKSQTfziDj51y1yeSqqLt142lNyJtBXG/gSw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
            <script src="https://cdn.jsdelivr.net/npm/summernote@0.8.18/dist/summernote-lite.min.js" type="text/javascript"></script>
            <script>
                jQuery(document).ready(function($){
                    /**
                     * action: speaking-ajax--set-primary-evaluation
                     * description: set the primary evaluation for the students
                     * status: completed
                     */
                    $(document).on('submit', '#speaking-ajax--set-primary-evaluation', function(event){
                        event.preventDefault();
                        let form = $(this);
                        let primaryEvaluation = form.find('#primary-evaluation').val();
                        let resultId = form.find('[name="result-id"]').val();
                        let btn = form.find('[type="submit"]');
                        let tmp = btn.html();
                        

                        window['ajax-set-primary-evaluation'] = $.ajax({
                            url: "/wp-admin/admin-ajax.php",
                            type: "POST",
                            data: {
                                action: "speaking-ajax--set-primary-evaluation",
                                primary: primaryEvaluation,
                                result_id: resultId
                            },
                            beforeSend: function(){
                                if(window['ajax-set-primary-evaluation'] != null){
                                    window['ajax-set-primary-evaluation'].abort();
                                }
                                btn.attr('disabled', true);
                                btn.html("Saving...");
                            },
                            success: function(response){
                                if(response.success){
                                    btn.html("Saved");
                                    setTimeout(() => {
                                        btn.attr('disabled', false);
                                        btn.html(tmp);
                                    }, 1000);
                                    
                                } else {
                                    btn.html("Error saving !");
                                    setTimeout(() => {
                                        btn.attr('disabled', false);
                                        btn.html(tmp);
                                    }, 1000);
                                }
                            },
                            error: function(err){
                                btn.html("Error saving !");
                                setTimeout(() => {
                                    btn.attr('disabled', false);
                                    btn.html(tmp);
                                }, 1000);
                            }
                        });
                    });

                    /**
                     * instructor post evaluation form
                     * status: completed
                     * type: instructor review
                     */
                    $(document).on('submit', '.proqyz__post-evaluation-form', function(event){
                        event.preventDefault();
                        
                        let resultId  = $(this).find('#result-id');
                        // feedback status
                        
                        let feedbackContent = $(this).find('#feedback-content');
                        let score1          = $(this).find('#score-1');
                        let score2          = $(this).find('#score-2');
                        let score3          = $(this).find('#score-3');
                        let score4          = $(this).find('#score-4');

                        let btn             = $(this).find('[type="submit"]');
                        let notice          = $(this).find('.notice__area');

                        let tmp             = btn.html();

                        let scores = [
                            +score1.val() || 1,
                            +score2.val() || 1,
                            +score3.val() || 1,
                            +score4.val() || 1
                        ];
                        

                        let report = {
                            "review_enable": 1,
                            "review_content":       feedbackContent.val(),
                            "scores":               scores,
                            "result_id":            resultId.val()
                        };


                        window[resultId.val()] = $.ajax({
                            url: "/wp-admin/admin-ajax.php",
                            type: 'POST',
                            dataType: 'json',
                            data: {
                                action: "proqyz-instructor-evaluation-speaking",
                                report: report
                            },
                            beforeSend: function(){
                                if(window[resultId.val()] != null){
                                    window[resultId.val()].abort();
                                }
                                btn.attr('disabled', true);
                                btn.html("Posting...");
                                notice.html('Posting...');

                            },
                            success: function(response){
                                if(response.success){
                                    notice.html(`<p class="text-success">Review Posted successfully</p>`);
                                }

                                if(response.error){
                                    notice.html(`<p class="text-danger">${response.error.message}</p>`);
                                }

                                btn.attr('disabled', false);
                                btn.html(tmp);
                                

                                setTimeout(() => {
                                    notice.html("");    
                                }, 2000);
                            },
                            error: function(err){
                                notice.html(`<p class="text-danger">${err.message}</p>`);
                                btn.attr('disabled', false);
                                btn.html(tmp);
                                setTimeout(() => {
                                    notice.html("");    
                                }, 2000);
                            }
                        });
                        
                    });

                    /**
                     * status: completed
                     * type: student 
                     * description: submit re-evaluation request from the students to the instructor
                     * quiz_category: speaking
                     */
                    $(document).on('submit', '.proqyz-student--submit-reevaluation-request-speaking', function(event){
                        event.preventDefault();
                        let form    = $(this);
                        let section = form.find('#section-id');
                        let result  = form.find('#result-id');
                        let reason  = form.find('#reason');
                        let notice  = form.find('.notice__area');
                        let btn     = form.find('[type="submit"]');

                        if(!result.val()){
                            notice.html(`<div class="alert alert-danger">Missing result reference.</div>`);
                            return;
                        }

                        $.ajax({
                            url: "/wp-admin/admin-ajax.php",
                            type: "POST",
                            dataType: "json",
                            data: {
                                action: "proqyz-student--submit-reevaluation-request-speaking",
                                section_id: section.val() || '',
                                result_id: result.val(),
                                reason: reason.val()
                            },
                            beforeSend: function(){
                                btn.attr('disabled', true);
                                notice.html(`<div class="alert alert-info">Posting request...</div>`);
                            },
                            success: function(response){
                                btn.attr('disabled', false);
                                if(response?.success){
                                    notice.html(`<div class="alert alert-success">${response.success.message || 'Request sent successfully.'}</div>`);
                                } else if(response?.error){
                                    notice.html(`<div class="alert alert-danger">${response.error.message || 'Failed to send request.'}</div>`);
                                } else {
                                    notice.html(`<div class="alert alert-danger">Unexpected response from server.</div>`);
                                }
                            },
                            error: function(err){
                                btn.attr('disabled', false);
                                notice.html(`<div class="alert alert-danger">${err?.message || 'Failed to send request.'}</div>`);
                            }
                        });
                    });

                    $(document).on('change', '.task-li', function(event) {
                        let rootId = $(this).data('holder');
                        $(rootId).html($(this).val());
                    });



                    // add to card event for speaking evaluation
                    $(document).on('submit', '.st-proqyz-ieltslms-evaluation-cart-form', function (event) {
                        event.preventDefault();
                        let form     = $(this);
                        let resultId = form.find('[name="selected-result-id"]').val();
                        let task     = form.find('[name="selected-task"]').val();
                        const tmp    = $('#modal-notification-payment .modal-detail').html();
                        $('#modal-notification-payment .modal-detail').removeClass('d-none');
                        $('#modal-notification-payment .error_detail').addClass('d-none');

                        window['ajax-add-to-cart'] = $.ajax({
                            url: `<?php echo admin_url('admin-ajax.php'); ?>`,
                            type: 'post',
                            data: {
                                "action"        : "ST_PROQYZ_IELTSLMS_EVALUATION_ADD_TO_CART",
                                "id"            : resultId,
                                "task"          : task,
                                "category"      : 'speaking',
                                "url"           : window.location.href
                            },
                            beforeSend: function () {
                                $('body').addClass('ajax-cart-loading');   
                                if(window['ajax-add-to-cart'] != null) window['ajax-add-to-cart'].abort(); 
                                $('#modal-notification-payment').modal('show');
                            },
                            success: function (json) {
                                if(json.success) {
                                    // Check if wallet is enabled in response
                                    if(json.success.wallet_enabled) {
                                        // Show wallet payment modal
                                        let walletBalance = json.success.wallet_balance || 0;
                                        let productPrice = json.success.product_price || 0;
                                        let sufficientBalance = json.success.sufficient_balance || false;
                                        let currencySymbol = '<?php echo class_exists("WooCommerce") ? get_woocommerce_currency_symbol() : "$"; ?>';
                                        $('#modal-notification-payment').modal('hide');

                                        // Populate wallet modal
                                        $('#modal-wallet-payment').find('.wallet-balance').html(currencySymbol + walletBalance.toFixed(2));
                                        $('#modal-wallet-payment').find('.product-price').html(currencySymbol + productPrice.toFixed(2));
                                        $('#modal-wallet-payment').find('.product-name').text(json.success.product_name || 'Speaking Evaluation');
                                        
                                        // Store payment details in modal for wallet payment
                                        $('#modal-wallet-payment').data('result-id', resultId);
                                        $('#modal-wallet-payment').data('task', task);
                                        $('#modal-wallet-payment').data('product-id', json.success.product_id || '');
                                        $('#modal-wallet-payment').data('option-key', json.success.option_key || '');
                                        $('#modal-wallet-payment').data('category', 'speaking');
                                        
                                        if(sufficientBalance) {
                                            $('#modal-wallet-payment .btn-pay-wallet').prop('disabled', false).show();
                                            $('#modal-wallet-payment .insufficient-balance-msg').hide();
                                        } else {
                                            $('#modal-wallet-payment .btn-pay-wallet').prop('disabled', true).hide();
                                            $('#modal-wallet-payment .insufficient-balance-msg').show();
                                        }


                                        
                                        // Show wallet modal
                                        $('#modal-wallet-payment').modal('show');
                                    } else {
                                        // Normal checkout flow
                                        // Normal checkout flow
                                        $('#modal-notification-payment .modal-detail').html(`
                                            <h3 class="modal-caption">
                                                ${json.success.message}
                                            </h3>
                                        `);
                                        if(json.success.has_redirect) {
                                            window.location.href = json.success.redirect_url;
                                        }
                                    }
                                } else if(json.error){
                                    $('#modal-notification-payment .error_detail').html(`
                                        <i class="fa fa-exclamation-triangle fa-2x" aria-hidden="true"></i>
                                        <h3 class="modal-caption">
                                            Error: ${json.error?.message || 'Unknown error'}
                                        </h3>
                                        <div class="modal-action">
                                            <button class="cancel-ajax-cart" data-dismiss="modal">Cancel</button>
                                        </div>
                                    `);
                                    $('#modal-notification-payment .modal-detail').addClass('d-none');
                                    $('#modal-notification-payment .error_detail').removeClass('d-none');  
                                } else {
                                    $('#modal-notification-payment .error_detail').html(`
                                        <i class="fa fa-exclamation-triangle fa-2x" aria-hidden="true"></i>
                                        <h3 class="modal-caption">
                                            Error: Unknown Response
                                        </h3>
                                        <div class="modal-action">
                                            <button class="cancel-ajax-cart" data-dismiss="modal">Cancel</button>
                                        </div>
                                    `);
                                    $('#modal-notification-payment .modal-detail').addClass('d-none');
                                    $('#modal-notification-payment .error_detail').removeClass('d-none');
                                }   
                            },
                            dataType: 'json',
                            error: function(){
                                $('#modal-notification-payment .error_detail').html(`
                                    <i class="fa fa-exclamation-triangle fa-2x" aria-hidden="true"></i>
                                    <h3 class="modal-caption">
                                        Error: Process failed, Please cancel and try again 
                                    </h3>
                                    <div class="modal-action">
                                        <button class="cancel-ajax-cart" data-dismiss="modal">Cancel</button>
                                    </div>
                                `);
                                $('#modal-notification-payment .modal-detail').addClass('d-none');
                                $('#modal-notification-payment .error_detail').removeClass('d-none');
                            }
                        });


                    });

                    $(document).on('click','.cancel-ajax-cart', (event) => {
                        $('body').removeClass('ajax-cart-loading');
                        if(window['ajax-add-to-cart'] != null){
                            window['ajax-add-to-cart'].abort();
                        }
                    });

                    // Wallet payment handler for speaking
                    $(document).on('click', '.btn-pay-wallet', function(e) {
                        e.preventDefault();
                        let modal = $('#modal-wallet-payment');
                        let resultId = modal.data('result-id');
                        let task = modal.data('task');
                        let productId = modal.data('product-id');
                        let optionKey = modal.data('option-key');
                        let category = modal.data('category');
                        let url = window.location.href;

                        // Hide normal content, show loading
                        modal.find('.modal-detail').first().hide();
                        modal.find('.error_detail').addClass('d-none').html(`
                            <img src="<?php echo site_url().($this->ielts_url); ?>/img/loading.gif" alt="loading..." />
                            <h3 class="modal-caption">
                                Processing payment...
                            </h3>
                        `).removeClass('d-none');

                        $.ajax({
                            url: `<?php echo admin_url('admin-ajax.php'); ?>`,
                            type: 'post',
                            data: {
                                "action": "ST_PROQYZ_WALLET_PAY_EVALUATION",
                                "product_id": productId || 0,
                                "result_id": resultId,
                                "task": task,
                                "category": category,
                                "option_key": optionKey || '',
                                "url": url
                            },
                            success: function(json) {
                                if(json.success) {
                                    modal.find('.error_detail').addClass('d-none');
                                    modal.find('.modal-detail').first().html(`
                                        <i class="fa fa-check-circle fa-2x" style="color: #28a745;" aria-hidden="true"></i>
                                        <h3 class="modal-caption" style="color: #28a745; margin-top: 15px;">
                                            Payment Successful!
                                        </h3>
                                        <p style="margin: 15px 0;">${json.success.message}</p>
                                        <div class="modal-action">
                                            <button onclick="location.reload();" style="padding: 10px 20px; background: #28a745; color: white; border: none; border-radius: 4px; cursor: pointer;">Continue</button>
                                        </div>
                                    `).show();
                                    
                                    // Reload page after 2 seconds
                                    setTimeout(function() {
                                        location.reload();
                                    }, 2000);
                                } else if(json.error) {
                                    modal.find('.modal-detail').first().hide();
                                    modal.find('.error_detail').html(`
                                        <i class="fa fa-exclamation-triangle fa-2x" aria-hidden="true"></i>
                                        <h3 class="modal-caption" style="margin-top: 15px;">
                                            Payment Failed
                                        </h3>
                                        <p class="wallet-error-message" style="margin: 15px 0;">${json.error.message}</p>
                                        <div class="modal-action">
                                            <button data-dismiss="modal" class="cancel-ajax-cart" style="padding: 10px 20px; background: #ccc; color: #333; border: none; border-radius: 4px; cursor: pointer;">Close</button>
                                        </div>
                                    `).removeClass('d-none');
                                }
                            },
                            error: function() {
                                modal.find('.modal-detail').first().hide();
                                modal.find('.error_detail').html(`
                                    <i class="fa fa-exclamation-triangle fa-2x" aria-hidden="true"></i>
                                    <h3 class="modal-caption" style="margin-top: 15px;">
                                        Error
                                    </h3>
                                    <p class="wallet-error-message" style="margin: 15px 0;">An error occurred. Please try again.</p>
                                    <div class="modal-action">
                                        <button data-dismiss="modal" class="cancel-ajax-cart" style="padding: 10px 20px; background: #ccc; color: #333; border: none; border-radius: 4px; cursor: pointer;">Close</button>
                                    </div>
                                `).removeClass('d-none');
                            }
                        });
                    });

                    // Go to checkout button handler
                    $(document).on('click', '.btn-go-checkout', function(e) {
                        e.preventDefault();
                        $('#modal-wallet-payment').modal('hide');
                        window.location.href = '<?php echo site_url(); ?>/checkout';
                    });

                    // evaluation tabs logic 
                    $(document).on('click','.evaluation-tabs [data-evaluator-category]', function(){
                        var root = $(this).closest('.evaluation-tabs-content');
                        let evaluatorCategory = $(this).data('evaluator-category');
                        // hide all other category tabs and make them inactive
                        root.find('[data-evaluator-category]').removeClass('active');
                        // hide tabs
                        root.find('.tab__content').removeClass('--show-contents');

                        $(this).addClass('active');
                        root.find(`#${evaluatorCategory}-tab`).addClass('--show-contents');

                    });

                    $(document).on('submit', '.generate-speaking-ai-evaluation', function(event){
                        event.preventDefault();
                        let form   = $(this);
                        let btn    = form.find('[type="submit"]');
                        let notice = form.find('.notice__area');
                        let resultId = form.find('[name="result-id"]').val();
                        let context  = form.find('[name="context"]').val() || 'student';

                        if(!resultId){
                            notice.html(`<div class="alert alert-danger">Missing result reference.</div>`);
                            return;
                        }

                        $.ajax({
                            url: "/wp-admin/admin-ajax.php",
                            type: "POST",
                            dataType: "json",
                            data: {
                                action: "proqyz__speaking-ai-evaluation",
                                result_id: resultId,
                                context: context
                            },
                            beforeSend: function(){
                                btn.attr('disabled', true);
                                notice.html(`<div class="alert alert-info">Processing evaluation, please wait... <br /> 
                                Note: Evaluation can take time longer than usual, please be patient. even if you see timeout or server timeout errors, the evaluation is still processing. so kindly reload to see  the result.</div>`);
                            },
                            success: function(response){
                                btn.attr('disabled', false);
                                if(response?.success){
                                    let message = response.success.message || 'Evaluation triggered successfully.';
                                    notice.html(`<div class="alert alert-success">${message}</div>`);
                                    if(response.success.reload){
                                        setTimeout(function(){
                                            window.location.reload();
                                        }, 1500);
                                    }
                                } else if(response?.error){
                                    notice.html(`<div class="alert alert-danger">${response.error.message || 'Evaluation request failed.'}</div>`);
                                } else {
                                    notice.html(`<div class="alert alert-danger">Unexpected response from server.</div>`);
                                }
                            },
                            error: function(err){
                                btn.attr('disabled', false);
                                notice.html(`<div class="alert alert-danger">${err?.message || 'Request failed. Please try again.'}</div>`);
                            }
                        });
                    });

                    

                    // reset the evaluation
                    $(document).on('submit', '.proqyz-instructor--reset-ai-evaluation-speaking', function(event) {
                        event.preventDefault();
                        
                        let resultId        = $(this).find('#result-id');
                        let notice          = $(this).find('.notice__area');
                        let btn             = $(this).find('[type="submit"]');

                        let confirm = window.confirm("Are you sure you want to reset evaluation?");
                        if( !confirm ) { return; }

                        window["reset-ai-evaluation-speaking-"+resultId.val()] = $.ajax({
                            url: "/wp-admin/admin-ajax.php",
                            type: 'POST',
                            dataType: 'json',
                            data: {
                                action: "proqyz-instructor--reset-ai-evaluation-speaking",
                                result_id:  resultId.val(),
                            },
                            beforeSend: function(){
                                if(window["reset-ai-evaluation-speaking-"+resultId.val()] != null){
                                    window["reset-ai-evaluation-speaking-"+resultId.val()].abort();
                                }
                                btn.attr('disabled', true);
                            },
                            success: function(response){
                                if(response.success){
                                    notice.html(`<div class="alert alert-success">${response?.success?.message || 'Evaluation reset successfully'}</p>`);
                                    window.location.reload();
                                }

                                if(response.error){
                                    notice.html(`<div class="alert alert-danger">${response?.error?.message || 'Failed to reset evaluation'}</p>`);
                                }

                                btn.attr('disabled', false);
                                
                            },
                            error: function(err){
                                notice.html(`<div class="alert alert-danger">${err?.message || 'Failed to reset evaluation'}</p>`);
                                btn.attr('disabled', false);
                                
                            }
                        });
                    });

                    $('.summernote').summernote();
                });
            </script>
            <script>
                function findCurrentQuestionIndex(currentTime, intervals) {
                    for (let i = 0; i < intervals.length - 1; i++) {
                        if (currentTime >= intervals[i] && currentTime < intervals[i + 1]) {
                            return i;
                        }
                    }
                    // If currentTime exceeds the last interval, return the index of the last interval
                    if (currentTime >= intervals[intervals.length - 1]) {
                        return intervals.length - 1;
                    }
                    // If currentTime is before the first interval, return -1 indicating no question found
                    return -1;
                }

                let jsPlayer = document.querySelectorAll('.audio-player');
                jsPlayer.forEach(p => {
                    new Plyr(p, {
                        settings: []
                    });
                    p.ontimeupdate = function(){
                        let raw = p.dataset.intervals;
                        // Parse it safely, even if it contains NaN
                        let intervals = JSON.parse(
                        raw.replace(/\bNaN\b/g, '0') // Replace literal NaN with 0 before parsing
                        );

                        // Ensure all are numbers (just in case)
                        intervals = intervals.map(x => isNaN(x) ? 0 : x);
                        let ids             = p.dataset.qusIds;
                        let questionsIds    = document.querySelector(ids).textContent;
                        questionsIds        = JSON.parse(questionsIds);
                        
                        if(intervals.length > 0){
                            let cqId = questionsIds[findCurrentQuestionIndex(p.currentTime, intervals)];
                            jQuery('[data-q_id]').removeClass('active');
                            if(document.querySelector(`[data-q_id='${cqId}']`)){
                                document.querySelector(`[data-q_id='${cqId}']`).classList.add('active');
                            }
                        }
                    };
                });

                jQuery(document).on('click', '[data-plyr="true"]', function(){
                    let time    = jQuery(this).data("current-time");
                    let index   = jQuery(this).data("index");
                    let player  = document.querySelector(`#audio-player-${index}`);
                    if( player ) {
                        document.querySelectorAll('AUDIO').forEach(a => {
                            a.pause();
                        });
                        console.log('[time]', time);
                        player.currentTime = +time;
                        player.play();
                    }
                });
                
            </script>
            <script id="ai-evaluation-audio-js">
                // jQuery(document).ready(function($){
                //     $('.ai-audio-player').each(function(){
                //         let player = new Plyr(this, {
                //             settings: []
                //         });
                //     });
                // });
            </script>
            <?php return ob_get_clean();
        } else {

            ob_start(); ?>
            <script id="quiz-json" type="application/json">
                <?php echo json_encode( (object) $this->_q); ?>
            </script>
            <script id="session-details" type="application/json">
                <?php 
                    echo json_encode( (object) [
                        "_id"           => $this->_id,
                        "category"      => $this->category,
                        "time"          => $this->default,
                        "post_id"       => $this->post_id,
                        "session"       => $this->session
                    ]); 
                ?>
            </script>
            <script id="sot-details" type="application/json"></script>

            <script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
            <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js"></script>
            <script src="https://cdnjs.cloudflare.com/ajax/libs/jQuery-Knob/1.2.13/jquery.knob.min.js" integrity="sha512-NhRZzPdzMOMf005Xmd4JonwPftz4Pe99mRVcFeRDcdCtfjv46zPIi/7ZKScbpHD/V0HB1Eb+ZWigMqw94VUVaw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
            <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.4.1/dist/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>
            <script src="https://higuma.github.io/web-audio-recorder-js/js/WebAudioRecorder.min.js"></script>
            <script src="https://unpkg.com/wavesurfer.js@5.1.0/dist/wavesurfer.js"></script>
            <script src="https://unpkg.com/wavesurfer.js@5.1.0/dist/plugin/wavesurfer.microphone.js"></script>
            <script src="https://cdnjs.cloudflare.com/ajax/libs/plyr/3.6.9/plyr.min.js" integrity="sha512-Wt3CCBrK4mMw9PUEzDpKPMN7cLCq7/Uu7vxRtG+EQv+DO9Yae/LKSQTfziDj51y1yeSqqLt142lNyJtBXG/gSw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
            <script src="https://cdnjs.cloudflare.com/ajax/libs/roundSlider/1.3/roundslider.js"></script>
            <script src="<?php echo site_url();?>/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/js/speaking.js" type="text/javascript"></script>
            <?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;
    }

    /**
     * Normalize transcript issues returned by AI so UI can handle multiple error types.
     *
     * @param array|object $issue
     * @return array|null
     */
    protected function normalize_ai_transcript_issue($issue) {
        $issue = (array) $issue;
        $question_id = isset($issue['question_id']) ? (string) $issue['question_id'] : '';
        if (!$question_id) {
            return null;
        }

        $issue_types = [];
        if (!empty($issue['error_types']) && is_array($issue['error_types'])) {
            foreach ($issue['error_types'] as $type_entry) {
                $type_entry = (array) $type_entry;
                $type_name  = trim((string) ($type_entry['type'] ?? ''));
                $slug       = $type_name ? preg_replace('/[^a-z0-9]+/i', '-', strtolower($type_name)) : 'general';
                $slug       = trim($slug, '-') ?: 'general';

                $suggestions = [];
                if (isset($type_entry['suggestions'])) {
                    $raw_suggestions = is_array($type_entry['suggestions']) ? $type_entry['suggestions'] : [$type_entry['suggestions']];
                    foreach ($raw_suggestions as $suggestion_text) {
                        $suggestion_text = trim((string) $suggestion_text);
                        if ($suggestion_text !== '') {
                            $suggestions[] = $suggestion_text;
                        }
                    }
                }

                $issue_types[] = [
                    'type'        => $type_name ?: __('General', 'spacetree'),
                    'label'       => $type_name ?: __('General', 'spacetree'),
                    'slug'        => $slug,
                    'suggestions' => $suggestions,
                ];
            }
        }

        if (empty($issue_types)) {
            $legacy_type = isset($issue['error_type']) ? (string) $issue['error_type'] : '';
            $legacy_slug = $legacy_type ? preg_replace('/[^a-z0-9]+/i', '-', strtolower($legacy_type)) : 'general';
            $legacy_slug = trim($legacy_slug, '-') ?: 'general';

            $legacy_suggestions = [];
            if (isset($issue['suggestion'])) {
                $raw_suggestions = is_array($issue['suggestion']) ? $issue['suggestion'] : [$issue['suggestion']];
                foreach ($raw_suggestions as $suggestion_text) {
                    $suggestion_text = trim((string) $suggestion_text);
                    if ($suggestion_text !== '') {
                        $legacy_suggestions[] = $suggestion_text;
                    }
                }
            }

            $issue_types[] = [
                'type'        => $legacy_type ?: __('General', 'spacetree'),
                'label'       => $legacy_type ?: __('General', 'spacetree'),
                'slug'        => $legacy_slug,
                'suggestions' => $legacy_suggestions,
            ];
        }

        $primary_type = $issue_types[0];
        $suggestion_display = [];
        foreach ($issue_types as $type_entry) {
            if (empty($type_entry['suggestions'])) {
                continue;
            }
            foreach ($type_entry['suggestions'] as $suggestion_text) {
                $suggestion_display[] = sprintf('%s: %s', $type_entry['label'], $suggestion_text);
            }
        }

        return [
            'question_id'      => $question_id,
            'text'             => isset($issue['text']) ? (string) $issue['text'] : '',
            'issue'            => isset($issue['issue']) ? (string) $issue['issue'] : '',
            'type_slug'        => $primary_type['slug'],
            'type_label'       => $primary_type['label'],
            'suggestions_text' => implode(' | ', $suggestion_display),
            'issue_types'      => $issue_types,
            'error_type'       => $primary_type['label'],
            'suggestion'       => !empty($suggestion_display) ? $suggestion_display[0] : '',
        ];
    }

    public function filter_question( $questions = [], $question_id = null, $section_id = null ){
        // Check if both _id and _postId match the desired conditions
        foreach ($questions as $obj) {
            if ( $obj->_id == $question_id && $obj->_postId == $section_id ) {
                // Object with given _id and _postId exists
                return $obj;
            }
        }
        
        // Object with given _id and _postId does not exist
        return null;
    }

    /**
     * changes @1.2.1.2
     */
    public function dynamic_css_imports() {
        $site_url = site_url();
        ob_start(); 
        require_once 'ielts/speaking-dynamic-css.php';
        return ob_get_clean();
    }

    /**
     * changes @1.2.1.2
     */
    public function dynamic_js_imports_header(){
        ob_start(); ?>
        <script>
            window.site_url = `<?php echo site_url(); ?>`;
        </script>
        <?php return ob_get_clean();
    }

    /**
     * Normalize user role
     * 
     * Maps WordPress roles to simplified dashboard roles:
     * - admin → admin
     * - instructor, teacher, trainer → teacher
     * - everything else → student
     * 
     * @param array $roles Array of user roles
     * @return string Normalized role (admin, teacher, or student)
     */
    private function normalize_user_role( $roles ) {
        // Handle empty roles
        if ( empty( $roles ) || ! is_array( $roles ) ) {
            return 'student';
        }
        
        // Check for admin role first (highest priority)
        if ( in_array( 'administrator', $roles, true ) ) {
            return 'admin';
        }
        
        // Define teacher-equivalent roles
        $teacher_roles = array( 'instructor', 'teacher', 'trainer' );
        
        // Check if user has any teacher role
        foreach ( $roles as $role ) {
            if ( in_array( strtolower( $role ), $teacher_roles, true ) ) {
                return 'teacher';
            }
        }
        
        // Default to student for all other roles
        return 'student';
    }
    
}



