'use client'; import { useState, useEffect } from 'react'; interface Checklist { id: string; name: string; type: string; status: string; aircraft: string; date: string; items: number; completed: number; description?: string; checklistItems?: Array<{ id: string; text: string; checked: boolean }>; standards?: { icao?: boolean; easa?: boolean; faa?: boolean; armak?: boolean }; inspector?: string; inspectorLicense?: string; operator?: string; checklistNumber?: string; } interface ChecklistCardModalProps { isOpen: boolean; onClose: () => void; checklist: Checklist | null; onSave?: (updatedChecklist: Checklist) => void; } export default function ChecklistCardModal({ isOpen, onClose, checklist, onSave }: ChecklistCardModalProps) { const [isEditing, setIsEditing] = useState(false); const [editedChecklist, setEditedChecklist] = useState(null); useEffect(() => { if (checklist) { setEditedChecklist({ ...checklist }); setIsEditing(false); } }, [checklist]); if (!isOpen || !checklist || !editedChecklist) { return null; } const handleChange = (field: keyof Checklist, value: string | number) => { setEditedChecklist({ ...editedChecklist, [field]: value }); }; const handleItemToggle = (itemId: string) => { if (editedChecklist.checklistItems) { const updatedItems = editedChecklist.checklistItems.map(item => item.id === itemId ? { ...item, checked: !item.checked } : item ); const completed = updatedItems.filter(item => item.checked).length; setEditedChecklist({ ...editedChecklist, checklistItems: updatedItems, completed, }); } }; const handleSave = () => { if (onSave) { onSave(editedChecklist); setIsEditing(false); alert('Чек-лист успешно обновлён'); } }; const handleCancel = () => { if (checklist) { setEditedChecklist({ ...checklist }); setIsEditing(false); } }; const currentChecklist = isEditing ? editedChecklist : checklist; const progress = currentChecklist.items > 0 ? Math.round((currentChecklist.completed / currentChecklist.items) * 100) : 0; return (
e.stopPropagation()} >
{isEditing ? (
handleChange('name', e.target.value)} style={{ width: '100%', padding: '12px', border: '1px solid #ccc', borderRadius: '4px', fontSize: '16px', }} />
) : (

{currentChecklist.name}

{currentChecklist.checklistNumber && (
Номер: {currentChecklist.checklistNumber}
)} {/* Отображение стандартов соответствия */} {currentChecklist.standards && (
{currentChecklist.standards.icao && ( ICAO )} {currentChecklist.standards.easa && ( EASA )} {currentChecklist.standards.faa && ( FAA )} {currentChecklist.standards.armak && ( АРМАК )}
)}
)}
{isEditing ? (
handleChange('aircraft', e.target.value)} style={{ width: '100%', padding: '8px', border: '1px solid #ccc', borderRadius: '4px', fontSize: '14px', }} />
) : (
Тип: {currentChecklist.type} | ВС: {currentChecklist.aircraft} | Дата: {currentChecklist.date}
{currentChecklist.operator && (
Оператор: {currentChecklist.operator}
)} {currentChecklist.inspector && (
Инспектор: {currentChecklist.inspector} {currentChecklist.inspectorLicense && ` (${currentChecklist.inspectorLicense})`}
)}
)}
{!isEditing && ( )}
Прогресс выполнения: {currentChecklist.completed} / {currentChecklist.items} ({progress}%)
Статус: {currentChecklist.status}
{currentChecklist.description && (

Описание

{isEditing ? (