package com.zj365.health.fragment

import android.graphics.drawable.GradientDrawable
import android.os.Build
import android.widget.TextView
import androidx.annotation.RequiresApi
import androidx.core.content.ContextCompat
import androidx.lifecycle.MutableLiveData
import com.xty.base.fragment.IBaseFrag
import com.xty.common.setOrganStatus
import com.zj365.health.weight.PopWindowUserInfo
import com.zj365.health.R
import com.zj365.health.databinding.FragWeekReportBinding
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

/**
 * 弃用
 */
class FragMonthReport  : IBaseFrag() {
    val popWindow by lazy{ PopWindowUserInfo() }
    val binding by lazy { FragWeekReportBinding.inflate(layoutInflater)}

    val heartIcon by lazy { arrayOf(
        R.mipmap.ic_heart_1,
        R.mipmap.ic_heart_2,
        R.mipmap.ic_heart_2,
        R.mipmap.ic_heart_4) }
    val liverIcon by lazy { arrayOf(
        R.mipmap.ic_liver_1,
        R.mipmap.ic_liver_2,
        R.mipmap.ic_liver_3,
        R.mipmap.ic_liver_4) }
    val spleenIcon by lazy { arrayOf(
        R.mipmap.ic_spleen_1,
        R.mipmap.ic_spleen_2,
        R.mipmap.ic_spleen_3,
        R.mipmap.ic_spleen_4) }
    val lungIcon by lazy { arrayOf(R.mipmap.ic_lung_1, R.mipmap.ic_lung_2, R.mipmap.ic_lung_3, R.mipmap.ic_lung_4) }
    val kidneyIcon by lazy { arrayOf(
        R.mipmap.ic_kidney_1,
        R.mipmap.ic_kidney_2,
        R.mipmap.ic_kidney_3,
        R.mipmap.ic_kidney_4) }
    val largeIcon by lazy { arrayOf(
        R.mipmap.ic_large_intestine_1 ,
        R.mipmap.ic_large_intestine_2,
        R.mipmap.ic_large_intestine_3,
        R.mipmap.ic_large_intestine_4) }
    val smallIcon by lazy { arrayOf(
        R.mipmap.ic_small_intestine_1 ,
        R.mipmap.ic_small_intestine_2,
        R.mipmap.ic_small_intestine_3,
        R.mipmap.ic_small_intestine_4) }
    val  stomachIcon by  lazy { arrayOf(
        R.mipmap.ic_stomach_1 ,
        R.mipmap.ic_stomach_2,
        R.mipmap.ic_stomach_3,
        R.mipmap.ic_stomach_4) }
    val  lymphIcon by lazy { arrayOf(
        R.mipmap.ic_lymph_1 ,
        R.mipmap.ic_lymph_2,
        R.mipmap.ic_lymph_3,
        R.mipmap.ic_lymph_4) }
    val  gallIcon by lazy { arrayOf(
        R.mipmap.ic_gallbladder_1 ,
        R.mipmap.ic_gallbladder_2,
        R.mipmap.ic_gallbladder_3,
        R.mipmap.ic_gallbladder_4) }
    val  bladderIcon by lazy { arrayOf(
        R.mipmap.ic_bladder_1 ,
        R.mipmap.ic_bladder_2,
        R.mipmap.ic_bladder_3,
        R.mipmap.ic_bladder_4) }
    val  pericardiumIcon by lazy { arrayOf(
        R.mipmap.ic_pericardium_1 ,
        R.mipmap.ic_pericardium_2,
        R.mipmap.ic_pericardium_3,
        R.mipmap.ic_pericardium_4) }


    val scrollLive by lazy{MutableLiveData<String>()}

    val statusStr by lazy{resources.getStringArray(R.array.status_array)}
    override fun setLayout()=binding.root

    @RequiresApi(Build.VERSION_CODES.M)
    override fun initView() {
        super.initView()
        popWindow.myPopWindow(requireContext(), R.layout.popwindow_my)
        changeTopShape(R.color.col_e0b,binding.status2)
        changeTopShape(R.color.col_ea7,binding.status3)
        changeTopShape(R.color.col_c3d,binding.status4)

        scrollLive.observe(this){
            binding.mScroll.scrollBy(0,   binding.mScroll.height)
        }

        binding.mScroll.setOnScrollChangeListener { v, scrollX, scrollY, oldScrollX, oldScrollY ->
            mainScope.launch {
                delay(10000)
                scrollLive.postValue("")

            }

        }
        setStatus()
//        binding.analysis.text=String.format(getString(R.string.analysis_info),"23","23","23","23","23","23","23")
    }



    fun setStatus(){
        binding.child.mHeart.setOrganStatus(requireContext(),0,heartIcon){
          //  popWindow.showAction(it)
        }
        binding.child.mStomach.setOrganStatus(requireContext(),2,stomachIcon){
         // popWindow.showAction(it)
        }
        binding.child.mLung.setOrganStatus(requireContext(),3,lungIcon){
           // popWindow.showAction(it)
        }
        binding.child.mKidney.setOrganStatus(requireContext(),0,kidneyIcon){
           //popWindow.showAction(it)
        }
        binding.child.mLiver.setOrganStatus(requireContext(),2,liverIcon){
            //popWindow.showAction(it)
        }
        binding.child.mSpleen.setOrganStatus(requireContext(),0,spleenIcon){
           // popWindow.showAction(it)
        }
        binding.child.mLarge.setOrganStatus(requireContext(),2,largeIcon){
            //popWindow.showAction(it)
        }
        binding.child.mSmall.setOrganStatus(requireContext(),1,smallIcon){
           // popWindow.showAction(it)
        }
        binding.child.mLymph.setOrganStatus(requireContext(),3,lymphIcon){
            //popWindow.showAction(it)
        }
        binding.child.mGallbladder.setOrganStatus(requireContext(),1,gallIcon){
            //popWindow.showAction(it)
        }
        binding.child.mBladder.setOrganStatus(requireContext(),1,bladderIcon){
            //popWindow.showAction(it)
        }
        binding.child.mPericardium.setOrganStatus(requireContext(),2,pericardiumIcon){
            //popWindow.showAction(it)
        }
    }



    fun changeTopShape(color:Int,textView: TextView){
        val drawable = ContextCompat.getDrawable(requireContext(), R.drawable.shape_status)
        val gradientDrawable = drawable as GradientDrawable
        gradientDrawable.setColor(ContextCompat.getColor(requireContext(), color))
        drawable.mutate()
        drawable.setBounds(0,0,drawable.minimumWidth,drawable.minimumHeight)
        textView.setCompoundDrawables(null,drawable,null,null)
    }

}