<template>
  <global-form
    :steps="['request', 'redirect']"
    form-id="register"
    endpoint="content/events_feedbacks"
    class="feedback-layout-container"
    @onRedirect="handleRedirection"
  >
    <template slot="fields">
      <input-hidden
        form-id="register"
        model-name="custom_form_type"
        :default-value="feedback_forms.custom_form_type"
        :rules="['required']"
      />

      <input-hidden
        form-id="register"
        model-name="bundle"
        default-value="events_feedbacks"
        :rules="['required']"
      />

      <input-hidden
        form-id="register"
        model-name="type"
        default-value="node"
        :rules="['required']"
      />

      <input-hidden
        form-id="register"
        model-name="title"
        :default-value="contentTitle"
        :rules="['required']"
      />

      <input-text
        form-id="register"
        :model-name="content_type"
        :defaultValue="title"
        :callback="() => uuid"
        :readonly="true"
        :label="$_tr('event')"
        :rules="['required']"
      />

      <input-text
        form-id="register"
        model-name="firstname"
        :default-value="getUserInfos.firstname"
        :label="$_tr('firstname')"
        :readonly="true"
        :standalone="true"
      />

      <input-text
        form-id="register"
        model-name="lastname"
        :default-value="getUserInfos.lastname"
        :label="$_tr('lastname')"
        :readonly="true"
        :standalone="true"
      />

      <slot />

      <input-textarea
        form-id="register"
        model-name="message"
        :label="$_tr('comment')"
      />
    </template>
  </global-form>
</template>

<script>
import RegisterFeedbackFormsMixin from './../../../mixins/register-feedback-forms-mixin'

import Random from '@inside-library/helpers/GenerateID'
import { formatHref } from '@inside-library/helpers/Langs'
import { getAttrs } from '@inside-library/helpers/Attrs'

export default {
  name: 'FeedbackLayout',
  $_i18nRootPath: 'customs.FORMS.REGISTER',
  mixins: [RegisterFeedbackFormsMixin],
  props: {
    feedback_forms: {
      type: Object,
      required: true
    },
    content_type: {
      type: String,
      required: true
    },
    title: {
      type: String,
      required: true
    },
    uuid: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      contentTitle: `event_feedback${Random.ID()}`
    }
  },
  methods: {
    handleRedirection() {
      const props = { ...this.$props, ...getAttrs(this.$attrs) }

      this.$router.push(
        formatHref({
          name: this.$_page('EventPage', props),
          params: this.$_params(props)
        })
      )
    }
  }
}
</script>

<style lang="scss">
.feedback-layout-container {
  .input-container {
    margin: var(--spacing-xxl) 0;
  }
}
</style>
