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

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.DialogAskShouldPrintBinding;

public class DialogAskShouldPrint {

    private Dialog currentDialog;

    public static Dialog make(final Context context, final String nomeEtichettaEN, RunnableArgs<Boolean> onDialogDismiss) {
        return new DialogAskShouldPrint(context, nomeEtichettaEN, onDialogDismiss).currentDialog;
    }

    private DialogAskShouldPrint(Context context, String nomeEtichettaEN, RunnableArgs<Boolean> onDialogDismiss) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
        DialogAskShouldPrintBinding bindings = DataBindingUtil.inflate(inflater, R.layout.dialog_ask_should_print, null, false);

        currentDialog = new Dialog(context);
        currentDialog.setContentView(bindings.getRoot());

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

        bindings.descriptionText.setText(String.format(context.getResources().getString(R.string.message_print_packing_list), nomeEtichettaEN));

        bindings.buttonConfirm.setOnClickListener(v -> {
            currentDialog.dismiss();
            onDialogDismiss.run(true);
        });

        bindings.buttonAbort.setOnClickListener(v -> {
            currentDialog.dismiss();
            onDialogDismiss.run(false);
        });

    }

}
