import React from 'react';
import type { DocumentsViewProps } from '../panel/DocumentsPanel';
import type { DocumentViewLogic } from '../hooks/useDocumentViewLogic';
import { useFolderItemLogic } from '../hooks/useFolderItemLogic';
import EntryShell from './EntryShell';

interface FolderEntryProps extends DocumentsViewProps {
    folder: any;
    viewLogic: DocumentViewLogic;
    component: React.ElementType;
    className?: string;
    role?: string;
    children: (logic: ReturnType<typeof useFolderItemLogic>) => React.ReactNode;
}

const FolderEntry: React.FC<FolderEntryProps> = (props) => {
    const { folder, component, className, role, children, viewLogic } = props;
    const logic = useFolderItemLogic({ folder, viewLogic, ...props });

    return (
        <EntryShell
            component={component}
            id={`folder-${folder.id}`}
            handlers={logic.handlers}
            isSelected={logic.isSelectedFolder}
            isDragging={logic.isDraggingFolder}
            canDrag={logic.canDragFolder}
            className={className}
            role={role}
        >
            {children(logic)}
        </EntryShell>
    );
};

export default FolderEntry;
