import { onMount } from 'svelte';
import { getDevice, putDevice } from '../lib/api.js';

let config = $state({});
let loading = $state(false);
let error = $state(null);

onMount(async () => {
  loading = true;
  try {
    const data = await getDevice();
    config = { ...data };
  } catch (e) {
    error = e.message;
  } finally {
    loading = false;
  }
});

function handleSave(event: Event) {
  event.preventDefault();
  putDevice(config).then(() => window.location.reload());
}
