<?
/**
 * @global CMain $APPLICATION
 * @var array $arParams
 * @var array $arResult
 */
if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true)
    die();

CJSCore::Init([
        'masked_input'
    ]
);

?>
<? ShowError($arResult["strProfileError"]); ?>
<?
if ($arResult['DATA_SAVED'] == 'Y')
    ShowNote(GetMessage('PROFILE_DATA_SAVED'));
?>

<form class="user_profile_data" method="post" name="form1" action="<?= $arResult["FORM_TARGET"] ?>"
      enctype="multipart/form-data">
    <?= $arResult["BX_SESSION_CHECK"] ?>
    <input type="hidden" name="lang" value="<?= LANG ?>"/>
    <input type="hidden" name="ID" value=<?= $arResult["ID"] ?>/>

    <?
    if (strlen($arResult['arUser']['PERSONAL_PHOTO']) > 0) {
        $renderImage = CFile::ResizeImageGet(
            $arResult['arUser']['PERSONAL_PHOTO'],
            array("width" => 64, "height" => 64),
            BX_RESIZE_IMAGE_PROPORTIONAL_ALT, false
        );
        $userPic = $renderImage['src'];
    } else {
        $userPic = '/local/img/nophoto.jpg';
    }
    ?>
    <div class="user_profile_data_photo">
        <input accept="image/*"
               onchange="document.getElementById('user_pic').src = window.URL.createObjectURL(this.files[0])"
               type="file"
               name="PERSONAL_PHOTO">
        <img src="<?= $userPic ?>" id="user_pic"/>
    </div>
    <div class="user_profile_radio">
        <label>Пол</label>
        <div class="user_profile_radio_item">
            <input type="radio" id="p2" <?= $arResult["arUser"]["PERSONAL_GENDER"] == "F" ? " checked" : "" ?>
                   name="PERSONAL_GENDER" value="F">
            <label for="p2">Мужской</label>
        </div>
        <div class="user_profile_radio_item">
            <input type="radio" id="p1" <?= $arResult["arUser"]["PERSONAL_GENDER"] == "M" ? " checked" : "" ?>
                   name="PERSONAL_GENDER" value="M">
            <label for="p1">Женский</label>
        </div>
    </div>
    <div class="user_profile_data_field user_profile_data_field_name">
        <label>Имя</label>
        <input type="text" name="NAME" maxlength="50" value="<?= $arResult["arUser"]["NAME"] ?>"/>
    </div>
    <div class="user_profile_data_field user_profile_data_field_name">
        <label>Фамилия</label>
        <input type="text" name="LAST_NAME" maxlength="50"
               value="<?= $arResult["arUser"]["LAST_NAME"] ?>"/>
    </div>
    <div class="user_profile_data_field user_profile_data_field_name">
        <label>Отчество</label>
        <input type="text" name="SECOND_NAME" maxlength="50"
               value="<?= $arResult["arUser"]["SECOND_NAME"] ?>"/>
    </div>
    <div class="user_profile_data_field">
        <label>Телефон</label>
        <input type="text" name="PERSONAL_MOBILE" maxlength="255" id="phone"
               value="<?= $arResult["arUser"]["PERSONAL_MOBILE"] ?>"/>
    </div>
    <div class="user_profile_data_field">
        <label>Город</label>
        <select name="PERSONAL_CITY" id="SELECT_CITY" required>
            <? if (empty($arResult['arUser']['PERSONAL_CITY'])) { ?>
                <option value="">
                    Выберите город
                </option>
            <? } else { ?>
                <option value="<?= $arResult['arUser']['PERSONAL_CITY'] ?>">
                    <?= $arResult['arUser']['PERSONAL_CITY'] ?>
                </option>
            <? } ?>
            <? foreach ($arResult['CITIES'] as $CITY) {
                if (!empty($arResult['arUser']['PERSONAL_CITY'])) {
                    if ($arResult['arUser']['PERSONAL_CITY'] === $CITY['NAME_RU']) {
                        continue;
                    }
                }
                ?>
                <option value="<? echo $CITY['NAME_RU'] ?>">
                    <? echo $CITY['NAME_RU'] ?>
                </option>
            <? } ?>
        </select>
    </div>
    <div class="user_profile_data_hr"></div>
    <div class="user_profile_data_field user_profile_data_field_name">
        <label>E-mail</label>
        <input type="text" class="hidden" name="LOGIN" id="duble" maxlength="50"
               value="<? echo $arResult["arUser"]["LOGIN"] ?>"/>
        <input type="text" name="EMAIL" onkeyup="duble.value = this.value" maxlength="50"
               value="<? echo $arResult["arUser"]["EMAIL"] ?>"/>
    </div>
    <div class="user_profile_data_field user_profile_data_field_name">
        <label><?= GetMessage('NEW_PASSWORD_REQ') ?></label>
        <input type="password" name="NEW_PASSWORD" maxlength="50" value="" placeholder="******" autocomplete="off"/>
    </div>
    <div class="user_profile_data_field user_profile_data_field_name">
        <label><?= GetMessage('NEW_PASSWORD_CONFIRM') ?></label>
        <input type="password" name="NEW_PASSWORD_CONFIRM" maxlength="50" value="" placeholder="******"
               autocomplete="off"/>
    </div>
    <input type="submit" name="save" class="btn btn_colored"
           value="Сохранить изменения">
</form>


<script>
    $(document).ready(function () {
        $("#SELECT_CITY").select2();
    });
    BX.ready(function () {
        var result = new BX.MaskedInput({
            mask: '+7 999 999 99 99', // устанавливаем маску
            input: BX('phone'),
            placeholder: '_' // символ замены +7 ___ ___ __ __
        });
        result.setValue(''); // устанавливаем значение
    });
</script>


