File size: 17,207 Bytes
99fe73b
 
7764813
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99fe73b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7764813
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99fe73b
 
7764813
99fe73b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
// Mock data for admin panel
const mockContacts = [
    { 
        id: 1, 
        name: "John Doe", 
        email: "john@example.com", 
        phone: "555-1234", 
        city: "New York",
        attachments: [
            { name: "project-brief.pdf", url: "http://static.photos/document/640x360/1" },
            { name: "reference.jpg", url: "http://static.photos/nature/640x360/1" }
        ]
    },
    { 
        id: 2, 
        name: "Jane Smith", 
        email: "jane@example.com", 
        phone: "555-5678", 
        city: "Los Angeles",
        attachments: []
    }
];
const mockSubscribers = [
    { id: 1, email: "user1@example.com", date: "2023-01-15" },
    { id: 2, email: "user2@example.com", date: "2023-02-20" }
];

// DOM elements
const adminContent = document.getElementById('admin-content');

// Navigation functions
function loadProjectsManagement() {
    adminContent.innerHTML = `
        <div class="bg-white rounded-xl shadow-md p-6">
            <div class="flex justify-between items-center mb-6">
                <h2 class="text-2xl font-bold text-gray-800">Projects Management</h2>
                <button id="add-project-btn" class="bg-primary text-white px-4 py-2 rounded-lg hover:bg-primary-600 transition duration-300">
                    <i data-feather="plus" class="mr-2"></i> Add Project
                </button>
            </div>
            
            <!-- Add Project Form (hidden by default) -->
            <div id="add-project-form" class="hidden mb-8">
                <form id="project-form" class="space-y-4">
                    <div>
                        <label for="project-image" class="block text-gray-700 mb-2">Project Image</label>
                        <input type="file" id="project-image" name="project-image" accept="image/*" class="w-full px-4 py-2 border border-gray-300 rounded-lg">
                    </div>
                    <div>
                        <label for="project-name" class="block text-gray-700 mb-2">Project Name</label>
                        <input type="text" id="project-name" name="project-name" required class="w-full px-4 py-2 border border-gray-300 rounded-lg">
                    </div>
                    <div>
                        <label for="project-description" class="block text-gray-700 mb-2">Description</label>
                        <textarea id="project-description" name="project-description" rows="4" required class="w-full px-4 py-2 border border-gray-300 rounded-lg"></textarea>
                    </div>
                    <div class="flex space-x-4">
                        <button type="submit" class="bg-primary text-white px-4 py-2 rounded-lg hover:bg-primary-600 transition duration-300">
                            Save Project
                        </button>
                        <button type="button" id="cancel-project-btn" class="bg-gray-200 text-gray-700 px-4 py-2 rounded-lg hover:bg-gray-300 transition duration-300">
                            Cancel
                        </button>
                    </div>
                </form>
            </div>
            
            <!-- Projects List -->
            <div class="overflow-x-auto">
                <table class="min-w-full bg-white">
                    <thead>
                        <tr class="border-b border-gray-200">
                            <th class="py-3 px-4 text-left text-gray-700">Image</th>
                            <th class="py-3 px-4 text-left text-gray-700">Name</th>
                            <th class="py-3 px-4 text-left text-gray-700">Description</th>
                            <th class="py-3 px-4 text-left text-gray-700">Actions</th>
                        </tr>
                    </thead>
                    <tbody id="projects-list">
                        ${mockProjects.map(project => `
                            <tr class="border-b border-gray-200 hover:bg-gray-50">
                                <td class="py-4 px-4">
                                    <img src="${project.image}" alt="${project.name}" class="w-20 h-12 object-cover rounded">
                                </td>
                                <td class="py-4 px-4 font-medium text-gray-800">${project.name}</td>
                                <td class="py-4 px-4 text-gray-600">${project.description.substring(0, 50)}...</td>
                                <td class="py-4 px-4">
                                    <div class="flex space-x-2">
                                        <button class="edit-project-btn p-2 text-blue-500 hover:bg-blue-50 rounded" data-id="${project.id}">
                                            <i data-feather="edit"></i>
                                        </button>
                                        <button class="delete-project-btn p-2 text-red-500 hover:bg-red-50 rounded" data-id="${project.id}">
                                            <i data-feather="trash-2"></i>
                                        </button>
                                    </div>
                                </td>
                            </tr>
                        `).join('')}
                    </tbody>
                </table>
            </div>
        </div>
    `;
    
    feather.replace();
    
    // Form toggle
    document.getElementById('add-project-btn').addEventListener('click', () => {
        document.getElementById('add-project-form').classList.toggle('hidden');
    });
    
    document.getElementById('cancel-project-btn').addEventListener('click', () => {
        document.getElementById('add-project-form').classList.add('hidden');
    });
    
    // Form submission
    document.getElementById('project-form').addEventListener('submit', (e) => {
        e.preventDefault();
        alert('Project saved successfully!');
        document.getElementById('add-project-form').classList.add('hidden');
        document.getElementById('project-form').reset();
    });
}

