<?php
class ItemController {
    private $itemModel;

    public function __construct(Item $itemModel) {
        $this->itemModel = $itemModel;
    }

    public function showItems() {
        $tag = $_GET['tag'] ?? null;
        $items = $tag ? $this->itemModel->getItemsByTag($tag) : $this->itemModel->getAllItems();
        $tags = $this->itemModel->getAllTags();

        return [
            'items' => $items->rows,
            'tags'  => $tags
        ];
    }

    public function showItem($id) {
        $item = $this->itemModel->getItemById($id);
        return $item->rows ? $item->rows[0] : null;
    }
}
?>
