import { Check, Save, X } from 'lucide-react'
/**
* Feste Aktionsleiste für Formulare/Modale: Speichern, Speichern & schließen, Abbrechen.
* Bleibt sichtbar (sticky), während der Formularinhalt scrollt.
*/
function ActionLabel({ Icon, long, short, saving, savingShort = '…' }) {
if (saving) {
return {savingShort}
}
return (
<>
{Icon ? : null}
{long}
{short != null && short !== '' ? (
{short}
) : null}
>
)
}
export default function FormActionBar({
placement = 'bottom',
variant = 'default',
saving = false,
saveLabel,
saveShortLabel,
saveAndCloseLabel = 'Speichern & schließen',
saveAndCloseShortLabel,
cancelLabel = 'Abbrechen',
onSave,
onSaveAndClose,
onCancel,
showSave = true,
showSaveAndClose = true,
showCancel = true,
formId,
isNew = false,
primaryIsSaveOnly = false,
}) {
const labelSave = saveLabel ?? (isNew ? 'Anlegen' : 'Speichern')
const shortSave = saveShortLabel ?? (isNew ? 'Neu' : 'Sichern')
const shortClose = saveAndCloseShortLabel ?? 'Fertig'
const showSaveBtn = showSave && (Boolean(onSave) || Boolean(formId))
const showCloseBtn = showSaveAndClose && (Boolean(onSaveAndClose) || Boolean(formId))
const showCancelBtn = showCancel && Boolean(onCancel)
if (!showSaveBtn && !showCloseBtn && !showCancelBtn) return null
const saveBtnClass = `btn form-action-bar__btn${
primaryIsSaveOnly ? ' btn-primary' : ' btn-secondary'
}`
const closeBtnClass = `btn form-action-bar__btn${
primaryIsSaveOnly ? ' btn-secondary' : ' btn-primary'
}`
const primaryCount = (showSaveBtn ? 1 : 0) + (showCloseBtn ? 1 : 0)
return (
{showCancelBtn ? (
) : null}
{showSaveBtn ? (
) : null}
{showCloseBtn ? (
) : null}
)
}