<?php

namespace App\Http\Controllers\Web;

use App\Http\Controllers\Controller;
use App\Http\Requests\Web\VisitorMessageRequest;
use App\Jobs\VisitorMessagesJob;
use App\VisitorMessage;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;

class VisitorMessageController extends Controller
{
    private $viewDirectory = 'web.visitor_messages.';

    /**
     * Show the Contact US details.
     * @param string $page
     * @param Request $request
     * @return View
     */
    public function index(string $slug= null, Request $request) //:?View
    {

        $title= __('main.contact_us');
        $keywords= __('main.contact_us');
        $meta_description= $keywords;

        return view( $this->viewDirectory.'contact_us', compact('title', 'keywords', 'meta_description') );
    }

    /**
     * Store a Message and send it to the admin in storage.
     *
     * @param VisitorMessageRequest $request
     * @return JsonResponse
     */
    public function store(VisitorMessageRequest $request) :JsonResponse
    {
        $this->dispatch(new VisitorMessagesJob($request->all(), $this->viewDirectory.'email'));
        VisitorMessage::create($request->all());
        return response()->json(['message' => __('visitorMessages.message_success')]);
    }
}
