<?php

declare(strict_types=1);

namespace app\controllers;

use Yii;
use yii\web\Controller;
use yii\web\Response;

class MainController extends Controller
{
    /**
     * {@inheritdoc}
     */
    public function actions()
    {
        return [
            'captcha' => [
                'class' => 'yii\captcha\CaptchaAction',
                'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
            ],
        ];
    }

    /**
     * Главная страница
     */
    public function actionIndex(): string|array
    {
        if (Yii::$app->request->isAjax) {
            // AJAX-POST-запрос

            Yii::$app->response->format = Response::FORMAT_JSON;

            return [
                'main' => $this->renderPartial('/index'),
                'redirect' => '/',
                '_csrf' => Yii::$app->request->getCsrfToken()
            ];
        }

        return $this->render('/index');
    }
}
