<?php
    $policy = $attendancePolicy ?? null;
    $allowWeb = $policy?->allowWebCheckin ?? true;
    $mode = $policy?->mode ?? 'normal';
    $allowsOffice = $policy?->allowsOffice() ?? false;
    $allowsRemote = $policy?->allowsRemote() ?? false;
    $isHybrid = $policy?->isHybrid() ?? false;
    $isNormal = $policy?->isNormal() ?? true;
    $requireOfficeLocation = (bool) ($policy?->requireLocationForOffice ?? true);
    $clockedIn = $todayAttendance && $todayAttendance->clock_in_date_time;
    $canClockIn = $allowWeb && ! ($todayHasOpenSession ?? false) && ! ($todayIsWeekoff ?? false);
    $canClockOut = $allowWeb && (bool) ($todayHasOpenSession ?? false);
    $offices = $attendanceOffices ?? [];
    $variant = $variant ?? 'full';
    $prefix = $prefix ?? 'att';
    $sessionType = $todayAttendance->attendance_type ?? '';
    $typeLabel = match ($todayAttendance->attendance_type ?? null) {
        'office' => 'Office',
        'remote' => 'Remote',
        'normal' => 'Normal',
        default => null,
    };
    $officeName = $todayAttendance?->clockInOffice?->name;
    $workingSeconds = ($clockedIn && empty($todayAttendance->clock_out_date_time))
        ? $todayAttendance->clock_in_date_time->diffInSeconds(now())
        : (int) ($todayAttendance->total_duration ?? 0);
    $punchJsPath = public_path('js/attendance-punch.js');
    $punchJsVersion = is_file($punchJsPath) ? filemtime($punchJsPath) : time();
?>

<?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($allowWeb): ?>
<?php
    $showSessionSummary = isset($showSummary)
        ? (bool) $showSummary
        : ($variant === 'full' || $prefix === 'selfdash');
