package com.example.defenseapplication.view

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.Gravity
import android.view.WindowManager
import com.example.defenseapplication.R
import com.example.defenseapplication.databinding.DialogAutoModeNoticeBinding
import java.util.Calendar

class AutoModeNoticeDialog(context: Context) : Dialog(context) {

    private lateinit var binding: DialogAutoModeNoticeBinding
    private var onConfirmListener: ((year: Int, month: Int, day: Int, hour: Int, minute: Int) -> Unit)? = null
    private var selectedYear = 0
    private var selectedMonth = 0
    private var selectedDay = 0
    private var selectedHour = 0
    private var selectedMinute = 0

    fun setOnConfirmListener(listener: (year: Int, month: Int, day: Int, hour: Int, minute: Int) -> Unit) {
        this.onConfirmListener = listener
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = DialogAutoModeNoticeBinding.inflate(layoutInflater)
        setContentView(binding.root)

        val window = window
        window?.let {
            val params = it.attributes
            params.gravity = Gravity.BOTTOM
            params.width = WindowManager.LayoutParams.MATCH_PARENT
            params.height = WindowManager.LayoutParams.WRAP_CONTENT
            it.attributes = params
            it.setBackgroundDrawableResource(R.drawable.round_bg)
        }

        val calendar = Calendar.getInstance()
        selectedYear = calendar.get(Calendar.YEAR)
        selectedMonth = calendar.get(Calendar.MONTH)
        selectedDay = calendar.get(Calendar.DAY_OF_MONTH)
        selectedHour = calendar.get(Calendar.HOUR_OF_DAY)
        selectedMinute = calendar.get(Calendar.MINUTE)

        updateDateDisplay()
        updateTimeDisplay()



        binding.btnConfirm.setOnClickListener {
            onConfirmListener?.invoke(selectedYear, selectedMonth, selectedDay, selectedHour, selectedMinute)
            dismiss()
        }
    }

    private fun updateDateDisplay() {

    }

    private fun updateTimeDisplay() {

    }
}