import { apiClient } from "./client"; import { ControlsData, SafetyControl, SafetyControlValue } from "./types"; export async function getControlsData(): Promise { const deviceId = apiClient.getSelectedDeviceId(); if (!deviceId) { // Return default controls if no device selected return { safetyControls: getDefaultControls(), }; } try { const response = await apiClient.get<{ success: boolean; safetyControls: SafetyControl[]; }>(`/parent/controls/${deviceId}`); return { safetyControls: response.safetyControls, }; } catch (e) { console.error("Failed to fetch controls data", e); return { safetyControls: getDefaultControls(), }; } } export async function updateSafetyControl( key: string, value: SafetyControlValue, ): Promise { const deviceId = apiClient.getSelectedDeviceId(); if (!deviceId) { console.warn("No device selected, cannot update control"); return; } try { await apiClient.post(`/parent/controls/${deviceId}`, { key, value }); } catch (e) { console.error(`Failed to update ${key}`, e); throw e; } } function getDefaultControls(): SafetyControl[] { return [ { key: "disable_buddy", title: "Disable Buddy", description: "Temporarily disable Buddy", defaultValue: false, }, { key: "adult_sites", title: "Adult sites", description: "Block adult websites.", defaultValue: true, }, { key: "family_link_anti_circumvention", title: "Anti-Circumvention", description: "Prevent disabling of Family Link protections.", defaultValue: false, }, { key: "filtering", title: "Content filtering", description: "Block unsafe or adult content.", defaultValue: true, }, { key: "new_people", title: "New contact alerts", description: "Get notified when your child chats with someone new.", defaultValue: true, }, { key: "block_strangers", title: "Block communications with strangers", description: "Block or scan communications with strangers.", defaultValue: false, }, { key: "notify_dangerous_messages", title: "Dangerous messages notifications", description: "Notify when messages are potentially dangerous.", defaultValue: true, }, { key: "notify_new_contact_added", title: "New contact added notifications", description: "Notify when a new contact is added.", defaultValue: true, }, { key: "gallery_scanning_mode", title: "Gallery scanning", description: "Scan gallery for inappropriate images", defaultValue: "none", }, ]; }