<?php
/******************************************************************************
 *   ______                                                                   *
 *  /       \                                                                 *
 * /$$$$$$  | ________  __    __   ______    ______                           *
 * $$ |__$$ |/        |/  |  /  | /      \  /      \                          *
 * $$    $$ |$$$$$$$$/ $$ |  $$ |/$$$$$$  |/$$$$$$  |                         *
 * $$$$$$$$ |  /  $$/  $$ |  $$ |$$ |  $$/ $$    $$ |                         *
 * $$ |  $$ | /$$$$/__ $$ \__$$ |$$ |      $$$$$$$$/                          *
 * $$ |  $$ |/$$      |$$    $$/ $$ |      $$       |                         *
 * $$/   $$/ $$$$$$$$/  $$$$$$/  $$/        $$$$$$$/                          *
 *                                                                            *
 * @PROJECT    : 3D Preview Extension [Magetop.com]                           *
 * @AUTHOR     : Azure - Developer                                            *
 * @COPYRIGHT  : © 2019  Magetop.com                                          *
 * @LINK       : https://Magetop.com                                          *
 * @CREATED    :  10/01/2022                                                  *
 ******************************************************************************/

/** @var \Magetop\Advancepreview\Block\Adminhtml\Order\View\CustomItems $block*/
/** @var \Magento\Sales\Model\Order $order*/
/* @var \Magento\Catalog\Helper\Image $imageHelper */
/** @var \Magetop\Advancepreview\Helper\OrderHelper $previewOrderHelper */
$previewOrderHelper = $this->helper('\Magetop\Advancepreview\Helper\OrderHelper');
//echo $block->getRequest()->getControllerName();
$imageHelper = $this->helper('Magento\Catalog\Helper\Image');
$order = $block->getData('order');
$items = $order->getAllItems();
$invoice = $block->getData('invoice');

$customerGroup = $block->getCustomerGroup();
$tax = 19;
$grandTotal = 0;
$customerId = $order->getCustomerId();
$urls = $block->getAdminAjaxUrl();
$updateStatusUrl = $urls['update_status_url'];
$updateCustomDesignPrintUrl = $urls['update_custom_design_print'];
$orderId = $block->getRequest()->getParam('order_id',0);
$statusLabels = [
    'new'=>'New',
    'process'=>'In progress',
    'shipping'=>'Ready for shipping/Production done',
    'shipped'=>'Shipped'
];
$statusCustomPrintLabels = [
    'new'=>'New',
    'downloading'=>'Checking design by Myfitmix',
    'design_failed'=>'Design failed',
    'design_approved'=>'Design approved',
    'customer_reject'=>'Design rejected by customer',
    'design_full_approved'=>'Design fully approved',
    'process'=>'In progress',
    'shipping'=>'Ready for shipping/Production done',
    'shipped'=>'Shipped',
    'delivered'=>'Delivered',
];
// print_r($statusCustomPrintLabels);
$mediaUrl = $block->getMediaUrl();
$iframeUrl = $block->getBaseUrl().'advance_preview/newPreview/index/';
?>
<?php if($items) : ?>
    <div id="product-custom-order-message"></div>
    <div class="preview-custom-order-items">
        <?php foreach ($items as $item) : ?>
            <?php
            /** @var  \Magento\Sales\Model\Order\Item $item*/
            if(!$previewOrderHelper->checkIncoiceAndItemId($invoice->getId(), $item->getId())) {
                continue;
            }
            $productId = $item->getProductId();
            $_product = $block->getProductById($productId);
            if(!$_product) {
                continue;
            }
            $previewOrderItem = $block->getPreviewItemByItemId($item->getId());
            $status = '';
            $customerUploadDesign = '';
            $isAdminCreateDesign = 0;
            $adminCreateStatus = 0;
            $requestOption = $block->getCustomItemDetail($item);
            $token = isset($requestOption['uenc']) ? $requestOption['uenc'] : '';
            $invoiceId = 0;
            $modelPreview = isset($requestOption['txt_preview_selected']) ? $requestOption['txt_preview_selected'] : '';
            $trakingInfo = '';
            if($previewOrderItem != null) {
                $status = $previewOrderItem->getData('status');
                $customerUploadDesign = $previewOrderItem->getData('custom_design');
                $isAdminCreateDesign = $previewOrderItem->getData('is_admin_create');
                $adminCreateStatus = $previewOrderItem->getData('admin_upload_status');
                if(trim($previewOrderItem->getData('preview_model')) != '') {
                    $modelPreview = $previewOrderItem->getData('preview_model');
                }
                $invoiceId = $previewOrderItem->getData('invoice_id');
                $trakingInfo = $previewOrderItem->getData('tracking_info');
            }
          /*  echo '<pre>';
                print_r($requestOption);
            echo '</pre>';*/
            $tierPrice = $block->getTierPriceByProductId($_product);
            $tierQtyPrice = $block->getTierPriceItemByQty($tierPrice, $item->getQtyOrdered());
         /*   $ourPrice = $block->getCustomTierOurPrice($_product,$tierQtyPrice, $customerId);
            $ourPriceRow = $ourPrice * $item->getQtyOrdered();*/
           /* $customDiscounts = $block->getPreviewDiscounts($productId);*/
            $customDiscounts = isset($requestOption['txt_preview_list_discount_price']) ? $requestOption['txt_preview_list_discount_price'] : '';
            if($customDiscounts != '') {
                $customDiscounts = (array)json_decode($customDiscounts);
            }
            else {
                $customDiscounts = [];
            }
            $ourPriceRow = isset($customDiscounts['our_price']) ? $customDiscounts['our_price'] : 0;
            $ourPrice = $ourPriceRow / $item->getQtyOrdered();
            $total = $ourPriceRow;
            $total = $ourPriceRow;
            $designType = isset($requestOption['txt_custom_preview_design_type']) ? $requestOption['txt_custom_preview_design_type'] : 0;
