@php
    $results = $outcome['results'] ?? [];
    $threshold = $outcome['threshold'] ?? 60;
    $matchedCount = $outcome['matched_count'] ?? 0;
    $criteria = $criteria ?? [];
    $canBook = $canBook ?? false;
    $firstDate = '';
    if (! empty($criteria['dates'])) { $firstDate = trim(explode(',', $criteria['dates'])[0]); }
@endphp

@component('components.widget', ['class' => 'box-primary'])
    <h4 style="margin-top:0">
        <strong>{{ $matchedCount }}</strong>
        @lang('bms::lang.of') {{ count($results) }} @lang('bms::lang.halls')
        — @lang('bms::lang.matches_at') {{ $threshold }}%
    </h4>

    @forelse($results as $r)
        @php
            $matched = $r['matched'];
            $score = $r['score'];
            $barClass = $matched ? 'progress-bar-success' : ($score >= ($threshold - 20) ? 'progress-bar-warning' : 'progress-bar-danger');
        @endphp
        <div class="bms-match-row" style="border:1px solid #eee;border-radius:6px;padding:12px;margin-bottom:10px;{{ $matched ? 'background:#f6fff6' : '' }}">
            <div class="row">
                <div class="col-md-6">
                    <strong style="font-size:15px;">{{ $r['hall_name'] }}</strong>
                    @if($matched)
                        <span class="label label-success">@lang('bms::lang.match')</span>
                    @else
                        <span class="label label-default">@lang('bms::lang.below_threshold')</span>
                    @endif
                    <br>
                    <small class="text-muted">{{ $r['venue_name'] ?? '—' }}</small>
                </div>
                <div class="col-md-6">
                    <div class="progress" style="margin-bottom:4px;">
                        <div class="progress-bar {{ $barClass }}" role="progressbar" style="width: {{ $score }}%;">
                            {{ $score }}%
                        </div>
                    </div>
                    @if($canBook)
                        <a href="{{ route('bms.bookings.create', array_filter(['hall_id' => $r['hall_id'], 'attendees' => $criteria['attendees'] ?? null, 'event_date' => $firstDate ?: null])) }}"
                           class="tw-dw-btn tw-dw-btn-xs tw-dw-btn-primary tw-text-white pull-right">
                            <i class="fa fa-plus"></i> @lang('bms::lang.create_booking_btn')
                        </a>
                    @endif
                </div>
            </div>

            @if(! empty($r['reasons']))
                <div style="margin-top:8px;">
                    <small class="{{ $matched ? 'text-muted' : 'text-danger' }}">
                        <i class="fa fa-info-circle"></i>
                        {{ $matched ? __('bms::lang.notes') : __('bms::lang.why_not') }}:
                    </small>
                    <ul style="margin:4px 0 0;padding-left:20px;">
                        @foreach($r['reasons'] as $reason)
                            <li><small class="{{ $matched ? 'text-muted' : 'text-danger' }}">{{ $reason }}</small></li>
                        @endforeach
                    </ul>
                </div>
            @endif
        </div>
    @empty
        <p class="text-muted">@lang('bms::lang.no_halls')</p>
    @endforelse
@endcomponent
