import { useTranslation } from 'react-i18next'; import { SettingDefinition } from '../../api/adminSettings'; import { cn } from '../../lib/utils'; import { StarIcon, LockIcon, RefreshIcon } from './icons'; import { SettingInput } from './SettingInput'; import { Toggle } from './Toggle'; import { formatSettingKey, stripHtml } from './utils'; interface SettingsTableRowProps { setting: SettingDefinition; isFavorite: boolean; onToggleFavorite: () => void; onUpdate: (value: string) => void; onReset: () => void; isUpdating?: boolean; isResetting?: boolean; isLast?: boolean; className?: string; } export function SettingsTableRow({ setting, isFavorite, onToggleFavorite, onUpdate, onReset, isUpdating, isResetting, isLast, className, }: SettingsTableRowProps) { const { t } = useTranslation(); const formattedKey = formatSettingKey(setting.name || setting.key); const displayName = t(`admin.settings.settingNames.${formattedKey}`, formattedKey); const description = setting.hint?.description ? stripHtml(setting.hint.description) : null; const isModified = setting.has_override; const isBool = setting.type === 'bool'; const boolChecked = setting.current === true || setting.current === 'true'; // env-locked keys are pinned in .env and shadow the DB — show value, no input. const locked = setting.read_only || setting.env_locked; const isLongValue = (() => { const val = String(setting.current ?? ''); const key = setting.key.toLowerCase(); return ( val.length > 50 || val.includes('\n') || val.startsWith('[') || val.startsWith('{') || key.includes('_items') || key.includes('_config') || key.includes('_keywords') || key.includes('_template') || key.includes('_packages') || key.includes('_list') || key.includes('_json') || key.includes('_periods') || key.includes('_discounts') ); })(); return (
{/* Left side: name, badges, key */}
{/* Name + badges row */}
{displayName} {isModified && ( {t('admin.settings.modified')} )} {setting.has_override && !locked && ( {t('admin.settings.badgeDb')} )} {setting.env_locked && ( {t('admin.settings.badgeEnv')} )}
{/* Setting key */}
{setting.key}
{/* Description for long values */} {isLongValue && description && (

{description}

)}
{/* Right side: control + action buttons */}
{locked ? ( {isBool ? boolChecked ? t('admin.settings.enabled') : t('admin.settings.disabled') : String(setting.current ?? '-')} ) : isBool ? ( onUpdate(boolChecked ? 'false' : 'true')} disabled={isUpdating} aria-label={displayName} /> ) : (
)} {/* Reset button -- hover-reveal when has_override */} {isModified && !locked && ( )} {/* Favorite button -- visible if favorited, hover-reveal otherwise */}
); }