import {
  GeneratePortalUrlParams,
  LoginMethodParams,
  OrgCode,
  UserProfile,
} from "@kinde/js-utils";

export enum TimeoutActivityType {
  preWarning = "preWarning",
  timeout = "timeout",
}

export type State = {
  user?: UserProfile;
  isLoading: boolean;
  isAuthenticated: boolean;
  error?: string | undefined;
};

export interface LoginLinkProps
  extends
    Partial<LoginMethodParams>,
    React.ButtonHTMLAttributes<HTMLButtonElement> {
  children: React.ReactNode;
}

export interface RegisterLinkProps
  extends
    Partial<LoginMethodParams>,
    React.ButtonHTMLAttributes<HTMLButtonElement> {
  children: React.ReactNode;
}

export interface LogoutLinkProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
  children: React.ReactNode;
  redirectUrl?: string;
  allSessions?: boolean;
}

export interface PortalLinkProps
  extends
    React.ButtonHTMLAttributes<HTMLButtonElement>,
    Partial<Omit<GeneratePortalUrlParams, "domain">> {
  children: React.ReactNode;
}

export interface SwitchOrgLinkProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
  children: React.ReactNode;
  orgCode: OrgCode;
}

export type ErrorProps = {
  error: string;
  errorDescription: string;
};

export type LogoutOptions = {
  allSessions?: boolean;
  redirectUrl?: string;
};

export type PopupOptions = {
  width?: number;
  height?: number;
  left?: number;
  top?: number;
};

/**
 * Activity timeout configuration.
 * ⚠️ Must be memoized or defined outside component to prevent effect re-runs.
 * @example
 * const config = useMemo(() => ({ timeoutMinutes: 30 }), []);
 * <KindeProvider activityTimeout={config} ... />
 */
export type ActivityTimeoutConfig = {
  timeoutMinutes: number;
  preWarningMinutes?: number;
  onTimeout?: (type: TimeoutActivityType) => void | Promise<void>;
};
