package it.integry.integrywmsnative.gest.prod_recupero_materiale.views;

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

import androidx.databinding.DataBindingUtil;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import it.integry.integrywmsnative.R;
import it.integry.integrywmsnative.core.expansion.RunnableArgs;
import it.integry.integrywmsnative.core.model.MtbAart;
import it.integry.integrywmsnative.core.model.MtbTCol;
import it.integry.integrywmsnative.core.rest.consumers.MagazzinoRESTConsumer;
import it.integry.integrywmsnative.core.utility.UtilityExceptions;
import it.integry.integrywmsnative.core.utility.UtilityProgress;
import it.integry.integrywmsnative.databinding.DialogInputQuantityToReturnBinding;

public class InputQuantityToReturnDialog {


    private Context mContext;

    private Dialog currentDialog;

    public static Dialog make(final Context context, MtbAart mtbAart, BigDecimal minQuantity, BigDecimal maxQuantity, RunnableArgs<BigDecimal> onDialogDismiss) {
        return new InputQuantityToReturnDialog(context, mtbAart, minQuantity, maxQuantity, onDialogDismiss).currentDialog;
    }

    private InputQuantityToReturnDialog(Context context, MtbAart mtbAart, BigDecimal minQuantity, BigDecimal maxQuantity, RunnableArgs<BigDecimal> onDialogDismiss) {
        this.mContext = context;

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

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

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

        InputQuantityToReturnViewModel viewModel = new InputQuantityToReturnViewModel();
        viewModel.setMtbAart(mtbAart)
                .setMinQuantity(minQuantity)
                .setMaxQuantity(maxQuantity);

        bindings.setMViewModel(viewModel);

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

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

    }


    public class InputQuantityToReturnViewModel {

        public MtbAart mtbAart;
        public BigDecimal minQuantity;
        public BigDecimal maxQuantity;

        public MtbAart getMtbAart() {
            return mtbAart;
        }

        public InputQuantityToReturnViewModel setMtbAart(MtbAart mtbAart) {
            this.mtbAart = mtbAart;
            return this;
        }

        public BigDecimal getMinQuantity() {
            return minQuantity;
        }

        public InputQuantityToReturnViewModel setMinQuantity(BigDecimal minQuantity) {
            this.minQuantity = minQuantity;
            return this;
        }

        public BigDecimal getMaxQuantity() {
            return maxQuantity;
        }

        public InputQuantityToReturnViewModel setMaxQuantity(BigDecimal maxQuantity) {
            this.maxQuantity = maxQuantity;
            return this;
        }
    }


}