@extends('agency.layouts.app')

@section('title', $tour->name . ' - Genel Bilgiler')
@section('page_title', 'Günübirlik Tur Düzenle')

@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' => ''],
        ['title' => 'Genel Bilgiler', 'url' => '']
    ];
@endphp

@push('styles')
    <!-- Quill Rich Text Editor CSS -->
    <link href="https://cdn.quilljs.com/1.3.6/quill.snow.css" rel="stylesheet">
    <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: 28px;
            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;
        }

        .tabs-container {
            background: white;
            border: 1px solid var(--gray-200);
            border-radius: var(--radius-xl);
            overflow: hidden;
            margin-bottom: 2rem;
        }

        .nav-tabs {
            background: var(--gray-50);
            border-bottom: 1px solid var(--gray-200);
            padding: 0 1rem;
            margin: 0;
        }

        .nav-tabs .nav-link {
            border: none;
            border-radius: 0;
            color: var(--gray-600);
            font-weight: 500;
            padding: 1rem 1.5rem;
            position: relative;
            transition: var(--transition);
        }

        .nav-tabs .nav-link:hover {
            color: var(--primary-color);
            background: transparent;
            border-color: transparent;
        }

        .nav-tabs .nav-link.active {
            color: var(--primary-color);
            background: transparent;
            border-color: transparent;
            font-weight: 600;
        }

        .nav-tabs .nav-link.active::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            right: 0;
            height: 3px;
            background: var(--primary-color);
            border-radius: 3px 3px 0 0;
        }

        .tab-content {
            padding: 2rem;
        }

        .form-section {
            background: white;
            border: 1px solid var(--gray-200);
            border-radius: var(--radius-lg);
            padding: 2rem;
            margin-bottom: 2rem;
        }

        .section-header {
            margin-bottom: 2rem;
            padding-bottom: 1rem;
            border-bottom: 2px solid var(--gray-200);
        }

        .section-title {
            font-size: 1.25rem;
            font-weight: 700;
            color: var(--gray-900);
            margin: 0;
            display: flex;
            align-items: center;
            gap: 0.75rem;
        }

        .section-icon {
            color: var(--primary-color);
            font-size: 1.5rem;
        }

        .form-group {
            margin-bottom: 1.5rem;
        }

        .form-label {
            font-weight: 600;
            color: var(--gray-900);
            margin-bottom: 0.5rem;
            display: block;
        }

        .form-text {
            font-size: 0.875rem;
            color: var(--gray-600);
            margin-top: 0.25rem;
        }

        .quill-editor-container {
            background: white;
            border: 1px solid var(--gray-300);
            border-radius: var(--radius-lg);
        }

        .ql-toolbar {
            border: none !important;
            border-bottom: 1px solid var(--gray-200) !important;
            background: var(--gray-50);
        }

        .ql-container {
            border: none !important;
            min-height: 200px;
            font-size: 14px;
        }

        .actions-bar {
            position: sticky;
            bottom: 0;
            background: white;
            border-top: 2px solid var(--gray-200);
            padding: 1.5rem 2rem;
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin: -2rem -2rem 0;
            border-radius: 0 0 var(--radius-xl) var(--radius-xl);
        }

        .weekdays-selection {
            display: flex;
            gap: 1rem;
            flex-wrap: wrap;
            padding: 1rem;
            background: var(--gray-50);
            border-radius: var(--radius-lg);
            margin-bottom: 0.5rem;
        }

        .weekday-checkbox {
            display: flex;
            align-items: center;
            gap: 0.5rem;
            padding: 0.5rem 1rem;
            background: white;
            border: 2px solid var(--gray-300);
            border-radius: var(--radius-md);
            cursor: pointer;
            transition: var(--transition);
        }

        .weekday-checkbox:hover {
            border-color: var(--primary-color);
        }

        .weekday-checkbox input[type="checkbox"]:checked ~ label,
        .weekday-checkbox:has(input[type="checkbox"]:checked) {
            border-color: var(--primary-color);
            background: var(--primary-light);
        }

        .weekday-checkbox input[type="checkbox"] {
            cursor: pointer;
        }

        .weekday-checkbox label {
            cursor: pointer;
            margin-bottom: 0;
            font-weight: 500;
            color: var(--gray-700);
        }
    </style>
