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

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.applovin.mediation.ads.MaxAdView;
import com.applovin.mediation.ads.MaxInterstitialAd;
import com.applovin.sdk.AppLovinSdk;
import com.facebook.ads.AudienceNetworkAds;
import com.newloanapp.instantloanapp.loancash.loanguide.loanapp.personalloanapply.loan.star.loanapply.CircleImageView;
import com.newloanapp.instantloanapp.loancash.loanguide.loanapp.personalloanapply.loan.star.loanapply.R;
import com.squareup.picasso.Picasso;

public class LoanDetailsActivity extends AppCompatActivity {

    private MaxInterstitialAd interstitialAd;
    public static LoanListActivity.Loan loan;

    @Override
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity_loan_details);
        AudienceNetworkAds.initialize(this);
        AppLovinSdk.getInstance( this ).setMediationProvider("max");
        AppLovinSdk.initializeSdk( this, configuration -> {
            MaxAdView maxAdView = new MaxAdView(getString(R.string.banner_id),this);
            ((LinearLayout)findViewById(R.id.adView)).addView(maxAdView);
            maxAdView.loadAd();
        });
        interstitialAd = new MaxInterstitialAd(getString(R.string.interstitial_id),this);
        interstitialAd.loadAd();
        CircleImageView dp = findViewById(R.id.companyLogo);
        Picasso.get().load(loan.getImage()).fit().into(dp);
        ((TextView)findViewById(R.id.companyName)).setText(loan.getName());
        ((TextView)findViewById(R.id.LoanAmount)).setText(loan.getAmount());
        ((TextView)findViewById(R.id.timePeriod)).setText(loan.getTime());
        ((TextView)findViewById(R.id.interestRate)).setText(loan.getInterest());
        ((TextView)findViewById(R.id.loanProcessingTime)).setText(loan.getProcess());
        ((TextView)findViewById(R.id.eligibility)).setText(loan.getIdentity());
        ((TextView)findViewById(R.id.proofOfAddress)).setText(loan.getAddress());
        ((TextView)findViewById(R.id.proofOfIdentity)).setText(loan.getIdentity());
        ((TextView)findViewById(R.id.incomeProof)).setText(loan.getIncome());
        ((TextView)findViewById(R.id.bankAccount)).setText(loan.getBank());
        ((TextView)findViewById(R.id.loanTerms)).setText(loan.getLoanterm());
        if (loan != null && !loan.getUrl().equals("")) {
            findViewById(R.id.applyBtn).setOnClickListener(view -> {
                if(interstitialAd.isReady()) {
                    interstitialAd.showAd();
                } else {
                    startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(loan.getUrl())));
                }
            });
        } else {
            Toast.makeText(this,"App not available right now",Toast.LENGTH_SHORT).show();
        }
    }
}
