const fs = require('fs');
let c = fs.readFileSync('index.html', 'utf8');

const missingBlock = `
  <!-- Voucher Modal -->
  <div id="voucher-modal" class="modal" style="z-index: 9999999 !important;">
    <div class="modal-content" style="width: 500px; max-width: 95%; max-height: 90vh; overflow-y: auto;">
      <h3 id="voucher-modal-title">إنشاء سند</h3>
      <input type="hidden" id="edit-voucher-id">
      <input type="hidden" id="voucher-type">
      <div class="flex-col" style="margin-bottom: 10px;">
        <label>التاريخ</label>
        <input type="datetime-local" id="voucher-date">
      </div>
      <div class="flex-col" style="margin-bottom: 10px;">
        <label>رقم المستند / المرجع</label>
        <input type="text" id="voucher-doc-no" placeholder="اختياري">
      </div>
      <div class="flex-col" style="margin-bottom: 10px;">
        <label id="voucher-contact-label">جهة / مستفيد</label>`;

if (!c.includes('<div id="voucher-modal"')) {
    c = c.replace(/<div class="flex-col" style="margin-bottom: 10px;">\s*<label id="voucher-contact-label">جهة \/ مستفيد<\/label>/, missingBlock);
    fs.writeFileSync('index.html', c);
    console.log('Fixed index.html!');
} else {
    console.log('Block already exists, nothing to fix.');
}
