@extends('agency.layouts.app')

@section('title', $tour->name)
@section('page_title', 'Tur Detayı')

@php
    $breadcrumbs = [
        ['title' => 'Ana Sayfa', 'url' => route('agency.dashboard')],
        ['title' => 'Günübirlik Turlar', 'url' => route('agency.products.gunubirlik-turlar.index')],
        ['title' => $tour->name, 'url' => '']
    ];
@endphp

@push('styles')
    <style>
        .tour-detail-container {
            max-width: 1200px;
            margin: 0 auto;
        }

        .tour-header {
            background: linear-gradient(135deg, #f59e0b, #fbbf24);
            color: white;
            padding: 2rem;
            border-radius: var(--radius-xl);
            margin-bottom: 2rem;
            position: relative;
            overflow: hidden;
        }

        .tour-header::before {
            content: '';
            position: absolute;
            top: 0;
            right: 0;
            width: 200px;
            height: 200px;
            background: rgba(255, 255, 255, 0.1);
            border-radius: 50%;
            transform: translate(50%, -50%);
        }

        .tour-header-content {
            position: relative;
            z-index: 2;
        }

        .tour-title {
            font-size: 32px;
            font-weight: 700;
            margin-bottom: 0.5rem;
        }

        .tour-code {
            font-size: 14px;
            opacity: 0.9;
            margin-bottom: 1rem;
        }

        .tour-meta {
            display: flex;
            gap: 2rem;
            flex-wrap: wrap;
        }

        .tour-meta-item {
            display: flex;
            align-items: center;
            gap: 0.5rem;
            font-size: 14px;
        }

        .tour-meta-icon {
            font-size: 16px;
            opacity: 0.8;
        }

        .action-buttons {
            display: flex;
            gap: 1rem;
            margin-bottom: 2rem;
        }

        .info-card {
            background: white;
            border: 1px solid var(--gray-200);
            border-radius: var(--radius-xl);
            padding: 2rem;
            margin-bottom: 2rem;
        }

        .info-card-title {
            font-size: 20px;
            font-weight: 700;
            margin-bottom: 1.5rem;
            color: var(--gray-900);
            display: flex;
            align-items: center;
            gap: 0.75rem;
        }

        .info-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
            gap: 1.5rem;
        }

        .info-item {
            display: flex;
            flex-direction: column;
            gap: 0.5rem;
        }

        .info-label {
            font-size: 0.875rem;
            color: var(--gray-600);
            font-weight: 500;
        }

        .info-value {
            font-size: 1rem;
            color: var(--gray-900);
            font-weight: 600;
        }

        .description-content {
            color: var(--gray-700);
            line-height: 1.7;
        }

        .badge {
            padding: 0.5rem 1rem;
            border-radius: var(--radius-md);
            font-size: 0.875rem;
            font-weight: 600;
        }

        .image-gallery {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
            gap: 1rem;
        }

        .gallery-item {
            position: relative;
            border-radius: var(--radius-lg);
            overflow: hidden;
            aspect-ratio: 16/9;
        }

        .gallery-item img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }

        .itinerary-item {
            border-left: 3px solid #f59e0b;
            padding-left: 1.5rem;
            margin-bottom: 2rem;
        }

        .itinerary-time {
            font-size: 0.875rem;
            color: #f59e0b;
            font-weight: 600;
            margin-bottom: 0.5rem;
        }

        .itinerary-title {
            font-size: 1.125rem;
            font-weight: 700;
            margin-bottom: 0.5rem;
        }

        .itinerary-location {
            font-size: 0.875rem;
            color: var(--gray-600);
            margin-bottom: 0.5rem;
        }

        .price-card {
            background: linear-gradient(135deg, #f59e0b10, #fbbf2410);
            border: 2px solid #f59e0b30;
            border-radius: var(--radius-lg);
            padding: 1.5rem;
        }

        .price-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
            gap: 1.5rem;
        }

        .price-item {
            display: flex;
            flex-direction: column;
            gap: 0.25rem;
            text-align: center;
        }

        .price-label {
            font-size: 0.875rem;
            color: var(--gray-600);
        }

        .price-value {
            font-size: 1.5rem;
            font-weight: 700;
            color: #f59e0b;
        }

        .time-badge {
            display: inline-flex;
            align-items: center;
            gap: 0.5rem;
            background: #f59e0b20;
            color: #b45309;
            padding: 0.5rem 1rem;
            border-radius: var(--radius-md);
            font-weight: 600;
        }

        .recurring-days {
            display: flex;
            gap: 0.5rem;
            flex-wrap: wrap;
        }

        .day-badge {
            padding: 0.5rem 1rem;
            background: var(--gray-100);
            border-radius: var(--radius-md);
            font-size: 0.875rem;
            font-weight: 500;
        }

        .day-badge.active {
            background: #f59e0b;
            color: white;
        }
    </style>
@endpush

