<?php

declare(strict_types=1);

namespace svoboda\works\controllers;

// Files of the project
use svoboda\works\controllers\core;

// Framework for PHP
use mirzaev\minimal\http\enumerations\content,
	mirzaev\minimal\http\enumerations\status;

/**
 * Index
 *
 * @package svoboda\works\controllers
 *
 * @param array $errors Registry of errors
 *
 * @method null index() Main page
 *
 * @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
 * @author svoboda <mail@domain.zone>
 */
final class index extends core
{
	/**
	 * Errors
	 *
	 * @var array $errors Registry of errors
	 */
	protected array $errors = [
		'session' => []
	];

	/**
	 * Main page
	 *
	 * @return null
	 */
	public function index(): null
	{
		if (str_contains($this->request->headers['accept'], content::any->value)) {
			// Request for any response

			// Initializing distributions
			$this->view->distributions = [
				[
					'identifier' => 1,
					'name' => 'Dreamers',
					'members' => [
						[
							'identifier' => 1,
							'name' => [
								'first' => 'Arsen',
								'second' => 'Mirzaev',
								'other' => 'Tatyano-Muradovich'
							]
						],
						[
							'identifier' => 2,
							'name' => [
								'first' => 'Margarita',
								'second' => 'Esenina',
								'other' => ''
							]
						],
						[
							'identifier' => 5,
							'name' => [
								'first' => 'Maxim',
								'second' => '',
								'other' => ''
							]
						],
						[
							'identifier' => 6,
							'name' => [
								'first' => 'Hidden',
								'second' => '',
								'other' => ''
							]
						],
						[
							'identifier' => 7,
							'name' => [
								'first' => 'Hidden',
								'second' => '',
								'other' => ''
							]
						]
					]
				],
				[
					'identifier' => 2,
					'name' => 'Unnamed',
					'members' => [
						[
							'identifier' => 3,
							'name' => [
								'first' => 'Pavel',
								'second' => '',
								'other' => ''
							]
						],
						[
							'identifier' => 4,
							'name' => [
								'first' => 'Georgiy',
								'second' => '',
								'other' => ''
							]
						]
					]
				]
			];

			// Render page
			$page = $this->view->render('/pages/statistics/total.html');

			// Sending response
			$this->response
				->start()
				->clean()
				->sse()
				->write($page)
				->validate($this->request)
				?->body()
				->end();

			// Deinitializing rendered page
			unset($page);

			// Exit (success)
			return null;
		}

		// Exit (fail)
		return null;
	}
}
