File size: 9,333 Bytes
0d37119
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
import { useState } from 'react';

const BACKEND_URL = import.meta.env.VITE_BACKEND_URL || (import.meta.env.DEV ? 'http://localhost:8000' : '');

const STATUS_CONFIG = {
  STANDBY: { label: 'STANDBY', bg: '#f1f3f4', color: '#5f6368' },
  READY: { label: 'READY', bg: 'rgba(52,168,83,0.1)', color: '#1e8e3e' },
  URGENT: { label: 'URGENT', bg: 'rgba(234,67,53,0.1)', color: '#d93025' },
  SIGNAL: { label: 'SIGNAL', bg: 'rgba(251,188,4,0.1)', color: '#e37400' },
};

function formatDate(dateStr) {
  if (!dateStr) return '';
  const d = new Date(dateStr);
  return d.toLocaleDateString('fr-FR', { day: 'numeric', month: 'short' });
}

function formatTime(timeStr) {
  if (!timeStr) return '';
  const d = new Date(timeStr);
  return d.toLocaleString('fr-FR', { day: 'numeric', month: 'short', hour: '2-digit', minute: '2-digit' });
}

export default function ProjectCard({ project, status, alerts }) {
  const st = STATUS_CONFIG[status] || STATUS_CONFIG.STANDBY;
  const [expanded, setExpanded] = useState(false);
  const [sources, setSources] = useState(null);
  const [loading, setLoading] = useState(false);

  const handleClick = async () => {
    if (expanded) { setExpanded(false); return; }
    if (!sources) {
      setLoading(true);
      try {
        const res = await fetch(`${BACKEND_URL}/api/project/${project.id}/sources`);
        setSources(await res.json());
      } catch (err) { console.error(err); }
      finally { setLoading(false); }
    }
    setExpanded(true);
  };

  return (
    <div
      onClick={handleClick}
      style={{
        background: '#ffffff',
        border: '1px solid #e0e0e0',
        borderLeft: `4px solid ${project.color}`,
        borderRadius: '12px',
        padding: '16px 20px',
        flex: '1 1 280px',
        minWidth: '0',
        maxWidth: '100%',
        cursor: 'pointer',
        transition: 'box-shadow 0.2s',
        overflow: 'hidden',
        wordBreak: 'break-word',
      }}
      onMouseEnter={(e) => e.currentTarget.style.boxShadow = '0 2px 8px rgba(0,0,0,0.08)'}
      onMouseLeave={(e) => e.currentTarget.style.boxShadow = 'none'}
    >
      <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: '10px' }}>
        <span style={{ fontSize: '11px', color: '#5f6368', letterSpacing: '1px', fontWeight: 500 }}>
          PROJET
        </span>
        <span style={{
          fontSize: '11px', fontWeight: 600, padding: '3px 10px',
          background: st.bg, color: st.color, borderRadius: '10px',
          animation: status === 'URGENT' ? 'pulse 1.5s infinite' : 'none',
        }}>
          {st.label}
        </span>
      </div>

      <h3 style={{ fontSize: '15px', color: '#1f1f1f', marginBottom: '6px', fontWeight: 600 }}>
        {project.name}
      </h3>

      {project.contact && (
        <p style={{ fontSize: '12px', color: '#5f6368', marginBottom: '10px' }}>{project.contact}</p>
      )}

      {alerts && alerts.length > 0 && (
        <ul style={{ listStyle: 'none', padding: 0 }}>
          {alerts.map((alert, i) => (
            <li key={i} style={{
              fontSize: '12px', color: st.color, padding: '5px 0',
              borderTop: '1px solid #f1f3f4',
            }}>
              {alert}
            </li>
          ))}
        </ul>
      )}

      {!expanded && (
        <div style={{ fontSize: '11px', color: '#9aa0a6', marginTop: '8px', textAlign: 'center' }}>
          Cliquer pour voir les sources
        </div>
      )}

      {loading && (
        <div style={{ fontSize: '12px', color: '#5f6368', marginTop: '10px', fontStyle: 'italic' }}>
          Chargement...
        </div>
      )}

      {expanded && sources && (
        <div onClick={(e) => e.stopPropagation()} style={{
          marginTop: '14px', borderTop: '1px solid #e0e0e0', paddingTop: '14px',
          animation: 'fadeIn 0.3s ease-out',
        }}>
          {/* Emails */}
          {sources.emails && sources.emails.length > 0 && (
            <div style={{ marginBottom: '16px' }}>
              <div style={{ fontSize: '11px', color: project.color, letterSpacing: '1px', marginBottom: '8px', fontWeight: 600 }}>
                EMAILS
              </div>
              {sources.emails.map((email, i) => (
                <div key={i} style={{
                  padding: '10px 12px', background: '#f8f9fa', borderRadius: '8px',
                  marginBottom: '6px', fontSize: '13px',
                }}>
                  <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: '4px' }}>
                    <span style={{ color: '#1f1f1f', fontWeight: 600, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', flex: 1, minWidth: 0 }}>{email.subject}</span>
                    <span style={{
                      fontSize: '11px',
                      color: email.days_since_reply >= 5 ? '#d93025' : '#5f6368',
                      fontWeight: email.days_since_reply >= 5 ? 600 : 400,
                    }}>
                      {email.days_since_reply != null ? `${email.days_since_reply}j` : ''}
                    </span>
                  </div>
                  <div style={{ color: '#5f6368', fontSize: '12px', marginBottom: '6px' }}>
                    De : {email.from} &middot; {formatDate(email.date)}
                  </div>
                  <div style={{ color: '#3c4043', fontSize: '12px', lineHeight: '1.5', marginBottom: '8px' }}>
                    {email.body}
                  </div>
                  <div style={{ display: 'flex', gap: '8px' }}>
                    <a
                      href={`mailto:${email.from}?subject=Re: ${email.subject}`}
                      style={{
                        fontSize: '11px', color: '#4285f4', textDecoration: 'none',
                        padding: '4px 10px', border: '1px solid #4285f4',
                        borderRadius: '14px', fontWeight: 500,
                      }}
                    >
                      Repondre
                    </a>
                    <a
                      href={`https://mail.google.com/mail/u/0/#search/from:${email.from}+subject:${encodeURIComponent(email.subject)}`}
                      target="_blank" rel="noopener noreferrer"
                      style={{
                        fontSize: '11px', color: '#5f6368', textDecoration: 'none',
                        padding: '4px 10px', border: '1px solid #e0e0e0',
                        borderRadius: '14px',
                      }}
                    >
                      Ouvrir dans Gmail
                    </a>
                  </div>
                </div>
              ))}
            </div>
          )}

          {/* Events */}
          {sources.events && sources.events.length > 0 && (
            <div style={{ marginBottom: '16px' }}>
              <div style={{ fontSize: '11px', color: project.color, letterSpacing: '1px', marginBottom: '8px', fontWeight: 600 }}>
                CALENDRIER
              </div>
              {sources.events.map((event, i) => (
                <div key={i} style={{
                  padding: '10px 12px', background: '#f8f9fa', borderRadius: '8px',
                  marginBottom: '6px', fontSize: '13px',
                  display: 'flex', justifyContent: 'space-between', alignItems: 'center',
                }}>
                  <div>
                    <div style={{ color: '#1f1f1f', fontWeight: 600 }}>{event.title}</div>
                    <div style={{ color: '#5f6368', fontSize: '12px', marginTop: '2px' }}>
                      {formatTime(event.time)}
                      {event.prep_block
                        ? <span style={{ color: '#1e8e3e', marginLeft: '8px', fontWeight: 500 }}>Prep OK</span>
                        : <span style={{ color: '#d93025', marginLeft: '8px', fontWeight: 500 }}>Pas de prep</span>
                      }
                    </div>
                  </div>
                  <a
                    href={`https://calendar.google.com/calendar/r/search?q=${encodeURIComponent(event.title)}`}
                    target="_blank" rel="noopener noreferrer"
                    style={{
                      fontSize: '11px', color: '#4285f4', textDecoration: 'none',
                      padding: '4px 10px', border: '1px solid #4285f4',
                      borderRadius: '14px', fontWeight: 500, flexShrink: 0,
                    }}
                  >
                    Ouvrir l'agenda
                  </a>
                </div>
              ))}
            </div>
          )}

          {/* Web signal */}
          {sources.search && (
            <div>
              <div style={{ fontSize: '11px', color: project.color, letterSpacing: '1px', marginBottom: '8px', fontWeight: 600 }}>
                SIGNAL EXTERNE
              </div>
              <div style={{
                padding: '10px 12px', background: '#f8f9fa', borderRadius: '8px',
                fontSize: '12px', color: '#3c4043', lineHeight: '1.5',
              }}>
                {sources.search}
              </div>
            </div>
          )}

          <div style={{ fontSize: '11px', color: '#9aa0a6', marginTop: '12px', textAlign: 'center' }}>
            Cliquer pour fermer
          </div>
        </div>
      )}
    </div>
  );
}