<?php

namespace App\Http\Controllers\Admin\Shop;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

use App\Models\Shop\PriceListValue;
use App\Repositories\Shop\PriceListValues;
use App\Repositories\Shop\PriceListValueCategories;
use App\Repositories\Shop\Taxes;
use App\Repositories\Shop\Packages;
use App\Repositories\Shop\Unities;
use App\Datatables\Shop\PriceListValuesDataTable;

class PriceListValueController extends Controller
{
    public function index(PriceListValuesDataTable $dataTable)
    {
        $data['categories'] = PriceListValueCategories::getOptions();
        return $dataTable->render('Admin.Shop.PriceListValues.list', $data);
    }

    public function create()
    {
        $data['unities'] = Unities::getOptions();
        $data['taxes_options'] = Taxes::getOptions();
        $data['categories'] = PriceListValueCategories::getOptions();
        return view('Admin.Shop.PriceListValues.create', $data);
    }

    public function edit($id)
    {
        $data['generic'] = PriceListValues::getFull($id)->toArray();
        $data['packages'] = Packages::getSelectByFamily($data['generic']['category']['article_family_id']);
        $data['unities'] = ($data['packages']['id'] ?? false) ? Unities::getSelectByPackage($data['packages']['id']) : [];
        $data['taxes_options'] = Taxes::getOptions();
        $data['categories'] = PriceListValueCategories::getOptions();
        return view('Admin.Shop.PriceListValues.edit', $data);
    }

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

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

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

    public function getPrice($id)
    {
        $data['generic'] = PriceListValues::getFull($id);
        return view('Admin.Shop.PriceListValues.partials.table-prices', $data);
    }

    public function addPrice($index)
    {
        $data['index'] = $index;
        return view('Admin.Shop.PriceListValues.partials.row_price', $data);
    }


}
