package com.cpm.lorealbaautomation.constant;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;

import com.google.android.material.snackbar.Snackbar;
import com.cpm.lorealbaautomation.download.DownloadActivity;

import android.content.Intent;
import android.widget.Toast;

import java.util.Objects;


/**
 * Created by jeevanp on 14-12-2017.
 */

public class AlertandMessages {
    public static final String MESSAGE_SOCKETEXCEPTION = "Network Communication Failure. Check Your Network Connection";
    public static void showAlert(final Activity activity, String str, final Boolean activityFinish) {
        try {
            AlertDialog.Builder builder = new AlertDialog.Builder(activity);
            builder.setTitle("Parinaam");
            builder.setMessage(str).setCancelable(false)
                    .setPositiveButton(android.R.string.ok, (dialog, id) -> {
                        if (activityFinish) {
                            activity.finish();
                        } else {
                            dialog.dismiss();
                        }

                    });
            AlertDialog alert = builder.create();
            alert.show();
        } catch (Exception e) {
            e.fillInStackTrace();
        }
    }

    public static void showAlertfordatanotSyncedcompeletetly(final Activity activity, String str, final Boolean activityFinish) {
        try {
            AlertDialog.Builder builder = new AlertDialog.Builder(activity);
            builder.setTitle("Parinaam");
            builder.setMessage(str).setCancelable(false)
                    .setPositiveButton(android.R.string.ok, (dialog, id) -> {
                        if (activityFinish) {
                            activity.finish();
                            activity.startActivity(new Intent(activity, DownloadActivity.class).putExtra(CommonString.TAG_FROM, 1));
                        } else {
                            dialog.dismiss();
                        }

                    });
            AlertDialog alert = builder.create();
            alert.show();
        } catch (Exception e) {
            e.fillInStackTrace();
        }
    }


    public static void showAlertlogin(final Activity activity, String str) {
        try {
            AlertDialog.Builder builder = new AlertDialog.Builder(activity);
            builder.setTitle("Parinaam");
            builder.setMessage(str).setCancelable(false)
                    .setPositiveButton(android.R.string.ok, (dialog, id) -> dialog.dismiss());
            AlertDialog alert = builder.create();
            alert.show();
        } catch (Exception e) {
            e.fillInStackTrace();
        }
    }

    public static void showAlertCounterlogin(final Activity activity, String str) {
        try {
            AlertDialog.Builder builder = new AlertDialog.Builder(activity);
            builder.setTitle("Parinaam");
            builder.setMessage(str).setCancelable(false)
                    .setPositiveButton(android.R.string.ok, (dialog, id) -> {
                        dialog.dismiss();
                        activity.finish();


                    });
            AlertDialog alert = builder.create();
            alert.show();
        } catch (Exception e) {
            e.fillInStackTrace();
        }
    }


    public static void showToastMsg(Context context, String message) {
        Toast.makeText(context, message, Toast.LENGTH_LONG).show();
    }

    public static void showSnackbarMsg(Context context, String message) {
        Snackbar.make(Objects.requireNonNull(((Activity) context).getCurrentFocus()), message, Snackbar.LENGTH_SHORT).show();
    }

    public static void closeApp(final Activity activity, String str) {
        final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        builder.setTitle("Alert");
        builder.setMessage(str).setCancelable(false)
                .setPositiveButton("Ok", (dialog, id) -> {
                    dialog.dismiss();
                    activity.finishAffinity();
                });
        AlertDialog alert = builder.create();
        alert.show();
    }
}
