<?php

namespace App\Http\Controllers\Web;

use App\Http\Requests\Web\JoinUsRequest;
use App\Http\Requests\Web\NewsLetterRequest;
use App\Models\Branch;
use App\Models\Demand;
use App\Models\File;
use App\Models\Gallery;
use App\Models\Mail;
use App\Models\Reservation;
use App\Models\Page;
use App\Models\Partner;
use App\Models\Slider;
use App\Jobs\VisitorMessagesJob;
use App\Models\Team;
use App\Models\VisitorMessage;
use App\Services\Interfaces\PageRepositoryInterface;
use App\Services\Interfaces\SliderRepositoryInterface;
use App\Services\Interfaces\VisitorMessageRepositoryInterface;
use App\Services\Response\ResponseService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
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.';
    private $pageRepository ;
    private $sliderRepository ;
    private $visitorMessageRepository ;
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct(
        PageRepositoryInterface $pageRepository,
        SliderRepositoryInterface $sliderRepository,
        VisitorMessageRepositoryInterface $visitorMessageRepository,
    )
    {
        $this->pageRepository = $pageRepository;
        $this->sliderRepository = $sliderRepository;
        $this->visitorMessageRepository = $visitorMessageRepository;
    }

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

    public function aboutus(Request $request): View
    {
        $title = __('web.aboutus');
        $sliders = $this->sliderRepository->get($request);
        $request->merge(['ids'=>[6,7,8],'paginate'=>null]);
        $pages = $this->pageRepository->get($request);
        
        
        $request->merge(['ids'=>[1,2,3,4],'paginate'=>null]);
        $cards = $this->pageRepository->get($request);
        
        
        $card1 = Page::find(13);
        $card1 = $this->pageRepository->getItem($card1);
        
        
        $card2 = Page::find(14);
        $card2 = $this->pageRepository->getItem($card2);
        
        return view($this->view.'aboutus', get_defined_vars());
    }

    public function contactus(): View
    {
        $title = __('web.contactus');
        return view($this->view.'contactus', get_defined_vars());
    }

    public function contact(ContactRequest $request) :JsonResponse
    {
        $this->visitorMessageRepository->save($request,null);
        // $request->merge(['to'=>settings('contact_email')]);
        // $this->dispatch(new VisitorMessagesJob($request->all(), 'admin.visitor_messages.email'));
        $response = [
            'status'=>200,
            'message'=>__('web.success'),
            'data'=> url()->previous(),
        ];
        return ResponseService::response($response);
    }
    
    
    public function terms(Request $request)
    {
        $title = __('web.terms');
        $sliders = $this->sliderRepository->get($request);
        $page = Page::find(15);
        $page = $this->pageRepository->getItem($page);
        return view($this->view.'page', get_defined_vars());
    }


}
