<?php


namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use App\Models\Profile;
use App\User;
use Illuminate\Http\Request;
use App\Models\Item;
use App\Models\Picture;
use Illuminate\Support\Facades\Auth;


class ProfileController extends Controller
{

    public function index()
    {

        $contentContainer = '';

        $profile = Profile::where('user_id', Auth::id())->first();
        if ($profile) {
            $contentContainer = (string)view('userprofile.profile_form', ['profile' => $profile]);
        }

        return view('userprofile.index', ["contentContainer" => $contentContainer]);
    }

    public function showAllItems(User $user = null)
    {

        $user = $user ?: Auth::user();

        $userItemsList = Item::where('user_id', '=', $user->id)->get();
        if (count($userItemsList) > 0) {
            $userItemsList->load('picture');
        }

        return view('userprofile.index', ['itemsList' => $userItemsList]);

    }

    public function userProfileInfo()
    {
        $contentContainer = '';

        $contentContainer = RegisterProfileController::createView();

        return view('userprofile.index', ["contentContainer" => $contentContainer]);
    }
}