@extends('layouts.admin')

@section('content')
<div class="container-fluid">
    <div class="card">
        <div class="card-header d-flex justify-content-between align-items-center">
            <h4 class="card-title">Product Variations</h4>
            <a href="{{ route('admin.product-variations.create') }}" class="btn btn-primary">Add New Variation</a>
        </div>
        <div class="card-body">
            @if(session('success'))
                <div class="alert alert-success alert-dismissible fade show" role="alert">
                    {{ session('success') }}
                    <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
                </div>
            @endif

            <div class="table-responsive">
                <table class="table table-bordered">
                    <thead>
                        <tr>
                            <th>Product</th>
                            <th>Variation Type</th>
                            <th>Value</th>
                            <th>Price</th>
                            <th>Stock</th>
                            <th>SKU</th>
                            <th>Active</th>
                            <th>Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        @forelse($productVariations as $variation)
                        <tr>
                            <td>{{ $variation->product->name }}</td>
                            <td>{{ $variation->variationType->name }}</td>
                            <td>{{ $variation->value }}</td>
                            <td>{{ number_format($variation->price, 2) }}</td>
                            <td>{{ $variation->stock_quantity }}</td>
                            <td>{{ $variation->sku }}</td>
                            <td>{{ $variation->is_active ? 'Yes' : 'No' }}</td>
                            <td>
                                <a href="{{ route('admin.product-variations.edit', $variation) }}" class="btn btn-sm btn-info">Edit</a>
                                <form action="{{ route('admin.product-variations.destroy', $variation) }}" method="POST" class="d-inline">
                                    @csrf
                                    @method('DELETE')
                                    <button type="submit" class="btn btn-sm btn-danger" onclick="return confirm('Are you sure?')">Delete</button>
                                </form>
                            </td>
                        </tr>
                        @empty
                        <tr>
                            <td colspan="8" class="text-center">No variations found.</td>
                        </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
            {{ $productVariations->links('pagination::bootstrap-5') }}
        </div>
    </div>
</div>
@endsection
