@extends('layouts.app')
@section('title','Thêm câu hỏi')
@section('content')<h3 class="fw-bold mb-4">Thêm câu hỏi</h3>@if($errors->any())<div class="alert alert-danger">Vui lòng kiểm tra dữ liệu.</div>@endif<div class="card shadow-sm"><div class="card-body"><form action="{{ route('question-bank.store') }}" method="POST">@csrf <div class="row g-3"><div class="col-md-3"><label>Mã câu hỏi</label><input name="code" class="form-control" value="{{ old('code',$questionBank->code ?? '') }}" required></div><div class="col-md-5"><label>Chủ đề</label><select name="question_topic_id" class="form-select" required><option value="">-- Chọn chủ đề --</option>@foreach($topics as $topic)<option value="{{ $topic->id }}" {{ old('question_topic_id',$questionBank->question_topic_id ?? '')==$topic->id?'selected':'' }}>{{ $topic->name }}</option>@endforeach</select></div><div class="col-md-2"><label>Mức độ</label><select name="difficulty" class="form-select"><option>Dễ</option><option selected>Trung bình</option><option>Khó</option></select></div><div class="col-md-2"><label>Điểm</label><input type="number" step="0.01" name="default_score" class="form-control" value="{{ old('default_score',$questionBank->default_score ?? 1) }}"></div><div class="col-md-12"><label>Nội dung câu hỏi</label><textarea name="question_text" class="form-control" rows="4" required>{{ old('question_text',$questionBank->question_text ?? '') }}</textarea></div>@php $opts=isset($questionBank)?$questionBank->options->values():collect();$ci=0;if(isset($questionBank)){foreach($opts as $i=>$o){if($o->is_correct)$ci=$i;}} @endphp<div class="col-md-12"><h5>Đáp án</h5>@for($i=0;$i<4;$i++)<div class="input-group mb-2"><span class="input-group-text">{{ chr(65+$i) }}</span><input name="options[{{ $i }}]" class="form-control" value="{{ old('options.'.$i,$opts[$i]->option_text ?? '') }}"><span class="input-group-text"><input type="radio" name="correct_option" value="{{ $i }}" {{ old('correct_option',$ci)==$i?'checked':'' }}></span><span class="input-group-text">Đúng</span></div>@endfor</div><div class="col-md-12"><label>Giải thích đáp án</label><textarea name="explanation" class="form-control" rows="3">{{ old('explanation',$questionBank->explanation ?? '') }}</textarea></div><input type="hidden" name="status" value="Đang sử dụng"></div><div class="mt-4 text-end"><button class="btn btn-primary">Lưu câu hỏi</button></div></form></div></div>@endsection