<?php
namespace common\widgets;
use common\models\Language;
use yii\base\InvalidParamException;
use yii\base\Widget;
use yii\bootstrap\ActiveForm;

class Multilang extends Widget
{
    public $id;

    public $langs;

    public $data_langs = [];

    public $ajaxpath;

    public $form;

    public function init()
    {
        parent::init();
        if(empty($this->id)) {
            $this->id = \Yii::$app->security->generateRandomString(8);
        }
        if(empty($this->langs)) {
            $this->langs = Language::getActiveLanguages();
        }
        if(empty($this->ajaxpath)) {
            throw new InvalidParamException('ajaxpath must be set');
        }
        if(empty($this->form)) {
            throw new InvalidParamException('form must be set');
        }
        ob_start();
        echo $this->render('multilang-begin', ['id' => $this->id, 'langs' => $this->langs, 'data_langs' => $this->data_langs, 'ajaxpath' => $this->ajaxpath, 'form' => $this->form]);
    }

    public function run()
    {
        echo $this->render('multilang-end', ['id' => $this->id, 'langs' => $this->langs, 'data_langs' => $this->data_langs, 'ajaxpath' => $this->ajaxpath, 'form' => $this->form]);
        $content = ob_get_clean();
        return $content;
    }
}