<?php

namespace App\Http\Controllers\Web;

use App\Http\Requests\Web\ProfileRequest;
use App\Services\Response\ResponseService;
use Illuminate\View\View;
use App\Http\Controllers\Controller;

class ProfileController extends Controller
{
    private $view = 'web.pages.profile.';

    public function profile(): View
    {
        $title = __('web.profile');
        $user = \Auth::user();
        $action = route('edit_profile');
        return view($this->view.'profile', get_defined_vars());
    }
    public function editProfile(ProfileRequest $request)
    {
        $user = \Auth::user();

        if($request->password) {
            $request->merge(['password'=>bcrypt($request->password)]);
        } else {
            unset($request['password']);
        }

        $user->update($request->all());

        $response =
            [
                'msg' => __('web.success'),
                'data' =>url(getCurrentLocale().'/profile'),
                'status' => 200,
            ];
        return ResponseService::response($response);
    }
}
