<?php $__env->startSection('title', 'Ürün Kategorileri'); ?>
<?php $__env->startSection('page_title', 'Ürün Kategorileri'); ?>

<?php
    $breadcrumbs = [
        ['title' => 'Ana Sayfa', 'url' => route('agency.dashboard')],
        ['title' => 'Hizmet Türleri', 'url' => route('agency.product-types.index')],
        ['title' => 'Kategoriler', 'url' => '']
    ];
?>

<?php $__env->startPush('styles'); ?>
    <style>
        .category-card {
            border: 1px solid var(--gray-200);
            border-radius: var(--radius-lg);
            background: white;
            transition: all 0.3s ease;
        }

        .category-card:hover {
            box-shadow: var(--shadow-md);
            border-color: var(--primary-color);
        }

        .category-header {
            padding: 1rem 1.5rem;
            border-bottom: 1px solid var(--gray-200);
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .category-icon {
            width: 40px;
            height: 40px;
            border-radius: var(--radius-md);
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 18px;
            margin-right: 1rem;
        }

        .category-level-0 {
            background: linear-gradient(135deg, var(--primary-color), #667eea);
            color: white;
        }

        .category-level-1 {
            background: linear-gradient(135deg, var(--success-color), #10b981);
            color: white;
        }

        .category-info {
            flex: 1;
        }

        .category-name {
            font-size: 16px;
            font-weight: 600;
            color: var(--gray-900);
            margin-bottom: 4px;
        }

        .category-description {
            font-size: 13px;
            color: var(--gray-600);
            margin: 0;
        }

        .category-badge {
            padding: 4px 10px;
            border-radius: var(--radius-md);
            font-size: 11px;
            font-weight: 600;
            text-transform: uppercase;
        }

        .badge-active {
            background: #d1fae5;
            color: #065f46;
        }

        .badge-inactive {
            background: var(--gray-100);
            color: var(--gray-600);
        }

        .badge-parent {
            background: #dbeafe;
            color: #1e40af;
        }

        .badge-child {
            background: #fef3c7;
            color: #92400e;
        }

        .subcategory-list {
            padding: 0.5rem 1.5rem 1rem 4rem;
        }

        .subcategory-item {
            padding: 0.75rem;
            border-left: 3px solid var(--gray-200);
            margin-bottom: 0.5rem;
            background: var(--gray-50);
            border-radius: var(--radius-md);
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .subcategory-item:hover {
            border-left-color: var(--primary-color);
            background: var(--gray-100);
        }

        .filter-bar {
            background: white;
            border: 1px solid var(--gray-200);
            border-radius: var(--radius-lg);
            padding: 1.25rem;
            margin-bottom: 1.5rem;
        }

        .empty-state {
            text-align: center;
            padding: 3rem 1rem;
            background: white;
            border: 1px solid var(--gray-200);
            border-radius: var(--radius-lg);
        }

        .empty-state i {
            font-size: 48px;
            color: var(--gray-300);
            margin-bottom: 1rem;
        }

        .empty-state h4 {
            color: var(--gray-700);
            margin-bottom: 0.5rem;
        }

        .empty-state p {
            color: var(--gray-500);
            margin-bottom: 1.5rem;
        }
    </style>
<?php $__env->stopPush(); ?>

<?php $__env->startSection('content'); ?>
    <div class="container-fluid">
        <!-- Page Header -->
        <div class="d-flex justify-content-between align-items-center mb-4">
            <div>
                <h1 class="h3 mb-1">Ürün Kategorileri</h1>
                <p class="text-muted mb-0">Ürünlerinizi kategorilere ayırarak düzenleyin</p>
            </div>
            <div>
                <a href="<?php echo e(route('agency.categories.create')); ?>" class="btn btn-primary">
                    <i class="fas fa-plus me-2"></i>
                    Yeni Kategori Ekle
                </a>
            </div>
        </div>

        <!-- Filter Bar -->
        <div class="filter-bar">
            <form method="GET" action="<?php echo e(route('agency.categories.index')); ?>" class="row g-3">
                <div class="col-md-4">
                    <label class="form-label small fw-bold">Hizmet Türü</label>
                    <select name="product_type_id" class="form-select">
                        <option value="">Tümü</option>
                        <?php $__currentLoopData = $productTypes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $type): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($type->id); ?>" <?php echo e(request('product_type_id') == $type->id ? 'selected' : ''); ?>>
                                <?php echo e($type->name); ?>

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

                <div class="col-md-3">
                    <label class="form-label small fw-bold">Durum</label>
                    <select name="status" class="form-select">
                        <option value="">Tümü</option>
                        <option value="active" <?php echo e(request('status') === 'active' ? 'selected' : ''); ?>>Aktif</option>
                        <option value="inactive" <?php echo e(request('status') === 'inactive' ? 'selected' : ''); ?>>Pasif</option>
                    </select>
                </div>

                <div class="col-md-3">
                    <label class="form-label small fw-bold">Arama</label>
                    <input type="text" name="search" class="form-control" placeholder="Kategori ara..." value="<?php echo e(request('search')); ?>">
                </div>

                <div class="col-md-2 d-flex align-items-end">
                    <button type="submit" class="btn btn-primary w-100">
                        <i class="fas fa-filter me-2"></i>
                        Filtrele
                    </button>
                </div>
            </form>
        </div>

        <!-- Categories List -->
        <?php if($categories->count() > 0): ?>
            <div class="row g-3">
                <?php $__currentLoopData = $categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $category): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <?php if($category->parent_id === null): ?>
                        <!-- Ana Kategori -->
                        <div class="col-12">
                            <div class="category-card">
                                <div class="category-header">
                                    <div class="d-flex align-items-center flex-grow-1">
                                        <div class="category-icon category-level-0">
                                            <i class="fas <?php echo e($category->icon ?? 'fa-folder'); ?>"></i>
                                        </div>
                                        <div class="category-info">
                                            <div class="category-name"><?php echo e($category->name); ?></div>
                                            <?php if($category->short_description): ?>
                                                <p class="category-description"><?php echo e($category->short_description); ?></p>
                                            <?php endif; ?>
                                        </div>
                                    </div>
                                    <div class="d-flex align-items-center gap-2">
                                        <span class="category-badge <?php echo e($category->is_active ? 'badge-active' : 'badge-inactive'); ?>">
                                            <?php echo e($category->is_active ? 'Aktif' : 'Pasif'); ?>

                                        </span>
                                        <span class="category-badge badge-parent">
                                            Ana Kategori
                                        </span>
                                        <?php if($category->productType): ?>
                                            <span class="badge bg-info text-white">
                                                <?php echo e($category->productType->name); ?>

                                            </span>
                                        <?php endif; ?>

                                        <div class="btn-group">
                                            <button type="button" class="btn btn-sm btn-outline-primary dropdown-toggle" data-bs-toggle="dropdown">
                                                <i class="fas fa-ellipsis-v"></i>
                                            </button>
                                            <ul class="dropdown-menu dropdown-menu-end">
                                                <li>
                                                    <a class="dropdown-item" href="<?php echo e(route('agency.categories.edit', $category)); ?>">
                                                        <i class="fas fa-edit me-2"></i> Düzenle
                                                    </a>
                                                </li>
                                                <li>
                                                    <form action="<?php echo e(route('agency.categories.toggle-status', $category)); ?>" method="POST" class="d-inline toggle-status-form">
                                                        <?php echo csrf_field(); ?>
                                                        <button type="submit" class="dropdown-item">
                                                            <i class="fas fa-toggle-<?php echo e($category->is_active ? 'off' : 'on'); ?> me-2"></i>
                                                            <?php echo e($category->is_active ? 'Pasif Et' : 'Aktif Et'); ?>

                                                        </button>
                                                    </form>
                                                </li>
                                                <li><hr class="dropdown-divider"></li>
                                                <li>
                                                    <form action="<?php echo e(route('agency.categories.destroy', $category)); ?>" method="POST" class="d-inline delete-form">
                                                        <?php echo csrf_field(); ?>
                                                        <?php echo method_field('DELETE'); ?>
                                                        <button type="submit" class="dropdown-item text-danger">
                                                            <i class="fas fa-trash me-2"></i> Sil
                                                        </button>
                                                    </form>
                                                </li>
                                            </ul>
                                        </div>
                                    </div>
                                </div>

                                <!-- Alt Kategoriler -->
                                <?php
                                    $subcategories = $category->children()->get();
                                ?>
                                <?php if($subcategories->count() > 0): ?>
                                    <div class="subcategory-list">
                                        <h6 class="text-muted mb-2" style="font-size: 12px; text-transform: uppercase; font-weight: 700;">
                                            Alt Kategoriler (<?php echo e($subcategories->count()); ?>)
                                        </h6>
                                        <?php $__currentLoopData = $subcategories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $subcategory): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <div class="subcategory-item">
                                                <div class="d-flex align-items-center">
                                                    <div class="category-icon category-level-1" style="width: 32px; height: 32px; font-size: 14px;">
                                                        <i class="fas <?php echo e($subcategory->icon ?? 'fa-folder'); ?>"></i>
                                                    </div>
                                                    <div>
                                                        <div style="font-weight: 600; font-size: 14px;"><?php echo e($subcategory->name); ?></div>
                                                        <?php if($subcategory->short_description): ?>
                                                            <div style="font-size: 12px; color: var(--gray-600);"><?php echo e($subcategory->short_description); ?></div>
                                                        <?php endif; ?>
                                                    </div>
                                                </div>
                                                <div class="d-flex align-items-center gap-2">
                                                    <span class="category-badge <?php echo e($subcategory->is_active ? 'badge-active' : 'badge-inactive'); ?>">
                                                        <?php echo e($subcategory->is_active ? 'Aktif' : 'Pasif'); ?>

                                                    </span>
                                                    <div class="btn-group">
                                                        <button type="button" class="btn btn-sm btn-outline-primary dropdown-toggle" data-bs-toggle="dropdown">
                                                            <i class="fas fa-ellipsis-v"></i>
                                                        </button>
                                                        <ul class="dropdown-menu dropdown-menu-end">
                                                            <li>
                                                                <a class="dropdown-item" href="<?php echo e(route('agency.categories.edit', $subcategory)); ?>">
                                                                    <i class="fas fa-edit me-2"></i> Düzenle
                                                                </a>
                                                            </li>
                                                            <li>
                                                                <form action="<?php echo e(route('agency.categories.toggle-status', $subcategory)); ?>" method="POST" class="d-inline toggle-status-form">
                                                                    <?php echo csrf_field(); ?>
                                                                    <button type="submit" class="dropdown-item">
                                                                        <i class="fas fa-toggle-<?php echo e($subcategory->is_active ? 'off' : 'on'); ?> me-2"></i>
                                                                        <?php echo e($subcategory->is_active ? 'Pasif Et' : 'Aktif Et'); ?>

                                                                    </button>
                                                                </form>
                                                            </li>
                                                            <li><hr class="dropdown-divider"></li>
                                                            <li>
                                                                <form action="<?php echo e(route('agency.categories.destroy', $subcategory)); ?>" method="POST" class="d-inline delete-form">
                                                                    <?php echo csrf_field(); ?>
                                                                    <?php echo method_field('DELETE'); ?>
                                                                    <button type="submit" class="dropdown-item text-danger">
                                                                        <i class="fas fa-trash me-2"></i> Sil
                                                                    </button>
                                                                </form>
                                                            </li>
                                                        </ul>
                                                    </div>
                                                </div>
                                            </div>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </div>
                                <?php endif; ?>
                            </div>
                        </div>
                    <?php endif; ?>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </div>

            <!-- Pagination -->
            <?php if($categories->hasPages()): ?>
                <div class="mt-4 d-flex justify-content-center">
                    <?php echo e($categories->links()); ?>

                </div>
            <?php endif; ?>
        <?php else: ?>
            <div class="empty-state">
                <i class="fas fa-folder-open"></i>
                <h4>Henüz Kategori Eklenmemiş</h4>
                <p>Bu hizmet türü için henüz kategori oluşturulmamış.</p>
                <a href="<?php echo e(route('agency.categories.create')); ?>" class="btn btn-primary">
                    <i class="fas fa-plus me-2"></i>
                    İlk Kategoriyi Oluştur
                </a>
            </div>
        <?php endif; ?>
    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // Toggle status forms
            document.querySelectorAll('.toggle-status-form').forEach(form => {
                form.addEventListener('submit', async function(e) {
                    e.preventDefault();

                    try {
                        const response = await fetch(this.action, {
                            method: 'POST',
                            headers: {
                                'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content,
                                'Accept': 'application/json',
                                'Content-Type': 'application/json'
                            }
                        });

                        const data = await response.json();

                        if (data.success) {
                            location.reload();
                        } else {
                            alert(data.message || 'Bir hata oluştu');
                        }
                    } catch (error) {
                        console.error('Error:', error);
                        alert('Bir hata oluştu');
                    }
                });
            });

            // Delete forms
            document.querySelectorAll('.delete-form').forEach(form => {
                form.addEventListener('submit', function(e) {
                    if (!confirm('Bu kategoriyi silmek istediğinizden emin misiniz?')) {
                        e.preventDefault();
                    }
                });
            });
        });
    </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/categories/index.blade.php ENDPATH**/ ?>