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

<?php $__env->startSection('page_title', 'Yetkilendirme (Rol Yönetimi)'); ?>

<?php
    $breadcrumbs = [
        ['title' => 'Dashboard', 'url' => route('agency.dashboard')],
        ['title' => 'Personel ve Yetki', 'url' => '#'],
        ['title' => 'Yetkilendirme', '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">Roller</h2>
                <p class="text-muted mb-0">Personelleriniz için yetki gruplarını yönetin</p>
            </div>
            <div>
                <a href="<?php echo e(route('agency.staff-management.roles.create')); ?>" class="btn btn-primary">
                    <i class="fas fa-plus me-2"></i>Yeni Rol Oluştur
                </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(session('error')): ?>
            <div class="alert alert-danger alert-dismissible fade show" role="alert">
                <i class="fas fa-exclamation-circle me-2"></i>
                <?php echo e(session('error')); ?>

                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
            </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">Rol Adı</th>
                                <th class="px-4 py-3">Sistem Adı</th>
                                <th class="px-4 py-3">Açıklama</th>
                                <th class="px-4 py-3">Yetki Sayısı</th>
                                <th class="px-4 py-3 text-end">İşlemler</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php $__empty_1 = true; $__currentLoopData = $roles; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $role): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                <tr>
                                    <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: rgba(37, 99, 235, 0.1);">
                                                <i class="fas fa-key"></i>
                                            </div>
                                            <div>
                                                <span class="fw-bold"><?php echo e($role->ui_name); ?></span>
                                                <?php if($role->agency_id === null): ?>
                                                    <span class="badge bg-secondary-soft text-secondary ms-1" style="font-size: 10px; background-color: #f1f5f9; color: #64748b;">SİSTEM</span>
                                                <?php endif; ?>
                                            </div>
                                        </div>
                                    </td>
                                    <td class="px-4 py-3">
                                        <code><?php echo e($role->name); ?></code>
                                    </td>
                                    <td class="px-4 py-3 text-muted small">
                                        <?php echo e(Str::limit($role->description ?? '-', 50)); ?>

                                    </td>
                                    <td class="px-4 py-3">
                                        <span class="badge bg-info-soft text-info" style="background-color: rgba(14, 165, 233, 0.1); color: #0ea5e9;">
                                            <?php echo e($role->permissions->count()); ?> Yetki
                                        </span>
                                    </td>
                                    <td class="px-4 py-3 text-end">
                                        <div class="btn-group">
                                            <a href="<?php echo e(route('agency.staff-management.roles.edit', $role)); ?>" class="btn btn-sm btn-outline-secondary" title="<?php echo e($role->agency_id === null ? 'Görüntüle' : 'Düzenle'); ?>">
                                                <i class="fas fa-<?php echo e($role->agency_id === null ? 'eye' : 'edit'); ?>"></i>
                                            </a>
                                            <?php if($role->agency_id !== null && !$role->is_system): ?>
                                                <form action="<?php echo e(route('agency.staff-management.roles.destroy', $role)); ?>" 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="5" class="text-center py-5 text-muted">
                                        <div class="mb-3">
                                            <i class="fas fa-shield-alt fa-3x opacity-20"></i>
                                        </div>
                                        <h5>Henüz rol oluşturulmamış</h5>
                                        <p>Personellerinize atayabileceğiniz yetki grupları oluşturun.</p>
                                        <a href="<?php echo e(route('agency.staff-management.roles.create')); ?>" class="btn btn-primary mt-2">
                                            <i class="fas fa-plus me-2"></i>İlk Rolü Oluştur
                                        </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 rolü silmek istediğinize emin misiniz? Bu rolü kullanan personeller yetkisiz kalabilir.')) {
                        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 /home/mehmetguruz/public_html/test/resources/views/agency/staff-management/roles/index.blade.php ENDPATH**/ ?>