//            $customerUploadDesign = isset($requestOption['customer_upload_design']) ? trim($requestOption['customer_upload_design']) : '';

            $gernerateProjoectId = isset($requestOption['text_project_generate']) ? $requestOption['text_project_generate'] : 0;
            $designOrderStatus = 'Ordered with standard design';
            if(isset($requestOption['txt_is_request_sample']) && $requestOption['txt_is_request_sample'] == 1) {
                $designOrderStatus = 'Ordered for samples';
            }
            else if($designType == 1) {
                $designOrderStatus = 'Ordered with custom design';
                $customWithExtraCost = isset($requestOption['preview_additional_options']) ? $requestOption['preview_additional_options'] : [];
                if(count($customWithExtraCost)) {
                    $designOrderStatus = 'Ordered with custom design extra costs';
                }

            }
            if($gernerateProjoectId > 0) {
                if($gernerateProjoectId > 1000) {
                    $gernerateProjoectId = $gernerateProjoectId;
                }
                else if($gernerateProjoectId > 100) {
                    $gernerateProjoectId = '0'.$gernerateProjoectId;
                }
                else if($gernerateProjoectId > 10) {
                    $gernerateProjoectId = '00'.$gernerateProjoectId;
                }
                else {
                    $gernerateProjoectId = '000'.$gernerateProjoectId;
                }
            }
            else {
                $gernerateProjoectId = '';
            }
            $projectName = isset($requestOption['custom_project_name']) ? $requestOption['custom_project_name'] : '';
            if($gernerateProjoectId != '') {
                $projectName = $gernerateProjoectId . ' - ' .$projectName;
            }
//            echo $modelPreview;
          /*  $previewModels = $block->getPreviewByProductId($productId);
            $light = 0;
            $namePreviewModel = '';
            $zoom = 0;
            $textureWidth = 0;
            $textureHeight = 0;
            if($previewModels && $previewModels->getSize() > 0) {
                $namePreviewModel = $previewModels->getFirstItem()->getData('file_preview');
                $light = $previewModels->getFirstItem()->getData('preview_light');
                $zoom = $previewModels->getFirstItem()->getData('preview_zoom');
            }*/
