<?php
/**
 *
 * @category  Magetop Extensions
 * @package   Magetop_Quotesystem
 * @author    Magetop Developer
 * @copyright Copyright (c) Magetop (https://www.magetop.com)
 * @license   https://www.magetop.com/license.html
 */
?>
<?= $block->getChildHtml('', true) ?>
<style>
#product_composite_configure_fields_qty{
    display:none;
}
</style>
<div id="mt_quotesystem" class="main-col" style="display: none;">
    <form id="mt_quotesystem_popup" method="POST" enctype="multipart/form-data" class="admin__scope-old edit-form"
    action="<?= $escaper->escapeUrl($block->getUrl(
        'quotesystem/buyerquote/savequote',
        ['_secure' => $block->getIsSecure()]
    ))?>">
        <div id="product_composite_configure_messages" style="display: none;">
            <div class="messages"><div class="message message-error error"><div></div></div></div>
        </div>
        <div id="product_composite_configure_form">
            <input type="hidden" name="as_js_varname" value="iFrameResponse">
        </div>
        <input type="hidden" name="as_js_varname" value="iFrameResponse">
        <input type="hidden" name="product" value=""/>
        <input type="hidden" name="customer_id" value=""/>
        <input type="hidden" name="store_id" value=""/>
        <input type="hidden" name="form_key" value="<?= $escaper->escapeHtml($block->getFormKey()) ?>"/>
        <div class="mt_quote_configurable_options product_composite_configure_form_fields"
         id =product_composite_configure_form_fields></div>
        <div class="entry-edit form-inline" >
            <fieldset class="fieldset admin__fieldset">
                <legend class="legend admin__legend"><?= /* @noEscape */ __("Quote Product") ?></legend>
                <div class="admin__field field field-attribute_label  required _required">
                    <label for="quote_qty" class="label admin__field-label quote_qty">
                        <span><?= /* @noEscape */ __("Quantity"); ?> :</span>
                    </label>
                    <div class="admin__field-control control">
                        <input type="text" id="quote_qty" name="quote_qty" 
                        class=" input-text admin__control-text required-entry required" 
                        data-validate="{required:true,'validate-greater-than-zero':true, 'validate-number':true}"/>
                    </div>
                    <span class="mt-qs-min-qty"></span>
                </div>
                <div class="admin__field field field-attribute_label  required _required">
                    <label for="quote_price" class="label admin__field-label">
                        <span><?= /* @noEscape */ __("Price per Item"); ?> :</span>
                    </label>
                    <div class="admin__field-control control">
                        <input type="text" id="quote_price" name="quote_price" class="admin__control-text" 
                        data-validate="{required:true,'validate-greater-than-zero':true, 'validate-number':true}"/>
                    </div>
                </div>
                <div class="admin__field field field-attribute_label  required _required">
                    <label for="quote_description" class="label admin__field-label">
                        <span><?= /* @noEscape */ __("Description"); ?> :</span>
                    </label>
                    <div class="admin__field-control control">
                        <textarea id="quote_description" name="quote_description" class="textarea"
                        data-validate="{required:true}"></textarea>
                    </div>
                </div>
                <div class="mt-file-field-container">
                    <label class="label mt-file-label mt-quote-primary-btn">
                        <?= /* @noEscape */ __('Add Attachment(s)') ?>
                        <input type="file" name="files" class="mt-file-field" id="mt-file-field"
                        data-url="<?= $escaper->escapeUrl(
                            $block->getUrl(
                                'quotesystem/buyerquote/fileUpload',
                                ['_secure' => $block->getRequest()->isSecure()]
                            )
                        ) ?>" multiple="multiple"/>
                    </label>
                    <span id="allowed-file-type" class="allowed-file-type">
                        <?= $escaper->escapeHtml("Allowed file type(s) *".$block->getAllowedFileTypes()."*"); ?>
                    </span>
                </div>
            </fieldset>
        </div>
    </form>
</div>
<div id="mt_open_modal">
    <div id="product_composite_configure_form_fields1" class="content product-composite-configure-inner"></div>
</div>



<!-- Form for mass quote action -->

