2024-12-20 22:15:26 +01:00
|
|
|
import { createRecommendationPopup, populateAuthorsContainer } from './recommendations-utils.js';
|
2024-12-10 22:53:16 +01:00
|
|
|
|
2024-12-29 12:48:45 +01:00
|
|
|
// StarterKit-Element erstellen
|
2024-12-10 22:53:16 +01:00
|
|
|
export function createStarterKitElement(kit) {
|
|
|
|
const template = document.getElementById('starterkit-template').content.cloneNode(true);
|
|
|
|
|
2024-12-12 22:30:51 +01:00
|
|
|
// Titel und Beschreibung
|
2024-12-10 22:53:16 +01:00
|
|
|
const kitElement = template.querySelector('.starterkit');
|
|
|
|
kitElement.querySelector('h3').textContent = kit.name;
|
|
|
|
kitElement.querySelector('p').textContent = kit.description;
|
|
|
|
|
2024-12-29 12:48:45 +01:00
|
|
|
// Profilanzahl
|
2024-12-10 22:53:16 +01:00
|
|
|
const profileCount = kitElement.querySelector('.profile-count');
|
2024-12-14 22:10:17 +01:00
|
|
|
profileCount.querySelector('.profile-line2').textContent = `${kit.accounts.length}`;
|
2024-12-10 22:53:16 +01:00
|
|
|
|
2024-12-29 12:48:45 +01:00
|
|
|
// Autoren hinzufügen
|
2024-12-19 20:40:34 +01:00
|
|
|
const authorsContainer = kitElement.querySelector('.authors-container');
|
|
|
|
if (!authorsContainer) {
|
|
|
|
console.error('Fehlendes Element: .authors-container im Template. Bitte prüfen!');
|
2024-12-29 12:48:45 +01:00
|
|
|
return kitElement;
|
2024-12-19 20:40:34 +01:00
|
|
|
}
|
|
|
|
|
2024-12-29 12:48:45 +01:00
|
|
|
populateAuthorsContainer(authorsContainer, kit.authors);
|
2024-12-10 22:53:16 +01:00
|
|
|
kitElement.dataset.accounts = JSON.stringify(kit.accounts);
|
2025-01-12 00:11:54 +01:00
|
|
|
kitElement.dataset.authors = JSON.stringify(kit.authors);
|
2024-12-10 22:53:16 +01:00
|
|
|
|
|
|
|
return kitElement;
|
|
|
|
}
|
|
|
|
|
2024-12-29 12:48:45 +01:00
|
|
|
// StarterKits mit Event-Listenern versehen
|
2024-12-10 22:53:16 +01:00
|
|
|
export function enhanceStarterKits() {
|
|
|
|
const starterkits = document.querySelectorAll('.starterkit');
|
|
|
|
|
|
|
|
starterkits.forEach(kit => {
|
|
|
|
kit.addEventListener('click', function () {
|
2024-12-29 12:48:45 +01:00
|
|
|
handleStarterKitClick(kit);
|
2024-12-10 22:53:16 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2024-12-14 22:10:17 +01:00
|
|
|
|
2024-12-29 12:48:45 +01:00
|
|
|
// StarterKit-Klick behandeln
|
|
|
|
function handleStarterKitClick(kit) {
|
2025-01-12 00:11:54 +01:00
|
|
|
loadStarterKitProfiles(kit);
|
2024-12-29 12:48:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// StarterKit-Profile laden
|
2024-12-14 22:10:17 +01:00
|
|
|
function loadStarterKitProfiles(kit) {
|
|
|
|
const title = kit.querySelector('h3').textContent;
|
2024-12-29 12:48:45 +01:00
|
|
|
const description = kit.querySelector('p').textContent;
|
2024-12-14 22:10:17 +01:00
|
|
|
const accounts = JSON.parse(kit.dataset.accounts || '[]');
|
2025-01-12 00:11:54 +01:00
|
|
|
const authors = JSON.parse(kit.dataset.authors || '[]');
|
2024-12-19 22:38:21 +01:00
|
|
|
|
|
|
|
const popup = createRecommendationPopup(accounts, title, authors, description);
|
2024-12-14 22:10:17 +01:00
|
|
|
document.body.appendChild(popup);
|
|
|
|
}
|