<template>
  <contents-form
    :content-block="entry"
    :show-task-selection="false"
    block-type="RoomEntry"
    v-if="entry.id"
    @save="saveEntry"
    @hide="hideModal"
  />
</template>

<script>
  import UPDATE_ROOM_ENTRY_MUTATION from 'gql/mutations/rooms/updateRoomEntry.gql';
  import ROOM_ENTRY_QUERY from '@/graphql/gql/queries/roomEntryByIdQuery.gql';

  import ContentsForm from '@/components/content-block-form/ContentsForm';

  export default {
    components: {
      ContentsForm
    },

    data() {
      return {
        entry: {}
      };
    },

    apollo: {
      entry() {
        return {
          query: ROOM_ENTRY_QUERY,
          variables: {
            id: this.$store.state.currentRoomEntry
          },
          update(data) {
            return data.roomEntry;
          }
        };
      }
    },

    computed: {},

    methods: {
      saveEntry(entry) {
        this.$apollo.mutate({
          mutation: UPDATE_ROOM_ENTRY_MUTATION,
          variables: {
            input: {
              roomEntry: entry
            }
          }
        }).then(() => {
          this.hideModal();
        });
      },
      hideModal() {
        this.$store.dispatch('hideModal');
      },
    }
  };
</script>