@endpush

@section('content')
    <div class="tour-detail-container">
        <!-- Tour Header -->
        <div class="tour-header">
            <div class="tour-header-content">
                <div class="tour-code">Tur Kodu: {{ $tour->code }}</div>
                <h1 class="tour-title">{{ $tour->name }}</h1>
                <div class="tour-meta">
                    <div class="tour-meta-item">
                        <i class="fas fa-map-marker-alt tour-meta-icon"></i>
                        {{ $tour->departureCity->city ?? 'Belirtilmemiş' }}
                        → {{ $tour->arrivalCity->city ?? 'Belirtilmemiş' }}
                    </div>
                    <div class="tour-meta-item">
                        <i class="fas fa-clock tour-meta-icon"></i>
                        {{ substr($tour->start_time, 0, 5) }} - {{ substr($tour->end_time, 0, 5) }}
                    </div>
                    <div class="tour-meta-item">
                        <i class="fas fa-dollar-sign tour-meta-icon"></i>
                        {{ number_format($tour->adult_price, 0) }} {{ $tour->currency }}
                    </div>
                </div>
            </div>
        </div>

        <!-- Tabs Container -->
        <div class="tabs-container">
            <!-- Tab Navigation -->
            @include('agency.products.gunubirlik-turlar._nav', ['active' => 'general'])

            <!-- Tab Content -->
            <div class="tab-content">
                <form method="POST" action="{{ route('agency.products.gunubirlik-turlar.update-general', $tour) }}" id="generalForm">
                    @csrf
                    @method('PUT')

                    <!-- Basic Information Section -->
                    <div class="form-section" id="basic-info">
                        <div class="section-header">
                            <h3 class="section-title">
                                <i class="fas fa-info-circle section-icon"></i>
                                Temel Bilgiler
                            </h3>
                        </div>

                        <div class="row">
                            <div class="col-md-8">
                                <div class="form-group">
                                    <label class="form-label">Tur Adı</label>
                                    <input type="text" name="name" class="form-control"
                                           value="{{ old('name', $tour->name) }}" required>
                                    @error('name')
                                    <div class="text-danger small mt-1">{{ $message }}</div>
                                    @enderror
                                </div>
                            </div>
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label class="form-label">Tur Tipi</label>
                                    <select name="tour_type" class="form-select" required>
                                        <option value="domestic" {{ old('tour_type', $tour->tour_type) === 'domestic' ? 'selected' : '' }}>
                                            Yurt İçi
                                        </option>
                                        <option value="international" {{ old('tour_type', $tour->tour_type) === 'international' ? 'selected' : '' }}>
                                            Yurt Dışı
                                        </option>
                                    </select>
                                    @error('tour_type')
                                    <div class="text-danger small mt-1">{{ $message }}</div>
                                    @enderror
                                </div>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="form-label">Kısa Açıklama</label>
                            <textarea name="short_description" class="form-control" rows="3"
                                      maxlength="500">{{ old('short_description', $tour->short_description) }}</textarea>
                            <div class="form-text">Maksimum 500 karakter</div>
                            @error('short_description')
                            <div class="text-danger small mt-1">{{ $message }}</div>
                            @enderror
                        </div>

                        <div class="form-group">
                            <label class="form-label">Detaylı Açıklama</label>
                            <div class="quill-editor-container">
                                <div id="editor-description"></div>
                            </div>
                            <input type="hidden" name="description" id="description-input"
                                   value="{{ old('description', $tour->description) }}">
                            @error('description')
                            <div class="text-danger small mt-1">{{ $message }}</div>
                            @enderror
                        </div>
                    </div>

                    <!-- Location & Time Section -->
                    <div class="form-section" id="location-time">
                        <div class="section-header">
                            <h3 class="section-title">
                                <i class="fas fa-map-marker-alt section-icon"></i>
                                Konum ve Zaman
                            </h3>
                        </div>

                        <div class="row">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="form-label">Kalkış Şehri</label>
                                    <select name="departure_city_id" class="form-select" required>
                                        <option value="">Seçiniz</option>
                                        @foreach($cities as $city)
                                            <option value="{{ $city->id }}"
                                                {{ old('departure_city_id', $tour->departure_city_id) == $city->id ? 'selected' : '' }}>
                                                {{ $city->city }}
                                            </option>
                                        @endforeach
                                    </select>
                                    @error('departure_city_id')
                                    <div class="text-danger small mt-1">{{ $message }}</div>
                                    @enderror
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="form-label">Varış Şehri</label>
                                    <select name="arrival_city_id" class="form-select" required>
                                        <option value="">Seçiniz</option>
                                        @foreach($cities as $city)
                                            <option value="{{ $city->id }}"
                                                {{ old('arrival_city_id', $tour->arrival_city_id) == $city->id ? 'selected' : '' }}>
                                                {{ $city->city }}
                                            </option>
                                        @endforeach
                                    </select>
                                    @error('arrival_city_id')
                                    <div class="text-danger small mt-1">{{ $message }}</div>
                                    @enderror
                                </div>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="form-label">Başlangıç Saati</label>
                                    <input type="time" name="start_time" class="form-control"
                                           value="{{ old('start_time', $tour->start_time ? substr($tour->start_time, 0, 5) : '') }}" required>
                                    @error('start_time')
                                    <div class="text-danger small mt-1">{{ $message }}</div>
                                    @enderror
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="form-label">Bitiş Saati</label>
                                    <input type="time" name="end_time" class="form-control"
                                           value="{{ old('end_time', $tour->end_time ? substr($tour->end_time, 0, 5) : '') }}" required>
                                    @error('end_time')
                                    <div class="text-danger small mt-1">{{ $message }}</div>
                                    @enderror
                                </div>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="form-label">Tekrar Eden Günler</label>
                            <div class="weekdays-selection">
                                @php
                                    $weekdays = [
                                        'monday' => 'Pazartesi',
                                        'tuesday' => 'Salı',
                                        'wednesday' => 'Çarşamba',
                                        'thursday' => 'Perşembe',
                                        'friday' => 'Cuma',
                                        'saturday' => 'Cumartesi',
                                        'sunday' => 'Pazar',
                                    ];
                                    $selectedDays = old('recurring_days', $tour->recurring_days ?? []);
                                @endphp
                                @foreach($weekdays as $key => $name)
                                    <div class="weekday-checkbox">
                                        <input type="checkbox" name="recurring_days[]" id="day_{{ $key }}"
                                               value="{{ $key }}"
                                               {{ in_array($key, $selectedDays) ? 'checked' : '' }}
                                               class="form-check-input">
                                        <label for="day_{{ $key }}" class="form-check-label">{{ $name }}</label>
                                    </div>
                                @endforeach
                            </div>
                            <div class="form-text">Turun tekrar edeceği günleri seçin. Seçili günlerde otomatik tarihler oluşturulacaktır.</div>
                            @error('recurring_days')
                            <div class="text-danger small mt-1">{{ $message }}</div>
                            @enderror
                        </div>
                    </div>

                    <!-- Features Section -->
                    <div class="form-section" id="features">
                        <div class="section-header">
                            <h3 class="section-title">
                                <i class="fas fa-star section-icon"></i>
                                Özellikler
                            </h3>
                        </div>

                        <div class="form-group">
                            <label class="form-label">Gezilecek Yerler</label>
                            <div class="quill-editor-container">
                                <div id="editor-places-to-visit"></div>
                            </div>
                            <input type="hidden" name="places_to_visit" id="places-to-visit-input"
                                   value="{{ old('places_to_visit', $tour->places_to_visit) }}">
                            <div class="form-text">Tur kapsamında gezilecek yerleri listeleyin</div>
                            @error('places_to_visit')
                            <div class="text-danger small mt-1">{{ $message }}</div>
                            @enderror
                        </div>

                        <div class="row">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="form-label">Dahil Edilen Hizmetler</label>
                                    @if(isset($inclusionsTemplates) && $inclusionsTemplates->count() > 0)
                                        <select class="form-select mb-2" id="inclusionsTemplateSelect">
                                            <option value="">Şablon Seç (Opsiyonel)</option>
                                            @foreach($inclusionsTemplates as $template)
                                                <option value="{{ $template->id }}" data-content="{{ $template->description }}">
                                                    {{ $template->name }}
                                                </option>
                                            @endforeach
                                        </select>
                                    @endif
                                    <div class="quill-editor-container">
                                        <div id="editor-inclusions"></div>
                                    </div>
                                    <input type="hidden" name="inclusions" id="inclusions-input"
                                           value="{{ old('inclusions', $tour->inclusions) }}">
                                    <div class="form-text">Tur fiyatına dahil olan hizmetleri listeleyin</div>
                                    @error('inclusions')
                                    <div class="text-danger small mt-1">{{ $message }}</div>
                                    @enderror
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="form-label">Dahil Edilmeyen Hizmetler</label>
                                    @if(isset($exclusionsTemplates) && $exclusionsTemplates->count() > 0)
                                        <select class="form-select mb-2" id="exclusionsTemplateSelect">
                                            <option value="">Şablon Seç (Opsiyonel)</option>
                                            @foreach($exclusionsTemplates as $template)
                                                <option value="{{ $template->id }}" data-content="{{ $template->description }}">
                                                    {{ $template->name }}
                                                </option>
                                            @endforeach
                                        </select>
                                    @endif
                                    <div class="quill-editor-container">
                                        <div id="editor-exclusions"></div>
                                    </div>
                                    <input type="hidden" name="exclusions" id="exclusions-input"
                                           value="{{ old('exclusions', $tour->exclusions) }}">
                                    <div class="form-text">Tur fiyatına dahil olmayan hizmetleri belirtin</div>
                                    @error('exclusions')
                                    <div class="text-danger small mt-1">{{ $message }}</div>
                                    @enderror
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- Capacity Section -->
                    <div class="form-section" id="capacity">
                        <div class="section-header">
                            <h3 class="section-title">
                                <i class="fas fa-users section-icon"></i>
                                Kapasite ve Yaş Sınırlamaları
                            </h3>
                        </div>

                        <div class="row">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="form-label">Minimum Katılımcı</label>
                                    <input type="number" name="min_participants" class="form-control"
                                           value="{{ old('min_participants', $tour->min_participants) }}" min="1" required>
                                    @error('min_participants')
                                    <div class="text-danger small mt-1">{{ $message }}</div>
                                    @enderror
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="form-label">Maksimum Katılımcı</label>
                                    <input type="number" name="max_participants" class="form-control"
                                           value="{{ old('max_participants', $tour->max_participants) }}" min="1">
                                    <div class="form-text">Boş bırakırsanız sınırsız olur</div>
                                    @error('max_participants')
                                    <div class="text-danger small mt-1">{{ $message }}</div>
                                    @enderror
                                </div>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="form-label">Minimum Yaş</label>
                                    <input type="number" name="min_age" class="form-control"
                                           value="{{ old('min_age', $tour->min_age) }}" min="0">
                                    @error('min_age')
                                    <div class="text-danger small mt-1">{{ $message }}</div>
                                    @enderror
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="form-label">Maksimum Yaş</label>
                                    <input type="number" name="max_age" class="form-control"
                                           value="{{ old('max_age', $tour->max_age) }}" min="1">
                                    @error('max_age')
                                    <div class="text-danger small mt-1">{{ $message }}</div>
                                    @enderror
                                </div>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label class="form-label">Zorluk Seviyesi</label>
                                    <select name="difficulty_level" class="form-select" required>
                                        <option value="easy" {{ old('difficulty_level', $tour->difficulty_level) === 'easy' ? 'selected' : '' }}>
                                            Kolay
                                        </option>
                                        <option value="moderate" {{ old('difficulty_level', $tour->difficulty_level) === 'moderate' ? 'selected' : '' }}>
                                            Orta
                                        </option>
                                        <option value="challenging" {{ old('difficulty_level', $tour->difficulty_level) === 'challenging' ? 'selected' : '' }}>
                                            Zorlu
                                        </option>
                                        <option value="extreme" {{ old('difficulty_level', $tour->difficulty_level) === 'extreme' ? 'selected' : '' }}>
                                            Çok Zorlu
                                        </option>
                                    </select>
                                    @error('difficulty_level')
                                    <div class="text-danger small mt-1">{{ $message }}</div>
                                    @enderror
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- Policies Section -->
                    <div class="form-section" id="policies">
                        <div class="section-header">
                            <h3 class="section-title">
                                <i class="fas fa-file-contract section-icon"></i>
                                Politikalar ve Şartlar
                            </h3>
                        </div>

                        <div class="form-group">
                            <label class="form-label">İptal Politikası</label>
                            @if(isset($cancellationPolicies) && $cancellationPolicies->count() > 0)
                                <select class="form-select mb-2" id="cancellationPolicySelect">
                                    <option value="">Şablon Seç (Opsiyonel)</option>
                                    @foreach($cancellationPolicies as $template)
                                        <option value="{{ $template->id }}" data-content="{{ $template->description }}">
                                            {{ $template->name }}
                                        </option>
                                    @endforeach
                                </select>
                            @endif
                            <div class="quill-editor-container">
                                <div id="editor-cancellation-policy"></div>
                            </div>
                            <input type="hidden" name="cancellation_policy" id="cancellation-policy-input"
                                   value="{{ old('cancellation_policy', $tour->cancellation_policy) }}">
                            @error('cancellation_policy')
                            <div class="text-danger small mt-1">{{ $message }}</div>
                            @enderror
                        </div>

                        <div class="form-group">
                            <label class="form-label">Şartlar ve Koşullar</label>
                            @if(isset($termsConditions) && $termsConditions->count() > 0)
                                <select class="form-select mb-2" id="termsConditionsSelect">
                                    <option value="">Şablon Seç (Opsiyonel)</option>
                                    @foreach($termsConditions as $template)
                                        <option value="{{ $template->id }}" data-content="{{ $template->description }}">
                                            {{ $template->name }}
                                        </option>
                                    @endforeach
                                </select>
                            @endif
                            <div class="quill-editor-container">
                                <div id="editor-terms-conditions"></div>
                            </div>
                            <input type="hidden" name="terms_conditions" id="terms-conditions-input"
                                   value="{{ old('terms_conditions', $tour->terms_conditions) }}">
                            @error('terms_conditions')
                            <div class="text-danger small mt-1">{{ $message }}</div>
                            @enderror
                        </div>
                    </div>

                    <!-- Actions Bar -->
                    <div class="actions-bar">
                        <div class="actions-bar-info">
                            Son güncelleme: {{ $tour->updated_at->diffForHumans() }}
                        </div>
                        <div class="d-flex gap-2">
                            <a href="{{ route('agency.products.gunubirlik-turlar.index') }}" class="btn btn-outline-secondary">
                                İptal
                            </a>
                            <button type="submit" class="btn btn-primary">
                                <i class="fas fa-save me-2"></i>
                                Değişiklikleri Kaydet
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
@endsection

