import { ExpoConfig, ConfigContext } from "expo/config";

export default ({ config }: ConfigContext): ExpoConfig => ({
  ...config,
  name: "ReBreak",
  slug: "rebreak",
  version: "0.1.0",
  orientation: "portrait",
  icon: "./assets/icon.png",
  scheme: "rebreak",
  userInterfaceStyle: "automatic",
  newArchEnabled: true,

  splash: {
    image: "./assets/splash.png",
    resizeMode: "contain",
    backgroundColor: "#0f172a",
  },

  ios: {
    supportsTablet: true,
    bundleIdentifier: "org.rebreak.app",
    config: {
      usesNonExemptEncryption: false,
    },
    infoPlist: {
      ITSAppUsesNonExemptEncryption: false,
      NSMicrophoneUsageDescription:
        "Rebreak nutzt das Mikrofon für Sprachnachrichten an Lyra.",
      NSPhotoLibraryUsageDescription:
        "Rebreak greift auf Fotos zu, damit du sie in deinen Posts teilen kannst.",
      NSPhotoLibraryAddUsageDescription:
        "Rebreak speichert Bilder in deine Foto-Mediathek.",
    },
  },

  android: {
    package: "org.rebreak.app",
    adaptiveIcon: {
      // Chain-only foreground (ohne "ReBreak"-Schrift). Auf Android schneidet die
      // Adaptive-Icon-Mask (Kreis/Squircle/etc.) den Untertitel sonst ab.
      foregroundImage: "./assets/adaptive-icon-android.png",
      backgroundColor: "#0a0a0a",
    },
    permissions: [
      "INTERNET",
      "ACCESS_NETWORK_STATE",
      "BIND_VPN_SERVICE",
      "FOREGROUND_SERVICE",
      "POST_NOTIFICATIONS",
      "BIND_ACCESSIBILITY_SERVICE",
      "RECORD_AUDIO",
    ],
  },

  plugins: [
    "expo-router",
    "expo-localization",
    "expo-font",
    "expo-web-browser",
    [
      "expo-build-properties",
      {
        ios: {
          deploymentTarget: "15.1",
          useFrameworks: "static",
        },
        android: {
          minSdkVersion: 26,
          compileSdkVersion: 35,
          targetSdkVersion: 35,
        },
      },
    ],
    // Xcode 16 + RN 0.79 fmt consteval workaround
    "./plugins/with-fmt-consteval-fix",
    // Phase 5: NEFilter Extension + Family Controls Entitlements (iOS)
    "./plugins/with-rebreak-protection-ios",
    // Phase 5: VpnService + AccessibilityService (Android)
    "./plugins/with-rebreak-protection-android",
    // Rive-Asset (lyra-avatar.riv) als Android raw-resource bundlen
    "./plugins/with-rive-asset-android",
  ],

  experiments: {
    typedRoutes: true,
  },

  extra: {
    apiUrl:
      process.env.EXPO_PUBLIC_API_URL ||
      process.env.API_URL ||
      "https://staging.rebreak.org",
    // TEMP: Staging Anon-Key + URL hardcoded für lokales Dev-Testing.
    // Anon-Key ist designed für Client-Ship (RLS protectiert DB). Trotzdem:
    // BFF-Migration kommt in Phase 5 — dann fliegen diese 2 Zeilen wieder raus.
    supabaseUrl:
      process.env.EXPO_PUBLIC_SUPABASE_URL ||
      process.env.SUPABASE_URL ||
      "https://db-staging.rebreak.org",
    supabaseAnonKey:
      process.env.EXPO_PUBLIC_SUPABASE_ANON_KEY ||
      process.env.SUPABASE_KEY ||
      process.env.SUPABASE_ANON_KEY ||
      "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsImF1ZCI6ImF1dGhlbnRpY2F0ZWQiLCJyb2xlIjoiYW5vbiIsImV4cCI6MjA5MTAxODk1NSwiaWF0IjoxNzc1NjU4OTU1fQ.93d2r3pft2E-alf1JezqueD0l0n1dim7dGvhBN0l1Cs",
  },
});
