<?php $__env->startSection('title', 'Kullanıcı Yönetimi'); ?>
<?php $__env->startSection('header_title', 'Kullanıcı Yönetimi'); ?>
<?php $__env->startSection('header_subtitle', 'Sistemdeki müşteri hesaplarını görüntüleyin, yetkilendirin veya silin.'); ?>

<?php $__env->startSection('content'); ?>
<?php if(session('error')): ?>
    <div class="alert alert-danger" style="background-color: rgba(255, 23, 68, 0.08); border-color: var(--danger); color: var(--danger); margin-bottom: 1.5rem; padding: 1rem; border-radius: var(--radius-sm);">
        <?php echo e(session('error')); ?>

    </div>
<?php endif; ?>

<div class="card">
    <div class="card-title">Kayıtlı Kullanıcılar</div>
    
    <div class="table-responsive">
        <table class="table">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>Ad Soyad</th>
                    <th>E-posta</th>
                    <th>Rol / Yetki</th>
                    <th>Firma / Grup</th>
                    <th>Kayıt Tarihi</th>
                    <th style="width: 250px;">İşlemler</th>
                </tr>
            </thead>
            <tbody>
                <?php $__currentLoopData = $users; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $u): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <tr>
                        <td>#<?php echo e($u->id); ?></td>
                        <td>
                            <strong><?php echo e($u->name); ?></strong>
                            <?php if($u->id === auth()->id()): ?>
                                <span style="font-size: 0.75rem; opacity: 0.6; font-style: italic;">(Siz)</span>
                            <?php endif; ?>
                        </td>
                        <td><?php echo e($u->email); ?></td>
                        <td>
                            <?php if($u->role === 'admin'): ?>
                                <span class="badge badge-completed">Yönetici</span>
                            <?php else: ?>
                                <span class="badge badge-pending">Müşteri</span>
                            <?php endif; ?>
                        </td>
                        <td>
                            <?php if($u->id !== auth()->id()): ?>
                                <form action="<?php echo e(route('users.assign-organization', $u->id)); ?>" method="POST" style="display: inline-block; margin: 0; vertical-align: middle; width: 100%;">
                                    <?php echo csrf_field(); ?>
                                    <select name="organization_id" class="form-select native-select" onchange="this.form.submit()" style="padding: 0.45rem 1.8rem 0.45rem 0.75rem; font-size: 0.85rem; width: 100%; min-width: 160px; border-radius: 6px; background-color: var(--bg-card); border: 1.5px solid var(--border-color); color: var(--text-primary); cursor: pointer; -webkit-appearance: none; -moz-appearance: none; appearance: none; background-image: url('data:image/svg+xml;utf8,<svg xmlns=%22http://www.w3.org/2000/svg%22 width=%2212%22 height=%2212%22 viewBox=%220 0 24 24%22 fill=%22none%22 stroke=%22%235da46b%22 stroke-width=%222%22 stroke-linecap=%22round%22 stroke-linejoin=%22round%22><polyline points=%226 9 12 15 18 9%22></polyline></svg>'); background-repeat: no-repeat; background-position: right 10px center; background-size: 12px; line-height: normal; display: block;">
                                        <option value="">Firma Yok (Kişisel)</option>
                                        <?php $__currentLoopData = $organizations; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $org): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <option value="<?php echo e($org->id); ?>" <?php echo e($u->organization_id == $org->id ? 'selected' : ''); ?>>
                                                <?php echo e($org->name); ?>

                                            </option>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </select>
                                </form>
                            <?php else: ?>
                                <strong><?php echo e($u->organization ? $u->organization->name : 'Firma Yok'); ?></strong>
                            <?php endif; ?>
                        </td>
                        <td><?php echo e($u->created_at->format('d.m.Y H:i')); ?></td>
                        <td>
                            <div style="display: flex; gap: 8px;">
                                <?php if($u->id !== auth()->id()): ?>
                                    <!-- Toggle Role -->
                                    <form action="<?php echo e(route('users.toggle', $u->id)); ?>" method="POST" style="display: inline;">
                                        <?php echo csrf_field(); ?>
                                        <button type="submit" class="btn btn-secondary btn-sm" style="display: inline-flex; align-items: center; gap: 4px;">
                                            <ion-icon name="swap-horizontal-outline"></ion-icon>
                                            Yetkiyi Değiştir
                                        </button>
                                    </form>
 
                                    <!-- Delete User -->
                                    <form action="<?php echo e(route('users.delete', $u->id)); ?>" method="POST" style="display: inline;" onsubmit="return confirm('Kullanıcıyı ve ilişkili tüm görevlerini silmek istediğinize emin misiniz?');">
                                        <?php echo csrf_field(); ?>
                                        <?php echo method_field('DELETE'); ?>
                                        <button type="submit" class="btn btn-danger btn-sm" style="display: inline-flex; align-items: center; gap: 4px;">
                                            <ion-icon name="trash-outline"></ion-icon>
                                            Sil
                                        </button>
                                    </form>
                                <?php else: ?>
                                    <span style="font-size: 0.85rem; color: var(--text-secondary); font-style: italic;">
                                        Kendi hesabınızı düzenleyemezsiniz.
                                    </span>
                                <?php endif; ?>
                            </div>
                        </td>
                    </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </tbody>
        </table>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.layout', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\Users\melih\Desktop\LEXALOG\resources\views/users.blade.php ENDPATH**/ ?>