import React, { ReactNode } from 'react'; import { cn } from '@/lib/utils'; import { GripVertical, Trash2, Copy, ChevronUp, ChevronDown } from 'lucide-react'; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from "@/components/ui/alert-dialog"; import { __ } from '@/lib/i18n'; import { useSortable } from '@dnd-kit/sortable'; import { CSS } from '@dnd-kit/utilities'; import { Section } from '../store/usePageEditorStore'; interface CanvasSectionProps { section: Section; children: ReactNode; isSelected: boolean; isHovered: boolean; onSelect: () => void; onHover: () => void; onLeave: () => void; onDelete: () => void; onDuplicate: () => void; onMoveUp: () => void; onMoveDown: () => void; canMoveUp: boolean; canMoveDown: boolean; } export function CanvasSection({ section, children, isSelected, isHovered, onSelect, onHover, onLeave, onDelete, onDuplicate, onMoveUp, onMoveDown, canMoveUp, canMoveDown, }: CanvasSectionProps) { const { attributes, listeners, setNodeRef, transform, transition, isDragging, } = useSortable({ id: section.id }); const style = { transform: CSS.Transform.toString(transform), transition, }; return (
{ e.stopPropagation(); onSelect(); }} onMouseEnter={onHover} onMouseLeave={onLeave} > {/* Section content with Styles */}
{/* Background Image & Overlay */} {section.styles?.backgroundImage && ( <>
)} {/* Content Wrapper */}
{children}
{/* Floating Toolbar (Standard Interaction) */} {isSelected && (
{/* Label */} {section.type.replace('-', ' ')} {/* Divider */}
{/* Actions */}
{__('Delete this section?')} {__('This action cannot be undone.')} e.stopPropagation()}>{__('Cancel')} { e.stopPropagation(); onDelete(); }} > {__('Delete')}
)} {/* Active Border Label */} {isSelected && (
{section.type}
)} {/* Drag Handle (Always visible on hover or select) */} {(isSelected || isHovered) && ( )}
); }