<script>
  import ModalFrame from "../components/ModalFrame";
  import ActivityIconSelect from "../components/ActivityIconSelect";

  import modal from "../stores/modal";
  import stufflog from "../stores/stufflog";

  let error = null;
  let name = "";
  let icon = "cubes";
  let dailyBonus = 100;

  function createActivity() {
    stufflog.createActivity({name, icon, dailyBonus}).then(() => {
      modal.close();
    }).catch(err => {
      error = err.message || err;
      console.warn(err);
    });
  }
</script>

<ModalFrame title="Create Activity" error={error} closable on:close={() => modal.close()}>
  <form on:submit|preventDefault={() => createActivity()}>
    <label>Name</label>
    <input type="text" bind:value={name} />
    <label>Icon</label>
    <ActivityIconSelect bind:value={icon} />
    <label>Daily Bonus</label>
    <input type="number" bind:value={dailyBonus} />
    <hr />

    <button type="submit">Create</button>
  </form>
</ModalFrame>