package w.soulofpluto.posstock;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;

/*
 Create by Ramesh Babu
 */
 public  class MenuAdapter extends RecyclerView.Adapter<MenuAdapter.ViewHolder> {
     ArrayList<String> arrayList;
     Context context;
     public MenuAdapter(Context context,ArrayList<String> arrayList){
         this.context   = context;
         this.arrayList = arrayList;
     }
    @NonNull
    @Override
    public MenuAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
        View listItem = layoutInflater.inflate(R.layout.menulist_item, parent, false);
        MenuAdapter.ViewHolder viewHolder = new MenuAdapter.ViewHolder(listItem);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull MenuAdapter.ViewHolder holder, final int position) {
        final String data = arrayList.get(position);
        holder.menu_name.setText(data);
        holder.layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(data.equalsIgnoreCase("Stock Audit")){
                    Intent intent = new Intent(context,DashBoardActivity.class);
                    context.startActivity(intent);
                }else if(data.equalsIgnoreCase("Create Delivery Slip")){
                    Intent intent = new Intent(context,CreateDeliverySlip.class);
                    context.startActivity(intent);
                }else{
                    Intent intent = new Intent(context,CreateSaleBill.class);
                    context.startActivity(intent);
                }
            }
        });
    }

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

    public class ViewHolder extends RecyclerView.ViewHolder{
        public TextView menu_name;
        public ImageView menu_image;
        public LinearLayout layout;
        public ViewHolder(View itemView){
            super(itemView);
            menu_name         = itemView.findViewById(R.id.menu_name);
            menu_image        = itemView.findViewById(R.id.menu_image);
            layout            = itemView.findViewById(R.id.layout);
        }
    }

}
