@extends('layouts.admin')

@section('title', 'Manage Products')
@section('heading', 'Products')

@section('toolbar')
    <a class="button" href="{{ route('admin.products.create') }}">Add Product</a>
@endsection

@section('content')
    <section class="card">
        <table>
            <thead>
                <tr>
                    <th>Name</th>
                    <th>Category</th>
                    <th>Price</th>
                    <th>Featured</th>
                    <th>Sort</th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                @foreach ($products as $product)
                    <tr>
                        <td>{{ $product->name }}</td>
                        <td>{{ $product->category }}</td>
                        <td>${{ number_format((float) $product->price, 2) }}</td>
                        <td>{{ $product->is_featured ? 'Yes' : 'No' }}</td>
                        <td>{{ $product->sort_order }}</td>
                        <td style="display: flex; gap: 10px;">
                            <a class="ghost-button button" href="{{ route('admin.products.edit', $product) }}">Edit</a>
                            <form action="{{ route('admin.products.destroy', $product) }}" method="POST">
                                @csrf
                                @method('DELETE')
                                <button class="ghost-button" type="submit">Delete</button>
                            </form>
                        </td>
                    </tr>
                @endforeach
            </tbody>
        </table>
    </section>
@endsection
