"use strict";

core.modules.connect(["telegram"])
	.then(() => {
		//

		// Expanding the "Web App" window
		// core.telegram.api.expand();

		// Writing settings for the "Web App" window
		core.telegram.api.enableVerticalSwipes();
		core.telegram.api.disableClosingConfirmation();
		core.telegram.api.setHeaderColor(core.telegram.api.themeParams.header_bg_color);
		core.telegram.api.setBackgroundColor(core.telegram.api.themeParams.secondary_bg_color);
		core.telegram.api.setBottomBarColor(core.telegram.api.themeParams.bottom_bar_bg_color);

		// Writing settings for the "Back Button" of the "Web App" window
		core.telegram.api.BackButton.hide();

		if (core.telegram.api.themeParams.section_bg_color === core.telegram.api.themeParams.bg_color) {
			// The sections color matches the background color
			
			// Replacing the sections color with the secondary background color
			document.documentElement.style.setProperty('--tg-theme-section-bg-color', 'var(--tg-theme-secondary-bg-color)');
		}

		core.modules.connect(["session", "account"])
			.then(() => {
				//
			
				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();
	});
