<?php

namespace App\Http\Controllers\Admin\Botanic;

use Illuminate\Http\Request;

use App\Repositories\Botanic\Species;
use App\Repositories\Botanic\Genres;
use App\Repositories\Shop\TagGroups;
use App\Datatables\Botanic\SpeciesDataTable;

class SpecieController extends Controller
{
    public function index(SpeciesDataTable $dataTable)
    {
        return $dataTable->render('Admin.Botanic.Species.list');
    }

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

    public function create()
    {
        $data['genres'] = Genres::getOptions();
        $data['tags_list'] = TagGroups::getTreeTags();
        return view('Admin.Botanic.Species.create', $data);
    }

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

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

    public function edit($id)
    {
        $data['specie'] = Species::getFull($id);
        $data['genres'] = Genres::getOptions();
        $data['tags_list'] = TagGroups::getTreeTags();
        return view('Admin.Botanic.Species.edit', $data);
    }

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

    public function getImages(Request $request, $id = false, $can_edit = true)
    {
        $id = $id ? $id : $request->input('id');
        $data['images'] = Species::getImages($id);
        $data['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 Species::deleteImage($id, $index);
    }

    public function exportExcel()
    {
        return Species::exportExcel();
    }
}
