File size: 5,313 Bytes
adcd9ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr

class DTCDisplay(gr.HTML):
    """Custom component for displaying Diagnostic Trouble Codes as cards"""

    def __init__(self, value=None, **kwargs):
        html_template = """
        <div class="dtc-main">
            <h3 class="dtc-title">πŸ”§ Diagnostic Trouble Codes</h3>
            <div class="dtc-wrapper">
                ${value && value.length > 0 ? `
                    <div class="dtc-container">
                        ${value.map(dtc => {
                            const firstLetter = dtc.code.charAt(0).toUpperCase();
                            let cardClass = 'dtc-card';
                            let icon = '⚠️';

                            if (firstLetter === 'P') {
                                cardClass += ' dtc-powertrain';
                                icon = 'βš™οΈ';
                            } else if (firstLetter === 'C') {
                                cardClass += ' dtc-chassis';
                                icon = 'πŸš—';
                            } else if (firstLetter === 'B') {
                                cardClass += ' dtc-body';
                                icon = 'πŸ”Œ';
                            } else if (firstLetter === 'U') {
                                cardClass += ' dtc-network';
                                icon = 'πŸ“‘';
                            }

                            return `<div class="${cardClass}">
                                <div class="dtc-header">
                                    <div class="dtc-icon">${icon}</div>
                                    <div class="dtc-code">${dtc.code}</div>
                                </div>
                                <div class="dtc-description">${dtc.description}</div>
                            </div>`;
                        }).join('')}
                    </div>
                ` : `
                    <div class="dtc-empty">βœ“ No fault codes detected</div>
                `}
            </div>
        </div>
        """

        css_template = """
        .dtc-main {
            width: 100%;
        }

        .dtc-title {
            margin: 0 0 12px 0;
            font-size: 18px;
            font-weight: 600;
            color: #333;
        }

        .dtc-wrapper {
            width: 100%;
            border: 1px solid #e0e0e0;
            border-radius: 8px;
            padding: 16px;
        }

        .dtc-container {
            display: flex;
            flex-wrap: wrap;
            gap: 16px;
            padding: 0;
            justify-content: center;
        }

        .dtc-card {
            border-radius: 8px;
            padding: 10px 12px;
            box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
            min-width: 140px;
            max-width: 190px;
            flex: 1 1 auto;
            display: flex;
            flex-direction: column;
            gap: 8px;
            transition: transform 0.2s ease, box-shadow 0.2s ease;
        }

        .dtc-card:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
        }

        /* Powertrain - Orange/Amber */
        .dtc-powertrain {
            background: linear-gradient(135deg, #ffa726 0%, #ff9800 100%);
        }

        /* Chassis - Blue */
        .dtc-chassis {
            background: linear-gradient(135deg, #42a5f5 0%, #2196f3 100%);
        }

        /* Body - Purple */
        .dtc-body {
            background: linear-gradient(135deg, #ab47bc 0%, #9c27b0 100%);
        }

        /* Network - Green */
        .dtc-network {
            background: linear-gradient(135deg, #66bb6a 0%, #4caf50 100%);
        }

        .dtc-header {
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
        }

        .dtc-icon {
            font-size: 26px;
            filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.15));
        }

        .dtc-code {
            font-size: 14px;
            font-weight: bold;
            color: white;
            font-family: 'Courier New', monospace;
            letter-spacing: 1px;
            text-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
        }

        .dtc-description {
            font-size: 13px;
            color: rgba(255, 255, 255, 0.95);
            text-align: center;
            line-height: 1.4;
        }

        .dtc-empty {
            color: #4caf50;
            font-weight: 500;
            text-align: center;
            padding: 24px;
            font-size: 15px;
        }
        """

        super().__init__(
            value=value or [],
            html_template=html_template,
            css_template=css_template,
            **kwargs
        )

# Example usage:
# dtc_display = DTCDisplay(value=[{'code': 'P0420', 'description': 'Catalyst System Efficiency Below Threshold'}, {'
# 'code': 'C1234', 'description': 'Wheel Speed Sensor Malfunction'}])   

#   To update the DTCDisplay component with actual DTCs, you can use it like this:

#   dtc_display.update(value=[
#       {"code": "P0420", "description": "Catalyst System Efficiency Below Threshold"},
#       {"code": "P0103", "description": "Mass Air Flow Circuit High Input"},
#       {"code": "P0171", "description": "System Too Lean (Bank 1)"}
#   ])