@extends('backend.layout.app')

@section('content')
<div class="container">
    <div class="container-header">
        <h1>{{ $title }}</h1>
    </div>

    <div class="card table-card">
        <div class="table-header">
            <form method="get" action="{{ route('backend.logs.numbers') }}" class="table-search-form">
                <div class="table-search">
                    <input type="text" name="search" class="search-input" placeholder="Search by number, service, user..." value="{{ $search ?? '' }}">
                    <i class="las la-search"></i>
                </div>
                <button type="submit" class="btn btn-secondary search-btn">Search</button>
                @if(!empty($search))
                    <a href="{{ route('backend.logs.numbers') }}" class="btn btn-outline">Clear</a>
                @endif
            </form>
        </div>
        <div class="table-responsive">
            <table class="table">
                <thead>
                    <tr>
                        <th>#</th>
                        <th>User</th>
                        <th>Number</th>
                        <th>Service</th>
                        <th>Server</th>
                        <th>Price</th>
                        <th>Status</th>
                        <th>SMS</th>
                        <th>Buy time</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse($numbers as $row)
                        <tr>
                            <td>{{ $numbers->firstItem() + $loop->index }}</td>
                            <td>{{ $row->user?->email ?? 'N/A' }}</td>
                            <td>{{ $row->number }}</td>
                            <td>{{ $row->service_name ?? $row->service_id }}</td>
                            <td>{{ $row->server_id }}</td>
                            <td>{{ number_format($row->service_price, 2) }}</td>
                            <td>{{ $row->status }}</td>
                            <td>{{ \Illuminate\Support\Str::limit($row->sms_text ?? '-', 40) }}</td>
                            <td>{{ $row->buy_time?->format('Y-m-d H:i') }}</td>
                        </tr>
                    @empty
                        <tr><td colspan="9" class="text-center">No numbers found.</td></tr>
                    @endforelse
                </tbody>
            </table>
        </div>

        @if($numbers instanceof \Illuminate\Pagination\LengthAwarePaginator)
            <div class="pagination-wrapper">
                {{ $numbers->links('vendor.pagination.default') }}
            </div>
        @endif
    </div>
</div>
@endsection

