package com.lukouguoji.hangban.page.query.list

import android.view.View
import com.lukouguoji.hangban.databinding.ItemHbQueryListBinding
import com.lukouguoji.module_base.base.BaseViewHolder
import com.lukouguoji.module_base.bean.FlightBean

class HbQueryListViewHolder(view: View) :
    BaseViewHolder<FlightBean, ItemHbQueryListBinding>(view) {

    override fun onBind(item: Any?, position: Int) {
        val bean = getItemBean(item)!!
        binding.bean = bean

        val ctx = binding.root.context
        if (bean.beArrival()) {
            // 到达航班：所有文字显示橙色
            setTextColorRecursive(binding.ll, android.graphics.Color.parseColor("#FF8C00"))
        } else {
            // 非到达航班：使用 text_gray (#666666)
            setTextColorRecursive(binding.ll, ctx.getColor(com.lukouguoji.hangban.R.color.text_gray))
            binding.tvFnoValue.setTextColor(ctx.getColor(com.lukouguoji.hangban.R.color.colorPrimary))
            val redColor = ctx.getColor(com.lukouguoji.hangban.R.color.text_red)
            binding.tvEstTakeoffNext.setTextColor(redColor)
            binding.tvActualTakeoffNext.setTextColor(redColor)
            binding.tvEstArrivalNext.setTextColor(redColor)
            binding.tvActualArrivalNext.setTextColor(redColor)
        }

        notifyItemClick(position, binding.ll)
    }

    private fun setTextColorRecursive(view: View, color: Int) {
        if (view is android.widget.TextView) {
            view.setTextColor(color)
        } else if (view is android.view.ViewGroup) {
            for (i in 0 until view.childCount) {
                setTextColorRecursive(view.getChildAt(i), color)
            }
        }
    }

}
