<?php $__env->startSection('title', 'Personeller'); ?>

<?php $__env->startSection('page_title', 'Personeller'); ?>

<?php
    $breadcrumbs = [
        ['title' => 'Dashboard', 'url' => route('agency.dashboard')],
        ['title' => 'Personel ve Yetki', 'url' => '#'],
        ['title' => 'Personeller', 'url' => '']
    ];
?>

<?php $__env->startSection('content'); ?>
    <div class="container-fluid">
        <!-- Header Actions -->
        <div class="d-flex justify-content-between align-items-center mb-4">
            <div>
                <h2 class="h4 mb-1">Personeller</h2>
                <p class="text-muted mb-0">Acentenizde görev yapan personel listesi</p>
            </div>
            <div>
                <a href="<?php echo e(route('agency.staff-management.staff.create')); ?>" class="btn btn-primary">
                    <i class="fas fa-plus me-2"></i>Yeni Personel Ekle
                </a>
            </div>
        </div>

        <?php if(session('success')): ?>
            <div class="alert alert-success alert-dismissible fade show" role="alert">
                <i class="fas fa-check-circle me-2"></i>
                <?php echo e(session('success')); ?>

                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
            </div>
        <?php endif; ?>

        <?php if(isset($invitations) && $invitations->isNotEmpty()): ?>
            <div class="card shadow-sm border-0 mb-4 border-warning border-start border-4">
                <div class="card-header bg-white py-3">
                    <h5 class="mb-0 fw-bold text-warning"><i class="fas fa-hourglass-half me-2"></i>Bekleyen Davetler</h5>
                </div>
                <div class="card-body p-0">
                    <div class="table-responsive">
                        <table class="table table-hover align-middle mb-0">
                            <thead class="bg-light text-muted small text-uppercase">
                                <tr>
                                    <th class="px-4 py-3">E-Posta Adresi</th>
                                    <th class="px-4 py-3">Önerilen Rol</th>
                                    <th class="px-4 py-3">Davet Tarihi</th>
                                    <th class="px-4 py-3 text-end">İşlemler</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php $__currentLoopData = $invitations; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $invitation): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <tr>
                                        <td class="px-4 py-3">
                                            <span class="fw-bold"><?php echo e($invitation->email); ?></span>
                                        </td>
                                        <td class="px-4 py-3">
                                            <span class="badge bg-light text-dark border"><?php echo e($invitation->role->ui_name); ?></span>
                                            <?php if($invitation->position): ?>
                                                <small class="text-muted d-block mt-1"><?php echo e($invitation->position); ?></small>
                                            <?php endif; ?>
                                        </td>
                                        <td class="px-4 py-3 small text-muted">
                                            <?php echo e($invitation->created_at->format('d.m.Y H:i')); ?>

                                        </td>
                                        <td class="px-4 py-3 text-end">
                                            <form action="<?php echo e(route('agency.staff-management.staff.cancel-invitation', $invitation->id)); ?>" method="POST" class="d-inline cancel-invitation-form">
                                                <?php echo csrf_field(); ?>
                                                <?php echo method_field('DELETE'); ?>
                                                <button type="submit" class="btn btn-sm btn-outline-danger" title="Daveti İptal Et">
                                                    <i class="fas fa-times"></i> İptal
                                                </button>
                                            </form>
                                        </td>
                                    </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        <?php endif; ?>

        <div class="card shadow-sm border-0">
            <div class="card-body p-0">
                <div class="table-responsive">
                    <table class="table table-hover align-middle mb-0">
                        <thead class="bg-light text-muted small text-uppercase">
                            <tr>
                                <th class="px-4 py-3">Ad Soyad</th>
                                <th class="px-4 py-3">Pozisyon / Rol</th>
                                <th class="px-4 py-3">İletişim</th>
                                <th class="px-4 py-3">İşe Giriş</th>
                                <th class="px-4 py-3">Durum</th>
                                <th class="px-4 py-3 text-end">İşlemler</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php $__empty_1 = true; $__currentLoopData = $staffMembers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $staff): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                
                                <tr data-quickview-url="<?php echo e(route('agency.staff-management.staff.quick-view', $staff->id)); ?>" style="cursor: pointer;">
                                    <td class="px-4 py-3">
                                        <div class="d-flex align-items-center">
                                            <div class="avatar-sm bg-primary-soft text-primary rounded-circle d-flex align-items-center justify-content-center me-3" style="width: 40px; height: 40px; background-color: #f1f5f9; color: #3b82f6;">
                                                <i class="fas fa-user"></i>
                                            </div>
                                            <div>
                                                <span class="fw-bold d-block"><?php echo e($staff->getFullNameAttribute()); ?></span>
                                                <small class="text-muted"><?php echo e($staff->email); ?></small>
                                            </div>
                                        </div>
                                    </td>
                                    <td class="px-4 py-3">
                                        <span class="d-block small fw-medium"><?php echo e($staff->position ?? '-'); ?></span>
                                        <?php if($staff->user): ?>
                                            <?php $__currentLoopData = $staff->user->roles; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $role): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <span class="badge bg-light text-dark border" style="font-size: 10px;"><?php echo e($role->ui_name); ?></span>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        <?php else: ?>
                                            <span class="badge bg-warning text-dark border" style="font-size: 10px;">Kullanıcı Hesabı Yok</span>
                                        <?php endif; ?>
                                    </td>
                                    <td class="px-4 py-3 small">
                                        <div class="d-flex flex-column">
                                            <span><i class="fas fa-phone-alt me-1 opacity-50"></i> <?php echo e($staff->phone ?? '-'); ?></span>
                                        </div>
                                    </td>
                                    <td class="px-4 py-3 small text-muted">
                                        <?php echo e($staff->hired_at ? $staff->hired_at->format('d.m.Y') : '-'); ?>

                                    </td>
                                    <td class="px-4 py-3">
                                        <span class="badge <?php echo e($staff->is_active ? 'bg-success' : 'bg-danger'); ?>">
                                            <?php echo e($staff->is_active ? 'Aktif' : 'Pasif'); ?>

                                        </span>
                                    </td>
                                    <td class="px-4 py-3 text-end">
                                        <div class="btn-group">
                                            <button type="button" class="btn btn-sm btn-outline-primary" title="Özlük Kartı"
                                                    onclick="openQuickView('<?php echo e(route('agency.staff-management.staff.quick-view', $staff->id)); ?>')">
                                                <i class="fas fa-id-card"></i>
                                            </button>
                                            <a href="<?php echo e(route('agency.staff-management.staff.edit', $staff->id)); ?>" class="btn btn-sm btn-outline-secondary" title="Düzenle">
                                                <i class="fas fa-edit"></i>
                                            </a>
                                            <?php if(!$staff->is_agency_owner): ?>
                                                <form action="<?php echo e(route('agency.staff-management.staff.destroy', $staff->id)); ?>" method="POST" class="d-inline delete-form">
                                                    <?php echo csrf_field(); ?>
                                                    <?php echo method_field('DELETE'); ?>
                                                    <button type="submit" class="btn btn-sm btn-outline-danger" title="Sil">
                                                        <i class="fas fa-trash"></i>
                                                    </button>
                                                </form>
                                            <?php endif; ?>
                                        </div>
                                    </td>
                                </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                <tr>
                                    <td colspan="6" class="text-center py-5 text-muted">
                                        <div class="mb-3">
                                            <i class="fas fa-users-cog fa-3x opacity-20"></i>
                                        </div>
                                        <h5>Henüz personel eklenmemiş</h5>
                                        <p>Acentenizde çalışacak personelleri buradan yönetebilirsiniz.</p>
                                        <a href="<?php echo e(route('agency.staff-management.staff.create')); ?>" class="btn btn-primary mt-2">
                                            <i class="fas fa-plus me-2"></i>İlk Personeli Ekle
                                        </a>
                                    </td>
                                </tr>
                            <?php endif; ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>
    <script>
        document.addEventListener('DOMContentLoaded', function () {
            document.querySelectorAll('.delete-form').forEach(form => {
                form.addEventListener('submit', function (e) {
                    e.preventDefault();
                    if (confirm('Bu personeli silmek istediğinize emin misiniz? Bu işlem personelin bu acentedeki tüm yetkilerini kaldıracaktır.')) {
                        this.submit();
                    }
                });
            });

            document.querySelectorAll('.cancel-invitation-form').forEach(form => {
                form.addEventListener('submit', function (e) {
                    e.preventDefault();
                    if (confirm('Bu daveti iptal etmek istediğinize emin misiniz?')) {
                        this.submit();
                    }
                });
            });
        });
    </script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('agency.layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\xampp\htdocs\acente\resources\views/agency/staff-management/staff/index.blade.php ENDPATH**/ ?>