<?php

namespace App\Http\Controllers\Fronted;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Validator;
use App\Volunteer;
use Image;
use Storage;
use App\Mail\VolunteerDetail;
use App\Mail\SendContact;
use Mail;

class PageController extends Controller
{
    public function index()
    {
        return view('frontend.index');
    }

    public function about()
    {
        return view('frontend.about');
    }

    public function contact()
    {
        return view('frontend.contact');
    }

    public function volunteer()
    {
        return view('frontend.volunteer');
    }

    public function savevolunteer(Request $request)
    {
        // Validation
        $this->validate($request, [
            'name' => 'required',
            'email' => 'required',
            'sex' => 'required',
            'phone' => 'required',
            'bio' => 'required',
            'cv' => 'required',
        ]);
        $volunteer = new Volunteer();
        $volunteer->name = $request->input('name');
        $volunteer->email = $request->input('email');
        $volunteer->sex = $request->input('sex');
        $volunteer->phone = $request->input('phone');
        $volunteer->bio = $request->input('bio');
        // save image 
        $cv = $request['cv'];       
        $filename = $cv->getClientOriginalName();        
        $destination = 'file';      
        $cv->move($destination, $filename);
        $volunteer->cv = $filename;

        $this->email = ['isaacchinonsogift@gmail.com'];
        
        Mail::to($this->email)->send(new VolunteerDetail($volunteer));

        \Session::flash('Success_message', '✔ Record Sent Successful, We will get in touch with you shortly.');

        return redirect()->route('volunteer');
    }

    public function sendcontact(Request $request)
    {
         // Validation
         $this->validate($request, [
            'name' => 'required',
            'email' => 'required',
            'subject' => 'required',
            'cont' => 'required',
        ]);

        $contact = $request['name'];
        $contact = $request['email'];
        $contact = $request['subject'];
        $contact = $request['cont'];

        $this->email = ['isaacchinonsogift@gmail.com'];
        
        Mail::to($this->email)->send(new SendContact($contact));

        \Session::flash('Success_message', '✔ Message Sent Successful, We will get in touch with you shortly.');

        return redirect()->route('contact');
    }

    public function gallery()
    {
        return view('frontend.gallery');
    }

    public function football()
    {
        return view('frontend.football');
    }

    public function outreach()
    {
        return view('frontend.outreach');
    }

    public function covid()
    {
        return view('frontend.covid-19');
    }

    public function feed()
    {
        return view('frontend.feed');
    }

    public function nursing()
    {
        return view('frontend.nursing');
    }

    public function human()
    {
        return view('frontend.human');
    }

    public function donation()
    {
        return view('frontend.donation');
    }

    public function hygiene()
    {
        return view('frontend.hygiene');
    }

    public function pad()
    {
        return view('frontend.pad');
    }

}
