package com.wisewoods.eduandroid.ui.adapter;

import com.wisewoods.base.app.UserManager;
import com.wisewoods.base.base.BaseVH;
import com.wisewoods.base.bean.ClassInfo;
import com.wisewoods.base.bean.Role;
import com.wisewoods.base.page.BasePageAdapter;
import com.wisewoods.base.utils.$;
import com.wisewoods.eduandroid.R;

import org.jetbrains.annotations.NotNull;

public class ClassAdapter extends BasePageAdapter<ClassInfo.DataBean> {
    public ClassAdapter() {
        super(R.layout.item_recycler_class);
        addChildClickViewIds(
                R.id.tv_check, R.id.tv_student_loading, R.id.tv_student_list,
                R.id.tv_check_detail, R.id.tv_res, R.id.tv_open
        );
    }

    @Override
    protected void convert(@NotNull BaseVH baseVH, ClassInfo.DataBean listBean) {
        String start = $.timeFormat2(listBean.teamStart);
        String end = $.timeFormat2(listBean.teamEnd);

        baseVH.setText(R.id.tv_name, listBean.teamName)
                .setText(R.id.tv_time, start + "-" + end)
                .setText(R.id.tv_pecent, listBean.getP())
                .setText(R.id.tv_progress_check, listBean.getB())
                .setProgress(R.id.pb_project, (int) (listBean.pxjd * 100))
                .setProgress(R.id.pb_check, (int) (listBean.bdl * 100))
                .setNetUrl(R.id.iv_logo, listBean.teamUrl, R.drawable.ic_class_logo)
        ;

        initUI(baseVH, listBean);
    }

    private void initUI(@NotNull BaseVH baseVH, ClassInfo.DataBean listBean) {
        Role role = UserManager.getUser().getRole();
        switch (role) {
            case ORGANIZER:
            case UNDERTAKER:
                baseVH.setGone(R.id.tv_student_loading, false)
                        .setGone(R.id.tv_check, true)
                        .setGone(R.id.ll_check_data, true)
                        .setGone(R.id.tv_student_list, true)
                        .setGone(R.id.tv_res, true)
                        .setGone(R.id.tv_check_detail, true)
                        .setGone(R.id.tv_open, true)
                        .setGone(R.id.ll_check_data, true)

                ;
                break;
            case EDUCATION:
                baseVH.setGone(R.id.tv_student_loading, true)
                        .setGone(R.id.tv_check, false)
                        .setGone(R.id.ll_check_data, false)
                        .setGone(R.id.tv_student_list, false)
                        .setGone(R.id.tv_res, true)
                        .setGone(R.id.tv_check_detail, true)
                        .setGone(R.id.tv_open, true)
                        .setGone(R.id.ll_check_data, true)
                ;
                break;
            case TRAIN:
                baseVH.setGone(R.id.tv_student_loading, true)
                        .setGone(R.id.tv_check, false)
                        .setGone(R.id.ll_check_data, false)
                        .setGone(R.id.tv_student_list, true)
                        .setGone(R.id.tv_res, false)
                        .setGone(R.id.tv_check_detail, listBean.isCheckin != 1 || listBean.openReport != 1)
                        .setGone(R.id.tv_open, listBean.isCheckin != 1 || listBean.openReport == 1)
                        .setGone(R.id.ll_check_data, listBean.isCheckin != 1 || listBean.openReport != 1)
                ;
                break;
        }
    }
}
