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.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.cooleshow.base.utils.GlideUtils;
import com.cooleshow.teacher.R;
import com.cooleshow.teacher.bean.TeacherSelfStyleInfoBean;

import java.util.List;

/**
 * 创建日期：2022/5/13 15:46
 *
 * @author Ryan
 * 类说明：
 */
public class MineStyleVideoAdapter extends BaseMultiItemQuickAdapter<TeacherSelfStyleInfoBean.StyleVideoBean, BaseViewHolder> {
    public static final String VIDEO_AUDIT_STATUS_DOING = "DOING";//审核中
    public static final String VIDEO_AUDIT_STATUS_PASS = "PASS";//审核通过
    public static final String VIDEO_AUDIT_STATUS_UNPASS = "UNPASS";//审核失败

    public MineStyleVideoAdapter(List<TeacherSelfStyleInfoBean.StyleVideoBean> data) {
        super(data);
        addItemType(0, R.layout.item_teacher_style_video_layout);
        addItemType(1, R.layout.item_teacher_style_video_layout_add);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder holder, TeacherSelfStyleInfoBean.StyleVideoBean styleVideoBean) {
        switch (styleVideoBean.getItemType()) {
            case 0:
                //加载视频缩略图
                ImageView iv_video_bg = holder.getView(R.id.iv_video_bg);
                GlideUtils.INSTANCE.loadVideoThumbnail(getContext(), styleVideoBean.videoUrl, iv_video_bg);
                ImageView im_delete = holder.getView(R.id.im_delete);
                im_delete.setOnClickListener(view -> {
                    if (null != itemAddClickAction) {
                        itemAddClickAction.delete(styleVideoBean.videoUrl);
                    }
                });
                //视频审核状态
                TextView tv_audit_status = holder.getView(R.id.tv_audit_status);
                if (TextUtils.equals(VIDEO_AUDIT_STATUS_DOING, styleVideoBean.authStatus)) {
                    tv_audit_status.setVisibility(View.VISIBLE);
                    tv_audit_status.setText("审核中");
                } else if (TextUtils.equals(VIDEO_AUDIT_STATUS_UNPASS, styleVideoBean.authStatus)) {
                    tv_audit_status.setVisibility(View.VISIBLE);
                    tv_audit_status.setText("审核失败");
                } else {
                    tv_audit_status.setVisibility(View.GONE);
                }
                break;
            case 1:
                ImageView iv_video_add = holder.getView(R.id.iv_video_add);
                iv_video_add.setOnClickListener(view -> {
                    if (null != itemAddClickAction) {
                        itemAddClickAction.add();
                    }
                });
                break;
        }
        holder.itemView.setOnClickListener(v -> {
            if (getItemViewType(holder.getAbsoluteAdapterPosition()) == 0) {
                if (null != itemAddClickAction) {
                    itemAddClickAction.play(styleVideoBean.videoUrl);
                }
            }
        });
    }

    private ItemAddClickAction itemAddClickAction;

    public void setItemAddClickAction(ItemAddClickAction itemAddClickAction) {
        this.itemAddClickAction = itemAddClickAction;

    }

    public interface ItemAddClickAction {
        void add();

        void play(String videoUrl);

        void delete(String url);
    }


}
