<?php
$admin_dir = __DIR__ . '/resources/views/admin';

function fixAllBladeFiles($dir) {
    $files = new RecursiveIteratorIterator(
        new RecursiveDirectoryIterator($dir),
        RecursiveIteratorIterator::LEAVES_ONLY
    );
    
    foreach ($files as $file) {
        if ($file->getExtension() === 'php' && strpos($file->getFilename(), '.blade.php') !== false) {
            $filepath = $file->getRealPath();
            $content = file_get_contents($filepath);
            
            if (strpos($content, '<x-app-layout>') !== false) {
                echo "Fixing: " . $file->getFilename() . "\n";
                
                // Replace opening tag
                $content = str_replace(
                    '<x-app-layout>',
                    "@extends('layouts.app')\n\n@section('content')",
                    $content
                );
                
                // Remove x-slot headers
                $content = str_replace('    <x-slot name="header">', '', $content);
                $content = str_replace('    </x-slot>', '', $content);
                
                // Replace closing tag
                $content = str_replace('</x-app-layout>', "</div>\n@endsection", $content);
                
                file_put_contents($filepath, $content);
            }
        }
    }
}

fixAllBladeFiles($admin_dir);
echo "Done!\n";
?>
