@php
    $types = \App\Models\Page::getSectionTypes();
    $data = $data ?? [];
    $sourceData = $sourceData ?? [];
    $sourceItems = $sourceData['items'] ?? [];
@endphp
<div class="text-sm text-slate-600 mb-1">{{ $types[$type]['label'] ?? $type }} — Section {{ $index + 1 }}</div>
@if($type === 'hero')
    <div class="space-y-2">
        <input type="text" name="translations[{{ $locale }}][sections][{{ $index }}][data][title]" value="{{ $data['title'] ?? '' }}" placeholder="Titre" class="w-full border border-slate-200 rounded-lg px-3 py-2 text-sm">
        <input type="text" name="translations[{{ $locale }}][sections][{{ $index }}][data][subtitle]" value="{{ $data['subtitle'] ?? '' }}" placeholder="Sous-titre" class="w-full border border-slate-200 rounded-lg px-3 py-2 text-sm">
        <input type="text" name="translations[{{ $locale }}][sections][{{ $index }}][data][cta_text]" value="{{ $data['cta_text'] ?? '' }}" placeholder="Texte bouton" class="w-full border border-slate-200 rounded-lg px-3 py-2 text-sm">
    </div>
@elseif($type === 'text')
    @php $tidTrText = 'trix-tr-'.$locale.'-text-'.$index.'-'.\Illuminate\Support\Str::random(12); @endphp
    <textarea id="{{ $tidTrText }}" name="translations[{{ $locale }}][sections][{{ $index }}][data][content]" class="hidden" rows="1" autocomplete="off">{{ \App\Support\SafeHtml::normalizeStoredRichText($data['content'] ?? '') }}</textarea>
    <trix-editor input="{{ $tidTrText }}" class="trix-content w-full min-h-[120px] border border-slate-200 rounded-lg px-3 py-2 text-sm prose prose-sm max-w-none"></trix-editor>
@elseif(in_array($type, ['image', 'text_image']))
    <div class="space-y-2">
        @if($type === 'text_image')
            @php $tidTrTi = 'trix-tr-'.$locale.'-ti-'.$index.'-'.\Illuminate\Support\Str::random(12); @endphp
            <input type="text" name="translations[{{ $locale }}][sections][{{ $index }}][data][title]" value="{{ $data['title'] ?? '' }}" placeholder="Titre" class="w-full border border-slate-200 rounded-lg px-3 py-2 text-sm">
            <textarea id="{{ $tidTrTi }}" name="translations[{{ $locale }}][sections][{{ $index }}][data][content]" class="hidden" rows="1" autocomplete="off">{{ \App\Support\SafeHtml::normalizeStoredRichText($data['content'] ?? '') }}</textarea>
            <trix-editor input="{{ $tidTrTi }}" class="trix-content w-full min-h-[100px] border border-slate-200 rounded-lg px-3 py-2 text-sm prose prose-sm max-w-none"></trix-editor>
            <input type="text" name="translations[{{ $locale }}][sections][{{ $index }}][data][cta_text]" value="{{ $data['cta_text'] ?? '' }}" placeholder="Texte bouton" class="w-full border border-slate-200 rounded-lg px-3 py-2 text-sm">
        @endif
        <input type="text" name="translations[{{ $locale }}][sections][{{ $index }}][data][alt]" value="{{ $data['alt'] ?? '' }}" placeholder="Texte alternatif" class="w-full border border-slate-200 rounded-lg px-3 py-2 text-sm">
    </div>
@elseif($type === 'features')
    <div class="space-y-2">
        <input type="text" name="translations[{{ $locale }}][sections][{{ $index }}][data][title]" value="{{ $data['title'] ?? '' }}" placeholder="Titre section" class="w-full border border-slate-200 rounded-lg px-3 py-2 text-sm">
        @foreach($sourceItems ?: ($data['items'] ?? []) as $i => $item)
            @php $trItem = ($data['items'] ?? [])[$i] ?? []; @endphp
            <div class="pl-2 border-l-2 border-slate-200 space-y-1">
                <input type="text" name="translations[{{ $locale }}][sections][{{ $index }}][data][items][{{ $i }}][title]" value="{{ $trItem['title'] ?? '' }}" placeholder="Titre item" class="w-full border border-slate-200 rounded px-2 py-1 text-sm">
                <input type="text" name="translations[{{ $locale }}][sections][{{ $index }}][data][items][{{ $i }}][text]" value="{{ $trItem['text'] ?? '' }}" placeholder="Description" class="w-full border border-slate-200 rounded px-2 py-1 text-sm">
            </div>
        @endforeach
    </div>
