<?php

namespace App\Http\Controllers\Admin\Shop;

use App\Datatables\Admin\Shop\DeliveriesDataTable;
use App\Repositories\Shop\Deliveries;
use Illuminate\Http\Request;

class DeliveryController extends Controller
{
    public function index(DeliveriesDataTable $dataTable)
    {
        $data = Deliveries::init();

        return $dataTable->render('Admin.Shop.Deliveries.list', $data);
    }

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

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

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

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

    public function show($id)
    {
        $data = [
            'delivery' => Deliveries::getArray($id),
        ];

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

    public function edit($id)
    {
        $data = Deliveries::init();
        $data['delivery'] = Deliveries::getArray($id);

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

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

    public function toggleActive(Request $request)
    {
        $data = Deliveries::toggleActive($request->input('id'), $request->input('active') === 'true' ? 1 : 0);

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