"use client"; import React from "react"; import { ConfigPanelBuilderProps, ConfigSectionDefinition } from "./ConfigPanelTypes"; import { ConfigSection } from "./ConfigSection"; import { ConfigField } from "./ConfigField"; import { Tabs, TabsList, TabsTrigger, TabsContent } from "@/components/ui/tabs"; function renderSections>( sections: ConfigSectionDefinition[], config: T, onChange: (key: string, value: any) => void, tableColumns?: any[], ) { return sections.map((section) => { if (section.condition && !section.condition(config)) { return null; } const visibleFields = section.fields.filter( (field) => !field.condition || field.condition(config), ); if (visibleFields.length === 0) { return null; } return ( {visibleFields.map((field) => ( ))} ); }); } export function ConfigPanelBuilder>({ config, onChange, onConfigChange, sections, presets, tableColumns, children, mode = "flat", context, }: ConfigPanelBuilderProps) { const effectiveTableColumns = tableColumns || context?.tableColumns; const presetSection = presets && presets.length > 0 && (

빠른 설정

{presets.map((preset, idx) => ( ))}
); if (mode === "tabs") { const groupMap = new Map[]>(); const ungrouped: ConfigSectionDefinition[] = []; for (const section of sections) { if (section.group) { const existing = groupMap.get(section.group) || []; existing.push(section); groupMap.set(section.group, existing); } else { ungrouped.push(section); } } const tabGroups = Array.from(groupMap.entries()); if (tabGroups.length === 0) { return (
{presetSection} {renderSections(sections, config, onChange, effectiveTableColumns)} {children}
); } const defaultTab = tabGroups[0]?.[0] || "general"; return (
{presetSection} {ungrouped.length > 0 && renderSections(ungrouped, config, onChange, effectiveTableColumns)} {tabGroups.map(([groupName]) => ( {groupName} ))} {tabGroups.map(([groupName, groupSections]) => ( {renderSections(groupSections, config, onChange, effectiveTableColumns)} ))} {children}
); } return (
{presetSection} {renderSections(sections, config, onChange, effectiveTableColumns)} {children}
); }