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

<?php
    $breadcrumbs = [
        ['title' => 'Dashboard', 'url' => route('agency.dashboard')],
        ['title' => 'Kaynak Yönetimi', 'url' => '']
    ];

    $sort = request('sort', 'name');
    $dir = request('dir', 'asc');

    $columns = [
        ['key' => 'name',    'label' => 'Kaynak',  'sortable' => true, 'sort' => 'name'],
        ['key' => 'type',    'label' => 'Tip',     'sortable' => true, 'sort' => 'type', 'align' => 'center'],
        ['key' => 'source',  'label' => 'Tedarik'],
        ['key' => 'contact', 'label' => 'İletişim'],
        ['key' => 'status',  'label' => 'Durum',   'sortable' => true, 'sort' => 'is_active', 'align' => 'center'],
        ['key' => 'cost',    'label' => 'Maliyet', 'align' => 'end'],
        ['key' => '_actions','label' => 'Aksiyon', 'fixed' => true, 'align' => 'end', 'width' => '130px'],
    ];

    $filters = [
        ['key' => 'type', 'label' => 'Tip', 'value' => request('type'), 'placeholder' => 'Tüm Tipler', 'options' => [
            'guide' => 'Rehber', 'vehicle' => 'Araç', 'captain' => 'Kaptan',
        ]],
        ['key' => 'source_type', 'label' => 'Tedarik', 'value' => request('source_type'), 'placeholder' => 'Tüm Tedarik', 'options' => [
            'internal' => 'İç Kaynak', 'external' => 'Dış Kaynak',
        ]],
        ['key' => 'status', 'label' => 'Durum', 'value' => request('status'), 'placeholder' => 'Tüm Durumlar', 'options' => [
            'active' => 'Aktif', 'inactive' => 'Pasif',
        ]],
    ];
?>

