const fs = require('fs');
let fileContent = fs.readFileSync('src/main/resources/templates/dao-tao-detail.html', 'utf8');
// 1. Remove the hardcoded tabs from the HTML layout
fileContent = fileContent.replace(
`
Tổng quan
Thông tin chung
`,
`
`
);
// 2. Add the trainingCourseInfo block renderer to blocksToHtml function
const newBlockHandler = `
case "trainingCourseInfo":
var d = block.data;
var introHtml = d.introText ? d.introText.split('\\n').filter(p=>p.trim()!=='').map(p => ''+p+'
').join('') : '';
var hoSoHtml = d.documents ? d.documents.split('\\n').filter(p=>p.trim()!=='').map(p => ''+p+' ').join('') : '';
if(hoSoHtml) hoSoHtml = '';
var luuYHtml = d.notes ? d.notes.split('\\n').filter(p=>p.trim()!=='').map(p => ''+p+' ').join('') : '';
if(luuYHtml) luuYHtml = '';
var locationHtml = d.location ? d.location.split('\\n').filter(p=>p.trim()!=='').map(p => ''+p+'
').join('') : '';
// Generating the complete Tabs HTML
html += '';
html += '
';
html += '
';
html += ' Tổng quan ';
html += ' Thông tin chung ';
html += '
';
html += '
';
// Tab 1
html += '
';
if(introHtml) html += introHtml;
if(d.bannerText) {
html += '
' + d.bannerText + '
';
}
html += '
';
html += '';
if(d.time) html += 'Thời gian: ' + d.time.replace(/\\n/g, ' ') + ' ';
if(d.audience) html += 'Đối tượng đăng ký: ' + d.audience.replace(/\\n/g, ' ') + ' ';
var thongTinLopHoc = '';
if(d.fileChieuSinh) thongTinLopHoc += 'Thông báo chiêu sinh file đính kèm ';
if(d.filePhieuDangKy) thongTinLopHoc += (thongTinLopHoc?' và ':'') + 'phiếu đăng ký file đính kèm ';
if(thongTinLopHoc) html += 'Thông tin lớp học ' + thongTinLopHoc + '
';
if(d.quantity) html += 'Số lượng: ' + d.quantity + ' ';
if(hoSoHtml) html += 'Hồ sơ đăng ký tham dự: ' + hoSoHtml + ' ';
if(luuYHtml) html += 'Lưu ý: ' + luuYHtml + ' ';
html += '
';
html += '
';
// Tab 2
html += '
';
html += '
';
html += '';
if(d.tuitionFee) html += 'Học phí: ' + d.tuitionFee + ' ';
if(locationHtml) html += 'Địa điểm nhận hồ sơ và học phí: ' + locationHtml + ' ';
var bankHtml = '';
if(d.bankAccountName) bankHtml += 'Tên tài khoản: ' + d.bankAccountName + ' ';
if(d.bankAccountNumber) bankHtml += 'Số tài khoản: ' + d.bankAccountNumber + ' ';
if(d.bankName) bankHtml += 'Tên ngân hàng: ' + d.bankName + ' ';
if(d.transferContent) bankHtml += 'Nội dung: ' + d.transferContent + ' ';
if(bankHtml) {
html += 'Hình thức nộp học phí: ';
html += 'Chuyển khoản: ';
}
html += '
';
html += '
';
html += '
';
break;
case "raw":`;
fileContent = fileContent.replace('case "raw":', newBlockHandler);
// 3. Remove the complicated tabSplit logic and leave just normal parsing
const tabSplitLogicRegex = /var isJsonSplit = false;[\s\S]*?if \(!isJsonSplit\) \{[\s\S]*?if \(contentText.indexOf\(''\) !== -1\) \{[\s\S]*?\} else \{[\s\S]*?parseEditorContent\(contentText, 'postContentParsed'\);[\s\S]*?parseEditorContent\(excerptText, 'postGeneralInfoParsed'\);[\s\S]*?\}[\s\S]*?\}/;
fileContent = fileContent.replace(tabSplitLogicRegex, "parseEditorContent(contentText, 'postContentParsed');");
// 4. Add the switchTrainingTab function script
const scriptToAppend = `
`;
if (!fileContent.includes('function switchTrainingTab')) {
fileContent = fileContent.replace('