<?php

namespace App\Modules\Bookings;

use Illuminate\Support\Facades\View;
use App\Models\User;
use App\Models\Severity;
use Illuminate\Support\Facades\Redirect;
use App\Http\Controllers\BaseController;

class MessagesController extends BaseController
{
    /**
     *	The layout that should be used for responses.
     */
    protected $layout = 'layouts.master';

    /**
     *	Returns the index page.
     */
    public function getIndex($id = 0)
    {
        if (! $id) {
            return Redirect::to('/');
        }

        $message = Message::find($id);

        // Redirect back to the dashboard if the ID was not found
        if (! $message) {
            return Redirect::to('/');
        }

        $severities = [];
        foreach (Severity::all() as $severity) {
            $severities[$severity->id] = $severity->name;
        }

        $data = [
            'users'   => User::with('profile_photo')->get(),
            'message' => $message,
        ];

        $this->layout->content = View::make('bookings::messages.index', $data);
    }
}
