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

import android.content.DialogInterface;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;

import org.jetbrains.annotations.NotNull;

import it.integry.integrywmsnative.R;
import it.integry.integrywmsnative.core.expansion.BaseDialogFragment;
import it.integry.integrywmsnative.core.expansion.RunnableArgs;
import it.integry.integrywmsnative.databinding.DialogAskShouldVersamentoAutomaticoUlBinding;

public class DialogAskShouldVersamentoAutomaticoULView extends BaseDialogFragment {

    private RunnableArgs<Boolean> mOnDismiss;
    private DialogAskShouldVersamentoAutomaticoUlBinding mBindings;

    private boolean returnValue = false;

    public static DialogAskShouldVersamentoAutomaticoULView newInstance(@NotNull RunnableArgs<Boolean> onDismiss) {
        return new DialogAskShouldVersamentoAutomaticoULView(onDismiss);
    }

    private DialogAskShouldVersamentoAutomaticoULView(@NotNull RunnableArgs<Boolean> onDismiss) {
        super();

        this.mOnDismiss = onDismiss;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mBindings = DataBindingUtil.inflate(inflater, R.layout.dialog_ask_should_versamento_automatico_ul, container, false);
        mBindings.setLifecycleOwner(this);

        getDialog().setCanceledOnTouchOutside(false);
        getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

        mBindings.setView(this);

        return mBindings.getRoot();
    }

    @Override
    public void onDismiss(@NonNull DialogInterface dialog) {
        super.onDismiss(dialog);

        if (mOnDismiss != null) {
            this.mOnDismiss.run(returnValue);
        }
    }


    public void confirm() {
        this.returnValue = true;
        dismiss();
    }

    public void abort() {
        this.returnValue = false;
        dismiss();
    }

}
