<?php

$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 [
    'modules' => [
        'webcms' => [
            'class' => 'frontend\modules\webcms\Module',
        ],
    ],
    'id'           => 'app-frontend',
    'name'         => 'SJ Nutrizione',
    'basePath'     => dirname(__DIR__),
    'bootstrap'    => ['log'],
    'defaultRoute' => 'site/index',
    'controllerNamespace' => 'frontend\controllers',
    'components' => [
        'request' => [
            'csrfParam' => '_csrf-frontend',
        ],
        'user' => [
            'identityClass'  => 'common\models\User',
            'enableAutoLogin'=> true,
            'identityCookie' => ['name' => '_identity-frontend', 'httpOnly' => true],
        ],
        'session' => [
            'name' => 'advanced-frontend',
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class'  => \yii\log\FileTarget::class,
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName'  => false,
            'rules' => [
                // ── webcms module — must come BEFORE the catch-all ──
                'webcms'                                    => 'webcms/default/index',
                'webcms/login'                              => 'webcms/default/login',
                'webcms/logout'                             => 'webcms/default/logout',
                'webcms/content'                            => 'webcms/default/content',
                'webcms/testimonials'                       => 'webcms/testimonial/index',
                'webcms/testimonials/add'                   => 'webcms/testimonial/create',
                'webcms/testimonials/edit/<id:\d+>'         => 'webcms/testimonial/update',
                'webcms/testimonials/toggle/<id:\d+>'       => 'webcms/testimonial/toggle',
                'webcms/testimonials/delete/<id:\d+>'       => 'webcms/testimonial/delete',
                'webcms/plans'                              => 'webcms/plan/index',
                'webcms/plans/add'                          => 'webcms/plan/create',
                'webcms/plans/edit/<id:\d+>'                => 'webcms/plan/update',
                'webcms/plans/toggle/<id:\d+>'              => 'webcms/plan/toggle',
                'webcms/plans/delete/<id:\d+>'              => 'webcms/plan/delete',

                // ── public site ──
                ''              => 'site/index',
                'plans'         => 'site/plans',
                'contact'       => 'site/contact',
                'get-started'   => 'site/lead',
                '<action:\w+>'  => 'site/<action>',
            ],
        ],
    ],
    'params' => $params,
];
