<script lang="ts">
  import { onMount } from "svelte";
  import * as rt from "../wailsjs/runtime/runtime";

  import Table from "./Table.svelte";
  import { proto } from "../wailsjs/go/models";
  import Aggregation from "./Aggregation.svelte";

  let path: string;
  let page = 0;

  let isAggregate = false;

  let limitReached: boolean;

  $: console.log(limitReached);

  const keys: string[] = Object.keys(new proto.Employee());

  onMount(async () => {
    rt.EventsOn("proto-opened", (_path: string) => {
      path = _path;
    });

    rt.EventsOn("csv-converted", (_path: string) => {
      console.log(_path);
    });

    rt.EventsOn("aggregation", () => {
      isAggregate = true;
    });
  });
</script>

<main>
  {#if path}
    <Table {path} bind:page bind:limitReached />
    <button disabled={page < 1} on:click={() => page--}>Prev</button>
    <span>{page + 1}</span>
    <button disabled={limitReached} on:click={() => page++}>Next</button>
    <Aggregation bind:isOpen={isAggregate} {keys} />
  {/if}
</main>

<style>
</style>
