@extends('layout.admin')

@section('content')
<div class="container py-4">
    <h2 class="mb-4">ফেসবুক আইডি সাবমিশন তালিকা</h2>

    @if (session('success'))
        <div class="alert alert-success mb-3">
            {{ session('success') }}
        </div>
    @endif

    <div class="table-responsive">
        <table class="table table-bordered align-middle text-center">
            <thead class="table-dark">
                <tr>
                    <th>ইউজার</th>
                    <th>Facebook Link</th>
                    <th>Email</th>
                    <th>Password</th>
                    <th>2FA</th>
                    <th>Cookie/Text</th>
                    <th>স্ট্যাটাস</th>
                    <th>অ্যাকশন</th>
                </tr>
            </thead>
            <tbody>
                @foreach ($submissions as $sub)
                    <tr>
                        <td>{{ $sub->user->name ?? 'N/A' }}</td>
                        <td>
                            @if(filter_var($sub->fb_uid, FILTER_VALIDATE_URL))
                                <a href="{{ $sub->fb_uid }}" target="_blank" rel="noopener" class="text-primary text-decoration-underline">
                                    {{ $sub->fb_uid }}
                                </a>
                            @else
                                {{ $sub->fb_uid }}
                            @endif
                        </td>
                        <td>{{ $sub->fb_email }}</td>
                        <td><code>{{ decrypt($sub->fb_password) }}</code></td>
                        <td><code>{{ decrypt($sub->fb_2fa) }}</code></td>
                        <td class="text-break" style="max-width:220px;">{{ $sub->fb_cookie_link ?: '-' }}</td>
                        <td>
                            <span class="badge
                                @if($sub->status == 'approved') bg-success
                                @elseif($sub->status == 'rejected') bg-danger
                                @else bg-warning text-dark
                                @endif">
                                {{ ucfirst($sub->status) }}
                            </span>
                        </td>
                        <td>
                            <form method="POST" action="{{ route('admin.fb.submissions.update-status', $sub->id) }}">
                                @csrf
                                <select name="status" class="form-select form-select-sm" onchange="this.form.submit()">
                                    <option value="pending" {{ $sub->status == 'pending' ? 'selected' : '' }}>Pending</option>
                                    <option value="processing" {{ $sub->status == 'processing' ? 'selected' : '' }}>Processing</option>
                                    <option value="approved" {{ $sub->status == 'approved' ? 'selected' : '' }}>Approved</option>
                                    <option value="rejected" {{ $sub->status == 'rejected' ? 'selected' : '' }}>Rejected</option>
                                </select>
                            </form>
                        </td>
                    </tr>
                @endforeach

                @if($submissions->isEmpty())
                    <tr>
                        <td colspan="8">কোনো সাবমিশন পাওয়া যায়নি।</td>
                    </tr>
                @endif
            </tbody>
        </table>
    </div>
</div>
@endsection
