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

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

  export let period = {};
  export let goal = {};
  export let activity = {};
  let error = null;

  function removePeriodLog() {
    stufflog.updatePeriod(period.id, {removeGoal: goal.id}).then(() => {
      modal.close();
    }).catch(err => {
      error = err.message || err;
      console.warn(err);
    });
  }
</script>

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

    <hr />

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