<title>Project Manager Dashboard</title>
@extends('ui::layouts.app')

@section('content')
<style type="text/css">
    body {
        background-color: #f0f2f5;
    }

    .ui.container {
        max-width: 100% !important;
        overflow-x: hidden;
        padding: 0 5rem 0 2rem;
        box-sizing: border-box;
    }
    
    .ui.segments {
        margin-top: 2rem;
    }

    .ui.segment {
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    }
    @keyframes spin { 
        to { transform: rotate(360deg); } 
    }
    #loader {
        position: fixed;
        top: 0; left: 0;
        width: 100%; height: 100%;
        display: none;
        align-items: center; justify-content: center;
        background: rgba(0, 0, 0, 0.5);
        z-index: 9999;
    }
    #loader div {
        margin-top: 20%;
        margin-left:45%;
        width: 60px; height: 60px;
        border: 6px solid #fff;
        border-top: 6px solid transparent;
        border-radius: 50%;
        animation: spin 1s linear infinite;
    }
</style>

<div id="loader"><div></div></div>
<div class="ui container">
    <h2 class="ui header">Project Manager Dashboard</h2>

    {{-- Pending Claims --}}
    <h3 class="ui dividing header">Pending Claims</h3>
    <table class="ui celled table">
        <thead>
            <tr>
                <th>#</th>
                <th>Staff</th>
                <th>Date</th>
                <th>Project</th>
                <th>Distance</th>
                <th>Total</th>
                <th>Status</th>
                <th>Action</th>
            </tr>
        </thead>
        <tbody>
            @forelse($claims->where('status', 'Diproses') as $claim)
                <tr>
                    <td>{{ $loop->iteration }}</td>
                    <td>{{ $claim->user->name ?? '-' }}</td>
                    <td>{{ $claim->claim_date }}</td>
                    <td>{{ $claim->project->p_project_description ?? '-' }}</td>
                    <td>{{ $claim->total_mileage }} km</td>
                    <td>RM {{ number_format($claim->total_claim_amount, 2) }}</td>
                    <td>{{ $claim->status }}</td>
                    <td>
                        <a href="{{ route('mileage::projectManager.show', $claim->id) }}" class="ui blue button tiny">
                            Lihat
                        </a>
                        <form action="{{ route('mileage::applications.updateStatus', $claim->id) }}" method="POST" style="display:inline;">
                            @csrf
                            @method('PUT')
                            <input type="hidden" name="action" value="verify">
                            <button class="ui green button tiny" type="submit">Verify</button>
                        </form>

                        <form action="{{ route('mileage::applications.updateStatus', $claim->id) }}" method="POST" style="display:inline;">
                            @csrf
                            @method('PUT')
                            <input type="hidden" name="action" value="reject">
                            <button class="ui red button tiny" type="submit">Reject</button>
                        </form>
                    </td>
                </tr>
            @empty
                <tr>
                    <td colspan="7">No pending claims.</td>
                </tr>
            @endforelse
        </tbody>
    </table>

    {{-- Previous Claims --}}
    <h3 class="ui dividing header">Previous Claims</h3>
    <table class="ui celled table">
        <thead>
            <tr>
                <th>#</th>
                <th>Staff</th>
                <th>Project</th>
                <th>Distance</th>
                <th>Total</th>
                <th>Status</th>
            </tr>
        </thead>
        <tbody>
            @forelse($claims->where('status', '!=', 'Diproses') as $claim)
                <tr>
                    <td>{{ $loop->iteration }}</td>
                    <td>{{ $claim->user->name ?? '-' }}</td>
                    <td>{{ $claim->project->p_project_description ?? '-' }}</td>
                    <td>{{ $claim->total_mileage }} km</td>
                    <td>RM {{ number_format($claim->total_claim_amount, 2) }}</td>
                    <td>{{ $claim->status }}</td>
                </tr>
            @empty
                <tr>
                    <td colspan="6">No previous claims.</td>
                </tr>
            @endforelse
        </tbody>
    </table>
</div>
@endsection
