@extends('layouts.admin')

@section('title', 'Edit Artikel Edukasi')

@section('content')
<div class="card border-0 shadow-sm rounded-4 p-4 col-lg-9 mx-auto">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h5 class="fw-bold mb-0">Form Edit Artikel</h5>
        <a href="{{ route('admin.articles.index') }}" class="btn btn-outline-secondary btn-sm rounded-pill">&larr; Batal & Kembali</a>
    </div>

    <form action="{{ route('admin.articles.update', $article->id) }}" method="POST">
        @csrf @method('PUT')
        
        <div class="mb-3">
            <label class="form-label fw-bold">Judul Artikel</label>
            <input type="text" name="title" class="form-control @error('title') is-invalid @enderror" value="{{ old('title', $article->title) }}" required>
            @error('title')<div class="invalid-feedback">{{ $message }}</div>@enderror
        </div>

        <div class="row">
            <div class="col-md-6 mb-3">
                <label class="form-label fw-bold">Kategori Artikel</label>
                <input type="text" name="category" class="form-control @error('category') is-invalid @enderror" value="{{ old('category', $article->category) }}" required>
                @error('category')<div class="invalid-feedback">{{ $message }}</div>@enderror
            </div>
            <div class="col-md-6 mb-3">
                <label class="form-label fw-bold">URL Gambar Sampul</label>
                <input type="text" name="image" class="form-control @error('image') is-invalid @enderror" value="{{ old('image', $article->image) }}">
                @error('image')<div class="invalid-feedback">{{ $message }}</div>@enderror
            </div>
        </div>

        <div class="mb-3">
            <label class="form-label fw-bold">URL Sumber / Artikel Asli (Opsional)</label>
            <input type="text" name="source_url" class="form-control @error('source_url') is-invalid @enderror" value="{{ old('source_url', $article->source_url) }}" placeholder="Contoh: https://journals2.ums.ac.id/buletinkkndik/article/view/11840">
            @error('source_url')<div class="invalid-feedback">{{ $message }}</div>@enderror
            <small class="text-muted" style="font-size: 0.8rem;">Jika Anda memasukkan link halaman web jurnal/portal berita di sini atau di kolom Gambar Sampul, sistem akan otomatis menyediakan tombol rujukan ke artikel asli.</small>
        </div>

        <div class="mb-3">
            <label class="form-label fw-bold">Ringkasan Singkat (Snippet)</label>
            <textarea name="snippet" class="form-control @error('snippet') is-invalid @enderror" rows="2" required>{{ old('snippet', $article->snippet) }}</textarea>
            @error('snippet')<div class="invalid-feedback">{{ $message }}</div>@enderror
        </div>

        <div class="mb-4">
            <label class="form-label fw-bold">Isi Konten Artikel Lengkap</label>
            <textarea name="content" class="form-control @error('content') is-invalid @enderror" rows="10" required>{{ old('content', $article->content) }}</textarea>
            @error('content')<div class="invalid-feedback">{{ $message }}</div>@enderror
        </div>

        <button type="submit" class="btn btn-warning btn-lg w-100 rounded-pill fw-bold">
            <i class="fa-solid fa-pen-to-square me-1"></i> Perbarui Artikel
        </button>
    </form>
</div>
@endsection
