package it.integry.integrywmsnative.gest.rettifica_giacenze.viewmodel;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.res.Resources;
import androidx.databinding.ObservableArrayList;
import androidx.databinding.ObservableField;
import androidx.annotation.NonNull;
import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.google.android.material.textfield.TextInputLayout;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import android.text.SpannableString;
import android.view.View;
import android.view.inputmethod.EditorInfo;

import com.annimon.stream.Stream;

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

import it.integry.integrywmsnative.MainActivity;
import it.integry.integrywmsnative.R;
import it.integry.integrywmsnative.core.REST.CommonRESTException;
import it.integry.integrywmsnative.core.REST.consumers.ColliMagazzinoRESTConsumer;
import it.integry.integrywmsnative.core.REST.consumers.ISimpleOperationCallback;
import it.integry.integrywmsnative.core.REST.consumers.ISingleValueOperationCallback;
import it.integry.integrywmsnative.core.REST.consumers.PrinterRESTConsumer;
import it.integry.integrywmsnative.core.barcode_reader.BarcodeManager;
import it.integry.integrywmsnative.core.di.BindableBoolean;
import it.integry.integrywmsnative.core.expansion.RunnableArgs;
import it.integry.integrywmsnative.core.interfaces.IRecyclerItemClicked;
import it.integry.integrywmsnative.core.model.CommonModelConsts;
import it.integry.integrywmsnative.core.model.MtbAart;
import it.integry.integrywmsnative.core.model.MtbColr;
import it.integry.integrywmsnative.core.model.MtbCols;
import it.integry.integrywmsnative.core.model.MtbColt;
import it.integry.integrywmsnative.core.report.ReportManager;
import it.integry.integrywmsnative.core.settings.SettingsManager;
import it.integry.integrywmsnative.core.utility.UtilityExceptions;
import it.integry.integrywmsnative.core.utility.UtilityLogger;
import it.integry.integrywmsnative.core.utility.UtilityNumber;
import it.integry.integrywmsnative.core.utility.UtilityProgress;
import it.integry.integrywmsnative.core.utility.UtilityString;
import it.integry.integrywmsnative.databinding.FragmentMainRettificaGiacenzeBinding;
import it.integry.integrywmsnative.gest.rettifica_giacenze.core.RettificaGiacenzeHelper;
import it.integry.integrywmsnative.gest.rettifica_giacenze.core.adapter.AutoCompleteFornitoreAdapter;
import it.integry.integrywmsnative.gest.rettifica_giacenze.core.adapter.RettificaGiacenzeMainListAdapter;
import it.integry.integrywmsnative.gest.rettifica_giacenze.dto.FornitoreDTO;
import it.integry.integrywmsnative.ui.StatusBarAlert;
import it.integry.integrywmsnative.view.dialogs.DialogSimpleMessageHelper;
import it.integry.integrywmsnative.view.dialogs.ask_position_of_lu.DialogAskPositionOfLU;
import it.integry.integrywmsnative.view.dialogs.choose_art_from_lista_arts.DialogChooseArtFromListaArts;
import it.integry.integrywmsnative.view.dialogs.input_quantity.DialogInputQuantity;
import it.integry.integrywmsnative.view.dialogs.input_quantity.QuantityDTO;
import it.integry.integrywmsnative.view.dialogs.scan_or_create_lu.DialogScanOrCreateLU;
import it.integry.plugins.barcode_base_library.model.BarcodeScanDTO;
import it.integry.plugins.barcode_base_library.model.BarcodeType;

public class RettificaGiacenzeViewModel implements IRecyclerItemClicked<MtbColr> {

    private Activity mContext;
    private FragmentMainRettificaGiacenzeBinding mBinding;

    private BottomSheetBehavior mBottomSheetBehavior;

    private RettificaGiacenzeHelper mHelper;
    private RettificaGiacenzeMainListAdapter mAdapter;

    public ObservableField<MtbColt> mtbColt = new ObservableField<>();
    public BindableBoolean isFabVisible = new BindableBoolean();
    public BindableBoolean isMtbColtLoaded = new BindableBoolean();



    public void init(Activity context, FragmentMainRettificaGiacenzeBinding binding, RettificaGiacenzeHelper helper) {
        mContext = context;
        mBinding = binding;
        mHelper = helper;
    }

