import type { WrapperProps, WrapperState } from './types' import { WrapperUI } from './wrapper-ui' import { widgetStoreActions } from '../stores/widget-store' import { useLayoutEffect } from 'react' /** * Container component providing a collapsible header with title, action buttons, and options menu for widgets. Syncs collapse, disabled, and title state with the widget store. * * @example * ```tsx * ]} * > * {children} * * ``` */ export function WidgetWrapper({ id, title, defaultCollapsed, disabled, sx, actions, options, labels, children, onChangeCollapsed, }: WrapperProps) { useLayoutEffect(() => { widgetStoreActions.setWidget(id, { collapsed: defaultCollapsed, disabled, title, }) }, [defaultCollapsed, disabled, title, id]) const handleChangeCollapsed = ( event: React.SyntheticEvent, expanded: boolean, ) => { onChangeCollapsed?.(event, expanded) widgetStoreActions.setWidget(id, { collapsed: !expanded }) } return ( {children} ) }