@extends('admin.layouts.app')
@section('title', 'Flash Sales')
@section('content')
<div class="action-bar">
    <span>{{ $flashSales->total() }} flash sales</span>
    <a href="{{ route('admin.flash-sales.create') }}" class="btn btn-primary">+ New Flash Sale</a>
</div>
<div class="card">
    <table>
        <tr><th>Title</th><th>Discount</th><th>Badge</th><th>Period</th><th>Order</th><th>Active</th><th>Actions</th></tr>
        @foreach($flashSales as $sale)
        <tr>
            <td><strong>{{ $sale->title }}</strong><br><span class="text-muted">{{ Str::limit($sale->description, 60) }}</span></td>
            <td>{{ $sale->discount_percentage ? $sale->discount_percentage.'%' : '—' }}</td>
            <td>{{ $sale->badge_text ?? '—' }}</td>
            <td>
                {{ $sale->start_date ? $sale->start_date->format('M j, Y') : '—' }}
                &rarr;
                {{ $sale->end_date ? $sale->end_date->format('M j, Y') : '∞' }}
            </td>
            <td>{{ $sale->order }}</td>
            <td>{!! $sale->is_active ? '<span style="color:#6fcf97">Yes</span>' : '<span style="color:#e74c3c">No</span>' !!}</td>
            <td class="inline-flex">
                <a href="{{ route('admin.flash-sales.edit', $sale) }}" class="btn btn-primary btn-sm">Edit</a>
                <form action="{{ route('admin.flash-sales.destroy', $sale) }}" method="POST" onsubmit="return confirm('Delete?')">
                    @csrf @method('DELETE')
                    <button type="submit" class="btn btn-danger btn-sm">Delete</button>
                </form>
            </td>
        </tr>
        @endforeach
    </table>
    <div class="pagination">{{ $flashSales->links() }}</div>
</div>
@endsection