    public void setMtbColt(MtbColt mtbColt) {
        this.mtbColt.set(mtbColt);

        isFabVisible.set(mtbColt != null);
        isMtbColtLoaded.set(mtbColt != null);

        if(this.mtbColt.get().getMtbColr() == null) this.mtbColt.get().setMtbColr(new ObservableArrayList<>());
        else {
            ObservableArrayList<MtbColr> mtbColrList = this.mtbColt.get().getMtbColr();

            for(int i = 0; i < mtbColrList.size(); i++) {
                if(mtbColrList.get(i).getQtaCol() == null || mtbColrList.get(i).getQtaCol().floatValue() < 0){
                    mtbColrList.remove(i);
                    i--;
                }
            }

        }


        initRecyclerView();
        initBottomSheetActions();
    }

    public void resetMtbColt(boolean openNew) {
        this.mtbColt.set(null);
        isFabVisible.set(false);
        isMtbColtLoaded.set(false);
        mBinding.rettificaGiacenzeMainList.setAdapter(null);

        if(openNew) openLU();
    }


    private void initRecyclerView() {
        mBinding.rettificaGiacenzeMainList.setNestedScrollingEnabled(false);

        mBinding.rettificaGiacenzeMainList.setHasFixedSize(true);

        mBinding.rettificaGiacenzeMainList.setLayoutManager(new LinearLayoutManager(mContext));

        DividerItemDecoration itemDecorator = new DividerItemDecoration(mContext, DividerItemDecoration.VERTICAL);
        itemDecorator.setDrawable(ContextCompat.getDrawable(mContext, R.drawable.divider));
        mBinding.rettificaGiacenzeMainList.addItemDecoration(itemDecorator);

        mAdapter = new RettificaGiacenzeMainListAdapter(mContext, mtbColt.get().getMtbColr(), this, mBinding.rettificaGiacenzeEmptyView);
        mBinding.rettificaGiacenzeMainList.setAdapter(mAdapter);
    }

    private void initBottomSheetActions() {
        mBinding.bg.setOnClickListener(v -> mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED));

        mBottomSheetBehavior = BottomSheetBehavior.from(mBinding.bottomSheetActions);

        mBottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
            @Override
            public void onStateChanged(@NonNull View bottomSheet, int newState) {
                if (newState == BottomSheetBehavior.STATE_COLLAPSED)
                    mBinding.bg.setVisibility(View.GONE);
            }

