<?php

namespace App\Http\Controllers\Admin\Shop;

use App\Datatables\Admin\Shop\PriceListsDataTable;
use App\Http\Controllers\Controller;
use App\Repositories\Shop\PriceLists;
use Illuminate\Http\Request;

class PriceListController extends Controller
{
    public function index(PriceListsDataTable $dataTable)
    {
        return $dataTable->render('Admin.Shop.PriceLists.list');
    }

    public function modalCreate($tariffId)
    {
        $data = PriceLists::init($tariffId);

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

    public function modalEdit($id)
    {
        $data = PriceLists::init();
        $data['price_list'] = PriceLists::edit($id);

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

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

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

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

        return response()->json(['code' => '200']);
    }

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

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

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

    public function getPrice($id)
    {
        $data = [
            'generic' => PriceLists::getFull($id),
        ];

        return view('Admin.Shop.PriceLists.partials.table-prices', $data);
    }
}
