import { Card, CardContent } from '@/components/ui/card';
import { Badge } from '@/components/ui/badge';
import { Star, MapPin, Ruler, FerrisWheel } from 'lucide-react';
import { Company } from '@/types/database';
import { useNavigate } from 'react-router-dom';

interface DesignerCardProps {
  company: Company;
}

export function DesignerCard({ company }: DesignerCardProps) {
  const navigate = useNavigate();

  const handleClick = () => {
    navigate(`/designers/${company.slug}/`);
  };

  const getCompanyIcon = () => {
    return <Ruler className="w-8 h-8 text-muted-foreground" />;
  };

  return (
    <Card 
      className="group cursor-pointer transition-all duration-200 hover:shadow-lg hover:scale-[1.02] bg-card border border-border overflow-hidden"
      onClick={handleClick}
    >
      {/* Header Image/Logo Section */}
      <div className="relative aspect-video bg-gradient-to-br from-background to-muted/50 flex items-center justify-center border-b border-border">
        {/* Background Gradient Overlay */}
        <div className="absolute inset-0 bg-gradient-to-br from-primary/5 via-transparent to-accent/5" />
        
        {/* Company Type Badge */}
        <div className="absolute top-3 left-3">
          <Badge variant="secondary" className="text-xs bg-background/80 backdrop-blur-sm border border-border/50">
            Designer
          </Badge>
        </div>

        {/* Logo or Icon */}
        <div className="relative z-10 flex items-center justify-center">
          {company.logo_url ? (
            <img 
              src={company.logo_url} 
              alt={`${company.name} logo`}
              className="max-w-20 max-h-20 object-contain filter drop-shadow-sm"
            />
          ) : (
            <div className="p-4 rounded-full bg-muted/30 backdrop-blur-sm border border-border/30">
              {getCompanyIcon()}
            </div>
          )}
        </div>
      </div>

      <CardContent className="p-6 space-y-4">
        {/* Company Name */}
        <div>
          <h3 className="font-semibold text-lg mb-2 group-hover:text-primary transition-colors line-clamp-1">
            {company.name}
          </h3>
          
          {/* Description */}
          {company.description && (
            <p className="text-sm text-muted-foreground line-clamp-2 mb-3">
              {company.description}
            </p>
          )}
        </div>

        {/* Company Details */}
        <div className="space-y-2 text-sm">
          {/* Founded Year */}
          {company.founded_year && (
            <div className="flex items-center gap-2">
              <span className="text-muted-foreground">Founded:</span>
              <span className="font-medium">{company.founded_year}</span>
            </div>
          )}
          
          {/* Location */}
          {company.headquarters_location && (
            <div className="flex items-center gap-2">
              <MapPin className="w-3 h-3 text-muted-foreground flex-shrink-0" />
              <span className="text-muted-foreground line-clamp-1">{company.headquarters_location}</span>
            </div>
          )}
          
          {/* Rating */}
          {company.average_rating > 0 && (
            <div className="flex items-center gap-2">
              <Star className="w-3 h-3 text-yellow-500 fill-yellow-500 flex-shrink-0" />
              <span className="font-medium">{company.average_rating.toFixed(1)}</span>
              <span className="text-muted-foreground">({company.review_count} reviews)</span>
            </div>
          )}
        </div>

        {/* Stats Display */}
        <div className="flex flex-wrap gap-x-4 gap-y-1 text-sm">
          {(company as any).ride_count > 0 && (
            <div className="flex items-center gap-1">
              <FerrisWheel className="w-3 h-3 text-muted-foreground" />
              <span className="font-medium">{(company as any).ride_count}</span>
              <span className="text-muted-foreground">designs</span>
            </div>
          )}
          
          {(company as any).coaster_count > 0 && (
            <div className="flex items-center gap-1">
              <span className="text-muted-foreground">•</span>
              <span className="font-medium">{(company as any).coaster_count}</span>
              <span className="text-muted-foreground">coasters</span>
            </div>
          )}
          
          {(company as any).model_count > 0 && (
            <div className="flex items-center gap-1">
              <span className="text-muted-foreground">•</span>
              <span className="font-medium">{(company as any).model_count}</span>
              <span className="text-muted-foreground">concepts</span>
            </div>
          )}
        </div>
      </CardContent>
    </Card>
  );
}