@extends('layouts.app')
@section('title', $case->case_number.' | Case')
@section('content')
<main class="nxl-container"><div class="nxl-content"><div class="page-header d-flex justify-content-between"><div><h5>{{ $case->case_number }} — {{ $case->subject }}</h5><small>Assigned to {{ $case->assignee?->name ?: 'Unassigned' }}</small></div><a class="btn btn-light" href="{{ route('cases.index') }}">All Cases</a></div><div class="main-content">
@if(session('success'))<div class="alert alert-success">{{ session('success') }}</div>@endif @if($errors->any())<div class="alert alert-danger">{{ $errors->first() }}</div>@endif
<ul class="nav nav-tabs mb-3"><li class="nav-item"><a class="nav-link active" data-bs-toggle="tab" href="#details">Details</a></li><li class="nav-item"><a class="nav-link" data-bs-toggle="tab" href="#comments">Comments & Resolution</a></li><li class="nav-item"><a class="nav-link" data-bs-toggle="tab" href="#attachments">Attachments</a></li><li class="nav-item"><a class="nav-link" data-bs-toggle="tab" href="#history">Case History</a></li></ul>
<div class="tab-content"><div class="tab-pane fade show active" id="details"><div class="card"><div class="card-body"><form method="POST" action="{{ route('cases.update',$case) }}" class="row g-3">@csrf @method('PUT')
<div class="col-md-8"><label class="form-label">Subject</label><input class="form-control" name="subject" value="{{ $case->subject }}"></div><div class="col-md-4"><label class="form-label">Category</label><input class="form-control" name="category" value="{{ $case->category }}"></div>
<x-case-remote-select name="account_id" label="Account" type="account" :selected="old('account_id', $case->account_id)" />
<x-case-remote-select name="contact_id" label="Contact" type="contact" :selected="old('contact_id', $case->contact_id)" />
<x-case-remote-select name="lead_id" label="Lead" type="lead" :selected="old('lead_id', $case->lead_id)" />
<x-case-remote-select name="deal_id" label="Deal" type="deal" :selected="old('deal_id', $case->deal_id)" />
<x-case-remote-select name="assigned_to" label="Employee" type="user" :selected="old('assigned_to', $case->assigned_to)" none="Unassigned" />
<div class="col-md-3"><label class="form-label">Priority</label><select class="form-select" name="priority">@foreach(['low','medium','high','urgent'] as $s)<option @selected($case->priority===$s)>{{ $s }}</option>@endforeach</select></div><div class="col-md-3"><label class="form-label">Status</label><select class="form-select" name="status">@foreach(['new','in_progress','waiting','resolved','closed'] as $s)<option @selected($case->status===$s)>{{ $s }}</option>@endforeach</select></div><div class="col-md-3"><label class="form-label">Due</label><input type="datetime-local" class="form-control" name="due_at" value="{{ $case->due_at?->format('Y-m-d\\TH:i') }}"></div>
<div class="col-12"><label class="form-label">Description</label><textarea class="form-control" name="description">{{ $case->description }}</textarea></div><div class="col-12"><label class="form-label">Resolution (required for Resolved/Closed)</label><textarea class="form-control" name="resolution">{{ $case->resolution }}</textarea></div><div class="col-12"><label class="form-label">Change comment</label><input class="form-control" name="change_comment"></div><div class="col-12"><button class="btn btn-primary">Update Case</button></div>
</form></div></div></div>
<div class="tab-pane fade" id="comments"><div class="card"><div class="card-body"><form method="POST" action="{{ route('cases.comments.store',$case) }}" class="d-flex gap-2 mb-4">@csrf<textarea class="form-control" name="comment" placeholder="Add comment" required></textarea><button class="btn btn-primary">Add</button></form>@forelse($case->comments as $comment)<div class="border rounded p-3 mb-2 @if($comment->is_resolution) border-success @endif"><strong>{{ $comment->is_resolution?'Resolution':'Comment' }} by {{ $comment->user?->name }}</strong><small class="float-end">{{ $comment->created_at->format('M d, Y H:i') }}</small><div>{{ $comment->comment }}</div></div>@empty<div class="text-muted">No comments or resolution history.</div>@endforelse</div></div></div>
<div class="tab-pane fade" id="attachments"><div class="card"><div class="card-body"><x-crm-file-manager module="cases" :record="$case" /></div></div></div>
<div class="tab-pane fade" id="history"><div class="card"><div class="card-body">@forelse($case->histories as $h)<div class="border-start border-primary ps-3 pb-4"><strong>{{ ucwords(str_replace('_',' ',$h->action)) }}</strong><span class="float-end">{{ $h->created_at->format('M d, Y H:i') }}</span><small class="d-block text-muted">{{ $h->from_status }} @if($h->to_status)→ {{ $h->to_status }}@endif by {{ $h->user?->name }}</small><div>{{ $h->comment }}</div></div>@empty<div class="text-muted">No Case history.</div>@endforelse</div></div></div>
</div><x-crm-related-workflows module="cases" :record="$case" /><x-unified-operational-timeline module="cases" :record="$case" /></div></div></main>
@include('cases.partials.remote-select-script')
@endsection