<form id="mt_quotesystem_massquote_popup" method="POST" enctype="multipart/form-data" class="admin__scope-old edit-form"
    action="<?= $escaper->escapeUrl($block->getUrl(
        'quotesystem/buyerquote/massquotesave',
        ['_secure' => $block->getIsSecure()]
    ))?>">
        <div id="product_composite_configure_messages" style="display: none;">
            <div class="messages"><div class="message message-error error"><div></div></div></div>
        </div>
        <div id="product_composite_configure_form">
            <input type="hidden" name="as_js_varname" value="iFrameResponse">
        </div>
        <input type="hidden" name="product_ids" value=""/>
        <input type="hidden" name="customer_id" value=""/>
        <input type="hidden" name="store_id" value=""/>
        <input type="hidden" name="form_key" value="<?= $escaper->escapeHtml($block->getFormKey()) ?>"/>

        <div class="entry-edit form-inline" >
            <fieldset class="fieldset admin__fieldset">
                <legend class="legend admin__legend"><?= /* @noEscape */ __("Quote Product") ?></legend>
                <div class="admin__field field field-attribute_label  required _required">
                    <label for="quote_qty" class="label admin__field-label quote_qty">
                        <span><?= /* @noEscape */ __("Quantity"); ?> :</span>
                    </label>
                    <div class="admin__field-control control">
                        <input type="text" id="quote_qty" name="quote_qty" 
                        class=" input-text admin__control-text required-entry required" 
                        data-validate="{required:true,'validate-greater-than-zero':true, 'validate-number':true}"/>
                    </div>
                    <span class="mt-qs-min-qty"></span>
                </div>
                <div class="admin__field field field-attribute_label  required _required">
                    <label for="quote_price" class="label admin__field-label">
                        <span><?= /* @noEscape */ __("Price per Item"); ?> :</span>
                    </label>
                    <div class="admin__field-control control">
                        <input type="text" id="quote_price" name="quote_price" class="admin__control-text" 
                        data-validate="{required:true,'validate-greater-than-zero':true, 'validate-number':true}"/>
                    </div>
                </div>
                <div class="admin__field field field-attribute_label  required _required">
                    <label for="quote_description" class="label admin__field-label">
                        <span><?= /* @noEscape */ __("Description"); ?> :</span>
                    </label>
                    <div class="admin__field-control control">
                        <textarea id="quote_description" name="quote_description" class="textarea"
                        data-validate="{required:true}"></textarea>
                    </div>
                </div>
                <div class="mt-file-field-container">
                    <label class="label mt-file-label mt-quote-primary-btn">
                        <?= /* @noEscape */ __('Add Attachment(s)') ?>
                        <input type="file" name="files" class="mt-file-field" id="mt-mass-file-field"
                        data-url="<?= $escaper->escapeUrl(
                            $block->getUrl(
                                'quotesystem/buyerquote/fileUpload',
                                ['_secure' => $block->getRequest()->isSecure()]
                            )
                        ) ?>" multiple="multiple"/>
                    </label>
                </div>
            </fieldset>
        </div>
        <script id="mt-mass-file-field-template" type="text/x-magento-template">
            <div class="mt-uploaded-file">
                <span class="mt-uploaded-file-style mt-quote-primary-btn"><%- data.extension %></span>
                <span class="mt-uploaded-file-name"><%- data.name %></span>
                <input type="hidden" name="attachments[]" value="<%- data.file %>" class="mt-uploaded-file-value"/>
                <span class="mt-uploaded-file-del"></span>
            </div>
        </script>
        <script id="mt-mass-file-field-uploader-template" type="text/x-magento-template">
            
        </script>
    </form>
<script id="mt-file-field-template" type="text/x-magento-template">
    <div class="mt-uploaded-file">
        <span class="mt-uploaded-file-style mt-quote-primary-btn"><%- data.extension %></span>
        <span class="mt-uploaded-file-name"><%- data.name %></span>
        <input type="hidden" name="attachments[]" value="<%- data.file %>" class="mt-uploaded-file-value"/>
        <span class="mt-uploaded-file-del"></span>
    </div>
</script>
<script id="mt-file-field-uploader-template" type="text/x-magento-template">
    <div id="<%- data.id %>" class="mt-uploaded-file-row">
        <img src="<?= $escaper->escapehtml($block->getViewFileUrl('Magetop_Quotesystem/images/ajax-loader-big.gif'))?>"/>
    </div>
</script>
<?php
    $formData = [
        "store" => $block->getUrl('quotesystem/buyerquote/store', ['_secure' => $block->getIsSecure()]),
        "ajaxurl" => $block->getUrl('quotesystem/buyerquote/checkproducttype', ['_secure' => $block->getIsSecure()]),
        "optionsurl" => $block->getUrl('quotesystem/buyerquote/productoptions', ['_secure' => $block->getIsSecure()]),
        "formkey" => $block->getFormKey(),
        "bundleOptionsUrl" => $block->getUrl(
            'quotesystem/buyerquote/bundleOptions',
            ['_secure' => $block->getIsSecure()]
        ),
        "customOptionsUrl" => $block->getUrl(
            'sales/order_create/configureProductToAdd',
            ['_secure' => $block->getIsSecure()]
        ),
        'fileDeleteUrl'         =>  $block->getUrl(
            'quotesystem/buyerquote/fileDelete',
            ['_secure' => $block->getRequest()->isSecure()]
        ),
        'quoteUrl' => $block->getUrl(
            'quotesystem/managequotes/index',
            ['_secure' => $block->getRequest()->isSecure()]
        ),
    ];
    $serializedFormData = $block->getJsonHelper()->jsonEncode($formData);
    ?>
<script type="text/x-magento-init">
    {
        "*": {
            "MtAddquote": <?= /* @noEscape */ $serializedFormData; ?>
        }
    }
</script>

