<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
?>
<?php
\backend\assets\CurpAsset::register($this);
\backend\assets\IcheckAsset::register($this);
$form = ActiveForm::begin();

$this->registerJs("$('#registros-fechanac').datepicker({
    format: 'dd-mm-yyyy',
                });", \yii\web\View::POS_END);


$this->registerJs('function generarCurp(){
    var curp = generaCurp({
        nombre: $("#registros-nombre").val(),
        apellido_paterno: $("#registros-apellidop").val(),
        apellido_materno: $("#registros-apellidom").val(),
        sexo: $("input[type=radio]:checked").val(),
        estado: $("#registros-lugarnac").val(),
        fecha_nacimiento: $("#registros-fechanac").val().split("-")
    });
$("#registros-curp").val(curp);    
};', \yii\web\View::POS_END);
?>
<div class="box box-primary">
    <div class="box-header with-border">
        <h3 class="box-title">Datos Generales</h3>
    </div>
    <div class="box-body">
        <div class="row margin">
            <div class="col-md-4">
                <?= $form->field($model, 'nombre')->textInput(['style' => 'text-transform: uppercase', 'maxlength' => true]) ?>
            </div>
            <div class="col-md-4">
                <?= $form->field($model, 'apellidop')->textInput(['style' => 'text-transform: uppercase', 'maxlength' => true]) ?>
            </div>
            <div class="col-md-4">
                <?= $form->field($model, 'apellidom')->textInput(['style' => 'text-transform: uppercase', 'maxlength' => true]) ?>
            </div>
        </div>
        <div class="row margin">
            <div class="col-md-4">
                <div class="form-group">
                    <?=
                    $form->field($model, 'genero')->radioList(
                            ['M' => 'Femenino', 'H' => 'Maculino']);
                    ?>

                </div>
            </div>
            <div class="col-md-4">
                <?=
                $form->field($model, 'fechanac')->textInput(['maxlength' => true])->widget(\yii\widgets\MaskedInput::className(), [
                    'mask' => '99-99-9999',
                ])
                ?>
            </div>
            <div class="col-md-4">
                <?=
                $form->field($model, 'lugarnac')->dropDownList(
                        \yii\helpers\ArrayHelper::map(app\models\Estados::find()->all(), 'clave', 'estado')
                )
                ?>
            </div>
        </div>
        <div class="row margin">
            <div class="col-md-4">
                <?= $form->field($model, 'correo')->textInput(['maxlength' => true]) ?>
            </div>
            <div class="col-md-4">
                <?= $form->field($model, 'curp')->textInput(['style' => 'text-transform: uppercase', 'maxlength' => true]) ?>
            </div>
            <div class="col-md-4">
                <button type="button" class="btn btn-app" onclick="generarCurp();">
                    <i class="fa fa-play"></i> Generar Curp
                </button>
            </div>
        </div>
    </div>
</div>

<div class="box box-success">
    <div class="box-header with-border">
        <h3 class="box-title">Datos de Linea</h3>
    </div>
    <div class="box-body">
        <div class="row margin">
            <div class="col-md-6">
                <?php
                echo $form->field($model, 'numero')->widget(\yii\widgets\MaskedInput::className(), [
                    'mask' => '999-999-9999',
                ])
                ?>
            </div>
            <div class="col-md-3">
                <?= $form->field($model, 'nip')->textInput(['maxlength' => true]) ?>
            </div>
            <div class="col-md-3">
                <?= $form->field($model, 'modelo')->textInput(['style' => 'text-transform: uppercase', 'maxlength' => true]) ?>
            </div>
        </div>
        <div class="row margin">
            <div class="col-md-3">
                <?=
                $form->field($model, 'dnref')->widget(\yii\widgets\MaskedInput::className(), [
                    'mask' => '999-999-9999',
                ])
                ?>
            </div>
            <div class="col-md-3">
                <?= $form->field($model, 'entrega')->textInput(['style' => 'text-transform: uppercase', 'maxlength' => true]) ?>
            </div>
            <div class="col-md-3">
                <?=
                $form->field($model, 'telefono_id')->dropDownList(
                        \yii\helpers\ArrayHelper::map(app\models\Telefono::find()->all(), 'id', 'liberado')
                )
                ?>
            </div>
            <div class="col-md-3">
                <?=
                $form->field($model, 'sim_id')->dropDownList(
                        \yii\helpers\ArrayHelper::map(app\models\Sim::find()->all(), 'id', 'tipo')
                )
                ?>
            </div>
        </div>

        <div class="box-footer">
            <div class="col-md-9">
                <?php
                if (\Yii::$app->user->can('isAdmin')) {
                    if (!$model->isNewRecord) {
                        echo $form->field($model, 'status_id')->dropDownList(
                                \yii\helpers\ArrayHelper::map(app\models\Statusr::find()->all(), 'id', 'status')
                        );
                        echo $form->field($model, 'created_by')->dropDownList(
                                \yii\helpers\ArrayHelper::map(\common\models\User::find()->all(), 'id', 'agente')
                        );
                    }
                }
                ?>
            </div>
            <div class="col-md-3">
                <?= Html::submitButton($model->isNewRecord ? 'Registrar' : 'Actualizar', ['class' => $model->isNewRecord ? 'btn btn-success pull-right' : 'btn btn-warning pull-right'])
                ?>
            </div>
        </div>
    </div>
</div>
<?php ActiveForm::end(); ?>

