Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
242 changes: 242 additions & 0 deletions src/app/components/home-projects/HomeProjectCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
"use client";

import { useState } from "react";
import Image from "next/image";
import Link from "next/link";
import { BsArrowUpRight } from "react-icons/bs";
import { FaGithub } from "react-icons/fa6";
import { ChevronLeft, ChevronRight, Layers, ListChecks } from "lucide-react";
import type { Project } from "@/data/projectss";

interface HomeProjectCardProps {
project: Project;
index: number;
className?: string;
}

export default function HomeProjectCard({
project,
index,
className = "",
}: HomeProjectCardProps) {
const [activeImageIndex, setActiveImageIndex] = useState(0);
const [activeTab, setActiveTab] = useState<"overview" | "features">(
"overview"
);

const projectImages = (
project.images?.length ? project.images : [project.image]
).filter(Boolean);

const currentImage =
projectImages[activeImageIndex] || project.image || "/web/1.jpg";
const hasMultipleImages = projectImages.length > 1;
const hasFeatures = Boolean(project.features && project.features.length > 0);
const formattedIndex = String(index + 1).padStart(2, "0");

const handlePrevImage = (e: React.MouseEvent) => {
e.preventDefault();
e.stopPropagation();
setActiveImageIndex((prev) =>
prev === 0 ? projectImages.length - 1 : prev - 1
);
};

const handleNextImage = (e: React.MouseEvent) => {
e.preventDefault();
e.stopPropagation();
setActiveImageIndex((prev) =>
prev === projectImages.length - 1 ? 0 : prev + 1
);
};

return (
<article
className={`group relative flex flex-col rounded-2xl border border-border/80 bg-primary/90 dark:bg-primary/95 backdrop-blur-xl shadow-[0_20px_50px_-15px_rgba(0,0,0,0.2)] dark:shadow-[0_20px_60px_-15px_rgba(0,0,0,0.65)] overflow-hidden transition-colors duration-300 hover:border-primaryColor/50 ${className}`}
>
{/* Thumbnail Header */}
<div className="relative w-full h-40 xl:h-44 shrink-0 overflow-hidden bg-muted border-b border-border/60">
<Image
src={currentImage}
alt={`${project.title} preview ${activeImageIndex + 1}`}
fill
sizes="(max-width: 768px) 92vw, (max-width: 1280px) 34vw, 420px"
priority={index === 0}
className="object-cover object-top transition-transform duration-500 group-hover:scale-[1.03]"
/>
<div className="absolute inset-0 bg-linear-to-t from-black/55 via-black/10 to-transparent pointer-events-none" />

{/* Project Number Badge */}
<div className="absolute top-3 left-3 flex items-center gap-2">
<span className="px-2.5 py-1 rounded-full text-xs font-bold tracking-wider bg-background/85 dark:bg-background/80 backdrop-blur-md text-primaryColor border border-primaryColor/30">
{formattedIndex}
</span>
</div>

{/* Gallery Controls */}
{hasMultipleImages && (
<div className="absolute bottom-2.5 right-2.5 flex items-center gap-1.5">
<button
type="button"
onClick={handlePrevImage}
aria-label={`Previous image for ${project.title}`}
className="h-7 w-7 rounded-full bg-background/85 backdrop-blur-md border border-border/80 text-foreground hover:border-primaryColor hover:text-primaryColor flex items-center justify-center transition-colors cursor-pointer"
>
<ChevronLeft className="h-3.5 w-3.5" />
</button>
<span className="px-2 py-0.5 rounded-full text-[11px] font-medium bg-background/85 backdrop-blur-md text-foreground border border-border/80">
{activeImageIndex + 1}/{projectImages.length}
</span>
<button
type="button"
onClick={handleNextImage}
aria-label={`Next image for ${project.title}`}
className="h-7 w-7 rounded-full bg-background/85 backdrop-blur-md border border-border/80 text-foreground hover:border-primaryColor hover:text-primaryColor flex items-center justify-center transition-colors cursor-pointer"
>
<ChevronRight className="h-3.5 w-3.5" />
</button>
</div>
)}
</div>

{/* Card Body */}
<div className="flex flex-col flex-1 min-h-0 p-4 sm:p-5 gap-3">
{/* Title + Tab Switcher */}
<div className="flex items-start justify-between gap-2">
<h3 className="text-base sm:text-lg xl:text-xl font-bold text-foreground leading-snug line-clamp-2">
{project.title}
</h3>
{hasFeatures && (
<button
type="button"
onClick={() =>
setActiveTab((prev) =>
prev === "overview" ? "features" : "overview"
)
}
className="shrink-0 inline-flex items-center gap-1 rounded-full border border-border bg-muted/70 px-2.5 py-1 text-[11px] font-medium text-textColor hover:border-primaryColor hover:text-primaryColor transition-colors cursor-pointer"
>
{activeTab === "overview" ? (
<>
<ListChecks className="h-3 w-3 text-primaryColor" />
Features
</>
) : (
<>
<Layers className="h-3 w-3 text-primaryColor" />
Overview
</>
)}
</button>
)}
</div>

{/* Scroll-safe Body Content */}
{activeTab === "overview" ? (
<div className="flex-1 min-h-0 flex flex-col justify-between gap-3">
<p className="text-xs sm:text-[13px] text-muted-foreground leading-relaxed line-clamp-4">
{project.description}
</p>

{/* Key Features Preview */}
{hasFeatures && (
<ul className="space-y-1 text-[11px] sm:text-xs text-muted-foreground">
{project.features!.slice(0, 2).map((feature, featureIdx) => (
<li
key={`${project.id}-preview-${featureIdx}`}
className="flex items-start gap-2"
>
<span className="mt-1.5 h-1.5 w-1.5 shrink-0 rounded-full bg-primaryColor" />
<span className="line-clamp-1">{feature}</span>
</li>
))}
</ul>
)}

{/* Technologies */}
{project.technologies && project.technologies.length > 0 && (
<div className="flex flex-wrap gap-1.5 pt-1">
{project.technologies.slice(0, 6).map((tech) => (
<span
key={`${project.id}-${tech}`}
className="rounded-full border border-primaryColor/25 bg-primaryColor/10 px-2.5 py-0.5 text-[11px] font-medium text-primaryColor"
>
{tech}
</span>
))}
{project.technologies.length > 6 && (
<span className="rounded-full border border-border bg-muted/60 px-2 py-0.5 text-[11px] font-medium text-muted-foreground">
+{project.technologies.length - 6}
</span>
)}
</div>
)}
</div>
) : (
<div className="flex-1 min-h-0 overflow-y-auto pr-1 space-y-3">
<ul className="space-y-1.5 text-xs text-muted-foreground">
{project.features?.map((feature, featureIdx) => (
<li
key={`${project.id}-full-feature-${featureIdx}`}
className="flex items-start gap-2"
>
<span className="mt-1.5 h-1.5 w-1.5 shrink-0 rounded-full bg-primaryColor" />
<span>{feature}</span>
</li>
))}
</ul>
{project.technologies && project.technologies.length > 0 && (
<div className="flex flex-wrap gap-1.5 pt-1 border-t border-border/50">
{project.technologies.map((tech) => (
<span
key={`${project.id}-all-${tech}`}
className="rounded-full border border-primaryColor/25 bg-primaryColor/10 px-2.5 py-0.5 text-[11px] font-medium text-primaryColor"
>
{tech}
</span>
))}
</div>
)}
</div>
)}

{/* Action Links */}
<div className="flex flex-wrap items-center gap-2 pt-3 border-t border-border/70 shrink-0">
{project.link && (
<Link
href={project.link}
target="_blank"
rel="noopener noreferrer"
className="inline-flex items-center gap-1.5 rounded-full bg-primaryColor px-3.5 py-1.5 text-xs font-semibold text-white hover:bg-primaryColor/85 transition-colors"
>
<BsArrowUpRight className="text-sm" />
Live
</Link>
)}
{project.github_client && (
<Link
href={project.github_client}
target="_blank"
rel="noopener noreferrer"
className="inline-flex items-center gap-1.5 rounded-full border border-primaryColor/60 px-3.5 py-1.5 text-xs font-semibold text-primaryColor hover:bg-primaryColor hover:text-white transition-colors"
>
<FaGithub className="text-sm" />
Client
</Link>
)}
{project.github_server && (
<Link
href={project.github_server}
target="_blank"
rel="noopener noreferrer"
className="inline-flex items-center gap-1.5 rounded-full border border-primaryColor/60 px-3.5 py-1.5 text-xs font-semibold text-primaryColor hover:bg-primaryColor hover:text-white transition-colors"
>
<FaGithub className="text-sm" />
Server
</Link>
)}
</div>
</div>
</article>
);
}
Loading