<script setup>

const router = useRouter()

const itemInfo = ref({})
const auth = useAuthStore()


const createTicket = async () => {

  const ticketRes = await useEntities("tickets").create({
    title: itemInfo.value.title,
  })

  console.log(ticketRes)

  const ticketMsgRes = await useEntities("ticketmessages").create({
    ticket: ticketRes.id,
    created_by: auth.user.user_id,
    content: itemInfo.value.content,
    internal: false
  })

  await router.push(`/support/${ticketRes.id}`)



}

</script>

<template>
  <UDashboardNavbar title="Neues Ticket erstellen">
    <template #right>
      <UButton
        @click="createTicket"
      >
        Erstellen
      </UButton>
    </template>
  </UDashboardNavbar>
  <UForm class="w-2/3 mx-auto mt-5">
    <UFormField
      label="Titel:"
    >
      <UInput
        v-model="itemInfo.title"
      />
    </UFormField>
    <UFormField
      label="Nachricht:"
    >
      <UTextarea
        v-model="itemInfo.content"
      />
    </UFormField>
  </UForm>
</template>

<style scoped>

</style>