package com.pixelnx.localhelp.ui.vendor;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import androidx.recyclerview.widget.RecyclerView;

import com.pixelnx.localhelp.R;
import com.pixelnx.localhelp.ui.login.ActivityLogin;
import com.pixelnx.localhelp.ui.notice.ActivityNotifications;
import com.pixelnx.localhelp.ui.order.ActivityCancelled;
import com.pixelnx.localhelp.ui.order.ActivityDelivered;
import com.pixelnx.localhelp.ui.order.ActivityNewOrder;
import com.pixelnx.localhelp.ui.storeitems.ActivityAddItem;
import com.pixelnx.localhelp.ui.storeitems.ActivityItemList;
import com.pixelnx.localhelp.utils.Consts;
import com.pixelnx.localhelp.utils.sharedpref.SharedPref;
import com.pixelnx.localhelp.utils.widgets.CustomTextMedium;


import java.util.List;
import java.util.Objects;



public class AdapterDashBoard extends RecyclerView.Adapter<AdapterDashBoard.HolderAdapterCategory> {
    private Context mContext;
    List<ModelItemsList> dataArrayList;
    private SharedPref sharedPref;



    public AdapterDashBoard(Context mContext, List<ModelItemsList> dataArrayList) {
        this.dataArrayList = dataArrayList;
        this.mContext = mContext;

    }

    @NonNull
    @Override
    public HolderAdapterCategory onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.adapter_dashboard, parent, false);
        return new HolderAdapterCategory(view);
    }

    @Override
    public void onBindViewHolder(@NonNull HolderAdapterCategory holder, final int position) {

        holder.tvTotal.setText("" + dataArrayList.get(position).getTitle());
        holder.ivIcon.setBackgroundResource(dataArrayList.get(position).imgId);




        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                switch (position) {

                    case 0:
                        Intent intentNotice=new Intent(mContext, ActivityNotifications.class);
                        mContext.startActivity(intentNotice);
                               break;
                    case 1:
                        Intent intentAdd=new Intent(mContext, ActivityItemList.class);
                        mContext.startActivity(intentAdd);
                        break;
                    case 2:
                        Intent intentItemList=new Intent(mContext, ActivityAddItem.class);
                        mContext.startActivity(intentItemList);
                        break;
                    case 3:
                        Intent intentProfile=new Intent(mContext, ActivityVendorProfile.class);
                        mContext.startActivity(intentProfile);
                        break;
                    case 4:
                        Intent intentNewOrder=new Intent(mContext, ActivityNewOrder.class);
                        mContext.startActivity(intentNewOrder);
                        break;
                    case 5:
                        Intent intentDelivery=new Intent(mContext, ActivityDelivered.class);
                        mContext.startActivity(intentDelivery);
                        break;
                    case 6:
                        Intent intentCancel=new Intent(mContext, ActivityCancelled.class);
                        mContext.startActivity(intentCancel);
                        break;
                    case 7:
                        sharedPref = SharedPref.getInstance(mContext);
                        logoutPopupDia();
                        break;



                }


            }
        });

    }

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

    public static class HolderAdapterCategory extends RecyclerView.ViewHolder {
        CustomTextMedium tvTotal;
        ImageView ivIcon;


        public HolderAdapterCategory(View itemView) {
            super(itemView);
            tvTotal = itemView.findViewById(R.id.tvTtl);
            ivIcon = itemView.findViewById(R.id.IvIcon);


        }
    }

    void logoutPopupDia() {

        final Dialog dialog ;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            dialog = new Dialog(mContext, android.R.style.Theme_Material_Light_Dialog_Alert);
        } else {
            dialog = new Dialog(mContext);
        }

        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setCancelable(false);
        dialog.setContentView(R.layout.logout_popups);
        Objects.requireNonNull(dialog.getWindow()).setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

        CustomTextMedium dialogYesButton = dialog.findViewById(R.id.btnYes);
        dialogYesButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {


                sharedPref.clearPreferences(Consts.Status.SP);
                sharedPref.setBooleanValue(Consts.Status.IS_REGIS,false);
                Intent loginScreen = new Intent(mContext, ActivityLogin.class);
                loginScreen.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                mContext.startActivity(loginScreen);

            }
        });


        CustomTextMedium dialogNoButton = dialog.findViewById(R.id.btnNo);
        dialogNoButton.setOnClickListener(new View.OnClickListener() {
            @Override

            public void onClick(View v) {

                dialog.dismiss();
            }
        });

        dialog.show();
    }


}
