

<?php $__env->startSection('title', 'Hari Libur - MagangTime'); ?>
<?php $__env->startSection('page-title', 'Hari Libur'); ?>

<?php $__env->startSection('content'); ?>
<div class="card">
    <div class="card-header bg-white">
        <div class="row align-items-center">
            <div class="col-md-6">
                <h5 class="mb-0"><i class="fas fa-calendar-alt me-2"></i>Kelola Hari Libur</h5>
            </div>
            <div class="col-md-6 text-end">
                <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addHolidayModal">
                    <i class="fas fa-plus me-2"></i>Tambah Hari Libur
                </button>
            </div>
        </div>
        
        <div class="row mt-3">
            <div class="col-md-8">
                <form method="GET" action="<?php echo e(route('admin.holidays')); ?>" class="d-flex">
                    <input type="text" name="search" class="form-control me-2" 
                           placeholder="Cari deskripsi atau tanggal..." 
                           value="<?php echo e(request('search')); ?>">
                    <button type="submit" class="btn btn-outline-primary"><i class="fas fa-search"></i></button>
                    <?php if(request('search')): ?>
                        <a href="<?php echo e(route('admin.holidays')); ?>" class="btn btn-outline-secondary ms-2"><i class="fas fa-times"></i></a>
                    <?php endif; ?>
                </form>
            </div>
        </div>
    </div>
    
    <div class="card-body">
        <?php if($errors->any()): ?>
            <div class="alert alert-danger">
                <ul class="mb-0"><?php $__currentLoopData = $errors->all(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $error): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><li><?php echo e($error); ?></li><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></ul>
            </div>
        <?php endif; ?>
        
        <div class="table-responsive">
            <table class="table table-striped table-hover">
                <thead class="table-dark">
                    <tr>
                        <th width="5%">No</th><th>Tanggal</th><th>Deskripsi</th><th width="10%">Status</th><th width="8%">Aksi</th>
                    </tr>
                </thead>
                <tbody>
                    <?php $__empty_1 = true; $__currentLoopData = $holidays; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $holiday): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                    <tr>
                        <td><?php echo e($holidays->firstItem() + $index); ?></td>
                        <td><?php echo e($holiday->date->isoFormat('dddd, D MMMM Y')); ?></td>
                        <td><?php echo e($holiday->description); ?></td>
                        <td class="text-center">
                            <?php if($holiday->date->isPast()): ?>
                                <span class="badge bg-secondary">Lewat</span>
                            <?php elseif($holiday->date->isToday()): ?>
                                <span class="badge bg-info">Hari Ini</span>
                            <?php else: ?>
                                <span class="badge bg-success">Mendatang</span>
                            <?php endif; ?>
                        </td>
                        <td>
                            <div class="btn-group" role="group">
                                <button class="btn btn-sm btn-warning" onclick="editHoliday(<?php echo e($holiday->id); ?>, '<?php echo e($holiday->date->format('Y-m-d')); ?>', '<?php echo e($holiday->description); ?>')"><i class="fas fa-edit"></i></button>
                                <button class="btn btn-sm btn-danger" onclick="confirmDelete(<?php echo e($holiday->id); ?>, '<?php echo e($holiday->description); ?>')"><i class="fas fa-trash"></i></button>
                            </div>
                        </td>
                    </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                    <tr>
                        <td colspan="5" class="text-center text-muted py-4">
                            <i class="fas fa-calendar-alt fa-3x mb-3"></i>
                            <p><?php echo e(request('search') ? 'Tidak ditemukan hari libur' : 'Belum ada hari libur yang ditetapkan'); ?></p>
                        </td>
                    </tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
        
        <?php if($holidays->hasPages()): ?>
            <?php echo e($holidays->appends(request()->query())->links('pagination::bootstrap-4')); ?>

        <?php endif; ?>
    </div>
</div>

<!-- Add Holiday Modal -->
<div class="modal fade" id="addHolidayModal" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">Tambah Hari Libur</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>
            <form method="POST" action="<?php echo e(route('admin.create.holiday')); ?>">
                <?php echo csrf_field(); ?>
                <div class="modal-body">
                    <div class="mb-3">
                        <label class="form-label">Tanggal <span class="text-danger">*</span></label>
                        <input type="date" name="date" class="form-control" value="<?php echo e(old('date')); ?>" required>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Deskripsi <span class="text-danger">*</span></label>
                        <input type="text" name="description" class="form-control" 
                               placeholder="Contoh: Hari Kemerdekaan RI" 
                               value="<?php echo e(old('description')); ?>" required>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Batal</button>
                    <button type="submit" class="btn btn-primary">Simpan</button>
                </div>
            </form>
        </div>
    </div>
</div>

<!-- Edit Holiday Modal -->
<div class="modal fade" id="editHolidayModal" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">Edit Hari Libur</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>
            <form id="editHolidayForm" method="POST">
                <?php echo csrf_field(); ?> <?php echo method_field('PUT'); ?>
                <div class="modal-body">
                    <div class="mb-3">
                        <label class="form-label">Tanggal <span class="text-danger">*</span></label>
                        <input type="date" name="date" id="edit_date" class="form-control" required>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Deskripsi <span class="text-danger">*</span></label>
                        <input type="text" name="description" id="edit_description" class="form-control" required>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Batal</button>
                    <button type="submit" class="btn btn-warning">Update</button>
                </div>
            </form>
        </div>
    </div>
</div>

<!-- Delete Confirmation Modal -->
<div class="modal fade" id="deleteModal" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">Konfirmasi Hapus</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>
            <div class="modal-body">
                <p>Apakah Anda yakin ingin menghapus hari libur <strong id="deleteName"></strong>?</p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Batal</button>
                <form id="deleteForm" method="POST" class="d-inline">
                    <?php echo csrf_field(); ?> <?php echo method_field('DELETE'); ?>
                    <button type="submit" class="btn btn-danger">Hapus</button>
                </form>
            </div>
        </div>
    </div>
</div>

<?php if($errors->any()): ?>
<script>
document.addEventListener('DOMContentLoaded', function() {
    new bootstrap.Modal(document.getElementById('addHolidayModal')).show();
});
</script>
<?php endif; ?>

<script>
function editHoliday(id, date, description) {
    document.getElementById('edit_date').value = date;
    document.getElementById('edit_description').value = description;
    document.getElementById('editHolidayForm').action = `<?php echo e(url('admin/holiday')); ?>/${id}/update`;
    new bootstrap.Modal(document.getElementById('editHolidayModal')).show();
}

function confirmDelete(id, description) {
    document.getElementById('deleteName').textContent = description;
    document.getElementById('deleteForm').action = `<?php echo e(url('admin/holiday')); ?>/${id}/delete`;
    new bootstrap.Modal(document.getElementById('deleteModal')).show();
}
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\laragon\www\presensi-magang\resources\views/admin/holidays.blade.php ENDPATH**/ ?>