import { Platform } from 'react-native'; import { requireOptionalNativeModule } from 'expo-modules-core'; interface BbpNotifyNative { /** * Post/replace an ongoing notification with a native chronometer counting down * to endTimeMillis. Returns a short diagnostic string (e.g. "posted enabled=true"). */ showCountdown(title: string, body: string, endTimeMillis: number): Promise; /** Same ticking countdown, plus "End" / "Pay" action buttons. */ showCheckin( title: string, body: string, endTimeMillis: number, endLabel: string, payLabel: string, ): Promise; /** Remove the countdown notification. */ clear(): Promise; /** Read + clear the action a notification button set: 'end' | 'pay' | ''. */ consumePendingAction(): Promise; } export type PendingAction = 'end' | 'pay' | null; // Android-only, and only present in a build that includes the native module // (returns null in Expo Go / other platforms — callers degrade gracefully). const native = Platform.OS === 'android' ? (requireOptionalNativeModule('BbpNotify') as BbpNotifyNative | null) : null; /** True when the native ticking-countdown module is available. */ export const hasNativeCountdown = native != null; export async function showCountdown( title: string, body: string, endTimeMillis: number, ): Promise { if (!native) return 'no-native-module'; return native.showCountdown(title, body, endTimeMillis); } export async function showCheckin( title: string, body: string, endTimeMillis: number, endLabel: string, payLabel: string, ): Promise { if (!native) return 'no-native-module'; return native.showCheckin(title, body, endTimeMillis, endLabel, payLabel); } export async function clearCountdown(): Promise { await native?.clear(); } /** Read + clear a notification-button action taken while the app was away. */ export async function consumePendingAction(): Promise { const a = await native?.consumePendingAction(); return a === 'end' || a === 'pay' ? a : null; }