# Resolve react_native_pods.rb with node to allow for hoisting
require Pod::Executable.execute_command('node', ['-p',
  'require.resolve(
    "@callstack/react-native-visionos/scripts/react_native_pods.rb",
    {paths: [process.argv[1]]},
  )', __dir__]).strip

# `@sentry/react-native`'s `RNSentry.podspec` is evaluated by CocoaPods with its
# own directory (`packages/core`) as the cwd, so its `require.resolve('react-native')`
# resolves the SDK's dev-dependency react-native (currently 0.87.x) — NOT this
# sample's `@callstack/react-native-visionos` 0.79.x. That mismatch makes the
# podspec's Hermes-runtime feature detection bake `-DNEW_HERMES_RUNTIME` (a 0.81+
# API) into a 0.79 build and fail to compile. Point the podspec's documented
# override at this sample's actual react-native so detection matches the headers.
ENV['REACT_NATIVE_NODE_MODULES_DIR'] ||= File.expand_path('../node_modules/react-native', __dir__)

platform :visionos, min_visionos_version_supported
prepare_react_native_project!

linkage = ENV['USE_FRAMEWORKS']
if linkage != nil
  Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green
  use_frameworks! :linkage => linkage.to_sym
end

target 'VisionSample' do
  config = use_native_modules!
  config[:reactNativePath] = '../node_modules/@callstack/react-native-visionos'

  use_react_native!(
    :path => config[:reactNativePath],
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )

  target 'VisionSampleTests' do
    inherit! :complete
    # Pods for testing
  end

  post_install do |installer|
    # https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202
    react_native_post_install(
      installer,
      config[:reactNativePath],
      :mac_catalyst_enabled => false
    )

    # fmt 11.0.2 (vendored by react-native 0.79) enables `consteval` whenever the
    # compiler advertises `__cpp_consteval`, then trips a "call to consteval
    # function is not a constant expression" error under the stricter C++20
    # evaluation in Xcode 26's clang. The detection block in `fmt/base.h` has no
    # `#ifndef` guard, so a command-line `-DFMT_USE_CONSTEVAL=0` is overridden —
    # the header itself has to be pinned. Force it off (idempotent; a no-op on
    # older toolchains and if a future fmt bump fixes this upstream).
    fmt_base_h = File.join(installer.sandbox.root, 'fmt', 'include', 'fmt', 'base.h')
    if File.exist?(fmt_base_h)
      contents = File.read(fmt_base_h)
      patched = contents.gsub(/#\s*define\s+FMT_USE_CONSTEVAL\s+1/, '#  define FMT_USE_CONSTEVAL 0')
      File.write(fmt_base_h, patched) if patched != contents
    end
  end
end