//            $modelPreview = isset($requestOption['txt_preview_selected']) ? $requestOption['txt_preview_selected'] : '';
            $namePreviewModel = isset($requestOption['txt_preview_file_selected']) ? $requestOption['txt_preview_file_selected'] : '';
            $light = isset($requestOption['txt_preview_light_selected']) ? (int)$requestOption['txt_preview_light_selected'] : 0;
            $zoom = isset($requestOption['txt_preview_zoom_selected']) ? (int)$requestOption['txt_preview_zoom_selected'] : 0;
            $textureWidth =  isset($requestOption['txt_preview_width_selected']) ? (int)$requestOption['txt_preview_width_selected'] : 0;
            $textureHeight =  isset($requestOption['txt_preview_height_selected']) ? (int)$requestOption['txt_preview_height_selected'] : 0;
            $is3D = false;
            if($block->checkProductEnable3D($_product) && $modelPreview != '' && $namePreviewModel != '' && $light > 0 && $zoom > 0) {
                $is3D = true;
            }
            // custom shipping
            $dailyId = isset($requestOption['txt_daily_shipping']) ? (int)$requestOption['txt_daily_shipping'] : 0;
            $dailyShippigAmount = 0;
            $dailyDays = 0;
            if($dailyId > 0) {
                $dailyShippig = $block->getDailyShippingById($dailyId);
                $dailyShippigAmount = $dailyShippig != null && $dailyShippig->getData('amount') > 0 ? $dailyShippig->getData('amount') : 0;
                $dailyDays = $dailyShippig != null && $dailyShippig->getData('delivery_days') > 0 ? $dailyShippig->getData('delivery_days') : 0;
            }
//            $modelPreview = isset($requestOption['txt_preview_selected']) ? $requestOption['txt_preview_selected'] : '';
            $namePreviewModel = isset($requestOption['txt_preview_file_selected']) ? $requestOption['txt_preview_file_selected'] : '';
            $light = isset($requestOption['txt_preview_light_selected']) ? (int)$requestOption['txt_preview_light_selected'] : 0;
            $zoom = isset($requestOption['txt_preview_zoom_selected']) ? (int)$requestOption['txt_preview_zoom_selected'] : 0;
            $textureWidth =  isset($requestOption['txt_preview_width_selected']) ? (int)$requestOption['txt_preview_width_selected'] : 0;
            $textureHeight =  isset($requestOption['txt_preview_height_selected']) ? (int)$requestOption['txt_preview_height_selected'] : 0;
            $texture =  isset($requestOption['txt_preview_texture_selected']) ? $requestOption['txt_preview_texture_selected'] : '0';
