@php($errorBag = $errors ?? new \Illuminate\Support\ViewErrorBag())

@if (session('status'))
    <div class="alert alert-success d-flex align-items-center" role="alert">
        <i class="fe fe-check-circle me-2"></i>
        <div>{{ session('status') }}</div>
    </div>
@endif

@php($bulk = session('bulk_result'))
@if (is_array($bulk))
    <div class="alert {{ count($bulk['failures'] ?? []) > 0 ? 'alert-warning' : 'alert-success' }} small" role="status">
        <div class="fw-semibold mb-1">
            {{ __('operational_ui.speed.toast_summary', [
                'label' => $bulk['label'] ?? '',
                'ok' => count($bulk['succeeded'] ?? []),
                'fail' => count($bulk['failures'] ?? []),
            ]) }}
        </div>
        @foreach ($bulk['failures'] ?? [] as $row)
            <div class="text-break">#{{ $row['id'] ?? '' }} — {{ $row['message'] ?? '' }}</div>
        @endforeach
    </div>
@endif

@if (session('error'))
    <div class="alert alert-danger d-flex align-items-center" role="alert">
        <i class="fe fe-alert-triangle me-2"></i>
        <div>{{ session('error') }}</div>
    </div>
@endif

@php($planLimit = session('plan_limit_upgrade'))
@if ($planLimit)
    <div class="alert alert-warning border border-warning d-flex flex-column flex-md-row align-items-md-center justify-content-between gap-3" role="alert">
        <div class="d-flex align-items-start gap-2">
            <i class="fe fe-zap me-1 mt-1"></i>
            <div>
                <div class="fw-semibold">{{ __('plan_limits.notifications.blocked_title') }}</div>
                <div class="small mt-1">{{ is_array($planLimit) ? ($planLimit['message'] ?? '') : $planLimit }}</div>
                <div class="small text-muted mt-1">{{ __('plan_limits.upgrade_cta') }}</div>
            </div>
        </div>
        @if (is_array($planLimit) && ! empty($planLimit['url']))
            <a href="{{ $planLimit['url'] }}" class="btn btn-sm btn-primary flex-shrink-0">
                {{ __('dashboard.upgrade_plan') }}
            </a>
        @endif
    </div>
@endif

@if ($errorBag->any() && ! request()->isMethod('get'))
    <div class="alert alert-danger" role="alert">
        <div class="d-flex align-items-center mb-1">
            <i class="fe fe-alert-circle me-2"></i>
            <strong>{{ __('common.validation_failed') }}</strong>
        </div>
        <ul class="mb-0 ps-4">
            @foreach ($errorBag->all() as $error)
                <li>{{ $error }}</li>
            @endforeach
        </ul>
    </div>
@endif
