import { useState } from 'react'; import { Box, Typography, Container, Chip, Button, Paper, Divider, Dialog, DialogTitle, DialogContent, DialogContentText, DialogActions, LinearProgress, } from '@mui/material'; import { Edit as EditIcon, Delete as DeleteIcon } from '@mui/icons-material'; import { useParams, useNavigate } from 'react-router-dom'; import { useQuery, useQueryClient } from '@tanstack/react-query'; import DashboardLayout from '../components/dashboard/DashboardLayout'; import { PageHeader } from '../components/templates'; import { usePermissionContext } from '../contexts/PermissionContext'; import { useNotification } from '../contexts/NotificationContext'; import { personalEquipmentApi } from '../services/personalEquipment'; import type { ZustandOption } from '../types/personalEquipment.types'; export default function PersoenlicheAusruestungDetail() { const { id } = useParams<{ id: string }>(); const navigate = useNavigate(); const queryClient = useQueryClient(); const { hasPermission } = usePermissionContext(); const { showSuccess, showError } = useNotification(); const [deleteOpen, setDeleteOpen] = useState(false); const [deleting, setDeleting] = useState(false); const { data: item, isLoading, isError } = useQuery({ queryKey: ['persoenliche-ausruestung', 'detail', id], queryFn: () => personalEquipmentApi.getById(id!), enabled: !!id, }); const { data: zustandOptions = [] } = useQuery({ queryKey: ['persoenliche-ausruestung', 'zustand-options'], queryFn: () => personalEquipmentApi.getZustandOptions(), staleTime: 5 * 60 * 1000, }); const getZustandLabel = (key: string) => zustandOptions.find(o => o.key === key)?.label ?? key; const getZustandColor = (key: string) => zustandOptions.find(o => o.key === key)?.color ?? 'default'; const canEdit = hasPermission('persoenliche_ausruestung:edit'); const canDelete = hasPermission('persoenliche_ausruestung:delete'); const handleDelete = async () => { if (!id) return; setDeleting(true); try { await personalEquipmentApi.delete(id); queryClient.invalidateQueries({ queryKey: ['persoenliche-ausruestung'] }); showSuccess('Persönliche Ausrüstung gelöscht'); navigate('/persoenliche-ausruestung'); } catch { showError('Fehler beim Löschen'); } finally { setDeleting(false); setDeleteOpen(false); } }; return ( {isLoading ? ( ) : isError || !item ? ( Fehler beim Laden. ) : ( <> ${item.artikel_kategorie_name}` : item.artikel_kategorie_name || item.kategorie || undefined} /> {/* Status + actions row */} {canEdit && ( )} {canDelete && ( )} {/* Info card */} Details {([ ['Benutzer', item.user_display_name || item.benutzer_name], ['Seriennummer', item.seriennummer], ['Inventarnummer', item.inventarnummer], ['Erstellt am', new Date(item.erstellt_am).toLocaleDateString('de-AT')], ] as [string, string | null | undefined][]).map(([label, value]) => value ? ( {label} {value} ) : null)} {item.anfrage_id && ( <> Aus Anfrage navigate(`/ausruestungsanfrage/${item.anfrage_id}`)} > Anfrage #{item.anfrage_id} )} {/* Eigenschaften */} {item.eigenschaften && item.eigenschaften.length > 0 && ( Eigenschaften {item.eigenschaften.map((e) => ( {e.name} {e.wert} ))} )} {/* Notizen */} {item.notizen && ( Notizen {item.notizen} )} )} {/* Delete confirmation */} setDeleteOpen(false)}> Persönliche Ausrüstung löschen? Dieser Eintrag wird dauerhaft gelöscht und kann nicht wiederhergestellt werden. ); }