<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Hotel;
use App\Country;
use App\Tour;
use App\Pages;
use App\WidgetSection;
use App\WidgetNavigationSection;
use App\Widgets;
use App\Post;
use DB;
use App\Team;
use App\Faq;
use App\Repository\PackagesRepository;
use App\Banners;
use App\WebsiteFaqs;

class IndexController extends Controller {

    public function __construct() {
        
    }

    public function index(PackagesRepository $packages) {
        
        $banners = Banners::where('Link', 'index')->where('Status', 'Enabled')->get();
        $data["banners"] = $banners;
        $pages = Pages::where('AccessURL', 'index')->where('Status', 'Enabled')->first();
        $data["pages"] = $pages;
        if (!empty($pages)) {
            $data["faqs"] = WebsiteFaqs::where("type", "pages")->where("type_id", $pages->PKPageID)->where("status", 1)->get();
        }
//        $data["sec1"] = Widgets::where('code', 'index_sec_1')->first();
        $data["sec2"] = Widgets::where('code', 'index_sec_2')->first();
        $data["sec3"] = Widgets::where('code', 'index_sec_3')->first();
        $data["sec4"] = Widgets::where('code', 'index_sec_4')->first();
//        $data["sec5"] = Widgets::where('code', 'index_sec_5')->first();
        $data["sec6"] = Widgets::where('code', 'index_sec_6')->first();
        $data["sec7"] = Widgets::where('code', 'index_sec_7')->first();
        $data["sec8"] = Widgets::where('code', 'index_sec_8')->first();
        $data["sec9"] = Widgets::where('code', 'index_sec_9')->first();
        $data["headerClass"] = '';
        $data["packagesView"] = $packages->all();
        return view('front/index', $data);
    }

    public function applynow(PackagesRepository $packages) {
        
    }

    public function about() {
        $key = "about";
        $model = Pages::where('AccessURL', $key)->first();

//        $team = self::getWidgetData(1);
        $team = Team::get();
        $partners = self::getWidgetData(2);
        $awards = self::getWidgetData(3);
        $tours = self::getWidgetData(4);
        $services = self::getWidgetData(5);

        $data["model"] = $model;
        $data["partners"] = $partners;
        $data["team"] = $team;
        $data["awards"] = $awards;
        $data["tours"] = $tours;
        $data["services"] = $services;
        $this->breadcrumbs[2]['link'] = "#_";
        $this->breadcrumbs[2]['name'] = $data['model']->Title;

        $data['breadcrumbs'] = $this->breadcrumbs;
        $data["posts"] = Post::orderBy(DB::raw('RAND()'))->where('type_id', 1)->limit(3)->get();
        return view('front/about', $data);
    }

    public static function getWidgetData($id) {
        $model = WidgetSection::

                join('cms_widget_navigation_sections as wn', 'cms_widget_sections.PKSectionID', '=', 'wn.FKSectionID')
                ->join('cms_widgets as w', 'w.PKWidgetID', '=', 'wn.FKWidgetID')
                ->where("FKSectionID", $id)
                ->get();

        return $model;
    }

}
