package com.example.defenseapplication.liveVideo

import TimePickerFragment
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.example.defenseapplication.databinding.AutoModeActivityBinding
import com.example.defenseapplication.view.AutoModeNoticeDialog
import com.gyf.immersionbar.ImmersionBar
import java.util.Calendar
//自动模式
class AutoModeActivity : AppCompatActivity() {

    private lateinit var binding: AutoModeActivityBinding
    private lateinit var calendar: Calendar
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = AutoModeActivityBinding.inflate(layoutInflater)
        setContentView(binding.root)

        ImmersionBar.with(this)
            .statusBarDarkFont(true)
            .titleBar(binding.topBar)
            .init()

        initListener()

        showAutoModeNoticeDialog()
    }

    private fun initListener() {
        binding.ivBack.setOnClickListener {
            finish()
        }

        binding.rbAutoMode.setOnClickListener {
            binding.rbSemiAutoMode.isChecked = false
            showAutoModeNoticeDialog()
        }

        binding.rbSemiAutoMode.setOnClickListener {
            binding.rbAutoMode.isChecked = false
        }
        // 起始时间选择
        binding.itemStartTime.setOnClickListener {
            showTimePicker { hour, minute ->
                val startTimeStr = String.format("%02d:%02d", hour, minute)
                binding.tvStartTime.text = startTimeStr
            }
        }
        // 结束时间选择
        binding.itemEndTime.setOnClickListener {
            showTimePicker { hour, minute ->
                val endTimeStr = String.format("%02d:%02d", hour, minute)
                binding.tvEndTime.text = endTimeStr
            }
        }
    }
    /**
     * 显示时间选择器对话框
     * @param onTimeSelected 时间选择回调，参数为小时和分钟
     */
    private fun showTimePicker(onTimeSelected: (hour: Int, minute: Int) -> Unit) {
        val timePickerFragment = TimePickerFragment { hour, minute ->
            onTimeSelected(hour, minute)
        }
        timePickerFragment.show(supportFragmentManager, "timePicker")
    }
    private fun showAutoModeNoticeDialog() {
        val dialog = AutoModeNoticeDialog(this)
        dialog.setOnConfirmListener {
        }
        dialog.show()
    }
}
