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

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

public class NoteAggiuntiveLUDialog {

    private Dialog mDialog;

    public static Dialog make(Context context, final RunnableArgs<String> onComplete, final Runnable onAbort) {
        return new NoteAggiuntiveLUDialog(context, onComplete, onAbort).mDialog;
    }

    private NoteAggiuntiveLUDialog(Context context, final RunnableArgs<String> onComplete, final Runnable onAbort){

        LayoutInflater inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
        DialogNoteAggiuntiveNuovaUlBinding bindings = DataBindingUtil.inflate(inflater, R.layout.dialog_note_aggiuntive_nuova_ul, null, false);

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

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

        bindings.buttonConfirm.setOnClickListener(v -> {
            mDialog.dismiss();
            if(onComplete != null) onComplete.run(bindings.additionalNotesText.getText().toString());
        });

        bindings.buttonAbort.setOnClickListener(v -> {
            mDialog.dismiss();
            if(onAbort != null) onAbort.run();
        });


    }

}
