<?php

final class ExtensionStoreExtensionListController
  extends ExtensionStoreBaseController {


  public function handleRequest(AphrontRequest $request) {
    $viewer = $request->getViewer();
    $query_key = $request->getURIData('queryKey');

    $controller = new PhabricatorApplicationSearchController()
      ->setQueryKey($query_key)
      ->setSearchEngine(new ExtensionStoreExtensionSearchEngine())
      ->setNavigation($this->buildSideNavView());
    return $this->delegateToController($controller);
  }

  public function buildSideNavView() {
    $user = $this->getRequest()->getUser();

    $nav = new AphrontSideNavFilterView();
    $nav->setBaseURI(new PhutilURI($this->getApplicationURI()));

    id(new ExtensionStoreExtensionSearchEngine())
      ->setViewer($user)
      ->addNavigationItems($nav->getMenu());

    $nav->selectFilter(null);

    return $nav;
  }

  protected function buildApplicationCrumbs() {
    $crumbs = parent::buildApplicationCrumbs();

    $crumbs->addCrumb(
        new PHUICrumbView()
        ->setHref($this->getApplicationURI("extension"))
        ->setName(pht("Extensions"))
        ->setIcon('fa-gift'));

    return $crumbs;
  }
}
