<?php
/**
 * Mageplaza
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Mageplaza.com license that is
 * available through the world-wide-web at this URL:
 * https://www.mageplaza.com/LICENSE.txt
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade this extension to newer
 * version in the future.
 *
 * @category    Mageplaza
 * @package     Mageplaza_SocialLogin
 * @copyright   Copyright (c) Mageplaza (https://www.mageplaza.com/)
 * @license     https://www.mageplaza.com/LICENSE.txt
 */
?>
<div class="social-login block-container create" style="display: none">
    <div class="social-login-title">
        <h2 class="create-account-title"><?= __('Create New Account') ?></h2>
    </div>
    <div class="block col-mp mp-12">
        <div class="block-content">
            <?= $block->getChildHtml('form_fields_before') ?>
            <?= $block->getChildHtml('customer.form.register.extra') ?>
            <form class="form-customer-create" id="social-form-create">
                <fieldset class="fieldset create info">
                    <input type="hidden" name="success_url" value="<?= $block->getSuccessUrl() ?>"/>
                    <input type="hidden" name="error_url" value="<?= $block->getErrorUrl() ?>"/>
                    <?= $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Name')->setObject($block->getFormData())->setForceUseCustomerAttributes(true)->toHtml() ?>
                    <div class="field required">
                        <label for="email_address" class="label"><span><?= __('Email') ?></span></label>
                        <div class="control">
                            <input type="email" name="email" id="email_address_create"
                                   value="<?= $block->escapeHtml($block->getFormData()->getEmail()) ?>"
                                   title="<?= __('Email') ?>" class="input-text"
                                   data-validate="{required:true, 'validate-email':true}"/>
                        </div>
                    </div>
                    <?php if ($block->isNewsletterEnabled()) : ?>
                        <div class="field choice newsletter">
                            <input type="checkbox" class="checkbox" name="is_subscribed"
                                   title="<?= __('Sign Up for Newsletter') ?>" value="1"
                                   id="is_subscribed"<?php if ($block->getFormData()->getIsSubscribed()) :
                                        ?> checked="checked"<?php
                                                     endif; ?> />
                            <label for="is_subscribed"
                                   class="label"><span><?= __('Sign Up for Newsletter') ?></span></label>
                        </div>
                        <?= $block->getChildHtml('customer.form.register.newsletter') ?>
                    <?php endif ?>
                    <?php $_dob = $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Dob') ?>
                    <?php if ($_dob->isEnabled()) : ?>
                        <div class="field date field-dob">
                            <label class="label" for="dob"><span><?= __('Date of Birth') ?></span></label>
                            <div class="control customer-dob">
                                <input type="text" name="mp_sociallogin_dob" id="mp_sociallogin_dob" value="" class="" data-validate="{"validate-date":{"dateFormat":"M\/d\/Y"}}"/>
                                <script type="text/javascript">
                                    require(["jquery", "mage/calendar"], function($){
                                        $("#mp_sociallogin_dob").calendar({
                                            showsTime: false,
                                            dateFormat: "M/d/Y",
                                            buttonImage: "<?= /* @noEscape */ $_dob->getViewFileUrl('Magento_Theme::calendar.png')?>",
                                            yearRange: "-120y:c+nn",
                                            buttonText: "Select Date",
                                            maxDate: "-1d",
                                            changeMonth: true,
                                            changeYear: true,
                                            showOn: "both"
                                        })
                                    });
                                </script>
                            </div>
                        </div>
                    <?php endif ?>
                    <?php $_taxvat = $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Taxvat') ?>
                    <?php if ($_taxvat->isEnabled()) : ?>
                        <?= $_taxvat->setTaxvat($block->getFormData()->getTaxvat())->toHtml() ?>
                    <?php endif ?>
                    <?php $_gender = $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Gender') ?>
                    <?php if ($_gender->isEnabled()) : ?>
                        <?= $_gender->setGender($block->getFormData()->getGender())->toHtml() ?>
                    <?php endif ?>
                </fieldset>
                <?php if ($block->getShowAddressFields()) : ?>
                    <fieldset class="fieldset address">
                        <legend class="legend"><span><?= __('Address Information') ?></span></legend>
                        <br>
                        <input type="hidden" name="create_address" value="1"/>
                        <div class="field company">
                            <label for="company" class="label"><span><?= __('Company') ?></span></label>
                            <div class="control">
                                <input type="text" name="company" id="company"
                                       value="<?= $block->escapeHtml($block->getFormData()->getCompany()) ?>"
                                       title="<?= __('Company') ?>"
                                       class="input-text <?= $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('company') ?>"/>
                            </div>
                        </div>
                        <div class="field telephone">
                            <label for="telephone" class="label"><span><?= __('Phone Number') ?></span></label>
                            <div class="control">
                                <input type="text" name="telephone" id="telephone"
                                       value="<?= $block->escapeHtml($block->getFormData()->getTelephone()) ?>"
                                       title="<?= __('Phone Number') ?>"
                                       class="input-text <?= $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('telephone') ?>"/>
                            </div>
                        </div>

                        <?php $_streetValidationClass = $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('street'); ?>
                        <div class="field street required">
                            <label for="street_1" class="label"><span><?= __('Street Address') ?></span></label>
                            <div class="control">
                                <input type="text" name="street[]"
                                       value="<?= $block->escapeHtml($block->getFormData()->getStreet(0)) ?>"
                                       title="<?= __('Street Address') ?>" id="street_1"
                                       class="input-text <?= $_streetValidationClass ?>"/>
                                <div class="nested">
                                    <?php $_streetValidationClass = trim(str_replace('required-entry', '', $_streetValidationClass)); ?>
                                    <?php for ($_i = 2, $_n = $this->helper('Magento\Customer\Helper\Address')->getStreetLines(); $_i <= $_n; $_i++) : ?>
                                        <div class="field additional">
                                            <label class="label"
                                                   for="street_<?= $_i ?>"><span><?= __('Address') ?></span></label>
                                            <div class="control">
                                                <input type="text" name="street[]"
                                                       value="<?= $block->escapeHtml($block->getFormData()->getStreetLine($_i - 1)) ?>"
                                                       title="<?= __('Street Address %1', $_i) ?>"
                                                       id="street_<?= $_i ?>"
                                                       class="input-text <?= $_streetValidationClass ?>"/>
                                            </div>
                                        </div>
                                    <?php endfor; ?>
                                </div>
                            </div>
                        </div>
                        <div class="field required">
                            <label for="city" class="label"><span><?= __('City') ?></span></label>
                            <div class="control">
                                <input type="text" name="city"
                                       value="<?= $block->escapeHtml($block->getFormData()->getCity()) ?>"
                                       id="city"
                                       title="<?= __('City') ?>"
                                       class="input-text <?= $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('city') ?>"/>
                            </div>
                        </div>
                        <div class="field region required">
                            <label for="region_id" class="label"><span><?= __('State/Province') ?></span></label>
                            <div class="control">
                                <select id="region_id" name="region_id" title="<?= __('State/Province') ?>"
                                        class="validate-select" style="display:none;">
                                    <option value=""><?= __('Please select a region, state or province.') ?></option>
                                </select>
                                <input type="text" id="region" name="region"
                                       value="<?= $block->escapeHtml($block->getRegion()) ?>"
                                       title="<?= __('State/Province') ?>"
                                       class="input-text <?= $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('region') ?>"
                                       style="display:none;"/>
                            </div>
                        </div>
                        <div class="field zip required">
                            <label for="zip" class="label"><span><?= __('Zip/Postal Code') ?></span></label>
                            <div class="control">
                                <input type="text" name="postcode"
                                       value="<?= $block->escapeHtml($block->getFormData()->getPostcode()) ?>"
                                       title="<?= __('Zip/Postal Code') ?>" id="zip"
                                       class="input-text validate-zip-international <?= $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('postcode') ?>">
                            </div>
                        </div>
                        <div class="field country required">
                            <label for="country" class="label"><span><?= __('Country') ?></span></label>
                            <div class="control"><?= $block->getCountryHtmlSelect() ?></div>
                        </div>

                        <?php $addressAttributes = $block->getChildBlock('customer_form_address_user_attributes'); ?>
                        <?php if ($addressAttributes) : ?>
                            <?php $addressAttributes->setEntityType('customer_address'); ?>
                            <?php $addressAttributes->setFieldIdFormat('address:%1$s')->setFieldNameFormat('address[%1$s]'); ?>
                            <?php $block->restoreSessionData($addressAttributes->getMetadataForm(), 'address'); ?>
                            <?= $addressAttributes->setShowContainer(false)->toHtml() ?>
                        <?php endif; ?>
                        <input type="hidden" name="default_billing" value="1">
                        <input type="hidden" name="default_shipping" value="1">
                    </fieldset>
                <?php endif; ?>
                <fieldset class="fieldset create account" data-hasrequired="<?= __('* Required Fields') ?>">
                    <div class="field password required">
                        <label for="password" class="label"><span><?= __('Password') ?></span></label>
                        <div class="control">
                            <input type="password" name="password" id="password-social"
                                   title="<?= __('Password') ?>" class="input-text"
                                   data-validate="{required:true, 'validate-password':true}" autocomplete="off"/>
                        </div>
                    </div>
                    <div class="field confirmation required">
                        <label for="password-confirmation"
                               class="label"><span><?= __('Confirm Password') ?></span></label>
                        <div class="control">
                            <input type="password" name="password_confirmation"
                                   title="<?= __('Confirm Password') ?>" id="password-confirmation-social"
                                   class="input-text" data-validate="{required:true, equalTo:'#password-social'}"
                                   autocomplete="off"/>
                        </div>
                    </div>
                    <?= $block->getChildHtml('form_additional_info') ?>
                    <?= $block->getChildHtml('create-msp-recaptcha') ?>
                    <?php echo $block->getChildHtml('create.captcha') ?>
                </fieldset>
                <div class="actions-toolbar">
                    <div class="primary">
                        <button type="button" id="button-create-social" class="action create primary"
                                title="<?= __('Create an Account') ?>">
                            <span><?= __('Create an Account') ?></span></button>
                        <div class="secondary">
                            <a class="action back" href="#"><span><?= __('Back') ?></span></a>
                        </div>
                    </div>
                </div>
            </form>
            <script>
                require([
                    'jquery',
                    'mage/mage'
                ], function ($) {
                    var dataForm = $('#social-form-create'),
                        ignore = <?= $_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>
            <?php if ($block->getShowAddressFields()) : ?>
                <script type="text/x-magento-init">
                    {
                        "#country": {
                            "regionUpdater": {
                                "optionalRegionAllowed": <?= $block->getConfig('general/region/display_all') ? 'true' : 'false' ?>,
                                "regionListId": "#region_id",
                                "regionInputId": "#region",
                                "postcodeId": "#zip",
                                "form": "#form-validate",
                                "regionJson": <?= $this->helper('Magento\Directory\Helper\Data')->getRegionJson() ?>,
                                "defaultRegion": "<?= $block->getFormData()->getRegionId() ?>",
                                "countriesWithOptionalZip": <?= $this->helper('Magento\Directory\Helper\Data')->getCountriesWithOptionalZip(true) ?>
                            }
                        }
                    }

                </script>
            <?php endif; ?>
        </div>
    </div>
</div>
