package com.example.fitbot.util;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.Button;

public class NavigationManager {

    /**
     * Sets up a button to navigate to a different activity when clicked.
     *
     * @param currentActivity The activity that contains the button
     * @param buttonId        The ID of the button
     * @param targetActivity  The activity to navigate to
     */
    public static void setupButtonNavigation(Activity currentActivity, int buttonId, Class<? extends Activity> targetActivity) {
        Button button = currentActivity.findViewById(buttonId);
        if (button == null) {
            throw new IllegalArgumentException("Button with ID " + buttonId + " not found in " + currentActivity.getClass().getSimpleName());
        }
        button.setOnClickListener(v -> NavigationManager.navigateToActivity(currentActivity, targetActivity));
    }

    /**
     * Navigates to the target activity.
     *
     * @param currentActivity The current activity
     * @param targetActivity  The target activity
     */
    public static void navigateToActivity(Activity currentActivity, Class<? extends Activity> targetActivity) {
        Intent intent = new Intent(currentActivity, targetActivity);
        // Close previous activity
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        currentActivity.startActivity(intent);
        currentActivity.finish();
    }

    /**
     * Navigates to the target activity.
     *
     * @param context        The context
     * @param targetActivity The target activity
     */
    public static void navigateToActivity(Context context, Class<? extends Activity> targetActivity) {
        Intent intent = new Intent(context, targetActivity);
        context.startActivity(intent);
    }

    public static void hideSystemUI(Activity currentActivity) {
        View decorView = currentActivity.getWindow().getDecorView();
        // Hide the status bar and navigation bar
        int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN
                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
        decorView.setSystemUiVisibility(uiOptions);
    }

}