@elseif($type === 'stats')
    <div class="space-y-2">
        <input type="text" name="translations[{{ $locale }}][sections][{{ $index }}][data][title]" value="{{ $data['title'] ?? '' }}" placeholder="Titre (optionnel)" class="w-full border border-slate-200 rounded-lg px-3 py-2 text-sm">
        @foreach($sourceItems ?: ($data['items'] ?? []) as $i => $item)
            @php $trItem = ($data['items'] ?? [])[$i] ?? []; @endphp
            <input type="text" name="translations[{{ $locale }}][sections][{{ $index }}][data][items][{{ $i }}][label]" value="{{ $trItem['label'] ?? '' }}" placeholder="Label" class="w-full border border-slate-200 rounded px-2 py-1 text-sm">
        @endforeach
    </div>
@elseif($type === 'testimonials')
    <div class="space-y-2">
        <input type="text" name="translations[{{ $locale }}][sections][{{ $index }}][data][title]" value="{{ $data['title'] ?? '' }}" placeholder="Titre" class="w-full border border-slate-200 rounded-lg px-3 py-2 text-sm">
        @foreach($sourceItems ?: ($data['items'] ?? []) as $i => $item)
            @php $trItem = ($data['items'] ?? [])[$i] ?? []; @endphp
            <div class="pl-2 border-l-2 border-slate-200 space-y-1">
                <input type="text" name="translations[{{ $locale }}][sections][{{ $index }}][data][items][{{ $i }}][name]" value="{{ $trItem['name'] ?? '' }}" placeholder="Nom" class="w-full border border-slate-200 rounded px-2 py-1 text-sm">
                <input type="text" name="translations[{{ $locale }}][sections][{{ $index }}][data][items][{{ $i }}][role]" value="{{ $trItem['role'] ?? '' }}" placeholder="Rôle" class="w-full border border-slate-200 rounded px-2 py-1 text-sm">
                <textarea name="translations[{{ $locale }}][sections][{{ $index }}][data][items][{{ $i }}][text]" rows="2" placeholder="Témoignage" class="w-full border border-slate-200 rounded px-2 py-1 text-sm">{{ $trItem['text'] ?? '' }}</textarea>
            </div>
        @endforeach
    </div>
@elseif($type === 'team')
    <div class="space-y-2">
        <input type="text" name="translations[{{ $locale }}][sections][{{ $index }}][data][title]" value="{{ $data['title'] ?? '' }}" placeholder="Titre" class="w-full border border-slate-200 rounded-lg px-3 py-2 text-sm">
        @foreach($sourceItems ?: ($data['items'] ?? []) as $i => $item)
            @php $trItem = ($data['items'] ?? [])[$i] ?? []; @endphp
            <div class="pl-2 border-l-2 border-slate-200 space-y-1">
                <input type="text" name="translations[{{ $locale }}][sections][{{ $index }}][data][items][{{ $i }}][name]" value="{{ $trItem['name'] ?? '' }}" placeholder="Nom" class="w-full border border-slate-200 rounded px-2 py-1 text-sm">
                <input type="text" name="translations[{{ $locale }}][sections][{{ $index }}][data][items][{{ $i }}][role]" value="{{ $trItem['role'] ?? '' }}" placeholder="Poste" class="w-full border border-slate-200 rounded px-2 py-1 text-sm">
            </div>
        @endforeach
    </div>
