import { MapPin, Star, Factory, Calendar, Wrench } from 'lucide-react';
import { Card, CardContent } from '@/components/ui/card';
import { Badge } from '@/components/ui/badge';
import { Button } from '@/components/ui/button';
import { Company } from '@/types/database';
import { cn } from '@/lib/utils';

interface ManufacturerListViewProps {
  manufacturers: Company[];
  onManufacturerClick: (manufacturer: Company) => void;
}

export function ManufacturerListView({ manufacturers, onManufacturerClick }: ManufacturerListViewProps) {
  return (
    <div className="space-y-3">
      {manufacturers.map((manufacturer, index) => (
        <Card 
          key={manufacturer.id}
          className={cn(
            "group overflow-hidden cursor-pointer",
            "border-border/40 bg-gradient-to-br from-card via-card/95 to-card/90",
            "hover:border-primary/30 hover:shadow-2xl hover:shadow-primary/5",
            "transition-all duration-500 animate-fade-in-up"
          )}
          style={{ animationDelay: `${index * 50}ms` }}
          onClick={() => onManufacturerClick(manufacturer)}
        >
          <CardContent className="p-0">
            <div className="flex flex-col sm:flex-row">
              {/* Logo */}
              <div className="w-full h-32 sm:w-32 sm:h-auto md:w-40 flex-shrink-0 self-stretch relative overflow-hidden bg-gradient-to-br from-muted/50 to-muted/30">
                {manufacturer.logo_url ? (
                  <img 
                    src={manufacturer.logo_url} 
                    alt={manufacturer.name}
                    className="w-full h-full object-contain p-4 group-hover:scale-110 transition-transform duration-700"
                  />
                ) : (
                  <div className="w-full h-full flex items-center justify-center">
                    <Factory className="w-12 h-12 text-muted-foreground/40" />
                  </div>
                )}
              </div>

              {/* Content */}
              <div className="flex-1 p-4 md:p-6 flex flex-col justify-between min-h-[128px]">
                <div className="space-y-3">
                  {/* Header */}
                  <div className="flex items-start justify-between gap-4">
                    <div className="flex-1 min-w-0">
                      <h3 className="font-bold text-lg md:text-xl group-hover:text-primary transition-colors duration-300 line-clamp-1 mb-1.5">
                        {manufacturer.name}
                      </h3>
                      
                      {manufacturer.headquarters_location && (
                        <div className="flex items-center text-sm text-muted-foreground group-hover:text-foreground transition-colors duration-300">
                          <MapPin className="w-3.5 h-3.5 mr-1.5 flex-shrink-0" />
                          <span className="line-clamp-1">{manufacturer.headquarters_location}</span>
                        </div>
                      )}
                    </div>

                    {/* Rating */}
                    {manufacturer.average_rating && manufacturer.average_rating > 0 && (
                      <div className="flex items-center gap-1.5 ml-4 flex-shrink-0 bg-yellow-400/10 px-3 py-1.5 rounded-full group-hover:bg-yellow-400/20 transition-colors duration-300">
                        <Star className="w-4 h-4 fill-yellow-400 text-yellow-400" />
                        <span className="font-semibold text-foreground">{manufacturer.average_rating.toFixed(1)}</span>
                        {manufacturer.review_count && manufacturer.review_count > 0 && (
                          <span className="text-xs text-muted-foreground">({manufacturer.review_count})</span>
                        )}
                      </div>
                    )}
                  </div>

                  {/* Description */}
                  {manufacturer.description && (
                    <p className="text-sm text-muted-foreground group-hover:text-foreground/80 transition-colors duration-300 line-clamp-2">
                      {manufacturer.description}
                    </p>
                  )}

                  {/* Tags */}
                  <div className="flex items-center gap-2 flex-wrap">
                    <Badge variant="outline" className="text-xs backdrop-blur-sm border-primary/20 group-hover:border-primary/40 transition-colors duration-300">
                      <Factory className="w-3 h-3 mr-1" />
                      Manufacturer
                    </Badge>
                    {manufacturer.founded_year && (
                      <Badge variant="outline" className="text-xs backdrop-blur-sm border-accent/20 group-hover:border-accent/40 transition-colors duration-300">
                        <Calendar className="w-3 h-3 mr-1" />
                        Est. {manufacturer.founded_year}
                      </Badge>
                    )}
                  </div>
                </div>

                {/* Actions */}
                <div className="flex items-center justify-end mt-4 pt-3 border-t border-border/50">
                  <Button 
                    size="sm" 
                    className="bg-gradient-to-r from-primary to-secondary hover:shadow-lg hover:shadow-primary/20 hover:scale-105 transition-all duration-300 flex-shrink-0"
                  >
                    <Wrench className="w-3.5 h-3.5 mr-1.5" />
                    <span className="hidden sm:inline">View Details</span>
                    <span className="sm:hidden">View</span>
                  </Button>
                </div>
              </div>
            </div>
          </CardContent>
        </Card>
      ))}
    </div>
  );
}
