<?php

namespace App\Http\Controllers\Admin\Shop;

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

class CustomerController extends Controller
{
    public function index(CustomersDataTable $dataTable)
    {
        $data = Customers::init();

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

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

        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 = Customers::init() + [
            'customer' => Customers::edit($id),
            'customer_addresses' => (new CustomerAddressesDataTable())->html(),
            'customer_invoices' => (new CustomerInvoicesDataTable())->html(),
            'customer_orders' => (new CustomerOrdersDataTable())->html(),
        ];

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

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