"use strict";

// Import dependencies
import("/js/core.js").then(() =>
	import("/js/damper.js").then(() =>
		import("/js/telegram.js").then(() =>
			import("/js/account.js").then(() => {
				const dependencies = setInterval(() => {
					if (
						typeof core === "function" &&
						typeof core.damper === "function" &&
						typeof core.telegram === "function" &&
						typeof core.account === "function"
					) {
						clearInterval(dependencies);
						clearTimeout(timeout);
						initialization();
					}
				}, 10);
				const timeout = setTimeout(() => {
					clearInterval(dependencies);
					initialization();
				}, 5000);

				function initialization() {
					//
					const { initData, initDataUnsafe, ...data } = core.telegram.api;

					//
					core.session.buffer.write("telegram_program", JSON.stringify(data));

					if (core.telegram.api.initData.length > 0) {
						//

						//
						core.account.authentication();
					}

					//
					core.telegram.api.ready();
				}
			})
		)
	)
);
