import React from 'react';
import { CurrentView, ResearchPaper } from '../types'; // Added ResearchPaper type
import { SECTION_IDS, RESEARCH_SECTION_CONTENT } from '../constants';
import { ChevronRightIcon } from './icons';
import ResearchCard from './ResearchCard';

interface ResearchSectionProps {
  researchPapers: ResearchPaper[]; // Changed from mockResearchPapers
  setCurrentView: (view: CurrentView) => void;
  setSelectedItemId: (id: string | null) => void;
}

const ResearchSection: React.FC<ResearchSectionProps> = ({ researchPapers, setCurrentView, setSelectedItemId }) => {
  
  const handleShowAllClick = (e: React.MouseEvent<HTMLAnchorElement>) => {
    e.preventDefault();
    setCurrentView('researchAll');
    setSelectedItemId(null);
  };

  if (!researchPapers || researchPapers.length === 0) {
     return (
      <section id={SECTION_IDS.latestResearch} className="py-16 md:py-24 bg-white">
        <div className="container mx-auto px-4 sm:px-6 lg:px-8 text-center">
          <p className="text-slate-600 font-inter">Загрузка исследований...</p>
        </div>
      </section>
    );
  }


  return (
    <section id={SECTION_IDS.latestResearch} 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-12 md:mb-16">
          <h2 className="font-quicksand text-4xl sm:text-5xl font-bold text-slate-900">
            {RESEARCH_SECTION_CONTENT.title}
          </h2>
          <a 
            href={`#${SECTION_IDS.researchAllPage}`}
            onClick={handleShowAllClick}
            className="group inline-flex items-center text-base font-medium text-slate-700 hover:text-black transition-colors whitespace-nowrap"
            aria-label={RESEARCH_SECTION_CONTENT.showAllAriaLabel}
          >
            {RESEARCH_SECTION_CONTENT.showAllText}
            <ChevronRightIcon className="ml-1 w-5 h-5 transform group-hover:translate-x-1 transition-transform duration-200" />
          </a>
        </div>
        
        <div className="grid grid-cols-1 md:grid-cols-2 gap-6 lg:gap-8 xl:gap-10">
          {researchPapers.slice(-4).reverse().map(paper => ( 
            <ResearchCard 
              key={paper.id} 
              paper={paper} 
              setCurrentView={setCurrentView}
              setSelectedItemId={setSelectedItemId}
            />
          ))}
        </div>
      </div>
    </section>
  );
};

export default ResearchSection;