@props([
    'section',              // App\Support\Witness\WitnessSection
    'answers' => [],        // buffer [section][question]
    'answerMeta' => null,   // keyed collection "section.question" => WitnessStatementAnswer
    'sectionProgress' => null, // ['answered','total','percent']
    'editingAnswerId' => null,
    'editingValue' => '',
    'bare' => false,        // true = render inside an accordion (no card/header)
    'validationRequested' => false,
    'touched' => [],
])

@php
    $buffer = $answers[$section->key] ?? [];
@endphp

<x-dynamic-component :component="$bare ? 'witness.section-shell-bare' : 'witness.section-shell-card'"
    :section="$section"
    :section-progress="$sectionProgress">

    @if($section->description)
        <p class="text-muted small">{{ $section->description }}</p>
    @endif

    @if($section->acceptsEvidence())
        <div class="text-muted small mb-3">
            <span class="mdi mdi-shield-search" aria-hidden="true"></span>
            Evidence-backed section — confirmed findings appear as suggestions.
        </div>
    @endif

    @foreach($section->questions as $question)
        @php $meta = $answerMeta?->get("{$section->key}.{$question->key}"); @endphp

        @if($meta && $meta->review_status === 'suggested')
            <div class="mb-3">
                <x-witness.suggested-answer
                    :answer="$meta"
                    :question="$question"
                    :editing-answer-id="$editingAnswerId"
                    :editing-value="$editingValue" />
            </div>
        @else
            <x-witness.question-field
                :question="$question"
                :section-key="$section->key"
                :value="$buffer[$question->key] ?? null"
                :meta="$meta"
                :validation-requested="$validationRequested"
                :touched="$touched" />
        @endif
    @endforeach
</x-dynamic-component>
