<?php

namespace App\Http\Controllers\Web;

use App\Http\Controllers\Controller;
use App\Models\Contact;
use App\Models\Email;
use App\Models\Gallery;
use App\Models\Partner;
use App\Models\MenuCategory;
use App\Models\Menyu;
use App\Models\MenyuGallery;
use App\Models\Room;
use App\Models\RoomCategory;
use App\Models\RoomGallery;
use App\Models\Service;
use App\Models\Speed;
use App\Models\Ticket;
use App\Traits\Description;
use App\Traits\Image;
use App\Traits\Title;
use App\Traits\Titles;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;

class WebController extends Controller
{

    use Image,Description,Title,Titles;


    //layout
    public function home(){
        $galleries = Gallery::all();
        $menuCategories = MenuCategory::where('show_in_main', 1)->get();
        $room_categories_categories =RoomCategory::where('option','room')->get();
        $room_categories_images =RoomCategory::where('option','terrace')->get();
        $menyus=Menyu::all();
        return view('app.web.home.home',compact([
            'menuCategories',
            'menyus',
            'room_categories_categories',
            'room_categories_images',
            'galleries'
        ]));
    }


    public function caspian() {
        $categories = MenuCategory::where('option', 'Caspian')
            ->where('position', '1')
            ->orderByRaw('CAST(number AS UNSIGNED) ASC')
            ->get();
    
        $menyus = Menyu::where('position', '1')
            ->orderByRaw('CAST(number AS UNSIGNED) ASC')
            ->get();
    
        return view('app.web.pages.caspian.caspian', compact('categories', 'menyus'));
    }


    public function cresent(){
        $categories =MenuCategory::where('option','Cresent')->get();
        $menyus=Menyu::all();
        return view('app.web.pages.cresent.cresent',compact([
            'categories',
            'menyus'
        ]));
    }

    public function breakfast(){
        $categories =MenuCategory::where('option','Breakfast')->get();
        $menyus=Menyu::all();
        return view('app.web.pages.breakfast.breakfast',compact([
            'categories',
            'menyus'
        ]));
    }

    public function abouts(){
        return view('app.web.pages.abouts.abouts');
    }
    
    public function pro(){
        return view('app.web.pages.pro.pro');
    }


    public function vacancies(){
        $rooms=Room::all();
        return view('app.web.pages.vacancies.vacancies',compact([
            'rooms'
        ]));
    }


    public function contacts(){
        return view('app.web.pages.contacts.contacts');
    }
    
    public function qr2(){
        return view('app.web.pages.qr2.qr2');
    }

    public function galleries(){
        $galleries = Gallery::all();
        return view('app.web.pages.galleries.galleries',compact([
            'galleries'
        ]));
    }


    //categories
    public function categories(){
        $menu_nocategories =MenuCategory::whereNull('menu_parent')
        ->where('option','nocategory')
        ->get();
        $room_categories_categories =RoomCategory::where('option','room')->get();
        $room_categories_images =RoomCategory::where('option','terrace')->get();
        return view('app.web.pages.categories.categories',compact([
            'room_categories_categories',
            'room_categories_images',
            'menu_nocategories'
        ]));
    }

    public function menu_categories(Request $request){
        $categoryId =$request->input('nocategoryId');
        $menu_nocategories =MenuCategory::where('menu_parent', $categoryId)
        ->where('option','nocategory')
        ->get();
        $menu_categories =MenuCategory::whereNull('menu_parent')
        ->where('option','category')
        ->get();
        return view('app.web.pages.menuCategories.menu_categories',compact([
            'menu_categories',
            'menu_nocategories'
        ]));
    }

     //menyus
    //  public function menyus(Request $request){
    //     $categoryId =$request->input('categoryId');
    //     $category =MenuCategory::where('id',$categoryId)->first();
    //     $menyus =Menyu::all();
    //     $menyu_categories =MenuCategory::where('menu_parent',$categoryId)->get();
    //     return view('app.web.pages.menyus.menyus',compact([
    //         'menyus',
    //         'menyu_categories',
    //         'category'
    //     ]));
    // }


