<?php

use Magento\Directory\Block\Data;
?>

<?php
/** @var \FiloBlu\Rma\Block\Returns\Form $block */
if ($block->getIsEasyReturnEnabled()) {

    $regionIsRequired = $block->isRegionRequired($block->getOrder());

    $orderAddressData = $block->getOrder()->getShippingAddress()->getData();
    $shippingMethod = $block->getOrder()->getShippingMethod();
    $shippingMethods = array("pickupinstore", "pickupinstore_pickupinstore", "upsap_1");
?>

    <input type="radio" id="simple-rma" name="return_type" value="easy-return" />
    <div class="field filoblu-firstname required">
        <label for="customer_firstname" class="label"><span><?= __('Name') ?></span></label>
        <div class="control">
            <input type="text" data-validate="{required:true}" name="customer_firstname" id="filoblu-firstname" value="<?= in_array($shippingMethod, $shippingMethods) ? "" : $orderAddressData['firstname'] ?>">
        </div>
    </div>
    <div class="field filoblu-lastname required">
        <label for="" class="label"><span><?= __('Surname') ?></span></label>
        <div class="control">
            <input type="text" data-validate="{required:true}" name="customer_lastname" id="filoblu-lastname" value="<?= in_array($shippingMethod, $shippingMethods) ? "" : $orderAddressData['lastname'] ?>">
        </div>
    </div>
    <div class="field filoblu-street required">
        <label for="street" class="label"><span><?= __('Address') ?></span></label>
        <div class="control">
            <input type="text" data-validate="{required:true}" name="street" id="filoblu-street" value="<?= in_array($shippingMethod, $shippingMethods) ? "" : $orderAddressData['street'] ?>">
        </div>
    </div>
    <div class="field filoblu-city required">
        <label for="city" class="label"><span><?= __('City') ?></span></label>
        <div class="control">
            <input type="text" data-validate="{required:true}" name="city" id="filoblu-city" value="<?= in_array($shippingMethod, $shippingMethods) ? "" : $orderAddressData['city'] ?>">
        </div>
    </div>
    <div class="field region <?php echo $regionIsRequired ? 'required' : '' ?>">
        <label for="region_id" class="label"><span><?php /* @escapeNotVerified */ echo __('State/Province') ?></span></label>
        <div class="control">
            <select data-default-region="<?= $orderAddressData['region'] ?>" id="region_id" name="region_id" title="<?php /* @escapeNotVerified */ echo __('State/Province') ?>" class="validate-select" style="display:none;">
                <option value=""><?php /* @escapeNotVerified */ echo __('Please select a region, state or province.') ?></option>
            </select>
            <input type="text" data-validate="{required:<?php echo $regionIsRequired ? 'true' : 'false' ?>}" id="region" name="region" value="<?php echo in_array($shippingMethod, $shippingMethods) ? "" :  $block->escapeHtml($block->getRegion()) ?>" title="<?php /* @escapeNotVerified */ echo __('State/Province') ?>" class="input-text <?php /* @escapeNotVerified */ echo $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('region') ?>" style="display:none;">
        </div>
    </div>

    <div class="field zip required">
        <label for="zip" class="label"><span><?php /* @escapeNotVerified */ echo __('Zip/Postal Code') ?></span></label>
        <div class="control">
            <input data-validate="{required:<?php echo $regionIsRequired ? 'true' : 'false' ?>}" value="<?= in_array($shippingMethod, $shippingMethods) ? "" : $orderAddressData['postcode'] ?>" type="text" name="postcode" title="<?php /* @escapeNotVerified */ echo __('Zip/Postal Code') ?>" id="zip" class="input-text validate-zip-international <?php /* @escapeNotVerified */ echo $this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('postcode') ?>">
        </div>
    </div>

    <div class="field country required">
        <label for="country" class="label"><span><?php /* @escapeNotVerified */ echo __('Country') ?></span></label>
        <div class="control">
            <?php $countryBlock = $block->getLayout()->createBlock(Data::class); ?>
            <?= $countryBlock->getCountryHtmlSelect($defValue = $orderAddressData['country_id'], $name = 'country_id', $id = 'country', $title = 'Country'); ?>
        </div>
    </div>

    <div class="field telephone">
        <label for="telephone" class="label"><span><?php /* @escapeNotVerified */ echo __('Telephone') ?></span></label>
        <div class="control">
            <input type="text" data-validate="{required:true}" name="telephone" id="filoblu-telephone" value="<?= in_array($shippingMethod, $shippingMethods) ? "" : $orderAddressData['telephone'] ?>">
        </div>
    </div>

    <script type="text/x-magento-init">
        {
            "#country": {
                "regionUpdater": {
                    "optionalRegionAllowed": <?php /* @escapeNotVerified */ echo ($block->getConfig('general/region/display_all') ? 'true' : 'false'); ?>,
                    "regionListId": "#region_id",
                    "regionInputId": "#region",
                    "postcodeId": "#zip",
                    "form": "#form-validate",
                    "regionJson": <?php /* @escapeNotVerified */ echo $this->helper(\Magento\Directory\Helper\Data::class)->getRegionJson() ?>,
                    "defaultRegion": "<?= $orderAddressData['region_id'] ?>",
                    "countriesWithOptionalZip": <?php /* @escapeNotVerified */ echo $this->helper(\Magento\Directory\Helper\Data::class)->getCountriesWithOptionalZip(true) ?>
                }
            }
        }
</script>

<?php
}
?>