<?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\CustomProduct $block */
//echo get_class($block);
$tierPrices = $block->getTierPrice();
$jsonTirPrice = '{}';
if(count($tierPrices)) {
    $jsonTirPrice = $block->convertJsonEncode($tierPrices);
}
//test
$mediaPath = $block->getMediaPath();
$extraOptions = @file_get_contents($mediaPath . 'previews/b2c_option_product.json');
$extraOptions = (array)json_decode($extraOptions);

$extraPriceOptions = @file_get_contents($mediaPath . 'previews/prices.json');
$extraPriceOptions =  (array)json_decode($extraPriceOptions);

$product = $block->getPreviewProductData();
$customerGroup = $block->getCustomerGroup();

//echo (string)$previewDiscounts->getSelect();
$minFirstQty = 0;
$maxFirstQty = 0;
if(count($tierPrices)) {
    $minFirstQty = 1;
    foreach ($tierPrices as $tierPrice) {
        $maxFirstQty = $tierPrice['price_qty'];
        break;
    }
}
?>
<?php if($product != null) : ?>
    <?php
    $allExtraCustompPrice = (float)$product->getData('preview_additional_options') + (float)$product->getData('pcto_shipping_price') + (float)$product->getData('pcto_shipping_price');
    $previewAdditionOptions = $block->getPreviewAdditionalOptions($product->getId());
    ?>
    <input type="hidden" name="extra_option_all_price" value="<?php echo $allExtraCustompPrice; ?>">
    <input type="hidden" id="txt-preview-type" name="txt_preview_type" value="1">
    <div class="custom-tier-prices" id="custom-tier-prices-content">

    </div>
    <div class="mgt-custom-box-qty">
        <div class="mgt-custom-box-qty-item">
            <div class="mgt-custom-box-qty-item-col">
                <?php echo __('QUANTITY') ?>
            </div>
            <div class="mgt-custom-box-qty-item-col-input">
                <input type="number" id="mgt-custom-qty" value="1" class="input-text qty" data-validate="{"required-number":true,"validate-item-quantity":{"minAllowed":1,"maxAllowed":10000}}">
            </div>
            <div class="mgt-custom-box-qty-item-col">
                <?php echo __('pcs') ?>
            </div>
        </div>
    </div>
    <div class="mgt-project-extra-options" id="preview-project-extra-options" style="display: none">
        <?php if($previewAdditionOptions && $previewAdditionOptions->getSize() > 0) :  ?>
            <?php foreach ($previewAdditionOptions as $additionOption) : ?>
                <div class="mgt-project-extra-option mgt-project-extra-option-first">
                    <div class="mgt-project-extra-option-col mgt-project-extra-option-col-first">
                        <input type="checkbox" class="txt-preview-extra-option" id="txt-preview-extra-option-additional-<?php echo $additionOption->getId(); ?>" name="preview_additional_options[]" value="<?php echo $additionOption->getId(); ?>" />
                    </div>
                    <div class="mgt-project-extra-option-col">
                        <label for="txt-preview-extra-option-additional"><?php echo $additionOption->getData('title') ?></label>
                    </div>
                    <div class="mgt-project-extra-option-col mgt-project-extra-option-col-last">
                        <a href="#" data-toggle="preview-tooltip" title="<?php echo $additionOption->getData('description') ?>"><i class="fas fa-info-circle"></i></a>
                    </div>
                </div>
            <?php endforeach; ?>
        <?php endif; ?>


    </div>

    <div class="mgt-project-price-options" id="mgt-project-discount-options" style="">


    </div>
    <div class="mgt-custom-box-project-name">
        <input type="text" id="mgt-custom-project-name" name="custom_project_name" value="" placeholder="<?php echo __('Project Name') ?>" class="input-text" data-validate="{"required-number":true}">
    </div>
    <div class="mgt-custom-box-project-name">
        <input type="checkbox" class="checkbox" id="txt-is-request-sample" value="0">
        <label for="txt-is-request-sample"><?php echo __('Request for sample product(s)') ?></label>
    </div>
    <input type="hidden" id="txt-tier-prices" value="<?php echo htmlentities($jsonTirPrice); ?>">

    <div class="preview-total-price-content">
        <div class="preview-total-price-text">
            <?php echo __('Gesammtpreis') ?>
        </div>
        <div id="preview-total-price-value">
            <?php echo $block->convertNumberToPrice($product->getFinalPrice()); ?>
        </div>
    </div>


<?php endif; ?>
<input type="hidden" id="txt-tier-fist-min-qty" value="<?php echo $minFirstQty ?>">
<input type="hidden" id="txt-tier-fist-max-qty" value="<?php echo $maxFirstQty ?>">
<input type="hidden" id="txt-custom-preview-design-type" name="txt_custom_preview_design_type" value="0">
