<?php
//@codingStandardsIgnoreFile
/** @var \Mirasvit\Rma\Block\Adminhtml\Rma\Edit\Form\Items $block */
$rma = $block->getRma();
$itemId = '%%item_id%%';
?>

<fieldset id="rma-create-form" class="fieldset admin__fieldset rma-edit__items" data-bind="scope:'rma-create-form'">
    <legend class="admin__legend legend">
        <span><?= __('Items') ?></span>

        <?php if ($rma->getId() > 0) : ?>
            <div class="actions _primary">
                <a href="#" data-role="show-all-items"><?= __('show all order items') ?></a>
            </div>
        <?php endif ?>
    </legend>

    <!-- ko template: getTemplate() --><!-- /ko -->
    <script type="text/x-magento-init">
        {
            "*": {
                "Magento_Ui/js/core/app": {
                    "components": {
                        "rma-create-form": {
                            "component": "Mirasvit_Rma/js/form/new"
                        }
                    }
                }
            }
        }
    </script>

    <table class="admin__control-table" data-role="items-table">
        <thead>
            <tr>
                <th><?= __('Product Name') ?></th>
                <th><?= __('Qty to Return') ?></th>
                <th><?= __('Reason to Return') ?></th>
                <th><?= __('Item Condition') ?></th>
                <th><?= __('Resolution') ?></th>
                <th></th>
            </tr>
        </thead>
        <tbody class="item-container">
        </tbody>
    </table>
</fieldset>

<script id="item_returnreasons" type="text/x-custom-template">
    <tr>
        <td>
            <input type='hidden' name="items[<?= $itemId ?>][is_offline]" value='1'>
            <input type='hidden' name="items[<?= $itemId ?>][is_return]" value='1'>
            <input type="text" name="items[<?= $itemId ?>][name]" value="" title="Item Name" maxlength="255"
                   class="input-text itemname required-entry">
        </td>
        <td>
            <div class="">
                <input name='items[<?= $itemId ?>][qty_requested]'
                       type="number"
                       maxlength="3"
                       class="admin__control-text required-entry"
                       value="0">
            </div>
        </td>
        <td>
            <select name="items[<?= $itemId ?>][reason_id]" class="admin__control-select">
                <option value=""><?= __('--') ?></option>
                <?php foreach ($block->getReasonList() as $reason): ?>
                    <option value="<?= $reason->getId() ?>">
                        <?= $reason->getName() ?>
                    </option>
                <?php endforeach ?>
            </select>
        </td>
        <td>
            <select name="items[<?= $itemId ?>][condition_id]" class="admin__control-select">
                <option value=""><?= __('--') ?></option>
                <?php foreach ($block->getConditionList() as $condition): ?>
                    <option value="<?= $condition->getId() ?>">
                        <?= $condition->getName() ?>
                    </option>
                <?php endforeach ?>
            </select>
        </td>
        <td>
            <select name="items[<?= $itemId ?>][resolution_id]" class="admin__control-select">
                <option value=""><?= __('--') ?></option>
                <?php foreach ($block->getResolutionList() as $resolution): ?>
                    <option value="<?= $resolution->getId() ?>">
                        <?= $resolution->getName() ?>
                    </option>
                <?php endforeach ?>
            </select>
        </td>
        <td>
            <div class="primary">
                <button type="button" class="action primary" data-bind="removeItem" data-role="item-remove">
                    <span><?= __('Remove Item') ?></span>
                </button>
            </div>
        </td>
    </tr>
</script>
