package com.gh.gamecenter.qa.questions.invite;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;

import androidx.core.content.ContextCompat;

import com.gh.gamecenter.common.base.BaseRecyclerViewHolder;
import com.gh.gamecenter.common.callback.OnListClickListener;
import com.gh.common.util.DialogUtils;
import com.gh.common.util.DirectUtils;
import com.gh.gamecenter.common.utils.ImageUtils;
import com.gh.gamecenter.core.utils.MtaHelper;
import com.gh.gamecenter.core.utils.NumberUtils;
import com.gh.gamecenter.R;
import com.gh.gamecenter.databinding.QuestionsinviteItemBinding;
import com.gh.gamecenter.feature.entity.MeEntity;
import com.gh.gamecenter.qa.entity.InviteEntity;

/**
 * Created by khy on 7/12/17.
 */

public class QuestionsInviteViewHolder extends BaseRecyclerViewHolder<InviteEntity> {

    public QuestionsinviteItemBinding binding;

    public QuestionsInviteViewHolder(QuestionsinviteItemBinding binding, OnListClickListener listClickListener) {
        super(binding.getRoot(), listClickListener);
        this.binding = binding;
        binding.questionsinviteItemInvite.setOnClickListener(this);
    }

    public void initQuestionsInviteViewHolder(Context context, InviteEntity entity, String path) {
        setClickData(entity);
        ImageUtils.displayIcon(binding.questionsinviteItemIcon, entity.getIcon());
        binding.questionsinviteItemName.setText(entity.getName());
        if (!TextUtils.isEmpty(entity.getDescription())) {
            binding.questionsinviteItemDes.setVisibility(View.VISIBLE);
            binding.questionsinviteItemDes.setText(entity.getDescription());
        } else {
            binding.questionsinviteItemDes.setVisibility(View.GONE);
        }

        if (entity.getAuth() != null) {
            ImageUtils.display(binding.questionsinviteItemBadge, entity.getAuth().getIcon());
        } else {
            ImageUtils.display(binding.questionsinviteItemBadge, "");
        }

        MeEntity me = entity.getMe();
        if (me != null && me.isUserInvite()) {
            binding.questionsinviteItemInvite.setTextColor(ContextCompat.getColor(context, R.color.theme));
            binding.questionsinviteItemInvite.setText(R.string.invited);
            binding.questionsinviteItemInvite.setBackgroundResource(R.drawable.button_border_blue_oval);
        } else {
            binding.questionsinviteItemInvite.setTextColor(ContextCompat.getColor(context, R.color.white));
            binding.questionsinviteItemInvite.setText(R.string.invite);
            binding.questionsinviteItemInvite.setBackgroundResource(R.drawable.button_blue_oval);
        }

        if (entity.getCount() != null) {
            binding.questionsinviteItemAnswercount.setText(context.getString(R.string.ask_answer_count, NumberUtils.transSimpleCount(entity.getCount().getAnswer())));
            binding.questionsinviteItemVotecount.setText(context.getString(R.string.ask_vote_count, NumberUtils.transSimpleCount(entity.getCount().getVote())));
        }

        if (entity.getBadge() != null) {
            binding.sdvUserBadge.setVisibility(View.VISIBLE);
            ImageUtils.display(binding.sdvUserBadge, entity.getBadge().getIcon());
        } else {
            binding.sdvUserBadge.setVisibility(View.GONE);
        }
        binding.sdvUserBadge.setOnClickListener(v -> DialogUtils.showViewBadgeDialog(context, entity.getBadge(),
                () -> {
                    String key = "";
                    if (path.equals("问题详情-邀请列表")) {
                        key = "问题详情-邀请";
                    } else if (path.equals("问题详情-邀请回答")) {
                        key = "邀请回答列表";
                    }
                    MtaHelper.onEvent("进入徽章墙_用户记录", key, entity.getName() + "（" + entity.getId() + "）");
                    MtaHelper.onEvent("徽章中心", "进入徽章中心", key);
                    DirectUtils.directToBadgeWall(context, entity.getId(), entity.getName(), entity.getIcon());
                }));
    }
}
