<?php $__env->startSection('content'); ?>
    <?php if(session('import_success') || session('test_success')): ?>
        <div class="floating-alert success">
            <?php echo e(session('import_success') ?? session('test_success')); ?>

        </div>
    <?php endif; ?>

    <section class="premium-dashboard dashboard-red-theme">
        <aside class="premium-sidebar">
            <div class="dashboard-brand-card">
                <img src="<?php echo e(asset('images/neutro-pharma-logo.svg')); ?>" alt="Neutro Pharma logo">
                <div>
                    <strong>Neutro Pharma</strong>
                    <small>(Pvt) Ltd.</small>
                </div>
            </div>

            <div class="sidebar-top">
                <button id="openTestModal" class="create-icon-button" type="button" aria-label="Create test" title="Create test">
                    +
                </button>
                <div>
                    <p class="eyebrow">Test Studio</p>
                    <h2>Tests</h2>
                </div>
            </div>

            <div class="sidebar-list-heading">
                <span>All Tests</span>
                <span class="sidebar-menu-icon" aria-hidden="true">&#9776;</span>
            </div>

            <div class="test-list">
                <?php $__currentLoopData = $quizzes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $managedQuiz): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <div class="test-item <?php if($quiz->id === $managedQuiz->id): ?> is-selected <?php endif; ?>">
                        <a class="test-link" href="<?php echo e(route('admin.quiz', ['quiz' => $managedQuiz->id])); ?>">
                            <span class="test-type"><?php echo e($managedQuiz->test_type); ?></span>
                            <strong><?php echo e($managedQuiz->title); ?></strong>
                            <small><?php echo e($managedQuiz->questions_count); ?> questions &middot; <?php echo e($managedQuiz->participants_count); ?> players</small>
                        </a>
                        <form method="POST" action="<?php echo e(route('admin.tests.toggle', ['quiz' => $managedQuiz->id])); ?>">
                            <?php echo csrf_field(); ?>
                            <button class="toggle-button <?php if(! $managedQuiz->is_enabled): ?> is-off <?php endif; ?>" type="submit">
                                <span class="status-dot"></span><?php echo e($managedQuiz->is_enabled ? 'Active' : 'Inactive'); ?>

                            </button>
                        </form>
                    </div>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </div>

            <nav class="sidebar-nav" aria-label="Admin navigation">
                <a class="sidebar-nav-link is-active" href="<?php echo e(route('admin.quiz', ['quiz' => $quiz->id])); ?>">
                    <span class="nav-icon" aria-hidden="true">&#9638;</span>
                    <span>Dashboard</span>
                </a>
                <button id="openQuestionsNav" class="sidebar-nav-link" type="button">
                    <span class="nav-icon" aria-hidden="true">&#9633;</span>
                    <span>Questions</span>
                </button>
                <a class="sidebar-nav-link" href="#participantsPanel">
                    <span class="nav-icon" aria-hidden="true">&#9675;</span>
                    <span>Participants</span>
                </a>
                <a class="sidebar-nav-link" href="<?php echo e(route('admin.reports.show', ['quiz' => $quiz->id])); ?>">
                    <span class="nav-icon" aria-hidden="true">&#9616;</span>
                    <span>Reports</span>
                </a>
                <button id="openSettingsNav" class="sidebar-nav-link" type="button">
                    <span class="nav-icon" aria-hidden="true">&#9881;</span>
                    <span>Settings</span>
                </button>
            </nav>

            <div class="sidebar-user-card">
                <span class="admin-avatar" aria-hidden="true">A</span>
                <div>
                    <strong>Admin User</strong>
                    <small>admin@teststudio.com</small>
                </div>
            </div>
        </aside>

        <section class="dashboard-main">
            <header class="dashboard-header premium-hero">
                <div>
                    <div class="hero-brand-strip">
                        <img src="<?php echo e(asset('images/neutro-pharma-logo.svg')); ?>" alt="Neutro Pharma logo">
                        <div>
                            <strong>Neutro Pharma (Pvt) Ltd.</strong>
                            <span>Learning and assessment dashboard</span>
                        </div>
                    </div>
                    <p class="eyebrow"><?php echo e($quiz->test_type); ?> &middot; <?php echo e($quiz->is_enabled ? 'Active' : 'Inactive'); ?></p>
                    <h1><?php echo e($quiz->title); ?></h1>
                    <?php if($quiz->is_enabled): ?>
                        <p class="muted">Participant link: <a href="<?php echo e(route('quiz.join', ['quizSlug' => $quiz->slug])); ?>"><?php echo e(route('quiz.join', ['quizSlug' => $quiz->slug])); ?></a></p>
                    <?php else: ?>
                        <p class="muted">Enable this test before sharing the participant link.</p>
                    <?php endif; ?>
                </div>
                <div class="admin-actions action-grid">
                    <button id="openImportModal" class="secondary-button action-button" type="button">
                        <span class="button-icon" aria-hidden="true">&#8679;</span>
                        <span>Import Questions</span>
                    </button>
                    <a class="secondary-button action-link action-button" href="<?php echo e(route('admin.reports.show', ['quiz' => $quiz->id])); ?>">
                        <span class="button-icon" aria-hidden="true">&#9616;</span>
                        <span>Result Report</span>
                    </a>
                    <button id="startBtn" class="primary-button action-button start-action" <?php if(! $quiz->is_enabled || $quiz->questions->isEmpty() || $shouldShowFinalResult): echo 'disabled'; endif; ?>>
                        <span class="button-icon" aria-hidden="true">&#9655;</span>
                        <span>Start Quiz</span>
                    </button>
                    <button id="nextBtn" class="secondary-button action-button" <?php if(! $quiz->is_enabled || $quiz->questions->isEmpty() || $shouldShowFinalResult): echo 'disabled'; endif; ?>>
                        <span class="button-icon" aria-hidden="true">&#8594;</span>
                        <span>Next Question</span>
                    </button>
                    <button id="resetBtn" class="danger-button action-button">
                        <span class="button-icon" aria-hidden="true">&#8635;</span>
                        <span>Reset</span>
                    </button>
                    <form method="POST" action="<?php echo e(route('admin.logout')); ?>" class="inline-form">
                        <?php echo csrf_field(); ?>
                        <button class="secondary-button action-button" type="submit">
                            <span class="button-icon" aria-hidden="true">&#10162;</span>
                            <span>Logout</span>
                        </button>
                    </form>
                </div>
            </header>

            <?php if(! $quiz->is_enabled || $quiz->questions->isEmpty()): ?>
                <section class="admin-notice-card">
                    <span class="notice-icon" aria-hidden="true">!</span>
                    <div>
                        <strong>
                            <?php if(! $quiz->is_enabled): ?>
                                This test is inactive.
                            <?php else: ?>
                                This test has no questions.
                            <?php endif; ?>
                        </strong>
                        <p>
                            <?php if(! $quiz->is_enabled): ?>
                                The selected test cannot be started and participants cannot join it until it is enabled.
                            <?php else: ?>
                                Add a question or import from the Excel template before clicking Start Quiz.
                            <?php endif; ?>
                        </p>
                    </div>

                    <div class="admin-notice-actions">
                        <?php if(! $quiz->is_enabled): ?>
                            <form method="POST" action="<?php echo e(route('admin.tests.toggle', ['quiz' => $quiz->id])); ?>">
                                <?php echo csrf_field(); ?>
                                <button class="primary-button" type="submit">Enable Test</button>
                            </form>
                        <?php endif; ?>
                        <button id="openImportModalNotice" class="secondary-button" type="button">Import Questions</button>
                    </div>
                </section>
            <?php endif; ?>

            <section class="card status-card">
                <div>
                    <span class="status-card-icon" aria-hidden="true">&#10003;</span>
                    <div>
                        <p class="label">Quiz Status</p>
                        <span id="statusPill" class="pill"><?php echo e(strtoupper($dashboardStatus)); ?></span>
                    </div>
                </div>
                <div>
                    <span class="status-card-icon muted-icon" aria-hidden="true">&#9711;</span>
                    <div>
                        <p class="label">Test Mode</p>
                        <strong class="big-number compact-number"><?php echo e($quiz->is_enabled ? 'ON' : 'OFF'); ?></strong>
                    </div>
                </div>
                <div>
                    <span class="status-card-icon" aria-hidden="true">&#9633;</span>
                    <div>
                        <p class="label">Questions</p>
                        <strong class="big-number"><?php echo e($quiz->questions->count()); ?></strong>
                    </div>
                </div>
                <div>
                    <span class="status-card-icon" aria-hidden="true">&#9675;</span>
                    <div>
                        <p class="label">Participants</p>
                        <strong id="participantCount" class="big-number"><?php echo e(count($participants)); ?></strong>
                    </div>
                </div>
                <div>
                    <span class="status-card-icon muted-icon" aria-hidden="true">&#9716;</span>
                    <div>
                        <p class="label">Timer</p>
                        <strong id="timer" class="big-number">--</strong>
                    </div>
                </div>
            </section>

            <section class="card question-card <?php if($shouldShowFinalResult): ?> is-finished <?php endif; ?>">
                <p class="label">Current Question</p>
                <h2 id="questionTitle"><?php echo e($shouldShowFinalResult ? 'Quiz finished. Result saved until reset.' : 'Waiting to start...'); ?></h2>
                <div id="questionOptions" class="option-list"></div>
            </section>

            <section class="card top-three-card">
                <div class="section-title-row">
                    <div>
                        <p id="topThreeLabel" class="label"><?php echo e($shouldShowFinalResult ? 'Final Result' : 'Fastest Correct Answers'); ?></p>
                        <h2 id="topThreeTitle"><?php echo e($shouldShowFinalResult ? 'Final Top 3' : 'Live Top 3'); ?></h2>
                    </div>
                </div>
                <div id="topThree" class="podium">
                    <div class="podium-box second"><span>2nd</span><strong>Waiting</strong></div>
                    <div class="podium-box first"><span>1st</span><strong>Waiting</strong></div>
                    <div class="podium-box third"><span>3rd</span><strong>Waiting</strong></div>
                </div>
            </section>

            <section id="participantsPanel" class="card participants-card">
                <div class="section-title-row">
                    <div>
                        <p class="label">Live Participants</p>
                        <h2>Active list</h2>
                    </div>
                </div>
                <ul id="participantList" class="participant-list"></ul>
            </section>

            <section class="card overall-card">
                <p class="label">Cumulative Score</p>
                <h2>Overall Leaderboard</h2>
                <ol id="overallList" class="overall-list"></ol>
            </section>
        </section>
    </section>

    <div id="testModal" class="modal-backdrop <?php if($errors->has('title') || $errors->has('test_type')): ?> is-open <?php endif; ?>" aria-hidden="<?php echo e(($errors->has('title') || $errors->has('test_type')) ? 'false' : 'true'); ?>">
        <section class="modal-panel builder-modal-panel" role="dialog" aria-modal="true" aria-labelledby="testModalTitle">
            <div class="section-title-row">
                <div>
                    <p class="label">New Quiz</p>
                    <h2 id="testModalTitle">Create Test</h2>
                </div>
                <button id="closeTestModal" class="icon-button" type="button" aria-label="Close test form">x</button>
            </div>

            <?php if($errors->has('title') || $errors->has('test_type')): ?>
                <div class="alert error">
                    <?php echo e($errors->first()); ?>

                </div>
            <?php endif; ?>

            <form method="POST" action="<?php echo e(route('admin.tests.store')); ?>" class="new-quiz-card modal-new-quiz-form">
                <?php echo csrf_field(); ?>
                <input type="hidden" name="test_type" value="General">
                <input type="hidden" name="is_enabled" value="1">
                <input id="test_title" name="title" value="<?php echo e(old('title')); ?>" required maxlength="160" placeholder="Quiz title">
                <textarea name="description" rows="3" maxlength="1000" placeholder="Description"><?php echo e(old('description')); ?></textarea>
                <button class="builder-primary-button" type="submit"><span>+</span>Create</button>
            </form>
        </section>
    </div>

    <div id="importModal" class="modal-backdrop import-builder-backdrop <?php if($errors->has('questions_import') || $errors->has('questions_file') || $errors->has('question_text')): ?> is-open <?php endif; ?>" aria-hidden="<?php echo e(($errors->has('questions_import') || $errors->has('questions_file') || $errors->has('question_text')) ? 'false' : 'true'); ?>">
        <section class="modal-panel import-builder-panel" role="dialog" aria-modal="true" aria-labelledby="importModalTitle">
            <div class="import-builder-header">
                <div>
                    <p class="label">Questions & Answers</p>
                    <h2 id="importModalTitle">Import Questions</h2>
                </div>
                <button id="closeImportModal" class="icon-button" type="button" aria-label="Close import form">x</button>
            </div>

            <section class="import-builder-shell">
                <aside class="quiz-builder-sidebar">
                    <form method="POST" action="<?php echo e(route('admin.tests.store')); ?>" class="builder-card new-quiz-card">
                        <?php echo csrf_field(); ?>
                        <input type="hidden" name="test_type" value="General">
                        <input type="hidden" name="is_enabled" value="1">
                        <h2>New Quiz</h2>
                        <input name="title" value="<?php echo e(old('title')); ?>" required maxlength="160" placeholder="Quiz title">
                        <textarea name="description" rows="3" maxlength="1000" placeholder="Description"><?php echo e(old('description')); ?></textarea>
                        <button class="builder-primary-button" type="submit"><span>+</span>Create</button>
                    </form>

                    <div class="builder-quiz-list">
                        <?php $__currentLoopData = $quizzes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $managedQuiz): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <article class="builder-quiz-item <?php if($quiz->id === $managedQuiz->id): ?> is-selected <?php endif; ?>">
                                <a href="<?php echo e(route('admin.quiz', ['quiz' => $managedQuiz->id])); ?>">
                                    <strong><?php echo e($managedQuiz->title); ?></strong>
                                    <span><?php echo e($managedQuiz->is_enabled ? 'Active' : 'Inactive'); ?></span>
                                </a>

                                <div class="builder-quiz-actions">
                                    <form method="POST" action="<?php echo e(route('admin.tests.toggle', ['quiz' => $managedQuiz->id])); ?>">
                                        <?php echo csrf_field(); ?>
                                        <button class="mini-action-button" type="submit"><?php echo e($managedQuiz->is_enabled ? 'Disable' : 'Enable'); ?></button>
                                    </form>
                                    <form method="POST" action="<?php echo e(route('admin.tests.destroy', ['quiz' => $managedQuiz->id])); ?>" onsubmit="return confirm('Delete this quiz and all of its questions?')">
                                        <?php echo csrf_field(); ?>
                                        <?php echo method_field('DELETE'); ?>
                                        <button class="delete-icon-button" type="submit" aria-label="Delete <?php echo e($managedQuiz->title); ?>">x</button>
                                    </form>
                                </div>
                            </article>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </div>
                </aside>

                <main class="quiz-builder-main">
                    <section class="builder-card add-question-card">
                        <div class="builder-section-title">
                            <div>
                                <h1>Add Question</h1>
                                <p><?php echo e($quiz->title); ?> &middot; <?php echo e($quiz->questions->count()); ?> questions</p>
                            </div>
                            <a class="builder-link-pill" href="<?php echo e(route('quiz.join', ['quizSlug' => $quiz->slug])); ?>">Join Link</a>
                        </div>

                        <?php if($errors->has('question_text') || $errors->has('option_a') || $errors->has('correct_option')): ?>
                            <div class="alert error">
                                <?php echo e($errors->first()); ?>

                            </div>
                        <?php endif; ?>

                        <form method="POST" action="<?php echo e(route('admin.questions.store')); ?>" class="question-builder-form">
                            <?php echo csrf_field(); ?>
                            <input type="hidden" name="quiz_id" value="<?php echo e($quiz->id); ?>">
                            <textarea id="import_question_text" name="question_text" rows="3" required placeholder="Question text"><?php echo e(old('question_text')); ?></textarea>

                            <div class="answer-option-grid">
                                <?php $__currentLoopData = ['A', 'B', 'C', 'D']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $letter): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <?php $field = 'option_'.strtolower($letter); ?>
                                    <label class="answer-option-row">
                                        <input type="radio" name="correct_option" value="<?php echo e($letter); ?>" <?php if(old('correct_option', 'A') === $letter): echo 'checked'; endif; ?>>
                                        <span><?php echo e($letter); ?></span>
                                        <input name="<?php echo e($field); ?>" value="<?php echo e(old($field)); ?>" required maxlength="255" placeholder="Option <?php echo e($loop->iteration); ?>">
                                    </label>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </div>

                            <div class="question-form-footer">
                                <div>
                                    <label for="duration_seconds">Time limit (seconds)</label>
                                    <input id="duration_seconds" name="duration_seconds" type="number" value="<?php echo e(old('duration_seconds', 15)); ?>" min="5" max="300" required>
                                </div>
                                <p>Correct: <strong id="correctChoiceLabel"><?php echo e(old('correct_option', 'A')); ?></strong></p>
                            </div>

                            <button class="builder-primary-button add-question-button" type="submit"><span>+</span>Add Question</button>
                        </form>
                    </section>

                    <section class="bulk-import-panel">
                        <div class="bulk-import-icon">#</div>
                        <div>
                            <h2>Bulk Import from Excel</h2>
                            <p>Download the template, review the rows, then import only if the file is clean.</p>
                        </div>

                        <?php if($errors->has('questions_import') || $errors->has('questions_file')): ?>
                            <div class="alert error bulk-alert">
                                <?php echo e($errors->first()); ?>

                            </div>
                        <?php endif; ?>

                        <form method="POST" action="<?php echo e(route('admin.quiz.import', ['quiz' => $quiz->id])); ?>" enctype="multipart/form-data" class="bulk-import-actions">
                            <?php echo csrf_field(); ?>
                            <input type="hidden" name="quiz_id" value="<?php echo e($quiz->id); ?>">
                            <input type="hidden" name="replace_existing" value="1">
                            <a class="template-download-button" href="<?php echo e(route('admin.templates.questions')); ?>" download>Download Template</a>
                            <label class="builder-primary-button upload-button">
                                Upload CSV
                                <input name="questions_file" type="file" accept=".csv,.txt,text/csv,text/plain" onchange="this.form.submit()">
                            </label>
                        </form>

                        <p class="bulk-columns">Columns: <code>question_text</code>, <code>option_a</code>, <code>option_b</code>, <code>option_c</code>, <code>option_d</code>, <code>correct_option</code> (A/B/C/D), <code>time_limit</code></p>
                    </section>

                    <section class="questions-table-section">
                        <h2>Questions (<?php echo e(count($questionList)); ?>)</h2>
                        <div class="questions-table">
                            <?php $__empty_1 = true; $__currentLoopData = $questionList; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                <article class="question-row-card">
                                    <span><?php echo e($item['sort_order']); ?></span>
                                    <div>
                                        <strong><?php echo e($item['text']); ?></strong>
                                        <small>Correct: <?php echo e(['', 'A', 'B', 'C', 'D'][$item['correct_option'] ?? 0] ?? '-'); ?> &middot; <?php echo e($item['duration_seconds']); ?>s</small>
                                    </div>
                                </article>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                <p class="empty-state">No questions yet. Add one manually or import a template.</p>
                            <?php endif; ?>
                        </div>
                    </section>
                </main>
            </section>
        </section>
    </div>

    <script>
        window.quizApp = <?php echo \Illuminate\Support\Js::from([
            'quizUuid' => $quiz->uuid,
            'csrf' => csrf_token(),
            'csrfUrl' => route('csrf.token'),
            'routes' => [
                'start' => route('admin.quiz.start', ['quiz' => $quiz->id]),
                'next' => route('admin.quiz.next', ['quiz' => $quiz->id]),
                'reset' => route('admin.quiz.reset', ['quiz' => $quiz->id]),
            ],
            'canControl' => $quiz->is_enabled && $quiz->questions->isNotEmpty() && ! $shouldShowFinalResult,
            'shouldShowFinalResult' => $shouldShowFinalResult,
            'participants' => $participants,
            'state' => $state,
            'topThree' => $topThree,
            'overall' => $overall,
        ]); ?>;
    </script>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('vite'); ?>
    <?php echo app('Illuminate\Foundation\Vite')(['resources/css/app.css', 'resources/js/admin.js']); ?>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('layout', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH G:\xampp\htdocs\quizapp\resources\views/admin.blade.php ENDPATH**/ ?>