

<?php $__env->startSection('title', 'Leave Management'); ?>
<?php $__env->startSection('heading', 'Leave Management'); ?>

<?php $__env->startSection('content'); ?>
<?php echo $__env->make('leaves.top-submenu', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
    <div
        x-data="{
            drawerOpen: false,
            drawerHtml: '',
            drawerLoading: false,
            drawerError: '',
            async openDrawer(url) {
                this.drawerOpen = true;
                this.drawerLoading = true;
                this.drawerError = '';
                this.drawerHtml = '';
                try {
                    const response = await fetch(url, { credentials: 'same-origin', headers: { 'Accept': 'text/html' } });
                    if (!response.ok) {
                        throw new Error('Failed to load leave details');
                    }
                    const html = await response.text();
                    const doc = new DOMParser().parseFromString(html, 'text/html');
                    this.drawerHtml = doc.body ? doc.body.innerHTML : html;
                } catch (e) {
                    this.drawerError = 'Unable to load leave details. Please try again.';
                } finally {
                    this.drawerLoading = false;
                }
            },
            closeDrawer() {
                this.drawerOpen = false;
                this.drawerHtml = '';
                this.drawerError = '';
                this.drawerLoading = false;
            }
        }"
        class="relative"
    >
    <?php if (isset($component)) { $__componentOriginal53747ceb358d30c0105769f8471417f6 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal53747ceb358d30c0105769f8471417f6 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.card','data' => []] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('card'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes([]); ?>
        <div class="mb-4 flex flex-wrap items-start justify-between gap-3">
            <div>
                <p class="text-sm text-slate-500">Review and manage leave requests</p>
            </div>
            <a href="<?php echo e(route('leaves.create')); ?>" class="inline-flex items-center rounded-lg bg-teal-700 px-4 py-2 text-sm font-medium text-white hover:bg-teal-600"><i class="bi bi-plus-lg me-1"></i>New Request</a>
        </div>

        <div class="mb-5 grid gap-3 md:grid-cols-2 xl:grid-cols-4">

    
    <div class="relative flex items-center justify-between overflow-hidden rounded-2xl border border-slate-200 bg-white p-4 pl-5 shadow-sm transition hover:shadow-md">
        <span class="absolute inset-y-0 left-0 w-1.5 rounded-l-2xl bg-amber-500" aria-hidden="true"></span>
        <div>
            <p class="text-xl font-semibold text-slate-900"><?php echo e($stats['pending']); ?></p>
            <p class="text-sm text-slate-500">Pending Requests</p>
        </div>
        <div class="flex h-10 w-10 items-center justify-center rounded-lg bg-amber-100 text-amber-600">
            <i class="bi bi-hourglass-split text-lg"></i>
        </div>
    </div>

    
    <div class="relative flex items-center justify-between overflow-hidden rounded-2xl border border-slate-200 bg-white p-4 pl-5 shadow-sm transition hover:shadow-md">
        <span class="absolute inset-y-0 left-0 w-1.5 rounded-l-2xl bg-emerald-500" aria-hidden="true"></span>
        <div>
            <p class="text-xl font-semibold text-slate-900"><?php echo e($stats['approved_today']); ?></p>
            <p class="text-sm text-slate-500">Approved Today</p>
        </div>
        <div class="flex h-10 w-10 items-center justify-center rounded-lg bg-green-100 text-green-600">
            <i class="bi bi-check-circle text-lg"></i>
        </div>
    </div>

    
    <div class="relative flex items-center justify-between overflow-hidden rounded-2xl border border-slate-200 bg-white p-4 pl-5 shadow-sm transition hover:shadow-md">
        <span class="absolute inset-y-0 left-0 w-1.5 rounded-l-2xl bg-rose-500" aria-hidden="true"></span>
        <div>
            <p class="text-xl font-semibold text-slate-900"><?php echo e($stats['rejected']); ?></p>
            <p class="text-sm text-slate-500">Rejected</p>
        </div>
        <div class="flex h-10 w-10 items-center justify-center rounded-lg bg-red-100 text-red-600">
            <i class="bi bi-x-circle text-lg"></i>
        </div>
    </div>

    
    <div class="relative flex items-center justify-between overflow-hidden rounded-2xl border border-slate-200 bg-white p-4 pl-5 shadow-sm transition hover:shadow-md">
        <span class="absolute inset-y-0 left-0 w-1.5 rounded-l-2xl bg-sky-500" aria-hidden="true"></span>
        <div>
            <p class="text-xl font-semibold text-slate-900"><?php echo e($stats['on_leave_today']); ?></p>
            <p class="text-sm text-slate-500">On Leave Today</p>
        </div>
        <div class="flex h-10 w-10 items-center justify-center rounded-lg bg-blue-100 text-blue-600">
            <i class="bi bi-calendar-x text-lg"></i>
        </div>
    </div>

</div>

        <div class="mb-5 flex flex-nowrap items-end justify-between gap-3 overflow-x-auto rounded-lg border border-slate-200 bg-slate-50 p-3">
            <div class="inline-flex shrink-0 rounded-lg border border-slate-300 bg-white p-1 text-sm">
                <a href="<?php echo e(route('leaves.index', array_merge(request()->except('status', 'page'), ['status' => null]))); ?>" class="rounded-md px-2 md:px-3 py-1.5 whitespace-nowrap <?php echo e(request('status') ? 'text-slate-600 hover:text-slate-900' : 'bg-teal-700 text-white'); ?>">All</a>
                <a href="<?php echo e(route('leaves.index', array_merge(request()->except('page'), ['status' => 'pending']))); ?>" class="rounded-md px-2 md:px-3 py-1.5 whitespace-nowrap <?php echo e(request('status') === 'pending' ? 'bg-teal-700 text-white' : 'text-slate-600 hover:text-slate-900'); ?>">Pending</a>
                <a href="<?php echo e(route('leaves.index', array_merge(request()->except('page'), ['status' => 'approved']))); ?>" class="rounded-md px-2 md:px-3 py-1.5 whitespace-nowrap <?php echo e(request('status') === 'approved' ? 'bg-teal-700 text-white' : 'text-slate-600 hover:text-slate-900'); ?>">Approved</a>
                <a href="<?php echo e(route('leaves.index', array_merge(request()->except('page'), ['status' => 'withdrawal_pending']))); ?>" class="rounded-md px-2 md:px-3 py-1.5 whitespace-nowrap <?php echo e(request('status') === 'withdrawal_pending' ? 'bg-teal-700 text-white' : 'text-slate-600 hover:text-slate-900'); ?>">Withdrawals</a>
                <a href="<?php echo e(route('leaves.index', array_merge(request()->except('page'), ['status' => 'rejected']))); ?>" class="rounded-md px-2 md:px-3 py-1.5 whitespace-nowrap <?php echo e(request('status') === 'rejected' ? 'bg-teal-700 text-white' : 'text-slate-600 hover:text-slate-900'); ?>">Rejected</a>
                <a href="<?php echo e(route('leaves.index', array_merge(request()->except('page'), ['status' => 'cancelled']))); ?>" class="rounded-md px-2 md:px-3 py-1.5 whitespace-nowrap <?php echo e(request('status') === 'cancelled' ? 'bg-teal-700 text-white' : 'text-slate-600 hover:text-slate-900'); ?>">Cancelled</a>
            </div>

            <form method="GET" action="<?php echo e(route('leaves.index')); ?>" class="flex flex-nowrap items-end gap-2">
                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(request()->filled('status')): ?>
                    <input type="hidden" name="status" value="<?php echo e(request('status')); ?>">
                <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                <div class="min-w-[10rem]">
                    <label class="mb-1 block text-xs font-medium text-slate-500">Leave type</label>
                    <select name="leave_type_id" class="w-full rounded-lg border border-slate-300 bg-white px-3 py-2 text-sm text-slate-800 js-select2">
                        <option value="">All types</option>
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__currentLoopData = ($leaveTypes ?? []); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $type): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($type->id); ?>" <?php if((string) request('leave_type_id') === (string) $type->id): echo 'selected'; endif; ?>><?php echo e($type->name); ?></option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                    </select>
                </div>
                <div class="min-w-[12rem]">
                    <label class="mb-1 block text-xs font-medium text-slate-500">Search</label>
                    <input type="search" name="q" value="<?php echo e(request('q')); ?>" placeholder="Employee, type, note…"
                           class="w-full rounded-lg border border-slate-300 bg-white px-3 py-2 text-sm text-slate-800 placeholder:text-slate-400">
                </div>
                <div class="flex shrink-0 gap-2 pb-px">
                    <button type="submit" class="rounded-lg bg-slate-800 px-4 py-2 text-sm font-medium text-white whitespace-nowrap hover:bg-slate-900">Apply</button>
                    <a href="<?php echo e(route('leaves.index', request()->only('status'))); ?>" class="rounded-lg bg-slate-100 px-4 py-2 text-sm font-medium text-slate-700 whitespace-nowrap">Reset</a>
                </div>
                <p class="shrink-0 pb-2 text-sm text-slate-500 whitespace-nowrap">Total: <?php echo e($leaves->total()); ?></p>
            </form>
        </div>

        <?php if (isset($component)) { $__componentOriginal163c8ba6efb795223894d5ffef5034f5 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal163c8ba6efb795223894d5ffef5034f5 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.table','data' => []] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('table'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes([]); ?>
             <?php $__env->slot('head', null, []); ?> 
                <tr>
                    <th class="px-4 py-3 text-left text-xs font-medium uppercase text-slate-500">Leave dates</th>
                    <th class="px-4 py-3 text-left text-xs font-medium uppercase text-slate-500">Leave type</th>
                    <th class="px-4 py-3 text-left text-xs font-medium uppercase text-slate-500">Status</th>
                    <th class="px-4 py-3 text-left text-xs font-medium uppercase text-slate-500">Requested by</th>
                    <th class="px-4 py-3 text-left text-xs font-medium uppercase text-slate-500">Leave note</th>
                    <th class="px-4 py-3 text-left text-xs font-medium uppercase text-slate-500">Actions</th>
                </tr>
             <?php $__env->endSlot(); ?>
            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__empty_1 = true; $__currentLoopData = $leaves; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $leave): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                <tr
                    class="cursor-pointer transition hover:bg-slate-50"
                    @click="openDrawer('<?php echo e(route('leave.popup')); ?>?leave_id=<?php echo e($leave->id); ?>')"
                >
                    <td class="px-4 py-3">
                        <p class="whitespace-nowrap font-medium text-slate-900"><?php echo e($leave->start_date?->format('d M Y') ?? '—'); ?></p>
                        <p class="text-xs text-slate-500">
                            <?php echo e($leave->total_days !== null ? rtrim(rtrim(number_format((float) $leave->total_days, 1, '.', ''), '0'), '.') : '—'); ?>

                            <?php echo e(abs((float) ($leave->total_days ?? 0)) == 1 ? 'Day' : 'Days'); ?>

                            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($leave->end_date && ! $leave->start_date?->isSameDay($leave->end_date)): ?>
                                · until <?php echo e($leave->end_date->format('d M Y')); ?>

                            <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                        </p>
                    </td>
                    <td class="px-4 py-3">
                        <p class="whitespace-nowrap font-medium text-slate-800"><?php echo e($leave->leaveType?->name ?? '—'); ?></p>
                        <p class="text-xs text-slate-500">Requested on <?php echo e($leave->created_at?->format('d M Y') ?? '—'); ?></p>
                    </td>
                    <td class="whitespace-nowrap px-4 py-3 text-sm text-slate-600">
                        <span class="rounded-full px-2 py-0.5 text-xs
                            <?php if($leave->status === 'approved'): ?> bg-emerald-100 text-emerald-700
                            <?php elseif($leave->status === 'rejected'): ?> bg-red-100 text-red-700
                            <?php elseif($leave->status === 'cancelled'): ?> bg-slate-100 text-slate-600
                            <?php elseif($leave->status === 'withdrawal_pending'): ?> bg-violet-100 text-violet-700
                            <?php else: ?> bg-amber-100 text-amber-700 <?php endif; ?>">
                            <?php echo e(ucfirst(str_replace('_', ' ', $leave->status))); ?>

                        </span>
                    </td>
                    <td class="px-4 py-3">
                        <p class="whitespace-nowrap font-medium text-slate-900"><?php echo e($leave->user?->name ?? '—'); ?></p>
                        <p class="whitespace-nowrap text-xs text-slate-500"><?php echo e($leave->user?->department?->name ?? '—'); ?></p>
                    </td>
                    <td class="max-w-[14rem] truncate px-4 py-3 text-sm text-slate-500" title="<?php echo e($leave->reason); ?>"><?php echo e($leave->reason ?: '—'); ?></td>
                    <td class="whitespace-nowrap px-4 py-3 text-sm" @click.stop>
                        <a
                            href="<?php echo e(route('leave.popup')); ?>?leave_id=<?php echo e($leave->id); ?>"
                            @click.prevent="openDrawer('<?php echo e(route('leave.popup')); ?>?leave_id=<?php echo e($leave->id); ?>')"
                            class="btn-icon-action btn-icon-action--view"
                            title="View"
                            aria-label="View"
                        ><i class="bi bi-eye"></i></a>
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if((int) $leave->user_id === (int) auth()->id() && $leave->status === 'pending'): ?>
                            <a
                                href="<?php echo e(route('leaves.edit', $leave)); ?>"
                                class="btn-icon-action btn-icon-action--edit"
                                title="Edit"
                                aria-label="Edit"
                            ><i class="bi bi-pencil-square"></i></a>
                            <form
                                method="POST"
                                action="<?php echo e(route('leaves.destroy', $leave)); ?>"
                                class="inline"
                                onsubmit="return confirm('Cancel this leave request?')"
                            >
                                <?php echo csrf_field(); ?>
                                <?php echo method_field('DELETE'); ?>
                                <button type="submit" class="btn-icon-action btn-icon-action--delete" title="Delete" aria-label="Delete"><i class="bi bi-trash3"></i></button>
                            </form>
                        <?php elseif(auth()->user()?->can('withdraw', $leave)): ?>
                            <a
                                href="<?php echo e(route('leave.popup')); ?>?leave_id=<?php echo e($leave->id); ?>"
                                @click.prevent="openDrawer('<?php echo e(route('leave.popup')); ?>?leave_id=<?php echo e($leave->id); ?>')"
                                class="btn-icon-action btn-icon-action--delete"
                                title="Withdraw"
                                aria-label="Withdraw"
                            ><i class="bi bi-arrow-return-left"></i></a>
                        <?php elseif($leave->status === 'withdrawal_pending' && auth()->user()?->can('approve', $leave)): ?>
                            <a
                                href="<?php echo e(route('leave.popup')); ?>?leave_id=<?php echo e($leave->id); ?>"
                                @click.prevent="openDrawer('<?php echo e(route('leave.popup')); ?>?leave_id=<?php echo e($leave->id); ?>')"
                                class="btn-icon-action btn-icon-action--view"
                                title="Review withdraw"
                                aria-label="Review withdraw"
                            ><i class="bi bi-clipboard-check"></i></a>
                        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                    </td>
                </tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                <tr><td colspan="6" class="px-4 py-8 text-center text-sm text-slate-500">No leave requests.</td></tr>
            <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
         <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal163c8ba6efb795223894d5ffef5034f5)): ?>
