File size: 6,598 Bytes
33b5019
4732481
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33b5019
4732481
 
 
33b5019
 
 
 
6110ac3
 
33b5019
6110ac3
 
 
 
 
 
 
 
33b5019
 
 
 
 
 
 
 
 
 
 
2a1f177
33b5019
2a1f177
33b5019
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2a1f177
33b5019
 
6110ac3
33b5019
 
6110ac3
33b5019
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6110ac3
 
 
33b5019
 
 
6110ac3
 
 
 
 
 
 
 
 
 
 
33b5019
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
```javascript
// API configuration
const API_BASE_URL = 'http://localhost:3000/api'; // Change to your backend URL

// Check backend connection
async function checkBackendConnection() {
  try {
    const response = await fetch(`${API_BASE_URL}/health`);
    const data = await response.json();
    const statusElement = document.getElementById('apiStatus');
    
    if (data.ok) {
      statusElement.textContent = 'API Status: Connected';
      statusElement.className = 'connected';
    } else {
      statusElement.textContent = 'API Status: Disconnected';
      statusElement.className = 'disconnected';
    }
  } catch (error) {
    console.error('Backend connection error:', error);
    document.getElementById('apiStatus').textContent = 'API Status: Connection Failed';
    document.getElementById('apiStatus').className = 'disconnected';
  }
}

document.addEventListener('DOMContentLoaded', () => {
  // First check backend status
  checkBackendConnection();
// Project creation handling
  const fileInput = document.getElementById('fileInput');
  const fileList = document.getElementById('fileList');
  const dropZone = document.getElementById('dropZone');
  const processBtn = document.getElementById('processBtn');
  const projectName = document.getElementById('projectName');
  const projectTypes = document.querySelectorAll('.project-type');
  
  // Project type selection
  projectTypes.forEach(type => {
    type.addEventListener('click', () => {
      projectTypes.forEach(t => t.classList.remove('active'));
      type.classList.add('active');
    });
  });
// Tab switching
  const tabBtns = document.querySelectorAll('.tab-btn');
  tabBtns.forEach(btn => {
    btn.addEventListener('click', () => {
      // Remove active class from all buttons and tabs
      document.querySelectorAll('.tab-btn').forEach(b => b.classList.remove('active'));
      document.querySelectorAll('.tab-content').forEach(t => t.classList.remove('active'));
      
      // Add active class to clicked button and corresponding tab
      btn.classList.add('active');
      const tabId = btn.getAttribute('data-tab');
      document.getElementById(tabId).classList.add('active');
    });
  });

  // Drag and drop functionality
  ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
    dropZone.addEventListener(eventName, preventDefaults, false);
  });

  function preventDefaults(e) {
    e.preventDefault();
    e.stopPropagation();
  }

  ['dragenter', 'dragover'].forEach(eventName => {
    dropZone.addEventListener(eventName, highlight, false);
  });

  ['dragleave', 'drop'].forEach(eventName => {
    dropZone.addEventListener(eventName, unhighlight, false);
  });

  function highlight() {
    dropZone.classList.add('drag-over');
  }

  function unhighlight() {
    dropZone.classList.remove('drag-over');
  }

  dropZone.addEventListener('drop', handleDrop, false);

  function handleDrop(e) {
    const dt = e.dataTransfer;
    const files = dt.files;
    handleFiles(files);
  }

  fileInput.addEventListener('change', function() {
    handleFiles(this.files);
  });
  function handleFiles(files) {
    fileList.innerHTML = '';
    if (files.length === 0) return;
    
    for (let i = 0; i < files.length; i++) {
      const file = files[i];
      if (!file.type.match('application/pdf|application/vnd.openxmlformats-officedocument.wordprocessingml.document|text/plain|application/vnd.ms-powerpoint|application/vnd.openxmlformats-officedocument.presentationml.presentation')) {
        continue;
      }
const fileItem = document.createElement('div');
      fileItem.className = 'file-item';
      fileItem.innerHTML = `
        <span>${file.name}</span>
        <i class="fas fa-times" data-index="${i}"></i>
      `;
      fileList.appendChild(fileItem);
      
      // Add remove file functionality
      fileItem.querySelector('i').addEventListener('click', function() {
        fileItem.remove();
        // In a real app, you would remove the file from the upload list
      });
    }
    
    if (fileList.children.length > 0) {
      processBtn.disabled = false;
    } else {
      processBtn.disabled = true;
    }
  }

  // Process files button
  processBtn.addEventListener('click', async function() {
    if (fileList.children.length === 0) {
      alert('ืื ื ื”ืขืœื” ืœืคื—ื•ืช ืงื•ื‘ืฅ ืื—ื“');
      return;
    }
    
    const projectNameValue = projectName.value.trim();
    if (!projectNameValue) {
      alert('ืื ื ื”ื–ืŸ ืฉื ืœืคืจื•ื™ืงื˜');
      return;
    }
    
    // Get selected output options
    const outputOptions = [];
    document.querySelectorAll('input[name="output"]:checked').forEach(checkbox => {
      outputOptions.push(checkbox.value);
    });
    
    if (outputOptions.length === 0) {
      alert('ืื ื ื‘ื—ืจ ืœืคื—ื•ืช ืืคืฉืจื•ืช ืคืœื˜ ืื—ืช');
      return;
    }
// Show loading state
    const originalText = processBtn.innerHTML;
    processBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> ืžืขื‘ื“...';
    processBtn.disabled = true;
    
    try {
      // Simulate processing (in a real app, this would be an API call)
      await new Promise(resolve => setTimeout(resolve, 3000));
      
      // Generate sample study materials
      generateSampleMaterials();
      
      // Show success message
      alert('ื—ื•ืžืจื™ ื”ืœื™ืžื•ื“ ื ื•ืฆืจื• ื‘ื”ืฆืœื—ื”!');
      
      // Switch to notes tab
      document.querySelector('.tab-btn[data-tab="notes"]').click();
      
    } catch (error) {
      console.error('Error processing files:', error);
      alert('ืื™ืจืขื” ืฉื’ื™ืื” ื‘ืขื™ื‘ื•ื“ ื”ืงื‘ืฆื™ื. ื ืกื” ืฉื•ื‘.');
    } finally {
      processBtn.innerHTML = originalText;
      processBtn.disabled = false;
    }
  });

  function generateSampleMaterials() {
    // Generate sample notes
    const notesTab = document.getElementById('notes');
    notesTab.innerHTML = `
      <div class="study-material">
        <h3>ืกื™ื›ื•ื ื”ืžืกืžืš</h3>
        <div class="content">
          <p>ื”ืžืกืžืš ื“ืŸ ื‘ื ื•ืฉืื™ื ืžืจื›ื–ื™ื™ื ื‘ืชื—ื•ื ื”ืœื™ืžื•ื“. ืœื”ืœืŸ ืขื™ืงืจื™ ื”ื“ื‘ืจื™ื:</p>
          <ul>
            <li>ื”ืงื“ืžื” ื”ื™ืกื˜ื•ืจื™ืช ืœื”ืชืคืชื—ื•ืช ื”ืชื—ื•ื</li>
            <li>ื”ื’ื“ืจื•ืช ื™ืกื•ื“ ื•ืžื•ืฉื’ื™ ืžืคืชื—</li>
            <li>ืชื™ืื•ืจื™ื•ืช ืžืจื›ื–ื™ื•ืช ื•ื”ืฉื•ื•ืื” ื‘ื™ื ื™ื”ืŸ</li>
            <li>ื™ื™ืฉื•ืžื™ื ืžืขืฉื™ื™ื ื•ืจืœื•ื•ื ื˜ื™ื•ืช ืœืชืงื•ืคื” ื”ื ื•ื›ื—ื™ืช</li>
          </ul>
          <p>ื”ืกื™ื›ื•ื ืžื‘ื•ืกืก ืขืœ ื ื™ืชื•ื— ืฉืœ 3 ืžืกืžื›ื™ื ืฉื”ืขืœื™ืช.</p>
        </div>
        <div class