package com.zj365.health.adapter

import android.os.Handler
import android.widget.TextView
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.xty.base.adapter.BaseAdapter
import com.zj365.health.R
import com.xty.network.model.CancerGoodsBean


class TongueRecordAdapter: BaseAdapter<CancerGoodsBean>(R.layout.item_tongue_record) {
    override fun convert(holder: BaseViewHolder, item: CancerGoodsBean) {

        var view = holder.getView<RecyclerView>(R.id.rvRecyclerview)
        view.layoutManager = GridLayoutManager(context,4)
        var adapter = PictureShowAdapter()
        view.adapter = adapter
        var images = mutableListOf<String>()
        item.imageUrl?.let { images.add(it) }
        item.backImageUrl?.let { images.add(it) }
        if (!view.isComputingLayout){
            Handler().post {
                adapter.setNewInstance(images)
            }
        }
        if (item.status == 1){
            //未完成上传流程
            holder.setGone(R.id.llUploadSuccess,true)
            holder.setGone(R.id.llUpload,false)
            holder.setText(R.id.tvPurchase,item.payTime)
        } else {
            holder.setText(R.id.tvTime,item.uploadTime)
            // 已完成上传流程
            holder.setGone(R.id.llUploadSuccess,false)
            holder.setGone(R.id.llUpload,true)
            holder.setText(R.id.tvEstimateStatus,getStatusText(item.status)).setTextColor(R.id.tvEstimateStatus,getStatusColor(item.status))
            var helper = holder.getView<TextView>(R.id.tvEstimateStatus)
            if (item.status == 3 || item.status == 5) {
                helper.setBackgroundResource(R.drawable.shape_r12_stroke_02c)
            } else {
                helper.setBackgroundResource(0)
            }
        }

    }

    private fun getStatusText(paystatus:Int?): String {
        var result = "识别中"
        when(paystatus){
            0 -> result="未支付"
            1 -> result="已支付"
            2 -> result="审核失败"
            3 -> result="去问诊"
            4 -> result="预判中"
            5 -> result="查看报告"
            6 -> result="失败"
        }
        return result
    }

    private fun getStatusColor(status:Int?): Int {
        var color = 0
        when(status){
            0 -> color = context.resources.getColor(R.color.col_96D)
            1 -> color = context.resources.getColor(R.color.col_96D)
            2 -> color = context.resources.getColor(R.color.col_2628)
            3 -> color = context.resources.getColor(R.color.col_02c)
            4 -> color = context.resources.getColor(R.color.col_96D)
            5 -> color = context.resources.getColor(R.color.col_02c)
            4 -> color = context.resources.getColor(R.color.col_2628)
        }
        return color
    }
}