<?php $attributes = $__attributesOriginal163c8ba6efb795223894d5ffef5034f5; ?>
<?php unset($__attributesOriginal163c8ba6efb795223894d5ffef5034f5); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal163c8ba6efb795223894d5ffef5034f5)): ?>
<?php $component = $__componentOriginal163c8ba6efb795223894d5ffef5034f5; ?>
<?php unset($__componentOriginal163c8ba6efb795223894d5ffef5034f5); ?>
<?php endif; ?>
        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($leaves->hasPages()): ?><div class="mt-4"><?php echo e($leaves->links()); ?></div><?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
     <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal53747ceb358d30c0105769f8471417f6)): ?>
<?php $attributes = $__attributesOriginal53747ceb358d30c0105769f8471417f6; ?>
<?php unset($__attributesOriginal53747ceb358d30c0105769f8471417f6); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal53747ceb358d30c0105769f8471417f6)): ?>
<?php $component = $__componentOriginal53747ceb358d30c0105769f8471417f6; ?>
<?php unset($__componentOriginal53747ceb358d30c0105769f8471417f6); ?>
<?php endif; ?>
        <div
            x-show="drawerOpen"
            x-cloak
            class="fixed inset-0 z-[70]"
            aria-labelledby="leave-drawer-title"
            role="dialog"
            aria-modal="true"
        >
            <div class="absolute inset-0 bg-slate-900/35" @click="closeDrawer()"></div>
            <div
                x-show="drawerOpen"
                x-transition:enter="transform transition ease-out duration-250"
                x-transition:enter-start="translate-x-full"
                x-transition:enter-end="translate-x-0"
                x-transition:leave="transform transition ease-in duration-200"
                x-transition:leave-start="translate-x-0"
                x-transition:leave-end="translate-x-full"
                class="absolute right-0 top-0 h-full w-full max-w-2xl overflow-hidden border-l border-slate-200 bg-white shadow-2xl"
            >
                <div class="flex items-center justify-between border-b border-slate-200 px-4 py-3">
                    <h3 id="leave-drawer-title" class="font-semibold text-slate-900">Leave Details</h3>
                    <button
                        type="button"
                        class="rounded-md p-2 text-slate-500 hover:bg-slate-100 hover:text-slate-700"
                        @click="closeDrawer()"
                    >
                        <span class="sr-only">Close</span>
                        <i class="bi bi-x-lg"></i>
                    </button>
                </div>
                <div class="leave-popup-page h-[calc(100%-57px)] overflow-y-auto bg-white p-4">
                    <template x-if="drawerLoading">
                        <p class="text-sm text-slate-500">Loading leave details…</p>
                    </template>
                    <template x-if="!drawerLoading && drawerError">
                        <p class="text-sm text-red-600" x-text="drawerError"></p>
                    </template>
                    <div x-show="!drawerLoading && !drawerError" x-html="drawerHtml"></div>
                </div>
            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /var/www/html/kiyohr/v2_version/resources/views/leaves/index.blade.php ENDPATH**/ ?>