import type { PillNavItem, } from '../types' import type { NormalizedControl, } from './controlSchemaNormalize' import { humanize, } from './controlSchemaUtils' import type { ControlDefinition, ControlSchemaOptions, ControlSectionConfig, ControlSidebarConfig, } from './controlSchemaTypes' export function sectionConfig( sectionId: string, controls: NormalizedControl[], options: ControlSchemaOptions, ): ControlSectionConfig { const configured = options.sections?.[sectionId] const first = controls[0]?.definition return { ...configured, id: sectionId, label: configured?.label ?? first?.sectionLabel, title: configured?.title ?? first?.sectionLabel, description: configured?.description ?? first?.sectionDescription, subtitle: configured?.subtitle ?? first?.sectionSubtitle, } } export function firstSidebarConfig(controls: NormalizedControl[]): ControlSidebarConfig | undefined { for (const control of controls) { const sidebar = control.definition.sidebar if (sidebar && typeof sidebar === 'object' && sidebar.enabled !== false) return sidebar } return undefined } export function isSidebarEnabled(sidebar: ControlDefinition['sidebar']): boolean { if (sidebar === false) return false if (sidebar && typeof sidebar === 'object') return sidebar.enabled !== false return true } export function controlViewItem(viewId: string, options: ControlSchemaOptions): PillNavItem { const config = options.views?.[viewId] return { id: viewId, label: config?.label ?? humanize(viewId), ...(config?.icon !== undefined ? { icon: config.icon } : {}), ...(config?.to !== undefined ? { to: config.to } : {}), ...(config?.href !== undefined ? { href: config.href } : {}), ...(config?.disabled !== undefined ? { disabled: config.disabled } : {}), ...(config?.children !== undefined ? { children: config.children } : {}), } }