<?php
$files = [
    'application/views/cliente.php',
    'application/views/proveedor.php',
    'application/views/productocategoria.php'
];

foreach ($files as $file) {
    if (!file_exists($file)) {
        echo "File not found: $file\n";
        continue;
    }
    
    $content = file_get_contents($file);

    // Lobibox Replacements
    $content = preg_replace("/Lobibox\.notify\s*\(\s*'success'\s*,\s*\{\s*size\s*:\s*'mini'\s*,\s*position\s*:\s*(?:'|\")top right(?:'|\")\s*,\s*msg\s*:\s*(.*?)\s*\}\s*\)\s*;/s", "Swal.fire({ icon: 'success', title: '¡Éxito!', text: $1, timer: 2000, showConfirmButton: false, toast: true, position: 'bottom-end' });", $content);

    $content = preg_replace("/Lobibox\.notify\s*\(\s*'error'\s*,\s*\{\s*size\s*:\s*'mini'\s*,\s*position\s*:\s*(?:'|\")top right(?:'|\")\s*,\s*msg\s*:\s*(.*?)\s*\}\s*\)\s*;/s", "Swal.fire({ icon: 'error', title: 'Error', text: $1, timer: 3000, showConfirmButton: false, toast: true, position: 'bottom-end' });", $content);

    $content = preg_replace("/Lobibox\.notify\s*\(\s*'warning'\s*,\s*\{\s*size\s*:\s*'mini'\s*,\s*position\s*:\s*(?:'|\")top right(?:'|\")\s*,\s*msg\s*:\s*(.*?)\s*\}\s*\)\s*;/s", "Swal.fire({ icon: 'warning', title: 'Atención', text: $1, timer: 3000, showConfirmButton: false, toast: true, position: 'bottom-end' });", $content);

    // Bootbox Replacements
    $content = preg_replace("/bootbox\.confirm\s*\(\s*\"([^\"]+)\"\s*,\s*function\s*\(\s*result\s*\)\s*\{\s*if\s*\(\s*result(?: === true)?\s*\)\s*\{/s", "Swal.fire({ title: '¿Estás seguro?', text: \"$1\", icon: 'warning', showCancelButton: true, confirmButtonColor: '#3085d6', cancelButtonColor: '#d33', confirmButtonText: 'Sí, confirmar', cancelButtonText: 'Cancelar' }).then((result) => { if (result.isConfirmed) {", $content);

    file_put_contents($file, $content);
    echo "$file updated successfully.\n";
}
?>
