@extends('layouts.admin')

@section('content')
<div class="container-fluid">
    <div class="card">
        <div class="card-header">
            <h4 class="card-title">Affiliate Details - {{ $affiliate->code }}</h4>
        </div>
        <div class="card-body">
            <div class="row mb-4">
                <div class="col-md-6">
                    <table class="table table-bordered">
                        <tr>
                            <th>Code</th>
                            <td>{{ $affiliate->code }}</td>
                        </tr>
                        <tr>
                            <th>User</th>
                            <td>{{ $affiliate->user?->name ?? 'N/A' }}</td>
                        </tr>
                        <tr>
                            <th>Balance</th>
                            <td>{{ number_format($affiliate->balance, 2) }}</td>
                        </tr>
                        <tr>
                            <th>Payment Method</th>
                            <td>{{ $affiliate->payment_method ?? 'N/A' }}</td>
                        </tr>
                        <tr>
                            <th>Payment Details</th>
                            <td>{{ $affiliate->payment_details ?? 'N/A' }}</td>
                        </tr>
                        <tr>
                            <th>Approved</th>
                            <td>
                                <span class="badge bg-{{ $affiliate->is_approved ? 'success' : 'warning' }}">
                                    {{ $affiliate->is_approved ? 'Approved' : 'Pending' }}
                                </span>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>

            <h5 class="mb-3">Transactions</h5>
            <div class="table-responsive">
                <table class="table table-bordered">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>Order ID</th>
                            <th>Amount</th>
                            <th>Type</th>
                            <th>Status</th>
                            <th>Date</th>
                        </tr>
                    </thead>
                    <tbody>
                        @forelse($affiliate->transactions as $transaction)
                        <tr>
                            <td>{{ $transaction->id }}</td>
                            <td>{{ $transaction->order_id ?? 'N/A' }}</td>
                            <td>{{ number_format($transaction->amount, 2) }}</td>
                            <td><span class="badge bg-{{ $transaction->type === 'commission' ? 'success' : 'info' }}">{{ ucfirst($transaction->type) }}</span></td>
                            <td>{{ ucfirst($transaction->status) }}</td>
                            <td>{{ $transaction->created_at->format('M d, Y H:i') }}</td>
                        </tr>
                        @empty
                        <tr>
                            <td colspan="6" class="text-center">No transactions found</td>
                        </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>

            <div class="mt-3">
                <a href="{{ route('admin.affiliates.index') }}" class="btn btn-secondary">Back to Affiliates</a>
            </div>
        </div>
    </div>
</div>
@endsection
