import type { CurriculumListContents } from '@/types/curriculum.type'; 
import { getCurriculumIconColor } from '../../../utils/curriculum.utils';
import SectionTitle from './Items/section-title';
import CurriculumSidebarItemWrapper from './Items/curriculum-sidebar-item-wrapper';
import SectionCommonItem from './Items/section-item';


interface SidebarItemProps {
    item: CurriculumListContents;
    selectedIndex: number;
    setSelectedIndex: (index: number) => void;
    index: number;
    done: boolean;
}

function SidebarItem({item, selectedIndex, setSelectedIndex, index, done}: SidebarItemProps): React.ReactNode {
   
  
  if (item.type === 'sectionTitle') {
        return <SectionTitle key={item.uuid} {...item} />;
      }
      const isSelected = selectedIndex === index;

      return (
        <CurriculumSidebarItemWrapper
          index={index}
          isSelected={isSelected}
          key={item.uuid}
          onClick={() => {
            setSelectedIndex(index);
          }}
        >
          <SectionCommonItem
            {...item}
            color={getCurriculumIconColor({
              done,
              selected: isSelected,
            })}
          />
        </CurriculumSidebarItemWrapper>
      );
    }

export default SidebarItem;