import { motion } from 'framer-motion' import { DndContext, closestCenter, KeyboardSensor, PointerSensor, TouchSensor, useSensor, useSensors } from '@dnd-kit/core' import { SortableContext, verticalListSortingStrategy } from '@dnd-kit/sortable' import { restrictToVerticalAxis } from '@dnd-kit/modifiers' import { formatCurrency } from '../utils/formatters' import SortableRow, { DragHandle } from './SortableRow' import useSortableList from '../hooks/useSortableList' export default function OfferItemsSection({ items, setItems, updateItem, addItem, removeItem, itemTemplates, showItemTemplateMenu, setShowItemTemplateMenu, addItemFromTemplate, totals, currency, applyVat, vatRate, itemsError, readOnly }) { const sensors = useSensors( useSensor(PointerSensor, { activationConstraint: { distance: 5 } }), useSensor(TouchSensor, { activationConstraint: { delay: 200, tolerance: 5 } }), useSensor(KeyboardSensor) ) const { handleDragEnd } = useSortableList(setItems, '_key') return (

Položky

{itemsError && {itemsError}}
{!readOnly && (
{itemTemplates.length > 0 && (
{showItemTemplateMenu && (
{itemTemplates.map(t => (
addItemFromTemplate(t)} >
{t.name}
{t.default_price > 0 && (
{Number(t.default_price).toFixed(2)}
)}
))}
)}
)}
)}
{!readOnly && } {!readOnly && } String(i._key))} strategy={verticalListSortingStrategy}> {items.map((item, index) => { const lineTotal = (Number(item.quantity) || 0) * (Number(item.unit_price) || 0) return ( {({ attributes, listeners }) => ( <> {!readOnly && ( )} {!readOnly && ( )} )} ) })}
# Popis položky Množství Jednotka Jedn. cena V ceně Celkem
{index + 1} updateItem(index, 'description', e.target.value)} className="admin-form-input" placeholder="Název položky" style={{ marginBottom: '0.5rem', fontWeight: 500 }} readOnly={readOnly} /> updateItem(index, 'item_description', e.target.value)} className="admin-form-input" placeholder="Podrobný popis (volitelný)" style={{ fontSize: '0.8rem', opacity: 0.8 }} readOnly={readOnly} /> updateItem(index, 'quantity', parseFloat(e.target.value) || 0)} className="admin-form-input" min="0" step="1" style={{ textAlign: 'center', height: '2.25rem', padding: '0.375rem 0.5rem' }} readOnly={readOnly} /> updateItem(index, 'unit', e.target.value)} className="admin-form-input" placeholder="hod" style={{ textAlign: 'center', height: '2.25rem', padding: '0.375rem 0.5rem' }} readOnly={readOnly} /> updateItem(index, 'unit_price', parseFloat(e.target.value) || 0)} className="admin-form-input" min="0" step="0.01" style={{ textAlign: 'right', height: '2.25rem', padding: '0.375rem 0.5rem' }} readOnly={readOnly} /> {formatCurrency(lineTotal, currency)} {items.length > 1 && ( )}
{/* Totals */}
Mezisoučet: {formatCurrency(totals.subtotal, currency)}
{applyVat && (
DPH ({vatRate}%): {formatCurrency(totals.vatAmount, currency)}
)}
Celkem k úhradě: {formatCurrency(totals.total, currency)}
) }