<!DOCTYPE html>
<html lang="tr">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title><?php echo e($resource->name); ?> — Çalışma Takvimi</title>
    <meta name="robots" content="noindex,nofollow">

    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
    <script src="https://cdn.jsdelivr.net/npm/fullcalendar@6.1.15/index.global.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/fullcalendar@6.1.15/locales-all.global.min.js"></script>

    <?php
        $typeColors = [
            'tour_assignment' => ['color' => '#2563eb', 'bg' => '#eff6ff', 'label' => 'Tur Görevi', 'icon' => 'fa-bus'],
            'block'           => ['color' => '#ef4444', 'bg' => '#fef2f2', 'label' => 'Bloke',      'icon' => 'fa-ban'],
            'maintenance'     => ['color' => '#f59e0b', 'bg' => '#fffbeb', 'label' => 'Bakım',      'icon' => 'fa-wrench'],
            'leave'           => ['color' => '#8b5cf6', 'bg' => '#f5f3ff', 'label' => 'İzin',       'icon' => 'fa-plane-departure'],
        ];
        $typeMeta = fn ($t) => $typeColors[$t] ?? ['color' => '#64748b', 'bg' => '#f1f5f9', 'label' => $t, 'icon' => 'fa-calendar'];

        $events = $schedules->map(function ($s) use ($typeMeta) {
            $tc = $typeMeta($s->schedule_type);
            $allDay = empty($s->start_time);
            return [
                'title' => $s->title,
                'start' => $s->start_date->format('Y-m-d') . ($s->start_time ? 'T' . substr($s->start_time, 0, 5) : ''),
                'end'   => $allDay
                    ? $s->end_date->copy()->addDay()->format('Y-m-d')
                    : $s->end_date->format('Y-m-d') . ($s->end_time ? 'T' . substr($s->end_time, 0, 5) : ''),
                'allDay' => $allDay,
                'color' => $tc['color'],
                'extendedProps' => [
                    'typeLabel' => $tc['label'],
                    'icon' => $tc['icon'],
                    'description' => $s->description,
                    'dateText' => $s->start_date->format('d.m.Y') . ($s->start_date->ne($s->end_date) ? ' → ' . $s->end_date->format('d.m.Y') : ''),
                    'timeText' => $s->start_time ? substr($s->start_time, 0, 5) . ' - ' . substr($s->end_time ?? '', 0, 5) : null,
                ],
            ];
        })->values();

        $initials = collect(explode(' ', $resource->name))->map(fn ($w) => mb_strtoupper(mb_substr($w, 0, 1)))->take(2)->implode('');
        $typeLabel = $resource->type === 'guide' ? 'Rehber' : ($resource->type === 'captain' ? 'Kaptan / Şoför' : 'Araç');
        $avatarBg = $resource->type === 'guide' ? 'linear-gradient(135deg,#3b82f6,#2563eb)' : ($resource->type === 'captain' ? 'linear-gradient(135deg,#8b5cf6,#7c3aed)' : 'linear-gradient(135deg,#10b981,#059669)');

        $now = now()->startOfDay();
        $upcoming = $schedules->filter(fn ($s) => $s->end_date->gte($now))->sortBy('start_date')->values();
        $past = $schedules->filter(fn ($s) => $s->end_date->lt($now))->sortByDesc('start_date')->values();
    ?>

    <style>
        * { box-sizing: border-box; }
        body { margin: 0; font-family: 'Inter', system-ui, sans-serif; background: #f1f5f9; color: #1e293b; }
        .wrap { max-width: 1080px; margin: 0 auto; padding: 24px 16px 60px; }

        .topbar { background: #fff; border-radius: 20px; padding: 22px 24px; display: flex; align-items: center; gap: 18px; box-shadow: 0 4px 24px rgba(15,23,42,.06); flex-wrap: wrap; }
        .avatar { width: 64px; height: 64px; border-radius: 18px; display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 1.4rem; flex-shrink: 0; box-shadow: 0 8px 20px rgba(37,99,235,.2); }
        .topbar h1 { font-size: 1.5rem; font-weight: 800; margin: 0 0 4px; letter-spacing: -.02em; }
        .topbar .sub { color: #64748b; font-size: .9rem; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
        .chip { display: inline-flex; align-items: center; gap: 6px; background: #eff6ff; color: #2563eb; font-weight: 700; font-size: .78rem; padding: 4px 12px; border-radius: 999px; }
        .agency { margin-left: auto; text-align: right; color: #94a3b8; font-size: .82rem; font-weight: 600; }
        .agency b { display: block; color: #475569; font-size: .95rem; }

        .legend { display: flex; gap: 8px; flex-wrap: wrap; margin: 18px 0; }
        .legend-item { display: inline-flex; align-items: center; gap: 7px; background: #fff; border: 1px solid #e2e8f0; border-radius: 999px; padding: 6px 14px; font-size: .8rem; font-weight: 600; color: #475569; }
        .legend-dot { width: 10px; height: 10px; border-radius: 50%; }

        .card { background: #fff; border-radius: 20px; padding: 20px; box-shadow: 0 4px 24px rgba(15,23,42,.05); margin-bottom: 22px; }
        .card-title { font-size: .78rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: #94a3b8; margin: 0 0 16px; display: flex; align-items: center; gap: 8px; }

        /* FullCalendar tweaks */
        #calendar { --fc-border-color: #eef2f7; --fc-today-bg-color: #eff6ff; font-size: .86rem; }
        .fc .fc-toolbar-title { font-size: 1.15rem; font-weight: 800; }
        .fc .fc-button { background: #f1f5f9; border: none; color: #475569; font-weight: 700; text-transform: capitalize; padding: 6px 12px; border-radius: 10px; }
        .fc .fc-button-primary:not(:disabled).fc-button-active, .fc .fc-button-primary:hover { background: #2563eb; color: #fff; }
        .fc .fc-button-primary:disabled { background: #e2e8f0; color: #94a3b8; }
        .fc-daygrid-event { border-radius: 6px; padding: 1px 5px; font-weight: 600; }
        .fc .fc-toolbar { flex-wrap: wrap; gap: 8px; }

        /* Chronological list */
        .sch-list { display: flex; flex-direction: column; gap: 10px; }
        .sch-item { display: flex; gap: 14px; align-items: flex-start; padding: 14px; border: 1px solid #eef2f7; border-radius: 14px; transition: .15s; }
        .sch-item:hover { border-color: #cbd5e1; background: #fafbff; }
        .sch-ic { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; font-size: 1rem; flex-shrink: 0; }
        .sch-body { flex: 1; min-width: 0; }
        .sch-badges { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 3px; }
        .sch-type { font-size: .66rem; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; padding: 2px 8px; border-radius: 6px; }
        .sch-date { font-size: .76rem; color: #64748b; font-weight: 600; }
        .sch-title { font-weight: 700; font-size: .92rem; color: #0f172a; margin: 1px 0; }
        .sch-desc { font-size: .82rem; color: #64748b; line-height: 1.5; white-space: pre-wrap; }
        .empty { text-align: center; padding: 40px 20px; color: #94a3b8; }
        .empty i { font-size: 2.4rem; color: #cbd5e1; display: block; margin-bottom: 10px; }
        .section-sep { font-size: .74rem; font-weight: 800; color: #94a3b8; text-transform: uppercase; letter-spacing: .06em; margin: 20px 0 10px; }
        .footer { text-align: center; color: #94a3b8; font-size: .78rem; margin-top: 30px; }
        @media(max-width:640px){ .agency{ margin-left:0; text-align:left; width:100%; } }
    </style>
</head>
<body>
<div class="wrap">

    <div class="topbar">
        <div class="avatar" style="background:<?php echo e($avatarBg); ?>"><?php echo e($initials); ?></div>
        <div>
            <h1><?php echo e($resource->name); ?></h1>
            <div class="sub">
                <span class="chip"><i class="fas <?php echo e($resource->type === 'guide' ? 'fa-user-tie' : ($resource->type === 'captain' ? 'fa-id-card' : 'fa-bus')); ?>"></i> <?php echo e($typeLabel); ?></span>
                <?php if($resource->phone): ?><span><i class="fas fa-phone" style="color:#94a3b8"></i> <?php echo e($resource->phone); ?></span><?php endif; ?>
            </div>
        </div>
        <?php if($resource->agency): ?>
            <div class="agency">
                <span>Çalışma Takvimi</span>
                <b><?php echo e($resource->agency->name ?? $resource->agency->company_name ?? ''); ?></b>
            </div>
        <?php endif; ?>
    </div>

    <div class="legend">
        <?php $__currentLoopData = $typeColors; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tc): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <span class="legend-item"><span class="legend-dot" style="background:<?php echo e($tc['color']); ?>"></span><?php echo e($tc['label']); ?></span>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
    </div>

    <div class="card">
        <div class="card-title"><i class="fas fa-calendar-days"></i> Takvim</div>
        <div id="calendar"></div>
    </div>

    <div class="card">
        <div class="card-title"><i class="fas fa-list-check"></i> Tüm Program (Liste)</div>

        <?php if($schedules->isEmpty()): ?>
            <div class="empty"><i class="fas fa-calendar-xmark"></i>Henüz planlanmış bir program bulunmuyor.</div>
        <?php else: ?>
            <?php if($upcoming->isNotEmpty()): ?>
                <div class="section-sep">Yaklaşan (<?php echo e($upcoming->count()); ?>)</div>
                <div class="sch-list">
                    <?php $__currentLoopData = $upcoming; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $s): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <?php echo $__env->make('page.partials.resource-schedule-item', ['s' => $s, 'tc' => $typeMeta($s->schedule_type)], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </div>
            <?php endif; ?>

            <?php if($past->isNotEmpty()): ?>
                <div class="section-sep">Geçmiş (<?php echo e($past->count()); ?>)</div>
                <div class="sch-list" style="opacity:.7">
                    <?php $__currentLoopData = $past; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $s): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <?php echo $__env->make('page.partials.resource-schedule-item', ['s' => $s, 'tc' => $typeMeta($s->schedule_type)], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </div>
            <?php endif; ?>
        <?php endif; ?>
    </div>

    <div class="footer">
        <i class="fas fa-lock" style="font-size:.7rem"></i> Bu sayfa yalnızca size özel bağlantı ile erişilebilir.
    </div>
</div>

<script>
    document.addEventListener('DOMContentLoaded', function () {
        const el = document.getElementById('calendar');
        const calendar = new FullCalendar.Calendar(el, {
            initialView: 'dayGridMonth',
            locale: 'tr',
            firstDay: 1,
            height: 'auto',
            headerToolbar: {
                left: 'prev,next today',
                center: 'title',
                right: 'dayGridMonth,timeGridWeek,listMonth'
            },
            buttonText: { today: 'Bugün', month: 'Ay', week: 'Hafta', list: 'Liste' },
            noEventsText: 'Bu aralıkta program yok',
            displayEventTime: true,
            events: <?php echo json_encode($events, 15, 512) ?>,
            eventDidMount: function (info) {
                const p = info.event.extendedProps;
                info.el.title = p.typeLabel + ' • ' + p.dateText + (p.timeText ? ' • ' + p.timeText : '') + (p.description ? '\n' + p.description : '');
            }
        });
        calendar.render();
    });
</script>
</body>
</html>
<?php /**PATH C:\xampp\htdocs\acente\resources\views/page/resource-schedule.blade.php ENDPATH**/ ?>