'use client';
import { useLayerStore } from '@/store';
import { useContextMenuStore } from '@/store/context-menu-store';
import { Eye, EyeOff, Trash2, Copy, Layers, MoveUp, MoveDown } from 'lucide-react';
import { cn } from '@/lib/utils';
import {
deleteLayerWithHistory,
updateLayerWithHistory,
duplicateLayerWithHistory,
} from '@/lib/layer-operations';
export function LayersPanel() {
const { layers, activeLayerId, setActiveLayer, reorderLayer } = useLayerStore();
const { showContextMenu } = useContextMenuStore();
// Sort layers by order (highest first)
const sortedLayers = [...layers].sort((a, b) => b.order - a.order);
const handleMoveLayer = (layerId: string, direction: 'up' | 'down') => {
const layer = layers.find((l) => l.id === layerId);
if (!layer) return;
const layerIndex = sortedLayers.findIndex((l) => l.id === layerId);
if (direction === 'up' && layerIndex > 0) {
const targetLayer = sortedLayers[layerIndex - 1];
reorderLayer(layerId, targetLayer.order);
} else if (direction === 'down' && layerIndex < sortedLayers.length - 1) {
const targetLayer = sortedLayers[layerIndex + 1];
reorderLayer(layerId, targetLayer.order);
}
};
const handleContextMenu = (e: React.MouseEvent, layerId: string) => {
e.preventDefault();
const layer = layers.find((l) => l.id === layerId);
if (!layer) return;
const layerIndex = sortedLayers.findIndex((l) => l.id === layerId);
const canMoveUp = layerIndex > 0;
const canMoveDown = layerIndex < sortedLayers.length - 1;
const canDelete = layers.length > 1;
showContextMenu(e.clientX, e.clientY, [
{
label: 'Duplicate Layer',
icon:
No layers
{layer.name}
{layer.width} × {layer.height}