<?php

namespace App\Http\Controllers\Website;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redirect;
use App\Models\About_us_section;
use App\Models\Partener;
use App\Models\Service;
use App\Models\Slider;
use App\Models\Team;
use App\Models\Why_choose_us_section;

class HomeController extends Controller
{
    public function index()
    {
        $slides = Slider::orderBy('order', 'asc')->get();
		$services = Service::orderBy('order')->get();
        $parteners = Partener::all();
        $why_choose_us_sections = Why_choose_us_section::orderBy('order')->get();

        return view('website.home')->with([
            'slides' => $slides,
            'services' => $services,
            'parteners' => $parteners,
            'why_choose_us_sections' => $why_choose_us_sections,
        ]);
    }

    public function chooseLang($lang)
    {
        ($lang == 'ar') ? app()->setLocale('ar') : app()->setLocale('en');
        
        session()->put('locale', $lang);
        return Redirect::back();
    }

    public function about()
    {
        $sections = About_us_section::orderBy('order')->get();
        $parteners = Partener::all();
        $teams = Team::orderBy('order')->get();

        return view('website.pages.about')->with([
            'sections' => $sections,
            'parteners' => $parteners,
            'teams' => $teams,
        ]);
    }

    public function contact()
    {
        return view('website.pages.contact');
    }

    public function servicePage($service_name)
    {
        $service = Service::HasPageDetails()->where('name_en', $service_name)->first();
        return $service 
            ? view('website.pages.service')->with('service', $service)
            : abort('404');
    }
}
