import { Badge } from '@/component/ui/badge' import { Card, CardContent, CardHeader, CardTitle } from '@/component/ui/card' import { Label } from '@/component/ui/label' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '@/component/ui/select' import { Building2, Target } from 'lucide-react' import { useLaboratories } from './hooks' import { mockApiHelpers } from './mockData' import { ConditionCellMapping, VerificationConditionsConfig } from './types' interface VerificationConditionsEditorProps { config: VerificationConditionsConfig onChange: (config: VerificationConditionsConfig) => void } export function VerificationConditionsEditor({ config, onChange, }: VerificationConditionsEditorProps) { const { data: laboratories = [], isLoading } = useLaboratories() const updateConfig = (updates: Partial) => { onChange({ ...config, ...updates }) } // Получаем выбранную лабораторию const selectedLab = laboratories.find( lab => lab.id === config.selectedLaboratoryId ) // Получаем все доступные условия (либо все из БД, либо условия конкретной лаборатории) const availableConditions = config.selectedLaboratoryId ? mockApiHelpers.getLaboratoryConditions(config.selectedLaboratoryId) : mockApiHelpers.getAllConditions() // Обновление привязки условия к ячейке const updateConditionMapping = (cellIndex: number, conditionKey: string) => { const conditionName = availableConditions.find(c => c.key === conditionKey)?.name || conditionKey const newMappings = [...(config.conditionMappings || [])] const existingIndex = newMappings.findIndex(m => m.cellIndex === cellIndex) if (conditionKey === '__none__') { // Убираем привязку if (existingIndex >= 0) { newMappings.splice(existingIndex, 1) } } else { // Добавляем или обновляем привязку const mapping: ConditionCellMapping = { cellIndex, conditionKey, conditionName, } if (existingIndex >= 0) { newMappings[existingIndex] = mapping } else { newMappings.push(mapping) } } updateConfig({ conditionMappings: newMappings }) } // Получить выбранное условие для ячейки const getSelectedCondition = (cellIndex: number): string => { const mapping = config.conditionMappings?.find( m => m.cellIndex === cellIndex ) return mapping?.conditionKey || '__none__' } return (
{/* Выбор лаборатории */} Лаборатория

{config.selectedLaboratoryId ? 'Доступны только условия выбранной лаборатории' : 'Доступны все условия из базы данных'}

{/* Привязка условий к ячейкам */} {config.targetCells.length > 0 && ( Привязка условий к ячейкам

Настройка записи данных

Выберите какое условие будет записываться в каждую целевую ячейку.

{config.targetCells.map((cell, index) => (
{cell.sheet}!{cell.cell}
))}
{/* Подсказка с доступными условиями */}

Доступные условия{' '} {selectedLab ? `для ${selectedLab.name}` : 'из базы данных'}:

    {availableConditions.map(condition => (
  • {condition.name} {condition.unit && ` (${condition.unit})`} {'isRequired' in condition && condition.isRequired && ' - обязательное'}
  • ))}
)} {/* Подсказка если нет целевых ячеек */} {config.targetCells.length === 0 && (

Целевые ячейки не настроены

Сначала настройте целевые ячейки в основном редакторе элементов, затем вернитесь сюда для привязки условий.

)}
) }