"use client"; import React, { useState } from "react"; import { motion, useMotionValue, useTransform } from "framer-motion"; import { useRouter } from "next/navigation"; // Removed local fallback JSX declaration — use the official React type definitions instead: // install @types/react and @types/react-dom so JSX.IntrinsicElements is provided by those packages. // 1. Updated ColorWay interface interface ColorWay { card: string; text: string; titleColor: string; // Added title color } // 2. Updated COLOR_WAYS array const COLOR_WAYS: ColorWay[] = [ { card: "#FEEEDF", text: "#173C46", titleColor: "#173C46" }, { card: "#FEEEDF", text: "#EA627F", titleColor: "#173C46" }, // Example: Title is dark, text is pink { card: "#DEE5D4", text: "#173C46", titleColor: "#EA627F" }, { card: "#DEE5D4", text: "#EA627F", titleColor: "#173C46" }, { card: "#B8C0AD", text: "#173C46", titleColor: "#173C46" }, { card: "#B8C0AD", text: "#173C46", titleColor: "#EA627F" }, ]; interface CardData { id: number; title: string; summary: string; tracks: string[]; } interface SwipeCardsProps { initialCards: CardData[]; } const SwipeCards: React.FC = ({ initialCards }) => { const [cards, setCards] = useState(initialCards); const router = useRouter(); const onSwipe = () => { setCards((prev) => prev.slice(0, prev.length - 1)); }; const handleRightSwipe = async (card: CardData) => { try { const response = await fetch("/api/chat", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ userMessage: `Explain the project: ${card.title}. Summary: ${card.summary}. Tracks: ${card.tracks.join(", ")}`, history: [], // Provide an empty array for history }), }); if (!response.ok) { const errorBody = await response.text(); // Read the response body throw new Error(`HTTP error! status: ${response.status}, body: ${errorBody}`); } // Assuming the chat API handles the message and we can then navigate router.push(`/chatbot?title=${encodeURIComponent(card.title)}&summary=${encodeURIComponent(card.summary)}`); } catch (error) { console.error("Error sending project to chatbot:", error); // Optionally, handle error state or show a message to the user } onSwipe(); // Remove the card after swiping right }; const handleReset = () => { setCards(initialCards); }; return (
{cards.length > 0 ? ( cards.map((card, index) => { const colorWay = COLOR_WAYS[card.id % COLOR_WAYS.length]; return ( ); }) ) : ( // ... (empty state)

No more cards!

You've swiped through them all.

)}
); }; interface CardProps { cardData: CardData; colorWay: ColorWay; isFront: boolean; onSwipe: () => void; // For left swipe (reject) onRightSwipe: (card: CardData) => void; // For right swipe (accept) } const Card: React.FC = ({ cardData, colorWay, isFront, onSwipe, onRightSwipe }) => { const { title, summary, tracks } = cardData; const x = useMotionValue(0); const rotate = useTransform(x, [-250, 250], [-25, 25]); const opacity = useTransform( x, [-250, -100, 0, 100, 250], [0, 1, 1, 1, 0], ); const acceptOpacity = useTransform(x, [50, 150], [0, 1]); const rejectOpacity = useTransform(x, [-150, -50], [1, 0]); const badgeRotate = useTransform(x, [-150, 150], [-15, 15]); const handleDragEnd = (event: MouseEvent | TouchEvent | PointerEvent, info: { offset: { x: number } }) => { if (info.offset.x > 100) { // Swiped right onRightSwipe(cardData); } else if (info.offset.x < -100) { // Swiped left onSwipe(); } }; return ( {/* Accept/Reject Badges */}

Accept

Reject

{/* Card Content */}
{/* 3. Applied the specific titleColor here */}

{title}

{/* This summary

will inherit colorWay.text from the parent */}

{summary}

{/* This

will also inherit colorWay.text */}

Tracks

{tracks.map((track) => ( {track} ))}
); }; export default SwipeCards;