package com.pixelnx.localhelp.ui.base;

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.BaseAdapter;





import com.pixelnx.localhelp.R;
import com.pixelnx.localhelp.ui.login.ActivityLogin;
import com.pixelnx.localhelp.ui.notice.ActivityCustomerNotifications;
import com.pixelnx.localhelp.ui.user.ActivityCustomerPro;
import com.pixelnx.localhelp.ui.user.ActivityPreviousOrderList;
import com.pixelnx.localhelp.ui.vendor.ActivityAllStore;
import com.pixelnx.localhelp.utils.Consts;
import com.pixelnx.localhelp.utils.sharedpref.SharedPref;
import com.pixelnx.localhelp.utils.widgets.CustomTextMedium;
import com.pixelnx.localhelp.utils.widgets.CustomTextSemiBold;


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


public class AdapterNavItems extends BaseAdapter {

    Context mContext;
    List<String> navList;
    private SharedPref sharedPref;


    public AdapterNavItems(Context mContext, List<String> navList) {
        this.mContext = mContext;
        this.navList = navList;

    }

    @Override
    public int getCount() {
        return navList.size();
    }

    @Override
    public Object getItem(int position) {
        return navList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        LayoutInflater vi = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        convertView = vi.inflate(R.layout.nav_items, parent, false);




        final CustomTextSemiBold title = (CustomTextSemiBold) convertView.findViewById(R.id.title);


        title.setText(navList.get(position));

        title.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {


                switch (position) {
                    case 3:
                    case 0:
                        Intent intent=new Intent(mContext, ActivityAllStore.class);
                        mContext.startActivity(intent);

                        break;
                    case 1:
                        Intent intent2=new Intent(mContext, ActivityCustomerPro.class);
                        mContext.startActivity(intent2);
                        break;
                    case 2:
                        Intent intent3=new Intent(mContext, ActivityPreviousOrderList.class);
                        mContext.startActivity(intent3);

                        break;


                    case 4:
                        Intent intent4=new Intent(mContext, ActivityCustomerNotifications.class);
                        mContext.startActivity(intent4);
                        break;
                    case 5:
                        sharedPref = SharedPref.getInstance(mContext);
                     logoutPopupDia();
                        break;

                }
            }
        });





        return convertView;
    }

    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.clearAllPreferences();
                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();
    }



}
