File size: 3,845 Bytes
e9fb731
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
class CustomCodeExplanation extends HTMLElement {
    constructor() {
        super();
        this.attachShadow({ mode: 'open' });
    }

    connectedCallback() {
        this.render();
    }

    static get observedAttributes() {
        return ['explanation', 'generated-code'];
    }

    attributeChangedCallback(name, oldValue, newValue) {
        if (oldValue !== newValue) {
            this.render();
        }
    }

    render() {
        const explanation = this.getAttribute('explanation') || 'Select a tool to generate code and see explanations';
        const generatedCode = this.getAttribute('generated-code') || '// No code generated yet';

        this.shadowRoot.innerHTML = `
            <style>
                :host {
                    display: block;
                }
                
                .header {
                    display: flex;
                    align-items: center;
                    margin-bottom: 1.5rem;
                }
                
                .header i {
                    margin-right: 0.75rem;
                    color: #3b82f6;
                }
                
                .header h2 {
                    font-size: 1.25rem;
                    font-weight: 600;
                    color: #1e293b;
                }
                
                .explanation-box {
                    background-color: #f8fafc;
                    border-radius: 0.5rem;
                    padding: 1.5rem;
                    margin-bottom: 1.5rem;
                    border: 1px solid #e2e8f0;
                }
                
                .code-box {
                    background-color: #1e293b;
                    color: #f8fafc;
                    border-radius: 0.5rem;
                    padding: 1.5rem;
                    font-family: monospace;
                    white-space: pre-wrap;
                    position: relative;
                    overflow: hidden;
                }
                
                .code-box::before {
                    content: 'CODE';
                    position: absolute;
                    top: 0;
                    right: 0;
                    background-color: #3b82f6;
                    color: white;
                    font-size: 0.75rem;
                    padding: 0.25rem 0.5rem;
                    border-bottom-left-radius: 0.5rem;
                }
                
                .code-tabs {
                    display: flex;
                    margin-bottom: -1px;
                }
                
                .code-tab {
                    padding: 0.5rem 1rem;
                    background-color: #e2e8f0;
                    border: 1px solid #cbd5e1;
                    border-bottom: none;
                    border-radius: 0.375rem 0.375rem 0 0;
                    margin-right: 0.25rem;
                    cursor: pointer;
                }
                
                .code-tab.active {
                    background-color: #1e293b;
                    color: white;
                    border-color: #1e293b;
                }
            </style>
            
            <div class="header">
                <i data-feather="book-open"></i>
                <h2>Explication du Code</h2>
            </div>
            
            <div class="explanation-box">
                ${explanation}
            </div>
            
            <div class="code-tabs">
                <div class="code-tab active">CSS</div>
                <div class="code-tab">HTML</div>
                <div class="code-tab">JS</div>
            </div>
            
            <div class="code-box">
                ${generatedCode}
            </div>
        `;
        
        feather.replace();
    }
}

customElements.define('custom-code-explanation', CustomCodeExplanation);