package com.newloanapp.instantloanapp.loancash.loanguide.loanapp.personalloanapply.loan.star.loanapply;

import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Constant {
    public static final String BASE_URL = "https://iplevent.com/Loanapp/";
    public static final String CATEGORY_URL = Constant.BASE_URL + "api.php?cat=true";
    public static final String SLIDER_URL = Constant.BASE_URL + "api.php?slider=true";
    public static final String LOANLIST_URL = Constant.BASE_URL + "api.php?detail=true&c_id=";
    public static final String[] titleList = new String[]{"Read, Share Shayari & Earn Money","Festy Wish Every Festival To Your Friend & Family","StudyMasterGK General Knowledge - সাধারণ জ্ঞান","MakeEasy - Free Android Studio & AIA Project File"};
    public static final int[] logoList = new int[]{R.drawable.quotes,R.drawable.festy,R.drawable.gk,R.drawable.me};
    public static final int[] bannerList = new int[]{R.drawable.qbnr,R.drawable.festybanner,R.drawable.gkbanner,R.drawable.mebanner};
    public static final String[] linkList = new String[]{"com.friendvilla.quotes","com.friendvilla.FestyPro","com.friendvilla.studymastergk","com.friendvilla.MakeEasy"};
    public static Ads HomeAdsInitialization() {
        List<Ads> adsList = new ArrayList<>();
        for(int i = 0; i < titleList.length; i++) {
            adsList.add(new Ads(titleList[i],logoList[i],bannerList[i],linkList[i]));
        }
        return adsList.get(new Random().nextInt(titleList.length));
    }
    public static class Ads {
        private final String title;
        private final int logo;
        private final int banner;
        private final String link;

        public Ads(String title, int logo, int banner, String link) {
            this.title = title;
            this.logo = logo;
            this.banner = banner;
            this.link = link;
        }

        public String getTitle() {
            return title;
        }

        public int getLogo() {
            return logo;
        }

        public int getBanner() {
            return banner;
        }

        public String getLink() {
            return link;
        }
    }
    public static void sendMail(Context ctx) {
        Intent putExtra = new Intent(Intent.ACTION_SENDTO)
                .setData(new Uri.Builder().scheme("mailto").build())
                .putExtra(Intent.EXTRA_EMAIL,new String[]{"LoanApp Admin <loantimeoffical@gmail.com>"})
                .putExtra(Intent.EXTRA_SUBJECT,"Hello")
                .putExtra(Intent.EXTRA_TEXT, "I need some help regarding");
        ComponentName resolveActivity = putExtra.resolveActivity(ctx.getPackageManager());
        ComponentName unflattenFromString = ComponentName.unflattenFromString("com.android.fallback/.Fallback");
        if (resolveActivity != null && !resolveActivity.equals(unflattenFromString)) {
            try {
                ctx.startActivity(Intent.createChooser(putExtra, "Send email with"));
                return;
            } catch (ActivityNotFoundException e) {
                e.fillInStackTrace();
            }
        }
        Toast.makeText(ctx,"Couldn't find an email app and account",Toast.LENGTH_SHORT).show();
    }
}
