package xn.hxp.ui.adapter

import android.view.View
import android.widget.LinearLayout
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import xn.hxp.R
import com.blankj.utilcode.util.LogUtils
import com.rc.httpcore.bean.RuleBean

class CabinetAdapter : BaseQuickAdapter<RuleBean, BaseViewHolder>(R.layout.item_cabinet_view) {

    init {
        addChildClickViewIds(R.id.lingOne)
        addChildClickViewIds(R.id.lintTwo)
        addChildClickViewIds(R.id.lintThree)
        addChildClickViewIds(R.id.lintFour)
        addChildClickViewIds(R.id.imgViews)
    }

    override fun convert(holder: BaseViewHolder, item: RuleBean) {
        holder.setText(R.id.cabinetName, "${item.cabinetName}")
        //柜子信息
        val cabinetDoorVoList = item.cabinetDoorVoList
        //lingOne(num)  lintTwo   lintThree    lintFour      cabinetDoorVoList根据长度  判断当前需要显示几个门  最多显示4个

        when (cabinetDoorVoList.size) {  //当前每一个柜门
            1 -> {
                holder.getView<LinearLayout>(R.id.lingOne).visibility = View.VISIBLE
                holder.getView<LinearLayout>(R.id.lintTwo).visibility = View.GONE
                holder.setText(R.id.doorNameOne, "${cabinetDoorVoList[0].doorName}")
                holder.setText(R.id.num, "${cabinetDoorVoList[0].stockNum}")
                val size = cabinetDoorVoList[0].cabinetAdminVoList!!.size  //管理员信息
                if (size <= 2) {
                    if (size == 1) {
                        val userName = cabinetDoorVoList[0].cabinetAdminVoList!![0].userName
                        holder.setText(R.id.teacher1, userName)
                    } else if (size == 2) {
                        holder.setText(
                            R.id.teacher1,
                            cabinetDoorVoList[0].cabinetAdminVoList!![0].userName
                        )
                        holder.setText(
                            R.id.teacher2,
                            cabinetDoorVoList[0].cabinetAdminVoList!![1].userName
                        )
                    }
                } else {
                    holder.setText(
                        R.id.teacher1,
                        cabinetDoorVoList[0].cabinetAdminVoList!![0].userName
                    )
                    holder.setText(
                        R.id.teacher2,
                        cabinetDoorVoList[0].cabinetAdminVoList!![1].userName
                    )
                }
            }

            2 -> {
                holder.getView<LinearLayout>(R.id.lingOne).visibility = View.VISIBLE
                holder.setText(R.id.doorNameOne, "${cabinetDoorVoList[0].doorName}")
                holder.setText(R.id.num, "${cabinetDoorVoList[0].stockNum}")
                val size = cabinetDoorVoList[0].cabinetAdminVoList!!.size  //管理员信息
                if (size <= 2) {
                    if (size == 1) {
                        val userName = cabinetDoorVoList[0].cabinetAdminVoList!![0].userName
                        holder.setText(R.id.teacher1, userName)
                    } else if (size == 2) {
                        holder.setText(
                            R.id.teacher1,
                            cabinetDoorVoList[0].cabinetAdminVoList!![0].userName
                        )
                        holder.setText(
                            R.id.teacher2,
                            cabinetDoorVoList[0].cabinetAdminVoList!![1].userName
                        )
                    }
                } else {
                    holder.setText(
                        R.id.teacher1,
                        cabinetDoorVoList[0].cabinetAdminVoList!![0].userName
                    )
                    holder.setText(
                        R.id.teacher2,
                        cabinetDoorVoList[0].cabinetAdminVoList!![1].userName
                    )
                }


                holder.getView<LinearLayout>(R.id.lintTwo).visibility = View.VISIBLE
                holder.setText(R.id.doorNameTwo, "${cabinetDoorVoList[1].doorName}")
                holder.setText(R.id.numTow, "${cabinetDoorVoList[1].stockNum}")
                val size1 = cabinetDoorVoList[1].cabinetAdminVoList!!.size  //管理员信息
                if (size1 <= 2) {
                    if (size1 == 1) {
                        val userName = cabinetDoorVoList[1].cabinetAdminVoList!![0].userName
                        holder.setText(R.id.teacher3, userName)
                    } else if (size1 == 2) {
                        holder.setText(
                            R.id.teacher3,
                            cabinetDoorVoList[1].cabinetAdminVoList!![0].userName
                        )
                        holder.setText(
                            R.id.teacher4,
                            cabinetDoorVoList[1].cabinetAdminVoList!![1].userName
                        )
                    }
                } else {
                    holder.setText(
                        R.id.teacher3,
                        cabinetDoorVoList[1].cabinetAdminVoList!![0].userName
                    )
                    holder.setText(
                        R.id.teacher4,
                        cabinetDoorVoList[1].cabinetAdminVoList!![1].userName
                    )
                }
            }

            else -> {
                holder.getView<LinearLayout>(R.id.lingOne).visibility = View.VISIBLE
                holder.setText(R.id.doorNameOne, "${cabinetDoorVoList[0].doorName}")
                holder.setText(R.id.num, "${cabinetDoorVoList[0].stockNum}")
                val size = cabinetDoorVoList[0].cabinetAdminVoList!!.size  //管理员信息
                if (size <= 2) {
                    if (size == 1) {
                        val userName = cabinetDoorVoList[0].cabinetAdminVoList!![0].userName
                        holder.setText(R.id.teacher1, userName)
                    } else if (size == 2) {
                        holder.setText(
                            R.id.teacher1,
                            cabinetDoorVoList[0].cabinetAdminVoList!![0].userName
                        )
                        holder.setText(
                            R.id.teacher2,
                            cabinetDoorVoList[0].cabinetAdminVoList!![1].userName
                        )
                    }
                } else {
                    holder.setText(
                        R.id.teacher1,
                        cabinetDoorVoList[0].cabinetAdminVoList!![0].userName
                    )
                    holder.setText(
                        R.id.teacher2,
                        cabinetDoorVoList[0].cabinetAdminVoList!![1].userName
                    )
                }


                holder.getView<LinearLayout>(R.id.lintTwo).visibility = View.VISIBLE
                holder.setText(R.id.doorNameTwo, "${cabinetDoorVoList[1].doorName}")
                holder.setText(R.id.numTow, "${cabinetDoorVoList[1].stockNum}")
                val size1 = cabinetDoorVoList[1].cabinetAdminVoList!!.size  //管理员信息
                if (size1 <= 2) {
                    if (size1 == 1) {
                        val userName = cabinetDoorVoList[1].cabinetAdminVoList!![0].userName
                        holder.setText(R.id.teacher3, userName)
                    } else if (size1 == 2) {
                        holder.setText(
                            R.id.teacher3,
                            cabinetDoorVoList[1].cabinetAdminVoList!![0].userName
                        )
                        holder.setText(
                            R.id.teacher4,
                            cabinetDoorVoList[1].cabinetAdminVoList!![1].userName
                        )
                    }
                } else {
                    holder.setText(
                        R.id.teacher3,
                        cabinetDoorVoList[1].cabinetAdminVoList!![0].userName
                    )
                    holder.setText(
                        R.id.teacher4,
                        cabinetDoorVoList[1].cabinetAdminVoList!![1].userName
                    )
                }

                holder.getView<LinearLayout>(R.id.lintThree).visibility = View.VISIBLE
                holder.setText(R.id.doorNameThree, "${cabinetDoorVoList[2].doorName}")
                holder.setText(R.id.numThree, "${cabinetDoorVoList[2].stockNum}")
                val size2 = cabinetDoorVoList[2].cabinetAdminVoList!!.size  //管理员信息
                if (size2 <= 2) {
                    if (size2 == 1) {
                        val userName = cabinetDoorVoList[2].cabinetAdminVoList!![0].userName
                        holder.setText(R.id.teacher5, userName)
                    } else if (size2 == 2) {
                        holder.setText(
                            R.id.teacher5,
                            cabinetDoorVoList[2].cabinetAdminVoList!![0].userName
                        )
                        holder.setText(
                            R.id.teacher6,
                            cabinetDoorVoList[2].cabinetAdminVoList!![1].userName
                        )
                    }
                } else {
                    holder.setText(
                        R.id.teacher5,
                        cabinetDoorVoList[2].cabinetAdminVoList!![0].userName
                    )
                    holder.setText(
                        R.id.teacher6,
                        cabinetDoorVoList[2].cabinetAdminVoList!![1].userName
                    )
                }


                holder.getView<LinearLayout>(R.id.lintFour).visibility = View.VISIBLE
                holder.setText(R.id.four, "${cabinetDoorVoList[3].doorName}")
                holder.setText(R.id.numFour, "${cabinetDoorVoList[3].stockNum}")
                val size3 = cabinetDoorVoList[3].cabinetAdminVoList!!.size  //管理员信息
                if (size3 <= 2) {
                    if (size3 == 1) {
                        val userName = cabinetDoorVoList[3].cabinetAdminVoList!![0].userName
                        holder.setText(R.id.teacher7, userName)
                    } else if (size3 == 2) {
                        holder.setText(
                            R.id.teacher7,
                            cabinetDoorVoList[3].cabinetAdminVoList!![0].userName
                        )
                        holder.setText(
                            R.id.teacher8,
                            cabinetDoorVoList[3].cabinetAdminVoList!![1].userName
                        )
                    }
                } else {
                    holder.setText(
                        R.id.teacher7,
                        cabinetDoorVoList[3].cabinetAdminVoList!![0].userName
                    )
                    holder.setText(
                        R.id.teacher8,
                        cabinetDoorVoList[3].cabinetAdminVoList!![1].userName
                    )
                }

            }
        }

    }


}