import 'dotenv/config';
import { env } from 'process';
import path from 'path';
import dotenv from 'dotenv';

import type { ConfigContext, ExpoConfig } from 'expo/config';

const API_HOST = env.ENV === 'production' ? env.PRODUCTION_API_HOST : env.DEVELOPMENT_API_HOST;
const MAP_HOST = env.ENV === 'production' ? env.PRODUCTION_MAP_HOST : env.DEVELOPMENT_MAP_HOST;

dotenv.config({
  path: path.resolve(process.cwd(), '.env')
});

export default ({ config }: ConfigContext): ExpoConfig => ({
  ...config,
  name: 'NomadMania',
  slug: 'nomadmania-app',
  owner: 'nomadmania',
  scheme: 'nm',
  // Should be updated after every production release (deploy to AppStore/PlayMarket)
  version: '1.0.0',
  // Should be updated after every dependency change
  runtimeVersion: '1.4',
  orientation: 'portrait',
  icon: './assets/icon.png',
  userInterfaceStyle: 'light',
  extra: {
    ENV: env.ENV,
    API_HOST: API_HOST,
    MAP_HOST: MAP_HOST,
    eas: {
      projectId: env.EAS_PROJECT_ID
    }
  },
  experiments: {
    tsconfigPaths: true
  },
  splash: {
    image: './assets/splash.png',
    resizeMode: 'cover'
  },
  notification: {
    icon: './assets/notification-icon.png'
  },
  updates: {
    url: 'https://u.expo.dev/c31c6828-3c32-4c7a-aabc-f9b8336b3b66'
  },
  platforms: ['ios', 'android'],
  assetBundlePatterns: ['**/*'],
  ios: {
    supportsTablet: true,
    bundleIdentifier: env.PACKAGE_NAME,
    config: {
      googleMapsApiKey: env.IOS_GOOGLE_MAP_APIKEY
    },
    infoPlist: {
      UIBackgroundModes: ['fetch'],
      NSLocationAlwaysUsageDescription:
        'Turn on location service to allow NomadMania.com find friends nearby.',
      NSPhotoLibraryUsageDescription:
        'Enable NomadMania.com to access your photo library to upload your profile picture. Any violence, excess of nudity, stolen picture, or scam is forbidden',
      NSPhotoLibraryAddUsageDescription:
        'Enable NomadMania.com to access your photo library to upload your profile picture. Any violence, excess of nudity, stolen picture, or scam is forbidden',
      NSPushNotificationsDescription:
        'This will allow NomadMania.com to send you notifications. Also you can disable it in app settings'
    }
  },
  android: {
    package: env.PACKAGE_NAME,
    config: {
      googleMaps: {
        apiKey: env.ANDROID_GOOGLE_MAP_APIKEY
      }
    },
    permissions: [
      'ACCESS_BACKGROUND_LOCATION',
      'ACCESS_FINE_LOCATION',
      'ACCESS_COARSE_LOCATION',
      'READ_EXTERNAL_STORAGE',
      'WRITE_EXTERNAL_STORAGE',
      'NOTIFICATIONS',
      'USER_FACING_NOTIFICATIONS',
      'INTERNET',
      'CAMERA'
    ]
  },
  plugins: [
    [
      'expo-image-picker',
      {
        photosPermission: 'Allow NomadMania.com access to your photo library to upload photos.',
        cameraPermission: 'Allow NomadMania.com access to your camera to upload photos directly.'
      }
    ]
  ]
});
