package com.cooleshow.teacher.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.TimeUtils;
import com.cooleshow.base.utils.UiUtils;
import com.cooleshow.teacher.R;
import com.cooleshow.teacher.bean.MineLiveCourseListBean;
import com.cooleshow.teacher.ui.course.MineLiveCourseActivity;

import java.util.List;

/**
 * 创建日期：2022/5/19 16:38
 *
 * @author Ryan
 * 类说明：
 */
public class MineLiveCourseAdapter extends BaseQuickAdapter<MineLiveCourseListBean.RowsBean, BaseViewHolder> implements LoadMoreModule {
    private String type;

    public MineLiveCourseAdapter(String type) {
        super(R.layout.layout_mine_live_course_item);
        this.type = type;
    }


    @Override
    protected void convert(BaseViewHolder helper, MineLiveCourseListBean.RowsBean item) {
        if (item == null) {
            return;
        }
        //课程封面
        ImageView im_pic = helper.getView(R.id.im_pic);
        GlideUtils.INSTANCE.loadImage(getContext(), item.backgroundPic, im_pic);
        //课程组名称
        TextView tv_course_name = helper.getView(R.id.tv_course_name);
        tv_course_name.setText(item.courseGroupName);
        //学生购买人数
        TextView tv_student_count = helper.getView(R.id.tv_student_count);
        tv_student_count.setText(UiUtils.getBuyNumTip(item.coursePrice, item.studentCount));
        if (TextUtils.equals(type, MineLiveCourseActivity.TYPE_NOT_SALE)) {
            tv_student_count.setVisibility(View.GONE);
        } else {
            tv_student_count.setVisibility(View.VISIBLE);
        }
        //课程时间
        TextView tv_date = helper.getView(R.id.tv_date);
        tv_date.setText(TextUtils.isEmpty(item.courseStartTime) ? "" : TimeUtils.date2String(TimeUtils.string2Date(item.courseStartTime), "yyyy-MM-dd HH:mm"));
        //课程价格
        TextView tv_price = helper.getView(R.id.tv_price);
        tv_price.setText(UiUtils.getLiveCoursePriceText(item.coursePrice, item.courseNum));
        TextView tv_price_unit = helper.getView(R.id.tv_price_unit);
        tv_price_unit.setText(String.format("/%d课时", item.courseNum));
        //声部
        helper.setText(R.id.subject_name, item.subjectName);

        TextView tv_course_status_tip = helper.getView(R.id.tv_course_status_tip);
        if (TextUtils.equals(type, MineLiveCourseActivity.TYPE_ING)) {
            //进行中
            tv_course_status_tip.setText("进行中");
            tv_course_status_tip.setTextColor(getContext().getResources().getColor(com.cooleshow.base.R.color.color_2dc7aa));
            tv_course_status_tip.setBackgroundResource(R.drawable.shape_d5fff7_15dp_left);
        } else if (TextUtils.equals(type, MineLiveCourseActivity.TYPE_NOT_SALE)) {
            //未上架
            tv_course_status_tip.setText("未上架");
            tv_course_status_tip.setTextColor(getContext().getResources().getColor(com.cooleshow.base.R.color.color_ff4e19));
            tv_course_status_tip.setBackgroundResource(R.drawable.shape_ffeee3_15dp_left);
        } else if (TextUtils.equals(type, MineLiveCourseActivity.TYPE_APPLY)) {
            //销售中
            tv_course_status_tip.setText("销售中");
            tv_course_status_tip.setTextColor(getContext().getResources().getColor(com.cooleshow.base.R.color.color_ff1919));
            tv_course_status_tip.setBackgroundResource(R.drawable.shape_ffe7e7_15dp_left);
        } else if (TextUtils.equals(type, MineLiveCourseActivity.TYPE_COMPLETE)) {
            //已完成
            tv_course_status_tip.setText("已完成");
            tv_course_status_tip.setTextColor(getContext().getResources().getColor(com.cooleshow.base.R.color.color_008ae0));
            tv_course_status_tip.setBackgroundResource(R.drawable.shape_def2ff_15dp_left);
        } else if (TextUtils.equals(type, MineLiveCourseActivity.TYPE_CANCEL)) {
            //已取消
            tv_course_status_tip.setText("已取消");
            tv_course_status_tip.setTextColor(getContext().getResources().getColor(com.cooleshow.base.R.color.color_666666));
            tv_course_status_tip.setBackgroundResource(R.drawable.shape_f0f0f0_15dp_left);
        } else if (TextUtils.equals(type, MineLiveCourseActivity.TYPE_OUT_SALE)) {
            tv_course_status_tip.setText("已下架");
            tv_course_status_tip.setTextColor(getContext().getResources().getColor(com.cooleshow.base.R.color.color_666666));
            tv_course_status_tip.setBackgroundResource(R.drawable.shape_f0f0f0_15dp_left);
        }
    }

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

}
