package it.integry.integrywmsnative.view.dialogs;

import android.app.Activity;
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.BaseDialog;
import it.integry.integrywmsnative.core.utility.UtilityDialog;
import it.integry.integrywmsnative.databinding.DialogAskActionEditDeleteBinding;

public class DialogAskAction {
    private Activity mContext;
    private Dialog mDialog;
    private Runnable mOnEditSelected;
    private Runnable mOnDeleteSelected;

    private DialogAskAction(Activity context,String title, String subTitle, Runnable onEditSelected, Runnable onDeleteSelected) {
        mContext = context;
        mOnEditSelected = onEditSelected;
        mOnDeleteSelected = onDeleteSelected;

        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        DialogAskActionEditDeleteBinding mBinding = DataBindingUtil.inflate(inflater, R.layout.dialog_ask_action_edit_delete, null, false);
        mBinding.setViewmodel(this);

        mDialog = new BaseDialog(context);
        mDialog.setContentView(mBinding.getRoot());
        UtilityDialog.setTo90PercentWidth(mContext, mDialog);
        mDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

        mBinding.bottomSheetActionsTitle.setText(title);
        mBinding.bottomSheetActionsSubtitle.setText(subTitle);

    }


    public static Dialog make(Activity context, String title, String subtitle, Runnable onEdit, Runnable onDelete) {
        return new DialogAskAction(context, title,subtitle,onEdit,onDelete).mDialog;
    }


    public void onEdit(){
        mDialog.dismiss();
        mOnEditSelected.run();
    }
    public void onDelete(){
        mDialog.dismiss();
        mOnDeleteSelected.run();
    }

}

