@extends('backend.layouts.app')
@section('title', @$data['title'])
@section('content')
    <form action="" method="GET">
        <div class="row align-items-center">
            <div class="col-md-4 col-lg-4 col-xl-3">
                <div class="form-group mb-20">

                    <input type="month" class="form-control ot-form-control ot-input" id="month" name="month" value="{{ request('month') ?? date('Y-m') }}" required>
                </div>
            </div>
            <div class="col-md-4 col-lg-4 col-xl-3">
                <div class="form-group mb-20">
                    <select name="user_id" class="form-control select2" data-placeholder="{{ _trans('common.Employee') }}">
                        <option value=""></option>
                        <option value="0">{{ _trans('common.All Employee') }}</option>
                        @foreach ($data['users'] ?? [] as $user)
                            <option value="{{ $user->id }}" {{ request('user_id') == $user->id ? 'selected' : '' }}>
                                {{ $user->name }} {{ $user->employee_id ? '[' . $user->employee_id . ']' : '' }}
                            </option>
                        @endforeach
                    </select>
                </div>
            </div>
            <div class="col-md-6 col-lg-4 col-xl-3">
                <div class="form-group mb-20">
                    <button type="submit" class="btn btn-gradian mr-3" name="search" value="1">{{ _trans('common.Search') }}</button>
                    @if(!empty($data['reports']))
                        <button class="btn btn-success p-2 px-3" name="excel_export" value="1">
                            <i class="fa-solid fa-download"></i>
                            {{ _trans('common.Export to Excel') }}
                        </button>
                    @endif
                </div>
            </div>
        </div>
    </form>
    <div class="table-content table-basic mt-3">
        <div class="card ot-card">
            <div class="d-flex align-items-center justify-content-center flex-column mb-20 mt-10">
                <h2 class="mb-10">{{ @$data['title'] }}</h2>
                <p class="fs-12">
                    {{ _trans('common.Generated At :') }} {{ \Carbon\Carbon::now()->format('d F Y, h:i A') }}
                    {{ _trans('common.By :') }} <strong>{{ auth()->user()->name }}</strong>
                </p>
            </div>
            <div class="card-header border-0 py-2 px-4 text-end">
                <small class="text-success">{{ _trans('common.P = Present') }}</small> |
                <small class="text-danger">{{ _trans('A = Absent') }}</small> |
                <small class="text-warning">{{ _trans('W = Weekend') }}</small> |
                <small class="text-danger">{{ _trans('H = Holiday') }}</small> |
                <small class="text-info">{{ _trans('L = Leave') }}</small>
            </div>
            <div class="card-body table-responsive p-0">
                <table class="table table-bordered table-nowrap">
                    <thead>
                        <th>{{ _trans('common.Employee') }}</th>
                        @for ($i = 1; $i <= $data['totalDays']; $i++)
                            <th class="text-center">{{ $i }}</th>
                        @endfor
                        <th class="text-center">{{ _trans('common.TP') }}</th>
                        <th class="text-center">{{ _trans('common.TA') }}</th>
                        <th class="text-center">{{ _trans('common.TW') }}</th>
                        <th class="text-center">{{ _trans('common.TH') }}</th>
                        <th class="text-center">{{ _trans('common.TL') }}</th>
                    </thead>
                    
                    <tbody>
    @forelse ($data['reports'] ?? [] as $report)
        <tr>
            <td>
                <span class="fw-semibold">
                    {{ $report['employee_name'] }}
                    @if ($report['employee_id'])
                        [{{ $report['employee_id'] }}]
                    @endif
                </span><br>
                <small class="text-muted">
                    {{ $report['department'] }}, {{ $report['designation'] }}
                </small>
            </td>
            
            @if (!empty($report['month_statuses']['totalNotJoin']))
                <td colspan="{{ $report['month_statuses']['totalNotJoin'] }}" 
                    class="text-center text-info fw-bold" 
                    style="background-color: #f3f4f6; color: #1a73e8;">
                    {{ _trans('common.Not Joined') }}
                </td>
            @endif

            @foreach ($report['month_statuses']['statuses'] as $key => $monthStatus)
                @if ($key >= $report['month_statuses']['totalNotJoin'])
                    <td class="text-center">{!! $monthStatus !!}</td>
                @endif
            @endforeach

            <td class="text-center fw-bold">{{ $report['month_statuses']['totalPresent'] }}</td>
            <td class="text-center fw-bold">{{ $report['month_statuses']['totalAbsent'] }}</td>
            <td class="text-center fw-bold">{{ $report['month_statuses']['totalWeekend'] }}</td>
            <td class="text-center fw-bold">{{ $report['month_statuses']['totalHoliday'] }}</td>
            <td class="text-center fw-bold">{{ $report['month_statuses']['totalLeave'] }}</td>
        </tr>
    @empty
        <tr>
            <td colspan="30" class="text-center text-danger fs-6 fw-bold">{{ _trans('common.No data found!') }}</td>
        </tr>
    @endforelse
</tbody>
                </table>

                <div class="mt-5">
                    {{ $data['reports']->links() }}
                </div>
            </div>
        </div>
    </div>
@endsection