@extends('layouts.app')

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

@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">Edit Request</h1>
                </div>
                <div class="col-sm-6">
                    <div class="float-sm-right">
                        <a href="{{ route('requests.show', $request) }}" class="btn btn-default">
                            <i class="fas fa-arrow-left"></i> Back to Details
                        </a>
                    </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">Update Request</h3>
                        </div>
                        <form action="{{ route('requests.update', $request) }}" method="POST">
                            @csrf
                            @method('PUT')
                            <div class="card-body">
                                <div class="form-group">
                                    <label for="status">Status</label>
                                    <select name="status" id="status" class="form-control @error('status') is-invalid @enderror">
                                        <option value="pending" {{ $request->status === 'pending' ? 'selected' : '' }}>Pending</option>
                                        <option value="in_progress" {{ $request->status === 'in_progress' ? 'selected' : '' }}>In Progress</option>
                                        <option value="completed" {{ $request->status === 'completed' ? 'selected' : '' }}>Completed</option>
                                        <option value="cancelled" {{ $request->status === 'cancelled' ? 'selected' : '' }}>Cancelled</option>
                                    </select>
                                    @error('status')
                                        <span class="invalid-feedback">{{ $message }}</span>
                                    @enderror
                                </div>

                                <div class="form-group">
                                    <label for="admin_note">Admin Note</label>
                                    <textarea name="admin_note" id="admin_note" rows="4" class="form-control @error('admin_note') is-invalid @enderror">{{ old('admin_note', $request->admin_note) }}</textarea>
                                    @error('admin_note')
                                        <span class="invalid-feedback">{{ $message }}</span>
                                    @enderror
                                </div>
                            </div>
                            <div class="card-footer">
                                <button type="submit" class="btn btn-primary">Update Request</button>
                            </div>
                        </form>
                    </div>
                </div>

                <div class="col-md-4">
                    <div class="card">
                        <div class="card-header">
                            <h3 class="card-title">Request Information</h3>
                        </div>
                        <div class="card-body">
                            <dl>
                                <dt>Request ID</dt>
                                <dd>{{ $request->id }}</dd>

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

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

                                <dt>Created At</dt>
                                <dd>{{ $request->created_at->format('M d, Y H:i') }}</dd>

                                <dt>Current 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>
                            </dl>

                            <div class="mt-4">
                                <h5>Request Note</h5>
                                <div class="p-3 bg-light rounded">
                                    {{ $request->note }}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
</div>
@endsection 