def node_require(script)
   # Resolve script with node to allow for hoisting
   require Pod::Executable.execute_command('node', ['-p',
     "require.resolve(
       '#{script}',
       {paths: [process.argv[1]]},
     )", __dir__]).strip
end

node_require('react-native/scripts/react_native_pods.rb')
node_require('react-native-permissions/scripts/setup.rb')

platform :ios, min_ios_version_supported
prepare_react_native_project!

setup_permissions([
  'Camera',
  'FaceID',
  'MediaLibrary',
  'Microphone',
  'Notifications',
  'PhotoLibrary',
  'PhotoLibraryAddOnly',
])

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

# If inside a Nix shell, allow pod install
inside_nix_shell = ENV['IN_NIX_SHELL']
allow_pod_install = !inside_nix_shell.nil?

unless allow_pod_install
    puts "ERROR: 'pod install' must be run inside a Nix shell. Please ensure you're inside a nix shell and try again."
    exit 1
end

abstract_target 'Status' do
  # Pods for StatusQuo
  config = use_native_modules!

  # Flags change depending on the env values.
  flags = get_default_flags()

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

  pod 'react-native-image-resizer', :path => '../node_modules/react-native-image-resizer'
  pod 'react-native-config', :path => '../node_modules/react-native-config'

  pod 'SSZipArchive', '2.4.3'

  pod "react-native-status-keycard", path: "../node_modules/react-native-status-keycard"
  pod "react-native-status", path: "../modules/react-native-status"
  pod "Keycard", git: "https://github.com/status-im/Keycard.swift.git"
  pod 'secp256k1', git: "https://github.com/status-im/secp256k1.swift.git", submodules: true

  target 'StatusIm' do

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

  target 'StatusImPR' do
  end

  post_install do |installer|
    # as per react-native 0.73.2 template
    # https://github.com/facebook/react-native/blob/c5c0563f209ead8f884204763e02115bd66d1960/packages/react-native/template/ios/Podfile#L49-L52
    react_native_post_install(
      installer,
      config[:reactNativePath],
      :mac_catalyst_enabled => false,
    )
    # some of libs wouldn't be build for x86_64 otherwise and that is
    # necessary for ios simulators
    installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
        config.build_settings['ONLY_ACTIVE_ARCH'] = 'NO'
      end
      # We need to remove the predefinition of IPHONEOS_DEPLOYMENT_TARGET from RNCK lib to use our own.
      case target.name
      when 'ReactNativeCameraKit'
        target.build_configurations.each do |config|
          config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET'
        end
      end
    end
  end

  use_native_modules!
end