<?php $__env->startSection('panel'); ?>
    <div class="row">
        <div class="col-lg-12">
            <div class="card b-radius--10">
                <div class="card-body p-0">
                    <div class="table-responsive--md table-responsive">
                        <table class="table table--light style--two">
                            <thead>
                                <tr>
                                    <th><?php echo app('translator')->get('Order Date'); ?></th>
                                    <th><?php echo app('translator')->get('Customer'); ?></th>
                                    <th><?php echo app('translator')->get('Order ID'); ?></th>
                                    <th><?php echo app('translator')->get('Payment Via'); ?></th>
                                    <th><?php echo app('translator')->get('Amount'); ?></th>
                                    <th><?php echo app('translator')->get('Payment Status'); ?></th>
                                    <th><?php echo app('translator')->get('Status'); ?></th>
                                    <th><?php echo app('translator')->get('Action'); ?></th>
                                </tr>
                            </thead>
                            <tbody class="list">
                                <?php $__empty_1 = true; $__currentLoopData = $orders; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $order): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                    <tr>
                                        <td><?php echo e(showDateTime($order->created_at, 'd M, Y')); ?></td>
                                        <td><a href="<?php echo e(route('admin.users.detail', @$order->user->id)); ?>"><?php echo e(@$order->user->username); ?></a></td>
                                        <td><?php echo e($order->order_number); ?></td>

                                        <td>
                                            <?php if($order->is_cod): ?>
                                                <span class="color--warning" title="<?php echo app('translator')->get('Cash On Delivery'); ?>"><?php echo e(@$deposit->gateway->name ?? trans('COD')); ?></span>
                                            <?php elseif($order->deposit): ?>
                                                <strong class="text-primary"><?php echo e(@$order->deposit->gateway->name); ?></strong>
                                            <?php endif; ?>
                                        </td>

                                        <td>
                                            <b><?php echo e(showAmount($order->total_amount)); ?></b>
                                        </td>

                                        <td><?php echo $order->paymentBadge() ?></td>
                                        <td><?php echo $order->statusBadge() ?></td>

                                        <td>

                                            <a href="<?php echo e(route('admin.order.details', $order->id)); ?>" class="btn btn-outline--dark btn-sm">
                                                <i class="la la-desktop"></i><?php echo app('translator')->get('Details'); ?>
                                            </a>

                                            <?php
                                                $question = null;
                                                $canCancel = false;
                                                $disabled = false;

                                                if ($order->status == Status::ORDER_PENDING) {
                                                    $canCancel = true;
                                                    $buttonText = 'Processing';
                                                    $question = 'Are you sure to mark the order as processing?';
                                                } elseif ($order->status == Status::ORDER_PROCESSING) {
                                                    $canCancel = true;
                                                    $buttonText = 'Dispatch';
                                                    $question = 'Are you sure to mark the order as dispatched?';
                                                } elseif ($order->status == Status::ORDER_DISPATCHED) {
                                                    $buttonText = 'Deliver';
                                                    $question = 'Are you sure to mark the order as delivered?';
                                                } elseif ($order->status == Status::ORDER_DELIVERED) {
                                                    $disabled = true;
                                                    $buttonText = 'Deliver';
                                                    $question = null;
                                                } elseif ($order->status == Status::ORDER_CANCELED) {
                                                    $disabled = true;
                                                    $buttonText = 'Canceled';
                                                    $question = null;
                                                } elseif ($order->status == Status::ORDER_RETURNED) {
                                                    $disabled = true;
                                                    $buttonText = 'Returned';
                                                    $question = null;
                                                }
                                            ?>

                                            <?php if($order->status == Status::ORDER_PENDING && $order->hasDownloadableProduct()): ?>
                                                <button type="button" class="btn btn-outline--success deliverDPBtn mx-1" data-question="<?php echo e(__($question)); ?>" data-action="<?php echo e(route('admin.order.status.change', $order->id)); ?>" data-has_physical_product="<?php echo e($order->hasPhysicalProduct(true)); ?>" data-after_sale_downloadable_products="<?php echo e($order->afterSaleDownloadableProducts); ?>" <?php if($disabled): echo 'disabled'; endif; ?>>
                                                    <i class="la la-check"></i><?php echo e(__($buttonText)); ?>

                                                </button>
                                            <?php else: ?>
                                                <button type="button" class="btn btn-outline--success confirmationBtn mx-1" data-question="<?php echo e(__($question)); ?>" data-action="<?php echo e(route('admin.order.status.change', $order->id)); ?>" <?php if($disabled): echo 'disabled'; endif; ?>><i class="la la-check"></i><?php echo e(__($buttonText)); ?></button>
                                            <?php endif; ?>

                                            <?php if(Route::is('admin.order.dispatched')): ?>
                                                <button class="btn btn-outline--danger confirmationBtn" data-question="<?php echo app('translator')->get('Are you sure to change status as returned?'); ?>" data-action="<?php echo e(route('admin.order.return', $order->id)); ?>">
                                                    <i class="las la-undo-alt"></i><?php echo app('translator')->get('Return'); ?>
                                                </button>
                                            <?php else: ?>
                                                <button class="btn btn-outline--danger confirmationBtn" data-question="<?php echo app('translator')->get('Are you sure to cancel this order?'); ?>" data-action="<?php echo e(route('admin.order.status.cancel', $order->id)); ?>" <?php if(!$canCancel): echo 'disabled'; endif; ?>>
                                                    <i class="la la-ban"></i><?php echo app('translator')->get('Cancel'); ?>
                                                </button>
                                            <?php endif; ?>
                                        </td>
                                    </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                    <tr>
                                        <td class="text-muted text-center" colspan="100%"><?php echo e(__($emptyMessage)); ?></td>
                                    </tr>
                                <?php endif; ?>
                            </tbody>
                        </table>
                    </div>
                </div>

                <?php if($orders->hasPages()): ?>
                    <div class="card-footer py-4">
                        <?php echo e(paginateLinks($orders)); ?>

                    </div>
                <?php endif; ?>
            </div>
        </div>
    </div>

    <div id="deliverModal" class="modal fade" tabindex="-1" role="dialog">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title"><?php echo app('translator')->get('Deliver Product'); ?></h5>
                    <button type="button" class="close" data-bs-dismiss="modal" aria-label="Close">
                        <i class="las la-times"></i>
                    </button>
                </div>
                <form method="POST" enctype="multipart/form-data">
                    <?php echo csrf_field(); ?>
                    <div class="modal-body"></div>
                    <div class="modal-footer">
                        <button type="submit" class="btn btn--primary w-100 h-45"><?php echo app('translator')->get('Submit'); ?></button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <?php if (isset($component)) { $__componentOriginalbd5922df145d522b37bf664b524be380 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginalbd5922df145d522b37bf664b524be380 = $attributes; } ?>
