<script src="assets/plugins/custom/tinymce/tinymce.bundle.js"></script>
<script>
"use strict";
<?php $editor_flds_id_arr = $benefit_flds_id_arr = $packing_flds_id_arr = []; 
	if($language_list){ 
		foreach($language_list as $language){
			array_push($editor_flds_id_arr,'#description_'.$language['code']);
			array_push($benefit_flds_id_arr,'benefit_'.$language['code']);
			array_push($packing_flds_id_arr,'packing_'.$language['code']);
		}
	} 
?>
var KTTinymce = function () {    
    // Private functions
    var demos = function () {                
        tinymce.init({
            selector: '<?=implode(", ",$editor_flds_id_arr)?>',
            extended_valid_elements: 'span[*],i[*]',
			relative_urls : false,
            menubar: false,
            toolbar: ['styleselect fontselect fontsizeselect',
                'undo redo | cut copy paste | bold italic | link image | alignleft aligncenter alignright alignjustify',
                'bullist numlist | outdent indent | blockquote subscript superscript | advlist | autolink | lists charmap | print preview |  code'], 
            plugins : 'advlist autolink link image lists charmap print preview code'
        });
    }

    return {
        // public functions
        init: function() {
            demos(); 
        }
    };
}();

var KTTagify = function() {
    // Private functions
<?php if($language_list){  ?>
	<?php foreach($benefit_flds_id_arr as $benefit_fld_id){ ?>
	var <?=$benefit_fld_id?>Tagify = function() {
        var <?=$benefit_fld_id?>_input = document.getElementById('<?=$benefit_fld_id?>');
        var <?=$benefit_fld_id?>_tagify = new Tagify(<?=$benefit_fld_id?>_input, {
            //pattern: /^.{0,20}$/, // Validate typed tag(s) by Regex. Here maximum chars length is defined as "20"
            delimiters: null, // add new tags when a comma or a space character is entered
            //maxTags: 6,
            blacklist: ["fuck", "shit", "pussy"],
            keepInvalidTags: true, // do not remove invalid tags (but keep them marked as invalid)
            //whitelist: ["temple", "stun"]
        });
    }
	<?php } ?>
	<?php foreach($packing_flds_id_arr as $packing_fld_id){ ?>
	var <?=$packing_fld_id?>Tagify = function() {
        var <?=$packing_fld_id?>_input = document.getElementById('<?=$packing_fld_id?>');
        var <?=$packing_fld_id?>_tagify = new Tagify(<?=$packing_fld_id?>_input, {
            //pattern: /^.{0,20}$/, // Validate typed tag(s) by Regex. Here maximum chars length is defined as "20"
            delimiters: null, // add new tags when a comma or a space character is entered
            //maxTags: 6,
            blacklist: ["fuck", "shit", "pussy"],
            keepInvalidTags: true, // do not remove invalid tags (but keep them marked as invalid)
            //whitelist: ["temple", "stun"]
        });
    }
	<?php } ?>
	return {
        // public functions
        init: function() {
			<?php foreach($benefit_flds_id_arr as $benefit_fld_id){ ?>
            <?=$benefit_fld_id?>Tagify();
			<?php } ?>
			<?php foreach($packing_flds_id_arr as $packing_fld_id){ ?>
            <?=$packing_fld_id?>Tagify();
			<?php } ?>
        }
    };
<?php } ?>
}();
// Initialization
jQuery(document).ready(function() {
    KTTinymce.init();
	KTTagify.init();
});

function showBannerImage(){
	var image = $('#uploaded_banner_image').val();
	loadModal('xl');
	var html = '<div class="modal-header">' +
			'<h5 class="modal-title" id="exampleModalLabel">Banner</h5>' +
			'<button type="button" class="close" data-dismiss="modal" aria-label="Close">' +
			'<i aria-hidden="true" class="ki ki-close"></i>' +
			'</button>' +
			'</div>' +
			'<div class="modal-body">'+
			'<img src="<?=base_url()?>/public/uploads/'+image+'" alt="'+image+'" class="img-fluid">' +
			'</div>';
			//alert(html);
	$('#popup_wrapper_model_content').html(html);	
}
function showProductImage(no){
	var image = $('#uploaded_product_image_'+no).val();
	loadModal('xl');
	var html = '<div class="modal-header">' +
			'<h5 class="modal-title" id="exampleModalLabel">Product Image ' + no + '</h5>' +
			'<button type="button" class="close" data-dismiss="modal" aria-label="Close">' +
			'<i aria-hidden="true" class="ki ki-close"></i>' +
			'</button>' +
			'</div>' +
			'<div class="modal-body">'+
			'<img src="<?=base_url()?>public/uploads/'+image+'" alt="'+image+'" class="img-fluid">' +
			'</div>';
			//alert(html);
	$('#popup_wrapper_model_content').html(html);	
}
function showProductIcon(no){
	var image = $('#uploaded_product_icon_img_' + no).val();
	loadModal('xl');
	var html = '<div class="modal-header">' +
			'<h5 class="modal-title" id="exampleModalLabel">Icon ' + no + '</h5>' +
			'<button type="button" class="close" data-dismiss="modal" aria-label="Close">' +
			'<i aria-hidden="true" class="ki ki-close"></i>' +
			'</button>' +
			'</div>' +
			'<div class="modal-body">'+
			'<img src="<?=base_url()?>public/uploads/'+image+'" alt="'+image+'" class="img-fluid">' +
			'</div>';
			//alert(html);
	$('#popup_wrapper_model_content').html(html);	
}
// document file
function showProduct_doc_file(){
	var image = $('#uploaded_product_icon_img_4').val();
	loadModal('xl');
	var html = '<div class="modal-header">' +
			'<h5 class="modal-title" id="exampleModalLabel">product_icon_img_4</h5>' +
			'<button type="button" class="close" data-dismiss="modal" aria-label="Close">' +
			'<i aria-hidden="true" class="ki ki-close"></i>' +
			'</button>' +
			'</div>' +
			'<div class="modal-body">'+
			'<img src="<?=base_url()?>/public/uploads/'+image+'" alt="'+image+'" class="img-fluid">' +
			'</div>';
			//alert(html);
	$('#popup_wrapper_model_content').html(html);	
}

function deleteFile(pno,fld_name){
	Swal.fire({
        title: "Are you sure?",
        text: "You won't be able to revert this!",
        icon: "warning",
        showCancelButton: true,
        confirmButtonText: "Yes, delete it!"
    }).then(function(result) {		
        if (result.value) {
			blockPage();
			$.get('<?=get_admin_path("products/delete_file")?>/'+ pno + '/' + fld_name, function(data, status){		
				if(data=='SUCCESS'){
					$('#view_'+fld_name).html('');
				}
				unblockPage();
			});
        }
    });	
}
</script>