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

// @codingStandardsIgnoreFile

/**
 * Last ordered items sidebar
 *
 * @var $block \Magento\Sales\Block\Reorder\Sidebar
 */
?>
<div class="block block-reorder" data-bind="scope: 'lastOrderedItems'">
    <div class="block-title no-display"
         data-bind="css: {'no-display': !lastOrderedItems().items || lastOrderedItems().items.length === 0}">
        <strong id="block-reorder-heading" role="heading" aria-level="2"><?php /* @escapeNotVerified */ echo __('My Orders') ?></strong>
    </div>
    <div class="block-content no-display"
         data-bind="css: {'no-display': !lastOrderedItems().items || lastOrderedItems().items.length === 0}"
         aria-labelledby="block-reorder-heading">
        <form method="post" class="form reorder"
              action="<?php /* @escapeNotVerified */ echo $block->getFormActionUrl() ?>" id="reorder-validate-detail">
            <strong class="subtitle"><?php /* @escapeNotVerified */ echo __('Last Ordered Items') ?></strong>
            <ol id="cart-sidebar-reorder" class="product-items product-items-names"
                data-bind="foreach: lastOrderedItems().items">
                <li class="product-item">
                    <div class="field item choice no-display" data-bind="css: {'no-display': !is_saleable}">
                        <label class="label" data-bind="attr: {'for': 'reorder-item-' + id}">
                            <span><?php /* @escapeNotVerified */ echo __('Add to Cart') ?></span>
                        </label>
                        <div class="control">
                            <input type="checkbox" name="order_items[]"
                                   data-bind="attr: {id: 'reorder-item-' + id, value: id}"
                                   title="<?php /* @escapeNotVerified */ echo __('Add to Cart') ?>"
                                   class="checkbox" data-validate='{"validate-one-checkbox-required-by-name": true}'/>
                        </div>
                    </div>
                    <strong class="product-item-name">
                        <a data-bind="attr: {href: url}" class="product-item-link">
                            <span data-bind="text: name"></span>
                        </a>
                    </strong>
                </li>
            </ol>
            <div id="cart-sidebar-reorder-advice-container"></div>
            <div class="actions-toolbar">
                    <div class="primary no-display"
                         data-bind="css: {'no-display': !lastOrderedItems().isShowAddToCart}">
                        <button type="submit" title="<?php /* @escapeNotVerified */ echo __('Add to Cart') ?>" class="action tocart primary">
                            <span><?php /* @escapeNotVerified */ echo __('Add to Cart') ?></span>
                        </button>
                    </div>
                <div class="secondary">
                    <a class="action view" href="<?php /* @escapeNotVerified */ echo $block->getUrl('customer/account') ?>">
                        <span><?php /* @escapeNotVerified */ echo __('View All'); ?></span>
                    </a>
                </div>
            </div>
        </form>
    </div>
    <script>
    require(["jquery", "mage/mage"], function(jQuery){
        jQuery('#reorder-validate-detail').mage('validation', {
            errorPlacement: function(error, element) {
                error.appendTo('#cart-sidebar-reorder-advice-container');
            }
        });
    });
    </script>
</div>
<script type="text/x-magento-init">
{
    "*": {
        "Magento_Ui/js/core/app": {
            "components": {
                "lastOrderedItems": {
                    "component": "Magento_Sales/js/view/last-ordered-items"
                }
            }
        }
    }
}
</script>
