# Script de correccion masiva para MSP-051
$ErrorActionPreference = "Stop"

Write-Host "=== CORRECCION MASIVA MSP-051 ===" -ForegroundColor Cyan

# Leer archivo
Write-Host "Leyendo archivo..." -ForegroundColor Yellow
$lines = Get-Content 'msp_051.php' -Encoding UTF8

Write-Host "Total de lineas: $($lines.Count)" -ForegroundColor Yellow

# Procesar línea por línea
Write-Host "Procesando correcciones..." -ForegroundColor Yellow
$newLines = @()

foreach ($line in $lines) {
    $newLine = $line
    
    # CORRECCION 1: Agregar color a inputs number, text, date, time
    if ($newLine -match '<input.*type="(number|text|date|time)"' -and $newLine -notmatch 'color:#000') {
        if ($newLine -match 'style="([^"]*)"') {
            $newLine = $newLine -replace 'style="([^"]*)"', 'style="$1 color:#000;"'
        }
        else {
            $newLine = $newLine -replace '(<input[^>]*)(>)', '$1 style="color:#000;"$2'
        }
    }
    
    # CORRECCION 2: Quitar tildes
    $newLine = $newLine -replace 'á', 'a' -replace 'é', 'e' -replace 'í', 'i' -replace 'ó', 'o' -replace 'ú', 'u'
    $newLine = $newLine -replace 'Á', 'A' -replace 'É', 'E' -replace 'Í', 'I' -replace 'Ó', 'O' -replace 'Ú', 'U'
    $newLine = $newLine -replace 'ñ', 'n' -replace 'Ñ', 'N'
    $newLine = $newLine -replace 'ü', 'u' -replace 'Ü', 'U'
    
    # CORRECCION 3: Ajustar colores de Seccion X
    $newLine = $newLine -replace 'background:\s*#D32F2F;\s*border-color:\s*#B71C1C;\s*color:white', 'background: #FF9800; color: #000; border: 1px solid #000'
    $newLine = $newLine -replace 'color:#B71C1C', 'color:#000'
    
    $newLines += $newLine
}

# Guardar archivo
Write-Host "Guardando archivo..." -ForegroundColor Yellow
$newLines | Set-Content 'msp_051.php' -Encoding UTF8

Write-Host ""
Write-Host "=== CORRECCION COMPLETADA ===" -ForegroundColor Green
Write-Host "Correcciones aplicadas:" -ForegroundColor Cyan
Write-Host "  - Inputs invisibles corregidos" -ForegroundColor Green
Write-Host "  - Tildes eliminadas" -ForegroundColor Green
Write-Host "  - Colores ajustados" -ForegroundColor Green
