@extends('layouts.app')

@section('title', __('vetAdmission::lang.ward_board'))

@section('css')
<style>
.vb-grid { display:grid; grid-template-columns:repeat(auto-fill,minmax(260px,1fr)); gap:14px; }
.vb-ward { background:#fff; border:1px solid #e5e9f0; border-radius:10px; overflow:hidden; }
.vb-ward-head { padding:9px 13px; font-weight:700; color:#fff; display:flex; justify-content:space-between; align-items:center; }
.vb-ward-body { padding:10px 13px; min-height:60px; }
.vb-occ { display:block; padding:7px 9px; border-radius:7px; background:#f8fafc; margin-bottom:6px;
    font-size:12px; text-decoration:none; color:#1e293b; border:1px solid #eef1f5; }
.vb-occ:hover { background:#eff6ff; color:#1e293b; text-decoration:none; }
.vb-empty { color:#94a3b8; font-size:12px; font-style:italic; }
.vb-cap { font-size:11px; font-weight:600; padding:2px 8px; border-radius:10px; background:rgba(255,255,255,.25); }
</style>
@endsection

@section('content')
<section class="content-header">
    <h1><i class="fas fa-th"></i> @lang('vetAdmission::lang.ward_board')
        <small>Live in-patient occupancy</small>
    </h1>
</section>

<section class="content">
    <div style="margin-bottom:12px;">
        <a href="{{ route('va.admissions.index') }}" class="btn btn-default btn-sm"><i class="fa fa-list"></i> Admissions List</a>
        <a href="{{ route('va.admissions.create') }}" class="btn btn-primary btn-sm"><i class="fa fa-plus"></i> @lang('vetAdmission::lang.new_admission')</a>
    </div>

    <div class="vb-grid">
        @foreach($wards as $ward)
            @php
                $occ  = $ward->currentAdmissions->count();
                $full = $ward->capacity > 0 && $occ >= $ward->capacity;
                $head = $full ? '#ef4444' : ($occ > 0 ? '#f59e0b' : '#22c55e');
            @endphp
            <div class="vb-ward">
                <div class="vb-ward-head" style="background:{{ $head }};">
                    <span><i class="fa fa-hospital"></i> {{ $ward->name }}</span>
                    <span class="vb-cap">{{ $occ }} / {{ $ward->capacity }}</span>
                </div>
                <div class="vb-ward-body">
                    @forelse($ward->currentAdmissions as $a)
                        <a href="{{ route('va.admissions.flowsheet', $a->id) }}" class="vb-occ"
                           title="Open flowsheet">
                            <strong><i class="fa fa-paw"></i> {{ optional($a->pet)->petname ?? '—' }}</strong><br>
                            <small class="text-muted">
                                {{ optional($a->owner)->name }} · {{ ucfirst(str_replace('_',' ',$a->type)) }}
                                · {{ $a->stay_days }}d
                            </small>
                        </a>
                    @empty
                        <span class="vb-empty">Empty</span>
                    @endforelse
                </div>
            </div>
        @endforeach
    </div>

    @if($unassigned->isNotEmpty())
        <h4 style="margin-top:22px;"><i class="fa fa-exclamation-triangle text-warning"></i> Admitted — No Ward Assigned</h4>
        <div class="vb-grid">
            @foreach($unassigned as $a)
                <a href="{{ route('va.admissions.show', $a->id) }}" class="vb-occ" style="display:block;">
                    <strong><i class="fa fa-paw"></i> {{ optional($a->pet)->petname ?? '—' }}</strong><br>
                    <small class="text-muted">{{ optional($a->owner)->name }} · {{ $a->admission_no }}</small>
                </a>
            @endforeach
        </div>
    @endif

    @if($wards->isEmpty())
        <div class="callout callout-info">
            No wards defined yet. Add wards/cages from <strong>Vet Clinic → Wards &amp; Cages</strong>.
        </div>
    @endif
</section>
@endsection
