File size: 7,485 Bytes
691cdd0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import React, { useRef } from 'react';
import { Link } from 'react-router-dom';
import ImageFlex from './ImageFlex.jsx';

export default function ProjectCard({ project }) {
  const cardRef = useRef(null);

  function getStatusClasses(status) {
    if (!status) return 'bg-slate-100 text-slate-700';
    switch (status) {
      case 'Completed':
        return 'bg-emerald-100 text-emerald-700';
      case 'Ongoing':
        return 'bg-amber-100 text-amber-700';
      case 'Upcoming':
        return 'bg-sky-100 text-sky-700';
      default:
        return 'bg-slate-100 text-slate-700';
    }
  }

  function onMove(e) {
    const el = cardRef.current;
    if (!el) return;
    if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) return;
    const rect = el.getBoundingClientRect();
    const x = e.clientX - rect.left;
    const y = e.clientY - rect.top;
    const midX = rect.width / 2;
    const midY = rect.height / 2;
    const rotateX = ((y - midY) / midY) * -4;
    const rotateY = ((x - midX) / midX) * 4;
    el.style.transform = `perspective(800px) rotateX(${rotateX}deg) rotateY(${rotateY}deg)`;
  }
  function onLeave() {
    const el = cardRef.current;
    if (!el) return;
    el.style.transform = 'perspective(800px) rotateX(0deg) rotateY(0deg)';
  }

  const hasGallery = Array.isArray(project.gallery) && project.gallery.length > 0;
  const primaryImage =
    (typeof project.image === 'string' && project.image.replace(/\.(jpg|jpeg|png|webp)$/i, '')) || null;
  const galleryImage = hasGallery ? project.gallery[0] : null;
  const explicitBase =
    typeof project.imageBase === 'string'
      ? project.imageBase.replace(/\.(jpg|jpeg|png|webp)$/i, '')
      : null;
  const slugFallback = !project.noDetail && project.slug ? `/assets/projects/${project.slug}/gallery-1` : null;

  const imageBases = [
    primaryImage,
    galleryImage,
    explicitBase,
    slugFallback
  ].filter(Boolean);

  const hasImage = imageBases.length > 0;

  return (
    <article
      ref={cardRef}
      onMouseMove={onMove}
      onMouseLeave={onLeave}
      className={`relative card group overflow-hidden will-change-transform before:pointer-events-none before:absolute before:inset-0 before:rounded-xl before:bg-brand-600/0 before:blur before:transition before:duration-300 hover:before:bg-brand-600/10 ${
        hasImage ? 'aspect-[3/4] min-h-[400px] md:min-h-[500px]' : 'h-full'
      }`}
      aria-labelledby={`proj-${project.slug}`}
    >
      {hasImage ? (
        <>
          <div className="relative h-full w-full bg-slate-200">
            <ImageFlex
              base={imageBases[0]}
              srcCandidates={imageBases.flatMap((base) =>
                ['webp', 'jpg', 'jpeg', 'png'].map((ext) => `${base}.${ext}`)
              )}
              alt={project.title}
              className="h-full w-full object-contain transition-transform group-hover:scale-[1.03]"
              loading="lazy"
            />
            <div className="pointer-events-none absolute inset-0 bg-gradient-to-t from-slate-900/80 via-slate-900/40 to-transparent"></div>
          </div>
          {/* Overlay text content */}
          <div className="absolute bottom-0 left-0 right-0 p-5 text-white">
            <h3 id={`proj-${project.slug}`} className="h3 text-white">
              {project.noDetail ? (
                <span>{project.title}</span>
              ) : (
                <Link to={`/project/${project.slug}`} className="hover:underline">
                  {project.title}
                </Link>
              )}
            </h3>
            <p className="mt-1 text-sm text-white/90">{project.location}</p>
            {project.projectSize && (
              <p className="mt-1 text-sm font-medium text-white">
                {project.projectSize}
              </p>
            )}
            <div className="mt-4 flex items-center justify-between">
              <span className="flex flex-wrap items-center gap-2">
                {project.status && (
                  <span
                    className={`rounded px-2 py-1 text-xs font-medium ${getStatusClasses(project.status)}`}
                    aria-label={`Status: ${project.status}`}
                  >
                    {project.status}
                  </span>
                )}
                {(project.categories || []).slice(0, 2).map((c) => (
                  <span key={c} className="rounded bg-white/20 backdrop-blur-sm px-2 py-1 text-xs text-white">
                    {c}
                  </span>
                ))}
              </span>
              {!project.noDetail && (
                <Link
                  to={`/project/${project.slug}`}
                  className="text-sm font-medium text-white underline-offset-2 hover:underline"
                  aria-label={`View ${project.title}`}
                >
                  View details
                </Link>
              )}
            </div>
          </div>
        </>
      ) : (
        <>
          <div className="flex h-24 w-full items-center justify-center bg-gradient-to-br from-brand-50 via-white to-brand-100">
            <svg
              className="h-12 w-12 text-brand-600"
              viewBox="0 0 24 24"
              fill="none"
              stroke="currentColor"
              strokeWidth="1.5"
              strokeLinecap="round"
              strokeLinejoin="round"
              aria-hidden="true"
            >
              <rect x="3" y="3" width="7" height="7" />
              <rect x="14" y="3" width="7" height="7" />
              <rect x="14" y="14" width="7" height="7" />
              <rect x="3" y="14" width="7" height="7" />
            </svg>
          </div>
          <div className="p-5">
            <h3 id={`proj-${project.slug}`} className="h3">
              {project.noDetail ? (
                <span>{project.title}</span>
              ) : (
                <Link to={`/project/${project.slug}`} className="hover:underline">
                  {project.title}
                </Link>
              )}
            </h3>
            <p className="mt-1 text-sm text-slate-600">{project.location}</p>
            {project.projectSize && (
              <p className="mt-1 text-sm font-medium text-brand-700">
                {project.projectSize}
              </p>
            )}
            <div className="mt-4 flex items-center justify-between">
              <span className="flex flex-wrap items-center gap-2">
                {project.status && (
                  <span
                    className={`rounded px-2 py-1 text-xs font-medium ${getStatusClasses(project.status)}`}
                    aria-label={`Status: ${project.status}`}
                  >
                    {project.status}
                  </span>
                )}
                {(project.categories || []).slice(0, 2).map((c) => (
                  <span key={c} className="rounded bg-slate-100 px-2 py-1 text-xs text-slate-700">
                    {c}
                  </span>
                ))}
              </span>
              {!project.noDetail && (
                <Link
                  to={`/project/${project.slug}`}
                  className="text-sm font-medium text-brand-700 underline-offset-2 hover:underline"
                  aria-label={`View ${project.title}`}
                >
                  View details
                </Link>
              )}
            </div>
          </div>
        </>
      )}
    </article>
  );
}