<?php
// @codingStandardsIgnoreFile
/**
 * @var $block \Magento\Customer\Block\Form\Register
 */

$address = $block->getAddress();
$addressHelper = $this->helper('Magento\Customer\Helper\Address');
$company = $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Company');
$telephone = $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Telephone');
?>
<?= $block->getChildHtml('form_fields_before') ?>
<?php /* Extensions placeholder */ ?>
<?= $block->getChildHtml('customer.form.register.extra') ?>
<div class="cs-dashboard__block">
    <form
        class="cs-form | form-create-account"
        action="<?= /* @escapeNotVerified */ $block->getPostActionUrl() ?>"
        method="post"
        id="form-validate"
        enctype="multipart/form-data"
        autocomplete="off"
    >
    <?= /* @noEscape */ $block->getBlockHtml('formkey'); ?>
        <fieldset class="cs-form__fieldset cs-form__fieldset--level_1 | create info">
            <legend class="cs-title-block cs-title-block--bordered cs-title-block--space-bottom">
                <span class="cs-title-block__span | cs-t-headline cs-t-headline--size_2 cs-t-headline--look_light">
                    <?= /* @escapeNotVerified */ __('Personal Information') ?>
                </span>
            </legend>

            <input type="hidden" name="success_url" value="<?= /* @escapeNotVerified */ $block->getSuccessUrl() ?>">
            <input type="hidden" name="error_url" value="<?= /* @escapeNotVerified */ $block->getErrorUrl() ?>">
            <?= $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Name')->setObject($block->getFormData())->setForceUseCustomerAttributes(true)->toHtml() ?>

            <?php $dob = $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Dob') ?>
            <?php if ($dob->isEnabled()): ?>
                <?= $dob->setDate($block->getFormData()->getDob())->toHtml() ?>
            <?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 ?>
            <?php if ($block->isNewsletterEnabled()): ?>
                <div class="cs-form__field | cs-input cs-input--type-checkbox | newsletter">
                    <input
                        type="checkbox"
                        name="is_subscribed"
                        title="<?= /* @escapeNotVerified */ __('Sign Up for Newsletter') ?>"
                        value="1"
                        id="is_subscribed"
                        <?php if ($block->getFormData()->getIsSubscribed()): ?> checked="checked"<?php endif; ?>
                        class="cs-input__checkbox"
                    >
                    <label for="is_subscribed" class="cs-input__label">
                        <span><?= /* @escapeNotVerified */ __('Sign Up for Newsletter') ?></span>
                    </label>
                </div>
                <?php /* Extensions placeholder */ ?>
                <?= $block->getChildHtml('customer.form.register.newsletter') ?>
            <?php endif ?>
        </fieldset>
        <?php if ($block->getShowAddressFields()): ?>
            <fieldset class="cs-form__fieldset cs-form__fieldset--level_1 | address">
                <div class="cs-form__fields-wrapper">
                    <legend class="cs-title-block cs-title-block--bordered cs-title-block--space-bottom">
                    <span class="cs-title-block__span | cs-t-headline cs-t-headline--size_2 cs-t-headline--look_light">
                        <?= /* @escapeNotVerified */ __('Address Information') ?>
                    </span>
                    </legend>

                    <input type="hidden" name="create_address" value="1"/>
                    <?php if ($company->isEnabled()): ?>
                    <div class="cs-form__field | cs-input | company">
                        <label for="company" class="cs-input__label">
                            <?= /* @escapeNotVerified */ __('Company') ?>
                        </label>

                        <div class="cs-input__control">
                            <input
                                type="text"
                                name="company"
                                id="company"
                                value="<?= $block->escapeHtml($block->getFormData()->getCompany()) ?>"
                                title="<?= /* @escapeNotVerified */ __('Company') ?>"
                                class="cs-input__input <?= /* @escapeNotVerified */ $addressHelper->getAttributeValidationClass('company') ?>"
                            >
                        </div>
                    </div>
                    <?php endif; ?>

                    <?php if ($telephone->isEnabled()): ?>
                    <div class="cs-form__field | cs-input | telephone <?= $addressHelper->getAttributeValidationClass('telephone') ?>">
                        <label for="telephone" class="cs-input__label">
                            <span><?= /* @escapeNotVerified */ __('Phone Number') ?></span>
                        </label>

                        <div class="cs-input__control">
                            <input
                                type="text"
                                name="telephone"
                                id="telephone"
                                value="<?= $block->escapeHtml($block->getFormData()->getTelephone()) ?>"
                                title="<?= /* @escapeNotVerified */ __('Phone Number') ?>"
                                class="cs-input__input <?= /* @escapeNotVerified */ $addressHelper->getAttributeValidationClass('telephone') ?>"
                            >
                        </div>
                    </div>
                    <?php endif; ?>

                    <?php $streetValidationClass = $addressHelper->getAttributeValidationClass('street'); ?>

                    <div class="cs-form__field | cs-input | street required">
                        <label for="street_1" class="cs-input__label"><?= /* @escapeNotVerified */ __('Street Address') ?></label>

                        <div class="cs-input__control">
                            <input
                                type="text"
                                name="street[]"
                                value="<?= $block->escapeHtml($block->getFormData()->getStreet(0)) ?>"
                                title="<?= /* @escapeNotVerified */ __('Street Address') ?>"
                                id="street_1"
                                class="cs-input__input <?= /* @escapeNotVerified */ $streetValidationClass ?>"
                            >

                            <div class="nested">
                                <?php $streetValidationClass = trim(str_replace('required-entry', '', $streetValidationClass)); ?>
                                <?php for ($lineNumber = 2, $totalLines = $addressHelper->getStreetLines(); $lineNumber <= $totalLines; $lineNumber++): ?>
                                    <div class="cs-form__field cs-form__field--space-top | cs-input | additional no-required">
                                        <label class="cs-input__label" for="street_<?= /* @escapeNotVerified */ $lineNumber ?>">
                                            <?= /* @escapeNotVerified */ __('Addtional Address Line') ?>
                                        </label>

                                        <div class="cs-input__control">
                                            <input
                                                type="text"
                                                name="street[]"
                                                value="<?= $block->escapeHtml($block->getFormData()->getStreetLine($lineNumber - 1)) ?>"
                                                title="<?= /* @escapeNotVerified */ __('Street Address %1', $lineNumber) ?>"
                                                id="street_<?= /* @escapeNotVerified */ $lineNumber ?>"
                                                class="cs-input__input <?= /* @escapeNotVerified */ $streetValidationClass ?>"
                                            >
                                        </div>
                                    </div>
                                <?php endfor; ?>
                            </div>
                        </div>
                    </div>

                    <div class="cs-form__field cs-form__field--type_zip | cs-input | zip required">
                        <label for="zip" class="cs-input__label">
                            <span><?= /* @escapeNotVerified */ __('Zip/Postal Code') ?></span>
                        </label>

                        <div class="cs-input__control">
                            <input
                                type="text"
                                name="postcode"
                                value="<?= $block->escapeHtml($block->getFormData()->getPostcode()) ?>"
                                title="<?= /* @escapeNotVerified */ __('Zip/Postal Code') ?>"
                                id="zip"
                                class="cs-input__input validate-zip-international <?= /* @escapeNotVerified */ $addressHelper->getAttributeValidationClass('postcode') ?>"
                            >
                        </div>
                    </div>

                    <div class="cs-form__field cs-form__field--type_city | cs-input | required">
                        <label for="city" class="cs-input__label">
                            <span><?= /* @escapeNotVerified */ __('City') ?></span>
                        </label>

                        <div class="cs-input__control">
                            <input
                                type="text"
                                name="city"
                                value="<?= $block->escapeHtml($block->getFormData()->getCity()) ?>"
                                title="<?= /* @escapeNotVerified */ __('City') ?>"
                                class="cs-input__input <?= /* @escapeNotVerified */ $addressHelper->getAttributeValidationClass('city') ?>"
                                id="city"
                            >
                        </div>
                    </div>

                    <div class="cs-form__field | cs-input | country required">
                        <label for="country" class="cs-input__label">
                            <span><?= /* @escapeNotVerified */ __('Country') ?></span>
                        </label>
                        <div class="cs-input__control">
                            <?= $block->getCountryHtmlSelect() ?>
                        </div>
                    </div>

                    <div class="cs-form__field | cs-input | region no-required">
                        <label for="region_id" class="cs-input__label">
                            <?= /* @escapeNotVerified */ __('State/Province') ?>
                        </label>

                        <div class="cs-input__control">
                            <select
                                id="region_id"
                                name="region_id"
                                title="<?= /* @escapeNotVerified */ __('State/Province') ?>"
                                class="cs-input__select"
                                style="display:none;"
                                >
                                <option value="">
                                    <?= /* @escapeNotVerified */ __('Please select a region, state or province.') ?>
                                </option>
                            </select>
                            <input
                                type="text"
                                id="region"
                                name="region"
                                value="<?= $block->escapeHtml($block->getRegion()) ?>"
                                title="<?= /* @escapeNotVerified */ __('State/Province') ?>"
                                class="cs-input__input <?= /* @escapeNotVerified */ $addressHelper->getAttributeValidationClass('region') ?>"
                                style="display:none;"
                                >
                        </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">

                </div>

            </fieldset>

        <?php endif; ?>
        <fieldset
            class="cs-form__fieldset cs-form__fieldset--level_1 | create account"
            data-hasrequired="<?= /* @escapeNotVerified */ __('* Required Fields') ?>"
        >
            <legend class="cs-title-block cs-title-block--bordered cs-title-block--space-bottom">
                    <span class="cs-title-block__span | cs-t-headline cs-t-headline--size_2 cs-t-headline--look_light">
                        <?= /* @escapeNotVerified */  __('Sign-in Information') ?>
                    </span>
            </legend>

            <div class="cs-form__field | cs-input | required">
                <label for="email_address" class="cs-input__label">
                    <span><?= /* @escapeNotVerified */ __('Email') ?></span>
                </label>

                <div class="cs-input__control">
                    <input
                        type="email"
                        name="email"
                        autocomplete="email"
                        id="email_address"
                        value="<?= $block->escapeHtml($block->getFormData()->getEmail()) ?>"
                        title="<?= /* @escapeNotVerified */ __('Email') ?>"
                        class="input-text"
                        data-validate="{required:true, 'validate-email':true}"
                    >
                </div>
            </div>
            <div class="cs-form__field | cs-input | password required" data-mage-init='{"passwordStrengthIndicator": {}}'>
                <label for="password" class="cs-input__label">
                    <span><?= /* @escapeNotVerified */ __('Password') ?></span>
                </label>

                <div class="cs-input__control">
                    <input type="password"
                           name="password"
                           id="password"
                           title="<?= /* @escapeNotVerified */ __('Password') ?>"
                           class="input-text"
                           data-password-min-length="<?= $block->escapeHtml($block->getMinimumPasswordLength()) ?>"
                           data-password-min-character-sets="<?= $block->escapeHtml($block->getRequiredCharacterClassesNumber()) ?>"
                           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 | ">
                            <?= /* @escapeNotVerified */ __('Password Strength'); ?>:
                            <span id="password-strength-meter-label" data-role="password-strength-meter-label">
                                <?= /* @escapeNotVerified */ __('No Password'); ?>
                            </span>
                            <div class="password-strength-meter__icons-wrapper">
                                <svg class="password-strength-meter__icon">
                                    <use xlink:href="#rhomb"></use>
                                </svg>
                                <svg class="password-strength-meter__icon">
                                    <use xlink:href="#rhomb"></use>
                                </svg>
                                <svg class="password-strength-meter__icon">
                                    <use xlink:href="#rhomb"></use>
                                </svg>
                                <svg class="password-strength-meter__icon">
                                    <use xlink:href="#rhomb"></use>
                                </svg>
                                <svg class="password-strength-meter__icon">
                                    <use xlink:href="#rhomb"></use>
                                </svg>
                                <svg class="password-strength-meter__icon">
                                    <use xlink:href="#rhomb"></use>
                                </svg>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
            <div class="cs-form__field | cs-input | confirmation required">
                <label for="password-confirmation" class="cs-input__label">
                    <span><?= /* @escapeNotVerified */ __('Confirm Password') ?></span>
                </label>

                <div class="cs-input__control">
                    <input
                        type="password"
                        name="password_confirmation"
                        title="<?= /* @escapeNotVerified */ __('Confirm Password') ?>"
                        id="password-confirmation"
                        class="cs-input__input"
                        data-validate="{required:true, equalTo:'#password'}"
                        autocomplete="off"
                    >
                </div>
            </div>
            <?= $block->getChildHtml('form_additional_info'); ?>
        </fieldset>
        <div class="cs-form__buttons">
            <button
                type="submit"
                class="cs-button cs-button--type_long cs-button--type_wide-mobile cs-button--look_default"
                title="<?= /* @escapeNotVerified */ __('Create an Account') ?>"
            >
                <span class="cs-button__span"> <?= /* @escapeNotVerified */ __('Create an Account') ?></span>
                <svg class="cs-button__icon">
                    <use xlink:href="#arrow_next"></use>
                </svg>
            </button>
        </div>
    </form>
