<?php

namespace App\Http\Controllers\Admin\Botanic;

use App\Datatables\Botanic\VarietiesDataTable;
use App\Repositories\Botanic\Species;
use App\Repositories\Botanic\Varieties;
use App\Repositories\Shop\TagGroups;
use Illuminate\Http\Request;

class VarietyController extends Controller
{
    public function index(VarietiesDataTable $dataTable)
    {
        return $dataTable->render('Admin.Botanic.Varieties.list');
    }

    public function getOptionsWithSpecie()
    {
        return response()->json(['0' => ''] + Varieties::getOptionsWithSpecie());
    }

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

        return view('Admin.Botanic.Varieties.create', $data);
    }

    public function store(Request $request)
    {
        $data = $request->all();
        Varieties::storeFull($data);

        return redirect()->route('Admin.Botanic.Varieties.index');
    }

    public function edit($id)
    {
        $data = Varieties::init();
        $data['variety'] = Varieties::getFull($id);

        return view('Admin.Botanic.Varieties.edit', $data);
    }

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

    public function getImages(Request $request, $id = false, $can_edit = true)
    {
        $id = $id ? $id : $request->input('id');
        $data = [
            'images' => Varieties::getImages($id),
            'can_edit' => $can_edit,
        ];

        return view('components.uploader.mini-gallery-items', $data);
    }

    public function deleteImage(Request $request)
    {
        $id = $request->input('id');
        $index = $request->input('index');

        return Varieties::deleteImage($id, $index);
    }
}
