package com.tencent.liteav.live.ui.widget.settingitem;

import android.view.ViewGroup;

import androidx.recyclerview.widget.LinearLayoutManager;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.ScreenUtils;
import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.tencent.liteav.live.R;
import com.tencent.liteav.live.databinding.ViewLinkListBinding;
import com.tencent.liteav.live.model.TRTCMeetingDef;
import com.tencent.liteav.live.ui.widget.LinkListAdapter;

import java.util.ArrayList;

public class LinkListDialog extends BottomSheetDialog {


    private ViewLinkListBinding binding;
    LinkListener listener;
    private LinkListAdapter roomListAdapter;

    public static interface LinkListener {
        void ok(TRTCMeetingDef.UserInfo item);

        void cancel(TRTCMeetingDef.UserInfo item);
    }

    public void setListener(LinkListener listener) {
        this.listener = listener;
    }

    public LinkListDialog(ArrayList<TRTCMeetingDef.UserInfo> mLinkList) {
        super(ActivityUtils.getTopActivity(), R.style.BottomSheetDialog);

        binding = ViewLinkListBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        ViewGroup.LayoutParams layoutParams = binding.rvList.getLayoutParams();
        layoutParams.height = ScreenUtils.getScreenHeight() / 2;
        binding.rvList.setLayoutParams(layoutParams);


        binding.rvList.setLayoutManager(new LinearLayoutManager(getContext()));
        roomListAdapter = new LinkListAdapter();
        roomListAdapter.setOnItemChildClickListener((adapter, view, position) -> {
            if (view.getId() == R.id.tv_ok) {
                if (listener != null) {
                    listener.ok(roomListAdapter.getItem(position));
                }
            } else if (view.getId() == R.id.tv_cancel) {
                if (listener != null) {
                    listener.cancel(roomListAdapter.getItem(position));
                }
            }
        });
        binding.rvList.setAdapter(roomListAdapter);

        roomListAdapter.setNewInstance(mLinkList);

    }


    public void refresh() {
        roomListAdapter.notifyDataSetChanged();
    }


}