package com.halo.assistant.fragment.user.region;

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

import androidx.recyclerview.widget.RecyclerView;

import com.gh.gamecenter.adapter.viewholder.AreaViewHolder;
import com.gh.gamecenter.databinding.AreaItemBinding;
import com.gh.gamecenter.login.user.UserManager;
import com.lightgame.adapter.BaseRecyclerAdapter;

import java.util.List;

/**
 * Created by khy on 25/09/17.
 */

class RegionProvAdapter extends BaseRecyclerAdapter {

    private OnRegionSelectListener mListener;

    private List<String> mProvList;

    private String mCurRegin;

    RegionProvAdapter(Context context, List<String> provList, OnRegionSelectListener listener) {
        super(context);
        mListener = listener;
        mProvList = provList;
        mCurRegin = UserManager.getInstance().getUserInfoEntity().getRegion();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int i) {
        return new AreaViewHolder(AreaItemBinding.inflate(mLayoutInflater, parent, false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof AreaViewHolder) {
            AreaViewHolder viewHolder = (AreaViewHolder) holder;
            viewHolder.binding.areaItemMore.setVisibility(View.GONE);
            final String name = mProvList.get(position);
            viewHolder.binding.areaItemName.setText(name);
            if (!TextUtils.isEmpty(mCurRegin) && mCurRegin.contains(name)) {
                viewHolder.binding.areaItemSelect.setVisibility(View.VISIBLE);
            } else {
                viewHolder.binding.areaItemSelect.setVisibility(View.GONE);
            }
            viewHolder.binding.getRoot().setOnClickListener(view -> mListener.onRegionSelect(name, null));
        }
    }

    @Override
    public int getItemCount() {
        return mProvList.size();
    }
}
