<?php

/**
 * Base-class for the portion of the site that it shown for logged-out users.
 */
abstract class ExtensionStoreBrowseBaseController
  extends ExtensionStoreBaseController {


  public function getApplicationURI($path = '') {
    if (!$this->isStandaloneDomain()) {
      return parent::getApplicationURI($path);
    }

    return $this->getStoreUri($path);
  }

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

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



    /* TODO sections:
     * - phorge extensions
     * - arcanist extensinos
     * - publishers
     * - other fancy searches?
     */

    $nav->addFilter(
      'server',
      pht('%s extensions', PlatformSymbols::getPlatformServerName()),
      '');
    $nav->addFilter(
      'client',
      pht('%s extensions', PlatformSymbols::getPlatformClientName()),
      '');
    $nav->addFilter('publishers', pht('Publishers'), '');


    $nav->selectFilter($selected);

    return $nav;
  }

  /**
   * @return true if the page is loaded via the dedicated domain, false if its
   * loaded via the full site.
   */
  protected function isStandaloneDomain() {
    $request = $this->getRequest();
    $site = $request->getSite();

    return $site instanceof ExtensionStorePublicSite;
  }

  public function newPage() {
    $page = parent::newPage();
    if ($this->isStandaloneDomain()) {
      $page->setShowChrome(false);
    }
    return $page;
  }
}
