<?php

namespace App\Http\Controllers\Web;

use App\Http\Requests\Web\NewsLetterRequest;
use App\Models\Mail;
use App\Models\Page;
use App\Models\VisitorMessage;
use Illuminate\Http\JsonResponse;
use Illuminate\View\View;
use App\Http\Controllers\Controller;
use App\Http\Requests\Web\ContactRequest;
use App\Http\Requests\Web\SendEmailRequest;


class PageController extends Controller
{
    private $view = 'web.pages.pages.';
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        // $this->middleware('auth')->except('lang');
    }

    /**
     * Show the application dashboard.
     * @return View
     */

    public function conditions(): View
    {
        $title = __('web.conditions');
        $page = Page::withDescription(25)->first();

        return view($this->view.'conditions', get_defined_vars());
    }
    public function privacy(): View
    {
        $title = __('web.privacy');
        $page = Page::withDescription(23)->first();

        return view($this->view.'conditions', get_defined_vars());
    }
    public function conditionsCompany(): View
    {
        $title = __('web.conditions_company');
        $page = Page::withDescription(24)->first();

        return view($this->view.'conditions', get_defined_vars());
    }

    public function aboutus(): View
    {
        $title = __('web.aboutus');
        $features = Page::withDescription([19,20,21,22])->get();
        $aboutus = Page::withDescription(5)->first();
        $cards = Page::withDescription([10,11,12])->get();
        return view($this->view.'aboutus', get_defined_vars());
    }

    public function contactus(): View
    {
        $title = __('web.contactus');
        $action = url(getCurrentLocale().'/contactus');
        $pages = Page::withDescription()->find([1,2]);
        return view($this->view.'contactus', get_defined_vars());
    }

    public function contact(ContactRequest $request) :JsonResponse
    {
        VisitorMessage::create($request->all());
        return response()->json(['message'=> __('web.success'),'data'=>url()->previous()]);
    }
    public function newsletter(NewsLetterRequest $request) :JsonResponse
    {
        Mail::create($request->all());
        return response()->json(['message'=> __('web.success'),'data'=>url()->previous()]);
    }

    public function sendEmail(SendEmailRequest $request) :JsonResponse
    {
        return response()->json(['message'=> __('web.success'),'data'=>url()->previous()]);
    }

}
