package io.rong.imkit.conversation.messgelist.provider;

import android.content.Context;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.cooleshow.base.common.BaseApplication;
import com.cooleshow.base.router.RouterPath;
import com.cooleshow.base.utils.GlideUtils;
import com.cooleshow.base.utils.helper.WebStartHelper;

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

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import io.rong.imkit.R;
import io.rong.imkit.adapter.ItemMarkAdapter;
import io.rong.imkit.model.UiMessage;
import io.rong.imkit.widget.RCChatShareLiveMessage;
import io.rong.imkit.widget.adapter.IViewProviderListener;
import io.rong.imkit.widget.adapter.ViewHolder;
import io.rong.imlib.model.MessageContent;

/**
 * 创建日期：2022/6/14 11:13
 *
 * @author Ryan
 * 类说明：
 */
public class RCChatShareLiveProvider extends BaseMessageItemProvider<RCChatShareLiveMessage> {

    public RCChatShareLiveProvider() {
        mConfig.showContentBubble = false;
        mConfig.showProgress = false;
    }

    @Override
    protected ViewHolder onCreateMessageContentViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.rc_chat_share_live, parent, false);
        return new ViewHolder(view.getContext(), view);
    }

    @Override
    protected void bindMessageContentViewHolder(final ViewHolder holder, ViewHolder parentHolder, RCChatShareLiveMessage liveMessage, final UiMessage uiMessage, int position, List<UiMessage> list, IViewProviderListener<UiMessage> listener) {
        //头像
        ImageView iv_avatar = holder.getView(R.id.iv_avatar);
        GlideUtils.INSTANCE.loadImage(holder.getContext(), liveMessage.getTeacherAvatar(), iv_avatar, R.drawable.icon_teacher_default_head);
        //名称提示
        String name = "老师";
        if (!TextUtils.isEmpty(liveMessage.getTeacherName())) {
            name = liveMessage.getTeacherName();
        }
        //直播间介绍
        holder.setText(R.id.tv_name_tip, holder.getContext().getString(R.string.live_name_tip, name));
        if (!TextUtils.isEmpty(liveMessage.getLiveDescMessage())) {
            holder.setText(R.id.tv_content, liveMessage.getLiveDescMessage());
        } else {
            holder.setText(R.id.tv_content, "暂无直播间介绍");
        }
    }


    @Override
    protected boolean isMessageViewType(MessageContent messageContent) {
        return messageContent instanceof RCChatShareLiveMessage;
    }


    @Override
    public Spannable getSummarySpannable(Context context, RCChatShareLiveMessage liveMessage) {
        return new SpannableString("[直播分享]");
    }

    @Override
    protected boolean onItemClick(ViewHolder holder, RCChatShareLiveMessage liveMessage, UiMessage uiMessage, int position, List<UiMessage> list, IViewProviderListener<UiMessage> listener) {
        if (TextUtils.isEmpty(liveMessage.getRoomUID())) {
            return false;
        }
        if (BaseApplication.Companion.isTeacherClient()) {
            ARouter.getInstance().build(RouterPath.LiveCenter.ACTIVITY_LIVE_ROOM_TEACHER)
                    .withString("roomid_key", liveMessage.getRoomUID())
                    .navigation();
        } else {
            ARouter.getInstance().build(RouterPath.LiveCenter.ACTIVITY_LIVE_ROOM)
                    .withString("roomid_key", liveMessage.getRoomUID())
                    .navigation();
        }
        return true;
    }
}