<?php
/* Smarty version 4.5.2, created on 2024-08-14 11:31:23
  from '/home/life/public_html/teg.lifestyle.uz/admin/templates/components/script/uploads-script.tpl' */

/* @var Smarty_Internal_Template $_smarty_tpl */
if ($_smarty_tpl->_decodeProperties($_smarty_tpl, array (
  'version' => '4.5.2',
  'unifunc' => 'content_66bc958b3504e3_47263118',
  'has_nocache_code' => false,
  'file_dependency' => 
  array (
    '063eb7302ac658169daf24e44f82d6c31a956a5e' => 
    array (
      0 => '/home/life/public_html/teg.lifestyle.uz/admin/templates/components/script/uploads-script.tpl',
      1 => 1715335750,
      2 => 'file',
    ),
  ),
  'includes' => 
  array (
  ),
),false)) {
function content_66bc958b3504e3_47263118 (Smarty_Internal_Template $_smarty_tpl) {
echo '<script'; ?>
>

	let modal_block_show = false, countSelected = 0;
	const attachmentDetails = document.querySelector('.attachment-details');
	const selectMime = document.querySelector("#attachment_filters_mime");
	const selectFilter = document.querySelector("#attachment_filters");
	function capitalize(s) {
		return s[0].toUpperCase() + s.slice(1);
	}

	// название функции переименовывать нельзя (подвязно к tinymce)
	function media_content(path, type) {

		$("#media").modal('show');
		// set parameters in localStorage
		settingPath(path, 1);
		localStorage.setItem('type', type);
		let breadcrumbPath = document.querySelector('.breadcrumb_path'), prevLink = "";
		// console.log(path)
		if (path === undefined || path === null) {
			breadcrumbPath.innerHTML = '<a href="index.php?mod=uploads&path=/" data-path="/" class="breadcrumb-item read-more">Uploads</a>';
		} else {
			breadcrumbPath.innerHTML = '<a href="index.php?mod=uploads&path=/" data-path="/" class="breadcrumb-item read-more">Uploads</a>';
			path.split('/').forEach(function (item) {
				if (item.length > 0) {
					prevLink += '/' + `${item}`;
					breadcrumbPath.innerHTML += '<a href="index.php?mod=uploads&path=' + path + '" data-path="' + prevLink + '" class="breadcrumb-item read-more">' + capitalize(`${item}`) + '</a>';
				}
			})
			attachmentDetails.classList.add('d-none')

			$(".add-content").attr('data-type', localStorage.getItem('type'));
		}

		fetchDataToHTML();
	}

	function settingPath(path, page) {
		const modalShowMoreTrigger = document.querySelector('#modal_show_more_trigger'),
				inputSearch = document.querySelector('#search_file'),
				newDirectoryButton = document.querySelector('.new_folder');

		localStorage.setItem('path', path);
		localStorage.setItem('page', page);

		newDirectoryButton.setAttribute("data-path", localStorage.getItem('path'));
		modalShowMoreTrigger.setAttribute('data-page', localStorage.getItem('page'));
		modalShowMoreTrigger.setAttribute("data-path", localStorage.getItem('path'));

		let searchQuery = localStorage.getItem('query');
		if (searchQuery) {
			inputSearch.value = searchQuery;
		}
	}

	// установить кол-во выбранных элементов
	function selectCount(count) {
		const countCheck = document.querySelector('.count_check'),
			mediaActions = document.querySelector('.media-actions'),
			mediaSearch = document.querySelector('.media-search')

		if (count > 0) {
			mediaActions.classList.remove('d-none')
			countCheck.innerHTML  = 'Выбрано (<b>' + count + '</b>)';
		} else {
			mediaActions.classList.add('d-none')
			mediaSearch.classList.remove('d-none')
		}
	}



	const readMoreButton = document.querySelectorAll('.read-more');
	const mediaActions = document.querySelector('.media-actions')
	const mediaSearch = document.querySelector('.media-search')

	Dropzone.autoDiscover = false;

	$(document).ready(function () {
		const id = "#upload_files";
		const progressBar = document.querySelector("#total-progress .progress-bar");
		let dropzoneSingle = new Dropzone(id, {
			dictDefaultMessage:             lang['dictDefaultMessage'],
			dictFallbackMessage:            lang['dictFallbackMessage'],
			dictFallbackText:               lang['dictFallbackText'],
			dictFileTooBig:                 lang['dictFileTooBig'],
			dictInvalidFileType:            lang['dictInvalidFileType'],
			dictResponseError:              lang['dictResponseError'],
			dictCancelUpload:               lang['dictCancelUpload'],
			dictCancelUploadConfirmation:   lang['dictCancelUploadConfirmation'],
			dictRemoveFile:                 lang['dictRemoveFile'],
			dictRemoveFileConfirmation:     lang['dictRemoveFileConfirmation'],
			dictMaxFilesExceeded:           lang['dictMaxFilesExceeded'],
			paramName: "file",
			url: "index.php?mod=uploads&action=upload",
			addRemoveLinks: true,
			maxFilesize:  1024,
			maxFiles: 100,
			params: { action: 'upload' },
		});

		dropzoneSingle.on("totaluploadprogress", function(progress) {
			progressBar.style.opacity = "1";
			progressBar.style.width = progress + "%";
			progressBar.innerHTML = Math.ceil(progress) + "%";
		});

		dropzoneSingle.on('sending', function (file, xhr, formData) {
			progressBar.style.opacity = "1";
			$('#upload_files').addClass('dz-started');

			formData.append('path', localStorage.getItem('path'));
			document.querySelectorAll(".dz-progress").forEach(e => e.remove());
		});

		dropzoneSingle.on("success", function (file, response) {
			if (response.status !== 200) {
				$(file.previewElement).find('.dz-error-mark').css('display', 'block').css('opacity', 1);
			}
			new Noty({ text: response.message, type: response.type }).show();
		});

		dropzoneSingle.on("queuecomplete", async function () {
			setTimeout(function () {
				progressBar.style.opacity = "0";
				progressBar.style.width = 0 + "%";
			}, 300);

			await fetchDataToHTML()

			setTimeout(function () {
				$('.dz-success').fadeOut('slow');
				setTimeout(function () {
					$('#upload_files').removeClass('dz-started');
				}, 800);
			}, 1000);
		});

		dropzoneSingle.on('error', function (file, response) {
			// $(file.previewElement).find('.dz-error-message');
			new Noty({ text: response, type: 'error' }).show();
			progressBar.style.width = 0 + "%";
			progressBar.innerHTML = Math.ceil(0) + "%";
		});
	});

	let index_color = '', type;

	//загрузка всех данных по пути
	$(document).on('click', '.read-more', function(e) {
		e.preventDefault();
		let element = $(this);
		modal_block_show = false;
		localStorage.setItem('page', element.data('type'))

		if (element.data('type') === undefined) {
			type = localStorage.getItem('type')
		} else {
			localStorage.setItem('type', element.data('type'))
			type = localStorage.getItem('type')
		}

		if (element.data('color') === undefined) {
			index_color = localStorage.getItem('color')
		} else {
			localStorage.setItem('color', element.data('color'))
			index_color = localStorage.getItem('color')
		}

		media_content (element.data('path'), type)
	});

	// читать файл

	document.addEventListener('click', async (e) => {
		let selectCardItem = e.target.closest('.card_file_item')

		if (selectCardItem) {
			let type = document.querySelector('.add-content').getAttribute('data-type'), template, fileIds = [];
			let element = selectCardItem.closest('.file-manager-list');

			if (type == 'image') {
				document.querySelectorAll('#file_list > figure.file-manager-list.selected').forEach(item => {
					item.classList.remove("selected", "details")
					item.children[0].classList.remove("border-primary", "border-opacity-50")
				})

				element.classList.add('selected', 'details');
				element.children[0].classList.add('border-primary', 'border-opacity-50');

				fileIds.push(selectCardItem.getAttribute('data-id'));
			} else {
				element.classList.toggle('selected');
				element.classList.toggle('details');
				element.children[0].classList.toggle('border-primary');
				element.children[0].classList.toggle('border-opacity-50');

				mediaActions.classList.remove('d-none')
				mediaSearch.classList.add('d-none')
				document.querySelectorAll('#file_list > figure.file-manager-list.selected')
						.forEach(item => fileIds.push(item.getAttribute('data-id')))
			}

			if (fileIds.length == 0) {
				mediaSearch.classList.remove('d-none')
			}
			selectCount(fileIds.length);
			if (fileIds.length > 0 && fileIds.length < 2) {
				let data = await fetchDataToJSON('get_file', {fileIds: fileIds, path: localStorage.getItem('path')});
				data.forEach(function (item) {
					attachmentDetails.innerHTML = previewTemplate(item);
					attachmentDetails.classList.remove('d-none')
				})
			} else {
				attachmentDetails.classList.add('d-none')
			}
		}

		let removeDirectory = e.target.closest('.remove_folder')
		if (removeDirectory) {
			let confirm = removeDirectory.getAttribute("data-confirm"), folder = removeDirectory.getAttribute("data-folder");
			bootbox.confirm({closeButton: false, message: confirm, callback: async function (res) {
				if (res === true) {
					let data = await fetchDataToJSON('delete_folder', {path: localStorage.getItem('path'), folder: folder});
					if (data.status == 200) {
						new Noty({text: data.message, type: data.type}).show();
						await fetchDataToHTML()
					} else {
						bootbox.confirm({closeButton: false, message: data.message, buttons: {confirm: {label: 'Yes', className: 'btn-sm btn-success'}, cancel: {label: 'No', className: 'btn-sm btn-danger'}}, callback: async function (res) {
							if (res === true) {
								let data = await fetchDataToJSON('confirm_remove_folder', {path: localStorage.getItem('path'), folder: folder});
								new Noty({text: data.message, type: data.type}).show();
								if (data.status == 200) {
									await fetchDataToHTML()
								}
							}
						}});
					}
				}
			}})
		}

		//  удаление файла / удаление файлов
		let removeFiles = e.target.closest('.remove-files')
		if (removeFiles) {
			let confirm =removeFiles.getAttribute("data-confirm"), fileIds = [removeFiles.getAttribute("data-id")];
			bootbox.confirm({ closeButton: false, message: confirm, callback: async function (result) {
				if (result === true) {
					document.querySelectorAll('#file_list > figure.file-manager-list.selected')
					.forEach(item => fileIds.push(item.getAttribute('data-id')))

					let data = await fetchDataToJSON('remove', { fileIds: fileIds, path: localStorage.getItem('path') });
					new Noty({text: data.message, type: data.type}).show();
					if (data.status == 200) {
						attachmentDetails.classList.add('d-none')
						await fetchDataToHTML();
					}
				}
			}})
		}
	})

	// Добавление к контенту, в галерею и основную картинку
	document.querySelector('.add-content').addEventListener('click', async (e) => {
		// console.log(e.target)
		let fileIds = [], type = e.target.getAttribute('data-type');

		document.querySelectorAll('#file_list > figure.file-manager-list.selected').forEach(item => fileIds.push(item.getAttribute('data-id')))

		let data = await fetchDataToJSON('get_file', {fileIds: fileIds, path: localStorage.getItem('path')});
		mediaActions.classList.add('d-none')
		mediaSearch.classList.remove('d-none')

		data.forEach(function (item, i) {
			$("#media").modal('hide');
			// console.log(item)
			if (localStorage.getItem('path') == 'admin') {
				document.querySelector('.profile-thumb').innerHTML = '<div class="profile-thumb">' +
						'<img src="' + item.url + '" class="img-thumbnail rounded-circle shadow" width="100" height="100" alt="">' +
						'<input type="hidden" name="image[fileId]" value="' + item.fileId + '" />' +
						'</div>';
			} else {
				console.log(item)
				if (item.class_ext === 2) {
					// add preview
					if (type === 'image') {
						// заменить текст кнопки при добавлении картинки
						document.getElementById('content-image-preview-add').innerHTML = '<i class="ph-image me-2"></i>Заменить файл';

						// добавляем блок с добавленной картинкой
						document.getElementById('content-image-preview').innerHTML =
								'<div class="card-img-actions card-image-preview" id="image_general-' + item.fileId + '">' +
								'<input type="hidden" name="image[fileId]" value="' + item.fileId + '" />' +
								'<img class="img-fluid" src="' + item.url + '" alt="">' +
								'</div>';

						// проверить на существование кнопки, если нет то добавить кнопку удаления
						const element = document.getElementById('content-image-preview-remove');
						if (!element) {
							document.getElementById('preview-image-footer').innerHTML += '<button id="content-image-preview-remove" type="button" class="btn btn-sm btn-danger" onclick="removePreviewImage()"><i class="ph-trash me-2"></i>Удалить</button>';
						}
					}

					// add content tinyMCE
					else if (type === 'favicon') {
						let attachmentUrl = 'https://' + window.location.hostname + '' + data[i].url
						document.getElementById('master_picture_url').value = attachmentUrl
						prepareInlinePicture(attachmentUrl);
					}else if (type === 'content') {
						parent.tinyMCE.execCommand('mceInsertContent', false, '<img class="" src="' + data[i].url + '"/>');
					}

					// add gallery
					else {
						$(".btn-upload").html('<i class="ph-image me-2"></i> Еще добавить ');
						document.getElementById('fileList').innerHTML +=
								'<figure class="gallery-item mb-0" id="gallery-item-' + item.fileId + '" data-id="' + item.fileId + '">' +
								'<div class="image">' +
								'<input type="hidden" name="gallery[' + item.fileId + '][fileId]" value="' + item.fileId + '" />' +
								'<img src="' + item.url + '"/>' +
								'<ul class="gallery-item-controls">' +
								'<li><span onclick="removePicture(' + item.fileId + ')"><i class="ph-trash"></i></span></li>' +
								'</ul>' +
								'</div>' +
								'</figure>';
					}
				}
				// add document
				if (item.class_ext === 1 || item.class_ext === 3) {
					$(".btn-docs").html('<i class="ph-file-doc me-2"></i> Еще добавить ');

					document.getElementById('pdf_docs').innerHTML +=
							'<figure class="docs mb-2" id="docs-item-' + item.fileId + '">' +
							'<div class="input-group">' +
							'<span class="input-group-text"><img src="/admin/assets/ico/' + item.extension + '.svg" width="30"/></span>' +
							'<input type="text" class="form-control" value="' + item.fileName + '">' +
							'<input type="hidden" name="docs[' + item.fileId + '][fileId]" value="' + item.fileId + '" />' +
							'<button type="button" class="btn btn-danger remove-docs" data-id="' + item.fileId + '"><i class="ph-trash"></i></button>' +
							'</div>' +
							'</figure>'
				}

			}
		})
	});

	// добавление папки
	const buttonNewDirectory = document.querySelector('a.new_folder');
	buttonNewDirectory.addEventListener('click', (e) => {
		e.preventDefault();
		let confirm = buttonNewDirectory.getAttribute('data-confirm');
		console.log(confirm);
		bootbox.prompt({title: confirm, callback: async function (name) {
			if (name !== null) {
				let data = await fetchDataToJSON('new_folder', { path: localStorage.getItem('path'), name: name });
				if (data.status == 200) {
					await fetchDataToHTML()
				}
				new Noty({text: data.message, type: data.type}).show();
			}
		}})
	});

	// выделить все файлы
	document.querySelector('.select-all').addEventListener('click', async () => {
		let list = document.querySelectorAll('#file_list > figure.file-manager-list');
		let countSelected = list.length
		list.forEach((item, i) => {
			setTimeout(function() {
				if(!item.classList.contains('selected')) {
					item.classList.add("selected", "details")
					item.querySelector('.card').classList.add("border-primary", "border-opacity-50")
				}
			}, i * 100);
		})
		selectCount(countSelected);
		attachmentDetails.classList.add('d-none')
	})

	// отменить выделенные все файлы
	document.querySelector('.deselect-all').addEventListener('click', async () => {
		let list = document.querySelectorAll('#file_list > figure.file-manager-list.selected');
		list.forEach((item, i) => {
			setTimeout(function() {
				if (item.classList.contains('selected')) {
					item.classList.remove("selected", "details")
					item.querySelector('.card').classList.remove("border-primary", "border-opacity-50")
				}
			}, i * 100);
		})
		selectCount(0);
		attachmentDetails.classList.add('d-none')
	})

	// поиск по названию файлу
	document.querySelector("input#search_file").addEventListener("keyup", (e) => {
		console.log(e.target.value)
		localStorage.setItem('query', e.target.value);
		fetchDataToHTML();
	});

	/* загрузка всех данных по выбору */
	$(document).on("change", "#attachment_filters", function () {
		localStorage.setItem('filter', $(this).val());
		fetchDataToHTML();
	});

	$(document).on("change", "#attachment_filters_mime", function () {
		localStorage.setItem('mime', $(this).val());
		fetchDataToHTML();
	});

	// $(document).on('click', '.remove-gallery-image', function() {
	//     var elem = document.getElementById($(this).attr('data-val') + '-' + $(this).attr('data-id'));
	//     elem.parentNode.removeChild(elem);
	//     return false;
	// });

	$(document).on('click','.remove-docs', function() {
		let elem = document.getElementById('docs-item-' + $(this).attr('data-id'));
		elem.parentNode.removeChild(elem);
		return false;
	});

	$(".info").on("click", function() {
		bootbox.alert('<div class="text-center"><br/><img src="<?php echo htmlspecialchars((string)$_smarty_tpl->tpl_vars['GLOBAL_URL']->value, ENT_QUOTES, 'UTF-8', true);?>
/admin/assets/img/logo-mnv.svg" alt="Файл менеджер"/><br/><br/><p><strong>Файл менеджер v.1.0.2</strong><br/><a href="https://www.life-style.uz/">life-style.uz</a></p><br/><p>Copyright © <a href="https://www.life-style.uz/" alt="Life Style">Life Style</a>. All rights reserved.</p><br/><p><i class="icon-medal"></i>License<br/><small><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc/3.0/">Creative Commons Attribution-NonCommercial 3.0 Unported License</a></small></p></div>');
	});

	const clipboard = new ClipboardJS('#button-copy', { text: function(trigger) {
		return $(this).attr('data-clipboard-text');
	}});

	clipboard.on('success', function (e) {
		console.info('Text:', e.text);
		$(e.trigger).removeClass('btn-light').addClass('btn-success').text('Скопировано');
		setTimeout(function(){
			$(e.trigger).removeClass('btn-success').addClass('btn-light').text('Скопировать ссылку');
		}, 2000);
	});

	clipboard.on('error', function (e) {
		$(e.trigger).removeClass('btn-light').addClass('btn-danger').text('Ошибка копирования');
		setTimeout(function(){
			$(e.trigger).removeClass('btn-danger').addClass('btn-light').text('Скопировать ссылку');
		}, 2000);
	});


	// подгрузка при скроле
	function modalScrollMore() {

		const file_list = document.getElementById('file_list')
		const show_more = document.querySelector('#modal_show_more_trigger')
		const listFiles = $('#listFiles');

		if (modal_block_show) {
			return false;
		}

		let wt = $(window).scrollTop(),
				wh = $(window).height(),
				et = show_more.offsetTop,
				eh = show_more.outerHeight,
				dh = $(document).height();

		if (wt + wh >= et || wh + wt === dh || eh + et < wh) {
			let page = show_more.getAttribute('data-page');
			page++;

			modal_block_show = true;
			localStorage.setItem('page', page);
			show_more.setAttribute('data-page', page);
			$.ajax({
				type: "POST",
				url: 'index.php?mod=uploads&action=read_more_files&page=' + localStorage.getItem('page'),
				dataType: 'JSON',
				data : { query: localStorage.getItem('query'), path: localStorage.getItem('path'), type: localStorage.getItem('mime'), filters: localStorage.getItem('filter') },
				beforeSend: function() {
					listFiles.block({ centerY: false, centerX: false, message: '<i class="ph-spinner spinner"></i>',
						overlayCSS: { 'z-index' : 98, backgroundColor: '#fff', opacity: 0.8, cursor: 'wait' },
						css: { 'z-index' : 99,  border: 0, padding: 0, backgroundColor: 'none', position: 'fixed', margin: 'auto' }
					});
				},
				success: function(response) {
					file_list.insertAdjacentHTML('beforeend', response.items)
					modal_block_show = response.status !== 200;
					window.setTimeout(function () {
						listFiles.unblock();
					}, 400);

					console.log("page => ", page)
					console.log("totalPages => ", response.pagination.totalPages)

					if (page == response.pagination.totalPages) {
						modal_block_show = true;
					}
				}
			});
		}
	}

	document.querySelector('.attachments').addEventListener('scroll', () => {
		modalScrollMore();
	});

	// ajax
	async function fetchDataToJSON(actions, params) {
		let requestOptions = {
			method: 'POST',
			headers: {'Content-Type': 'application/json'},
			body: JSON.stringify(params)
		};
		try {
			const response = await fetch(`index.php?mod=uploads&action=${actions}`, requestOptions);
			return await response.json();
		} catch (error) {
			console.log('error', error);
			return null;
		}
	}

	// ajax
	async function fetchDataToHTML() {
		const file_list = document.getElementById('file_list')

		let query = localStorage.getItem('query'),
			path = localStorage.getItem('path'),
			type = localStorage.getItem('mime'),
			filters = localStorage.getItem('filter'),
			page = localStorage.getItem('page');

		await fetch("index.php?mod=uploads&action=read_more", {
			method: 'POST',
			headers: {'Content-Type': 'application/json'},
			body: JSON.stringify({
				query: query,
				path: path,
				type: type,
				filters: filters
			})
		}).then(response => response.json()).then(data => {
			$("#media").modal('show');
			selectCount(0);
			file_list.innerHTML = data.items;
			if (page == data.pagination.totalPages) {
				modal_block_show = true;
			}
		}).catch(error => console.error(error));

		// }).then(response => response.json()).then(data => {
		// 	if (data.items.dirs) {
		// 		data.items.dirs.forEach(item => directoryToHTML(data.path, item))
		// 	}
		// 	if (data.items.files) {
		// 		data.items.files.forEach(item => fileToHTML(data.path, item))
		// 	}
		// 	if (page == data.pagination.totalPages) {
		// 		modal_block_show = true;
		// 	}
		// })
	}

	function previewTemplate(item) {
		switch (item.type) {
			case 'image':
			case 'svg':
				return '<div class="card border shadow-sm">' +
						'<div class="card-img bg-light rounded-top text-center"><img src="' + item.url + '" class="img-fluid rounded-top" /></div>' +
						'<div class="card-file-upload-body p-2">' +
						'<div class="img-apply">' +
						'<div class="card-title fw-semibold mb-1"><i class="ph-image text-muted me-2"></i>' + item.fileName + '</div>' +
						'<div class="font-size-sm text-muted mb-1"><i class="ph-image me-2"></i> ' + item.size + '</div>' +
						'<div class="font-size-sm text-muted mb-1"><input type="text" id="copy_link" value="' + item.url + '" class="form-control" readonly /></div>' +
						'<div class="font-size-sm text-muted mb-1">' +
						'<button id="button-copy" class="btn btn-light btn-sm" data-clipboard-action="copy" data-clipboard-target="#copy_link" data-clipboard-text="' + item.url + '">Скопировать ссылку</button>' +
						'</div>' +
						'</div>' +
						'</div>' +
						'</div>';
				break;
			case 'video':
				return '<div class="card border shadow-sm ' + item.type + '">' +
						'<div class="card-img bg-light rounded-top text-center">' +
						'<video width="400" controls class="img-fluid rounded-top" style="min-height: 100px;">' +
						'<source src="' + item.url + '" type="' + item.type + '/' + item.extension + '">' +
						'</video>' +
						'</div>' +
						'<div class="card-file-upload-body p-2">' +
						'<div class="img-apply">' +
						'<div class="card-title fw-semibold mb-1"><i class="ph-file-video text-muted"></i> ' + item.fileName + '</div>' +
						'<div class="font-size-sm text-muted mb-1"><i class="ph-file-video"></i> ' + item.size + '</div>' +
						'<div class="font-size-sm text-muted mb-1"><input type="text" id="copy_link" value="' + item.url + '" class="form-control" readonly /></div>' +
						'<div class="font-size-sm text-muted mb-1">' +
						'<button id="button-copy" class="btn btn-light btn-sm" data-clipboard-action="copy" data-clipboard-target="#copy_link" data-clipboard-text="' + item.url + '">Скопировать ссылку</button>' +
						'</div>' +
						'</div>' +
						'</div>' +
						'</div>';
				break;
			case 'audio':
				return '<div class="card border shadow-sm ' + item.type + '">' +
						'<div class="card-img bg-light rounded-top text-center media-wrapper">' +
						'<audio id="player2" preload="none" src="' + item.url + '" controls style="max-width:100%; background-color: #f1f3f4;">' +
						'<source src="' + item.url + '" type="' + item.type + '/' + item.extension + '">' +
						'</audio>' +
						'</div>' +
						'<div class="card-file-upload-body p-2">' +
						'<div class="img-apply">' +
						'<div class="card-title fw-semibold mb-1"><i class="ph-file-audio text-muted"></i> ' + item.fileName + '</div>' +
						'<div class="font-size-sm text-muted mb-1"><i class="ph-file-audio"></i> ' + item.size + '</div>' +
						'<div class="font-size-sm text-muted mb-1"><input type="text" id="copy_link" value="' + item.url + '" class="form-control" readonly /></div>' +
						'<div class="font-size-sm text-muted mb-1">' +
						'<button id="button-copy" class="btn btn-light btn-sm" data-clipboard-action="copy" data-clipboard-target="#copy_link" data-clipboard-text="' + item.url + '">Скопировать ссылку</button>' +
						'</div>' +
						'</div>' +
						'</div>' +
						'</div>';
				break;
			default:
				return '<div class="card default">' +
						'<div class="card-img bg-light rounded-top text-center"><img src="' + item.icon + '" class="img-fluid" style="min-height: 100px;"/></div>' +
						'<div class="card-file-upload-body p-2">' +
						'<div class="img-apply">' +
						'<div class="card-title fw-semibold mb-1">' + item.fileName + '</div>' +
						'<div class="font-size-sm text-muted mb-1"><i class="ph-image"></i> ' + item.size + '</div>' +
						'<div class="font-size-sm text-muted mb-1"><input type="text" id="copy_link" value="' + item.url + '" class="form-control" readonly /></div>' +
						'<div class="font-size-sm text-muted mb-1">' +
						'<button id="button-copy" class="btn btn-light btn-sm" data-clipboard-action="copy" data-clipboard-target="#copy_link" data-clipboard-text="' + item.url + '">Скопировать ссылку</button>' +
						'</div>' +
						'</div>' +
						'</div>' +
						'</div>';
				break;
		}
	}


	function directoryToHTML(path, {name, size}) {
		console.log(path)
		const directoryList = document.getElementById('file_list');
		directoryList.insertAdjacentHTML('beforeend', `
			<div class="file-manager-list" data-name="${name}">
				<div class="card border shadow-sm">
					<a href="javascript:void('')" data-path="${path}${name}" data-action="read_more" class="card-body bg-light rounded-top read-more p-0">
						<div class="card-img-actions mx-1"><i class="ph-folder-notch card-img img-fluid text-primary" style="font-size: 83px;"></i></div>
						<div class="card-file-upload-body text-left">
							<div class="img-apply">
								<div class="fw-semibold text-primary">${name}</div>
								<div class="fs-sm text-muted mb-2">Size: ${size}</div>
							</div>
						</div>
					</a>
					<div class="card-footer d-flex justify-content-center align-items-center p-1">
						<ul class="list-inline mb-0">
							<li class="list-inline-item">
								<button type="button" data-path="${path}" data-folder="${name}" data-action="delete_folder" data-confirm="Вы уверены, что хотите удалить «${name}»?" class="list-icons-item remove_folder btn btn-link">
									<i class="ph-trash"></i>
								</button>
							</li>
						</ul>
					</div>
				</div>
			</div>`);
	}

	function fileToHTML(path, {fileId, class_ext, icon, original, size, fileName})
	{
		console.log(path)
		const directoryList = document.getElementById('file_list');
		let style = '';
		if (class_ext != 2) {
			style = `background-size: contain; background-image: url('${icon}')`
		} else {
			style = `background-image: url('${original}')`
		}
		directoryList.insertAdjacentHTML('beforeend', `
			<figure class="file-manager-list" data-id="${fileId}">
				<div class="card border shadow-sm">
					<a href="javascript:void('')" class="card-body card_file_item bg-light rounded-top p-1" data-action="read_file" data-id="${fileId}" data-path="${path}">
						<div class="card-img-actions">
							<div class="card-img card-file-upload class_ext_${class_ext}" style="`+ style + `"></div>
						</div>
						<div class="card-file-upload-body text-left">
							<div class="img-apply">
								<div class="fw-semibold text-nowrap text-primary" style="overflow: hidden;text-overflow: ellipsis;white-space: nowrap;"> ${fileName}</div>
								<div class="fs-sm text-muted mb-2">Size: ${size}</div>
							</div>
						</div>
					</a>
					<div class="card-footer d-flex justify-content-center align-items-center p-1">
						<ul class="list-inline mb-0">
							<li class="list-inline-item">
								<a href="${original}" download class="list-icons-item btn btn-link"><i class="ph-download-simple top-0"></i></a>
							</li>
							<li class="list-inline-item">
								<button type="button" data-id="${fileId}" data-path="${path}" data-action="remove" data-confirm="Вы уверены, что хотите удалить «${fileName}»?" class="list-icons-item remove-files btn btn-link">
									<i class="ph-trash"></i>
								</button>
							</li>
						</ul>
					</div>
				</div>
			</figure>`
		);
	}


<?php echo '</script'; ?>
>

<?php }
}
