<?php
    use App\Models\Product\ProductType;

    $agency = auth()->user()?->agency;
    $allProductTypes = ProductType::where('is_active', true)
        ->orderBy('sort_order')
        ->get();

    $agencyActiveProductTypeIds = $agency ? $agency->productTypes()
        ->where('agency_product_types.is_active', true)
        ->pluck('product_types.id')
        ->toArray() : [];

    $pendingResCount = \App\Models\Sale\Sale::byAgency(auth()->user()->currentAgencyId() ?? 0)
        ->byStatus('pending')
        ->count();
?>

<!-- Sidebar -->
<aside class="agency-sidebar" id="agencySidebar">
    <div class="sidebar-header">
        <div class="logo-container">
            <?php if($agency && $agency->logo): ?>
                <div class="logo-wrapper">
                    <img src="<?php echo e(asset('storage/' . $agency->logo)); ?>" alt="Logo" class="agency-logo">
                </div>
            <?php else: ?>
                <div class="logo-icon">
                    <i class="fas fa-building"></i>
                </div>
            <?php endif; ?>
            <div class="logo-text">
                <span class="logo-title"><?php echo e($agency?->name ?? 'Acente'); ?></span>
                <span class="logo-subtitle">Yönetim Paneli</span>
            </div>
        </div>
        <button class="sidebar-collapse-btn" id="sidebarCollapseBtn">
            <i class="fas fa-chevron-left"></i>
        </button>
    </div>

    <div class="sidebar-content">
        <!-- User Section -->
        <div class="user-profile-widget">
            <div class="user-avatar-container">
                <img src="https://ui-avatars.com/api/?name=<?php echo e(urlencode(auth()->user()->full_name)); ?>&background=2563eb&color=fff&bold=true"
                    alt="Avatar" class="user-avatar">
                <span class="status-badge pulse"></span>
            </div>
            <div class="user-info">
                <h6 class="user-name"><?php echo e(auth()->user()->full_name); ?></h6>
                <p class="user-role"><?php echo e(auth()->user()->position ?? 'Acente Sahibi'); ?></p>
            </div>
        </div>

        <!-- Navigation Menu -->
        <nav class="sidebar-nav">
            <div class="nav-section-label">Ana Menü</div>
            <ul class="nav-list">
                <li class="nav-item">
                    <a href="<?php echo e(route('agency.dashboard')); ?>"
                        class="nav-link <?php echo e(request()->routeIs('agency.dashboard') ? 'active' : ''); ?>">
                        <div class="nav-icon-wrapper">
                            <i class="fas fa-th-large"></i>
                        </div>
                        <span class="nav-text">Panel</span>
                    </a>
                </li>

                <!-- Site Yönetimi -->
                <li
                    class="nav-item has-dropdown <?php echo e(request()->is('agency/page*') || request()->is('agency/website*') ? 'open' : ''); ?>">
                    <a href="javascript:void(0)" class="nav-link">
                        <div class="nav-icon-wrapper">
                            <i class="fas fa-magic"></i>
                        </div>
                        <span class="nav-text">Site Yönetimi</span>
                        <i class="fas fa-chevron-right dropdown-arrow"></i>
                    </a>
                    <ul class="nav-dropdown">
                        <li>
                            <a href="<?php echo e(route('agency.page.index')); ?>" target="_blank" class="dropdown-link">
                                <i class="fas fa-edit"></i>
                                <span>Düzenle</span>
                            </a>
                        </li>
                        <li>
                            <a href="<?php echo e(route('agency.page.preview')); ?>" target="_blank" class="dropdown-link">
                                <i class="fas fa-external-link-alt"></i>
                                <span>Önizle</span>
                            </a>
                        </li>
                        <li>
                            <a href="<?php echo e(route('agency.website.settings')); ?>"
                                class="dropdown-link <?php echo e(request()->routeIs('agency.website.settings') ? 'active' : ''); ?>">
                                <i class="fas fa-sliders-h"></i>
                                <span>Site Ayarları</span>
                            </a>
                        </li>
                    </ul>
                </li>

                <!-- Ürün Yönetimi -->
                <li
                    class="nav-item has-dropdown <?php echo e(request()->is('agency/product*') || request()->is('agency/categories*') ? 'open' : ''); ?>">
                    <a href="javascript:void(0)" class="nav-link">
                        <div class="nav-icon-wrapper">
                            <i class="fas fa-box-open"></i>
                        </div>
                        <span class="nav-text">Ürün Yönetimi</span>
                        <i class="fas fa-chevron-right dropdown-arrow"></i>
                    </a>
                    <ul class="nav-dropdown">
                        <?php $__currentLoopData = $allProductTypes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $productType): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <?php
                                $isActive = in_array($productType->id, $agencyActiveProductTypeIds);
                                $routeSlug = $productType->route_slug;
                                $routeName = $isActive ? "agency.products.{$routeSlug}.index" : "agency.product-types.apply";
                            ?>
                            <li>
                                <a href="<?php echo e($isActive ? route($routeName) : route($routeName, $productType->slug)); ?>"
                                    class="dropdown-link <?php echo e($isActive && request()->is("agency/products/{$routeSlug}*") ? 'active' : ''); ?>">
                                    <i class="<?php echo e($productType->icon); ?> <?php echo e($isActive ? 'text-indigo' : 'text-muted'); ?>"></i>
                                    <span><?php echo e($productType->name); ?></span>
                                    <?php if(!$isActive): ?>
                                        <span class="badge-status inactive">Pasif</span>
                                    <?php endif; ?>
                                </a>
                            </li>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        <li class="dropdown-divider"></li>
                        <li>
                            <a href="<?php echo e(route('agency.product-types.index')); ?>"
                                class="dropdown-link <?php echo e(request()->routeIs('agency.product-types.index') ? 'active' : ''); ?>">
                                <i class="fas fa-layer-group"></i>
                                <span>Hizmet Türleri</span>
                            </a>
                        </li>
                    </ul>
                </li>

                <!-- Tanımlamalar -->
                <?php if(isset($sidebarDefinitionTypes) && $sidebarDefinitionTypes->isNotEmpty()): ?>
                    <li class="nav-item has-dropdown <?php echo e(request()->is('agency/definitions*') ? 'open' : ''); ?>">
                        <a href="javascript:void(0)" class="nav-link">
                            <div class="nav-icon-wrapper">
                                <i class="fas fa-tags"></i>
                            </div>
                            <span class="nav-text">Tanımlamalar</span>
                            <i class="fas fa-chevron-right dropdown-arrow"></i>
                        </a>
                        <ul class="nav-dropdown">
                            <?php $__currentLoopData = $sidebarDefinitionTypes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $type): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <li>
                                    <a href="<?php echo e(route('agency.definitions.index', ['type' => $type->id])); ?>"
                                        class="dropdown-link <?php echo e(request()->get('type') == $type->id ? 'active' : ''); ?>">
                                        <i class="<?php echo e($type->icon ?? 'fas fa-circle'); ?>"></i>
                                        <span><?php echo e($type->display_name); ?></span>
                                        <span class="count-badge"><?php echo e($type->definitions->count()); ?></span>
                                    </a>
                                </li>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            <li class="dropdown-divider"></li>
                            <li>
                                <a href="<?php echo e(route('agency.definitions.index')); ?>" class="dropdown-link">
                                    <i class="fas fa-list"></i>
                                    <span>Tüm Tanımlar</span>
                                </a>
                            </li>
                        </ul>
                    </li>
                <?php endif; ?>

                <div class="nav-section-label">Operasyon</div>

                <li class="nav-item has-dropdown <?php echo e(request()->routeIs('agency.sales.*') ? 'open' : ''); ?>">
                    <a href="javascript:void(0)" class="nav-link">
                        <div class="nav-icon-wrapper">
                            <i class="fas fa-shopping-cart"></i>
                            <?php if($pendingResCount > 0): ?>
                                <span class="nav-notification-dot"></span>
                            <?php endif; ?>
                        </div>
                        <span class="nav-text">Satış</span>
                        <?php if($pendingResCount > 0): ?>
                            <span class="nav-badge-new"><?php echo e($pendingResCount); ?></span>
                        <?php endif; ?>
                        <i class="fas fa-chevron-right dropdown-arrow"></i>
                    </a>
                    <ul class="nav-dropdown">
                        <li>
                            <a href="<?php echo e(route('agency.sales.index')); ?>"
                               class="dropdown-link <?php echo e(request()->routeIs('agency.sales.index') ? 'active' : ''); ?>">
                                <i class="fas fa-chart-line"></i>
                                <span>Başlangıç</span>
                            </a>
                        </li>
                        <li>
                            <a href="<?php echo e(route('agency.sales.leads')); ?>"
                               class="dropdown-link <?php echo e(request()->routeIs('agency.sales.leads') ? 'active' : ''); ?>">
                                <i class="fas fa-user-clock"></i>
                                <span>Müşteri Adayları</span>
                            </a>
                        </li>
                        <li>
                            <a href="<?php echo e(route('agency.sales.deals')); ?>"
                               class="dropdown-link <?php echo e(request()->routeIs('agency.sales.deals') ? 'active' : ''); ?>">
                                <i class="fas fa-handshake"></i>
                                <span>Anlaşmalar</span>
                            </a>
                        </li>
                        <li>
                            <a href="<?php echo e(route('agency.sales.cancellations')); ?>"
                               class="dropdown-link <?php echo e(request()->routeIs('agency.sales.cancellations') ? 'active' : ''); ?>">
                                <i class="fas fa-undo"></i>
                                <span>İptal ve İadeler</span>
                            </a>
                        </li>
                    </ul>
                </li>

                <li class="nav-item has-dropdown <?php echo e(request()->is('agency/customers*') ? 'open' : ''); ?>">
                    <a href="javascript:void(0)" class="nav-link">
                        <div class="nav-icon-wrapper">
                            <i class="fas fa-user-friends"></i>
                        </div>
                        <span class="nav-text">Müşteriler</span>
                        <i class="fas fa-chevron-right dropdown-arrow"></i>
                    </a>
                    <ul class="nav-dropdown">
                        <li>
                            <a href="<?php echo e(route('agency.customers.index', ['type' => 'individual'])); ?>"
                                class="dropdown-link <?php echo e(request()->is('agency/customers*') && request('type') == 'individual' ? 'active' : ''); ?>">
                                <i class="fas fa-user"></i>
                                <span>Kişiler</span>
                            </a>
                        </li>
                        <li>
                            <a href="<?php echo e(route('agency.customers.index', ['type' => 'corporate'])); ?>"
                                class="dropdown-link <?php echo e(request()->is('agency/customers*') && request('type') == 'corporate' ? 'active' : ''); ?>">
                                <i class="fas fa-building"></i>
                                <span>Şirketler</span>
                            </a>
                        </li>
                        <li>
                            <a href="<?php echo e(route('agency.customers.index')); ?>"
                                class="dropdown-link <?php echo e(request()->is('agency/customers*') && !request('type') ? 'active' : ''); ?>">
                                <i class="fas fa-users"></i>
                                <span>Tüm Müşteriler</span>
                            </a>
                        </li>
                    </ul>
                </li>

                <li class="nav-item has-dropdown <?php echo e(request()->is('agency/suppliers*') ? 'open' : ''); ?>">
                    <a href="javascript:void(0)" class="nav-link">
                        <div class="nav-icon-wrapper">
                            <i class="fas fa-handshake"></i>
                        </div>
                        <span class="nav-text">Tedarikçiler</span>
                        <i class="fas fa-chevron-right dropdown-arrow"></i>
                    </a>
                    <ul class="nav-dropdown">
                        <li>
                            <a href="<?php echo e(route('agency.suppliers.index', ['supplier_type' => 'hotel'])); ?>"
                                class="dropdown-link <?php echo e(request()->is('agency/suppliers*') && request('supplier_type') == 'hotel' ? 'active' : ''); ?>">
                                <i class="fas fa-hotel"></i>
                                <span>Oteller</span>
                            </a>
                        </li>
                        <li>
                            <a href="<?php echo e(route('agency.suppliers.index', ['supplier_type' => 'transportation'])); ?>"
                                class="dropdown-link <?php echo e(request()->is('agency/suppliers*') && request('supplier_type') == 'transportation' ? 'active' : ''); ?>">
                                <i class="fas fa-shuttle-van"></i>
                                <span>Taşıma Firmaları</span>
                            </a>
                        </li>
                        <li>
                            <a href="<?php echo e(route('agency.suppliers.index')); ?>"
                                class="dropdown-link <?php echo e(request()->is('agency/suppliers*') && !request('supplier_type') ? 'active' : ''); ?>">
                                <i class="fas fa-truck-loading"></i>
                                <span>Tüm Tedarikçiler</span>
                            </a>
                        </li>
                    </ul>
                </li>

                <li class="nav-item">
                    <a href="<?php echo e(route('agency.disk.index')); ?>"
                        class="nav-link <?php echo e(request()->routeIs('agency.disk.*') ? 'active' : ''); ?>">
                        <div class="nav-icon-wrapper">
                            <i class="fas fa-hdd"></i>
                        </div>
                        <span class="nav-text">Disk</span>
                    </a>
                </li>

                <li class="nav-item">
                    <a href="<?php echo e(route('agency.finance.index')); ?>"
                        class="nav-link <?php echo e(request()->routeIs('agency.finance.*') ? 'active' : ''); ?>">
                        <div class="nav-icon-wrapper">
                            <i class="fas fa-chart-line"></i>
                        </div>
                        <span class="nav-text">Finansal Raporlar</span>
                    </a>
                </li>

                <div class="nav-section-label">Ayarlar</div>

                <li class="nav-item has-dropdown <?php echo e(request()->is('agency/staff-management*') ? 'open' : ''); ?>">
                    <a href="javascript:void(0)" class="nav-link">
                        <div class="nav-icon-wrapper">
                            <i class="fas fa-user-shield"></i>
                        </div>
                        <span class="nav-text">Kullanıcı ve Yetki</span>
                        <i class="fas fa-chevron-right dropdown-arrow"></i>
                    </a>
                    <ul class="nav-dropdown">
                        <li>
                            <a href="<?php echo e(route('agency.staff-management.staff.index')); ?>"
                                class="dropdown-link <?php echo e(request()->is('agency/staff-management/staff*') ? 'active' : ''); ?>">
                                <i class="fas fa-user-tie"></i>
                                <span>Personeller</span>
                            </a>
                        </li>
                        <li>
                            <a href="<?php echo e(route('agency.staff-management.roles.index')); ?>"
                                class="dropdown-link <?php echo e(request()->is('agency/staff-management/roles*') ? 'active' : ''); ?>">
                                <i class="fas fa-key"></i>
                                <span>Yetkilendirme</span>
                            </a>
                        </li>
                    </ul>
                </li>

                <li class="nav-item">
                    <a href="<?php echo e(route('agency.settings')); ?>"
                        class="nav-link <?php echo e(request()->routeIs('agency.settings') ? 'active' : ''); ?>">
                        <div class="nav-icon-wrapper">
                            <i class="fas fa-cog"></i>
                        </div>
                        <span class="nav-text">Ayarlar</span>
                    </a>
                </li>
            </ul>
        </nav>
    </div>

    <div class="sidebar-footer">
        <a href="javascript:void(0)" onclick="document.getElementById('logout-form').submit();" class="logout-btn">
            <i class="fas fa-sign-out-alt"></i>
            <span>Oturumu Kapat</span>
        </a>
        <form id="logout-form" action="<?php echo e(route('agency.logout')); ?>" method="POST" style="display: none;">
            <?php echo csrf_field(); ?>
        </form>
    </div>
</aside><?php /**PATH /Applications/XAMPP/xamppfiles/htdocs/acente/resources/views/agency/layouts/partials/sidebar.blade.php ENDPATH**/ ?>