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

import android.app.Dialog;
import android.content.Context;
import android.content.res.ColorStateList;
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.core.utility.UtilityDialog;
import it.integry.integrywmsnative.databinding.DialogInputGeneralBinding;

/**
 * Created by GiuseppeS on 22/03/2018.
 */

public class DialogSimpleInputHelper {


    private static Dialog makeBase(Context mContext, String titleText, RunnableArgs<String> onPositiveClick, Runnable onNegativeClick){
        Dialog dialog = new Dialog(mContext);
        DialogSimpleInputViewModel viewModel = new DialogSimpleInputViewModel(dialog);



        DialogInputGeneralBinding mBinding = DataBindingUtil.inflate(LayoutInflater.from(mContext), R.layout.dialog_input_general, null, false);
        viewModel
                .setOnPositive(()->{

                    onPositiveClick.run(mBinding.generalInput.getText().toString());
                })
                .setOnNegative(onNegativeClick);

        mBinding.setViewmodel(viewModel);

        //Title VIEW
        mBinding.titleText.setText(titleText);
        ColorStateList colorStateList = ColorStateList.valueOf(Color.WHITE);

        //Content View
        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(false);
        dialog.setContentView(mBinding.getRoot());
        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        UtilityDialog.setTo90PercentWidth(mContext,dialog);

        return dialog;
    }


    public static Dialog makeInputDialog(Context mContext, String title, RunnableArgs<String> onPositiveClick, Runnable onNegativeClick){

        return makeBase(mContext,
                title,
                onPositiveClick,
                onNegativeClick);

    }



}
