@extends('layouts.app')

@section('title', \App\Helpers\TranslationHelper::transFromDatabase('Leave Request Details', __('Leave Request Details')))

@section('content')
<div class="min-h-screen bg-gradient-to-br from-slate-50 to-slate-100 py-8 px-4 md:px-8">
    <div class="max-w-4xl mx-auto">
        <div class="flex items-center justify-between mb-8">
            <div>
                <h1 class="text-3xl font-bold text-gray-900 mb-2">{{ \App\Helpers\TranslationHelper::transFromDatabase('Leave Request Details', __('Leave Request Details')) }}</h1>
                <p class="text-gray-600">{{ \App\Helpers\TranslationHelper::transFromDatabase('View and manage employee leave request information', __('View and manage employee leave request information')) }}</p>
            </div>
            <a href="{{ route('employee-leaves.index') }}" class="inline-flex items-center px-4 py-2 bg-white border border-gray-300 rounded-lg text-gray-700 font-medium hover:bg-gray-50 transition-all duration-200 shadow-sm">
                <i class="fas fa-arrow-right ml-2"></i>
                <span>{{ \App\Helpers\TranslationHelper::transFromDatabase('Back to List', __('Back to List')) }}</span>
            </a>
        </div>

        <div class="grid grid-cols-1 lg:grid-cols-3 gap-8">
            <!-- Left Column: Details -->
            <div class="lg:col-span-2 space-y-6">
                <div class="bg-white rounded-xl shadow-lg overflow-hidden border border-gray-200">
                    <div class="bg-gradient-to-r from-gray-800 to-gray-900 px-6 py-4">
                        <h2 class="text-lg font-bold text-white">{{ \App\Helpers\TranslationHelper::transFromDatabase('Request Information', __('Request Information')) }}</h2>
                    </div>
                    <div class="p-6">
                        <div class="grid grid-cols-2 gap-y-6">
                            <div>
                                <p class="text-sm text-gray-500 mb-1">{{ \App\Helpers\TranslationHelper::transFromDatabase('Employee', __('Employee')) }}</p>
                                <p class="font-bold text-gray-900 text-lg">{{ $employeeLeave->employee->user->name }}</p>
                                <p class="text-sm text-gray-600">{{ $employeeLeave->employee->employee_number }}</p>
                            </div>
                            <div>
                                <p class="text-sm text-gray-500 mb-1">{{ \App\Helpers\TranslationHelper::transFromDatabase('Leave Type', __('Leave Type')) }}</p>
                                <p class="font-bold text-gray-900 text-lg">
                                    @if(isset($employeeLeave::$leaveTypes[$employeeLeave->leave_type]))
                                        {{ $employeeLeave::$leaveTypes[$employeeLeave->leave_type] }}
                                    @else
                                        {{ $employeeLeave->leave_type }}
                                    @endif
                                </p>
                            </div>
                            <div>
                                <p class="text-sm text-gray-500 mb-1">{{ \App\Helpers\TranslationHelper::transFromDatabase('Duration', __('Duration')) }}</p>
                                <div class="flex items-center gap-4">
                                    <div>
                                        <p class="text-xs text-gray-400 uppercase tracking-wider">{{ \App\Helpers\TranslationHelper::transFromDatabase('From', __('From')) }}</p>
                                        <p class="font-semibold text-gray-800">{{ $employeeLeave->start_date }}</p>
                                    </div>
                                    <i class="fas fa-long-arrow-alt-left text-gray-300"></i>
                                    <div>
                                        <p class="text-xs text-gray-400 uppercase tracking-wider">{{ \App\Helpers\TranslationHelper::transFromDatabase('To', __('To')) }}</p>
                                        <p class="font-semibold text-gray-800">{{ $employeeLeave->end_date }}</p>
                                    </div>
                                </div>
                                <p class="mt-2 inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-blue-100 text-blue-800">
                                    {{ $employeeLeave->days }} {{ \App\Helpers\TranslationHelper::transFromDatabase('Days', __('Days')) }}
                                </p>
                            </div>
                            <div>
                                <p class="text-sm text-gray-500 mb-1">{{ \App\Helpers\TranslationHelper::transFromDatabase('Request Status', __('Request Status')) }}</p>
                                @if($employeeLeave->status == 'pending')
                                    <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-amber-100 text-amber-700">
                                        <span class="w-2 h-2 bg-amber-500 rounded-full ml-2"></span>
                                        {{ \App\Helpers\TranslationHelper::transFromDatabase('Pending', __('Pending')) }}
                                    </span>
                                @elseif($employeeLeave->status == 'approved')
                                    <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-green-100 text-green-700">
                                        <span class="w-2 h-2 bg-green-500 rounded-full ml-2"></span>
                                        {{ \App\Helpers\TranslationHelper::transFromDatabase('Approved', __('Approved')) }}
                                    </span>
                                @elseif($employeeLeave->status == 'rejected')
                                    <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-red-100 text-red-700">
                                        <span class="w-2 h-2 bg-red-500 rounded-full ml-2"></span>
                                        {{ \App\Helpers\TranslationHelper::transFromDatabase('Rejected', __('Rejected')) }}
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="mt-8">
                            <p class="text-sm text-gray-500 mb-2">{{ \App\Helpers\TranslationHelper::transFromDatabase('Reason', __('Reason')) }}</p>
                            <div class="bg-gray-50 rounded-lg p-4 text-gray-700 border border-gray-100">
                                {{ $employeeLeave->reason }}
                            </div>
                        </div>

                        @if($employeeLeave->attachment)
                        <div class="mt-8 pt-6 border-t border-gray-100">
                            <p class="text-sm text-gray-500 mb-3">{{ \App\Helpers\TranslationHelper::transFromDatabase('Attachments', __('Attachments')) }}</p>
                            <a href="{{ Storage::url($employeeLeave->attachment) }}" target="_blank" class="inline-flex items-center px-4 py-3 bg-blue-50 text-blue-700 rounded-xl hover:bg-blue-100 transition-colors border border-blue-100 group">
                                <i class="fas fa-file-pdf text-2xl ml-3 group-hover:scale-110 transition-transform"></i>
                                <div>
                                    <p class="font-semibold text-sm">{{ \App\Helpers\TranslationHelper::transFromDatabase('View Attached File', __('View Attached File')) }}</p>
                                    <p class="text-xs opacity-75">{{ \App\Helpers\TranslationHelper::transFromDatabase('Click to open or download', __('Click to open or download')) }}</p>
                                </div>
                            </a>
                        </div>
                        @endif
                    </div>
                </div>

                @if($employeeLeave->status == 'rejected' && $employeeLeave->rejection_reason)
                <div class="bg-red-50 rounded-xl border border-red-200 p-6">
                    <div class="flex items-start">
                        <i class="fas fa-exclamation-triangle text-red-500 text-xl ml-4 mt-1"></i>
                        <div>
                            <h3 class="text-red-800 font-bold mb-2">{{ \App\Helpers\TranslationHelper::transFromDatabase('Rejection Reason', __('Rejection Reason')) }}</h3>
                            <p class="text-red-700">{{ $employeeLeave->rejection_reason }}</p>
                        </div>
                    </div>
                </div>
                @endif
            </div>

            <!-- Right Column: Actions & Log -->
            <div class="space-y-6">
                <div class="bg-white rounded-xl shadow-lg p-6 border border-gray-200">
                    <h3 class="font-bold text-gray-900 mb-4 pb-2 border-b">{{ \App\Helpers\TranslationHelper::transFromDatabase('Actions', __('Actions')) }}</h3>
                    <div class="space-y-3">
                        @if($employeeLeave->status == 'pending')
                            @can('hr.leaves.approve')
                            <form action="{{ route('employee-leaves.approve', $employeeLeave) }}" method="POST">
                                @csrf
                                <button type="submit" class="w-full inline-flex items-center justify-center px-4 py-2 bg-green-600 text-white font-bold rounded-lg hover:bg-green-700 transition-all shadow hover:shadow-lg" onclick="return confirm('{{ \App\Helpers\TranslationHelper::transFromDatabase('Are you sure you want to approve this leave request?', __('Are you sure you want to approve this leave request?')) }}')">
                                    <i class="fas fa-check ml-2"></i>
                                    {{ \App\Helpers\TranslationHelper::transFromDatabase('Approve Request', __('Approve Request')) }}
                                </button>
                            </form>

                            <button type="button" class="w-full inline-flex items-center justify-center px-4 py-2 bg-red-600 text-white font-bold rounded-lg hover:bg-red-700 transition-all shadow hover:shadow-lg" data-toggle="modal" data-target="#rejectModal">
                                <i class="fas fa-times ml-2"></i>
                                {{ \App\Helpers\TranslationHelper::transFromDatabase('Reject Request', __('Reject Request')) }}
                            </button>
                            @endcan

                            @can('hr.leaves.edit')
                            <a href="{{ route('employee-leaves.edit', $employeeLeave) }}" class="w-full inline-flex items-center justify-center px-4 py-2 bg-amber-100 text-amber-700 font-bold rounded-lg hover:bg-amber-200 transition-all">
                                <i class="fas fa-edit ml-2"></i>
                                {{ \App\Helpers\TranslationHelper::transFromDatabase('Edit Request', __('Edit Request')) }}
                            </a>
                            @endcan
                        @endif

                        @can('hr.leaves.delete')
                        <form action="{{ route('employee-leaves.destroy', $employeeLeave) }}" method="POST">
                            @csrf
                            @method('DELETE')
                            <button type="submit" class="w-full inline-flex items-center justify-center px-4 py-2 bg-red-50 text-red-600 font-bold rounded-lg hover:bg-red-100 transition-all" onclick="return confirm('{{ \App\Helpers\TranslationHelper::transFromDatabase('Are you sure you want to delete this leave request?', __('Are you sure you want to delete this leave request?')) }}')">
                                <i class="fas fa-trash ml-2"></i>
                                {{ \App\Helpers\TranslationHelper::transFromDatabase('Delete Request', __('Delete Request')) }}
                            </button>
                        </form>
                        @endcan
                    </div>
                </div>

                @if($employeeLeave->status != 'pending')
                <div class="bg-white rounded-xl shadow-lg p-6 border border-gray-200">
                    <h3 class="font-bold text-gray-900 mb-4 pb-2 border-b">{{ \App\Helpers\TranslationHelper::transFromDatabase('Decision Details', __('Decision Details')) }}</h3>
                    <div class="space-y-4">
                        <div>
                            <p class="text-xs text-gray-500 mb-1 uppercase tracking-wider">{{ \App\Helpers\TranslationHelper::transFromDatabase('Processed By', __('Processed By')) }}</p>
                            <div class="flex items-center">
                                <div class="w-8 h-8 rounded-full bg-gray-100 flex items-center justify-center ml-3">
                                    <i class="fas fa-user text-gray-400"></i>
                                </div>
                                <p class="font-bold text-gray-800">{{ $employeeLeave->approver->name ?? 'N/A' }}</p>
                            </div>
                        </div>
                        <div>
                            <p class="text-xs text-gray-500 mb-1 uppercase tracking-wider">{{ \App\Helpers\TranslationHelper::transFromDatabase('Decision Date', __('Decision Date')) }}</p>
                            <p class="font-semibold text-gray-800">{{ $employeeLeave->approved_at ? $employeeLeave->approved_at->format('Y-m-d H:i') : 'N/A' }}</p>
                        </div>
                    </div>
                </div>
                @endif
            </div>
        </div>
    </div>
</div>

<!-- Rejection Modal -->
<div class="modal fade" id="rejectModal" tabindex="-1" role="dialog" aria-labelledby="rejectModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <form action="{{ route('employee-leaves.reject', $employeeLeave) }}" method="POST">
                @csrf
                <div class="modal-header">
                    <h5 class="modal-title" id="rejectModalLabel">{{ \App\Helpers\TranslationHelper::transFromDatabase('Reject Leave Request', __('Reject Leave Request')) }}</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body text-right">
                    <div class="form-group">
                        <label for="rejection_reason">{{ \App\Helpers\TranslationHelper::transFromDatabase('Rejection Reason', __('Rejection Reason')) }} <span class="text-danger">*</span></label>
                        <textarea name="rejection_reason" id="rejection_reason" rows="3" class="form-control" required></textarea>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">{{ \App\Helpers\TranslationHelper::transFromDatabase('Cancel', __('Cancel')) }}</button>
                    <button type="submit" class="btn btn-danger">{{ \App\Helpers\TranslationHelper::transFromDatabase('Reject Leave', __('Reject Leave')) }}</button>
                </div>
            </form>
        </div>
    </div>
</div>
@endsection
