@extends('layouts.admin')

@section('title', 'Brands')
@section('page-title', 'Brands')

@section('content')
<div class="bg-white rounded-xl shadow-sm p-6">
    <div class="flex justify-end mb-4">
        <a href="{{ route('admin.brands.create') }}" class="bg-red-600 text-white px-4 py-2 rounded-lg text-sm hover:bg-red-700">+ Add Brand</a>
    </div>
    <table class="w-full text-sm">
        <thead>
            <tr class="text-gray-500 border-b bg-gray-50">
                <th class="text-left p-3">Logo</th>
                <th class="text-left p-3">Name</th>
                <th class="text-left p-3">Products</th>
                <th class="text-left p-3">Status</th>
                <th class="text-left p-3">Actions</th>
            </tr>
        </thead>
        <tbody>
            @foreach($brands as $brand)
            <tr class="border-b hover:bg-gray-50">
                <td class="p-3">
                    @if($brand->logo)
                    <img src="{{ asset('storage/' . $brand->logo) }}" class="w-10 h-10 object-contain">
                    @else
                    <div class="w-10 h-10 bg-gray-100 rounded flex items-center justify-center text-xs text-gray-400">N/A</div>
                    @endif
                </td>
                <td class="p-3 font-medium">{{ $brand->name }}</td>
                <td class="p-3">{{ $brand->products_count ?? 0 }}</td>
                <td class="p-3">
                    <span class="px-2 py-0.5 rounded-full text-xs {{ $brand->is_active ? 'bg-green-100 text-green-700' : 'bg-gray-100 text-gray-600' }}">
                        {{ $brand->is_active ? 'Active' : 'Inactive' }}
                    </span>
                </td>
                <td class="p-3 flex gap-2">
                    <a href="{{ route('admin.brands.edit', $brand->id) }}" class="text-xs bg-blue-600 text-white px-2 py-1 rounded hover:bg-blue-700">Edit</a>
                    <form action="{{ route('admin.brands.destroy', $brand->id) }}" method="POST" onsubmit="return confirm('Delete?')">
                        @csrf @method('DELETE')
                        <button class="text-xs bg-red-600 text-white px-2 py-1 rounded hover:bg-red-700">Delete</button>
                    </form>
                </td>
            </tr>
            @endforeach
        </tbody>
    </table>
    @if(isset($brands) && method_exists($brands, 'links'))
    <div class="mt-4">{{ $brands->links() }}</div>
    @endif
</div>
@endsection
