import {useCallback,useEffect,useRef,useState} from 'react'; import {LoadingRegion,Button,Icon,IconButton,ResourceList,ResourceRow,SettingsCard,StatusBadge} from '@nodedc/ui-react'; import type {SensorDetailProps} from '../../../../packages/sensor-ui/src/extensions'; import {perform} from '../../../../packages/sensor-ui/src/contracts'; import {LiveViewport} from '../../../../packages/sensor-ui/src/LiveViewport'; import {CameraSettings} from './CameraSettings'; import {RecoverySettings} from './RecoverySettings'; import {cameraStatus,fileName,type CameraFiles,type CameraSettings as Settings} from './model'; export function X4Detail({device,transport,enabled,back,refresh,failure}:SensorDetailProps){ const status=cameraStatus(device); const [settings,setSettings]=useState(null); const [files,setFiles]=useState(null); const [pending,setPending]=useState(null);const busy=pending!==null; const [settingsLoading,setSettingsLoading]=useState(false);const running=useRef(false);const mounted=useRef(true); const available=enabled&&device.online&&status.connected; useEffect(()=>{mounted.current=true;return()=>{mounted.current=false;};},[]); const load=useCallback(async()=>{ if(status.function_mode===null)return; if(mounted.current)setSettingsLoading(true); try{const value=await perform(transport,device,'settings.read',{mode:status.function_mode});if(mounted.current)setSettings(value);} finally{if(mounted.current)setSettingsLoading(false);} },[transport,device.id,device.snapshot.context.session_id,status.function_mode]); useEffect(()=>{if(available)void load().catch(error=>{if(mounted.current)failure(error);});},[available,load]); async function action(name:string,parameters:Record={},key=name){ if(running.current||!enabled||(!available&&!['refresh','recovery.configure','preview.stop'].includes(name)))return; running.current=true;setPending(key);failure(null); try{ const result=name==='refresh'?(available?await load():undefined):await perform(transport,device,name,parameters); if(!mounted.current)return; if(name==='settings.apply')setSettings(result as Settings); if(name==='files.list')setFiles(result as CameraFiles); if(name==='photo.capture'||name==='record.stop')setFiles(null); await refresh(); }catch(error){if(mounted.current)failure(error);} finally{running.current=false;if(mounted.current)setPending(null);} } const mode=settings?.mode??status.function_mode; const recordLabel=status.recording===1?'Идёт запись на карту':status.recording===0?'Запись остановлена':'Состояние записи не подтверждено'; const viewDevice=available?device:{...device,snapshot:{...device.snapshot,acquisition:'idle'}}; return
void action('refresh')}>}>
Серийный номер
{status.serial||'Не получен'}
{!available&&

Нет свежей связи с камерой.

}
{status.alerts?.temperature_high&&

Камера сообщает о перегреве.

} {status.alerts?.storage_full&&

На карте камеры закончилось место.

} {status.alerts?.battery_low&&

Камера сообщает о низком заряде.

}
{status.recovery?.supported&&void action('recovery.configure',{enabled:value,wakeup_confirmed:value})}/>} {available?recordLabel:'Состояние недоступно'}}>
{available&&status.recording===1&&

Запись продолжится после закрытия просмотра.

}
{settings?void action('settings.apply',{mode:settings.mode,key,value})}/>:available&&!settingsLoading?

Настройки недоступны. Обновите состояние камеры.

:null}
void action('files.list',{offset:0},'files.refresh')}>Обновить список}> {files?files.items.length?<>{files.items.map((item,index)=>
  • }/>
  • )}
    {files.offset+1}–{files.offset+files.items.length} из {files.total}
    :

    Файлов нет.

    :

    Обновите список, чтобы увидеть записи на карте камеры.

    }
    ; }