import { useTranslation } from 'react-i18next'; import { useSortable } from '@dnd-kit/sortable'; import { CSS } from '@dnd-kit/utilities'; import { cn } from '../../lib/utils'; import { GripIcon, TrashIcon } from '../icons/LandingIcons'; import { LocalizedInput } from './LocalizedInput'; import type { AdminLandingFeature, LocaleDict, SupportedLocale } from '../../api/landings'; export type FeatureWithId = AdminLandingFeature & { _id: string }; interface SortableFeatureProps { feature: FeatureWithId; index: number; locale: SupportedLocale; onUpdateIcon: (index: number, value: string) => void; onUpdateLocalized: (index: number, field: 'title' | 'description', value: LocaleDict) => void; onRemove: (index: number) => void; } export function SortableFeatureItem({ feature, index, locale, onUpdateIcon, onUpdateLocalized, onRemove, }: SortableFeatureProps) { const { t } = useTranslation(); const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({ id: feature._id, }); const style: React.CSSProperties = { transform: CSS.Transform.toString(transform), transition, zIndex: isDragging ? 50 : undefined, position: isDragging ? 'relative' : undefined, }; return (
onUpdateIcon(index, e.target.value)} placeholder={t('admin.landings.featureIcon')} className="w-16 rounded-lg border border-dark-700 bg-dark-800 px-2 py-1.5 text-center text-sm text-dark-100 outline-none focus:border-accent-500" /> onUpdateLocalized(index, 'title', v)} locale={locale} placeholder={t('admin.landings.featureTitle')} className="min-w-0 flex-1 rounded-lg border border-dark-700 bg-dark-800 px-3 py-1.5 text-sm text-dark-100 outline-none focus:border-accent-500" />
onUpdateLocalized(index, 'description', v)} locale={locale} placeholder={t('admin.landings.featureDesc')} className="w-full rounded-lg border border-dark-700 bg-dark-800 px-3 py-1.5 text-sm text-dark-100 outline-none focus:border-accent-500" />
); }