<?php

namespace App\Http\Controllers\Admin\Shop;

use Illuminate\Http\Request;

use App\Repositories\Shop\Packages;
use App\Repositories\Shop\Unities;
use App\Repositories\Shop\Variations;

use App\Datatables\Shop\VariationsDataTable;

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['packages'] = Packages::getOptions();
        $data['unities'] = Unities::getOptions();
        return view('Admin.Shop.Variations.create', $data);
    }

    public function edit($id)
    {
        $data['variation'] = Variations::get($id);
        $data['packages'] = Packages::getOptions();
        $data['unities'] = Unities::getOptions();
        return view('Admin.Shop.Variations.edit', $data);
    }

    public function store(Request $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);
    }
}
