core.modules.connect(["generator", "pechatalka"])
	.then(() => {
		// Imported modules

		// Initializing the instance
		const instance = core.global.pechatalka = new core.global.pechatalka(
			document.getElementById("pechatalka"),
			document.getElementById("pechatalka")?.querySelector(".canvas"),
			document.getElementById("pechatalka")?.querySelector(".result"),
			new Map([
				["interface", true],
				["round", true],
			]),
		);

		// instence.layers.set('interface', true)

		// Reinitializing the `layer create` event
		instance.events
			.get("layers")
			.set("create", (layer) => {
				for (const button of layer.buttons.values()) {
					// Iterating over the layer buttons

					// Writing the class
					button.classList.add("rounded");
				}

				// Initializing the interface changing function
				const interface_change = (value) => {
					if (value) {
						// Interface are enabled

						for (const button of layer.buttons.values()) {
							// Iterating over the layer buttons

							// Writing the class
							button.classList.remove("disabled");
						}
					} else {
						// Interface are disabled

						for (const button of layer.buttons.values()) {
							// Iterating over the layer buttons

							// Writing the class
							button.classList.add("disabled");
						}
					}
				};

				// Reinitializing `interface` events functions
				layer.events.set(
					"interface",
					new Map([
						["toggle", interface_change],
						["set", interface_change],
					]),
				);

				// Initial processing of the interface function
				interface_change(instance.preset.get("interface") ?? false);

				// Initializing the round changing function
				const round_change = (value) => {
					if (value) {
						// Round are enabled

						// Writing the class
						layer.content.classList.add("rounded");
					} else {
						// Round are disabled

						// Writing the class
						layer.content.classList.remove("rounded");
					}
				};

				// Reinitializing `round` events functions
				layer.events.set(
					"round",
					new Map([
						["toggle", round_change],
						["set", round_change],
					]),
				);

				// Initial processing of the round function
				round_change(instance.preset.get("round") ?? false);

				if (layer.type === "image") {
					// Image

					// Writing the layer type
					layer.wrap.setAttribute("data-layer-type", "image");
				}
			});

		// Reinitializing the `layer create` event
		instance.events
			.get("cost")
			.set("changed", (to, from) => {
				// Writing the total cost into the document
				instance.result.querySelector(".cost").innerText = to;
			});
	});
