<?php
    use artbox\core\components\SeoComponent;
    use frontend\components\UrlManager;
    
    $a = \Yii::t('app', 'Message');

    $params = array_merge(
        require( __DIR__ . '/../../common/config/params.php' ),
        require( __DIR__ . '/../../common/config/params-local.php' ),
        require( __DIR__ . '/params.php' ),
        require( __DIR__ . '/params-local.php' )
    );
    return [
        'id'                  => 'app-frontend',
        'homeUrl'             => '/',
        'basePath'            => dirname(__DIR__),
        'bootstrap'           => [
            'log',
            'i18n',
            'contact',
        ],
        'controllerNamespace' => 'frontend\controllers',
        'container'           => [
            'singletons' => [
                'artbox\core\services\Languages' =>'artbox\core\services\Languages',
            ]
        ],
    
        'components'          => [
            'request' => [
                'csrfParam' => '_csrf-frontend',
                'baseUrl'   => '',
            ],
    
            'user'         => [
                'identityClass'   => 'common\models\User',
                'enableAutoLogin' => true,
                'identityCookie'  => [
                    'name'     => '_identity-frontend',
                    'httpOnly' => true,
                ],
            ],
            'session'      => [
                // this is the name of the session cookie used for login on the frontend
                'name' => 'advanced-frontend',
            ],
            'log'          => [
                'traceLevel' => YII_DEBUG ? 3 : 0,
                'targets'    => [
                    [
                        'class'  => 'yii\log\FileTarget',
                        'levels' => [
                            'error',
                            'warning',
                        ],
                    ],
                ],
            ],
            'seo'          => [
                'class' => SeoComponent::className(),
            ],
            'errorHandler' => [
                'errorAction' => 'site/error',
            ],
            'i18n'         => [
                'translations' => [
                    'core' => [
                        'class'    => 'yii\i18n\PhpMessageSource',
                        'basePath' => '@common/messages',
                    ],
                    'app'  => [
                        'class'    => 'yii\i18n\PhpMessageSource',
                        'basePath' => '@common/messages',
                    ],
                ],
            ],
            'urlManager'   => [
                'class'                     => UrlManager::className(),
                'baseUrl'                   => '/',
                'enablePrettyUrl'           => true,
                'showScriptName'            => false,
                'rules'                     => [ ],
                'hideDefaultLanguagePrefix' => true,
            ],
        ],
        'modules'             => [
            'feedback' => [
                'class'           => 'artbox\core\forms\Module',
                'activeRecord'    => "frontend\models\Feedback",
                'attributes'      => [
                    'name',
                    'email',
                    'message',
                ],
                'rules'           => [
                    [
                        [ 'email' ],
                        'email',
                    ],
                    [
                        [
                            'email',
                            'name',
                            'message',
                        ],
                        'required',
                    ],
                ],
                'labels'          => [
                    'email'   => \Yii::t('app','Email'),
                    'name'    => \Yii::t('app','Name'),
                    'message' => \Yii::t('app','You question'),
                ],
                'inputOptions'    => [
                    'message' => [
                        'type'    => 'textarea',
                        'options' => [],
                    ],
                ],
                'buttonContent'   => \Yii::t('app', 'Send'),
                'scenario'        => 'feedback',
                'sendEmail'       => false,
                'formId'          => 'feedback-form',
                'ajax'            => true,
                'successCallback' => 'function (data) {
                        if (data.status == "success"){
                              document.getElementById("feedback-form").reset();
                              $(".close").click();
                              $(".success_").animate({opacity: 1, top: \'40\'}, 200).addClass("done_");
                              setTimeout(function(){$(".success_").animate({opacity: 0, top: \'0\'}, 200,function(){
                                  $(this).removeClass("done_");
                              })}, 4000);
                              var data = $("#feedback-form").data(\'yiiActiveForm\');
                              data.validated = false;
                              }
                              
                    }',
            ],
            'contact' => [
	            'class' => 'frontend\modules\forms\Module',
	            #'class' => 'artbox\core\forms\Module',
                'activeRecord' => "frontend\models\Feedback",
                'templateForm' => '<div class="row">{form}</div>',
                'attributes'   => [
                    'name',
                    'email',
                    'phone',
                    'message',

                ],
                'rules'        => [
                    [
                        [ 'email' ],
                        'email',
                    ],
                    [
                        [
                            'email',
                            'name',
                            'phone',
                        ],
                        'required',
                    ],

                ],
                'labels'     => [
                    'email'   => \Yii::t('app','Email'),
                    'name'    => \Yii::t('app', 'Name'),
                    'message' => \Yii::t('app','Message'),
                    'phone'   => \Yii::t('app','Phone')
                ],
    
                'inputOptions'    => [
                    'name'   => [
                        'template' => '<div class="col-sm-12">{input}</div>',
                    ],
                    'email'   => [
                        'template' => '<div class="col-sm-6">{input}</div>'
                    ],
                    'phone'   => [
                        'template' => '<div class="col-sm-6">{input}</div>'
                    ],
                    'message' => [
                        'type'    => 'textarea',
                        'options' => [],
                        'template' => '<div class="col-sm-12">{input}</div>'
                    ],
                ],
                'buttonTemplate'  => '<div class="col-sm-12 text-center">{button}</div>',
                'buttonOptions'   => [
                    'class' => 'btn btn-template-main',
                ],
                'buttonContent'   => '<i class="fa fa-envelope-o"></i>Send Message',
                'sendEmail'       => false,
                'ajax'            => true,
                'formId'          => 'contact-form',
                'scenario'        => 'default',
                'successCallback' => 'function (data) {
                if (data.status == "success"){
                              document.getElementById("contact-form").reset();
                              $(".close").click();
                              $(".success_").animate({opacity: 1, top: \'40\'}, 200).addClass("done_");
                              setTimeout(function(){$(".success_").animate({opacity: 0, top: \'0\'}, 200,function(){
                                  $(this).removeClass("done_");
                              })}, 4000);
                              }
                    }',

            ],
        ],
        'params'              => $params,
    ];
    