package com.sixin.module_p.ui.gnj.accidentVisa.add

import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import android.view.ViewGroup
import android.widget.EditText
import com.lukouguoji.module_base.common.Constant
import com.lukouguoji.module_base.common.DetailsPageType
import com.lukouguoji.module_base.ktx.addOnItemClickListener
import com.sixin.module_p.R
import com.sixin.module_p.base.BasePdaActivity
import com.sixin.module_p.databinding.ActivityAccidentVisaAddBinding


class PdaAccidentVisaAddActivity :
    BasePdaActivity<ActivityAccidentVisaAddBinding, PdaAccidentVisaAddViewModel>() {
    override fun layoutId(): Int {
        return R.layout.activity_accident_visa_add
    }

    override fun viewModelClass(): Class<PdaAccidentVisaAddViewModel> {
        return PdaAccidentVisaAddViewModel::class.java
    }

    override fun initOnCreate(savedInstanceState: Bundle?) {
        viewModel.rv = binding.rv
        viewModel.initOnCreate(intent)

        setBackArrow("国内事故签证${viewModel.pageType.value!!.title}")

        binding.viewModel = viewModel
        binding.rv.addOnItemClickListener(viewModel)

        // 调用方法修改所有 EditText 的背景色
        if(viewModel.pageType.value == DetailsPageType.Add){
            println("--------------调用方法修改所有 EditText 的背景色")
            var large = findViewById<ViewGroup>(R.id.largeView)
            large.setBackgroundColor(Color.parseColor("#F2F0EA"))

            var group = findViewById<ViewGroup>(R.id.addVisa)
            changeEditTextBackgroundColor(group, Color.parseColor("#F2F0EA")) // 设置为白色   灰色 #F2F0EA
//            group.setBackgroundColor(Color.parseColor("#FFFFFFFF"))
        }


    }
    private fun changeEditTextBackgroundColor(group: ViewGroup, color: Int) {
        group.setBackgroundColor(color)
        for (i in 0 until group.childCount) {
            val view = group.getChildAt(i)
            if (view is EditText) {
                view.setBackgroundColor(Color.parseColor("#FFFFFFFF")) // 修改背景色
            } else if (view is ViewGroup) {
                changeEditTextBackgroundColor(view, color) // 递归处理子视图
            }
        }
    }
    companion object {
        @JvmStatic
        fun start(context: Context, id: String = "", editable: Boolean = id.isEmpty()) {
            val starter = Intent(context, PdaAccidentVisaAddActivity::class.java)
                .putExtra(Constant.Key.ID, id)
                .putExtra(Constant.Key.DATA, editable)
            context.startActivity(starter)
        }
    }

}