package com.cooleshow.teacher.adapter

import android.annotation.SuppressLint
import android.text.TextUtils
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.cooleshow.base.ext.setVisible
import com.cooleshow.base.utils.GlideUtils
import com.cooleshow.base.utils.UiUtils
import com.cooleshow.teacher.R
import com.cooleshow.teacher.bean.CourseTableDataBean

/**
 * Author by pq, Date on 2022/4/21.
 */
class CourseTableListAdapter(layoutResId: Int) :
    BaseQuickAdapter<CourseTableDataBean.StudentListBean?, BaseViewHolder>(layoutResId) {
    companion object {
        const val LIVE_COURSE = "LIVE"//直播课
        const val OTHER_COURSE = "PRACTICE"//陪练课
        const val PIANO_ROOM_COURSE = "PIANO_ROOM_CLASS"//琴房课
        const val NOT_START = "NOT_START"
        const val ING = "ING"
        const val COMPLETE = "COMPLETE"
        const val CANCEL = "CANCEL"
    }

    init {
        addChildClickViewIds(R.id.tv_course_status_bt)
        addChildClickViewIds(R.id.iv_go_chat)
    }

    @SuppressLint("ResourceAsColor")
    override fun convert(
        baseViewHolder: BaseViewHolder,
        data: CourseTableDataBean.StudentListBean?
    ) {
        val tvTime = baseViewHolder.getView<TextView>(R.id.tv_time)
        val ivAvatar = baseViewHolder.getView<ImageView>(R.id.iv_avatar)
        val viewLine2 = baseViewHolder.getView<View>(R.id.view_line2)
        val tvBuyNum = baseViewHolder.getView<TextView>(R.id.tv_buy_num)
        val tvCourseStatusBt = baseViewHolder.getView<TextView>(R.id.tv_course_status_bt)
        //开始时间
        tvTime.text = UiUtils.getCourseTimeString(data?.startTime,data?.endTime);
        //title
        baseViewHolder.setText(R.id.tv_title, data?.name);
        //subjectName
        baseViewHolder.setText(R.id.tv_course_name, data?.subjectName);
        if (TextUtils.equals(OTHER_COURSE, data?.courseType)) {
            //陪练课
            GlideUtils.loadImage(
                context,
                data!!.cover,
                ivAvatar,
                R.drawable.icon_teacher_default_head
            )
            viewLine2.setVisible(false)
            tvBuyNum.setVisible(false)
        } else if (TextUtils.equals(PIANO_ROOM_COURSE, data?.courseType)) {
            //琴房课
            ivAvatar.setImageResource(R.drawable.icon_piano_room_course)
            tvBuyNum.text = data?.payCount + "人"
            viewLine2.setVisible(true)
            tvBuyNum.setVisible(true)
        } else {
            //直播课
            ivAvatar.setImageResource(R.drawable.icon_live_bg)
            var payCount = data?.payCount
            //已购人数
            tvBuyNum.text = context.getString(R.string.pay_count_str, payCount)
            viewLine2.setVisible(true)
            tvBuyNum.setVisible(true)
        }
        when (data?.status) {
            NOT_START -> {
                //未开始
                if (TextUtils.equals(OTHER_COURSE, data?.courseType)) {
                    tvCourseStatusBt.setVisible(true)
                } else {
                    //直播课隐藏
                    tvCourseStatusBt.setVisible(false)
                }
                baseViewHolder.setText(R.id.tv_course_status, "未开始")
                baseViewHolder.setTextColor(R.id.tv_course_status, context.resources.getColor(com.cooleshow.base.R.color.color_ff802c))
                tvCourseStatusBt.text = "调课"
                tvCourseStatusBt.setBackgroundResource(R.drawable.shape_course_status_normal);
                tvCourseStatusBt.setTextColor(context.resources.getColor(com.cooleshow.base.R.color.color_2dc7aa))
            }
            ING -> {
                //进行中
                tvCourseStatusBt.setVisible(true)
                tvCourseStatusBt.text = "进入教室"
                baseViewHolder.setText(R.id.tv_course_status, "进行中")
                baseViewHolder.setTextColor(R.id.tv_course_status, context.resources.getColor(com.cooleshow.base.R.color.color_2dc7aa))
                tvCourseStatusBt.setBackgroundResource(R.drawable.shape_course_status_ing);
                tvCourseStatusBt.setTextColor(context.resources.getColor(R.color.white))

            }
            COMPLETE -> {
                //已完成
                if (TextUtils.equals(OTHER_COURSE, data?.courseType)) {
                    tvCourseStatusBt.setVisible(true)
                } else {
                    //直播课隐藏
                    tvCourseStatusBt.setVisible(false)
                }
                if (data?.teacherReplied == 0) {
                    tvCourseStatusBt.text = "评价"
                } else {
                    tvCourseStatusBt.text = "已评价"
                }
                baseViewHolder.setText(R.id.tv_course_status, "已结束")
                baseViewHolder.setTextColor(R.id.tv_course_status, context.resources.getColor(com.cooleshow.base.R.color.color_999999))
                tvCourseStatusBt.setBackgroundResource(R.drawable.shape_course_status_normal);
                tvCourseStatusBt.setTextColor(context.resources.getColor(com.cooleshow.base.R.color.color_2dc7aa))
            }
        }
    }
}