package com.wisewoods.eduandroid.ui.adapter;

import android.graphics.Color;
import android.text.TextUtils;

import com.wisewoods.base.app.UserManager;
import com.wisewoods.base.base.BaseVH;
import com.wisewoods.base.bean.Role;
import com.wisewoods.base.bean.ScheduleInfo;
import com.wisewoods.base.page.BasePageAdapter;
import com.wisewoods.eduandroid.R;

import org.jetbrains.annotations.NotNull;

public class ScheduleAdapter extends BasePageAdapter<ScheduleInfo.DataBean> {
    public ScheduleAdapter() {
        super(R.layout.item_recycler_shedule);
        addChildClickViewIds(R.id.tv_course_start, R.id.tv_course_end,
                R.id.tv_course_detail, R.id.tv_student,
                R.id.tv_go_live, R.id.tv_download
        );
    }

    @Override
    protected void convert(@NotNull BaseVH baseVH, ScheduleInfo.DataBean dataBean) {
        String rightStr = "";
        if (dataBean.isLive == 1) {
            rightStr = "直播";
        }
        if ("3".equals(dataBean.courseType)) {
            rightStr = "录播";
        }
        if (TextUtils.isEmpty(rightStr)) {
            baseVH.setGone(R.id.tv_live, true)
                    .setGone(R.id.v_type, true);
        } else {
            baseVH.setGone(R.id.tv_live, false)
                    .setGone(R.id.v_type, false)
                    .setText(R.id.tv_live, rightStr);
            ;
            if ("直播".equals(rightStr)) {
                baseVH.setTextTop(R.id.tv_live, R.drawable.ic_course_live)
                        .setTextColor(R.id.tv_live, Color.parseColor("#2175E7"))
                ;
            } else if ("录播".equals(rightStr)) {
                baseVH.setTextTop(R.id.tv_live, R.drawable.ic_course_record)
                        .setTextColor(R.id.tv_live, Color.parseColor("#8a49eb"))
                ;
            }
        }

        baseVH
                .setText(R.id.tv_course_name, dataBean.courseCeremoneyName)
                .setText(R.id.tv_time, dataBean.courseStartTime + "-" + dataBean.courseEndTime)
                .setText(R.id.tv_course_type, TextUtils.isEmpty(dataBean.courseType) ? "活动" : "课程")
                .setText(R.id.tv_progress_check, dataBean.getS())
                .setGone(R.id.iv_course_cover, TextUtils.isEmpty(dataBean.courseType))
                .setProgress(R.id.pb_check, (int) (dataBean.signInRate * 100))
                .setNetUrl(R.id.iv_course_cover, dataBean.courseThumbnailUrl, R.drawable.shape_dialog_edit)
                .setText(R.id.tv_group, dataBean.groupsName)
        ;
        initUI(baseVH, dataBean);
    }

    private void initUI(BaseVH baseVH, ScheduleInfo.DataBean dataBean) {
        Role role = UserManager.getUser().getRole();
        switch (role) {
            case EDUCATION:
                baseVH.setGone(R.id.tv_course_start, true)
                        .setGone(R.id.ll_check_progress, true)
                        .setGone(R.id.tv_student, true)
                        .setGone(R.id.ll_zcc, true)
                        .setGone(R.id.tv_course_detail, true)
                        .setGone(R.id.tv_go_live, true);
                break;
            case TRAIN:
                baseVH.setGone(R.id.tv_course_start, "3".equals(dataBean.courseType))
                        .setGone(R.id.ll_check_progress, dataBean.groupType == 0 || "3".equals(dataBean.courseType))
                        .setGone(R.id.tv_student, false)
                        .setGone(R.id.ll_zcc, dataBean.keynoteId == 0)
                        .setGone(R.id.tv_course_detail, TextUtils.isEmpty(dataBean.courseType))
                        .setGone(R.id.tv_go_live, dataBean.isLive == 0 || dataBean.liveStatus == 2);

                break;
            case TEACHER:
                baseVH.setGone(R.id.tv_course_start, true)
                        .setGone(R.id.ll_zcc, true)
                        .setGone(R.id.ll_check_progress, true)
                        .setGone(R.id.tv_student, false)
                        .setGone(R.id.tv_course_detail, TextUtils.isEmpty(dataBean.courseType))
                        .setGone(R.id.tv_go_live, dataBean.isLive == 0 || dataBean.liveStatus == 2);
                break;
        }

        String status = "";
        if (dataBean.courseStatus == 0) {
            baseVH.setTextLeft(R.id.tv_status, R.drawable.shape_point_live_off)
                    .setTextColor(R.id.tv_status, Color.parseColor("#7a7a7a"))
                    .setText(R.id.tv_status, "未开始");
            if (role == Role.TRAIN) {
                baseVH.setGone(R.id.tv_course_start, "3".equals(dataBean.courseType))
                        .setGone(R.id.tv_course_end, true);
            }
        } else if (dataBean.courseStatus == 1) {
            baseVH.setTextLeft(R.id.tv_status, R.drawable.shape_point_live_on)
                    .setTextColor(R.id.tv_status, Color.parseColor("#13d596"))
                    .setText(R.id.tv_status, "上课中");
            if (role == Role.TRAIN) {
                baseVH.setGone(R.id.tv_course_start, true)
                        .setGone(R.id.tv_course_end, "3".equals(dataBean.courseType));
            }
        } else if (dataBean.courseStatus == 2) {
            baseVH.setTextLeft(R.id.tv_status, R.drawable.shape_point_end)
                    .setTextColor(R.id.tv_status, Color.parseColor("#ff4330"))
                    .setText(R.id.tv_status, "已结束");
            if (role == Role.TRAIN) {
                baseVH.setGone(R.id.tv_course_start, true)
                        .setGone(R.id.tv_course_end, true);
            }
        }


    }
}