@elseif($type === 'faq')
    <div class="space-y-2">
        <input type="text" name="translations[{{ $locale }}][sections][{{ $index }}][data][title]" value="{{ $data['title'] ?? '' }}" placeholder="Titre" class="w-full border border-slate-200 rounded-lg px-3 py-2 text-sm">
        @foreach($sourceItems ?: ($data['items'] ?? []) as $i => $item)
            @php $trItem = ($data['items'] ?? [])[$i] ?? []; @endphp
            <div class="pl-2 border-l-2 border-slate-200 space-y-1">
                <input type="text" name="translations[{{ $locale }}][sections][{{ $index }}][data][items][{{ $i }}][question]" value="{{ $trItem['question'] ?? '' }}" placeholder="Question" class="w-full border border-slate-200 rounded px-2 py-1 text-sm">
                <textarea name="translations[{{ $locale }}][sections][{{ $index }}][data][items][{{ $i }}][answer]" rows="2" placeholder="Réponse" class="w-full border border-slate-200 rounded px-2 py-1 text-sm">{{ $trItem['answer'] ?? '' }}</textarea>
            </div>
        @endforeach
    </div>
@elseif($type === 'cta')
    <div class="space-y-2">
        <input type="text" name="translations[{{ $locale }}][sections][{{ $index }}][data][title]" value="{{ $data['title'] ?? '' }}" placeholder="Titre" class="w-full border border-slate-200 rounded-lg px-3 py-2 text-sm">
        <input type="text" name="translations[{{ $locale }}][sections][{{ $index }}][data][text]" value="{{ $data['text'] ?? '' }}" placeholder="Texte" class="w-full border border-slate-200 rounded-lg px-3 py-2 text-sm">
        <input type="text" name="translations[{{ $locale }}][sections][{{ $index }}][data][button_text]" value="{{ $data['button_text'] ?? '' }}" placeholder="Texte bouton" class="w-full border border-slate-200 rounded-lg px-3 py-2 text-sm">
    </div>
@elseif($type === 'contact')
    <div class="space-y-2">
        <input type="text" name="translations[{{ $locale }}][sections][{{ $index }}][data][title]" value="{{ $data['title'] ?? '' }}" placeholder="Titre" class="w-full border border-slate-200 rounded-lg px-3 py-2 text-sm">
        <textarea name="translations[{{ $locale }}][sections][{{ $index }}][data][text]" rows="2" placeholder="Texte intro" class="w-full border border-slate-200 rounded-lg px-3 py-2 text-sm">{{ $data['text'] ?? '' }}</textarea>
    </div>
@elseif($type === 'carousel')
    <div class="space-y-2">
        <input type="text" name="translations[{{ $locale }}][sections][{{ $index }}][data][title]" value="{{ $data['title'] ?? '' }}" placeholder="Titre" class="w-full border border-slate-200 rounded-lg px-3 py-2 text-sm">
        @foreach($sourceItems ?: ($data['items'] ?? []) as $i => $item)
            @php $trItem = ($data['items'] ?? [])[$i] ?? []; @endphp
            <div class="pl-2 border-l-2 border-slate-200 space-y-1">
                <input type="text" name="translations[{{ $locale }}][sections][{{ $index }}][data][items][{{ $i }}][title]" value="{{ $trItem['title'] ?? '' }}" placeholder="Titre" class="w-full border border-slate-200 rounded px-2 py-1 text-sm">
                <input type="text" name="translations[{{ $locale }}][sections][{{ $index }}][data][items][{{ $i }}][caption]" value="{{ $trItem['caption'] ?? '' }}" placeholder="Légende" class="w-full border border-slate-200 rounded px-2 py-1 text-sm">
            </div>
        @endforeach
    </div>
@elseif($type === 'gallery')
    <div class="space-y-2">
        <input type="text" name="translations[{{ $locale }}][sections][{{ $index }}][data][title]" value="{{ $data['title'] ?? '' }}" placeholder="Titre" class="w-full border border-slate-200 rounded-lg px-3 py-2 text-sm">
        @foreach($sourceItems ?: ($data['items'] ?? []) as $i => $item)
            @php $trItem = ($data['items'] ?? [])[$i] ?? []; @endphp
            <div class="pl-2 border-l-2 border-slate-200 space-y-1">
                <input type="text" name="translations[{{ $locale }}][sections][{{ $index }}][data][items][{{ $i }}][title]" value="{{ $trItem['title'] ?? '' }}" placeholder="Titre" class="w-full border border-slate-200 rounded px-2 py-1 text-sm">
                <input type="text" name="translations[{{ $locale }}][sections][{{ $index }}][data][items][{{ $i }}][caption]" value="{{ $trItem['caption'] ?? '' }}" placeholder="Légende" class="w-full border border-slate-200 rounded px-2 py-1 text-sm">
            </div>
        @endforeach
    </div>