function loadClientsManagement() {
    adminContent.innerHTML = `
        <div class="bg-white rounded-xl shadow-md p-6">
            <div class="flex justify-between items-center mb-6">
                <h2 class="text-2xl font-bold text-gray-800">Clients Management</h2>
                <button id="add-client-btn" class="bg-primary text-white px-4 py-2 rounded-lg hover:bg-primary-600 transition duration-300">
                    <i data-feather="plus" class="mr-2"></i> Add Client
                </button>
            </div>
            
            <!-- Add Client Form (hidden by default) -->
            <div id="add-client-form" class="hidden mb-8">
                <form id="client-form" class="space-y-4">
                    <div>
                        <label for="client-image" class="block text-gray-700 mb-2">Client Image</label>
                        <input type="file" id="client-image" name="client-image" accept="image/*" class="w-full px-4 py-2 border border-gray-300 rounded-lg">
                    </div>
                    <div>
                        <label for="client-name" class="block text-gray-700 mb-2">Client Name</label>
                        <input type="text" id="client-name" name="client-name" required class="w-full px-4 py-2 border border-gray-300 rounded-lg">
                    </div>
                    <div>
                        <label for="client-designation" class="block text-gray-700 mb-2">Designation</label>
                        <input type="text" id="client-designation" name="client-designation" required class="w-full px-4 py-2 border border-gray-300 rounded-lg">
                    </div>
                    <div>
                        <label for="client-description" class="block text-gray-700 mb-2">Testimonial</label>
                        <textarea id="client-description" name="client-description" rows="4" required class="w-full px-4 py-2 border border-gray-300 rounded-lg"></textarea>
                    </div>
                    <div class="flex space-x-4">
                        <button type="submit" class="bg-primary text-white px-4 py-2 rounded-lg hover:bg-primary-600 transition duration-300">
                            Save Client
                        </button>
                        <button type="button" id="cancel-client-btn" class="bg-gray-200 text-gray-700 px-4 py-2 rounded-lg hover:bg-gray-300 transition duration-300">
                            Cancel
                        </button>
                    </div>
                </form>
            </div>
            
            <!-- Clients List -->
            <div class="overflow-x-auto">
                <table class="min-w-full bg-white">
                    <thead>
                        <tr class="border-b border-gray-200">
                            <th class="py-3 px-4 text-left text-gray-700">Image</th>
                            <th class="py-3 px-4 text-left text-gray-700">Name</th>
                            <th class="py-3 px-4 text-left text-gray-700">Designation</th>
                            <th class="py-3 px-4 text-left text-gray-700">Testimonial</th>
                            <th class="py-3 px-4 text-left text-gray-700">Actions</th>
                        </tr>
                    </thead>
                    <tbody id="clients-list">
                        ${mockClients.map(client => `
                            <tr class="border-b border-gray-200 hover:bg-gray-50">
                                <td class="py-4 px-4">
                                    <img src="${client.image}" alt="${client.name}" class="w-12 h-12 rounded-full object-cover">
                                </td>
                                <td class="py-4 px-4 font-medium text-gray-800">${client.name}</td>
                                <td class="py-4 px-4 text-gray-600">${client.designation}</td>
                                <td class="py-4 px-4 text-gray-600">"${client.description.substring(0, 50)}..."</td>
                                <td class="py-4 px-4">
                                    <div class="flex space-x-2">
                                        <button class="edit-client-btn p-2 text-blue-500 hover:bg-blue-50 rounded" data-id="${client.id}">
                                            <i data-feather="edit"></i>
                                        </button>
                                        <button class="delete-client-btn p-2 text-red-500 hover:bg-red-50 rounded" data-id="${client.id}">
                                            <i data-feather="trash-2"></i>
                                        </button>
                                    </div>
                                </td>
                            </tr>
                        `).join('')}
                    </tbody>
                </table>
            </div>
        </div>
    `;
    
    feather.replace();
    
    // Form toggle
    document.getElementById('add-client-btn').addEventListener('click', () => {
        document.getElementById('add-client-form').classList.toggle('hidden');
    });
    
    document.getElementById('cancel-client-btn').addEventListener('click', () => {
        document.getElementById('add-client-form').classList.add('hidden');
    });
    
    // Form submission
    document.getElementById('client-form').addEventListener('submit', (e) => {
        e.preventDefault();
        alert('Client saved successfully!');
        document.getElementById('add-client-form').classList.add('hidden');
        document.getElementById('client-form').reset();
    });
}

