<?php
// src/config.php
return (function () {
  $CONFIG = [
    'db_host' => '127.0.0.1',
    'db_port' => 3306,
    'db_name' => 'thirty',
    'db_user' => 'Fresh',
    'db_pass' => '9j\V<2&2-f02Pre5(R=~E<$wg}.N:B',
    'app_url' => 'https://www.entradasfresh.es/',
    'debug' => false
  ];

  $local = __DIR__ . '/config.local.php';
  if (file_exists($local)) {
    $override = include $local;
    if (is_array($override)) { 
      $CONFIG = array_merge($CONFIG, $override); 
    }
  }

  // Derivar URLs de subida de forma robusta
  $app = rtrim($CONFIG['app_url'], '/');
  if (empty($CONFIG['upload_dir'])) {
    $CONFIG['upload_dir'] = __DIR__ . '/../uploads';
  }
  if (empty($CONFIG['upload_url'])) {
    $CONFIG['upload_url'] = $app . '/uploads';
  }

  return $CONFIG;
})();