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

// @codingStandardsIgnoreFile

/**
USAGE:

Simple:

<?php echo $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Name')
   ->setObject($block->getAddress())
   ->toHtml() ?>

For checkout/onepage/shipping.phtml:

<?php echo $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Name')
   ->setObject($block->getAddress())
   ->setFieldIdFormat('shipping:%s')
   ->setFieldNameFormat('shipping[%s]')
   ->setFieldParams('onchange="shipping.setSameAsBilling(false);"')
   ->toHtml() ?>
*/
/* @var $block \Magento\Customer\Block\Widget\Name */
$prefix = $block->showPrefix();
$middle = $block->showMiddlename();
$suffix = $block->showSuffix();
?>

<?php if (($prefix || $middle || $suffix) && !$block->getNoWrap()): ?>
<div class="form-group field required fullname <?php /* @escapeNotVerified */ echo $block->getContainerClassName() ?>">
    <label for="<?php /* @escapeNotVerified */ echo $block->getFieldId('firstname') ?>">
        <span><?php /* @escapeNotVerified */ echo __('Name') ?></span>
    </label>

    <fieldset class="fieldset fieldset-fullname">
    <div class="fields">
<?php endif; ?>

<?php if ($prefix): ?>
    <div class="form-group field field-name-prefix<?php if ($block->isPrefixRequired()) echo ' required' ?>">
        <label for="<?php /* @escapeNotVerified */ echo $block->getFieldId('prefix') ?>">
            <span><?php /* @escapeNotVerified */ echo $block->getStoreLabel('prefix') ?></span>
        </label>

        <?php if ($block->getPrefixOptions() === false): ?>
            <input type="text" id="<?php /* @escapeNotVerified */ echo $block->getFieldId('prefix') ?>"
                   name="<?php /* @escapeNotVerified */ echo $block->getFieldName('prefix') ?>"
                   value="<?php echo $block->escapeHtml($block->getObject()->getPrefix()) ?>"
                   title="<?php /* @escapeNotVerified */ echo $block->getStoreLabel('prefix') ?>"
                   class="form-control <?php /* @escapeNotVerified */ echo $block->getAttributeValidationClass('prefix') ?>" <?php /* @escapeNotVerified */ echo $block->getFieldParams() ?> <?php if ($block->isPrefixRequired()) echo ' data-validate="{required:true}"' ?>>
        <?php else: ?>
            <select id="<?php /* @escapeNotVerified */ echo $block->getFieldId('prefix') ?>"
                    name="<?php /* @escapeNotVerified */ echo $block->getFieldName('prefix') ?>"
                    title="<?php /* @escapeNotVerified */ echo $block->getStoreLabel('prefix') ?>"
                    class="<?php /* @escapeNotVerified */ echo $block->getAttributeValidationClass('prefix') ?>" <?php /* @escapeNotVerified */ echo $block->getFieldParams() ?> <?php if ($block->isPrefixRequired()) echo ' data-validate="{required:true}"' ?> >
                <?php foreach ($block->getPrefixOptions() as $_option): ?>
                    <option value="<?php /* @escapeNotVerified */ echo $_option ?>"<?php if ($block->getObject()->getPrefix() == $_option): ?> selected="selected"<?php endif; ?>>
                        <?php /* @escapeNotVerified */ echo __($_option) ?>
                    </option>
                <?php endforeach; ?>
            </select>
        <?php endif; ?>
    </div>
<?php endif; ?>
    <div class="form-group field field-name-firstname required">
        <label for="<?php /* @escapeNotVerified */ echo $block->getFieldId('firstname') ?>">
            <span><?php /* @escapeNotVerified */ echo $block->getStoreLabel('firstname') ?></span>
        </label>

        <div class="control">
            <input type="text" id="<?php /* @escapeNotVerified */ echo $block->getFieldId('firstname') ?>"
                   name="<?php /* @escapeNotVerified */ echo $block->getFieldName('firstname') ?>"
                   value="<?php echo $block->escapeHtml($block->getObject()->getFirstname()) ?>"
                   title="<?php /* @escapeNotVerified */ echo $block->getStoreLabel('firstname') ?>"
                   class="form-control <?php /* @escapeNotVerified */ echo $block->getAttributeValidationClass('firstname') ?>" <?php /* @escapeNotVerified */ echo $block->getFieldParams() ?> <?php if ($block->getAttributeValidationClass('firstname') == 'required-entry') echo ' data-validate="{required:true}"' ?>>
        </div>
    </div>
