package com.lc.myapplication.security.locks.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

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

import com.lc.myapplication.security.locks.databinding.BottomCodeViewBinding;
import com.lc.myapplication.security.locks.listener.BottomnumberClick;

public class BottomInputadapter extends RecyclerView.Adapter<BottomInputadapter.BottomViewHolder> {

    private String[] bottomcodes = new String[]{"1","2","3","4","5","6","7","8","9","-10","0","-12"};
    private BottomnumberClick bottomnumberClick;
    @NonNull
    @Override
    public BottomViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        BottomCodeViewBinding bottomCodeViewBinding = BottomCodeViewBinding.inflate(LayoutInflater.from(parent.getContext()),parent,false);
        return new BottomViewHolder(bottomCodeViewBinding);
    }
    public void setBottomClick(BottomnumberClick bottomClick){
        this.bottomnumberClick = bottomClick;
    }


    @Override
    public void onBindViewHolder(@NonNull BottomViewHolder holder, int position) {
        String code = bottomcodes[position];
        if (position == 9){
            holder.bottomCodeViewBinding.bottomText.setVisibility(View.GONE);
            holder.bottomCodeViewBinding.bottomImage.setVisibility(View.GONE);
        }else if(position == 11){
            holder.bottomCodeViewBinding.bottomText.setVisibility(View.GONE);
            holder.bottomCodeViewBinding.bottomImage.setVisibility(View.VISIBLE);
        }else {
            holder.bottomCodeViewBinding.bottomText.setVisibility(View.VISIBLE);
            holder.bottomCodeViewBinding.bottomText.setText(bottomcodes[position]);
            holder.bottomCodeViewBinding.bottomImage.setVisibility(View.GONE);
        }
        holder.bottomCodeViewBinding.bottomText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                bottomnumberClick.numberClick(code);
            }
        });
        holder.bottomCodeViewBinding.bottomImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                bottomnumberClick.delete();
            }
        });
    }

    @Override
    public int getItemCount() {
        return 12;
    }

    public class BottomViewHolder extends RecyclerView.ViewHolder {
        private BottomCodeViewBinding bottomCodeViewBinding;
        public BottomViewHolder(@NonNull BottomCodeViewBinding bottomViewBinding) {
            super(bottomViewBinding.getRoot());
            bottomCodeViewBinding = bottomViewBinding;
        }
    }
}
