<?php
namespace TPS\Shop\Http\Controllers;
use TPS\Shop\Repositories\WebsiteReviewRepository;
use Webkul\Shop\Http\Controllers\Controller;
use Illuminate\Http\Request;

class WebsiteReviewController extends Controller
{
    /**
     * Loads the home page for the storefront.
     *
     * @return \Illuminate\View\View
     */

    public function __construct(protected WebsiteReviewRepository $websiteReviewRepository){$this->customer = auth()->guard('customer')->user();}

    public function index()
    {
        $websiteReviews = $this->websiteReviewRepository->paginate(10); // 10 reviews per page

        return view('shop::websiteReview.index', compact('websiteReviews'));
    }


    public function store(Request $request){

        $request->validate([
            'web_review_text' => 'required',
            'web_review_rating'  => 'required'
        ]);

        $data = array_merge(request()->all(), [
            'customer_id'     => auth()->guard('customer')->user()->id,
        ]);

        if($this->websiteReviewRepository->create($data)){
            return response()->json(['success' => true,'message'=>trans('shop::app.review.success')]);
        }

        return response()->json(['success' => false,'message'=>trans('shop::app.review.error')]);
    }

}