<?php

namespace App\Http\Controllers\Web;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

use App\User;
use Notification;
use App\Notifications\ArticlesNotification;
use App\Http\Requests\MailRequest;

use Config;
use Illuminate\View\View;
use App\Slider;
use App\Mail;
use App\About;
use App\Article;
use App\Review;
use App\Service;

class HomeController extends Controller
{
    private $view = 'web.pages.';
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        // $this->middleware('auth')->except('lang');
    }

    /**
     * Show the application dashboard.
     * @return View
     */
    public function index(): View
    {
        $sliders = Slider::cursor(); 
        $about = About::where('id','1')->first();
        $allservices = Service::orderBy('id','DESC')->get();
        $count = Service::count();
        if($count == 0){
            $count = 1;
        }
        $part = $count/8;
        $services = collect();
        $counter =0; 
         for($i=0;$i<$part;$i++){
              $services->push(collect());
        }
         $counters = 0;
        for($x=0;$x<count($allservices);$x++){
            if($x%8 == 0 && $x != 0){
                $counters++;
            }
            $services[$counters]->push($allservices[$x]);
        }
        $doctors = User::where('role_id','4')->get();
       $articles = Article::inRandomOrder()->limit(2)->get();
        $main_article = Article::inRandomOrder()->limit(1)->first();
        $reviews = Review::inRandomOrder()->limit(3)->get();
        return view($this->view.'index',compact('sliders','about','services','doctors','articles','main_article','reviews'));
    }
    public function mailsend(MailRequest $request){
        Mail::create($request->all());
        return redirect()->back();
    }
}
