package com.example.defenseapplication.home

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.defenseapplication.adapter.MessageListAdapter
import com.example.defenseapplication.adapter.MessageListItem
import com.example.defenseapplication.databinding.MessageActivityBinding
import com.gyf.immersionbar.ImmersionBar
//消息通知页面
class MessageActivity : AppCompatActivity() {
    private lateinit var binding: MessageActivityBinding
    private val messageAdapter by lazy { MessageListAdapter() }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        binding = MessageActivityBinding.inflate(layoutInflater)
        setContentView(binding.root)
        ImmersionBar.with(this)
            .statusBarDarkFont(true)
            .titleBar(binding.topBar)
            .init()
        ViewCompat.setOnApplyWindowInsetsListener(binding.main) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
        initView()
    }

    private fun initView() {
        binding.ivBack.setOnClickListener { finish() }
        binding.rvMessageList.layoutManager = LinearLayoutManager(this)
        binding.rvMessageList.adapter = messageAdapter
        messageAdapter.submitList(buildMockData())
    }

    private fun buildMockData(): List<MessageListItem> {
        return listOf(
            MessageListItem.Header("今天"),
            MessageListItem.Message(
                time = "15:54",
                title = "有人入侵",
                dateTime = "2026-05-06 15:54:25",
                unread = true
            ),
            MessageListItem.Message(
                time = "12:54",
                title = "有人入侵",
                dateTime = "2026-05-06 15:54:25",
                unread = true
            ),
            MessageListItem.Message(
                time = "11:54",
                title = "有人入侵",
                dateTime = "2026-05-06 15:54:25",
                unread = true
            ),
            MessageListItem.Header("05-05"),
            MessageListItem.Message(
                time = "15:54",
                title = "设备故障",
                dateTime = "2026-05-06 15:54:25",
                unread = false
            ),
            MessageListItem.Message(
                time = "08:07",
                title = "设备离线",
                dateTime = "2026-05-06 15:54:25",
                unread = false
            ),
            MessageListItem.Message(
                time = "08:07",
                title = "到期提醒",
                dateTime = "2026-05-06 15:54:25",
                unread = false
            ),
            MessageListItem.Message(
                time = "11:54",
                title = "有人入侵",
                dateTime = "2026-05-06 15:54:25",
                unread = false
            ),
            MessageListItem.Message(
                time = "11:54",
                title = "有人入侵",
                dateTime = "2026-05-06 15:54:25",
                unread = false
            )
        )
    }
}