<?php

namespace App\Http\Controllers\Shop;

use App\Http\Controllers\Controller;
use App\Repositories\Shop\Articles;
use App\Repositories\Shop\ArticleSiblings;
use Illuminate\Http\Request;

class ArticleController extends Controller
{
    public function autocomplete(Request $request, $str = false)
    {
        $str = $str ? $str : $request->input('q');

        return response()->json(Articles::autocomplete($str));
    }

    public function showBySlug($slug)
    {
        $id = Articles::getIDBySlug($slug);

        return $id ? $this->show($id) : view('errors.404');
    }

    public function show($id)
    {
        $data = [
            'article' => Articles::getArticleToSell($id),
            'offers2' => ArticleSiblings::getSiblings($id)->toArray(),
        ];

        return view('Shop.Articles.show', $data);
    }
}
