package com.example.applock.lockadapter;

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

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.example.applock.click.ButtomKeyClick;
import com.example.applock.databinding.ButtomKeyViewBinding;

import java.util.Objects;


public class ButtomAdapter extends RecyclerView.Adapter<ButtomAdapter.ButtomViewHolder> {
    private ButtomKeyClick buttomKeyClick;
    public void setBottomKeyClick(ButtomKeyClick buttomKeyClick){
        this.buttomKeyClick = buttomKeyClick;
    }
    private String[] bottomkeys = new String[]{"1","2","3","4","5","6","7","8","9","-10","0","-12"};
    public static class ButtomViewHolder extends RecyclerView.ViewHolder{
        private ButtomKeyViewBinding buttomKeyViewBinding;

        public ButtomViewHolder(ButtomKeyViewBinding buttomBinding) {
            super(buttomBinding.getRoot());
            buttomKeyViewBinding = buttomBinding;
        }
    }
    @NonNull
    @Override
    public ButtomViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ButtomKeyViewBinding buttomKeyViewBinding = ButtomKeyViewBinding.inflate(LayoutInflater.from(parent.getContext()),parent,false);
        return new ButtomViewHolder(buttomKeyViewBinding);
    }

    @Override
    public void onBindViewHolder(@NonNull ButtomViewHolder holder, int position) {
        String bottomkey = bottomkeys[position];
        if(position == 9&& Objects.equals(bottomkey, "-10")){
            holder.buttomKeyViewBinding.bottomKeyLinear.setVisibility(View.GONE);
        }else if (position == 11){
            holder.buttomKeyViewBinding.bottomKeyLinear.setVisibility(View.VISIBLE);
            holder.buttomKeyViewBinding.textKeyNumber.setVisibility(View.GONE);
            holder.buttomKeyViewBinding.imageDelete.setVisibility(View.VISIBLE);
        }else {
            holder.buttomKeyViewBinding.bottomKeyLinear.setVisibility(View.VISIBLE);
            holder.buttomKeyViewBinding.textKeyNumber.setText(bottomkeys[position]);
            holder.buttomKeyViewBinding.imageDelete.setVisibility(View.GONE);
        }
        holder.buttomKeyViewBinding.textKeyNumber.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                    buttomKeyClick.OnKeyClick(bottomkey);
            }
        });
        holder.buttomKeyViewBinding.imageDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                buttomKeyClick.OnDelete();
            }
        });

    }

    @Override
    public int getItemCount() {
        return bottomkeys.length;
    }


}
