<?php

namespace Drupal\nodehive_core_space_dashboard\Controller;

use Drupal\Core\Controller\ControllerBase;
use Drupal\nodehive_content\Controller\NodehiveContentController;
use Drupal\nodehive_core\SpaceInterface;
use Drupal\nodehive_core_space_dashboard\DashboardBuilderInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;

/**
 * Space dashboard.
 */
class SpaceContentController extends ControllerBase {

  /**
   * The dashboard builder.
   *
   * @var \Drupal\nodehive_core_space_dashboard\DashboardBuilderInterface
   */
  protected $dashboardBuilder;

  /**
   * The request stack.
   *
   * @var \Symfony\Component\HttpFoundation\RequestStack
   */
  protected $requestStack;

  /**
   * The NodeHive content controller.
   *
   * @var \Drupal\nodehive_content\Controller\NodehiveContentController
   */
  protected $nodehiveContentController;

  /**
   * Constructs a new SpaceContentController object.
   *
   * @param \Drupal\nodehive_core_space_dashboard\DashboardBuilderInterface $dashboard_builder
   *   The dashboard builder.
   * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
   *   The request stack.
   * @param \Drupal\nodehive_content\Controller\NodehiveContentController $nodehive_content_controller
   *   The NodeHive content controller.
   */
  public function __construct(DashboardBuilderInterface $dashboard_builder, RequestStack $request_stack, NodehiveContentController $nodehive_content_controller) {
    $this->dashboardBuilder = $dashboard_builder;
    $this->requestStack = $request_stack;
    $this->nodehiveContentController = $nodehive_content_controller;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static(
      $container->get('nodehive_core_space_dashboard.dashboard_builder'),
      $container->get('request_stack'),
      NodehiveContentController::create($container),
    );
  }

  /**
   * Display the content overview for a space using Content X.
   */
  public function contentOverview(SpaceInterface $nodehive_space) {
    $request = $this->requestStack->getCurrentRequest();
    $request->query->set('space', $nodehive_space->id());
    $request->attributes->set('hide_space_filter', TRUE);

    return $this->nodehiveContentController->overview($request);
  }

  /**
   * {@inheritdoc}
   */
  public function content(SpaceInterface $nodehive_space) {
    $build = [];

    /*
    $build['top_content'] = [
    '#type' => 'container',
    '#attributes' => [
    'class' => ['top-container'],
    ],
    ];

    $build['top_content']['add_content_block'] =
    $this->dashboardBuilder->buildAddContentBlock($nodehive_space);

    $build['middle_content'] = [
    '#type' => 'container',
    '#attributes' => [
    'class' => ["middle-content-container"],
    ],
    ];

    $build['middle_content']['menu_block'] =
    $this->dashboardBuilder->buildMenuBlock($nodehive_space);

    $build['middle_content']['content_block'] =
    $this->dashboardBuilder->buildContentBlock($nodehive_space);
     */
    $build['content_block'] = $this->dashboardBuilder->buildContentBlock($nodehive_space);
    $build['#attached']['library'][] = 'nodehive_core_space_dashboard/dashboard';

    return $build;
  }

}
