// === API FUNCTIONS === async function fetchTags() { try { const r = await fetch(`${API}/${state.base}?order=ref.asc`); state.tags = r.ok ? await r.json() : []; } catch(e) { state.tags = []; } } async function fetchGroups() { try { const r = await fetch(`${API}/api_groups`); state.groups = r.ok ? await r.json() : []; } catch(e) { state.groups = []; } } async function fetchLibraries() { try { const r = await fetch(`${API}/api_library_list`); state.libraries = r.ok ? await r.json() : []; } catch(e) { state.libraries = []; } } async function fetchGraphEdges() { try { const r = await fetch(`${API}/graph_hst`); state.graphEdges = r.ok ? await r.json() : []; } catch(e) { state.graphEdges = []; } } async function fetchTreeEdges() { try { const r = await fetch(`${API}/tree_hst`); state.treeEdges = r.ok ? await r.json() : []; } catch(e) { state.treeEdges = []; } } async function fetchLibraryMembers(mrf) { try { const r = await fetch(`${API}/library_hst?mrf_library=eq.${mrf}`); return r.ok ? (await r.json()).map(d => d.mrf_tag) : []; } catch(e) { return []; } } async function fetchChildren(mrf) { try { const r = await fetch(`${API}/rpc/api_children`, { method: "POST", headers: {"Content-Type": "application/json"}, body: JSON.stringify({parent_mrf: mrf}) }); return r.ok ? await r.json() : []; } catch(e) { return []; } } async function fetchRelated(mrf) { try { const r = await fetch(`${API}/rpc/api_related`, { method: "POST", headers: {"Content-Type": "application/json"}, body: JSON.stringify({tag_mrf: mrf}) }); return r.ok ? await r.json() : []; } catch(e) { return []; } }