@elseif($type === 'pricing')
    <div class="space-y-2">
        <input type="text" name="translations[{{ $locale }}][sections][{{ $index }}][data][title]" value="{{ $data['title'] ?? '' }}" placeholder="Titre" class="w-full border border-slate-200 rounded-lg px-3 py-2 text-sm">
        @foreach($sourceItems ?: ($data['items'] ?? []) as $i => $item)
            @php $trItem = ($data['items'] ?? [])[$i] ?? []; @endphp
            <div class="pl-2 border-l-2 border-slate-200 space-y-1">
                <input type="text" name="translations[{{ $locale }}][sections][{{ $index }}][data][items][{{ $i }}][name]" value="{{ $trItem['name'] ?? '' }}" placeholder="Nom offre" class="w-full border border-slate-200 rounded px-2 py-1 text-sm">
                <textarea name="translations[{{ $locale }}][sections][{{ $index }}][data][items][{{ $i }}][features]" rows="2" placeholder="Fonctionnalités" class="w-full border border-slate-200 rounded px-2 py-1 text-sm">{{ is_array($trItem['features'] ?? null) ? implode("\n", $trItem['features']) : ($trItem['features'] ?? '') }}</textarea>
                <input type="text" name="translations[{{ $locale }}][sections][{{ $index }}][data][items][{{ $i }}][button_text]" value="{{ $trItem['button_text'] ?? '' }}" placeholder="Texte bouton" class="w-full border border-slate-200 rounded px-2 py-1 text-sm">
            </div>
        @endforeach
    </div>
@elseif($type === 'timeline')
    <div class="space-y-2">
        <input type="text" name="translations[{{ $locale }}][sections][{{ $index }}][data][title]" value="{{ $data['title'] ?? '' }}" placeholder="Titre" class="w-full border border-slate-200 rounded-lg px-3 py-2 text-sm">
        @foreach($sourceItems ?: ($data['items'] ?? []) as $i => $item)
            @php $trItem = ($data['items'] ?? [])[$i] ?? []; @endphp
            <div class="pl-2 border-l-2 border-slate-200 space-y-1">
                <input type="text" name="translations[{{ $locale }}][sections][{{ $index }}][data][items][{{ $i }}][title]" value="{{ $trItem['title'] ?? '' }}" placeholder="Titre" class="w-full border border-slate-200 rounded px-2 py-1 text-sm">
                <textarea name="translations[{{ $locale }}][sections][{{ $index }}][data][items][{{ $i }}][description]" rows="2" placeholder="Description" class="w-full border border-slate-200 rounded px-2 py-1 text-sm">{{ $trItem['description'] ?? '' }}</textarea>
            </div>
        @endforeach
    </div>
@elseif(in_array($type, ['video', 'logos']))
    <div class="space-y-2">
        <input type="text" name="translations[{{ $locale }}][sections][{{ $index }}][data][title]" value="{{ $data['title'] ?? '' }}" placeholder="Titre" class="w-full border border-slate-200 rounded-lg px-3 py-2 text-sm">
        @if($type === 'video')
            <input type="text" name="translations[{{ $locale }}][sections][{{ $index }}][data][caption]" value="{{ $data['caption'] ?? '' }}" placeholder="Légende" class="w-full border border-slate-200 rounded-lg px-3 py-2 text-sm">
        @else
            @foreach($sourceItems ?: ($data['items'] ?? []) as $i => $item)
                @php $trItem = ($data['items'] ?? [])[$i] ?? []; @endphp
                <input type="text" name="translations[{{ $locale }}][sections][{{ $index }}][data][items][{{ $i }}][name]" value="{{ $trItem['name'] ?? '' }}" placeholder="Nom" class="w-full border border-slate-200 rounded px-2 py-1 text-sm">
            @endforeach
        @endif
    </div>
@else
    <p class="text-slate-500 text-xs">Aucun champ traduisible pour ce type de section.</p>
@endif
