package com.example.defenseapplication.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.example.defenseapplication.databinding.ItemAlarmLogBinding

class AlarmLogAdapter(private val items: List<String>) : RecyclerView.Adapter<AlarmLogAdapter.ViewHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val binding = ItemAlarmLogBinding.inflate(
            LayoutInflater.from(parent.context),
            parent,
            false
        )
        return ViewHolder(binding)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.bind(items[position])
    }

    override fun getItemCount(): Int = items.size

    class ViewHolder(private val binding: ItemAlarmLogBinding) : RecyclerView.ViewHolder(binding.root) {
        fun bind(item: String) {
            val parts = item.split(" - ")
            binding.tvTitle.text = parts.firstOrNull()
            binding.tvTime.text = parts.getOrNull(1)
        }
    }
}
