import { Game } from './game/Game.js';

document.addEventListener('DOMContentLoaded', () => {
    const canvas = document.getElementById('game-canvas');
    const game = new Game(canvas);

    const menuScreen = document.getElementById('menu-screen');
    const controlsPanel = document.getElementById('controls-panel');
    const menuContent = document.querySelector('.menu-content');

    // Показать кнопку "Продолжить" если есть сохранение
    const btnContinue = document.getElementById('btn-continue');
    if (game.saveSystem.hasSave()) {
        btnContinue.classList.remove('hidden');
    }

    function startGame(fromSave) {
        menuScreen.classList.add('hidden');

        // Crosshair
        if (!document.getElementById('crosshair')) {
            const crosshair = document.createElement('div');
            crosshair.id = 'crosshair';
            document.body.appendChild(crosshair);
        }

        if (fromSave) {
            game.startFromSave();
        } else {
            game.start();
        }

        // Инициализация звука по клику
        game.sound.resume();
    }

    document.getElementById('btn-start').addEventListener('click', () => startGame(false));
    btnContinue.addEventListener('click', () => startGame(true));

    document.getElementById('btn-controls').addEventListener('click', () => {
        menuContent.classList.add('hidden');
        controlsPanel.classList.remove('hidden');
    });

    document.getElementById('btn-back').addEventListener('click', () => {
        controlsPanel.classList.add('hidden');
        menuContent.classList.remove('hidden');
    });
});