</div>
<script>
    require([
        'jquery',
        'bundle',
        'mage/mage',
    ], function($, bundle) {
        // Init address google autosuggest
        bundle.AddressAutofill({
            streetField: $( '#form-validate #street_1'),
            zipField: $( '#form-validate input[name="postcode"]'),
            cityField: $( '#form-validate input[name="city"]'),
            countrySelect: $( '#form-validate select[name="country_id"]'),
        });

        var dataForm = $('#form-validate');
        var ignore = <?= /* @escapeNotVerified */ $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.appendTo(element.parents('.cs-input'));
                }
            },
            ignore: ':hidden:not(' + ignore + ')'
            <?php else: ?>
            ignore: ignore ? ':hidden:not(' + ignore + ')' : ':hidden'
            <?php endif ?>
        }).find('input:text').attr('autocomplete', 'off');
    });
</script>
<?php if ($block->getShowAddressFields()): ?>
    <script type="text/x-magento-init">
    {
        "#country": {
            "regionUpdater": {
                "optionalRegionAllowed": <?= /* @escapeNotVerified */
        ($block->getConfig('general/region/display_all') ? 'true' : 'false'); ?>,
                "regionListId": "#region_id",
                "regionInputId": "#region",
                "postcodeId": "#zip",
                "form": "#form-validate",
                "regionJson": <?= /* @escapeNotVerified */ $this->helper('Magento\Directory\Helper\Data')->getRegionJson() ?>,
                "defaultRegion": "<?= /* @escapeNotVerified */ $block->getFormData()->getRegionId() ?>",
                "countriesWithOptionalZip": <?= /* @escapeNotVerified */ $this->helper('Magento\Directory\Helper\Data')->getCountriesWithOptionalZip(true) ?>
            }
        }
    }
    </script>
<?php endif; ?>
