<script>
  import DeviceDetails from "../libs/DeviceDetails.svelte";
  import { onMount } from "svelte";
  import { writable } from "svelte/store";
  export let deviceId;

  const apiURL = import.meta.env.VITE_API_URL + "/" + deviceId;

  const deviceLog = writable([]);

  const fetchData = async () => {
    try {
      const response = await fetch(apiURL);
      const data = await response.json();
      deviceLog.set(data["result"].device_log);
    } catch (error) {
      console.log(error);
    }
  };

  onMount(fetchData);
</script>

<div class="body">
  <DeviceDetails {deviceLog} />
</div>

<style>
  .body {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
  }
</style>
