@extends('layouts.admin')

@section('title', 'Edit Brand')

@section('content')
<x-admin.form-page
    title="Edit Brand: {{ $brand->name }}"
    :crumbs="[['label' => 'Catalogue', 'url' => null], ['label' => 'Brands', 'url' => route('admin.brands.index')], 'Edit']"
    :back-url="route('admin.brands.index')"
    :action="route('admin.brands.update', $brand->id)"
    method="PUT"
    form-id="brandForm"
    submit-label="Update Brand"
    enctype="multipart/form-data"
>
    <section class="pp-card">
        <div class="pp-card__head">
            <span class="pp-card__icon"><i class="bi bi-award"></i></span>
            <div>
                <h2 class="pp-card__title">Details</h2>
                <p class="pp-card__sub">Brand name, slug and logo</p>
            </div>
        </div>
        <div class="pp-card__body">
            <div class="pp-grid pp-grid--2">
                <div class="pp-field">
                    <label for="name">Brand Name <span class="pp-req">*</span></label>
                    <input type="text"
                           name="name"
                           id="name"
                           class="form-control @error('name') is-invalid @enderror"
                           value="{{ old('name', $brand->name) }}"
                           required
                           placeholder="Enter brand name">
                    @error('name')
                        <div class="invalid-feedback d-block">{{ $message }}</div>
                    @enderror
                </div>
                <div class="pp-field">
                    <label for="slug">Slug</label>
                    <input type="text"
                           name="slug"
                           id="slug"
                           class="form-control @error('slug') is-invalid @enderror"
                           value="{{ old('slug', $brand->slug) }}"
                           placeholder="Auto-generated from name">
                    <p class="pp-hint">Leave empty to auto-generate from brand name</p>
                    @error('slug')
                        <div class="invalid-feedback d-block">{{ $message }}</div>
                    @enderror
                </div>
                <div class="pp-field">
                    <label for="logo">Brand Logo</label>
                    @if($brand->logo_path)
                        <div class="mb-2">
                            <img src="{{ asset('storage/' . $brand->logo_path) }}"
                                 alt="{{ $brand->name }}"
                                 class="img-thumbnail"
                                 style="max-width: 150px; max-height: 150px; object-fit: contain;">
                            <p class="pp-hint">Current logo</p>
                        </div>
                    @endif
                    <input type="file"
                           name="logo"
                           id="logo"
                           class="form-control @error('logo') is-invalid @enderror"
                           accept="image/*">
                    <p class="pp-hint">Leave empty to keep current logo. Recommended size: 200x200px. Max file size: 2MB</p>
                    @error('logo')
                        <div class="invalid-feedback d-block">{{ $message }}</div>
                    @enderror
                </div>
            </div>
            <div class="pp-toggles">
                <label class="pp-toggle" for="isActive">
                    <input type="hidden" name="is_active" value="0">
                    <input type="checkbox" class="form-check-input" role="switch" name="is_active" id="isActive" value="1" {{ old('is_active', $brand->is_active) ? 'checked' : '' }}>
                    Active
                </label>
                <p class="pp-hint">Inactive brands won't appear in product selection</p>
            </div>
        </div>
    </section>

    <x-slot:summary>
        <div class="mb-2">
            <strong>Products:</strong>
            <span class="badge bg-primary">{{ $brand->products()->count() }}</span>
        </div>
        <div class="mb-2">
            <strong>Created:</strong>
            <small class="text-muted">{{ $brand->created_at->format('M d, Y') }}</small>
        </div>
        <div class="mb-3">
            <strong>Last Updated:</strong>
            <small class="text-muted">{{ $brand->updated_at->format('M d, Y') }}</small>
        </div>
    </x-slot:summary>
</x-admin.form-page>
@endsection
