<?php

namespace App\Http\Controllers;

use App\Models\Meeting;
use App\Models\MeetingParticipant;
use Illuminate\Http\Request;
use App\Models\Pro;

class ProController extends Controller
{

    public function dashboard(Request $request){
        return view('pro.dashboard', ['sessionKey' => $request->cookie('sessionKey')]);
    }

    public function index(){
        $pros = Pro::all();
        return view('pro.index', compact('pros'));
    }

    public function create(){
        return view('pro.create');
    }

    public function show($uid, Request $request){
        $pro = Pro::where('uid', $uid)->first();
        return view('pro.show', compact('pro'));
    }

    public function meeting(Request $request, $meetingID) {
        $meeting = Meeting::where('uid', $meetingID)->first();
        if(!$meeting) {
            return abort(404, "Meeting no longer active");
        }
        $participants = MeetingParticipant::where('meeting_id', $meeting->id)->get();
        foreach ($participants as $participant) {
            $participant->proName = $participant->proName(); // eager-fill proName
        }
        return view('meeting', [
            'meetingID' => $meetingID,
            'participants' => $participants,
            'guest' => false
        ]);
    }
}
