<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\captcha\Captcha;
use kartik\file\FileInput;

/**
 * @var yii\web\View $this
 * @var app\models\RegistrationForm $model
 */

$this->title = Yii::t('user', 'Sign up');
$this->params['breadcrumbs'][] = $this->title;

$files = new \app\models\Files();
?>

<div class="col-md-6 col-md-offset-3">
    <div class="panel panel-primary">
        <div class="panel-heading">
            <span class="glyphicon glyphicon-qrcode"></span>
            <strong><?= Html::encode($this->title) ?></strong>
        </div>
        <div class="panel-body">
            <div class="row">
                <div class="col">
                    <?= Html::errorSummary($model, ['class' => 'alert alert-danger']) ?>
                    <?php $form = ActiveForm::begin([
                        'id' => 'registration-form',
                        'enableAjaxValidation' => true,
                        'enableClientValidation' => true,
                    ]); ?>

                    <!-- Роль пользователя -->
                    <?= $form->field($model, 'role')->radioList([
                        '2' => Yii::t('app', 'Member'),
                        '1' => Yii::t('app', 'Organizer'),
                    ], [
                        'class' => 'role-selector',
                    ]) ?>

                    <?= $form->field($model, 'org_type')->radioList([
                        'entity' => Yii::t('app', 'Entity'),
                        'individual' => Yii::t('app', 'Individual'),
                        'fop' => Yii::t('app', 'FOP'),
                    ]) ?>


                    <?= $form->field($model, 'at_org') ?>

                    <?= $form->field($model, 'fio') ?>
                    <?= $form->field($model, 'phone')->widget(\yii\widgets\MaskedInput::className(), [
                        'mask' => '+389999999999',
                    ]) ?>             
                    <?= $form->field($model, 'inn') ?>
                    <?= $form->field($model, 'u_address') ?>
                    <?= $form->field($model, 'f_address') ?>

                    <?= $form->field($model, 'member')->textInput()->label(Yii::t('app', 'MemberFrom ID')) ?>

                    <?php echo $form->field($files, 'file')->widget(FileInput::classname(), [
                        'model' => $files,
                        'pluginOptions' => [
                            //'allowedFileExtensions'=>['doc','docx','pdf', 'png', ],
                            'initialCaption'=>'*.doc *.docx *.pdf *.png *.jpg *.tiff, *.zip *rar',
                            'showPreview' => false,
                            'showCaption' => true,
                            'showRemove' => false,
                            'showUpload' => false
                        ],
                        'options' => ['multiple' => true,],

                    ])->label(Yii::t('app','Документи')); ?>                    

                    <!-- Поля пользователя -->
                    <?= $form->field($model, 'email') ?>
                    <?= $form->field($model, 'username') ?>
                    <?= $form->field($model, 'password')->passwordInput() ?>
                    <?= $form->field($model, 'repeatpassword')->passwordInput() ?>

                    <!-- Captcha -->

                    <!-- Кнопка регистрации -->
                    <?= Html::submitButton(Yii::t('user', 'Sign up'), ['class' => 'btn btn-success btn-block']) ?>

                    <?php ActiveForm::end(); ?>
                </div>
            </div>
        </div>
    </div>
</div>


<?php
$script = <<<JS
function updateVisibility() {
    var role = $('input[name="register-form[role]"]:checked').val();
    var orgType = $('input[name="register-form[org_type]"]:checked').val();

    $('.field-register-form-at_org').show();    
    if (orgType === 'entity') {
        $('.field-register-form-at_org').hide();
        
    }
    
    // $('.field-register-form-member').show();
    // if (orgType !== 'individual' || orgType !== 'fop') {
    //     $('.field-register-form-member').hide();
    // }

    // console.log(role, orgType);
}

$(document).on('change', '.role-selector input, #register-form-org_type input', updateVisibility);
updateVisibility();
JS;

$this->registerJs($script);
?>
