package com.example.timert

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

class CreatingTraining : AppCompatActivity() {
    private var isSave = false
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_creating_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 buttonSave: Button = findViewById(R.id.btn_save)
        buttonSave.setOnClickListener {

            isSave=true

        }
        val button_on_main: Button = findViewById(R.id.btn_on_main)
        button_on_main.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)

            }
            }

    }
}