package com.example.timert

import android.app.AlertDialog
import android.content.Intent
import android.os.Bundle
import android.widget.Button
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class AllTraining : AppCompatActivity() {
    private var isSave = false

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_all_training)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
        val buttonSaveAll: Button = findViewById(R.id.btn_save_all_vse)
        buttonSaveAll.setOnClickListener {
            val intent = Intent(this, MainActivity::class.java)
            startActivity(intent)
            isSave = true

        }
        val button_on_main_all: Button = findViewById(R.id.btn_on_main_all_vse)
        button_on_main_all.setOnClickListener {
            if (isSave == false) {
                AlertDialog.Builder(this)
                    .setTitle("Изменения не сохранены")
                    .setMessage("Продолжить без сохранения?")
                    .setPositiveButton("Да") { _, _ ->

                        val intent = Intent(this, MainActivity::class.java)
                        startActivity(intent)
                    }
                    .setNegativeButton("Нет") { dialog, _ ->
                        dialog.dismiss()
                    }
                    .show()
            } else {
                val intent = Intent(this, MainActivity::class.java)
                startActivity(intent)
            }
        }
    }
}