//            echo $_product->getData('image');
            $paramAdditionalOptions = isset($requestOption['preview_additional_options']) ? $requestOption['preview_additional_options'] : [];
            ?>
            <div class="preview-custom-order-item" status="<?php echo $status ?>" item-id="<?php echo $item->getId() ?>" product-id="<?php echo $_product->getId() ?>">
                <?php if($is3D) : ?>
                    <?php /*<div class="custom-order-items-3d" id="preview-custom-order-preview-item-<?php echo $item->getItemId(); ?>" product-id="<?php echo $productId ?>" model-preview="<?php echo $modelPreview; ?>" preview-file-name="<?php echo $namePreviewModel; ?>" preview-light="<?php echo $light; ?>" preview-zoom="<?php echo $zoom; ?>">
                    </div> */ ?>
                    <?php
                    $previewParam = "name_preview/{$namePreviewModel}/model_preview/{$modelPreview}/product_id/{$productId}";
                    ?>
                    <div class="custom-order-items-3d">
                        <iframe id="iframe-preview-pro" src="<?php echo $iframeUrl.$previewParam; ?>" title="HIhi" style="width: 100%; height: 190px; border: 0px !important;"></iframe>
                    </div>

                <?php else : ?>
                    <div class="custom-order-items-image">
                        <?php
                        $image = $block->getMediaUrl() .'catalog/product/'. $_product->getData('image');//$imageHelper->init($_product, 'product_page_image_small')->keepAspectRatio(true)->resize(200, 200)->getUrl();
                        ?>
                        <img src="<?php echo $image;?>" alt="<?php echo $_product->getName() ?>" type="<?php echo $_product->getName() ?>">
                    </div>
                <?php endif; ?>
                <div class="custom-order-item-info">
                    <span class="pc-item-info"><?php echo $projectName; ?></span>
                    <span class="pc-item-info"><a href="<?php echo $_product->getProductUrl() ?>"><?php echo $_product->getName(); ?></a> </span>
                    <span class="pc-item-info"><?php echo $_product->getSku(); ?></span>
                    <span class="pc-item-info"><?php echo $designOrderStatus; ?></span>
                    <span class="pc-item-info"><?php echo $_product->getData('short_description'); ?></span>
                    <?php if(count($paramAdditionalOptions)) : ?>
                        <?php $addionLables = $block->getPreviewAdditionalOptionLabels($paramAdditionalOptions); ?>
                        <span class="pc-item-info"><?php echo $addionLables; ?></span>
                    <?php endif; ?>
                </div>
                <div class="custom-order-item-total">
                    <div class="preview-custom-order-item-col-last">
                        <div class="preview-custom-order-item-col-last-left">
                            <!-- <input type="text" id="txt-qty-<?php echo $item->getId(); ?>" name="" value="<?php echo $item->getQtyOrdered() ?>"> -->
                            <span class="quantity"><?php echo (int)$item->getQtyOrdered() ?></span>

                        </div>
                        <div class="preview-custom-order-item-col-last-right">
                            <span class="pc-item-info-pcs">PCS</span>

                        </div>
                    </div>
                    <div class="preview-custom-order-item-col-last">
                        <div class="preview-custom-order-item-col-last-left">
                            <span class="pc-item-info"><?php echo (int)$item->getQtyOrdered() ?> x <?php echo $block->convertNumberToPrice($ourPrice); ?></span>
                        </div>
                        <div class="preview-custom-order-item-col-last-right">
                            <span><?php echo $block->convertNumberToPrice($ourPriceRow) ?></span>
                        </div>
                    </div>
                    <?php $i = 0; ?>
                    <?php foreach ($customDiscounts as $akt => $customDiscount) : ?>
                        <?php if($i == 0) { $i++; continue; } ?>
                        <?php
                        /*$priceDiscountItem = $customDiscount->getData('discount_price');
                        if($designType == 1 && $i == 1) {

                            $priceDiscountItem += $block->getAdditionalOptionPrice($paramAdditionalOptions, $productId);
                        }
                        else if($dailyShippigAmount > 0 && $i == $customDiscounts->getSize() - 1) {
                            // if shipping
                            $shippingCharge = (($tierQtyPrice * $dailyShippigAmount * $item->getQtyOrdered()) / 100);
                            $priceDiscountItem += $shippingCharge;
                        }*/
                        $priceDiscountItem = $customDiscount;
                        $priceAfterDiscont = $customDiscount;
