package com.example.doctor.Patients.Reports

import android.annotation.SuppressLint
import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.example.doctor.R
import com.example.doctor.databinding.ItemQbaBinding


class QBBAdapter() : ListAdapter<QBAModel, QBBAdapter.Holder>(Comparator()) {
    class Holder(view: View) :
        RecyclerView.ViewHolder(view) {

        val binding = ItemQbaBinding.bind(view)


        @SuppressLint("SuspiciousIndentation")
        fun bind(item: QBAModel) = with(binding) {
//            if (item.one == 1) {
//                txtB1.text = "Да"
//            } else {
//                txtB1.text = "Нет"
//            }

            txtDate.text = item.date
            if(item.oneb >= 6){
                txtStatusB.text = "Плохо"
                CVB.setCardBackgroundColor(Color.parseColor("#DA8383"))
            }

            else if(item.fourb == 1 || item.fiveb == 1 ||item.sixb == 1 ||item.sevenb == 1 ||item.nineb == 1){
                txtStatusB.text = "Средне"
                CVB.setCardBackgroundColor(Color.parseColor("#DABA83"))
            }
            else{
                txtStatusB.text = "Хорошо"
                CVB.setCardBackgroundColor(Color.parseColor("#ABDA83"))
            }

            if(item.ninea == 1){
                txtStatusA.text = "Плохо"
                CVA.setCardBackgroundColor(Color.parseColor("#DA8383"))
            }
            else if(item.onea >= 6 || item.threea == 1 ||item.sixa == 1 ||item.eighta == 1 ||item.elevena == 1){
                txtStatusA.text = "Средне"
                CVA.setCardBackgroundColor(Color.parseColor("#DABA83"))
            }
            else{
                txtStatusA.text= "Хорошо"
                CVA.setCardBackgroundColor(Color.parseColor("#ABDA83"))
            }

            txtB1.text = item.oneb.toString()
            if(item.oneb==0){
                CLQB1.setBackgroundColor(Color.parseColor("#C686DF8F"))
            }
            else if(item.oneb in 1..5){
                CLQB1.setBackgroundColor(Color.parseColor("#C6DFD386"))
            }
            else{
                CLQB1.setBackgroundColor(Color.parseColor("#C6DF8686"))
            }

            //Красный - "#C6DF8686"
            //Зеленый - "#C686DF8F"
            //Желтый - "#C6DFD386"
            if (item.twob == 1) {
                txtB2.text = "Да"
                CLQB2.setBackgroundColor(Color.parseColor("#C6DF8686"))
            } else {
                txtB2.text = "Нет"
                CLQB2.setBackgroundColor(Color.parseColor("#C686DF8F"))
            }

            if (item.threeb == 1) {
                txtB3.text = "Да"
                CLQB3.setBackgroundColor(Color.parseColor("#C6DF8686"))
            } else {
                txtB3.text = "Нет"
                CLQB3.setBackgroundColor(Color.parseColor("#C686DF8F"))
            }

            if (item.fourb == 1) {
                txtB4.text = "Да"
                CLQB4.setBackgroundColor(Color.parseColor("#C6DF8686"))
            } else {
                txtB4.text = "Нет"
                CLQB4.setBackgroundColor(Color.parseColor("#C686DF8F"))
            }

            if (item.fiveb == 1) {
                txtB5.text = "Да"
                CLQB5.setBackgroundColor(Color.parseColor("#C6DF8686"))
            } else {
                txtB5.text = "Нет"
                CLQB5.setBackgroundColor(Color.parseColor("#C686DF8F"))
            }

            if (item.sixb == 1) {
                txtB6.text = "Да"
                CLQB6.setBackgroundColor(Color.parseColor("#C6DF8686"))
            } else {
                txtB6.text = "Нет"
                CLQB6.setBackgroundColor(Color.parseColor("#C686DF8F"))
            }

            if (item.sevenb == 1) {
                txtB7.text = "Да"
                CLQB7.setBackgroundColor(Color.parseColor("#C6DF8686"))
            } else {
                txtB7.text = "Нет"
                CLQB7.setBackgroundColor(Color.parseColor("#C686DF8F"))
            }

            if (item.eightb == 1) {
                txtB8.text = "Да"
                CLQB8.setBackgroundColor(Color.parseColor("#C6DF8686"))
            } else {
                txtB8.text = "Нет"
                CLQB8.setBackgroundColor(Color.parseColor("#C686DF8F"))
            }

            if (item.nineb == 1) {
                txtB9.text = "Да"
                CLQB9.setBackgroundColor(Color.parseColor("#C6DF8686"))
            } else {
                txtB9.text = "Нет"
                CLQB9.setBackgroundColor(Color.parseColor("#C686DF8F"))
            }


            txtA1.text = item.onea.toString()
            if(item.onea==0){
                CLQA1.setBackgroundColor(Color.parseColor("#C686DF8F"))
            }
            else if(item.onea in 1..5){
                CLQA1.setBackgroundColor(Color.parseColor("#C6DFD386"))
            }
            else{
                CLQA1.setBackgroundColor(Color.parseColor("#C6DF8686"))
            }

            if (item.twoa == 1) {
                txtA2.text = "Да"
                CLQA2.setBackgroundColor(Color.parseColor("#C6DF8686"))
            } else {
                txtA2.text = "Нет"
                CLQA2.setBackgroundColor(Color.parseColor("#C686DF8F"))
            }

            if (item.threea == 1) {
                txtA3.text = "Да"
                CLQA3.setBackgroundColor(Color.parseColor("#C6DF8686"))
            } else {
                txtA3.text = "Нет"
                CLQA3.setBackgroundColor(Color.parseColor("#C686DF8F"))
            }

            if (item.foura == 1) {
                txtA4.text = "Да"
                CLQA4.setBackgroundColor(Color.parseColor("#C6DF8686"))
            } else {
                txtA4.text = "Нет"
                CLQA4.setBackgroundColor(Color.parseColor("#C686DF8F"))
            }

            if (item.fivea == 1) {
                txtA5.text = "Да"
                CLQA5.setBackgroundColor(Color.parseColor("#C6DF8686"))
            } else {
                txtA5.text = "Нет"
                CLQA5.setBackgroundColor(Color.parseColor("#C686DF8F"))
            }

            if (item.sixa == 1) {
                txtA6.text = "Да"
                CLQA6.setBackgroundColor(Color.parseColor("#C6DF8686"))

            } else {
                txtA6.text = "Нет"
                CLQA6.setBackgroundColor(Color.parseColor("#C686DF8F"))
            }

            if (item.sevena == 1) {
                txtA7.text = "Да"
                CLQA7.setBackgroundColor(Color.parseColor("#C6DF8686"))
            } else {
                txtA7.text = "Нет"
                CLQA7.setBackgroundColor(Color.parseColor("#C686DF8F"))
            }

            if (item.eighta == 1) {
                txtA8.text = "Да"
                CLQA8.setBackgroundColor(Color.parseColor("#C6DF8686"))
            } else {
                txtA8.text = "Нет"
                CLQA8.setBackgroundColor(Color.parseColor("#C686DF8F"))
            }

            if (item.ninea == 1) {
                txtA9.text = "Да"
                CLQA9.setBackgroundColor(Color.parseColor("#C6DF8686"))

            } else {
                txtA9.text = "Нет"
                CLQA9.setBackgroundColor(Color.parseColor("#C686DF8F"))
            }

            if (item.tena == 1) {
                txtA10.text = "Да"
                CLQA10.setBackgroundColor(Color.parseColor("#C6DF8686"))
            } else {
                txtA10.text = "Нет"
                CLQA10.setBackgroundColor(Color.parseColor("#C686DF8F"))
            }

            if (item.elevena == 1) {
                txtA11.text = "Да"
                CLQA11.setBackgroundColor(Color.parseColor("#C6DF8686"))
            } else {
                txtA11.text = "Нет"
                CLQA11.setBackgroundColor(Color.parseColor("#C686DF8F"))
            }

            if (item.twelvea == 1) {
                txtA12.text = "Да"
                CLQA12.setBackgroundColor(Color.parseColor("#C6DF8686"))
            } else {
                txtA12.text = "Нет"
                CLQA12.setBackgroundColor(Color.parseColor("#C686DF8F"))
            }
        }
    }


    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.item_qba, parent, false)
        return Holder(view)
    }

    override fun onBindViewHolder(holder: Holder, position: Int) {
        val view = holder.bind(getItem(position))
    }

    class Comparator : DiffUtil.ItemCallback<QBAModel>() {
        override fun areItemsTheSame(oldItem: QBAModel, newItem: QBAModel): Boolean {
            return oldItem.id == newItem.id
        }

        override fun areContentsTheSame(oldItem: QBAModel, newItem: QBAModel): Boolean {
            return oldItem == newItem
        }
    }



}




