/**
 * 隐私模糊（plan.md「0.4 隐私模糊」）。
 * 参考 BeeCount 的 BackdropFilter sigmaX:30 全屏模糊。
 *
 * 本模块提供状态计算逻辑，实际的 BlurView 渲染在组件层。
 */

export type AppState = 'active' | 'background' | 'inactive';

export interface PrivacyBlurState {
  isBlurred: boolean;
  reason: 'background' | 'inactive' | 'auth-pending' | 'none';
}

/**
 * 计算隐私模糊状态。
 * - background/inactive → 模糊
 * - active + appLockEnabled → 延迟解除（等认证完成）
 * - active + !appLockEnabled → 立即解除
 */
export function computePrivacyBlur(
  appState: AppState,
  appLockEnabled: boolean,
  authenticated: boolean,
): PrivacyBlurState {
  if (appState === 'background') {
    return { isBlurred: true, reason: 'background' };
  }
  if (appState === 'inactive') {
    return { isBlurred: true, reason: 'inactive' };
  }
  // active
  if (appLockEnabled && !authenticated) {
    return { isBlurred: true, reason: 'auth-pending' };
  }
  return { isBlurred: false, reason: 'none' };
}

/** Hook 封装（供组件用，订阅 settingsStore.appLockEnabled）。 */
export function usePrivacyBlurLogic(
  appState: AppState,
  authenticated: boolean,
  appLockEnabled: boolean,
): PrivacyBlurState {
  return computePrivacyBlur(appState, appLockEnabled, authenticated);
}
