
var shop = use('shop')
var io = use('io')

// Initialize shop if needed
if (!shop.init()) {
  log.error("Failed to initialize .cell directory")
  return
}

// Load configuration
var config = shop.load_config()
if (!config) {
  log.console("No modules installed (no cell.toml found)")
  return
}

// List dependencies
if (!config.dependencies || Object.keys(config.dependencies).length == 0) {
  log.console("No modules installed")
  return
}

log.console("Installed modules:")
log.console("")

// Display each dependency
for (var alias in config.dependencies) {
  var locator = config.dependencies[alias]
  var parsed = shop.parse_locator(locator)
  
  if (parsed) {
    log.console("  " + alias + " -> " + locator)
    
    // Check if module directory exists
    var module_dir = '.cell/modules/' + alias + '@' + parsed.version
    if (io.exists(module_dir)) {
      log.console("    ✓ Downloaded to " + module_dir)
    } else {
      log.console("    ✗ Not downloaded (run 'cell get " + locator + "')")
    }
    
    // Check if vendored
    var vendor_dir = 'modules/' + alias + '@' + parsed.version
    if (io.exists(vendor_dir)) {
      log.console("    ✓ Vendored to " + vendor_dir)
    }
    
    // Check if compiled
    var build_dir = '.cell/build/' + alias + '@' + parsed.version
    if (io.exists(build_dir)) {
      log.console("    ✓ Compiled to " + build_dir)
    }
  } else {
    log.console("  " + alias + " -> " + locator + " (invalid locator)")
  }
  
  log.console("")
}

// Show patches if any
if (config.patches && Object.keys(config.patches).length > 0) {
  log.console("Patches:")
  for (var alias in config.patches) {
    var patch_file = config.patches[alias]
    log.console("  " + alias + " -> " + patch_file)
    if (io.exists('.cell/' + patch_file)) {
      log.console("    ✓ Patch file exists")
    } else {
      log.console("    ✗ Patch file missing")
    }
  }
}

$_.stop()