package com.cooleshow.teacher.adapter;

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

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.teacher.R;
import com.cooleshow.teacher.bean.LiveCourseListBean;
import com.cooleshow.teacher.constants.CourseConstants;
import com.cooleshow.usercenter.helper.UserHelper;

import androidx.annotation.NonNull;

/**
 * Author by pq, Date on 2022/4/25.
 */
public class LiveCourseListAdapter extends BaseQuickAdapter<LiveCourseListBean.RowsBean, BaseViewHolder> implements LoadMoreModule {

    public LiveCourseListAdapter() {
        super(R.layout.item_live_course_list_layout);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder holder, LiveCourseListBean.RowsBean data) {
        //时间
        holder.setText(R.id.tv_time, UiUtils.getCourseTimeString(data.startTime, data.endTime));
        //title
        holder.setText(R.id.tv_title, data.courseGroupName);
        //subjectName
        holder.setText(R.id.tv_course_name, data.subjectName);
        //购买人数
        holder.setText(R.id.tv_buy_num, getContext().getString(R.string.pay_count_str, data.studentCount));
        //封面
        ImageView iv_cover = holder.getView(R.id.iv_bg);
        GlideUtils.INSTANCE.loadImage(getContext(), data.backgroundPic, iv_cover, com.cooleshow.base.R.drawable.bg_video_placeholder);
        //头像
        ImageView cir_avatar = holder.getView(R.id.teacher_head);
        GlideUtils.INSTANCE.loadImage(getContext(), data.avatar, cir_avatar, R.drawable.icon_teacher_default_head);
        //老师名称
        holder.setText(R.id.teacher_name, UserHelper.getTeacherName(data.username, data.userId));

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

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

        if (TextUtils.equals(CourseConstants.COURSE_STATUS_ING, data.status)) {
            //进行中
            holder.setText(R.id.tv_course_status, "进行中");
            tvCourseStatusBt.setTextColor(getContext().getResources().getColor(com.cooleshow.base.R.color.color_2dc7aa));
        }

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

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