@extends('layouts.app')

@section('title', 'Add Hadith')

@section('content')
<div class="page-content">
    <div class="container-fluid">
        <!-- Page Title -->
        <div class="row">
            <div class="col-12">
                <div class="page-title-box d-sm-flex align-items-center justify-content-between">
                    <h4 class="mb-sm-0">Add Hadith</h4>
                    <div class="page-title-right">
                        <ol class="breadcrumb m-0">
                            <li class="breadcrumb-item"><a href="{{ route('home') }}">Home</a></li>
                            <li class="breadcrumb-item"><a href="{{ route('hadith.index') }}">Hadiths</a></li>
                            <li class="breadcrumb-item active">Create</li>
                        </ol>
                    </div>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-lg-12">
                <div class="card border-0 shadow-sm">
                    <div class="card-header bg-transparent border-bottom">
                        <div class="d-flex justify-content-between align-items-center">
                            <h4 class="card-title mb-0">
                                <i class="ri-add-line text-primary me-2"></i> Add New Hadith
                            </h4>
                            <a href="{{ route('hadith.index') }}" class="btn btn-sm btn-secondary">
                                <i class="ri-arrow-left-line me-1"></i> Back
                            </a>
                        </div>
                    </div>
                    <div class="card-body">
                        @if(session('error'))
                            <div class="alert alert-danger alert-dismissible fade show" role="alert">
                                <i class="ri-error-warning-line me-2"></i>{{ session('error') }}
                                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
                            </div>
                        @endif

                        <form method="POST" action="{{ route('hadith.store') }}">
                            @csrf
                            
                            <div class="row">
                                <div class="col-md-6 mb-3">
                                    <label for="hadith_category_id" class="form-label">Category <span class="text-danger">*</span></label>
                                    <select class="form-control @error('hadith_category_id') is-invalid @enderror" id="hadith_category_id" name="hadith_category_id" required>
                                        <option value="">Select Category</option>
                                        @foreach($categories as $category)
                                            <option value="{{ $category->id }}" {{ old('hadith_category_id') == $category->id ? 'selected' : '' }}>{{ $category->name }}</option>
                                        @endforeach
                                    </select>
                                    @error('hadith_category_id')
                                        <div class="invalid-feedback">{{ $message }}</div>
                                    @enderror
                                </div>

                                <div class="col-md-6 mb-3">
                                    <label for="source" class="form-label">Source <span class="text-danger">*</span></label>
                                    <input type="text" class="form-control @error('source') is-invalid @enderror" 
                                           id="source" name="source" value="{{ old('source') }}" 
                                           placeholder="e.g., Şahih al-Bukhārī 54" required>
                                    @error('source')
                                        <div class="invalid-feedback">{{ $message }}</div>
                                    @enderror
                                </div>
                            </div>

                            <div class="row">
                                <div class="col-md-6 mb-3">
                                    <label for="topic" class="form-label">Topic (English) <span class="text-danger">*</span></label>
                                    <input type="text" class="form-control @error('topic') is-invalid @enderror" 
                                           id="topic" name="topic" value="{{ old('topic') }}" required>
                                    @error('topic')
                                        <div class="invalid-feedback">{{ $message }}</div>
                                    @enderror
                                </div>

                                <div class="col-md-6 mb-3">
                                    <label for="topic_arabic" class="form-label">Topic (Arabic) <span class="text-danger">*</span></label>
                                    <input type="text" class="form-control @error('topic_arabic') is-invalid @enderror" 
                                           id="topic_arabic" name="topic_arabic" value="{{ old('topic_arabic') }}" 
                                           style="direction: rtl; text-align: right; font-family: 'Amiri', 'Traditional Arabic', serif;" required>
                                    @error('topic_arabic')
                                        <div class="invalid-feedback">{{ $message }}</div>
                                    @enderror
                                </div>
                            </div>

                            <div class="mb-3">
                                <label for="narrator" class="form-label">Narrator <span class="text-danger">*</span></label>
                                <textarea class="form-control @error('narrator') is-invalid @enderror" 
                                          id="narrator" name="narrator" rows="2" required>{{ old('narrator') }}</textarea>
                                <small class="text-muted">e.g., "Umar ibn al-Khattab reported: The Messenger of Allah, peace and blessings be upon him, said:"</small>
                                @error('narrator')
                                    <div class="invalid-feedback">{{ $message }}</div>
                                @enderror
                            </div>

                            <div class="mb-3">
                                <label for="arabic_text" class="form-label">Arabic Text <span class="text-danger">*</span></label>
                                <textarea class="form-control @error('arabic_text') is-invalid @enderror" 
                                          id="arabic_text" name="arabic_text" rows="4" 
                                          style="direction: rtl; text-align: right; font-family: 'Amiri', 'Traditional Arabic', serif; font-size: 18px;" required>{{ old('arabic_text') }}</textarea>
                                @error('arabic_text')
                                    <div class="invalid-feedback">{{ $message }}</div>
                                @enderror
                            </div>

                            <div class="mb-3">
                                <label for="english_translation" class="form-label">English Translation <span class="text-danger">*</span></label>
                                <textarea class="form-control @error('english_translation') is-invalid @enderror" 
                                          id="english_translation" name="english_translation" rows="5" required>{{ old('english_translation') }}</textarea>
                                @error('english_translation')
                                    <div class="invalid-feedback">{{ $message }}</div>
                                @enderror
                            </div>

                            <div class="mb-3">
                                <label for="grade" class="form-label">Grade</label>
                                <input type="text" class="form-control @error('grade') is-invalid @enderror" 
                                       id="grade" name="grade" value="{{ old('grade') }}" 
                                       placeholder="e.g., Muttafaqun Alayhi">
                                @error('grade')
                                    <div class="invalid-feedback">{{ $message }}</div>
                                @enderror
                            </div>
                            
                            <div class="d-flex gap-2">
                                <button type="submit" class="btn btn-primary">
                                    <i class="ri-save-line me-1"></i> Add Hadith
                                </button>
                                <a href="{{ route('hadith.index') }}" class="btn btn-secondary">
                                    <i class="ri-close-line me-1"></i> Cancel
                                </a>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

