@extends('layouts.admin')

@section('title', 'Edit Category')

@section('admin-content')
    <div class="page-header">
        <div>
            <h3 class="page-title">Edit Category</h3>
            <p class="text-muted mb-0">Update category details</p>
        </div>
        <a href="{{ route('admin.categories.index') }}" class="btn btn-light border shadow-sm">
            <i class="bi bi-arrow-left me-1"></i> Back to List
        </a>
    </div>

    <div class="row justify-content-center">
        <div class="col-md-6">
            <div class="card shadow-sm">
                <div class="card-body p-4">
                    <form action="{{ route('admin.categories.update', $category->id) }}" method="POST" enctype="multipart/form-data">
                        @csrf
                        @method('PUT')
                        <div class="mb-3">
                            <label class="form-label fw-bold">Category Name</label>
                            <input type="text" name="name" class="form-control" value="{{ $category->name }}" required>
                        </div>
                        
                        <div class="mb-3">
                            <label class="form-label fw-bold">Parent Category (Optional)</label>
                            <select name="parent_id" class="form-select">
                                <option value="">None</option>
                                @foreach($categories as $parent)
                                    <option value="{{ $parent->id }}" {{ $category->parent_id == $parent->id ? 'selected' : '' }}>{{ $parent->name }}</option>
                                @endforeach
                            </select>
                        </div>

                        <div class="mb-3">
                            <label class="form-label fw-bold">Category Image</label>
                            @if($category->image)
                                <div class="mb-2">
                                    <img src="{{ asset('storage/' . $category->image) }}" alt="Current Image" class="img-thumbnail" style="height: 100px;">
                                </div>
                            @endif
                            <input type="file" name="image" class="form-control" accept="image/*">
                            <div class="form-text">Recommended size: 800x600px</div>
                        </div>

                        <div class="mb-3">
                            <div class="form-check form-switch">
                                <input class="form-check-input" type="checkbox" name="is_featured" id="isFeatured" {{ $category->is_featured ? 'checked' : '' }}>
                                <label class="form-check-label" for="isFeatured">Featured Category</label>
                            </div>
                            <div class="form-check form-switch mt-2">
                                <input class="form-check-input" type="checkbox" name="is_active" id="isActive" {{ $category->is_active ? 'checked' : '' }}>
                                <label class="form-check-label" for="isActive">Active</label>
                            </div>
                        </div>

                        <button type="submit" class="btn btn-primary-gradient w-100 py-2">
                            <i class="bi bi-check-lg me-2"></i> Update Category
                        </button>
                    </form>
                </div>
            </div>
        </div>
    </div>
@endsection
