{{-- admin/pages/products/index.blade.php --}}
@extends('admin.layouts.app')
@section('title','Products')
@section('page-title','Products')
@section('content')
<div class="d-flex justify-content-between align-items-center mb-3">
    <div style="font-size:.82rem;color:#64748b">{{ $products->count() }} products</div>
    <a href="{{ route('admin.products.create') }}" class="btn btn-admin btn-sm px-3">
        <i class="bi bi-plus-lg me-1"></i>Add Product
    </a>
</div>

<div class="card-admin">
    <table class="table table-hover mb-0">
        <thead>
            <tr>
                <th style="width:40px">#</th>
                <th>Name</th>
                <th>Standard Badge</th>
                <th>Status</th>
                <th>Order</th>
                <th style="width:130px">Actions</th>
            </tr>
        </thead>
        <tbody>
            @forelse($products as $product)
            <tr>
                <td class="text-muted">{{ $product->id }}</td>
                <td>
                    <div class="fw-600" style="color:#0f172a">{{ $product->name }}</div>
                    <div style="font-size:.74rem;color:#94a3b8">{{ Str::limit($product->short_description, 60) }}</div>
                </td>
                <td>
                    @if($product->standard_badge)
                    <span class="badge" style="background:#dbeafe;color:#1e40af;font-size:.72rem">{{ $product->standard_badge }}</span>
                    @else <span class="text-muted">—</span> @endif
                </td>
                <td>
                    @if($product->is_active)
                    <span class="badge" style="background:#f0fdf4;color:#166534;font-size:.72rem">Active</span>
                    @else
                    <span class="badge" style="background:#fee2e2;color:#991b1b;font-size:.72rem">Inactive</span>
                    @endif
                </td>
                <td class="text-muted">{{ $product->sort_order }}</td>
                <td>
                    <div class="d-flex gap-1">
                        <a href="{{ route('admin.products.edit', $product->id) }}" class="btn btn-sm" style="background:#eff6ff;color:#1d4ed8;border:none" title="Edit"><i class="bi bi-pencil"></i></a>
                        <a href="{{ route('product.show', $product->slug) }}" target="_blank" class="btn btn-sm" style="background:#f0fdf4;color:#166534;border:none" title="View"><i class="bi bi-eye"></i></a>
                        <form method="POST" action="{{ route('admin.products.destroy', $product->id) }}" onsubmit="return confirm('Delete this product?')">
                            @csrf @method('DELETE')
                            <button class="btn btn-sm" style="background:#fee2e2;color:#991b1b;border:none" title="Delete"><i class="bi bi-trash"></i></button>
                        </form>
                    </div>
                </td>
            </tr>
            @empty
            <tr><td colspan="6" class="text-center py-4 text-muted">No products yet. <a href="{{ route('admin.products.create') }}">Add one</a>.</td></tr>
            @endforelse
        </tbody>
    </table>
</div>
@endsection
