package com.example.defenseapplication.liveVideo

import android.os.Bundle
import android.os.LocaleList
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.defenseapplication.R
import com.example.defenseapplication.adapter.AlarmLogAdapter
import com.example.defenseapplication.databinding.AlarmLogActivityBinding
import com.gyf.immersionbar.ImmersionBar
import com.google.android.material.datepicker.MaterialDatePicker
import java.util.*
//告警记录
class AlarmLogActivity : AppCompatActivity() {
    private lateinit var binding: AlarmLogActivityBinding
    private lateinit var calendar: Calendar
    private var adapter: AlarmLogAdapter? = null
    private val alarmList = mutableListOf<String>()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = AlarmLogActivityBinding.inflate(layoutInflater)
        setContentView(binding.root)
        ImmersionBar.with(this)
            .statusBarDarkFont(true)
            .titleBar(binding.topBar)
            .init()

        calendar = Calendar.getInstance()
        updateDateDisplay()
        initRecyclerView()
        loadAlarmList()
        initListener()
    }

    private fun initRecyclerView() {
        adapter = AlarmLogAdapter(alarmList)
        binding.alarmListRecyclerView.layoutManager = LinearLayoutManager(this)
        binding.alarmListRecyclerView.adapter = adapter
    }

    private fun loadAlarmList() {
        alarmList.clear()
        alarmList.add("入侵告警 - 10:30")
        alarmList.add("入侵告警 - 09:15")
        alarmList.add("入侵告警 - 08:45")
        alarmList.add("入侵告警 - 07:20")
        alarmList.add("入侵告警 - 06:50")
        adapter?.notifyDataSetChanged()
    }

    private fun updateDateDisplay() {
        val month = calendar.get(Calendar.MONTH) + 1
        val day = calendar.get(Calendar.DAY_OF_MONTH)
        binding.tvDate.text = "${month}月${day}日"
    }

    private fun initListener() {
        binding.btnBack.setOnClickListener {
            finish()
        }
        binding.expandImg.setOnClickListener {
            showDatePicker()
        }
    }

    private fun showDatePicker() {
        val datePicker = android.app.DatePickerDialog(
            this,
            { _, year, month, dayOfMonth ->
                calendar.set(year, month, dayOfMonth)
                updateDateDisplay()
                loadAlarmList()
            },
            calendar.get(Calendar.YEAR),
            calendar.get(Calendar.MONTH),
            calendar.get(Calendar.DAY_OF_MONTH)
        )
        datePicker.show()
    }
}
