<?php

namespace App\Http\Controllers;

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Redirect;
use App\User;
use App\YesPin;
use Illuminate\Http\Request;
use App\Http\Requests\StoreUsersRequest;
use App\Http\Requests\StoreBinUsersRequest;
use App\Http\Requests\UpdateUsersRequest;
use Yajra\Datatables\Datatables;
use Mail;
use Illuminate\Support\Carbon;
use Validator;

class UsersOutController extends Controller
{
    public function __construct() {
    }
    /**
     * Display a listing of User.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(){
        return view('front.index');
    }

    public function homepage()
    {
        return view('homepage');
    }
    public function track_order(Request $request)
    {
        if(isset($request->ack_number)){
            $customer = \App\EvCustomer::where([['ack_number', '=',$request->ack_number]])->first();
            if(isset($customer->id)){
            $ev_ev_solar_model_ids = \App\EvEvSolarModels::where('id', $customer->ev_ev_solar_model_id)->first();
            return view('homepage', array(
                'ev_ev_solar_model_ids' => $ev_ev_solar_model_ids,
                'customer' => $customer
            ));
            }else{
                dd("Not Found.");
            }

        }else{
            return view('front.track-order'); 
        }

    }
    public function aboutus()
    {
        return view('front.aboutus');
    }
    public function visionMission()
    {
        return view('front.vision-mission');
    }
    public function whychooseus()
    {
        return view('front.whychooseus');
    }
    public function contactus()
    {
        return view('front.contactus');
    }
    public function contactus_form(Request $request)
    {

        if($request->full_name){
            $validator = Validator::make($request->all(), [
                'full_name' => 'required|max:155',
                'mobile_no' => 'required|max:12',
                'location' => 'required|max:100',
                //'captcha' => 'required|captcha',
                'monthly_elecbill' => 'required|max:10',
                'property_type' => 'required|max:25',
                'preferred_date' => 'required|max:10',
                'time_slot' => 'required|max:30',
                'comment' => 'required|max:155'
            ],
            //['captcha.captcha' => "Captcha Code entered was incorrect."]
        );

            if ($validator->fails()) {
                return Redirect::back()
                            ->withErrors($validator)
                            ->withInput();
            }
            else
            {   
                \App\EvSiteVisit::create([
                    'full_name' => $request->full_name,
                    'mobile_no' => $request->mobile_no,
                    'location' => $request->location,
                    //'captcha' => $request->comment,
                    'monthly_elecbill' => $request->monthly_elecbill,
                    'property_type' => $request->property_type,
                    'preferred_date' => $request->preferred_date,
                    'time_slot' => $request->time_slot,
                    'comment' => $request->comment
                ]);

                    // Mail::send('email.newMessage', [ 'data' => $request ], function($message)
                    // use($request)
                    // {
                    //     $message->to('support@bizzbasket.com', 'BizzBasket')->subject('BizzBasket: New message.');
                    // });

                    return Redirect::back()->with('success','Message sent. We will revert back to you soon.');

            }
        }
    }

    public function company()
    {
        return view('company');
    }

    public function showroom()
    {
        return view('showroom');
    }
    public function grievance()
    {
        return view('grievance');
    }
    public function opportunity()
    {
        return view('opportunity');
    }
    public function projects()
    {
        return view('projects');
    }
    public function services()
    {
        return view('front.services');
    }
    
    public function realestate()
    {
        return view('realestate');
    }
    
    public function guidelines()
    {
        return view('front.guidelines');
    }
    public function documents_required()
    {
        return view('front.documents-required');
    }

    public function subsidy_scheme()
    {
        return view('front.subsidy-scheme');
    }

    public function getCity(Request $request)
    {
        $data['cities'] = DB::table('cities')->where("state_id",$request->state_id)->orderBy('name', 'asc')
                    ->get(["name","id"]);
        return response()->json($data);
    }
    
    public function galleryFront(){

        $galleries = \App\Gallery::select('*')->where('type', 'SOLAR')->orderBy('created_at', 'DESC')->get();
        return view('front.gallery_front', ['galleries'=>$galleries]);
    }
    
    public function galleryImgFront(){
        $galleries = \App\ImageGallery::select('*')->where('type', 'SOLAR')->orderBy('created_at', 'DESC')->get();
        return view('front.gallery_img_front', ['galleries'=>$galleries]);
    }



}
