class CustomSidebar extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: 'open' });
}
connectedCallback() {
this.render();
this.addEventListeners();
}
static get observedAttributes() {
return ['current-project', 'current-tool'];
}
attributeChangedCallback(name, oldValue, newValue) {
if (oldValue !== newValue) {
this.render();
}
}
render() {
const currentProject = this.getAttribute('current-project') || 'Espace Codage - Projet 1';
const currentTool = this.getAttribute('current-tool') || '';
this.shadowRoot.innerHTML = `
CodeWhale
Projets
Espace Codage - Projet 1
Espace Codage - Projet 2
Outils
La Baleine
Rosalinda
CodeExplainer
ThemeGenerator
`;
feather.replace();
}
addEventListeners() {
this.shadowRoot.addEventListener('click', (e) => {
const projectItem = e.target.closest('.project-item');
const toolItem = e.target.closest('.tool-item');
if (projectItem) {
const project = projectItem.getAttribute('data-project');
window.appState.currentProject = project;
window.appState.currentTool = null;
window.appState.updateUI();
}
if (toolItem) {
const tool = toolItem.getAttribute('data-tool');
window.appState.currentTool = tool;
// Simulate generating some code when a tool is selected
if (tool === 'ThemeGenerator') {
window.appState.generatedCode = `body {\n background-color: #f8fafc;\n color: #1e293b;\n}\n\n.button {\n background-color: #3b82f6;\n color: white;\n}`;
window.appState.codeExplanation = window.appState.generateCodeExplanation(window.appState.generatedCode);
window.appState.generatedImage = window.appState.generateImageFromCode(window.appState.generatedCode);
}
window.appState.updateUI();
}
});
}
}
customElements.define('custom-sidebar', CustomSidebar);