            @Override
            public void onSlide(@NonNull View bottomSheet, float slideOffset) {
                mBinding.bg.setVisibility(View.VISIBLE);
                mBinding.bg.setAlpha(slideOffset);
            }
        });
    }

    public RunnableArgs<BarcodeScanDTO> onScanSuccessfull = data -> {

        BarcodeManager.disable();

        if(data.getType() == BarcodeType.EAN8 || data.getType() == BarcodeType.EAN13 || data.getType() == BarcodeType.UPCA){
            searchArtInt(data.getStringValue());
        } else {
            BarcodeManager.enable();
        }

    };


    public void setupSearchFornitori(ArrayList<FornitoreDTO> listaFornitori) {
        AutoCompleteFornitoreAdapter autoCompleteFornitoreAdapter = new AutoCompleteFornitoreAdapter(mContext, listaFornitori);
        mBinding.autoCompleteFornitori.setAdapter(autoCompleteFornitoreAdapter);
        mBinding.autoCompleteFornitori.setDropDownWidth(mContext.getResources().getDisplayMetrics().widthPixels);

        mBinding.inputCodArtDescrForn.setOnEditorActionListener((v, actionId, event) -> {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                resetAllError();
                if(UtilityString.isNullOrEmpty(mBinding.autoCompleteFornitori.getText().toString())) {
                    setError(mBinding.autoCompleteFornitoriLayout, mContext.getResources().getText(R.string.error).toString());
                    return true;
                }

                if(UtilityString.isNullOrEmpty(mBinding.inputCodArtDescrForn.getText().toString())) {
                    setError(mBinding.layoutCodArtDescrForn, mContext.getResources().getText(R.string.error).toString());
                    return true;
                }

                searchArtFor(
                        mBinding.autoCompleteFornitori.getText().toString(),
                        mBinding.inputCodArtDescrForn.getText().toString());
                return true;
            }
            return false;
        });


        mBinding.inputCodArtDescrInt.setOnEditorActionListener((v, actionId, event) -> {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                resetAllError();

                if(UtilityString.isNullOrEmpty(mBinding.inputCodArtDescrInt.getText().toString())) {
                    setError(mBinding.layoutCodArtDescrInt, mContext.getResources().getText(R.string.error).toString());
                    return true;
                }

                searchArtInt(mBinding.inputCodArtDescrInt.getText().toString());
                return true;
            }
            return false;
        });
    }


    private void setError(TextInputLayout textInputLayout, String message){
        textInputLayout.setErrorEnabled(true);
        textInputLayout.setError(message);
    }

    private void resetAllError() {
        resetError(mBinding.autoCompleteFornitoriLayout);
        resetError(mBinding.layoutCodArtDescrForn);
        resetError(mBinding.layoutCodArtDescrInt);
    }

    private void resetTexts() {
        //mBinding.autoCompleteFornitori.setText("");
        mBinding.inputCodArtDescrForn.setText("");
        mBinding.inputCodArtDescrInt.setText("");
}

    private void resetError(TextInputLayout textInputLayout) {
        textInputLayout.setErrorEnabled(false);
        textInputLayout.setError(null);
    }

    private void searchArtFor(String codAlis, String queryText) {
        final ProgressDialog progressDialog = UtilityProgress.createDefaultProgressDialog(mContext);
        //progressDialog.show();

        mHelper.searchArtForn(codAlis, queryText, listaArts -> {
            progressDialog.dismiss();

            List<MtbAart> mtbAarts = Stream.of(listaArts).map(x -> (MtbAart) x).toList();

            dispatchArtsList(mtbAarts);
        }, ex -> UtilityExceptions.defaultException(mContext, ex, progressDialog));
    }

    private void searchArtInt(String queryText) {
        final ProgressDialog progressDialog = UtilityProgress.createDefaultProgressDialog(mContext);
        //progressDialog.show();

        mHelper.searchArtInt(queryText, listaArts -> {
            progressDialog.dismiss();
            BarcodeManager.enable();
            dispatchArtsList(listaArts);
        }, ex -> {
            UtilityExceptions.defaultException(mContext, ex, progressDialog);
            BarcodeManager.enable();
        });
    }


    private void dispatchArtsList(List<MtbAart> articoloFornitoreDTOS){

        if(articoloFornitoreDTOS != null){
            if(articoloFornitoreDTOS.size() == 0) {
                showNoArtsFound();
            } else if(articoloFornitoreDTOS.size() == 1) {
                dispatchArt(articoloFornitoreDTOS.get(0));
            } else {
                DialogChooseArtFromListaArts.make(mContext, articoloFornitoreDTOS, this::dispatchArt).show();
            }
        } else {
            showNoArtsFound();
        }
    }

    private void showNoArtsFound() {
        DialogSimpleMessageHelper.makeWarningDialog(mContext,
                new SpannableString(mContext.getResources().getText(R.string.no_items_found_message)),
                null, null).show();
    }


    private void dispatchArt(MtbAart mtbAart){
        DialogInputQuantity.DTO qtaDto = new DialogInputQuantity.DTO();

        qtaDto.setMtbAart(mtbAart);

        qtaDto.setQtaCnf(mtbAart.getQtaCnf());
        qtaDto.setNumCnf(1);
        qtaDto.setQtaTot(mtbAart.getQtaCnf());

        qtaDto.setQtaDaEvadere(new BigDecimal(-1));
        qtaDto.setQtaDisponibile(new BigDecimal(-1));

        qtaDto.setCanPartitaMagBeChanged(true);
        qtaDto.setCanDataScadBeChanged(true);


        DialogInputQuantity.makeBase(mContext, qtaDto, true, (quantityDTO) -> {
            onPostDispatch(mtbAart, quantityDTO);
        }).show();
    }



    private void onPostDispatch(MtbAart mtbAart, QuantityDTO quantityDTO) {

        final ProgressDialog progress = ProgressDialog.show(mContext, mContext.getText(R.string.waiting),
                mContext.getText(R.string.loading) + " ...", true);

        final MtbColr mtbColr = new MtbColr()
                .setCodMart(mtbAart.getCodMart())
                .setPartitaMag(quantityDTO.batchLot.get())
                .setDataScadPartita(quantityDTO.expireDate)
                .setQtaCol(new BigDecimal(quantityDTO.qtaTot.get()))
                .setDescrizione(mtbAart.getDescrizioneEstesa());

        mtbColr.setOperation(CommonModelConsts.OPERATION.INSERT_OR_UPDATE);

        MtbColt cloneMtbColt = (MtbColt) mtbColt.get().clone();
        cloneMtbColt.setOperation(CommonModelConsts.OPERATION.NO_OP);

        cloneMtbColt.setMtbColr(new ObservableArrayList());
        cloneMtbColt.getMtbColr().add(mtbColr);

        ColliMagazzinoRESTConsumer.saveCollo(cloneMtbColt, new ISimpleOperationCallback<MtbColt>() {
            @Override
            public void onSuccess(MtbColt value) {

                mtbColr
                        .setDataCollo(value.getDataColloS())
                        .setNumCollo(value.getNumCollo())
                        .setGestione(value.getGestione())
                        .setSerCollo(value.getSerCollo())
                        .setRiga(value.getMtbColr().get(0).getRiga())
                        .setUntMis(mtbAart.getUntMis())
                        .setMtbAart(mtbAart);

                mtbColt.get().getMtbColr().add(mtbColr);

                new StatusBarAlert.Builder(mContext)
                        .autoHide(true)
                        .withDuration(2500)
                        .showProgress(false)
                        .withText(R.string.data_saved)
                        .withAlertColor(R.color.mainGreen)
                        .build();

                resetTexts();
                progress.dismiss();
            }

            @Override
            public void onFailed(Exception ex) {
                UtilityExceptions.defaultException(mContext, ex, progress);
            }
        });

    }




    @Override
    public void onItemClick(MtbColr item, int position) {
        mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);

        MtbColr clickedItem = mtbColt.get().getMtbColr().get(position);

        mBinding.bottomSheetActionsTitle.setText(clickedItem.getDescrizione());
        mBinding.bottomSheetActionsSubtitle.setText(clickedItem.getCodMart());

        mBinding.bottomSheetActionsEditBtn.setOnClickListener(v -> onItemEdit(item, position));
        mBinding.bottomSheetActionsDeleteBtn.setOnClickListener(v -> onItemDelete(item));

        mBinding.bottomSheetActionsQuantity.setText(UtilityNumber.decimalToString(clickedItem.getQtaCol()) +  " " + clickedItem.getMtbAart().getUntMis());
    }

    public void openLU() {
        DialogScanOrCreateLU.make(mContext, mtbColt -> {
            if(mtbColt == null) {
                ((MainActivity)mContext).popToMain();
            } else {
                setMtbColt(mtbColt);
            }
        }).show();
    }

    public boolean thereIsAnOpenedUL() {
        return mtbColt.get() != null;
    }
    public boolean thereIsAnyRowInUL() {
        return mtbColt.get() != null &&
                mtbColt.get().getMtbColr() != null &&
                mtbColt.get().getMtbColr().size() > 0;
    }

    public void closeLU(boolean openNewOne, boolean saveCausale) {

        if(thereIsAnOpenedUL()) {

            final ProgressDialog progress = ProgressDialog.show(mContext, mContext.getText(R.string.waiting),
                    mContext.getText(R.string.loading) + " ...", true);

            if (thereIsAnyRowInUL()) {

                if (!UtilityString.isNullOrEmpty(SettingsManager.iDB().getDefaultCausaleRettificaGiacenze()) && saveCausale) {
                    posizionaCollo(() ->
                        saveCausaleRettificaGiacenze(progress, () -> {
                            if (!mtbColt.get().getDisablePrint()) {
                                printCollo(progress);
                            } else {
                                progress.dismiss();
                                resetMtbColt(openNewOne);
                            }
                    }), progress::dismiss, ex ->
                        UtilityExceptions.defaultException(mContext, ex, progress)
                    );

                } else {
                    posizionaCollo(() -> {
                        if (!mtbColt.get().getDisablePrint()) {
                            printCollo(progress);
                        } else {
                            resetMtbColt(openNewOne);
                        }
                    }, progress::dismiss, ex -> UtilityExceptions.defaultException(mContext, ex, progress));
                }
            } else {

                ColliMagazzinoRESTConsumer.deleteCollo(mtbColt.get(), () -> {
                    progress.dismiss();
                    resetMtbColt(openNewOne);
                }, ex -> UtilityExceptions.defaultException(mContext, ex, progress));

            }
        }
    }

    private void saveCausaleRettificaGiacenze(ProgressDialog progress, Runnable onComplete) {

        final MtbCols mtbCols = new MtbCols()
                .setCausale(SettingsManager.iDB().getDefaultCausaleRettificaGiacenze());
        mtbCols.setOperation(CommonModelConsts.OPERATION.INSERT_OR_UPDATE);

        MtbColt cloneMtbColt = (MtbColt) mtbColt.get().clone();
        cloneMtbColt.setOperation(CommonModelConsts.OPERATION.NO_OP);

        cloneMtbColt.setMtbCols(new ArrayList<>());
        cloneMtbColt.getMtbCols().add(mtbCols);

        ColliMagazzinoRESTConsumer.saveCollo(cloneMtbColt, new ISimpleOperationCallback<MtbColt>() {
            @Override
            public void onSuccess(MtbColt value) {
                onComplete.run();
            }

            @Override
            public void onFailed(Exception ex) {
                UtilityExceptions.defaultException(mContext, ex, progress);
            }
        });
    }

    private void posizionaCollo(Runnable onComplete, Runnable onAbort, RunnableArgs<Exception> onFailed) {
        DialogAskPositionOfLU.makeBase(mContext, mtbColt.get(), mtbDepoPosizione -> {
            if(mtbDepoPosizione != null) {
                mtbColt.get().setPosizione(mtbDepoPosizione.getPosizione());
                onComplete.run();
            } else {
                onAbort.run();
            }


        }, onFailed).show();
    }

    private void onItemEdit(MtbColr mtbColrToEdit, int index) {
        mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);

        MtbColr mtbColrToEditClone = (MtbColr) mtbColrToEdit.clone();

        DialogInputQuantity.DTO dto = new DialogInputQuantity.DTO()
                .setBatchLot(mtbColrToEditClone.getPartitaMag())
                .setQtaDaEvadere(null)
                .setQtaOrd(null)
                .setQtaDisponibile(new BigDecimal(-1))
                .setMtbAart(mtbColrToEditClone.getMtbAart())
                .setCanPartitaMagBeChanged(false)
                .setQtaTot(mtbColrToEditClone.getQtaCol());

        DialogInputQuantity.makeBase(mContext, dto, true, value -> {

            mtbColrToEditClone
                    .setRiga(null)
                    .setDatetimeRow(new Date())
                    .setQtaCol(new BigDecimal(value.qtaTot.get()).subtract(mtbColrToEditClone.getQtaCol()))
                    .setOperation(CommonModelConsts.OPERATION.INSERT);

            MtbColt mtbColtClone = (MtbColt) mtbColt.get().clone();
            mtbColtClone.setMtbColr(new ObservableArrayList<>());
            mtbColtClone.getMtbColr().add(mtbColrToEditClone);
            mtbColtClone.setOperation(CommonModelConsts.OPERATION.INSERT_OR_UPDATE);

            ProgressDialog progressDialog = UtilityProgress.createDefaultProgressDialog(mContext);

            ColliMagazzinoRESTConsumer.saveCollo(mtbColtClone, valueNewMtbColt -> {
                progressDialog.dismiss();
                mtbColt.get().getMtbColr().remove(index);

                mtbColrToEditClone
                        .setQtaCol(new BigDecimal(value.qtaTot.get()))
                        .setOperation(CommonModelConsts.OPERATION.NO_OP);

                mtbColt.get().getMtbColr().add(index, mtbColrToEditClone);
            }, ex -> {
                UtilityExceptions.defaultException(mContext, ex, progressDialog);
            });

        }).show();

    }

    private void onItemDelete(MtbColr mtbColrToDelete) {
        mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);

        MtbColr mtbColrToDeleteClone = (MtbColr) mtbColrToDelete.clone();

        mtbColrToDeleteClone
                .setRiga(null)
                .setDatetimeRow(new Date())
                .setQtaCol(mtbColrToDeleteClone.getQtaCol().multiply(new BigDecimal(-1)))
                .setOperation(CommonModelConsts.OPERATION.INSERT);

        MtbColt mtbColtClone = (MtbColt) mtbColt.get().clone();
        mtbColtClone.setMtbColr(new ObservableArrayList<>());
        mtbColtClone.getMtbColr().add(mtbColrToDeleteClone);
        mtbColtClone.setOperation(CommonModelConsts.OPERATION.INSERT_OR_UPDATE);

        ProgressDialog progressDialog = UtilityProgress.createDefaultProgressDialog(mContext);

        ColliMagazzinoRESTConsumer.saveCollo(mtbColtClone, value -> {
            progressDialog.dismiss();
            mtbColt.get().getMtbColr().remove(mtbColrToDelete);
        }, ex -> {
            UtilityExceptions.defaultException(mContext, ex, progressDialog);
        });
    }



    private void printCollo(ProgressDialog progress) {

        this.showAskPrint(shouldPrint -> {

            if(shouldPrint) {
                PrinterRESTConsumer.getAvailablePrinters(SettingsManager.i().userSession.depo.getCodMdep(), new ISimpleOperationCallback<List<String>>() {
                    @Override
                    public void onSuccess(List<String> value) {

                        if (value.size() > 0) {

                            try {
                                ReportManager.getRightReportNameByMtbColt(mtbColt.get(), reportName -> {

                                    PrinterRESTConsumer.printCollo(value.get(0),
                                            mtbColt.get(),
                                            1,
                                            reportName,
                                            () -> {
                                                progress.dismiss();
                                                resetMtbColt(true);

                                                Resources res = mContext.getResources();
                                                String errorMessage = res.getText(R.string.alert_print_completed_message).toString();
                                                DialogSimpleMessageHelper.makeSuccessDialog(mContext, res.getText(R.string.completed).toString(), new SpannableString(errorMessage), null, null).show();
                                            }, ex -> {
                                                UtilityLogger.errorMe(ex);
                                                progress.dismiss();
                                                String errorMessage = CommonRESTException.tryRecognizeThenGetMessage(ex);
                                                showPrintErrorDialog(errorMessage);
                                            });

                                }, ex -> {
                                    UtilityLogger.errorMe(ex);
                                    progress.dismiss();
                                    String errorMessage = CommonRESTException.tryRecognizeThenGetMessage(ex);
                                    showPrintErrorDialog(errorMessage);
                                });
                            } catch (Exception ex) {
                                progress.dismiss();
                                UtilityLogger.errorMe(ex);
                                String errorMessage = CommonRESTException.tryRecognizeThenGetMessage(ex);
                                showPrintErrorDialog(errorMessage);
                            }

                        } else {
                            progress.dismiss();
                            String errorMessage = "Nessuna stampante configurata";
                            showPrintErrorDialog(errorMessage);
                        }
                    }

                    @Override
                    public void onFailed(Exception ex) {
                        progress.dismiss();
                        UtilityLogger.errorMe(ex);
                        String errorMessage = CommonRESTException.tryRecognizeThenGetMessage(ex);
                        showPrintErrorDialog(errorMessage);
                    }
                });
            } else {
                progress.dismiss();
                resetMtbColt(true);
            }

        });
    }


    private void showAskPrint(RunnableArgs<Boolean> onComplete) {
        DialogSimpleMessageHelper.makeInfoDialog(
                mContext,
                mContext.getResources().getString(R.string.action_print_ul),
                new SpannableString(mContext.getResources().getString(R.string.ask_print_message)),
                null,
                () -> onComplete.run(true),
                () -> onComplete.run(false)).show();
    }

    private void showPrintErrorDialog(String message) {
        DialogSimpleMessageHelper.makeErrorDialog(
                mContext,
                new SpannableString(message),
                null,
                null,
                R.string.button_ignore_print,
                () -> resetMtbColt(true)).show();
    }
}
