<?php
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

/** @var \Magento\Customer\Block\Form\Edit $block */
?>
<form class="form form-edit-account" action="<?php /* @escapeNotVerified */
echo $block->getUrl('customer/account/editPost') ?>" method="post" id="form-validate" enctype="multipart/form-data" data-hasrequired="<?php /* @escapeNotVerified */
echo __('* Required Fields') ?>" autocomplete="off">
    <div class="row">
        <div class="col-md-6">
            <fieldset class="fieldset info">
                <?php echo $block->getBlockHtml('formkey') ?>
                <legend class="legend"><span><?php /* @escapeNotVerified */
                        echo __('Account Information') ?></span></legend>
                <br>
                <?php echo $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Name')->setObject($block->getCustomer())->toHtml() ?>

                <?php $_dob = $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Dob') ?>
                <?php $_taxvat = $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Taxvat') ?>
                <?php $_gender = $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Gender') ?>
                <?php if ($_dob->isEnabled()): ?>
                    <?php echo $_dob->setDate($block->getCustomer()->getDob())->toHtml() ?>
                <?php endif ?>
                <?php if ($_taxvat->isEnabled()): ?>
                    <?php echo $_taxvat->setTaxvat($block->getCustomer()->getTaxvat())->toHtml() ?>
                <?php endif ?>
                <?php if ($_gender->isEnabled()): ?>
                    <?php echo $_gender->setGender($block->getCustomer()->getGender())->toHtml() ?>
                <?php endif ?>
                <div class="form-group">
                    <div class="custom-control custom-checkbox">
                        <input type="checkbox" name="change_email" id="change-email" data-role="change-email" value="1" title="<?php /* @escapeNotVerified */
                        echo __('Change Email') ?>" class="checkbox custom-control-input"/>
                        <label for="change-email" class="custom-control-label"><?php /* @escapeNotVerified */ echo __('Change Email') ?></label>
                    </div>
                </div>
                <div class="form-group">
                    <div class="custom-control custom-checkbox">
                        <input type="checkbox" name="change_password" id="change-password" data-role="change-password" value="1" title="<?php /* @escapeNotVerified */
                        echo __('Change Password') ?>"<?php if ($block->getChangePassword()): ?> checked="checked"<?php endif; ?>
                               class="checkbox custom-control-input"/>
                        <label for="change-password" class="custom-control-label"><?php /* @escapeNotVerified */ echo __('Change Password') ?></label>
                    </div>
                </div>
            </fieldset>
        </div>
        <div class="col-md-6">
            <fieldset class="fieldset password" data-container="change-email-password">
                <legend class="legend"><span data-title="change-email-password"><?php /* @escapeNotVerified */
                        echo __('Change Email and Password') ?></span></legend>
                <br>
                <div class="field email required" data-container="change-email">
                    <label for="email"><span><?php /* @escapeNotVerified */
                            echo __('Email') ?></span></label>
                    <div class="control">
                        <input type="email" name="email" id="email" autocomplete="email" data-input="change-email"
                               value="<?php echo $block->escapeHtml($block->getCustomer()->getEmail()) ?>" title="<?php /* @escapeNotVerified */
                        echo __('Email') ?>" class="form-control" data-validate="{required:true, 'validate-email':true}"/>
                    </div>
                </div>
                <div class="field password current required">
                    <label for="current-password"><span><?php /* @escapeNotVerified */
                            echo __('Current Password') ?></span></label>
                    <div class="control">
                        <input type="password" class="form-control" name="current_password" id="current-password" data-input="current-password" autocomplete="off"/>
                    </div>
                </div>
                <div class="field new password required" data-container="new-password" data-mage-init='{"passwordStrengthIndicator": {}}'>
                    <label for="password"><span><?php /* @escapeNotVerified */
                            echo __('New Password') ?></span></label>
                    <div class="control">
                        <input type="password" class="form-control" name="password" id="password"
                               data-password-min-length="<?php echo $block->escapeHtml($block->getMinimumPasswordLength()) ?>"
                               data-password-min-character-sets="<?php echo $block->escapeHtml($block->getRequiredCharacterClassesNumber()) ?>"
                               data-input="new-password"
                               data-validate="{required:true, 'validate-customer-password':true}"
                               autocomplete="off"/>
                        <div id="password-strength-meter-container" data-role="password-strength-meter">
                            <div id="password-strength-meter" class="password-strength-meter">
                                <?php /* @escapeNotVerified */
                                echo __('Password Strength'); ?>:
                                <span id="password-strength-meter-label" data-role="password-strength-meter-label">
                            <?php /* @escapeNotVerified */
                            echo __('No Password'); ?>
                        </span>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="field confirm password required" data-container="confirm-password">
                    <label for="password-confirmation"><span><?php /* @escapeNotVerified */
                            echo __('Confirm New Password') ?></span></label>
                    <div class="control">
                        <input type="password" class="form-control" name="password_confirmation" id="password-confirmation"
                               data-input="confirm-password"
                               autocomplete="off"/>
                    </div>
                </div>
                <?php echo $block->getChildHtml('form_additional_info'); ?>
            </fieldset>
        </div>
    </div>

    <button type="submit" class="btn btn-primary" title="<?php /* @escapeNotVerified */
    echo __('Save') ?>"><span><?php /* @escapeNotVerified */
            echo __('Save') ?></span></button>

    <a class="btn btn-danger" href="<?php echo $block->escapeUrl($block->getBackUrl()) ?>"><span><?php /* @escapeNotVerified */
            echo __('Go back') ?></span></a>

</form>
<script>
    require([
        "jquery",
        "mage/mage"
    ], function ($) {
        var dataForm = $('#form-validate');
        var ignore = <?php /* @escapeNotVerified */ echo $_dob->isEnabled() ? '\'input[id$="full"]\'' : 'null'; ?>;

        dataForm.mage('validation', {
            <?php if ($_dob->isEnabled()): ?>
            errorPlacement: function (error, element) {
                if (element.prop('id').search('full') !== -1) {
                    var dobElement = $(element).parents('.customer-dob'),
                        errorClass = error.prop('class');
                    error.insertAfter(element.parent());
                    dobElement.find('.validate-custom').addClass(errorClass)
                        .after('<div class="' + errorClass + '"></div>');
                }
                else {
                    error.insertAfter(element);
                }
            },
            ignore: ':hidden:not(' + ignore + ')'
            <?php else: ?>
            ignore: ignore ? ':hidden:not(' + ignore + ')' : ':hidden'
            <?php endif ?>
        });

    });
</script>
<script type="text/x-magento-init">
    {
        "[data-role=change-email], [data-role=change-password]": {
            "changeEmailPassword": {
                "titleChangeEmail": "<?php /* @escapeNotVerified */
    echo __('Change Email') ?>",
                "titleChangePassword": "<?php /* @escapeNotVerified */
    echo __('Change Password') ?>",
                "titleChangeEmailAndPassword": "<?php /* @escapeNotVerified */
    echo __('Change Email and Password') ?>"
            }
        }
    }


</script>