<?php $__env->startPush('styles'); ?>
<style>
    /* Kaynak listesi hücre yardımcıları */
    .r-avatar { width:40px; height:40px; border-radius:12px; display:flex; align-items:center; justify-content:center; font-weight:700; font-size:.85rem; flex-shrink:0; color:#fff; }
    /* Kapak fotoğrafı varsa avatar olarak göster */
    .r-avatar.has-img { background-size:cover; background-position:center; background-color:#e2e8f0; border:1px solid #e2e8f0; }
    .r-avatar.guide   { background: linear-gradient(135deg, #3b82f6, #2563eb); }
    .r-avatar.vehicle { background: linear-gradient(135deg, #10b981, #059669); }
    .r-avatar.captain { background: linear-gradient(135deg, #8b5cf6, #7c3aed); }

    .type-chip { display:inline-flex; align-items:center; gap:5px; padding:3px 10px; border-radius:20px; font-size:.72rem; font-weight:600; }
    .tc-guide   { background:#eff6ff; color:#2563eb; }
    .tc-vehicle { background:#ecfdf5; color:#059669; }
    .tc-captain { background:#f5f3ff; color:#7c3aed; }

    .src-chip { display:inline-flex; align-items:center; gap:4px; padding:3px 9px; border-radius:8px; font-size:.7rem; font-weight:600; }
    .src-internal { background:#f1f5f9; color:#475569; }
    .src-external { background:#fef3c7; color:#92400e; }

    .status-chip { display:inline-flex; align-items:center; gap:5px; padding:4px 10px; border-radius:20px; font-size:.72rem; font-weight:600; }
    .status-chip::before { content:''; width:6px; height:6px; border-radius:50%; }
    .sc-active   { background:#d1fae5; color:#065f46; }
    .sc-active::before { background:#10b981; }
    .sc-inactive { background:#f1f5f9; color:#475569; }
    .sc-inactive::before { background:#94a3b8; }
</style>
<?php $__env->stopPush(); ?>

<?php $__env->startSection('content'); ?>
<div class="container-fluid">
    <?php if (isset($component)) { $__componentOriginalc8463834ba515134d5c98b88e1a9dc03 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginalc8463834ba515134d5c98b88e1a9dc03 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.data-table','data' => ['module' => 'resources','title' => 'Kaynak Yönetimi','subtitle' => 'Rehber, araç ve şoför kaynaklarınızı yönetin','icon' => 'fa-cubes','columns' => $columns,'filters' => $filters,'search' => request('search', ''),'searchPlaceholder' => 'İsim, plaka, telefon veya e-posta ara...','sort' => $sort,'dir' => $dir,'createUrl' => route('agency.resources.create'),'createLabel' => 'Yeni Kaynak','paginator' => $resources,'perPageOptions' => [15, 30, 60, 100]]] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('data-table'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['module' => 'resources','title' => 'Kaynak Yönetimi','subtitle' => 'Rehber, araç ve şoför kaynaklarınızı yönetin','icon' => 'fa-cubes','columns' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($columns),'filters' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($filters),'search' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(request('search', '')),'search-placeholder' => 'İsim, plaka, telefon veya e-posta ara...','sort' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($sort),'dir' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($dir),'create-url' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(route('agency.resources.create')),'create-label' => 'Yeni Kaynak','paginator' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($resources),'per-page-options' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute([15, 30, 60, 100])]); ?>
         <?php $__env->slot('headerActions', null, []); ?> 
            <a href="<?php echo e(route('agency.resources.calendar')); ?>" class="dt-btn dt-btn-ghost">
                <i class="fas fa-calendar-alt"></i> Genel Takvim
            </a>
         <?php $__env->endSlot(); ?>

        <?php $__empty_1 = true; $__currentLoopData = $resources; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $resource): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
            <?php
                $initials = collect(explode(' ', $resource->name))->map(fn($w)=>mb_strtoupper(mb_substr($w,0,1)))->take(2)->implode('');
                $coverUrl = $resource->coverImage?->image_url; // kapak yoksa ilk fotoğraf (bkz. Resource::coverImage)
            ?>
            <tr class="resource-row" data-id="<?php echo e($resource->id); ?>" style="cursor:pointer">
                <td data-col="name">
                    <div class="d-flex align-items-center gap-3">
                        <?php if($coverUrl): ?>
                            <div class="r-avatar has-img" style="background-image:url('<?php echo e($coverUrl); ?>')" title="<?php echo e($resource->name); ?>"></div>
                        <?php else: ?>
                            <div class="r-avatar <?php echo e($resource->type); ?>"><?php echo e($initials); ?></div>
                        <?php endif; ?>
                        <div>
                            <div class="dt-cell-main"><?php echo e($resource->name); ?></div>
                            <?php if($resource->type === 'vehicle' && $resource->vehicle_plate): ?>
                                <div class="dt-cell-sub">
                                    <i class="fas fa-tag"></i> <?php echo e($resource->vehicle_plate); ?>

                                    <?php if($resource->vehicle_capacity): ?> · <i class="fas fa-users"></i> <?php echo e($resource->vehicle_capacity); ?> Yolcu <?php endif; ?>
                                    <?php if($resource->vehicle_fuel_consumption): ?> · <i class="fas fa-gas-pump"></i> <?php echo e(number_format($resource->vehicle_fuel_consumption, 1)); ?> km/lt <?php endif; ?>
                                </div>
                            <?php elseif($resource->user): ?>
                                <div class="dt-cell-sub"><i class="fas fa-link"></i> <?php echo e($resource->user->first_name); ?></div>
                            <?php endif; ?>
                        </div>
                    </div>
                </td>
                <td data-col="type" class="text-center">
                    <span class="type-chip tc-<?php echo e($resource->type); ?>">
                        <?php if($resource->type === 'guide'): ?> <i class="fas fa-user-tie"></i> Rehber
                        <?php elseif($resource->type === 'vehicle'): ?> <i class="fas fa-bus"></i> Araç
                        <?php else: ?> <i class="fas fa-id-card"></i> Kaptan
                        <?php endif; ?>
                    </span>
                </td>
                <td data-col="source">
                    <span class="src-chip src-<?php echo e($resource->source_type); ?>">
                        <?php echo e($resource->source_type === 'internal' ? 'İç Kaynak' : 'Dış Kaynak'); ?>

                    </span>
                    <?php if($resource->supplier): ?>
                        <div class="dt-cell-sub mt-1"><?php echo e($resource->supplier->company_name); ?></div>
                    <?php endif; ?>
                </td>
                <td data-col="contact">
                    <?php if($resource->phone): ?>
                        <div style="font-size:.8rem;color:#334155"><i class="fas fa-phone text-muted me-1"></i><?php echo e($resource->phone); ?></div>
                    <?php endif; ?>
                    <?php if($resource->email): ?>
                        <div class="dt-cell-sub"><i class="fas fa-envelope me-1"></i><?php echo e($resource->email); ?></div>
                    <?php endif; ?>
                    <?php if(!$resource->phone && !$resource->email): ?>
                        <span class="dt-cell-sub">—</span>
                    <?php endif; ?>
                </td>
                <td data-col="status" class="text-center">
                    <span class="status-chip <?php echo e($resource->is_active ? 'sc-active' : 'sc-inactive'); ?>">
                        <?php echo e($resource->is_active ? 'Aktif' : 'Pasif'); ?>

                    </span>
                </td>
                <td data-col="cost" class="text-end">
                    <?php if($resource->costItems->isNotEmpty()): ?>
                        <div class="dt-cell-main" style="color:#10b981">₺<?php echo e(number_format($resource->cost_total, 2)); ?></div>
                        <div class="dt-cell-sub text-truncate" style="max-width:180px"
                             title="<?php echo e($resource->costItems->map->label->implode(' · ')); ?>"><?php echo e($resource->cost_summary); ?></div>
                    <?php else: ?>
                        <span class="dt-cell-sub">—</span>
                    <?php endif; ?>
                </td>
                <td data-col="_actions" class="text-end">
                    <div class="dt-rowact justify-content-end">
                        <a href="<?php echo e(route('agency.resources.calendar', ['resource_id' => $resource->id])); ?>" class="dt-iconbtn" title="Müsaitlik Takvimi"><i class="fas fa-calendar-alt"></i></a>
                        <a href="<?php echo e(route('agency.resources.edit', $resource)); ?>" class="dt-iconbtn" title="Düzenle"><i class="fas fa-pen"></i></a>
                        <button type="button" class="dt-iconbtn danger" title="Sil" onclick="deleteResource(<?php echo e($resource->id); ?>, '<?php echo e(addslashes($resource->name)); ?>')"><i class="fas fa-trash-alt"></i></button>
                        <form id="del-form-<?php echo e($resource->id); ?>" method="POST" action="<?php echo e(route('agency.resources.destroy', $resource)); ?>" style="display:none"><?php echo csrf_field(); ?> <?php echo method_field('DELETE'); ?></form>
                    </div>
                </td>
            </tr>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
            <tr>
                <td colspan="100">
                    <div class="dt-empty">
                        <i class="fas fa-cubes"></i>
                        <h4>Kaynak bulunamadı</h4>
                        <p>Filtrelerinize uyan kaynak bulunmuyor.</p>
                    </div>
                </td>
            </tr>
        <?php endif; ?>
     <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginalc8463834ba515134d5c98b88e1a9dc03)): ?>
<?php $attributes = $__attributesOriginalc8463834ba515134d5c98b88e1a9dc03; ?>
<?php unset($__attributesOriginalc8463834ba515134d5c98b88e1a9dc03); ?>
<?php endif; ?>
<?php if (isset($__componentOriginalc8463834ba515134d5c98b88e1a9dc03)): ?>
<?php $component = $__componentOriginalc8463834ba515134d5c98b88e1a9dc03; ?>
<?php unset($__componentOriginalc8463834ba515134d5c98b88e1a9dc03); ?>
<?php endif; ?>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>
<script>
function deleteResource(id, name) {
    Swal.fire({
        title: 'Kaynağı sil?',
        html: `<strong>${name}</strong> adlı kaynak kalıcı olarak silinecek.`,
        icon: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#ef4444',
        cancelButtonColor: '#6b7280',
        confirmButtonText: 'Evet, Sil',
        cancelButtonText: 'Vazgeç'
    }).then(r => r.isConfirmed && document.getElementById('del-form-' + id).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 C:\xampp\htdocs\acente\resources\views/agency/resources/index.blade.php ENDPATH**/ ?>