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

/** @var $block \Magento\Bundle\Block\Adminhtml\Catalog\Product\Edit\Tab\Bundle */
/** @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer */
?>

<?php $scriptString = <<<script
if(typeof Bundle=='undefined') {
    Bundle = {};
}
script;
?>
<?= /* @noEscape */ $secureRenderer->renderTag('script', [], $scriptString, false) ?>

<div id="bundle_product_container" class="entry-edit form-inline">
    <fieldset class="fieldset">
        <div class="field field-ship-bundle-items">
            <label for="shipment_type" class="label"><?= $block->escapeHtml(__('Ship Bundle Items')) ?></label>
            <div class="control">
                <select <?php if ($block->isReadonly()): ?>disabled="disabled" <?php endif;?>
                        id="shipment_type"
                        name="<?= $block->escapeHtmlAttr($block->getFieldSuffix()) ?>[shipment_type]"
                        class="select">
                    <option value="1"><?= $block->escapeHtml(__('Separately')) ?></option>
                    <option value="0"
                        <?php if ($block->getProduct()->getShipmentType() == 0): ?>
                            selected="selected"
                        <?php endif; ?>
                    >
                        <?= $block->escapeHtml(__('Together')) ?>
                    </option>
                </select>
            </div>
        </div>

        <div
            id="product_bundle_container"
            class="entry-edit custom-options bundle sortable-wrapper">
            <?= $block->getOptionsBoxHtml() ?>
        </div>

        <?= $block->getAddButtonHtml() ?>
    </fieldset>
</div>

<input type="hidden" name="affect_bundle_product_selections" value="1" />

<?php $scriptString = <<<script

require(["prototype", "mage/adminhtml/form"], function(){
    // re-bind form elements onchange
    varienWindowOnload(true);
script;
if ($block->isReadonly()):
    $scriptString .= <<<script
    $('product_bundle_container').select('input', 'select', 'textarea', 'button').each(function(input){
        input.disabled = true;
        if (input.tagName.toLowerCase() == 'button') {
            input.addClassName('disabled');
        }
    });
script;
endif;
$scriptString .= <<<script
});
script;
?>
<?= /* @noEscape */ $secureRenderer->renderTag('script', [], $scriptString, false) ?>
