<?php

namespace MNM\Spitzner\Block\Magento\Customer\Widget;

use Magento\Customer\Api\AddressMetadataInterface;
use Magento\Customer\Api\CustomerMetadataInterface;
use Magento\Customer\Api\Data\CustomerInterface;
use Magento\Customer\Helper\Address as AddressHelper;
use Magento\Customer\Model\Options;
use Magento\Framework\View\Element\Template\Context;

/**
 * Widget for showing customer name.
 *
 * @method CustomerInterface getObject()
 * @method Name setObject(CustomerInterface $customer)
 *
 * @SuppressWarnings(PHPMD.DepthOfInheritance)
 */
class Name extends \Magento\Customer\Block\Widget\Name
{
    /**
     * Retrieve name prefix drop-down options
     *
     * @return array|bool
     */
    public function getPrefixOptions()
    {
        $prefixOptions = $this->options->getNamePrefixOptions();

        if ($this->getObject() && !empty($prefixOptions)) {
            $prefixOption = $this->getObject()->getPrefix();
//MNM - check before trim
            if ($prefixOption !== null) {
//MNM - check before trim
                $oldPrefix = $this->escapeHtml(trim($prefixOption));
                if ($prefixOption !== null && !isset($prefixOptions[$oldPrefix]) && !isset($prefixOptions[$prefixOption])) {
                    $prefixOptions[$oldPrefix] = $oldPrefix;
                }
            }
        }
        return $prefixOptions;
    }

    /**
     * Retrieve name suffix drop-down options
     *
     * @return array|bool
     */
    public function getSuffixOptions()
    {
        $suffixOptions = $this->options->getNameSuffixOptions();
        if ($this->getObject() && !empty($suffixOptions)) {
            $suffixOption = $this->getObject()->getSuffix();
//MNM - check before trim
            if ($suffixOption !== null) {
//MNM - check before trim
                $oldSuffix = $this->escapeHtml(trim($suffixOption));
                if ($suffixOption !== null && !isset($suffixOptions[$oldSuffix]) && !isset($suffixOptions[$suffixOption])) {
                    $suffixOptions[$oldSuffix] = $oldSuffix;
                }
            }
        }
        return $suffixOptions;
    }
}
