<template>
  <widget-page disable>
    <new-task-form @save="save" @cancel="cancel" />
  </widget-page>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
import { Task } from '@/widgets/tasks/types/Task'
import { RouteNames } from '@/widgets/tasks/router/routeNames'
import WidgetPage from '@/widgets/base/components/widget-page/WidgetPage.vue'
import NewTaskForm from '@/widgets/tasks/components/form/NewTaskForm.vue'

@Component({
  components: { NewTaskForm, WidgetPage },
})
export default class CreateTaskPage extends Vue {
  save(task: Task) {
    if (task.orderName) {
      return this.$router.push({
        name: RouteNames.orderTasks,
        params: { orderName: task.orderName },
      })
    }

    return this.$router.push({
      name: RouteNames.categoryTasks,
      params: {
        group: task.dateGroup,
        categoryId: String(task.categoryId || ''),
      },
    })
  }

  cancel() {
    this.$router.back()
  }
}
</script>
