import './common/backup';
import { restoreFile } from './common/backup/restoreFile';
import { compressFile } from './compress';
import { applyWatermark } from './watermark';
import { addAnimationToBtnSaveChanges, getActionsContainer } from './common/DOMElements';
import { userHasCredits } from './common/Account/user';

import '../scss/app.scss';

window.addEventListener('load', function () {
	addAnimationToBtnSaveChanges();

	userHasCredits();

	document.addEventListener('click', function (event) {
		const btnTrigger = event.target;

		if (btnTrigger.classList.contains('ipdf-btn--media-action-compress')) {
			event.preventDefault();

			btnTrigger.classList.add('ipdf-btn--media-action-trigger');
			const statusContainer = getActionsContainer(btnTrigger);

			compressFile(statusContainer, btnTrigger);
		}

		if (btnTrigger.classList.contains('ipdf-btn--media-action-watermark')) {
			event.preventDefault();

			btnTrigger.classList.add('ipdf-btn--media-action-trigger');
			const statusContainer = getActionsContainer(btnTrigger);

			applyWatermark(statusContainer, btnTrigger);
		}

		if (event.target.classList.contains('ipdf-btn--media-action-restore')) {
			event.preventDefault();

			restoreFile(btnTrigger);
		}
	});
});
