<?php
/**
 * Quote list at buyer end
 *
 * @category  Magetop Extensions
 * @package   Magetop_Quotesystem
 * @author    Magetop Developer
 * @copyright Copyright (c) Magetop (https://www.magetop.com)
 * @license   https://www.magetop.com/license.html
 */
?>
 <head>
     <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
    <?php
    $quoteHelper = $block->getHelper();
    $filterStatus = 0;
    $filter = '';
    $filterSorting = '';
    $filterSortingType = 'Inc';
    $totalPriceFrom = '';
    $totalPriceTo = '';
    $data = $block->getRequest()->getParams();
    $baseCurrency = $quoteHelper->getBaseCurrencyCode();
    $storeCurrency = $quoteHelper->getCurrentCurrency();
    if ($proName = $block->getRequest()->getParam('id')) {
        $filter = $proName != "" ? $proName : "";
    }
    if (isset($data['sortingStatus'])) {
        $filterSorting = $data['sortingStatus'];
    }
    if (isset($data['sortingType'])) {
        $filterSortingType = $data['sortingType'];
    }
    if (isset($data['status'])) {
        $filterStatus = $data['status'] != "" ? $data['status'] : 0;
    }
    if (isset($data['total_price_from'])) {
        $totalPriceFrom = $data['total_price_from'];
    }
    if (isset($data['total_price_to'])) {
        $totalPriceTo = $data['total_price_to'];
    }
    ?>
 <div class="table-wrapper mt-quote-buyer-list">
    <form action="<?=
        $escaper->escapeHtml(
            $block->getUrl(
                'quotesystem/buyerquote/index/',
                ['_secure' => $block->getRequest()->isSecure()]
            )
        )?>" method="get" id="form-productlist-filter"  name="formProductlistFilter" data-mage-init='{"validation":{}}'>
        <table cellspacing="0" class="data table table-order-items history">
            <thead>
                <tr id="mt_mp_tr_heading">
                <th scope="col" class="col quoteId">
                    <span><?= $escaper->escapeHtml(__('Quote ID')) ?></span>
                </th>
                <th scope="col" class="col status">
                    <span><?= $escaper->escapeHtml(__('Status')) ?></span>
                </th>
                <th scope="col" class="col total_price">
                    <span><?= $escaper->escapeHtml(__('Total Quote Price')) ?></span>
                </th>
                <th>
                    <span>&nbsp;</span>
                </th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td data-th="Quote Id" class="col productName">
                        <input type="text" class="input-text" name="id" 
                        placeholder='<?= $escaper->escapeHtml(__('Search by quote id')) ?>' 
                        value="<?= $escaper->escapeHtml($filter)?>"/>
                    </td>
                    <td data-th="Quote Status" class="col status">
                    <select name="status" id="quote_status">
                    <option value="" <?= ($filterStatus == 0) ? 'selected="selected"' : '' ?>>
                            <?= $escaper->escapeHtml(__('All')) ?></option>
                            <option value="1" <?= ($filterStatus == 1) ? 'selected="selected"' : '' ?>>
                                <?= $escaper->escapeHtml(__('Pending')) ?>
                            </option>
                            <option value="2" <?= ($filterStatus == 2) ? 'selected="selected"' : '' ?>>
                                <?= $escaper->escapeHtml(__('Approved')) ?>
                            </option>
                            <option value="3" <?= ($filterStatus == 3) ? 'selected="selected"' : '' ?>>
                                <?= $escaper->escapeHtml(__('Declined')) ?>
                            </option>
                            <option value="4" <?= ($filterStatus == 4) ? 'selected="selected"' : '' ?>>
                                <?= $escaper->escapeHtml(__('Sold')) ?>
                            </option>
                    </select>
                    <td data-th="Quote Price" class="col quote_price">
                        <input type="text" class="input-text" name="total_price_from" 
                        placeholder='<?= $escaper->escapeHtml(__('From')) ?>'
                        value="<?= $escaper->escapeHtml($totalPriceFrom)?>" />
                        &nbsp;
                        <input type="text" class="input-text" name="total_price_to" 
                        placeholder='<?= $escaper->escapeHtml(__('To')) ?>'
                        value="<?= $escaper->escapeHtml($totalPriceTo)?>" />
                    </td>
                    </td>
                    <input type="hidden" id="sortingStatus" name="sortingStatus" 
                    value="<?= $escaper->escapeHtml($filterSorting); ?>">
                    <input type="hidden" id="sortingType" name="sortingType" 
                    value="<?= $escaper->escapeHtml($filterSortingType); ?>">
                    <td>
                        <button class="button" id="save" title="Save" type="submit">
                            <span><span><span><?= $escaper->escapeHtml(__('Submit')) ?></span></span></span>
                        </button>
                    </td>
                </tr>
            </tbody>
        </table>
    </form>
    <?php if (count($block->getQuotesCollection())==0): ?>
        <div class="fieldset mt_fieldset">
            <div class="mt_emptymsg">
                <?= $escaper->escapeHtml(__('No Quotes Available')) ?>
            </div>
        </div>
    <?php else: ?>
        <?= $block->getBlockHtml('formkey')?>
            <table cellspacing="0" class="data mt_quotelist_table table table-order-items history">
                <thead>
                    <tr>
                        <th scope="col" class="mt_check_first_td sort">
                        <i class="<?= $escaper->escapeHtml($block->quoteId); ?>" type="quoteId"
                            sortingType="<?= $escaper->escapeHtml($filterSortingType); ?>"
                            name="quoteId" aria-hidden="true"></i>
                            <?= $escaper->escapeHtml(__('Quote Id'))?>
                        </th>
                        <th scope="col" class="col mtdate sort">
                        <i class="<?= $escaper->escapeHtml($block->createdAt); ?>" type="createdAt"
                            sortingType="<?= $escaper->escapeHtml($filterSortingType); ?>"
                            name="createdAt" aria-hidden="true"></i>
                        <span><?= $escaper->escapeHtml(__('Date')) ?></span>
                        </th>
                        <th scope="col" class="col mtstatus sort">
                            <i class="<?= $escaper->escapeHtml($block->status); ?>" type="status"
                            sortingType="<?= $escaper->escapeHtml($filterSortingType); ?>"
                            name="status" aria-hidden="true"></i>
                            <?= $escaper->escapeHtml(__('Status'))?>
                        </th>
                        <th scope="col" class="col productPrice sort">
                            <i class="<?= $escaper->escapeHtml($block->quotePrice); ?>" type="quotePrice"
                            sortingType="<?= $escaper->escapeHtml($filterSortingType); ?>"
                            name="quotePrice" aria-hidden="true"></i>
                            <?= $escaper->escapeHtml(__('Total Quote Price'))?>
                        </th>
                        <th scope="col" class="col mtactions">
                            <?= $escaper->escapeHtml(__('Action'))?>
                        </th>
                    </tr>
                </thead>
                <tbody>
                    <?php $i = 0;
                    foreach ($block->getQuotesCollection() as $quote):
                        $currency = $quote->getQuoteCurrency() ? $quote->getQuoteCurrency() : $baseCurrency;
                        ?>
                        <tr>
                            <input type="hidden" class="id" value="<?= $escaper->escapeHtml($quote->getEntityId()); ?>"
                        />
                            <input type="hidden" id="sortingType" name="sortingType" 
                                value="<?= $escaper->escapeHtml($filterSortingType); ?>">
                            <td data-th="Quote Id" class="col body quoteId">
                                <span class="label">
                                <?= $escaper->escapeHtml($quote->getQuoteId()); ?>
                                </span>
                            </td>
                            <td data-th="Date" class="col mtdate">
                                <span class="label">
                                <?= $escaper->escapeHtml($block->formatDate($quote->getCreatedAt())); ?>
                                </span>
                            </td>
                            <td data-th="Status" class="col mtstatus">
                                <span class="label">
                                <?= $escaper->escapeHtml($block->getQuoteStatus($quote->getQuoteId())); ?>
                                </span>
                            </td>
                            <td data-th="Product Price" class="col productPrice">
                                <span class="label">
                                    <input type="hidden"
                                    class="mt_qs_quote_price"
                                    value="<?= $escaper->escapeHtml($quote->getQuotePrice()); ?>">
                                        <?= /* @noEscape */$quoteHelper->getFormatPrice(
                                            $quoteHelper->getmtconvertCurrency(
                                                $currency,
                                                $storeCurrency,
                                                $block->getTotalPrice($quote->getQuoteId())
                                            ),
                                            $storeCurrency
                                        ); ?>
                                </span>
                            </td>
                            <td data-th="Action" class="col mtactions">
                                <span class="label mt_action">
                                    <span><a class="quote_view" aria-hidden="true"
                                    title="<?= $escaper->escapeHtml(__('View Quote'))?>"
                                    href = "<?= $escaper->escapeUrl($block->getUrl(
                                        'quotesystem/buyerquote/view/',
                                        [
                                            'quote_id'=>$quote->getQuoteId(),
                                            '_secure' => $block->getIsSecure()
                                        ]
                                    )) ?>"
                                    login-url = "<?= $escaper->escapeUrl($block->getUrl('customer/account/login')); ?>"
                                    data-type="<?=$escaper->escapeHtml($quote->getEntityId());?>">
                                    <?= $escaper->escapeHtml(__('View Quote'))?></i></span>
                                </span>
                            </td>
                            
                        </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
    <?php endif; ?>
</div>
<div class="toolbar bottom">
    <?= $block->getPagerHtml(); ?>
</div>
<?php
$formData = [
    'quoteedit'         =>   '.quote_edit',
    'massdelete'        =>  '#mass_delete_butn',
    'quotecheckbox'     =>  '.quotecheckbox',
    'massdeleteform'    =>  '#formmassdelete',
    'selectall'         =>  '#quoteselecctall',
    'quotestatus'       =>  '.pro_status button',
    'customerloginUrl'  =>  $block->getUrl('customer/account/login', ['_secure' => $block->getIsSecure()])
];
$serializedFormData = $block->getJsonHelper()->jsonEncode($formData);
// phpcs:disable
?>
<script type="text/x-magento-init">
    {
        "*": {
            "MtQuotesystem": <?= /* @noEscape */ $serializedFormData; ?>
        }
    }
</script>
<?php // phpcs:enable ?>