<?php
$dir = new RecursiveDirectoryIterator('c:/xampp/htdocs/inveetaire/app/views');
$ite = new RecursiveIteratorIterator($dir);
$files = new RegexIterator($ite, '/^.+\.php$/i', RecursiveRegexIterator::GET_MATCH);

$modifiedFiles = [];

foreach ($files as $file) {
    $path = $file[0];
    if (strpos($path, 'layouts') !== false || strpos($path, 'public') !== false) {
        continue; // skip
    }
    
    $originalContent = file_get_contents($path);
    $content = $originalContent;

    // 1. Standardize Card Paddings
    // Finds bg-white rounded-* ... p-4, p-5, or p-6 ... and replaces with p-4 md:p-6
    // Note: only replacing if it's p-4, p-5, or p-6.
    $content = preg_replace('/(class="[^"]*bg-white[^"]*rounded-[a-z0-9]+[^"]*)\bp-[2-6]\b([^"]*")/i', '$1p-4 md:p-6$2', $content);

    // 2. Button Gaps
    // Let's find flex containers that contain buttons and ensure gap is standard.
    // This is hard to do with regex perfectly, so we'll do targeted replacements.
    $content = preg_replace('/class="([^"]*flex[^"]*)gap-[1-2]\b([^"]*)"/i', 'class="$1gap-3$2"', $content);

    // 3. Form Spacing
    // If a form doesn't have space-y, add space-y-6
    $content = preg_replace_callback('/<form([^>]*)class="([^"]*)"([^>]*)>/i', function($matches) {
        $classes = $matches[2];
        if (strpos($classes, 'space-y-') === false && strpos($classes, 'flex') === false && strpos($classes, 'grid') === false) {
            $classes .= ' space-y-6';
        }
        return '<form' . $matches[1] . 'class="' . $classes . '"' . $matches[3] . '>';
    }, $content);

    if ($content !== $originalContent) {
        file_put_contents($path, $content);
        $modifiedFiles[] = str_replace('c:/xampp/htdocs/inveetaire/app/views/', '', str_replace('\\', '/', $path));
    }
}

echo "Modified files:\n";
print_r($modifiedFiles);
