package com.zztrapp.zztrapp.ui.currency.adapter;


import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.zztrapp.zztrapp.bean.MeetListBean;
import com.zztrapp.zztrapp.databinding.ItemRvVideoconferencingBinding;

import java.util.List;

/**
 * Describe 视频会议
 * Created by Bby on 2022/6/23
 * Email bby0856@163.com
 */

public class VideoconferencingAdapter extends RecyclerView.Adapter<VideoconferencingAdapter.ItemHolder> {

    private Context mContext;
    private OnItemClickListener onItemClickListener;
    private List<MeetListBean.RecordsBean> list;

    public interface OnItemClickListener {
        void onJoinClick(int position);
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public VideoconferencingAdapter(Context context) {
        this.mContext = context;
    }

    public void setData(List<MeetListBean.RecordsBean> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ItemHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ItemRvVideoconferencingBinding binding = ItemRvVideoconferencingBinding.inflate(LayoutInflater.from(mContext), parent, false);
        return new ItemHolder(binding);
    }

    @Override
    public void onBindViewHolder(ItemHolder holder, @SuppressLint("RecyclerView") int position) {
            holder.bindings.meetingName.setText(list.get(position).getHymc());
            holder.bindings.meetingNumber.setText("会议号："+list.get(position).getHyh());
            holder.bindings.name.setText("发起人：："+list.get(position).getFqr());
            holder.bindings.time.setText("预约开始时间："+list.get(position).getKssj());
            if (list.get(position).getZt()==2){
                holder.bindings.lookDetailView.setVisibility(View.GONE);
                holder.bindings.line.setVisibility(View.GONE);
            }else {
                holder.bindings.lookDetailView.setVisibility(View.VISIBLE);
                holder.bindings.line.setVisibility(View.VISIBLE);
            }
        holder.bindings.lookDetail.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onItemClickListener != null) {
                    onItemClickListener.onJoinClick(position);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return list != null ? list.size() : 0;
    }

    static class ItemHolder extends RecyclerView.ViewHolder {
        private ItemRvVideoconferencingBinding bindings;

        public ItemHolder(ItemRvVideoconferencingBinding binding) {
            super(binding.getRoot());
            bindings = binding;
        }
    }
}