require 'json'
require 'shellwords'
package_json = JSON.parse(File.read('package.json'))

react_native_search_root = defined?(Pod::Config) ? Pod::Config.instance.installation_root.to_s : __dir__

# A standard React Native Podfile has already required react_native_pods by the time this runs,
# so a failure here is only fatal when nothing else defined install_modules_dependencies.
react_native_pods_load_error = nil
begin
  require File.join(File.dirname(`node --print "require.resolve('react-native/package.json', {paths: [process.argv[1]]})" #{Shellwords.escape(react_native_search_root)}`), "scripts/react_native_pods")
rescue LoadError, Errno::ENOENT => e
  react_native_pods_load_error = e
end

unless defined?(install_modules_dependencies)
  raise Pod::Informative, "[RNInsider] Could not load react-native/scripts/react_native_pods.rb " \
    "resolving react-native from #{react_native_search_root}: " \
    "#{react_native_pods_load_error&.message || 'install_modules_dependencies is undefined'}. " \
    "Make sure node is on PATH and react-native is installed for this app"
end

Pod::Spec.new do |s|
  s.name         = 'RNInsider'
  s.version      = package_json['version']
  s.summary      = package_json['description']
  s.homepage     = package_json['homepage']
  s.authors      = package_json['author']
  s.license      = 'MIT'
  s.platform     = :ios, '12.0'
  s.source = {:http => 'https://mobilesdk.useinsider.com/iOS/16.3.0/InsiderMobileIOSFramework.zip'}
  s.source_files = 'ios/RNInsider/*.{h,m,mm}'
  s.requires_arc = true
  s.compiler_flags = '-fobjc-arc-exceptions'
  s.static_framework = true
  install_modules_dependencies(s)
  s.dependency 'InsiderMobile', '16.3.0'
  s.dependency 'InsiderGeofence', '1.3.0'
  if Dir.exist?(File.join(__dir__, 'ios', 'RNInsiderTests'))
    s.test_spec 'Tests' do |test_spec|
      test_spec.source_files = 'ios/RNInsiderTests/**/*.{h,m,mm}'
      test_spec.frameworks    = 'XCTest'
      test_spec.requires_app_host = false
      test_spec.dependency 'OCMock', '~> 3.9'
    end
  end
end
