import { Project, Tag, Language, Social } from '@/typings/project'
import {
  IconBrandGithub,
  IconBrandYoutube,
  IconCoffee,
  IconBrandRust,
  IconBrandGolang,
  IconBrandTypescript,
  IconDiamond,
  IconBrandKotlin,
  IconBrandPython,
} from '@tabler/icons-react'

type Props = {
  project: Project
}

const socialIcons: Record<Social, React.JSX.Element> = {
  Github: <IconBrandGithub />,
  YouTube: <IconBrandYoutube />,
}

const languageIcons: Record<Language, React.JSX.Element> = {
  Java: <IconCoffee color="#b07219" />,
  Rust: <IconBrandRust color="#dea584" />,
  Go: <IconBrandGolang color="#00ADD8" />,
  Ruby: <IconDiamond color="#701516" />,
  Kotlin: <IconBrandKotlin color="#7f52ff" />,
  TypeScript: <IconBrandTypescript color="#3178C6" />,
  Python: <IconBrandPython color="#306998" />,
}

const tagStyles: Record<Tag, string> = {
  '1.8': 'text-orange-500 border-orange-500',
  '1.17': 'text-orange-500 border-orange-500',
  '1.12': 'text-orange-500 border-orange-500',
  Paper: 'text-blue-500 border-blue-500',
  Bungee: 'text-blue-500 border-blue-500',
  Frontend: 'text-cyan-500 border-cyan-500',
  Backend: 'text-cyan-500 border-cyan-500',
  Fullstack: 'text-cyan-500 border-cyan-500',
  Archived: 'text-gray-600 border-gray-600',
}

export const ProjectCard = ({ project }: Props) => {
  return (
    <div className="relative flex h-80 w-64 flex-col overflow-hidden rounded-lg bg-white shadow-md transition-transform duration-300 hover:scale-105 dark:bg-gray-800">
      <img
        src={project.imageUrl}
        alt={project.name}
        className="h-32 w-full rounded-t-lg object-cover"
      />
      <div className="flex flex-1 flex-col p-2 text-center">
        <div>
          <div className="truncate text-xl font-bold text-gray-900 dark:text-gray-100">
            {project.name}
          </div>
          <div className="mt-2 flex flex-wrap justify-center gap-2">
            {project.tags.map(tag => (
              <span
                key={tag}
                className={`rounded-full border px-2 py-1 text-xs ${tagStyles[tag]} dark:border-opacity-50`}
              >
                {tag}
              </span>
            ))}
          </div>
        </div>
        <div className="mt-2 flex-1 overflow-hidden text-ellipsis text-gray-600 dark:text-gray-400">
          {project.description}
        </div>
      </div>
      <div className="absolute bottom-0 left-0 right-0 flex items-center justify-between bg-white p-2 dark:bg-gray-800">
        <div className="flex gap-2">
          {project.socials &&
            Object.entries(project.socials).map(([social, url]) => (
              <a
                key={social}
                href={url}
                target="_blank"
                rel="noopener noreferrer"
                className="hover:animate-jump transition-colors"
              >
                {socialIcons[social as Social]}
              </a>
            ))}
        </div>
        <div className="flex gap-2">
          {project.languages.map(language => (
            <div key={language}>{languageIcons[language]}</div>
          ))}
        </div>
      </div>
    </div>
  )
}
