// Config Renderer - Handles all rendering logic class ConfigRenderer { constructor() { this.fieldTypes = { text: this.renderTextField.bind(this), number: this.renderNumberField.bind(this), email: this.renderEmailField.bind(this), password: this.renderPasswordField.bind(this), select: this.renderSelectField.bind(this), checkbox: this.renderCheckboxField.bind(this), textarea: this.renderTextareaField.bind(this) }; } renderSubcategoryWithMaster(masterKey, configItems, displaySubcategory, subcategoryDescription, isAdvanced = false) { const isEnabled = masterKey.value === 'true'; const sectionId = `master-${masterKey.key}`; let html = `

${displaySubcategory}

${subcategoryDescription}

`; // Add all other fields (excluding the master toggle) configItems.filter(item => item.key !== masterKey.key).forEach(item => { const fieldId = `config-${item.key}`; html += window.ConfigShared?.generateField(fieldId, item.key, item.value, item.title, item.description, item.options) || ''; }); html += `
`; return html; } renderSubcategorySection(configItems, displaySubcategory, subcategoryDescription, config = {}) { let html = `

${displaySubcategory}

${subcategoryDescription}

`; // Add all fields configItems.forEach(item => { const fieldId = `config-${item.key}`; html += window.ConfigShared?.generateField(fieldId, item.key, item.value, item.title, item.description, item.options, config) || ''; }); html += `
`; return html; } renderRegularSubcategory(configItems, displaySubcategory, subcategoryDescription, config = {}) { let html = `

${displaySubcategory}

${subcategoryDescription}

`; // Add all fields configItems.forEach(item => { const fieldId = `config-${item.key}`; html += window.ConfigShared?.generateField(fieldId, item.key, item.value, item.title, item.description, item.options, config) || ''; }); html += `
`; return html; } // Field rendering methods renderTextField(fieldId, key, value, title, description, options) { return `
${description ? `${this.cleanDescription(description)}` : ''}
`; } renderNumberField(fieldId, key, value, title, description, options) { return `
${description ? `${this.cleanDescription(description)}` : ''}
`; } renderEmailField(fieldId, key, value, title, description, options) { return `
${description ? `${this.cleanDescription(description)}` : ''}
`; } renderPasswordField(fieldId, key, value, title, description, options) { return `
${description ? `${this.cleanDescription(description)}` : ''}
`; } renderSelectField(fieldId, key, value, title, description, fieldOptions) { const options = window.ConfigOptions?.getSelectOptions(key) || []; return `
${description ? `${this.cleanDescription(description)}` : ''}
`; } renderCheckboxField(fieldId, key, value, title, description, options) { const isChecked = value === 'true' || value === true; return `
${description ? `${this.cleanDescription(description)}` : ''}
`; } renderTextareaField(fieldId, key, value, title, description, options) { return `
${description ? `${this.cleanDescription(description)}` : ''}
`; } togglePasswordVisibility(fieldId) { const input = document.getElementById(fieldId); const button = document.querySelector(`button[onclick*="${fieldId}"]`); if (input && button) { if (input.type === 'password') { input.type = 'text'; button.innerHTML = 'đŸ™ˆī¸'; } else { input.type = 'password'; button.innerHTML = 'đŸ‘ī¸'; } } } cleanDescription(description) { if (!description) return ''; return description.replace(/CFG_[A-Z_]+/g, '').replace(/[-_]/g, ' ').replace(/\b\w/g, l => l.toUpperCase()); } } // Export for use in other modules window.ConfigRenderer = ConfigRenderer;