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

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

import androidx.appcompat.app.AlertDialog;
import androidx.databinding.DataBindingUtil;
import it.integry.integrywmsnative.R;
import it.integry.integrywmsnative.databinding.DialogExceptionBinding;

public class DialogException {

    private Context mContext;
    private DialogExceptionBinding mBinding;
    private AlertDialog mAlert;

    private Runnable mOnConfirm;


    public static AlertDialog make(Context context, Runnable onConfirm) {
        return new DialogException(context, onConfirm).mAlert;
    }

    public DialogException(Context context, Runnable onConfirm) {
        mContext = context;
        mOnConfirm = onConfirm;

        LayoutInflater inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );

        mBinding = DataBindingUtil.inflate(inflater, R.layout.dialog_exception, null, false);

        final AlertDialog.Builder alertDialog = new AlertDialog.Builder(context)
                .setView(mBinding.getRoot());

        mAlert = alertDialog.create();
        mAlert.setCanceledOnTouchOutside(false);
        mAlert.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));


        mBinding.buttonConfirm.setOnClickListener(v -> {
            onConfirm.run();
            mAlert.dismiss();
        });
    }


}
