"use client";
/**
* DividerProperties.tsx — 구분선 컴포넌트 설정
*
* - section="data": 구분선은 데이터 바인딩 없으므로 null 반환
* - section="style": StyleAccordion 패턴 (방향 & 선 스타일 + 색상)
*/
import { useState, useCallback } from "react";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import { ChevronRight } from "lucide-react";
import { useReportDesigner } from "@/contexts/ReportDesignerContext";
import type { ComponentConfig } from "@/types/report";
interface Props {
component: ComponentConfig;
/** 우측 패널: "style" | 모달: "data" | 미전달: 전체 표시 (하위 호환) */
section?: "style" | "data";
}
function StyleAccordion({
label,
isOpen,
onToggle,
children,
}: {
label: string;
isOpen: boolean;
onToggle: () => void;
children: React.ReactNode;
}) {
return (
{isOpen && (
{children}
)}
);
}
function ColorInput({ value, onChange }: { value: string; onChange: (v: string) => void }) {
return (
onChange(e.target.value)}
className="h-7 w-7 shrink-0 cursor-pointer rounded border-0 p-0"
/>
onChange(e.target.value)}
className="h-7 border-0 bg-transparent px-1 font-mono text-xs shadow-none focus-visible:ring-0"
/>
);
}
export function DividerProperties({ component, section }: Props) {
const { updateComponent } = useReportDesigner();
const showStyle = !section || section === "style";
if (section === "data") return null;
const [openSections, setOpenSections] = useState>(new Set(["line"]));
const toggleSection = (id: string) => {
setOpenSections((prev) => {
const next = new Set(prev);
if (next.has(id)) next.delete(id);
else next.add(id);
return next;
});
};
const update = useCallback(
(updates: Partial) => updateComponent(component.id, updates),
[component.id, updateComponent],
);
return (
<>
{showStyle && (
{/* 방향 & 선 스타일 */}
toggleSection("line")}>
{
const val = parseFloat(e.target.value);
if (!isNaN(val) && val >= 0.5) {
update({ lineWidth: val });
}
}}
className="h-9 text-xs"
/>
{/* 색상 */}
toggleSection("color")}>
update({ lineColor: v })}
/>
)}
>
);
}