<?php
/**
 * Dashboard page controller.
 *
 * @package MonitorCat\Admin
 */

declare(strict_types=1);

namespace MonitorCat\Admin;

defined( 'ABSPATH' ) || exit;

use MonitorCat\Module\ModuleRegistry;
use MonitorCat\Modules\ComingSoon\ComingSoonModule;

/**
 * Handles rendering of the main plugin dashboard page.
 */
final class DashboardPage {

	/**
	 * Page renderer instance.
	 *
	 * @var PageRenderer
	 */
	private PageRenderer $renderer;

	/**
	 * Module registry instance.
	 *
	 * @var ModuleRegistry
	 */
	private ModuleRegistry $registry;

	/**
	 * Constructor.
	 *
	 * @param PageRenderer   $renderer Page renderer.
	 * @param ModuleRegistry $registry Module registry.
	 */
	public function __construct( PageRenderer $renderer, ModuleRegistry $registry ) {
		$this->renderer = $renderer;
		$this->registry = $registry;
	}

	/**
	 * Render the dashboard page.
	 */
	public function render(): void {
		$coming_soon = array();

		foreach ( $this->registry->coming_soon() as $module ) {
			if ( $module instanceof ComingSoonModule ) {
				$coming_soon = $module->get_placeholders();
				break;
			}
		}

		$this->renderer->render(
			'admin/dashboard',
			array(
				'modules'     => $this->registry->active(),
				'coming_soon' => $coming_soon,
				'registry'    => $this->registry,
			)
		);
	}
}
