const fs = require('fs');

const css = fs.readFileSync('scratch/all.css', 'utf8');

// 1. Extract button rules
const btnRules = [];
const regex = /([^}]+?)\{([^}]+)\}/g;
let match;
while ((match = regex.exec(css)) !== null) {
    const selector = match[1].trim();
    const rules = match[2].trim();
    if (selector.includes('.tj-primary-btn') || selector.includes('.white-btn')) {
        btnRules.push(`${selector} {\n${rules}\n}`);
    }
}

fs.writeFileSync('scratch/buttons.css', btnRules.join('\n\n'));
console.log(`Saved ${btnRules.length} button rules to scratch/buttons.css`);

// 2. Extract font-face for Lato and Libre Franklin
const fontFaces = [];
const ffRegex = /@font-face\s*\{([^}]+)\}/g;
let ffMatch;
while ((ffMatch = ffRegex.exec(css)) !== null) {
    const rules = ffMatch[1];
    if (rules.includes('Lato') || rules.includes('Libre Franklin')) {
        fontFaces.push(`@font-face {\n${rules}\n}`);
    }
}
fs.writeFileSync('scratch/fonts.css', fontFaces.join('\n\n'));
console.log(`Saved ${fontFaces.length} font-faces to scratch/fonts.css`);