function loadContactResponses() {
    adminContent.innerHTML = `
        <div class="bg-white rounded-xl shadow-md p-6">
            <h2 class="text-2xl font-bold text-gray-800 mb-6">Contact Form Responses</h2>
            
            <div class="overflow-x-auto">
                <table class="min-w-full bg-white">
                    <thead>
                        <tr class="border-b border-gray-200">
                            <th class="py-3 px-4 text-left text-gray-700">Name</th>
                            <th class="py-3 px-4 text-left text-gray-700">Email</th>
                            <th class="py-3 px-4 text-left text-gray-700">Phone</th>
                            <th class="py-3 px-4 text-left text-gray-700">City</th>
                            <th class="py-3 px-4 text-left text-gray-700">Actions</th>
                        </tr>
                    </thead>
                    <tbody id="contacts-list">
                        ${mockContacts.map(contact => `
                            <tr class="border-b border-gray-200 hover:bg-gray-50">
                                <td class="py-4 px-4 font-medium text-gray-800">${contact.name}</td>
                                <td class="py-4 px-4 text-gray-600">${contact.email}</td>
                                <td class="py-4 px-4 text-gray-600">${contact.phone}</td>
                                <td class="py-4 px-4 text-gray-600">${contact.city}</td>
                                <td class="py-4 px-4">
                                    <div class="flex items-center space-x-4">
                                        ${contact.attachments.length > 0 ? `
                                            <div class="relative group">
                                                <button class="view-attachments-btn p-2 text-blue-500 hover:bg-blue-50 rounded" data-id="${contact.id}">
                                                    <i data-feather="paperclip"></i>
                                                </button>
                                                <div class="attachments-popup hidden absolute right-0 z-10 mt-2 w-64 bg-white rounded-md shadow-lg p-2 group-hover:block">
                                                    <div class="text-xs font-medium text-gray-500 mb-1">Attachments (${contact.attachments.length})</div>
                                                    ${contact.attachments.map(file => `
                                                        <a href="${file.url}" target="_blank" class="block px-2 py-1 text-sm text-gray-700 hover:bg-gray-100 rounded">
                                                            <i data-feather="${file.name.endsWith('.pdf') ? 'file-text' : file.name.match(/\.(jpg|png|gif)$/) ? 'image' : 'file'}" class="w-4 h-4 mr-2 inline"></i>
                                                            ${file.name}
                                                        </a>
                                                    `).join('')}
                                                </div>
                                            </div>
                                        ` : ''}
                                        <button class="delete-contact-btn p-2 text-red-500 hover:bg-red-50 rounded" data-id="${contact.id}">
                                            <i data-feather="trash-2"></i>
                                        </button>
                                    </div>
                                </td>
                            </tr>
`).join('')}
                    </tbody>
                </table>
            </div>
        </div>
    `;
    
    feather.replace();
}

function loadSubscribers() {
    adminContent.innerHTML = `
        <div class="bg-white rounded-xl shadow-md p-6">
            <h2 class="text-2xl font-bold text-gray-800 mb-6">Newsletter Subscribers</h2>
            
            <div class="overflow-x-auto">
                <table class="min-w-full bg-white">
                    <thead>
                        <tr class="border-b border-gray-200">
                            <th class="py-3 px-4 text-left text-gray-700">Email</th>
                            <th class="py-3 px-4 text-left text-gray-700">Subscription Date</th>
                            <th class="py-3 px-4 text-left text-gray-700">Actions</th>
                        </tr>
                    </thead>
                    <tbody id="subscribers-list">
                        ${mockSubscribers.map(subscriber => `
                            <tr class="border-b border-gray-200 hover:bg-gray-50">
                                <td class="py-4 px-4 font-medium text-gray-800">${subscriber.email}</td>
                                <td class="py-4 px-4 text-gray-600">${subscriber.date}</td>
                                <td class="py-4 px-4">
                                    <button class="delete-subscriber-btn p-2 text-red-500 hover:bg-red-50 rounded" data-id="${subscriber.id}">
                                        <i data-feather="trash-2"></i>
                                    </button>
                                </td>
                            </tr>
                        `).join('')}
                    </tbody>
                </table>
            </div>
        </div>
    `;
    
    feather.replace();
}

// Initialize admin panel
document.addEventListener('DOMContentLoaded', function() {
    // This would be set based on navigation in the sidebar component
    // For now, we'll default to projects management
    loadProjectsManagement();
});