<?php

namespace App\Http\Controllers\Web;

use App\Services\Response\ResponseService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
use App\Http\Controllers\Controller;
use Modules\VisitorMessage\Requests\Web\VisitorMessageRequest;
use Modules\VisitorMessage\Services\VisitorMessageService;


class VisitorMessageController extends Controller
{
    private $view = 'web.pages.contactus.';
    private VisitorMessageService $messageService ;
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct(
        VisitorMessageService $messageService,
    )
    {
        $this->messageService = $messageService;
    }

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

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


    public function store(VisitorMessageRequest $request) :JsonResponse
    {
        $this->messageService->save($request,null);
        $response = [
            'status'=>200,
            'message'=>__('web.success'),
            'data'=> url()->previous(),
        ];
        return ResponseService::response($response);
    }

}
