package com.dittomart.meatsbhavan.ui;

import android.os.Build;
import android.util.Log;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;

import com.dittomart.meatsbhavan.R;

/**
 * Base activity class to provide common functionality across all activities
 */
public abstract class BaseActivity extends AppCompatActivity {
    
    private static final String TAG = "BaseActivity";
    
    @Override
    protected void onCreate(android.os.Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setupStatusBar();
    }
    
    /**
     * Setup status bar for consistent appearance across all activities
     * Following Android 15 best practices without full screen mode
     */
    protected void setupStatusBar() {
        try {
            // Ensure content fits system windows (no edge-to-edge for WebView apps)
            if (Build.VERSION.SDK_INT >= 35) {
                getWindow().setDecorFitsSystemWindows(true);
                Log.d(TAG, "DecorFitsSystemWindows set to TRUE for " + getClass().getSimpleName());
            }
            
            // Set status bar color to white
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                getWindow().setStatusBarColor(android.graphics.Color.WHITE);
                Log.d(TAG, "Status bar color set to WHITE for " + getClass().getSimpleName());
            }
            
            // Set status bar text/icons to dark color for visibility on white background
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                int flags = getWindow().getDecorView().getSystemUiVisibility();
                flags |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
                getWindow().getDecorView().setSystemUiVisibility(flags);
                Log.d(TAG, "Status bar icons set to DARK for " + getClass().getSimpleName());
            }
            
            // Android 15+ system bars appearance configuration
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
                getWindow().getInsetsController().setSystemBarsAppearance(
                    android.view.WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS,
                    android.view.WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS);
                Log.d(TAG, "System bars appearance configured for " + getClass().getSimpleName());
            }
            
            Log.d(TAG, "Status bar configuration completed for " + getClass().getSimpleName());
        } catch (Exception e) {
            Log.e(TAG, "Error setting up status bar: " + e.getMessage());
        }
    }
    
    /**
     * Force status bar to white color - can be called if status bar color needs to be enforced
     */
    protected void forceWhiteStatusBar() {
        try {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                getWindow().setStatusBarColor(android.graphics.Color.WHITE);
                Log.d(TAG, "Status bar color FORCED to WHITE for " + getClass().getSimpleName());
            }
        } catch (Exception e) {
            Log.e(TAG, "Error forcing white status bar: " + e.getMessage());
        }
    }
}
