@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">
                    <div class="d-flex justify-content-between align-items-center">
                        <h4 class="mb-0">Edit Book</h4>
                        <a href="{{ route('books.index') }}" class="btn btn-sm btn-outline-secondary">Back to Books</a>
                    </div>
                </div>

                <div class="card-body">
                    <form method="POST" action="{{ route('books.update', $book->id) }}" enctype="multipart/form-data">
                        @csrf
                        @method('PUT')

                        <div class="mb-3">
                            <label for="name" class="form-label">📌 Book Name:</label>
                            <input type="text" class="form-control" id="name" name="name" value="{{ old('name', $book->name) }}" required>
                        </div>

                        <div class="mb-3">
                            <label for="author" class="form-label">✍️ Author Name:</label>
                            <input type="text" class="form-control" id="author" name="author" value="{{ old('author', $book->author) }}" required>
                        </div>

                        <div class="mb-3">
                            <label for="co_author" class="form-label">🤝 Co-Author Name:</label>
                            <input type="text" class="form-control" id="co_author" name="co_author" value="{{ old('co_author', $book->co_author) }}">
                        </div>

                        <div class="mb-3">
                            <label for="published_no" class="form-label">🔢 Published No:</label>
                            <input type="text" class="form-control" id="published_no" name="published_no" value="{{ old('published_no', $book->published_no) }}" required>
                        </div>

                        <div class="mb-3">
                            <label for="publisher" class="form-label">🏢 Publisher:</label>
                            <input type="text" class="form-control" id="publisher" name="publisher" value="{{ old('publisher', $book->publisher) }}" required>
                        </div>

                        <div class="mb-3">
                            <label for="ddc_no" class="form-label">📚 DDC No:</label>
                            <input type="text" class="form-control" id="ddc_no" name="ddc_no" value="{{ old('ddc_no', $book->ddc_no) }}" required>
                        </div>

                        <div class="mb-3">
                            <label for="edition" class="form-label">📑 Edition:</label>
                            <input type="text" class="form-control" id="edition" name="edition" value="{{ old('edition', $book->edition) }}" required>
                        </div>

                        <div class="mb-3">
                            <label for="publish_year" class="form-label">📅 Publish Year:</label>
                            <input type="number" class="form-control" id="publish_year" name="publish_year" value="{{ old('publish_year', $book->publish_year) }}" min="1900" max="{{ date('Y') + 1 }}" required>
                        </div>

                        <div class="mb-3">
                            <label class="form-label">🌍 Status:</label>
                            <div>
                                <div class="form-check form-check-inline">
                                    <input class="form-check-input" type="radio" name="status" id="status_national" value="National" {{ old('status', $book->status) == 'National' ? 'checked' : '' }}>
                                    <label class="form-check-label" for="status_national">National</label>
                                </div>
                                <div class="form-check form-check-inline">
                                    <input class="form-check-input" type="radio" name="status" id="status_international" value="International" {{ old('status', $book->status) == 'International' ? 'checked' : '' }}>
                                    <label class="form-check-label" for="status_international">International</label>
                                </div>
                            </div>
                        </div>

                        <div class="mb-3">
                            <label class="form-label">🔐 Authentication:</label>
                            <div>
                                <div class="form-check form-check-inline">
                                    <input class="form-check-input" type="radio" name="authentication" id="auth_single" value="Single" {{ old('authentication', $book->authentication) == 'Single' ? 'checked' : '' }}>
                                    <label class="form-check-label" for="auth_single">Single</label>
                                </div>
                                <div class="form-check form-check-inline">
                                    <input class="form-check-input" type="radio" name="authentication" id="auth_multi" value="Multi" {{ old('authentication', $book->authentication) == 'Multi' ? 'checked' : '' }}>
                                    <label class="form-check-label" for="auth_multi">Multi</label>
                                </div>
                            </div>
                        </div>

                        <div class="mb-3">
                            <label for="cover_image" class="form-label">📸 Book Cover:</label>
                            <input type="file" class="form-control" id="cover_image" name="cover_image">
                            @if($book->cover_image)
                                <div class="mt-2">
                                    <small>Current Cover:</small>
                                    <img src="{{ asset('storage/' . $book->cover_image) }}" width="100" class="d-block mt-1">
                                </div>
                            @endif
                        </div>

                        <div class="d-grid gap-2">
                            <button type="submit" class="btn btn-primary">Update Book</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection
