package com.pixelnx.localhelp.ui.user;



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

import com.pixelnx.localhelp.R;
import com.pixelnx.localhelp.model.ModelUserData;
import com.pixelnx.localhelp.ui.login.ActivityLogin;
import com.pixelnx.localhelp.utils.Consts;
import com.pixelnx.localhelp.utils.sharedpref.SharedPref;
import com.pixelnx.localhelp.utils.widgets.CustomTextBold;
import com.pixelnx.localhelp.utils.widgets.CustomTextMedium;

import java.util.Objects;

public class ActivityProfileSetting extends Activity {
    ImageView backIv;
    SharedPref sharedPref;
    CustomTextBold btLog;
    CustomTextBold btPreviousOrder;
    CustomTextBold btPro;
    CustomTextMedium details;
    ModelUserData modelUserData;
    Context mContext;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_profile);
        backIv = findViewById(R.id.backIv);
        btLog = findViewById(R.id.btLog);
        btPro = findViewById(R.id.btPro);
        btPro.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(mContext,ActivityCustomerPro.class);
                startActivity(intent);
            }
        });
        btPreviousOrder = findViewById(R.id.btPreviousOrder);
        details = findViewById(R.id.deatils);
        mContext = ActivityProfileSetting.this;

        sharedPref = SharedPref.getInstance(mContext);
        modelUserData = sharedPref.getUser(Consts.Status.SP);
String detail="Name-  "+modelUserData.getData().getUserName()+" \nMobile-  "+modelUserData.getData().getUserMobile()+"\nEmail-  "
        +modelUserData.getData().getUserEmail();
        details.setText(detail);
        backIv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                onBackPressed();
            }
        });
        btLog.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                logoutPopupDia();


            }
        });


        btPreviousOrder.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(mContext,ActivityPreviousOrderList.class);
                startActivity(intent);

            }
        });
    }
    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 intent=new Intent(mContext, ActivityLogin.class);
                finish();
                startActivity(intent);

            }
        });


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

            public void onClick(View v) {

                dialog.dismiss();
            }
        });

        dialog.show();
    }
}
