<template>
  <company-block
    v-model="newCompany"
    title="company_create__title_card"
    btnText="company_create__btn"
    @update = "addCompany"
  />
</template>

<script setup lang="ts">
  import { ref } from 'vue'
  import { useRouter } from 'vue-router'
  import companyBlock from 'components/companyBlock.vue'
  import { useCompaniesStore } from 'stores/companies'
  import type { CompanyParams } from 'types/Company'

  const router = useRouter()
  const companiesStore = useCompaniesStore()

  const newCompany = ref(<CompanyParams>{
    name: '',
    logo: '',
    description: '',
    site: '',
    address: '',
    phone: '',
    email: ''
  })
  
  async function addCompany () {
    await companiesStore.add(newCompany.value)
    router.go(-1)
  }

</script>
