'use client';
import { useState, useRef, useEffect } from 'react';
import { ChevronDown, ChevronRight, Wand2, Square, Move, Hexagon, History, Sliders, Wrench } from 'lucide-react';
import { useUIStore } from '@/store';
import { LayersPanel } from '@/components/layers/layers-panel';
import { ColorPanel } from '@/components/colors';
import { FilterPanel } from '@/components/filters';
import { SelectionPanel } from '@/components/selection';
import { TransformPanel } from '@/components/transform';
import { ShapePanel } from '@/components/shapes';
import { HistoryPanel } from './history-panel';
interface CollapsibleSectionProps {
title: string;
icon?: React.ComponentType<{ className?: string }>;
children: React.ReactNode;
id: 'filters' | 'selection' | 'transform' | 'shapeSettings';
}
function CollapsibleSection({ title, icon: Icon, children, id }: CollapsibleSectionProps) {
const { collapsed, toggleCollapsed } = useUIStore();
const isOpen = collapsed[id];
return (
{isOpen &&
{children}
}
);
}
export function PanelDock() {
const {
panelDock,
setActiveTab,
setPanelWidth,
setLayersHeight,
setColorsHeight,
} = useUIStore();
const { activeTab, width, layersHeight, colorsHeight } = panelDock;
const [isResizingWidth, setIsResizingWidth] = useState(false);
const [isResizingLayersHeight, setIsResizingLayersHeight] = useState(false);
const [isResizingColorsHeight, setIsResizingColorsHeight] = useState(false);
const dockRef = useRef(null);
// Handle width resize
useEffect(() => {
if (!isResizingWidth) return;
const handleMouseMove = (e: MouseEvent) => {
if (!dockRef.current) return;
const containerRect = dockRef.current.parentElement?.getBoundingClientRect();
if (!containerRect) return;
const newWidth = containerRect.right - e.clientX;
setPanelWidth(newWidth);
};
const handleMouseUp = () => {
setIsResizingWidth(false);
};
document.addEventListener('mousemove', handleMouseMove);
document.addEventListener('mouseup', handleMouseUp);
return () => {
document.removeEventListener('mousemove', handleMouseMove);
document.removeEventListener('mouseup', handleMouseUp);
};
}, [isResizingWidth]);
// Handle layers height resize
useEffect(() => {
if (!isResizingLayersHeight) return;
const handleMouseMove = (e: MouseEvent) => {
if (!dockRef.current) return;
const dockRect = dockRef.current.getBoundingClientRect();
const relativeY = e.clientY - dockRect.top;
const percentage = (relativeY / dockRect.height) * 100;
setLayersHeight(percentage);
};
const handleMouseUp = () => {
setIsResizingLayersHeight(false);
};
document.addEventListener('mousemove', handleMouseMove);
document.addEventListener('mouseup', handleMouseUp);
return () => {
document.removeEventListener('mousemove', handleMouseMove);
document.removeEventListener('mouseup', handleMouseUp);
};
}, [isResizingLayersHeight]);
// Handle colors height resize
useEffect(() => {
if (!isResizingColorsHeight) return;
const handleMouseMove = (e: MouseEvent) => {
if (!dockRef.current) return;
const dockRect = dockRef.current.getBoundingClientRect();
const layersBottom = (layersHeight / 100) * dockRect.height;
const relativeY = e.clientY - dockRect.top - layersBottom;
const percentage = (relativeY / dockRect.height) * 100;
setColorsHeight(percentage);
};
const handleMouseUp = () => {
setIsResizingColorsHeight(false);
};
document.addEventListener('mousemove', handleMouseMove);
document.addEventListener('mouseup', handleMouseUp);
return () => {
document.removeEventListener('mousemove', handleMouseMove);
document.removeEventListener('mouseup', handleMouseUp);
};
}, [isResizingColorsHeight, layersHeight]);
return (
{/* Width resize handle (left edge) */}
setIsResizingWidth(true)}
/>
{/* Layers Panel */}
{/* Height resize handle (between layers and colors) */}
setIsResizingLayersHeight(true)}
/>
{/* Colors Panel */}
{/* Height resize handle (between colors and tabs) */}
setIsResizingColorsHeight(true)}
/>
{/* Tabbed section */}
{/* Tab buttons */}
{/* Tab content */}
{activeTab === 'adjustments' && (
)}
{activeTab === 'tools' && (
)}
{activeTab === 'history' && (
)}
);
}