import { Title } from '@mantine/core'; import { useTranslation } from 'next-i18next'; import { openContextModalGeneric } from '../../../../tools/mantineModalManagerExtensions'; import WidgetsDefinitions from '../../../../widgets'; import { IWidget } from '../../../../widgets/widgets'; import { useWrapperColumnCount } from '../../Wrappers/gridstack/store'; import { GenericTileMenu } from '../GenericTileMenu'; import { WidgetEditModalInnerProps } from './WidgetsEditModal'; import { WidgetsRemoveModalInnerProps } from './WidgetsRemoveModal'; export type WidgetChangePositionModalInnerProps = { widgetType: string; widget: IWidget; wrapperColumnCount: number; }; interface WidgetsMenuProps { integration: string; widget: IWidget | undefined; } export const WidgetsMenu = ({ integration, widget }: WidgetsMenuProps) => { const { t } = useTranslation(`modules/${integration}`); const wrapperColumnCount = useWrapperColumnCount(); if (!widget || !wrapperColumnCount) return null; // Match widget.id with WidgetsDefinitions // First get the keys const keys = Object.keys(WidgetsDefinitions); // Then find the key that matches the widget.type const widgetDefinition = keys.find((key) => key === widget.type); // Then get the widget definition const widgetDefinitionObject = WidgetsDefinitions[widgetDefinition as keyof typeof WidgetsDefinitions]; const handleDeleteClick = () => { openContextModalGeneric({ modal: 'integrationRemove', title: {t('common:remove')}, innerProps: { widgetType: integration, }, styles: { inner: { position: 'sticky', top: 30, }, }, }); }; const handleChangeSizeClick = () => { openContextModalGeneric({ modal: 'changeIntegrationPositionModal', size: 'xl', title: null, innerProps: { widgetType: integration, widget, wrapperColumnCount, }, }); }; const handleEditClick = () => { openContextModalGeneric({ modal: 'integrationOptions', title: t('descriptor.settings.title'), innerProps: { widgetType: integration, options: widget.properties, // Cast as the right type for the correct widget widgetOptions: widgetDefinitionObject.options as any, }, zIndex: 5, }); }; return ( ); };