<?php if ($middle): ?>
    <?php $isMiddlenameRequired = $block->isMiddlenameRequired(); ?>
    <div class="form-group field field-name-middlename<?php echo $isMiddlenameRequired ? ' required' : '' ?>">
        <label for="<?php /* @escapeNotVerified */ echo $block->getFieldId('middlename') ?>">
            <span><?php /* @escapeNotVerified */ echo $block->getStoreLabel('middlename') ?></span>
        </label>

        <div class="control">
            <input type="text" id="<?php /* @escapeNotVerified */ echo $block->getFieldId('middlename') ?>"
                   name="<?php /* @escapeNotVerified */ echo $block->getFieldName('middlename') ?>"
                   value="<?php echo $block->escapeHtml($block->getObject()->getMiddlename()) ?>"
                   title="<?php /* @escapeNotVerified */ echo $block->getStoreLabel('middlename') ?>"
                   class="form-control <?php /* @escapeNotVerified */ echo $block->getAttributeValidationClass('middlename') ?>" <?php /* @escapeNotVerified */ echo $block->getFieldParams() ?> <?php echo $isMiddlenameRequired ? ' data-validate="{required:true}"' : '' ?>>
        </div>
    </div>
<?php endif; ?>
    <div class="form-group field field-name-lastname required">
        <label for="<?php /* @escapeNotVerified */ echo $block->getFieldId('lastname') ?>">
            <span><?php /* @escapeNotVerified */ echo $block->getStoreLabel('lastname') ?></span>
        </label>

        <div class="control">
            <input type="text" id="<?php /* @escapeNotVerified */ echo $block->getFieldId('lastname') ?>"
                   name="<?php /* @escapeNotVerified */ echo $block->getFieldName('lastname') ?>"
                   value="<?php echo $block->escapeHtml($block->getObject()->getLastname()) ?>"
                   title="<?php /* @escapeNotVerified */ echo $block->getStoreLabel('lastname') ?>"
                   class="form-control <?php /* @escapeNotVerified */ echo $block->getAttributeValidationClass('lastname') ?>" <?php /* @escapeNotVerified */ echo $block->getFieldParams() ?> <?php if ($block->getAttributeValidationClass('lastname') == 'required-entry') echo ' data-validate="{required:true}"' ?>>
        </div>
    </div>
<?php if ($suffix): ?>
    <div class="form-group field field-name-suffix<?php if ($block->isSuffixRequired()) echo ' required' ?>">
        <label for="<?php /* @escapeNotVerified */ echo $block->getFieldId('suffix') ?>">
            <span><?php /* @escapeNotVerified */ echo $block->getStoreLabel('suffix') ?></span>
        </label>

        <div class="control">
            <?php if ($block->getSuffixOptions() === false): ?>
                <input type="text" id="<?php /* @escapeNotVerified */ echo $block->getFieldId('suffix') ?>"
                       name="<?php /* @escapeNotVerified */ echo $block->getFieldName('suffix') ?>"
                       value="<?php echo $block->escapeHtml($block->getObject()->getSuffix()) ?>"
                       title="<?php /* @escapeNotVerified */ echo $block->getStoreLabel('suffix') ?>"
                       class="form-control <?php /* @escapeNotVerified */ echo $block->getAttributeValidationClass('suffix') ?>" <?php /* @escapeNotVerified */ echo $block->getFieldParams() ?> <?php if ($block->isSuffixRequired()) echo ' data-validate="{required:true}"' ?>>
            <?php else: ?>
                <select id="<?php /* @escapeNotVerified */ echo $block->getFieldId('suffix') ?>"
                        name="<?php /* @escapeNotVerified */ echo $block->getFieldName('suffix') ?>"
                        title="<?php /* @escapeNotVerified */ echo $block->getStoreLabel('suffix') ?>"
                        class="<?php /* @escapeNotVerified */ echo $block->getAttributeValidationClass('suffix') ?>" <?php /* @escapeNotVerified */ echo $block->getFieldParams() ?> <?php if ($block->isSuffixRequired()) echo ' data-validate="{required:true}"' ?>>
                    <?php foreach ($block->getSuffixOptions() as $_option): ?>
                        <option value="<?php /* @escapeNotVerified */ echo $_option ?>"<?php if ($block->getObject()->getSuffix() == $_option): ?> selected="selected"<?php endif; ?>>
                            <?php /* @escapeNotVerified */ echo __($_option) ?>
                        </option>
                    <?php endforeach; ?>
                </select>
            <?php endif; ?>
        </div>
    </div>
<?php endif; ?>

<?php if (($prefix || $middle || $suffix) && !$block->getNoWrap()): ?>
        </div>
    </fieldset>
</div>
<?php endif; ?>