<?php

namespace App\Http\Controllers\Admin\Shop;

use App\Datatables\Admin\Shop\CustomerAddressesDataTable;
use App\Datatables\Admin\Shop\CustomersDataTable;
use App\Repositories\Shop\Customers;
use App\Repositories\Shop\Deliveries;
use Illuminate\Http\Request;

class CustomerController extends Controller
{
    public function index(CustomersDataTable $dataTable)
    {
        $data = [];

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

    public function create()
    {
        $data['deliveries'] = Deliveries::getOptions();

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

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

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

    public function show($id)
    {
        $data['customer'] = Customers::get($id);

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

    public function edit($id)
    {
        $data['customer'] = Customers::edit($id);
        $data['deliveries'] = Deliveries::getOptions();
        $model = new CustomerAddressesDataTable();
        $data['customer_addresses'] = $model->html();

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

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