import { ActionIcon, Button, ColorInput, Group, NumberInput, Paper, SegmentedControl, Select, Stack, Text, TextInput, Tooltip, } from '@mantine/core'; import { IconBold, IconItalic, IconTrash } from '@tabler/icons-react'; import { useTranslation } from 'react-i18next'; import type { TemplateFieldPlacement, TemplateVariable } from '@ema-platform/api'; interface Props { block: TemplateFieldPlacement | null; variables: TemplateVariable[]; onChange: (block: TemplateFieldPlacement) => void; onDelete: (id: string) => void; disabled: boolean; } /** Everything about the selected block that is not its position on the page. */ export function BlockPropertiesPanel({ block, variables, onChange, onDelete, disabled, }: Props) { const { t } = useTranslation(); if (!block) { return ( {t('designer.noBlockSelected', 'Select a block on the page to edit it.')} ); } const current = block; const isLiteral = current.variable === null; const isImage = current.type === 'image'; const variableByKey = new Map(variables.map((v) => [v.key, v])); const selectVariable = (key: string | null) => { if (!key) return; const kind: 'text' | 'image' = variableByKey.get(key)?.kind === 'image' ? 'image' : 'text'; onChange({ ...current, variable: key, type: kind }); }; return ( {t('designer.blockProperties', 'Selected block')} onDelete(block.id)} > value === 'text' ? onChange({ ...block, variable: null, type: 'text', text: block.text ?? '' }) : selectVariable(variables[0]?.key ?? 'companyName') } data={[ { value: 'variable', label: t('designer.blockVariable', 'Variable') }, { value: 'text', label: t('designer.blockText', 'Fixed text') }, ]} /> {isLiteral ? ( onChange({ ...block, text: e.currentTarget.value })} disabled={disabled} /> ) : (