<?php
namespace frontend\controllers;

use common\models\Customers;
use common\models\User;
use Yii;
use common\models\LoginForm;
use frontend\models\PasswordResetRequestForm;
use frontend\models\ResetPasswordForm;
use frontend\models\SignupForm;
use frontend\models\ContactForm;
use yii\base\InvalidParamException;
use yii\helpers\ArrayHelper;
use yii\web\BadRequestHttpException;
use yii\web\Controller;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use yii\web\Response;
use yii\widgets\ActiveForm;

/**
 * Site controller
 */
class CabinetController extends Controller
{

    public $layout = 'cabinet';

    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            'access' => [
                'class' => AccessControl::className(),
                'rules' => [
                    [
                        'actions' => ['login', 'error'],
                        'allow' => true,
                    ],
                    [
                        'actions' => ['logout', 'index', 'create', 'update', 'view', 'delete','my-orders','bookmarks'],
                        'allow' => true,
                        'roles' => ['@'],
                    ],
                ],
            ],
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'logout' => ['post'],
                ],
            ],
        ];
    }

    public function actionIndex(){
        return $this->render('index');
    }

    public function actionUpdate(){



        $model = Yii::$app->user->identity;


        if(Yii::$app->request->post()){

            $model->load(Yii::$app->request->post());
            $model->validate();

                if($model->validate()){
                    $model->save();
                    $this->redirect('index');

                }

        }


        return $this->render('update',[
            'model' =>$model
        ]);
    }


    public function actionBookmarks(){
        return $this->render('bookmarks',[

        ]);
    }

    public function actionMyOrders(){
        return $this->render('my-orders',[

        ]);
    }

}