<?php $component = App\View\Components\ConfirmationModal::resolve([] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('confirmation-modal'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\App\View\Components\ConfirmationModal::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes([]); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginalbd5922df145d522b37bf664b524be380)): ?>
<?php $attributes = $__attributesOriginalbd5922df145d522b37bf664b524be380; ?>
<?php unset($__attributesOriginalbd5922df145d522b37bf664b524be380); ?>
<?php endif; ?>
<?php if (isset($__componentOriginalbd5922df145d522b37bf664b524be380)): ?>
<?php $component = $__componentOriginalbd5922df145d522b37bf664b524be380; ?>
<?php unset($__componentOriginalbd5922df145d522b37bf664b524be380); ?>
<?php endif; ?>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('breadcrumb-plugins'); ?>
    <?php if (isset($component)) { $__componentOriginale48b4598ffc2f41a085f001458a956d1 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginale48b4598ffc2f41a085f001458a956d1 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.search-form','data' => []] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('search-form'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes([]); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginale48b4598ffc2f41a085f001458a956d1)): ?>
<?php $attributes = $__attributesOriginale48b4598ffc2f41a085f001458a956d1; ?>
<?php unset($__attributesOriginale48b4598ffc2f41a085f001458a956d1); ?>
<?php endif; ?>
<?php if (isset($__componentOriginale48b4598ffc2f41a085f001458a956d1)): ?>
<?php $component = $__componentOriginale48b4598ffc2f41a085f001458a956d1; ?>
<?php unset($__componentOriginale48b4598ffc2f41a085f001458a956d1); ?>
<?php endif; ?>
<?php $__env->stopPush(); ?>

<?php $__env->startPush('script'); ?>
    <script>
        (function($) {
            'use strict';
            $('.deliverDPBtn').on('click', function() {
                let data = $(this).data();

                let modal = $('#deliverModal');
                let html = `<h6 class="question">${data.question}</h6>`;

                if (data.after_sale_downloadable_products.length) {
                    html += `<div class="alert alert-info p-3 my-2">
                            <small class="text--info"><?php echo app('translator')->get('This order has an after sale downloadable product. So, if you want to mark the order as delivered you need to submit the file here.'); ?></small>
                        </div>`;

                    $.each(data.after_sale_downloadable_products, function(index, product) {
                        html += `<div class="form-group">
                                <label class="required">${nameToTitle(product.name)}</label>
                                <input type="file" name="download_file[${product.id}]" accept=".zip" class="form-control" required>
                            </div>`
                    });
                } else if (data.has_physical_product == 0) {
                    html += `<small class="text--info"><?php echo app('translator')->get('Note: This order contains only instant downloadable products. Once processing is complete, the order status will automatically be updated to "Delivered."'); ?></small>`;
                }

                modal.find('form').attr('action', data.action);
                modal.find('.modal-body').html(html);
                modal.modal('show');
            })

            function nameToTitle(name) {
                return name.toLowerCase().split(' ').map(function(word) {
                    return word.charAt(0).toUpperCase() + word.slice(1);
                }).join(' ');
            }
        })(jQuery);
    </script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('admin.layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/creativedesignbd/ecommerce7.creativedesign.com.bd/core/resources/views/admin/order/all.blade.php ENDPATH**/ ?>