'use client'; import { useEffect, type ReactNode } from 'react'; import { createPortal } from 'react-dom'; import { Loader2 } from '@/components/icons'; import { Button } from '@/components/ui/button'; import { useAdminShell } from './shell-context'; interface AdminSaveBarProps { dirty: boolean; saving?: boolean; onSave: () => void; /** Drops the edits; without it the bar offers only Save. */ onDiscard?: () => void; saveLabel?: string; /** What the save does, e.g. "Users see the change on their next login". */ note?: ReactNode; } /** * The one place a page saves from. It appears at the bottom of the panel * while something is unsaved (through the shell's portal host, so it sits * below the scrolling content and above the mobile rail) and takes Ctrl+S. */ export function AdminSaveBar({ dirty, saving = false, onSave, onDiscard, saveLabel = 'Save changes', note }: AdminSaveBarProps) { const host = useAdminShell()?.saveBarHost ?? null; useEffect(() => { if (!dirty) return; const onKeyDown = (event: KeyboardEvent) => { if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === 's') { event.preventDefault(); if (!saving) onSave(); } }; window.addEventListener('keydown', onKeyDown); return () => window.removeEventListener('keydown', onKeyDown); }, [dirty, saving, onSave]); if (!dirty) return null; const bar = (