"use client"; import React, { useState } from "react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Badge } from "@/components/ui/badge"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import { Group, Ungroup, Palette, Settings, X, Check, AlignLeft, AlignCenter, AlignRight, StretchHorizontal, StretchVertical, } from "lucide-react"; import { GroupState, ComponentData, ComponentStyle } from "@/types/screen"; import { createGroupStyle } from "@/lib/utils/groupingUtils"; interface GroupingToolbarProps { groupState: GroupState; onGroupStateChange: (state: GroupState) => void; onGroupCreate: (componentIds: string[], title: string, style?: ComponentStyle) => void; onGroupUngroup: (groupId: string) => void; selectedComponents: ComponentData[]; allComponents: ComponentData[]; onGroupAlign?: (mode: "left" | "centerX" | "right" | "top" | "centerY" | "bottom") => void; onGroupDistribute?: (orientation: "horizontal" | "vertical") => void; showCreateDialog?: boolean; onShowCreateDialogChange?: (show: boolean) => void; } export const GroupingToolbar: React.FC = ({ groupState, onGroupStateChange, onGroupCreate, onGroupUngroup, selectedComponents, allComponents, onGroupAlign, onGroupDistribute, showCreateDialog: externalShowCreateDialog, onShowCreateDialogChange, }) => { const [internalShowCreateDialog, setInternalShowCreateDialog] = useState(false); const showCreateDialog = externalShowCreateDialog ?? internalShowCreateDialog; const setShowCreateDialog = onShowCreateDialogChange ?? setInternalShowCreateDialog; const [groupTitle, setGroupTitle] = useState("새 그룹"); const [groupStyle, setGroupStyle] = useState(createGroupStyle()); // 선택된 컴포넌트가 2개 이상인지 확인 const canCreateGroup = selectedComponents.length >= 2; // 선택된 컴포넌트가 그룹인지 확인 const selectedGroup = selectedComponents.length === 1 && selectedComponents[0].type === "group"; const handleCreateGroup = () => { if (canCreateGroup) { setGroupTitle("새 그룹"); setGroupStyle(createGroupStyle()); setShowCreateDialog(true); } }; const handleUngroup = () => { if (selectedGroup) { onGroupUngroup(selectedComponents[0].id); onGroupStateChange({ ...groupState, selectedComponents: [], isGrouping: false, }); } }; const handleConfirmCreate = () => { if (groupTitle.trim()) { const componentIds = selectedComponents.map((c) => c.id); onGroupCreate(componentIds, groupTitle.trim(), groupStyle); setShowCreateDialog(false); onGroupStateChange({ ...groupState, selectedComponents: [], isGrouping: false, }); } }; const handleCancelCreate = () => { setShowCreateDialog(false); setGroupTitle("새 그룹"); setGroupStyle(createGroupStyle()); }; const handleStyleChange = (property: string, value: string) => { setGroupStyle((prev) => ({ ...prev, [property]: value, })); }; return ( <>
그룹화
{/* 선택된 컴포넌트 표시 */} {selectedComponents.length > 0 && ( {selectedComponents.length}개 선택됨 {selectedComponents.length > 1 && ( (Shift+클릭으로 다중선택, 드래그로 함께 이동) )} )}
{/* 그룹 생성 버튼 */} {/* 그룹 해제 버튼 */} {/* 선택 해제 버튼 */} {selectedComponents.length > 0 && ( )} {/* 정렬/분배 도구 */} {selectedComponents.length > 1 && (
정렬
균등
)}
{/* 그룹 생성 다이얼로그 */} 그룹 생성 선택된 {selectedComponents.length}개의 컴포넌트를 그룹으로 묶습니다.
{/* 그룹 제목 */}
setGroupTitle(e.target.value)} placeholder="그룹 제목을 입력하세요" maxLength={50} />
{/* 그룹 스타일 */}
{/* 배경색 */}
{/* 테두리 스타일 */}
{/* 테두리 색상 */}
{/* 모서리 둥글기 */}
); };