

<?php $__env->startSection('header-title', 'Modül Yönetimi'); ?>

<?php $__env->startSection('content'); ?>
<style>
    .module-list { display: flex; flex-direction: column; gap: 10px; }
    .module-item {
        display: flex; align-items: center; gap: 12px;
        background: #fff;
        border: 1px solid #e2e8f0;
        border-radius: 10px;
        padding: 14px 16px;
        transition: all 0.2s;
    }
    .module-item.inactive { opacity: 0.55; background: #f8fafc; }

    .module-icon {
        width: 44px; height: 44px;
        border-radius: 10px;
        display: flex; align-items: center; justify-content: center;
        font-size: 22px;
        background: linear-gradient(135deg, rgba(59,130,246,0.1), rgba(139,92,246,0.1));
        flex-shrink: 0;
    }
    .module-info { flex: 1; min-width: 0; }
    .module-name { font-size: 14px; font-weight: 600; color: #0f172a; }
    .module-desc { font-size: 12px; color: #94a3b8; margin-top: 3px; }
    .route-badge { background: #dbeafe; color: #2563eb; font-size: 10px; font-weight: 600; padding: 3px 8px; border-radius: 6px; font-family: monospace; }

    .module-controls { display: flex; align-items: center; gap: 20px; flex-shrink: 0; }
    .control-group { display: flex; flex-direction: column; align-items: center; gap: 4px; }
    .control-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: #94a3b8; }
    .control-status { font-size: 11px; font-weight: 600; }
    .status-on { color: #16a34a; }
    .status-off { color: #94a3b8; }
    .status-maint { color: #d97706; }

    /* ─── Toggle Button ─── */
    .toggle-btn {
        position: relative;
        display: inline-flex;
        align-items: center;
        width: 48px;
        height: 28px;
        border-radius: 14px;
        border: none;
        cursor: pointer;
        transition: background 0.25s;
        flex-shrink: 0;
        padding: 0;
        outline: none;
        background: #cbd5e1;
    }
    .toggle-btn.active { background: #22c55e; }
    .toggle-btn.maintenance { background: #f59e0b; }
    .toggle-btn.loading { opacity: 0.6; cursor: not-allowed; }
    .toggle-knob {
        position: absolute;
        left: 4px;
        width: 20px;
        height: 20px;
        border-radius: 50%;
        background: white;
        box-shadow: 0 1px 3px rgba(0,0,0,0.3);
        transition: transform 0.25s;
        pointer-events: none;
    }
    .toggle-btn.active .toggle-knob,
    .toggle-btn.maintenance .toggle-knob { transform: translateX(20px); }

    .info-box {
        background: linear-gradient(135deg, #eff6ff, #f0fdf4);
        border: 1px solid #bfdbfe;
        border-radius: 10px;
        padding: 12px 16px;
        margin-bottom: 16px;
        display: flex;
        align-items: flex-start;
        gap: 10px;
        font-size: 13px;
        color: #1e40af;
    }
</style>

<div class="page-header">
    <div>
        <h1 class="page-title">📦 Modül Yönetimi</h1>
        <p class="page-subtitle">Platform modüllerini aktif/pasif yapın ve bakım modunu yönetin</p>
    </div>
    <div class="page-actions">
        <a href="<?php echo e(route('admin.homepage.index')); ?>" class="btn btn-secondary">🏠 Widgetlar</a>
    </div>
</div>

<div class="info-box">
    <span style="font-size: 16px;">ℹ️</span>
    <div>
        <strong>Nasıl Çalışır?</strong> — <strong>Aktif</strong> modülü tamamen açar/kapatır. <strong>Bakım Modu</strong> ise modülü geçici olarak kapatır.
    </div>
</div>

<div class="card">
    <div class="card-header">
        <div>
            <h3 class="card-title">Tüm Modüller (<?php echo e($modules->count()); ?>)</h3>
            <p class="card-subtitle">Değişiklikler otomatik kaydedilir</p>
        </div>
    </div>
    <div class="card-body" style="padding: 14px;">
        <div class="module-list">
            <?php $__currentLoopData = $modules; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $module): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <div class="module-item <?php echo e($module->is_active ? '' : 'inactive'); ?>" id="module-<?php echo e($module->id); ?>">
                <div class="module-icon"><?php echo e($module->icon); ?></div>
                <div class="module-info">
                    <div class="module-name"><?php echo e($module->label); ?></div>
                    <div class="module-desc"><?php echo e($module->description); ?></div>
                    <?php if($module->route_name): ?>
                        <span class="route-badge"><?php echo e($module->route_name); ?></span>
                    <?php endif; ?>
                </div>

                <div class="module-controls">
                    
                    <div class="control-group">
                        <button type="button"
                                class="toggle-btn <?php echo e($module->is_active ? 'active' : ''); ?>"
                                data-id="<?php echo e($module->id); ?>"
                                data-active="<?php echo e($module->is_active ? '1' : '0'); ?>"
                                onclick="toggleModuleActive(this)"
                                title="<?php echo e($module->is_active ? 'Aktif — Tıkla kapat' : 'Pasif — Tıkla aç'); ?>">
                            <span class="toggle-knob"></span>
                        </button>
                        <span class="control-label">Aktif</span>
                        <span class="control-status status-<?php echo e($module->is_active ? 'on' : 'off'); ?>" id="active-status-<?php echo e($module->id); ?>">
                            <?php echo e($module->is_active ? '✓ AÇIK' : '✕ KAPALI'); ?>

                        </span>
                    </div>

                    
                    <div class="control-group">
                        <button type="button"
                                class="toggle-btn <?php echo e($module->is_maintenance ? 'maintenance' : ''); ?>"
                                data-id="<?php echo e($module->id); ?>"
                                data-maintenance="<?php echo e($module->is_maintenance ? '1' : '0'); ?>"
                                onclick="toggleModuleMaintenance(this)"
                                title="<?php echo e($module->is_maintenance ? 'Bakımda — Tıkla normal' : 'Normal — Tıkla bakım'); ?>">
                            <span class="toggle-knob"></span>
                        </button>
                        <span class="control-label">Bakım</span>
                        <span class="control-status status-<?php echo e($module->is_maintenance ? 'maint' : 'off'); ?>" id="maint-status-<?php echo e($module->id); ?>">
                            <?php echo e($module->is_maintenance ? '⚠ BAKIM' : '✓ NORMAL'); ?>

                        </span>
                    </div>
                </div>
            </div>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </div>
    </div>
</div>

<script>
var CSRF_TOKEN = '<?php echo e(csrf_token()); ?>';
var BASE_URL = '<?php echo e(url('')); ?>';

function toggleModuleActive(btn) {
    if (btn.classList.contains('loading')) return;

    var id = btn.getAttribute('data-id');
    var isActive = btn.getAttribute('data-active') === '1';
    var item = document.getElementById('module-' + id);
    var status = document.getElementById('active-status-' + id);

    btn.classList.add('loading');

    fetch(BASE_URL + '/admin/modules/' + id + '/toggle-active', {
        method: 'POST',
        headers: {
            'X-CSRF-TOKEN': CSRF_TOKEN,
            'Accept': 'application/json',
            'Content-Type': 'application/json'
        }
    })
    .then(function(r) {
        if (!r.ok) throw new Error('HTTP ' + r.status);
        return r.json();
    })
    .then(function(data) {
        var nowActive = data.is_active ? true : false;
        btn.setAttribute('data-active', nowActive ? '1' : '0');
        btn.title = nowActive ? 'Aktif — Tıkla kapat' : 'Pasif — Tıkla aç';

        if (nowActive) {
            btn.classList.add('active');
            item.classList.remove('inactive');
            status.className = 'control-status status-on';
            status.textContent = '✓ AÇIK';
        } else {
            btn.classList.remove('active');
            item.classList.add('inactive');
            status.className = 'control-status status-off';
            status.textContent = '✕ KAPALI';
        }
        showToast(data.message || (nowActive ? 'Modül aktif edildi' : 'Modül pasif edildi'), 'success');
    })
    .catch(function(err) {
        showToast('Hata: ' + err.message, 'error');
    })
    .finally(function() {
        btn.classList.remove('loading');
    });
}

function toggleModuleMaintenance(btn) {
    if (btn.classList.contains('loading')) return;

    var id = btn.getAttribute('data-id');
    var isMaint = btn.getAttribute('data-maintenance') === '1';
    var status = document.getElementById('maint-status-' + id);

    btn.classList.add('loading');

    fetch(BASE_URL + '/admin/modules/' + id + '/toggle-maintenance', {
        method: 'POST',
        headers: {
            'X-CSRF-TOKEN': CSRF_TOKEN,
            'Accept': 'application/json',
            'Content-Type': 'application/json'
        }
    })
    .then(function(r) {
        if (!r.ok) throw new Error('HTTP ' + r.status);
        return r.json();
    })
    .then(function(data) {
        var nowMaint = data.is_maintenance ? true : false;
        btn.setAttribute('data-maintenance', nowMaint ? '1' : '0');
        btn.title = nowMaint ? 'Bakımda — Tıkla normal' : 'Normal — Tıkla bakım';

        if (nowMaint) {
            btn.classList.add('maintenance');
            status.className = 'control-status status-maint';
            status.textContent = '⚠ BAKIM';
        } else {
            btn.classList.remove('maintenance');
            status.className = 'control-status status-off';
            status.textContent = '✓ NORMAL';
        }
        showToast(data.message || (nowMaint ? 'Bakım modu açıldı' : 'Bakım modu kapatıldı'), 'success');
    })
    .catch(function(err) {
        showToast('Hata: ' + err.message, 'error');
    })
    .finally(function() {
        btn.classList.remove('loading');
    });
}
</script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('admin.layout', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\xampp\htdocs\askeribilgiler\resources\views\admin\modules\index.blade.php ENDPATH**/ ?>