package com.app.rewardapp.util;

import static com.ads.androidsdk.sdk.util.Tool.encrypt_code;
import static com.ads.androidsdk.sdk.util.Tool.md5;
import static com.app.rewardapp.util.Const.getAK;
import static com.app.rewardapp.util.Const.getAV;

import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import androidx.appcompat.app.AlertDialog;
import androidx.browser.customtabs.CustomTabsIntent;
import androidx.core.content.ContextCompat;

import com.ads.androidsdk.sdk.util.Base64;
import com.ads.androidsdk.sdk.util.Tool;
import com.app.rewardapp.BuildConfig;
import com.app.rewardapp.R;
import com.app.rewardapp.restApi.ApiClient;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.Random;


import de.mateware.snacky.Snacky;

public class Fun {
	public static AlertDialog win_dialog;
	private static int getRandom() {
		Random random = new Random();
		return random.nextInt(900);
	}

	public static String data(String s1, String s2, String s3, String s4, String s5, String s6, int i, int i1, String i2){
		String s= ""+ getRandom();
		JsonObject jsObj = (JsonObject) new Gson().toJsonTree(new ApiClient());
		switch (i){
			case 0:
				jsObj.addProperty("name",s1);
				jsObj.addProperty("email",s2);
				jsObj.addProperty("password",s3);
				jsObj.addProperty("phone",s4);
				jsObj.addProperty("token",s5);
				jsObj.addProperty("refferal_id",s6);
				break;

			case 1:
				jsObj.addProperty("email",s2);
				jsObj.addProperty("password",s3);
				jsObj.addProperty("randomString",s4);
				break;

			case 2:
				jsObj.addProperty("Reqtype",s1);
				jsObj.addProperty("require",s2);
				jsObj.addProperty("amount",s3);
				jsObj.addProperty("detail",s4);
				jsObj.addProperty("data",s5);
				break;

			case 3:
				jsObj.addProperty("name",s1);
				jsObj.addProperty("email",s2);
				jsObj.addProperty("google",s3);
				jsObj.addProperty("profile",s4);
				jsObj.addProperty("token",s5);
				jsObj.addProperty("refferal_id",s6);
				break;
		}

		jsObj.addProperty("id",i1);
		jsObj.addProperty("ex_id",i2);
		jsObj.addProperty("ex",s1);
		jsObj.addProperty("type",i);
		jsObj.addProperty("i4",s);
		return Base64.encrypt(getAK(),getAV(),jsObj.toString());
	}

	public static void Error(Activity ctx, String msg) {
		Snacky.builder()
				.setActivity(ctx)
				.setText(msg)
				.setDuration(6000)
				.error()
				.show();
	}
	public static void Success(Activity ctx, String msg) {
		Snacky.builder()
				.setActivity(ctx)
				.setText(msg)
				.setDuration(6000)
				.success()
				.show();
	}

	public static AlertDialog loading(Context context) {
		AlertDialog dialog = new AlertDialog.Builder(context).setView(LayoutInflater.from(context).inflate(R.layout.progress_dialog, null)).create();
		dialog.getWindow().setBackgroundDrawableResource(R.color.transparent);
		dialog.getWindow().setWindowAnimations(R.style.Dialoganimation);
		dialog.setCanceledOnTouchOutside(false);
		Window w = dialog.getWindow();
		if (w != null) {
			w.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
			w.setNavigationBarColor(ContextCompat.getColor(context, R.color.colorPrimaryDark));
		}
		return dialog;
	}

	public static AlertDialog Alert(Context context) {
		AlertDialog dialog = new AlertDialog.Builder(context).setView(LayoutInflater.from(context).inflate(R.layout.layout_alert, null)).create();
		dialog.getWindow().setBackgroundDrawableResource(R.color.transparent);
		dialog.getWindow().setWindowAnimations(R.style.Dialoganimation);
		dialog.setCanceledOnTouchOutside(false);
		Window w = dialog.getWindow();
		if (w != null) {
			w.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
			w.setNavigationBarColor(ContextCompat.getColor(context, R.color.colorPrimaryDark));
		}
		return dialog;
	}

	public static void launchCustomTabs(Activity activity, String url) {
		CustomTabsIntent.Builder customIntent = new CustomTabsIntent.Builder();
		customIntent.setToolbarColor(ContextCompat.getColor(activity, R.color.colorPrimary));
		customIntent.setExitAnimations(activity, R.anim.exit, R.anim.enter);
		customIntent.setStartAnimations(activity, R.anim.enter, R.anim.exit);
		customIntent.setUrlBarHidingEnabled(true);
		customIntent.build().launchUrl(activity, Uri.parse(url));
	}

}
