@extends('layout.admin')

@section('content')
<h1 class="text-2xl font-semibold mb-6 text-red-700">Rejected Gmail Sales</h1>

@include('admin.gmail_sales._date_filter', [
    'filterRoute' => 'admin.gmail.sales.rejected',
    'selectedFromDate' => $selectedFromDate ?? null,
    'selectedToDate' => $selectedToDate ?? null,
    'exportStatus' => 'rejected',
])

@if($gmailSales->count())
    <div class="overflow-x-auto bg-white shadow rounded-lg">
        <table class="min-w-full divide-y divide-red-200">
            <thead class="bg-red-100">
                <tr>
                    <th class="px-5 py-3 text-left text-sm font-semibold text-red-700 uppercase tracking-wider">User</th>
                    <th class="px-5 py-3 text-left text-sm font-semibold text-red-700 uppercase tracking-wider">Gmail</th>
                    <th class="px-5 py-3 text-left text-sm font-semibold text-red-700 uppercase tracking-wider">Password</th>
                    <th class="px-5 py-3 text-left text-sm font-semibold text-red-700 uppercase tracking-wider">Recovery Email</th> <!-- ✅ নতুন -->
                    <th class="px-5 py-3 text-left text-sm font-semibold text-red-700 uppercase tracking-wider">Rate</th>
                    <th class="px-5 py-3 text-left text-sm font-semibold text-red-700 uppercase tracking-wider">Price</th>
                    <th class="px-5 py-3 text-left text-sm font-semibold text-red-700 uppercase tracking-wider">Status</th>
                    <th class="px-5 py-3 text-left text-sm font-semibold text-red-700 uppercase tracking-wider">Submitted</th>
                    <th class="px-5 py-3 text-left text-sm font-semibold text-red-700 uppercase tracking-wider">Action</th>
                </tr>
            </thead>
            <tbody class="divide-y divide-red-200 bg-red-50">
                @foreach($gmailSales as $sale)
                    <tr class="hover:bg-red-100 transition-colors duration-150">
                        <td class="px-5 py-3 text-sm text-red-800 font-medium">{{ $sale->user->name ?? 'N/A' }}</td>
                        <td class="px-5 py-3 text-sm text-red-800 font-mono">{{ $sale->gmail }}</td>
                        <td class="px-5 py-3 text-sm text-red-800 font-mono">{{ $sale->gmail_password }}</td>
                        <td class="px-5 py-3 text-sm text-red-800 font-mono">{{ $sale->recovery_email ?? 'N/A' }}</td> <!-- ✅ নতুন -->
                        <td class="px-5 py-3 text-sm text-red-800">{{ $sale->rate_label }}</td>
                        <td class="px-5 py-3 text-sm text-red-800">{{ $sale->price_label }}</td>
                        <td class="px-5 py-3 text-sm">
                            <span class="inline-block px-3 py-1 text-xs font-semibold rounded-full bg-red-200 text-red-800">
                                {{ ucfirst($sale->status) }}
                            </span>
                        </td>
                        <td class="px-5 py-3 text-sm text-red-800">{{ $sale->created_at->diffForHumans() }}</td>
                        <td class="px-5 py-3 text-sm text-red-800">
                            <form action="{{ route('admin.gmail.sales.status', $sale->id) }}" method="POST" class="flex gap-2 items-center">
                                @csrf
                                @method('PUT')
                                <select name="status" class="text-sm border border-red-300 rounded px-3 py-1 focus:outline-none focus:ring-2 focus:ring-red-400">
                                    <option value="pending" @selected($sale->status === 'pending')>Pending</option>
                                    <option value="checked" @selected($sale->status === 'checked')>Checked</option>
                                    <option value="rejected" @selected($sale->status === 'rejected')>Rejected</option>
                                    <option value="completed" @selected($sale->status === 'completed')>Completed</option>
                                </select>
                                <button type="submit" class="bg-red-600 hover:bg-red-700 text-white px-4 py-1 rounded text-sm transition-colors duration-200">
                                    Update
                                </button>
                            </form>
                        </td>
                    </tr>
                @endforeach
            </tbody>
        </table>
    </div>
@else
    <div class="bg-red-100 text-red-800 px-5 py-4 rounded-lg font-medium">
        No Rejected Gmail Sales found.
    </div>
@endif
@endsection
