// utils.ts
let isLoggedIn = false; // Global state for login status. In a real app, use more robust state management.
let userToken: string | null = null; // Store user token

export const updateLoggedInState = (loggedIn: boolean, token: string | null = null) => {
    isLoggedIn = loggedIn;
    userToken = token;
    // You can add more logic here, like redirecting based on login state
};

export const isLoggedInUser = () => {
    return isLoggedIn;
};

export const getUserToken = () => {
    return userToken;
};

// Function to generate a random 6-digit ID
export const generateUserId = (): string => {
    return String(Math.floor(100000 + Math.random() * 900000));
};

// Function to navigate to a different page (prototype routing)
export const navigateTo = (path: string) => {
    window.location.hash = path;
};

// Helper function to create HTML elements
export const createElement = <K extends keyof HTMLElementTagNameMap>(tagName: K, options?: ElementCreationOptions): HTMLElementTagNameMap[K] => {
    return document.createElement(tagName, options);
};