const fs = require('fs');

let html = fs.readFileSync('d:/برنامج مخازن/index.html', 'utf8');

const missingModules = `
            <label class="perm-card"><input type="checkbox" class="perm-module" value="sales"> مبيعات</label>
            <label class="perm-card"><input type="checkbox" class="perm-module" value="purchases"> مشتريات</label>
            <label class="perm-card"><input type="checkbox" class="perm-module" value="accounting"> حسابات</label>
            <label class="perm-card"><input type="checkbox" class="perm-module" value="store"> إدارة المخازن (أمين المخزن)</label>
            <label class="perm-card"><input type="checkbox" class="perm-module" value="contractors"> عقود ومقاولين</label>
            <label class="perm-card"><input type="checkbox" class="perm-module" value="settlements"> عهد وتسويات</label>
            <label class="perm-card"><input type="checkbox" class="perm-module" value="vouchers"> سندات ومرتجعات</label>
`;

if (!html.includes('value="sales"')) {
    // Find the end of the units label
    const regex = /<label class="perm-card"><input type="checkbox" class="perm-module" value="units">[^<]*<\/label>/;
    if (regex.test(html)) {
        html = html.replace(regex, match => match + missingModules);
        fs.writeFileSync('d:/برنامج مخازن/index.html', html, 'utf8');
        console.log('Successfully injected missing modules into index.html');
    } else {
        console.log('Regex did not match the units label.');
    }
} else {
    console.log('Already has sales module.');
}
