@extends('layouts.app')
@section('title', 'Findings — ' . ucwords(str_replace('_', ' ', $systemKey)))

@section('content')
<section class="content-header">
    <h1><i class="fa fa-list-ul"></i> Findings
        <small>{{ ucwords(str_replace('_', ' ', $systemKey)) }}</small></h1>
    <ol class="breadcrumb">
        <li><a href="{{ route('vc.system-findings.index') }}">System Findings</a></li>
        <li class="active">{{ ucwords(str_replace('_', ' ', $systemKey)) }}</li>
    </ol>
</section>

<section class="content">
    <div class="box box-primary">
        <div class="box-header">
            <h3 class="box-title">
                <i class="fa fa-list"></i> All Findings
                <span class="badge" style="background:#2980b9;margin-left:6px;">{{ $rows->count() }}</span>
            </h3>
            <div class="box-tools pull-right">
                <a href="{{ route('vc.system-findings.create', $systemKey) }}" class="btn btn-sm btn-primary">
                    <i class="fa fa-plus"></i> Add finding
                </a>
            </div>
        </div>
        <div class="box-body">
            <table class="table table-condensed table-striped" style="font-size:12.5px;">
                <thead>
                    <tr style="background:#f1f5f9;">
                        <th>Order</th>
                        <th>Value (key)</th>
                        <th>Label</th>
                        <th>Severity</th>
                        <th>L/R</th>
                        <th>Critical</th>
                        <th>Source</th>
                        <th>Status</th>
                        <th></th>
                    </tr>
                </thead>
                <tbody>
                @forelse($rows as $r)
                    @php $isSystem = $r->business_id === null; @endphp
                    <tr style="{{ $isSystem ? 'background:#fafafa;' : '' }}">
                        <td>{{ $r->sort_order }}</td>
                        <td><code style="font-size:11px;">{{ $r->value }}</code></td>
                        <td>{{ $r->label }}</td>
                        <td>@if($r->supports_severity)<i class="fa fa-check text-success"></i>@endif</td>
                        <td>@if($r->supports_lr)<i class="fa fa-check text-success"></i>@endif</td>
                        <td>@if($r->is_critical)<i class="fa fa-flag" style="color:#dc2626;"></i>@endif</td>
                        <td>
                            @if($isSystem)
                                <span class="label label-default">SYSTEM</span>
                            @else
                                <span class="label label-success">BUSINESS</span>
                            @endif
                        </td>
                        <td>
                            @if($r->status === 'active')
                                <span class="label label-success">Active</span>
                            @else
                                <span class="label label-default">Inactive</span>
                            @endif
                        </td>
                        <td>
                            @if(!$isSystem)
                                <a href="{{ route('vc.system-findings.edit', $r->id) }}" class="btn btn-xs btn-warning">
                                    <i class="fa fa-edit"></i>
                                </a>
                                <form method="POST" action="{{ route('vc.system-findings.destroy', $r->id) }}"
                                      style="display:inline;" onsubmit="return confirm('Delete this finding?');">
                                    @csrf @method('DELETE')
                                    <button type="submit" class="btn btn-xs btn-danger"><i class="fa fa-trash"></i></button>
                                </form>
                            @endif
                        </td>
                    </tr>
                @empty
                    <tr><td colspan="9" class="text-center text-muted" style="padding:30px;">No findings yet. Add one.</td></tr>
                @endforelse
                </tbody>
            </table>
        </div>
    </div>
</section>
@endsection
