<?php

namespace App\Http\Controllers;

use App\Models\Item;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;

class ItemsInfoController extends Controller
{

    public function userItemsAJAX(Request $request)
    {
        $itemListResponse = '';
        $items = Item::where('user_id', Auth::id())->where('archive', '0')->get();
        foreach ($items as $item) {
            $itemListResponse .= view('templates.info_card', ['item' => $item]);
        }
        return $itemListResponse;
    }

    public function userItemModifyAJAX(Request $request, Item $item)
    {
        $user = $request->user();
        if ($item->user_id === $user->id) {

            $data = collect();
            $data->item = $item;
            $data->categories = DB::table('categories')->get();
            $data->subcategories = DB::table('subcategories')->get();
            $data->pictures = $data->item->getPictures();

            return view('items.item_modify', ['data' => $data]);
        }
//        return view('templates.modal_form', ['item' => $item]);
    }
}
