package com.swiftcleaner.chovey.view.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.widget.ImageView;

import androidx.appcompat.widget.AppCompatButton;
import androidx.cardview.widget.CardView;

import com.swiftcleaner.chovey.R;
import com.tool.zxdemo.utils.NativeView;
import com.zxdemo.admob.AdmobHelper;

public class AppExitDialog extends Dialog {

    private Activity activity;
    private OnDialogClickListener listener;

    public interface OnDialogClickListener {
        void onCancel();

        void onSubmit();
    }

    public AppExitDialog(Activity activity) {
        super(activity, R.style.TransparentDialogTheme);
        this.activity = activity;
        setContentView(R.layout.dialog_app_exit_item);

        AppCompatButton dialog_exit = findViewById(R.id.dialog_exit);
        AppCompatButton dialog_experience = findViewById(R.id.dialog_experience);
        ImageView iv_dialog_close = findViewById(R.id.iv_dialog_close);
        CardView cardView = findViewById(R.id.cardview);
        cardView.setCardBackgroundColor(Color.TRANSPARENT);

        dialog_exit.setOnClickListener(v -> {
            if (listener != null) {
                listener.onCancel();
            }
            dismiss();
        });

        dialog_experience.setOnClickListener(v -> {
            if (listener != null) {
                listener.onSubmit();
            }
            dismiss();
        });
        iv_dialog_close.setOnClickListener(v -> {
            dismiss();
        });
        setCanceledOnTouchOutside(false);

        NativeView nativeView = findViewById(R.id.fl_ad);
        AdmobHelper.INSTANCE.showNativeAd(activity, (nativeAd) -> {
            nativeView.removeAllViews();
            nativeView.setNativeAd(nativeAd, R.layout.layout_ad_native);
            return null;
        }, null, null);
    }

    public void show() {
        super.show();
    }

    public void setOnDialogClickListener(OnDialogClickListener listener) {
        this.listener = listener;
    }
}