<template>
  <room-form
    :room="room"
    @save="updateRoom"
  ></room-form>
</template>

<script>
  import RoomForm from '@/components/rooms/RoomForm';

  import UPDATE_ROOM_MUTATION from '@/graphql/gql/mutations/updateRoom.gql';

  export default {
    props: ['room'],

    components: {
      RoomForm
    },

    methods: {
      updateRoom(room) {
        this.$apollo.mutate({
          mutation: UPDATE_ROOM_MUTATION,
          variables: {
            input: {
              room: {
                id: room.id,
                title: room.title,
                appearance: room.appearance,
                description: room.description,
                userGroup: room.userGroup
              }
            }
          }
        }).then(() => {
          this.$router.push('/rooms');
        });
      }
    },
  }
</script>
