import { useEffect, useState } from 'react' import { NavLink, Outlet, useLocation, Link } from 'react-router' import { ArrowUpRight, Bell, BookOpen, ChartNoAxesCombined, CheckCheck, ChevronDown, CircleDot, FileText, House, Menu, Plus, ScanLine, ShieldCheck, X } from 'lucide-react' import { pendingNotices, store, useApp, LEVEL_META } from '@/lib/engine' import { useHealth } from '@/lib/metrics' import {isCloud} from '@/lib/cloud-client' import { Brand, Empty } from './Design' import {groundedApi,type ContractResult} from '@/lib/grounded' import type {Observation} from '@/lib/domain' const NAV=[{to:'/home',label:'家庭概览',icon:House},{to:'/watches',label:'关注事项',icon:CircleDot},{to:'/memories',label:'对象记忆',icon:BookOpen},{to:'/events',label:'事件与取证',icon:ScanLine},{to:'/review',label:'生活回顾',icon:FileText},{to:'/insights',label:'运行洞察',icon:ChartNoAxesCombined},{to:'/privacy',label:'隐私与数据',icon:ShieldCheck}] export default function Shell(){ const state=useApp(), health=useHealth(), location=useLocation() const [noticesOpen,setNoticesOpen]=useState(false),[mobileOpen,setMobileOpen]=useState(false) const pending=pendingNotices(state) const contractIds=state.items.filter(i=>i.contractId&&i.enabled).map(i=>i.contractId).join(',') useEffect(()=>{if(!contractIds)return;let stopped=false;const tick=()=>groundedApi<{registrationId:string;notices:ContractResult['notices'];observations:Observation[]}[]>('/api/contracts/notices?ids='+encodeURIComponent(contractIds)).then(rows=>{if(!stopped)rows.forEach(r=>{store.syncContractHistory(r.registrationId,r.observations||[]);store.applyContractNotices(r.registrationId,r.notices)})}).catch(()=>{});void tick();const timer=setInterval(()=>{void tick()},10000);return()=>{stopped=true;clearInterval(timer)}},[contractIds]) useEffect(()=>{if(health)store.setModelStatus(health.ready?'ready':'offline')},[health]) useEffect(()=>{setMobileOpen(false);setNoticesOpen(false);document.querySelector('.content-scroll')?.scrollTo(0,0)},[location.pathname]) useEffect(()=>{const escape=(e:KeyboardEvent)=>{if(e.key==='Escape'){setNoticesOpen(false);setMobileOpen(false)}};window.addEventListener('keydown',escape);return()=>window.removeEventListener('keydown',escape)},[]) const title=NAV.find(n=>location.pathname===n.to)?.label||(location.pathname==='/create'?'新建关注':'事项详情') return