@extends('layouts.app')
@section('title','Discipline Case — '.$discipline->case_number)
@section('page-title','Discipline Management')
@section('content')
<div class="page-header">
    <div class="d-flex align-items-center justify-content-between flex-wrap gap-2">
        <div class="d-flex align-items-center gap-2">
            <a href="{{ route('discipline.index') }}" class="btn btn-sm btn-outline-secondary"><i class="bi bi-arrow-left"></i></a>
            <div><h1>{{ $discipline->case_number }}</h1>
            <nav aria-label="breadcrumb"><ol class="breadcrumb"><li class="breadcrumb-item"><a href="{{ route('discipline.index') }}">Discipline</a></li><li class="breadcrumb-item active">{{ $discipline->case_number }}</li></ol></nav></div>
        </div>
        <span class="badge bg-{{ $discipline->status==='open'?'danger':($discipline->status==='resolved'?'secondary':'success') }} fs-6">{{ ucfirst($discipline->status) }}</span>
    </div>
</div>
<div class="row g-3">
    <div class="col-12 col-lg-8">
        <div class="card mb-3">
            <div class="card-header"><i class="bi bi-shield-exclamation me-2" style="color:var(--ul-primary);"></i>Case Details</div>
            <div class="card-body">
                <div class="row g-3">
                    <div class="col-6 col-md-4"><div style="font-size:.65rem;color:var(--text-2);font-weight:700;text-transform:uppercase;letter-spacing:.06em;">Employee</div><div class="fw-semibold mt-1">{{ $discipline->employee->full_name ?? '—' }}</div><div style="font-size:.75rem;color:var(--text-2);">{{ $discipline->employee->employee_number ?? '' }}</div></div>
                    <div class="col-6 col-md-4"><div style="font-size:.65rem;color:var(--text-2);font-weight:700;text-transform:uppercase;letter-spacing:.06em;">Department</div><div class="fw-semibold mt-1">{{ $discipline->employee->department->name ?? '—' }}</div></div>
                    <div class="col-6 col-md-4"><div style="font-size:.65rem;color:var(--text-2);font-weight:700;text-transform:uppercase;letter-spacing:.06em;">Infraction Type</div><div class="mt-1"><span style="font-weight:700;font-size:.85rem;">{{ $discipline->infraction_type }}</span></div></div>
                    <div class="col-6 col-md-4"><div style="font-size:.65rem;color:var(--text-2);font-weight:700;text-transform:uppercase;letter-spacing:.06em;">Incident Date</div><div class="fw-semibold mt-1">{{ $discipline->incident_date?->format('F j, Y') }}</div></div>
                    <div class="col-6 col-md-4"><div style="font-size:.65rem;color:var(--text-2);font-weight:700;text-transform:uppercase;letter-spacing:.06em;">Reported By</div><div class="fw-semibold mt-1">{{ $discipline->reportedBy->name ?? '—' }}</div></div>
                    <div class="col-6 col-md-4"><div style="font-size:.65rem;color:var(--text-2);font-weight:700;text-transform:uppercase;letter-spacing:.06em;">Case Date</div><div class="fw-semibold mt-1">{{ $discipline->created_at->format('M j, Y') }}</div></div>
                    <div class="col-12"><div style="font-size:.65rem;color:var(--text-2);font-weight:700;text-transform:uppercase;letter-spacing:.06em;">Description</div><div class="mt-1" style="font-size:.87rem;line-height:1.65;">{{ $discipline->description }}</div></div>
                    @if($discipline->evidence)<div class="col-12"><div style="font-size:.65rem;color:var(--text-2);font-weight:700;text-transform:uppercase;letter-spacing:.06em;">Evidence / Witnesses</div><div class="mt-1" style="font-size:.87rem;">{{ $discipline->evidence }}</div></div>@endif
                </div>
            </div>
        </div>
        @if($discipline->status === 'open' && auth()->user()->isHrOrAdmin())
        <div class="card">
            <div class="card-header"><i class="bi bi-gavel me-2" style="color:var(--ul-primary);"></i>Record Disciplinary Action</div>
            <div class="card-body">
                <form method="POST" action="{{ route('discipline.action',$discipline) }}">
                    @csrf
                    <div class="row g-3">
                        <div class="col-6"><label class="form-label">Action Taken *</label>
                            <select name="action_taken" class="form-select" required>
                                <option value="">— Select —</option>
                                @foreach(['verbal_warning'=>'Verbal Warning','written_warning'=>'Written Warning','suspension'=>'Suspension','demotion'=>'Demotion','termination'=>'Termination'] as $val=>$label)
                                <option value="{{ $val }}">{{ $label }}</option>
                                @endforeach
                            </select>
                        </div>
                        <div class="col-6"><label class="form-label">Action Date *</label><input type="date" name="action_date" class="form-control" value="{{ today()->format('Y-m-d') }}" required></div>
                        <div class="col-12"><label class="form-label">Action Details *</label><textarea name="action_details" class="form-control" rows="3" required placeholder="Describe the action taken and any conditions…"></textarea></div>
                        <div class="col-6"><label class="form-label">Suspension Days (if applicable)</label><input type="number" name="suspension_days" class="form-control" min="0"></div>
                    </div>
                    <div class="mt-3 d-flex gap-2">
                        <button type="submit" class="btn btn-primary"><i class="bi bi-gavel me-1"></i>Record Action</button>
                        <form method="POST" action="{{ route('discipline.close',$discipline) }}" class="d-inline">
                            @csrf<button type="submit" class="btn btn-outline-secondary" onclick="return confirm('Close this case without action?')">Close Case</button>
                        </form>
                    </div>
                </form>
            </div>
        </div>
        @elseif($discipline->action_taken)
        <div class="card">
            <div class="card-header"><i class="bi bi-gavel me-2" style="color:var(--ul-primary);"></i>Action Taken</div>
            <div class="card-body">
                <div class="row g-3">
                    <div class="col-6"><div style="font-size:.65rem;color:var(--text-2);font-weight:700;text-transform:uppercase;letter-spacing:.06em;">Action</div>
                        <span class="badge bg-{{ in_array($discipline->action_taken,['termination','suspension'])?'danger':'secondary' }} mt-1">{{ ucfirst(str_replace('_',' ',$discipline->action_taken)) }}</span></div>
                    <div class="col-6"><div style="font-size:.65rem;color:var(--text-2);font-weight:700;text-transform:uppercase;letter-spacing:.06em;">Action Date</div><div class="fw-semibold mt-1">{{ $discipline->action_date?->format('M j, Y') }}</div></div>
                    <div class="col-12"><div style="font-size:.65rem;color:var(--text-2);font-weight:700;text-transform:uppercase;letter-spacing:.06em;">Details</div><div class="mt-1">{{ $discipline->action_details }}</div></div>
                    @if($discipline->handledBy)<div class="col-12"><div style="font-size:.65rem;color:var(--text-2);font-weight:700;text-transform:uppercase;letter-spacing:.06em;">Handled By</div><div class="fw-semibold mt-1">{{ $discipline->handledBy->name }}</div></div>@endif
                </div>
            </div>
        </div>
        @endif
    </div>
    <div class="col-12 col-lg-4">
        <div class="card">
            <div class="card-header" style="font-size:.85rem;"><i class="bi bi-person me-2" style="color:var(--ul-primary);"></i>Employee Info</div>
            <div class="card-body">
                <div class="d-flex align-items-center gap-3 mb-3">
                    <div class="avatar avatar-md" style="background:linear-gradient(135deg,var(--ul-primary),var(--ul-accent));color:#fff;">
                        {{ strtoupper(substr($discipline->employee->first_name??'?',0,1).substr($discipline->employee->last_name??'',0,1)) }}
                    </div>
                    <div>
                        <div class="fw-bold">{{ $discipline->employee->full_name ?? '—' }}</div>
                        <div style="font-size:.78rem;color:var(--text-2);">{{ $discipline->employee->position ?? '' }}</div>
                    </div>
                </div>
                <a href="{{ route('employees.show',$discipline->employee) }}" class="btn btn-sm btn-outline-primary w-100">
                    <i class="bi bi-person me-1"></i>View Full Profile
                </a>
            </div>
        </div>
    </div>
</div>
@endsection
