import { useEffect } from 'react'
import PropTypes from 'prop-types'
import { useTranslation } from 'react-i18next'
import classNames from 'classnames'
import Icon from '../../../shared/components/icon'
import {
useFileTreeSelectable,
useSelectableEntity,
} from '../contexts/file-tree-selectable'
import { useDroppable } from '../contexts/file-tree-draggable'
import FileTreeItemInner from './file-tree-item/file-tree-item-inner'
import FileTreeFolderList from './file-tree-folder-list'
import usePersistedState from '../../../shared/hooks/use-persisted-state'
function FileTreeFolder({ name, id, folders, docs, files }) {
const { t } = useTranslation()
const { isSelected, props: selectableEntityProps } = useSelectableEntity(id)
const { selectedEntityParentIds } = useFileTreeSelectable(id)
const [expanded, setExpanded] = usePersistedState(
`folder.${id}.expanded`,
false
)
useEffect(() => {
if (selectedEntityParentIds.has(id)) {
setExpanded(true)
}
}, [id, selectedEntityParentIds, setExpanded])
function handleExpandCollapseClick() {
setExpanded(!expanded)
}
const { isOver: isOverRoot, dropRef: dropRefRoot } = useDroppable(id)
const { isOver: isOverList, dropRef: dropRefList } = useDroppable(id)
const icons = (
<>