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

// @codingStandardsIgnoreFile

/** @var $block \Magento\Bundle\Block\Adminhtml\Catalog\Product\Edit\Tab\Bundle */
?>
<script>

if(typeof Bundle=='undefined') {
    Bundle = {};
}

</script>

<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"><?php /* @escapeNotVerified */ echo __('Ship Bundle Items') ?></label>
            <div class="control">
                <select <?php if ($block->isReadonly()): ?>disabled="disabled" <?php endif;?>
                        id="shipment_type"
                        name="<?php /* @escapeNotVerified */ echo $block->getFieldSuffix() ?>[shipment_type]"
                        class="select">
                    <option value="1"><?php /* @escapeNotVerified */ echo __('Separately') ?></option>
                    <option value="0"<?php if ($block->getProduct()->getShipmentType() == 0): ?> selected="selected"<?php endif; ?>><?php /* @escapeNotVerified */ echo __('Together') ?></option>
                </select>
            </div>
        </div>

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

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

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

<script>
require(["prototype", "mage/adminhtml/form"], function(){
    // re-bind form elements onchange
    varienWindowOnload(true);

    <?php if ($block->isReadonly()):?>
    $('product_bundle_container').select('input', 'select', 'textarea', 'button').each(function(input){
        input.disabled = true;
        if (input.tagName.toLowerCase() == 'button') {
            input.addClassName('disabled');
        }
    });
    <?php endif; ?>
});
</script>
