<x-app-layout>
    <x-slot name="header">
        <h2 class="serif" style="font-size: 1.3rem; color: var(--cream); font-weight: 400; letter-spacing: 0.05em;">
            {{ __('Admin / Edit Product') }}
        </h2>
    </x-slot>

    <style>
        .form-card {
            background: #fff;
            border-radius: 4px;
            border: 1px solid rgba(26,24,20,0.08);
            padding: 3rem;
            max-width: 800px;
            margin: 0 auto;
        }
        .form-group { margin-bottom: 1.5rem; }
        .form-label {
            display: block;
            font-size: 0.7rem;
            letter-spacing: 0.12em;
            text-transform: uppercase;
            color: var(--warm-gray);
            font-weight: 600;
            margin-bottom: 0.6rem;
        }
        .form-input {
            width: 100%;
            padding: 0.8rem 1rem;
            background: var(--ivory);
            border: 1px solid rgba(26,24,20,0.08);
            border-radius: 2px;
            font-family: 'DM Sans', sans-serif;
            font-size: 0.9rem;
            color: var(--ink);
            transition: border-color 0.2s;
        }
        .form-input:focus {
            outline: none;
            border-color: var(--amber);
        }
        .btn-save {
            background: var(--charcoal);
            color: var(--cream);
            border: none;
            border-radius: 2px;
            padding: 1rem 2rem;
            font-size: 0.8rem;
            letter-spacing: 0.15em;
            text-transform: uppercase;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s;
        }
        .btn-save:hover {
            background: var(--amber);
            color: var(--charcoal);
        }
    </style>

    <div style="padding: 4rem 0 8rem;">
        <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
            
            <div class="form-card">
                <form action="{{ route('admin.products.update', $product) }}" method="POST" enctype="multipart/form-data">
                    @csrf
                    @method('PUT')

                    <div class="form-group">
                        <label class="form-label">Category</label>
                        <select name="category_id" class="form-input" required>
                            @foreach($categories as $category)
                                <option value="{{ $category->id }}" {{ $product->category_id == $category->id ? 'selected' : '' }}>
                                    {{ $category->parent ? $category->parent->name . ' > ' : '' }}{{ $category->name }}
                                </option>
                            @endforeach
                        </select>
                    </div>

                    <div class="form-group">
                        <label class="form-label">Product Name</label>
                        <input type="text" name="name" class="form-input" value="{{ $product->name }}" required>
                    </div>

                    <div class="form-group">
                        <label class="form-label">Description</label>
                        <textarea name="description" rows="5" class="form-input">{{ $product->description }}</textarea>
                    </div>

                    <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 2rem;">
                        <div class="form-group">
                            <label class="form-label">Price (৳)</label>
                            <input type="number" step="0.01" name="price" class="form-input" value="{{ $product->price }}" required>
                        </div>
                        <div class="form-group">
                            <label class="form-label">Stock Quantity</label>
                            <input type="number" name="stock" class="form-input" value="{{ $product->stock }}" required>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="form-label">Product Image</label>
                        @if($product->image)
                            <div style="margin-bottom: 1rem;">
                                <img src="{{ asset('storage/' . $product->image) }}" style="width: 100px; height: 120px; object-fit: cover; border-radius: 2px;">
                                <p style="font-size: 0.7rem; color: var(--mist); margin-top: 0.5rem;">Current Image</p>
                            </div>
                        @endif
                        <input type="file" name="image" class="form-input">
                    </div>

                    <div style="margin-top: 3rem; display: flex; justify-content: space-between; align-items: center;">
                        <a href="{{ route('admin.products.index') }}" style="color: var(--warm-gray); text-decoration: none; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.1em;">Cancel</a>
                        <button type="submit" class="btn-save">Update Product</button>
                    </div>
                </form>
            </div>

        </div>
    </div>
</x-app-layout>
