import { useState, useEffect, useRef } from "react";
import SkillCard from "../SkillCard/SkillCard.jsx";
import "./SingleProject.css";

function SingleProject({ image, title, description, skills, id, school, beginningYear, endYear }) {
    const color = ["blue", "green", "purple", "red", "yellow"]

    return (
        <div className="single-project">
            <div className="single-project-top">
                <img src={`/assets/images/projects/${image}/${image}_1.png`} alt={image}/>
            </div>
            <div className="single-project-bottom">
                <div className="single-project-bottom-header">
                    <div className="single-project-title-wrapper">
                        <div className={`single-project-line color-${color[(id-1)%color.length]}`}></div>
                        <h3 className="single-project-title">
                            {title}
                            {school ? (
                                <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640" fill="#D95F46" width="1.25em" height="1.25em">
                                    <path d="M80 259.8L289.2 345.9C299 349.9 309.4 352 320 352C330.6 352 341 349.9 350.8 345.9L593.2 246.1C602.2 242.4 608 233.7 608 224C608 214.3 602.2 205.6 593.2 201.9L350.8 102.1C341 98.1 330.6 96 320 96C309.4 96 299 98.1 289.2 102.1L46.8 201.9C37.8 205.6 32 214.3 32 224L32 520C32 533.3 42.7 544 56 544C69.3 544 80 533.3 80 520L80 259.8zM128 331.5L128 448C128 501 214 544 320 544C426 544 512 501 512 448L512 331.4L369.1 390.3C353.5 396.7 336.9 400 320 400C303.1 400 286.5 396.7 270.9 390.3L128 331.4z"/>
                                </svg>
                            ) : null}
                        </h3>
                    </div>
                    {endYear === null ? (
                        <p className="single-project-years">{beginningYear + ' – in progress'}</p>
                    ) : beginningYear === endYear ? (
                            <p className="single-project-years">{beginningYear}</p>
                    ) : (
                        <p className="single-project-years">{beginningYear + ' – ' + endYear}</p>
                    )}
                </div>
                <div className="single-project-bottom-container">
                    <p className="single-project-description" style={{ whiteSpace: "pre-line" }}>
                        {description}
                    </p>

                    <ul className="single-project-skills-list">
                        {skills.map((skill) => (
                            <li key={skill}>
                                <SkillCard text={skill} />
                            </li>
                        ))}
                    </ul>

                    <p className="single-project-link">Learn more</p>
                </div>
            </div>
        </div>
    );
}

export default SingleProject;
