<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Auth;

class WebsiteController extends Controller
{

    public function __construct()
    {
        $this->setLang($_COOKIE['lang'] ?? 'de');
    }

    private function setLang($lang)
    {
        if (!in_array($lang, ['de', 'en'])) {
            $lang = 'de';
        }

        App::setLocale($lang);
    }

    //
    public function index(Request $request)
    {
        return view('content.index');
    }

    public function about(Request $request){
        return view('content.about');
    }

    public function contact(Request $request){
        return view('content.contact');
    }

    public function imprint(Request $request){
        return view('content.imprint');
    }

    public function news(Request $request){
        return view('content.news', ['blogs' => BlogController::blogPaginated(App::getLocale(), true)]);
    }

    public function services(Request $request){
        return view('content.services');
    }

    public function apply(Request $request){
        return view('application.apply');
    }


    // c3gov-Stuffs

    public function showRegister()
    {
        return view('login.register');
    }

    public function showLogin()
    {
        return view('login.login');
    }

    public function editTicker(){
        if(Auth::check()){
            return view('ticker.edit');
        }
        abort(404);
    }

    public function editNews(){
        if(Auth::check()){
            return response()
                ->view('blog.edit', ['blogs' => BlogController::blogPaginatedEdit()])
                ->header('Cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
        }
        abort(404);
    }
}
