@extends('admin.layouts.app')
@section('title', $news->id ? 'تعديل خبر' : 'خبر جديد')
@section('page-title', $news->id ? 'تعديل الخبر' : 'إضافة خبر جديد')

@section('content')

<div class="row justify-content-center">
<div class="col-lg-9">
<div class="card">
    <div class="card-body">
        <form method="POST"
              action="{{ $news->id ? route('admin.news.update', $news->id) : route('admin.news.store') }}"
              enctype="multipart/form-data">
            @csrf
            @if($news->id) @method('PUT') @endif

            <div class="row g-3">
                <div class="col-12">
                    <label class="form-label fw-semibold">عنوان الخبر (عربي) <span class="text-danger">*</span></label>
                    <input type="text" name="title" value="{{ old('title', $news->title) }}"
                           class="form-control form-control-lg @error('title') is-invalid @enderror"
                           placeholder="عنوان الخبر بالعربي" required>
                    @error('title') <div class="invalid-feedback">{{ $message }}</div> @enderror
                </div>
                <div class="col-md-6">
                    <label class="form-label">العنوان (إنجليزي)</label>
                    <input type="text" name="title_ar" value="{{ old('title_ar', $news->title_ar) }}"
                           class="form-control" placeholder="Title in English">
                </div>
                <div class="col-md-3">
                    <label class="form-label">التصنيف</label>
                    <select name="category" class="form-select">
                        <option value="">بدون تصنيف</option>
                        <option value="news"     {{ old('category',$news->category)=='news'     ? 'selected':'' }}>أخبار طبية</option>
                        <option value="tips"     {{ old('category',$news->category)=='tips'     ? 'selected':'' }}>نصائح صحية</option>
                        <option value="research" {{ old('category',$news->category)=='research' ? 'selected':'' }}>أبحاث</option>
                    </select>
                </div>
                <div class="col-md-3">
                    <label class="form-label">المصدر</label>
                    <input type="text" name="source" value="{{ old('source', $news->source) }}"
                           class="form-control" placeholder="WHO، وزارة الصحة...">
                </div>
                <div class="col-12">
                    <label class="form-label">مقتطف مختصر</label>
                    <textarea name="excerpt" rows="2" class="form-control"
                              placeholder="وصف مختصر يظهر في قائمة الأخبار...">{{ old('excerpt', $news->excerpt) }}</textarea>
                </div>
                <div class="col-12">
                    <label class="form-label fw-semibold">المحتوى الكامل <span class="text-danger">*</span></label>
                    <textarea name="content" id="content" rows="12"
                              class="form-control @error('content') is-invalid @enderror"
                              required>{{ old('content', $news->content) }}</textarea>
                    @error('content') <div class="invalid-feedback">{{ $message }}</div> @enderror
                </div>
                <div class="col-12">
                    <label class="form-label">صورة الغلاف</label>
                    @if($news->cover_image)
                        <div class="mb-2">
                            <img src="{{ asset('storage/'.$news->cover_image) }}"
                                 style="height:120px;border-radius:8px;object-fit:cover">
                            <small class="text-muted ms-2">الصورة الحالية</small>
                        </div>
                    @endif
                    <input type="file" name="cover_image" class="form-control" accept="image/*">
                </div>
                <div class="col-12">
                    <div class="form-check form-switch">
                        <input class="form-check-input" type="checkbox" name="is_published"
                               id="is_published" value="1"
                               {{ old('is_published', $news->is_published) ? 'checked' : '' }}>
                        <label class="form-check-label" for="is_published">
                            نشر الخبر فوراً
                        </label>
                    </div>
                </div>
            </div>

            <hr class="my-4">
            <div class="d-flex justify-content-end gap-2">
                <a href="{{ route('admin.news.index') }}" class="btn btn-outline-secondary">إلغاء</a>
                <button type="submit" class="btn btn-primary px-4">
                    <i class="bi bi-save me-1"></i> حفظ
                </button>
            </div>
        </form>
    </div>
</div>
</div>
</div>

@endsection
