<?php 
/**
 * Webkul Software.
 * 
 * PHP version 7.0+
 *
 * @category  Webkul
 * @package   Webkul_MobikulCore
 * @author    Webkul <support@webkul.com>
 * @copyright 2010-2019 Webkul Software Private Limited (https://webkul.com)
 * @license   https://store.webkul.com/license.html ASL Licence
 * @link      https://store.webkul.com/license.html
 */
$textureData = $block->getTextureImageData();
$key = 1;
if ($textureData["texture_images"] && is_array(json_decode($textureData["texture_images"])) && count(json_decode($textureData["texture_images"]))) { ?>
    <?php $images = json_decode($textureData["texture_images"]);
    $i = 1; ?>
    <div id="wk-mobikul-textureimages">
        <?php foreach ($images as $key => $image) {
            $path = parse_url($image)["path"] ?? "";
            $path = explode(".", $path)[0]; ?>
            <div class="admin__field texture-image">
                <label class="admin__field-label">
                    <span><?php echo __("Texture Image"); ?></span>
                </label>
                <div class="admin__field-control">
                    <input class="admin__control-file" type="file" name="ar_texture_image[ar_<?php echo $key ?>]" form="product_form" data-form-part="product_form">
                    <span>
                        <img height="24px" width="24px" src="<?php echo $image; ?>">
                        <input type="checkbox" name="texture_image_delete[<?php echo $path ?>]" id="LIUERMU_delete" form="product_form" data-form-part="product_form" >
                        <div class="admin__field-note" >
                            <span><?php echo __("Allowed file type: png, jpg, jpeg."); ?></span>
                        </div>
                        <span data-bind="i18n:'Delete'">Delete</span>
                    </span>
                </div>
                <?php if ($i == 1) { ?>
                    <button id="wk-mobikul-texture-add-more"><?php echo __("Add More");?></bitton>
                <?php } ?>
            </div>
            <?php $i++; ?>
        <?php } ?>
    </div>
<?php } else { ?>
    <div id="wk-mobikul-textureimages" >
        <div class="admin__field texture-image" >
            <label class="admin__field-label">
                <span><?php echo __("Texture Image"); ?></span>
            </label>
            <div class="admin__field-control">
                <input class="admin__control-file" type="file" name="ar_texture_image[ar_0]" form="product_form" data-form-part="product_form">
                <div class="admin__field-note" >
                    <span><?php echo __("Allowed file type: png, jpg, jpeg."); ?></span>
                </div>
            </div>
            <button id="wk-mobikul-texture-add-more"><?php echo __("Add More");?></bitton>
        </div>
    </div>
<?php } ?>
<script id="wk-texture-template" type="text/x-magento-template">
    <div class="admin__field texture-image">
        <label class="admin__field-label">
            <span><?php echo __("Texture Image"); ?></span>
        </label>
        <div class="admin__field-control">
            <input class="admin__control-file" type="file" name="ar_texture_image[ar_<%- data.index %>]" form="product_form" data-form-part="product_form">
            <div class="admin__field-note" >
                <span><?php echo __("Allowed file type: png, jpg, jpeg."); ?></span>
            </div>
        </div>
        <button id="wk-mobikul-texture-delete"><?php echo __("Delete");?></bitton>
    </div>
</script>
<?php if ($textureData) { ?>
    <script type="text/x-magento-init">
        {
            "*": {
                "Webkul_MobikulCore/js/textureimage": {
                    "arType" : "<?php /* @noEscape */ echo $textureData['ar_type'] ?>",
                    "productType" : "<?php /* @noEscape */ echo $textureData['product_type'] ?>",
                    "ar_model_file_android_model" : "<?php /* @noEscape */ echo $textureData['ar_model_file_android_model'] ?>",
                    "ar_model_file_ios_model" : "<?php /* @noEscape */ echo $textureData['ar_model_file_ios_model'] ?>",
                    "key": "<?php /* @noEscape */ echo $key ?>"
                }
            }
        }
    </script>
<?php } ?>
<script>
    require([
        "jquery",
        "mage/mage"
    ], function($){
        $('[data-index=block_gallery]').find('div').trigger('click');
        $("#wk-mobikul-textureimages").hide();
    });
</script>
