
import React from 'react';
import { BusinessStory, CurrentView } from '../types';
import { ViewMode } from './FilterSortBar';

interface BusinessCardProps {
  story: BusinessStory;
  setCurrentView: (view: CurrentView) => void;
  setSelectedItemId: (id: string | null) => void;
  className?: string; 
  viewMode?: ViewMode;
}

const BusinessCard: React.FC<BusinessCardProps> = ({ story, setCurrentView, setSelectedItemId, className = "", viewMode = 'grid' }) => {
  
  const handleCardClick = () => {
    setCurrentView('businessStoryDetail');
    setSelectedItemId(story.id);
  };

  if (viewMode === 'list') {
    return (
      <div 
        onClick={handleCardClick}
        className={`group block p-4 rounded-lg bg-white transition-all duration-300 ease-in-out hover:bg-slate-50 cursor-pointer w-full ${className}`}
        role="article"
        aria-labelledby={`business-title-${story.id}`}
      >
        <div className="flex items-start space-x-4">
          <div className="flex-shrink-0 w-24 h-24 rounded-md overflow-hidden bg-slate-200">
            <img 
              src={story.imageUrl} 
              alt={`Изображение для: ${story.title}`} 
              className="w-full h-full object-cover group-hover:scale-105 transition-transform duration-300 ease-in-out" 
              loading="lazy" 
            />
          </div>
          <div className="flex-1">
            <h3 id={`business-title-${story.id}`} className="text-base md:text-lg font-quicksand font-semibold text-slate-800 group-hover:text-black mb-1 transition-colors duration-200 leading-tight">
              {story.title}
            </h3>
            <p className="text-xs text-slate-500 mb-2">
              <span className="font-semibold text-slate-600">{story.category}</span>
            </p>
            {story.description && (
               <p className="text-sm text-slate-600 line-clamp-2 font-inter">{story.description}</p>
            )}
          </div>
        </div>
      </div>
    );
  }

  // Grid view
  return (
    <div 
      onClick={handleCardClick}
      className={`group relative bg-white rounded-xl overflow-hidden transition-all duration-300 ease-in-out transform hover:-translate-y-1 cursor-pointer shadow-sm hover:shadow-md ${className}`}
      role="article"
      aria-labelledby={`business-title-${story.id}`}
    >
      <div className="relative w-full overflow-hidden aspect-[4/3]">
        <img 
          src={story.imageUrl} 
          alt={`Изображение для: ${story.title}`}
          className="w-full h-full object-cover group-hover:scale-105 transition-transform duration-300 ease-in-out"
          loading="lazy"
        />
      </div>
      <div className="p-4 md:p-5">
        <p className="text-xs text-slate-600 font-semibold mb-1">
          {story.category}
        </p>
        <h3 id={`business-title-${story.id}`} className="font-quicksand font-semibold text-md md:text-lg text-slate-800 group-hover:text-black mb-1 transition-colors duration-200 leading-tight">
          {story.title}
        </h3>
        {story.description && (
          <p className="text-sm text-slate-600 mt-2 line-clamp-3 font-inter">{story.description}</p>
        )}
      </div>
    </div>
  );
};

export default BusinessCard;
