<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use DB;
use App\Packages;
use App\Categories;
use App\Repository\PackagesRepository;
use App\WebsiteFaqs;
use App\Widgets;
use App\CategoryPlan;
use App\Pages;

class PackagesController extends Controller {

    public function __construct() {
        
    }

    public function listing(PackagesRepository $packages, $category_id) {
        $data["view"] = $packages->getPackages($category_id);
        $data["category_id"] = $category_id;
        
        return view('front/packages', $data);
    }

    public function package(PackagesRepository $packages, $code1, $code2) {

        $data["view"] = $packages->getPackage($code1, $code2);
        $data["headerClass"] = '';
        return view('front/package', $data);
    }

    public function category(PackagesRepository $packages, $code) {

        $model = Categories::where("status", 1)->where("code", $code)->first();
        $model2 = Pages::where("Template", "None")->where('AccessURL', $code)->first();

        if (empty($model) && empty($model2) && empty($model3)) {
            abort(404);
        } else {
            if (!empty($model)) {
                $data["packagesView"] = $packages->getPackages($model->id);
                $data["faqs"] = WebsiteFaqs::where("type", "categories")->where("type_id", $model->id)->where("status", 1)->get();

                if ($code == 'landlord-care') {
                    $data["plans"] = Widgets::where('code', 'landlord_plans')->first();
                } else {
                    $data["plans"] = Widgets::where('code', 'homecare_plans')->first();
                }

                $data["model"] = $model;
                $data["sec1"] = Widgets::where('code', 'index_sec_2')->first();
                $data["sec2"] = Widgets::where('code', 'index_sec_9')->first();
                $data["headerClass"] = '';
                return view('front/category', $data);
            } else if (!empty($model2)) {
                $data["model"] = $model2;
                // d($code,1);
                $data["sec2"] = Widgets::where('code', 'become_an_engineer_sec_2')->first();
                $data["sec3"] = Widgets::where('code', 'become_an_engineer_sec_3')->first();
                $data["sec4"] = Widgets::where('code', 'index_sec_5')->first();
                $data["headerClass"] = '';
                $data["code"] = $code;
                return view('front/' . $code, $data);
            }
        }
    }

}
