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

platform :ios, min_ios_version_supported
prepare_react_native_project!

# react-native-permissions : 사용하는 권한만 빌드에 포함해요
require_relative '../node_modules/react-native-permissions/scripts/setup'
setup_permissions(['Camera'])

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 'rnclisample' do
  config = use_native_modules!

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

  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,
      # :ccache_enabled => true
    )

    # Xcode 16.3+ clang 은 fmt 의 consteval 포맷 검사를 컴파일 에러로 처리해요.
    # fmt 본체만 C++17 로 낮추면 consteval 경로가 비활성화됩니다.
    xcode_version = `xcodebuild -version`[/Xcode (\d+(\.\d+)?)/, 1].to_f
    if xcode_version >= 16.3
      installer.pods_project.targets.each do |target|
        next unless target.name == 'fmt'
        target.build_configurations.each do |config|
          config.build_settings['CLANG_CXX_LANGUAGE_STANDARD'] = 'c++17'
        end
      end
    end
  end
end
