package com.makeeasy.dpandstatus.sheets;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.Nullable;

import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
import com.google.android.play.core.review.ReviewManager;
import com.google.android.play.core.review.ReviewManagerFactory;
import com.makeeasy.dpandstatus.R;

public class ExitSheet extends BottomSheetDialogFragment {

    private final Activity ctx;
    private final ReviewManager reviewManager;
    public ExitSheet(Activity ctx) {
        this.ctx = ctx;
        reviewManager = ReviewManagerFactory.create(ctx);
    }
    @SuppressLint("SetTextI18n")
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.exit,container,false);
        setStyle(BottomSheetDialogFragment.STYLE_NORMAL,R.style.CustomSheet);
        v.findViewById(R.id.txt_rate).setOnClickListener(view -> {
            dismiss();
            reviewManager.requestReviewFlow().addOnCompleteListener(tasked -> {
                if (tasked.isSuccessful()) {
                    reviewManager.launchReviewFlow(ctx,tasked.getResult()).addOnCompleteListener(task -> ctx.finish());
                    return;
                }
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + ctx.getPackageName())));
            });
        });
        v.findViewById(R.id.txt_later).setOnClickListener(view -> {
            dismiss();ctx.finish();
        });
        setCancelable(true);
        return v;
    }
}