package com.example.cmpt362_group30_maze_game

import android.content.Intent
import android.os.Bundle
import android.widget.ArrayAdapter
import android.widget.Button
import android.widget.Spinner
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.WindowCompat
import com.example.cmpt362_group30_maze_game.game.GameActivity


class MainActivity : AppCompatActivity() {

    private lateinit var startButton: Button
    private lateinit var leaderboardButton: Button
    private lateinit var settingsButton: Button

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        // Light icons on status bar
        WindowCompat.getInsetsController(window, window.decorView)
            .isAppearanceLightStatusBars = true

        // Difficulty spinner
        val difficultyTypeSpinner: Spinner = findViewById(R.id.difficulty_spinner)
        val difficultyTypeSpinnerAdapter = ArrayAdapter.createFromResource(
            this,
            R.array.map_difficulties,
            android.R.layout.simple_spinner_item
        )
        difficultyTypeSpinnerAdapter.setDropDownViewResource(
            android.R.layout.simple_spinner_dropdown_item
        )
        difficultyTypeSpinner.adapter = difficultyTypeSpinnerAdapter

        // ---- START GAME (directly opens GameActivity, no calibration dialog) ----
        startButton = findViewById(R.id.startGameButton)
        startButton.setOnClickListener {
            val difficultyIndex = difficultyTypeSpinner.selectedItemPosition
            val intent = Intent(this, GameActivity::class.java)
            intent.putExtra(GameActivity.DIFFICULTY_ARG_KEY, difficultyIndex)
            startActivity(intent)
        }

        // ---- LEADERBOARD ----
        leaderboardButton = findViewById(R.id.leaderboardButton)
        leaderboardButton.setOnClickListener {
            val intent = Intent(this, LeaderboardActivity::class.java)
            startActivity(intent)
        }

        // ---- SETTINGS ----
        settingsButton = findViewById(R.id.settingsButton)
        settingsButton.setOnClickListener {
            val intent = Intent(this, SettingsActivity::class.java)
            startActivity(intent)
        }
    }
}
