<?php
    use common\models\SlashRedirect;
    use frontend\components\UrlManager;
use common\models\Settings;


    
    $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','assetsAutoCompress' ],
        'controllerNamespace' => 'frontend\controllers',
        'container' => [
            'singletons' => [
                'artbox\core\services\Languages' =>'artbox\core\services\Languages',
            ]
        ],
        'modules'             => [
            'feedback' => [
                'class'      => 'artbox\core\forms\Module',
                'activeRecord' => "artbox\core\models\Feedback",
                'attributes' => [
                    'name',
                    'phone',
                    'message',

                ],
                'rules'      => [
                    [
                        [
                            'name',
                            'phone',
                        ],
                        'required',
                    ]
                ],
                'labels'     => [
                    'name'    => \Yii::t('app','Name'),
                    'message' => \Yii::t('app','Message'),
                    'phone'   => \Yii::t('app','Phone'),
                ],
    
                'inputOptions'    => [
                    'name'   => [
                      'template' => '<div class="input-wr">{input}</div>'
                    ],
                    'phone'   => [
                        'template' => '<div class="input-wr phones_mask">{input}</div>'
                    ],
                    'message' => [
                        'type'    => 'textarea',
                        'options' => [],
                        'template' => '<div class="input-wr">{input}</div>'
                    ],
                ],
                'buttonTemplate'  => '<div class="button-wr">{button}</div>',
                'buttonOptions'   => [],
                'buttonContent'   => 'Send',
                'sendEmail'       => false,
                'ajax'            => true,
                'formId'          => 'feedback-form',
                'scenario'        => 'callback',
                'successCallback' => 'function (data) {
                 document.getElementById("feedback-form").reset();
                              $("#modal_close").click();
                              if (data.status == "success"){
                              document.getElementById("feedback-form").reset();
                              success();
                               var data = $("#feedback-form").data(\'yiiActiveForm\');
                              data.validated = false;
                              }
                    }',
                
            ],
            'contact' => [
	            'class' => 'frontend\modules\forms\Module',
                'activeRecord' => "artbox\core\models\Feedback",
	            'alternateMailLogic' => true,

                'attributes' => [
                    'name',
                    'phone',
                    'message',
                ],
                'rules'      => [
                    [
                        [
                            'name',
                            'email',
                        ],
                        'required',
                    ]
                ],
                'labels'     => [
                    'name'    => \Yii::t('app','Name'),
                    'message' => \Yii::t('app','Yours question'),
                    'phone'   => \Yii::t('app','Phone'),
                ],
    
                'inputOptions'    => [
                    'name'   => [
                        'template' => '<div class="input-wr required">{input}</div>'
                    ],
                    'phone'   => [
                        'template' => '<div class="input-wr required phones_mask">{input}</div>'
                    ],
                    'message' => [
                        'type'    => 'textarea',
                        'options' => [],
                        'template' => '<div class="input-wr">{input}</div>'
                    ],
                ],
                'buttonTemplate'  => '<div class="button-wr submit-close-wr-c-a">{button}</div>',
                'buttonOptions'   => [],
                'buttonContent'   => 'Send',
	            'email' => 'alkhonko@gmail.com',
	            'sendEmail' => true,
                'ajax'            => true,
                'formId'          => 'contact-form',
                'scenario'        => 'callback',
                'successCallback' => 'function (data) {
                 document.getElementById("contact-form").reset();
                              if (data.status == "success"){
                              document.getElementById("contact-form").reset();
                              success();
                               var data = $("#contact-form").data(\'yiiActiveForm\');
                              data.validated = false;
                              }
                    }',

            ],
            'comments' => [
                'class'      => 'artbox\core\forms\Module',
                'activeRecord' => "common\models\Comment",
                'attributes' => [
                    'name',
                    'email',
                    'comment',
                    'entity_id',
	                'entity',

                ],
                'rules'      => [
                    [
                        [
                            'name',
                            'email',
                        ],
                        'required',
                    ]
                ],
                'labels'     => [
                    'name'    => 'ФИО',
                    'email' => 'Email',
                    'comment' => 'Ваш отзыв',
                    'entity_id' => false,
	                'entity' => false,


                ],
    
                'inputOptions'    => [
                    'name'   => [
                        'template' => '<div class="input-wr required">{input}</div>'
                    ],
                    'email'   => [
                        'template' => '<div class="input-wr required">{input}</div>'
                    ],
                    'comment' => [
                        'type'    => 'textarea',
                        'options' => [],
                        'template' => '<div class="input-wr">{input}</div>'
                    ],
                ],
                'buttonTemplate'  => '<div class="button-wr submit-close-wr-c-a">{button} <div class="submit-close-c-a"><span>Закрыть окно</span></div></div>',
                'buttonOptions'   => [],
                'buttonContent'   => 'Отправить отзыв',
                'sendEmail'       => false,
                'ajax'            => true,
                'formId'          => 'comment-form',
                'scenario'        => 'default',
                'successCallback' => 'function (data) {
                 document.getElementById("comment-form").reset();
                              var data = $("#comment-form").data(\'yiiActiveForm\');
                              $("#comment-form").find(".submit-close-c-a span").click();
                              $("#comment-form").parent().parent().parent().find(".service-c-a-btns").after("<p>Ваш отзыв появится после проверки модератором</p>")
                              data.validated = false;
                    }',

            ],

	        'questions' => [
                'class'      => 'artbox\core\forms\Module',
                'activeRecord' => "common\models\Question",
                'attributes' => [
                    'name',
                    'email',
                    'question',
                    'service_id'
                ],
                'rules'      => [
                    [
                        [
                            'name',
                            'email',
                        ],
                        'required',
                    ]
                ],
                'labels'     => [
                    'name'    => 'ФИО',
                    'email' => 'Email',
                    'question' => 'Ваш вопрос',
                    'service_id' => false
                ],
    
                'inputOptions'    => [
                    'name'   => [
                        'template' => '<div class="input-wr required">{input}</div>'
                    ],
                    'email'   => [
                        'template' => '<div class="input-wr required">{input}</div>'
                    ],
                    'question' => [
                        'type'    => 'textarea',
                        'options' => [],
                        'template' => '<div class="input-wr">{input}</div>'
                    ],
                ],
                'buttonTemplate'  => '<div class="button-wr submit-close-wr-c-a">{button} <div class="submit-close-c-a"><span>Закрыть окно</span></div></div>',
                'buttonOptions'   => [],
                'buttonContent'   => 'Отправить вопрос',
                'sendEmail'       => false,
                'ajax'            => true,
                'formId'          => 'question-form',
                'scenario'        => 'question',
                'successCallback' => 'function (data) {
                 document.getElementById("question-form").reset();
                              var data = $("#question-form").data(\'yiiActiveForm\');
                              $("#question-form").find(".submit-close-c-a span").click();
                              $("#question-form").parent().parent().parent().find(".service-c-a-btns").after("<p>Спасибо за Вваш вопрос. Мы обязательно на него ответим</p>")
                              data.validated = false;
                    }',

            ],

            'visit' => [
                'class'      => 'artbox\core\forms\Module',
                'activeRecord' => "common\models\Visit",
                'attributes' => [
                    'name',
                    'phone',
                    'email',
                    'message',
                    
                    'entity',
	                'entity_id',
	                'request_webpage',
                ],
                'rules'      => [
                    [
                        [
                            'phone',
                        ],
                        'required',
                    ]
                ],
                'labels'     => [
                    'name'    =>\Yii::t('app','FIO'),
                    'email' =>\Yii::t('app','Email'),
                    'phone' => \Yii::t('app','Phone'),
                    'message' => \Yii::t('app','Message'),
                    'entity_id' => false,
	                'entity' => false,
	                'request_webpage' => false
                ],
    
                'inputOptions'    => [
                    'entity' => [
                       'type' => 'hiddenInput'
                    ],
                    'entity_id' => [
                        'type' => 'hiddenInput'
                    ],
	                'request_webpage' => [
		                'type' => 'hiddenInput',
		                'options' =>
			                [

				                'value' => $_SERVER['REQUEST_URI'],
			                ],

	                ],
                    'name'   => [
                        'template' => '<div class="input-wr">{input}</div>'
                    ],
                    'email'   => [
                        'template' => '<div class="input-wr">{input}</div>'
                    ],
                    'phone'   => [
                        'template' => '<div class="input-wr required phones_mask">{input}</div>',
                        'options' => [
                            'placeholder' => '(0__)___-__-__'
                        ]
                    ],
                    'message' => [
                        'type'    => 'textarea',
                        'options' => ['cols' => 30, 'rows'=> 10],
                        'template' => '<div class="input-wr">{input}</div>'
                    ],
                ],
                'buttonTemplate'  => '<div class="button-wr">{button}</div>',
                'buttonOptions'   => [],
                'buttonContent'   => 'Отправить',
                'sendEmail'       => false,
                'ajax'            => true,
                'formId'          => 'visit-form',
                'scenario'        => 'default',
                'successCallback' => 'function (data) {
                 document.getElementById("visit-form").reset();
                              var data = $("#visit-form").data(\'yiiActiveForm\');
                              data.validated = false;
                              success();
                    }',

            ],
        ],
        'components'          => [
            'assetManager'       => [
                'bundles'         => [
                    'yii\bootstrap\BootstrapAsset' => [
                        'basePath' => '@webroot',
                        'baseUrl'  => '@web',
                        'css'       => [],
                    ],
                    'frontend\assets\ArtboxModalAsset' => [
                        'basePath' => '@webroot',
                        'baseUrl'  => '@web',
                        'css'       => [],
                    ],
                ],
                'appendTimestamp' => true,
            ],
            'request'      => [
                'csrfParam' => '_csrf-frontend',
                'baseUrl'   => '',
            ],
//	        'mailer' => [
//		        'class' => 'yii\swiftmailer\Mailer',
//		        'viewPath' => '@frontend/mail',
//		        'useFileTransport' => false,
//
//		        'transport' => [
//			        'class' => 'Swift_SmtpTransport',
//			        'host' => 'smtp.gmail.com',
//			        # пока что стоят мои данные, потому что я пробивал свою почту
//			        # для возможности отправки писем
//			        'username' => 'alkhonko@gmail.com',
//			        'password' => 'jakirothebest123',
//			        'port' => '587',
//			        'encryption' => 'tls',
//		        ],
//	        ],
            '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',
                        ],
                    ],
	                [
		                'class' => 'yii\log\EmailTarget',
		                'categories' => ['mail_error'],
		                'levels' => [
			                'error',
			                'warning',
			                'info'
		                ],
		                'mailer' => [
			                'class' => 'yii\swiftmailer\Mailer',
			                'viewPath' => '@frontend/mail',
			                'useFileTransport' => false,

			                'transport' => [
				                'class' => 'Swift_SmtpTransport',
				                'host' => 'smtp.gmail.com',
				                'username' => 'artboxcore@gmail.com',
				                'password' => 'upfly2000',
				                'port' => '587',
				                'encryption' => 'tls',
			                ],
		                ],
		                'logVars' => [],
		                'message' => [
			                'from' => ['artboxcore@gmail.com' => 'ABClinic'],
			                'to' => ['artboxcore@gmail.com'],
			                'subject' => 'Ошибка в почтовом адресе  ABClinic. Письма не доставляются после обработки одной из форм',
		                ],
	                ],
                ],
            ],
            'errorHandler' => [
                'errorAction' => 'site/error',
            ],
            'urlManager'   => [
                'class'           => UrlManager::className(),
                'baseUrl'         => '/',
                'enablePrettyUrl' => true,
                'showScriptName'  => false,
                'rules'           => [

                ],
                'hideDefaultLanguagePrefix' => true,
                'redirects'            => [
                    SlashRedirect::className(),
                ],
            ],
            'assetsAutoCompress' => [
                'class'   => '\skeeks\yii2\assetsAuto\AssetsAutoCompressComponent',
                'enabled' => true,
    
                'readFileTimeout' => 3,
                //Time in seconds for reading each asset file
    
                'jsCompress'                => true,
                //Enable minification js in html code
                'jsCompressFlaggedComments' => true,
                //Cut comments during processing js
    
                'cssCompress' => true,
                //Enable minification css in html code
    
                'cssFileCompile'        => true,
                //Turning association css files
                'cssFileRemouteCompile' => false,
                //Trying to get css files to which the specified path as the remote file, skchat him to her.
                'cssFileCompress'       => true,
                //Enable compression and processing before being stored in the css file
                'cssFileBottom'         => false,
                //Moving down the page css files
                'cssFileBottomLoadOnJs' => false,
                //Transfer css file down the page and uploading them using js
    
                'jsFileCompile'                 => true,
                //Turning association js files
                'jsFileRemouteCompile'          => false,
                //Trying to get a js files to which the specified path as the remote file, skchat him to her.
                'jsFileCompress'                => true,
                //Enable compression and processing js before saving a file
                'jsFileCompressFlaggedComments' => true,
                //Cut comments during processing js
    
                'htmlCompress'           => true,
                //Enable compression html
                'noIncludeJsFilesOnPjax' => true,
                //Do not connect the js files when all pjax requests
                'htmlFormatter' => [
                    //Enable compression html
                    'class'         => 'skeeks\yii2\assetsAuto\formatters\html\TylerHtmlCompressor',
                    'extra'         => false,       //use more compact algorithm
                    'noComments'    => true,        //cut all the html comments
                    'maxNumberRows' => 50000,       //The maximum number of rows that the formatter runs on
        
                    //or
        
                    //                    'class' => 'skeeks\yii2\assetsAuto\formatters\html\MrclayHtmlCompressor',
        
                    //or any other your handler implements skeeks\yii2\assetsAuto\IFormatter interface
        
                    //or false
                ],
            ],
        ],
        
        'params'              => $params,
    ];
