import React from 'react';
import { CurrentView, BusinessStory } from '../types'; 
import { SECTION_IDS, BUSINESS_SECTION_CONTENT } from '../constants'; 
import { ChevronRightIcon } from './icons';
import BusinessCard from './BusinessCard'; 

interface BusinessSectionProps {
  businessStories: BusinessStory[]; // Added to accept fetched data
  setCurrentView: (view: CurrentView) => void;
  setSelectedItemId: (id: string | null) => void; 
}

const BusinessSection: React.FC<BusinessSectionProps> = ({ businessStories, setCurrentView, setSelectedItemId }) => {
  
  const handleShowAllClick = (e: React.MouseEvent<HTMLAnchorElement>) => {
    e.preventDefault();
    setCurrentView('businessLanding');
    setSelectedItemId(null); 
  };

  if (!businessStories || businessStories.length === 0) {
    return (
      <section id={SECTION_IDS.businessShowcase} className="py-16 md:py-24 bg-white">
        <div className="container mx-auto px-4 sm:px-6 lg:px-8 text-center">
          {/* Optionally, you can add a loading or empty state specific to this section */}
        </div>
      </section>
    );
  }

  return (
    <section id={SECTION_IDS.businessShowcase} className="py-16 md:py-24 bg-white">
      <div className="container mx-auto px-4 sm:px-6 lg:px-8">
        <div className="flex justify-between items-baseline mb-10 md:mb-12">
          <h2 className="font-quicksand text-4xl sm:text-5xl font-bold text-slate-900">
            {BUSINESS_SECTION_CONTENT.title}
          </h2>
          <a 
            href={`#${SECTION_IDS.businessLandingPage}`} 
            onClick={handleShowAllClick}
            className="group inline-flex items-center text-base font-medium text-slate-700 hover:text-black transition-colors whitespace-nowrap"
            aria-label={BUSINESS_SECTION_CONTENT.showAllAriaLabel}
          >
            {BUSINESS_SECTION_CONTENT.showAllText}
            <ChevronRightIcon className="ml-1 w-5 h-5 transform group-hover:translate-x-1 transition-transform duration-200" />
          </a>
        </div>
      </div>
      
      <div className="w-full overflow-x-auto overflow-y-hidden no-scrollbar snap-x snap-mandatory">
        <div className="flex flex-nowrap gap-4 sm:gap-6 px-4 sm:px-6 lg:px-8 min-w-max pb-2 -mb-2">
          {businessStories.slice(-6).reverse().map(story => ( // Show up to 6 stories in the scroller
            <BusinessCard 
              key={story.id} 
              story={story} 
              setCurrentView={setCurrentView}
              setSelectedItemId={setSelectedItemId}
              className="flex-shrink-0 w-72 sm:w-80 md:w-[22rem] snap-start" 
            />
          ))}
        </div>
      </div>
    </section>
  );
};

export default BusinessSection;