//                        $priceAfterDiscont = $block->getAddDiscountAdditionAllPrice($priceDiscountItem, $_product, $customerId);
                        $total += $priceAfterDiscont;
                        $txtDiscountTitle = str_replace('_',' ',$akt);
                        ?>

                        <div class="preview-custom-order-item-col-last">
                            <div class="preview-custom-order-item-col-last-left">
                                <?php  if($dailyShippigAmount > 0 && $i == count($customDiscounts) -1) : ?>
                                    <span class="pc-item-info">
                                           <?php echo __('Delivery time: ') ?><b><?php echo $dailyDays ?></b><?php echo __(' days plus shipping') ?>
                                    </span>
                                <?php else : ?>
                                    <span class="pc-item-info"><?php echo  __($txtDiscountTitle); ?></span>
                                <?php endif; ?>
                            </div>
                            <div class="preview-custom-order-item-col-last-right">
                                <span class="pc-item-info"><?php echo $block->convertNumberToPrice($priceAfterDiscont); ?></span>
                            </div>
                        </div>
                        <?php $i++; ?>
                    <?php endforeach; ?>
                    <div class="preview-custom-order-item-col-last">
                        <div class="preview-custom-order-item-col-last-left total">
                            <?php $txtTax = number_format((float)$tax, 2, '.', ''); ?>
                            <span class="pc-item-info"><?php echo __('%1% VAT',$txtTax) ?></span>
                            <br/>
                            <span class="pc-item-info"><?php echo __('Total') ?></span>
                        </div>
                        <div class="preview-custom-order-item-col-last-right total">
                            <?php $taxTotal = (($total * $tax) / 100); // add tax ?>
                            <?php $total = $total + $taxTotal; // add tax ?>
                            <?php $grandTotal += $total; ?>
                            <span><?php echo $block->convertNumberToPrice($taxTotal) ?></span>
                            <br/>

                            <span><?php echo $block->convertNumberToPrice($total) ?></span>
                        </div>
                    </div>

                </div>
                <div class="preview-custom-order-item-status">
                    <?php if($designType == 0) : ?>
                        <span id="preview-project-item-status-<?php echo $item->getId(); ?>"><?php echo  isset($statusLabels[$status]) ? $statusLabels[$status] : ucfirst($status); ?></span>
                    <?php elseif ($designType == 1) : ?>
                        <span id="preview-project-item-status-<?php echo $item->getId(); ?>"><?php echo  isset($statusCustomPrintLabels[$status]) ? $statusCustomPrintLabels[$status] : ucfirst($status); ?></span>
                    <?php endif; ?>
                </div>
                <div class="preview-custom-order-item-action">
                    <?php if($status == 'shipped' || $status == 'delivered') : ?>
                        <p style="float: left">
                            <?php echo $trakingInfo ?>
                        </p>
                    <?php endif; ?>
                    <?php if($designType == 0) : ?>
                        <?php if($status == 'new') : ?>
                            <button type="button" class="btn-update-standard-status" item-id="<?php echo $item->getId() ?>" txt-status="<?php echo 'process'; ?>" txt-product-name="<?php echo $_product->getName(); ?>" txt-order="<?php echo $order->getIncrementId() ?>"><?php echo __('Start Production') ?></button>
                        <?php elseif($status == 'process') :  ?>
                            <button type="button" class="btn-update-standard-status" item-id="<?php echo $item->getId() ?>" txt-status="<?php echo 'shipping'; ?>" txt-product-name="<?php echo $_product->getName(); ?>" txt-order="<?php echo $order->getIncrementId() ?>"><?php echo __('Ready for shipping') ?></button>
                        <?php elseif($status == 'shipping') :  ?>
                            <button type="button" class="btn-update-standard-status"  item-id="<?php echo $item->getId() ?>" txt-status="<?php echo 'shipped'; ?>" txt-product-name="<?php echo $_product->getName(); ?>" txt-order="<?php echo $order->getIncrementId() ?>"><?php echo __('Proceed to shipment') ?></button>
                        <?php elseif($status == 'shipped') :  ?>
                        <?php endif; ?>
                    <?php elseif ($designType == 1 && $customerUploadDesign != '' && ($status == 'new' || $status == 'downloading')) : ?>
                        <?php $urlDownload = $mediaUrl.'advancepreview/custom_previews/product_id_'.$productId.'/'. $modelPreview.'/'.$customerUploadDesign; ?>
                        <button type="button" class="btn-download-custom-design" id="btn-download-custom-design-<?php echo $item->getId() ?>" item-id="<?php echo $item->getId() ?>" txt-status="<?php echo 'downloading'; ?>" txt-product-name="<?php echo $_product->getName(); ?>" url-download="<?php echo $urlDownload; ?>" <?php if($status != 'new') { ?> style="display: none;" <?php } ?> txt-order="<?php echo $order->getIncrementId() ?>"><?php echo __('Download file') ?></button>
                        <button type="button" class="btn-download-custom-design-approved" id="btn-download-custom-design-approved-<?php echo $item->getId() ?>" item-id="<?php echo $item->getId() ?>" txt-status="<?php echo 'design_approved'; ?>" txt-product-name="<?php echo $_product->getName(); ?>" <?php if($status != 'downloading') { ?> style="display: none;" <?php } else { ?> style="display: inline-block;"  <?php } ?> txt-order="<?php echo $order->getIncrementId() ?>"><?php echo __('Design approved') ?></button>
                        <button type="button" class="btn-download-custom-design-failed" id="btn-download-custom-design-failed-<?php echo $item->getId() ?>" item-id="<?php echo $item->getId() ?>" txt-status="<?php echo 'design_failed'; ?>" txt-product-name="<?php echo $_product->getName(); ?>" <?php if($status != 'downloading') { ?> style="display: none;" <?php } else { ?> style="display: inline-block;"  <?php } ?>  txt-order="<?php echo $order->getIncrementId() ?>"><?php echo __('Design failed') ?></button>
                        <?php elseif($designType == 1 && $customerUploadDesign != '' && ($status == 'customer_reject' || $status == 'design_approved')) : ?>
                        <form action="/" method="post" id="form-upload-custom-design-item-<?php echo $item->getId() ?>" enctype="multipart/form-data" >
                            <input type="hidden" name="form_key" value="<?php echo $block->getFormKey(); ?>" />
                            <input type="hidden" name="product_id" value="<?php echo $_product->getId(); ?>">
                            <input type="hidden" name="texture" value="<?php echo $texture; ?>">
                            <input type="hidden" name="texture_width" value="<?php echo $textureWidth; ?>">
                            <input type="hidden" name="texture_height" value="<?php echo $textureHeight; ?>">
                            <input type="hidden" name="own_folder" value="<?php echo $modelPreview; ?>">
                            <input type="hidden" name="original_file" value="<?php echo $customerUploadDesign; ?>">
                            <input type="hidden" name="zoom" value="<?php echo $zoom; ?>">
                            <input type="hidden" name="light" value="<?php echo $light ?>">
                            <input type="hidden" name="name_preview" value="<?php echo $namePreviewModel ?>">
                            <input type="hidden" name="item_id" value="<?php echo $item->getId(); ?>">
                            <button class="btn-preview-upload-custom-design" type="button" id="btn-preview-upload-custom-design-<?php echo $item->getId() ?>" item-id="<?php echo $item->getId(); ?>"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Pro 6.0.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2022 Fonticons, Inc. --><path d="M105.4 182.6c12.5 12.49 32.76 12.5 45.25 .001L224 109.3V352c0 17.67 14.33 32 32 32c17.67 0 32-14.33 32-32V109.3l73.38 73.38c12.49 12.49 32.75 12.49 45.25-.001c12.49-12.49 12.49-32.75 0-45.25l-128-128C272.4 3.125 264.2 0 256 0S239.6 3.125 233.4 9.375L105.4 137.4C92.88 149.9 92.88 170.1 105.4 182.6zM480 352h-160c0 35.35-28.65 64-64 64s-64-28.65-64-64H32c-17.67 0-32 14.33-32 32v96c0 17.67 14.33 32 32 32h448c17.67 0 32-14.33 32-32v-96C512 366.3 497.7 352 480 352zM432 456c-13.2 0-24-10.8-24-24c0-13.2 10.8-24 24-24s24 10.8 24 24C456 445.2 445.2 456 432 456z"/></svg><span><?php echo __('Upload File') ?></span></button>
                            <span style="display: none">
                            <input class="txt-preview-upload-custom-design" item-id="<?php echo $item->getId(); ?>" id="txt-preview-upload-custom-design-<?php echo $item->getId() ?>" type="file" name="custom_preview" />

                            </span>
                        </form>
                    <?php elseif($designType == 1 && $customerUploadDesign != '' && $status == 'design_full_approved') : ?>
                        <button type="button" class="btn-update-standard-status" item-id="<?php echo $item->getId() ?>" txt-status="<?php echo 'process'; ?>" txt-product-name="<?php echo $_product->getName(); ?>" txt-order="<?php echo $order->getIncrementId() ?>"><?php echo __('Start Production') ?></button>
                    <?php elseif($designType == 1 && $customerUploadDesign != '' && $status == 'process') :  ?>
                        <button type="button" class="btn-update-standard-status" item-id="<?php echo $item->getId() ?>" txt-status="<?php echo 'shipping'; ?>" txt-product-name="<?php echo $_product->getName(); ?>" txt-order="<?php echo $order->getIncrementId() ?>"><?php echo __('Ready for shipping') ?></button>
                    <?php elseif($designType == 1 && $customerUploadDesign != '' && $status == 'shipping') :  ?>
                        <button type="button" class="btn-update-standard-status"  item-id="<?php echo $item->getId() ?>" txt-status="<?php echo 'shipped'; ?>" txt-product-name="<?php echo $_product->getName(); ?>" txt-order="<?php echo $order->getIncrementId() ?>"><?php echo __('Proceed to shipment') ?></button>
                    <?php elseif($designType == 1 && $customerUploadDesign == '' && ($status == 'new' || $status == 'customer_reject')&& $isAdminCreateDesign == 1) :  ?>
                        <form action="/" method="post" id="form-upload-custom-design-item-<?php echo $item->getId() ?>" enctype="multipart/form-data" >
                            <input type="hidden" name="form_key" value="<?php echo $block->getFormKey(); ?>" />
                            <input type="hidden" name="product_id" value="<?php echo $_product->getId(); ?>">
                            <input type="hidden" name="texture" value="<?php echo $texture; ?>">
                            <input type="hidden" name="texture_width" value="<?php echo $textureWidth; ?>">
                            <input type="hidden" name="texture_height" value="<?php echo $textureHeight; ?>">
                            <input type="hidden" name="own_folder" value="<?php echo $modelPreview; ?>">
                            <input type="hidden" name="original_file" value="<?php echo $customerUploadDesign; ?>">
                            <input type="hidden" name="zoom" value="<?php echo $zoom; ?>">
                            <input type="hidden" name="light" value="<?php echo $light ?>">
                            <input type="hidden" name="name_preview" value="<?php echo $namePreviewModel ?>">
                            <input type="hidden" name="item_id" value="<?php echo $item->getId(); ?>">
                            <input type="hidden" name="is_create_design" value="1">
                            <button class="btn-preview-upload-custom-design" type="button" id="btn-preview-upload-custom-design-<?php echo $item->getId() ?>" item-id="<?php echo $item->getId(); ?>"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Pro 6.0.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2022 Fonticons, Inc. --><path d="M105.4 182.6c12.5 12.49 32.76 12.5 45.25 .001L224 109.3V352c0 17.67 14.33 32 32 32c17.67 0 32-14.33 32-32V109.3l73.38 73.38c12.49 12.49 32.75 12.49 45.25-.001c12.49-12.49 12.49-32.75 0-45.25l-128-128C272.4 3.125 264.2 0 256 0S239.6 3.125 233.4 9.375L105.4 137.4C92.88 149.9 92.88 170.1 105.4 182.6zM480 352h-160c0 35.35-28.65 64-64 64s-64-28.65-64-64H32c-17.67 0-32 14.33-32 32v96c0 17.67 14.33 32 32 32h448c17.67 0 32-14.33 32-32v-96C512 366.3 497.7 352 480 352zM432 456c-13.2 0-24-10.8-24-24c0-13.2 10.8-24 24-24s24 10.8 24 24C456 445.2 445.2 456 432 456z"/></svg><span><?php echo __('Upload File') ?></span></button>
                            <span style="display: none">
                            <input class="txt-preview-upload-custom-design" item-id="<?php echo $item->getId(); ?>" id="txt-preview-upload-custom-design-<?php echo $item->getId() ?>" type="file" name="custom_preview" />

                            </span>
                        </form>
                    <?php elseif($designType == 1 && $customerUploadDesign != '' && $status == 'shipped') :  ?>
                    <?php endif; ?>
                    <?php if($status == 'shipping') : ?>
                        <div class="preview-order-tracking">
                            <textarea class="track-textarea" placeholder="Enter parcel tracking number/link and the shipping courier company name" id="txt-tracking-item-<?php echo $item->getId() ?>"></textarea>
                        </div>
                    <?php endif; ?>
                    <?php if($status == 'shipped') : ?>
                    <!--delivered-->
                        <button type="button" class="btn-update-standard-status" id="btn-update-standard-status-<?php echo $item->getItemId(); ?>" item-id="<?php echo $item->getId() ?>" txt-status="<?php echo 'delivered'; ?>" txt-product-name="<?php echo $_product->getName(); ?>" txt-order="<?php echo $order->getIncrementId() ?>" order-id="<?php echo $orderId ?>" qty="<?php echo $item->getQtyOrdered() ?>" total="<?php echo $total; ?>"><?php echo __('Delivered') ?></button>
                    <?php elseif($status == 'delivered' && $invoiceId > 0 && $block->getRequest()->getControllerName() == 'order') : ?>
                        <?php
                        $invoiceUrl = $block->getBaseUrl().'advance_preview/order/DownloadInvoicePdf/invoice_id/'.$invoiceId.'/order_id/'.$orderId;
                        if($token != '') {
                            $invoiceUrl .= '/token/'.sha1($token);
                        }
                        ?>
                        <a class="action primary" target="_blank" href="<?php echo $invoiceUrl; ?>"><?php echo __('View Invoice') ?></a>
                    <?php endif; ?>
                </div>

            </div>
        <?php endforeach; ?>
    </div>
    <input  type="hidden" id="txt-update-status-url" value="<?php echo $updateStatusUrl; ?>">
    <input  type="hidden" id="txt-update-custom-print-status-url" value="<?php echo $updateCustomDesignPrintUrl; ?>">
    <input  type="hidden" id="txt-upload-proof-url" value="<?php echo $urls['uplolad_proofUrl']; ?>">
    <input  type="hidden" id="txt-custom-order-detail" value="<?php echo $block->getUrl('sales/order/view/order_id/'.$orderId); ?>">
    <input  type="hidden" id="txt-customer-name" value="<?php echo $order->getCustomerName(); ?>">
    <input  type="hidden" id="txt-customer-email" value="<?php echo $order->getCustomerEmail(); ?>">
    <input  type="hidden" id="txt-customer-id" value="<?php echo $order->getCustomerId(); ?>">
    <!--tracking url-->
    <input  type="hidden" id="txt-tracking-items-url" value="<?php echo $urls['tracking_items_url']; ?>">
    <input  type="hidden" id="txt-tracking-edit-url" value="<?php echo $urls['tracking_edit_url']; ?>">
    <input  type="hidden" id="txt-tracking-save-url" value="<?php echo $urls['tracking_save_url']; ?>">
    <input  type="hidden" id="txt-tracking-dell-url" value="<?php echo $urls['tracking_dell_url']; ?>">
    <div id="preview-add-tracking-modal">

    </div>
    <script>
        require([
            'jquery',
            'preview_custom_order'
        ],function ($, previewCustomOrder) {
            previewCustomOrder.init();
        })
    </script>
<?php endif; ?>
