Spaces:
Running

File size: 4,472 Bytes
fab03ee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
class CustomStatsCard extends HTMLElement {
    static get observedAttributes() {
        return ['title', 'value', 'icon', 'color'];
    }

    constructor() {
        super();
        this.attachShadow({ mode: 'open' });
    }

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

    connectedCallback() {
        this.render();
    }

    render() {
        const title = this.getAttribute('title') || 'Title';
        const value = this.getAttribute('value') || '0';
        const icon = this.getAttribute('icon') || 'activity';
        const color = this.getAttribute('color') || 'primary';
        
        const colorClasses = {
            primary: 'from-primary-500 to-primary-600 shadow-primary-500/25',
            secondary: 'from-secondary-500 to-secondary-600 shadow-secondary-500/25',
            blue: 'from-blue-500 to-blue-600 shadow-blue-500/25',
            emerald: 'from-emerald-500 to-emerald-600 shadow-emerald-500/25',
            rose: 'from-rose-500 to-rose-600 shadow-rose-500/25'
        };

        const iconColors = {
            primary: 'text-primary-400',
            secondary: 'text-secondary-400',
            blue: 'text-blue-400',
            emerald: 'text-emerald-400',
            rose: 'text-rose-400'
        };

        this.shadowRoot.innerHTML = `
            <style>
                :host {
                    display: block;
                }
                .card {
                    background: rgba(30, 41, 59, 0.6);
                    backdrop-filter: blur(12px);
                    border: 1px solid rgba(255, 255, 255, 0.05);
                    transition: all 0.3s ease;
                }
                .card:hover {
                    transform: translateY(-2px);
                    border-color: rgba(99, 102, 241, 0.3);
                    box-shadow: 0 10px 40px -10px rgba(0, 0, 0, 0.5);
                }
                .icon-box {
                    background: linear-gradient(135deg, ${color === 'primary' ? '#6366f1' : color === 'secondary' ? '#10b981' : color === 'blue' ? '#3b82f6' : color === 'emerald' ? '#10b981' : '#f43f5e'}20, transparent);
                }
                .value-text {
                    font-variant-numeric: tabular-nums;
                }
            </style>
            <div class="card rounded-2xl p-5 relative overflow-hidden">
                <div class="absolute top-0 right-0 w-32 h-32 bg-gradient-to-br ${colorClasses[color]} opacity-5 rounded-full blur-3xl -mr-16 -mt-16"></div>
                
                <div class="flex items-start justify-between relative z-10">
                    <div>
                        <p class="text-slate-400 text-sm font-medium mb-1">${title}</p>
                        <h3 class="text-2xl font-bold text-white value-text tracking-tight">${value}</h3>
                    </div>
                    <div class="icon-box w-10 h-10 rounded-xl flex items-center justify-center ${iconColors[color]}">
                        <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                            ${this.getIconPath(icon)}
                        </svg>
                    </div>
                </div>
                
                <div class="mt-4 flex items-center gap-2">
                    <span class="text-xs text-slate-500">Updated just now</span>
                    <div class="w-1.5 h-1.5 rounded-full bg-emerald-500 animate-pulse"></div>
                </div>
            </div>
        `;
    }

    getIconPath(icon) {
        const icons = {
            'dollar-sign': '<line x1="12" y1="1" x2="12" y2="23"></line><path d="M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6"></path>',
            'trending-up': '<polyline points="23 6 13.5 15.5 8.5 10.5 1 18"></polyline><polyline points="17 6 23 6 23 12"></polyline>',
            'activity': '<polyline points="22 12 18 12 15 21 9 3 6 12 2 12"></polyline>',
            'bar-chart-2': '<line x1="18" y1="20" x2="18" y2="10"></line><line x1="12" y1="20" x2="12" y2="4"></line><line x1="6" y1="20" x2="6" y2="14"></line>',
            'user': '<path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path><circle cx="12" cy="7" r="4"></circle>'
        };
        return icons[icon] || icons['activity'];
    }
}

customElements.define('custom-stats-card', CustomStatsCard);