<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Pages;
use App\WidgetSection;
use App\Widgets;
use App\WebsiteFaqs;
class ProductController extends FrontController
{
      public function __construct() {
        $this->breadcrumbs = $this->getBreadcrumbs();
        $this->breadcrumbs[1]['link'] = "#_";
        $this->breadcrumbs[1]['name'] = "About";
    }

    public function index() {
        
        
         $key = "about";
         $model= Pages::where("Template", "About")->where('AccessURL','product')->first();
         $data["model"]=$model;
         $data["sec3"] = Widgets::where('code', 'index_sec_3')->first();
         $data["sec6"]= Widgets::where('code','index_sec_2')->first();
            if(!empty($model->PKPageID)){
                $data["faqs"] = WebsiteFaqs::where("type_id", $model->PKPageID)->where("status", 1)->get();

            }
        
        $productsWidget=WidgetSection::where('code','products')->first();
        if(!empty($productsWidget->PKSectionID)){
                    $data["products"]= self::getWidgetData($productsWidget->PKSectionID);

        }else{
            $data["products"]=array();
        }
 
        

//         $data["latests"] = Post::orderBy(DB::raw('RAND()'))->limit(3)->get();
//         $data["leaders"] = Team::where('team_role','leader')->get();
//         $data["stafs"] = Team::where('team_role','staff')->get();
        $data["headerClass"]='';
            return view('front/product',$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;
    }
}
