@extends('admin.layouts.app')
@section('title', 'Versions - ' . $product->name)
@section('content')
<div class="action-bar">
    <span>{{ $versions->total() }} versions for <strong>{{ $product->name }}</strong></span>
    <div>
        <a href="{{ route('admin.products.edit', $product) }}" class="btn btn-sm" style="background:#2a2a3e;color:#e0e0e0;margin-right:5px">Back to Product</a>
        <a href="{{ route('admin.products.versions.create', $product) }}" class="btn btn-primary">+ New Version</a>
    </div>
</div>
<div class="card">
    <table>
        <tr><th>Version</th><th>Price</th><th>Sale Price</th><th>Order</th><th>Active</th><th>Actions</th></tr>
        @foreach($versions as $v)
        <tr>
            <td><strong>{{ $v->version }}</strong></td>
            <td>${{ number_format($v->price, 2) }}</td>
            <td>{{ $v->sale_price ? '$'.number_format($v->sale_price, 2) : '—' }}</td>
            <td>{{ $v->order }}</td>
            <td>{!! $v->is_active ? '<span style="color:#6fcf97">Yes</span>' : '<span style="color:#e74c3c">No</span>' !!}</td>
            <td class="inline-flex">
                <a href="{{ route('admin.products.versions.edit', [$product, $v]) }}" class="btn btn-primary btn-sm">Edit</a>
                <form action="{{ route('admin.products.versions.destroy', [$product, $v]) }}" method="POST" onsubmit="return confirm('Delete this version?')">
                    @csrf @method('DELETE')
                    <button type="submit" class="btn btn-danger btn-sm">Delete</button>
                </form>
            </td>
        </tr>
        @endforeach
    </table>
    <div class="pagination">{{ $versions->links() }}</div>
</div>
@endsection
