<?php

namespace App\Http\Controllers\Admin\Shop;

use App\Datatables\Admin\Shop\VariationsDataTable;
use App\Http\Requests\Admin\Shop\StoreVariationPost;
use App\Repositories\Shop\Variations;
use Illuminate\Http\Request;

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

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

    public function index(VariationsDataTable $dataTable)
    {
        return $dataTable->render('Admin.Shop.Variations.list');
    }

    public function create()
    {
        $data = Variations::init();

        return view('Admin.Shop.Variations.create', $data);
    }

    public function edit($id)
    {
        $data = Variations::init();
        $data['variation'] = Variations::get($id);

        return view('Admin.Shop.Variations.edit', $data);
    }

    public function store(StoreVariationPost $request)
    {
        $ret = Variations::store($request->all());

        return redirect()->route('Admin.Shop.Variations.index');
    }

    public function show($id)
    {
        $data = Variations::get($id);

        return view('Admin.Shop.Variations.view', $data);
    }

    public function destroy($id)
    {
        return Variations::destroy($id);
    }
}