?>
<div class="attendance-punch" data-attendance-punch data-variant="<?php echo e($variant); ?>" data-prefix="<?php echo e($prefix); ?>" data-mode="<?php echo e($mode); ?>" data-session-type="<?php echo e($sessionType); ?>" data-allows-office="<?php echo e($allowsOffice ? '1' : '0'); ?>" data-allows-remote="<?php echo e($allowsRemote ? '1' : '0'); ?>" data-is-hybrid="<?php echo e($isHybrid ? '1' : '0'); ?>" data-require-office-location="<?php echo e($requireOfficeLocation ? '1' : '0'); ?>" data-accuracy-requirement="<?php echo e($policy?->gpsAccuracyRequirement ?? ''); ?>" data-offices='<?php echo json_encode($offices, 15, 512) ?>'>
    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($showSessionSummary): ?>
        <div class="space-y-2">
            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($clockedIn): ?>
                <div class="flex flex-wrap gap-x-4 gap-y-1 text-sm text-slate-600">
                    <span>In: <?php echo e($todayAttendance->clock_in_date_time->format('g:i A')); ?></span>
                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($typeLabel): ?>
                        <span><?php echo e($typeLabel); ?><?php echo e($officeName ? ' · '.$officeName : ''); ?></span>
                    <?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(($todayAttendance->remote_approval_status ?? null) === 'pending'): ?>
                        <span class="text-amber-700">Remote pending approval</span>
                    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                    <span data-working-duration data-started-at="<?php echo e($todayAttendance->clock_out_date_time ? '' : $todayAttendance->clock_in_date_time->toIso8601String()); ?>" data-total-seconds="<?php echo e($workingSeconds); ?>">
                        Duration: <?php echo e(intdiv($workingSeconds, 3600)); ?>h <?php echo e(intdiv($workingSeconds % 3600, 60)); ?>m
                    </span>
                </div>
            <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
            <div data-geo-status class="text-sm text-slate-600"></div>
        </div>
    <?php else: ?>
        <div data-geo-status class="sr-only" aria-live="polite"></div>
    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>

    <div class="<?php echo e($showSessionSummary ? 'mt-2' : ''); ?> flex flex-wrap items-center gap-2">
        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($canClockIn): ?>
            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($isHybrid): ?>
                <form action="<?php echo e(route('attendance.check-in')); ?>" method="post" class="attendance-punch-form mb-0" data-punch-type="hybrid">
                    <?php echo csrf_field(); ?>
                    <input type="hidden" name="latitude" data-field="latitude" value="">
                    <input type="hidden" name="longitude" data-field="longitude" value="">
                    <input type="hidden" name="accuracy" data-field="accuracy" value="">
                    <input type="hidden" name="location" data-field="location" value="">
                    <button type="submit" data-office-submit class="inline-flex items-center gap-2 rounded-lg bg-primary px-3 py-2 text-sm font-medium text-white hover:opacity-95 disabled:cursor-not-allowed disabled:opacity-60">
                        Check In
                    </button>
                </form>
            <?php else: ?>
                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($allowsOffice): ?>
                    <form action="<?php echo e(route('attendance.check-in')); ?>" method="post" class="attendance-punch-form mb-0" data-punch-type="office">
                        <?php echo csrf_field(); ?>
                        <input type="hidden" name="latitude" data-field="latitude" value="">
                        <input type="hidden" name="longitude" data-field="longitude" value="">
                        <input type="hidden" name="accuracy" data-field="accuracy" value="">
                        <input type="hidden" name="location" data-field="location" value="">
                        <input type="hidden" name="attendance_type" value="office">
                        <button type="submit" data-office-submit class="inline-flex items-center gap-2 rounded-lg bg-primary px-3 py-2 text-sm font-medium text-white hover:opacity-95 disabled:cursor-not-allowed disabled:opacity-60">
                            Check In
                        </button>
                    </form>
                <?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($allowsRemote): ?>
                    <form action="<?php echo e(route('attendance.check-in')); ?>" method="post" class="attendance-punch-form mb-0" data-punch-type="remote">
                        <?php echo csrf_field(); ?>
                        <input type="hidden" name="latitude" data-field="latitude" value="">
                        <input type="hidden" name="longitude" data-field="longitude" value="">
                        <input type="hidden" name="accuracy" data-field="accuracy" value="">
                        <input type="hidden" name="location" data-field="location" value="">
                        <input type="hidden" name="attendance_type" value="remote">
                        <button type="submit" class="inline-flex items-center gap-2 rounded-lg bg-primary px-3 py-2 text-sm font-medium text-white hover:opacity-95 disabled:cursor-not-allowed disabled:opacity-60">
                            Check In
                        </button>
                    </form>
                <?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($isNormal): ?>
                    <form action="<?php echo e(route('attendance.check-in')); ?>" method="post" class="attendance-punch-form mb-0" data-punch-type="normal">
                        <?php echo csrf_field(); ?>
                        <input type="hidden" name="latitude" data-field="latitude" value="">
                        <input type="hidden" name="longitude" data-field="longitude" value="">
                        <input type="hidden" name="accuracy" data-field="accuracy" value="">
                        <input type="hidden" name="location" data-field="location" value="">
                        <input type="hidden" name="attendance_type" value="normal">
                        <button type="submit" class="inline-flex items-center gap-2 rounded-lg bg-primary px-3 py-2 text-sm font-medium text-white hover:opacity-95">
                            Check In
                        </button>
                    </form>
                <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
            <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
        <?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($canClockOut): ?>
            <form action="<?php echo e(route('attendance.check-out')); ?>" method="post" class="attendance-punch-form mb-0" data-punch-type="<?php echo e($sessionType ?: 'normal'); ?>">
                <?php echo csrf_field(); ?>
                <input type="hidden" name="latitude" data-field="latitude" value="">
                <input type="hidden" name="longitude" data-field="longitude" value="">
                <input type="hidden" name="accuracy" data-field="accuracy" value="">
                <input type="hidden" name="location" data-field="location" value="">
                <input type="hidden" name="attendance_type" value="<?php echo e($sessionType ?: 'normal'); ?>">
                <button type="submit" <?php if($sessionType === 'office'): ?> data-office-submit <?php endif; ?> class="inline-flex items-center gap-2 rounded-lg px-3 py-2 text-sm font-medium text-white hover:opacity-95 disabled:cursor-not-allowed disabled:opacity-60" style="background-color: var(--color-secondary)">
                    Check Out
                </button>
            </form>
        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
    </div>
</div>
<?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>

<?php if (! $__env->hasRenderedOnce('attendance-punch-js')): $__env->markAsRenderedOnce('attendance-punch-js');
$__env->startPush('scripts'); ?>
    <script src="<?php echo e(asset('js/attendance-punch.js')); ?>?v=<?php echo e($punchJsVersion); ?>" defer></script>
<?php $__env->stopPush(); endif; ?>
<?php /**PATH /var/www/html/kiyohr/v2_version/resources/views/attendance/partials/punch-forms.blade.php ENDPATH**/ ?>