import React, { useState, useMemo } from 'react'; import { CurrentView, BusinessStory } from '../types'; import { SECTION_IDS, BUSINESS_LANDING_CONTENT } from '../constants'; import BusinessCard from './BusinessCard'; import FilterSortBar, { ViewMode, SortOptionKey, SortOption } from './FilterSortBar'; interface BusinessLandingSectionProps { businessStories: BusinessStory[]; setCurrentView: (view: CurrentView) => void; setSelectedItemId: (id: string | null) => void; } const sortOptions: SortOption[] = [ { key: 'alphabetical', label: 'По алфавиту (А-Я)' }, ]; const BusinessLandingSection: React.FC = ({ businessStories, setCurrentView, setSelectedItemId }) => { const [viewMode, setViewMode] = useState('grid'); const [selectedCategories, setSelectedCategories] = useState([]); const [selectedSort, setSelectedSort] = useState('alphabetical'); const availableCategories = useMemo(() => { if (!businessStories) return []; return Array.from(new Set(businessStories.map(p => p.category))).sort(); }, [businessStories]); const handleCategoryChange = (category: string) => { setSelectedCategories(prev => prev.includes(category) ? prev.filter(c => c !== category) : [...prev, category] ); }; const filteredAndSortedStories = useMemo(() => { if (!businessStories) return []; const filtered = selectedCategories.length > 0 ? businessStories.filter(p => selectedCategories.includes(p.category)) : businessStories; return [...filtered].sort((a, b) => { if (selectedSort === 'alphabetical') { return a.title.localeCompare(b.title); } return 0; // Only alphabetical sort is supported }); }, [businessStories, selectedCategories, selectedSort]); if (!businessStories) { return (

Загрузка кейсов...

); } const layoutClasses = viewMode === 'grid' ? "grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6 md:gap-8" : "flex flex-col gap-4"; return (

{BUSINESS_LANDING_CONTENT.title}

{BUSINESS_LANDING_CONTENT.subtitle}

setSelectedCategories([])} sortOptions={sortOptions} selectedSort={selectedSort} onSortChange={setSelectedSort} /> {filteredAndSortedStories.length > 0? (
{filteredAndSortedStories.map(story => ( ))}
) : (

{BUSINESS_LANDING_CONTENT.emptyStateTitle}

{BUSINESS_LANDING_CONTENT.emptyStateMessage}

)}
); }; export default BusinessLandingSection;