'use client'
import { format } from 'date-fns'
import type { GanttChartProps } from './types'
import { useGanttState } from './hooks/useGanttState'
import { GanttFilterBar } from './GanttFilterBar'
import { GanttTimelineView } from './GanttTimelineView'
import { GanttBoardView } from './GanttBoardView'
import { GanttListView } from './GanttListView'
export function GanttChart(props: GanttChartProps) {
const {
className,
infoColumnLabel = 'Item',
infoColumnWidth = 320,
showCategory = true,
showStatus = true,
showFilterBar = false,
showFullscreen = false,
showViewSwitcher = false,
onItemEdit,
} = props
const {
isFullscreen,
viewMode,
setViewMode,
detailItem,
setDetailItem,
uniqueStatuses,
uniqueCategories,
filteredItems,
tasks,
filters,
setFilters,
wrapperRef,
handleItemClick,
categoryColors,
onStatusChange,
// Timeline view props
zoomIndex,
setZoomIndex,
collapsed,
mounted,
dragState,
focusedRowIndex,
dayWidth,
startDate,
days,
months,
timeHeaderUnits,
dependencyPaths,
timelineWidth,
bodyHeight,
bodyScrollRef,
headerTimelineRef,
infoColumnRef,
toggleFullscreen,
toggleCollapse,
handleBodyScroll,
getBarPosition,
handleDragStart,
onDateChange,
// Board view props
boardColumns,
boardDragItem,
setBoardDragItem,
// List view props
listItems,
} = useGanttState(props)
if (tasks.length === 0 && filteredItems.length === 0) {
return (
No items with dates to display
)
}
return (
{/* Filter bar */}
{showFilterBar && (
setFilters(f)}
uniqueStatuses={uniqueStatuses}
uniqueCategories={uniqueCategories}
/>
)}
{/* View switcher */}
{showViewSwitcher && (
{(['timeline', 'board', 'list'] as const).map((mode) => (
))}
)}
{/* Timeline view */}
{viewMode === 'timeline' && (
)}
{/* Board view */}
{viewMode === 'board' && (
)}
{/* List view */}
{viewMode === 'list' && (
)}
{/* Detail modal */}
{detailItem && onItemEdit && (
setDetailItem(null)}>
e.stopPropagation()}>
{detailItem.title}
{detailItem.description && (
{detailItem.description}
)}
{detailItem.category !== undefined && (
)}
{detailItem.progress !== undefined && (
{
const val = parseInt(e.target.value)
const updated = { ...detailItem, progress: val }
setDetailItem(updated)
onItemEdit(detailItem.id, { progress: val })
}}
className="gantt-detail-slider"
/>
)}
)}
)
}