@section('content')
    <div class="tour-detail-container">
        <!-- Tour Header -->
        <div class="tour-header">
            <div class="tour-header-content">
                <h1 class="tour-title">{{ $tour->name }}</h1>
                <div class="tour-code">Tur Kodu: {{ $tour->code }}</div>
                <div class="tour-meta">
                    <div class="tour-meta-item">
                        <i class="fas fa-clock tour-meta-icon"></i>
                        <span>{{ substr($tour->start_time, 0, 5) }} - {{ substr($tour->end_time, 0, 5) }}</span>
                    </div>
                    <div class="tour-meta-item">
                        <i class="fas fa-map-marker-alt tour-meta-icon"></i>
                        <span>{{ $tour->departureCity?->city ?? 'Belirtilmemiş' }}</span>
                    </div>
                    @if($tour->tour_type)
                        <div class="tour-meta-item">
                            <i class="fas fa-tag tour-meta-icon"></i>
                            <span>{{ $tour->tour_type === 'domestic' ? 'Yurt İçi' : 'Yurt Dışı' }}</span>
                        </div>
                    @endif
                    <div class="tour-meta-item">
                        <i class="fas fa-{{ $tour->is_active ? 'check-circle' : 'times-circle' }} tour-meta-icon"></i>
                        <span>{{ $tour->is_active ? 'Aktif' : 'Pasif' }}</span>
                    </div>
                </div>
            </div>
        </div>

        <!-- Action Buttons -->
        <div class="action-buttons">
            <a href="{{ route('agency.products.gunubirlik-turlar.general', $tour) }}" class="btn btn-primary">
                <i class="fas fa-edit me-2"></i>Düzenle
            </a>
            <a href="{{ route('agency.products.gunubirlik-turlar.index') }}" class="btn btn-secondary">
                <i class="fas fa-arrow-left me-2"></i>Geri
            </a>
        </div>

        <!-- Basic Information -->
        <div class="info-card">
            <h2 class="info-card-title">
                <i class="fas fa-info-circle"></i>
                Genel Bilgiler
            </h2>
            <div class="info-grid">
                <div class="info-item">
                    <span class="info-label">Tur Adı</span>
                    <span class="info-value">{{ $tour->name }}</span>
                </div>
                <div class="info-item">
                    <span class="info-label">Tur Kodu</span>
                    <span class="info-value">{{ $tour->code }}</span>
                </div>
                <div class="info-item">
                    <span class="info-label">Saat</span>
                    <span class="info-value">
                        <span class="time-badge">
                            <i class="fas fa-clock"></i>
                            {{ substr($tour->start_time, 0, 5) }} - {{ substr($tour->end_time, 0, 5) }}
                        </span>
                    </span>
                </div>
                <div class="info-item">
                    <span class="info-label">Kalkış Şehri</span>
                    <span class="info-value">{{ $tour->departureCity?->city ?? '-' }}</span>
                </div>
                <div class="info-item">
                    <span class="info-label">Varış Şehri</span>
                    <span class="info-value">{{ $tour->arrivalCity?->city ?? '-' }}</span>
                </div>
                <div class="info-item">
                    <span class="info-label">Tur Tipi</span>
                    <span class="info-value">{{ $tour->tour_type === 'domestic' ? 'Yurt İçi' : 'Yurt Dışı' }}</span>
                </div>
                <div class="info-item">
                    <span class="info-label">Katılımcı Sayısı</span>
                    <span class="info-value">
                        Min: {{ $tour->min_participants }}
                        @if($tour->max_participants)
                            / Max: {{ $tour->max_participants }}
                        @endif
                    </span>
                </div>
                <div class="info-item">
                    <span class="info-label">Durum</span>
                    <span class="info-value">
                        <span class="badge {{ $tour->is_active ? 'bg-success' : 'bg-secondary' }}">
                            {{ $tour->is_active ? 'Aktif' : 'Pasif' }}
                        </span>
                    </span>
                </div>
            </div>

            @if($tour->short_description)
                <div class="mt-4">
                    <span class="info-label d-block mb-2">Kısa Açıklama</span>
                    <div class="description-content">{{ $tour->short_description }}</div>
                </div>
            @endif

            @if($tour->description)
                <div class="mt-4">
                    <span class="info-label d-block mb-2">Detaylı Açıklama</span>
                    <div class="description-content">{!! $tour->description !!}</div>
                </div>
            @endif
        </div>

        <!-- Pricing -->
        <div class="info-card">
            <h2 class="info-card-title">
                <i class="fas fa-lira-sign"></i>
                Fiyatlar
            </h2>
            <div class="price-card">
                <div class="price-grid">
                    <div class="price-item">
                        <span class="price-label">Yetişkin</span>
                        <span class="price-value">{{ number_format($tour->adult_price, 2) }} TL</span>
                    </div>
                    <div class="price-item">
                        <span class="price-label">Çocuk</span>
                        <span class="price-value">{{ number_format($tour->child_price, 2) }} TL</span>
                    </div>
                    <div class="price-item">
                        <span class="price-label">Bebek</span>
                        <span class="price-value">{{ number_format($tour->infant_price, 2) }} TL</span>
                    </div>
                </div>
            </div>
        </div>

        <!-- Recurring Days -->
        @if($tour->recurring_days && count($tour->recurring_days) > 0)
            <div class="info-card">
                <h2 class="info-card-title">
                    <i class="fas fa-calendar-week"></i>
                    Düzenli Hareket Günleri
                </h2>
                @php
                    $dayNames = [
                        'monday' => 'Pazartesi',
                        'tuesday' => 'Salı',
                        'wednesday' => 'Çarşamba',
                        'thursday' => 'Perşembe',
                        'friday' => 'Cuma',
                        'saturday' => 'Cumartesi',
                        'sunday' => 'Pazar',
                    ];
                    $allDays = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'];
                @endphp
                <div class="recurring-days">
                    @foreach($allDays as $day)
                        <span class="day-badge {{ in_array($day, $tour->recurring_days) ? 'active' : '' }}">
                            {{ $dayNames[$day] }}
                        </span>
                    @endforeach
                </div>
            </div>
        @endif

        <!-- Categories -->
        @if($tour->categories && $tour->categories->count() > 0)
            <div class="info-card">
                <h2 class="info-card-title">
                    <i class="fas fa-tags"></i>
                    Kategoriler
                </h2>
                <div class="d-flex flex-wrap gap-2">
                    @foreach($tour->categories as $category)
                        <span class="badge bg-warning text-dark">{{ $category->name }}</span>
                    @endforeach
                </div>
            </div>
        @endif

        <!-- Images -->
        @if($tour->activeImages && $tour->activeImages->count() > 0)
            <div class="info-card">
                <h2 class="info-card-title">
                    <i class="fas fa-images"></i>
                    Görseller
                </h2>
                <div class="image-gallery">
                    @foreach($tour->activeImages as $image)
                        <div class="gallery-item">
                            <img src="{{ $image->image_url }}" alt="{{ $image->title ?? $tour->name }}">
                        </div>
                    @endforeach
                </div>
            </div>
        @endif

        <!-- Itinerary -->
        @if($tour->activeItineraries && $tour->activeItineraries->count() > 0)
            <div class="info-card">
                <h2 class="info-card-title">
                    <i class="fas fa-route"></i>
                    Tur Programı
                </h2>
                @foreach($tour->activeItineraries as $itinerary)
                    <div class="itinerary-item">
                        @if($itinerary->start_time)
                            <div class="itinerary-time">
                                <i class="fas fa-clock me-1"></i>
                                {{ substr($itinerary->start_time, 0, 5) }}
                                @if($itinerary->end_time)
                                    - {{ substr($itinerary->end_time, 0, 5) }}
                                @endif
                            </div>
                        @endif
                        <div class="itinerary-title">{{ $itinerary->title }}</div>
                        @if($itinerary->location)
                            <div class="itinerary-location">
                                <i class="fas fa-map-marker-alt me-1"></i>{{ $itinerary->location }}
                            </div>
                        @endif
                        @if($itinerary->description)
                            <div class="description-content mt-2">{!! $itinerary->description !!}</div>
                        @endif
                    </div>
                @endforeach
            </div>
        @endif

        <!-- Upcoming Dates -->
        @if($tour->upcomingDates && $tour->upcomingDates->count() > 0)
            <div class="info-card">
                <h2 class="info-card-title">
                    <i class="fas fa-calendar-alt"></i>
                    Yaklaşan Tarihler
                </h2>
                <div class="table-responsive">
                    <table class="table">
                        <thead>
                            <tr>
                                <th>Tarih</th>
                                <th>Saat</th>
                                <th>Kontenjan</th>
                                <th>Durum</th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach($tour->upcomingDates as $date)
                                <tr>
                                    <td>{{ \Carbon\Carbon::parse($date->tour_date)->format('d.m.Y') }}</td>
                                    <td>{{ substr($date->start_time ?? $tour->start_time, 0, 5) }}</td>
                                    <td>{{ $date->available_seats }} / {{ $date->max_participants ?? $tour->max_participants ?? '-' }}</td>
                                    <td>
                                        <span class="badge {{ $date->is_available ? 'bg-success' : 'bg-danger' }}">
                                            {{ $date->is_available ? 'Müsait' : 'Dolu' }}
                                        </span>
                                    </td>
                                </tr>
                            @endforeach
                        </tbody>
                    </table>
                </div>
            </div>
        @endif

        <!-- Inclusions & Exclusions -->
        @if($tour->inclusions || $tour->exclusions)
            <div class="row">
                @if($tour->inclusions)
                    <div class="col-md-6">
                        <div class="info-card">
                            <h2 class="info-card-title">
                                <i class="fas fa-check-circle text-success"></i>
                                Fiyata Dahil
                            </h2>
                            <div class="description-content">{!! $tour->inclusions !!}</div>
                        </div>
                    </div>
                @endif
                @if($tour->exclusions)
                    <div class="col-md-6">
                        <div class="info-card">
                            <h2 class="info-card-title">
                                <i class="fas fa-times-circle text-danger"></i>
                                Fiyata Dahil Değil
                            </h2>
                            <div class="description-content">{!! $tour->exclusions !!}</div>
                        </div>
                    </div>
                @endif
            </div>
        @endif
    </div>
@endsection
