<script>
import { markRaw } from 'vue'

import ReservationForm from './ReservationsForm'
import ReservationsFormModal from '@inside-agenda/modals/ReservationsFormModal'

export default {
  name: 'reservations-form-modal',
  components: {
    ReservationForm
  },
  extends: ReservationsFormModal,
  methods: {
    scaffold() {
      return {
        sections: [
          {
            fields: [
              {
                tag: markRaw(ReservationForm),
                data: {
                  heritedOptions: this.heritedOptions,
                  heritedData: this.heritedData,
                  contentType: this.getCheckedData(
                    this.heritedData,
                    'reservationContentType',
                    this.heritedData.content_type
                  ),
                  parentData: this.heritedData.parentData
                }
              }
            ]
          }
        ]
      }
    },
    formatData(fields) {
      fields.frequency = this.formatFrequency(fields)

      delete fields.until

      if (this.isEdition && this.recursivityAlreadyStarted) {
        delete fields.start_date
        delete fields.end_date
        delete fields.frequency
      }

      return {
        bundle: this.contentType,
        type: 'node',
        ...(!('information_technologies' in fields) && {
          information_technologies: []
        }),
        ...(!('catering_services' in fields) && {
          catering_services: []
        }),
        ...(fields.start_date && { date: fields.start_date.split(' ')[0] }),
        ...fields
      }
    }
  }
}
</script>
