<?php

namespace App\Http\Controllers\Admin\Shop;

use App\Datatables\Admin\Shop\TagGroupsDataTable;
use App\Http\Controllers\Controller;
use App\Repositories\Shop\ArticleNatures;
use App\Repositories\Shop\TagGroups;
use Illuminate\Http\Request;

class TagGroupController extends Controller
{
    public function index(TagGroupsDataTable $dataTable)
    {
        return $dataTable->render('Admin.Shop.TagGroups.list');
    }

    public function create()
    {
        $data = [
            'article_families' => ArticleNatures::getOptions(),
        ];

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

    public function store(Request $request)
    {
        $ret = TagGroups::store($request->all());

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

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

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

    public function edit($id)
    {
        $data = TagGroups::get($id);
        $data['article_families'] = ArticleNatures::getOptions();

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

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

    public function toggleVisible(Request $request)
    {
        $data = TagGroups::toggleVisible($request->input('id'), $request->input('visible') === 'true' ? 1 : 0);

        return response()->json(['error' => 0]);
    }
}
