<?php

namespace App\Http\Controllers\Shop;

use App\Repositories\Shop\CustomerAddresses;
use App\Repositories\Shop\Customers;
use Illuminate\Http\Request;

class CustomerController extends Controller
{
    public function profile()
    {
        $data = Customers::editProfile(Customers::getId());

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

    public static function checkAuth()
    {
        if (Customers::isNotConnected()) {
            return redirect()->route('Shop.login');
        }
    }

    public function modalProfile($id = false)
    {
        $data = [
            'customer' => Customers::get($id),
        ];

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

    public function edit()
    {
        $data = [
            'customer' => Customers::edit(Customers::getId()),
        ];

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

    public function storeProfileAjax(Request $request)
    {
        $data = $request->all();
        $customer = Customers::store($data);

        return response()->json(['error' => 0]);
    }

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

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

    public function delete_address($id)
    {
        $ret = CustomerAddresses::destroy($id);

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