@extends('layouts.app')

@section('title', 'Request Details')

@section('content')
<div class="content-wrapper">
    <div class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <h1 class="m-0">Request Details</h1>
                </div>
                <div class="col-sm-6">
                    <div class="float-sm-right">
                        <a href="{{ route('requests.index') }}" class="btn btn-default">
                            <i class="fas fa-arrow-left"></i> Back to List
                        </a>
                        @if(auth()->user()->isAdmin() || auth()->user()->isOperation())
                            <a href="{{ route('requests.edit', $request) }}" class="btn btn-primary">
                                <i class="fas fa-edit"></i> Edit Request
                            </a>
                        @endif
                    </div>
                </div>
            </div>
        </div>
    </div>

    <section class="content">
        <div class="container-fluid">
            <div class="row">
                <div class="col-md-8">
                    <div class="card">
                        <div class="card-header">
                            <h3 class="card-title">Request Information</h3>
                        </div>
                        <div class="card-body">
                            <div class="row">
                                <div class="col-md-6">
                                    <dl>
                                        <dt>Request ID</dt>
                                        <dd>{{ $request->id }}</dd>

                                        <dt>Request Type</dt>
                                        <dd>{{ $request->requestType->name }}</dd>

                                        <dt>Status</dt>
                                        <dd>
                                            <span class="badge badge-{{ $request->status === 'pending' ? 'warning' : ($request->status === 'in_progress' ? 'info' : ($request->status === 'completed' ? 'success' : 'danger')) }}">
                                                {{ ucfirst($request->status) }}
                                            </span>
                                        </dd>

                                        <dt>Created At</dt>
                                        <dd>{{ $request->created_at->format('M d, Y H:i') }}</dd>
                                    </dl>
                                </div>
                                <div class="col-md-6">
                                    <dl>
                                        <dt>Owner</dt>
                                        <dd>{{ $request->user->name }}</dd>

                                        <dt>Owner Email</dt>
                                        <dd>{{ $request->user->email }}</dd>

                                        <dt>Owner Phone</dt>
                                        <dd>{{ $request->user->phone }}</dd>

                                        @if($request->completed_at)
                                            <dt>Completed At</dt>
                                            <dd>{{ $request->completed_at->format('M d, Y H:i') }}</dd>
                                        @endif
                                    </dl>
                                </div>
                            </div>

                            <div class="row mt-4">
                                <div class="col-12">
                                    <h5>Request Note</h5>
                                    <div class="p-3 bg-light rounded">
                                        {{ $request->note }}
                                    </div>
                                </div>
                            </div>

                            @if($request->admin_note)
                                <div class="row mt-4">
                                    <div class="col-12">
                                        <h5>Admin Note</h5>
                                        <div class="p-3 bg-light rounded">
                                            {{ $request->admin_note }}
                                        </div>
                                    </div>
                                </div>
                            @endif
                        </div>
                    </div>
                </div>

                <div class="col-md-4">
                    <div class="card">
                        <div class="card-header">
                            <h3 class="card-title">Status History</h3>
                        </div>
                        <div class="card-body">
                            <div class="timeline">
                                <div class="time-label">
                                    <span class="bg-primary">{{ $request->created_at->format('M d, Y') }}</span>
                                </div>
                                <div>
                                    <i class="fas fa-plus bg-primary"></i>
                                    <div class="timeline-item">
                                        <span class="time"><i class="fas fa-clock"></i> {{ $request->created_at->format('H:i') }}</span>
                                        <h3 class="timeline-header">Request Created</h3>
                                    </div>
                                </div>

                                @if($request->status !== 'pending')
                                    <div>
                                        <i class="fas fa-edit bg-info"></i>
                                        <div class="timeline-item">
                                            <span class="time"><i class="fas fa-clock"></i> {{ $request->updated_at->format('H:i') }}</span>
                                            <h3 class="timeline-header">Status Updated to {{ ucfirst($request->status) }}</h3>
                                        </div>
                                    </div>
                                @endif

                                @if($request->completed_at)
                                    <div>
                                        <i class="fas fa-check bg-success"></i>
                                        <div class="timeline-item">
                                            <span class="time"><i class="fas fa-clock"></i> {{ $request->completed_at->format('H:i') }}</span>
                                            <h3 class="timeline-header">Request Completed</h3>
                                        </div>
                                    </div>
                                @endif
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
</div>
@endsection 