<?php
/**
 * Shortcode front-end template.
 *
 * Variables available:
 *   $title          (string)  Sanitized shortcode title.
 *   $show_header    (bool)    Whether to show the header section.
 *   $show_learndash (bool)    Whether to show LearnDash integration button.
 *   $max_questions  (int)     Maximum number of questions.
 *
 * @package MasterQuiz
 * @since   1.0.0
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
?>
<div class="masterquiz-wrapper" id="masterquiz-wrapper">

	<!-- Dropzone -->
	<div class="masterquiz-dropzone" id="masterquiz-dropzone">
		<div id="masterquiz-dropzone-content">
			<div class="masterquiz-dropzone-icon">
				<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
					<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" />
					<polyline points="17 8 12 3 7 8" />
					<line x1="12" y1="3" x2="12" y2="15" />
				</svg>
			</div>
			<div class="masterquiz-dropzone-text">
				<?php
				echo wp_kses(
					sprintf(
						/* translators: %1$s: opening tag, %2$s: closing tag for the browse link */
						__( 'Drop your PDF here or %1$sbrowse%2$s', 'masterquiz-ai' ),
						'<span class="masterquiz-browse-link">',
						'</span>'
					),
					array( 'span' => array( 'class' => array() ) )
				);
				?>
			</div>
			<div class="masterquiz-dropzone-subtext">
				<?php
				printf(
					/* translators: %d: maximum file size in MB */
					esc_html__( 'PDF to Quiz Generator: upload PDF to quiz (up to %dMB)', 'masterquiz-ai' ),
					absint( get_option( 'masterquiz_max_pdf_size', 10 ) )
				);
				?>
			</div>
		</div>
		<!-- File info (shown inside dropzone after file selection) -->
		<div class="masterquiz-file-info" id="masterquiz-file-info">
			<div class="masterquiz-file-check-icon">
				<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
					<path d="M22 11.08V12a10 10 0 1 1-5.93-9.14" />
					<polyline points="22 4 12 14.01 9 11.01" />
				</svg>
			</div>
			<div class="masterquiz-file-name" id="masterquiz-file-name"></div>
			<div class="masterquiz-file-size" id="masterquiz-file-size"></div>
			<button type="button" id="masterquiz-remove-file" class="masterquiz-remove-btn">
				<?php esc_html_e( 'Remove', 'masterquiz-ai' ); ?>
			</button>
		</div>
		<input type="file" id="masterquiz-file-input" accept="application/pdf,.pdf" style="display:none;" />
	</div>

	<!-- Settings -->
	<div class="masterquiz-settings">
		<div class="masterquiz-setting-group">
			<label for="masterquiz-num-questions">
				<?php esc_html_e( 'Number of Questions', 'masterquiz-ai' ); ?>
			</label>
			<input type="number" id="masterquiz-num-questions" min="3" max="<?php echo esc_attr( $max_questions ); ?>" value="5" />
			<small class="masterquiz-helper-text">
				<?php
				printf(
					/* translators: %d: max number of questions */
					esc_html__( '3-%d questions per quiz', 'masterquiz-ai' ),
					(int) $max_questions
				);
				?>
			</small>
		</div>

		<div class="masterquiz-setting-group">
			<label for="masterquiz-quiz-mode">
				<?php esc_html_e( 'Generation Mode', 'masterquiz-ai' ); ?>
			</label>
			<select id="masterquiz-quiz-mode">
				<option value="fast"><?php esc_html_e( 'Fast Mode', 'masterquiz-ai' ); ?></option>
				<option value="quality"><?php esc_html_e( 'Quality Mode', 'masterquiz-ai' ); ?></option>
			</select>
		</div>

		<div class="masterquiz-setting-group masterquiz-question-types">
			<label><?php esc_html_e( 'Question Types', 'masterquiz-ai' ); ?></label>
			<div class="masterquiz-checkbox-group">
				<label>
					<input type="checkbox" name="masterquiz_question_types[]" value="mcq" checked />
					<span><?php esc_html_e( 'Multiple Choice', 'masterquiz-ai' ); ?></span>
				</label>
				<label>
					<input type="checkbox" name="masterquiz_question_types[]" value="true_false" checked />
					<span><?php esc_html_e( 'True / False', 'masterquiz-ai' ); ?></span>
				</label>
				<label>
					<input type="checkbox" name="masterquiz_question_types[]" value="essay" checked />
					<span><?php esc_html_e( 'Essay', 'masterquiz-ai' ); ?></span>
				</label>
			</div>
		</div>
	</div>

	<!-- Generate button -->
	<button type="button" class="masterquiz-generate-btn" id="masterquiz-generate-btn" disabled>
		<?php esc_html_e( 'Generate Quiz', 'masterquiz-ai' ); ?>
	</button>

	<div class="masterquiz-below-btn-links">
		<a href="#" id="masterquiz-try-sample" role="button">
			<?php esc_html_e( 'Try the Free AI Quiz Generator with sample PDF to quiz', 'masterquiz-ai' ); ?> &rarr;
		</a>
		<a href="<?php echo esc_url( MASTERQUIZ_PLUGIN_URL . 'public/sample/sample.pdf' ); ?>" target="_blank" rel="noopener noreferrer" download>
			<?php esc_html_e( 'Download sample PDF (see what the quiz is based on)', 'masterquiz-ai' ); ?>
		</a>
	</div>

	<!-- Progress bar -->
	<div class="masterquiz-progress" id="masterquiz-progress">
		<div class="masterquiz-progress-bar-wrapper">
			<div class="masterquiz-progress-bar" id="masterquiz-progress-bar"></div>
		</div>
		<div class="masterquiz-progress-text" id="masterquiz-progress-text">
			<?php esc_html_e( 'Starting...', 'masterquiz-ai' ); ?>
		</div>
	</div>

	<!-- Messages -->
	<div class="masterquiz-message" id="masterquiz-message"></div>

	<!-- Quiz results -->
	<div class="masterquiz-results" id="masterquiz-results">
		<div class="masterquiz-results-header">
			<h3><?php esc_html_e( 'Your Quiz is Ready!', 'masterquiz-ai' ); ?></h3>
			<div class="masterquiz-results-actions">
				<button type="button" class="masterquiz-btn masterquiz-btn-primary" id="masterquiz-export-btn">
					<?php esc_html_e( 'Download All Formats', 'masterquiz-ai' ); ?>
				</button>
				<?php if ( $show_learndash ) : ?>
				<button type="button" class="masterquiz-btn masterquiz-btn-success" id="masterquiz-create-ld-btn">
					<?php esc_html_e( 'Create LearnDash Quiz', 'masterquiz-ai' ); ?>
				</button>
				<?php endif; ?>
				<button type="button" class="masterquiz-btn masterquiz-btn-secondary" id="masterquiz-new-quiz-btn">
					<?php esc_html_e( 'New Quiz', 'masterquiz-ai' ); ?>
				</button>
			</div>
		</div>

		<!-- LearnDash result message -->
		<div class="masterquiz-learndash-result" id="masterquiz-learndash-result"></div>

		<!-- Questions container (populated by JS) -->
		<div id="masterquiz-questions-container"></div>

		<!-- Navigation -->
		<div class="masterquiz-navigation" id="masterquiz-navigation" style="display:none;">
			<button type="button" class="masterquiz-btn masterquiz-btn-secondary" id="masterquiz-prev-btn" disabled>
				&laquo; <?php esc_html_e( 'Previous', 'masterquiz-ai' ); ?>
			</button>
			<span class="masterquiz-question-counter" id="masterquiz-question-counter"></span>
			<button type="button" class="masterquiz-btn masterquiz-btn-secondary" id="masterquiz-next-btn">
				<?php esc_html_e( 'Next', 'masterquiz-ai' ); ?> &raquo;
			</button>
		</div>
	</div>

	<!-- Export modal -->
	<div class="masterquiz-export-modal" id="masterquiz-export-modal">
		<div class="masterquiz-export-modal-content">
			<h3><?php esc_html_e( 'Export Quiz', 'masterquiz-ai' ); ?></h3>
			<div class="masterquiz-export-format-list">
				<button type="button" class="masterquiz-export-format-btn" data-format="json">JSON</button>
				<button type="button" class="masterquiz-export-format-btn" data-format="xml">XML</button>
				<button type="button" class="masterquiz-export-format-btn" data-format="csv">CSV</button>
				<button type="button" class="masterquiz-export-format-btn" data-format="txt">Text</button>
				<button type="button" class="masterquiz-export-format-btn" data-format="gift">GIFT (Moodle)</button>
				<button type="button" class="masterquiz-export-format-btn" data-format="qti">QTI</button>
				<button type="button" class="masterquiz-export-format-btn" data-format="aiken">Aiken</button>
				<button type="button" class="masterquiz-export-format-btn" data-format="learndash_csv">LearnDash CSV</button>
				<button type="button" class="masterquiz-export-format-btn" data-format="learndash_xml">LearnDash XML</button>
			</div>
			<button type="button" class="masterquiz-export-close" id="masterquiz-export-close">
				<?php esc_html_e( 'Close', 'masterquiz-ai' ); ?>
			</button>
		</div>
	</div>

</div>
