import React from 'react';
import { Link, usePage } from '@inertiajs/react';
import { ArrowUpRight, TrendingUp, Shield } from 'lucide-react';

interface ProjectProps {
    project: {
        id: number;
        title: string;
        slug: string;
        short_description: string;
        client_name?: string;
        industry?: string;
        key_metric?: string;
        key_metric_label?: string;
        show_key_metric?: boolean;
        show_visit_url?: boolean;
        project_url?: string;
        technologies?: string[];
        category?: { name: string };
    };
}

export const ProjectCard: React.FC<ProjectProps> = ({ project }) => {
    const { globalSettings } = usePage().props as any;
    const isMetricVisible = (globalSettings?.projects_global_show_metrics !== '0') && (project.show_key_metric !== false) && Boolean(project.key_metric);

    return (
        <div className="glass-card glass-card-hover rounded-2xl overflow-hidden flex flex-col justify-between group">
            {/* Visual Cover Header */}
            <div className="h-48 bg-gradient-to-br from-[#0B132B] via-[#0F172A] to-[#1E293B] relative p-6 flex flex-col justify-between border-b border-slate-800">
                <div className="flex items-center justify-between">
                    <div className="flex items-center gap-1.5">
                        <span className="text-xs font-semibold px-2.5 py-1 rounded-full bg-[#00F2FE]/10 text-[#00F2FE] border border-[#00F2FE]/30">
                            {project.category?.name || project.industry || 'Case Study'}
                        </span>
                        {isMetricVisible && (
                            <span className="text-[11px] font-bold px-2 py-0.5 rounded-full bg-emerald-500/10 text-emerald-400 border border-emerald-500/25 flex items-center gap-1">
                                <TrendingUp className="w-3 h-3" /> {project.key_metric}
                            </span>
                        )}
                    </div>
                    <Link
                        href={`/projects/${project.slug}`}
                        className="w-8 h-8 rounded-full bg-[#060B18]/60 border border-slate-700 flex items-center justify-center text-slate-300 group-hover:text-[#00F2FE] group-hover:border-[#00F2FE] transition-colors"
                    >
                        <ArrowUpRight className="w-4 h-4" />
                    </Link>
                </div>
                <div>
                    <span className="text-xs font-medium text-slate-400 block mb-1">
                        {project.client_name || 'Enterprise Client'}
                    </span>
                    <h3 className="text-lg font-bold text-white group-hover:text-[#00F2FE] transition-colors line-clamp-1">
                        {project.title}
                    </h3>
                </div>
            </div>

            {/* Description & Tech Tags */}
            <div className="p-6 flex-1 flex flex-col justify-between space-y-4">
                <p className="text-sm text-slate-400 line-clamp-3">
                    {project.short_description}
                </p>

                {project.technologies && project.technologies.length > 0 && (
                    <div className="flex flex-wrap gap-1.5 pt-2">
                        {project.technologies.slice(0, 4).map((tech, idx) => (
                            <span
                                key={idx}
                                className="text-[10px] font-medium px-2 py-0.5 rounded-md bg-[#0F172A] text-slate-300 border border-slate-800"
                            >
                                {tech}
                            </span>
                        ))}
                    </div>
                )}
            </div>
        </div>
    );
};

