package com.ycgis.macall.personalcenter.v.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;

import com.rs.macall.androidx.basemodel.base.BaseRecyclerAdapter;
import com.rs.macall.androidx.basemodel.base.BaseRecyclerPlusAdapter;
import com.ycgis.macall.personalcenter.R;
import com.ycgis.macall.personalcenter.databinding.ItemApplyAuditBinding;
import com.ycgis.macall.personalcenter.databinding.ItemAuthenticationBinding;
import com.ycgis.macall.personalcenter.m.adapterbean.AuthManageItem;
import com.ycgis.macall.personalcenter.m.adapterbean.BaseBean;

import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 * created by:   Macall
 * create time:  2023/11/17 15:23
 * copyright:    @ruansee.com
 * Describe:
 */
public class AuthManageAdapter extends BaseRecyclerPlusAdapter<AuthManageItem, BaseRecyclerPlusAdapter.ViewHolder> {

    public AuthManageAdapter(Context context, List<AuthManageItem> dataList) {
        super(context, dataList);
    }

    @Override
    public int getItemViewType(int position) {
        return getDataItem(position).getBaseType();
    }

    @Override
    public BaseRecyclerPlusAdapter.ViewHolder getViewHolder(@NotNull ViewGroup parent, int viewType) {
        if (viewType == 0 || viewType == -1) {
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_error_empty_xiao, parent, false);
            return new ErrorViewHolder(view);
        }
        if (viewType == 1) {
            View view = bindView(parent, R.layout.item_authentication);
            ItemAuthenticationBinding binding = ItemAuthenticationBinding.bind(view);
            return new ViewBindingHolder<>(binding);
        }
        return null;
    }

    @Override
    public void bindViewHolder(@NotNull BaseRecyclerPlusAdapter.ViewHolder viewHolder, int position, @NotNull List payloads) {
        AuthManageItem item = getDataItem(position);
        if (payloads.isEmpty()) {
            if (viewHolder instanceof ViewBindingHolder) {
                ViewBindingHolder<ItemAuthenticationBinding> holder = (ViewBindingHolder<ItemAuthenticationBinding>) viewHolder;
                holder.viewBind.tvTitle.setText(item.getName());
                // 是否一开通
                if (item.isActivate()) {
                    // 已开通的 有三中状态 1 默认绑定不支持修改   2 未绑定 需要绑定    3 已绑定支持修改
                    if (item.isAutheType()){//已绑定
                        if (item.isUpdate()){//支持修改
                            holder.viewBind.btnUpdate.setText("修改");
                            holder.viewBind.tvStauts.setVisibility(View.GONE);
                            holder.viewBind.btnUpdate.setVisibility(View.VISIBLE);
                            holder.viewBind.btnUpdate.setBackground(ContextCompat.getDrawable(context, R.drawable.back_opinion1));
                            holder.viewBind.btnUpdate.setTextColor(ContextCompat.getColor(context, R.color.colorYellow7));
                        }else {
                            holder.viewBind.tvStauts.setText("已绑定/不支持修改");
                            holder.viewBind.tvStauts.setVisibility(View.VISIBLE);
                            holder.viewBind.btnUpdate.setVisibility(View.GONE);
                        }
                    }else {//未绑定的
                        holder.viewBind.tvStauts.setVisibility(View.GONE);
                        holder.viewBind.btnUpdate.setVisibility(View.VISIBLE);
                        holder.viewBind.btnUpdate.setText("设置");
                        holder.viewBind.btnUpdate.setBackground(ContextCompat.getDrawable(context, R.drawable.edit_brack_select));
                        holder.viewBind.btnUpdate.setTextColor(ContextCompat.getColor(context, R.color.colorBluen6));
                    }
                }else {
                    holder.viewBind.tvStauts.setText("暂未开通");
                    holder.viewBind.tvStauts.setVisibility(View.VISIBLE);
                    holder.viewBind.btnUpdate.setVisibility(View.GONE);
                    return;
                }
                if (item.isSelect()) {
                    holder.viewBind.imageView3.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_network_normal));
                } else {
                    holder.viewBind.imageView3.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_network_pause));
                }
                holder.setChileViewClick(holder.viewBind.btnUpdate, position, 1, "");

            }
            if (viewHolder instanceof BaseRecyclerAdapter.ErrorViewHolder) {
                ErrorViewHolder holder = (ErrorViewHolder) viewHolder;
                if (getDataItem(position).getBaseType() == 0) {
                    holder.setEmpty(getDataItem(position).getBaseMessage());
                } else {
                    holder.setError(getDataItem(position).getBaseMessage());
                }
            }
        }else {
            Object o = payloads.get(0);
            if (o instanceof Integer){
                int a = (int) o;
                if (a == 5){
                    if (viewHolder instanceof ViewBindingHolder) {
                        ViewBindingHolder<ItemAuthenticationBinding> holder = (ViewBindingHolder<ItemAuthenticationBinding>) viewHolder;
                        if (item.isSelect()) {
                            holder.viewBind.imageView3.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_network_normal));
                        } else {
                            holder.viewBind.imageView3.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_network_pause));
                        }
                    }
                }
            }
        }


    }


}