@push('scripts')
    <!-- Quill Rich Text Editor JS -->
    <script src="https://cdn.quilljs.com/1.3.6/quill.js"></script>
    <script>
        document.addEventListener('DOMContentLoaded', function () {
            const toolbarOptions = [
                ['bold', 'italic', 'underline', 'strike'],
                ['blockquote', 'code-block'],
                [{'list': 'ordered'}, {'list': 'bullet'}],
                [{'header': [1, 2, 3, 4, 5, 6, false]}],
                [{'color': []}, {'background': []}],
                [{'align': []}],
                ['link'],
                ['clean']
            ];

            // Description Editor
            const descriptionEditor = new Quill('#editor-description', {
                theme: 'snow',
                modules: {toolbar: toolbarOptions},
                placeholder: 'Turun detaylı açıklamasını yazın...'
            });

            const descriptionInput = document.getElementById('description-input');
            if (descriptionInput.value) {
                descriptionEditor.root.innerHTML = descriptionInput.value;
            }
            descriptionEditor.on('text-change', function () {
                descriptionInput.value = descriptionEditor.root.innerHTML;
            });

            // Places to Visit Editor
            const placesToVisitEditor = new Quill('#editor-places-to-visit', {
                theme: 'snow',
                modules: {toolbar: toolbarOptions},
                placeholder: 'Gezilecek yerleri yazın...'
            });

            const placesToVisitInput = document.getElementById('places-to-visit-input');
            if (placesToVisitInput.value) {
                placesToVisitEditor.root.innerHTML = placesToVisitInput.value;
            }
            placesToVisitEditor.on('text-change', function () {
                placesToVisitInput.value = placesToVisitEditor.root.innerHTML;
            });

            // Inclusions Editor
            const inclusionsEditor = new Quill('#editor-inclusions', {
                theme: 'snow',
                modules: {toolbar: toolbarOptions},
                placeholder: 'Dahil olan hizmetleri yazın...'
            });

            const inclusionsInput = document.getElementById('inclusions-input');
            if (inclusionsInput.value) {
                inclusionsEditor.root.innerHTML = inclusionsInput.value;
            }
            inclusionsEditor.on('text-change', function () {
                inclusionsInput.value = inclusionsEditor.root.innerHTML;
            });

            // Exclusions Editor
            const exclusionsEditor = new Quill('#editor-exclusions', {
                theme: 'snow',
                modules: {toolbar: toolbarOptions},
                placeholder: 'Dahil olmayan hizmetleri yazın...'
            });

            const exclusionsInput = document.getElementById('exclusions-input');
            if (exclusionsInput.value) {
                exclusionsEditor.root.innerHTML = exclusionsInput.value;
            }
            exclusionsEditor.on('text-change', function () {
                exclusionsInput.value = exclusionsEditor.root.innerHTML;
            });

            // Cancellation Policy Editor
            const cancellationPolicyEditor = new Quill('#editor-cancellation-policy', {
                theme: 'snow',
                modules: {toolbar: toolbarOptions},
                placeholder: 'İptal politikasını yazın...'
            });

            const cancellationPolicyInput = document.getElementById('cancellation-policy-input');
            if (cancellationPolicyInput.value) {
                cancellationPolicyEditor.root.innerHTML = cancellationPolicyInput.value;
            }
            cancellationPolicyEditor.on('text-change', function () {
                cancellationPolicyInput.value = cancellationPolicyEditor.root.innerHTML;
            });

            // Terms Conditions Editor
            const termsConditionsEditor = new Quill('#editor-terms-conditions', {
                theme: 'snow',
                modules: {toolbar: toolbarOptions},
                placeholder: 'Şartlar ve koşulları yazın...'
            });

            const termsConditionsInput = document.getElementById('terms-conditions-input');
            if (termsConditionsInput.value) {
                termsConditionsEditor.root.innerHTML = termsConditionsInput.value;
            }
            termsConditionsEditor.on('text-change', function () {
                termsConditionsInput.value = termsConditionsEditor.root.innerHTML;
            });

            // Template selects
            const inclusionsTemplateSelect = document.getElementById('inclusionsTemplateSelect');
            if (inclusionsTemplateSelect) {
                inclusionsTemplateSelect.addEventListener('change', function () {
                    const selectedOption = this.options[this.selectedIndex];
                    if (selectedOption.value) {
                        const content = selectedOption.getAttribute('data-content');
                        inclusionsEditor.root.innerHTML = content || '';
                        inclusionsInput.value = content || '';
                    }
                });
            }

            const exclusionsTemplateSelect = document.getElementById('exclusionsTemplateSelect');
            if (exclusionsTemplateSelect) {
                exclusionsTemplateSelect.addEventListener('change', function () {
                    const selectedOption = this.options[this.selectedIndex];
                    if (selectedOption.value) {
                        const content = selectedOption.getAttribute('data-content');
                        exclusionsEditor.root.innerHTML = content || '';
                        exclusionsInput.value = content || '';
                    }
                });
            }

            const cancellationPolicySelect = document.getElementById('cancellationPolicySelect');
            if (cancellationPolicySelect) {
                cancellationPolicySelect.addEventListener('change', function () {
                    const selectedOption = this.options[this.selectedIndex];
                    if (selectedOption.value) {
                        const content = selectedOption.getAttribute('data-content');
                        cancellationPolicyEditor.root.innerHTML = content || '';
                        cancellationPolicyInput.value = content || '';
                    }
                });
            }

            const termsConditionsSelect = document.getElementById('termsConditionsSelect');
            if (termsConditionsSelect) {
                termsConditionsSelect.addEventListener('change', function () {
                    const selectedOption = this.options[this.selectedIndex];
                    if (selectedOption.value) {
                        const content = selectedOption.getAttribute('data-content');
                        termsConditionsEditor.root.innerHTML = content || '';
                        termsConditionsInput.value = content || '';
                    }
                });
            }

        });
    </script>
@endpush
