<template>
  <div class="submission-form__text-answer submission-form">
    <textarea
      v-auto-grow
      :placeholder="placeholder"
      :readonly="readonly"
      :value="inputText"
      :class="{'submission-form__textarea--readonly': readonly}"
      rows="1"
      class="submission-form__textarea"
      @input="$emit('input', $event.target.value)"
    />
    <div
      class="submission-form__save-status submission-form__save-status--saved"
      v-if="saved">
      <tick-circle-icon class="submission-form__save-status-icon"/>
    </div>
    <div
      class="submission-form__save-status submission-form__save-status--unsaved"
      v-if="!saved">
      <loading-icon class="submission-form__save-status-icon submission-form__saving-icon"/>
    </div>
  </div>
</template>

<script>
  import TickCircleIcon from '@/components/icons/TickCircleIcon';
  import LoadingIcon from '@/components/icons/LoadingIcon';

  export default {
    props: {
      inputText: String,
      saved: Boolean,
      readonly: Boolean,
      placeholder: {
        type: String,
        default: 'Ergebnis erfassen'
      }
    },
    components: {
      TickCircleIcon,
      LoadingIcon
    }
  };
</script>

<style scoped lang="scss">
  @import "@/styles/_helpers.scss";

  .submission-form {
    display: flex;
    flex-direction: row;
    justify-content: space-between;

    &__textarea {
      display: flex;
      width: 95%;
      padding: 0;
      box-sizing: border-box;
      border-bottom-left-radius: 0;
      border-bottom-right-radius: 0;
      line-height: 1.5;
      border: 0;
      min-height: 110px;
    }

    &__save-status {
      position: relative;
      align-items: center;
    }

    &__save-status-icon {
      width: 22px;
      height: 22px;
      fill: $color-silver-dark;
    }

    &__saving-icon {
      @include spin;
    }
  }
</style>
