/**
* @file Session Time Hooks
* @description React hooks for time-based session calculations.
*
* These hooks replace the deprecated selectors that used Date.now() inside
* createSelector combiners. Using Date.now() in selectors breaks memoization
* because the combiner returns a new value on every call.
*
* These hooks properly handle time-based calculations with:
* - Configurable update intervals
* - Proper cleanup on unmount
* - Stable references for callback dependencies
*
* @module state/hooks/useSessionTime
* @version 1.0.0
*
* @example
* ```tsx
* function SessionTimer() {
* const duration = useSessionDuration();
* const timeUntilExpiry = useTimeUntilExpiry();
* const isExpired = useIsSessionExpired();
*
* if (isExpired) {
* return ;
* }
*
* return (
*
*
Session duration: {formatDuration(duration)}
*
Time until expiry: {formatDuration(timeUntilExpiry)}
*
* );
* }
* ```
*/
/**
* Options for session time hooks.
*/
export interface SessionTimeOptions {
/**
* Update interval in milliseconds.
* Lower values provide more accurate time displays but use more resources.
* @default 1000 (1 second)
*/
readonly updateInterval?: number;
/**
* Whether to enable automatic updates.
* Set to false if you only need the initial value.
* @default true
*/
readonly enableUpdates?: boolean;
}
/**
* Hook to get the current session duration.
*
* Unlike the deprecated selectSessionDuration selector, this hook properly
* handles time calculations using useState and useEffect with an interval.
*
* @param options - Hook options
* @returns Session duration in milliseconds, or null if no session
*
* @example
* ```tsx
* function SessionInfo() {
* const duration = useSessionDuration();
*
* if (duration === null) {
* return No active session
;
* }
*
* const minutes = Math.floor(duration / 60000);
* return Session active for {minutes} minutes
;
* }
* ```
*/
export declare function useSessionDuration(options?: SessionTimeOptions): number | null;
/**
* Hook to get the time until session expiry.
*
* Unlike the deprecated selectTimeUntilExpiry selector, this hook properly
* handles time calculations using useState and useEffect with an interval.
*
* @param options - Hook options
* @returns Time until expiry in milliseconds, or null if no expiry set
*
* @example
* ```tsx
* function ExpiryWarning() {
* const timeUntilExpiry = useTimeUntilExpiry();
*
* if (timeUntilExpiry === null) {
* return null;
* }
*
* if (timeUntilExpiry < 60000) {
* return Session expires in less than a minute!;
* }
*
* return null;
* }
* ```
*/
export declare function useTimeUntilExpiry(options?: SessionTimeOptions): number | null;
/**
* Hook to check if the session is expired.
*
* Unlike the deprecated selectIsSessionExpired selector, this hook properly
* handles time calculations using useState and useEffect with an interval.
*
* Checks both:
* - Hard expiry time (sessionExpiresAt)
* - Inactivity timeout (lastActivity + activityTimeoutMs)
*
* @param options - Hook options
* @returns true if session is expired
*
* @example
* ```tsx
* function SessionGuard({ children }) {
* const isExpired = useIsSessionExpired();
*
* if (isExpired) {
* return ;
* }
*
* return children;
* }
* ```
*/
export declare function useIsSessionExpired(options?: SessionTimeOptions): boolean;
/**
* Return type for useSessionTimeInfo hook.
*/
export interface SessionTimeInfo {
/** Duration in milliseconds since session started */
readonly duration: number | null;
/** Time until expiry in milliseconds */
readonly timeUntilExpiry: number | null;
/** Whether the session is expired */
readonly isExpired: boolean;
/** Formatted duration string (e.g., "5m 30s") */
readonly formattedDuration: string | null;
/** Formatted time until expiry string (e.g., "2m 15s") */
readonly formattedTimeUntilExpiry: string | null;
}
/**
* Combined hook for all session time information.
*
* Use this when you need multiple time-based session values to avoid
* multiple intervals running independently.
*
* @param options - Hook options
* @returns Combined session time information
*
* @example
* ```tsx
* function SessionStatus() {
* const {
* formattedDuration,
* formattedTimeUntilExpiry,
* isExpired,
* } = useSessionTimeInfo();
*
* if (isExpired) {
* return Session expired
;
* }
*
* return (
*
*
Active: {formattedDuration}
*
Expires in: {formattedTimeUntilExpiry}
*
* );
* }
* ```
*/
export declare function useSessionTimeInfo(options?: SessionTimeOptions): SessionTimeInfo;