import * as Notifications from 'expo-notifications';
import * as Device from 'expo-device';
import Constants from 'expo-constants';
import { Platform } from 'react-native';
import { api } from '../api/client';
import { useSession } from '../state/session';
Notifications.setNotificationHandler({handleNotification:async()=>({shouldShowBanner:true,shouldShowList:true,shouldPlaySound:false,shouldSetBadge:true})});
export async function registerPush(){
 if(!Device.isDevice)return {enabled:false,reason:'physical_device_required'};
 const current=await Notifications.getPermissionsAsync();let status=current.status;if(status!=='granted')status=(await Notifications.requestPermissionsAsync()).status;if(status!=='granted')return {enabled:false,reason:'permission_denied'};
 if(Platform.OS==='android')await Notifications.setNotificationChannelAsync('baltique-critical',{name:'Baltique OS',importance:Notifications.AndroidImportance.HIGH,lockscreenVisibility:Notifications.AndroidNotificationVisibility.PRIVATE});
 const projectId=(Constants.expoConfig?.extra as any)?.eas?.projectId;const token=(await Notifications.getExpoPushTokenAsync(projectId&&projectId!=='REPLACE_WITH_EAS_PROJECT_ID'?{projectId}:undefined)).data;
 const s=useSession.getState();await api.registerDevice({device_uid:s.deviceUid,platform:Platform.OS,push_token:token,push_provider:'expo',locale:s.locale,site_key:s.site?.site_key,app_version:Constants.expoConfig?.version,build_number:Platform.OS==='ios'?Constants.expoConfig?.ios?.buildNumber:String(Constants.expoConfig?.android?.versionCode||1)});return {enabled:true,token};
}
