import { useState, useEffect } from 'react'; import type { ZinoClient } from '../../api/client'; export function useDetailViewData(client: ZinoClient, dvUid: string | undefined, instanceId: string | number) { const [data, setData] = useState | null>(null); const [config, setConfig] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { let live = true; async function run() { setLoading(true); setError(null); try { if (!dvUid) throw new Error("dvUid is required to fetch detail view data."); const r = await client.detailView(dvUid, instanceId); if (live) { setData(r.data || {}); setConfig(r.config || {}); } } catch (e) { if (live) setError((e as { message?: string })?.message ?? 'Failed to load'); } finally { if (live) setLoading(false); } } run(); return () => { live = false; }; }, [client, dvUid, instanceId]); return { data, config, loading, error }; }