"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_extra_1 = __importDefault(require("fs-extra"));
const path_1 = __importDefault(require("path"));
async function cleanupAppCss(projectRoot) {
    const appCssPath = path_1.default.join(projectRoot, 'src', 'App.css');
    if (await fs_extra_1.default.pathExists(appCssPath)) {
        let content = await fs_extra_1.default.readFile(appCssPath, 'utf-8');
        // Styles to remove from App.css
        const stylesToRemove = [
            'max-width: 1280px',
            'max-width:1280px',
            'margin: 0 auto',
            'margin:0 auto',
            'padding: 2rem',
            'padding:2rem',
            'text-align: center',
            'text-align:center'
        ];
        let hasChanges = false;
        // Remove unwanted styles from #app selector and other selectors
        content = content.replace(/#app\s*\{[^}]*\}/g, (match) => {
            let appStyles = match;
            let originalStyles = appStyles;
            stylesToRemove.forEach(style => {
                // Remove the style with optional semicolon and whitespace
                const regex = new RegExp(`\\s*${style.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\s*;?`, 'gi');
                appStyles = appStyles.replace(regex, '');
            });
            if (originalStyles !== appStyles) {
                hasChanges = true;
            }
            // Clean up empty #app selector
            if (appStyles.match(/#app\s*\{\s*\}/)) {
                return '';
            }
            return appStyles;
        });
        // Also remove these styles from any other selectors or standalone
        stylesToRemove.forEach(style => {
            const regex = new RegExp(`\\s*${style.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\s*;?`, 'gi');
            const originalContent = content;
            content = content.replace(regex, '');
            if (originalContent !== content) {
                hasChanges = true;
            }
        });
        // Add or update #root selector with required styles
        const rootStyles = `#root {
  width: 100%;
  min-height: 100vh;
}`;
        if (content.includes('#root')) {
            // Update existing #root selector
            content = content.replace(/#root\s*\{[^}]*\}/g, rootStyles);
            hasChanges = true;
        }
        else {
            // Add #root selector at the beginning
            content = rootStyles + '\n\n' + content;
            hasChanges = true;
        }
        // Clean up multiple empty lines
        content = content.replace(/\n\s*\n\s*\n/g, '\n\n');
        if (hasChanges) {
            await fs_extra_1.default.writeFile(appCssPath, content);
            console.log('✅ Updated App.css: added root styles and removed conflicting styles');
        }
    }
}
//# sourceMappingURL=cssSetup.js.map