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

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

  export let period = {};

  let error = null;

  function deletePeriod() {
    stufflog.deletePeriod(period.id).then(() => {
      modal.close();
    }).catch(err => {
      error = err.message || err;
      console.warn(err);
    });
  }
</script>

<ModalFrame title={`Remove ${period.name}`} error={error} closable on:close={() => modal.close()}>
  <form on:submit|preventDefault={() => deletePeriod()}>
    <p>
      Are you sure you want to remove period <b>{period.name}</b>?
    </p>

    <hr />

    <button type="submit">Yes, do as I say</button>
  </form>
</ModalFrame>