import { useEffect, useState } from 'react' import { Box, IconButton, Tooltip, Typography, useMediaQuery, useTheme } from '@mui/material' import { ArrowLeft, LayoutGrid, List as ListIcon, Inbox } from 'lucide-react' import { useActiveInquiries } from '../../hooks/useInquiries' import { EmptyState } from '../ui' import { InquiryList } from './InquiryList' import { InquiryCardGrid } from './InquiryCardGrid' import { InquiryDetailPanel } from './InquiryDetailPanel' type ViewMode = 'list' | 'grid' const VIEW_STORAGE_KEY = 'view-inquiries' function loadViewMode(): ViewMode { if (typeof window === 'undefined') return 'list' const stored = window.localStorage.getItem(VIEW_STORAGE_KEY) return stored === 'grid' ? 'grid' : 'list' } export function ActiveInquiriesTab() { const { data: inquiries = [], isLoading } = useActiveInquiries() const [selectedId, setSelectedId] = useState(null) const [view, setView] = useState(loadViewMode()) const theme = useTheme() const isMobile = useMediaQuery(theme.breakpoints.down('md')) useEffect(() => { if (typeof window !== 'undefined') { window.localStorage.setItem(VIEW_STORAGE_KEY, view) } }, [view]) // Auto-select first inquiry on desktop only useEffect(() => { if (!isMobile && !selectedId && inquiries.length > 0) { setSelectedId(inquiries[0].id) } }, [inquiries, selectedId, isMobile]) if (!isLoading && inquiries.length === 0) { return ( } title="Keine aktiven Anfragen" description="Sobald Interessenten Anfragen zu Ihren Objekten stellen, erscheinen diese hier." /> ) } // Mobile: show detail panel when an inquiry is selected if (isMobile && selectedId) { return ( setSelectedId(null)}> ) } return ( {/* Left column: list/grid */} Anfragen {inquiries.length} setView('list')} sx={{ bgcolor: view === 'list' ? '#e0e7ff' : 'transparent', color: view === 'list' ? '#1e3a5f' : '#64748b' }}> setView('grid')} sx={{ bgcolor: view === 'grid' ? '#e0e7ff' : 'transparent', color: view === 'grid' ? '#1e3a5f' : '#64748b' }}> {view === 'list' ? ( ) : ( )} {/* Right column: detail (desktop only) */} {!isMobile && ( {selectedId ? ( ) : ( } title="Anfrage auswählen" description="Wählen Sie eine Anfrage aus der Liste, um Details anzuzeigen und zu antworten." /> )} )} ) }