export class TabManager {
constructor() {
this.activeTab = 'sam-dict';
this.currentFile = null;
this.currentFormat = 'text';
}
clearCurrentFile() {
this.currentFile = null;
this.currentFormat = 'text';
const preview = document.getElementById('binary-preview');
if (preview) {
preview.style.display = 'none';
}
}
switchTab(tabId) {
const validTabs = ['sam-dict', 'assembly-report', 'vcf', 'binary'];
if (!validTabs.includes(tabId)) {
console.warn(`Invalid tab ID: ${tabId}`);
return;
}
document.querySelectorAll('.tab-content').forEach(tab => {
tab.classList.remove('active');
});
document.querySelectorAll('.tab-button').forEach(btn => {
btn.classList.remove('active');
});
const tabContent = document.getElementById('tab-' + tabId);
if (tabContent) {
tabContent.classList.add('active');
}
document.querySelectorAll('.tab-button').forEach(btn => {
if (btn.onclick && btn.onclick.toString().includes(`'${tabId}'`)) {
btn.classList.add('active');
}
});
this.activeTab = tabId;
this.clearCurrentFile();
this.validateFormat();
}
validateFormat() {
const submitBtn = document.getElementById('submit-btn');
if (submitBtn) {
submitBtn.disabled = !this.hasValidContent();
}
}
hasValidContent() {
switch (this.activeTab) {
case 'sam-dict': {
const input = document.getElementById('header-input');
return (input && input.value.trim() !== '') || this.currentFile !== null;
}
case 'assembly-report': {
const input = document.getElementById('assembly-input');
return (input && input.value.trim() !== '') || this.currentFile !== null;
}
case 'vcf': {
const input = document.getElementById('vcf-input');
return (input && input.value.trim() !== '') || this.currentFile !== null;
}
case 'binary':
return this.currentFile !== null;
default:
return false;
}
}
getCurrentInput() {
switch (this.activeTab) {
case 'sam-dict': {
const textarea = document.getElementById('header-input');
const textContent = textarea ? textarea.value.trim() : '';
if (textContent) {
return {
type: 'text',
content: textContent,
format: 'sam'
};
} else if (this.currentFile) {
return {
type: 'file',
file: this.currentFile,
format: this.currentFormat
};
}
break;
}
case 'assembly-report': {
const textarea = document.getElementById('assembly-input');
const textContent = textarea ? textarea.value.trim() : '';
if (textContent) {
return {
type: 'text',
content: textContent,
format: 'assembly'
};
} else if (this.currentFile) {
return {
type: 'file',
file: this.currentFile,
format: this.currentFormat
};
}
break;
}
case 'vcf': {
const textarea = document.getElementById('vcf-input');
const textContent = textarea ? textarea.value.trim() : '';
if (textContent) {
return {
type: 'text',
content: textContent,
format: 'vcf'
};
} else if (this.currentFile) {
return {
type: 'file',
file: this.currentFile,
format: this.currentFormat
};
}
break;
}
case 'binary':
if (this.currentFile) {
return {
type: 'file',
file: this.currentFile,
format: this.currentFormat
};
}
break;
}
return null;
}
setCurrentFile(file, format) {
this.currentFile = file;
this.currentFormat = format;
this.validateFormat();
}
getTextareaId() {
switch (this.activeTab) {
case 'sam-dict':
return 'header-input';
case 'assembly-report':
return 'assembly-input';
case 'vcf':
return 'vcf-input';
default:
return null;
}
}
}