/**
  * @param int $categoryPageId
  * @param Page[]|Collection $pages
  * @param array $options
  * @return string
  */
 protected function _renderCategory($categoryPageId, $pages, $options)
 {
     if (array_key_exists('view', $options) && empty($options['view'])) {
         unset($options['view']);
     }
     $defaultOptions = ['render' => true, 'renderIfEmpty' => true, 'view' => 'default', 'type' => 'all', 'per_page' => 20, 'limit' => 0, 'content' => '', 'canonicals' => config('coaster::frontend.canonicals')];
     $options = array_merge($defaultOptions, $options);
     if (!$options['render']) {
         return $pages;
     }
     // select page of selected type
     $pagesOfSelectedType = [];
     if ($options['type'] == 'all') {
         $pagesOfSelectedType = is_a($pages, Collection::class) ? $pages->all() : $pages;
     } else {
         foreach ($pages as $page) {
             $children = count(Page::getChildPageIds($page->id));
             if ($options['type'] == 'pages' && $children == 0 || $options['type'] == 'categories' && $children > 0) {
                 $pagesOfSelectedType[] = $page;
             }
         }
     }
     // limit results
     if (!empty($options['limit']) && is_int($options['limit'])) {
         $pagesOfSelectedType = array_slice($pagesOfSelectedType, 0, $options['limit']);
     }
     // pagination
     if (!empty($options['per_page']) && (int) $options['per_page'] > 0) {
         $paginator = new LengthAwarePaginator($pagesOfSelectedType, count($pagesOfSelectedType), $options['per_page'], Request::input('page', 1));
         $paginator->setPath(Request::getPathInfo());
         $paginationLinks = PaginatorRender::run($paginator);
         $pages = array_slice($pagesOfSelectedType, ($paginator->currentPage() - 1) * $options['per_page'], $options['per_page']);
     } else {
         $pages = $pagesOfSelectedType;
         $paginationLinks = '';
     }
     $list = '';
     $total = count($pages);
     if (!$total && !$options['renderIfEmpty']) {
         return '';
     }
     $groupPageContainerId = 0;
     if ($categoryPageId && !$options['canonicals']) {
         $categoryPage = Page::preload($categoryPageId);
         $groupPageContainerId = $categoryPage->exists && $categoryPage->group_container > 0 ? $categoryPage->id : 0;
     }
     $pages = array_values($pages);
     foreach ($pages as $count => $page) {
         $isFirst = $count == 0;
         $isLast = $count == $total - 1;
         if (is_string($page->id)) {
             $tmpCustomBlockKey = $this->_customBlockDataKey;
             $this->_customBlockDataKey = 'customPage:' . $page->id;
             $pageDetails = new \stdClass();
             foreach ($page as $blockName => $content) {
                 if (in_array($blockName, ['fullUrl', 'fullName'])) {
                     $pageDetails->{$blockName} = $content;
                 } else {
                     $this->setCustomBlockData($blockName, $content, $this->_customBlockDataKey);
                 }
             }
             Path::addCustomPagePath($page->id, $pageDetails);
         }
         $fullPageInfo = new PageDetails($page->id, $groupPageContainerId);
         $this->pageOverride = $page;
         $list .= $this->_getRenderedView('categories.' . $options['view'] . '.page', ['page' => $fullPageInfo, 'category_id' => $categoryPageId, 'is_first' => $isFirst, 'is_last' => $isLast, 'count' => $count + 1, 'total' => $total]);
         if (isset($tmpCustomBlockKey)) {
             $this->_customBlockDataKey = $tmpCustomBlockKey;
             $tmpCustomBlockKey = null;
         }
         $this->pageOverride = null;
     }
     return $this->_getRenderedView('categories.' . $options['view'] . '.pages_wrap', ['pages' => $list, 'category_id' => $categoryPageId, 'pagination' => $paginationLinks, 'links' => $paginationLinks, 'total' => $total, 'content' => $options['content'], 'search_query' => $this->searchQuery]);
 }