module GeneratorMessages

def check_shakapacker_version_warning

def check_shakapacker_version_warning
  # Try to detect Shakapacker version from Gemfile.lock
  return "" unless File.exist?("Gemfile.lock")
  gemfile_lock_content = File.read("Gemfile.lock")
  shakapacker_match = gemfile_lock_content.match(/shakapacker \((\d+\.\d+\.\d+)\)/)
  return "" unless shakapacker_match
  version = shakapacker_match[1]
  major_version = version.split(".").first.to_i
  if major_version < 8
    <<~WARNING
      ⚠️  #{Rainbow('IMPORTANT: Upgrade Recommended').yellow.bold}
      ─────────────────────────────────────────────────────────────────────────
      You are using Shakapacker #{version}. React on Rails v15+ works best with
      Shakapacker 8.0+ for optimal Hot Module Replacement and build performance.
      To upgrade: #{Rainbow('bundle update shakapacker').cyan}
      Learn more: #{Rainbow('https://github.com/shakacode/shakapacker').cyan.underline}
    WARNING
  else
    ""
  end
rescue StandardError
  # If version detection fails, don't show a warning to avoid noise
  ""
end