<?php

namespace App\Http\Controllers\Admin\Shop;

use App\Datatables\Admin\Shop\ProducersDataTable;
use App\Repositories\Shop\Producers;
use Illuminate\Http\Request;

class ProducerController extends Controller
{
    public function index(ProducersDataTable $dataTable)
    {
        return $dataTable->render('Admin.Shop.Producers.list');
    }

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

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

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

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

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

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

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

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

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

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