<?php
/**
 * Copyright © 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="field required fullname <?= $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr($block->getContainerClassName()) ?>">
    <label for="<?= $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr($block->getFieldId('firstname')) ?>" class="label">
        <span><?= $block->escapeHtml(__('Name')) ?></span>
    </label>
    <div class="control">
        <fieldset class="fieldset fieldset-fullname">
        <div class="fields">
<?php endif; ?>

    <?php if ($prefix): ?>
        <div class="field field-name-prefix<?php if ($block->isPrefixRequired()) echo ' required' ?>">
            <label class="label" for="<?= $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr($block->getFieldId('prefix')) ?>">
                <span><?= $block->escapeHtml($block->getStoreLabel('prefix')) ?></span>
            </label>

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

            <div class="control">
                <input type="text" id="<?= $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr($block->getFieldId('firstname')) ?>"
                       name="<?= $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr($block->getFieldName('firstname')) ?>"
                       value="<?= $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr($block->getObject()->getFirstname()) ?>"
                       title="<?= $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr($block->getStoreLabel('firstname')) ?>"
                       class="input-text <?= $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr($block->getAttributeValidationClass('firstname')) ?>" <?php if ($block->getAttributeValidationClass('firstname') == 'required-entry') echo ' data-validate="{required:true}"' ?>>
            </div>
        </div>
    <?php if ($middle): ?>
        <?php $isMiddlenameRequired = $block->isMiddlenameRequired(); ?>
        <div class="field field-name-middlename<?= $isMiddlenameRequired ? ' required' : '' ?>">
            <label class="label" for="<?= $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr($block->getFieldId('middlename')) ?>">
                <span><?= $block->escapeHtml($block->getStoreLabel('middlename')) ?></span>
            </label>

            <div class="control">
                <input type="text" id="<?= $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr($block->getFieldId('middlename')) ?>"
                       name="<?= $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr($block->getFieldName('middlename')) ?>"
                       value="<?= $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr($block->getObject()->getMiddlename()) ?>"
                       title="<?= $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr($block->getStoreLabel('middlename')) ?>"
                       class="input-text <?= $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr($block->getAttributeValidationClass('middlename')) ?>" <?= $isMiddlenameRequired ? ' data-validate="{required:true}"' : '' ?>>
            </div>
        </div>
    <?php endif; ?>
        <div class="field field-name-lastname required">
            <label class="label" for="<?= $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr($block->getFieldId('lastname')) ?>">
                <span><?= $block->escapeHtml($block->getStoreLabel('lastname')) ?></span>
            </label>

            <div class="control">
                <input type="text" id="<?= $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr($block->getFieldId('lastname')) ?>"
                       name="<?= $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr($block->getFieldName('lastname')) ?>"
                       value="<?= $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr($block->getObject()->getLastname()) ?>"
                       title="<?= $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr($block->getStoreLabel('lastname')) ?>"
                       class="input-text <?= $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr($block->getAttributeValidationClass('lastname')) ?>" <?php if ($block->getAttributeValidationClass('lastname') == 'required-entry') echo ' data-validate="{required:true}"' ?>>
            </div>
        </div>
    <?php if ($suffix): ?>
        <div class="field field-name-suffix<?php if ($block->isSuffixRequired()) echo ' required' ?>">
            <label class="label" for="<?= $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr($block->getFieldId('suffix')) ?>">
                <span><?= $block->escapeHtml($block->getStoreLabel('suffix')) ?></span>
            </label>

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

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