package it.integry.integrywmsnative.view.dialogs;

import android.content.Context;
import android.text.SpannableString;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentActivity;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import it.integry.integrywmsnative.R;
import it.integry.integrywmsnative.view.dialogs.base.DialogSimpleMessageView;

public class DialogCommon {


    public static void showNoArtFoundDialog(@NotNull Context context, @Nullable Runnable onPositiveClick) {
        DialogSimpleMessageView
                .makeWarningDialog(new SpannableString(context.getResources().getText(R.string.no_result_from_barcode)),
                        null, onPositiveClick)
                .show(((AppCompatActivity) context).getSupportFragmentManager(), "tag");
    }

    public static void showNoULFound(@NotNull Context context, @Nullable Runnable onPositiveClick) {
        DialogSimpleMessageView.makeWarningDialog(new SpannableString(context.getResources().getText(R.string.no_lu_found_message)),
                null, onPositiveClick)
                .show(((AppCompatActivity) context).getSupportFragmentManager(), "tag");
    }


    public static void showNoOrderFound(@NotNull Context context, @Nullable Runnable onPositiveClick) {
        DialogSimpleMessageView.makeWarningDialog(new SpannableString(context.getResources().getText(R.string.no_orders_found_message)),
                null, onPositiveClick)
                .show(((AppCompatActivity) context).getSupportFragmentManager(), "tag");
        ;
    }


    public static void showDataSaved(@NotNull FragmentActivity context, @Nullable Runnable onPositiveClick) {
        context.runOnUiThread(() -> {
            DialogSimpleMessageView.makeSuccessDialog(
                    context.getResources().getString(R.string.completed),
                    new SpannableString(context.getResources().getString(R.string.data_saved)),
                    null, onPositiveClick)
                    .show(context.getSupportFragmentManager(), "tag");
        });

    }


    public static void showRestError(@NotNull Context context, Exception ex, @Nullable Runnable onPositiveClick) {
        DialogSimpleMessageView
                .makeErrorDialog(new SpannableString(ex.getMessage()), null, onPositiveClick)
                .show(((AppCompatActivity) context).getSupportFragmentManager(), "tag");
    }
}
