<?php

namespace App\Controllers\Panel;

class JobsPanelController extends PanelController
{
    public function index()
    {
        $user = $this->currentUser();
        if ($user->isCandidate()) {
            $categories = \Config\Database::connect()->table('job_categories')->orderBy('name', 'ASC')->get()->getResultArray();
            return view('panel/jobs/browse', $this->panelData(['title' => 'Browse Jobs', 'categories' => $categories]));
        }
        $this->requireAgency();
        return view('panel/jobs/index', $this->panelData(['title' => 'Jobs']));
    }

    public function create()
    {
        $this->requireAgency();
        return view('panel/jobs/form', $this->panelData(['title' => 'Post a Job', 'job' => null]));
    }

    public function edit(int $id)
    {
        $this->requireAgency();
        return view('panel/jobs/form', $this->panelData(['title' => 'Edit Job', 'jobId' => $id]));
    }

    public function show(int $id)
    {
        $this->requireAgency();
        return view('panel/jobs/detail', $this->panelData(['title' => 'Job Detail', 'jobId' => $id]));
    }
}
