<?php

namespace App\Http\Controllers\Admin\Shop;

use App\Datatables\Admin\Shop\PriceListValuesDataTable;
use App\Http\Controllers\Controller;
use App\Repositories\Shop\Packages;
use App\Repositories\Shop\PriceListValues;
use App\Repositories\Shop\Taxes;
use App\Repositories\Shop\Unities;
use Illuminate\Http\Request;

class PriceListValueController extends Controller
{
    public function index(PriceListValuesDataTable $dataTable)
    {
        return $dataTable->render('Admin.Shop.PriceListValues.list', $data);
    }

    public function create()
    {
        $data = [
            'unities' => Unities::getOptions(),
            'taxes_options' => Taxes::getOptions(),
        ];

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

    public function edit($id)
    {
        $priceListValue = PriceListValues::getFull($id)->toArray();
        $familyId = $priceListValue['category']['article_family_id'];
        // $packages = Packages::getSelectByFamily($familyId);
        $data = [
            'generic' => $priceListValue,
            'packages' => $packages,
            'unities' => $packages['id'] ?? false ? Unities::getSelectByPackage($packages['id']) : [],
            'taxes_options' => Taxes::getOptions(),
            '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,
            'taxes' => Taxes::getOptions(),
        ];

        return view('Admin.Shop.PriceListValues.partials.row_price', $data);
    }
}
