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

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

  export let activity = {};
  export let subActivtiy = {};

  let error = null;

  function removeSubActivity() {
    stufflog.updateActivity(activity.id, {removeSub: subActivtiy.id}).then(() => {
      modal.close();
    }).catch(err => {
      error = err.message || err;
      console.warn(err);
    });
  }
</script>

<ModalFrame title={`Remove ${activity.name} Sub-Activity`} error={error} closable on:close={() => modal.close()}>
  <form on:submit|preventDefault={() => removeSubActivity()}>
    <p>
      Are you sure you want to remove sub-acitvity <b>{subActivtiy.name || "(unnamed)"}</b> from
      activity <b>{activity.name}</b>?
    </p>

    <hr />

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