package com.tofly.ghrq_route.common.util;

import android.content.Context;

import androidx.appcompat.app.AlertDialog;

import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.ImageView;

import com.tofly.ghrq_route.R;

import java.util.Objects;

public class Dialogs {

    public static void show(Context context, OnFinishListener onFinishListener) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.dialog);
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_tips, null);
        EditText editText = view.findViewById(R.id.et_search);
        ImageView imageView = view.findViewById(R.id.iv_search);
        builder.setView(view)
                .setCancelable(false);
        AlertDialog dialog = builder.create();
        WindowManager.LayoutParams layoutParams = Objects.requireNonNull(dialog.getWindow()).getAttributes();
        layoutParams.gravity = Gravity.CENTER;
        layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
        layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
        dialog.getWindow().getDecorView().setPadding(0, 0, 0, 0);
        dialog.setCancelable(true);
        dialog.show();
        imageView.setOnClickListener(v -> {
            onFinishListener.onFinish(editText.getText().toString());
            dialog.dismiss();
        });
    }

    public static void show1(Context context, OnFinishListener onFinishListener) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.dialog);
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_tips1, null);
        EditText editText = view.findViewById(R.id.et_search);
        ImageView imageView = view.findViewById(R.id.iv_search);
        builder.setView(view)
                .setCancelable(false);
        AlertDialog dialog = builder.create();
        WindowManager.LayoutParams layoutParams = Objects.requireNonNull(dialog.getWindow()).getAttributes();
        layoutParams.gravity = Gravity.CENTER;
        layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
        layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
        dialog.getWindow().getDecorView().setPadding(0, 0, 0, 0);
        dialog.setCancelable(true);
        dialog.show();
        imageView.setOnClickListener(v -> {
            onFinishListener.onFinish(editText.getText().toString());
            dialog.dismiss();
        });
    }

    public static void show2(Context context, OnFinishListener onFinishListener) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.dialog);
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_tips2, null);
        EditText editText = view.findViewById(R.id.et_search);
        ImageView imageView = view.findViewById(R.id.iv_search);
        builder.setView(view)
                .setCancelable(false);
        AlertDialog dialog = builder.create();
        WindowManager.LayoutParams layoutParams = Objects.requireNonNull(dialog.getWindow()).getAttributes();
        layoutParams.gravity = Gravity.CENTER;
        layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
        layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
        dialog.getWindow().getDecorView().setPadding(0, 0, 0, 0);
        dialog.setCancelable(true);
        dialog.show();
        imageView.setOnClickListener(v -> {
            onFinishListener.onFinish(editText.getText().toString());
            dialog.dismiss();
        });
    }

    public interface OnFinishListener {
        void onFinish(String editText);
    }

}
