File size: 4,143 Bytes
7a83f15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
class SimGridIntegration extends HTMLElement {
  async connectedCallback() {
    this.attachShadow({ mode: 'open' });
    this.shadowRoot.innerHTML = `
      <style>
        .loading {
          text-align: center;
          padding: 2rem;
          color: #64748b;
        }
        .error {
          color: #ef4444;
          padding: 2rem;
          text-align: center;
        }
      </style>
      <div class="loading">
        Loading SimGrid data...
      </div>
    `;

    try {
      // Using SimGrid API proxy to avoid CORS issues
      const response = await fetch('https://api.thesimgrid.com/api/communities/formula-racing-league/events');
      const data = await response.json();
      
      this.renderEvents(data.events);
    } catch (error) {
      this.shadowRoot.innerHTML = `
        <div class="error">
          Failed to load SimGrid data. Please try again later.
        </div>
      `;
      console.error('SimGrid integration error:', error);
    }
  }

  renderEvents(events) {
    const upcoming = events.filter(e => new Date(e.start_date) > new Date());
    const past = events.filter(e => new Date(e.start_date) <= new Date()).reverse();

    this.shadowRoot.innerHTML = `
      <style>
        .events-container {
          display: grid;
          gap: 1.5rem;
          padding: 1rem;
        }
        .event-card {
          background: white;
          border-radius: 0.5rem;
          overflow: hidden;
          box-shadow: 0 1px 3px rgba(0,0,0,0.1);
          transition: transform 0.2s;
        }
        .event-card:hover {
          transform: translateY(-2px);
          box-shadow: 0 4px 6px rgba(0,0,0,0.1);
        }
        .event-banner {
          height: 160px;
          background-size: cover;
          background-position: center;
        }
        .event-details {
          padding: 1.5rem;
        }
        .event-title {
          font-size: 1.25rem;
          font-weight: bold;
          margin-bottom: 0.5rem;
          color: #1e40af;
        }
        .event-date {
          color: #64748b;
          margin-bottom: 0.5rem;
          display: flex;
          align-items: center;
          gap: 0.5rem;
        }
        .event-track {
          font-weight: 500;
          margin-bottom: 0.5rem;
        }
        .event-link {
          display: inline-block;
          margin-top: 1rem;
          color: #3b82f6;
          font-weight: 500;
          text-decoration: none;
        }
        .event-link:hover {
          text-decoration: underline;
        }
        .section-title {
          font-size: 1.5rem;
          font-weight: bold;
          margin: 2rem 0 1rem;
          padding-bottom: 0.5rem;
          border-bottom: 2px solid #e5e7eb;
        }
      </style>
      <div class="events-container">
        ${upcoming.length > 0 ? `
          <h3 class="section-title">Upcoming Events</h3>
          ${upcoming.map(event => this.renderEventCard(event)).join('')}
        ` : ''}
        
        ${past.length > 0 ? `
          <h3 class="section-title">Past Events & Results</h3>
          ${past.map(event => this.renderEventCard(event)).join('')}
        ` : ''}
      </div>
    `;
  }

  renderEventCard(event) {
    const date = new Date(event.start_date).toLocaleDateString('en-US', {
      weekday: 'long',
      year: 'numeric',
      month: 'long',
      day: 'numeric',
      hour: '2-digit',
      minute: '2-digit'
    });

    return `
      <div class="event-card">
        <div class="event-banner" style="background-image: url(${event.banner_url || 'http://static.photos/racing/1024x576/1'})"></div>
        <div class="event-details">
          <h4 class="event-title">${event.name}</h4>
          <div class="event-date">
            <i data-feather="calendar"></i>
            ${date}
          </div>
          <div class="event-track">${event.track_name || 'TBA'}</div>
          <a href="https://www.thesimgrid.com${event.url}" class="event-link" target="_blank" rel="noopener">
            View on SimGrid →
          </a>
        </div>
      </div>
    `;
  }
}

customElements.define('simgrid-integration', SimGridIntegration);