require "json"

package = JSON.parse(File.read(File.join(__dir__, "package.json")))
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'

fabric_enabled = ENV['RCT_NEW_ARCH_ENABLED'] == '1'

Pod::Spec.new do |s|
  s.name         = "ReactNativeVideo"
  s.version      = package["version"]
  s.summary      = package["description"]
  s.homepage     = package["homepage"]
  s.license      = package["license"]
  s.authors      = package["author"]

  s.platforms    = { :ios => min_ios_version_supported }
  s.source       = { :git => "https://github.com/KrzysztofMoch/react-native-video.git", :tag => "#{s.version}" }

  s.source_files = [
    "ios/*.{h,m,mm,swift}",
    "ios/Core/**/*.{h,m,mm,swift}", # Core library files
    "ios/Hybrids/**/*.{h,m,mm,swift}", # Nitro Hybrid files
    "ios/View/**/*.{h,m,mm,swift}"  # Video View files
  ]

  if fabric_enabled
    s.exclude_files = ["ios/view/paper/**/*.{h,m,mm,swift}"]
  else
    s.exclude_files = ["ios/view/fabric/**/*.{h,m,mm,swift}"]
  end

  # Cxx to Swift bridging helpers
  s.public_header_files = ["ios/Video-Bridging-Header.h"]

  s.pod_target_xcconfig = {
    "GCC_PREPROCESSOR_DEFINITIONS" => "$(inherited) FOLLY_NO_CONFIG FOLLY_CFG_NO_COROUTINES FOLLY_MOBILE"
  }

  # Try to manually add the dependencies
  # because they are not automatically added by expo
  # when USE_FRAMEWORKS is true
  if ENV["USE_FRAMEWORKS"]
    s.dependency "React-Core"

    puts "[ReactNativeVideo] Detected USE_FRAMEWORKS, adding required dependencies..."
   
    add_dependency(s, "React-jsinspector", :framework_name => "jsinspector_modern")
    add_dependency(s, "React-rendererconsistency", :framework_name => "React_rendererconsistency")

    # @KrzysztofMoch Note: We need to add this as well for newer versions of React Native, but it's not available in older versions
    # add_dependency(s, "React-jsinspectortracing", :framework_name => 'jsinspector_moderntracing')
  end

  # Add all files generated by Nitrogen
  load 'nitrogen/generated/ios/ReactNativeVideo+autolinking.rb'
  add_nitrogen_files(s)

  install_modules_dependencies(s)
end
