@extends('layouts.admin')

@section('content')
<div class="container-fluid">
    <div class="card">
        <div class="card-header">
            <div class="d-flex justify-content-between align-items-center">
                <h4 class="card-title mb-0">Gift Cards</h4>
                <a href="{{ route('admin.gift-cards.create') }}" class="btn btn-primary">
                    <i class="bi bi-plus"></i> Add New Gift Card
                </a>
            </div>
        </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

            @if(session('error'))
            <div class="alert alert-danger alert-dismissible fade show" role="alert">
                {{ session('error') }}
                <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>Code</th>
                            <th>Initial Balance</th>
                            <th>Current Balance</th>
                            <th>Recipient</th>
                            <th>Expiry</th>
                            <th>Active</th>
                            <th>Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($giftCards as $giftCard)
                        <tr>
                            <td>{{ $giftCard->code }}</td>
                            <td>₦{{ number_format($giftCard->initial_balance, 2) }}</td>
                            <td>₦{{ number_format($giftCard->current_balance, 2) }}</td>
                            <td>{{ $giftCard->recipient_email ?? 'N/A' }}</td>
                            <td>{{ $giftCard->expiry_date?->format('M d, Y') ?? 'No Expiry' }}</td>
                            <td>
                                <span class="badge bg-{{ $giftCard->is_active ? 'success' : 'danger' }}">
                                    {{ $giftCard->is_active ? 'Yes' : 'No' }}
                                </span>
                            </td>
                            <td>
                                <a href="{{ route('admin.gift-cards.edit', $giftCard) }}" class="btn btn-sm btn-info">Edit</a>
                                <form action="{{ route('admin.gift-cards.destroy', $giftCard) }}" 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>
                        @endforeach
                    </tbody>
                </table>
            </div>
            {{ $giftCards->links('pagination::bootstrap-5') }}
        </div>
    </div>
</div>
@endsection
