package it.integry.integrywmsnative.view.dialogs.yes_no;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;

import androidx.databinding.DataBindingUtil;
import it.integry.integrywmsnative.R;
import it.integry.integrywmsnative.core.expansion.RunnableArgs;
import it.integry.integrywmsnative.databinding.DialogYesNoBinding;
import it.integry.integrywmsnative.view.dialogs.DialogConsts;

public class DialogYesNo {

    private Dialog currentDialog;

    public static Dialog make(final Context context, final String title, final String description, RunnableArgs<DialogConsts.Results> onDialogDismiss) {
        return new DialogYesNo(context, title, description, onDialogDismiss).currentDialog;
    }

    private DialogYesNo(Context context, String title, String description, RunnableArgs<DialogConsts.Results> onDialogDismiss) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
        DialogYesNoBinding bindings = DataBindingUtil.inflate(inflater, R.layout.dialog_yes_no, null, false);

        currentDialog = new Dialog(context);

        currentDialog.setContentView(bindings.getRoot());

        currentDialog.setCancelable(false);
        currentDialog.setCanceledOnTouchOutside(false);
        currentDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

        bindings.titleText.setText(title);
        bindings.descriptionText.setText(description);

        bindings.buttonYes.setOnClickListener(v -> {
            onDialogDismiss.run(DialogConsts.Results.YES);
            currentDialog.dismiss();
        });

        bindings.buttonNo.setOnClickListener(v -> {
            onDialogDismiss.run(DialogConsts.Results.NO);
            currentDialog.dismiss();
        });


    }


}
