package com.cooleshow.student.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.module.BaseLoadMoreModule;
import com.chad.library.adapter.base.module.LoadMoreModule;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.cooleshow.base.utils.GlideUtils;
import com.cooleshow.base.utils.UiUtils;
import com.cooleshow.student.R;
import com.cooleshow.student.bean.PracticeCourseListBean;
import com.cooleshow.student.constants.CourseConstants;

/**
 * 创建日期：2022/5/30 10:41
 *
 * @author Ryan
 * 类说明：
 */
public class PracticeCourseListAdapter extends BaseQuickAdapter<PracticeCourseListBean.RowsBean, BaseViewHolder> implements LoadMoreModule {

    public PracticeCourseListAdapter(int layoutResId) {
        super(layoutResId);
        addChildClickViewIds(R.id.iv_go_chat);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder holder, PracticeCourseListBean.RowsBean data) {
        if (data == null) {
            return;
        }
        //时间
        holder.setText(R.id.tv_time, UiUtils.getCourseTimeString(data.startTime, data.endTime));
        //title
        holder.setText(R.id.tv_title, data.userName);
        //subjectName
        holder.setText(R.id.tv_course_name, data.subjectName);
        ImageView iv_avatar = holder.getView(R.id.iv_avatar);
        //头像
        GlideUtils.INSTANCE.loadImage(getContext(), data.avatar, iv_avatar, R.drawable.icon_teacher_default_head);

        TextView tvCourseStatusBt = holder.getView(R.id.tv_course_status_bt);
        TextView tv_course_status = holder.getView(R.id.tv_course_status);

        if (TextUtils.equals(CourseConstants.COURSE_STATUS_NOT_START, data.status)) {
            //未开始
            tv_course_status.setText("未开始");
            tv_course_status.setTextColor(getContext().getResources().getColor(com.cooleshow.base.R.color.color_ff802c));
            tvCourseStatusBt.setVisibility(View.GONE);
        }

        if (TextUtils.equals(CourseConstants.COURSE_STATUS_ING, data.status)) {
            //进行中
            tv_course_status.setText("进行中");
            tv_course_status.setTextColor(getContext().getResources().getColor(com.cooleshow.base.R.color.color_2dc7aa));
            tvCourseStatusBt.setText("进入教室");
            tvCourseStatusBt.setVisibility(View.GONE);
            tvCourseStatusBt.setBackgroundResource(R.drawable.shape_course_status_ing);
            tvCourseStatusBt.setTextColor(getContext().getResources().getColor(com.cooleshow.base.R.color.white));
        }

        if (TextUtils.equals(CourseConstants.COURSE_STATUS_COMPLETE, data.status)) {
            //已结束
            tv_course_status.setText("已结束");
            tv_course_status.setTextColor(getContext().getResources().getColor(com.cooleshow.base.R.color.color_999999));

            tvCourseStatusBt.setText("评价");
            tvCourseStatusBt.setVisibility(View.GONE);
            tvCourseStatusBt.setBackgroundResource(R.drawable.shape_course_status_normal);
            tvCourseStatusBt.setTextColor(getContext().getResources().getColor(com.cooleshow.base.R.color.color_2dc7aa));
        }
    }

    @NonNull
    @Override
    public BaseLoadMoreModule addLoadMoreModule(@NonNull BaseQuickAdapter<?, ?> baseQuickAdapter) {
        return new BaseLoadMoreModule(baseQuickAdapter);
    }
}
