<?php
    $regularization = $regularization ?? null;
    $canRequest = (bool) ($canRequest ?? false);
    $canApprove = $regularization && auth()->user()?->canApproveRegularization($regularization);
    $isPending = $regularization && $regularization->status === \App\Models\AttendanceRegularization::STATUS_PENDING;
    $reqClockIn = $regularization?->requested_clock_in?->format('H:i') ?? $defaultClockIn ?? '';
    $reqClockOut = $regularization?->requested_clock_out?->format('H:i') ?? $defaultClockOut ?? '';
?>

<div class="rounded-xl border border-slate-200 bg-white p-4">
    <p class="mb-3 text-sm font-semibold text-slate-900">Request Regularization</p>

    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($regularization): ?>
        <div class="mb-4 rounded-lg border border-slate-200 bg-slate-50 p-3 text-sm">
            <div class="flex flex-wrap items-center justify-between gap-2">
                <span class="font-medium text-slate-800">Existing request</span>
                <span class="rounded-full px-2 py-0.5 text-xs
                    <?php if($regularization->status === 'approved'): ?> bg-emerald-100 text-emerald-700
                    <?php elseif($regularization->status === 'rejected'): ?> bg-red-100 text-red-700
                    <?php else: ?> bg-amber-100 text-amber-700 <?php endif; ?>">
                    <?php echo e(ucfirst($regularization->status)); ?>

                </span>
            </div>
            <p class="mt-2 text-slate-600">
                Requested:
                <?php echo e($regularization->requested_clock_in ? $regularization->requested_clock_in->format('h:i A') : '—'); ?>

                –
                <?php echo e($regularization->requested_clock_out ? $regularization->requested_clock_out->format('h:i A') : '—'); ?>

            </p>
            <p class="mt-1 text-slate-600"><?php echo e($regularization->reason); ?></p>
            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($regularization->review_remarks): ?>
                <p class="mt-2 text-xs text-slate-500">Reviewer remarks: <?php echo e($regularization->review_remarks); ?></p>
            <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
        </div>
    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>

    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($canApprove && $isPending): ?>
        <div class="mb-4 space-y-3 border-t border-slate-200 pt-4">
            <p class="text-sm font-medium text-slate-800">Manager approval</p>
            <form action="<?php echo e(route('attendance-regularizations.approve', $regularization)); ?>" method="POST" class="space-y-2">
                <?php echo csrf_field(); ?>
                <input type="hidden" name="redirect_to" value="attendance">
                <input type="hidden" name="year" value="<?php echo e($selectedYear); ?>">
                <input type="hidden" name="month" value="<?php echo e($selectedMonth); ?>">
                <input type="hidden" name="employee_id" value="<?php echo e($selectedEmployeeId); ?>">
                <input type="text" name="review_remarks" placeholder="Approval remarks (optional)" class="w-full rounded-lg border border-slate-300 px-3 py-2 text-sm">
                <button type="submit" class="inline-flex w-full items-center justify-center rounded-lg bg-emerald-600 px-4 py-2 text-sm font-medium text-white hover:bg-emerald-700">Approve</button>
            </form>
            <form action="<?php echo e(route('attendance-regularizations.reject', $regularization)); ?>" method="POST" class="space-y-2">
                <?php echo csrf_field(); ?>
                <input type="hidden" name="redirect_to" value="attendance">
                <input type="hidden" name="year" value="<?php echo e($selectedYear); ?>">
                <input type="hidden" name="month" value="<?php echo e($selectedMonth); ?>">
                <input type="hidden" name="employee_id" value="<?php echo e($selectedEmployeeId); ?>">
                <input type="text" name="review_remarks" placeholder="Rejection reason (optional)" class="w-full rounded-lg border border-slate-300 px-3 py-2 text-sm">
                <button type="submit" class="inline-flex w-full items-center justify-center rounded-lg border border-red-300 bg-white px-4 py-2 text-sm font-medium text-red-700 hover:bg-red-50">Reject</button>
            </form>
        </div>
    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>

    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($canRequest && ! $isPending): ?>
        <form action="<?php echo e(route('attendance-regularizations.store')); ?>" method="POST" class="space-y-3">
            <?php echo csrf_field(); ?>
            <input type="hidden" name="date" value="<?php echo e($date); ?>">
            <input type="hidden" name="redirect_to" value="attendance">
            <input type="hidden" name="year" value="<?php echo e($selectedYear); ?>">
            <input type="hidden" name="month" value="<?php echo e($selectedMonth); ?>">
            <input type="hidden" name="employee_id" value="<?php echo e($selectedEmployeeId); ?>">
            <p class="text-xs text-slate-500">Update the times you want corrected. Your manager (and higher approvers) will be notified.</p>
            <div class="grid gap-3 sm:grid-cols-2">
                <div>
                    <label class="mb-1 block text-xs font-medium uppercase text-slate-500">Requested clock in</label>
                    <input type="time" name="requested_clock_in_time" step="60" value="<?php echo e(old('requested_clock_in_time', $reqClockIn)); ?>" class="w-full rounded-lg border border-slate-300 px-3 py-2 text-sm">
                </div>
                <div>
                    <label class="mb-1 block text-xs font-medium uppercase text-slate-500">Requested clock out</label>
                    <input type="time" name="requested_clock_out_time" step="60" value="<?php echo e(old('requested_clock_out_time', $reqClockOut)); ?>" class="w-full rounded-lg border border-slate-300 px-3 py-2 text-sm">
                </div>
            </div>
            <div>
                <label class="mb-1 block text-xs font-medium uppercase text-slate-500">Reason</label>
                <textarea name="reason" rows="3" required class="w-full rounded-lg border border-slate-300 px-3 py-2 text-sm" placeholder="Why is this correction needed?"><?php echo e(old('reason')); ?></textarea>
            </div>
            <button type="submit" class="inline-flex w-full items-center justify-center rounded-lg bg-slate-800 px-4 py-2 text-sm font-medium text-white hover:bg-slate-700">
                Submit for approval
            </button>
        </form>
    <?php elseif($canRequest && $isPending): ?>
        <p class="text-sm text-amber-700">Your request is pending manager approval.</p>
    <?php elseif(! $canRequest && ! $regularization): ?>
        <p class="text-sm text-slate-500">Only the employee can submit a regularization request from this calendar.</p>
    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
</div>
<?php /**PATH /var/www/html/kiyohr/v2_version/resources/views/attendance/partials/day-regularization.blade.php ENDPATH**/ ?>