<?php

namespace App\Http\Controllers\Admin\Shop;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

use App\Repositories\Shop\ArticleNatures;
use App\Repositories\Shop\Packages;
use App\Datatables\Shop\PackagesDataTable;

class PackageController extends Controller
{
    public function index(PackagesDataTable $dataTable)
    {
        $data['families'] = ArticleNatures::getOptions();
        return $dataTable->render('Admin.Shop.Packages.list', $data);
    }

    public function getOptionsByFamily(Request $request)
    {
        $id = $request->input('family_id');
        return response()->json(Packages::getSelectByFamily($id));
    }

    public function create()
    {
        $data['families'] = ArticleNatures::getOptions();
        return view('Admin.Shop.Packages.create', $data);
    }

    public function store(Request $request)
    {
        $ret = Packages::store($request->all());
        return redirect()->route('Admin.Shop.Packages.index');
    }

    public function show($id)
    {
        $data = Packages::get($id);
        return view('Admin.Shop.Packages.view', $data);
    }

    public function edit($id)
    {
        $data['package'] = Packages::get($id);
        $data['families'] = ArticleNatures::getOptions();
        return view('Admin.Shop.Packages.edit', $data);
    }

    public function update(Request $request)
    {
        //
    }

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