@extends('agency.layouts.app')

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

@php
    $breadcrumbs = [
        ['title' => 'Ana Sayfa', 'url' => route('agency.dashboard')],
        ['title' => 'Yurt Dışı Turları', 'url' => route('agency.products.yurtdisi-turlari.index')],
        ['title' => $tour->name, 'url' => '']
    ];
@endphp

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

        .tour-header {
            background: linear-gradient(135deg, var(--primary-color), var(--primary-light));
            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 var(--primary-color);
            padding-left: 1.5rem;
            margin-bottom: 2rem;
        }

        .itinerary-day {
            font-size: 0.875rem;
            color: var(--primary-color);
            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;
        }

        .pricing-card {
            background: var(--gray-50);
            border: 2px solid var(--gray-200);
            border-radius: var(--radius-lg);
            padding: 1.5rem;
            margin-bottom: 1rem;
        }

        .pricing-card.default {
            border-color: var(--success-color);
            background: linear-gradient(to right, rgba(34, 197, 94, 0.05), transparent);
        }

        .pricing-name {
            font-size: 1.25rem;
            font-weight: 700;
            margin-bottom: 0.5rem;
        }

        .pricing-badge {
            background: var(--success-color);
            color: white;
            padding: 0.25rem 0.75rem;
            border-radius: var(--radius-md);
            font-size: 0.75rem;
            font-weight: 600;
            margin-left: 0.5rem;
        }

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

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

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

        .price-value {
            font-size: 1.25rem;
            font-weight: 700;
            color: var(--primary-color);
        }
    </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-calendar tour-meta-icon"></i>
                        <span>{{ $tour->days }} Gün {{ $tour->nights }} Gece</span>
                    </div>
                    <div class="tour-meta-item">
                        <i class="fas fa-map-marker-alt tour-meta-icon"></i>
                        <span>{{ $tour->departureCity?->name ?? '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_display_name }}</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">
            @can('update', $tour)
                <a href="{{ route('agency.products.yurtdisi-turlari.general', $tour) }}" class="btn btn-primary">
                    <i class="fas fa-edit me-2"></i>Düzenle
                </a>
            @endcan
            <a href="{{ route('agency.products.yurtdisi-turlari.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">Süre</span>
                    <span class="info-value">{{ $tour->days }} Gün / {{ $tour->nights }} Gece</span>
                </div>
                <div class="info-item">
                    <span class="info-label">Kalkış Şehri</span>
                    <span class="info-value">{{ $tour->departureCity?->name ?? '-' }}</span>
                </div>
                <div class="info-item">
                    <span class="info-label">Varış Şehri</span>
                    <span class="info-value">{{ $tour->arrivalCity?->name ?? '-' }}</span>
                </div>
                <div class="info-item">
                    <span class="info-label">Tur Tipi</span>
                    <span class="info-value">{{ $tour->tour_type_display_name ?? '-' }}</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>

        <!-- Categories -->
        @if($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-primary">{{ $category->name }}</span>
                    @endforeach
                </div>
            </div>
        @endif

        <!-- Images -->
        @if($tour->activeTourImages->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->activeTourImages as $image)
                        <div class="gallery-item">
                            <img src="{{ $image->image_url }}" alt="{{ $image->title }}">
                        </div>
                    @endforeach
                </div>
            </div>
        @endif

        <!-- Itinerary -->
        @if($tour->activeItineraries->count() > 0)
            <div class="info-card">
                <h2 class="info-card-title">
                    <i class="fas fa-list"></i>
                    Tur Programı
                </h2>
                @foreach($tour->activeItineraries as $itinerary)
                    <div class="itinerary-item">
                        <div class="itinerary-day">Gün {{ $itinerary->day_number }}</div>
                        <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

        <!-- Pricing (tarih bazlı) -->
        @if($tour->tourDates->count() > 0)
            <div class="info-card">
                <h2 class="info-card-title">
                    <i class="fas fa-dollar-sign"></i>
                    Fiyatlandırma (Tarih Bazlı)
                </h2>
                @foreach($tour->tourDates as $pricing)
                    <div class="pricing-card">
                        <div class="pricing-name">
                            {{ $pricing->code }} — {{ $pricing->formatted_date_range }}
                        </div>
                        <div class="price-grid">
                            <div class="price-item">
                                <span class="price-label">Kişi Başı (2 kişilik oda)</span>
                                <span class="price-value">{{ number_format($pricing->adult_price, 2) }} {{ $pricing->currency }}</span>
                            </div>
                            @if($pricing->single_supplement)
                                <div class="price-item">
                                    <span class="price-label">Tek Kişilik Oda Farkı</span>
                                    <span class="price-value">+{{ number_format($pricing->single_supplement, 2) }} {{ $pricing->currency }}</span>
                                </div>
                            @endif
                            @if($pricing->extra_bed_price)
                                <div class="price-item">
                                    <span class="price-label">Ek Yatak Fiyatı</span>
                                    <span class="price-value">{{ number_format($pricing->extra_bed_price, 2) }} {{ $pricing->currency }}</span>
                                </div>
                            @endif
                            @if($pricing->child_price_1)
                                <div class="price-item">
                                    <span class="price-label">1. Çocuk
                                        @if($pricing->child_min_age || $pricing->child_max_age)
                                            ({{ $pricing->child_min_age ?? 0 }}-{{ $pricing->child_max_age ?? 12 }} yaş)
                                        @endif
                                    </span>
                                    <span class="price-value">{{ number_format($pricing->child_price_1, 2) }} {{ $pricing->currency }}</span>
                                </div>
                            @endif
                            @if($pricing->child_price_2)
                                <div class="price-item">
                                    <span class="price-label">2. Çocuk</span>
                                    <span class="price-value">{{ number_format($pricing->child_price_2, 2) }} {{ $pricing->currency }}</span>
                                </div>
                            @endif
                            @if($pricing->infant_price)
                                <div class="price-item">
                                    <span class="price-label">Bebek
                                        @if($pricing->infant_max_age)
                                            ({{ $pricing->infant_min_age ?? 0 }}-{{ $pricing->infant_max_age }} yaş)
                                        @endif
                                    </span>
                                    <span class="price-value">{{ number_format($pricing->infant_price, 2) }} {{ $pricing->currency }}</span>
                                </div>
                            @endif
                            @if($pricing->room_capacity)
                                <div class="price-item">
                                    <span class="price-label">Oda Kapasitesi</span>
                                    <span class="price-value">{{ $pricing->room_capacity }} kişi</span>
                                </div>
                            @endif
                        </div>
                    </div>
                @endforeach
            </div>
        @endif

        <!-- Upcoming Dates -->
        @if($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>Başlangıç</th>
                                <th>Bitiş</th>
                                <th>Kontenjan</th>
                                <th>Durum</th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach($tour->upcomingDates as $date)
                                <tr>
                                    <td>{{ \Carbon\Carbon::parse($date->start_date)->format('d.m.Y') }}</td>
                                    <td>{{ \Carbon\Carbon::parse($date->end_date)->format('d.m.Y') }}</td>
                                    <td>{{ $date->available_seats }} / {{ $date->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
    </div>
@endsection