    //menyu
    public function menyu(Request $request){
        $menyuId =$request->input('menyuId');
        $menyu = Menyu::where('id', $menyuId)->first();
        $menyu_galleries =MenyuGallery::where('menyu_id',$menyu->id)->get();
        return view('app.web.pages.menyus.menyu',compact([
            'menyu',
            'menyu_galleries',
        ]));
    }

     //room_detail
     public function room_detail(Request $request){
        $roomId =$request->input('roomId');
        $room = Room::where('id', $roomId)->first();
        $room_galleries =RoomGallery::where('room_id',$room->getAttribute('id'))->get();
        return view('app.web.pages.rooms.room-detail',compact([
            'room',
            'room_galleries',
        ]));
    }

       //menyu Main
       public function main_menyu(Request $request){
        $categoryId = $request->input('categoryId');
        $menyu_categories = MenuCategory::where('id',$categoryId)->first();
        $menyus = Menyu::where('category_id',$categoryId)->get();
        return view('app.web.pages.menyus.main_menyu',compact([
            'menyus',
            'menyu_categories'
        ]));
    }


    public function room_category(Request $request){

        $categoryId =$request->input('categoryId');
        $rooms =Room::where('category_id',$categoryId)->get();
        $room_category =RoomCategory::where('id',$categoryId)->first();
        return view('app.web.pages.rooms.roomCategory',compact([
            'rooms',
            'room_category'
        ]));
    }

    public function room_image(Request $request){
        $imageId =$request->input('imageId');
        $rooms =Room::where('category_id',$imageId)->get();
        $room_category =RoomCategory::where('id',$imageId)->first();
        return view('app.web.pages.rooms.roomImage',compact([
            'rooms',
            'room_category'
        ]));
    }

    public function spa(){
        return view('app.web.pages.statics.spa');
    }

    public function residense(){
        return view('app.web.pages.statics.residense');
    }

    public function room1(){
        return view('app.web.pages.statics.room1');
    }

    public function room2(){
        return view('app.web.pages.statics.room2');
    }

    public function room3(){
        return view('app.web.pages.statics.room3');
    }

    public function room4(){
        return view('app.web.pages.statics.room4');
    }


    public function register_s(){
        return view('app.web.pages.statics.register_s');
    }

    public function room_s(){
        return view('app.web.pages.statics.room_s');
    }

    public function tv(){
        return view('app.web.pages.statics.tv');
    }

    public function others(){
        return view('app.web.pages.statics.others');
    }

    public function restaurant(){
        return view('app.web.pages.statics.restaurant');
    }

    public function mainroom(){
        return view('app.web.pages.statics.mainroom');
    }





    //Services
    public function services()
    {
        $services = Service::all();
        $contacts = Contact::all();
        $serviceImages =Service::all();
        return view('app.web.pages.services.services', compact([
            'services',
            'contacts',
            'serviceImages'
        ]));
    }

    //Service
    public function service(Service $service)
    {
        $services = Service::all();
        $contacts = Contact::all();
        $partners =Partner::take(6)->get();
        $randomServices = Service::inRandomOrder()->get();
        return view('app.web.pages.services.service', compact([
            'services',
            'contacts',
            'partners',
            'service',
            'randomServices'
        ]));
    }


    public function partners(){
        $partners =Partner::all();
       return view('app.web.pages.partners.partners',compact([
           'partners'
       ]));
    }


    //Save form Contact Message
    public function contactStore(Request $request)
    {
        $data =$request->all();

        Ticket::create($data);

        Cache::forget('contacts');

        return redirect()->back();
    }



    //Save form Contact Message
    public function speedStore(Request $request)
    {
        $data =$request->all();

        Speed::create($data);

        Cache::forget('speeds');

        return redirect()->back();
    }

    //Save form Email Message
    public function emailStore(Request $request)
    {
        $data =$request->all();

        Email::create($data);

        Cache::forget('emails');

        return redirect()->back();
    }




}
