@extends('layout')

@section('title', __('store/reseller.commissions'))

@section('content')
<div class="container py-5">
    <x-clientarea.page-header
        icon="fas fa-store"
        :title="__('store/reseller.commissions')"
    >
        <a href="{{ route('store.auth.reseller.dashboard') }}" class="btn btn-outline-secondary">
            <i class="fas fa-arrow-left me-1"></i>{{ __('store/reseller.dashboard') }}
        </a>
    </x-clientarea.page-header>

    {{-- Commission totals --}}
    <div class="row g-3 mb-4">
        <div class="col-md-4">
            <div class="card shadow-sm border-0 text-center">
                <div class="card-body py-3">
                    <div class="fs-4 fw-bold text-warning">{{ number_format($totals['pending'], 2) }}</div>
                    <div class="text-muted small">{{ __('store/reseller.commission_pending') }}</div>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="card shadow-sm border-0 text-center">
                <div class="card-body py-3">
                    <div class="fs-4 fw-bold text-info">{{ number_format($totals['approved'], 2) }}</div>
                    <div class="text-muted small">{{ __('store/reseller.commission_approved') }}</div>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="card shadow-sm border-0 text-center">
                <div class="card-body py-3">
                    <div class="fs-4 fw-bold text-success">{{ number_format($totals['paid'], 2) }}</div>
                    <div class="text-muted small">{{ __('store/reseller.commission_paid') }}</div>
                </div>
            </div>
        </div>
    </div>

    <div class="card shadow-sm border-0">
        <div class="card-body p-0">
            @if($commissions->isEmpty())
                <div class="text-center py-5 text-muted">
                    <i class="fas fa-coins fa-3x mb-3 d-block"></i>
                    {{ __('store/reseller.no_commissions') }}
                </div>
            @else
                <div class="table-responsive">
                    <table class="table table-hover mb-0">
                        <thead><tr>
                            <th>{{ __('store/reseller.commission_date') }}</th>
                            <th>{{ __('store/reseller.order_client') }}</th>
                            <th>{{ __('store/reseller.commission_description') }}</th>
                            <th>{{ __('store/reseller.commission_amount') }}</th>
                            <th>{{ __('store/reseller.commission_status') }}</th>
                        </tr></thead>
                        <tbody>
                        @foreach($commissions as $commission)
                            <tr>
                                <td>{{ $commission->created_at->format('d.m.Y H:i') }}</td>
                                <td>{{ $commission->client?->first_name }} {{ $commission->client?->last_name }}</td>
                                <td>{{ $commission->description ?: '-' }}</td>
                                <td class="fw-bold">{{ number_format($commission->commission_amount, 2) }}</td>
                                <td>
                                    @if($commission->status === 'pending')
                                        <span class="badge bg-warning">{{ __('store/reseller.commission_pending') }}</span>
                                    @elseif($commission->status === 'approved')
                                        <span class="badge bg-info">{{ __('store/reseller.commission_approved') }}</span>
                                    @else
                                        <span class="badge bg-success">{{ __('store/reseller.commission_paid') }}</span>
                                    @endif
                                </td>
                            </tr>
                        @endforeach
                        </tbody>
                    </table>
                </div>

                <div class="d-flex justify-content-center py-3">
                    {{ $commissions->links() }}
                </div>
            @endif
        </div>
    </div>
</div>
@endsection
