<template>
  <project-block
    v-model="newProject"
    title="project_create__title_card"
    btnText="project_create__btn"
    @update="addProject"
  />
</template>

<script setup lang="ts">
  import { ref } from 'vue'
  import { useRouter } from 'vue-router'
  import projectBlock from 'components/projectBlock.vue'
  import { useProjectsStore } from 'stores/projects'
  import type { ProjectParams } from 'types/Project'

  const router = useRouter()
  const projectsStore = useProjectsStore()

  const newProject = ref(<ProjectParams>{
    name: '',
    logo: '',
    description: '',
    is_logo_bg: false
  })
  
  async function addProject () {
    const newDataProject = await projectsStore.add(newProject.value)
    await router.replace({ name: 'chats', params: { id: newDataProject.id }})
  }

</script>
