package com.cooleshow.teacher.adapter;

import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

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.teacher.R;
import com.cooleshow.teacher.bean.MineLiveCourseListBean;
import com.cooleshow.teacher.bean.MusicSheetListBean;

import java.util.ArrayList;
import java.util.List;

/**
 * 创建日期：2022/5/20 17:19
 *
 * @author Ryan
 * 类说明：
 */
public class MineScoreAdapter extends BaseQuickAdapter<MusicSheetListBean.RowsBean, BaseViewHolder> implements LoadMoreModule {

    public MineScoreAdapter() {
        super(R.layout.layout_mine_score_item);
    }


    @Override
    protected void convert(BaseViewHolder helper, MusicSheetListBean.RowsBean item) {
        TextView tv_name = helper.getView(R.id.tv_name);
        TextView tv_author_name = helper.getView(R.id.tv_author_name);
        ImageView im_state = helper.getView(R.id.im_state);
        ImageView im_header = helper.getView(R.id.im_header);
        TextView tv_teacher_name = helper.getView(R.id.tv_teacher_name);
        RecyclerView rv_mark = helper.getView(R.id.rv_mark);

        switch (item.chargeType) {
            case "FREE":
                im_state.setBackgroundResource(R.drawable.icon_score_free);
                break;
            case "VIP":
                im_state.setBackgroundResource(R.drawable.icon_score_vip);
                break;
            case "CHARGE":
                im_state.setBackgroundResource(R.drawable.icon_score_demand);
                break;
        }
        tv_name.setText(item.musicSheetName);
        tv_author_name.setText(item.composer);
        GlideUtils.INSTANCE.loadImage(getContext(), item.addUserAvatar, im_header, R.drawable.icon_teacher_default_head);
        tv_teacher_name.setText(item.addName);
        if (!TextUtils.isEmpty(item.subjectNames)) {
            rv_mark.setVisibility(View.VISIBLE);
            List<String> markList = new ArrayList<>();
            if (item.subjectNames.contains(",")) {
                String[] split = item.subjectNames.split(",");
                for (String s : split) {
                    markList.add(s);
                }
            } else {
                markList.add(item.subjectNames);
            }
            LinearLayoutManager manager = new LinearLayoutManager(getContext());
            manager.setOrientation(LinearLayoutManager.HORIZONTAL);
            rv_mark.setLayoutManager(manager);
            ItemMarkAdapter itemMarkAdapter = new ItemMarkAdapter(markList);
            rv_mark.setAdapter(itemMarkAdapter);
        } else {
            rv_mark.setVisibility(View.GONE);
        }

    }

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

}
