public function generateItems()
    {
        // Iterator for pagination pages.
        $j = 1;

        foreach ($this->getLinks() as $index => $link) {
            // Create new pagination item
            $item = new PaginationItem($link);

            // If we on first link and currently active page is not first,
            // we know that this link is for previous pagination item.
            if ($index === 0 && $this->currentPage != 1) {
                $this->markAsPrevious($item);

                continue;
            }

            // If we on last link and currently active page is not last,
            // we know that this link is for next pagination item.
            if (
                $index === $this->getLinksCount(true)
                && $this->currentPage != $this->getLinksCount(true)
            ) {
                $this->markAsNext($item);

                break;
            }

            // We can't use loop index, because sometimes first and
            // last link are for the next and previous item, so use
            // external iterator to index pages of pagination.
            $item->number = $j++;

            // Push pagination pages to items collection.
            $this->items[] = $item;
        }
    }