@extends('layouts.report-print')

@section('content')
    <table class="report-info">
        <tr>
            <td>{{ __('Total Employees') }}:</td>
            <td>{{ $employees->count() }}</td>
            <td>{{ __('Date') }}:</td>
            <td>{{ now()->format('Y-m-d') }}</td>
        </tr>
    </table>

    <table class="data-table">
        <thead>
            <tr>
                <th>{{ __('Code') }}</th>
                <th>{{ __('Name') }}</th>
                <th>{{ __('Department') }}</th>
                <th>{{ __('Position') }}</th>
                <th>{{ __('Joining Date') }}</th>
                <th>{{ __('Iqama Expiry') }}</th>
                <th>{{ __('Status') }}</th>
            </tr>
        </thead>
        <tbody>
            @foreach($employees as $e)
                <tr>
                    <td>{{ $e->employee_code }}</td>
                    <td>{{ $e->first_name }} {{ $e->last_name }}</td>
                    <td>{{ optional($e->department)->name }}</td>
                    <td>{{ optional($e->designation)->name }}</td>
                    <td>{{ $e->joining_date ? $e->joining_date->format('Y-m-d') : '' }}</td>
                    <td>
                        @if($e->iqama_expiry_date)
                            @php
                                $days = now()->diffInDays($e->iqama_expiry_date, false);
                            @endphp
                            {{ $e->iqama_expiry_date->format('Y-m-d') }}
                            @if($days < 0)
                                (Expired)
                            @elseif($days <= 30)
                                (Expiring Soon)
                            @endif
                        @endif
                    </td>
                    <td>{{ ucfirst($e->status) }}</td>
                </tr>
            @endforeach
            @if($employees->isEmpty())
                <tr>
                    <td colspan="7" style="text-align: center;">{{ __('No employees found.') }}</td>
                </tr>
            @endif
        </tbody>
    </table>
@endsection