<?php
/**
 * template: ProQyz fullmock test template
 */

$proqyz_lesson = (object) $lesson;
$mock_test__course_id = $proqyz_lesson->_courseId;
$mock_test__lesson_id = $proqyz_lesson->_id;
$quizzes = $proqyz_lesson->quizzes;
$course = (object) $res_course;
$course_title = isset($course->title)?  $course->title : "Unknown course";
$lesson_title = isset($proqyz_lesson->title)? $proqyz_lesson->title : "";

// body classes
$body_classNames = "user-logged-in path-take-test page-node-type-set has-glyphicons";
// site logo
$custom_logo_id = get_theme_mod( 'custom_logo' );
$logo_url = wp_get_attachment_image_url( $custom_logo_id , 'full' );
// urls constants
$site_url           = site_url();
$assets_url         = $site_url . '/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/full-mock-test/dist';

# update - slug
$course_url         = st_proqyz_get_course_url( $mock_test__course_id );
$instructions_url   = st_proqyz_get_mock_test_url( $mock_test__course_id, $mock_test__lesson_id, "general-guidance");


$is_admin = false;
$current_step = "not-started";
$current_user = wp_get_current_user();
$current_user_id = $current_user->ID;
// if its admin , teacher or student based on below function
$current_user_role = fullmock_test_normalize_user_role( $current_user->roles );   
if( $current_user_role === "admin" || $current_user_role === "teacher" ) {
    // now we need to use given user_id which may be from $_GET['child_id']
    if(isset($_GET['child_id']) && $_GET['child_id'] !== "") {
        $child_user_id = (int) $_GET['child_id'];
        if( $child_user_id !== $current_user_id ) {
            $current_user_id = $child_user_id;
            $is_admin = true;
        }
    }
}


$get_full_test_meta = get_user_meta( $current_user_id, "proqyz__full-mock-test--$mock_test__course_id-$mock_test__lesson_id", true);
if( $get_full_test_meta) {
    $get_full_test_meta = (object) $get_full_test_meta;
    if(isset($get_full_test_meta->status)) {
        if($get_full_test_meta->status === "speaking-completed--finish-test") {
            $current_step = "finish-test";
        } 
    }
}

if( $current_step !== "finish-test" ){
    wp_redirect( esc_url( $instructions_url ) );
    exit;
}


// get quizzes []
$steps_quizzes  = ["ielts-listening", "ielts-reading", "ielts-writing", "ielts-speaking"];
# update - slug
$quiz_result_data = (object) get_fullmock_test_results($mock_test__course_id, $mock_test__lesson_id, $current_user_id);
$listening_html = $quiz_result_data->listening;
$reading_html = $quiz_result_data->reading;
$writing_html = $quiz_result_data->writing;
$speaking_html = $quiz_result_data->speaking;
$combine_html = $listening_html . $reading_html . $writing_html . $speaking_html;




// request rest test
if ( isset($_GET['reset_test']) && $_GET['reset_test'] == true ) {
    if ( is_user_logged_in() ) {
        if( $is_admin ) {
            reset_fullmock_test_as_admin($mock_test__course_id, $mock_test__lesson_id, $current_user_id);
        } else {
            reset_fullmock_test($mock_test__course_id, $mock_test__lesson_id);
        }
    }
}





?>
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
    <meta charset="<?php bloginfo('charset'); ?>" />    
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <?php echo dynamic_css_imports(); ?>
    <link rel="stylesheet" href="<?php echo site_url() . '/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/css/polyfixes.css'; ?>" />
    <link rel="stylesheet" href="<?php echo site_url() . '/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/quiz/dist/css/proqyz-quiz.css'; ?>" />
    <link rel="stylesheet" href="<?php echo site_url() . '/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/full-mock-test/dist/css/result.css'; ?>" />
    <style>
        .take-test__body {
            display: flex;
            flex-direction: column;
            justify-content: flex-end;
        }

        .test-result .practice-item__icon {
            display: inline-block;
            width: 32px;
            height: 32px;
            background: url(<?php echo $assets_url; ?>/icons/headphone-duotone.svg) center no-repeat;
            background-size: contain;
            margin-bottom: 5px;
        }

        .test-result .practice-item__icon.-reading {
            background-image: url(<?php echo $assets_url; ?>/icons/notepad.svg);
        }

        .test-result .practice-item__icon.-writing {
            background-image: url(<?php echo $assets_url; ?>/icons/pennibstraight.svg);
        }

        .test-result .practice-item__icon.-speaking {
            background-image: url(<?php echo $assets_url; ?>/icons/microphone.svg);
        }
    </style>
</head>    
<body class="<?php echo $body_classNames; ?>">
    <div class="dialog-off-canvas-main-canvas" data-off-canvas-main-canvas="">
        <header class="realtest-header">
            <?php if( $logo_url ) { ?> 
                <img style="width:145px;" src="<?php echo esc_url( $logo_url ); ?>" alt="<?php echo get_bloginfo( 'name' ); ?>" class="realtest-header__logo" />
            <?php } else { ?>
                <h4 class="site--title"><?php echo get_bloginfo( 'name' ); ?></h4>    
            <?php } ?>
            <div class="realtest-header__user-id hide"></div>
            <a href="<?php echo $course_url; ?>" class="realtest-header__btn-exit hide">
                Exit<span class="ioticon-log-out"></span>
            </a>
        </header>
        
        <div class="page test-result">
            <div class="take-test__body">
                <div class="region region-content">
                    <div data-drupal-messages-fallback="" class="hidden"></div>
                    <div class="result-box">
                        <img src="<?php echo $assets_url.'/img/congratulation-people.svg'; ?>" alt="" class="result-box__people-img">
                        <h1 class="result-box__title">Congratulations!</h1>
                        <div class="result-box__caption">You have finished the</div>
                        <div class="result-box__test-name"><?php echo $course_title; ?> - <?php echo $lesson_title; ?></div>
                        <div class="result-box__contents flex-grid">
                            <?php echo $combine_html; ?>
                        </div>
                    </div>
                    <div class="result-box__note">In the real exam, your results will be available 3 to 5 days after your test date.</div>
                    <div style="display: flex;align-items: center;justify-content: center;margin: 40px auto 40px;">
                        <a href="<?php echo $course_url; ?>" class="result-box__bottom-btn iot-grbt -white" style="width:auto;margin:0;">
                            Go to Test Collection <span class="ioticon-next-icon"></span>
                        </a>
                        <div class="gap-4" style="padding:0 10px;"></div>
                        <a href="javascript:;" class="result-box__bottom-btn iot-grbt -primary" style="width:auto;margin:0;" data-toggle="modal" data-target="#modal-reset-test">
                            Reset Progress <span class="ioticon-trash-3"></span>
                        </a>
                    </div>
                    
                </div>
            </div>
        </div>

        <?php if( $is_admin ) { ?>
            <?php echo reset_modals($mock_test__course_id, $mock_test__lesson_id, $current_user_id); ?>        
        <?php } else { ?>
            <?php echo reset_modals($mock_test__course_id, $mock_test__lesson_id); ?>        
        <?php } ?>
    </div>
<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.nicescroll/3.7.6/jquery.nicescroll.min.js" integrity="sha512-zMfrMAZYAlNClPKjN+JMuslK/B6sPM09BGvrWlW+cymmPmsUT1xJF3P4kxI3lOh9zypakSgWaTpY6vDJY/3Dig==" 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="<?php echo $site_url . '/wp-content/plugins/spacetree/libs/proqyz/includes/templates/public/full-mock-test/dist/js/progress-bar.js'; ?>"></script>

</body>
</html>

