// Path: Frontend/src/components/assignment/shared/assignment-question-list.tsx

import type { Component } from "solid-js";
import { For, Show } from "solid-js";
import styles from "./assignment-question-list.module.scss";
import type { AssignmentPageData } from "./assignment-types";

type Props = {
	data: AssignmentPageData;
};

const AssignmentQuestionList: Component<Props> = (props) => {
	return (
		<section class={styles.section}>
			<div class={styles.header}>
				<h2>Question review</h2>
				<p>{props.data.questions.length} questions in this assignment</p>
			</div>

			<div class={styles.list}>
				<For each={props.data.questions}>
					{(question) => (
						<article class={styles.card}>
							<div class={styles.cardTop}>
								<div>
									<p class={styles.order}>Question {question.order}</p>
									<h3>{question.prompt}</h3>
								</div>
								<span classList={{ [styles.statusPill]: true, [styles[question.statusTone]]: true }}>{question.statusLabel}</span>
							</div>

							<div class={styles.metaRow}>
								<span>{question.topic}</span>
								<Show when={question.subTopic}>
									<span>{question.subTopic}</span>
								</Show>
								<Show when={question.difficulty}>
									<span>{question.difficulty}</span>
								</Show>
								<Show when={question.marks !== null}>
									<span>{question.marks} mark</span>
								</Show>
								<Show when={question.solveModeLabel}>
									<span>{question.solveModeLabel}</span>
								</Show>
							</div>

							<div class={styles.responseBlock}>
								<p>{question.responseLabel}</p>
								<strong>{question.responseValue}</strong>
								<Show when={question.feedback}>
									<span>{question.feedback}</span>
								</Show>
							</div>

							<Show when={question.workingSteps}>
								<div class={styles.supportBlock}>
									<p>Your steps and explanation</p>
									<pre>{question.workingSteps}</pre>
								</div>
							</Show>

							<Show when={question.showAnswerKey}>
								<div class={styles.answerKey}>
									<p>Correct answer</p>
									<strong>{question.correctAnswer}</strong>
								</div>
							</Show>
						</article>
					)}
				</For>
			</div>
		</section>
	);
};

export default AssignmentQuestionList;
