import { For } from "solid-js";
import { createAsync } from "@solidjs/router";

import Button from "@/components/Button";
import Timer from "@/components/Timer";
import { getButtons, getTimers } from "@/helpers/api";
import styles from "./index.module.css";

export default function Home() {
  const btns = createAsync(getButtons);
  const timers = createAsync(getTimers);

  return (
    <>
      <div
        class={styles.btnsCont}
        style={{ "--rows-count": Math.floor(btns()?.length / 2) }}
      >
        <For each={btns()}>{(btn) => <Button {...btn} />}</For>
      </div>
      <div class={styles.timersCont}>
        <For each={timers()}>
          {(timer) => (
            <>
              <hr />
              <Timer {...timer} />
            </>
          )}
        </For>
      </div>
    </>
  );
}
