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

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

  import UPDATE_ROOM_MUTATION from 'gql/mutations/rooms/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,
                schoolClass: room.schoolClass,
              }
            }
          }
        }).then(() => {
          this.$router.push('/rooms');
        });
      }
    },
  };
</script>
