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

// @codingStandardsIgnoreFile

/** @var $block \Magento\Eav\Block\Adminhtml\Attribute\Edit\Options\Options */
?>
<fieldset class="fieldset">
    <legend class="legend"><span><?php /* @escapeNotVerified */ echo __('Manage Options (values of your attribute)') ?></span></legend>
    <div id="manage-options-panel">
        <table class="admin__control-table">
            <thead>
                <tr id="attribute-options-table">
                    <th class="col-draggable"></th>
                    <th class="col-default control-table-actions-th"><?php /* @escapeNotVerified */ echo __('Is Default') ?></th>
                    <?php
                    $storelist = $block->getStores();
                    foreach ($storelist as $_store):
                        ?>
                        <th><?php /* @escapeNotVerified */ echo __($_store->getName()) ?></th>
                    <?php endforeach;
                    $storetotal = count($storelist) + 3;
                    ?>
                    <th class="col-delete">&nbsp;</th>
                </tr>
            </thead>
            <tbody data-role="options-container" class="ignore-validate"></tbody>
            <tfoot>
            <tr>
                <th colspan="<?php /* @escapeNotVerified */ echo $storetotal; ?>" class="validation">
                    <input type="hidden" class="required-dropdown-attribute-entry" name="dropdown_attribute_validation"/>
                </th>
            </tr>
            <tr>
                <th colspan="<?php /* @escapeNotVerified */ echo $storetotal; ?>" class="col-actions-add">
                    <?php if (!$block->getReadOnly() && !$block->canManageOptionDefaultOnly()):?>
                        <button id="add_new_option_button" title="<?php /* @escapeNotVerified */ echo __('Add Option'); ?>"
                            type="button" class="action- scalable add">
                             <span><?php /* @escapeNotVerified */ echo __('Add Option'); ?></span>
                        </button>
                    <?php endif; ?>
                </th>
            </tr>
            </tfoot>
        </table>
        <input type="hidden" id="option-count-check" value="" />
    </div>
    <script id="row-template" type="text/x-magento-template">
         <tr>
            <td class="col-draggable">
                <?php if (!$block->getReadOnly() && !$block->canManageOptionDefaultOnly()): ?>
                    <div data-role="draggable-handle" class="draggable-handle" title="<?php /* @escapeNotVerified */ echo __('Sort Option'); ?>"></div>
                <?php endif; ?>
                <input data-role="order" type="hidden" name="option[order][<%- data.id %>]"  value="<%- data.sort_order %>" <?php if ($block->getReadOnly() || $block->canManageOptionDefaultOnly()): ?> disabled="disabled"<?php endif; ?>/>
            </td>
            <td class="col-default control-table-actions-cell">
                <input class="input-radio" type="<%- data.intype %>" name="default[]" value="<%- data.id %>" <%- data.checked %><?php if ($block->getReadOnly()):?>disabled="disabled"<?php endif;?>/>
            </td>
            <?php foreach ($block->getStores() as $_store): ?>
            <td class="col-<%- data.id %>"><input name="option[value][<%- data.id %>][<?php /* @escapeNotVerified */ echo $_store->getId() ?>]" value="<%- data.store<?php /* @escapeNotVerified */ echo $_store->getId() ?> %>" class="input-text<?php if ($_store->getId() == \Magento\Store\Model\Store::DEFAULT_STORE_ID): ?> required-option<?php endif; ?>" type="text" <?php if ($block->getReadOnly() || $block->canManageOptionDefaultOnly()):?> disabled="disabled"<?php endif;?>/></td>
            <?php endforeach; ?>
            <td id="delete_button_container_<%- data.id %>" class="col-delete">
                <input type="hidden" class="delete-flag" name="option[delete][<%- data.id %>]" value="" />
                <?php if (!$block->getReadOnly() && !$block->canManageOptionDefaultOnly()):?>
                    <button id="delete_button_<%- data.id %>" title="<?php /* @escapeNotVerified */ echo __('Delete') ?>" type="button"
                        class="action- scalable delete delete-option"
                        >
                        <span><?php /* @escapeNotVerified */ echo __('Delete') ?></span>
                    </button>
                <?php endif;?>
            </td>
        </tr>
    </script>
    <?php
    $values = [];
    foreach($block->getOptionValues() as $value) {
        array_push($values, $value->getData());
    }
    ?>
    <script type="text/x-magento-init">
        {
            "*": {
                "Magento_Catalog/js/options": {
                    "attributesData": <?php /* @escapeNotVerified */ echo json_encode($values); ?>,
                    "isSortable":  <?php echo (int)(!$block->getReadOnly() && !$block->canManageOptionDefaultOnly()) ?>,
                    "isReadOnly": <?php echo (int)$block->getReadOnly(); ?>
                }
            }
        }
    </script>
</fieldset>
